1 | As promised, another pullreq... This one's mostly RTH's patches. | 1 | Last minute pullreq for arm related patches; quite large because |
---|---|---|---|
2 | there were several series that only just made it through code review | ||
3 | in time. | ||
2 | 4 | ||
3 | thanks | 5 | thanks |
4 | -- PMM | 6 | -- PMM |
5 | 7 | ||
6 | The following changes since commit 784c2e4f232adf5ef47a84a262ec72a07d068d6a: | 8 | The following changes since commit 091e3e3dbc499d84c004e1c50bc9870af37f6e99: |
7 | 9 | ||
8 | Merge remote-tracking branch 'remotes/jasowang/tags/net-pull-request' into staging (2018-10-19 15:30:40 +0100) | 10 | Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-10-26' into staging (2020-10-26 22:36:35 +0000) |
9 | 11 | ||
10 | are available in the Git repository at: | 12 | are available in the Git repository at: |
11 | 13 | ||
12 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20181019 | 14 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20201027-1 |
13 | 15 | ||
14 | for you to fetch changes up to 88c9add25e7120e8622796c81ad3f3fb7f8d40e7: | 16 | for you to fetch changes up to 32bd322a0134ed89db00f2b9b3894982db3dedcb: |
15 | 17 | ||
16 | target/arm: Only flush tlb if ASID changes (2018-10-19 17:38:48 +0100) | 18 | hw/timer/armv7m_systick: Rewrite to use ptimers (2020-10-27 11:15:31 +0000) |
17 | 19 | ||
18 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
19 | target-arm queue: | 21 | target-arm queue: |
20 | * ssi-sd: Make devices picking up backends unavailable with -device | 22 | * raspi: add model of cprman clock manager |
21 | * Add support for VCPU event states | 23 | * sbsa-ref: add an SBSA generic watchdog device |
22 | * Move towards making ID registers the source of truth for | 24 | * arm/trace: Fix hex printing |
23 | whether a guest CPU implements a feature, rather than having | 25 | * raspi: Add models of Pi 3 model A+, Pi Zero and Pi A+ |
24 | parallel ID registers and feature bit flags | 26 | * hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly |
25 | * Implement various HCR hypervisor trap/config bits | 27 | * Nuvoton NPCM7xx: Add USB, RNG, GPIO and watchdog support |
26 | * Get IL bit correct for v7 syndrome values | 28 | * hw/arm: fix min_cpus for xlnx-versal-virt platform |
27 | * Report correct syndrome for FP/SIMD traps to Hyp mode | 29 | * hw/arm/highbank: Silence warnings about missing fallthrough statements |
28 | * hw/arm/boot: Increase compliance with kernel arm64 boot protocol | 30 | * linux-user: Support Aarch64 BTI |
29 | * Refactor A32 Neon to use generic vector infrastructure | 31 | * Armv7M systick: fix corner case bugs by rewriting to use ptimer |
30 | * Fix a bug in A32 VLD2 "(multiple 2-element structures)" insn | ||
31 | * net: cadence_gem: Report features correctly in ID register | ||
32 | * Avoid some unnecessary TLB flushes on TTBR register writes | ||
33 | 32 | ||
34 | ---------------------------------------------------------------- | 33 | ---------------------------------------------------------------- |
35 | Dongjiu Geng (1): | 34 | Dr. David Alan Gilbert (1): |
36 | target/arm: Add support for VCPU event states | 35 | arm/trace: Fix hex printing |
37 | 36 | ||
38 | Edgar E. Iglesias (2): | 37 | Hao Wu (1): |
39 | net: cadence_gem: Announce availability of priority queues | 38 | hw/timer: Adding watchdog for NPCM7XX Timer. |
40 | net: cadence_gem: Announce 64bit addressing support | ||
41 | 39 | ||
42 | Markus Armbruster (1): | 40 | Havard Skinnemoen (4): |
43 | ssi-sd: Make devices picking up backends unavailable with -device | 41 | Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause |
42 | hw/misc: Add npcm7xx random number generator | ||
43 | hw/arm/npcm7xx: Add EHCI and OHCI controllers | ||
44 | hw/gpio: Add GPIO model for Nuvoton NPCM7xx | ||
44 | 45 | ||
45 | Peter Maydell (10): | 46 | Luc Michel (14): |
46 | target/arm: Improve debug logging of AArch32 exception return | 47 | hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro |
47 | target/arm: Make switch_mode() file-local | 48 | hw/core/clock: trace clock values in Hz instead of ns |
48 | target/arm: Implement HCR.FB | 49 | hw/arm/raspi: fix CPRMAN base address |
49 | target/arm: Implement HCR.DC | 50 | hw/arm/raspi: add a skeleton implementation of the CPRMAN |
50 | target/arm: ISR_EL1 bits track virtual interrupts if IMO/FMO set | 51 | hw/misc/bcm2835_cprman: add a PLL skeleton implementation |
51 | target/arm: Implement HCR.VI and VF | 52 | hw/misc/bcm2835_cprman: implement PLLs behaviour |
52 | target/arm: Implement HCR.PTW | 53 | hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation |
53 | target/arm: New utility function to extract EC from syndrome | 54 | hw/misc/bcm2835_cprman: implement PLL channels behaviour |
54 | target/arm: Get IL bit correct for v7 syndrome values | 55 | hw/misc/bcm2835_cprman: add a clock mux skeleton implementation |
55 | target/arm: Report correct syndrome for FP/SIMD traps to Hyp mode | 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 | ||
56 | 61 | ||
57 | Richard Henderson (30): | 62 | Pavel Dovgalyuk (1): |
58 | target/arm: Move some system registers into a substructure | 63 | hw/arm: fix min_cpus for xlnx-versal-virt platform |
59 | target/arm: V8M should not imply V7VE | ||
60 | target/arm: Convert v8 extensions from feature bits to isar tests | ||
61 | target/arm: Convert division from feature bits to isar0 tests | ||
62 | target/arm: Convert jazelle from feature bit to isar1 test | ||
63 | target/arm: Convert t32ee from feature bit to isar3 test | ||
64 | target/arm: Convert sve from feature bit to aa64pfr0 test | ||
65 | target/arm: Convert v8.2-fp16 from feature bit to aa64pfr0 test | ||
66 | target/arm: Hoist address increment for vector memory ops | ||
67 | target/arm: Don't call tcg_clear_temp_count | ||
68 | target/arm: Use tcg_gen_gvec_dup_i64 for LD[1-4]R | ||
69 | target/arm: Promote consecutive memory ops for aa64 | ||
70 | target/arm: Mark some arrays const | ||
71 | target/arm: Use gvec for NEON VDUP | ||
72 | target/arm: Use gvec for NEON VMOV, VMVN, VBIC & VORR (immediate) | ||
73 | target/arm: Use gvec for NEON_3R_LOGIC insns | ||
74 | target/arm: Use gvec for NEON_3R_VADD_VSUB insns | ||
75 | target/arm: Use gvec for NEON_2RM_VMN, NEON_2RM_VNEG | ||
76 | target/arm: Use gvec for NEON_3R_VMUL | ||
77 | target/arm: Use gvec for VSHR, VSHL | ||
78 | target/arm: Use gvec for VSRA | ||
79 | target/arm: Use gvec for VSRI, VSLI | ||
80 | target/arm: Use gvec for NEON_3R_VML | ||
81 | target/arm: Use gvec for NEON_3R_VTST_VCEQ, NEON_3R_VCGT, NEON_3R_VCGE | ||
82 | target/arm: Use gvec for NEON VLD all lanes | ||
83 | target/arm: Reorg NEON VLD/VST all elements | ||
84 | target/arm: Promote consecutive memory ops for aa32 | ||
85 | target/arm: Reorg NEON VLD/VST single element to one lane | ||
86 | target/arm: Remove writefn from TTBR0_EL3 | ||
87 | target/arm: Only flush tlb if ASID changes | ||
88 | 64 | ||
89 | Stewart Hildebrand (1): | 65 | Peter Maydell (2): |
90 | hw/arm/boot: Increase compliance with kernel arm64 boot protocol | 66 | hw/core/ptimer: Support ptimer being disabled by timer callback |
67 | hw/timer/armv7m_systick: Rewrite to use ptimers | ||
91 | 68 | ||
92 | target/arm/cpu.h | 227 ++++++- | 69 | Philippe Mathieu-Daudé (10): |
93 | target/arm/internals.h | 45 +- | 70 | linux-user/elfload: Avoid leaking interp_name using GLib memory API |
94 | target/arm/kvm_arm.h | 24 + | 71 | hw/arm/bcm2836: Restrict BCM283XInfo declaration to C source |
95 | target/arm/translate.h | 21 + | 72 | hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type |
96 | hw/arm/boot.c | 18 + | 73 | hw/arm/bcm2836: Introduce BCM283XClass::core_count |
97 | hw/intc/armv7m_nvic.c | 12 +- | 74 | hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs |
98 | hw/net/cadence_gem.c | 9 +- | 75 | hw/arm/bcm2836: Split out common realize() code |
99 | hw/sd/ssi-sd.c | 2 + | 76 | hw/arm/bcm2836: Introduce the BCM2835 SoC |
100 | linux-user/aarch64/signal.c | 4 +- | 77 | hw/arm/raspi: Add the Raspberry Pi A+ machine |
101 | linux-user/elfload.c | 60 +- | 78 | hw/arm/raspi: Add the Raspberry Pi Zero machine |
102 | linux-user/syscall.c | 10 +- | 79 | hw/arm/raspi: Add the Raspberry Pi 3 model A+ |
103 | target/arm/cpu.c | 242 ++++---- | ||
104 | target/arm/cpu64.c | 148 +++-- | ||
105 | target/arm/helper.c | 397 ++++++++---- | ||
106 | target/arm/kvm.c | 60 ++ | ||
107 | target/arm/kvm32.c | 13 + | ||
108 | target/arm/kvm64.c | 15 +- | ||
109 | target/arm/machine.c | 28 +- | ||
110 | target/arm/op_helper.c | 2 +- | ||
111 | target/arm/translate-a64.c | 715 ++++----------------- | ||
112 | target/arm/translate.c | 1451 ++++++++++++++++++++++++++++--------------- | ||
113 | 21 files changed, 2021 insertions(+), 1482 deletions(-) | ||
114 | 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 |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Since QEMU does not implement ASIDs, changes to the ASID must flush the | 3 | The kernel sets btype for the signal handler as if for a call. |
4 | tlb. However, if the ASID does not change there is no reason to flush. | ||
5 | 4 | ||
6 | In testing a boot of the Ubuntu installer to the first menu, this reduces | 5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | the number of flushes by 30%, or nearly 600k instances. | ||
8 | |||
9 | Reviewed-by: Aaron Lindsay <aaron@os.amperecomputing.com> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Message-id: 20201021173749.111103-2-richard.henderson@linaro.org |
12 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
13 | Message-id: 20181019015617.22583-3-richard.henderson@linaro.org | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | --- | 9 | --- |
16 | target/arm/helper.c | 8 +++----- | 10 | linux-user/aarch64/signal.c | 10 ++++++++-- |
17 | 1 file changed, 3 insertions(+), 5 deletions(-) | 11 | 1 file changed, 8 insertions(+), 2 deletions(-) |
18 | 12 | ||
19 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 13 | diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c |
20 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/helper.c | 15 | --- a/linux-user/aarch64/signal.c |
22 | +++ b/target/arm/helper.c | 16 | +++ b/linux-user/aarch64/signal.c |
23 | @@ -XXX,XX +XXX,XX @@ static void vmsa_tcr_el1_write(CPUARMState *env, const ARMCPRegInfo *ri, | 17 | @@ -XXX,XX +XXX,XX @@ static void target_setup_frame(int usig, struct target_sigaction *ka, |
24 | static void vmsa_ttbr_write(CPUARMState *env, const ARMCPRegInfo *ri, | 18 | + offsetof(struct target_rt_frame_record, tramp); |
25 | uint64_t value) | ||
26 | { | ||
27 | - /* 64 bit accesses to the TTBRs can change the ASID and so we | ||
28 | - * must flush the TLB. | ||
29 | - */ | ||
30 | - if (cpreg_field_is_64bit(ri)) { | ||
31 | + /* If the ASID changes (with a 64-bit write), we must flush the TLB. */ | ||
32 | + if (cpreg_field_is_64bit(ri) && | ||
33 | + extract64(raw_read(env, ri) ^ value, 48, 16) != 0) { | ||
34 | ARMCPU *cpu = arm_env_get_cpu(env); | ||
35 | - | ||
36 | tlb_flush(CPU(cpu)); | ||
37 | } | 19 | } |
38 | raw_write(env, ri, value); | 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); | ||
39 | -- | 36 | -- |
40 | 2.19.1 | 37 | 2.20.1 |
41 | 38 | ||
42 | 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 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 3 | Transform the prot bit to a qemu internal page bit, and save |
4 | it in the page tables. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | Message-id: 20181016223115.24100-9-richard.henderson@linaro.org | 8 | Message-id: 20201021173749.111103-3-richard.henderson@linaro.org |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 10 | --- |
9 | target/arm/cpu.h | 17 +++++++++++++++- | 11 | include/exec/cpu-all.h | 2 ++ |
10 | linux-user/elfload.c | 6 +----- | 12 | linux-user/syscall_defs.h | 4 ++++ |
11 | target/arm/cpu64.c | 16 ++++++++------- | 13 | target/arm/cpu.h | 5 +++++ |
12 | target/arm/helper.c | 2 +- | 14 | linux-user/mmap.c | 16 ++++++++++++++++ |
13 | target/arm/translate-a64.c | 40 +++++++++++++++++++------------------- | 15 | target/arm/translate-a64.c | 6 +++--- |
14 | target/arm/translate.c | 6 +++--- | 16 | 5 files changed, 30 insertions(+), 3 deletions(-) |
15 | 6 files changed, 50 insertions(+), 37 deletions(-) | ||
16 | 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 */ | ||
17 | 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 |
18 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/arm/cpu.h | 48 | --- a/target/arm/cpu.h |
20 | +++ b/target/arm/cpu.h | 49 | +++ b/target/arm/cpu.h |
21 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 50 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) |
22 | ARM_FEATURE_PMU, /* has PMU support */ | 51 | #define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0) |
23 | ARM_FEATURE_VBAR, /* has cp15 VBAR */ | 52 | #define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1) |
24 | ARM_FEATURE_M_SECURITY, /* M profile Security Extension */ | 53 | |
25 | - ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */ | 54 | +/* |
26 | ARM_FEATURE_M_MAIN, /* M profile Main Extension */ | 55 | + * AArch64 usage of the PAGE_TARGET_* bits for linux-user. |
27 | }; | 56 | + */ |
28 | 57 | +#define PAGE_BTI PAGE_TARGET_1 | |
29 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa32_dp(const ARMISARegisters *id) | ||
30 | return FIELD_EX32(id->id_isar6, ID_ISAR6, DP) != 0; | ||
31 | } | ||
32 | |||
33 | +static inline bool isar_feature_aa32_fp16_arith(const ARMISARegisters *id) | ||
34 | +{ | ||
35 | + /* | ||
36 | + * This is a placeholder for use by VCMA until the rest of | ||
37 | + * the ARMv8.2-FP16 extension is implemented for aa32 mode. | ||
38 | + * At which point we can properly set and check MVFR1.FPHP. | ||
39 | + */ | ||
40 | + return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, FP) == 1; | ||
41 | +} | ||
42 | + | 58 | + |
43 | /* | 59 | /* |
44 | * 64-bit feature tests via id registers. | 60 | * Naming convention for isar_feature functions: |
45 | */ | 61 | * Functions which test 32-bit ID registers should have _aa32_ in |
46 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_fcma(const ARMISARegisters *id) | 62 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c |
47 | return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, FCMA) != 0; | 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 | |||
70 | +#ifdef TARGET_AARCH64 | ||
71 | + /* | ||
72 | + * The PROT_BTI bit is only accepted if the cpu supports the feature. | ||
73 | + * Since this is the unusual case, don't bother checking unless | ||
74 | + * the bit has been requested. If set and valid, record the bit | ||
75 | + * within QEMU's page_flags. | ||
76 | + */ | ||
77 | + if (prot & TARGET_PROT_BTI) { | ||
78 | + ARMCPU *cpu = ARM_CPU(thread_cpu); | ||
79 | + if (cpu_isar_feature(aa64_bti, cpu)) { | ||
80 | + valid |= TARGET_PROT_BTI; | ||
81 | + page_flags |= PAGE_BTI; | ||
82 | + } | ||
83 | + } | ||
84 | +#endif | ||
85 | + | ||
86 | return prot & ~valid ? 0 : page_flags; | ||
48 | } | 87 | } |
49 | |||
50 | +static inline bool isar_feature_aa64_fp16(const ARMISARegisters *id) | ||
51 | +{ | ||
52 | + /* We always set the AdvSIMD and FP fields identically wrt FP16. */ | ||
53 | + return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, FP) == 1; | ||
54 | +} | ||
55 | + | ||
56 | static inline bool isar_feature_aa64_sve(const ARMISARegisters *id) | ||
57 | { | ||
58 | return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, SVE) != 0; | ||
59 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
60 | index XXXXXXX..XXXXXXX 100644 | ||
61 | --- a/linux-user/elfload.c | ||
62 | +++ b/linux-user/elfload.c | ||
63 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | ||
64 | hwcaps |= ARM_HWCAP_A64_ASIMD; | ||
65 | |||
66 | /* probe for the extra features */ | ||
67 | -#define GET_FEATURE(feat, hwcap) \ | ||
68 | - do { if (arm_feature(&cpu->env, feat)) { hwcaps |= hwcap; } } while (0) | ||
69 | #define GET_FEATURE_ID(feat, hwcap) \ | ||
70 | do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0) | ||
71 | |||
72 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | ||
73 | GET_FEATURE_ID(aa64_sha3, ARM_HWCAP_A64_SHA3); | ||
74 | GET_FEATURE_ID(aa64_sm3, ARM_HWCAP_A64_SM3); | ||
75 | GET_FEATURE_ID(aa64_sm4, ARM_HWCAP_A64_SM4); | ||
76 | - GET_FEATURE(ARM_FEATURE_V8_FP16, | ||
77 | - ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP); | ||
78 | + GET_FEATURE_ID(aa64_fp16, ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP); | ||
79 | GET_FEATURE_ID(aa64_atomics, ARM_HWCAP_A64_ATOMICS); | ||
80 | GET_FEATURE_ID(aa64_rdm, ARM_HWCAP_A64_ASIMDRDM); | ||
81 | GET_FEATURE_ID(aa64_dp, ARM_HWCAP_A64_ASIMDDP); | ||
82 | GET_FEATURE_ID(aa64_fcma, ARM_HWCAP_A64_FCMA); | ||
83 | GET_FEATURE_ID(aa64_sve, ARM_HWCAP_A64_SVE); | ||
84 | |||
85 | -#undef GET_FEATURE | ||
86 | #undef GET_FEATURE_ID | ||
87 | |||
88 | return hwcaps; | ||
89 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/target/arm/cpu64.c | ||
92 | +++ b/target/arm/cpu64.c | ||
93 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) | ||
94 | |||
95 | t = cpu->isar.id_aa64pfr0; | ||
96 | t = FIELD_DP64(t, ID_AA64PFR0, SVE, 1); | ||
97 | + t = FIELD_DP64(t, ID_AA64PFR0, FP, 1); | ||
98 | + t = FIELD_DP64(t, ID_AA64PFR0, ADVSIMD, 1); | ||
99 | cpu->isar.id_aa64pfr0 = t; | ||
100 | |||
101 | /* Replicate the same data to the 32-bit id registers. */ | ||
102 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) | ||
103 | u = FIELD_DP32(u, ID_ISAR6, DP, 1); | ||
104 | cpu->isar.id_isar6 = u; | ||
105 | |||
106 | -#ifdef CONFIG_USER_ONLY | ||
107 | - /* We don't set these in system emulation mode for the moment, | ||
108 | - * since we don't correctly set the ID registers to advertise them, | ||
109 | - * and in some cases they're only available in AArch64 and not AArch32, | ||
110 | - * whereas the architecture requires them to be present in both if | ||
111 | - * present in either. | ||
112 | + /* | ||
113 | + * FIXME: We do not yet support ARMv8.2-fp16 for AArch32 yet, | ||
114 | + * so do not set MVFR1.FPHP. Strictly speaking this is not legal, | ||
115 | + * but it is also not legal to enable SVE without support for FP16, | ||
116 | + * and enabling SVE in system mode is more useful in the short term. | ||
117 | */ | ||
118 | - set_feature(&cpu->env, ARM_FEATURE_V8_FP16); | ||
119 | + | ||
120 | +#ifdef CONFIG_USER_ONLY | ||
121 | /* For usermode -cpu max we can use a larger and more efficient DCZ | ||
122 | * blocksize since we don't have to follow what the hardware does. | ||
123 | */ | ||
124 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
125 | index XXXXXXX..XXXXXXX 100644 | ||
126 | --- a/target/arm/helper.c | ||
127 | +++ b/target/arm/helper.c | ||
128 | @@ -XXX,XX +XXX,XX @@ void HELPER(vfp_set_fpscr)(CPUARMState *env, uint32_t val) | ||
129 | uint32_t changed; | ||
130 | |||
131 | /* When ARMv8.2-FP16 is not supported, FZ16 is RES0. */ | ||
132 | - if (!arm_feature(env, ARM_FEATURE_V8_FP16)) { | ||
133 | + if (!cpu_isar_feature(aa64_fp16, arm_env_get_cpu(env))) { | ||
134 | val &= ~FPCR_FZ16; | ||
135 | } | ||
136 | 88 | ||
137 | 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 |
138 | index XXXXXXX..XXXXXXX 100644 | 90 | index XXXXXXX..XXXXXXX 100644 |
139 | --- a/target/arm/translate-a64.c | 91 | --- a/target/arm/translate-a64.c |
140 | +++ b/target/arm/translate-a64.c | 92 | +++ b/target/arm/translate-a64.c |
141 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_compare(DisasContext *s, uint32_t insn) | 93 | @@ -XXX,XX +XXX,XX @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn) |
142 | break; | 94 | */ |
143 | case 3: | 95 | static bool is_guarded_page(CPUARMState *env, DisasContext *s) |
144 | size = MO_16; | 96 | { |
145 | - if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | 97 | -#ifdef CONFIG_USER_ONLY |
146 | + if (dc_isar_feature(aa64_fp16, s)) { | 98 | - return false; /* FIXME */ |
147 | break; | 99 | -#else |
148 | } | 100 | uint64_t addr = s->base.pc_first; |
149 | /* fallthru */ | 101 | +#ifdef CONFIG_USER_ONLY |
150 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_ccomp(DisasContext *s, uint32_t insn) | 102 | + return page_get_flags(addr) & PAGE_BTI; |
151 | break; | 103 | +#else |
152 | case 3: | 104 | int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx); |
153 | size = MO_16; | 105 | unsigned int index = tlb_index(env, mmu_idx, addr); |
154 | - if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | 106 | CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); |
155 | + if (dc_isar_feature(aa64_fp16, s)) { | ||
156 | break; | ||
157 | } | ||
158 | /* fallthru */ | ||
159 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_csel(DisasContext *s, uint32_t insn) | ||
160 | break; | ||
161 | case 3: | ||
162 | sz = MO_16; | ||
163 | - if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
164 | + if (dc_isar_feature(aa64_fp16, s)) { | ||
165 | break; | ||
166 | } | ||
167 | /* fallthru */ | ||
168 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_1src(DisasContext *s, uint32_t insn) | ||
169 | handle_fp_1src_double(s, opcode, rd, rn); | ||
170 | break; | ||
171 | case 3: | ||
172 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
173 | + if (!dc_isar_feature(aa64_fp16, s)) { | ||
174 | unallocated_encoding(s); | ||
175 | return; | ||
176 | } | ||
177 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_2src(DisasContext *s, uint32_t insn) | ||
178 | handle_fp_2src_double(s, opcode, rd, rn, rm); | ||
179 | break; | ||
180 | case 3: | ||
181 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
182 | + if (!dc_isar_feature(aa64_fp16, s)) { | ||
183 | unallocated_encoding(s); | ||
184 | return; | ||
185 | } | ||
186 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_3src(DisasContext *s, uint32_t insn) | ||
187 | handle_fp_3src_double(s, o0, o1, rd, rn, rm, ra); | ||
188 | break; | ||
189 | case 3: | ||
190 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
191 | + if (!dc_isar_feature(aa64_fp16, s)) { | ||
192 | unallocated_encoding(s); | ||
193 | return; | ||
194 | } | ||
195 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_imm(DisasContext *s, uint32_t insn) | ||
196 | break; | ||
197 | case 3: | ||
198 | sz = MO_16; | ||
199 | - if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
200 | + if (dc_isar_feature(aa64_fp16, s)) { | ||
201 | break; | ||
202 | } | ||
203 | /* fallthru */ | ||
204 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_fixed_conv(DisasContext *s, uint32_t insn) | ||
205 | case 1: /* float64 */ | ||
206 | break; | ||
207 | case 3: /* float16 */ | ||
208 | - if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
209 | + if (dc_isar_feature(aa64_fp16, s)) { | ||
210 | break; | ||
211 | } | ||
212 | /* fallthru */ | ||
213 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_int_conv(DisasContext *s, uint32_t insn) | ||
214 | break; | ||
215 | case 0x6: /* 16-bit float, 32-bit int */ | ||
216 | case 0xe: /* 16-bit float, 64-bit int */ | ||
217 | - if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
218 | + if (dc_isar_feature(aa64_fp16, s)) { | ||
219 | break; | ||
220 | } | ||
221 | /* fallthru */ | ||
222 | @@ -XXX,XX +XXX,XX @@ static void disas_fp_int_conv(DisasContext *s, uint32_t insn) | ||
223 | case 1: /* float64 */ | ||
224 | break; | ||
225 | case 3: /* float16 */ | ||
226 | - if (arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
227 | + if (dc_isar_feature(aa64_fp16, s)) { | ||
228 | break; | ||
229 | } | ||
230 | /* fallthru */ | ||
231 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_across_lanes(DisasContext *s, uint32_t insn) | ||
232 | */ | ||
233 | is_min = extract32(size, 1, 1); | ||
234 | is_fp = true; | ||
235 | - if (!is_u && arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
236 | + if (!is_u && dc_isar_feature(aa64_fp16, s)) { | ||
237 | size = 1; | ||
238 | } else if (!is_u || !is_q || extract32(size, 0, 1)) { | ||
239 | unallocated_encoding(s); | ||
240 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_mod_imm(DisasContext *s, uint32_t insn) | ||
241 | |||
242 | if (o2 != 0 || ((cmode == 0xf) && is_neg && !is_q)) { | ||
243 | /* Check for FMOV (vector, immediate) - half-precision */ | ||
244 | - if (!(arm_dc_feature(s, ARM_FEATURE_V8_FP16) && o2 && cmode == 0xf)) { | ||
245 | + if (!(dc_isar_feature(aa64_fp16, s) && o2 && cmode == 0xf)) { | ||
246 | unallocated_encoding(s); | ||
247 | return; | ||
248 | } | ||
249 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_pairwise(DisasContext *s, uint32_t insn) | ||
250 | case 0x2f: /* FMINP */ | ||
251 | /* FP op, size[0] is 32 or 64 bit*/ | ||
252 | if (!u) { | ||
253 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
254 | + if (!dc_isar_feature(aa64_fp16, s)) { | ||
255 | unallocated_encoding(s); | ||
256 | return; | ||
257 | } else { | ||
258 | @@ -XXX,XX +XXX,XX @@ static void handle_simd_shift_intfp_conv(DisasContext *s, bool is_scalar, | ||
259 | size = MO_32; | ||
260 | } else if (immh & 2) { | ||
261 | size = MO_16; | ||
262 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
263 | + if (!dc_isar_feature(aa64_fp16, s)) { | ||
264 | unallocated_encoding(s); | ||
265 | return; | ||
266 | } | ||
267 | @@ -XXX,XX +XXX,XX @@ static void handle_simd_shift_fpint_conv(DisasContext *s, bool is_scalar, | ||
268 | size = MO_32; | ||
269 | } else if (immh & 0x2) { | ||
270 | size = MO_16; | ||
271 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
272 | + if (!dc_isar_feature(aa64_fp16, s)) { | ||
273 | unallocated_encoding(s); | ||
274 | return; | ||
275 | } | ||
276 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_three_reg_same_fp16(DisasContext *s, | ||
277 | return; | ||
278 | } | ||
279 | |||
280 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
281 | + if (!dc_isar_feature(aa64_fp16, s)) { | ||
282 | unallocated_encoding(s); | ||
283 | } | ||
284 | |||
285 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_fp16(DisasContext *s, uint32_t insn) | ||
286 | TCGv_ptr fpst; | ||
287 | bool pairwise = false; | ||
288 | |||
289 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
290 | + if (!dc_isar_feature(aa64_fp16, s)) { | ||
291 | unallocated_encoding(s); | ||
292 | return; | ||
293 | } | ||
294 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | ||
295 | case 0x1c: /* FCADD, #90 */ | ||
296 | case 0x1e: /* FCADD, #270 */ | ||
297 | if (size == 0 | ||
298 | - || (size == 1 && !arm_dc_feature(s, ARM_FEATURE_V8_FP16)) | ||
299 | + || (size == 1 && !dc_isar_feature(aa64_fp16, s)) | ||
300 | || (size == 3 && !is_q)) { | ||
301 | unallocated_encoding(s); | ||
302 | return; | ||
303 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_two_reg_misc_fp16(DisasContext *s, uint32_t insn) | ||
304 | bool need_fpst = true; | ||
305 | int rmode; | ||
306 | |||
307 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
308 | + if (!dc_isar_feature(aa64_fp16, s)) { | ||
309 | unallocated_encoding(s); | ||
310 | return; | ||
311 | } | ||
312 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
313 | } | ||
314 | break; | ||
315 | } | ||
316 | - if (is_fp16 && !arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
317 | + if (is_fp16 && !dc_isar_feature(aa64_fp16, s)) { | ||
318 | unallocated_encoding(s); | ||
319 | return; | ||
320 | } | ||
321 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
322 | index XXXXXXX..XXXXXXX 100644 | ||
323 | --- a/target/arm/translate.c | ||
324 | +++ b/target/arm/translate.c | ||
325 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn) | ||
326 | int size = extract32(insn, 20, 1); | ||
327 | data = extract32(insn, 23, 2); /* rot */ | ||
328 | if (!dc_isar_feature(aa32_vcma, s) | ||
329 | - || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) { | ||
330 | + || (!size && !dc_isar_feature(aa32_fp16_arith, s))) { | ||
331 | return 1; | ||
332 | } | ||
333 | fn_gvec_ptr = size ? gen_helper_gvec_fcmlas : gen_helper_gvec_fcmlah; | ||
334 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn) | ||
335 | int size = extract32(insn, 20, 1); | ||
336 | data = extract32(insn, 24, 1); /* rot */ | ||
337 | if (!dc_isar_feature(aa32_vcma, s) | ||
338 | - || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) { | ||
339 | + || (!size && !dc_isar_feature(aa32_fp16_arith, s))) { | ||
340 | return 1; | ||
341 | } | ||
342 | fn_gvec_ptr = size ? gen_helper_gvec_fcadds : gen_helper_gvec_fcaddh; | ||
343 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_2reg_scalar_ext(DisasContext *s, uint32_t insn) | ||
344 | return 1; | ||
345 | } | ||
346 | if (size == 0) { | ||
347 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FP16)) { | ||
348 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | ||
349 | return 1; | ||
350 | } | ||
351 | /* For fp16, rm is just Vm, and index is M. */ | ||
352 | -- | 107 | -- |
353 | 2.19.1 | 108 | 2.20.1 |
354 | 109 | ||
355 | 110 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | For a sequence of loads or stores from a single register, | 3 | These are all of the defines required to parse |
4 | little-endian operations can be promoted to an 8-byte op. | 4 | GNU_PROPERTY_AARCH64_FEATURE_1_AND, copied from binutils. |
5 | This can reduce the number of operations by a factor of 8. | 5 | Other missing defines related to other GNU program headers |
6 | and notes are elided for now. | ||
6 | 7 | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20181011205206.3552-20-richard.henderson@linaro.org | 10 | Message-id: 20201021173749.111103-4-richard.henderson@linaro.org |
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 12 | --- |
13 | target/arm/translate.c | 10 ++++++++++ | 13 | include/elf.h | 22 ++++++++++++++++++++++ |
14 | 1 file changed, 10 insertions(+) | 14 | 1 file changed, 22 insertions(+) |
15 | 15 | ||
16 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 16 | diff --git a/include/elf.h b/include/elf.h |
17 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/translate.c | 18 | --- a/include/elf.h |
19 | +++ b/target/arm/translate.c | 19 | +++ b/include/elf.h |
20 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | 20 | @@ -XXX,XX +XXX,XX @@ typedef int64_t Elf64_Sxword; |
21 | if (size == 3 && (interleave | spacing) != 1) { | 21 | #define PT_NOTE 4 |
22 | return 1; | 22 | #define PT_SHLIB 5 |
23 | } | 23 | #define PT_PHDR 6 |
24 | + /* For our purposes, bytes are always little-endian. */ | 24 | +#define PT_LOOS 0x60000000 |
25 | + if (size == 0) { | 25 | +#define PT_HIOS 0x6fffffff |
26 | + endian = MO_LE; | 26 | #define PT_LOPROC 0x70000000 |
27 | + } | 27 | #define PT_HIPROC 0x7fffffff |
28 | + /* Consecutive little-endian elements from a single register | 28 | |
29 | + * can be promoted to a larger little-endian operation. | 29 | +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) |
30 | + */ | 30 | + |
31 | + if (interleave == 1 && endian == MO_LE) { | 31 | #define PT_MIPS_REGINFO 0x70000000 |
32 | + size = 3; | 32 | #define PT_MIPS_RTPROC 0x70000001 |
33 | + } | 33 | #define PT_MIPS_OPTIONS 0x70000002 |
34 | tmp64 = tcg_temp_new_i64(); | 34 | @@ -XXX,XX +XXX,XX @@ typedef struct elf64_shdr { |
35 | addr = tcg_temp_new_i32(); | 35 | #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ |
36 | tmp2 = tcg_const_i32(1 << size); | 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 | * | ||
37 | -- | 59 | -- |
38 | 2.19.1 | 60 | 2.20.1 |
39 | 61 | ||
40 | 62 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Both arm and thumb2 division are controlled by the same ISAR field, | 3 | Fix an unlikely memory leak in load_elf_image(). |
4 | which takes care of the arm implies thumb case. Having M imply | ||
5 | thumb2 division was wrong for cortex-m0, which is v6m and does not | ||
6 | have thumb2 at all, much less thumb2 division. | ||
7 | 4 | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 5 | Fixes: bf858897b7 ("linux-user: Re-use load_elf_image for the main binary.") |
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
10 | Message-id: 20181016223115.24100-5-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> | 11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 13 | --- |
14 | target/arm/cpu.h | 12 ++++++++++-- | 14 | linux-user/elfload.c | 8 ++++---- |
15 | linux-user/elfload.c | 4 ++-- | 15 | 1 file changed, 4 insertions(+), 4 deletions(-) |
16 | target/arm/cpu.c | 10 +--------- | ||
17 | target/arm/translate.c | 4 ++-- | ||
18 | 4 files changed, 15 insertions(+), 15 deletions(-) | ||
19 | 16 | ||
20 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/target/arm/cpu.h | ||
23 | +++ b/target/arm/cpu.h | ||
24 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | ||
25 | ARM_FEATURE_VFP3, | ||
26 | ARM_FEATURE_VFP_FP16, | ||
27 | ARM_FEATURE_NEON, | ||
28 | - ARM_FEATURE_THUMB_DIV, /* divide supported in Thumb encoding */ | ||
29 | ARM_FEATURE_M, /* Microcontroller profile. */ | ||
30 | ARM_FEATURE_OMAPCP, /* OMAP specific CP15 ops handling. */ | ||
31 | ARM_FEATURE_THUMB2EE, | ||
32 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | ||
33 | ARM_FEATURE_V5, | ||
34 | ARM_FEATURE_STRONGARM, | ||
35 | ARM_FEATURE_VAPA, /* cp15 VA to PA lookups */ | ||
36 | - ARM_FEATURE_ARM_DIV, /* divide supported in ARM encoding */ | ||
37 | ARM_FEATURE_VFP4, /* VFPv4 (implies that NEON is v2) */ | ||
38 | ARM_FEATURE_GENERIC_TIMER, | ||
39 | ARM_FEATURE_MVFR, /* Media and VFP Feature Registers 0 and 1 */ | ||
40 | @@ -XXX,XX +XXX,XX @@ extern const uint64_t pred_esz_masks[4]; | ||
41 | /* | ||
42 | * 32-bit feature tests via id registers. | ||
43 | */ | ||
44 | +static inline bool isar_feature_thumb_div(const ARMISARegisters *id) | ||
45 | +{ | ||
46 | + return FIELD_EX32(id->id_isar0, ID_ISAR0, DIVIDE) != 0; | ||
47 | +} | ||
48 | + | ||
49 | +static inline bool isar_feature_arm_div(const ARMISARegisters *id) | ||
50 | +{ | ||
51 | + return FIELD_EX32(id->id_isar0, ID_ISAR0, DIVIDE) > 1; | ||
52 | +} | ||
53 | + | ||
54 | static inline bool isar_feature_aa32_aes(const ARMISARegisters *id) | ||
55 | { | ||
56 | return FIELD_EX32(id->id_isar5, ID_ISAR5, AES) != 0; | ||
57 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 17 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
58 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
59 | --- a/linux-user/elfload.c | 19 | --- a/linux-user/elfload.c |
60 | +++ b/linux-user/elfload.c | 20 | +++ b/linux-user/elfload.c |
61 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | 21 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
62 | GET_FEATURE(ARM_FEATURE_VFP3, ARM_HWCAP_ARM_VFPv3); | 22 | info->brk = vaddr_em; |
63 | GET_FEATURE(ARM_FEATURE_V6K, ARM_HWCAP_ARM_TLS); | 23 | } |
64 | GET_FEATURE(ARM_FEATURE_VFP4, ARM_HWCAP_ARM_VFPv4); | 24 | } else if (eppnt->p_type == PT_INTERP && pinterp_name) { |
65 | - GET_FEATURE(ARM_FEATURE_ARM_DIV, ARM_HWCAP_ARM_IDIVA); | 25 | - char *interp_name; |
66 | - GET_FEATURE(ARM_FEATURE_THUMB_DIV, ARM_HWCAP_ARM_IDIVT); | 26 | + g_autofree char *interp_name = NULL; |
67 | + GET_FEATURE_ID(arm_div, ARM_HWCAP_ARM_IDIVA); | 27 | |
68 | + GET_FEATURE_ID(thumb_div, ARM_HWCAP_ARM_IDIVT); | 28 | if (*pinterp_name) { |
69 | /* All QEMU's VFPv3 CPUs have 32 registers, see VFP_DREG in translate.c. | 29 | errmsg = "Multiple PT_INTERP entries"; |
70 | * Note that the ARM_HWCAP_ARM_VFPv3D16 bit is always the inverse of | 30 | goto exit_errmsg; |
71 | * ARM_HWCAP_ARM_VFPD32 (and so always clear for QEMU); it is unrelated | 31 | } |
72 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 32 | - interp_name = malloc(eppnt->p_filesz); |
73 | index XXXXXXX..XXXXXXX 100644 | 33 | + interp_name = g_malloc(eppnt->p_filesz); |
74 | --- a/target/arm/cpu.c | 34 | if (!interp_name) { |
75 | +++ b/target/arm/cpu.c | 35 | goto exit_perror; |
76 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) | 36 | } |
77 | * Presence of EL2 itself is ARM_FEATURE_EL2, and of the | 37 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
78 | * Security Extensions is ARM_FEATURE_EL3. | 38 | errmsg = "Invalid PT_INTERP entry"; |
79 | */ | 39 | goto exit_errmsg; |
80 | - set_feature(env, ARM_FEATURE_ARM_DIV); | 40 | } |
81 | + assert(cpu_isar_feature(arm_div, cpu)); | 41 | - *pinterp_name = interp_name; |
82 | set_feature(env, ARM_FEATURE_LPAE); | 42 | + *pinterp_name = g_steal_pointer(&interp_name); |
83 | set_feature(env, ARM_FEATURE_V7); | 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); | ||
84 | } | 52 | } |
85 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) | 53 | |
86 | if (arm_feature(env, ARM_FEATURE_V5)) { | 54 | #ifdef USE_ELF_CORE_DUMP |
87 | set_feature(env, ARM_FEATURE_V4T); | ||
88 | } | ||
89 | - if (arm_feature(env, ARM_FEATURE_M)) { | ||
90 | - set_feature(env, ARM_FEATURE_THUMB_DIV); | ||
91 | - } | ||
92 | - if (arm_feature(env, ARM_FEATURE_ARM_DIV)) { | ||
93 | - set_feature(env, ARM_FEATURE_THUMB_DIV); | ||
94 | - } | ||
95 | if (arm_feature(env, ARM_FEATURE_VFP4)) { | ||
96 | set_feature(env, ARM_FEATURE_VFP3); | ||
97 | set_feature(env, ARM_FEATURE_VFP_FP16); | ||
98 | @@ -XXX,XX +XXX,XX @@ static void cortex_r5_initfn(Object *obj) | ||
99 | ARMCPU *cpu = ARM_CPU(obj); | ||
100 | |||
101 | set_feature(&cpu->env, ARM_FEATURE_V7); | ||
102 | - set_feature(&cpu->env, ARM_FEATURE_THUMB_DIV); | ||
103 | - set_feature(&cpu->env, ARM_FEATURE_ARM_DIV); | ||
104 | set_feature(&cpu->env, ARM_FEATURE_V7MP); | ||
105 | set_feature(&cpu->env, ARM_FEATURE_PMSA); | ||
106 | cpu->midr = 0x411fc153; /* r1p3 */ | ||
107 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/target/arm/translate.c | ||
110 | +++ b/target/arm/translate.c | ||
111 | @@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) | ||
112 | case 1: | ||
113 | case 3: | ||
114 | /* SDIV, UDIV */ | ||
115 | - if (!arm_dc_feature(s, ARM_FEATURE_ARM_DIV)) { | ||
116 | + if (!dc_isar_feature(arm_div, s)) { | ||
117 | goto illegal_op; | ||
118 | } | ||
119 | if (((insn >> 5) & 7) || (rd != 15)) { | ||
120 | @@ -XXX,XX +XXX,XX @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn) | ||
121 | tmp2 = load_reg(s, rm); | ||
122 | if ((op & 0x50) == 0x10) { | ||
123 | /* sdiv, udiv */ | ||
124 | - if (!arm_dc_feature(s, ARM_FEATURE_THUMB_DIV)) { | ||
125 | + if (!dc_isar_feature(thumb_div, s)) { | ||
126 | goto illegal_op; | ||
127 | } | ||
128 | if (op & 0x20) | ||
129 | -- | 55 | -- |
130 | 2.19.1 | 56 | 2.20.1 |
131 | 57 | ||
132 | 58 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Instantiating mps2-an505 (cortex-m33) will fail make check when | 3 | Fixing this now will clarify following patches. |
4 | V7VE asserts that ID_ISAR0.Divide includes ARM division. It is | ||
5 | also wrong to include ARM_FEATURE_LPAE. | ||
6 | 4 | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20181016223115.24100-3-richard.henderson@linaro.org | 6 | Message-id: 20201021173749.111103-6-richard.henderson@linaro.org |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 9 | --- |
12 | target/arm/cpu.c | 6 +++++- | 10 | linux-user/elfload.c | 12 +++++++++--- |
13 | 1 file changed, 5 insertions(+), 1 deletion(-) | 11 | 1 file changed, 9 insertions(+), 3 deletions(-) |
14 | 12 | ||
15 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 13 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
16 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/cpu.c | 15 | --- a/linux-user/elfload.c |
18 | +++ b/target/arm/cpu.c | 16 | +++ b/linux-user/elfload.c |
19 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) | 17 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
20 | 18 | abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len; | |
21 | /* Some features automatically imply others: */ | 19 | int elf_prot = 0; |
22 | if (arm_feature(env, ARM_FEATURE_V8)) { | 20 | |
23 | - set_feature(env, ARM_FEATURE_V7VE); | 21 | - if (eppnt->p_flags & PF_R) elf_prot = PROT_READ; |
24 | + if (arm_feature(env, ARM_FEATURE_M)) { | 22 | - if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE; |
25 | + set_feature(env, ARM_FEATURE_V7); | 23 | - if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC; |
26 | + } else { | 24 | + if (eppnt->p_flags & PF_R) { |
27 | + set_feature(env, ARM_FEATURE_V7VE); | 25 | + elf_prot |= PROT_READ; |
28 | + } | 26 | + } |
29 | } | 27 | + if (eppnt->p_flags & PF_W) { |
30 | if (arm_feature(env, ARM_FEATURE_V7VE)) { | 28 | + elf_prot |= PROT_WRITE; |
31 | /* v7 Virtualization Extensions. In real hardware this implies | 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); | ||
32 | -- | 36 | -- |
33 | 2.19.1 | 37 | 2.20.1 |
34 | 38 | ||
35 | 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 | Most of the v8 extensions are self-contained within the ISAR | 3 | The second loop uses a loop induction variable, and the first |
4 | registers and are not implied by other feature bits, which | 4 | does not. Transform the first to match the second, to simplify |
5 | makes them the easiest to convert. | 5 | a following patch moving code between them. |
6 | 6 | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Message-id: 20181016223115.24100-4-richard.henderson@linaro.org | 8 | Message-id: 20201021173749.111103-7-richard.henderson@linaro.org |
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 11 | --- |
13 | target/arm/cpu.h | 131 +++++++++++++++++++++++++++++++++---- | 12 | linux-user/elfload.c | 9 +++++---- |
14 | target/arm/translate.h | 7 ++ | 13 | 1 file changed, 5 insertions(+), 4 deletions(-) |
15 | linux-user/elfload.c | 46 ++++++++----- | ||
16 | target/arm/cpu.c | 27 +++++--- | ||
17 | target/arm/cpu64.c | 57 +++++++++------- | ||
18 | target/arm/translate-a64.c | 101 ++++++++++++++-------------- | ||
19 | target/arm/translate.c | 36 +++++----- | ||
20 | 7 files changed, 273 insertions(+), 132 deletions(-) | ||
21 | 14 | ||
22 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/target/arm/cpu.h | ||
25 | +++ b/target/arm/cpu.h | ||
26 | @@ -XXX,XX +XXX,XX @@ typedef enum ARMPSCIState { | ||
27 | PSCI_ON_PENDING = 2 | ||
28 | } ARMPSCIState; | ||
29 | |||
30 | +typedef struct ARMISARegisters ARMISARegisters; | ||
31 | + | ||
32 | /** | ||
33 | * ARMCPU: | ||
34 | * @env: #CPUARMState | ||
35 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | ||
36 | ARM_FEATURE_LPAE, /* has Large Physical Address Extension */ | ||
37 | ARM_FEATURE_V8, | ||
38 | ARM_FEATURE_AARCH64, /* supports 64 bit mode */ | ||
39 | - ARM_FEATURE_V8_AES, /* implements AES part of v8 Crypto Extensions */ | ||
40 | ARM_FEATURE_CBAR, /* has cp15 CBAR */ | ||
41 | ARM_FEATURE_CRC, /* ARMv8 CRC instructions */ | ||
42 | ARM_FEATURE_CBAR_RO, /* has cp15 CBAR and it is read-only */ | ||
43 | ARM_FEATURE_EL2, /* has EL2 Virtualization support */ | ||
44 | ARM_FEATURE_EL3, /* has EL3 Secure monitor support */ | ||
45 | - ARM_FEATURE_V8_SHA1, /* implements SHA1 part of v8 Crypto Extensions */ | ||
46 | - ARM_FEATURE_V8_SHA256, /* implements SHA256 part of v8 Crypto Extensions */ | ||
47 | - ARM_FEATURE_V8_PMULL, /* implements PMULL part of v8 Crypto Extensions */ | ||
48 | ARM_FEATURE_THUMB_DSP, /* DSP insns supported in the Thumb encodings */ | ||
49 | ARM_FEATURE_PMU, /* has PMU support */ | ||
50 | ARM_FEATURE_VBAR, /* has cp15 VBAR */ | ||
51 | ARM_FEATURE_M_SECURITY, /* M profile Security Extension */ | ||
52 | ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ | ||
53 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | ||
54 | - ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | ||
55 | - ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | ||
56 | - ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ | ||
57 | - ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */ | ||
58 | - ARM_FEATURE_V8_ATOMICS, /* ARMv8.1-Atomics feature */ | ||
59 | - ARM_FEATURE_V8_RDM, /* implements v8.1 simd round multiply */ | ||
60 | - ARM_FEATURE_V8_DOTPROD, /* implements v8.2 simd dot product */ | ||
61 | ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */ | ||
62 | - ARM_FEATURE_V8_FCMA, /* has complex number part of v8.3 extensions. */ | ||
63 | ARM_FEATURE_M_MAIN, /* M profile Main Extension */ | ||
64 | }; | ||
65 | |||
66 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t *aa64_vfp_qreg(CPUARMState *env, unsigned regno) | ||
67 | /* Shared between translate-sve.c and sve_helper.c. */ | ||
68 | extern const uint64_t pred_esz_masks[4]; | ||
69 | |||
70 | +/* | ||
71 | + * 32-bit feature tests via id registers. | ||
72 | + */ | ||
73 | +static inline bool isar_feature_aa32_aes(const ARMISARegisters *id) | ||
74 | +{ | ||
75 | + return FIELD_EX32(id->id_isar5, ID_ISAR5, AES) != 0; | ||
76 | +} | ||
77 | + | ||
78 | +static inline bool isar_feature_aa32_pmull(const ARMISARegisters *id) | ||
79 | +{ | ||
80 | + return FIELD_EX32(id->id_isar5, ID_ISAR5, AES) > 1; | ||
81 | +} | ||
82 | + | ||
83 | +static inline bool isar_feature_aa32_sha1(const ARMISARegisters *id) | ||
84 | +{ | ||
85 | + return FIELD_EX32(id->id_isar5, ID_ISAR5, SHA1) != 0; | ||
86 | +} | ||
87 | + | ||
88 | +static inline bool isar_feature_aa32_sha2(const ARMISARegisters *id) | ||
89 | +{ | ||
90 | + return FIELD_EX32(id->id_isar5, ID_ISAR5, SHA2) != 0; | ||
91 | +} | ||
92 | + | ||
93 | +static inline bool isar_feature_aa32_crc32(const ARMISARegisters *id) | ||
94 | +{ | ||
95 | + return FIELD_EX32(id->id_isar5, ID_ISAR5, CRC32) != 0; | ||
96 | +} | ||
97 | + | ||
98 | +static inline bool isar_feature_aa32_rdm(const ARMISARegisters *id) | ||
99 | +{ | ||
100 | + return FIELD_EX32(id->id_isar5, ID_ISAR5, RDM) != 0; | ||
101 | +} | ||
102 | + | ||
103 | +static inline bool isar_feature_aa32_vcma(const ARMISARegisters *id) | ||
104 | +{ | ||
105 | + return FIELD_EX32(id->id_isar5, ID_ISAR5, VCMA) != 0; | ||
106 | +} | ||
107 | + | ||
108 | +static inline bool isar_feature_aa32_dp(const ARMISARegisters *id) | ||
109 | +{ | ||
110 | + return FIELD_EX32(id->id_isar6, ID_ISAR6, DP) != 0; | ||
111 | +} | ||
112 | + | ||
113 | +/* | ||
114 | + * 64-bit feature tests via id registers. | ||
115 | + */ | ||
116 | +static inline bool isar_feature_aa64_aes(const ARMISARegisters *id) | ||
117 | +{ | ||
118 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, AES) != 0; | ||
119 | +} | ||
120 | + | ||
121 | +static inline bool isar_feature_aa64_pmull(const ARMISARegisters *id) | ||
122 | +{ | ||
123 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, AES) > 1; | ||
124 | +} | ||
125 | + | ||
126 | +static inline bool isar_feature_aa64_sha1(const ARMISARegisters *id) | ||
127 | +{ | ||
128 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA1) != 0; | ||
129 | +} | ||
130 | + | ||
131 | +static inline bool isar_feature_aa64_sha256(const ARMISARegisters *id) | ||
132 | +{ | ||
133 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA2) != 0; | ||
134 | +} | ||
135 | + | ||
136 | +static inline bool isar_feature_aa64_sha512(const ARMISARegisters *id) | ||
137 | +{ | ||
138 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA2) > 1; | ||
139 | +} | ||
140 | + | ||
141 | +static inline bool isar_feature_aa64_crc32(const ARMISARegisters *id) | ||
142 | +{ | ||
143 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, CRC32) != 0; | ||
144 | +} | ||
145 | + | ||
146 | +static inline bool isar_feature_aa64_atomics(const ARMISARegisters *id) | ||
147 | +{ | ||
148 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, ATOMIC) != 0; | ||
149 | +} | ||
150 | + | ||
151 | +static inline bool isar_feature_aa64_rdm(const ARMISARegisters *id) | ||
152 | +{ | ||
153 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, RDM) != 0; | ||
154 | +} | ||
155 | + | ||
156 | +static inline bool isar_feature_aa64_sha3(const ARMISARegisters *id) | ||
157 | +{ | ||
158 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SHA3) != 0; | ||
159 | +} | ||
160 | + | ||
161 | +static inline bool isar_feature_aa64_sm3(const ARMISARegisters *id) | ||
162 | +{ | ||
163 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SM3) != 0; | ||
164 | +} | ||
165 | + | ||
166 | +static inline bool isar_feature_aa64_sm4(const ARMISARegisters *id) | ||
167 | +{ | ||
168 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, SM4) != 0; | ||
169 | +} | ||
170 | + | ||
171 | +static inline bool isar_feature_aa64_dp(const ARMISARegisters *id) | ||
172 | +{ | ||
173 | + return FIELD_EX64(id->id_aa64isar0, ID_AA64ISAR0, DP) != 0; | ||
174 | +} | ||
175 | + | ||
176 | +static inline bool isar_feature_aa64_fcma(const ARMISARegisters *id) | ||
177 | +{ | ||
178 | + return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, FCMA) != 0; | ||
179 | +} | ||
180 | + | ||
181 | +/* | ||
182 | + * Forward to the above feature tests given an ARMCPU pointer. | ||
183 | + */ | ||
184 | +#define cpu_isar_feature(name, cpu) \ | ||
185 | + ({ ARMCPU *cpu_ = (cpu); isar_feature_##name(&cpu_->isar); }) | ||
186 | + | ||
187 | #endif | ||
188 | diff --git a/target/arm/translate.h b/target/arm/translate.h | ||
189 | index XXXXXXX..XXXXXXX 100644 | ||
190 | --- a/target/arm/translate.h | ||
191 | +++ b/target/arm/translate.h | ||
192 | @@ -XXX,XX +XXX,XX @@ | ||
193 | /* internal defines */ | ||
194 | typedef struct DisasContext { | ||
195 | DisasContextBase base; | ||
196 | + const ARMISARegisters *isar; | ||
197 | |||
198 | target_ulong pc; | ||
199 | target_ulong page_start; | ||
200 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i32 get_ahp_flag(void) | ||
201 | return ret; | ||
202 | } | ||
203 | |||
204 | +/* | ||
205 | + * Forward to the isar_feature_* tests given a DisasContext pointer. | ||
206 | + */ | ||
207 | +#define dc_isar_feature(name, ctx) \ | ||
208 | + ({ DisasContext *ctx_ = (ctx); isar_feature_##name(ctx_->isar); }) | ||
209 | + | ||
210 | #endif /* TARGET_ARM_TRANSLATE_H */ | ||
211 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
212 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
213 | --- a/linux-user/elfload.c | 17 | --- a/linux-user/elfload.c |
214 | +++ b/linux-user/elfload.c | 18 | +++ b/linux-user/elfload.c |
215 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | 19 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
216 | /* probe for the extra features */ | 20 | loaddr = -1, hiaddr = 0; |
217 | #define GET_FEATURE(feat, hwcap) \ | 21 | info->alignment = 0; |
218 | do { if (arm_feature(&cpu->env, feat)) { hwcaps |= hwcap; } } while (0) | 22 | for (i = 0; i < ehdr->e_phnum; ++i) { |
219 | + | 23 | - if (phdr[i].p_type == PT_LOAD) { |
220 | +#define GET_FEATURE_ID(feat, hwcap) \ | 24 | - abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset; |
221 | + do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0) | 25 | + struct elf_phdr *eppnt = phdr + i; |
222 | + | 26 | + if (eppnt->p_type == PT_LOAD) { |
223 | /* EDSP is in v5TE and above, but all our v5 CPUs are v5TE */ | 27 | + abi_ulong a = eppnt->p_vaddr - eppnt->p_offset; |
224 | GET_FEATURE(ARM_FEATURE_V5, ARM_HWCAP_ARM_EDSP); | 28 | if (a < loaddr) { |
225 | GET_FEATURE(ARM_FEATURE_VFP, ARM_HWCAP_ARM_VFP); | 29 | loaddr = a; |
226 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap2(void) | ||
227 | ARMCPU *cpu = ARM_CPU(thread_cpu); | ||
228 | uint32_t hwcaps = 0; | ||
229 | |||
230 | - GET_FEATURE(ARM_FEATURE_V8_AES, ARM_HWCAP2_ARM_AES); | ||
231 | - GET_FEATURE(ARM_FEATURE_V8_PMULL, ARM_HWCAP2_ARM_PMULL); | ||
232 | - GET_FEATURE(ARM_FEATURE_V8_SHA1, ARM_HWCAP2_ARM_SHA1); | ||
233 | - GET_FEATURE(ARM_FEATURE_V8_SHA256, ARM_HWCAP2_ARM_SHA2); | ||
234 | - GET_FEATURE(ARM_FEATURE_CRC, ARM_HWCAP2_ARM_CRC32); | ||
235 | + GET_FEATURE_ID(aa32_aes, ARM_HWCAP2_ARM_AES); | ||
236 | + GET_FEATURE_ID(aa32_pmull, ARM_HWCAP2_ARM_PMULL); | ||
237 | + GET_FEATURE_ID(aa32_sha1, ARM_HWCAP2_ARM_SHA1); | ||
238 | + GET_FEATURE_ID(aa32_sha2, ARM_HWCAP2_ARM_SHA2); | ||
239 | + GET_FEATURE_ID(aa32_crc32, ARM_HWCAP2_ARM_CRC32); | ||
240 | return hwcaps; | ||
241 | } | ||
242 | |||
243 | #undef GET_FEATURE | ||
244 | +#undef GET_FEATURE_ID | ||
245 | |||
246 | #else | ||
247 | /* 64 bit ARM definitions */ | ||
248 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | ||
249 | /* probe for the extra features */ | ||
250 | #define GET_FEATURE(feat, hwcap) \ | ||
251 | do { if (arm_feature(&cpu->env, feat)) { hwcaps |= hwcap; } } while (0) | ||
252 | - GET_FEATURE(ARM_FEATURE_V8_AES, ARM_HWCAP_A64_AES); | ||
253 | - GET_FEATURE(ARM_FEATURE_V8_PMULL, ARM_HWCAP_A64_PMULL); | ||
254 | - GET_FEATURE(ARM_FEATURE_V8_SHA1, ARM_HWCAP_A64_SHA1); | ||
255 | - GET_FEATURE(ARM_FEATURE_V8_SHA256, ARM_HWCAP_A64_SHA2); | ||
256 | - GET_FEATURE(ARM_FEATURE_CRC, ARM_HWCAP_A64_CRC32); | ||
257 | - GET_FEATURE(ARM_FEATURE_V8_SHA3, ARM_HWCAP_A64_SHA3); | ||
258 | - GET_FEATURE(ARM_FEATURE_V8_SM3, ARM_HWCAP_A64_SM3); | ||
259 | - GET_FEATURE(ARM_FEATURE_V8_SM4, ARM_HWCAP_A64_SM4); | ||
260 | - GET_FEATURE(ARM_FEATURE_V8_SHA512, ARM_HWCAP_A64_SHA512); | ||
261 | +#define GET_FEATURE_ID(feat, hwcap) \ | ||
262 | + do { if (cpu_isar_feature(feat, cpu)) { hwcaps |= hwcap; } } while (0) | ||
263 | + | ||
264 | + GET_FEATURE_ID(aa64_aes, ARM_HWCAP_A64_AES); | ||
265 | + GET_FEATURE_ID(aa64_pmull, ARM_HWCAP_A64_PMULL); | ||
266 | + GET_FEATURE_ID(aa64_sha1, ARM_HWCAP_A64_SHA1); | ||
267 | + GET_FEATURE_ID(aa64_sha256, ARM_HWCAP_A64_SHA2); | ||
268 | + GET_FEATURE_ID(aa64_sha512, ARM_HWCAP_A64_SHA512); | ||
269 | + GET_FEATURE_ID(aa64_crc32, ARM_HWCAP_A64_CRC32); | ||
270 | + GET_FEATURE_ID(aa64_sha3, ARM_HWCAP_A64_SHA3); | ||
271 | + GET_FEATURE_ID(aa64_sm3, ARM_HWCAP_A64_SM3); | ||
272 | + GET_FEATURE_ID(aa64_sm4, ARM_HWCAP_A64_SM4); | ||
273 | GET_FEATURE(ARM_FEATURE_V8_FP16, | ||
274 | ARM_HWCAP_A64_FPHP | ARM_HWCAP_A64_ASIMDHP); | ||
275 | - GET_FEATURE(ARM_FEATURE_V8_ATOMICS, ARM_HWCAP_A64_ATOMICS); | ||
276 | - GET_FEATURE(ARM_FEATURE_V8_RDM, ARM_HWCAP_A64_ASIMDRDM); | ||
277 | - GET_FEATURE(ARM_FEATURE_V8_DOTPROD, ARM_HWCAP_A64_ASIMDDP); | ||
278 | - GET_FEATURE(ARM_FEATURE_V8_FCMA, ARM_HWCAP_A64_FCMA); | ||
279 | + GET_FEATURE_ID(aa64_atomics, ARM_HWCAP_A64_ATOMICS); | ||
280 | + GET_FEATURE_ID(aa64_rdm, ARM_HWCAP_A64_ASIMDRDM); | ||
281 | + GET_FEATURE_ID(aa64_dp, ARM_HWCAP_A64_ASIMDDP); | ||
282 | + GET_FEATURE_ID(aa64_fcma, ARM_HWCAP_A64_FCMA); | ||
283 | GET_FEATURE(ARM_FEATURE_SVE, ARM_HWCAP_A64_SVE); | ||
284 | + | ||
285 | #undef GET_FEATURE | ||
286 | +#undef GET_FEATURE_ID | ||
287 | |||
288 | return hwcaps; | ||
289 | } | ||
290 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
291 | index XXXXXXX..XXXXXXX 100644 | ||
292 | --- a/target/arm/cpu.c | ||
293 | +++ b/target/arm/cpu.c | ||
294 | @@ -XXX,XX +XXX,XX @@ static void arm_max_initfn(Object *obj) | ||
295 | cortex_a15_initfn(obj); | ||
296 | #ifdef CONFIG_USER_ONLY | ||
297 | /* We don't set these in system emulation mode for the moment, | ||
298 | - * since we don't correctly set the ID registers to advertise them, | ||
299 | + * since we don't correctly set (all of) the ID registers to | ||
300 | + * advertise them. | ||
301 | */ | ||
302 | set_feature(&cpu->env, ARM_FEATURE_V8); | ||
303 | - set_feature(&cpu->env, ARM_FEATURE_V8_AES); | ||
304 | - set_feature(&cpu->env, ARM_FEATURE_V8_SHA1); | ||
305 | - set_feature(&cpu->env, ARM_FEATURE_V8_SHA256); | ||
306 | - set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); | ||
307 | - set_feature(&cpu->env, ARM_FEATURE_CRC); | ||
308 | - set_feature(&cpu->env, ARM_FEATURE_V8_RDM); | ||
309 | - set_feature(&cpu->env, ARM_FEATURE_V8_DOTPROD); | ||
310 | - set_feature(&cpu->env, ARM_FEATURE_V8_FCMA); | ||
311 | + { | ||
312 | + uint32_t t; | ||
313 | + | ||
314 | + t = cpu->isar.id_isar5; | ||
315 | + t = FIELD_DP32(t, ID_ISAR5, AES, 2); | ||
316 | + t = FIELD_DP32(t, ID_ISAR5, SHA1, 1); | ||
317 | + t = FIELD_DP32(t, ID_ISAR5, SHA2, 1); | ||
318 | + t = FIELD_DP32(t, ID_ISAR5, CRC32, 1); | ||
319 | + t = FIELD_DP32(t, ID_ISAR5, RDM, 1); | ||
320 | + t = FIELD_DP32(t, ID_ISAR5, VCMA, 1); | ||
321 | + cpu->isar.id_isar5 = t; | ||
322 | + | ||
323 | + t = cpu->isar.id_isar6; | ||
324 | + t = FIELD_DP32(t, ID_ISAR6, DP, 1); | ||
325 | + cpu->isar.id_isar6 = t; | ||
326 | + } | ||
327 | #endif | ||
328 | } | ||
329 | } | ||
330 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | ||
331 | index XXXXXXX..XXXXXXX 100644 | ||
332 | --- a/target/arm/cpu64.c | ||
333 | +++ b/target/arm/cpu64.c | ||
334 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a57_initfn(Object *obj) | ||
335 | set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); | ||
336 | set_feature(&cpu->env, ARM_FEATURE_AARCH64); | ||
337 | set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); | ||
338 | - set_feature(&cpu->env, ARM_FEATURE_V8_AES); | ||
339 | - set_feature(&cpu->env, ARM_FEATURE_V8_SHA1); | ||
340 | - set_feature(&cpu->env, ARM_FEATURE_V8_SHA256); | ||
341 | - set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); | ||
342 | - set_feature(&cpu->env, ARM_FEATURE_CRC); | ||
343 | set_feature(&cpu->env, ARM_FEATURE_EL2); | ||
344 | set_feature(&cpu->env, ARM_FEATURE_EL3); | ||
345 | set_feature(&cpu->env, ARM_FEATURE_PMU); | ||
346 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a53_initfn(Object *obj) | ||
347 | set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); | ||
348 | set_feature(&cpu->env, ARM_FEATURE_AARCH64); | ||
349 | set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); | ||
350 | - set_feature(&cpu->env, ARM_FEATURE_V8_AES); | ||
351 | - set_feature(&cpu->env, ARM_FEATURE_V8_SHA1); | ||
352 | - set_feature(&cpu->env, ARM_FEATURE_V8_SHA256); | ||
353 | - set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); | ||
354 | - set_feature(&cpu->env, ARM_FEATURE_CRC); | ||
355 | set_feature(&cpu->env, ARM_FEATURE_EL2); | ||
356 | set_feature(&cpu->env, ARM_FEATURE_EL3); | ||
357 | set_feature(&cpu->env, ARM_FEATURE_PMU); | ||
358 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a72_initfn(Object *obj) | ||
359 | set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); | ||
360 | set_feature(&cpu->env, ARM_FEATURE_AARCH64); | ||
361 | set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); | ||
362 | - set_feature(&cpu->env, ARM_FEATURE_V8_AES); | ||
363 | - set_feature(&cpu->env, ARM_FEATURE_V8_SHA1); | ||
364 | - set_feature(&cpu->env, ARM_FEATURE_V8_SHA256); | ||
365 | - set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); | ||
366 | - set_feature(&cpu->env, ARM_FEATURE_CRC); | ||
367 | set_feature(&cpu->env, ARM_FEATURE_EL2); | ||
368 | set_feature(&cpu->env, ARM_FEATURE_EL3); | ||
369 | set_feature(&cpu->env, ARM_FEATURE_PMU); | ||
370 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) | ||
371 | if (kvm_enabled()) { | ||
372 | kvm_arm_set_cpu_features_from_host(cpu); | ||
373 | } else { | ||
374 | + uint64_t t; | ||
375 | + uint32_t u; | ||
376 | aarch64_a57_initfn(obj); | ||
377 | + | ||
378 | + t = cpu->isar.id_aa64isar0; | ||
379 | + t = FIELD_DP64(t, ID_AA64ISAR0, AES, 2); /* AES + PMULL */ | ||
380 | + t = FIELD_DP64(t, ID_AA64ISAR0, SHA1, 1); | ||
381 | + t = FIELD_DP64(t, ID_AA64ISAR0, SHA2, 2); /* SHA512 */ | ||
382 | + t = FIELD_DP64(t, ID_AA64ISAR0, CRC32, 1); | ||
383 | + t = FIELD_DP64(t, ID_AA64ISAR0, ATOMIC, 2); | ||
384 | + t = FIELD_DP64(t, ID_AA64ISAR0, RDM, 1); | ||
385 | + t = FIELD_DP64(t, ID_AA64ISAR0, SHA3, 1); | ||
386 | + t = FIELD_DP64(t, ID_AA64ISAR0, SM3, 1); | ||
387 | + t = FIELD_DP64(t, ID_AA64ISAR0, SM4, 1); | ||
388 | + t = FIELD_DP64(t, ID_AA64ISAR0, DP, 1); | ||
389 | + cpu->isar.id_aa64isar0 = t; | ||
390 | + | ||
391 | + t = cpu->isar.id_aa64isar1; | ||
392 | + t = FIELD_DP64(t, ID_AA64ISAR1, FCMA, 1); | ||
393 | + cpu->isar.id_aa64isar1 = t; | ||
394 | + | ||
395 | + /* Replicate the same data to the 32-bit id registers. */ | ||
396 | + u = cpu->isar.id_isar5; | ||
397 | + u = FIELD_DP32(u, ID_ISAR5, AES, 2); /* AES + PMULL */ | ||
398 | + u = FIELD_DP32(u, ID_ISAR5, SHA1, 1); | ||
399 | + u = FIELD_DP32(u, ID_ISAR5, SHA2, 1); | ||
400 | + u = FIELD_DP32(u, ID_ISAR5, CRC32, 1); | ||
401 | + u = FIELD_DP32(u, ID_ISAR5, RDM, 1); | ||
402 | + u = FIELD_DP32(u, ID_ISAR5, VCMA, 1); | ||
403 | + cpu->isar.id_isar5 = u; | ||
404 | + | ||
405 | + u = cpu->isar.id_isar6; | ||
406 | + u = FIELD_DP32(u, ID_ISAR6, DP, 1); | ||
407 | + cpu->isar.id_isar6 = u; | ||
408 | + | ||
409 | #ifdef CONFIG_USER_ONLY | ||
410 | /* We don't set these in system emulation mode for the moment, | ||
411 | * since we don't correctly set the ID registers to advertise them, | ||
412 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) | ||
413 | * whereas the architecture requires them to be present in both if | ||
414 | * present in either. | ||
415 | */ | ||
416 | - set_feature(&cpu->env, ARM_FEATURE_V8_SHA512); | ||
417 | - set_feature(&cpu->env, ARM_FEATURE_V8_SHA3); | ||
418 | - set_feature(&cpu->env, ARM_FEATURE_V8_SM3); | ||
419 | - set_feature(&cpu->env, ARM_FEATURE_V8_SM4); | ||
420 | - set_feature(&cpu->env, ARM_FEATURE_V8_ATOMICS); | ||
421 | - set_feature(&cpu->env, ARM_FEATURE_V8_RDM); | ||
422 | - set_feature(&cpu->env, ARM_FEATURE_V8_DOTPROD); | ||
423 | set_feature(&cpu->env, ARM_FEATURE_V8_FP16); | ||
424 | - set_feature(&cpu->env, ARM_FEATURE_V8_FCMA); | ||
425 | set_feature(&cpu->env, ARM_FEATURE_SVE); | ||
426 | /* For usermode -cpu max we can use a larger and more efficient DCZ | ||
427 | * blocksize since we don't have to follow what the hardware does. | ||
428 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
429 | index XXXXXXX..XXXXXXX 100644 | ||
430 | --- a/target/arm/translate-a64.c | ||
431 | +++ b/target/arm/translate-a64.c | ||
432 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_excl(DisasContext *s, uint32_t insn) | ||
433 | } | ||
434 | if (rt2 == 31 | ||
435 | && ((rt | rs) & 1) == 0 | ||
436 | - && arm_dc_feature(s, ARM_FEATURE_V8_ATOMICS)) { | ||
437 | + && dc_isar_feature(aa64_atomics, s)) { | ||
438 | /* CASP / CASPL */ | ||
439 | gen_compare_and_swap_pair(s, rs, rt, rn, size | 2); | ||
440 | return; | ||
441 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_excl(DisasContext *s, uint32_t insn) | ||
442 | } | ||
443 | if (rt2 == 31 | ||
444 | && ((rt | rs) & 1) == 0 | ||
445 | - && arm_dc_feature(s, ARM_FEATURE_V8_ATOMICS)) { | ||
446 | + && dc_isar_feature(aa64_atomics, s)) { | ||
447 | /* CASPA / CASPAL */ | ||
448 | gen_compare_and_swap_pair(s, rs, rt, rn, size | 2); | ||
449 | return; | ||
450 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_excl(DisasContext *s, uint32_t insn) | ||
451 | case 0xb: /* CASL */ | ||
452 | case 0xe: /* CASA */ | ||
453 | case 0xf: /* CASAL */ | ||
454 | - if (rt2 == 31 && arm_dc_feature(s, ARM_FEATURE_V8_ATOMICS)) { | ||
455 | + if (rt2 == 31 && dc_isar_feature(aa64_atomics, s)) { | ||
456 | gen_compare_and_swap(s, rs, rt, rn, size); | ||
457 | return; | ||
458 | } | ||
459 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn, | ||
460 | int rs = extract32(insn, 16, 5); | ||
461 | int rn = extract32(insn, 5, 5); | ||
462 | int o3_opc = extract32(insn, 12, 4); | ||
463 | - int feature = ARM_FEATURE_V8_ATOMICS; | ||
464 | TCGv_i64 tcg_rn, tcg_rs; | ||
465 | AtomicThreeOpFn *fn; | ||
466 | |||
467 | - if (is_vector) { | ||
468 | + if (is_vector || !dc_isar_feature(aa64_atomics, s)) { | ||
469 | unallocated_encoding(s); | ||
470 | return; | ||
471 | } | ||
472 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn, | ||
473 | unallocated_encoding(s); | ||
474 | return; | ||
475 | } | ||
476 | - if (!arm_dc_feature(s, feature)) { | ||
477 | - unallocated_encoding(s); | ||
478 | - return; | ||
479 | - } | ||
480 | |||
481 | if (rn == 31) { | ||
482 | gen_check_sp_alignment(s); | ||
483 | @@ -XXX,XX +XXX,XX @@ static void handle_crc32(DisasContext *s, | ||
484 | TCGv_i64 tcg_acc, tcg_val; | ||
485 | TCGv_i32 tcg_bytes; | ||
486 | |||
487 | - if (!arm_dc_feature(s, ARM_FEATURE_CRC) | ||
488 | + if (!dc_isar_feature(aa64_crc32, s) | ||
489 | || (sf == 1 && sz != 3) | ||
490 | || (sf == 0 && sz == 3)) { | ||
491 | unallocated_encoding(s); | ||
492 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_three_reg_same_extra(DisasContext *s, | ||
493 | bool u = extract32(insn, 29, 1); | ||
494 | TCGv_i32 ele1, ele2, ele3; | ||
495 | TCGv_i64 res; | ||
496 | - int feature; | ||
497 | + bool feature; | ||
498 | |||
499 | switch (u * 16 + opcode) { | ||
500 | case 0x10: /* SQRDMLAH (vector) */ | ||
501 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_three_reg_same_extra(DisasContext *s, | ||
502 | unallocated_encoding(s); | ||
503 | return; | ||
504 | } | ||
505 | - feature = ARM_FEATURE_V8_RDM; | ||
506 | + feature = dc_isar_feature(aa64_rdm, s); | ||
507 | break; | ||
508 | default: | ||
509 | unallocated_encoding(s); | ||
510 | return; | ||
511 | } | ||
512 | - if (!arm_dc_feature(s, feature)) { | ||
513 | + if (!feature) { | ||
514 | unallocated_encoding(s); | ||
515 | return; | ||
516 | } | ||
517 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_diff(DisasContext *s, uint32_t insn) | ||
518 | return; | ||
519 | } | ||
520 | if (size == 3) { | ||
521 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_PMULL)) { | ||
522 | + if (!dc_isar_feature(aa64_pmull, s)) { | ||
523 | unallocated_encoding(s); | ||
524 | return; | ||
525 | } | 30 | } |
526 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | 31 | - a = phdr[i].p_vaddr + phdr[i].p_memsz; |
527 | int size = extract32(insn, 22, 2); | 32 | + a = eppnt->p_vaddr + eppnt->p_memsz; |
528 | bool u = extract32(insn, 29, 1); | 33 | if (a > hiaddr) { |
529 | bool is_q = extract32(insn, 30, 1); | 34 | hiaddr = a; |
530 | - int feature, rot; | 35 | } |
531 | + bool feature; | 36 | ++info->nsegs; |
532 | + int rot; | 37 | - info->alignment |= phdr[i].p_align; |
533 | 38 | + info->alignment |= eppnt->p_align; | |
534 | switch (u * 16 + opcode) { | ||
535 | case 0x10: /* SQRDMLAH (vector) */ | ||
536 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | ||
537 | unallocated_encoding(s); | ||
538 | return; | ||
539 | } | ||
540 | - feature = ARM_FEATURE_V8_RDM; | ||
541 | + feature = dc_isar_feature(aa64_rdm, s); | ||
542 | break; | ||
543 | case 0x02: /* SDOT (vector) */ | ||
544 | case 0x12: /* UDOT (vector) */ | ||
545 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | ||
546 | unallocated_encoding(s); | ||
547 | return; | ||
548 | } | ||
549 | - feature = ARM_FEATURE_V8_DOTPROD; | ||
550 | + feature = dc_isar_feature(aa64_dp, s); | ||
551 | break; | ||
552 | case 0x18: /* FCMLA, #0 */ | ||
553 | case 0x19: /* FCMLA, #90 */ | ||
554 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_same_extra(DisasContext *s, uint32_t insn) | ||
555 | unallocated_encoding(s); | ||
556 | return; | ||
557 | } | ||
558 | - feature = ARM_FEATURE_V8_FCMA; | ||
559 | + feature = dc_isar_feature(aa64_fcma, s); | ||
560 | break; | ||
561 | default: | ||
562 | unallocated_encoding(s); | ||
563 | return; | ||
564 | } | ||
565 | - if (!arm_dc_feature(s, feature)) { | ||
566 | + if (!feature) { | ||
567 | unallocated_encoding(s); | ||
568 | return; | ||
569 | } | ||
570 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
571 | break; | ||
572 | case 0x1d: /* SQRDMLAH */ | ||
573 | case 0x1f: /* SQRDMLSH */ | ||
574 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_RDM)) { | ||
575 | + if (!dc_isar_feature(aa64_rdm, s)) { | ||
576 | unallocated_encoding(s); | ||
577 | return; | ||
578 | } | ||
579 | break; | ||
580 | case 0x0e: /* SDOT */ | ||
581 | case 0x1e: /* UDOT */ | ||
582 | - if (size != MO_32 || !arm_dc_feature(s, ARM_FEATURE_V8_DOTPROD)) { | ||
583 | + if (size != MO_32 || !dc_isar_feature(aa64_dp, s)) { | ||
584 | unallocated_encoding(s); | ||
585 | return; | ||
586 | } | ||
587 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
588 | case 0x13: /* FCMLA #90 */ | ||
589 | case 0x15: /* FCMLA #180 */ | ||
590 | case 0x17: /* FCMLA #270 */ | ||
591 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)) { | ||
592 | + if (!dc_isar_feature(aa64_fcma, s)) { | ||
593 | unallocated_encoding(s); | ||
594 | return; | ||
595 | } | ||
596 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn) | ||
597 | TCGv_i32 tcg_decrypt; | ||
598 | CryptoThreeOpIntFn *genfn; | ||
599 | |||
600 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_AES) | ||
601 | - || size != 0) { | ||
602 | + if (!dc_isar_feature(aa64_aes, s) || size != 0) { | ||
603 | unallocated_encoding(s); | ||
604 | return; | ||
605 | } | ||
606 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn) | ||
607 | int rd = extract32(insn, 0, 5); | ||
608 | CryptoThreeOpFn *genfn; | ||
609 | TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | ||
610 | - int feature = ARM_FEATURE_V8_SHA256; | ||
611 | + bool feature; | ||
612 | |||
613 | if (size != 0) { | ||
614 | unallocated_encoding(s); | ||
615 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn) | ||
616 | case 2: /* SHA1M */ | ||
617 | case 3: /* SHA1SU0 */ | ||
618 | genfn = NULL; | ||
619 | - feature = ARM_FEATURE_V8_SHA1; | ||
620 | + feature = dc_isar_feature(aa64_sha1, s); | ||
621 | break; | ||
622 | case 4: /* SHA256H */ | ||
623 | genfn = gen_helper_crypto_sha256h; | ||
624 | + feature = dc_isar_feature(aa64_sha256, s); | ||
625 | break; | ||
626 | case 5: /* SHA256H2 */ | ||
627 | genfn = gen_helper_crypto_sha256h2; | ||
628 | + feature = dc_isar_feature(aa64_sha256, s); | ||
629 | break; | ||
630 | case 6: /* SHA256SU1 */ | ||
631 | genfn = gen_helper_crypto_sha256su1; | ||
632 | + feature = dc_isar_feature(aa64_sha256, s); | ||
633 | break; | ||
634 | default: | ||
635 | unallocated_encoding(s); | ||
636 | return; | ||
637 | } | ||
638 | |||
639 | - if (!arm_dc_feature(s, feature)) { | ||
640 | + if (!feature) { | ||
641 | unallocated_encoding(s); | ||
642 | return; | ||
643 | } | ||
644 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn) | ||
645 | int rn = extract32(insn, 5, 5); | ||
646 | int rd = extract32(insn, 0, 5); | ||
647 | CryptoTwoOpFn *genfn; | ||
648 | - int feature; | ||
649 | + bool feature; | ||
650 | TCGv_ptr tcg_rd_ptr, tcg_rn_ptr; | ||
651 | |||
652 | if (size != 0) { | ||
653 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn) | ||
654 | |||
655 | switch (opcode) { | ||
656 | case 0: /* SHA1H */ | ||
657 | - feature = ARM_FEATURE_V8_SHA1; | ||
658 | + feature = dc_isar_feature(aa64_sha1, s); | ||
659 | genfn = gen_helper_crypto_sha1h; | ||
660 | break; | ||
661 | case 1: /* SHA1SU1 */ | ||
662 | - feature = ARM_FEATURE_V8_SHA1; | ||
663 | + feature = dc_isar_feature(aa64_sha1, s); | ||
664 | genfn = gen_helper_crypto_sha1su1; | ||
665 | break; | ||
666 | case 2: /* SHA256SU0 */ | ||
667 | - feature = ARM_FEATURE_V8_SHA256; | ||
668 | + feature = dc_isar_feature(aa64_sha256, s); | ||
669 | genfn = gen_helper_crypto_sha256su0; | ||
670 | break; | ||
671 | default: | ||
672 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn) | ||
673 | return; | ||
674 | } | ||
675 | |||
676 | - if (!arm_dc_feature(s, feature)) { | ||
677 | + if (!feature) { | ||
678 | unallocated_encoding(s); | ||
679 | return; | ||
680 | } | ||
681 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
682 | int rm = extract32(insn, 16, 5); | ||
683 | int rn = extract32(insn, 5, 5); | ||
684 | int rd = extract32(insn, 0, 5); | ||
685 | - int feature; | ||
686 | + bool feature; | ||
687 | CryptoThreeOpFn *genfn; | ||
688 | |||
689 | if (o == 0) { | ||
690 | switch (opcode) { | ||
691 | case 0: /* SHA512H */ | ||
692 | - feature = ARM_FEATURE_V8_SHA512; | ||
693 | + feature = dc_isar_feature(aa64_sha512, s); | ||
694 | genfn = gen_helper_crypto_sha512h; | ||
695 | break; | ||
696 | case 1: /* SHA512H2 */ | ||
697 | - feature = ARM_FEATURE_V8_SHA512; | ||
698 | + feature = dc_isar_feature(aa64_sha512, s); | ||
699 | genfn = gen_helper_crypto_sha512h2; | ||
700 | break; | ||
701 | case 2: /* SHA512SU1 */ | ||
702 | - feature = ARM_FEATURE_V8_SHA512; | ||
703 | + feature = dc_isar_feature(aa64_sha512, s); | ||
704 | genfn = gen_helper_crypto_sha512su1; | ||
705 | break; | ||
706 | case 3: /* RAX1 */ | ||
707 | - feature = ARM_FEATURE_V8_SHA3; | ||
708 | + feature = dc_isar_feature(aa64_sha3, s); | ||
709 | genfn = NULL; | ||
710 | break; | ||
711 | } | ||
712 | } else { | ||
713 | switch (opcode) { | ||
714 | case 0: /* SM3PARTW1 */ | ||
715 | - feature = ARM_FEATURE_V8_SM3; | ||
716 | + feature = dc_isar_feature(aa64_sm3, s); | ||
717 | genfn = gen_helper_crypto_sm3partw1; | ||
718 | break; | ||
719 | case 1: /* SM3PARTW2 */ | ||
720 | - feature = ARM_FEATURE_V8_SM3; | ||
721 | + feature = dc_isar_feature(aa64_sm3, s); | ||
722 | genfn = gen_helper_crypto_sm3partw2; | ||
723 | break; | ||
724 | case 2: /* SM4EKEY */ | ||
725 | - feature = ARM_FEATURE_V8_SM4; | ||
726 | + feature = dc_isar_feature(aa64_sm4, s); | ||
727 | genfn = gen_helper_crypto_sm4ekey; | ||
728 | break; | ||
729 | default: | ||
730 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
731 | } | 39 | } |
732 | } | 40 | } |
733 | 41 | ||
734 | - if (!arm_dc_feature(s, feature)) { | ||
735 | + if (!feature) { | ||
736 | unallocated_encoding(s); | ||
737 | return; | ||
738 | } | ||
739 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | ||
740 | int rn = extract32(insn, 5, 5); | ||
741 | int rd = extract32(insn, 0, 5); | ||
742 | TCGv_ptr tcg_rd_ptr, tcg_rn_ptr; | ||
743 | - int feature; | ||
744 | + bool feature; | ||
745 | CryptoTwoOpFn *genfn; | ||
746 | |||
747 | switch (opcode) { | ||
748 | case 0: /* SHA512SU0 */ | ||
749 | - feature = ARM_FEATURE_V8_SHA512; | ||
750 | + feature = dc_isar_feature(aa64_sha512, s); | ||
751 | genfn = gen_helper_crypto_sha512su0; | ||
752 | break; | ||
753 | case 1: /* SM4E */ | ||
754 | - feature = ARM_FEATURE_V8_SM4; | ||
755 | + feature = dc_isar_feature(aa64_sm4, s); | ||
756 | genfn = gen_helper_crypto_sm4e; | ||
757 | break; | ||
758 | default: | ||
759 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | ||
760 | return; | ||
761 | } | ||
762 | |||
763 | - if (!arm_dc_feature(s, feature)) { | ||
764 | + if (!feature) { | ||
765 | unallocated_encoding(s); | ||
766 | return; | ||
767 | } | ||
768 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) | ||
769 | int ra = extract32(insn, 10, 5); | ||
770 | int rn = extract32(insn, 5, 5); | ||
771 | int rd = extract32(insn, 0, 5); | ||
772 | - int feature; | ||
773 | + bool feature; | ||
774 | |||
775 | switch (op0) { | ||
776 | case 0: /* EOR3 */ | ||
777 | case 1: /* BCAX */ | ||
778 | - feature = ARM_FEATURE_V8_SHA3; | ||
779 | + feature = dc_isar_feature(aa64_sha3, s); | ||
780 | break; | ||
781 | case 2: /* SM3SS1 */ | ||
782 | - feature = ARM_FEATURE_V8_SM3; | ||
783 | + feature = dc_isar_feature(aa64_sm3, s); | ||
784 | break; | ||
785 | default: | ||
786 | unallocated_encoding(s); | ||
787 | return; | ||
788 | } | ||
789 | |||
790 | - if (!arm_dc_feature(s, feature)) { | ||
791 | + if (!feature) { | ||
792 | unallocated_encoding(s); | ||
793 | return; | ||
794 | } | ||
795 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_xar(DisasContext *s, uint32_t insn) | ||
796 | TCGv_i64 tcg_op1, tcg_op2, tcg_res[2]; | ||
797 | int pass; | ||
798 | |||
799 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA3)) { | ||
800 | + if (!dc_isar_feature(aa64_sha3, s)) { | ||
801 | unallocated_encoding(s); | ||
802 | return; | ||
803 | } | ||
804 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn) | ||
805 | TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | ||
806 | TCGv_i32 tcg_imm2, tcg_opcode; | ||
807 | |||
808 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_SM3)) { | ||
809 | + if (!dc_isar_feature(aa64_sm3, s)) { | ||
810 | unallocated_encoding(s); | ||
811 | return; | ||
812 | } | ||
813 | @@ -XXX,XX +XXX,XX @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, | ||
814 | ARMCPU *arm_cpu = arm_env_get_cpu(env); | ||
815 | int bound; | ||
816 | |||
817 | + dc->isar = &arm_cpu->isar; | ||
818 | dc->pc = dc->base.pc_first; | ||
819 | dc->condjmp = 0; | ||
820 | |||
821 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
822 | index XXXXXXX..XXXXXXX 100644 | ||
823 | --- a/target/arm/translate.c | ||
824 | +++ b/target/arm/translate.c | ||
825 | @@ -XXX,XX +XXX,XX @@ static const uint8_t neon_2rm_sizes[] = { | ||
826 | static int do_v81_helper(DisasContext *s, gen_helper_gvec_3_ptr *fn, | ||
827 | int q, int rd, int rn, int rm) | ||
828 | { | ||
829 | - if (arm_dc_feature(s, ARM_FEATURE_V8_RDM)) { | ||
830 | + if (dc_isar_feature(aa32_rdm, s)) { | ||
831 | int opr_sz = (1 + q) * 8; | ||
832 | tcg_gen_gvec_3_ptr(vfp_reg_offset(1, rd), | ||
833 | vfp_reg_offset(1, rn), | ||
834 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
835 | return 1; | ||
836 | } | ||
837 | if (!u) { /* SHA-1 */ | ||
838 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA1)) { | ||
839 | + if (!dc_isar_feature(aa32_sha1, s)) { | ||
840 | return 1; | ||
841 | } | ||
842 | ptr1 = vfp_reg_ptr(true, rd); | ||
843 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
844 | gen_helper_crypto_sha1_3reg(ptr1, ptr2, ptr3, tmp4); | ||
845 | tcg_temp_free_i32(tmp4); | ||
846 | } else { /* SHA-256 */ | ||
847 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA256) || size == 3) { | ||
848 | + if (!dc_isar_feature(aa32_sha2, s) || size == 3) { | ||
849 | return 1; | ||
850 | } | ||
851 | ptr1 = vfp_reg_ptr(true, rd); | ||
852 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
853 | if (op == 14 && size == 2) { | ||
854 | TCGv_i64 tcg_rn, tcg_rm, tcg_rd; | ||
855 | |||
856 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_PMULL)) { | ||
857 | + if (!dc_isar_feature(aa32_pmull, s)) { | ||
858 | return 1; | ||
859 | } | ||
860 | tcg_rn = tcg_temp_new_i64(); | ||
861 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
862 | { | ||
863 | NeonGenThreeOpEnvFn *fn; | ||
864 | |||
865 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_RDM)) { | ||
866 | + if (!dc_isar_feature(aa32_rdm, s)) { | ||
867 | return 1; | ||
868 | } | ||
869 | if (u && ((rd | rn) & 1)) { | ||
870 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
871 | break; | ||
872 | } | ||
873 | case NEON_2RM_AESE: case NEON_2RM_AESMC: | ||
874 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_AES) | ||
875 | - || ((rm | rd) & 1)) { | ||
876 | + if (!dc_isar_feature(aa32_aes, s) || ((rm | rd) & 1)) { | ||
877 | return 1; | ||
878 | } | ||
879 | ptr1 = vfp_reg_ptr(true, rd); | ||
880 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
881 | tcg_temp_free_i32(tmp3); | ||
882 | break; | ||
883 | case NEON_2RM_SHA1H: | ||
884 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA1) | ||
885 | - || ((rm | rd) & 1)) { | ||
886 | + if (!dc_isar_feature(aa32_sha1, s) || ((rm | rd) & 1)) { | ||
887 | return 1; | ||
888 | } | ||
889 | ptr1 = vfp_reg_ptr(true, rd); | ||
890 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
891 | } | ||
892 | /* bit 6 (q): set -> SHA256SU0, cleared -> SHA1SU1 */ | ||
893 | if (q) { | ||
894 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA256)) { | ||
895 | + if (!dc_isar_feature(aa32_sha2, s)) { | ||
896 | return 1; | ||
897 | } | ||
898 | - } else if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA1)) { | ||
899 | + } else if (!dc_isar_feature(aa32_sha1, s)) { | ||
900 | return 1; | ||
901 | } | ||
902 | ptr1 = vfp_reg_ptr(true, rd); | ||
903 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn) | ||
904 | /* VCMLA -- 1111 110R R.1S .... .... 1000 ...0 .... */ | ||
905 | int size = extract32(insn, 20, 1); | ||
906 | data = extract32(insn, 23, 2); /* rot */ | ||
907 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA) | ||
908 | + if (!dc_isar_feature(aa32_vcma, s) | ||
909 | || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) { | ||
910 | return 1; | ||
911 | } | ||
912 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn) | ||
913 | /* VCADD -- 1111 110R 1.0S .... .... 1000 ...0 .... */ | ||
914 | int size = extract32(insn, 20, 1); | ||
915 | data = extract32(insn, 24, 1); /* rot */ | ||
916 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA) | ||
917 | + if (!dc_isar_feature(aa32_vcma, s) | ||
918 | || (!size && !arm_dc_feature(s, ARM_FEATURE_V8_FP16))) { | ||
919 | return 1; | ||
920 | } | ||
921 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn) | ||
922 | } else if ((insn & 0xfeb00f00) == 0xfc200d00) { | ||
923 | /* V[US]DOT -- 1111 1100 0.10 .... .... 1101 .Q.U .... */ | ||
924 | bool u = extract32(insn, 4, 1); | ||
925 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_DOTPROD)) { | ||
926 | + if (!dc_isar_feature(aa32_dp, s)) { | ||
927 | return 1; | ||
928 | } | ||
929 | fn_gvec = u ? gen_helper_gvec_udot_b : gen_helper_gvec_sdot_b; | ||
930 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_2reg_scalar_ext(DisasContext *s, uint32_t insn) | ||
931 | int size = extract32(insn, 23, 1); | ||
932 | int index; | ||
933 | |||
934 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_FCMA)) { | ||
935 | + if (!dc_isar_feature(aa32_vcma, s)) { | ||
936 | return 1; | ||
937 | } | ||
938 | if (size == 0) { | ||
939 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_2reg_scalar_ext(DisasContext *s, uint32_t insn) | ||
940 | } else if ((insn & 0xffb00f00) == 0xfe200d00) { | ||
941 | /* V[US]DOT -- 1111 1110 0.10 .... .... 1101 .Q.U .... */ | ||
942 | int u = extract32(insn, 4, 1); | ||
943 | - if (!arm_dc_feature(s, ARM_FEATURE_V8_DOTPROD)) { | ||
944 | + if (!dc_isar_feature(aa32_dp, s)) { | ||
945 | return 1; | ||
946 | } | ||
947 | fn_gvec = u ? gen_helper_gvec_udot_idx_b : gen_helper_gvec_sdot_idx_b; | ||
948 | @@ -XXX,XX +XXX,XX @@ static void disas_arm_insn(DisasContext *s, unsigned int insn) | ||
949 | * op1 == 3 is UNPREDICTABLE but handle as UNDEFINED. | ||
950 | * Bits 8, 10 and 11 should be zero. | ||
951 | */ | ||
952 | - if (!arm_dc_feature(s, ARM_FEATURE_CRC) || op1 == 0x3 || | ||
953 | - (c & 0xd) != 0) { | ||
954 | + if (!dc_isar_feature(aa32_crc32, s) || op1 == 0x3 || (c & 0xd) != 0) { | ||
955 | goto illegal_op; | ||
956 | } | ||
957 | |||
958 | @@ -XXX,XX +XXX,XX @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn) | ||
959 | case 0x28: | ||
960 | case 0x29: | ||
961 | case 0x2a: | ||
962 | - if (!arm_dc_feature(s, ARM_FEATURE_CRC)) { | ||
963 | + if (!dc_isar_feature(aa32_crc32, s)) { | ||
964 | goto illegal_op; | ||
965 | } | ||
966 | break; | ||
967 | @@ -XXX,XX +XXX,XX @@ static void arm_tr_init_disas_context(DisasContextBase *dcbase, CPUState *cs) | ||
968 | CPUARMState *env = cs->env_ptr; | ||
969 | ARMCPU *cpu = arm_env_get_cpu(env); | ||
970 | |||
971 | + dc->isar = &cpu->isar; | ||
972 | dc->pc = dc->base.pc_first; | ||
973 | dc->condjmp = 0; | ||
974 | |||
975 | -- | 42 | -- |
976 | 2.19.1 | 43 | 2.20.1 |
977 | 44 | ||
978 | 45 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | For BTI, we need to know if the executable is static or dynamic, | ||
4 | which means looking for PT_INTERP earlier. | ||
5 | |||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | Message-id: 20181011205206.3552-12-richard.henderson@linaro.org | 7 | Message-id: 20201021173749.111103-8-richard.henderson@linaro.org |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 10 | --- |
8 | target/arm/translate.c | 31 +++++++++++++++---------------- | 11 | linux-user/elfload.c | 60 +++++++++++++++++++++++--------------------- |
9 | 1 file changed, 15 insertions(+), 16 deletions(-) | 12 | 1 file changed, 31 insertions(+), 29 deletions(-) |
10 | 13 | ||
11 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 14 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
12 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate.c | 16 | --- a/linux-user/elfload.c |
14 | +++ b/target/arm/translate.c | 17 | +++ b/linux-user/elfload.c |
15 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 18 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
16 | vec_size, vec_size); | 19 | |
20 | mmap_lock(); | ||
21 | |||
22 | - /* Find the maximum size of the image and allocate an appropriate | ||
23 | - amount of memory to handle that. */ | ||
24 | + /* | ||
25 | + * Find the maximum size of the image and allocate an appropriate | ||
26 | + * amount of memory to handle that. Locate the interpreter, if any. | ||
27 | + */ | ||
28 | loaddr = -1, hiaddr = 0; | ||
29 | info->alignment = 0; | ||
30 | for (i = 0; i < ehdr->e_phnum; ++i) { | ||
31 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
17 | } | 32 | } |
18 | return 0; | 33 | ++info->nsegs; |
34 | info->alignment |= eppnt->p_align; | ||
35 | + } else if (eppnt->p_type == PT_INTERP && pinterp_name) { | ||
36 | + g_autofree char *interp_name = NULL; | ||
19 | + | 37 | + |
20 | + case NEON_3R_VMUL: /* VMUL */ | 38 | + if (*pinterp_name) { |
21 | + if (u) { | 39 | + errmsg = "Multiple PT_INTERP entries"; |
22 | + /* Polynomial case allows only P8 and is handled below. */ | 40 | + goto exit_errmsg; |
23 | + if (size != 0) { | 41 | + } |
24 | + return 1; | 42 | + interp_name = g_malloc(eppnt->p_filesz); |
43 | + if (!interp_name) { | ||
44 | + goto exit_perror; | ||
45 | + } | ||
46 | + | ||
47 | + if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { | ||
48 | + memcpy(interp_name, bprm_buf + eppnt->p_offset, | ||
49 | + eppnt->p_filesz); | ||
50 | + } else { | ||
51 | + retval = pread(image_fd, interp_name, eppnt->p_filesz, | ||
52 | + eppnt->p_offset); | ||
53 | + if (retval != eppnt->p_filesz) { | ||
54 | + goto exit_perror; | ||
25 | + } | 55 | + } |
26 | + } else { | ||
27 | + tcg_gen_gvec_mul(size, rd_ofs, rn_ofs, rm_ofs, | ||
28 | + vec_size, vec_size); | ||
29 | + return 0; | ||
30 | + } | 56 | + } |
31 | + break; | 57 | + if (interp_name[eppnt->p_filesz - 1] != 0) { |
58 | + errmsg = "Invalid PT_INTERP entry"; | ||
59 | + goto exit_errmsg; | ||
60 | + } | ||
61 | + *pinterp_name = g_steal_pointer(&interp_name); | ||
32 | } | 62 | } |
33 | if (size == 3) { | 63 | } |
34 | /* 64-bit element instructions. */ | 64 | |
35 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 65 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
36 | return 1; | 66 | if (vaddr_em > info->brk) { |
67 | info->brk = vaddr_em; | ||
37 | } | 68 | } |
38 | break; | 69 | - } else if (eppnt->p_type == PT_INTERP && pinterp_name) { |
39 | - case NEON_3R_VMUL: | 70 | - g_autofree char *interp_name = NULL; |
40 | - if (u && (size != 0)) { | 71 | - |
41 | - /* UNDEF on invalid size for polynomial subcase */ | 72 | - if (*pinterp_name) { |
42 | - return 1; | 73 | - errmsg = "Multiple PT_INTERP entries"; |
74 | - goto exit_errmsg; | ||
43 | - } | 75 | - } |
44 | - break; | 76 | - interp_name = g_malloc(eppnt->p_filesz); |
45 | case NEON_3R_VFM_VQRDMLSH: | 77 | - if (!interp_name) { |
46 | if (!arm_dc_feature(s, ARM_FEATURE_VFP4)) { | 78 | - goto exit_perror; |
47 | return 1; | 79 | - } |
48 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 80 | - |
49 | } | 81 | - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { |
50 | break; | 82 | - memcpy(interp_name, bprm_buf + eppnt->p_offset, |
51 | case NEON_3R_VMUL: | 83 | - eppnt->p_filesz); |
52 | - if (u) { /* polynomial */ | 84 | - } else { |
53 | - gen_helper_neon_mul_p8(tmp, tmp, tmp2); | 85 | - retval = pread(image_fd, interp_name, eppnt->p_filesz, |
54 | - } else { /* Integer */ | 86 | - eppnt->p_offset); |
55 | - switch (size) { | 87 | - if (retval != eppnt->p_filesz) { |
56 | - case 0: gen_helper_neon_mul_u8(tmp, tmp, tmp2); break; | 88 | - goto exit_perror; |
57 | - case 1: gen_helper_neon_mul_u16(tmp, tmp, tmp2); break; | ||
58 | - case 2: tcg_gen_mul_i32(tmp, tmp, tmp2); break; | ||
59 | - default: abort(); | ||
60 | - } | 89 | - } |
61 | - } | 90 | - } |
62 | + /* VMUL.P8; other cases already eliminated. */ | 91 | - if (interp_name[eppnt->p_filesz - 1] != 0) { |
63 | + gen_helper_neon_mul_p8(tmp, tmp, tmp2); | 92 | - errmsg = "Invalid PT_INTERP entry"; |
64 | break; | 93 | - goto exit_errmsg; |
65 | case NEON_3R_VPMAX: | 94 | - } |
66 | GEN_NEON_INTEGER_OP(pmax); | 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.19.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 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 3 | This is a bit clearer than open-coding some of this |
4 | with a bare c string. | ||
5 | |||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | Message-id: 20181016223115.24100-7-richard.henderson@linaro.org | 7 | Message-id: 20201021173749.111103-9-richard.henderson@linaro.org |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 10 | --- |
9 | target/arm/cpu.h | 6 +++++- | 11 | linux-user/elfload.c | 37 ++++++++++++++++++++----------------- |
10 | linux-user/elfload.c | 2 +- | 12 | 1 file changed, 20 insertions(+), 17 deletions(-) |
11 | target/arm/cpu.c | 4 ---- | ||
12 | target/arm/helper.c | 2 +- | ||
13 | target/arm/machine.c | 3 +-- | ||
14 | 5 files changed, 8 insertions(+), 9 deletions(-) | ||
15 | 13 | ||
16 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/target/arm/cpu.h | ||
19 | +++ b/target/arm/cpu.h | ||
20 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | ||
21 | ARM_FEATURE_NEON, | ||
22 | ARM_FEATURE_M, /* Microcontroller profile. */ | ||
23 | ARM_FEATURE_OMAPCP, /* OMAP specific CP15 ops handling. */ | ||
24 | - ARM_FEATURE_THUMB2EE, | ||
25 | ARM_FEATURE_V7MP, /* v7 Multiprocessing Extensions */ | ||
26 | ARM_FEATURE_V7VE, /* v7 Virtualization Extensions (non-EL2 parts) */ | ||
27 | ARM_FEATURE_V4T, | ||
28 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_jazelle(const ARMISARegisters *id) | ||
29 | return FIELD_EX32(id->id_isar1, ID_ISAR1, JAZELLE) != 0; | ||
30 | } | ||
31 | |||
32 | +static inline bool isar_feature_t32ee(const ARMISARegisters *id) | ||
33 | +{ | ||
34 | + return FIELD_EX32(id->id_isar3, ID_ISAR3, T32EE) != 0; | ||
35 | +} | ||
36 | + | ||
37 | static inline bool isar_feature_aa32_aes(const ARMISARegisters *id) | ||
38 | { | ||
39 | return FIELD_EX32(id->id_isar5, ID_ISAR5, AES) != 0; | ||
40 | 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 |
41 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
42 | --- a/linux-user/elfload.c | 16 | --- a/linux-user/elfload.c |
43 | +++ b/linux-user/elfload.c | 17 | +++ b/linux-user/elfload.c |
44 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | 18 | @@ -XXX,XX +XXX,XX @@ |
45 | GET_FEATURE(ARM_FEATURE_V5, ARM_HWCAP_ARM_EDSP); | 19 | #include "qemu/guest-random.h" |
46 | GET_FEATURE(ARM_FEATURE_VFP, ARM_HWCAP_ARM_VFP); | 20 | #include "qemu/units.h" |
47 | GET_FEATURE(ARM_FEATURE_IWMMXT, ARM_HWCAP_ARM_IWMMXT); | 21 | #include "qemu/selfmap.h" |
48 | - GET_FEATURE(ARM_FEATURE_THUMB2EE, ARM_HWCAP_ARM_THUMBEE); | 22 | +#include "qapi/error.h" |
49 | + GET_FEATURE_ID(t32ee, ARM_HWCAP_ARM_THUMBEE); | 23 | |
50 | GET_FEATURE(ARM_FEATURE_NEON, ARM_HWCAP_ARM_NEON); | 24 | #ifdef _ARCH_PPC64 |
51 | GET_FEATURE(ARM_FEATURE_VFP3, ARM_HWCAP_ARM_VFPv3); | 25 | #undef ARCH_DLINFO |
52 | GET_FEATURE(ARM_FEATURE_V6K, ARM_HWCAP_ARM_TLS); | 26 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
53 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 27 | struct elf_phdr *phdr; |
54 | index XXXXXXX..XXXXXXX 100644 | 28 | abi_ulong load_addr, load_bias, loaddr, hiaddr, error; |
55 | --- a/target/arm/cpu.c | 29 | int i, retval; |
56 | +++ b/target/arm/cpu.c | 30 | - const char *errmsg; |
57 | @@ -XXX,XX +XXX,XX @@ static void cortex_a8_initfn(Object *obj) | 31 | + Error *err = NULL; |
58 | set_feature(&cpu->env, ARM_FEATURE_V7); | 32 | |
59 | set_feature(&cpu->env, ARM_FEATURE_VFP3); | 33 | /* First of all, some simple consistency checks */ |
60 | set_feature(&cpu->env, ARM_FEATURE_NEON); | 34 | - errmsg = "Invalid ELF image for this architecture"; |
61 | - set_feature(&cpu->env, ARM_FEATURE_THUMB2EE); | 35 | if (!elf_check_ident(ehdr)) { |
62 | set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS); | 36 | + error_setg(&err, "Invalid ELF image for this architecture"); |
63 | set_feature(&cpu->env, ARM_FEATURE_EL3); | 37 | goto exit_errmsg; |
64 | cpu->midr = 0x410fc080; | ||
65 | @@ -XXX,XX +XXX,XX @@ static void cortex_a9_initfn(Object *obj) | ||
66 | set_feature(&cpu->env, ARM_FEATURE_VFP3); | ||
67 | set_feature(&cpu->env, ARM_FEATURE_VFP_FP16); | ||
68 | set_feature(&cpu->env, ARM_FEATURE_NEON); | ||
69 | - set_feature(&cpu->env, ARM_FEATURE_THUMB2EE); | ||
70 | set_feature(&cpu->env, ARM_FEATURE_EL3); | ||
71 | /* Note that A9 supports the MP extensions even for | ||
72 | * A9UP and single-core A9MP (which are both different | ||
73 | @@ -XXX,XX +XXX,XX @@ static void cortex_a7_initfn(Object *obj) | ||
74 | set_feature(&cpu->env, ARM_FEATURE_V7VE); | ||
75 | set_feature(&cpu->env, ARM_FEATURE_VFP4); | ||
76 | set_feature(&cpu->env, ARM_FEATURE_NEON); | ||
77 | - set_feature(&cpu->env, ARM_FEATURE_THUMB2EE); | ||
78 | set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); | ||
79 | set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS); | ||
80 | set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); | ||
81 | @@ -XXX,XX +XXX,XX @@ static void cortex_a15_initfn(Object *obj) | ||
82 | set_feature(&cpu->env, ARM_FEATURE_V7VE); | ||
83 | set_feature(&cpu->env, ARM_FEATURE_VFP4); | ||
84 | set_feature(&cpu->env, ARM_FEATURE_NEON); | ||
85 | - set_feature(&cpu->env, ARM_FEATURE_THUMB2EE); | ||
86 | set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); | ||
87 | set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS); | ||
88 | set_feature(&cpu->env, ARM_FEATURE_CBAR_RO); | ||
89 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/target/arm/helper.c | ||
92 | +++ b/target/arm/helper.c | ||
93 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
94 | define_arm_cp_regs(cpu, vmsa_pmsa_cp_reginfo); | ||
95 | define_arm_cp_regs(cpu, vmsa_cp_reginfo); | ||
96 | } | 38 | } |
97 | - if (arm_feature(env, ARM_FEATURE_THUMB2EE)) { | 39 | bswap_ehdr(ehdr); |
98 | + if (cpu_isar_feature(t32ee, cpu)) { | 40 | if (!elf_check_ehdr(ehdr)) { |
99 | define_arm_cp_regs(cpu, t2ee_cp_reginfo); | 41 | + error_setg(&err, "Invalid ELF image for this architecture"); |
42 | goto exit_errmsg; | ||
100 | } | 43 | } |
101 | if (arm_feature(env, ARM_FEATURE_GENERIC_TIMER)) { | 44 | |
102 | diff --git a/target/arm/machine.c b/target/arm/machine.c | 45 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
103 | index XXXXXXX..XXXXXXX 100644 | 46 | g_autofree char *interp_name = NULL; |
104 | --- a/target/arm/machine.c | 47 | |
105 | +++ b/target/arm/machine.c | 48 | if (*pinterp_name) { |
106 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m = { | 49 | - errmsg = "Multiple PT_INTERP entries"; |
107 | static bool thumb2ee_needed(void *opaque) | 50 | + error_setg(&err, "Multiple PT_INTERP entries"); |
108 | { | 51 | goto exit_errmsg; |
109 | ARMCPU *cpu = opaque; | 52 | } |
110 | - CPUARMState *env = &cpu->env; | 53 | + |
111 | 54 | interp_name = g_malloc(eppnt->p_filesz); | |
112 | - return arm_feature(env, ARM_FEATURE_THUMB2EE); | 55 | - if (!interp_name) { |
113 | + return cpu_isar_feature(t32ee, cpu); | 56 | - goto exit_perror; |
57 | - } | ||
58 | |||
59 | if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { | ||
60 | memcpy(interp_name, bprm_buf + eppnt->p_offset, | ||
61 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
62 | retval = pread(image_fd, interp_name, eppnt->p_filesz, | ||
63 | eppnt->p_offset); | ||
64 | if (retval != eppnt->p_filesz) { | ||
65 | - goto exit_perror; | ||
66 | + goto exit_read; | ||
67 | } | ||
68 | } | ||
69 | if (interp_name[eppnt->p_filesz - 1] != 0) { | ||
70 | - errmsg = "Invalid PT_INTERP entry"; | ||
71 | + error_setg(&err, "Invalid PT_INTERP entry"); | ||
72 | goto exit_errmsg; | ||
73 | } | ||
74 | *pinterp_name = g_steal_pointer(&interp_name); | ||
75 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
76 | (ehdr->e_type == ET_EXEC ? MAP_FIXED : 0), | ||
77 | -1, 0); | ||
78 | if (load_addr == -1) { | ||
79 | - goto exit_perror; | ||
80 | + goto exit_mmap; | ||
81 | } | ||
82 | load_bias = load_addr - loaddr; | ||
83 | |||
84 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
85 | image_fd, eppnt->p_offset - vaddr_po); | ||
86 | |||
87 | if (error == -1) { | ||
88 | - goto exit_perror; | ||
89 | + goto exit_mmap; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
94 | } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { | ||
95 | Mips_elf_abiflags_v0 abiflags; | ||
96 | if (eppnt->p_filesz < sizeof(Mips_elf_abiflags_v0)) { | ||
97 | - errmsg = "Invalid PT_MIPS_ABIFLAGS entry"; | ||
98 | + error_setg(&err, "Invalid PT_MIPS_ABIFLAGS entry"); | ||
99 | goto exit_errmsg; | ||
100 | } | ||
101 | if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { | ||
102 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
103 | retval = pread(image_fd, &abiflags, sizeof(Mips_elf_abiflags_v0), | ||
104 | eppnt->p_offset); | ||
105 | if (retval != sizeof(Mips_elf_abiflags_v0)) { | ||
106 | - goto exit_perror; | ||
107 | + goto exit_read; | ||
108 | } | ||
109 | } | ||
110 | bswap_mips_abiflags(&abiflags); | ||
111 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
112 | |||
113 | exit_read: | ||
114 | if (retval >= 0) { | ||
115 | - errmsg = "Incomplete read of file header"; | ||
116 | - goto exit_errmsg; | ||
117 | + error_setg(&err, "Incomplete read of file header"); | ||
118 | + } else { | ||
119 | + error_setg_errno(&err, errno, "Error reading file header"); | ||
120 | } | ||
121 | - exit_perror: | ||
122 | - errmsg = strerror(errno); | ||
123 | + goto exit_errmsg; | ||
124 | + exit_mmap: | ||
125 | + error_setg_errno(&err, errno, "Error mapping file"); | ||
126 | + goto exit_errmsg; | ||
127 | exit_errmsg: | ||
128 | - fprintf(stderr, "%s: %s\n", image_name, errmsg); | ||
129 | + error_reportf_err(err, "%s: ", image_name); | ||
130 | exit(-1); | ||
114 | } | 131 | } |
115 | 132 | ||
116 | static const VMStateDescription vmstate_thumb2ee = { | ||
117 | -- | 133 | -- |
118 | 2.19.1 | 134 | 2.20.1 |
119 | 135 | ||
120 | 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 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 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. | ||
6 | |||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | Message-id: 20181016223115.24100-8-richard.henderson@linaro.org | 8 | Message-id: 20201021173749.111103-10-richard.henderson@linaro.org |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 11 | --- |
9 | target/arm/cpu.h | 16 +++++++++++++++- | 12 | linux-user/elfload.c | 15 ++++++++------- |
10 | linux-user/aarch64/signal.c | 4 ++-- | 13 | 1 file changed, 8 insertions(+), 7 deletions(-) |
11 | linux-user/elfload.c | 2 +- | ||
12 | linux-user/syscall.c | 10 ++++++---- | ||
13 | target/arm/cpu64.c | 5 ++++- | ||
14 | target/arm/helper.c | 9 ++++++--- | ||
15 | target/arm/machine.c | 3 +-- | ||
16 | target/arm/translate-a64.c | 4 ++-- | ||
17 | 8 files changed, 37 insertions(+), 16 deletions(-) | ||
18 | 14 | ||
19 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/arm/cpu.h | ||
22 | +++ b/target/arm/cpu.h | ||
23 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64ISAR1, FRINTTS, 32, 4) | ||
24 | FIELD(ID_AA64ISAR1, SB, 36, 4) | ||
25 | FIELD(ID_AA64ISAR1, SPECRES, 40, 4) | ||
26 | |||
27 | +FIELD(ID_AA64PFR0, EL0, 0, 4) | ||
28 | +FIELD(ID_AA64PFR0, EL1, 4, 4) | ||
29 | +FIELD(ID_AA64PFR0, EL2, 8, 4) | ||
30 | +FIELD(ID_AA64PFR0, EL3, 12, 4) | ||
31 | +FIELD(ID_AA64PFR0, FP, 16, 4) | ||
32 | +FIELD(ID_AA64PFR0, ADVSIMD, 20, 4) | ||
33 | +FIELD(ID_AA64PFR0, GIC, 24, 4) | ||
34 | +FIELD(ID_AA64PFR0, RAS, 28, 4) | ||
35 | +FIELD(ID_AA64PFR0, SVE, 32, 4) | ||
36 | + | ||
37 | QEMU_BUILD_BUG_ON(ARRAY_SIZE(((ARMCPU *)0)->ccsidr) <= R_V7M_CSSELR_INDEX_MASK); | ||
38 | |||
39 | /* If adding a feature bit which corresponds to a Linux ELF | ||
40 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | ||
41 | ARM_FEATURE_PMU, /* has PMU support */ | ||
42 | ARM_FEATURE_VBAR, /* has cp15 VBAR */ | ||
43 | ARM_FEATURE_M_SECURITY, /* M profile Security Extension */ | ||
44 | - ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | ||
45 | ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */ | ||
46 | ARM_FEATURE_M_MAIN, /* M profile Main Extension */ | ||
47 | }; | ||
48 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_fcma(const ARMISARegisters *id) | ||
49 | return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, FCMA) != 0; | ||
50 | } | ||
51 | |||
52 | +static inline bool isar_feature_aa64_sve(const ARMISARegisters *id) | ||
53 | +{ | ||
54 | + return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, SVE) != 0; | ||
55 | +} | ||
56 | + | ||
57 | /* | ||
58 | * Forward to the above feature tests given an ARMCPU pointer. | ||
59 | */ | ||
60 | diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/linux-user/aarch64/signal.c | ||
63 | +++ b/linux-user/aarch64/signal.c | ||
64 | @@ -XXX,XX +XXX,XX @@ static int target_restore_sigframe(CPUARMState *env, | ||
65 | break; | ||
66 | |||
67 | case TARGET_SVE_MAGIC: | ||
68 | - if (arm_feature(env, ARM_FEATURE_SVE)) { | ||
69 | + if (cpu_isar_feature(aa64_sve, arm_env_get_cpu(env))) { | ||
70 | vq = (env->vfp.zcr_el[1] & 0xf) + 1; | ||
71 | sve_size = QEMU_ALIGN_UP(TARGET_SVE_SIG_CONTEXT_SIZE(vq), 16); | ||
72 | if (!sve && size == sve_size) { | ||
73 | @@ -XXX,XX +XXX,XX @@ static void target_setup_frame(int usig, struct target_sigaction *ka, | ||
74 | &layout); | ||
75 | |||
76 | /* SVE state needs saving only if it exists. */ | ||
77 | - if (arm_feature(env, ARM_FEATURE_SVE)) { | ||
78 | + if (cpu_isar_feature(aa64_sve, arm_env_get_cpu(env))) { | ||
79 | vq = (env->vfp.zcr_el[1] & 0xf) + 1; | ||
80 | sve_size = QEMU_ALIGN_UP(TARGET_SVE_SIG_CONTEXT_SIZE(vq), 16); | ||
81 | sve_ofs = alloc_sigframe_space(sve_size, &layout); | ||
82 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | 15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
83 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
84 | --- a/linux-user/elfload.c | 17 | --- a/linux-user/elfload.c |
85 | +++ b/linux-user/elfload.c | 18 | +++ b/linux-user/elfload.c |
86 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | 19 | @@ -XXX,XX +XXX,XX @@ static void load_elf_interp(const char *filename, struct image_info *info, |
87 | GET_FEATURE_ID(aa64_rdm, ARM_HWCAP_A64_ASIMDRDM); | 20 | char bprm_buf[BPRM_BUF_SIZE]) |
88 | GET_FEATURE_ID(aa64_dp, ARM_HWCAP_A64_ASIMDDP); | 21 | { |
89 | GET_FEATURE_ID(aa64_fcma, ARM_HWCAP_A64_FCMA); | 22 | int fd, retval; |
90 | - GET_FEATURE(ARM_FEATURE_SVE, ARM_HWCAP_A64_SVE); | 23 | + Error *err = NULL; |
91 | + GET_FEATURE_ID(aa64_sve, ARM_HWCAP_A64_SVE); | 24 | |
92 | 25 | fd = open(path(filename), O_RDONLY); | |
93 | #undef GET_FEATURE | 26 | if (fd < 0) { |
94 | #undef GET_FEATURE_ID | 27 | - goto exit_perror; |
95 | diff --git a/linux-user/syscall.c b/linux-user/syscall.c | 28 | + error_setg_file_open(&err, errno, filename); |
96 | index XXXXXXX..XXXXXXX 100644 | 29 | + error_report_err(err); |
97 | --- a/linux-user/syscall.c | 30 | + exit(-1); |
98 | +++ b/linux-user/syscall.c | 31 | } |
99 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | 32 | |
100 | * even though the current architectural maximum is VQ=16. | 33 | retval = read(fd, bprm_buf, BPRM_BUF_SIZE); |
101 | */ | 34 | if (retval < 0) { |
102 | ret = -TARGET_EINVAL; | 35 | - goto exit_perror; |
103 | - if (arm_feature(cpu_env, ARM_FEATURE_SVE) | 36 | + error_setg_errno(&err, errno, "Error reading file header"); |
104 | + if (cpu_isar_feature(aa64_sve, arm_env_get_cpu(cpu_env)) | 37 | + error_reportf_err(err, "%s: ", filename); |
105 | && arg2 >= 0 && arg2 <= 512 * 16 && !(arg2 & 15)) { | 38 | + exit(-1); |
106 | CPUARMState *env = cpu_env; | 39 | } |
107 | ARMCPU *cpu = arm_env_get_cpu(env); | ||
108 | @@ -XXX,XX +XXX,XX @@ static abi_long do_syscall1(void *cpu_env, int num, abi_long arg1, | ||
109 | return ret; | ||
110 | case TARGET_PR_SVE_GET_VL: | ||
111 | ret = -TARGET_EINVAL; | ||
112 | - if (arm_feature(cpu_env, ARM_FEATURE_SVE)) { | ||
113 | - CPUARMState *env = cpu_env; | ||
114 | - ret = ((env->vfp.zcr_el[1] & 0xf) + 1) * 16; | ||
115 | + { | ||
116 | + ARMCPU *cpu = arm_env_get_cpu(cpu_env); | ||
117 | + if (cpu_isar_feature(aa64_sve, cpu)) { | ||
118 | + ret = ((cpu->env.vfp.zcr_el[1] & 0xf) + 1) * 16; | ||
119 | + } | ||
120 | } | ||
121 | return ret; | ||
122 | #endif /* AARCH64 */ | ||
123 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | ||
124 | index XXXXXXX..XXXXXXX 100644 | ||
125 | --- a/target/arm/cpu64.c | ||
126 | +++ b/target/arm/cpu64.c | ||
127 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) | ||
128 | t = FIELD_DP64(t, ID_AA64ISAR1, FCMA, 1); | ||
129 | cpu->isar.id_aa64isar1 = t; | ||
130 | |||
131 | + t = cpu->isar.id_aa64pfr0; | ||
132 | + t = FIELD_DP64(t, ID_AA64PFR0, SVE, 1); | ||
133 | + cpu->isar.id_aa64pfr0 = t; | ||
134 | + | 40 | + |
135 | /* Replicate the same data to the 32-bit id registers. */ | 41 | if (retval < BPRM_BUF_SIZE) { |
136 | u = cpu->isar.id_isar5; | 42 | memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); |
137 | u = FIELD_DP32(u, ID_ISAR5, AES, 2); /* AES + PMULL */ | ||
138 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) | ||
139 | * present in either. | ||
140 | */ | ||
141 | set_feature(&cpu->env, ARM_FEATURE_V8_FP16); | ||
142 | - set_feature(&cpu->env, ARM_FEATURE_SVE); | ||
143 | /* For usermode -cpu max we can use a larger and more efficient DCZ | ||
144 | * blocksize since we don't have to follow what the hardware does. | ||
145 | */ | ||
146 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/target/arm/helper.c | ||
149 | +++ b/target/arm/helper.c | ||
150 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
151 | define_one_arm_cp_reg(cpu, &sctlr); | ||
152 | } | 43 | } |
153 | 44 | ||
154 | - if (arm_feature(env, ARM_FEATURE_SVE)) { | 45 | load_elf_image(filename, fd, info, NULL, bprm_buf); |
155 | + if (cpu_isar_feature(aa64_sve, cpu)) { | 46 | - return; |
156 | define_one_arm_cp_reg(cpu, &zcr_el1_reginfo); | 47 | - |
157 | if (arm_feature(env, ARM_FEATURE_EL2)) { | 48 | - exit_perror: |
158 | define_one_arm_cp_reg(cpu, &zcr_el2_reginfo); | 49 | - fprintf(stderr, "%s: %s\n", filename, strerror(errno)); |
159 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | 50 | - exit(-1); |
160 | uint32_t flags; | ||
161 | |||
162 | if (is_a64(env)) { | ||
163 | + ARMCPU *cpu = arm_env_get_cpu(env); | ||
164 | + | ||
165 | *pc = env->pc; | ||
166 | flags = ARM_TBFLAG_AARCH64_STATE_MASK; | ||
167 | /* Get control bits for tagged addresses */ | ||
168 | flags |= (arm_regime_tbi0(env, mmu_idx) << ARM_TBFLAG_TBI0_SHIFT); | ||
169 | flags |= (arm_regime_tbi1(env, mmu_idx) << ARM_TBFLAG_TBI1_SHIFT); | ||
170 | |||
171 | - if (arm_feature(env, ARM_FEATURE_SVE)) { | ||
172 | + if (cpu_isar_feature(aa64_sve, cpu)) { | ||
173 | int sve_el = sve_exception_el(env, current_el); | ||
174 | uint32_t zcr_len; | ||
175 | |||
176 | @@ -XXX,XX +XXX,XX @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq) | ||
177 | void aarch64_sve_change_el(CPUARMState *env, int old_el, | ||
178 | int new_el, bool el0_a64) | ||
179 | { | ||
180 | + ARMCPU *cpu = arm_env_get_cpu(env); | ||
181 | int old_len, new_len; | ||
182 | bool old_a64, new_a64; | ||
183 | |||
184 | /* Nothing to do if no SVE. */ | ||
185 | - if (!arm_feature(env, ARM_FEATURE_SVE)) { | ||
186 | + if (!cpu_isar_feature(aa64_sve, cpu)) { | ||
187 | return; | ||
188 | } | ||
189 | |||
190 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
191 | index XXXXXXX..XXXXXXX 100644 | ||
192 | --- a/target/arm/machine.c | ||
193 | +++ b/target/arm/machine.c | ||
194 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_iwmmxt = { | ||
195 | static bool sve_needed(void *opaque) | ||
196 | { | ||
197 | ARMCPU *cpu = opaque; | ||
198 | - CPUARMState *env = &cpu->env; | ||
199 | |||
200 | - return arm_feature(env, ARM_FEATURE_SVE); | ||
201 | + return cpu_isar_feature(aa64_sve, cpu); | ||
202 | } | 51 | } |
203 | 52 | ||
204 | /* The first two words of each Zreg is stored in VFP state. */ | 53 | static int symfind(const void *s0, const void *s1) |
205 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
206 | index XXXXXXX..XXXXXXX 100644 | ||
207 | --- a/target/arm/translate-a64.c | ||
208 | +++ b/target/arm/translate-a64.c | ||
209 | @@ -XXX,XX +XXX,XX @@ void aarch64_cpu_dump_state(CPUState *cs, FILE *f, | ||
210 | cpu_fprintf(f, " FPCR=%08x FPSR=%08x\n", | ||
211 | vfp_get_fpcr(env), vfp_get_fpsr(env)); | ||
212 | |||
213 | - if (arm_feature(env, ARM_FEATURE_SVE) && sve_exception_el(env, el) == 0) { | ||
214 | + if (cpu_isar_feature(aa64_sve, cpu) && sve_exception_el(env, el) == 0) { | ||
215 | int j, zcr_len = sve_zcr_len_for_el(env, el); | ||
216 | |||
217 | for (i = 0; i <= FFR_PRED_NUM; i++) { | ||
218 | @@ -XXX,XX +XXX,XX @@ static void disas_a64_insn(CPUARMState *env, DisasContext *s) | ||
219 | unallocated_encoding(s); | ||
220 | break; | ||
221 | case 0x2: | ||
222 | - if (!arm_dc_feature(s, ARM_FEATURE_SVE) || !disas_sve(s, insn)) { | ||
223 | + if (!dc_isar_feature(aa64_sve, s) || !disas_sve(s, insn)) { | ||
224 | unallocated_encoding(s); | ||
225 | } | ||
226 | break; | ||
227 | -- | 54 | -- |
228 | 2.19.1 | 55 | 2.20.1 |
229 | 56 | ||
230 | 57 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Instead of shifts and masks, use direct loads and stores from | 3 | This is generic support, with the code disabled for all targets. |
4 | the neon register file. | ||
5 | 4 | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20181011205206.3552-21-richard.henderson@linaro.org | 6 | Message-id: 20201021173749.111103-11-richard.henderson@linaro.org |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 9 | --- |
11 | target/arm/translate.c | 92 +++++++++++++++++++++++------------------- | 10 | linux-user/qemu.h | 4 ++ |
12 | 1 file changed, 50 insertions(+), 42 deletions(-) | 11 | linux-user/elfload.c | 157 +++++++++++++++++++++++++++++++++++++++++++ |
13 | 12 | 2 files changed, 161 insertions(+) | |
14 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 13 | |
14 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/translate.c | 16 | --- a/linux-user/qemu.h |
17 | +++ b/target/arm/translate.c | 17 | +++ b/linux-user/qemu.h |
18 | @@ -XXX,XX +XXX,XX @@ static TCGv_i32 neon_load_reg(int reg, int pass) | 18 | @@ -XXX,XX +XXX,XX @@ struct image_info { |
19 | return tmp; | 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); | ||
20 | } | 51 | } |
21 | 52 | ||
22 | +static void neon_load_element(TCGv_i32 var, int reg, int ele, TCGMemOp mop) | 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) | ||
23 | +{ | 68 | +{ |
24 | + long offset = neon_element_offset(reg, ele, mop & MO_SIZE); | 69 | + uint32_t pr_type, pr_datasz, step; |
25 | + | 70 | + |
26 | + switch (mop) { | 71 | + if (*off > datasz || !QEMU_IS_ALIGNED(*off, ELF_GNU_PROPERTY_ALIGN)) { |
27 | + case MO_UB: | 72 | + goto error_data; |
28 | + tcg_gen_ld8u_i32(var, cpu_env, offset); | 73 | + } |
29 | + break; | 74 | + datasz -= *off; |
30 | + case MO_UW: | 75 | + data += *off / sizeof(uint32_t); |
31 | + tcg_gen_ld16u_i32(var, cpu_env, offset); | 76 | + |
32 | + break; | 77 | + if (datasz < 2 * sizeof(uint32_t)) { |
33 | + case MO_UL: | 78 | + goto error_data; |
34 | + tcg_gen_ld_i32(var, cpu_env, offset); | 79 | + } |
35 | + break; | 80 | + pr_type = data[0]; |
36 | + default: | 81 | + pr_datasz = data[1]; |
37 | + g_assert_not_reached(); | 82 | + data += 2; |
38 | + } | 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; | ||
39 | +} | 110 | +} |
40 | + | 111 | + |
41 | static void neon_load_element64(TCGv_i64 var, int reg, int ele, TCGMemOp mop) | 112 | +/* Process NT_GNU_PROPERTY_TYPE_0. */ |
42 | { | 113 | +static bool parse_elf_properties(int image_fd, |
43 | long offset = neon_element_offset(reg, ele, mop & MO_SIZE); | 114 | + struct image_info *info, |
44 | @@ -XXX,XX +XXX,XX @@ static void neon_store_reg(int reg, int pass, TCGv_i32 var) | 115 | + const struct elf_phdr *phdr, |
45 | tcg_temp_free_i32(var); | 116 | + char bprm_buf[BPRM_BUF_SIZE], |
46 | } | 117 | + Error **errp) |
47 | |||
48 | +static void neon_store_element(int reg, int ele, TCGMemOp size, TCGv_i32 var) | ||
49 | +{ | 118 | +{ |
50 | + long offset = neon_element_offset(reg, ele, size); | 119 | + union { |
51 | + | 120 | + struct elf_note nhdr; |
52 | + switch (size) { | 121 | + uint32_t data[NOTE_DATA_SZ / sizeof(uint32_t)]; |
53 | + case MO_8: | 122 | + } note; |
54 | + tcg_gen_st8_i32(var, cpu_env, offset); | 123 | + |
55 | + break; | 124 | + int n, off, datasz; |
56 | + case MO_16: | 125 | + bool have_prev_type; |
57 | + tcg_gen_st16_i32(var, cpu_env, offset); | 126 | + uint32_t prev_type; |
58 | + break; | 127 | + |
59 | + case MO_32: | 128 | + /* Unless the arch requires properties, ignore them. */ |
60 | + tcg_gen_st_i32(var, cpu_env, offset); | 129 | + if (!ARCH_USE_GNU_PROPERTY) { |
61 | + break; | 130 | + return true; |
62 | + default: | 131 | + } |
63 | + g_assert_not_reached(); | 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; | ||
64 | + } | 194 | + } |
65 | +} | 195 | +} |
66 | + | 196 | + |
67 | static void neon_store_element64(int reg, int ele, TCGMemOp size, TCGv_i64 var) | 197 | /* Load an ELF image into the address space. |
68 | { | 198 | |
69 | long offset = neon_element_offset(reg, ele, size); | 199 | IMAGE_NAME is the filename of the image, to use in error messages. |
70 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | 200 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
71 | int stride; | 201 | goto exit_errmsg; |
72 | int size; | ||
73 | int reg; | ||
74 | - int pass; | ||
75 | int load; | ||
76 | - int shift; | ||
77 | int n; | ||
78 | int vec_size; | ||
79 | int mmu_idx; | ||
80 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | ||
81 | } else { | ||
82 | /* Single element. */ | ||
83 | int idx = (insn >> 4) & 0xf; | ||
84 | - pass = (insn >> 7) & 1; | ||
85 | + int reg_idx; | ||
86 | switch (size) { | ||
87 | case 0: | ||
88 | - shift = ((insn >> 5) & 3) * 8; | ||
89 | + reg_idx = (insn >> 5) & 7; | ||
90 | stride = 1; | ||
91 | break; | ||
92 | case 1: | ||
93 | - shift = ((insn >> 6) & 1) * 16; | ||
94 | + reg_idx = (insn >> 6) & 3; | ||
95 | stride = (insn & (1 << 5)) ? 2 : 1; | ||
96 | break; | ||
97 | case 2: | ||
98 | - shift = 0; | ||
99 | + reg_idx = (insn >> 7) & 1; | ||
100 | stride = (insn & (1 << 6)) ? 2 : 1; | ||
101 | break; | ||
102 | default: | ||
103 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | ||
104 | */ | ||
105 | return 1; | ||
106 | } | 202 | } |
107 | + tmp = tcg_temp_new_i32(); | 203 | *pinterp_name = g_steal_pointer(&interp_name); |
108 | addr = tcg_temp_new_i32(); | 204 | + } else if (eppnt->p_type == PT_GNU_PROPERTY) { |
109 | load_reg_var(s, addr, rn); | 205 | + if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) { |
110 | for (reg = 0; reg < nregs; reg++) { | 206 | + goto exit_errmsg; |
111 | if (load) { | 207 | + } |
112 | - tmp = tcg_temp_new_i32(); | ||
113 | - switch (size) { | ||
114 | - case 0: | ||
115 | - gen_aa32_ld8u(s, tmp, addr, get_mem_index(s)); | ||
116 | - break; | ||
117 | - case 1: | ||
118 | - gen_aa32_ld16u(s, tmp, addr, get_mem_index(s)); | ||
119 | - break; | ||
120 | - case 2: | ||
121 | - gen_aa32_ld32u(s, tmp, addr, get_mem_index(s)); | ||
122 | - break; | ||
123 | - default: /* Avoid compiler warnings. */ | ||
124 | - abort(); | ||
125 | - } | ||
126 | - if (size != 2) { | ||
127 | - tmp2 = neon_load_reg(rd, pass); | ||
128 | - tcg_gen_deposit_i32(tmp, tmp2, tmp, | ||
129 | - shift, size ? 16 : 8); | ||
130 | - tcg_temp_free_i32(tmp2); | ||
131 | - } | ||
132 | - neon_store_reg(rd, pass, tmp); | ||
133 | + gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), | ||
134 | + s->be_data | size); | ||
135 | + neon_store_element(rd, reg_idx, size, tmp); | ||
136 | } else { /* Store */ | ||
137 | - tmp = neon_load_reg(rd, pass); | ||
138 | - if (shift) | ||
139 | - tcg_gen_shri_i32(tmp, tmp, shift); | ||
140 | - switch (size) { | ||
141 | - case 0: | ||
142 | - gen_aa32_st8(s, tmp, addr, get_mem_index(s)); | ||
143 | - break; | ||
144 | - case 1: | ||
145 | - gen_aa32_st16(s, tmp, addr, get_mem_index(s)); | ||
146 | - break; | ||
147 | - case 2: | ||
148 | - gen_aa32_st32(s, tmp, addr, get_mem_index(s)); | ||
149 | - break; | ||
150 | - } | ||
151 | - tcg_temp_free_i32(tmp); | ||
152 | + neon_load_element(tmp, rd, reg_idx, size); | ||
153 | + gen_aa32_st_i32(s, tmp, addr, get_mem_index(s), | ||
154 | + s->be_data | size); | ||
155 | } | ||
156 | rd += stride; | ||
157 | tcg_gen_addi_i32(addr, addr, 1 << size); | ||
158 | } | ||
159 | tcg_temp_free_i32(addr); | ||
160 | + tcg_temp_free_i32(tmp); | ||
161 | stride = nregs * (1 << size); | ||
162 | } | 208 | } |
163 | } | 209 | } |
210 | |||
164 | -- | 211 | -- |
165 | 2.19.1 | 212 | 2.20.1 |
166 | 213 | ||
167 | 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 | Also introduces neon_element_offset to find the env offset | 3 | Use the new generic support for NT_GNU_PROPERTY_TYPE_0. |
4 | of a specific element within a neon register. | ||
5 | 4 | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20181011205206.3552-7-richard.henderson@linaro.org | 6 | Message-id: 20201021173749.111103-12-richard.henderson@linaro.org |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 9 | --- |
11 | target/arm/translate.c | 63 ++++++++++++++++++++++++------------------ | 10 | linux-user/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++-- |
12 | 1 file changed, 36 insertions(+), 27 deletions(-) | 11 | 1 file changed, 46 insertions(+), 2 deletions(-) |
13 | 12 | ||
14 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 13 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
15 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/translate.c | 15 | --- a/linux-user/elfload.c |
17 | +++ b/target/arm/translate.c | 16 | +++ b/linux-user/elfload.c |
18 | @@ -XXX,XX +XXX,XX @@ neon_reg_offset (int reg, int n) | 17 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, |
19 | return vfp_reg_offset(0, sreg); | 18 | |
19 | #include "elf.h" | ||
20 | |||
21 | +/* We must delay the following stanzas until after "elf.h". */ | ||
22 | +#if defined(TARGET_AARCH64) | ||
23 | + | ||
24 | +static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
25 | + const uint32_t *data, | ||
26 | + struct image_info *info, | ||
27 | + Error **errp) | ||
28 | +{ | ||
29 | + if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { | ||
30 | + if (pr_datasz != sizeof(uint32_t)) { | ||
31 | + error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND"); | ||
32 | + return false; | ||
33 | + } | ||
34 | + /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */ | ||
35 | + info->note_flags = *data; | ||
36 | + } | ||
37 | + return true; | ||
38 | +} | ||
39 | +#define ARCH_USE_GNU_PROPERTY 1 | ||
40 | + | ||
41 | +#else | ||
42 | + | ||
43 | static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
44 | const uint32_t *data, | ||
45 | struct image_info *info, | ||
46 | @@ -XXX,XX +XXX,XX @@ static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
20 | } | 47 | } |
21 | 48 | #define ARCH_USE_GNU_PROPERTY 0 | |
22 | +/* Return the offset of a 2**SIZE piece of a NEON register, at index ELE, | 49 | |
23 | + * where 0 is the least significant end of the register. | 50 | +#endif |
24 | + */ | 51 | + |
25 | +static inline long | 52 | struct exec |
26 | +neon_element_offset(int reg, int element, TCGMemOp size) | 53 | { |
27 | +{ | 54 | unsigned int a_info; /* Use macros N_MAGIC, etc for access */ |
28 | + int element_size = 1 << size; | 55 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
29 | + int ofs = element * element_size; | 56 | struct elfhdr *ehdr = (struct elfhdr *)bprm_buf; |
30 | +#ifdef HOST_WORDS_BIGENDIAN | 57 | struct elf_phdr *phdr; |
31 | + /* Calculate the offset assuming fully little-endian, | 58 | abi_ulong load_addr, load_bias, loaddr, hiaddr, error; |
32 | + * then XOR to account for the order of the 8-byte units. | 59 | - int i, retval; |
60 | + int i, retval, prot_exec; | ||
61 | Error *err = NULL; | ||
62 | |||
63 | /* First of all, some simple consistency checks */ | ||
64 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
65 | info->brk = 0; | ||
66 | info->elf_flags = ehdr->e_flags; | ||
67 | |||
68 | + prot_exec = PROT_EXEC; | ||
69 | +#ifdef TARGET_AARCH64 | ||
70 | + /* | ||
71 | + * If the BTI feature is present, this indicates that the executable | ||
72 | + * pages of the startup binary should be mapped with PROT_BTI, so that | ||
73 | + * branch targets are enforced. | ||
74 | + * | ||
75 | + * The startup binary is either the interpreter or the static executable. | ||
76 | + * The interpreter is responsible for all pages of a dynamic executable. | ||
77 | + * | ||
78 | + * Elf notes are backward compatible to older cpus. | ||
79 | + * Do not enable BTI unless it is supported. | ||
33 | + */ | 80 | + */ |
34 | + if (element_size < 8) { | 81 | + if ((info->note_flags & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) |
35 | + ofs ^= 8 - element_size; | 82 | + && (pinterp_name == NULL || *pinterp_name == 0) |
83 | + && cpu_isar_feature(aa64_bti, ARM_CPU(thread_cpu))) { | ||
84 | + prot_exec |= TARGET_PROT_BTI; | ||
36 | + } | 85 | + } |
37 | +#endif | 86 | +#endif |
38 | + return neon_reg_offset(reg, 0) + ofs; | ||
39 | +} | ||
40 | + | 87 | + |
41 | static TCGv_i32 neon_load_reg(int reg, int pass) | 88 | for (i = 0; i < ehdr->e_phnum; i++) { |
42 | { | 89 | struct elf_phdr *eppnt = phdr + i; |
43 | TCGv_i32 tmp = tcg_temp_new_i32(); | 90 | if (eppnt->p_type == PT_LOAD) { |
44 | @@ -XXX,XX +XXX,XX @@ static int disas_vfp_insn(DisasContext *s, uint32_t insn) | 91 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
45 | tmp = load_reg(s, rd); | 92 | elf_prot |= PROT_WRITE; |
46 | if (insn & (1 << 23)) { | ||
47 | /* VDUP */ | ||
48 | - if (size == 0) { | ||
49 | - gen_neon_dup_u8(tmp, 0); | ||
50 | - } else if (size == 1) { | ||
51 | - gen_neon_dup_low16(tmp); | ||
52 | - } | ||
53 | - for (n = 0; n <= pass * 2; n++) { | ||
54 | - tmp2 = tcg_temp_new_i32(); | ||
55 | - tcg_gen_mov_i32(tmp2, tmp); | ||
56 | - neon_store_reg(rn, n, tmp2); | ||
57 | - } | ||
58 | - neon_store_reg(rn, n, tmp); | ||
59 | + int vec_size = pass ? 16 : 8; | ||
60 | + tcg_gen_gvec_dup_i32(size, neon_reg_offset(rn, 0), | ||
61 | + vec_size, vec_size, tmp); | ||
62 | + tcg_temp_free_i32(tmp); | ||
63 | } else { | ||
64 | /* VMOV */ | ||
65 | switch (size) { | ||
66 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
67 | tcg_temp_free_i32(tmp); | ||
68 | } else if ((insn & 0x380) == 0) { | ||
69 | /* VDUP */ | ||
70 | + int element; | ||
71 | + TCGMemOp size; | ||
72 | + | ||
73 | if ((insn & (7 << 16)) == 0 || (q && (rd & 1))) { | ||
74 | return 1; | ||
75 | } | ||
76 | - if (insn & (1 << 19)) { | ||
77 | - tmp = neon_load_reg(rm, 1); | ||
78 | - } else { | ||
79 | - tmp = neon_load_reg(rm, 0); | ||
80 | - } | ||
81 | if (insn & (1 << 16)) { | ||
82 | - gen_neon_dup_u8(tmp, ((insn >> 17) & 3) * 8); | ||
83 | + size = MO_8; | ||
84 | + element = (insn >> 17) & 7; | ||
85 | } else if (insn & (1 << 17)) { | ||
86 | - if ((insn >> 18) & 1) | ||
87 | - gen_neon_dup_high16(tmp); | ||
88 | - else | ||
89 | - gen_neon_dup_low16(tmp); | ||
90 | + size = MO_16; | ||
91 | + element = (insn >> 18) & 3; | ||
92 | + } else { | ||
93 | + size = MO_32; | ||
94 | + element = (insn >> 19) & 1; | ||
95 | } | ||
96 | - for (pass = 0; pass < (q ? 4 : 2); pass++) { | ||
97 | - tmp2 = tcg_temp_new_i32(); | ||
98 | - tcg_gen_mov_i32(tmp2, tmp); | ||
99 | - neon_store_reg(rd, pass, tmp2); | ||
100 | - } | ||
101 | - tcg_temp_free_i32(tmp); | ||
102 | + tcg_gen_gvec_dup_mem(size, neon_reg_offset(rd, 0), | ||
103 | + neon_element_offset(rm, element, size), | ||
104 | + q ? 16 : 8, q ? 16 : 8); | ||
105 | } else { | ||
106 | return 1; | ||
107 | } | 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; | ||
108 | -- | 100 | -- |
109 | 2.19.1 | 101 | 2.20.1 |
110 | 102 | ||
111 | 103 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The note test requires gcc 10 for -mbranch-protection=standard. | ||
4 | The mmap test uses PROT_BTI and does not require special compiler support. | ||
5 | |||
6 | Acked-by: Alex Bennée <alex.bennee@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | Message-id: 20181011205206.3552-13-richard.henderson@linaro.org | 9 | Message-id: 20201021173749.111103-13-richard.henderson@linaro.org |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 11 | --- |
8 | target/arm/translate.c | 70 +++++++++++++++++++++++++++++------------- | 12 | tests/tcg/aarch64/bti-1.c | 62 ++++++++++++++++ |
9 | 1 file changed, 48 insertions(+), 22 deletions(-) | 13 | tests/tcg/aarch64/bti-2.c | 116 ++++++++++++++++++++++++++++++ |
10 | 14 | tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++ | |
11 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 15 | tests/tcg/aarch64/Makefile.target | 10 +++ |
16 | tests/tcg/configure.sh | 4 ++ | ||
17 | 5 files changed, 243 insertions(+) | ||
18 | create mode 100644 tests/tcg/aarch64/bti-1.c | ||
19 | create mode 100644 tests/tcg/aarch64/bti-2.c | ||
20 | create mode 100644 tests/tcg/aarch64/bti-crt.inc.c | ||
21 | |||
22 | diff --git a/tests/tcg/aarch64/bti-1.c b/tests/tcg/aarch64/bti-1.c | ||
23 | new file mode 100644 | ||
24 | index XXXXXXX..XXXXXXX | ||
25 | --- /dev/null | ||
26 | +++ b/tests/tcg/aarch64/bti-1.c | ||
27 | @@ -XXX,XX +XXX,XX @@ | ||
28 | +/* | ||
29 | + * Branch target identification, basic notskip cases. | ||
30 | + */ | ||
31 | + | ||
32 | +#include "bti-crt.inc.c" | ||
33 | + | ||
34 | +static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc) | ||
35 | +{ | ||
36 | + uc->uc_mcontext.pc += 8; | ||
37 | + uc->uc_mcontext.pstate = 1; | ||
38 | +} | ||
39 | + | ||
40 | +#define NOP "nop" | ||
41 | +#define BTI_N "hint #32" | ||
42 | +#define BTI_C "hint #34" | ||
43 | +#define BTI_J "hint #36" | ||
44 | +#define BTI_JC "hint #38" | ||
45 | + | ||
46 | +#define BTYPE_1(DEST) \ | ||
47 | + asm("mov %0,#1; adr x16, 1f; br x16; 1: " DEST "; mov %0,#0" \ | ||
48 | + : "=r"(skipped) : : "x16") | ||
49 | + | ||
50 | +#define BTYPE_2(DEST) \ | ||
51 | + asm("mov %0,#1; adr x16, 1f; blr x16; 1: " DEST "; mov %0,#0" \ | ||
52 | + : "=r"(skipped) : : "x16", "x30") | ||
53 | + | ||
54 | +#define BTYPE_3(DEST) \ | ||
55 | + asm("mov %0,#1; adr x15, 1f; br x15; 1: " DEST "; mov %0,#0" \ | ||
56 | + : "=r"(skipped) : : "x15") | ||
57 | + | ||
58 | +#define TEST(WHICH, DEST, EXPECT) \ | ||
59 | + do { WHICH(DEST); fail += skipped ^ EXPECT; } while (0) | ||
60 | + | ||
61 | + | ||
62 | +int main() | ||
63 | +{ | ||
64 | + int fail = 0; | ||
65 | + int skipped; | ||
66 | + | ||
67 | + /* Signal-like with SA_SIGINFO. */ | ||
68 | + signal_info(SIGILL, skip2_sigill); | ||
69 | + | ||
70 | + TEST(BTYPE_1, NOP, 1); | ||
71 | + TEST(BTYPE_1, BTI_N, 1); | ||
72 | + TEST(BTYPE_1, BTI_C, 0); | ||
73 | + TEST(BTYPE_1, BTI_J, 0); | ||
74 | + TEST(BTYPE_1, BTI_JC, 0); | ||
75 | + | ||
76 | + TEST(BTYPE_2, NOP, 1); | ||
77 | + TEST(BTYPE_2, BTI_N, 1); | ||
78 | + TEST(BTYPE_2, BTI_C, 0); | ||
79 | + TEST(BTYPE_2, BTI_J, 1); | ||
80 | + TEST(BTYPE_2, BTI_JC, 0); | ||
81 | + | ||
82 | + TEST(BTYPE_3, NOP, 1); | ||
83 | + TEST(BTYPE_3, BTI_N, 1); | ||
84 | + TEST(BTYPE_3, BTI_C, 1); | ||
85 | + TEST(BTYPE_3, BTI_J, 0); | ||
86 | + TEST(BTYPE_3, BTI_JC, 0); | ||
87 | + | ||
88 | + return fail; | ||
89 | +} | ||
90 | diff --git a/tests/tcg/aarch64/bti-2.c b/tests/tcg/aarch64/bti-2.c | ||
91 | new file mode 100644 | ||
92 | index XXXXXXX..XXXXXXX | ||
93 | --- /dev/null | ||
94 | +++ b/tests/tcg/aarch64/bti-2.c | ||
95 | @@ -XXX,XX +XXX,XX @@ | ||
96 | +/* | ||
97 | + * Branch target identification, basic notskip cases. | ||
98 | + */ | ||
99 | + | ||
100 | +#include <stdio.h> | ||
101 | +#include <signal.h> | ||
102 | +#include <string.h> | ||
103 | +#include <unistd.h> | ||
104 | +#include <sys/mman.h> | ||
105 | + | ||
106 | +#ifndef PROT_BTI | ||
107 | +#define PROT_BTI 0x10 | ||
108 | +#endif | ||
109 | + | ||
110 | +static void skip2_sigill(int sig, siginfo_t *info, void *vuc) | ||
111 | +{ | ||
112 | + ucontext_t *uc = vuc; | ||
113 | + uc->uc_mcontext.pc += 8; | ||
114 | + uc->uc_mcontext.pstate = 1; | ||
115 | +} | ||
116 | + | ||
117 | +#define NOP "nop" | ||
118 | +#define BTI_N "hint #32" | ||
119 | +#define BTI_C "hint #34" | ||
120 | +#define BTI_J "hint #36" | ||
121 | +#define BTI_JC "hint #38" | ||
122 | + | ||
123 | +#define BTYPE_1(DEST) \ | ||
124 | + "mov x1, #1\n\t" \ | ||
125 | + "adr x16, 1f\n\t" \ | ||
126 | + "br x16\n" \ | ||
127 | +"1: " DEST "\n\t" \ | ||
128 | + "mov x1, #0" | ||
129 | + | ||
130 | +#define BTYPE_2(DEST) \ | ||
131 | + "mov x1, #1\n\t" \ | ||
132 | + "adr x16, 1f\n\t" \ | ||
133 | + "blr x16\n" \ | ||
134 | +"1: " DEST "\n\t" \ | ||
135 | + "mov x1, #0" | ||
136 | + | ||
137 | +#define BTYPE_3(DEST) \ | ||
138 | + "mov x1, #1\n\t" \ | ||
139 | + "adr x15, 1f\n\t" \ | ||
140 | + "br x15\n" \ | ||
141 | +"1: " DEST "\n\t" \ | ||
142 | + "mov x1, #0" | ||
143 | + | ||
144 | +#define TEST(WHICH, DEST, EXPECT) \ | ||
145 | + WHICH(DEST) "\n" \ | ||
146 | + ".if " #EXPECT "\n\t" \ | ||
147 | + "eor x1, x1," #EXPECT "\n" \ | ||
148 | + ".endif\n\t" \ | ||
149 | + "add x0, x0, x1\n\t" | ||
150 | + | ||
151 | +asm("\n" | ||
152 | +"test_begin:\n\t" | ||
153 | + BTI_C "\n\t" | ||
154 | + "mov x2, x30\n\t" | ||
155 | + "mov x0, #0\n\t" | ||
156 | + | ||
157 | + TEST(BTYPE_1, NOP, 1) | ||
158 | + TEST(BTYPE_1, BTI_N, 1) | ||
159 | + TEST(BTYPE_1, BTI_C, 0) | ||
160 | + TEST(BTYPE_1, BTI_J, 0) | ||
161 | + TEST(BTYPE_1, BTI_JC, 0) | ||
162 | + | ||
163 | + TEST(BTYPE_2, NOP, 1) | ||
164 | + TEST(BTYPE_2, BTI_N, 1) | ||
165 | + TEST(BTYPE_2, BTI_C, 0) | ||
166 | + TEST(BTYPE_2, BTI_J, 1) | ||
167 | + TEST(BTYPE_2, BTI_JC, 0) | ||
168 | + | ||
169 | + TEST(BTYPE_3, NOP, 1) | ||
170 | + TEST(BTYPE_3, BTI_N, 1) | ||
171 | + TEST(BTYPE_3, BTI_C, 1) | ||
172 | + TEST(BTYPE_3, BTI_J, 0) | ||
173 | + TEST(BTYPE_3, BTI_JC, 0) | ||
174 | + | ||
175 | + "ret x2\n" | ||
176 | +"test_end:" | ||
177 | +); | ||
178 | + | ||
179 | +int main() | ||
180 | +{ | ||
181 | + struct sigaction sa; | ||
182 | + void *tb, *te; | ||
183 | + | ||
184 | + void *p = mmap(0, getpagesize(), | ||
185 | + PROT_EXEC | PROT_READ | PROT_WRITE | PROT_BTI, | ||
186 | + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); | ||
187 | + if (p == MAP_FAILED) { | ||
188 | + perror("mmap"); | ||
189 | + return 1; | ||
190 | + } | ||
191 | + | ||
192 | + memset(&sa, 0, sizeof(sa)); | ||
193 | + sa.sa_sigaction = skip2_sigill; | ||
194 | + sa.sa_flags = SA_SIGINFO; | ||
195 | + if (sigaction(SIGILL, &sa, NULL) < 0) { | ||
196 | + perror("sigaction"); | ||
197 | + return 1; | ||
198 | + } | ||
199 | + | ||
200 | + /* | ||
201 | + * ??? With "extern char test_begin[]", some compiler versions | ||
202 | + * will use :got references, and some linker versions will | ||
203 | + * resolve this reference to a static symbol incorrectly. | ||
204 | + * Bypass this error by using a pc-relative reference directly. | ||
205 | + */ | ||
206 | + asm("adr %0, test_begin; adr %1, test_end" : "=r"(tb), "=r"(te)); | ||
207 | + | ||
208 | + memcpy(p, tb, te - tb); | ||
209 | + | ||
210 | + return ((int (*)(void))p)(); | ||
211 | +} | ||
212 | diff --git a/tests/tcg/aarch64/bti-crt.inc.c b/tests/tcg/aarch64/bti-crt.inc.c | ||
213 | new file mode 100644 | ||
214 | index XXXXXXX..XXXXXXX | ||
215 | --- /dev/null | ||
216 | +++ b/tests/tcg/aarch64/bti-crt.inc.c | ||
217 | @@ -XXX,XX +XXX,XX @@ | ||
218 | +/* | ||
219 | + * Minimal user-environment for testing BTI. | ||
220 | + * | ||
221 | + * Normal libc is not (yet) built with BTI support enabled, | ||
222 | + * and so could generate a BTI TRAP before ever reaching main. | ||
223 | + */ | ||
224 | + | ||
225 | +#include <stdlib.h> | ||
226 | +#include <signal.h> | ||
227 | +#include <ucontext.h> | ||
228 | +#include <asm/unistd.h> | ||
229 | + | ||
230 | +int main(void); | ||
231 | + | ||
232 | +void _start(void) | ||
233 | +{ | ||
234 | + exit(main()); | ||
235 | +} | ||
236 | + | ||
237 | +void exit(int ret) | ||
238 | +{ | ||
239 | + register int x0 __asm__("x0") = ret; | ||
240 | + register int x8 __asm__("x8") = __NR_exit; | ||
241 | + | ||
242 | + asm volatile("svc #0" : : "r"(x0), "r"(x8)); | ||
243 | + __builtin_unreachable(); | ||
244 | +} | ||
245 | + | ||
246 | +/* | ||
247 | + * Irritatingly, the user API struct sigaction does not match the | ||
248 | + * kernel API struct sigaction. So for simplicity, isolate the | ||
249 | + * kernel ABI here, and make this act like signal. | ||
250 | + */ | ||
251 | +void signal_info(int sig, void (*fn)(int, siginfo_t *, ucontext_t *)) | ||
252 | +{ | ||
253 | + struct kernel_sigaction { | ||
254 | + void (*handler)(int, siginfo_t *, ucontext_t *); | ||
255 | + unsigned long flags; | ||
256 | + unsigned long restorer; | ||
257 | + unsigned long mask; | ||
258 | + } sa = { fn, SA_SIGINFO, 0, 0 }; | ||
259 | + | ||
260 | + register int x0 __asm__("x0") = sig; | ||
261 | + register void *x1 __asm__("x1") = &sa; | ||
262 | + register void *x2 __asm__("x2") = 0; | ||
263 | + register int x3 __asm__("x3") = sizeof(unsigned long); | ||
264 | + register int x8 __asm__("x8") = __NR_rt_sigaction; | ||
265 | + | ||
266 | + asm volatile("svc #0" | ||
267 | + : : "r"(x0), "r"(x1), "r"(x2), "r"(x3), "r"(x8) : "memory"); | ||
268 | +} | ||
269 | diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target | ||
12 | index XXXXXXX..XXXXXXX 100644 | 270 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate.c | 271 | --- a/tests/tcg/aarch64/Makefile.target |
14 | +++ b/target/arm/translate.c | 272 | +++ b/tests/tcg/aarch64/Makefile.target |
15 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 273 | @@ -XXX,XX +XXX,XX @@ run-pauth-%: QEMU_OPTS += -cpu max |
16 | size--; | 274 | run-plugin-pauth-%: QEMU_OPTS += -cpu max |
17 | } | 275 | endif |
18 | shift = (insn >> 16) & ((1 << (3 + size)) - 1); | 276 | |
19 | - /* To avoid excessive duplication of ops we implement shift | 277 | +# BTI Tests |
20 | - by immediate using the variable shift operations. */ | 278 | +# bti-1 tests the elf notes, so we require special compiler support. |
21 | if (op < 8) { | 279 | +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),) |
22 | /* Shift by immediate: | 280 | +AARCH64_TESTS += bti-1 |
23 | VSHR, VSRA, VRSHR, VRSRA, VSRI, VSHL, VQSHL, VQSHLU. */ | 281 | +bti-1: CFLAGS += -mbranch-protection=standard |
24 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 282 | +bti-1: LDFLAGS += -nostdlib |
25 | } | 283 | +endif |
26 | /* Right shifts are encoded as N - shift, where N is the | 284 | +# bti-2 tests PROT_BTI, so no special compiler support required. |
27 | element size in bits. */ | 285 | +AARCH64_TESTS += bti-2 |
28 | - if (op <= 4) | 286 | + |
29 | + if (op <= 4) { | 287 | # Semihosting smoke test for linux-user |
30 | shift = shift - (1 << (size + 3)); | 288 | AARCH64_TESTS += semihosting |
31 | + } | 289 | run-semihosting: semihosting |
32 | + | 290 | diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh |
33 | + switch (op) { | 291 | index XXXXXXX..XXXXXXX 100755 |
34 | + case 0: /* VSHR */ | 292 | --- a/tests/tcg/configure.sh |
35 | + /* Right shift comes here negative. */ | 293 | +++ b/tests/tcg/configure.sh |
36 | + shift = -shift; | 294 | @@ -XXX,XX +XXX,XX @@ for target in $target_list; do |
37 | + /* Shifts larger than the element size are architecturally | 295 | -march=armv8.3-a -o $TMPE $TMPC; then |
38 | + * valid. Unsigned results in all zeros; signed results | 296 | echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak |
39 | + * in all sign bits. | 297 | fi |
40 | + */ | 298 | + if do_compiler "$target_compiler" $target_compiler_cflags \ |
41 | + if (!u) { | 299 | + -mbranch-protection=standard -o $TMPE $TMPC; then |
42 | + tcg_gen_gvec_sari(size, rd_ofs, rm_ofs, | 300 | + echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak |
43 | + MIN(shift, (8 << size) - 1), | 301 | + fi |
44 | + vec_size, vec_size); | 302 | ;; |
45 | + } else if (shift >= 8 << size) { | 303 | esac |
46 | + tcg_gen_gvec_dup8i(rd_ofs, vec_size, vec_size, 0); | ||
47 | + } else { | ||
48 | + tcg_gen_gvec_shri(size, rd_ofs, rm_ofs, shift, | ||
49 | + vec_size, vec_size); | ||
50 | + } | ||
51 | + return 0; | ||
52 | + | ||
53 | + case 5: /* VSHL, VSLI */ | ||
54 | + if (!u) { /* VSHL */ | ||
55 | + /* Shifts larger than the element size are | ||
56 | + * architecturally valid and results in zero. | ||
57 | + */ | ||
58 | + if (shift >= 8 << size) { | ||
59 | + tcg_gen_gvec_dup8i(rd_ofs, vec_size, vec_size, 0); | ||
60 | + } else { | ||
61 | + tcg_gen_gvec_shli(size, rd_ofs, rm_ofs, shift, | ||
62 | + vec_size, vec_size); | ||
63 | + } | ||
64 | + return 0; | ||
65 | + } | ||
66 | + break; | ||
67 | + } | ||
68 | + | ||
69 | if (size == 3) { | ||
70 | count = q + 1; | ||
71 | } else { | ||
72 | count = q ? 4: 2; | ||
73 | } | ||
74 | - switch (size) { | ||
75 | - case 0: | ||
76 | - imm = (uint8_t) shift; | ||
77 | - imm |= imm << 8; | ||
78 | - imm |= imm << 16; | ||
79 | - break; | ||
80 | - case 1: | ||
81 | - imm = (uint16_t) shift; | ||
82 | - imm |= imm << 16; | ||
83 | - break; | ||
84 | - case 2: | ||
85 | - case 3: | ||
86 | - imm = shift; | ||
87 | - break; | ||
88 | - default: | ||
89 | - abort(); | ||
90 | - } | ||
91 | + | ||
92 | + /* To avoid excessive duplication of ops we implement shift | ||
93 | + * by immediate using the variable shift operations. | ||
94 | + */ | ||
95 | + imm = dup_const(size, shift); | ||
96 | |||
97 | for (pass = 0; pass < count; pass++) { | ||
98 | if (size == 3) { | ||
99 | neon_load_reg64(cpu_V0, rm + pass); | ||
100 | tcg_gen_movi_i64(cpu_V1, imm); | ||
101 | switch (op) { | ||
102 | - case 0: /* VSHR */ | ||
103 | case 1: /* VSRA */ | ||
104 | if (u) | ||
105 | gen_helper_neon_shl_u64(cpu_V0, cpu_V0, cpu_V1); | ||
106 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
107 | cpu_V0, cpu_V1); | ||
108 | } | ||
109 | break; | ||
110 | + default: | ||
111 | + g_assert_not_reached(); | ||
112 | } | ||
113 | if (op == 1 || op == 3) { | ||
114 | /* Accumulate. */ | ||
115 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
116 | tmp2 = tcg_temp_new_i32(); | ||
117 | tcg_gen_movi_i32(tmp2, imm); | ||
118 | switch (op) { | ||
119 | - case 0: /* VSHR */ | ||
120 | case 1: /* VSRA */ | ||
121 | GEN_NEON_INTEGER_OP(shl); | ||
122 | break; | ||
123 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
124 | case 7: /* VQSHL */ | ||
125 | GEN_NEON_INTEGER_OP_ENV(qshl); | ||
126 | break; | ||
127 | + default: | ||
128 | + g_assert_not_reached(); | ||
129 | } | ||
130 | tcg_temp_free_i32(tmp2); | ||
131 | 304 | ||
132 | -- | 305 | -- |
133 | 2.19.1 | 306 | 2.20.1 |
134 | 307 | ||
135 | 308 | diff view generated by jsdifflib |
1 | From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com> | 1 | From: Thomas Huth <thuth@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Announce 64bit addressing support. | 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. | ||
4 | 7 | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Signed-off-by: Thomas Huth <thuth@redhat.com> |
6 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 9 | Message-id: 20201020105938.23209-1-thuth@redhat.com |
7 | Message-id: 20181017213932.19973-3-edgar.iglesias@gmail.com | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 12 | --- |
11 | hw/net/cadence_gem.c | 3 ++- | 13 | hw/arm/highbank.c | 2 ++ |
12 | 1 file changed, 2 insertions(+), 1 deletion(-) | 14 | 1 file changed, 2 insertions(+) |
13 | 15 | ||
14 | diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c | 16 | diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/net/cadence_gem.c | 18 | --- a/hw/arm/highbank.c |
17 | +++ b/hw/net/cadence_gem.c | 19 | +++ b/hw/arm/highbank.c |
18 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ static void hb_reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info) |
19 | #define GEM_DESCONF4 (0x0000028C/4) | 21 | address_space_stl_notdirty(&address_space_memory, |
20 | #define GEM_DESCONF5 (0x00000290/4) | 22 | SMP_BOOT_REG + 0x30, 0, |
21 | #define GEM_DESCONF6 (0x00000294/4) | 23 | MEMTXATTRS_UNSPECIFIED, NULL); |
22 | +#define GEM_DESCONF6_64B_MASK (1U << 23) | 24 | + /* fallthrough */ |
23 | #define GEM_DESCONF7 (0x00000298/4) | 25 | case 3: |
24 | 26 | address_space_stl_notdirty(&address_space_memory, | |
25 | #define GEM_INT_Q1_STATUS (0x00000400 / 4) | 27 | SMP_BOOT_REG + 0x20, 0, |
26 | @@ -XXX,XX +XXX,XX @@ static void gem_reset(DeviceState *d) | 28 | MEMTXATTRS_UNSPECIFIED, NULL); |
27 | s->regs[GEM_DESCONF] = 0x02500111; | 29 | + /* fallthrough */ |
28 | s->regs[GEM_DESCONF2] = 0x2ab13fff; | 30 | case 2: |
29 | s->regs[GEM_DESCONF5] = 0x002f2045; | 31 | address_space_stl_notdirty(&address_space_memory, |
30 | - s->regs[GEM_DESCONF6] = 0x0; | 32 | SMP_BOOT_REG + 0x10, 0, |
31 | + s->regs[GEM_DESCONF6] = GEM_DESCONF6_64B_MASK; | ||
32 | |||
33 | if (s->num_priority_queues > 1) { | ||
34 | queues_mask = MAKE_64BIT_MASK(1, s->num_priority_queues - 1); | ||
35 | -- | 33 | -- |
36 | 2.19.1 | 34 | 2.20.1 |
37 | 35 | ||
38 | 36 | diff view generated by jsdifflib |
1 | From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com> | 1 | From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> |
---|---|---|---|
2 | 2 | ||
3 | Announce the availability of the various priority queues. | 3 | This patch sets min_cpus field for xlnx-versal-virt platform, |
4 | This fixes an issue where guest kernels would miss to | 4 | because it always creates XLNX_VERSAL_NR_ACPUS cpus even with |
5 | configure secondary queues due to inproper feature bits. | 5 | -smp 1 command line option. |
6 | 6 | ||
7 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 7 | Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> |
8 | Message-id: 20181017213932.19973-2-edgar.iglesias@gmail.com | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> |
10 | Message-id: 160343854912.8460.17915238517799132371.stgit@pasha-ThinkPad-X280 | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 12 | --- |
12 | hw/net/cadence_gem.c | 8 +++++++- | 13 | hw/arm/xlnx-versal-virt.c | 1 + |
13 | 1 file changed, 7 insertions(+), 1 deletion(-) | 14 | 1 file changed, 1 insertion(+) |
14 | 15 | ||
15 | diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c | 16 | diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c |
16 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/net/cadence_gem.c | 18 | --- a/hw/arm/xlnx-versal-virt.c |
18 | +++ b/hw/net/cadence_gem.c | 19 | +++ b/hw/arm/xlnx-versal-virt.c |
19 | @@ -XXX,XX +XXX,XX @@ static void gem_reset(DeviceState *d) | 20 | @@ -XXX,XX +XXX,XX @@ static void versal_virt_machine_class_init(ObjectClass *oc, void *data) |
20 | int i; | 21 | |
21 | CadenceGEMState *s = CADENCE_GEM(d); | 22 | mc->desc = "Xilinx Versal Virtual development board"; |
22 | const uint8_t *a; | 23 | mc->init = versal_virt_init; |
23 | + uint32_t queues_mask = 0; | 24 | + mc->min_cpus = XLNX_VERSAL_NR_ACPUS; |
24 | 25 | mc->max_cpus = XLNX_VERSAL_NR_ACPUS; | |
25 | DB_PRINT("\n"); | 26 | mc->default_cpus = XLNX_VERSAL_NR_ACPUS; |
26 | 27 | mc->no_cdrom = true; | |
27 | @@ -XXX,XX +XXX,XX @@ static void gem_reset(DeviceState *d) | ||
28 | s->regs[GEM_DESCONF] = 0x02500111; | ||
29 | s->regs[GEM_DESCONF2] = 0x2ab13fff; | ||
30 | s->regs[GEM_DESCONF5] = 0x002f2045; | ||
31 | - s->regs[GEM_DESCONF6] = 0x00000200; | ||
32 | + s->regs[GEM_DESCONF6] = 0x0; | ||
33 | + | ||
34 | + if (s->num_priority_queues > 1) { | ||
35 | + queues_mask = MAKE_64BIT_MASK(1, s->num_priority_queues - 1); | ||
36 | + s->regs[GEM_DESCONF6] |= queues_mask; | ||
37 | + } | ||
38 | |||
39 | /* Set MAC address */ | ||
40 | a = &s->conf.macaddr.a[0]; | ||
41 | -- | 28 | -- |
42 | 2.19.1 | 29 | 2.20.1 |
43 | 30 | ||
44 | 31 | diff view generated by jsdifflib |
1 | From: Stewart Hildebrand <Stewart.Hildebrand@dornerworks.com> | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | 2 | ||
3 | "The Image must be placed text_offset bytes from a 2MB aligned base | 3 | This allows us to reuse npcm7xx_timer_pause for the watchdog timer. |
4 | address anywhere in usable system RAM and called there." | ||
5 | 4 | ||
6 | For the virt board, we write our startup bootloader at the very | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
7 | bottom of RAM, so that bit can't be used for the image. To avoid | 6 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> |
8 | overlap in case the image requests to be loaded at an offset | ||
9 | smaller than our bootloader, we increment the load offset to the | ||
10 | next 2MB. | ||
11 | |||
12 | This fixes a boot failure for Xen AArch64. | ||
13 | |||
14 | Signed-off-by: Stewart Hildebrand <stewart.hildebrand@dornerworks.com> | ||
15 | Tested-by: Andre Przywara <andre.przywara@arm.com> | ||
16 | Message-id: b8a89518794b4436af0c151ed10de4fa@dornerworks.com | ||
17 | [PMM: Rephrased a comment a bit] | ||
18 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 8 | --- |
21 | hw/arm/boot.c | 18 ++++++++++++++++++ | 9 | hw/timer/npcm7xx_timer.c | 6 +++--- |
22 | 1 file changed, 18 insertions(+) | 10 | 1 file changed, 3 insertions(+), 3 deletions(-) |
23 | 11 | ||
24 | diff --git a/hw/arm/boot.c b/hw/arm/boot.c | 12 | diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c |
25 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/arm/boot.c | 14 | --- a/hw/timer/npcm7xx_timer.c |
27 | +++ b/hw/arm/boot.c | 15 | +++ b/hw/timer/npcm7xx_timer.c |
28 | @@ -XXX,XX +XXX,XX @@ | 16 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t) |
29 | #include "qemu/config-file.h" | 17 | timer_del(&t->qtimer); |
30 | #include "qemu/option.h" | 18 | now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
31 | #include "exec/address-spaces.h" | 19 | t->remaining_ns = t->expires_ns - now; |
32 | +#include "qemu/units.h" | 20 | - if (t->remaining_ns <= 0) { |
33 | 21 | - npcm7xx_timer_reached_zero(t); | |
34 | /* Kernel boot protocol is specified in the kernel docs | 22 | - } |
35 | * Documentation/arm/Booting and Documentation/arm64/booting.txt | 23 | } |
36 | @@ -XXX,XX +XXX,XX @@ | 24 | |
37 | #define ARM64_TEXT_OFFSET_OFFSET 8 | 25 | /* |
38 | #define ARM64_MAGIC_OFFSET 56 | 26 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) |
39 | 27 | } else { | |
40 | +#define BOOTLOADER_MAX_SIZE (4 * KiB) | 28 | t->tcsr &= ~NPCM7XX_TCSR_CACT; |
41 | + | 29 | npcm7xx_timer_pause(t); |
42 | AddressSpace *arm_boot_address_space(ARMCPU *cpu, | 30 | + if (t->remaining_ns <= 0) { |
43 | const struct arm_boot_info *info) | 31 | + npcm7xx_timer_reached_zero(t); |
44 | { | ||
45 | @@ -XXX,XX +XXX,XX @@ static void write_bootloader(const char *name, hwaddr addr, | ||
46 | code[i] = tswap32(insn); | ||
47 | } | ||
48 | |||
49 | + assert((len * sizeof(uint32_t)) < BOOTLOADER_MAX_SIZE); | ||
50 | + | ||
51 | rom_add_blob_fixed_as(name, code, len * sizeof(uint32_t), addr, as); | ||
52 | |||
53 | g_free(code); | ||
54 | @@ -XXX,XX +XXX,XX @@ static uint64_t load_aarch64_image(const char *filename, hwaddr mem_base, | ||
55 | memcpy(&hdrvals, buffer + ARM64_TEXT_OFFSET_OFFSET, sizeof(hdrvals)); | ||
56 | if (hdrvals[1] != 0) { | ||
57 | kernel_load_offset = le64_to_cpu(hdrvals[0]); | ||
58 | + | ||
59 | + /* | ||
60 | + * We write our startup "bootloader" at the very bottom of RAM, | ||
61 | + * so that bit can't be used for the image. Luckily the Image | ||
62 | + * format specification is that the image requests only an offset | ||
63 | + * from a 2MB boundary, not an absolute load address. So if the | ||
64 | + * image requests an offset that might mean it overlaps with the | ||
65 | + * bootloader, we can just load it starting at 2MB+offset rather | ||
66 | + * than 0MB + offset. | ||
67 | + */ | ||
68 | + if (kernel_load_offset < BOOTLOADER_MAX_SIZE) { | ||
69 | + kernel_load_offset += 2 * MiB; | ||
70 | + } | 32 | + } |
71 | } | 33 | } |
72 | } | 34 | } |
73 | 35 | } | |
74 | -- | 36 | -- |
75 | 2.19.1 | 37 | 2.20.1 |
76 | 38 | ||
77 | 39 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Instead of shifts and masks, use direct loads and stores from the neon | 3 | The watchdog is part of NPCM7XX's timer module. Its behavior is |
4 | register file. Mirror the iteration structure of the ARM pseudocode | 4 | controlled by the WTCR register in the timer. |
5 | more closely. Correct the parameters of the VLD2 A2 insn. | ||
6 | 5 | ||
7 | Note that this includes a bugfix for handling of the insn | 6 | When enabled, the watchdog issues an interrupt signal after a pre-set |
8 | "VLD2 (multiple 2-element structures)" -- we were using an | 7 | amount of cycles, and issues a reset signal shortly after that. |
9 | incorrect stride value. | ||
10 | 8 | ||
11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 9 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> |
12 | Message-id: 20181011205206.3552-19-richard.henderson@linaro.org | 10 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
11 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
13 | 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] | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | --- | 15 | --- |
16 | target/arm/translate.c | 170 ++++++++++++++++++----------------------- | 16 | include/hw/misc/npcm7xx_clk.h | 2 + |
17 | 1 file changed, 74 insertions(+), 96 deletions(-) | 17 | include/hw/timer/npcm7xx_timer.h | 48 +++- |
18 | hw/arm/npcm7xx.c | 12 + | ||
19 | hw/misc/npcm7xx_clk.c | 28 ++ | ||
20 | hw/timer/npcm7xx_timer.c | 266 ++++++++++++++---- | ||
21 | tests/qtest/npcm7xx_watchdog_timer-test.c | 319 ++++++++++++++++++++++ | ||
22 | MAINTAINERS | 1 + | ||
23 | tests/qtest/meson.build | 2 +- | ||
24 | 8 files changed, 624 insertions(+), 54 deletions(-) | ||
25 | create mode 100644 tests/qtest/npcm7xx_watchdog_timer-test.c | ||
18 | 26 | ||
19 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 27 | diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h |
20 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/translate.c | 29 | --- a/include/hw/misc/npcm7xx_clk.h |
22 | +++ b/target/arm/translate.c | 30 | +++ b/include/hw/misc/npcm7xx_clk.h |
23 | @@ -XXX,XX +XXX,XX @@ static TCGv_i32 neon_load_reg(int reg, int pass) | 31 | @@ -XXX,XX +XXX,XX @@ |
24 | return tmp; | 32 | */ |
33 | #define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) | ||
34 | |||
35 | +#define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in" | ||
36 | + | ||
37 | typedef struct NPCM7xxCLKState { | ||
38 | SysBusDevice parent; | ||
39 | |||
40 | diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_timer.h | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/include/hw/timer/npcm7xx_timer.h | ||
43 | +++ b/include/hw/timer/npcm7xx_timer.h | ||
44 | @@ -XXX,XX +XXX,XX @@ | ||
45 | */ | ||
46 | #define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t)) | ||
47 | |||
48 | +/* The basic watchdog timer period is 2^14 clock cycles. */ | ||
49 | +#define NPCM7XX_WATCHDOG_BASETIME_SHIFT 14 | ||
50 | + | ||
51 | +#define NPCM7XX_WATCHDOG_RESET_GPIO_OUT "npcm7xx-clk-watchdog-reset-gpio-out" | ||
52 | + | ||
53 | typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState; | ||
54 | |||
55 | /** | ||
56 | - * struct NPCM7xxTimer - Individual timer state. | ||
57 | - * @irq: GIC interrupt line to fire on expiration (if enabled). | ||
58 | + * struct NPCM7xxBaseTimer - Basic functionality that both regular timer and | ||
59 | + * watchdog timer use. | ||
60 | * @qtimer: QEMU timer that notifies us on expiration. | ||
61 | * @expires_ns: Absolute virtual expiration time. | ||
62 | * @remaining_ns: Remaining time until expiration if timer is paused. | ||
63 | + */ | ||
64 | +typedef struct NPCM7xxBaseTimer { | ||
65 | + QEMUTimer qtimer; | ||
66 | + int64_t expires_ns; | ||
67 | + int64_t remaining_ns; | ||
68 | +} NPCM7xxBaseTimer; | ||
69 | + | ||
70 | +/** | ||
71 | + * struct NPCM7xxTimer - Individual timer state. | ||
72 | + * @ctrl: The timer module that owns this timer. | ||
73 | + * @irq: GIC interrupt line to fire on expiration (if enabled). | ||
74 | + * @base_timer: The basic timer functionality for this timer. | ||
75 | * @tcsr: The Timer Control and Status Register. | ||
76 | * @ticr: The Timer Initial Count Register. | ||
77 | */ | ||
78 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxTimer { | ||
79 | NPCM7xxTimerCtrlState *ctrl; | ||
80 | |||
81 | qemu_irq irq; | ||
82 | - QEMUTimer qtimer; | ||
83 | - int64_t expires_ns; | ||
84 | - int64_t remaining_ns; | ||
85 | + NPCM7xxBaseTimer base_timer; | ||
86 | |||
87 | uint32_t tcsr; | ||
88 | uint32_t ticr; | ||
89 | } NPCM7xxTimer; | ||
90 | |||
91 | +/** | ||
92 | + * struct NPCM7xxWatchdogTimer - The watchdog timer state. | ||
93 | + * @ctrl: The timer module that owns this timer. | ||
94 | + * @irq: GIC interrupt line to fire on expiration (if enabled). | ||
95 | + * @reset_signal: The GPIO used to send a reset signal. | ||
96 | + * @base_timer: The basic timer functionality for this timer. | ||
97 | + * @wtcr: The Watchdog Timer Control Register. | ||
98 | + */ | ||
99 | +typedef struct NPCM7xxWatchdogTimer { | ||
100 | + NPCM7xxTimerCtrlState *ctrl; | ||
101 | + | ||
102 | + qemu_irq irq; | ||
103 | + qemu_irq reset_signal; | ||
104 | + NPCM7xxBaseTimer base_timer; | ||
105 | + | ||
106 | + uint32_t wtcr; | ||
107 | +} NPCM7xxWatchdogTimer; | ||
108 | + | ||
109 | /** | ||
110 | * struct NPCM7xxTimerCtrlState - Timer Module device state. | ||
111 | * @parent: System bus device. | ||
112 | * @iomem: Memory region through which registers are accessed. | ||
113 | + * @index: The index of this timer module. | ||
114 | * @tisr: The Timer Interrupt Status Register. | ||
115 | - * @wtcr: The Watchdog Timer Control Register. | ||
116 | * @timer: The five individual timers managed by this module. | ||
117 | + * @watchdog_timer: The watchdog timer managed by this module. | ||
118 | */ | ||
119 | struct NPCM7xxTimerCtrlState { | ||
120 | SysBusDevice parent; | ||
121 | @@ -XXX,XX +XXX,XX @@ struct NPCM7xxTimerCtrlState { | ||
122 | MemoryRegion iomem; | ||
123 | |||
124 | uint32_t tisr; | ||
125 | - uint32_t wtcr; | ||
126 | |||
127 | NPCM7xxTimer timer[NPCM7XX_TIMERS_PER_CTRL]; | ||
128 | + NPCM7xxWatchdogTimer watchdog_timer; | ||
129 | }; | ||
130 | |||
131 | #define TYPE_NPCM7XX_TIMER "npcm7xx-timer" | ||
132 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
133 | index XXXXXXX..XXXXXXX 100644 | ||
134 | --- a/hw/arm/npcm7xx.c | ||
135 | +++ b/hw/arm/npcm7xx.c | ||
136 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { | ||
137 | NPCM7XX_TIMER12_IRQ, | ||
138 | NPCM7XX_TIMER13_IRQ, | ||
139 | NPCM7XX_TIMER14_IRQ, | ||
140 | + NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */ | ||
141 | + NPCM7XX_WDG1_IRQ, /* Timer Module 1 Watchdog */ | ||
142 | + NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ | ||
143 | }; | ||
144 | |||
145 | /* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ | ||
146 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
147 | qemu_irq irq = npcm7xx_irq(s, first_irq + j); | ||
148 | sysbus_connect_irq(sbd, j, irq); | ||
149 | } | ||
150 | + | ||
151 | + /* IRQ for watchdogs */ | ||
152 | + sysbus_connect_irq(sbd, NPCM7XX_TIMERS_PER_CTRL, | ||
153 | + npcm7xx_irq(s, NPCM7XX_WDG0_IRQ + i)); | ||
154 | + /* GPIO that connects clk module with watchdog */ | ||
155 | + qdev_connect_gpio_out_named(DEVICE(&s->tim[i]), | ||
156 | + NPCM7XX_WATCHDOG_RESET_GPIO_OUT, 0, | ||
157 | + qdev_get_gpio_in_named(DEVICE(&s->clk), | ||
158 | + NPCM7XX_WATCHDOG_RESET_GPIO_IN, i)); | ||
159 | } | ||
160 | |||
161 | /* UART0..3 (16550 compatible) */ | ||
162 | diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c | ||
163 | index XXXXXXX..XXXXXXX 100644 | ||
164 | --- a/hw/misc/npcm7xx_clk.c | ||
165 | +++ b/hw/misc/npcm7xx_clk.c | ||
166 | @@ -XXX,XX +XXX,XX @@ | ||
167 | #include "qemu/osdep.h" | ||
168 | |||
169 | #include "hw/misc/npcm7xx_clk.h" | ||
170 | +#include "hw/timer/npcm7xx_timer.h" | ||
171 | #include "migration/vmstate.h" | ||
172 | #include "qemu/error-report.h" | ||
173 | #include "qemu/log.h" | ||
174 | @@ -XXX,XX +XXX,XX @@ | ||
175 | #include "qemu/timer.h" | ||
176 | #include "qemu/units.h" | ||
177 | #include "trace.h" | ||
178 | +#include "sysemu/watchdog.h" | ||
179 | |||
180 | #define PLLCON_LOKI BIT(31) | ||
181 | #define PLLCON_LOKS BIT(30) | ||
182 | @@ -XXX,XX +XXX,XX @@ static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] = { | ||
183 | [NPCM7XX_CLK_AHBCKFI] = 0x000000c8, | ||
184 | }; | ||
185 | |||
186 | +/* Register Field Definitions */ | ||
187 | +#define NPCM7XX_CLK_WDRCR_CA9C BIT(0) /* Cortex A9 Cores */ | ||
188 | + | ||
189 | +/* The number of watchdogs that can trigger a reset. */ | ||
190 | +#define NPCM7XX_NR_WATCHDOGS (3) | ||
191 | + | ||
192 | static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size) | ||
193 | { | ||
194 | uint32_t reg = offset / sizeof(uint32_t); | ||
195 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_write(void *opaque, hwaddr offset, | ||
196 | s->regs[reg] = value; | ||
25 | } | 197 | } |
26 | 198 | ||
27 | +static void neon_load_element64(TCGv_i64 var, int reg, int ele, TCGMemOp mop) | 199 | +/* Perform reset action triggered by a watchdog */ |
28 | +{ | 200 | +static void npcm7xx_clk_perform_watchdog_reset(void *opaque, int n, |
29 | + long offset = neon_element_offset(reg, ele, mop & MO_SIZE); | 201 | + int level) |
30 | + | 202 | +{ |
31 | + switch (mop) { | 203 | + NPCM7xxCLKState *clk = NPCM7XX_CLK(opaque); |
32 | + case MO_UB: | 204 | + uint32_t rcr; |
33 | + tcg_gen_ld8u_i64(var, cpu_env, offset); | 205 | + |
34 | + break; | 206 | + g_assert(n >= 0 && n <= NPCM7XX_NR_WATCHDOGS); |
35 | + case MO_UW: | 207 | + rcr = clk->regs[NPCM7XX_CLK_WD0RCR + n]; |
36 | + tcg_gen_ld16u_i64(var, cpu_env, offset); | 208 | + if (rcr & NPCM7XX_CLK_WDRCR_CA9C) { |
37 | + break; | 209 | + watchdog_perform_action(); |
38 | + case MO_UL: | 210 | + } else { |
39 | + tcg_gen_ld32u_i64(var, cpu_env, offset); | 211 | + qemu_log_mask(LOG_UNIMP, |
40 | + break; | 212 | + "%s: only CPU reset is implemented. (requested 0x%" PRIx32")\n", |
41 | + case MO_Q: | 213 | + __func__, rcr); |
42 | + tcg_gen_ld_i64(var, cpu_env, offset); | 214 | + } |
43 | + break; | 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; | ||
44 | + default: | 307 | + default: |
45 | + g_assert_not_reached(); | 308 | + g_assert_not_reached(); |
46 | + } | 309 | + } |
47 | +} | 310 | +} |
48 | + | 311 | + |
49 | static void neon_store_reg(int reg, int pass, TCGv_i32 var) | 312 | +static void npcm7xx_watchdog_timer_reset_cycles(NPCM7xxWatchdogTimer *t, |
313 | + int64_t cycles) | ||
314 | +{ | ||
315 | + uint32_t prescaler = npcm7xx_watchdog_timer_prescaler(t); | ||
316 | + int64_t ns = (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ) * cycles; | ||
317 | + | ||
318 | + /* | ||
319 | + * The reset function always clears the current timer. The caller of the | ||
320 | + * this needs to decide whether to start the watchdog timer based on | ||
321 | + * specific flag in WTCR. | ||
322 | + */ | ||
323 | + npcm7xx_timer_clear(&t->base_timer); | ||
324 | + | ||
325 | + ns *= prescaler; | ||
326 | + t->base_timer.remaining_ns = ns; | ||
327 | +} | ||
328 | + | ||
329 | +static void npcm7xx_watchdog_timer_reset(NPCM7xxWatchdogTimer *t) | ||
330 | +{ | ||
331 | + int64_t cycles = 1; | ||
332 | + uint32_t s = NPCM7XX_WTCR_WTIS(t->wtcr); | ||
333 | + | ||
334 | + g_assert(s <= 3); | ||
335 | + | ||
336 | + cycles <<= NPCM7XX_WATCHDOG_BASETIME_SHIFT; | ||
337 | + cycles <<= 2 * s; | ||
338 | + | ||
339 | + npcm7xx_watchdog_timer_reset_cycles(t, cycles); | ||
340 | +} | ||
341 | + | ||
342 | /* | ||
343 | * Raise the interrupt line if there's a pending interrupt and interrupts are | ||
344 | * enabled for this timer. If not, lower it. | ||
345 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_check_interrupt(NPCM7xxTimer *t) | ||
346 | trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, pending); | ||
347 | } | ||
348 | |||
349 | -/* Start or resume the timer. */ | ||
350 | -static void npcm7xx_timer_start(NPCM7xxTimer *t) | ||
351 | -{ | ||
352 | - int64_t now; | ||
353 | - | ||
354 | - now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
355 | - t->expires_ns = now + t->remaining_ns; | ||
356 | - timer_mod(&t->qtimer, t->expires_ns); | ||
357 | -} | ||
358 | - | ||
359 | /* | ||
360 | * Called when the counter reaches zero. Sets the interrupt flag, and either | ||
361 | * restarts or disables the timer. | ||
362 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t) | ||
363 | tc->tisr |= BIT(index); | ||
364 | |||
365 | if (t->tcsr & NPCM7XX_TCSR_PERIODIC) { | ||
366 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); | ||
367 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); | ||
368 | if (t->tcsr & NPCM7XX_TCSR_CEN) { | ||
369 | - npcm7xx_timer_start(t); | ||
370 | + npcm7xx_timer_start(&t->base_timer); | ||
371 | } | ||
372 | } else { | ||
373 | t->tcsr &= ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT); | ||
374 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t) | ||
375 | npcm7xx_timer_check_interrupt(t); | ||
376 | } | ||
377 | |||
378 | -/* Stop counting. Record the time remaining so we can continue later. */ | ||
379 | -static void npcm7xx_timer_pause(NPCM7xxTimer *t) | ||
380 | -{ | ||
381 | - int64_t now; | ||
382 | - | ||
383 | - timer_del(&t->qtimer); | ||
384 | - now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
385 | - t->remaining_ns = t->expires_ns - now; | ||
386 | -} | ||
387 | |||
388 | /* | ||
389 | * Restart the timer from its initial value. If the timer was enabled and stays | ||
390 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t) | ||
391 | */ | ||
392 | static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr) | ||
50 | { | 393 | { |
51 | tcg_gen_st_i32(var, cpu_env, neon_reg_offset(reg, pass)); | 394 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); |
52 | tcg_temp_free_i32(var); | 395 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); |
396 | |||
397 | if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { | ||
398 | - npcm7xx_timer_start(t); | ||
399 | + npcm7xx_timer_start(&t->base_timer); | ||
400 | } | ||
53 | } | 401 | } |
54 | 402 | ||
55 | +static void neon_store_element64(int reg, int ele, TCGMemOp size, TCGv_i64 var) | 403 | @@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_timer_read_tdr(NPCM7xxTimer *t) |
56 | +{ | 404 | if (t->tcsr & NPCM7XX_TCSR_CEN) { |
57 | + long offset = neon_element_offset(reg, ele, size); | 405 | int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
58 | + | 406 | |
59 | + switch (size) { | 407 | - return npcm7xx_timer_ns_to_count(t, t->expires_ns - now); |
60 | + case MO_8: | 408 | + return npcm7xx_timer_ns_to_count(t, t->base_timer.expires_ns - now); |
61 | + tcg_gen_st8_i64(var, cpu_env, offset); | 409 | } |
62 | + break; | 410 | |
63 | + case MO_16: | 411 | - return npcm7xx_timer_ns_to_count(t, t->remaining_ns); |
64 | + tcg_gen_st16_i64(var, cpu_env, offset); | 412 | + return npcm7xx_timer_ns_to_count(t, t->base_timer.remaining_ns); |
65 | + break; | 413 | } |
66 | + case MO_32: | 414 | |
67 | + tcg_gen_st32_i64(var, cpu_env, offset); | 415 | static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) |
68 | + break; | 416 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) |
69 | + case MO_64: | 417 | |
70 | + tcg_gen_st_i64(var, cpu_env, offset); | 418 | if (npcm7xx_tcsr_prescaler(old_tcsr) != npcm7xx_tcsr_prescaler(new_tcsr)) { |
71 | + break; | 419 | /* Recalculate time remaining based on the current TDR value. */ |
420 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, tdr); | ||
421 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, tdr); | ||
422 | if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { | ||
423 | - npcm7xx_timer_start(t); | ||
424 | + npcm7xx_timer_start(&t->base_timer); | ||
425 | } | ||
426 | } | ||
427 | |||
428 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) | ||
429 | if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_CEN) { | ||
430 | if (new_tcsr & NPCM7XX_TCSR_CEN) { | ||
431 | t->tcsr |= NPCM7XX_TCSR_CACT; | ||
432 | - npcm7xx_timer_start(t); | ||
433 | + npcm7xx_timer_start(&t->base_timer); | ||
434 | } else { | ||
435 | t->tcsr &= ~NPCM7XX_TCSR_CACT; | ||
436 | - npcm7xx_timer_pause(t); | ||
437 | - if (t->remaining_ns <= 0) { | ||
438 | + npcm7xx_timer_pause(&t->base_timer); | ||
439 | + if (t->base_timer.remaining_ns <= 0) { | ||
440 | npcm7xx_timer_reached_zero(t); | ||
441 | } | ||
442 | } | ||
443 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tisr(NPCM7xxTimerCtrlState *s, uint32_t value) | ||
444 | if (value & (1U << i)) { | ||
445 | npcm7xx_timer_check_interrupt(&s->timer[i]); | ||
446 | } | ||
447 | + | ||
448 | } | ||
449 | } | ||
450 | |||
451 | +static void npcm7xx_timer_write_wtcr(NPCM7xxWatchdogTimer *t, uint32_t new_wtcr) | ||
452 | +{ | ||
453 | + uint32_t old_wtcr = t->wtcr; | ||
454 | + | ||
455 | + /* | ||
456 | + * WTIF and WTRF are cleared by writing 1. Writing 0 makes these bits | ||
457 | + * unchanged. | ||
458 | + */ | ||
459 | + if (new_wtcr & NPCM7XX_WTCR_WTIF) { | ||
460 | + new_wtcr &= ~NPCM7XX_WTCR_WTIF; | ||
461 | + } else if (old_wtcr & NPCM7XX_WTCR_WTIF) { | ||
462 | + new_wtcr |= NPCM7XX_WTCR_WTIF; | ||
463 | + } | ||
464 | + if (new_wtcr & NPCM7XX_WTCR_WTRF) { | ||
465 | + new_wtcr &= ~NPCM7XX_WTCR_WTRF; | ||
466 | + } else if (old_wtcr & NPCM7XX_WTCR_WTRF) { | ||
467 | + new_wtcr |= NPCM7XX_WTCR_WTRF; | ||
468 | + } | ||
469 | + | ||
470 | + t->wtcr = new_wtcr; | ||
471 | + | ||
472 | + if (new_wtcr & NPCM7XX_WTCR_WTR) { | ||
473 | + t->wtcr &= ~NPCM7XX_WTCR_WTR; | ||
474 | + npcm7xx_watchdog_timer_reset(t); | ||
475 | + if (new_wtcr & NPCM7XX_WTCR_WTE) { | ||
476 | + npcm7xx_timer_start(&t->base_timer); | ||
477 | + } | ||
478 | + } else if ((old_wtcr ^ new_wtcr) & NPCM7XX_WTCR_WTE) { | ||
479 | + if (new_wtcr & NPCM7XX_WTCR_WTE) { | ||
480 | + npcm7xx_timer_start(&t->base_timer); | ||
481 | + } else { | ||
482 | + npcm7xx_timer_pause(&t->base_timer); | ||
483 | + } | ||
484 | + } | ||
485 | + | ||
486 | +} | ||
487 | + | ||
488 | static hwaddr npcm7xx_tcsr_index(hwaddr reg) | ||
489 | { | ||
490 | switch (reg) { | ||
491 | @@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_timer_read(void *opaque, hwaddr offset, unsigned size) | ||
492 | break; | ||
493 | |||
494 | case NPCM7XX_TIMER_WTCR: | ||
495 | - value = s->wtcr; | ||
496 | + value = s->watchdog_timer.wtcr; | ||
497 | break; | ||
498 | |||
499 | default: | ||
500 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write(void *opaque, hwaddr offset, | ||
501 | return; | ||
502 | |||
503 | case NPCM7XX_TIMER_WTCR: | ||
504 | - qemu_log_mask(LOG_UNIMP, "%s: WTCR write not implemented: 0x%08x\n", | ||
505 | - __func__, value); | ||
506 | + npcm7xx_timer_write_wtcr(&s->watchdog_timer, value); | ||
507 | return; | ||
508 | } | ||
509 | |||
510 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_enter_reset(Object *obj, ResetType type) | ||
511 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { | ||
512 | NPCM7xxTimer *t = &s->timer[i]; | ||
513 | |||
514 | - timer_del(&t->qtimer); | ||
515 | - t->expires_ns = 0; | ||
516 | - t->remaining_ns = 0; | ||
517 | + npcm7xx_timer_clear(&t->base_timer); | ||
518 | t->tcsr = 0x00000005; | ||
519 | t->ticr = 0x00000000; | ||
520 | } | ||
521 | |||
522 | s->tisr = 0x00000000; | ||
523 | - s->wtcr = 0x00000400; | ||
524 | + /* | ||
525 | + * Set WTCLK to 1(default) and reset all flags except WTRF. | ||
526 | + * WTRF is not reset during a core domain reset. | ||
527 | + */ | ||
528 | + s->watchdog_timer.wtcr = 0x00000400 | (s->watchdog_timer.wtcr & | ||
529 | + NPCM7XX_WTCR_WTRF); | ||
530 | +} | ||
531 | + | ||
532 | +static void npcm7xx_watchdog_timer_expired(void *opaque) | ||
533 | +{ | ||
534 | + NPCM7xxWatchdogTimer *t = opaque; | ||
535 | + | ||
536 | + if (t->wtcr & NPCM7XX_WTCR_WTE) { | ||
537 | + if (t->wtcr & NPCM7XX_WTCR_WTIF) { | ||
538 | + if (t->wtcr & NPCM7XX_WTCR_WTRE) { | ||
539 | + t->wtcr |= NPCM7XX_WTCR_WTRF; | ||
540 | + /* send reset signal to CLK module*/ | ||
541 | + qemu_irq_raise(t->reset_signal); | ||
542 | + } | ||
543 | + } else { | ||
544 | + t->wtcr |= NPCM7XX_WTCR_WTIF; | ||
545 | + if (t->wtcr & NPCM7XX_WTCR_WTIE) { | ||
546 | + /* send interrupt */ | ||
547 | + qemu_irq_raise(t->irq); | ||
548 | + } | ||
549 | + npcm7xx_watchdog_timer_reset_cycles(t, | ||
550 | + NPCM7XX_WATCHDOG_INTERRUPT_TO_RESET_CYCLES); | ||
551 | + npcm7xx_timer_start(&t->base_timer); | ||
552 | + } | ||
553 | + } | ||
554 | } | ||
555 | |||
556 | static void npcm7xx_timer_hold_reset(Object *obj) | ||
557 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_hold_reset(Object *obj) | ||
558 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { | ||
559 | qemu_irq_lower(s->timer[i].irq); | ||
560 | } | ||
561 | + qemu_irq_lower(s->watchdog_timer.irq); | ||
562 | } | ||
563 | |||
564 | static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) | ||
565 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) | ||
566 | NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(dev); | ||
567 | SysBusDevice *sbd = &s->parent; | ||
568 | int i; | ||
569 | + NPCM7xxWatchdogTimer *w; | ||
570 | |||
571 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { | ||
572 | NPCM7xxTimer *t = &s->timer[i]; | ||
573 | t->ctrl = s; | ||
574 | - timer_init_ns(&t->qtimer, QEMU_CLOCK_VIRTUAL, npcm7xx_timer_expired, t); | ||
575 | + timer_init_ns(&t->base_timer.qtimer, QEMU_CLOCK_VIRTUAL, | ||
576 | + npcm7xx_timer_expired, t); | ||
577 | sysbus_init_irq(sbd, &t->irq); | ||
578 | } | ||
579 | |||
580 | + w = &s->watchdog_timer; | ||
581 | + w->ctrl = s; | ||
582 | + timer_init_ns(&w->base_timer.qtimer, QEMU_CLOCK_VIRTUAL, | ||
583 | + npcm7xx_watchdog_timer_expired, w); | ||
584 | + sysbus_init_irq(sbd, &w->irq); | ||
585 | + | ||
586 | memory_region_init_io(&s->iomem, OBJECT(s), &npcm7xx_timer_ops, s, | ||
587 | TYPE_NPCM7XX_TIMER, 4 * KiB); | ||
588 | sysbus_init_mmio(sbd, &s->iomem); | ||
589 | + qdev_init_gpio_out_named(dev, &w->reset_signal, | ||
590 | + NPCM7XX_WATCHDOG_RESET_GPIO_OUT, 1); | ||
591 | } | ||
592 | |||
593 | -static const VMStateDescription vmstate_npcm7xx_timer = { | ||
594 | - .name = "npcm7xx-timer", | ||
595 | +static const VMStateDescription vmstate_npcm7xx_base_timer = { | ||
596 | + .name = "npcm7xx-base-timer", | ||
597 | .version_id = 0, | ||
598 | .minimum_version_id = 0, | ||
599 | .fields = (VMStateField[]) { | ||
600 | - VMSTATE_TIMER(qtimer, NPCM7xxTimer), | ||
601 | - VMSTATE_INT64(expires_ns, NPCM7xxTimer), | ||
602 | - VMSTATE_INT64(remaining_ns, NPCM7xxTimer), | ||
603 | + VMSTATE_TIMER(qtimer, NPCM7xxBaseTimer), | ||
604 | + VMSTATE_INT64(expires_ns, NPCM7xxBaseTimer), | ||
605 | + VMSTATE_INT64(remaining_ns, NPCM7xxBaseTimer), | ||
606 | + VMSTATE_END_OF_LIST(), | ||
607 | + }, | ||
608 | +}; | ||
609 | + | ||
610 | +static const VMStateDescription vmstate_npcm7xx_timer = { | ||
611 | + .name = "npcm7xx-timer", | ||
612 | + .version_id = 1, | ||
613 | + .minimum_version_id = 1, | ||
614 | + .fields = (VMStateField[]) { | ||
615 | + VMSTATE_STRUCT(base_timer, NPCM7xxTimer, | ||
616 | + 0, vmstate_npcm7xx_base_timer, | ||
617 | + NPCM7xxBaseTimer), | ||
618 | VMSTATE_UINT32(tcsr, NPCM7xxTimer), | ||
619 | VMSTATE_UINT32(ticr, NPCM7xxTimer), | ||
620 | VMSTATE_END_OF_LIST(), | ||
621 | }, | ||
622 | }; | ||
623 | |||
624 | -static const VMStateDescription vmstate_npcm7xx_timer_ctrl = { | ||
625 | - .name = "npcm7xx-timer-ctrl", | ||
626 | +static const VMStateDescription vmstate_npcm7xx_watchdog_timer = { | ||
627 | + .name = "npcm7xx-watchdog-timer", | ||
628 | .version_id = 0, | ||
629 | .minimum_version_id = 0, | ||
630 | + .fields = (VMStateField[]) { | ||
631 | + VMSTATE_STRUCT(base_timer, NPCM7xxWatchdogTimer, | ||
632 | + 0, vmstate_npcm7xx_base_timer, | ||
633 | + NPCM7xxBaseTimer), | ||
634 | + VMSTATE_UINT32(wtcr, NPCM7xxWatchdogTimer), | ||
635 | + VMSTATE_END_OF_LIST(), | ||
636 | + }, | ||
637 | +}; | ||
638 | + | ||
639 | +static const VMStateDescription vmstate_npcm7xx_timer_ctrl = { | ||
640 | + .name = "npcm7xx-timer-ctrl", | ||
641 | + .version_id = 1, | ||
642 | + .minimum_version_id = 1, | ||
643 | .fields = (VMStateField[]) { | ||
644 | VMSTATE_UINT32(tisr, NPCM7xxTimerCtrlState), | ||
645 | - VMSTATE_UINT32(wtcr, NPCM7xxTimerCtrlState), | ||
646 | VMSTATE_STRUCT_ARRAY(timer, NPCM7xxTimerCtrlState, | ||
647 | NPCM7XX_TIMERS_PER_CTRL, 0, vmstate_npcm7xx_timer, | ||
648 | NPCM7xxTimer), | ||
649 | + VMSTATE_STRUCT(watchdog_timer, NPCM7xxTimerCtrlState, | ||
650 | + 0, vmstate_npcm7xx_watchdog_timer, | ||
651 | + NPCM7xxWatchdogTimer), | ||
652 | VMSTATE_END_OF_LIST(), | ||
653 | }, | ||
654 | }; | ||
655 | diff --git a/tests/qtest/npcm7xx_watchdog_timer-test.c b/tests/qtest/npcm7xx_watchdog_timer-test.c | ||
656 | new file mode 100644 | ||
657 | index XXXXXXX..XXXXXXX | ||
658 | --- /dev/null | ||
659 | +++ b/tests/qtest/npcm7xx_watchdog_timer-test.c | ||
660 | @@ -XXX,XX +XXX,XX @@ | ||
661 | +/* | ||
662 | + * QTests for Nuvoton NPCM7xx Timer Watchdog Modules. | ||
663 | + * | ||
664 | + * Copyright 2020 Google LLC | ||
665 | + * | ||
666 | + * This program is free software; you can redistribute it and/or modify it | ||
667 | + * under the terms of the GNU General Public License as published by the | ||
668 | + * Free Software Foundation; either version 2 of the License, or | ||
669 | + * (at your option) any later version. | ||
670 | + * | ||
671 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
672 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
673 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
674 | + * for more details. | ||
675 | + */ | ||
676 | + | ||
677 | +#include "qemu/osdep.h" | ||
678 | +#include "qemu/timer.h" | ||
679 | + | ||
680 | +#include "libqos/libqtest.h" | ||
681 | +#include "qapi/qmp/qdict.h" | ||
682 | + | ||
683 | +#define WTCR_OFFSET 0x1c | ||
684 | +#define REF_HZ (25000000) | ||
685 | + | ||
686 | +/* WTCR bit fields */ | ||
687 | +#define WTCLK(rv) ((rv) << 10) | ||
688 | +#define WTE BIT(7) | ||
689 | +#define WTIE BIT(6) | ||
690 | +#define WTIS(rv) ((rv) << 4) | ||
691 | +#define WTIF BIT(3) | ||
692 | +#define WTRF BIT(2) | ||
693 | +#define WTRE BIT(1) | ||
694 | +#define WTR BIT(0) | ||
695 | + | ||
696 | +typedef struct Watchdog { | ||
697 | + int irq; | ||
698 | + uint64_t base_addr; | ||
699 | +} Watchdog; | ||
700 | + | ||
701 | +static const Watchdog watchdog_list[] = { | ||
702 | + { | ||
703 | + .irq = 47, | ||
704 | + .base_addr = 0xf0008000 | ||
705 | + }, | ||
706 | + { | ||
707 | + .irq = 48, | ||
708 | + .base_addr = 0xf0009000 | ||
709 | + }, | ||
710 | + { | ||
711 | + .irq = 49, | ||
712 | + .base_addr = 0xf000a000 | ||
713 | + } | ||
714 | +}; | ||
715 | + | ||
716 | +static int watchdog_index(const Watchdog *wd) | ||
717 | +{ | ||
718 | + ptrdiff_t diff = wd - watchdog_list; | ||
719 | + | ||
720 | + g_assert(diff >= 0 && diff < ARRAY_SIZE(watchdog_list)); | ||
721 | + | ||
722 | + return diff; | ||
723 | +} | ||
724 | + | ||
725 | +static uint32_t watchdog_read_wtcr(QTestState *qts, const Watchdog *wd) | ||
726 | +{ | ||
727 | + return qtest_readl(qts, wd->base_addr + WTCR_OFFSET); | ||
728 | +} | ||
729 | + | ||
730 | +static void watchdog_write_wtcr(QTestState *qts, const Watchdog *wd, | ||
731 | + uint32_t value) | ||
732 | +{ | ||
733 | + qtest_writel(qts, wd->base_addr + WTCR_OFFSET, value); | ||
734 | +} | ||
735 | + | ||
736 | +static uint32_t watchdog_prescaler(QTestState *qts, const Watchdog *wd) | ||
737 | +{ | ||
738 | + switch (extract32(watchdog_read_wtcr(qts, wd), 10, 2)) { | ||
739 | + case 0: | ||
740 | + return 1; | ||
741 | + case 1: | ||
742 | + return 256; | ||
743 | + case 2: | ||
744 | + return 2048; | ||
745 | + case 3: | ||
746 | + return 65536; | ||
72 | + default: | 747 | + default: |
73 | + g_assert_not_reached(); | 748 | + g_assert_not_reached(); |
74 | + } | 749 | + } |
75 | +} | 750 | +} |
76 | + | 751 | + |
77 | static inline void neon_load_reg64(TCGv_i64 var, int reg) | 752 | +static QDict *get_watchdog_action(QTestState *qts) |
78 | { | 753 | +{ |
79 | tcg_gen_ld_i64(var, cpu_env, vfp_reg_offset(1, reg)); | 754 | + QDict *ev = qtest_qmp_eventwait_ref(qts, "WATCHDOG"); |
80 | @@ -XXX,XX +XXX,XX @@ static struct { | 755 | + QDict *data; |
81 | int interleave; | 756 | + |
82 | int spacing; | 757 | + data = qdict_get_qdict(ev, "data"); |
83 | } const neon_ls_element_type[11] = { | 758 | + qobject_ref(data); |
84 | - {4, 4, 1}, | 759 | + qobject_unref(ev); |
85 | - {4, 4, 2}, | 760 | + return data; |
86 | + {1, 4, 1}, | 761 | +} |
87 | + {1, 4, 2}, | 762 | + |
88 | {4, 1, 1}, | 763 | +#define RESET_CYCLES 1024 |
89 | - {4, 2, 1}, | 764 | +static uint32_t watchdog_interrupt_cycles(QTestState *qts, const Watchdog *wd) |
90 | - {3, 3, 1}, | 765 | +{ |
91 | - {3, 3, 2}, | 766 | + uint32_t wtis = extract32(watchdog_read_wtcr(qts, wd), 4, 2); |
92 | + {2, 2, 2}, | 767 | + return 1 << (14 + 2 * wtis); |
93 | + {1, 3, 1}, | 768 | +} |
94 | + {1, 3, 2}, | 769 | + |
95 | {3, 1, 1}, | 770 | +static int64_t watchdog_calculate_steps(uint32_t count, uint32_t prescale) |
96 | {1, 1, 1}, | 771 | +{ |
97 | - {2, 2, 1}, | 772 | + return (NANOSECONDS_PER_SECOND / REF_HZ) * count * prescale; |
98 | - {2, 2, 2}, | 773 | +} |
99 | + {1, 2, 1}, | 774 | + |
100 | + {1, 2, 2}, | 775 | +static int64_t watchdog_interrupt_steps(QTestState *qts, const Watchdog *wd) |
101 | {2, 1, 1} | 776 | +{ |
102 | }; | 777 | + return watchdog_calculate_steps(watchdog_interrupt_cycles(qts, wd), |
103 | 778 | + watchdog_prescaler(qts, wd)); | |
104 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | 779 | +} |
105 | int shift; | 780 | + |
106 | int n; | 781 | +/* Check wtcr can be reset to default value */ |
107 | int vec_size; | 782 | +static void test_init(gconstpointer watchdog) |
108 | + int mmu_idx; | 783 | +{ |
109 | + TCGMemOp endian; | 784 | + const Watchdog *wd = watchdog; |
110 | TCGv_i32 addr; | 785 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
111 | TCGv_i32 tmp; | 786 | + |
112 | TCGv_i32 tmp2; | 787 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
113 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | 788 | + |
114 | rn = (insn >> 16) & 0xf; | 789 | + watchdog_write_wtcr(qts, wd, WTCLK(1) | WTRF | WTIF | WTR); |
115 | rm = insn & 0xf; | 790 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(1)); |
116 | load = (insn & (1 << 21)) != 0; | 791 | + |
117 | + endian = s->be_data; | 792 | + qtest_quit(qts); |
118 | + mmu_idx = get_mem_index(s); | 793 | +} |
119 | if ((insn & (1 << 23)) == 0) { | 794 | + |
120 | /* Load store all elements. */ | 795 | +/* Check a watchdog can generate interrupt and reset actions */ |
121 | op = (insn >> 8) & 0xf; | 796 | +static void test_reset_action(gconstpointer watchdog) |
122 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | 797 | +{ |
123 | nregs = neon_ls_element_type[op].nregs; | 798 | + const Watchdog *wd = watchdog; |
124 | interleave = neon_ls_element_type[op].interleave; | 799 | + QTestState *qts = qtest_init("-machine quanta-gsj"); |
125 | spacing = neon_ls_element_type[op].spacing; | 800 | + QDict *ad; |
126 | - if (size == 3 && (interleave | spacing) != 1) | 801 | + |
127 | + if (size == 3 && (interleave | spacing) != 1) { | 802 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
128 | return 1; | 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); | ||
129 | + } | 855 | + } |
130 | + tmp64 = tcg_temp_new_i64(); | 856 | + } |
131 | addr = tcg_temp_new_i32(); | 857 | +} |
132 | + tmp2 = tcg_const_i32(1 << size); | 858 | + |
133 | load_reg_var(s, addr, rn); | 859 | +/* |
134 | - stride = (1 << size) * interleave; | 860 | + * Check a watchdog doesn't fire if corresponding flags (WTIE and WTRE) are not |
135 | for (reg = 0; reg < nregs; reg++) { | 861 | + * set. |
136 | - if (interleave > 2 || (interleave == 2 && nregs == 2)) { | 862 | + */ |
137 | - load_reg_var(s, addr, rn); | 863 | +static void test_enabling_flags(gconstpointer watchdog) |
138 | - tcg_gen_addi_i32(addr, addr, (1 << size) * reg); | 864 | +{ |
139 | - } else if (interleave == 2 && nregs == 4 && reg == 2) { | 865 | + const Watchdog *wd = watchdog; |
140 | - load_reg_var(s, addr, rn); | 866 | + QTestState *qts; |
141 | - tcg_gen_addi_i32(addr, addr, 1 << size); | 867 | + |
142 | - } | 868 | + /* Neither WTIE or WTRE is set, no interrupt or reset should happen */ |
143 | - if (size == 3) { | 869 | + qts = qtest_init("-machine quanta-gsj"); |
144 | - tmp64 = tcg_temp_new_i64(); | 870 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
145 | - if (load) { | 871 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTRF | WTR); |
146 | - gen_aa32_ld64(s, tmp64, addr, get_mem_index(s)); | 872 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); |
147 | - neon_store_reg64(tmp64, rd); | 873 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); |
148 | - } else { | 874 | + g_assert_false(qtest_get_irq(qts, wd->irq)); |
149 | - neon_load_reg64(tmp64, rd); | 875 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, |
150 | - gen_aa32_st64(s, tmp64, addr, get_mem_index(s)); | 876 | + watchdog_prescaler(qts, wd))); |
151 | - } | 877 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); |
152 | - tcg_temp_free_i64(tmp64); | 878 | + g_assert_false(watchdog_read_wtcr(qts, wd) & WTRF); |
153 | - tcg_gen_addi_i32(addr, addr, stride); | 879 | + qtest_quit(qts); |
154 | - } else { | 880 | + |
155 | - for (pass = 0; pass < 2; pass++) { | 881 | + /* Only WTIE is set, interrupt is triggered but reset should not happen */ |
156 | - if (size == 2) { | 882 | + qts = qtest_init("-machine quanta-gsj"); |
157 | - if (load) { | 883 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
158 | - tmp = tcg_temp_new_i32(); | 884 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTIE | WTRF | WTR); |
159 | - gen_aa32_ld32u(s, tmp, addr, get_mem_index(s)); | 885 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); |
160 | - neon_store_reg(rd, pass, tmp); | 886 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); |
161 | - } else { | 887 | + g_assert_true(qtest_get_irq(qts, wd->irq)); |
162 | - tmp = neon_load_reg(rd, pass); | 888 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, |
163 | - gen_aa32_st32(s, tmp, addr, get_mem_index(s)); | 889 | + watchdog_prescaler(qts, wd))); |
164 | - tcg_temp_free_i32(tmp); | 890 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); |
165 | - } | 891 | + g_assert_false(watchdog_read_wtcr(qts, wd) & WTRF); |
166 | - tcg_gen_addi_i32(addr, addr, stride); | 892 | + qtest_quit(qts); |
167 | - } else if (size == 1) { | 893 | + |
168 | - if (load) { | 894 | + /* Only WTRE is set, interrupt is triggered but reset should not happen */ |
169 | - tmp = tcg_temp_new_i32(); | 895 | + qts = qtest_init("-machine quanta-gsj"); |
170 | - gen_aa32_ld16u(s, tmp, addr, get_mem_index(s)); | 896 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
171 | - tcg_gen_addi_i32(addr, addr, stride); | 897 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTRE | WTRF | WTR); |
172 | - tmp2 = tcg_temp_new_i32(); | 898 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); |
173 | - gen_aa32_ld16u(s, tmp2, addr, get_mem_index(s)); | 899 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); |
174 | - tcg_gen_addi_i32(addr, addr, stride); | 900 | + g_assert_false(qtest_get_irq(qts, wd->irq)); |
175 | - tcg_gen_shli_i32(tmp2, tmp2, 16); | 901 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, |
176 | - tcg_gen_or_i32(tmp, tmp, tmp2); | 902 | + watchdog_prescaler(qts, wd))); |
177 | - tcg_temp_free_i32(tmp2); | 903 | + g_assert_false(strcmp(qdict_get_str(get_watchdog_action(qts), "action"), |
178 | - neon_store_reg(rd, pass, tmp); | 904 | + "reset")); |
179 | - } else { | 905 | + qtest_qmp_eventwait(qts, "RESET"); |
180 | - tmp = neon_load_reg(rd, pass); | 906 | + qtest_quit(qts); |
181 | - tmp2 = tcg_temp_new_i32(); | 907 | + |
182 | - tcg_gen_shri_i32(tmp2, tmp, 16); | 908 | + /* |
183 | - gen_aa32_st16(s, tmp, addr, get_mem_index(s)); | 909 | + * The case when both flags are set is already tested in |
184 | - tcg_temp_free_i32(tmp); | 910 | + * test_reset_action(). |
185 | - tcg_gen_addi_i32(addr, addr, stride); | 911 | + */ |
186 | - gen_aa32_st16(s, tmp2, addr, get_mem_index(s)); | 912 | +} |
187 | - tcg_temp_free_i32(tmp2); | 913 | + |
188 | - tcg_gen_addi_i32(addr, addr, stride); | 914 | +/* Check a watchdog can pause and resume by setting WTE bits */ |
189 | - } | 915 | +static void test_pause(gconstpointer watchdog) |
190 | - } else /* size == 0 */ { | 916 | +{ |
191 | - if (load) { | 917 | + const Watchdog *wd = watchdog; |
192 | - tmp2 = NULL; | 918 | + QTestState *qts; |
193 | - for (n = 0; n < 4; n++) { | 919 | + int64_t remaining_steps, steps; |
194 | - tmp = tcg_temp_new_i32(); | 920 | + |
195 | - gen_aa32_ld8u(s, tmp, addr, get_mem_index(s)); | 921 | + qts = qtest_init("-machine quanta-gsj"); |
196 | - tcg_gen_addi_i32(addr, addr, stride); | 922 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); |
197 | - if (n == 0) { | 923 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTIE | WTRF | WTR); |
198 | - tmp2 = tmp; | 924 | + remaining_steps = watchdog_interrupt_steps(qts, wd); |
199 | - } else { | 925 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTE | WTIE); |
200 | - tcg_gen_shli_i32(tmp, tmp, n * 8); | 926 | + |
201 | - tcg_gen_or_i32(tmp2, tmp2, tmp); | 927 | + /* Run for half of the execution period. */ |
202 | - tcg_temp_free_i32(tmp); | 928 | + steps = remaining_steps / 2; |
203 | - } | 929 | + remaining_steps -= steps; |
204 | - } | 930 | + qtest_clock_step(qts, steps); |
205 | - neon_store_reg(rd, pass, tmp2); | 931 | + |
206 | - } else { | 932 | + /* Pause the watchdog */ |
207 | - tmp2 = neon_load_reg(rd, pass); | 933 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTIE); |
208 | - for (n = 0; n < 4; n++) { | 934 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTIE); |
209 | - tmp = tcg_temp_new_i32(); | 935 | + |
210 | - if (n == 0) { | 936 | + /* Run for a long period of time, the watchdog shouldn't fire */ |
211 | - tcg_gen_mov_i32(tmp, tmp2); | 937 | + qtest_clock_step(qts, steps << 4); |
212 | - } else { | 938 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTIE); |
213 | - tcg_gen_shri_i32(tmp, tmp2, n * 8); | 939 | + g_assert_false(qtest_get_irq(qts, wd->irq)); |
214 | - } | 940 | + |
215 | - gen_aa32_st8(s, tmp, addr, get_mem_index(s)); | 941 | + /* Resume the watchdog */ |
216 | - tcg_temp_free_i32(tmp); | 942 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIE); |
217 | - tcg_gen_addi_i32(addr, addr, stride); | 943 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTE | WTIE); |
218 | - } | 944 | + |
219 | - tcg_temp_free_i32(tmp2); | 945 | + /* Run for the reset of the execution period, the watchdog should fire */ |
220 | - } | 946 | + qtest_clock_step(qts, remaining_steps); |
221 | + for (n = 0; n < 8 >> size; n++) { | 947 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, |
222 | + int xs; | 948 | + WTCLK(0) | WTE | WTIF | WTIE); |
223 | + for (xs = 0; xs < interleave; xs++) { | 949 | + g_assert_true(qtest_get_irq(qts, wd->irq)); |
224 | + int tt = rd + reg + spacing * xs; | 950 | + |
225 | + | 951 | + qtest_quit(qts); |
226 | + if (load) { | 952 | +} |
227 | + gen_aa32_ld_i64(s, tmp64, addr, mmu_idx, endian | size); | 953 | + |
228 | + neon_store_element64(tt, n, size, tmp64); | 954 | +static void watchdog_add_test(const char *name, const Watchdog* wd, |
229 | + } else { | 955 | + GTestDataFunc fn) |
230 | + neon_load_element64(tmp64, tt, n, size); | 956 | +{ |
231 | + gen_aa32_st_i64(s, tmp64, addr, mmu_idx, endian | size); | 957 | + g_autofree char *full_name = g_strdup_printf( |
232 | } | 958 | + "npcm7xx_watchdog_timer[%d]/%s", watchdog_index(wd), name); |
233 | + tcg_gen_add_i32(addr, addr, tmp2); | 959 | + qtest_add_data_func(full_name, wd, fn); |
234 | } | 960 | +} |
235 | } | 961 | +#define add_test(name, td) watchdog_add_test(#name, td, test_##name) |
236 | - rd += spacing; | 962 | + |
237 | } | 963 | +int main(int argc, char **argv) |
238 | tcg_temp_free_i32(addr); | 964 | +{ |
239 | - stride = nregs * 8; | 965 | + g_test_init(&argc, &argv, NULL); |
240 | + tcg_temp_free_i32(tmp2); | 966 | + g_test_set_nonfatal_assertions(); |
241 | + tcg_temp_free_i64(tmp64); | 967 | + |
242 | + stride = nregs * interleave * 8; | 968 | + for (int i = 0; i < ARRAY_SIZE(watchdog_list); ++i) { |
243 | } else { | 969 | + const Watchdog *wd = &watchdog_list[i]; |
244 | size = (insn >> 10) & 3; | 970 | + |
245 | if (size == 3) { | 971 | + add_test(init, wd); |
972 | + add_test(reset_action, wd); | ||
973 | + add_test(prescaler, wd); | ||
974 | + add_test(enabling_flags, wd); | ||
975 | + add_test(pause, wd); | ||
976 | + } | ||
977 | + | ||
978 | + return g_test_run(); | ||
979 | +} | ||
980 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
981 | index XXXXXXX..XXXXXXX 100644 | ||
982 | --- a/MAINTAINERS | ||
983 | +++ b/MAINTAINERS | ||
984 | @@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org | ||
985 | S: Supported | ||
986 | F: hw/*/npcm7xx* | ||
987 | F: include/hw/*/npcm7xx* | ||
988 | +F: tests/qtest/npcm7xx* | ||
989 | F: pc-bios/npcm7xx_bootrom.bin | ||
990 | F: roms/vbootrom | ||
991 | |||
992 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
993 | index XXXXXXX..XXXXXXX 100644 | ||
994 | --- a/tests/qtest/meson.build | ||
995 | +++ b/tests/qtest/meson.build | ||
996 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | ||
997 | (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \ | ||
998 | ['prom-env-test', 'boot-serial-test'] | ||
999 | |||
1000 | -qtests_npcm7xx = ['npcm7xx_timer-test'] | ||
1001 | +qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] | ||
1002 | qtests_arm = \ | ||
1003 | (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ | ||
1004 | (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ | ||
246 | -- | 1005 | -- |
247 | 2.19.1 | 1006 | 2.20.1 |
248 | 1007 | ||
249 | 1008 | diff view generated by jsdifflib |
1 | For the v7 version of the Arm architecture, the IL bit in | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | syndrome register values where the field is not valid was | ||
3 | defined to be UNK/SBZP. In v8 this is RES1, which is what | ||
4 | QEMU currently implements. Handle the desired v7 behaviour | ||
5 | by squashing the IL bit for the affected cases: | ||
6 | * EC == EC_UNCATEGORIZED | ||
7 | * prefetch aborts | ||
8 | * data aborts where ISV is 0 | ||
9 | 2 | ||
10 | (The fourth case listed in the v8 Arm ARM DDI 0487C.a in | 3 | The RNG module returns a byte of randomness when the Data Valid bit is |
11 | section G7.2.70, "illegal state exception", can't happen | 4 | set. |
12 | on a v7 CPU.) | ||
13 | 5 | ||
14 | This deals with a corner case noted in a comment. | 6 | This implementation ignores the prescaler setting, and loads a new value |
7 | into RNGD every time RNGCS is read while the RNG is enabled and random | ||
8 | data is available. | ||
15 | 9 | ||
10 | A qtest featuring some simple randomness tests is included. | ||
11 | |||
12 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | ||
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
18 | Message-id: 20181012144235.19646-10-peter.maydell@linaro.org | ||
19 | --- | 16 | --- |
20 | target/arm/internals.h | 7 ++----- | 17 | docs/system/arm/nuvoton.rst | 2 +- |
21 | target/arm/helper.c | 13 +++++++++++++ | 18 | include/hw/arm/npcm7xx.h | 2 + |
22 | 2 files changed, 15 insertions(+), 5 deletions(-) | 19 | include/hw/misc/npcm7xx_rng.h | 34 ++++ |
20 | hw/arm/npcm7xx.c | 7 +- | ||
21 | hw/misc/npcm7xx_rng.c | 180 +++++++++++++++++++++ | ||
22 | tests/qtest/npcm7xx_rng-test.c | 278 +++++++++++++++++++++++++++++++++ | ||
23 | hw/misc/meson.build | 1 + | ||
24 | hw/misc/trace-events | 4 + | ||
25 | tests/qtest/meson.build | 5 +- | ||
26 | 9 files changed, 510 insertions(+), 3 deletions(-) | ||
27 | create mode 100644 include/hw/misc/npcm7xx_rng.h | ||
28 | create mode 100644 hw/misc/npcm7xx_rng.c | ||
29 | create mode 100644 tests/qtest/npcm7xx_rng-test.c | ||
23 | 30 | ||
24 | diff --git a/target/arm/internals.h b/target/arm/internals.h | 31 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
25 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/target/arm/internals.h | 33 | --- a/docs/system/arm/nuvoton.rst |
27 | +++ b/target/arm/internals.h | 34 | +++ b/docs/system/arm/nuvoton.rst |
28 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t syn_get_ec(uint32_t syn) | 35 | @@ -XXX,XX +XXX,XX @@ Supported devices |
29 | /* Utility functions for constructing various kinds of syndrome value. | 36 | * DDR4 memory controller (dummy interface indicating memory training is done) |
30 | * Note that in general we follow the AArch64 syndrome values; in a | 37 | * OTP controllers (no protection features) |
31 | * few cases the value in HSR for exceptions taken to AArch32 Hyp | 38 | * Flash Interface Unit (FIU; no protection features) |
32 | - * mode differs slightly, so if we ever implemented Hyp mode then the | 39 | + * Random Number Generator (RNG) |
33 | - * syndrome value would need some massaging on exception entry. | 40 | |
34 | - * (One example of this is that AArch64 defaults to IL bit set for | 41 | Missing devices |
35 | - * exceptions which don't specifically indicate information about the | 42 | --------------- |
36 | - * trapping instruction, whereas AArch32 defaults to IL bit clear.) | 43 | @@ -XXX,XX +XXX,XX @@ Missing devices |
37 | + * mode differs slightly, and we fix this up when populating HSR in | 44 | * Peripheral SPI controller (PSPI) |
38 | + * arm_cpu_do_interrupt_aarch32_hyp(). | 45 | * Analog to Digital Converter (ADC) |
39 | */ | 46 | * SD/MMC host |
40 | static inline uint32_t syn_uncategorized(void) | 47 | - * Random Number Generator (RNG) |
41 | { | 48 | * PECI interface |
42 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 49 | * Pulse Width Modulation (PWM) |
50 | * Tachometer | ||
51 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | ||
43 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/target/arm/helper.c | 53 | --- a/include/hw/arm/npcm7xx.h |
45 | +++ b/target/arm/helper.c | 54 | +++ b/include/hw/arm/npcm7xx.h |
46 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch32_hyp(CPUState *cs) | 55 | @@ -XXX,XX +XXX,XX @@ |
56 | #include "hw/mem/npcm7xx_mc.h" | ||
57 | #include "hw/misc/npcm7xx_clk.h" | ||
58 | #include "hw/misc/npcm7xx_gcr.h" | ||
59 | +#include "hw/misc/npcm7xx_rng.h" | ||
60 | #include "hw/nvram/npcm7xx_otp.h" | ||
61 | #include "hw/timer/npcm7xx_timer.h" | ||
62 | #include "hw/ssi/npcm7xx_fiu.h" | ||
63 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { | ||
64 | NPCM7xxOTPState key_storage; | ||
65 | NPCM7xxOTPState fuse_array; | ||
66 | NPCM7xxMCState mc; | ||
67 | + NPCM7xxRNGState rng; | ||
68 | NPCM7xxFIUState fiu[2]; | ||
69 | } NPCM7xxState; | ||
70 | |||
71 | diff --git a/include/hw/misc/npcm7xx_rng.h b/include/hw/misc/npcm7xx_rng.h | ||
72 | new file mode 100644 | ||
73 | index XXXXXXX..XXXXXXX | ||
74 | --- /dev/null | ||
75 | +++ b/include/hw/misc/npcm7xx_rng.h | ||
76 | @@ -XXX,XX +XXX,XX @@ | ||
77 | +/* | ||
78 | + * Nuvoton NPCM7xx Random Number Generator. | ||
79 | + * | ||
80 | + * Copyright 2020 Google LLC | ||
81 | + * | ||
82 | + * This program is free software; you can redistribute it and/or modify it | ||
83 | + * under the terms of the GNU General Public License as published by the | ||
84 | + * Free Software Foundation; either version 2 of the License, or | ||
85 | + * (at your option) any later version. | ||
86 | + * | ||
87 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
88 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
89 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
90 | + * for more details. | ||
91 | + */ | ||
92 | +#ifndef NPCM7XX_RNG_H | ||
93 | +#define NPCM7XX_RNG_H | ||
94 | + | ||
95 | +#include "hw/sysbus.h" | ||
96 | + | ||
97 | +typedef struct NPCM7xxRNGState { | ||
98 | + SysBusDevice parent; | ||
99 | + | ||
100 | + MemoryRegion iomem; | ||
101 | + | ||
102 | + uint8_t rngcs; | ||
103 | + uint8_t rngd; | ||
104 | + uint8_t rngmode; | ||
105 | +} NPCM7xxRNGState; | ||
106 | + | ||
107 | +#define TYPE_NPCM7XX_RNG "npcm7xx-rng" | ||
108 | +#define NPCM7XX_RNG(obj) OBJECT_CHECK(NPCM7xxRNGState, (obj), TYPE_NPCM7XX_RNG) | ||
109 | + | ||
110 | +#endif /* NPCM7XX_RNG_H */ | ||
111 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/hw/arm/npcm7xx.c | ||
114 | +++ b/hw/arm/npcm7xx.c | ||
115 | @@ -XXX,XX +XXX,XX @@ | ||
116 | #define NPCM7XX_GCR_BA (0xf0800000) | ||
117 | #define NPCM7XX_CLK_BA (0xf0801000) | ||
118 | #define NPCM7XX_MC_BA (0xf0824000) | ||
119 | +#define NPCM7XX_RNG_BA (0xf000b000) | ||
120 | |||
121 | /* Internal AHB SRAM */ | ||
122 | #define NPCM7XX_RAM3_BA (0xc0008000) | ||
123 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | ||
124 | object_initialize_child(obj, "otp2", &s->fuse_array, | ||
125 | TYPE_NPCM7XX_FUSE_ARRAY); | ||
126 | object_initialize_child(obj, "mc", &s->mc, TYPE_NPCM7XX_MC); | ||
127 | + object_initialize_child(obj, "rng", &s->rng, TYPE_NPCM7XX_RNG); | ||
128 | |||
129 | for (i = 0; i < ARRAY_SIZE(s->tim); i++) { | ||
130 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | ||
131 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
132 | serial_hd(i), DEVICE_LITTLE_ENDIAN); | ||
47 | } | 133 | } |
48 | 134 | ||
49 | if (cs->exception_index != EXCP_IRQ && cs->exception_index != EXCP_FIQ) { | 135 | + /* Random Number Generator. Cannot fail. */ |
50 | + if (!arm_feature(env, ARM_FEATURE_V8)) { | 136 | + sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); |
51 | + /* | 137 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); |
52 | + * QEMU syndrome values are v8-style. v7 has the IL bit | 138 | + |
53 | + * UNK/SBZP for "field not valid" cases, where v8 uses RES1. | 139 | /* |
54 | + * If this is a v7 CPU, squash the IL bit in those cases. | 140 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects |
55 | + */ | 141 | * specified, but this is a programming error. |
56 | + if (cs->exception_index == EXCP_PREFETCH_ABORT || | 142 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
57 | + (cs->exception_index == EXCP_DATA_ABORT && | 143 | create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * KiB); |
58 | + !(env->exception.syndrome & ARM_EL_ISV)) || | 144 | create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB); |
59 | + syn_get_ec(env->exception.syndrome) == EC_UNCATEGORIZED) { | 145 | create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB); |
60 | + env->exception.syndrome &= ~ARM_EL_IL; | 146 | - create_unimplemented_device("npcm7xx.rng", 0xf000b000, 4 * KiB); |
147 | create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * KiB); | ||
148 | create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB); | ||
149 | create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * KiB); | ||
150 | diff --git a/hw/misc/npcm7xx_rng.c b/hw/misc/npcm7xx_rng.c | ||
151 | new file mode 100644 | ||
152 | index XXXXXXX..XXXXXXX | ||
153 | --- /dev/null | ||
154 | +++ b/hw/misc/npcm7xx_rng.c | ||
155 | @@ -XXX,XX +XXX,XX @@ | ||
156 | +/* | ||
157 | + * Nuvoton NPCM7xx Random Number Generator. | ||
158 | + * | ||
159 | + * Copyright 2020 Google LLC | ||
160 | + * | ||
161 | + * This program is free software; you can redistribute it and/or modify it | ||
162 | + * under the terms of the GNU General Public License as published by the | ||
163 | + * Free Software Foundation; either version 2 of the License, or | ||
164 | + * (at your option) any later version. | ||
165 | + * | ||
166 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
167 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
168 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
169 | + * for more details. | ||
170 | + */ | ||
171 | + | ||
172 | +#include "qemu/osdep.h" | ||
173 | + | ||
174 | +#include "hw/misc/npcm7xx_rng.h" | ||
175 | +#include "migration/vmstate.h" | ||
176 | +#include "qemu/bitops.h" | ||
177 | +#include "qemu/guest-random.h" | ||
178 | +#include "qemu/log.h" | ||
179 | +#include "qemu/module.h" | ||
180 | +#include "qemu/units.h" | ||
181 | + | ||
182 | +#include "trace.h" | ||
183 | + | ||
184 | +#define NPCM7XX_RNG_REGS_SIZE (4 * KiB) | ||
185 | + | ||
186 | +#define NPCM7XX_RNGCS (0x00) | ||
187 | +#define NPCM7XX_RNGCS_CLKP(rv) extract32(rv, 2, 4) | ||
188 | +#define NPCM7XX_RNGCS_DVALID BIT(1) | ||
189 | +#define NPCM7XX_RNGCS_RNGE BIT(0) | ||
190 | + | ||
191 | +#define NPCM7XX_RNGD (0x04) | ||
192 | +#define NPCM7XX_RNGMODE (0x08) | ||
193 | +#define NPCM7XX_RNGMODE_NORMAL (0x02) | ||
194 | + | ||
195 | +static bool npcm7xx_rng_is_enabled(NPCM7xxRNGState *s) | ||
196 | +{ | ||
197 | + return (s->rngcs & NPCM7XX_RNGCS_RNGE) && | ||
198 | + (s->rngmode == NPCM7XX_RNGMODE_NORMAL); | ||
199 | +} | ||
200 | + | ||
201 | +static uint64_t npcm7xx_rng_read(void *opaque, hwaddr offset, unsigned size) | ||
202 | +{ | ||
203 | + NPCM7xxRNGState *s = opaque; | ||
204 | + uint64_t value = 0; | ||
205 | + | ||
206 | + switch (offset) { | ||
207 | + case NPCM7XX_RNGCS: | ||
208 | + /* | ||
209 | + * If the RNG is enabled, but we don't have any valid random data, try | ||
210 | + * obtaining some and update the DVALID bit accordingly. | ||
211 | + */ | ||
212 | + if (!npcm7xx_rng_is_enabled(s)) { | ||
213 | + s->rngcs &= ~NPCM7XX_RNGCS_DVALID; | ||
214 | + } else if (!(s->rngcs & NPCM7XX_RNGCS_DVALID)) { | ||
215 | + uint8_t byte = 0; | ||
216 | + | ||
217 | + if (qemu_guest_getrandom(&byte, sizeof(byte), NULL) == 0) { | ||
218 | + s->rngd = byte; | ||
219 | + s->rngcs |= NPCM7XX_RNGCS_DVALID; | ||
61 | + } | 220 | + } |
62 | + } | 221 | + } |
63 | env->cp15.esr_el[2] = env->exception.syndrome; | 222 | + value = s->rngcs; |
64 | } | 223 | + break; |
65 | 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, | ||
281 | + .max_access_size = 4, | ||
282 | + .unaligned = false, | ||
283 | + }, | ||
284 | +}; | ||
285 | + | ||
286 | +static void npcm7xx_rng_enter_reset(Object *obj, ResetType type) | ||
287 | +{ | ||
288 | + NPCM7xxRNGState *s = NPCM7XX_RNG(obj); | ||
289 | + | ||
290 | + s->rngcs = 0; | ||
291 | + s->rngd = 0; | ||
292 | + s->rngmode = 0; | ||
293 | +} | ||
294 | + | ||
295 | +static void npcm7xx_rng_init(Object *obj) | ||
296 | +{ | ||
297 | + NPCM7xxRNGState *s = NPCM7XX_RNG(obj); | ||
298 | + | ||
299 | + memory_region_init_io(&s->iomem, obj, &npcm7xx_rng_ops, s, "regs", | ||
300 | + NPCM7XX_RNG_REGS_SIZE); | ||
301 | + sysbus_init_mmio(&s->parent, &s->iomem); | ||
302 | +} | ||
303 | + | ||
304 | +static const VMStateDescription vmstate_npcm7xx_rng = { | ||
305 | + .name = "npcm7xx-rng", | ||
306 | + .version_id = 0, | ||
307 | + .minimum_version_id = 0, | ||
308 | + .fields = (VMStateField[]) { | ||
309 | + VMSTATE_UINT8(rngcs, NPCM7xxRNGState), | ||
310 | + VMSTATE_UINT8(rngd, NPCM7xxRNGState), | ||
311 | + VMSTATE_UINT8(rngmode, NPCM7xxRNGState), | ||
312 | + VMSTATE_END_OF_LIST(), | ||
313 | + }, | ||
314 | +}; | ||
315 | + | ||
316 | +static void npcm7xx_rng_class_init(ObjectClass *klass, void *data) | ||
317 | +{ | ||
318 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | ||
319 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
320 | + | ||
321 | + dc->desc = "NPCM7xx Random Number Generator"; | ||
322 | + dc->vmsd = &vmstate_npcm7xx_rng; | ||
323 | + rc->phases.enter = npcm7xx_rng_enter_reset; | ||
324 | +} | ||
325 | + | ||
326 | +static const TypeInfo npcm7xx_rng_types[] = { | ||
327 | + { | ||
328 | + .name = TYPE_NPCM7XX_RNG, | ||
329 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
330 | + .instance_size = sizeof(NPCM7xxRNGState), | ||
331 | + .class_init = npcm7xx_rng_class_init, | ||
332 | + .instance_init = npcm7xx_rng_init, | ||
333 | + }, | ||
334 | +}; | ||
335 | +DEFINE_TYPES(npcm7xx_rng_types); | ||
336 | diff --git a/tests/qtest/npcm7xx_rng-test.c b/tests/qtest/npcm7xx_rng-test.c | ||
337 | new file mode 100644 | ||
338 | index XXXXXXX..XXXXXXX | ||
339 | --- /dev/null | ||
340 | +++ b/tests/qtest/npcm7xx_rng-test.c | ||
341 | @@ -XXX,XX +XXX,XX @@ | ||
342 | +/* | ||
343 | + * QTest testcase for the Nuvoton NPCM7xx Random Number Generator | ||
344 | + * | ||
345 | + * Copyright 2020 Google LLC | ||
346 | + * | ||
347 | + * This program is free software; you can redistribute it and/or modify it | ||
348 | + * under the terms of the GNU General Public License as published by the | ||
349 | + * Free Software Foundation; either version 2 of the License, or | ||
350 | + * (at your option) any later version. | ||
351 | + * | ||
352 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
353 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
354 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
355 | + * for more details. | ||
356 | + */ | ||
357 | + | ||
358 | +#include "qemu/osdep.h" | ||
359 | + | ||
360 | +#include <math.h> | ||
361 | + | ||
362 | +#include "libqtest-single.h" | ||
363 | +#include "qemu/bitops.h" | ||
364 | + | ||
365 | +#define RNG_BASE_ADDR 0xf000b000 | ||
366 | + | ||
367 | +/* Control and Status Register */ | ||
368 | +#define RNGCS 0x00 | ||
369 | +# define DVALID BIT(1) /* Data Valid */ | ||
370 | +# define RNGE BIT(0) /* RNG Enable */ | ||
371 | +/* Data Register */ | ||
372 | +#define RNGD 0x04 | ||
373 | +/* Mode Register */ | ||
374 | +#define RNGMODE 0x08 | ||
375 | +# define ROSEL_NORMAL (2) /* RNG only works in this mode */ | ||
376 | + | ||
377 | +/* Number of bits to collect for randomness tests. */ | ||
378 | +#define TEST_INPUT_BITS (128) | ||
379 | + | ||
380 | +static void rng_writeb(unsigned int offset, uint8_t value) | ||
381 | +{ | ||
382 | + writeb(RNG_BASE_ADDR + offset, value); | ||
383 | +} | ||
384 | + | ||
385 | +static uint8_t rng_readb(unsigned int offset) | ||
386 | +{ | ||
387 | + return readb(RNG_BASE_ADDR + offset); | ||
388 | +} | ||
389 | + | ||
390 | +/* Disable RNG and set normal ring oscillator mode. */ | ||
391 | +static void rng_reset(void) | ||
392 | +{ | ||
393 | + rng_writeb(RNGCS, 0); | ||
394 | + rng_writeb(RNGMODE, ROSEL_NORMAL); | ||
395 | +} | ||
396 | + | ||
397 | +/* Reset RNG and then enable it. */ | ||
398 | +static void rng_reset_enable(void) | ||
399 | +{ | ||
400 | + rng_reset(); | ||
401 | + rng_writeb(RNGCS, RNGE); | ||
402 | +} | ||
403 | + | ||
404 | +/* Wait until Data Valid bit is set. */ | ||
405 | +static bool rng_wait_ready(void) | ||
406 | +{ | ||
407 | + /* qemu_guest_getrandom may fail. Assume it won't fail 10 times in a row. */ | ||
408 | + int retries = 10; | ||
409 | + | ||
410 | + while (retries-- > 0) { | ||
411 | + if (rng_readb(RNGCS) & DVALID) { | ||
412 | + return true; | ||
413 | + } | ||
414 | + } | ||
415 | + | ||
416 | + return false; | ||
417 | +} | ||
418 | + | ||
419 | +/* | ||
420 | + * Perform a frequency (monobit) test, as defined by NIST SP 800-22, on the | ||
421 | + * sequence in buf and return the P-value. This represents the probability of a | ||
422 | + * truly random sequence having the same proportion of zeros and ones as the | ||
423 | + * sequence in buf. | ||
424 | + * | ||
425 | + * An RNG which always returns 0x00 or 0xff, or has some bits stuck at 0 or 1, | ||
426 | + * will fail this test. However, an RNG which always returns 0x55, 0xf0 or some | ||
427 | + * other value with an equal number of zeroes and ones will pass. | ||
428 | + */ | ||
429 | +static double calc_monobit_p(const uint8_t *buf, unsigned int len) | ||
430 | +{ | ||
431 | + unsigned int i; | ||
432 | + double s_obs; | ||
433 | + int sn = 0; | ||
434 | + | ||
435 | + for (i = 0; i < len; i++) { | ||
436 | + /* | ||
437 | + * Each 1 counts as 1, each 0 counts as -1. | ||
438 | + * s = cp - (8 - cp) = 2 * cp - 8 | ||
439 | + */ | ||
440 | + sn += 2 * ctpop8(buf[i]) - 8; | ||
441 | + } | ||
442 | + | ||
443 | + s_obs = abs(sn) / sqrt(len * BITS_PER_BYTE); | ||
444 | + | ||
445 | + return erfc(s_obs / sqrt(2)); | ||
446 | +} | ||
447 | + | ||
448 | +/* | ||
449 | + * Perform a runs test, as defined by NIST SP 800-22, and return the P-value. | ||
450 | + * This represents the probability of a truly random sequence having the same | ||
451 | + * number of runs (i.e. uninterrupted sequences of identical bits) as the | ||
452 | + * sequence in buf. | ||
453 | + */ | ||
454 | +static double calc_runs_p(const unsigned long *buf, unsigned int nr_bits) | ||
455 | +{ | ||
456 | + unsigned int j; | ||
457 | + unsigned int k; | ||
458 | + int nr_ones = 0; | ||
459 | + int vn_obs = 0; | ||
460 | + double pi; | ||
461 | + | ||
462 | + g_assert(nr_bits % BITS_PER_LONG == 0); | ||
463 | + | ||
464 | + for (j = 0; j < nr_bits / BITS_PER_LONG; j++) { | ||
465 | + nr_ones += __builtin_popcountl(buf[j]); | ||
466 | + } | ||
467 | + pi = (double)nr_ones / nr_bits; | ||
468 | + | ||
469 | + for (k = 0; k < nr_bits - 1; k++) { | ||
470 | + vn_obs += !(test_bit(k, buf) ^ test_bit(k + 1, buf)); | ||
471 | + } | ||
472 | + vn_obs += 1; | ||
473 | + | ||
474 | + return erfc(fabs(vn_obs - 2 * nr_bits * pi * (1.0 - pi)) | ||
475 | + / (2 * sqrt(2 * nr_bits) * pi * (1.0 - pi))); | ||
476 | +} | ||
477 | + | ||
478 | +/* | ||
479 | + * Verifies that DVALID is clear, and RNGD reads zero, when RNGE is cleared, | ||
480 | + * and DVALID eventually becomes set when RNGE is set. | ||
481 | + */ | ||
482 | +static void test_enable_disable(void) | ||
483 | +{ | ||
484 | + /* Disable: DVALID should not be set, and RNGD should read zero */ | ||
485 | + rng_reset(); | ||
486 | + g_assert_cmphex(rng_readb(RNGCS), ==, 0); | ||
487 | + g_assert_cmphex(rng_readb(RNGD), ==, 0); | ||
488 | + | ||
489 | + /* Enable: DVALID should be set, but we can't make assumptions about RNGD */ | ||
490 | + rng_writeb(RNGCS, RNGE); | ||
491 | + g_assert_true(rng_wait_ready()); | ||
492 | + g_assert_cmphex(rng_readb(RNGCS), ==, DVALID | RNGE); | ||
493 | + | ||
494 | + /* Disable: DVALID should not be set, and RNGD should read zero */ | ||
495 | + rng_writeb(RNGCS, 0); | ||
496 | + g_assert_cmphex(rng_readb(RNGCS), ==, 0); | ||
497 | + g_assert_cmphex(rng_readb(RNGD), ==, 0); | ||
498 | +} | ||
499 | + | ||
500 | +/* | ||
501 | + * Verifies that the RNG only produces data when RNGMODE is set to 'normal' | ||
502 | + * ring oscillator mode. | ||
503 | + */ | ||
504 | +static void test_rosel(void) | ||
505 | +{ | ||
506 | + rng_reset_enable(); | ||
507 | + g_assert_true(rng_wait_ready()); | ||
508 | + rng_writeb(RNGMODE, 0); | ||
509 | + g_assert_false(rng_wait_ready()); | ||
510 | + rng_writeb(RNGMODE, ROSEL_NORMAL); | ||
511 | + g_assert_true(rng_wait_ready()); | ||
512 | + rng_writeb(RNGMODE, 0); | ||
513 | + g_assert_false(rng_wait_ready()); | ||
514 | +} | ||
515 | + | ||
516 | +/* | ||
517 | + * Verifies that a continuous sequence of bits collected after enabling the RNG | ||
518 | + * satisfies a monobit test. | ||
519 | + */ | ||
520 | +static void test_continuous_monobit(void) | ||
521 | +{ | ||
522 | + uint8_t buf[TEST_INPUT_BITS / BITS_PER_BYTE]; | ||
523 | + unsigned int i; | ||
524 | + | ||
525 | + rng_reset_enable(); | ||
526 | + for (i = 0; i < sizeof(buf); i++) { | ||
527 | + g_assert_true(rng_wait_ready()); | ||
528 | + buf[i] = rng_readb(RNGD); | ||
529 | + } | ||
530 | + | ||
531 | + g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01); | ||
532 | +} | ||
533 | + | ||
534 | +/* | ||
535 | + * Verifies that a continuous sequence of bits collected after enabling the RNG | ||
536 | + * satisfies a runs test. | ||
537 | + */ | ||
538 | +static void test_continuous_runs(void) | ||
539 | +{ | ||
540 | + union { | ||
541 | + unsigned long l[TEST_INPUT_BITS / BITS_PER_LONG]; | ||
542 | + uint8_t c[TEST_INPUT_BITS / BITS_PER_BYTE]; | ||
543 | + } buf; | ||
544 | + unsigned int i; | ||
545 | + | ||
546 | + rng_reset_enable(); | ||
547 | + for (i = 0; i < sizeof(buf); i++) { | ||
548 | + g_assert_true(rng_wait_ready()); | ||
549 | + buf.c[i] = rng_readb(RNGD); | ||
550 | + } | ||
551 | + | ||
552 | + g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01); | ||
553 | +} | ||
554 | + | ||
555 | +/* | ||
556 | + * Verifies that the first data byte collected after enabling the RNG satisfies | ||
557 | + * a monobit test. | ||
558 | + */ | ||
559 | +static void test_first_byte_monobit(void) | ||
560 | +{ | ||
561 | + /* Enable, collect one byte, disable. Repeat until we have 100 bits. */ | ||
562 | + uint8_t buf[TEST_INPUT_BITS / BITS_PER_BYTE]; | ||
563 | + unsigned int i; | ||
564 | + | ||
565 | + rng_reset(); | ||
566 | + for (i = 0; i < sizeof(buf); i++) { | ||
567 | + rng_writeb(RNGCS, RNGE); | ||
568 | + g_assert_true(rng_wait_ready()); | ||
569 | + buf[i] = rng_readb(RNGD); | ||
570 | + rng_writeb(RNGCS, 0); | ||
571 | + } | ||
572 | + | ||
573 | + g_assert_cmpfloat(calc_monobit_p(buf, sizeof(buf)), >, 0.01); | ||
574 | +} | ||
575 | + | ||
576 | +/* | ||
577 | + * Verifies that the first data byte collected after enabling the RNG satisfies | ||
578 | + * a runs test. | ||
579 | + */ | ||
580 | +static void test_first_byte_runs(void) | ||
581 | +{ | ||
582 | + /* Enable, collect one byte, disable. Repeat until we have 100 bits. */ | ||
583 | + union { | ||
584 | + unsigned long l[TEST_INPUT_BITS / BITS_PER_LONG]; | ||
585 | + uint8_t c[TEST_INPUT_BITS / BITS_PER_BYTE]; | ||
586 | + } buf; | ||
587 | + unsigned int i; | ||
588 | + | ||
589 | + rng_reset(); | ||
590 | + for (i = 0; i < sizeof(buf); i++) { | ||
591 | + rng_writeb(RNGCS, RNGE); | ||
592 | + g_assert_true(rng_wait_ready()); | ||
593 | + buf.c[i] = rng_readb(RNGD); | ||
594 | + rng_writeb(RNGCS, 0); | ||
595 | + } | ||
596 | + | ||
597 | + g_assert_cmpfloat(calc_runs_p(buf.l, sizeof(buf) * BITS_PER_BYTE), >, 0.01); | ||
598 | +} | ||
599 | + | ||
600 | +int main(int argc, char **argv) | ||
601 | +{ | ||
602 | + int ret; | ||
603 | + | ||
604 | + g_test_init(&argc, &argv, NULL); | ||
605 | + g_test_set_nonfatal_assertions(); | ||
606 | + | ||
607 | + qtest_add_func("npcm7xx_rng/enable_disable", test_enable_disable); | ||
608 | + qtest_add_func("npcm7xx_rng/rosel", test_rosel); | ||
609 | + qtest_add_func("npcm7xx_rng/continuous/monobit", test_continuous_monobit); | ||
610 | + qtest_add_func("npcm7xx_rng/continuous/runs", test_continuous_runs); | ||
611 | + qtest_add_func("npcm7xx_rng/first_byte/monobit", test_first_byte_monobit); | ||
612 | + qtest_add_func("npcm7xx_rng/first_byte/runs", test_first_byte_runs); | ||
613 | + | ||
614 | + qtest_start("-machine npcm750-evb"); | ||
615 | + ret = g_test_run(); | ||
616 | + qtest_end(); | ||
617 | + | ||
618 | + return ret; | ||
619 | +} | ||
620 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
621 | index XXXXXXX..XXXXXXX 100644 | ||
622 | --- a/hw/misc/meson.build | ||
623 | +++ b/hw/misc/meson.build | ||
624 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_MAINSTONE', if_true: files('mst_fpga.c')) | ||
625 | softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files( | ||
626 | 'npcm7xx_clk.c', | ||
627 | 'npcm7xx_gcr.c', | ||
628 | + 'npcm7xx_rng.c', | ||
629 | )) | ||
630 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files( | ||
631 | 'omap_clk.c', | ||
632 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | ||
633 | index XXXXXXX..XXXXXXX 100644 | ||
634 | --- a/hw/misc/trace-events | ||
635 | +++ b/hw/misc/trace-events | ||
636 | @@ -XXX,XX +XXX,XX @@ npcm7xx_clk_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " valu | ||
637 | npcm7xx_gcr_read(uint64_t offset, uint32_t value) " offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 | ||
638 | npcm7xx_gcr_write(uint64_t offset, uint32_t value) "offset: 0x%04" PRIx64 " value: 0x%08" PRIx32 | ||
639 | |||
640 | +# npcm7xx_rng.c | ||
641 | +npcm7xx_rng_read(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" | ||
642 | +npcm7xx_rng_write(uint64_t offset, uint64_t value, unsigned size) "offset: 0x%04" PRIx64 " value: 0x%02" PRIx64 " size: %u" | ||
643 | + | ||
644 | # stm32f4xx_syscfg.c | ||
645 | stm32f4xx_syscfg_set_irq(int gpio, int line, int level) "Interupt: GPIO: %d, Line: %d; Level: %d" | ||
646 | stm32f4xx_pulse_exti(int irq) "Pulse EXTI: %d" | ||
647 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
648 | index XXXXXXX..XXXXXXX 100644 | ||
649 | --- a/tests/qtest/meson.build | ||
650 | +++ b/tests/qtest/meson.build | ||
651 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | ||
652 | (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \ | ||
653 | ['prom-env-test', 'boot-serial-test'] | ||
654 | |||
655 | -qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] | ||
656 | +qtests_npcm7xx = \ | ||
657 | + ['npcm7xx_rng-test', | ||
658 | + 'npcm7xx_timer-test', | ||
659 | + 'npcm7xx_watchdog_timer-test'] | ||
660 | qtests_arm = \ | ||
661 | (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ | ||
662 | (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ | ||
66 | -- | 663 | -- |
67 | 2.19.1 | 664 | 2.20.1 |
68 | 665 | ||
69 | 666 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | 2 | ||
3 | Move cmtst_op expanders from translate-a64.c. | 3 | The NPCM730 and NPCM750 chips have a single USB host port shared between |
4 | a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. This | ||
5 | adds support for both of them. | ||
4 | 6 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Testing notes: |
6 | Message-id: 20181011205206.3552-17-richard.henderson@linaro.org | 8 | * With -device usb-kbd, qemu will automatically insert a full-speed |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | hub, and the keyboard becomes controlled by the OHCI controller. |
10 | * With -device usb-kbd,bus=usb-bus.0,port=1, the keyboard is directly | ||
11 | attached to the port without any hubs, and the device becomes | ||
12 | controlled by the EHCI controller since it's high speed capable. | ||
13 | * With -device usb-kbd,bus=usb-bus.0,port=1,usb_version=1, the | ||
14 | keyboard is directly attached to the port, but it only advertises | ||
15 | itself as full-speed capable, so it becomes controlled by the OHCI | ||
16 | controller. | ||
17 | |||
18 | In all cases, the keyboard device enumerates correctly. | ||
19 | |||
20 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | ||
21 | Reviewed-by: Gerd Hoffmann <kraxel@redhat.com> | ||
22 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 24 | --- |
10 | target/arm/translate.h | 2 + | 25 | docs/system/arm/nuvoton.rst | 2 +- |
11 | target/arm/translate-a64.c | 38 ------------------ | 26 | hw/usb/hcd-ehci.h | 1 + |
12 | target/arm/translate.c | 81 +++++++++++++++++++++++++++----------- | 27 | include/hw/arm/npcm7xx.h | 4 ++++ |
13 | 3 files changed, 60 insertions(+), 61 deletions(-) | 28 | hw/arm/npcm7xx.c | 27 +++++++++++++++++++++++++-- |
29 | hw/usb/hcd-ehci-sysbus.c | 19 +++++++++++++++++++ | ||
30 | 5 files changed, 50 insertions(+), 3 deletions(-) | ||
14 | 31 | ||
15 | diff --git a/target/arm/translate.h b/target/arm/translate.h | 32 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
16 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate.h | 34 | --- a/docs/system/arm/nuvoton.rst |
18 | +++ b/target/arm/translate.h | 35 | +++ b/docs/system/arm/nuvoton.rst |
19 | @@ -XXX,XX +XXX,XX @@ extern const GVecGen3 bit_op; | 36 | @@ -XXX,XX +XXX,XX @@ Supported devices |
20 | extern const GVecGen3 bif_op; | 37 | * OTP controllers (no protection features) |
21 | extern const GVecGen3 mla_op[4]; | 38 | * Flash Interface Unit (FIU; no protection features) |
22 | extern const GVecGen3 mls_op[4]; | 39 | * Random Number Generator (RNG) |
23 | +extern const GVecGen3 cmtst_op[4]; | 40 | + * USB host (USBH) |
24 | extern const GVecGen2i ssra_op[4]; | 41 | |
25 | extern const GVecGen2i usra_op[4]; | 42 | Missing devices |
26 | extern const GVecGen2i sri_op[4]; | 43 | --------------- |
27 | extern const GVecGen2i sli_op[4]; | 44 | @@ -XXX,XX +XXX,XX @@ Missing devices |
28 | +void gen_cmtst_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b); | 45 | * eSPI slave interface |
29 | 46 | ||
30 | /* | 47 | * Ethernet controllers (GMAC and EMC) |
31 | * Forward to the isar_feature_* tests given a DisasContext pointer. | 48 | - * USB host (USBH) |
32 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 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 | ||
33 | index XXXXXXX..XXXXXXX 100644 | 53 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/target/arm/translate-a64.c | 54 | --- a/hw/usb/hcd-ehci.h |
35 | +++ b/target/arm/translate-a64.c | 55 | +++ b/hw/usb/hcd-ehci.h |
36 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_three_reg_diff(DisasContext *s, uint32_t insn) | 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); | ||
37 | } | 112 | } |
38 | } | 113 | |
39 | 114 | + object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); | |
40 | -/* CMTST : test is "if (X & Y != 0)". */ | 115 | + object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); |
41 | -static void gen_cmtst_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | 116 | + |
42 | -{ | 117 | QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu)); |
43 | - tcg_gen_and_i32(d, a, b); | 118 | for (i = 0; i < ARRAY_SIZE(s->fiu); i++) { |
44 | - tcg_gen_setcondi_i32(TCG_COND_NE, d, d, 0); | 119 | object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i], |
45 | - tcg_gen_neg_i32(d, d); | 120 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
46 | -} | 121 | sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); |
47 | - | 122 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); |
48 | -static void gen_cmtst_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | 123 | |
49 | -{ | 124 | + /* USB Host */ |
50 | - tcg_gen_and_i64(d, a, b); | 125 | + object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true, |
51 | - tcg_gen_setcondi_i64(TCG_COND_NE, d, d, 0); | 126 | + &error_abort); |
52 | - tcg_gen_neg_i64(d, d); | 127 | + sysbus_realize(SYS_BUS_DEVICE(&s->ehci), &error_abort); |
53 | -} | 128 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ehci), 0, NPCM7XX_EHCI_BA); |
54 | - | 129 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ehci), 0, |
55 | -static void gen_cmtst_vec(unsigned vece, TCGv_vec d, TCGv_vec a, TCGv_vec b) | 130 | + npcm7xx_irq(s, NPCM7XX_EHCI_IRQ)); |
56 | -{ | 131 | + |
57 | - tcg_gen_and_vec(vece, d, a, b); | 132 | + object_property_set_str(OBJECT(&s->ohci), "masterbus", "usb-bus.0", |
58 | - tcg_gen_dupi_vec(vece, a, 0); | 133 | + &error_abort); |
59 | - tcg_gen_cmp_vec(TCG_COND_NE, vece, d, d, a); | 134 | + object_property_set_uint(OBJECT(&s->ohci), "num-ports", 1, &error_abort); |
60 | -} | 135 | + sysbus_realize(SYS_BUS_DEVICE(&s->ohci), &error_abort); |
61 | - | 136 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ohci), 0, NPCM7XX_OHCI_BA); |
62 | static void handle_3same_64(DisasContext *s, int opcode, bool u, | 137 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci), 0, |
63 | TCGv_i64 tcg_rd, TCGv_i64 tcg_rn, TCGv_i64 tcg_rm) | 138 | + npcm7xx_irq(s, NPCM7XX_OHCI_IRQ)); |
64 | { | 139 | + |
65 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_3same_float(DisasContext *s, uint32_t insn) | 140 | /* |
66 | /* Integer op subgroup of C3.6.16. */ | 141 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects |
67 | static void disas_simd_3same_int(DisasContext *s, uint32_t insn) | 142 | * specified, but this is a programming error. |
68 | { | 143 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) |
69 | - static const GVecGen3 cmtst_op[4] = { | 144 | create_unimplemented_device("npcm7xx.mcphy", 0xf05f0000, 64 * KiB); |
70 | - { .fni4 = gen_helper_neon_tst_u8, | 145 | create_unimplemented_device("npcm7xx.gmac1", 0xf0802000, 8 * KiB); |
71 | - .fniv = gen_cmtst_vec, | 146 | create_unimplemented_device("npcm7xx.gmac2", 0xf0804000, 8 * KiB); |
72 | - .vece = MO_8 }, | 147 | - create_unimplemented_device("npcm7xx.ehci", 0xf0806000, 4 * KiB); |
73 | - { .fni4 = gen_helper_neon_tst_u16, | 148 | - create_unimplemented_device("npcm7xx.ohci", 0xf0807000, 4 * KiB); |
74 | - .fniv = gen_cmtst_vec, | 149 | create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB); |
75 | - .vece = MO_16 }, | 150 | create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB); |
76 | - { .fni4 = gen_cmtst_i32, | 151 | create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB); |
77 | - .fniv = gen_cmtst_vec, | 152 | diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c |
78 | - .vece = MO_32 }, | ||
79 | - { .fni8 = gen_cmtst_i64, | ||
80 | - .fniv = gen_cmtst_vec, | ||
81 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
82 | - .vece = MO_64 }, | ||
83 | - }; | ||
84 | - | ||
85 | int is_q = extract32(insn, 30, 1); | ||
86 | int u = extract32(insn, 29, 1); | ||
87 | int size = extract32(insn, 22, 2); | ||
88 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
89 | index XXXXXXX..XXXXXXX 100644 | 153 | index XXXXXXX..XXXXXXX 100644 |
90 | --- a/target/arm/translate.c | 154 | --- a/hw/usb/hcd-ehci-sysbus.c |
91 | +++ b/target/arm/translate.c | 155 | +++ b/hw/usb/hcd-ehci-sysbus.c |
92 | @@ -XXX,XX +XXX,XX @@ const GVecGen3 mls_op[4] = { | 156 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo ehci_aw_h3_type_info = { |
93 | .vece = MO_64 }, | 157 | .class_init = ehci_aw_h3_class_init, |
94 | }; | 158 | }; |
95 | 159 | ||
96 | +/* CMTST : test is "if (X & Y != 0)". */ | 160 | +static void ehci_npcm7xx_class_init(ObjectClass *oc, void *data) |
97 | +static void gen_cmtst_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
98 | +{ | 161 | +{ |
99 | + tcg_gen_and_i32(d, a, b); | 162 | + SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc); |
100 | + tcg_gen_setcondi_i32(TCG_COND_NE, d, d, 0); | 163 | + DeviceClass *dc = DEVICE_CLASS(oc); |
101 | + tcg_gen_neg_i32(d, d); | 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); | ||
102 | +} | 170 | +} |
103 | + | 171 | + |
104 | +void gen_cmtst_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | 172 | +static const TypeInfo ehci_npcm7xx_type_info = { |
105 | +{ | 173 | + .name = TYPE_NPCM7XX_EHCI, |
106 | + tcg_gen_and_i64(d, a, b); | 174 | + .parent = TYPE_SYS_BUS_EHCI, |
107 | + tcg_gen_setcondi_i64(TCG_COND_NE, d, d, 0); | 175 | + .class_init = ehci_npcm7xx_class_init, |
108 | + tcg_gen_neg_i64(d, d); | ||
109 | +} | ||
110 | + | ||
111 | +static void gen_cmtst_vec(unsigned vece, TCGv_vec d, TCGv_vec a, TCGv_vec b) | ||
112 | +{ | ||
113 | + tcg_gen_and_vec(vece, d, a, b); | ||
114 | + tcg_gen_dupi_vec(vece, a, 0); | ||
115 | + tcg_gen_cmp_vec(TCG_COND_NE, vece, d, d, a); | ||
116 | +} | ||
117 | + | ||
118 | +const GVecGen3 cmtst_op[4] = { | ||
119 | + { .fni4 = gen_helper_neon_tst_u8, | ||
120 | + .fniv = gen_cmtst_vec, | ||
121 | + .vece = MO_8 }, | ||
122 | + { .fni4 = gen_helper_neon_tst_u16, | ||
123 | + .fniv = gen_cmtst_vec, | ||
124 | + .vece = MO_16 }, | ||
125 | + { .fni4 = gen_cmtst_i32, | ||
126 | + .fniv = gen_cmtst_vec, | ||
127 | + .vece = MO_32 }, | ||
128 | + { .fni8 = gen_cmtst_i64, | ||
129 | + .fniv = gen_cmtst_vec, | ||
130 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
131 | + .vece = MO_64 }, | ||
132 | +}; | 176 | +}; |
133 | + | 177 | + |
134 | /* Translate a NEON data processing instruction. Return nonzero if the | 178 | static void ehci_tegra2_class_init(ObjectClass *oc, void *data) |
135 | instruction is invalid. | 179 | { |
136 | We process data in a mixture of 32-bit and 64-bit chunks. | 180 | SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc); |
137 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 181 | @@ -XXX,XX +XXX,XX @@ static void ehci_sysbus_register_types(void) |
138 | tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, vec_size, vec_size, | 182 | type_register_static(&ehci_platform_type_info); |
139 | u ? &mls_op[size] : &mla_op[size]); | 183 | type_register_static(&ehci_exynos4210_type_info); |
140 | return 0; | 184 | type_register_static(&ehci_aw_h3_type_info); |
141 | + | 185 | + type_register_static(&ehci_npcm7xx_type_info); |
142 | + case NEON_3R_VTST_VCEQ: | 186 | type_register_static(&ehci_tegra2_type_info); |
143 | + if (u) { /* VCEQ */ | 187 | type_register_static(&ehci_ppc4xx_type_info); |
144 | + tcg_gen_gvec_cmp(TCG_COND_EQ, size, rd_ofs, rn_ofs, rm_ofs, | 188 | type_register_static(&ehci_fusbh200_type_info); |
145 | + vec_size, vec_size); | ||
146 | + } else { /* VTST */ | ||
147 | + tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, | ||
148 | + vec_size, vec_size, &cmtst_op[size]); | ||
149 | + } | ||
150 | + return 0; | ||
151 | + | ||
152 | + case NEON_3R_VCGT: | ||
153 | + tcg_gen_gvec_cmp(u ? TCG_COND_GTU : TCG_COND_GT, size, | ||
154 | + rd_ofs, rn_ofs, rm_ofs, vec_size, vec_size); | ||
155 | + return 0; | ||
156 | + | ||
157 | + case NEON_3R_VCGE: | ||
158 | + tcg_gen_gvec_cmp(u ? TCG_COND_GEU : TCG_COND_GE, size, | ||
159 | + rd_ofs, rn_ofs, rm_ofs, vec_size, vec_size); | ||
160 | + return 0; | ||
161 | } | ||
162 | |||
163 | if (size == 3) { | ||
164 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
165 | case NEON_3R_VQSUB: | ||
166 | GEN_NEON_INTEGER_OP_ENV(qsub); | ||
167 | break; | ||
168 | - case NEON_3R_VCGT: | ||
169 | - GEN_NEON_INTEGER_OP(cgt); | ||
170 | - break; | ||
171 | - case NEON_3R_VCGE: | ||
172 | - GEN_NEON_INTEGER_OP(cge); | ||
173 | - break; | ||
174 | case NEON_3R_VSHL: | ||
175 | GEN_NEON_INTEGER_OP(shl); | ||
176 | break; | ||
177 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
178 | tmp2 = neon_load_reg(rd, pass); | ||
179 | gen_neon_add(size, tmp, tmp2); | ||
180 | break; | ||
181 | - case NEON_3R_VTST_VCEQ: | ||
182 | - if (!u) { /* VTST */ | ||
183 | - switch (size) { | ||
184 | - case 0: gen_helper_neon_tst_u8(tmp, tmp, tmp2); break; | ||
185 | - case 1: gen_helper_neon_tst_u16(tmp, tmp, tmp2); break; | ||
186 | - case 2: gen_helper_neon_tst_u32(tmp, tmp, tmp2); break; | ||
187 | - default: abort(); | ||
188 | - } | ||
189 | - } else { /* VCEQ */ | ||
190 | - switch (size) { | ||
191 | - case 0: gen_helper_neon_ceq_u8(tmp, tmp, tmp2); break; | ||
192 | - case 1: gen_helper_neon_ceq_u16(tmp, tmp, tmp2); break; | ||
193 | - case 2: gen_helper_neon_ceq_u32(tmp, tmp, tmp2); break; | ||
194 | - default: abort(); | ||
195 | - } | ||
196 | - } | ||
197 | - break; | ||
198 | case NEON_3R_VMUL: | ||
199 | /* VMUL.P8; other cases already eliminated. */ | ||
200 | gen_helper_neon_mul_p8(tmp, tmp, tmp2); | ||
201 | -- | 189 | -- |
202 | 2.19.1 | 190 | 2.20.1 |
203 | 191 | ||
204 | 192 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | 2 | ||
3 | For a sequence of loads or stores from a single register, | 3 | The NPCM7xx chips have multiple GPIO controllers that are mostly |
4 | little-endian operations can be promoted to an 8-byte op. | 4 | identical except for some minor differences like the reset values of |
5 | This can reduce the number of operations by a factor of 8. | 5 | some registers. Each controller controls up to 32 pins. |
6 | 6 | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Each individual pin is modeled as a pair of unnamed GPIOs -- one for |
8 | Message-id: 20181011205206.3552-5-richard.henderson@linaro.org | 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. | ||
11 | |||
12 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | ||
13 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 16 | --- |
12 | target/arm/translate-a64.c | 66 +++++++++++++++++++++++--------------- | 17 | docs/system/arm/nuvoton.rst | 2 +- |
13 | 1 file changed, 40 insertions(+), 26 deletions(-) | 18 | include/hw/arm/npcm7xx.h | 2 + |
19 | include/hw/gpio/npcm7xx_gpio.h | 55 +++++ | ||
20 | hw/arm/npcm7xx.c | 80 ++++++ | ||
21 | hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++++++++++++++++++++++ | ||
22 | tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++++++++++++++++++++ | ||
23 | hw/gpio/meson.build | 1 + | ||
24 | hw/gpio/trace-events | 7 + | ||
25 | tests/qtest/meson.build | 3 +- | ||
26 | 9 files changed, 957 insertions(+), 2 deletions(-) | ||
27 | create mode 100644 include/hw/gpio/npcm7xx_gpio.h | ||
28 | create mode 100644 hw/gpio/npcm7xx_gpio.c | ||
29 | create mode 100644 tests/qtest/npcm7xx_gpio-test.c | ||
14 | 30 | ||
15 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 31 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
16 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate-a64.c | 33 | --- a/docs/system/arm/nuvoton.rst |
18 | +++ b/target/arm/translate-a64.c | 34 | +++ b/docs/system/arm/nuvoton.rst |
19 | @@ -XXX,XX +XXX,XX @@ static void write_vec_element_i32(DisasContext *s, TCGv_i32 tcg_src, | 35 | @@ -XXX,XX +XXX,XX @@ Supported devices |
20 | 36 | * Flash Interface Unit (FIU; no protection features) | |
21 | /* Store from vector register to memory */ | 37 | * Random Number Generator (RNG) |
22 | static void do_vec_st(DisasContext *s, int srcidx, int element, | 38 | * USB host (USBH) |
23 | - TCGv_i64 tcg_addr, int size) | 39 | + * GPIO controller |
24 | + TCGv_i64 tcg_addr, int size, TCGMemOp endian) | 40 | |
25 | { | 41 | Missing devices |
26 | - TCGMemOp memop = s->be_data + size; | 42 | --------------- |
27 | TCGv_i64 tcg_tmp = tcg_temp_new_i64(); | 43 | |
28 | 44 | - * GPIO controller | |
29 | read_vec_element(s, tcg_tmp, srcidx, element, size); | 45 | * LPC/eSPI host-to-BMC interface, including |
30 | - tcg_gen_qemu_st_i64(tcg_tmp, tcg_addr, get_mem_index(s), memop); | 46 | |
31 | + tcg_gen_qemu_st_i64(tcg_tmp, tcg_addr, get_mem_index(s), endian | size); | 47 | * Keyboard and mouse controller interface (KBCI) |
32 | 48 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | |
33 | tcg_temp_free_i64(tcg_tmp); | 49 | index XXXXXXX..XXXXXXX 100644 |
34 | } | 50 | --- a/include/hw/arm/npcm7xx.h |
35 | 51 | +++ b/include/hw/arm/npcm7xx.h | |
36 | /* Load from memory to vector register */ | 52 | @@ -XXX,XX +XXX,XX @@ |
37 | static void do_vec_ld(DisasContext *s, int destidx, int element, | 53 | |
38 | - TCGv_i64 tcg_addr, int size) | 54 | #include "hw/boards.h" |
39 | + TCGv_i64 tcg_addr, int size, TCGMemOp endian) | 55 | #include "hw/cpu/a9mpcore.h" |
40 | { | 56 | +#include "hw/gpio/npcm7xx_gpio.h" |
41 | - TCGMemOp memop = s->be_data + size; | 57 | #include "hw/mem/npcm7xx_mc.h" |
42 | TCGv_i64 tcg_tmp = tcg_temp_new_i64(); | 58 | #include "hw/misc/npcm7xx_clk.h" |
43 | 59 | #include "hw/misc/npcm7xx_gcr.h" | |
44 | - tcg_gen_qemu_ld_i64(tcg_tmp, tcg_addr, get_mem_index(s), memop); | 60 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { |
45 | + tcg_gen_qemu_ld_i64(tcg_tmp, tcg_addr, get_mem_index(s), endian | size); | 61 | NPCM7xxOTPState fuse_array; |
46 | write_vec_element(s, tcg_tmp, destidx, element, size); | 62 | NPCM7xxMCState mc; |
47 | 63 | NPCM7xxRNGState rng; | |
48 | tcg_temp_free_i64(tcg_tmp); | 64 | + NPCM7xxGPIOState gpio[8]; |
49 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn) | 65 | EHCISysBusState ehci; |
50 | bool is_postidx = extract32(insn, 23, 1); | 66 | OHCISysBusState ohci; |
51 | bool is_q = extract32(insn, 30, 1); | 67 | NPCM7xxFIUState fiu[2]; |
52 | TCGv_i64 tcg_addr, tcg_rn, tcg_ebytes; | 68 | diff --git a/include/hw/gpio/npcm7xx_gpio.h b/include/hw/gpio/npcm7xx_gpio.h |
53 | + TCGMemOp endian = s->be_data; | 69 | new file mode 100644 |
54 | 70 | index XXXXXXX..XXXXXXX | |
55 | - int ebytes = 1 << size; | 71 | --- /dev/null |
56 | - int elements = (is_q ? 128 : 64) / (8 << size); | 72 | +++ b/include/hw/gpio/npcm7xx_gpio.h |
57 | + int ebytes; /* bytes per element */ | 73 | @@ -XXX,XX +XXX,XX @@ |
58 | + int elements; /* elements per vector */ | 74 | +/* |
59 | int rpt; /* num iterations */ | 75 | + * Nuvoton NPCM7xx General Purpose Input / Output (GPIO) |
60 | int selem; /* structure elements */ | 76 | + * |
61 | int r; | 77 | + * Copyright 2020 Google LLC |
62 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn) | 78 | + * |
63 | gen_check_sp_alignment(s); | 79 | + * This program is free software; you can redistribute it and/or |
80 | + * modify it under the terms of the GNU General Public License | ||
81 | + * version 2 as published by the Free Software Foundation. | ||
82 | + * | ||
83 | + * This program is distributed in the hope that it will be useful, | ||
84 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
85 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
86 | + * GNU General Public License for more details. | ||
87 | + */ | ||
88 | +#ifndef NPCM7XX_GPIO_H | ||
89 | +#define NPCM7XX_GPIO_H | ||
90 | + | ||
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); | ||
64 | } | 206 | } |
65 | 207 | ||
66 | + /* For our purposes, bytes are always little-endian. */ | 208 | + for (i = 0; i < ARRAY_SIZE(s->gpio); i++) { |
67 | + if (size == 0) { | 209 | + object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO); |
68 | + endian = MO_LE; | ||
69 | + } | 210 | + } |
70 | + | 211 | + |
71 | + /* Consecutive little-endian elements from a single register | 212 | object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); |
72 | + * can be promoted to a larger little-endian operation. | 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 | ||
242 | new file mode 100644 | ||
243 | index XXXXXXX..XXXXXXX | ||
244 | --- /dev/null | ||
245 | +++ b/hw/gpio/npcm7xx_gpio.c | ||
246 | @@ -XXX,XX +XXX,XX @@ | ||
247 | +/* | ||
248 | + * Nuvoton NPCM7xx General Purpose Input / Output (GPIO) | ||
249 | + * | ||
250 | + * Copyright 2020 Google LLC | ||
251 | + * | ||
252 | + * This program is free software; you can redistribute it and/or | ||
253 | + * modify it under the terms of the GNU General Public License | ||
254 | + * version 2 as published by the Free Software Foundation. | ||
255 | + * | ||
256 | + * This program is distributed in the hope that it will be useful, | ||
257 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
258 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
259 | + * GNU General Public License for more details. | ||
260 | + */ | ||
261 | + | ||
262 | +#include "qemu/osdep.h" | ||
263 | + | ||
264 | +#include "hw/gpio/npcm7xx_gpio.h" | ||
265 | +#include "hw/irq.h" | ||
266 | +#include "hw/qdev-properties.h" | ||
267 | +#include "migration/vmstate.h" | ||
268 | +#include "qapi/error.h" | ||
269 | +#include "qemu/log.h" | ||
270 | +#include "qemu/module.h" | ||
271 | +#include "qemu/units.h" | ||
272 | +#include "trace.h" | ||
273 | + | ||
274 | +/* 32-bit register indices. */ | ||
275 | +enum NPCM7xxGPIORegister { | ||
276 | + NPCM7XX_GPIO_TLOCK1, | ||
277 | + NPCM7XX_GPIO_DIN, | ||
278 | + NPCM7XX_GPIO_POL, | ||
279 | + NPCM7XX_GPIO_DOUT, | ||
280 | + NPCM7XX_GPIO_OE, | ||
281 | + NPCM7XX_GPIO_OTYP, | ||
282 | + NPCM7XX_GPIO_MP, | ||
283 | + NPCM7XX_GPIO_PU, | ||
284 | + NPCM7XX_GPIO_PD, | ||
285 | + NPCM7XX_GPIO_DBNC, | ||
286 | + NPCM7XX_GPIO_EVTYP, | ||
287 | + NPCM7XX_GPIO_EVBE, | ||
288 | + NPCM7XX_GPIO_OBL0, | ||
289 | + NPCM7XX_GPIO_OBL1, | ||
290 | + NPCM7XX_GPIO_OBL2, | ||
291 | + NPCM7XX_GPIO_OBL3, | ||
292 | + NPCM7XX_GPIO_EVEN, | ||
293 | + NPCM7XX_GPIO_EVENS, | ||
294 | + NPCM7XX_GPIO_EVENC, | ||
295 | + NPCM7XX_GPIO_EVST, | ||
296 | + NPCM7XX_GPIO_SPLCK, | ||
297 | + NPCM7XX_GPIO_MPLCK, | ||
298 | + NPCM7XX_GPIO_IEM, | ||
299 | + NPCM7XX_GPIO_OSRC, | ||
300 | + NPCM7XX_GPIO_ODSC, | ||
301 | + NPCM7XX_GPIO_DOS = 0x68 / sizeof(uint32_t), | ||
302 | + NPCM7XX_GPIO_DOC, | ||
303 | + NPCM7XX_GPIO_OES, | ||
304 | + NPCM7XX_GPIO_OEC, | ||
305 | + NPCM7XX_GPIO_TLOCK2 = 0x7c / sizeof(uint32_t), | ||
306 | + NPCM7XX_GPIO_REGS_END, | ||
307 | +}; | ||
308 | + | ||
309 | +#define NPCM7XX_GPIO_REGS_SIZE (4 * KiB) | ||
310 | + | ||
311 | +#define NPCM7XX_GPIO_LOCK_MAGIC1 (0xc0defa73) | ||
312 | +#define NPCM7XX_GPIO_LOCK_MAGIC2 (0xc0de1248) | ||
313 | + | ||
314 | +static void npcm7xx_gpio_update_events(NPCM7xxGPIOState *s, uint32_t din_diff) | ||
315 | +{ | ||
316 | + uint32_t din_new = s->regs[NPCM7XX_GPIO_DIN]; | ||
317 | + | ||
318 | + /* Trigger on high level */ | ||
319 | + s->regs[NPCM7XX_GPIO_EVST] |= din_new & ~s->regs[NPCM7XX_GPIO_EVTYP]; | ||
320 | + /* Trigger on both edges */ | ||
321 | + s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & s->regs[NPCM7XX_GPIO_EVTYP] | ||
322 | + & s->regs[NPCM7XX_GPIO_EVBE]); | ||
323 | + /* Trigger on rising edge */ | ||
324 | + s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & din_new | ||
325 | + & s->regs[NPCM7XX_GPIO_EVTYP]); | ||
326 | + | ||
327 | + trace_npcm7xx_gpio_update_events(DEVICE(s)->canonical_path, | ||
328 | + s->regs[NPCM7XX_GPIO_EVST], | ||
329 | + s->regs[NPCM7XX_GPIO_EVEN]); | ||
330 | + qemu_set_irq(s->irq, !!(s->regs[NPCM7XX_GPIO_EVST] | ||
331 | + & s->regs[NPCM7XX_GPIO_EVEN])); | ||
332 | +} | ||
333 | + | ||
334 | +static void npcm7xx_gpio_update_pins(NPCM7xxGPIOState *s, uint32_t diff) | ||
335 | +{ | ||
336 | + uint32_t drive_en; | ||
337 | + uint32_t drive_lvl; | ||
338 | + uint32_t not_driven; | ||
339 | + uint32_t undefined; | ||
340 | + uint32_t pin_diff; | ||
341 | + uint32_t din_old; | ||
342 | + | ||
343 | + /* Calculate level of each pin driven by GPIO controller. */ | ||
344 | + drive_lvl = s->regs[NPCM7XX_GPIO_DOUT] ^ s->regs[NPCM7XX_GPIO_POL]; | ||
345 | + /* If OTYP=1, only drive low (open drain) */ | ||
346 | + drive_en = s->regs[NPCM7XX_GPIO_OE] & ~(s->regs[NPCM7XX_GPIO_OTYP] | ||
347 | + & drive_lvl); | ||
348 | + /* | ||
349 | + * If a pin is driven to opposite levels by the GPIO controller and the | ||
350 | + * external driver, the result is undefined. | ||
73 | + */ | 351 | + */ |
74 | + if (selem == 1 && endian == MO_LE) { | 352 | + undefined = drive_en & s->ext_driven & (drive_lvl ^ s->ext_level); |
75 | + size = 3; | 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); | ||
76 | + } | 357 | + } |
77 | + ebytes = 1 << size; | 358 | + |
78 | + elements = (is_q ? 16 : 8) / ebytes; | 359 | + not_driven = ~(drive_en | s->ext_driven); |
79 | + | 360 | + pin_diff = s->pin_level; |
80 | tcg_rn = cpu_reg_sp(s, rn); | 361 | + |
81 | tcg_addr = tcg_temp_new_i64(); | 362 | + /* Set pins to externally driven level. */ |
82 | tcg_gen_mov_i64(tcg_addr, tcg_rn); | 363 | + s->pin_level = s->ext_level & s->ext_driven; |
83 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn) | 364 | + /* Set internally driven pins, ignoring any conflicts. */ |
84 | for (r = 0; r < rpt; r++) { | 365 | + s->pin_level |= drive_lvl & drive_en; |
85 | int e; | 366 | + /* Pull up undriven pins with internal pull-up enabled. */ |
86 | for (e = 0; e < elements; e++) { | 367 | + s->pin_level |= not_driven & s->regs[NPCM7XX_GPIO_PU]; |
87 | - int tt = (rt + r) % 32; | 368 | + /* Pins not driven, pulled up or pulled down are undefined */ |
88 | int xs; | 369 | + undefined |= not_driven & ~(s->regs[NPCM7XX_GPIO_PU] |
89 | for (xs = 0; xs < selem; xs++) { | 370 | + | s->regs[NPCM7XX_GPIO_PD]); |
90 | + int tt = (rt + r + xs) % 32; | 371 | + |
91 | if (is_store) { | 372 | + /* If any pins changed state, update the outgoing GPIOs. */ |
92 | - do_vec_st(s, tt, e, tcg_addr, size); | 373 | + pin_diff ^= s->pin_level; |
93 | + do_vec_st(s, tt, e, tcg_addr, size, endian); | 374 | + pin_diff |= undefined & diff; |
94 | } else { | 375 | + if (pin_diff) { |
95 | - do_vec_ld(s, tt, e, tcg_addr, size); | 376 | + int i; |
96 | - | 377 | + |
97 | - /* For non-quad operations, setting a slice of the low | 378 | + for (i = 0; i < NPCM7XX_GPIO_NR_PINS; i++) { |
98 | - * 64 bits of the register clears the high 64 bits (in | 379 | + uint32_t mask = BIT(i); |
99 | - * the ARM ARM pseudocode this is implicit in the fact | 380 | + if (pin_diff & mask) { |
100 | - * that 'rval' is a 64 bit wide variable). | 381 | + int level = (undefined & mask) ? -1 : !!(s->pin_level & mask); |
101 | - * For quad operations, we might still need to zero the | 382 | + trace_npcm7xx_gpio_set_output(DEVICE(s)->canonical_path, |
102 | - * high bits of SVE. We optimize by noticing that we only | 383 | + i, level); |
103 | - * need to do this the first time we touch a register. | 384 | + qemu_set_irq(s->output[i], level); |
104 | - */ | 385 | + } |
105 | - if (e == 0 && (r == 0 || xs == selem - 1)) { | ||
106 | - clear_vec_high(s, is_q, tt); | ||
107 | - } | ||
108 | + do_vec_ld(s, tt, e, tcg_addr, size, endian); | ||
109 | } | ||
110 | tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_ebytes); | ||
111 | - tt = (tt + 1) % 32; | ||
112 | } | ||
113 | } | ||
114 | } | ||
115 | |||
116 | + if (!is_store) { | ||
117 | + /* For non-quad operations, setting a slice of the low | ||
118 | + * 64 bits of the register clears the high 64 bits (in | ||
119 | + * the ARM ARM pseudocode this is implicit in the fact | ||
120 | + * that 'rval' is a 64 bit wide variable). | ||
121 | + * For quad operations, we might still need to zero the | ||
122 | + * high bits of SVE. | ||
123 | + */ | ||
124 | + for (r = 0; r < rpt * selem; r++) { | ||
125 | + int tt = (rt + r) % 32; | ||
126 | + clear_vec_high(s, is_q, tt); | ||
127 | + } | 386 | + } |
128 | + } | 387 | + } |
129 | + | 388 | + |
130 | if (is_postidx) { | 389 | + /* Calculate new value of DIN after masking and polarity setting. */ |
131 | int rm = extract32(insn, 16, 5); | 390 | + din_old = s->regs[NPCM7XX_GPIO_DIN]; |
132 | if (rm == 31) { | 391 | + s->regs[NPCM7XX_GPIO_DIN] = ((s->pin_level & s->regs[NPCM7XX_GPIO_IEM]) |
133 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn) | 392 | + ^ s->regs[NPCM7XX_GPIO_POL]); |
134 | } else { | 393 | + |
135 | /* Load/store one element per register */ | 394 | + /* See if any new events triggered because of all this. */ |
136 | if (is_load) { | 395 | + npcm7xx_gpio_update_events(s, din_old ^ s->regs[NPCM7XX_GPIO_DIN]); |
137 | - do_vec_ld(s, rt, index, tcg_addr, scale); | 396 | +} |
138 | + do_vec_ld(s, rt, index, tcg_addr, scale, s->be_data); | 397 | + |
139 | } else { | 398 | +static bool npcm7xx_gpio_is_locked(NPCM7xxGPIOState *s) |
140 | - do_vec_st(s, rt, index, tcg_addr, scale); | 399 | +{ |
141 | + do_vec_st(s, rt, index, tcg_addr, scale, s->be_data); | 400 | + return s->regs[NPCM7XX_GPIO_TLOCK1] == 1; |
142 | } | 401 | +} |
143 | } | 402 | + |
144 | tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_ebytes); | 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, | ||
567 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
568 | + .valid = { | ||
569 | + .min_access_size = 4, | ||
570 | + .max_access_size = 4, | ||
571 | + .unaligned = false, | ||
572 | + }, | ||
573 | +}; | ||
574 | + | ||
575 | +static void npcm7xx_gpio_set_input(void *opaque, int line, int level) | ||
576 | +{ | ||
577 | + NPCM7xxGPIOState *s = opaque; | ||
578 | + | ||
579 | + trace_npcm7xx_gpio_set_input(DEVICE(s)->canonical_path, line, level); | ||
580 | + | ||
581 | + g_assert(line >= 0 && line < NPCM7XX_GPIO_NR_PINS); | ||
582 | + | ||
583 | + s->ext_driven = deposit32(s->ext_driven, line, 1, level >= 0); | ||
584 | + s->ext_level = deposit32(s->ext_level, line, 1, level > 0); | ||
585 | + | ||
586 | + npcm7xx_gpio_update_pins(s, BIT(line)); | ||
587 | +} | ||
588 | + | ||
589 | +static void npcm7xx_gpio_enter_reset(Object *obj, ResetType type) | ||
590 | +{ | ||
591 | + NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj); | ||
592 | + | ||
593 | + memset(s->regs, 0, sizeof(s->regs)); | ||
594 | + | ||
595 | + s->regs[NPCM7XX_GPIO_PU] = s->reset_pu; | ||
596 | + s->regs[NPCM7XX_GPIO_PD] = s->reset_pd; | ||
597 | + s->regs[NPCM7XX_GPIO_OSRC] = s->reset_osrc; | ||
598 | + s->regs[NPCM7XX_GPIO_ODSC] = s->reset_odsc; | ||
599 | +} | ||
600 | + | ||
601 | +static void npcm7xx_gpio_hold_reset(Object *obj) | ||
602 | +{ | ||
603 | + NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj); | ||
604 | + | ||
605 | + npcm7xx_gpio_update_pins(s, -1); | ||
606 | +} | ||
607 | + | ||
608 | +static void npcm7xx_gpio_init(Object *obj) | ||
609 | +{ | ||
610 | + NPCM7xxGPIOState *s = NPCM7XX_GPIO(obj); | ||
611 | + DeviceState *dev = DEVICE(obj); | ||
612 | + | ||
613 | + memory_region_init_io(&s->mmio, obj, &npcm7xx_gpio_regs_ops, s, | ||
614 | + "regs", NPCM7XX_GPIO_REGS_SIZE); | ||
615 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); | ||
616 | + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); | ||
617 | + | ||
618 | + qdev_init_gpio_in(dev, npcm7xx_gpio_set_input, NPCM7XX_GPIO_NR_PINS); | ||
619 | + qdev_init_gpio_out(dev, s->output, NPCM7XX_GPIO_NR_PINS); | ||
620 | +} | ||
621 | + | ||
622 | +static const VMStateDescription vmstate_npcm7xx_gpio = { | ||
623 | + .name = "npcm7xx-gpio", | ||
624 | + .version_id = 0, | ||
625 | + .minimum_version_id = 0, | ||
626 | + .fields = (VMStateField[]) { | ||
627 | + VMSTATE_UINT32(pin_level, NPCM7xxGPIOState), | ||
628 | + VMSTATE_UINT32(ext_level, NPCM7xxGPIOState), | ||
629 | + VMSTATE_UINT32(ext_driven, NPCM7xxGPIOState), | ||
630 | + VMSTATE_UINT32_ARRAY(regs, NPCM7xxGPIOState, NPCM7XX_GPIO_NR_REGS), | ||
631 | + VMSTATE_END_OF_LIST(), | ||
632 | + }, | ||
633 | +}; | ||
634 | + | ||
635 | +static Property npcm7xx_gpio_properties[] = { | ||
636 | + /* Bit n set => pin n has pullup enabled by default. */ | ||
637 | + DEFINE_PROP_UINT32("reset-pullup", NPCM7xxGPIOState, reset_pu, 0), | ||
638 | + /* Bit n set => pin n has pulldown enabled by default. */ | ||
639 | + DEFINE_PROP_UINT32("reset-pulldown", NPCM7xxGPIOState, reset_pd, 0), | ||
640 | + /* Bit n set => pin n has high slew rate by default. */ | ||
641 | + DEFINE_PROP_UINT32("reset-osrc", NPCM7xxGPIOState, reset_osrc, 0), | ||
642 | + /* Bit n set => pin n has high drive strength by default. */ | ||
643 | + DEFINE_PROP_UINT32("reset-odsc", NPCM7xxGPIOState, reset_odsc, 0), | ||
644 | + DEFINE_PROP_END_OF_LIST(), | ||
645 | +}; | ||
646 | + | ||
647 | +static void npcm7xx_gpio_class_init(ObjectClass *klass, void *data) | ||
648 | +{ | ||
649 | + ResettableClass *reset = RESETTABLE_CLASS(klass); | ||
650 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
651 | + | ||
652 | + QEMU_BUILD_BUG_ON(NPCM7XX_GPIO_REGS_END > NPCM7XX_GPIO_NR_REGS); | ||
653 | + | ||
654 | + dc->desc = "NPCM7xx GPIO Controller"; | ||
655 | + dc->vmsd = &vmstate_npcm7xx_gpio; | ||
656 | + reset->phases.enter = npcm7xx_gpio_enter_reset; | ||
657 | + reset->phases.hold = npcm7xx_gpio_hold_reset; | ||
658 | + device_class_set_props(dc, npcm7xx_gpio_properties); | ||
659 | +} | ||
660 | + | ||
661 | +static const TypeInfo npcm7xx_gpio_types[] = { | ||
662 | + { | ||
663 | + .name = TYPE_NPCM7XX_GPIO, | ||
664 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
665 | + .instance_size = sizeof(NPCM7xxGPIOState), | ||
666 | + .class_init = npcm7xx_gpio_class_init, | ||
667 | + .instance_init = npcm7xx_gpio_init, | ||
668 | + }, | ||
669 | +}; | ||
670 | +DEFINE_TYPES(npcm7xx_gpio_types); | ||
671 | diff --git a/tests/qtest/npcm7xx_gpio-test.c b/tests/qtest/npcm7xx_gpio-test.c | ||
672 | new file mode 100644 | ||
673 | index XXXXXXX..XXXXXXX | ||
674 | --- /dev/null | ||
675 | +++ b/tests/qtest/npcm7xx_gpio-test.c | ||
676 | @@ -XXX,XX +XXX,XX @@ | ||
677 | +/* | ||
678 | + * QTest testcase for the Nuvoton NPCM7xx GPIO modules. | ||
679 | + * | ||
680 | + * Copyright 2020 Google LLC | ||
681 | + * | ||
682 | + * This program is free software; you can redistribute it and/or modify it | ||
683 | + * under the terms of the GNU General Public License as published by the | ||
684 | + * Free Software Foundation; either version 2 of the License, or | ||
685 | + * (at your option) any later version. | ||
686 | + * | ||
687 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
688 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
689 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
690 | + * for more details. | ||
691 | + */ | ||
692 | + | ||
693 | +#include "qemu/osdep.h" | ||
694 | +#include "libqtest-single.h" | ||
695 | + | ||
696 | +#define NR_GPIO_DEVICES (8) | ||
697 | +#define GPIO(x) (0xf0010000 + (x) * 0x1000) | ||
698 | +#define GPIO_IRQ(x) (116 + (x)) | ||
699 | + | ||
700 | +/* GPIO registers */ | ||
701 | +#define GP_N_TLOCK1 0x00 | ||
702 | +#define GP_N_DIN 0x04 /* Data IN */ | ||
703 | +#define GP_N_POL 0x08 /* Polarity */ | ||
704 | +#define GP_N_DOUT 0x0c /* Data OUT */ | ||
705 | +#define GP_N_OE 0x10 /* Output Enable */ | ||
706 | +#define GP_N_OTYP 0x14 | ||
707 | +#define GP_N_MP 0x18 | ||
708 | +#define GP_N_PU 0x1c /* Pull-up */ | ||
709 | +#define GP_N_PD 0x20 /* Pull-down */ | ||
710 | +#define GP_N_DBNC 0x24 /* Debounce */ | ||
711 | +#define GP_N_EVTYP 0x28 /* Event Type */ | ||
712 | +#define GP_N_EVBE 0x2c /* Event Both Edge */ | ||
713 | +#define GP_N_OBL0 0x30 | ||
714 | +#define GP_N_OBL1 0x34 | ||
715 | +#define GP_N_OBL2 0x38 | ||
716 | +#define GP_N_OBL3 0x3c | ||
717 | +#define GP_N_EVEN 0x40 /* Event Enable */ | ||
718 | +#define GP_N_EVENS 0x44 /* Event Set (enable) */ | ||
719 | +#define GP_N_EVENC 0x48 /* Event Clear (disable) */ | ||
720 | +#define GP_N_EVST 0x4c /* Event Status */ | ||
721 | +#define GP_N_SPLCK 0x50 | ||
722 | +#define GP_N_MPLCK 0x54 | ||
723 | +#define GP_N_IEM 0x58 /* Input Enable */ | ||
724 | +#define GP_N_OSRC 0x5c | ||
725 | +#define GP_N_ODSC 0x60 | ||
726 | +#define GP_N_DOS 0x68 /* Data OUT Set */ | ||
727 | +#define GP_N_DOC 0x6c /* Data OUT Clear */ | ||
728 | +#define GP_N_OES 0x70 /* Output Enable Set */ | ||
729 | +#define GP_N_OEC 0x74 /* Output Enable Clear */ | ||
730 | +#define GP_N_TLOCK2 0x7c | ||
731 | + | ||
732 | +static void gpio_unlock(int n) | ||
733 | +{ | ||
734 | + if (readl(GPIO(n) + GP_N_TLOCK1) != 0) { | ||
735 | + writel(GPIO(n) + GP_N_TLOCK2, 0xc0de1248); | ||
736 | + writel(GPIO(n) + GP_N_TLOCK1, 0xc0defa73); | ||
737 | + } | ||
738 | +} | ||
739 | + | ||
740 | +/* Restore the GPIO controller to a sensible default state. */ | ||
741 | +static void gpio_reset(int n) | ||
742 | +{ | ||
743 | + gpio_unlock(0); | ||
744 | + | ||
745 | + writel(GPIO(n) + GP_N_EVEN, 0x00000000); | ||
746 | + writel(GPIO(n) + GP_N_EVST, 0xffffffff); | ||
747 | + writel(GPIO(n) + GP_N_POL, 0x00000000); | ||
748 | + writel(GPIO(n) + GP_N_DOUT, 0x00000000); | ||
749 | + writel(GPIO(n) + GP_N_OE, 0x00000000); | ||
750 | + writel(GPIO(n) + GP_N_OTYP, 0x00000000); | ||
751 | + writel(GPIO(n) + GP_N_PU, 0xffffffff); | ||
752 | + writel(GPIO(n) + GP_N_PD, 0x00000000); | ||
753 | + writel(GPIO(n) + GP_N_IEM, 0xffffffff); | ||
754 | +} | ||
755 | + | ||
756 | +static void test_dout_to_din(void) | ||
757 | +{ | ||
758 | + gpio_reset(0); | ||
759 | + | ||
760 | + /* When output is enabled, DOUT should be reflected on DIN. */ | ||
761 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
762 | + /* PU and PD shouldn't have any impact on DIN. */ | ||
763 | + writel(GPIO(0) + GP_N_PU, 0xffff0000); | ||
764 | + writel(GPIO(0) + GP_N_PD, 0x0000ffff); | ||
765 | + writel(GPIO(0) + GP_N_DOUT, 0x12345678); | ||
766 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x12345678); | ||
767 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x12345678); | ||
768 | +} | ||
769 | + | ||
770 | +static void test_pullup_pulldown(void) | ||
771 | +{ | ||
772 | + gpio_reset(0); | ||
773 | + | ||
774 | + /* | ||
775 | + * When output is disabled, and PD is the inverse of PU, PU should be | ||
776 | + * reflected on DIN. If PD is not the inverse of PU, the state of DIN is | ||
777 | + * undefined, so we don't test that. | ||
778 | + */ | ||
779 | + writel(GPIO(0) + GP_N_OE, 0x00000000); | ||
780 | + /* DOUT shouldn't have any impact on DIN. */ | ||
781 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | ||
782 | + writel(GPIO(0) + GP_N_PU, 0x23456789); | ||
783 | + writel(GPIO(0) + GP_N_PD, ~0x23456789U); | ||
784 | + g_assert_cmphex(readl(GPIO(0) + GP_N_PU), ==, 0x23456789); | ||
785 | + g_assert_cmphex(readl(GPIO(0) + GP_N_PD), ==, ~0x23456789U); | ||
786 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x23456789); | ||
787 | +} | ||
788 | + | ||
789 | +static void test_output_enable(void) | ||
790 | +{ | ||
791 | + gpio_reset(0); | ||
792 | + | ||
793 | + /* | ||
794 | + * With all pins weakly pulled down, and DOUT all-ones, OE should be | ||
795 | + * reflected on DIN. | ||
796 | + */ | ||
797 | + writel(GPIO(0) + GP_N_DOUT, 0xffffffff); | ||
798 | + writel(GPIO(0) + GP_N_PU, 0x00000000); | ||
799 | + writel(GPIO(0) + GP_N_PD, 0xffffffff); | ||
800 | + writel(GPIO(0) + GP_N_OE, 0x3456789a); | ||
801 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x3456789a); | ||
802 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x3456789a); | ||
803 | + | ||
804 | + writel(GPIO(0) + GP_N_OEC, 0x00030002); | ||
805 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x34547898); | ||
806 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x34547898); | ||
807 | + | ||
808 | + writel(GPIO(0) + GP_N_OES, 0x0000f001); | ||
809 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OE), ==, 0x3454f899); | ||
810 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x3454f899); | ||
811 | +} | ||
812 | + | ||
813 | +static void test_open_drain(void) | ||
814 | +{ | ||
815 | + gpio_reset(0); | ||
816 | + | ||
817 | + /* | ||
818 | + * Upper half of DOUT drives a 1 only if the corresponding bit in OTYP is | ||
819 | + * not set. If OTYP is set, DIN is determined by PU/PD. Lower half of | ||
820 | + * DOUT always drives a 0 regardless of OTYP; PU/PD have no effect. When | ||
821 | + * OE is 0, output is determined by PU/PD; OTYP has no effect. | ||
822 | + */ | ||
823 | + writel(GPIO(0) + GP_N_OTYP, 0x456789ab); | ||
824 | + writel(GPIO(0) + GP_N_OE, 0xf0f0f0f0); | ||
825 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | ||
826 | + writel(GPIO(0) + GP_N_PU, 0xff00ff00); | ||
827 | + writel(GPIO(0) + GP_N_PD, 0x00ff00ff); | ||
828 | + g_assert_cmphex(readl(GPIO(0) + GP_N_OTYP), ==, 0x456789ab); | ||
829 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff900f00); | ||
830 | +} | ||
831 | + | ||
832 | +static void test_polarity(void) | ||
833 | +{ | ||
834 | + gpio_reset(0); | ||
835 | + | ||
836 | + /* | ||
837 | + * In push-pull mode, DIN should reflect DOUT because the signal is | ||
838 | + * inverted in both directions. | ||
839 | + */ | ||
840 | + writel(GPIO(0) + GP_N_OTYP, 0x00000000); | ||
841 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
842 | + writel(GPIO(0) + GP_N_DOUT, 0x56789abc); | ||
843 | + writel(GPIO(0) + GP_N_POL, 0x6789abcd); | ||
844 | + g_assert_cmphex(readl(GPIO(0) + GP_N_POL), ==, 0x6789abcd); | ||
845 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0x56789abc); | ||
846 | + | ||
847 | + /* | ||
848 | + * When turning off the drivers, DIN should reflect the inverse of the | ||
849 | + * pulled-up lines. | ||
850 | + */ | ||
851 | + writel(GPIO(0) + GP_N_OE, 0x00000000); | ||
852 | + writel(GPIO(0) + GP_N_POL, 0xffffffff); | ||
853 | + writel(GPIO(0) + GP_N_PU, 0x789abcde); | ||
854 | + writel(GPIO(0) + GP_N_PD, ~0x789abcdeU); | ||
855 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, ~0x789abcdeU); | ||
856 | + | ||
857 | + /* | ||
858 | + * In open-drain mode, DOUT=1 will appear to drive the pin high (since DIN | ||
859 | + * is inverted), while DOUT=0 will leave the pin floating. | ||
860 | + */ | ||
861 | + writel(GPIO(0) + GP_N_OTYP, 0xffffffff); | ||
862 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
863 | + writel(GPIO(0) + GP_N_PU, 0xffff0000); | ||
864 | + writel(GPIO(0) + GP_N_PD, 0x0000ffff); | ||
865 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
866 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff00ffff); | ||
867 | +} | ||
868 | + | ||
869 | +static void test_input_mask(void) | ||
870 | +{ | ||
871 | + gpio_reset(0); | ||
872 | + | ||
873 | + /* IEM=0 forces the input to zero before polarity inversion. */ | ||
874 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
875 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
876 | + writel(GPIO(0) + GP_N_POL, 0xffff0000); | ||
877 | + writel(GPIO(0) + GP_N_IEM, 0x87654321); | ||
878 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DIN), ==, 0xff9a4300); | ||
879 | +} | ||
880 | + | ||
881 | +static void test_temp_lock(void) | ||
882 | +{ | ||
883 | + gpio_reset(0); | ||
884 | + | ||
885 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | ||
886 | + | ||
887 | + /* Make sure we're unlocked initially. */ | ||
888 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | ||
889 | + /* Writing any value to TLOCK1 will lock. */ | ||
890 | + writel(GPIO(0) + GP_N_TLOCK1, 0); | ||
891 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 1); | ||
892 | + writel(GPIO(0) + GP_N_DOUT, 0xa9876543); | ||
893 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x98765432); | ||
894 | + /* Now, try to unlock. */ | ||
895 | + gpio_unlock(0); | ||
896 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | ||
897 | + writel(GPIO(0) + GP_N_DOUT, 0xa9876543); | ||
898 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0xa9876543); | ||
899 | + | ||
900 | + /* Try it again, but write TLOCK2 to lock. */ | ||
901 | + writel(GPIO(0) + GP_N_TLOCK2, 0); | ||
902 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 1); | ||
903 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | ||
904 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0xa9876543); | ||
905 | + /* Now, try to unlock. */ | ||
906 | + gpio_unlock(0); | ||
907 | + g_assert_cmphex(readl(GPIO(0) + GP_N_TLOCK1), ==, 0); | ||
908 | + writel(GPIO(0) + GP_N_DOUT, 0x98765432); | ||
909 | + g_assert_cmphex(readl(GPIO(0) + GP_N_DOUT), ==, 0x98765432); | ||
910 | +} | ||
911 | + | ||
912 | +static void test_events_level(void) | ||
913 | +{ | ||
914 | + gpio_reset(0); | ||
915 | + | ||
916 | + writel(GPIO(0) + GP_N_EVTYP, 0x00000000); | ||
917 | + writel(GPIO(0) + GP_N_DOUT, 0xba987654); | ||
918 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
919 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | ||
920 | + | ||
921 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba987654); | ||
922 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
923 | + writel(GPIO(0) + GP_N_DOUT, 0x00000000); | ||
924 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba987654); | ||
925 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
926 | + writel(GPIO(0) + GP_N_EVST, 0x00007654); | ||
927 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0xba980000); | ||
928 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
929 | + writel(GPIO(0) + GP_N_EVST, 0xba980000); | ||
930 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
931 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
932 | +} | ||
933 | + | ||
934 | +static void test_events_rising_edge(void) | ||
935 | +{ | ||
936 | + gpio_reset(0); | ||
937 | + | ||
938 | + writel(GPIO(0) + GP_N_EVTYP, 0xffffffff); | ||
939 | + writel(GPIO(0) + GP_N_EVBE, 0x00000000); | ||
940 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | ||
941 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
942 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | ||
943 | + | ||
944 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
945 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
946 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
947 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x0000ff00); | ||
948 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
949 | + writel(GPIO(0) + GP_N_DOUT, 0x00ff0000); | ||
950 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ffff00); | ||
951 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
952 | + writel(GPIO(0) + GP_N_EVST, 0x0000f000); | ||
953 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ff0f00); | ||
954 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
955 | + writel(GPIO(0) + GP_N_EVST, 0x00ff0f00); | ||
956 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
957 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
958 | +} | ||
959 | + | ||
960 | +static void test_events_both_edges(void) | ||
961 | +{ | ||
962 | + gpio_reset(0); | ||
963 | + | ||
964 | + writel(GPIO(0) + GP_N_EVTYP, 0xffffffff); | ||
965 | + writel(GPIO(0) + GP_N_EVBE, 0xffffffff); | ||
966 | + writel(GPIO(0) + GP_N_DOUT, 0xffff0000); | ||
967 | + writel(GPIO(0) + GP_N_OE, 0xffffffff); | ||
968 | + writel(GPIO(0) + GP_N_EVST, 0xffffffff); | ||
969 | + | ||
970 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
971 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
972 | + writel(GPIO(0) + GP_N_DOUT, 0xff00ff00); | ||
973 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00ffff00); | ||
974 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
975 | + writel(GPIO(0) + GP_N_DOUT, 0xef00ff08); | ||
976 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x10ffff08); | ||
977 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
978 | + writel(GPIO(0) + GP_N_EVST, 0x0000f000); | ||
979 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x10ff0f08); | ||
980 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
981 | + writel(GPIO(0) + GP_N_EVST, 0x10ff0f08); | ||
982 | + g_assert_cmphex(readl(GPIO(0) + GP_N_EVST), ==, 0x00000000); | ||
983 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(0))); | ||
984 | +} | ||
985 | + | ||
986 | +static void test_gpion_irq(gconstpointer test_data) | ||
987 | +{ | ||
988 | + intptr_t n = (intptr_t)test_data; | ||
989 | + | ||
990 | + gpio_reset(n); | ||
991 | + | ||
992 | + writel(GPIO(n) + GP_N_EVTYP, 0x00000000); | ||
993 | + writel(GPIO(n) + GP_N_DOUT, 0x00000000); | ||
994 | + writel(GPIO(n) + GP_N_OE, 0xffffffff); | ||
995 | + writel(GPIO(n) + GP_N_EVST, 0xffffffff); | ||
996 | + writel(GPIO(n) + GP_N_EVEN, 0x00000000); | ||
997 | + | ||
998 | + /* Trigger an event; interrupts are masked. */ | ||
999 | + g_assert_cmphex(readl(GPIO(n) + GP_N_EVST), ==, 0x00000000); | ||
1000 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1001 | + writel(GPIO(n) + GP_N_DOS, 0x00008000); | ||
1002 | + g_assert_cmphex(readl(GPIO(n) + GP_N_EVST), ==, 0x00008000); | ||
1003 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1004 | + | ||
1005 | + /* Unmask all event interrupts; verify that the interrupt fired. */ | ||
1006 | + writel(GPIO(n) + GP_N_EVEN, 0xffffffff); | ||
1007 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1008 | + | ||
1009 | + /* Clear the current bit, set a new bit, irq stays asserted. */ | ||
1010 | + writel(GPIO(n) + GP_N_DOC, 0x00008000); | ||
1011 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1012 | + writel(GPIO(n) + GP_N_DOS, 0x00000200); | ||
1013 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1014 | + writel(GPIO(n) + GP_N_EVST, 0x00008000); | ||
1015 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1016 | + | ||
1017 | + /* Mask/unmask the event that's currently active. */ | ||
1018 | + writel(GPIO(n) + GP_N_EVENC, 0x00000200); | ||
1019 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1020 | + writel(GPIO(n) + GP_N_EVENS, 0x00000200); | ||
1021 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1022 | + | ||
1023 | + /* Clear the input and the status bit, irq is deasserted. */ | ||
1024 | + writel(GPIO(n) + GP_N_DOC, 0x00000200); | ||
1025 | + g_assert_true(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1026 | + writel(GPIO(n) + GP_N_EVST, 0x00000200); | ||
1027 | + g_assert_false(qtest_get_irq(global_qtest, GPIO_IRQ(n))); | ||
1028 | +} | ||
1029 | + | ||
1030 | +int main(int argc, char **argv) | ||
1031 | +{ | ||
1032 | + int ret; | ||
1033 | + int i; | ||
1034 | + | ||
1035 | + g_test_init(&argc, &argv, NULL); | ||
1036 | + g_test_set_nonfatal_assertions(); | ||
1037 | + | ||
1038 | + qtest_add_func("/npcm7xx_gpio/dout_to_din", test_dout_to_din); | ||
1039 | + qtest_add_func("/npcm7xx_gpio/pullup_pulldown", test_pullup_pulldown); | ||
1040 | + qtest_add_func("/npcm7xx_gpio/output_enable", test_output_enable); | ||
1041 | + qtest_add_func("/npcm7xx_gpio/open_drain", test_open_drain); | ||
1042 | + qtest_add_func("/npcm7xx_gpio/polarity", test_polarity); | ||
1043 | + qtest_add_func("/npcm7xx_gpio/input_mask", test_input_mask); | ||
1044 | + qtest_add_func("/npcm7xx_gpio/temp_lock", test_temp_lock); | ||
1045 | + qtest_add_func("/npcm7xx_gpio/events/level", test_events_level); | ||
1046 | + qtest_add_func("/npcm7xx_gpio/events/rising_edge", test_events_rising_edge); | ||
1047 | + qtest_add_func("/npcm7xx_gpio/events/both_edges", test_events_both_edges); | ||
1048 | + | ||
1049 | + for (i = 0; i < NR_GPIO_DEVICES; i++) { | ||
1050 | + g_autofree char *test_name = | ||
1051 | + g_strdup_printf("/npcm7xx_gpio/gpio[%d]/irq", i); | ||
1052 | + qtest_add_data_func(test_name, (void *)(intptr_t)i, test_gpion_irq); | ||
1053 | + } | ||
1054 | + | ||
1055 | + qtest_start("-machine npcm750-evb"); | ||
1056 | + qtest_irq_intercept_in(global_qtest, "/machine/soc/a9mpcore/gic"); | ||
1057 | + ret = g_test_run(); | ||
1058 | + qtest_end(); | ||
1059 | + | ||
1060 | + return ret; | ||
1061 | +} | ||
1062 | diff --git a/hw/gpio/meson.build b/hw/gpio/meson.build | ||
1063 | index XXXXXXX..XXXXXXX 100644 | ||
1064 | --- a/hw/gpio/meson.build | ||
1065 | +++ b/hw/gpio/meson.build | ||
1066 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_PUV3', if_true: files('puv3_gpio.c')) | ||
1067 | softmmu_ss.add(when: 'CONFIG_ZAURUS', if_true: files('zaurus.c')) | ||
1068 | |||
1069 | softmmu_ss.add(when: 'CONFIG_IMX', if_true: files('imx_gpio.c')) | ||
1070 | +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_gpio.c')) | ||
1071 | softmmu_ss.add(when: 'CONFIG_NRF51_SOC', if_true: files('nrf51_gpio.c')) | ||
1072 | softmmu_ss.add(when: 'CONFIG_OMAP', if_true: files('omap_gpio.c')) | ||
1073 | softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_gpio.c')) | ||
1074 | diff --git a/hw/gpio/trace-events b/hw/gpio/trace-events | ||
1075 | index XXXXXXX..XXXXXXX 100644 | ||
1076 | --- a/hw/gpio/trace-events | ||
1077 | +++ b/hw/gpio/trace-events | ||
1078 | @@ -XXX,XX +XXX,XX @@ | ||
1079 | # See docs/devel/tracing.txt for syntax documentation. | ||
1080 | |||
1081 | +# npcm7xx_gpio.c | ||
1082 | +npcm7xx_gpio_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 | ||
1083 | +npcm7xx_gpio_write(const char *id, uint64_t offset, uint64_t value) "%s offset: 0x%04" PRIx64 " value 0x%08" PRIx64 | ||
1084 | +npcm7xx_gpio_set_input(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32 | ||
1085 | +npcm7xx_gpio_set_output(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32 | ||
1086 | +npcm7xx_gpio_update_events(const char *id, uint32_t evst, uint32_t even) "%s evst: 0x%08" PRIx32 " even: 0x%08" PRIx32 | ||
1087 | + | ||
1088 | # nrf51_gpio.c | ||
1089 | nrf51_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
1090 | nrf51_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64 | ||
1091 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
1092 | index XXXXXXX..XXXXXXX 100644 | ||
1093 | --- a/tests/qtest/meson.build | ||
1094 | +++ b/tests/qtest/meson.build | ||
1095 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | ||
1096 | ['prom-env-test', 'boot-serial-test'] | ||
1097 | |||
1098 | qtests_npcm7xx = \ | ||
1099 | - ['npcm7xx_rng-test', | ||
1100 | + ['npcm7xx_gpio-test', | ||
1101 | + 'npcm7xx_rng-test', | ||
1102 | 'npcm7xx_timer-test', | ||
1103 | 'npcm7xx_watchdog_timer-test'] | ||
1104 | qtests_arm = \ | ||
145 | -- | 1105 | -- |
146 | 2.19.1 | 1106 | 2.20.1 |
147 | 1107 | ||
148 | 1108 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Zenghui Yu <yuzenghui@huawei.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Ensure the vSMMUv3 will be restored before all PCIe devices so that DMA |
4 | Message-id: 20181011205206.3552-11-richard.henderson@linaro.org | 4 | translation can work properly during migration. |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 5 | |
6 | Signed-off-by: Zenghui Yu <yuzenghui@huawei.com> | ||
7 | Message-id: 20201019091508.197-1-yuzenghui@huawei.com | ||
8 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 10 | --- |
8 | target/arm/translate.c | 16 ++++++++-------- | 11 | hw/arm/smmuv3.c | 1 + |
9 | 1 file changed, 8 insertions(+), 8 deletions(-) | 12 | 1 file changed, 1 insertion(+) |
10 | 13 | ||
11 | 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 |
12 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate.c | 16 | --- a/hw/arm/smmuv3.c |
14 | +++ b/target/arm/translate.c | 17 | +++ b/hw/arm/smmuv3.c |
15 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 18 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_smmuv3 = { |
16 | tcg_temp_free_ptr(ptr1); | 19 | .name = "smmuv3", |
17 | tcg_temp_free_ptr(ptr2); | 20 | .version_id = 1, |
18 | break; | 21 | .minimum_version_id = 1, |
19 | + | 22 | + .priority = MIG_PRI_IOMMU, |
20 | + case NEON_2RM_VMVN: | 23 | .fields = (VMStateField[]) { |
21 | + tcg_gen_gvec_not(0, rd_ofs, rm_ofs, vec_size, vec_size); | 24 | VMSTATE_UINT32(features, SMMUv3State), |
22 | + break; | 25 | VMSTATE_UINT8(sid_size, SMMUv3State), |
23 | + case NEON_2RM_VNEG: | ||
24 | + tcg_gen_gvec_neg(size, rd_ofs, rm_ofs, vec_size, vec_size); | ||
25 | + break; | ||
26 | + | ||
27 | default: | ||
28 | elementwise: | ||
29 | for (pass = 0; pass < (q ? 4 : 2); pass++) { | ||
30 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
31 | case NEON_2RM_VCNT: | ||
32 | gen_helper_neon_cnt_u8(tmp, tmp); | ||
33 | break; | ||
34 | - case NEON_2RM_VMVN: | ||
35 | - tcg_gen_not_i32(tmp, tmp); | ||
36 | - break; | ||
37 | case NEON_2RM_VQABS: | ||
38 | switch (size) { | ||
39 | case 0: | ||
40 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
41 | default: abort(); | ||
42 | } | ||
43 | break; | ||
44 | - case NEON_2RM_VNEG: | ||
45 | - tmp2 = tcg_const_i32(0); | ||
46 | - gen_neon_rsb(size, tmp, tmp2); | ||
47 | - tcg_temp_free_i32(tmp2); | ||
48 | - break; | ||
49 | case NEON_2RM_VCGT0_F: | ||
50 | { | ||
51 | TCGv_ptr fpstatus = get_fpstatus_ptr(1); | ||
52 | -- | 26 | -- |
53 | 2.19.1 | 27 | 2.20.1 |
54 | 28 | ||
55 | 29 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | No code out of bcm2836.c uses (or requires) the BCM283XInfo |
4 | Message-id: 20181011205206.3552-10-richard.henderson@linaro.org | 4 | declarations. Move it locally to the C source file. |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 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 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 10 | --- |
8 | target/arm/translate.c | 29 ++++++++++------------------- | 11 | include/hw/arm/bcm2836.h | 8 -------- |
9 | 1 file changed, 10 insertions(+), 19 deletions(-) | 12 | hw/arm/bcm2836.c | 14 ++++++++++++++ |
13 | 2 files changed, 14 insertions(+), 8 deletions(-) | ||
10 | 14 | ||
11 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 15 | diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h |
12 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate.c | 17 | --- a/include/hw/arm/bcm2836.h |
14 | +++ b/target/arm/translate.c | 18 | +++ b/include/hw/arm/bcm2836.h |
15 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 19 | @@ -XXX,XX +XXX,XX @@ struct BCM283XState { |
16 | break; | 20 | BCM2835PeripheralState peripherals; |
17 | } | 21 | }; |
18 | return 0; | 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; | ||
19 | + | 41 | + |
20 | + case NEON_3R_VADD_VSUB: | 42 | +typedef struct BCM283XClass { |
21 | + if (u) { | 43 | + /*< private >*/ |
22 | + tcg_gen_gvec_sub(size, rd_ofs, rn_ofs, rm_ofs, | 44 | + DeviceClass parent_class; |
23 | + vec_size, vec_size); | 45 | + /*< public >*/ |
24 | + } else { | 46 | + const BCM283XInfo *info; |
25 | + tcg_gen_gvec_add(size, rd_ofs, rn_ofs, rm_ofs, | 47 | +} BCM283XClass; |
26 | + vec_size, vec_size); | 48 | + |
27 | + } | 49 | struct BCM283XInfo { |
28 | + return 0; | 50 | const char *name; |
29 | } | 51 | const char *cpu_type; |
30 | if (size == 3) { | 52 | @@ -XXX,XX +XXX,XX @@ struct BCM283XInfo { |
31 | /* 64-bit element instructions. */ | 53 | int clusterid; |
32 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 54 | }; |
33 | cpu_V1, cpu_V0); | 55 | |
34 | } | 56 | +#define BCM283X_CLASS(klass) \ |
35 | break; | 57 | + OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X) |
36 | - case NEON_3R_VADD_VSUB: | 58 | +#define BCM283X_GET_CLASS(obj) \ |
37 | - if (u) { | 59 | + OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) |
38 | - tcg_gen_sub_i64(CPU_V001); | 60 | + |
39 | - } else { | 61 | static const BCM283XInfo bcm283x_socs[] = { |
40 | - tcg_gen_add_i64(CPU_V001); | 62 | { |
41 | - } | 63 | .name = TYPE_BCM2836, |
42 | - break; | ||
43 | default: | ||
44 | abort(); | ||
45 | } | ||
46 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
47 | tmp2 = neon_load_reg(rd, pass); | ||
48 | gen_neon_add(size, tmp, tmp2); | ||
49 | break; | ||
50 | - case NEON_3R_VADD_VSUB: | ||
51 | - if (!u) { /* VADD */ | ||
52 | - gen_neon_add(size, tmp, tmp2); | ||
53 | - } else { /* VSUB */ | ||
54 | - switch (size) { | ||
55 | - case 0: gen_helper_neon_sub_u8(tmp, tmp, tmp2); break; | ||
56 | - case 1: gen_helper_neon_sub_u16(tmp, tmp, tmp2); break; | ||
57 | - case 2: tcg_gen_sub_i32(tmp, tmp, tmp2); break; | ||
58 | - default: abort(); | ||
59 | - } | ||
60 | - } | ||
61 | - break; | ||
62 | case NEON_3R_VTST_VCEQ: | ||
63 | if (!u) { /* VTST */ | ||
64 | switch (size) { | ||
65 | -- | 64 | -- |
66 | 2.19.1 | 65 | 2.20.1 |
67 | 66 | ||
68 | 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 |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | The BCM2835 has only one core. Introduce the core_count field to |
4 | Message-id: 20181011205206.3552-8-richard.henderson@linaro.org | 4 | be able to use values different than BCM283X_NCPUS (4). |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 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 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 10 | --- |
8 | target/arm/translate.c | 67 ++++++++++++++++++++++++------------------ | 11 | hw/arm/bcm2836.c | 5 ++++- |
9 | 1 file changed, 39 insertions(+), 28 deletions(-) | 12 | 1 file changed, 4 insertions(+), 1 deletion(-) |
10 | 13 | ||
11 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 14 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
12 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate.c | 16 | --- a/hw/arm/bcm2836.c |
14 | +++ b/target/arm/translate.c | 17 | +++ b/hw/arm/bcm2836.c |
15 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 18 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass { |
16 | return 1; | 19 | /*< public >*/ |
17 | } | 20 | const char *name; |
18 | } else { /* (insn & 0x00380080) == 0 */ | 21 | const char *cpu_type; |
19 | - int invert; | 22 | + unsigned core_count; |
20 | + int invert, reg_ofs, vec_size; | 23 | hwaddr peri_base; /* Peripheral base address seen by the CPU */ |
21 | + | 24 | hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */ |
22 | if (q && (rd & 1)) { | 25 | int clusterid; |
23 | return 1; | 26 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) |
24 | } | 27 | BCM283XClass *bc = BCM283X_GET_CLASS(obj); |
25 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 28 | int n; |
26 | break; | 29 | |
27 | case 14: | 30 | - for (n = 0; n < BCM283X_NCPUS; n++) { |
28 | imm |= (imm << 8) | (imm << 16) | (imm << 24); | 31 | + for (n = 0; n < bc->core_count; n++) { |
29 | - if (invert) | 32 | object_initialize_child(obj, "cpu[*]", &s->cpu[n].core, |
30 | + if (invert) { | 33 | bc->cpu_type); |
31 | imm = ~imm; | 34 | } |
32 | + } | 35 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data) |
33 | break; | 36 | BCM283XClass *bc = BCM283X_CLASS(oc); |
34 | case 15: | 37 | |
35 | if (invert) { | 38 | bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"); |
36 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 39 | + bc->core_count = BCM283X_NCPUS; |
37 | | ((imm & 0x40) ? (0x1f << 25) : (1 << 30)); | 40 | bc->peri_base = 0x3f000000; |
38 | break; | 41 | bc->ctrl_base = 0x40000000; |
39 | } | 42 | bc->clusterid = 0xf; |
40 | - if (invert) | 43 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) |
41 | + if (invert) { | 44 | BCM283XClass *bc = BCM283X_CLASS(oc); |
42 | imm = ~imm; | 45 | |
43 | + } | 46 | bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"); |
44 | 47 | + bc->core_count = BCM283X_NCPUS; | |
45 | - for (pass = 0; pass < (q ? 4 : 2); pass++) { | 48 | bc->peri_base = 0x3f000000; |
46 | - if (op & 1 && op < 12) { | 49 | bc->ctrl_base = 0x40000000; |
47 | - tmp = neon_load_reg(rd, pass); | 50 | bc->clusterid = 0x0; |
48 | - if (invert) { | ||
49 | - /* The immediate value has already been inverted, so | ||
50 | - BIC becomes AND. */ | ||
51 | - tcg_gen_andi_i32(tmp, tmp, imm); | ||
52 | - } else { | ||
53 | - tcg_gen_ori_i32(tmp, tmp, imm); | ||
54 | - } | ||
55 | + reg_ofs = neon_reg_offset(rd, 0); | ||
56 | + vec_size = q ? 16 : 8; | ||
57 | + | ||
58 | + if (op & 1 && op < 12) { | ||
59 | + if (invert) { | ||
60 | + /* The immediate value has already been inverted, | ||
61 | + * so BIC becomes AND. | ||
62 | + */ | ||
63 | + tcg_gen_gvec_andi(MO_32, reg_ofs, reg_ofs, imm, | ||
64 | + vec_size, vec_size); | ||
65 | } else { | ||
66 | - /* VMOV, VMVN. */ | ||
67 | - tmp = tcg_temp_new_i32(); | ||
68 | - if (op == 14 && invert) { | ||
69 | - int n; | ||
70 | - uint32_t val; | ||
71 | - val = 0; | ||
72 | - for (n = 0; n < 4; n++) { | ||
73 | - if (imm & (1 << (n + (pass & 1) * 4))) | ||
74 | - val |= 0xff << (n * 8); | ||
75 | - } | ||
76 | - tcg_gen_movi_i32(tmp, val); | ||
77 | - } else { | ||
78 | - tcg_gen_movi_i32(tmp, imm); | ||
79 | - } | ||
80 | + tcg_gen_gvec_ori(MO_32, reg_ofs, reg_ofs, imm, | ||
81 | + vec_size, vec_size); | ||
82 | + } | ||
83 | + } else { | ||
84 | + /* VMOV, VMVN. */ | ||
85 | + if (op == 14 && invert) { | ||
86 | + TCGv_i64 t64 = tcg_temp_new_i64(); | ||
87 | + | ||
88 | + for (pass = 0; pass <= q; ++pass) { | ||
89 | + uint64_t val = 0; | ||
90 | + int n; | ||
91 | + | ||
92 | + for (n = 0; n < 8; n++) { | ||
93 | + if (imm & (1 << (n + pass * 8))) { | ||
94 | + val |= 0xffull << (n * 8); | ||
95 | + } | ||
96 | + } | ||
97 | + tcg_gen_movi_i64(t64, val); | ||
98 | + neon_store_reg64(t64, rd + pass); | ||
99 | + } | ||
100 | + tcg_temp_free_i64(t64); | ||
101 | + } else { | ||
102 | + tcg_gen_gvec_dup32i(reg_ofs, vec_size, vec_size, imm); | ||
103 | } | ||
104 | - neon_store_reg(rd, pass, tmp); | ||
105 | } | ||
106 | } | ||
107 | } else { /* (insn & 0x00800010 == 0x00800000) */ | ||
108 | -- | 51 | -- |
109 | 2.19.1 | 52 | 2.20.1 |
110 | 53 | ||
111 | 54 | diff view generated by jsdifflib |
1 | The switch_mode() function is defined in target/arm/helper.c and used | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | only in that file and nowhere else, so we can make it file-local | ||
3 | rather than global. | ||
4 | 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 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20181012144235.19646-3-peter.maydell@linaro.org | ||
8 | --- | 9 | --- |
9 | target/arm/internals.h | 1 - | 10 | hw/arm/bcm2836.c | 15 +++++++-------- |
10 | target/arm/helper.c | 6 ++++-- | 11 | 1 file changed, 7 insertions(+), 8 deletions(-) |
11 | 2 files changed, 4 insertions(+), 3 deletions(-) | ||
12 | 12 | ||
13 | diff --git a/target/arm/internals.h b/target/arm/internals.h | 13 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
14 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/internals.h | 15 | --- a/hw/arm/bcm2836.c |
16 | +++ b/target/arm/internals.h | 16 | +++ b/hw/arm/bcm2836.c |
17 | @@ -XXX,XX +XXX,XX @@ static inline int bank_number(int mode) | 17 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass { |
18 | g_assert_not_reached(); | 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 | } | ||
19 | } | 40 | } |
20 | 41 | ||
21 | -void switch_mode(CPUARMState *, int); | 42 | -static Property bcm2836_props[] = { |
22 | void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu); | 43 | - DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, |
23 | void arm_translate_init(void); | 44 | - BCM283X_NCPUS), |
24 | 45 | - DEFINE_PROP_END_OF_LIST() | |
25 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 46 | -}; |
26 | index XXXXXXX..XXXXXXX 100644 | 47 | - |
27 | --- a/target/arm/helper.c | 48 | static void bcm283x_class_init(ObjectClass *oc, void *data) |
28 | +++ b/target/arm/helper.c | 49 | { |
29 | @@ -XXX,XX +XXX,XX @@ static void v8m_security_lookup(CPUARMState *env, uint32_t address, | 50 | DeviceClass *dc = DEVICE_CLASS(oc); |
30 | V8M_SAttributes *sattrs); | 51 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data) |
52 | bc->ctrl_base = 0x40000000; | ||
53 | bc->clusterid = 0xf; | ||
54 | dc->realize = bcm2836_realize; | ||
55 | - device_class_set_props(dc, bcm2836_props); | ||
56 | }; | ||
57 | |||
58 | #ifdef TARGET_AARCH64 | ||
59 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) | ||
60 | bc->ctrl_base = 0x40000000; | ||
61 | bc->clusterid = 0x0; | ||
62 | dc->realize = bcm2836_realize; | ||
63 | - device_class_set_props(dc, bcm2836_props); | ||
64 | }; | ||
31 | #endif | 65 | #endif |
32 | 66 | ||
33 | +static void switch_mode(CPUARMState *env, int mode); | ||
34 | + | ||
35 | static int vfp_gdb_get_reg(CPUARMState *env, uint8_t *buf, int reg) | ||
36 | { | ||
37 | int nregs; | ||
38 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_tt)(CPUARMState *env, uint32_t addr, uint32_t op) | ||
39 | return 0; | ||
40 | } | ||
41 | |||
42 | -void switch_mode(CPUARMState *env, int mode) | ||
43 | +static void switch_mode(CPUARMState *env, int mode) | ||
44 | { | ||
45 | ARMCPU *cpu = arm_env_get_cpu(env); | ||
46 | |||
47 | @@ -XXX,XX +XXX,XX @@ void aarch64_sync_64_to_32(CPUARMState *env) | ||
48 | |||
49 | #else | ||
50 | |||
51 | -void switch_mode(CPUARMState *env, int mode) | ||
52 | +static void switch_mode(CPUARMState *env, int mode) | ||
53 | { | ||
54 | int old_mode; | ||
55 | int i; | ||
56 | -- | 67 | -- |
57 | 2.19.1 | 68 | 2.20.1 |
58 | 69 | ||
59 | 70 | diff view generated by jsdifflib |
1 | From: Richard Henderson <rth@twiddle.net> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | This can reduce the number of opcodes required for certain | 3 | The realize() function is clearly composed of two parts, |
4 | complex forms of load-multiple (e.g. ld4.16b). | 4 | each described by a comment: |
5 | 5 | ||
6 | Signed-off-by: Richard Henderson <rth@twiddle.net> | 6 | void realize() |
7 | Message-id: 20181011205206.3552-2-richard.henderson@linaro.org | 7 | { |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 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 | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 21 | --- |
11 | target/arm/translate-a64.c | 12 ++++++++---- | 22 | hw/arm/bcm2836.c | 22 ++++++++++++++++++---- |
12 | 1 file changed, 8 insertions(+), 4 deletions(-) | 23 | 1 file changed, 18 insertions(+), 4 deletions(-) |
13 | 24 | ||
14 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 25 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
15 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/translate-a64.c | 27 | --- a/hw/arm/bcm2836.c |
17 | +++ b/target/arm/translate-a64.c | 28 | +++ b/hw/arm/bcm2836.c |
18 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn) | 29 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) |
19 | bool is_store = !extract32(insn, 22, 1); | 30 | qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count); |
20 | bool is_postidx = extract32(insn, 23, 1); | ||
21 | bool is_q = extract32(insn, 30, 1); | ||
22 | - TCGv_i64 tcg_addr, tcg_rn; | ||
23 | + TCGv_i64 tcg_addr, tcg_rn, tcg_ebytes; | ||
24 | |||
25 | int ebytes = 1 << size; | ||
26 | int elements = (is_q ? 128 : 64) / (8 << size); | ||
27 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn) | ||
28 | tcg_rn = cpu_reg_sp(s, rn); | ||
29 | tcg_addr = tcg_temp_new_i64(); | ||
30 | tcg_gen_mov_i64(tcg_addr, tcg_rn); | ||
31 | + tcg_ebytes = tcg_const_i64(ebytes); | ||
32 | |||
33 | for (r = 0; r < rpt; r++) { | ||
34 | int e; | ||
35 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn) | ||
36 | clear_vec_high(s, is_q, tt); | ||
37 | } | ||
38 | } | ||
39 | - tcg_gen_addi_i64(tcg_addr, tcg_addr, ebytes); | ||
40 | + tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_ebytes); | ||
41 | tt = (tt + 1) % 32; | ||
42 | } | ||
43 | } | ||
44 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn) | ||
45 | tcg_gen_add_i64(tcg_rn, tcg_rn, cpu_reg(s, rm)); | ||
46 | } | ||
47 | } | 31 | } |
48 | + tcg_temp_free_i64(tcg_ebytes); | 32 | |
49 | tcg_temp_free_i64(tcg_addr); | 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"); | ||
50 | } | 43 | } |
51 | 44 | ||
52 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn) | 45 | -static void bcm2836_realize(DeviceState *dev, Error **errp) |
53 | bool replicate = false; | 46 | +static bool bcm283x_common_realize(DeviceState *dev, Error **errp) |
54 | int index = is_q << 3 | S << 2 | size; | 47 | { |
55 | int ebytes, xs; | 48 | BCM283XState *s = BCM283X(dev); |
56 | - TCGv_i64 tcg_addr, tcg_rn; | 49 | BCM283XClass *bc = BCM283X_GET_CLASS(dev); |
57 | + TCGv_i64 tcg_addr, tcg_rn, tcg_ebytes; | 50 | Object *obj; |
58 | 51 | - int n; | |
59 | switch (scale) { | 52 | |
60 | case 3: | 53 | /* common peripherals from bcm2835 */ |
61 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn) | 54 | |
62 | tcg_rn = cpu_reg_sp(s, rn); | 55 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) |
63 | tcg_addr = tcg_temp_new_i64(); | 56 | object_property_add_const_link(OBJECT(&s->peripherals), "ram", obj); |
64 | tcg_gen_mov_i64(tcg_addr, tcg_rn); | 57 | |
65 | + tcg_ebytes = tcg_const_i64(ebytes); | 58 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->peripherals), errp)) { |
66 | 59 | - return; | |
67 | for (xs = 0; xs < selem; xs++) { | 60 | + return false; |
68 | if (replicate) { | ||
69 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn) | ||
70 | do_vec_st(s, rt, index, tcg_addr, scale); | ||
71 | } | ||
72 | } | ||
73 | - tcg_gen_addi_i64(tcg_addr, tcg_addr, ebytes); | ||
74 | + tcg_gen_add_i64(tcg_addr, tcg_addr, tcg_ebytes); | ||
75 | rt = (rt + 1) % 32; | ||
76 | } | 61 | } |
77 | 62 | ||
78 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn) | 63 | object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals), |
79 | tcg_gen_add_i64(tcg_rn, tcg_rn, cpu_reg(s, rm)); | 64 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) |
80 | } | 65 | |
81 | } | 66 | sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0, |
82 | + tcg_temp_free_i64(tcg_ebytes); | 67 | bc->peri_base, 1); |
83 | tcg_temp_free_i64(tcg_addr); | 68 | + return true; |
84 | } | 69 | +} |
85 | 70 | + | |
71 | +static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
72 | +{ | ||
73 | + BCM283XState *s = BCM283X(dev); | ||
74 | + BCM283XClass *bc = BCM283X_GET_CLASS(dev); | ||
75 | + int n; | ||
76 | + | ||
77 | + if (!bcm283x_common_realize(dev, errp)) { | ||
78 | + return; | ||
79 | + } | ||
80 | |||
81 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ | ||
82 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) { | ||
86 | -- | 83 | -- |
87 | 2.19.1 | 84 | 2.20.1 |
88 | 85 | ||
89 | 86 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> |
4 | Message-id: 20181011205206.3552-18-richard.henderson@linaro.org | 4 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
5 | [PMM: added parens in ?: expression] | 5 | Message-id: 20201024170127.3592182-7-f4bug@amsat.org |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 7 | --- |
9 | target/arm/translate.c | 81 ++++++++++++++---------------------------- | 8 | include/hw/arm/bcm2836.h | 1 + |
10 | 1 file changed, 26 insertions(+), 55 deletions(-) | 9 | hw/arm/bcm2836.c | 34 ++++++++++++++++++++++++++++++++++ |
10 | hw/arm/raspi.c | 2 ++ | ||
11 | 3 files changed, 37 insertions(+) | ||
11 | 12 | ||
12 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 13 | diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/translate.c | 15 | --- a/include/hw/arm/bcm2836.h |
15 | +++ b/target/arm/translate.c | 16 | +++ b/include/hw/arm/bcm2836.h |
16 | @@ -XXX,XX +XXX,XX @@ static void gen_vfp_msr(TCGv_i32 tmp) | 17 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X) |
17 | tcg_temp_free_i32(tmp); | 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; | ||
18 | } | 31 | } |
19 | 32 | ||
20 | -static void gen_neon_dup_u8(TCGv_i32 var, int shift) | 33 | +static void bcm2835_realize(DeviceState *dev, Error **errp) |
21 | -{ | 34 | +{ |
22 | - TCGv_i32 tmp = tcg_temp_new_i32(); | 35 | + BCM283XState *s = BCM283X(dev); |
23 | - if (shift) | 36 | + |
24 | - tcg_gen_shri_i32(var, var, shift); | 37 | + if (!bcm283x_common_realize(dev, errp)) { |
25 | - tcg_gen_ext8u_i32(var, var); | 38 | + return; |
26 | - tcg_gen_shli_i32(tmp, var, 8); | 39 | + } |
27 | - tcg_gen_or_i32(var, var, tmp); | 40 | + |
28 | - tcg_gen_shli_i32(tmp, var, 16); | 41 | + if (!qdev_realize(DEVICE(&s->cpu[0].core), NULL, errp)) { |
29 | - tcg_gen_or_i32(var, var, tmp); | 42 | + return; |
30 | - tcg_temp_free_i32(tmp); | 43 | + } |
31 | -} | 44 | + |
32 | - | 45 | + /* Connect irq/fiq outputs from the interrupt controller. */ |
33 | static void gen_neon_dup_low16(TCGv_i32 var) | 46 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0, |
47 | + qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_IRQ)); | ||
48 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1, | ||
49 | + qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_FIQ)); | ||
50 | +} | ||
51 | + | ||
52 | static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
34 | { | 53 | { |
35 | TCGv_i32 tmp = tcg_temp_new_i32(); | 54 | BCM283XState *s = BCM283X(dev); |
36 | @@ -XXX,XX +XXX,XX @@ static void gen_neon_dup_high16(TCGv_i32 var) | 55 | @@ -XXX,XX +XXX,XX @@ static void bcm283x_class_init(ObjectClass *oc, void *data) |
37 | tcg_temp_free_i32(tmp); | 56 | dc->user_creatable = false; |
38 | } | 57 | } |
39 | 58 | ||
40 | -static TCGv_i32 gen_load_and_replicate(DisasContext *s, TCGv_i32 addr, int size) | 59 | +static void bcm2835_class_init(ObjectClass *oc, void *data) |
41 | -{ | 60 | +{ |
42 | - /* Load a single Neon element and replicate into a 32 bit TCG reg */ | 61 | + DeviceClass *dc = DEVICE_CLASS(oc); |
43 | - TCGv_i32 tmp = tcg_temp_new_i32(); | 62 | + BCM283XClass *bc = BCM283X_CLASS(oc); |
44 | - switch (size) { | 63 | + |
45 | - case 0: | 64 | + bc->cpu_type = ARM_CPU_TYPE_NAME("arm1176"); |
46 | - gen_aa32_ld8u(s, tmp, addr, get_mem_index(s)); | 65 | + bc->core_count = 1; |
47 | - gen_neon_dup_u8(tmp, 0); | 66 | + bc->peri_base = 0x20000000; |
48 | - break; | 67 | + dc->realize = bcm2835_realize; |
49 | - case 1: | 68 | +}; |
50 | - gen_aa32_ld16u(s, tmp, addr, get_mem_index(s)); | 69 | + |
51 | - gen_neon_dup_low16(tmp); | 70 | static void bcm2836_class_init(ObjectClass *oc, void *data) |
52 | - break; | ||
53 | - case 2: | ||
54 | - gen_aa32_ld32u(s, tmp, addr, get_mem_index(s)); | ||
55 | - break; | ||
56 | - default: /* Avoid compiler warnings. */ | ||
57 | - abort(); | ||
58 | - } | ||
59 | - return tmp; | ||
60 | -} | ||
61 | - | ||
62 | static int handle_vsel(uint32_t insn, uint32_t rd, uint32_t rn, uint32_t rm, | ||
63 | uint32_t dp) | ||
64 | { | 71 | { |
65 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | 72 | DeviceClass *dc = DEVICE_CLASS(oc); |
66 | int load; | 73 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) |
67 | int shift; | 74 | |
68 | int n; | 75 | static const TypeInfo bcm283x_types[] = { |
69 | + int vec_size; | 76 | { |
70 | TCGv_i32 addr; | 77 | + .name = TYPE_BCM2835, |
71 | TCGv_i32 tmp; | 78 | + .parent = TYPE_BCM283X, |
72 | TCGv_i32 tmp2; | 79 | + .class_init = bcm2835_class_init, |
73 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | 80 | + }, { |
74 | } | 81 | .name = TYPE_BCM2836, |
75 | addr = tcg_temp_new_i32(); | 82 | .parent = TYPE_BCM283X, |
76 | load_reg_var(s, addr, rn); | 83 | .class_init = bcm2836_class_init, |
77 | - if (nregs == 1) { | 84 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
78 | - /* VLD1 to all lanes: bit 5 indicates how many Dregs to write */ | 85 | index XXXXXXX..XXXXXXX 100644 |
79 | - tmp = gen_load_and_replicate(s, addr, size); | 86 | --- a/hw/arm/raspi.c |
80 | - tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd, 0)); | 87 | +++ b/hw/arm/raspi.c |
81 | - tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd, 1)); | 88 | @@ -XXX,XX +XXX,XX @@ FIELD(REV_CODE, MEMORY_SIZE, 20, 3); |
82 | - if (insn & (1 << 5)) { | 89 | FIELD(REV_CODE, STYLE, 23, 1); |
83 | - tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd + 1, 0)); | 90 | |
84 | - tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd + 1, 1)); | 91 | typedef enum RaspiProcessorId { |
85 | - } | 92 | + PROCESSOR_ID_BCM2835 = 0, |
86 | - tcg_temp_free_i32(tmp); | 93 | PROCESSOR_ID_BCM2836 = 1, |
87 | - } else { | 94 | PROCESSOR_ID_BCM2837 = 2, |
88 | - /* VLD2/3/4 to all lanes: bit 5 indicates register stride */ | 95 | } RaspiProcessorId; |
89 | - stride = (insn & (1 << 5)) ? 2 : 1; | 96 | @@ -XXX,XX +XXX,XX @@ static const struct { |
90 | - for (reg = 0; reg < nregs; reg++) { | 97 | const char *type; |
91 | - tmp = gen_load_and_replicate(s, addr, size); | 98 | int cores_count; |
92 | - tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd, 0)); | 99 | } soc_property[] = { |
93 | - tcg_gen_st_i32(tmp, cpu_env, neon_reg_offset(rd, 1)); | 100 | + [PROCESSOR_ID_BCM2835] = {TYPE_BCM2835, 1}, |
94 | - tcg_temp_free_i32(tmp); | 101 | [PROCESSOR_ID_BCM2836] = {TYPE_BCM2836, BCM283X_NCPUS}, |
95 | - tcg_gen_addi_i32(addr, addr, 1 << size); | 102 | [PROCESSOR_ID_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS}, |
96 | - rd += stride; | 103 | }; |
97 | + | ||
98 | + /* VLD1 to all lanes: bit 5 indicates how many Dregs to write. | ||
99 | + * VLD2/3/4 to all lanes: bit 5 indicates register stride. | ||
100 | + */ | ||
101 | + stride = (insn & (1 << 5)) ? 2 : 1; | ||
102 | + vec_size = nregs == 1 ? stride * 8 : 8; | ||
103 | + | ||
104 | + tmp = tcg_temp_new_i32(); | ||
105 | + for (reg = 0; reg < nregs; reg++) { | ||
106 | + gen_aa32_ld_i32(s, tmp, addr, get_mem_index(s), | ||
107 | + s->be_data | size); | ||
108 | + if ((rd & 1) && vec_size == 16) { | ||
109 | + /* We cannot write 16 bytes at once because the | ||
110 | + * destination is unaligned. | ||
111 | + */ | ||
112 | + tcg_gen_gvec_dup_i32(size, neon_reg_offset(rd, 0), | ||
113 | + 8, 8, tmp); | ||
114 | + tcg_gen_gvec_mov(0, neon_reg_offset(rd + 1, 0), | ||
115 | + neon_reg_offset(rd, 0), 8, 8); | ||
116 | + } else { | ||
117 | + tcg_gen_gvec_dup_i32(size, neon_reg_offset(rd, 0), | ||
118 | + vec_size, vec_size, tmp); | ||
119 | } | ||
120 | + tcg_gen_addi_i32(addr, addr, 1 << size); | ||
121 | + rd += stride; | ||
122 | } | ||
123 | + tcg_temp_free_i32(tmp); | ||
124 | tcg_temp_free_i32(addr); | ||
125 | stride = (1 << size) * nregs; | ||
126 | } else { | ||
127 | -- | 104 | -- |
128 | 2.19.1 | 105 | 2.20.1 |
129 | 106 | ||
130 | 107 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | The Pi A is almost the first machine released. |
4 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 4 | It uses a BCM2835 SoC which includes a ARMv6Z core. |
5 | Message-id: 20181011205206.3552-6-richard.henderson@linaro.org | 5 | |
6 | [PMM: drop change to now-deleted cpu_mode_names array] | 6 | Example booting the machine using content from [*] |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 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 | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 26 | --- |
10 | target/arm/translate.c | 4 ++-- | 27 | hw/arm/raspi.c | 13 +++++++++++++ |
11 | 1 file changed, 2 insertions(+), 2 deletions(-) | 28 | 1 file changed, 13 insertions(+) |
12 | 29 | ||
13 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 30 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
14 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/translate.c | 32 | --- a/hw/arm/raspi.c |
16 | +++ b/target/arm/translate.c | 33 | +++ b/hw/arm/raspi.c |
17 | @@ -XXX,XX +XXX,XX @@ static TCGv_i64 cpu_F0d, cpu_F1d; | 34 | @@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc, |
18 | 35 | mc->default_ram_id = "ram"; | |
19 | #include "exec/gen-icount.h" | 36 | }; |
20 | 37 | ||
21 | -static const char *regnames[] = | 38 | +static void raspi1ap_machine_class_init(ObjectClass *oc, void *data) |
22 | +static const char * const regnames[] = | 39 | +{ |
23 | { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7", | 40 | + MachineClass *mc = MACHINE_CLASS(oc); |
24 | "r8", "r9", "r10", "r11", "r12", "r13", "r14", "pc" }; | 41 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); |
25 | 42 | + | |
26 | @@ -XXX,XX +XXX,XX @@ static struct { | 43 | + rmc->board_rev = 0x900021; /* Revision 1.1 */ |
27 | int nregs; | 44 | + raspi_machine_class_common_init(mc, rmc->board_rev); |
28 | int interleave; | 45 | +}; |
29 | int spacing; | 46 | + |
30 | -} neon_ls_element_type[11] = { | 47 | static void raspi2b_machine_class_init(ObjectClass *oc, void *data) |
31 | +} const neon_ls_element_type[11] = { | 48 | { |
32 | {4, 4, 1}, | 49 | MachineClass *mc = MACHINE_CLASS(oc); |
33 | {4, 4, 2}, | 50 | @@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data) |
34 | {4, 1, 1}, | 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, | ||
35 | -- | 61 | -- |
36 | 2.19.1 | 62 | 2.20.1 |
37 | 63 | ||
38 | 64 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Move mla_op and mls_op expanders from translate-a64.c. | 3 | Similarly to the Pi A, the Pi Zero uses a BCM2835 SoC (ARMv6Z core). |
4 | 4 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | The only difference between the revision 1.2 and 1.3 is the latter |
6 | Message-id: 20181011205206.3552-16-richard.henderson@linaro.org | 6 | exposes a CSI camera connector. As we do not implement the Unicam |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | peripheral, there is no point in exposing a camera connector :) |
8 | Therefore we choose to model the 1.2 revision. | ||
9 | |||
10 | Example booting the machine using content from [*]: | ||
11 | |||
12 | $ qemu-system-arm -M raspi0 -serial stdio \ | ||
13 | -kernel raspberrypi/firmware/boot/kernel.img \ | ||
14 | -dtb raspberrypi/firmware/boot/bcm2708-rpi-zero.dtb \ | ||
15 | -append 'printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0' | ||
16 | [ 0.000000] Booting Linux on physical CPU 0x0 | ||
17 | [ 0.000000] Linux version 4.19.118+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1311 Mon Apr 27 14:16:15 BST 2020 | ||
18 | [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d | ||
19 | [ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache | ||
20 | [ 0.000000] OF: fdt: Machine model: Raspberry Pi Zero | ||
21 | ... | ||
22 | |||
23 | [*] http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20200512-2_armhf.deb | ||
24 | |||
25 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
26 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | ||
27 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
28 | Message-id: 20201024170127.3592182-9-f4bug@amsat.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 29 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 30 | --- |
10 | target/arm/translate.h | 2 + | 31 | hw/arm/raspi.c | 13 +++++++++++++ |
11 | target/arm/translate-a64.c | 106 ----------------------------- | 32 | 1 file changed, 13 insertions(+) |
12 | target/arm/translate.c | 134 ++++++++++++++++++++++++++++++++----- | ||
13 | 3 files changed, 120 insertions(+), 122 deletions(-) | ||
14 | 33 | ||
15 | diff --git a/target/arm/translate.h b/target/arm/translate.h | 34 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
16 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate.h | 36 | --- a/hw/arm/raspi.c |
18 | +++ b/target/arm/translate.h | 37 | +++ b/hw/arm/raspi.c |
19 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i32 get_ahp_flag(void) | 38 | @@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc, |
20 | extern const GVecGen3 bsl_op; | 39 | mc->default_ram_id = "ram"; |
21 | extern const GVecGen3 bit_op; | ||
22 | extern const GVecGen3 bif_op; | ||
23 | +extern const GVecGen3 mla_op[4]; | ||
24 | +extern const GVecGen3 mls_op[4]; | ||
25 | extern const GVecGen2i ssra_op[4]; | ||
26 | extern const GVecGen2i usra_op[4]; | ||
27 | extern const GVecGen2i sri_op[4]; | ||
28 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/target/arm/translate-a64.c | ||
31 | +++ b/target/arm/translate-a64.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_3same_float(DisasContext *s, uint32_t insn) | ||
33 | } | ||
34 | } | ||
35 | |||
36 | -static void gen_mla8_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
37 | -{ | ||
38 | - gen_helper_neon_mul_u8(a, a, b); | ||
39 | - gen_helper_neon_add_u8(d, d, a); | ||
40 | -} | ||
41 | - | ||
42 | -static void gen_mla16_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
43 | -{ | ||
44 | - gen_helper_neon_mul_u16(a, a, b); | ||
45 | - gen_helper_neon_add_u16(d, d, a); | ||
46 | -} | ||
47 | - | ||
48 | -static void gen_mla32_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
49 | -{ | ||
50 | - tcg_gen_mul_i32(a, a, b); | ||
51 | - tcg_gen_add_i32(d, d, a); | ||
52 | -} | ||
53 | - | ||
54 | -static void gen_mla64_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
55 | -{ | ||
56 | - tcg_gen_mul_i64(a, a, b); | ||
57 | - tcg_gen_add_i64(d, d, a); | ||
58 | -} | ||
59 | - | ||
60 | -static void gen_mla_vec(unsigned vece, TCGv_vec d, TCGv_vec a, TCGv_vec b) | ||
61 | -{ | ||
62 | - tcg_gen_mul_vec(vece, a, a, b); | ||
63 | - tcg_gen_add_vec(vece, d, d, a); | ||
64 | -} | ||
65 | - | ||
66 | -static void gen_mls8_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
67 | -{ | ||
68 | - gen_helper_neon_mul_u8(a, a, b); | ||
69 | - gen_helper_neon_sub_u8(d, d, a); | ||
70 | -} | ||
71 | - | ||
72 | -static void gen_mls16_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
73 | -{ | ||
74 | - gen_helper_neon_mul_u16(a, a, b); | ||
75 | - gen_helper_neon_sub_u16(d, d, a); | ||
76 | -} | ||
77 | - | ||
78 | -static void gen_mls32_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
79 | -{ | ||
80 | - tcg_gen_mul_i32(a, a, b); | ||
81 | - tcg_gen_sub_i32(d, d, a); | ||
82 | -} | ||
83 | - | ||
84 | -static void gen_mls64_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
85 | -{ | ||
86 | - tcg_gen_mul_i64(a, a, b); | ||
87 | - tcg_gen_sub_i64(d, d, a); | ||
88 | -} | ||
89 | - | ||
90 | -static void gen_mls_vec(unsigned vece, TCGv_vec d, TCGv_vec a, TCGv_vec b) | ||
91 | -{ | ||
92 | - tcg_gen_mul_vec(vece, a, a, b); | ||
93 | - tcg_gen_sub_vec(vece, d, d, a); | ||
94 | -} | ||
95 | - | ||
96 | /* Integer op subgroup of C3.6.16. */ | ||
97 | static void disas_simd_3same_int(DisasContext *s, uint32_t insn) | ||
98 | { | ||
99 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_3same_int(DisasContext *s, uint32_t insn) | ||
100 | .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
101 | .vece = MO_64 }, | ||
102 | }; | ||
103 | - static const GVecGen3 mla_op[4] = { | ||
104 | - { .fni4 = gen_mla8_i32, | ||
105 | - .fniv = gen_mla_vec, | ||
106 | - .opc = INDEX_op_mul_vec, | ||
107 | - .load_dest = true, | ||
108 | - .vece = MO_8 }, | ||
109 | - { .fni4 = gen_mla16_i32, | ||
110 | - .fniv = gen_mla_vec, | ||
111 | - .opc = INDEX_op_mul_vec, | ||
112 | - .load_dest = true, | ||
113 | - .vece = MO_16 }, | ||
114 | - { .fni4 = gen_mla32_i32, | ||
115 | - .fniv = gen_mla_vec, | ||
116 | - .opc = INDEX_op_mul_vec, | ||
117 | - .load_dest = true, | ||
118 | - .vece = MO_32 }, | ||
119 | - { .fni8 = gen_mla64_i64, | ||
120 | - .fniv = gen_mla_vec, | ||
121 | - .opc = INDEX_op_mul_vec, | ||
122 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
123 | - .load_dest = true, | ||
124 | - .vece = MO_64 }, | ||
125 | - }; | ||
126 | - static const GVecGen3 mls_op[4] = { | ||
127 | - { .fni4 = gen_mls8_i32, | ||
128 | - .fniv = gen_mls_vec, | ||
129 | - .opc = INDEX_op_mul_vec, | ||
130 | - .load_dest = true, | ||
131 | - .vece = MO_8 }, | ||
132 | - { .fni4 = gen_mls16_i32, | ||
133 | - .fniv = gen_mls_vec, | ||
134 | - .opc = INDEX_op_mul_vec, | ||
135 | - .load_dest = true, | ||
136 | - .vece = MO_16 }, | ||
137 | - { .fni4 = gen_mls32_i32, | ||
138 | - .fniv = gen_mls_vec, | ||
139 | - .opc = INDEX_op_mul_vec, | ||
140 | - .load_dest = true, | ||
141 | - .vece = MO_32 }, | ||
142 | - { .fni8 = gen_mls64_i64, | ||
143 | - .fniv = gen_mls_vec, | ||
144 | - .opc = INDEX_op_mul_vec, | ||
145 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
146 | - .load_dest = true, | ||
147 | - .vece = MO_64 }, | ||
148 | - }; | ||
149 | |||
150 | int is_q = extract32(insn, 30, 1); | ||
151 | int u = extract32(insn, 29, 1); | ||
152 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
153 | index XXXXXXX..XXXXXXX 100644 | ||
154 | --- a/target/arm/translate.c | ||
155 | +++ b/target/arm/translate.c | ||
156 | @@ -XXX,XX +XXX,XX @@ static void gen_neon_narrow_op(int op, int u, int size, | ||
157 | #define NEON_3R_VABA 15 | ||
158 | #define NEON_3R_VADD_VSUB 16 | ||
159 | #define NEON_3R_VTST_VCEQ 17 | ||
160 | -#define NEON_3R_VML 18 /* VMLA, VMLAL, VMLS, VMLSL */ | ||
161 | +#define NEON_3R_VML 18 /* VMLA, VMLS */ | ||
162 | #define NEON_3R_VMUL 19 | ||
163 | #define NEON_3R_VPMAX 20 | ||
164 | #define NEON_3R_VPMIN 21 | ||
165 | @@ -XXX,XX +XXX,XX @@ const GVecGen2i sli_op[4] = { | ||
166 | .vece = MO_64 }, | ||
167 | }; | 40 | }; |
168 | 41 | ||
169 | +static void gen_mla8_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | 42 | +static void raspi0_machine_class_init(ObjectClass *oc, void *data) |
170 | +{ | 43 | +{ |
171 | + gen_helper_neon_mul_u8(a, a, b); | 44 | + MachineClass *mc = MACHINE_CLASS(oc); |
172 | + gen_helper_neon_add_u8(d, d, a); | 45 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); |
173 | +} | ||
174 | + | 46 | + |
175 | +static void gen_mls8_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | 47 | + rmc->board_rev = 0x920092; /* Revision 1.2 */ |
176 | +{ | 48 | + raspi_machine_class_common_init(mc, rmc->board_rev); |
177 | + gen_helper_neon_mul_u8(a, a, b); | ||
178 | + gen_helper_neon_sub_u8(d, d, a); | ||
179 | +} | ||
180 | + | ||
181 | +static void gen_mla16_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
182 | +{ | ||
183 | + gen_helper_neon_mul_u16(a, a, b); | ||
184 | + gen_helper_neon_add_u16(d, d, a); | ||
185 | +} | ||
186 | + | ||
187 | +static void gen_mls16_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
188 | +{ | ||
189 | + gen_helper_neon_mul_u16(a, a, b); | ||
190 | + gen_helper_neon_sub_u16(d, d, a); | ||
191 | +} | ||
192 | + | ||
193 | +static void gen_mla32_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
194 | +{ | ||
195 | + tcg_gen_mul_i32(a, a, b); | ||
196 | + tcg_gen_add_i32(d, d, a); | ||
197 | +} | ||
198 | + | ||
199 | +static void gen_mls32_i32(TCGv_i32 d, TCGv_i32 a, TCGv_i32 b) | ||
200 | +{ | ||
201 | + tcg_gen_mul_i32(a, a, b); | ||
202 | + tcg_gen_sub_i32(d, d, a); | ||
203 | +} | ||
204 | + | ||
205 | +static void gen_mla64_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
206 | +{ | ||
207 | + tcg_gen_mul_i64(a, a, b); | ||
208 | + tcg_gen_add_i64(d, d, a); | ||
209 | +} | ||
210 | + | ||
211 | +static void gen_mls64_i64(TCGv_i64 d, TCGv_i64 a, TCGv_i64 b) | ||
212 | +{ | ||
213 | + tcg_gen_mul_i64(a, a, b); | ||
214 | + tcg_gen_sub_i64(d, d, a); | ||
215 | +} | ||
216 | + | ||
217 | +static void gen_mla_vec(unsigned vece, TCGv_vec d, TCGv_vec a, TCGv_vec b) | ||
218 | +{ | ||
219 | + tcg_gen_mul_vec(vece, a, a, b); | ||
220 | + tcg_gen_add_vec(vece, d, d, a); | ||
221 | +} | ||
222 | + | ||
223 | +static void gen_mls_vec(unsigned vece, TCGv_vec d, TCGv_vec a, TCGv_vec b) | ||
224 | +{ | ||
225 | + tcg_gen_mul_vec(vece, a, a, b); | ||
226 | + tcg_gen_sub_vec(vece, d, d, a); | ||
227 | +} | ||
228 | + | ||
229 | +/* Note that while NEON does not support VMLA and VMLS as 64-bit ops, | ||
230 | + * these tables are shared with AArch64 which does support them. | ||
231 | + */ | ||
232 | +const GVecGen3 mla_op[4] = { | ||
233 | + { .fni4 = gen_mla8_i32, | ||
234 | + .fniv = gen_mla_vec, | ||
235 | + .opc = INDEX_op_mul_vec, | ||
236 | + .load_dest = true, | ||
237 | + .vece = MO_8 }, | ||
238 | + { .fni4 = gen_mla16_i32, | ||
239 | + .fniv = gen_mla_vec, | ||
240 | + .opc = INDEX_op_mul_vec, | ||
241 | + .load_dest = true, | ||
242 | + .vece = MO_16 }, | ||
243 | + { .fni4 = gen_mla32_i32, | ||
244 | + .fniv = gen_mla_vec, | ||
245 | + .opc = INDEX_op_mul_vec, | ||
246 | + .load_dest = true, | ||
247 | + .vece = MO_32 }, | ||
248 | + { .fni8 = gen_mla64_i64, | ||
249 | + .fniv = gen_mla_vec, | ||
250 | + .opc = INDEX_op_mul_vec, | ||
251 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
252 | + .load_dest = true, | ||
253 | + .vece = MO_64 }, | ||
254 | +}; | 49 | +}; |
255 | + | 50 | + |
256 | +const GVecGen3 mls_op[4] = { | 51 | static void raspi1ap_machine_class_init(ObjectClass *oc, void *data) |
257 | + { .fni4 = gen_mls8_i32, | 52 | { |
258 | + .fniv = gen_mls_vec, | 53 | MachineClass *mc = MACHINE_CLASS(oc); |
259 | + .opc = INDEX_op_mul_vec, | 54 | @@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data) |
260 | + .load_dest = true, | 55 | |
261 | + .vece = MO_8 }, | 56 | static const TypeInfo raspi_machine_types[] = { |
262 | + { .fni4 = gen_mls16_i32, | 57 | { |
263 | + .fniv = gen_mls_vec, | 58 | + .name = MACHINE_TYPE_NAME("raspi0"), |
264 | + .opc = INDEX_op_mul_vec, | 59 | + .parent = TYPE_RASPI_MACHINE, |
265 | + .load_dest = true, | 60 | + .class_init = raspi0_machine_class_init, |
266 | + .vece = MO_16 }, | 61 | + }, { |
267 | + { .fni4 = gen_mls32_i32, | 62 | .name = MACHINE_TYPE_NAME("raspi1ap"), |
268 | + .fniv = gen_mls_vec, | 63 | .parent = TYPE_RASPI_MACHINE, |
269 | + .opc = INDEX_op_mul_vec, | 64 | .class_init = raspi1ap_machine_class_init, |
270 | + .load_dest = true, | ||
271 | + .vece = MO_32 }, | ||
272 | + { .fni8 = gen_mls64_i64, | ||
273 | + .fniv = gen_mls_vec, | ||
274 | + .opc = INDEX_op_mul_vec, | ||
275 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
276 | + .load_dest = true, | ||
277 | + .vece = MO_64 }, | ||
278 | +}; | ||
279 | + | ||
280 | /* Translate a NEON data processing instruction. Return nonzero if the | ||
281 | instruction is invalid. | ||
282 | We process data in a mixture of 32-bit and 64-bit chunks. | ||
283 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
284 | return 0; | ||
285 | } | ||
286 | break; | ||
287 | + | ||
288 | + case NEON_3R_VML: /* VMLA, VMLS */ | ||
289 | + tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, vec_size, vec_size, | ||
290 | + u ? &mls_op[size] : &mla_op[size]); | ||
291 | + return 0; | ||
292 | } | ||
293 | + | ||
294 | if (size == 3) { | ||
295 | /* 64-bit element instructions. */ | ||
296 | for (pass = 0; pass < (q ? 2 : 1); pass++) { | ||
297 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
298 | } | ||
299 | } | ||
300 | break; | ||
301 | - case NEON_3R_VML: /* VMLA, VMLAL, VMLS,VMLSL */ | ||
302 | - switch (size) { | ||
303 | - case 0: gen_helper_neon_mul_u8(tmp, tmp, tmp2); break; | ||
304 | - case 1: gen_helper_neon_mul_u16(tmp, tmp, tmp2); break; | ||
305 | - case 2: tcg_gen_mul_i32(tmp, tmp, tmp2); break; | ||
306 | - default: abort(); | ||
307 | - } | ||
308 | - tcg_temp_free_i32(tmp2); | ||
309 | - tmp2 = neon_load_reg(rd, pass); | ||
310 | - if (u) { /* VMLS */ | ||
311 | - gen_neon_rsb(size, tmp, tmp2); | ||
312 | - } else { /* VMLA */ | ||
313 | - gen_neon_add(size, tmp, tmp2); | ||
314 | - } | ||
315 | - break; | ||
316 | case NEON_3R_VMUL: | ||
317 | /* VMUL.P8; other cases already eliminated. */ | ||
318 | gen_helper_neon_mul_p8(tmp, tmp, tmp2); | ||
319 | -- | 65 | -- |
320 | 2.19.1 | 66 | 2.20.1 |
321 | 67 | ||
322 | 68 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Move shi_op and sli_op expanders from translate-a64.c. | 3 | The Pi 3A+ is a stripped down version of the 3B: |
4 | - 512 MiB of RAM instead of 1 GiB | ||
5 | - no on-board ethernet chipset | ||
4 | 6 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Add it as it is a closer match to what we model. |
6 | Message-id: 20181011205206.3552-15-richard.henderson@linaro.org | 8 | |
7 | 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 | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 13 | --- |
10 | target/arm/translate.h | 2 + | 14 | hw/arm/raspi.c | 13 +++++++++++++ |
11 | target/arm/translate-a64.c | 152 +---------------------- | 15 | 1 file changed, 13 insertions(+) |
12 | target/arm/translate.c | 244 ++++++++++++++++++++++++++----------- | ||
13 | 3 files changed, 179 insertions(+), 219 deletions(-) | ||
14 | 16 | ||
15 | diff --git a/target/arm/translate.h b/target/arm/translate.h | 17 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
16 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate.h | 19 | --- a/hw/arm/raspi.c |
18 | +++ b/target/arm/translate.h | 20 | +++ b/hw/arm/raspi.c |
19 | @@ -XXX,XX +XXX,XX @@ extern const GVecGen3 bit_op; | 21 | @@ -XXX,XX +XXX,XX @@ static void raspi2b_machine_class_init(ObjectClass *oc, void *data) |
20 | extern const GVecGen3 bif_op; | ||
21 | extern const GVecGen2i ssra_op[4]; | ||
22 | extern const GVecGen2i usra_op[4]; | ||
23 | +extern const GVecGen2i sri_op[4]; | ||
24 | +extern const GVecGen2i sli_op[4]; | ||
25 | |||
26 | /* | ||
27 | * Forward to the isar_feature_* tests given a DisasContext pointer. | ||
28 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | ||
30 | --- a/target/arm/translate-a64.c | ||
31 | +++ b/target/arm/translate-a64.c | ||
32 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_two_reg_misc(DisasContext *s, uint32_t insn) | ||
33 | } | ||
34 | } | ||
35 | |||
36 | -static void gen_shr8_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
37 | -{ | ||
38 | - uint64_t mask = dup_const(MO_8, 0xff >> shift); | ||
39 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
40 | - | ||
41 | - tcg_gen_shri_i64(t, a, shift); | ||
42 | - tcg_gen_andi_i64(t, t, mask); | ||
43 | - tcg_gen_andi_i64(d, d, ~mask); | ||
44 | - tcg_gen_or_i64(d, d, t); | ||
45 | - tcg_temp_free_i64(t); | ||
46 | -} | ||
47 | - | ||
48 | -static void gen_shr16_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
49 | -{ | ||
50 | - uint64_t mask = dup_const(MO_16, 0xffff >> shift); | ||
51 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
52 | - | ||
53 | - tcg_gen_shri_i64(t, a, shift); | ||
54 | - tcg_gen_andi_i64(t, t, mask); | ||
55 | - tcg_gen_andi_i64(d, d, ~mask); | ||
56 | - tcg_gen_or_i64(d, d, t); | ||
57 | - tcg_temp_free_i64(t); | ||
58 | -} | ||
59 | - | ||
60 | -static void gen_shr32_ins_i32(TCGv_i32 d, TCGv_i32 a, int32_t shift) | ||
61 | -{ | ||
62 | - tcg_gen_shri_i32(a, a, shift); | ||
63 | - tcg_gen_deposit_i32(d, d, a, 0, 32 - shift); | ||
64 | -} | ||
65 | - | ||
66 | -static void gen_shr64_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
67 | -{ | ||
68 | - tcg_gen_shri_i64(a, a, shift); | ||
69 | - tcg_gen_deposit_i64(d, d, a, 0, 64 - shift); | ||
70 | -} | ||
71 | - | ||
72 | -static void gen_shr_ins_vec(unsigned vece, TCGv_vec d, TCGv_vec a, int64_t sh) | ||
73 | -{ | ||
74 | - uint64_t mask = (2ull << ((8 << vece) - 1)) - 1; | ||
75 | - TCGv_vec t = tcg_temp_new_vec_matching(d); | ||
76 | - TCGv_vec m = tcg_temp_new_vec_matching(d); | ||
77 | - | ||
78 | - tcg_gen_dupi_vec(vece, m, mask ^ (mask >> sh)); | ||
79 | - tcg_gen_shri_vec(vece, t, a, sh); | ||
80 | - tcg_gen_and_vec(vece, d, d, m); | ||
81 | - tcg_gen_or_vec(vece, d, d, t); | ||
82 | - | ||
83 | - tcg_temp_free_vec(t); | ||
84 | - tcg_temp_free_vec(m); | ||
85 | -} | ||
86 | - | ||
87 | /* SSHR[RA]/USHR[RA] - Vector shift right (optional rounding/accumulate) */ | ||
88 | static void handle_vec_simd_shri(DisasContext *s, bool is_q, bool is_u, | ||
89 | int immh, int immb, int opcode, int rn, int rd) | ||
90 | { | ||
91 | - static const GVecGen2i sri_op[4] = { | ||
92 | - { .fni8 = gen_shr8_ins_i64, | ||
93 | - .fniv = gen_shr_ins_vec, | ||
94 | - .load_dest = true, | ||
95 | - .opc = INDEX_op_shri_vec, | ||
96 | - .vece = MO_8 }, | ||
97 | - { .fni8 = gen_shr16_ins_i64, | ||
98 | - .fniv = gen_shr_ins_vec, | ||
99 | - .load_dest = true, | ||
100 | - .opc = INDEX_op_shri_vec, | ||
101 | - .vece = MO_16 }, | ||
102 | - { .fni4 = gen_shr32_ins_i32, | ||
103 | - .fniv = gen_shr_ins_vec, | ||
104 | - .load_dest = true, | ||
105 | - .opc = INDEX_op_shri_vec, | ||
106 | - .vece = MO_32 }, | ||
107 | - { .fni8 = gen_shr64_ins_i64, | ||
108 | - .fniv = gen_shr_ins_vec, | ||
109 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
110 | - .load_dest = true, | ||
111 | - .opc = INDEX_op_shri_vec, | ||
112 | - .vece = MO_64 }, | ||
113 | - }; | ||
114 | - | ||
115 | int size = 32 - clz32(immh) - 1; | ||
116 | int immhb = immh << 3 | immb; | ||
117 | int shift = 2 * (8 << size) - immhb; | ||
118 | @@ -XXX,XX +XXX,XX @@ static void handle_vec_simd_shri(DisasContext *s, bool is_q, bool is_u, | ||
119 | clear_vec_high(s, is_q, rd); | ||
120 | } | ||
121 | |||
122 | -static void gen_shl8_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
123 | -{ | ||
124 | - uint64_t mask = dup_const(MO_8, 0xff << shift); | ||
125 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
126 | - | ||
127 | - tcg_gen_shli_i64(t, a, shift); | ||
128 | - tcg_gen_andi_i64(t, t, mask); | ||
129 | - tcg_gen_andi_i64(d, d, ~mask); | ||
130 | - tcg_gen_or_i64(d, d, t); | ||
131 | - tcg_temp_free_i64(t); | ||
132 | -} | ||
133 | - | ||
134 | -static void gen_shl16_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
135 | -{ | ||
136 | - uint64_t mask = dup_const(MO_16, 0xffff << shift); | ||
137 | - TCGv_i64 t = tcg_temp_new_i64(); | ||
138 | - | ||
139 | - tcg_gen_shli_i64(t, a, shift); | ||
140 | - tcg_gen_andi_i64(t, t, mask); | ||
141 | - tcg_gen_andi_i64(d, d, ~mask); | ||
142 | - tcg_gen_or_i64(d, d, t); | ||
143 | - tcg_temp_free_i64(t); | ||
144 | -} | ||
145 | - | ||
146 | -static void gen_shl32_ins_i32(TCGv_i32 d, TCGv_i32 a, int32_t shift) | ||
147 | -{ | ||
148 | - tcg_gen_deposit_i32(d, d, a, shift, 32 - shift); | ||
149 | -} | ||
150 | - | ||
151 | -static void gen_shl64_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
152 | -{ | ||
153 | - tcg_gen_deposit_i64(d, d, a, shift, 64 - shift); | ||
154 | -} | ||
155 | - | ||
156 | -static void gen_shl_ins_vec(unsigned vece, TCGv_vec d, TCGv_vec a, int64_t sh) | ||
157 | -{ | ||
158 | - uint64_t mask = (1ull << sh) - 1; | ||
159 | - TCGv_vec t = tcg_temp_new_vec_matching(d); | ||
160 | - TCGv_vec m = tcg_temp_new_vec_matching(d); | ||
161 | - | ||
162 | - tcg_gen_dupi_vec(vece, m, mask); | ||
163 | - tcg_gen_shli_vec(vece, t, a, sh); | ||
164 | - tcg_gen_and_vec(vece, d, d, m); | ||
165 | - tcg_gen_or_vec(vece, d, d, t); | ||
166 | - | ||
167 | - tcg_temp_free_vec(t); | ||
168 | - tcg_temp_free_vec(m); | ||
169 | -} | ||
170 | - | ||
171 | /* SHL/SLI - Vector shift left */ | ||
172 | static void handle_vec_simd_shli(DisasContext *s, bool is_q, bool insert, | ||
173 | int immh, int immb, int opcode, int rn, int rd) | ||
174 | { | ||
175 | - static const GVecGen2i shi_op[4] = { | ||
176 | - { .fni8 = gen_shl8_ins_i64, | ||
177 | - .fniv = gen_shl_ins_vec, | ||
178 | - .opc = INDEX_op_shli_vec, | ||
179 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
180 | - .load_dest = true, | ||
181 | - .vece = MO_8 }, | ||
182 | - { .fni8 = gen_shl16_ins_i64, | ||
183 | - .fniv = gen_shl_ins_vec, | ||
184 | - .opc = INDEX_op_shli_vec, | ||
185 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
186 | - .load_dest = true, | ||
187 | - .vece = MO_16 }, | ||
188 | - { .fni4 = gen_shl32_ins_i32, | ||
189 | - .fniv = gen_shl_ins_vec, | ||
190 | - .opc = INDEX_op_shli_vec, | ||
191 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
192 | - .load_dest = true, | ||
193 | - .vece = MO_32 }, | ||
194 | - { .fni8 = gen_shl64_ins_i64, | ||
195 | - .fniv = gen_shl_ins_vec, | ||
196 | - .opc = INDEX_op_shli_vec, | ||
197 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
198 | - .load_dest = true, | ||
199 | - .vece = MO_64 }, | ||
200 | - }; | ||
201 | int size = 32 - clz32(immh) - 1; | ||
202 | int immhb = immh << 3 | immb; | ||
203 | int shift = immhb - (8 << size); | ||
204 | @@ -XXX,XX +XXX,XX @@ static void handle_vec_simd_shli(DisasContext *s, bool is_q, bool insert, | ||
205 | } | ||
206 | |||
207 | if (insert) { | ||
208 | - gen_gvec_op2i(s, is_q, rd, rn, shift, &shi_op[size]); | ||
209 | + gen_gvec_op2i(s, is_q, rd, rn, shift, &sli_op[size]); | ||
210 | } else { | ||
211 | gen_gvec_fn2i(s, is_q, rd, rn, shift, tcg_gen_gvec_shli, size); | ||
212 | } | ||
213 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
214 | index XXXXXXX..XXXXXXX 100644 | ||
215 | --- a/target/arm/translate.c | ||
216 | +++ b/target/arm/translate.c | ||
217 | @@ -XXX,XX +XXX,XX @@ const GVecGen2i usra_op[4] = { | ||
218 | .vece = MO_64, }, | ||
219 | }; | 22 | }; |
220 | 23 | ||
221 | +static void gen_shr8_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | 24 | #ifdef TARGET_AARCH64 |
25 | +static void raspi3ap_machine_class_init(ObjectClass *oc, void *data) | ||
222 | +{ | 26 | +{ |
223 | + uint64_t mask = dup_const(MO_8, 0xff >> shift); | 27 | + MachineClass *mc = MACHINE_CLASS(oc); |
224 | + TCGv_i64 t = tcg_temp_new_i64(); | 28 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); |
225 | + | 29 | + |
226 | + tcg_gen_shri_i64(t, a, shift); | 30 | + rmc->board_rev = 0x9020e0; /* Revision 1.0 */ |
227 | + tcg_gen_andi_i64(t, t, mask); | 31 | + raspi_machine_class_common_init(mc, rmc->board_rev); |
228 | + tcg_gen_andi_i64(d, d, ~mask); | ||
229 | + tcg_gen_or_i64(d, d, t); | ||
230 | + tcg_temp_free_i64(t); | ||
231 | +} | ||
232 | + | ||
233 | +static void gen_shr16_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
234 | +{ | ||
235 | + uint64_t mask = dup_const(MO_16, 0xffff >> shift); | ||
236 | + TCGv_i64 t = tcg_temp_new_i64(); | ||
237 | + | ||
238 | + tcg_gen_shri_i64(t, a, shift); | ||
239 | + tcg_gen_andi_i64(t, t, mask); | ||
240 | + tcg_gen_andi_i64(d, d, ~mask); | ||
241 | + tcg_gen_or_i64(d, d, t); | ||
242 | + tcg_temp_free_i64(t); | ||
243 | +} | ||
244 | + | ||
245 | +static void gen_shr32_ins_i32(TCGv_i32 d, TCGv_i32 a, int32_t shift) | ||
246 | +{ | ||
247 | + tcg_gen_shri_i32(a, a, shift); | ||
248 | + tcg_gen_deposit_i32(d, d, a, 0, 32 - shift); | ||
249 | +} | ||
250 | + | ||
251 | +static void gen_shr64_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
252 | +{ | ||
253 | + tcg_gen_shri_i64(a, a, shift); | ||
254 | + tcg_gen_deposit_i64(d, d, a, 0, 64 - shift); | ||
255 | +} | ||
256 | + | ||
257 | +static void gen_shr_ins_vec(unsigned vece, TCGv_vec d, TCGv_vec a, int64_t sh) | ||
258 | +{ | ||
259 | + if (sh == 0) { | ||
260 | + tcg_gen_mov_vec(d, a); | ||
261 | + } else { | ||
262 | + TCGv_vec t = tcg_temp_new_vec_matching(d); | ||
263 | + TCGv_vec m = tcg_temp_new_vec_matching(d); | ||
264 | + | ||
265 | + tcg_gen_dupi_vec(vece, m, MAKE_64BIT_MASK((8 << vece) - sh, sh)); | ||
266 | + tcg_gen_shri_vec(vece, t, a, sh); | ||
267 | + tcg_gen_and_vec(vece, d, d, m); | ||
268 | + tcg_gen_or_vec(vece, d, d, t); | ||
269 | + | ||
270 | + tcg_temp_free_vec(t); | ||
271 | + tcg_temp_free_vec(m); | ||
272 | + } | ||
273 | +} | ||
274 | + | ||
275 | +const GVecGen2i sri_op[4] = { | ||
276 | + { .fni8 = gen_shr8_ins_i64, | ||
277 | + .fniv = gen_shr_ins_vec, | ||
278 | + .load_dest = true, | ||
279 | + .opc = INDEX_op_shri_vec, | ||
280 | + .vece = MO_8 }, | ||
281 | + { .fni8 = gen_shr16_ins_i64, | ||
282 | + .fniv = gen_shr_ins_vec, | ||
283 | + .load_dest = true, | ||
284 | + .opc = INDEX_op_shri_vec, | ||
285 | + .vece = MO_16 }, | ||
286 | + { .fni4 = gen_shr32_ins_i32, | ||
287 | + .fniv = gen_shr_ins_vec, | ||
288 | + .load_dest = true, | ||
289 | + .opc = INDEX_op_shri_vec, | ||
290 | + .vece = MO_32 }, | ||
291 | + { .fni8 = gen_shr64_ins_i64, | ||
292 | + .fniv = gen_shr_ins_vec, | ||
293 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
294 | + .load_dest = true, | ||
295 | + .opc = INDEX_op_shri_vec, | ||
296 | + .vece = MO_64 }, | ||
297 | +}; | 32 | +}; |
298 | + | 33 | + |
299 | +static void gen_shl8_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | 34 | static void raspi3b_machine_class_init(ObjectClass *oc, void *data) |
300 | +{ | 35 | { |
301 | + uint64_t mask = dup_const(MO_8, 0xff << shift); | 36 | MachineClass *mc = MACHINE_CLASS(oc); |
302 | + TCGv_i64 t = tcg_temp_new_i64(); | 37 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo raspi_machine_types[] = { |
303 | + | 38 | .parent = TYPE_RASPI_MACHINE, |
304 | + tcg_gen_shli_i64(t, a, shift); | 39 | .class_init = raspi2b_machine_class_init, |
305 | + tcg_gen_andi_i64(t, t, mask); | 40 | #ifdef TARGET_AARCH64 |
306 | + tcg_gen_andi_i64(d, d, ~mask); | 41 | + }, { |
307 | + tcg_gen_or_i64(d, d, t); | 42 | + .name = MACHINE_TYPE_NAME("raspi3ap"), |
308 | + tcg_temp_free_i64(t); | 43 | + .parent = TYPE_RASPI_MACHINE, |
309 | +} | 44 | + .class_init = raspi3ap_machine_class_init, |
310 | + | 45 | }, { |
311 | +static void gen_shl16_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | 46 | .name = MACHINE_TYPE_NAME("raspi3b"), |
312 | +{ | 47 | .parent = TYPE_RASPI_MACHINE, |
313 | + uint64_t mask = dup_const(MO_16, 0xffff << shift); | ||
314 | + TCGv_i64 t = tcg_temp_new_i64(); | ||
315 | + | ||
316 | + tcg_gen_shli_i64(t, a, shift); | ||
317 | + tcg_gen_andi_i64(t, t, mask); | ||
318 | + tcg_gen_andi_i64(d, d, ~mask); | ||
319 | + tcg_gen_or_i64(d, d, t); | ||
320 | + tcg_temp_free_i64(t); | ||
321 | +} | ||
322 | + | ||
323 | +static void gen_shl32_ins_i32(TCGv_i32 d, TCGv_i32 a, int32_t shift) | ||
324 | +{ | ||
325 | + tcg_gen_deposit_i32(d, d, a, shift, 32 - shift); | ||
326 | +} | ||
327 | + | ||
328 | +static void gen_shl64_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
329 | +{ | ||
330 | + tcg_gen_deposit_i64(d, d, a, shift, 64 - shift); | ||
331 | +} | ||
332 | + | ||
333 | +static void gen_shl_ins_vec(unsigned vece, TCGv_vec d, TCGv_vec a, int64_t sh) | ||
334 | +{ | ||
335 | + if (sh == 0) { | ||
336 | + tcg_gen_mov_vec(d, a); | ||
337 | + } else { | ||
338 | + TCGv_vec t = tcg_temp_new_vec_matching(d); | ||
339 | + TCGv_vec m = tcg_temp_new_vec_matching(d); | ||
340 | + | ||
341 | + tcg_gen_dupi_vec(vece, m, MAKE_64BIT_MASK(0, sh)); | ||
342 | + tcg_gen_shli_vec(vece, t, a, sh); | ||
343 | + tcg_gen_and_vec(vece, d, d, m); | ||
344 | + tcg_gen_or_vec(vece, d, d, t); | ||
345 | + | ||
346 | + tcg_temp_free_vec(t); | ||
347 | + tcg_temp_free_vec(m); | ||
348 | + } | ||
349 | +} | ||
350 | + | ||
351 | +const GVecGen2i sli_op[4] = { | ||
352 | + { .fni8 = gen_shl8_ins_i64, | ||
353 | + .fniv = gen_shl_ins_vec, | ||
354 | + .load_dest = true, | ||
355 | + .opc = INDEX_op_shli_vec, | ||
356 | + .vece = MO_8 }, | ||
357 | + { .fni8 = gen_shl16_ins_i64, | ||
358 | + .fniv = gen_shl_ins_vec, | ||
359 | + .load_dest = true, | ||
360 | + .opc = INDEX_op_shli_vec, | ||
361 | + .vece = MO_16 }, | ||
362 | + { .fni4 = gen_shl32_ins_i32, | ||
363 | + .fniv = gen_shl_ins_vec, | ||
364 | + .load_dest = true, | ||
365 | + .opc = INDEX_op_shli_vec, | ||
366 | + .vece = MO_32 }, | ||
367 | + { .fni8 = gen_shl64_ins_i64, | ||
368 | + .fniv = gen_shl_ins_vec, | ||
369 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
370 | + .load_dest = true, | ||
371 | + .opc = INDEX_op_shli_vec, | ||
372 | + .vece = MO_64 }, | ||
373 | +}; | ||
374 | + | ||
375 | /* Translate a NEON data processing instruction. Return nonzero if the | ||
376 | instruction is invalid. | ||
377 | We process data in a mixture of 32-bit and 64-bit chunks. | ||
378 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
379 | int pairwise; | ||
380 | int u; | ||
381 | int vec_size; | ||
382 | - uint32_t imm, mask; | ||
383 | + uint32_t imm; | ||
384 | TCGv_i32 tmp, tmp2, tmp3, tmp4, tmp5; | ||
385 | TCGv_ptr ptr1, ptr2, ptr3; | ||
386 | TCGv_i64 tmp64; | ||
387 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
388 | } | ||
389 | return 0; | ||
390 | |||
391 | + case 4: /* VSRI */ | ||
392 | + if (!u) { | ||
393 | + return 1; | ||
394 | + } | ||
395 | + /* Right shift comes here negative. */ | ||
396 | + shift = -shift; | ||
397 | + /* Shift out of range leaves destination unchanged. */ | ||
398 | + if (shift < 8 << size) { | ||
399 | + tcg_gen_gvec_2i(rd_ofs, rm_ofs, vec_size, vec_size, | ||
400 | + shift, &sri_op[size]); | ||
401 | + } | ||
402 | + return 0; | ||
403 | + | ||
404 | case 5: /* VSHL, VSLI */ | ||
405 | - if (!u) { /* VSHL */ | ||
406 | + if (u) { /* VSLI */ | ||
407 | + /* Shift out of range leaves destination unchanged. */ | ||
408 | + if (shift < 8 << size) { | ||
409 | + tcg_gen_gvec_2i(rd_ofs, rm_ofs, vec_size, | ||
410 | + vec_size, shift, &sli_op[size]); | ||
411 | + } | ||
412 | + } else { /* VSHL */ | ||
413 | /* Shifts larger than the element size are | ||
414 | * architecturally valid and results in zero. | ||
415 | */ | ||
416 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
417 | tcg_gen_gvec_shli(size, rd_ofs, rm_ofs, shift, | ||
418 | vec_size, vec_size); | ||
419 | } | ||
420 | - return 0; | ||
421 | } | ||
422 | - break; | ||
423 | + return 0; | ||
424 | } | ||
425 | |||
426 | if (size == 3) { | ||
427 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
428 | else | ||
429 | gen_helper_neon_rshl_s64(cpu_V0, cpu_V0, cpu_V1); | ||
430 | break; | ||
431 | - case 4: /* VSRI */ | ||
432 | - case 5: /* VSHL, VSLI */ | ||
433 | - gen_helper_neon_shl_u64(cpu_V0, cpu_V0, cpu_V1); | ||
434 | - break; | ||
435 | case 6: /* VQSHLU */ | ||
436 | gen_helper_neon_qshlu_s64(cpu_V0, cpu_env, | ||
437 | cpu_V0, cpu_V1); | ||
438 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
439 | /* Accumulate. */ | ||
440 | neon_load_reg64(cpu_V1, rd + pass); | ||
441 | tcg_gen_add_i64(cpu_V0, cpu_V0, cpu_V1); | ||
442 | - } else if (op == 4 || (op == 5 && u)) { | ||
443 | - /* Insert */ | ||
444 | - neon_load_reg64(cpu_V1, rd + pass); | ||
445 | - uint64_t mask; | ||
446 | - if (shift < -63 || shift > 63) { | ||
447 | - mask = 0; | ||
448 | - } else { | ||
449 | - if (op == 4) { | ||
450 | - mask = 0xffffffffffffffffull >> -shift; | ||
451 | - } else { | ||
452 | - mask = 0xffffffffffffffffull << shift; | ||
453 | - } | ||
454 | - } | ||
455 | - tcg_gen_andi_i64(cpu_V1, cpu_V1, ~mask); | ||
456 | - tcg_gen_or_i64(cpu_V0, cpu_V0, cpu_V1); | ||
457 | } | ||
458 | neon_store_reg64(cpu_V0, rd + pass); | ||
459 | } else { /* size < 3 */ | ||
460 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
461 | case 3: /* VRSRA */ | ||
462 | GEN_NEON_INTEGER_OP(rshl); | ||
463 | break; | ||
464 | - case 4: /* VSRI */ | ||
465 | - case 5: /* VSHL, VSLI */ | ||
466 | - switch (size) { | ||
467 | - case 0: gen_helper_neon_shl_u8(tmp, tmp, tmp2); break; | ||
468 | - case 1: gen_helper_neon_shl_u16(tmp, tmp, tmp2); break; | ||
469 | - case 2: gen_helper_neon_shl_u32(tmp, tmp, tmp2); break; | ||
470 | - default: abort(); | ||
471 | - } | ||
472 | - break; | ||
473 | case 6: /* VQSHLU */ | ||
474 | switch (size) { | ||
475 | case 0: | ||
476 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
477 | tmp2 = neon_load_reg(rd, pass); | ||
478 | gen_neon_add(size, tmp, tmp2); | ||
479 | tcg_temp_free_i32(tmp2); | ||
480 | - } else if (op == 4 || (op == 5 && u)) { | ||
481 | - /* Insert */ | ||
482 | - switch (size) { | ||
483 | - case 0: | ||
484 | - if (op == 4) | ||
485 | - mask = 0xff >> -shift; | ||
486 | - else | ||
487 | - mask = (uint8_t)(0xff << shift); | ||
488 | - mask |= mask << 8; | ||
489 | - mask |= mask << 16; | ||
490 | - break; | ||
491 | - case 1: | ||
492 | - if (op == 4) | ||
493 | - mask = 0xffff >> -shift; | ||
494 | - else | ||
495 | - mask = (uint16_t)(0xffff << shift); | ||
496 | - mask |= mask << 16; | ||
497 | - break; | ||
498 | - case 2: | ||
499 | - if (shift < -31 || shift > 31) { | ||
500 | - mask = 0; | ||
501 | - } else { | ||
502 | - if (op == 4) | ||
503 | - mask = 0xffffffffu >> -shift; | ||
504 | - else | ||
505 | - mask = 0xffffffffu << shift; | ||
506 | - } | ||
507 | - break; | ||
508 | - default: | ||
509 | - abort(); | ||
510 | - } | ||
511 | - tmp2 = neon_load_reg(rd, pass); | ||
512 | - tcg_gen_andi_i32(tmp, tmp, mask); | ||
513 | - tcg_gen_andi_i32(tmp2, tmp2, ~mask); | ||
514 | - tcg_gen_or_i32(tmp, tmp, tmp2); | ||
515 | - tcg_temp_free_i32(tmp2); | ||
516 | } | ||
517 | neon_store_reg(rd, pass, tmp); | ||
518 | } | ||
519 | -- | 48 | -- |
520 | 2.19.1 | 49 | 2.20.1 |
521 | 50 | ||
522 | 51 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: "Dr. David Alan Gilbert" <dgilbert@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | The EL3 version of this register does not include an ASID, | 3 | Use of 0x%d - make up our mind as 0x%x |
4 | and so the tlb_flush performed by vmsa_ttbr_write is not needed. | ||
5 | 4 | ||
6 | Reviewed-by: Aaron Lindsay <aaron@os.amperecomputing.com> | 5 | Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Acked-by: Eric Auger <eric.auger@redhat.com> |
9 | Message-id: 20181019015617.22583-2-richard.henderson@linaro.org | 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 | --- | 10 | --- |
12 | target/arm/helper.c | 2 +- | 11 | hw/arm/trace-events | 2 +- |
13 | 1 file changed, 1 insertion(+), 1 deletion(-) | 12 | 1 file changed, 1 insertion(+), 1 deletion(-) |
14 | 13 | ||
15 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 14 | diff --git a/hw/arm/trace-events b/hw/arm/trace-events |
16 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/helper.c | 16 | --- a/hw/arm/trace-events |
18 | +++ b/target/arm/helper.c | 17 | +++ b/hw/arm/trace-events |
19 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el3_cp_reginfo[] = { | 18 | @@ -XXX,XX +XXX,XX @@ smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64 |
20 | .fieldoffset = offsetof(CPUARMState, cp15.mvbar) }, | 19 | smmuv3_decode_cd(uint32_t oas) "oas=%d" |
21 | { .name = "TTBR0_EL3", .state = ARM_CP_STATE_AA64, | 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" |
22 | .opc0 = 3, .opc1 = 6, .crn = 2, .crm = 0, .opc2 = 0, | 21 | smmuv3_cmdq_cfgi_ste(int streamid) "streamid =%d" |
23 | - .access = PL3_RW, .writefn = vmsa_ttbr_write, .resetvalue = 0, | 22 | -smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%d - end=0x%d" |
24 | + .access = PL3_RW, .resetvalue = 0, | 23 | +smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x" |
25 | .fieldoffset = offsetof(CPUARMState, cp15.ttbr0_el[3]) }, | 24 | smmuv3_cmdq_cfgi_cd(uint32_t sid) "streamid = %d" |
26 | { .name = "TCR_EL3", .state = ARM_CP_STATE_AA64, | 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)" |
27 | .opc0 = 3, .opc1 = 6, .crn = 2, .crm = 0, .opc2 = 2, | 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)" |
28 | -- | 27 | -- |
29 | 2.19.1 | 28 | 2.20.1 |
30 | 29 | ||
31 | 30 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
4 | Message-id: 20181011205206.3552-4-richard.henderson@linaro.org | 4 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 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> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 9 | --- |
8 | target/arm/translate-a64.c | 28 +++------------------------- | 10 | include/hw/clock.h | 5 +++++ |
9 | 1 file changed, 3 insertions(+), 25 deletions(-) | 11 | 1 file changed, 5 insertions(+) |
10 | 12 | ||
11 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 13 | diff --git a/include/hw/clock.h b/include/hw/clock.h |
12 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate-a64.c | 15 | --- a/include/hw/clock.h |
14 | +++ b/target/arm/translate-a64.c | 16 | +++ b/include/hw/clock.h |
15 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn) | 17 | @@ -XXX,XX +XXX,XX @@ extern const VMStateDescription vmstate_clock; |
16 | for (xs = 0; xs < selem; xs++) { | 18 | VMSTATE_CLOCK_V(field, state, 0) |
17 | if (replicate) { | 19 | #define VMSTATE_CLOCK_V(field, state, version) \ |
18 | /* Load and replicate to all elements */ | 20 | VMSTATE_STRUCT_POINTER_V(field, state, version, vmstate_clock, Clock) |
19 | - uint64_t mulconst; | 21 | +#define VMSTATE_ARRAY_CLOCK(field, state, num) \ |
20 | TCGv_i64 tcg_tmp = tcg_temp_new_i64(); | 22 | + VMSTATE_ARRAY_CLOCK_V(field, state, num, 0) |
21 | 23 | +#define VMSTATE_ARRAY_CLOCK_V(field, state, num, version) \ | |
22 | tcg_gen_qemu_ld_i64(tcg_tmp, tcg_addr, | 24 | + VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(field, state, num, version, \ |
23 | get_mem_index(s), s->be_data + scale); | 25 | + vmstate_clock, Clock) |
24 | - switch (scale) { | 26 | |
25 | - case 0: | 27 | /** |
26 | - mulconst = 0x0101010101010101ULL; | 28 | * clock_setup_canonical_path: |
27 | - break; | ||
28 | - case 1: | ||
29 | - mulconst = 0x0001000100010001ULL; | ||
30 | - break; | ||
31 | - case 2: | ||
32 | - mulconst = 0x0000000100000001ULL; | ||
33 | - break; | ||
34 | - case 3: | ||
35 | - mulconst = 0; | ||
36 | - break; | ||
37 | - default: | ||
38 | - g_assert_not_reached(); | ||
39 | - } | ||
40 | - if (mulconst) { | ||
41 | - tcg_gen_muli_i64(tcg_tmp, tcg_tmp, mulconst); | ||
42 | - } | ||
43 | - write_vec_element(s, tcg_tmp, rt, 0, MO_64); | ||
44 | - if (is_q) { | ||
45 | - write_vec_element(s, tcg_tmp, rt, 1, MO_64); | ||
46 | - } | ||
47 | + tcg_gen_gvec_dup_i64(scale, vec_full_reg_offset(s, rt), | ||
48 | + (is_q + 1) * 8, vec_full_reg_size(s), | ||
49 | + tcg_tmp); | ||
50 | tcg_temp_free_i64(tcg_tmp); | ||
51 | - clear_vec_high(s, is_q, rt); | ||
52 | } else { | ||
53 | /* Load/store one element per register */ | ||
54 | if (is_load) { | ||
55 | -- | 29 | -- |
56 | 2.19.1 | 30 | 2.20.1 |
57 | 31 | ||
58 | 32 | diff view generated by jsdifflib |
1 | If the HCR_EL2 PTW virtualizaiton configuration register bit | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | is set, then this means that a stage 2 Permission fault must | ||
3 | be generated if a stage 1 translation table access is made | ||
4 | to an address that is mapped as Device memory in stage 2. | ||
5 | Implement this. | ||
6 | 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> | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20181012144235.19646-8-peter.maydell@linaro.org | ||
10 | --- | 20 | --- |
11 | target/arm/helper.c | 21 ++++++++++++++++++++- | 21 | hw/core/clock.c | 6 +++--- |
12 | 1 file changed, 20 insertions(+), 1 deletion(-) | 22 | hw/core/trace-events | 4 ++-- |
23 | 2 files changed, 5 insertions(+), 5 deletions(-) | ||
13 | 24 | ||
14 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 25 | diff --git a/hw/core/clock.c b/hw/core/clock.c |
15 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/helper.c | 27 | --- a/hw/core/clock.c |
17 | +++ b/target/arm/helper.c | 28 | +++ b/hw/core/clock.c |
18 | @@ -XXX,XX +XXX,XX @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, | 29 | @@ -XXX,XX +XXX,XX @@ bool clock_set(Clock *clk, uint64_t period) |
19 | hwaddr s2pa; | 30 | if (clk->period == period) { |
20 | int s2prot; | 31 | return false; |
21 | int ret; | ||
22 | + ARMCacheAttrs cacheattrs = {}; | ||
23 | + ARMCacheAttrs *pcacheattrs = NULL; | ||
24 | + | ||
25 | + if (env->cp15.hcr_el2 & HCR_PTW) { | ||
26 | + /* | ||
27 | + * PTW means we must fault if this S1 walk touches S2 Device | ||
28 | + * memory; otherwise we don't care about the attributes and can | ||
29 | + * save the S2 translation the effort of computing them. | ||
30 | + */ | ||
31 | + pcacheattrs = &cacheattrs; | ||
32 | + } | ||
33 | |||
34 | ret = get_phys_addr_lpae(env, addr, 0, ARMMMUIdx_S2NS, &s2pa, | ||
35 | - &txattrs, &s2prot, &s2size, fi, NULL); | ||
36 | + &txattrs, &s2prot, &s2size, fi, pcacheattrs); | ||
37 | if (ret) { | ||
38 | assert(fi->type != ARMFault_None); | ||
39 | fi->s2addr = addr; | ||
40 | @@ -XXX,XX +XXX,XX @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, | ||
41 | fi->s1ptw = true; | ||
42 | return ~0; | ||
43 | } | ||
44 | + if (pcacheattrs && (pcacheattrs->attrs & 0xf0) == 0) { | ||
45 | + /* Access was to Device memory: generate Permission fault */ | ||
46 | + fi->type = ARMFault_Permission; | ||
47 | + fi->s2addr = addr; | ||
48 | + fi->stage2 = true; | ||
49 | + fi->s1ptw = true; | ||
50 | + return ~0; | ||
51 | + } | ||
52 | addr = s2pa; | ||
53 | } | 32 | } |
54 | return addr; | 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" | ||
55 | -- | 62 | -- |
56 | 2.19.1 | 63 | 2.20.1 |
57 | 64 | ||
58 | 65 | diff view generated by jsdifflib |
1 | The A/I/F bits in ISR_EL1 should track the virtual interrupt | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | status, not the physical interrupt status, if the associated | ||
3 | HCR_EL2.AMO/IMO/FMO bit is set. Implement this, rather than | ||
4 | always showing the physical interrupt status. | ||
5 | 2 | ||
6 | We don't currently implement anything to do with external | 3 | The CPRMAN (clock controller) was mapped at the watchdog/power manager |
7 | aborts, so this applies only to the I and F bits (though it | 4 | address. It was also split into two unimplemented peripherals (CM and |
8 | ought to be possible for the outer guest to present a virtual | 5 | A2W) but this is really the same one, as shown by this extract of the |
9 | external abort to the inner guest, even if QEMU doesn't | 6 | Raspberry Pi 3 Linux device tree: |
10 | emulate physical external aborts, so there is missing | ||
11 | functionality in this area). | ||
12 | 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> | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 27 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
15 | Message-id: 20181012144235.19646-6-peter.maydell@linaro.org | ||
16 | --- | 28 | --- |
17 | target/arm/helper.c | 22 ++++++++++++++++++---- | 29 | include/hw/arm/bcm2835_peripherals.h | 2 +- |
18 | 1 file changed, 18 insertions(+), 4 deletions(-) | 30 | include/hw/arm/raspi_platform.h | 5 ++--- |
31 | hw/arm/bcm2835_peripherals.c | 4 ++-- | ||
32 | 3 files changed, 5 insertions(+), 6 deletions(-) | ||
19 | 33 | ||
20 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 34 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h |
21 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/arm/helper.c | 36 | --- a/include/hw/arm/bcm2835_peripherals.h |
23 | +++ b/target/arm/helper.c | 37 | +++ b/include/hw/arm/bcm2835_peripherals.h |
24 | @@ -XXX,XX +XXX,XX @@ static uint64_t isr_read(CPUARMState *env, const ARMCPRegInfo *ri) | 38 | @@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState { |
25 | CPUState *cs = ENV_GET_CPU(env); | 39 | BCM2835MphiState mphi; |
26 | uint64_t ret = 0; | 40 | UnimplementedDeviceState txp; |
27 | 41 | UnimplementedDeviceState armtmr; | |
28 | - if (cs->interrupt_request & CPU_INTERRUPT_HARD) { | 42 | + UnimplementedDeviceState powermgt; |
29 | - ret |= CPSR_I; | 43 | UnimplementedDeviceState cprman; |
30 | + if (arm_hcr_el2_imo(env)) { | 44 | - UnimplementedDeviceState a2w; |
31 | + if (cs->interrupt_request & CPU_INTERRUPT_VIRQ) { | 45 | PL011State uart0; |
32 | + ret |= CPSR_I; | 46 | BCM2835AuxState aux; |
33 | + } | 47 | BCM2835FBState fb; |
34 | + } else { | 48 | diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h |
35 | + if (cs->interrupt_request & CPU_INTERRUPT_HARD) { | 49 | index XXXXXXX..XXXXXXX 100644 |
36 | + ret |= CPSR_I; | 50 | --- a/include/hw/arm/raspi_platform.h |
37 | + } | 51 | +++ b/include/hw/arm/raspi_platform.h |
38 | } | 52 | @@ -XXX,XX +XXX,XX @@ |
39 | - if (cs->interrupt_request & CPU_INTERRUPT_FIQ) { | 53 | #define ARMCTRL_TIMER0_1_OFFSET (ARM_OFFSET + 0x400) /* Timer 0 and 1 (SP804) */ |
40 | - ret |= CPSR_F; | 54 | #define ARMCTRL_0_SBM_OFFSET (ARM_OFFSET + 0x800) /* User 0 (ARM) Semaphores |
41 | + | 55 | * Doorbells & Mailboxes */ |
42 | + if (arm_hcr_el2_fmo(env)) { | 56 | -#define CPRMAN_OFFSET 0x100000 /* Power Management, Watchdog */ |
43 | + if (cs->interrupt_request & CPU_INTERRUPT_VFIQ) { | 57 | -#define CM_OFFSET 0x101000 /* Clock Management */ |
44 | + ret |= CPSR_F; | 58 | -#define A2W_OFFSET 0x102000 /* Reset controller */ |
45 | + } | 59 | +#define PM_OFFSET 0x100000 /* Power Management */ |
46 | + } else { | 60 | +#define CPRMAN_OFFSET 0x101000 /* Clock Management */ |
47 | + if (cs->interrupt_request & CPU_INTERRUPT_FIQ) { | 61 | #define AVS_OFFSET 0x103000 /* Audio Video Standard */ |
48 | + ret |= CPSR_F; | 62 | #define RNG_OFFSET 0x104000 |
49 | + } | 63 | #define GPIO_OFFSET 0x200000 |
50 | } | 64 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c |
51 | + | 65 | index XXXXXXX..XXXXXXX 100644 |
52 | /* External aborts are not possible in QEMU so A bit is always clear */ | 66 | --- a/hw/arm/bcm2835_peripherals.c |
53 | return ret; | 67 | +++ b/hw/arm/bcm2835_peripherals.c |
54 | } | 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); | ||
55 | -- | 79 | -- |
56 | 2.19.1 | 80 | 2.20.1 |
57 | 81 | ||
58 | 82 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Luc Michel <luc@lmichel.fr> | |
2 | |||
3 | The BCM2835 CPRMAN is the clock manager of the SoC. It is composed of a | ||
4 | main oscillator, and several sub-components (PLLs, multiplexers, ...) to | ||
5 | generate the BCM2835 clock tree. | ||
6 | |||
7 | This commit adds a skeleton of the CPRMAN, with a dummy register | ||
8 | read/write implementation. It embeds the main oscillator (xosc) from | ||
9 | which all the clocks will be derived. | ||
10 | |||
11 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
12 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
14 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | --- | ||
17 | include/hw/arm/bcm2835_peripherals.h | 3 +- | ||
18 | include/hw/misc/bcm2835_cprman.h | 37 +++++ | ||
19 | include/hw/misc/bcm2835_cprman_internals.h | 24 +++ | ||
20 | hw/arm/bcm2835_peripherals.c | 11 +- | ||
21 | hw/misc/bcm2835_cprman.c | 163 +++++++++++++++++++++ | ||
22 | hw/misc/meson.build | 1 + | ||
23 | hw/misc/trace-events | 5 + | ||
24 | 7 files changed, 242 insertions(+), 2 deletions(-) | ||
25 | create mode 100644 include/hw/misc/bcm2835_cprman.h | ||
26 | create mode 100644 include/hw/misc/bcm2835_cprman_internals.h | ||
27 | create mode 100644 hw/misc/bcm2835_cprman.c | ||
28 | |||
29 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/include/hw/arm/bcm2835_peripherals.h | ||
32 | +++ b/include/hw/arm/bcm2835_peripherals.h | ||
33 | @@ -XXX,XX +XXX,XX @@ | ||
34 | #include "hw/misc/bcm2835_mbox.h" | ||
35 | #include "hw/misc/bcm2835_mphi.h" | ||
36 | #include "hw/misc/bcm2835_thermal.h" | ||
37 | +#include "hw/misc/bcm2835_cprman.h" | ||
38 | #include "hw/sd/sdhci.h" | ||
39 | #include "hw/sd/bcm2835_sdhost.h" | ||
40 | #include "hw/gpio/bcm2835_gpio.h" | ||
41 | @@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState { | ||
42 | UnimplementedDeviceState txp; | ||
43 | UnimplementedDeviceState armtmr; | ||
44 | UnimplementedDeviceState powermgt; | ||
45 | - UnimplementedDeviceState cprman; | ||
46 | + BCM2835CprmanState cprman; | ||
47 | PL011State uart0; | ||
48 | BCM2835AuxState aux; | ||
49 | BCM2835FBState fb; | ||
50 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | ||
51 | new file mode 100644 | ||
52 | index XXXXXXX..XXXXXXX | ||
53 | --- /dev/null | ||
54 | +++ b/include/hw/misc/bcm2835_cprman.h | ||
55 | @@ -XXX,XX +XXX,XX @@ | ||
56 | +/* | ||
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 | ||
66 | + | ||
67 | +#include "hw/sysbus.h" | ||
68 | +#include "hw/qdev-clock.h" | ||
69 | + | ||
70 | +#define TYPE_BCM2835_CPRMAN "bcm2835-cprman" | ||
71 | + | ||
72 | +typedef struct BCM2835CprmanState BCM2835CprmanState; | ||
73 | + | ||
74 | +DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN, | ||
75 | + TYPE_BCM2835_CPRMAN) | ||
76 | + | ||
77 | +#define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) | ||
78 | + | ||
79 | +struct BCM2835CprmanState { | ||
80 | + /*< private >*/ | ||
81 | + SysBusDevice parent_obj; | ||
82 | + | ||
83 | + /*< public >*/ | ||
84 | + MemoryRegion iomem; | ||
85 | + | ||
86 | + uint32_t regs[CPRMAN_NUM_REGS]; | ||
87 | + uint32_t xosc_freq; | ||
88 | + | ||
89 | + Clock *xosc; | ||
90 | +}; | ||
91 | + | ||
92 | +#endif | ||
93 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
94 | new file mode 100644 | ||
95 | index XXXXXXX..XXXXXXX | ||
96 | --- /dev/null | ||
97 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
98 | @@ -XXX,XX +XXX,XX @@ | ||
99 | +/* | ||
100 | + * BCM2835 CPRMAN clock manager | ||
101 | + * | ||
102 | + * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> | ||
103 | + * | ||
104 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
105 | + */ | ||
106 | + | ||
107 | +#ifndef HW_MISC_CPRMAN_INTERNALS_H | ||
108 | +#define HW_MISC_CPRMAN_INTERNALS_H | ||
109 | + | ||
110 | +#include "hw/registerfields.h" | ||
111 | +#include "hw/misc/bcm2835_cprman.h" | ||
112 | + | ||
113 | +/* Register map */ | ||
114 | + | ||
115 | +/* | ||
116 | + * This field is common to all registers. Each register write value must match | ||
117 | + * the CPRMAN_PASSWORD magic value in its 8 MSB. | ||
118 | + */ | ||
119 | +FIELD(CPRMAN, PASSWORD, 24, 8) | ||
120 | +#define CPRMAN_PASSWORD 0x5a | ||
121 | + | ||
122 | +#endif | ||
123 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | ||
124 | index XXXXXXX..XXXXXXX 100644 | ||
125 | --- a/hw/arm/bcm2835_peripherals.c | ||
126 | +++ b/hw/arm/bcm2835_peripherals.c | ||
127 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj) | ||
128 | /* DWC2 */ | ||
129 | object_initialize_child(obj, "dwc2", &s->dwc2, TYPE_DWC2_USB); | ||
130 | |||
131 | + /* CPRMAN clock manager */ | ||
132 | + object_initialize_child(obj, "cprman", &s->cprman, TYPE_BCM2835_CPRMAN); | ||
133 | + | ||
134 | object_property_add_const_link(OBJECT(&s->dwc2), "dma-mr", | ||
135 | OBJECT(&s->gpu_bus_mr)); | ||
136 | } | ||
137 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
138 | return; | ||
139 | } | ||
140 | |||
141 | + /* CPRMAN clock manager */ | ||
142 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->cprman), errp)) { | ||
143 | + return; | ||
144 | + } | ||
145 | + memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET, | ||
146 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0)); | ||
147 | + | ||
148 | memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET, | ||
149 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0)); | ||
150 | sysbus_pass_irq(SYS_BUS_DEVICE(s), SYS_BUS_DEVICE(&s->ic)); | ||
151 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
152 | create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000); | ||
153 | create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); | ||
154 | create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114); | ||
155 | - create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000); | ||
156 | create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100); | ||
157 | create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100); | ||
158 | create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20); | ||
159 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
160 | new file mode 100644 | ||
161 | index XXXXXXX..XXXXXXX | ||
162 | --- /dev/null | ||
163 | +++ b/hw/misc/bcm2835_cprman.c | ||
164 | @@ -XXX,XX +XXX,XX @@ | ||
165 | +/* | ||
166 | + * BCM2835 CPRMAN clock manager | ||
167 | + * | ||
168 | + * Copyright (c) 2020 Luc Michel <luc@lmichel.fr> | ||
169 | + * | ||
170 | + * SPDX-License-Identifier: GPL-2.0-or-later | ||
171 | + */ | ||
172 | + | ||
173 | +/* | ||
174 | + * This peripheral is roughly divided into 3 main parts: | ||
175 | + * - the PLLs | ||
176 | + * - the PLL channels | ||
177 | + * - the clock muxes | ||
178 | + * | ||
179 | + * A main oscillator (xosc) feeds all the PLLs. Each PLLs has one or more | ||
180 | + * channels. Those channel are then connected to the clock muxes. Each mux has | ||
181 | + * multiples sources (usually the xosc, some of the PLL channels and some "test | ||
182 | + * debug" clocks). A mux is configured to select a given source through its | ||
183 | + * control register. Each mux has one output clock that also goes out of the | ||
184 | + * CPRMAN. This output clock usually connects to another peripheral in the SoC | ||
185 | + * (so a given mux is dedicated to a peripheral). | ||
186 | + * | ||
187 | + * At each level (PLL, channel and mux), the clock can be altered through | ||
188 | + * dividers (and multipliers in case of the PLLs), and can be disabled (in this | ||
189 | + * case, the next levels see no clock). | ||
190 | + * | ||
191 | + * This can be sum-up as follows (this is an example and not the actual BCM2835 | ||
192 | + * clock tree): | ||
193 | + * | ||
194 | + * /-->[PLL]-|->[PLL channel]--... [mux]--> to peripherals | ||
195 | + * | |->[PLL channel] muxes takes [mux] | ||
196 | + * | \->[PLL channel] inputs from [mux] | ||
197 | + * | some channels [mux] | ||
198 | + * [xosc]---|-->[PLL]-|->[PLL channel] and other srcs [mux] | ||
199 | + * | \->[PLL channel] ...-->[mux] | ||
200 | + * | [mux] | ||
201 | + * \-->[PLL]--->[PLL channel] [mux] | ||
202 | + * | ||
203 | + * The page at https://elinux.org/The_Undocumented_Pi gives the actual clock | ||
204 | + * tree configuration. | ||
205 | + */ | ||
206 | + | ||
207 | +#include "qemu/osdep.h" | ||
208 | +#include "qemu/log.h" | ||
209 | +#include "migration/vmstate.h" | ||
210 | +#include "hw/qdev-properties.h" | ||
211 | +#include "hw/misc/bcm2835_cprman.h" | ||
212 | +#include "hw/misc/bcm2835_cprman_internals.h" | ||
213 | +#include "trace.h" | ||
214 | + | ||
215 | +/* CPRMAN "top level" model */ | ||
216 | + | ||
217 | +static uint64_t cprman_read(void *opaque, hwaddr offset, | ||
218 | + unsigned size) | ||
219 | +{ | ||
220 | + BCM2835CprmanState *s = CPRMAN(opaque); | ||
221 | + uint64_t r = 0; | ||
222 | + size_t idx = offset / sizeof(uint32_t); | ||
223 | + | ||
224 | + switch (idx) { | ||
225 | + default: | ||
226 | + r = s->regs[idx]; | ||
227 | + } | ||
228 | + | ||
229 | + trace_bcm2835_cprman_read(offset, r); | ||
230 | + return r; | ||
231 | +} | ||
232 | + | ||
233 | +static void cprman_write(void *opaque, hwaddr offset, | ||
234 | + uint64_t value, unsigned size) | ||
235 | +{ | ||
236 | + BCM2835CprmanState *s = CPRMAN(opaque); | ||
237 | + size_t idx = offset / sizeof(uint32_t); | ||
238 | + | ||
239 | + if (FIELD_EX32(value, CPRMAN, PASSWORD) != CPRMAN_PASSWORD) { | ||
240 | + trace_bcm2835_cprman_write_invalid_magic(offset, value); | ||
241 | + return; | ||
242 | + } | ||
243 | + | ||
244 | + value &= ~R_CPRMAN_PASSWORD_MASK; | ||
245 | + | ||
246 | + trace_bcm2835_cprman_write(offset, value); | ||
247 | + s->regs[idx] = value; | ||
248 | + | ||
249 | +} | ||
250 | + | ||
251 | +static const MemoryRegionOps cprman_ops = { | ||
252 | + .read = cprman_read, | ||
253 | + .write = cprman_write, | ||
254 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
255 | + .valid = { | ||
256 | + /* | ||
257 | + * Although this hasn't been checked against real hardware, nor the | ||
258 | + * information can be found in a datasheet, it seems reasonable because | ||
259 | + * of the "PASSWORD" magic value found in every registers. | ||
260 | + */ | ||
261 | + .min_access_size = 4, | ||
262 | + .max_access_size = 4, | ||
263 | + .unaligned = false, | ||
264 | + }, | ||
265 | + .impl = { | ||
266 | + .max_access_size = 4, | ||
267 | + }, | ||
268 | +}; | ||
269 | + | ||
270 | +static void cprman_reset(DeviceState *dev) | ||
271 | +{ | ||
272 | + BCM2835CprmanState *s = CPRMAN(dev); | ||
273 | + | ||
274 | + memset(s->regs, 0, sizeof(s->regs)); | ||
275 | + | ||
276 | + clock_update_hz(s->xosc, s->xosc_freq); | ||
277 | +} | ||
278 | + | ||
279 | +static void cprman_init(Object *obj) | ||
280 | +{ | ||
281 | + BCM2835CprmanState *s = CPRMAN(obj); | ||
282 | + | ||
283 | + s->xosc = clock_new(obj, "xosc"); | ||
284 | + | ||
285 | + memory_region_init_io(&s->iomem, obj, &cprman_ops, | ||
286 | + s, "bcm2835-cprman", 0x2000); | ||
287 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); | ||
288 | +} | ||
289 | + | ||
290 | +static const VMStateDescription cprman_vmstate = { | ||
291 | + .name = TYPE_BCM2835_CPRMAN, | ||
292 | + .version_id = 1, | ||
293 | + .minimum_version_id = 1, | ||
294 | + .fields = (VMStateField[]) { | ||
295 | + VMSTATE_UINT32_ARRAY(regs, BCM2835CprmanState, CPRMAN_NUM_REGS), | ||
296 | + VMSTATE_END_OF_LIST() | ||
297 | + } | ||
298 | +}; | ||
299 | + | ||
300 | +static Property cprman_properties[] = { | ||
301 | + DEFINE_PROP_UINT32("xosc-freq-hz", BCM2835CprmanState, xosc_freq, 19200000), | ||
302 | + DEFINE_PROP_END_OF_LIST() | ||
303 | +}; | ||
304 | + | ||
305 | +static void cprman_class_init(ObjectClass *klass, void *data) | ||
306 | +{ | ||
307 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
308 | + | ||
309 | + dc->reset = cprman_reset; | ||
310 | + dc->vmsd = &cprman_vmstate; | ||
311 | + device_class_set_props(dc, cprman_properties); | ||
312 | +} | ||
313 | + | ||
314 | +static const TypeInfo cprman_info = { | ||
315 | + .name = TYPE_BCM2835_CPRMAN, | ||
316 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
317 | + .instance_size = sizeof(BCM2835CprmanState), | ||
318 | + .class_init = cprman_class_init, | ||
319 | + .instance_init = cprman_init, | ||
320 | +}; | ||
321 | + | ||
322 | +static void cprman_register_types(void) | ||
323 | +{ | ||
324 | + type_register_static(&cprman_info); | ||
325 | +} | ||
326 | + | ||
327 | +type_init(cprman_register_types); | ||
328 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
329 | index XXXXXXX..XXXXXXX 100644 | ||
330 | --- a/hw/misc/meson.build | ||
331 | +++ b/hw/misc/meson.build | ||
332 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files( | ||
333 | 'bcm2835_property.c', | ||
334 | 'bcm2835_rng.c', | ||
335 | 'bcm2835_thermal.c', | ||
336 | + 'bcm2835_cprman.c', | ||
337 | )) | ||
338 | softmmu_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_misc.c')) | ||
339 | softmmu_ss.add(when: 'CONFIG_ZYNQ', if_true: files('zynq_slcr.c', 'zynq-xadc.c')) | ||
340 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | ||
341 | index XXXXXXX..XXXXXXX 100644 | ||
342 | --- a/hw/misc/trace-events | ||
343 | +++ b/hw/misc/trace-events | ||
344 | @@ -XXX,XX +XXX,XX @@ grlib_apb_pnp_read(uint64_t addr, uint32_t value) "APB PnP read addr:0x%03"PRIx6 | ||
345 | # pca9552.c | ||
346 | pca955x_gpio_status(const char *description, const char *buf) "%s GPIOs 0-15 [%s]" | ||
347 | pca955x_gpio_change(const char *description, unsigned id, unsigned prev_state, unsigned current_state) "%s GPIO id:%u status: %u -> %u" | ||
348 | + | ||
349 | +# bcm2835_cprman.c | ||
350 | +bcm2835_cprman_read(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | ||
351 | +bcm2835_cprman_write(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | ||
352 | +bcm2835_cprman_write_invalid_magic(uint64_t offset, uint64_t value) "offset:0x%" PRIx64 " value:0x%" PRIx64 | ||
353 | -- | ||
354 | 2.20.1 | ||
355 | |||
356 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | Create struct ARMISARegisters, to be accessed during translation. | 3 | There are 5 PLLs in the CPRMAN, namely PLL A, C, D, H and B. All of them |
4 | 4 | take the xosc clock as input and produce a new clock. | |
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | |
6 | Message-id: 20181016223115.24100-2-richard.henderson@linaro.org | 6 | This commit adds a skeleton implementation for the PLLs as sub-devices |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | of the CPRMAN. The PLLs are instantiated and connected internally to the |
8 | main oscillator. | ||
9 | |||
10 | Each PLL has 6 registers : CM, A2W_CTRL, A2W_ANA[0,1,2,3], A2W_FRAC. A | ||
11 | write to any of them triggers a call to the (not yet implemented) | ||
12 | pll_update function. | ||
13 | |||
14 | If the main oscillator changes frequency, an update is also triggered. | ||
15 | |||
16 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
18 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
19 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 21 | --- |
10 | target/arm/cpu.h | 32 ++++---- | 22 | include/hw/misc/bcm2835_cprman.h | 29 +++++ |
11 | hw/intc/armv7m_nvic.c | 12 +-- | 23 | include/hw/misc/bcm2835_cprman_internals.h | 144 +++++++++++++++++++++ |
12 | target/arm/cpu.c | 178 +++++++++++++++++++++--------------------- | 24 | hw/misc/bcm2835_cprman.c | 108 ++++++++++++++++ |
13 | target/arm/cpu64.c | 70 ++++++++--------- | 25 | 3 files changed, 281 insertions(+) |
14 | target/arm/helper.c | 28 +++---- | 26 | |
15 | 5 files changed, 162 insertions(+), 158 deletions(-) | 27 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h |
16 | |||
17 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/arm/cpu.h | 29 | --- a/include/hw/misc/bcm2835_cprman.h |
20 | +++ b/target/arm/cpu.h | 30 | +++ b/include/hw/misc/bcm2835_cprman.h |
21 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { | 31 | @@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN, |
22 | * ARMv7AR ARM Architecture Reference Manual. A reset_ prefix | 32 | |
23 | * is used for reset values of non-constant registers; no reset_ | 33 | #define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) |
24 | * prefix means a constant register. | 34 | |
25 | + * Some of these registers are split out into a substructure that | 35 | +typedef enum CprmanPll { |
26 | + * is shared with the translators to control the ISA. | 36 | + CPRMAN_PLLA = 0, |
27 | */ | 37 | + CPRMAN_PLLC, |
28 | + struct ARMISARegisters { | 38 | + CPRMAN_PLLD, |
29 | + uint32_t id_isar0; | 39 | + CPRMAN_PLLH, |
30 | + uint32_t id_isar1; | 40 | + CPRMAN_PLLB, |
31 | + uint32_t id_isar2; | 41 | + |
32 | + uint32_t id_isar3; | 42 | + CPRMAN_NUM_PLL |
33 | + uint32_t id_isar4; | 43 | +} CprmanPll; |
34 | + uint32_t id_isar5; | 44 | + |
35 | + uint32_t id_isar6; | 45 | +typedef struct CprmanPllState { |
36 | + uint32_t mvfr0; | 46 | + /*< private >*/ |
37 | + uint32_t mvfr1; | 47 | + DeviceState parent_obj; |
38 | + uint32_t mvfr2; | 48 | + |
39 | + uint64_t id_aa64isar0; | 49 | + /*< public >*/ |
40 | + uint64_t id_aa64isar1; | 50 | + CprmanPll id; |
41 | + uint64_t id_aa64pfr0; | 51 | + |
42 | + uint64_t id_aa64pfr1; | 52 | + uint32_t *reg_cm; |
43 | + } isar; | 53 | + uint32_t *reg_a2w_ctrl; |
44 | uint32_t midr; | 54 | + uint32_t *reg_a2w_ana; /* ANA[0] .. ANA[3] */ |
45 | uint32_t revidr; | 55 | + uint32_t prediv_mask; /* prediv bit in ana[1] */ |
46 | uint32_t reset_fpsid; | 56 | + uint32_t *reg_a2w_frac; |
47 | - uint32_t mvfr0; | 57 | + |
48 | - uint32_t mvfr1; | 58 | + Clock *xosc_in; |
49 | - uint32_t mvfr2; | 59 | + Clock *out; |
50 | uint32_t ctr; | 60 | +} CprmanPllState; |
51 | uint32_t reset_sctlr; | 61 | + |
52 | uint32_t id_pfr0; | 62 | struct BCM2835CprmanState { |
53 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { | 63 | /*< private >*/ |
54 | uint32_t id_mmfr2; | 64 | SysBusDevice parent_obj; |
55 | uint32_t id_mmfr3; | 65 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { |
56 | uint32_t id_mmfr4; | 66 | /*< public >*/ |
57 | - uint32_t id_isar0; | 67 | MemoryRegion iomem; |
58 | - uint32_t id_isar1; | 68 | |
59 | - uint32_t id_isar2; | 69 | + CprmanPllState plls[CPRMAN_NUM_PLL]; |
60 | - uint32_t id_isar3; | 70 | + |
61 | - uint32_t id_isar4; | 71 | uint32_t regs[CPRMAN_NUM_REGS]; |
62 | - uint32_t id_isar5; | 72 | uint32_t xosc_freq; |
63 | - uint32_t id_isar6; | 73 | |
64 | - uint64_t id_aa64pfr0; | 74 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h |
65 | - uint64_t id_aa64pfr1; | ||
66 | uint64_t id_aa64dfr0; | ||
67 | uint64_t id_aa64dfr1; | ||
68 | uint64_t id_aa64afr0; | ||
69 | uint64_t id_aa64afr1; | ||
70 | - uint64_t id_aa64isar0; | ||
71 | - uint64_t id_aa64isar1; | ||
72 | uint64_t id_aa64mmfr0; | ||
73 | uint64_t id_aa64mmfr1; | ||
74 | uint32_t dbgdidr; | ||
75 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | ||
76 | index XXXXXXX..XXXXXXX 100644 | 75 | index XXXXXXX..XXXXXXX 100644 |
77 | --- a/hw/intc/armv7m_nvic.c | 76 | --- a/include/hw/misc/bcm2835_cprman_internals.h |
78 | +++ b/hw/intc/armv7m_nvic.c | 77 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
79 | @@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs) | 78 | @@ -XXX,XX +XXX,XX @@ |
80 | case 0xd5c: /* MMFR3. */ | 79 | #include "hw/registerfields.h" |
81 | return cpu->id_mmfr3; | 80 | #include "hw/misc/bcm2835_cprman.h" |
82 | case 0xd60: /* ISAR0. */ | 81 | |
83 | - return cpu->id_isar0; | 82 | +#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" |
84 | + return cpu->isar.id_isar0; | 83 | + |
85 | case 0xd64: /* ISAR1. */ | 84 | +DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, |
86 | - return cpu->id_isar1; | 85 | + TYPE_CPRMAN_PLL) |
87 | + return cpu->isar.id_isar1; | 86 | + |
88 | case 0xd68: /* ISAR2. */ | 87 | /* Register map */ |
89 | - return cpu->id_isar2; | 88 | |
90 | + return cpu->isar.id_isar2; | 89 | +/* PLLs */ |
91 | case 0xd6c: /* ISAR3. */ | 90 | +REG32(CM_PLLA, 0x104) |
92 | - return cpu->id_isar3; | 91 | + FIELD(CM_PLLA, LOADDSI0, 0, 1) |
93 | + return cpu->isar.id_isar3; | 92 | + FIELD(CM_PLLA, HOLDDSI0, 1, 1) |
94 | case 0xd70: /* ISAR4. */ | 93 | + FIELD(CM_PLLA, LOADCCP2, 2, 1) |
95 | - return cpu->id_isar4; | 94 | + FIELD(CM_PLLA, HOLDCCP2, 3, 1) |
96 | + return cpu->isar.id_isar4; | 95 | + FIELD(CM_PLLA, LOADCORE, 4, 1) |
97 | case 0xd74: /* ISAR5. */ | 96 | + FIELD(CM_PLLA, HOLDCORE, 5, 1) |
98 | - return cpu->id_isar5; | 97 | + FIELD(CM_PLLA, LOADPER, 6, 1) |
99 | + return cpu->isar.id_isar5; | 98 | + FIELD(CM_PLLA, HOLDPER, 7, 1) |
100 | case 0xd78: /* CLIDR */ | 99 | + FIELD(CM_PLLx, ANARST, 8, 1) |
101 | return cpu->clidr; | 100 | +REG32(CM_PLLC, 0x108) |
102 | case 0xd7c: /* CTR */ | 101 | + FIELD(CM_PLLC, LOADCORE0, 0, 1) |
103 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 102 | + FIELD(CM_PLLC, HOLDCORE0, 1, 1) |
103 | + FIELD(CM_PLLC, LOADCORE1, 2, 1) | ||
104 | + FIELD(CM_PLLC, HOLDCORE1, 3, 1) | ||
105 | + FIELD(CM_PLLC, LOADCORE2, 4, 1) | ||
106 | + FIELD(CM_PLLC, HOLDCORE2, 5, 1) | ||
107 | + FIELD(CM_PLLC, LOADPER, 6, 1) | ||
108 | + FIELD(CM_PLLC, HOLDPER, 7, 1) | ||
109 | +REG32(CM_PLLD, 0x10c) | ||
110 | + FIELD(CM_PLLD, LOADDSI0, 0, 1) | ||
111 | + FIELD(CM_PLLD, HOLDDSI0, 1, 1) | ||
112 | + FIELD(CM_PLLD, LOADDSI1, 2, 1) | ||
113 | + FIELD(CM_PLLD, HOLDDSI1, 3, 1) | ||
114 | + FIELD(CM_PLLD, LOADCORE, 4, 1) | ||
115 | + FIELD(CM_PLLD, HOLDCORE, 5, 1) | ||
116 | + FIELD(CM_PLLD, LOADPER, 6, 1) | ||
117 | + FIELD(CM_PLLD, HOLDPER, 7, 1) | ||
118 | +REG32(CM_PLLH, 0x110) | ||
119 | + FIELD(CM_PLLH, LOADPIX, 0, 1) | ||
120 | + FIELD(CM_PLLH, LOADAUX, 1, 1) | ||
121 | + FIELD(CM_PLLH, LOADRCAL, 2, 1) | ||
122 | +REG32(CM_PLLB, 0x170) | ||
123 | + FIELD(CM_PLLB, LOADARM, 0, 1) | ||
124 | + FIELD(CM_PLLB, HOLDARM, 1, 1) | ||
125 | + | ||
126 | +REG32(A2W_PLLA_CTRL, 0x1100) | ||
127 | + FIELD(A2W_PLLx_CTRL, NDIV, 0, 10) | ||
128 | + FIELD(A2W_PLLx_CTRL, PDIV, 12, 3) | ||
129 | + FIELD(A2W_PLLx_CTRL, PWRDN, 16, 1) | ||
130 | + FIELD(A2W_PLLx_CTRL, PRST_DISABLE, 17, 1) | ||
131 | +REG32(A2W_PLLC_CTRL, 0x1120) | ||
132 | +REG32(A2W_PLLD_CTRL, 0x1140) | ||
133 | +REG32(A2W_PLLH_CTRL, 0x1160) | ||
134 | +REG32(A2W_PLLB_CTRL, 0x11e0) | ||
135 | + | ||
136 | +REG32(A2W_PLLA_ANA0, 0x1010) | ||
137 | +REG32(A2W_PLLA_ANA1, 0x1014) | ||
138 | + FIELD(A2W_PLLx_ANA1, FB_PREDIV, 14, 1) | ||
139 | +REG32(A2W_PLLA_ANA2, 0x1018) | ||
140 | +REG32(A2W_PLLA_ANA3, 0x101c) | ||
141 | + | ||
142 | +REG32(A2W_PLLC_ANA0, 0x1030) | ||
143 | +REG32(A2W_PLLC_ANA1, 0x1034) | ||
144 | +REG32(A2W_PLLC_ANA2, 0x1038) | ||
145 | +REG32(A2W_PLLC_ANA3, 0x103c) | ||
146 | + | ||
147 | +REG32(A2W_PLLD_ANA0, 0x1050) | ||
148 | +REG32(A2W_PLLD_ANA1, 0x1054) | ||
149 | +REG32(A2W_PLLD_ANA2, 0x1058) | ||
150 | +REG32(A2W_PLLD_ANA3, 0x105c) | ||
151 | + | ||
152 | +REG32(A2W_PLLH_ANA0, 0x1070) | ||
153 | +REG32(A2W_PLLH_ANA1, 0x1074) | ||
154 | + FIELD(A2W_PLLH_ANA1, FB_PREDIV, 11, 1) | ||
155 | +REG32(A2W_PLLH_ANA2, 0x1078) | ||
156 | +REG32(A2W_PLLH_ANA3, 0x107c) | ||
157 | + | ||
158 | +REG32(A2W_PLLB_ANA0, 0x10f0) | ||
159 | +REG32(A2W_PLLB_ANA1, 0x10f4) | ||
160 | +REG32(A2W_PLLB_ANA2, 0x10f8) | ||
161 | +REG32(A2W_PLLB_ANA3, 0x10fc) | ||
162 | + | ||
163 | +REG32(A2W_PLLA_FRAC, 0x1200) | ||
164 | + FIELD(A2W_PLLx_FRAC, FRAC, 0, 20) | ||
165 | +REG32(A2W_PLLC_FRAC, 0x1220) | ||
166 | +REG32(A2W_PLLD_FRAC, 0x1240) | ||
167 | +REG32(A2W_PLLH_FRAC, 0x1260) | ||
168 | +REG32(A2W_PLLB_FRAC, 0x12e0) | ||
169 | + | ||
170 | /* | ||
171 | * This field is common to all registers. Each register write value must match | ||
172 | * the CPRMAN_PASSWORD magic value in its 8 MSB. | ||
173 | @@ -XXX,XX +XXX,XX @@ | ||
174 | FIELD(CPRMAN, PASSWORD, 24, 8) | ||
175 | #define CPRMAN_PASSWORD 0x5a | ||
176 | |||
177 | +/* PLL init info */ | ||
178 | +typedef struct PLLInitInfo { | ||
179 | + const char *name; | ||
180 | + size_t cm_offset; | ||
181 | + size_t a2w_ctrl_offset; | ||
182 | + size_t a2w_ana_offset; | ||
183 | + uint32_t prediv_mask; /* Prediv bit in ana[1] */ | ||
184 | + size_t a2w_frac_offset; | ||
185 | +} PLLInitInfo; | ||
186 | + | ||
187 | +#define FILL_PLL_INIT_INFO(pll_) \ | ||
188 | + .cm_offset = R_CM_ ## pll_, \ | ||
189 | + .a2w_ctrl_offset = R_A2W_ ## pll_ ## _CTRL, \ | ||
190 | + .a2w_ana_offset = R_A2W_ ## pll_ ## _ANA0, \ | ||
191 | + .a2w_frac_offset = R_A2W_ ## pll_ ## _FRAC | ||
192 | + | ||
193 | +static const PLLInitInfo PLL_INIT_INFO[] = { | ||
194 | + [CPRMAN_PLLA] = { | ||
195 | + .name = "plla", | ||
196 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | ||
197 | + FILL_PLL_INIT_INFO(PLLA), | ||
198 | + }, | ||
199 | + [CPRMAN_PLLC] = { | ||
200 | + .name = "pllc", | ||
201 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | ||
202 | + FILL_PLL_INIT_INFO(PLLC), | ||
203 | + }, | ||
204 | + [CPRMAN_PLLD] = { | ||
205 | + .name = "plld", | ||
206 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | ||
207 | + FILL_PLL_INIT_INFO(PLLD), | ||
208 | + }, | ||
209 | + [CPRMAN_PLLH] = { | ||
210 | + .name = "pllh", | ||
211 | + .prediv_mask = R_A2W_PLLH_ANA1_FB_PREDIV_MASK, | ||
212 | + FILL_PLL_INIT_INFO(PLLH), | ||
213 | + }, | ||
214 | + [CPRMAN_PLLB] = { | ||
215 | + .name = "pllb", | ||
216 | + .prediv_mask = R_A2W_PLLx_ANA1_FB_PREDIV_MASK, | ||
217 | + FILL_PLL_INIT_INFO(PLLB), | ||
218 | + }, | ||
219 | +}; | ||
220 | + | ||
221 | +#undef FILL_PLL_CHANNEL_INIT_INFO | ||
222 | + | ||
223 | +static inline void set_pll_init_info(BCM2835CprmanState *s, | ||
224 | + CprmanPllState *pll, | ||
225 | + CprmanPll id) | ||
226 | +{ | ||
227 | + pll->id = id; | ||
228 | + pll->reg_cm = &s->regs[PLL_INIT_INFO[id].cm_offset]; | ||
229 | + pll->reg_a2w_ctrl = &s->regs[PLL_INIT_INFO[id].a2w_ctrl_offset]; | ||
230 | + pll->reg_a2w_ana = &s->regs[PLL_INIT_INFO[id].a2w_ana_offset]; | ||
231 | + pll->prediv_mask = PLL_INIT_INFO[id].prediv_mask; | ||
232 | + pll->reg_a2w_frac = &s->regs[PLL_INIT_INFO[id].a2w_frac_offset]; | ||
233 | +} | ||
234 | + | ||
235 | #endif | ||
236 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
104 | index XXXXXXX..XXXXXXX 100644 | 237 | index XXXXXXX..XXXXXXX 100644 |
105 | --- a/target/arm/cpu.c | 238 | --- a/hw/misc/bcm2835_cprman.c |
106 | +++ b/target/arm/cpu.c | 239 | +++ b/hw/misc/bcm2835_cprman.c |
107 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s) | 240 | @@ -XXX,XX +XXX,XX @@ |
108 | g_hash_table_foreach(cpu->cp_regs, cp_reg_check_reset, cpu); | 241 | #include "hw/misc/bcm2835_cprman_internals.h" |
109 | 242 | #include "trace.h" | |
110 | env->vfp.xregs[ARM_VFP_FPSID] = cpu->reset_fpsid; | 243 | |
111 | - env->vfp.xregs[ARM_VFP_MVFR0] = cpu->mvfr0; | 244 | +/* PLL */ |
112 | - env->vfp.xregs[ARM_VFP_MVFR1] = cpu->mvfr1; | 245 | + |
113 | - env->vfp.xregs[ARM_VFP_MVFR2] = cpu->mvfr2; | 246 | +static void pll_update(CprmanPllState *pll) |
114 | + env->vfp.xregs[ARM_VFP_MVFR0] = cpu->isar.mvfr0; | 247 | +{ |
115 | + env->vfp.xregs[ARM_VFP_MVFR1] = cpu->isar.mvfr1; | 248 | + clock_update(pll->out, 0); |
116 | + env->vfp.xregs[ARM_VFP_MVFR2] = cpu->isar.mvfr2; | 249 | +} |
117 | 250 | + | |
118 | cpu->power_state = cpu->start_powered_off ? PSCI_OFF : PSCI_ON; | 251 | +static void pll_xosc_update(void *opaque) |
119 | s->halted = cpu->start_powered_off; | 252 | +{ |
120 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) | 253 | + pll_update(CPRMAN_PLL(opaque)); |
121 | * registers as well. These are id_pfr1[7:4] and id_aa64pfr0[15:12]. | 254 | +} |
122 | */ | 255 | + |
123 | cpu->id_pfr1 &= ~0xf0; | 256 | +static void pll_init(Object *obj) |
124 | - cpu->id_aa64pfr0 &= ~0xf000; | 257 | +{ |
125 | + cpu->isar.id_aa64pfr0 &= ~0xf000; | 258 | + CprmanPllState *s = CPRMAN_PLL(obj); |
126 | } | 259 | + |
127 | 260 | + s->xosc_in = qdev_init_clock_in(DEVICE(s), "xosc-in", pll_xosc_update, s); | |
128 | if (!cpu->has_el2) { | 261 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); |
129 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) | 262 | +} |
130 | * registers if we don't have EL2. These are id_pfr1[15:12] and | 263 | + |
131 | * id_aa64pfr0_el1[11:8]. | 264 | +static const VMStateDescription pll_vmstate = { |
132 | */ | 265 | + .name = TYPE_CPRMAN_PLL, |
133 | - cpu->id_aa64pfr0 &= ~0xf00; | 266 | + .version_id = 1, |
134 | + cpu->isar.id_aa64pfr0 &= ~0xf00; | 267 | + .minimum_version_id = 1, |
135 | cpu->id_pfr1 &= ~0xf000; | 268 | + .fields = (VMStateField[]) { |
136 | } | 269 | + VMSTATE_CLOCK(xosc_in, CprmanPllState), |
137 | 270 | + VMSTATE_END_OF_LIST() | |
138 | @@ -XXX,XX +XXX,XX @@ static void arm1136_r2_initfn(Object *obj) | 271 | + } |
139 | set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS); | 272 | +}; |
140 | cpu->midr = 0x4107b362; | 273 | + |
141 | cpu->reset_fpsid = 0x410120b4; | 274 | +static void pll_class_init(ObjectClass *klass, void *data) |
142 | - cpu->mvfr0 = 0x11111111; | 275 | +{ |
143 | - cpu->mvfr1 = 0x00000000; | 276 | + DeviceClass *dc = DEVICE_CLASS(klass); |
144 | + cpu->isar.mvfr0 = 0x11111111; | 277 | + |
145 | + cpu->isar.mvfr1 = 0x00000000; | 278 | + dc->vmsd = &pll_vmstate; |
146 | cpu->ctr = 0x1dd20d2; | 279 | +} |
147 | cpu->reset_sctlr = 0x00050078; | 280 | + |
148 | cpu->id_pfr0 = 0x111; | 281 | +static const TypeInfo cprman_pll_info = { |
149 | @@ -XXX,XX +XXX,XX @@ static void arm1136_r2_initfn(Object *obj) | 282 | + .name = TYPE_CPRMAN_PLL, |
150 | cpu->id_mmfr0 = 0x01130003; | 283 | + .parent = TYPE_DEVICE, |
151 | cpu->id_mmfr1 = 0x10030302; | 284 | + .instance_size = sizeof(CprmanPllState), |
152 | cpu->id_mmfr2 = 0x01222110; | 285 | + .class_init = pll_class_init, |
153 | - cpu->id_isar0 = 0x00140011; | 286 | + .instance_init = pll_init, |
154 | - cpu->id_isar1 = 0x12002111; | 287 | +}; |
155 | - cpu->id_isar2 = 0x11231111; | 288 | + |
156 | - cpu->id_isar3 = 0x01102131; | 289 | + |
157 | - cpu->id_isar4 = 0x141; | 290 | /* CPRMAN "top level" model */ |
158 | + cpu->isar.id_isar0 = 0x00140011; | 291 | |
159 | + cpu->isar.id_isar1 = 0x12002111; | 292 | static uint64_t cprman_read(void *opaque, hwaddr offset, |
160 | + cpu->isar.id_isar2 = 0x11231111; | 293 | @@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset, |
161 | + cpu->isar.id_isar3 = 0x01102131; | 294 | return r; |
162 | + cpu->isar.id_isar4 = 0x141; | ||
163 | cpu->reset_auxcr = 7; | ||
164 | } | 295 | } |
165 | 296 | ||
166 | @@ -XXX,XX +XXX,XX @@ static void arm1136_initfn(Object *obj) | 297 | +#define CASE_PLL_REGS(pll_) \ |
167 | set_feature(&cpu->env, ARM_FEATURE_CACHE_BLOCK_OPS); | 298 | + case R_CM_ ## pll_: \ |
168 | cpu->midr = 0x4117b363; | 299 | + case R_A2W_ ## pll_ ## _CTRL: \ |
169 | cpu->reset_fpsid = 0x410120b4; | 300 | + case R_A2W_ ## pll_ ## _ANA0: \ |
170 | - cpu->mvfr0 = 0x11111111; | 301 | + case R_A2W_ ## pll_ ## _ANA1: \ |
171 | - cpu->mvfr1 = 0x00000000; | 302 | + case R_A2W_ ## pll_ ## _ANA2: \ |
172 | + cpu->isar.mvfr0 = 0x11111111; | 303 | + case R_A2W_ ## pll_ ## _ANA3: \ |
173 | + cpu->isar.mvfr1 = 0x00000000; | 304 | + case R_A2W_ ## pll_ ## _FRAC |
174 | cpu->ctr = 0x1dd20d2; | 305 | + |
175 | cpu->reset_sctlr = 0x00050078; | 306 | static void cprman_write(void *opaque, hwaddr offset, |
176 | cpu->id_pfr0 = 0x111; | 307 | uint64_t value, unsigned size) |
177 | @@ -XXX,XX +XXX,XX @@ static void arm1136_initfn(Object *obj) | 308 | { |
178 | cpu->id_mmfr0 = 0x01130003; | 309 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, |
179 | cpu->id_mmfr1 = 0x10030302; | 310 | trace_bcm2835_cprman_write(offset, value); |
180 | cpu->id_mmfr2 = 0x01222110; | 311 | s->regs[idx] = value; |
181 | - cpu->id_isar0 = 0x00140011; | 312 | |
182 | - cpu->id_isar1 = 0x12002111; | 313 | + switch (idx) { |
183 | - cpu->id_isar2 = 0x11231111; | 314 | + CASE_PLL_REGS(PLLA) : |
184 | - cpu->id_isar3 = 0x01102131; | 315 | + pll_update(&s->plls[CPRMAN_PLLA]); |
185 | - cpu->id_isar4 = 0x141; | 316 | + break; |
186 | + cpu->isar.id_isar0 = 0x00140011; | 317 | + |
187 | + cpu->isar.id_isar1 = 0x12002111; | 318 | + CASE_PLL_REGS(PLLC) : |
188 | + cpu->isar.id_isar2 = 0x11231111; | 319 | + pll_update(&s->plls[CPRMAN_PLLC]); |
189 | + cpu->isar.id_isar3 = 0x01102131; | 320 | + break; |
190 | + cpu->isar.id_isar4 = 0x141; | 321 | + |
191 | cpu->reset_auxcr = 7; | 322 | + CASE_PLL_REGS(PLLD) : |
323 | + pll_update(&s->plls[CPRMAN_PLLD]); | ||
324 | + break; | ||
325 | + | ||
326 | + CASE_PLL_REGS(PLLH) : | ||
327 | + pll_update(&s->plls[CPRMAN_PLLH]); | ||
328 | + break; | ||
329 | + | ||
330 | + CASE_PLL_REGS(PLLB) : | ||
331 | + pll_update(&s->plls[CPRMAN_PLLB]); | ||
332 | + break; | ||
333 | + } | ||
192 | } | 334 | } |
193 | 335 | ||
194 | @@ -XXX,XX +XXX,XX @@ static void arm1176_initfn(Object *obj) | 336 | +#undef CASE_PLL_REGS |
195 | set_feature(&cpu->env, ARM_FEATURE_EL3); | 337 | + |
196 | cpu->midr = 0x410fb767; | 338 | static const MemoryRegionOps cprman_ops = { |
197 | cpu->reset_fpsid = 0x410120b5; | 339 | .read = cprman_read, |
198 | - cpu->mvfr0 = 0x11111111; | 340 | .write = cprman_write, |
199 | - cpu->mvfr1 = 0x00000000; | 341 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps cprman_ops = { |
200 | + cpu->isar.mvfr0 = 0x11111111; | 342 | static void cprman_reset(DeviceState *dev) |
201 | + cpu->isar.mvfr1 = 0x00000000; | 343 | { |
202 | cpu->ctr = 0x1dd20d2; | 344 | BCM2835CprmanState *s = CPRMAN(dev); |
203 | cpu->reset_sctlr = 0x00050078; | 345 | + size_t i; |
204 | cpu->id_pfr0 = 0x111; | 346 | |
205 | @@ -XXX,XX +XXX,XX @@ static void arm1176_initfn(Object *obj) | 347 | memset(s->regs, 0, sizeof(s->regs)); |
206 | cpu->id_mmfr0 = 0x01130003; | 348 | |
207 | cpu->id_mmfr1 = 0x10030302; | 349 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { |
208 | cpu->id_mmfr2 = 0x01222100; | 350 | + device_cold_reset(DEVICE(&s->plls[i])); |
209 | - cpu->id_isar0 = 0x0140011; | 351 | + } |
210 | - cpu->id_isar1 = 0x12002111; | 352 | + |
211 | - cpu->id_isar2 = 0x11231121; | 353 | clock_update_hz(s->xosc, s->xosc_freq); |
212 | - cpu->id_isar3 = 0x01102131; | ||
213 | - cpu->id_isar4 = 0x01141; | ||
214 | + cpu->isar.id_isar0 = 0x0140011; | ||
215 | + cpu->isar.id_isar1 = 0x12002111; | ||
216 | + cpu->isar.id_isar2 = 0x11231121; | ||
217 | + cpu->isar.id_isar3 = 0x01102131; | ||
218 | + cpu->isar.id_isar4 = 0x01141; | ||
219 | cpu->reset_auxcr = 7; | ||
220 | } | 354 | } |
221 | 355 | ||
222 | @@ -XXX,XX +XXX,XX @@ static void arm11mpcore_initfn(Object *obj) | 356 | static void cprman_init(Object *obj) |
223 | set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS); | 357 | { |
224 | cpu->midr = 0x410fb022; | 358 | BCM2835CprmanState *s = CPRMAN(obj); |
225 | cpu->reset_fpsid = 0x410120b4; | 359 | + size_t i; |
226 | - cpu->mvfr0 = 0x11111111; | 360 | + |
227 | - cpu->mvfr1 = 0x00000000; | 361 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { |
228 | + cpu->isar.mvfr0 = 0x11111111; | 362 | + object_initialize_child(obj, PLL_INIT_INFO[i].name, |
229 | + cpu->isar.mvfr1 = 0x00000000; | 363 | + &s->plls[i], TYPE_CPRMAN_PLL); |
230 | cpu->ctr = 0x1d192992; /* 32K icache 32K dcache */ | 364 | + set_pll_init_info(s, &s->plls[i], i); |
231 | cpu->id_pfr0 = 0x111; | 365 | + } |
232 | cpu->id_pfr1 = 0x1; | 366 | |
233 | @@ -XXX,XX +XXX,XX @@ static void arm11mpcore_initfn(Object *obj) | 367 | s->xosc = clock_new(obj, "xosc"); |
234 | cpu->id_mmfr0 = 0x01100103; | 368 | |
235 | cpu->id_mmfr1 = 0x10020302; | 369 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) |
236 | cpu->id_mmfr2 = 0x01222000; | 370 | sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); |
237 | - cpu->id_isar0 = 0x00100011; | ||
238 | - cpu->id_isar1 = 0x12002111; | ||
239 | - cpu->id_isar2 = 0x11221011; | ||
240 | - cpu->id_isar3 = 0x01102131; | ||
241 | - cpu->id_isar4 = 0x141; | ||
242 | + cpu->isar.id_isar0 = 0x00100011; | ||
243 | + cpu->isar.id_isar1 = 0x12002111; | ||
244 | + cpu->isar.id_isar2 = 0x11221011; | ||
245 | + cpu->isar.id_isar3 = 0x01102131; | ||
246 | + cpu->isar.id_isar4 = 0x141; | ||
247 | cpu->reset_auxcr = 1; | ||
248 | } | 371 | } |
249 | 372 | ||
250 | @@ -XXX,XX +XXX,XX @@ static void cortex_m3_initfn(Object *obj) | 373 | +static void cprman_realize(DeviceState *dev, Error **errp) |
251 | cpu->id_mmfr1 = 0x00000000; | 374 | +{ |
252 | cpu->id_mmfr2 = 0x00000000; | 375 | + BCM2835CprmanState *s = CPRMAN(dev); |
253 | cpu->id_mmfr3 = 0x00000000; | 376 | + size_t i; |
254 | - cpu->id_isar0 = 0x01141110; | 377 | + |
255 | - cpu->id_isar1 = 0x02111000; | 378 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { |
256 | - cpu->id_isar2 = 0x21112231; | 379 | + CprmanPllState *pll = &s->plls[i]; |
257 | - cpu->id_isar3 = 0x01111110; | 380 | + |
258 | - cpu->id_isar4 = 0x01310102; | 381 | + clock_set_source(pll->xosc_in, s->xosc); |
259 | - cpu->id_isar5 = 0x00000000; | 382 | + |
260 | - cpu->id_isar6 = 0x00000000; | 383 | + if (!qdev_realize(DEVICE(pll), NULL, errp)) { |
261 | + cpu->isar.id_isar0 = 0x01141110; | 384 | + return; |
262 | + cpu->isar.id_isar1 = 0x02111000; | 385 | + } |
263 | + cpu->isar.id_isar2 = 0x21112231; | 386 | + } |
264 | + cpu->isar.id_isar3 = 0x01111110; | 387 | +} |
265 | + cpu->isar.id_isar4 = 0x01310102; | 388 | + |
266 | + cpu->isar.id_isar5 = 0x00000000; | 389 | static const VMStateDescription cprman_vmstate = { |
267 | + cpu->isar.id_isar6 = 0x00000000; | 390 | .name = TYPE_BCM2835_CPRMAN, |
391 | .version_id = 1, | ||
392 | @@ -XXX,XX +XXX,XX @@ static void cprman_class_init(ObjectClass *klass, void *data) | ||
393 | { | ||
394 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
395 | |||
396 | + dc->realize = cprman_realize; | ||
397 | dc->reset = cprman_reset; | ||
398 | dc->vmsd = &cprman_vmstate; | ||
399 | device_class_set_props(dc, cprman_properties); | ||
400 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_info = { | ||
401 | static void cprman_register_types(void) | ||
402 | { | ||
403 | type_register_static(&cprman_info); | ||
404 | + type_register_static(&cprman_pll_info); | ||
268 | } | 405 | } |
269 | 406 | ||
270 | static void cortex_m4_initfn(Object *obj) | 407 | type_init(cprman_register_types); |
271 | @@ -XXX,XX +XXX,XX @@ static void cortex_m4_initfn(Object *obj) | ||
272 | cpu->id_mmfr1 = 0x00000000; | ||
273 | cpu->id_mmfr2 = 0x00000000; | ||
274 | cpu->id_mmfr3 = 0x00000000; | ||
275 | - cpu->id_isar0 = 0x01141110; | ||
276 | - cpu->id_isar1 = 0x02111000; | ||
277 | - cpu->id_isar2 = 0x21112231; | ||
278 | - cpu->id_isar3 = 0x01111110; | ||
279 | - cpu->id_isar4 = 0x01310102; | ||
280 | - cpu->id_isar5 = 0x00000000; | ||
281 | - cpu->id_isar6 = 0x00000000; | ||
282 | + cpu->isar.id_isar0 = 0x01141110; | ||
283 | + cpu->isar.id_isar1 = 0x02111000; | ||
284 | + cpu->isar.id_isar2 = 0x21112231; | ||
285 | + cpu->isar.id_isar3 = 0x01111110; | ||
286 | + cpu->isar.id_isar4 = 0x01310102; | ||
287 | + cpu->isar.id_isar5 = 0x00000000; | ||
288 | + cpu->isar.id_isar6 = 0x00000000; | ||
289 | } | ||
290 | |||
291 | static void cortex_m33_initfn(Object *obj) | ||
292 | @@ -XXX,XX +XXX,XX @@ static void cortex_m33_initfn(Object *obj) | ||
293 | cpu->id_mmfr1 = 0x00000000; | ||
294 | cpu->id_mmfr2 = 0x01000000; | ||
295 | cpu->id_mmfr3 = 0x00000000; | ||
296 | - cpu->id_isar0 = 0x01101110; | ||
297 | - cpu->id_isar1 = 0x02212000; | ||
298 | - cpu->id_isar2 = 0x20232232; | ||
299 | - cpu->id_isar3 = 0x01111131; | ||
300 | - cpu->id_isar4 = 0x01310132; | ||
301 | - cpu->id_isar5 = 0x00000000; | ||
302 | - cpu->id_isar6 = 0x00000000; | ||
303 | + cpu->isar.id_isar0 = 0x01101110; | ||
304 | + cpu->isar.id_isar1 = 0x02212000; | ||
305 | + cpu->isar.id_isar2 = 0x20232232; | ||
306 | + cpu->isar.id_isar3 = 0x01111131; | ||
307 | + cpu->isar.id_isar4 = 0x01310132; | ||
308 | + cpu->isar.id_isar5 = 0x00000000; | ||
309 | + cpu->isar.id_isar6 = 0x00000000; | ||
310 | cpu->clidr = 0x00000000; | ||
311 | cpu->ctr = 0x8000c000; | ||
312 | } | ||
313 | @@ -XXX,XX +XXX,XX @@ static void cortex_r5_initfn(Object *obj) | ||
314 | cpu->id_mmfr1 = 0x00000000; | ||
315 | cpu->id_mmfr2 = 0x01200000; | ||
316 | cpu->id_mmfr3 = 0x0211; | ||
317 | - cpu->id_isar0 = 0x02101111; | ||
318 | - cpu->id_isar1 = 0x13112111; | ||
319 | - cpu->id_isar2 = 0x21232141; | ||
320 | - cpu->id_isar3 = 0x01112131; | ||
321 | - cpu->id_isar4 = 0x0010142; | ||
322 | - cpu->id_isar5 = 0x0; | ||
323 | - cpu->id_isar6 = 0x0; | ||
324 | + cpu->isar.id_isar0 = 0x02101111; | ||
325 | + cpu->isar.id_isar1 = 0x13112111; | ||
326 | + cpu->isar.id_isar2 = 0x21232141; | ||
327 | + cpu->isar.id_isar3 = 0x01112131; | ||
328 | + cpu->isar.id_isar4 = 0x0010142; | ||
329 | + cpu->isar.id_isar5 = 0x0; | ||
330 | + cpu->isar.id_isar6 = 0x0; | ||
331 | cpu->mp_is_up = true; | ||
332 | cpu->pmsav7_dregion = 16; | ||
333 | define_arm_cp_regs(cpu, cortexr5_cp_reginfo); | ||
334 | @@ -XXX,XX +XXX,XX @@ static void cortex_a8_initfn(Object *obj) | ||
335 | set_feature(&cpu->env, ARM_FEATURE_EL3); | ||
336 | cpu->midr = 0x410fc080; | ||
337 | cpu->reset_fpsid = 0x410330c0; | ||
338 | - cpu->mvfr0 = 0x11110222; | ||
339 | - cpu->mvfr1 = 0x00011111; | ||
340 | + cpu->isar.mvfr0 = 0x11110222; | ||
341 | + cpu->isar.mvfr1 = 0x00011111; | ||
342 | cpu->ctr = 0x82048004; | ||
343 | cpu->reset_sctlr = 0x00c50078; | ||
344 | cpu->id_pfr0 = 0x1031; | ||
345 | @@ -XXX,XX +XXX,XX @@ static void cortex_a8_initfn(Object *obj) | ||
346 | cpu->id_mmfr1 = 0x20000000; | ||
347 | cpu->id_mmfr2 = 0x01202000; | ||
348 | cpu->id_mmfr3 = 0x11; | ||
349 | - cpu->id_isar0 = 0x00101111; | ||
350 | - cpu->id_isar1 = 0x12112111; | ||
351 | - cpu->id_isar2 = 0x21232031; | ||
352 | - cpu->id_isar3 = 0x11112131; | ||
353 | - cpu->id_isar4 = 0x00111142; | ||
354 | + cpu->isar.id_isar0 = 0x00101111; | ||
355 | + cpu->isar.id_isar1 = 0x12112111; | ||
356 | + cpu->isar.id_isar2 = 0x21232031; | ||
357 | + cpu->isar.id_isar3 = 0x11112131; | ||
358 | + cpu->isar.id_isar4 = 0x00111142; | ||
359 | cpu->dbgdidr = 0x15141000; | ||
360 | cpu->clidr = (1 << 27) | (2 << 24) | 3; | ||
361 | cpu->ccsidr[0] = 0xe007e01a; /* 16k L1 dcache. */ | ||
362 | @@ -XXX,XX +XXX,XX @@ static void cortex_a9_initfn(Object *obj) | ||
363 | set_feature(&cpu->env, ARM_FEATURE_CBAR); | ||
364 | cpu->midr = 0x410fc090; | ||
365 | cpu->reset_fpsid = 0x41033090; | ||
366 | - cpu->mvfr0 = 0x11110222; | ||
367 | - cpu->mvfr1 = 0x01111111; | ||
368 | + cpu->isar.mvfr0 = 0x11110222; | ||
369 | + cpu->isar.mvfr1 = 0x01111111; | ||
370 | cpu->ctr = 0x80038003; | ||
371 | cpu->reset_sctlr = 0x00c50078; | ||
372 | cpu->id_pfr0 = 0x1031; | ||
373 | @@ -XXX,XX +XXX,XX @@ static void cortex_a9_initfn(Object *obj) | ||
374 | cpu->id_mmfr1 = 0x20000000; | ||
375 | cpu->id_mmfr2 = 0x01230000; | ||
376 | cpu->id_mmfr3 = 0x00002111; | ||
377 | - cpu->id_isar0 = 0x00101111; | ||
378 | - cpu->id_isar1 = 0x13112111; | ||
379 | - cpu->id_isar2 = 0x21232041; | ||
380 | - cpu->id_isar3 = 0x11112131; | ||
381 | - cpu->id_isar4 = 0x00111142; | ||
382 | + cpu->isar.id_isar0 = 0x00101111; | ||
383 | + cpu->isar.id_isar1 = 0x13112111; | ||
384 | + cpu->isar.id_isar2 = 0x21232041; | ||
385 | + cpu->isar.id_isar3 = 0x11112131; | ||
386 | + cpu->isar.id_isar4 = 0x00111142; | ||
387 | cpu->dbgdidr = 0x35141000; | ||
388 | cpu->clidr = (1 << 27) | (1 << 24) | 3; | ||
389 | cpu->ccsidr[0] = 0xe00fe019; /* 16k L1 dcache. */ | ||
390 | @@ -XXX,XX +XXX,XX @@ static void cortex_a7_initfn(Object *obj) | ||
391 | cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A7; | ||
392 | cpu->midr = 0x410fc075; | ||
393 | cpu->reset_fpsid = 0x41023075; | ||
394 | - cpu->mvfr0 = 0x10110222; | ||
395 | - cpu->mvfr1 = 0x11111111; | ||
396 | + cpu->isar.mvfr0 = 0x10110222; | ||
397 | + cpu->isar.mvfr1 = 0x11111111; | ||
398 | cpu->ctr = 0x84448003; | ||
399 | cpu->reset_sctlr = 0x00c50078; | ||
400 | cpu->id_pfr0 = 0x00001131; | ||
401 | @@ -XXX,XX +XXX,XX @@ static void cortex_a7_initfn(Object *obj) | ||
402 | /* a7_mpcore_r0p5_trm, page 4-4 gives 0x01101110; but | ||
403 | * table 4-41 gives 0x02101110, which includes the arm div insns. | ||
404 | */ | ||
405 | - cpu->id_isar0 = 0x02101110; | ||
406 | - cpu->id_isar1 = 0x13112111; | ||
407 | - cpu->id_isar2 = 0x21232041; | ||
408 | - cpu->id_isar3 = 0x11112131; | ||
409 | - cpu->id_isar4 = 0x10011142; | ||
410 | + cpu->isar.id_isar0 = 0x02101110; | ||
411 | + cpu->isar.id_isar1 = 0x13112111; | ||
412 | + cpu->isar.id_isar2 = 0x21232041; | ||
413 | + cpu->isar.id_isar3 = 0x11112131; | ||
414 | + cpu->isar.id_isar4 = 0x10011142; | ||
415 | cpu->dbgdidr = 0x3515f005; | ||
416 | cpu->clidr = 0x0a200023; | ||
417 | cpu->ccsidr[0] = 0x701fe00a; /* 32K L1 dcache */ | ||
418 | @@ -XXX,XX +XXX,XX @@ static void cortex_a15_initfn(Object *obj) | ||
419 | cpu->kvm_target = QEMU_KVM_ARM_TARGET_CORTEX_A15; | ||
420 | cpu->midr = 0x412fc0f1; | ||
421 | cpu->reset_fpsid = 0x410430f0; | ||
422 | - cpu->mvfr0 = 0x10110222; | ||
423 | - cpu->mvfr1 = 0x11111111; | ||
424 | + cpu->isar.mvfr0 = 0x10110222; | ||
425 | + cpu->isar.mvfr1 = 0x11111111; | ||
426 | cpu->ctr = 0x8444c004; | ||
427 | cpu->reset_sctlr = 0x00c50078; | ||
428 | cpu->id_pfr0 = 0x00001131; | ||
429 | @@ -XXX,XX +XXX,XX @@ static void cortex_a15_initfn(Object *obj) | ||
430 | cpu->id_mmfr1 = 0x20000000; | ||
431 | cpu->id_mmfr2 = 0x01240000; | ||
432 | cpu->id_mmfr3 = 0x02102211; | ||
433 | - cpu->id_isar0 = 0x02101110; | ||
434 | - cpu->id_isar1 = 0x13112111; | ||
435 | - cpu->id_isar2 = 0x21232041; | ||
436 | - cpu->id_isar3 = 0x11112131; | ||
437 | - cpu->id_isar4 = 0x10011142; | ||
438 | + cpu->isar.id_isar0 = 0x02101110; | ||
439 | + cpu->isar.id_isar1 = 0x13112111; | ||
440 | + cpu->isar.id_isar2 = 0x21232041; | ||
441 | + cpu->isar.id_isar3 = 0x11112131; | ||
442 | + cpu->isar.id_isar4 = 0x10011142; | ||
443 | cpu->dbgdidr = 0x3515f021; | ||
444 | cpu->clidr = 0x0a200023; | ||
445 | cpu->ccsidr[0] = 0x701fe00a; /* 32K L1 dcache */ | ||
446 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | ||
447 | index XXXXXXX..XXXXXXX 100644 | ||
448 | --- a/target/arm/cpu64.c | ||
449 | +++ b/target/arm/cpu64.c | ||
450 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a57_initfn(Object *obj) | ||
451 | cpu->midr = 0x411fd070; | ||
452 | cpu->revidr = 0x00000000; | ||
453 | cpu->reset_fpsid = 0x41034070; | ||
454 | - cpu->mvfr0 = 0x10110222; | ||
455 | - cpu->mvfr1 = 0x12111111; | ||
456 | - cpu->mvfr2 = 0x00000043; | ||
457 | + cpu->isar.mvfr0 = 0x10110222; | ||
458 | + cpu->isar.mvfr1 = 0x12111111; | ||
459 | + cpu->isar.mvfr2 = 0x00000043; | ||
460 | cpu->ctr = 0x8444c004; | ||
461 | cpu->reset_sctlr = 0x00c50838; | ||
462 | cpu->id_pfr0 = 0x00000131; | ||
463 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a57_initfn(Object *obj) | ||
464 | cpu->id_mmfr1 = 0x40000000; | ||
465 | cpu->id_mmfr2 = 0x01260000; | ||
466 | cpu->id_mmfr3 = 0x02102211; | ||
467 | - cpu->id_isar0 = 0x02101110; | ||
468 | - cpu->id_isar1 = 0x13112111; | ||
469 | - cpu->id_isar2 = 0x21232042; | ||
470 | - cpu->id_isar3 = 0x01112131; | ||
471 | - cpu->id_isar4 = 0x00011142; | ||
472 | - cpu->id_isar5 = 0x00011121; | ||
473 | - cpu->id_isar6 = 0; | ||
474 | - cpu->id_aa64pfr0 = 0x00002222; | ||
475 | + cpu->isar.id_isar0 = 0x02101110; | ||
476 | + cpu->isar.id_isar1 = 0x13112111; | ||
477 | + cpu->isar.id_isar2 = 0x21232042; | ||
478 | + cpu->isar.id_isar3 = 0x01112131; | ||
479 | + cpu->isar.id_isar4 = 0x00011142; | ||
480 | + cpu->isar.id_isar5 = 0x00011121; | ||
481 | + cpu->isar.id_isar6 = 0; | ||
482 | + cpu->isar.id_aa64pfr0 = 0x00002222; | ||
483 | cpu->id_aa64dfr0 = 0x10305106; | ||
484 | cpu->pmceid0 = 0x00000000; | ||
485 | cpu->pmceid1 = 0x00000000; | ||
486 | - cpu->id_aa64isar0 = 0x00011120; | ||
487 | + cpu->isar.id_aa64isar0 = 0x00011120; | ||
488 | cpu->id_aa64mmfr0 = 0x00001124; | ||
489 | cpu->dbgdidr = 0x3516d000; | ||
490 | cpu->clidr = 0x0a200023; | ||
491 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a53_initfn(Object *obj) | ||
492 | cpu->midr = 0x410fd034; | ||
493 | cpu->revidr = 0x00000000; | ||
494 | cpu->reset_fpsid = 0x41034070; | ||
495 | - cpu->mvfr0 = 0x10110222; | ||
496 | - cpu->mvfr1 = 0x12111111; | ||
497 | - cpu->mvfr2 = 0x00000043; | ||
498 | + cpu->isar.mvfr0 = 0x10110222; | ||
499 | + cpu->isar.mvfr1 = 0x12111111; | ||
500 | + cpu->isar.mvfr2 = 0x00000043; | ||
501 | cpu->ctr = 0x84448004; /* L1Ip = VIPT */ | ||
502 | cpu->reset_sctlr = 0x00c50838; | ||
503 | cpu->id_pfr0 = 0x00000131; | ||
504 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a53_initfn(Object *obj) | ||
505 | cpu->id_mmfr1 = 0x40000000; | ||
506 | cpu->id_mmfr2 = 0x01260000; | ||
507 | cpu->id_mmfr3 = 0x02102211; | ||
508 | - cpu->id_isar0 = 0x02101110; | ||
509 | - cpu->id_isar1 = 0x13112111; | ||
510 | - cpu->id_isar2 = 0x21232042; | ||
511 | - cpu->id_isar3 = 0x01112131; | ||
512 | - cpu->id_isar4 = 0x00011142; | ||
513 | - cpu->id_isar5 = 0x00011121; | ||
514 | - cpu->id_isar6 = 0; | ||
515 | - cpu->id_aa64pfr0 = 0x00002222; | ||
516 | + cpu->isar.id_isar0 = 0x02101110; | ||
517 | + cpu->isar.id_isar1 = 0x13112111; | ||
518 | + cpu->isar.id_isar2 = 0x21232042; | ||
519 | + cpu->isar.id_isar3 = 0x01112131; | ||
520 | + cpu->isar.id_isar4 = 0x00011142; | ||
521 | + cpu->isar.id_isar5 = 0x00011121; | ||
522 | + cpu->isar.id_isar6 = 0; | ||
523 | + cpu->isar.id_aa64pfr0 = 0x00002222; | ||
524 | cpu->id_aa64dfr0 = 0x10305106; | ||
525 | - cpu->id_aa64isar0 = 0x00011120; | ||
526 | + cpu->isar.id_aa64isar0 = 0x00011120; | ||
527 | cpu->id_aa64mmfr0 = 0x00001122; /* 40 bit physical addr */ | ||
528 | cpu->dbgdidr = 0x3516d000; | ||
529 | cpu->clidr = 0x0a200023; | ||
530 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a72_initfn(Object *obj) | ||
531 | cpu->midr = 0x410fd083; | ||
532 | cpu->revidr = 0x00000000; | ||
533 | cpu->reset_fpsid = 0x41034080; | ||
534 | - cpu->mvfr0 = 0x10110222; | ||
535 | - cpu->mvfr1 = 0x12111111; | ||
536 | - cpu->mvfr2 = 0x00000043; | ||
537 | + cpu->isar.mvfr0 = 0x10110222; | ||
538 | + cpu->isar.mvfr1 = 0x12111111; | ||
539 | + cpu->isar.mvfr2 = 0x00000043; | ||
540 | cpu->ctr = 0x8444c004; | ||
541 | cpu->reset_sctlr = 0x00c50838; | ||
542 | cpu->id_pfr0 = 0x00000131; | ||
543 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a72_initfn(Object *obj) | ||
544 | cpu->id_mmfr1 = 0x40000000; | ||
545 | cpu->id_mmfr2 = 0x01260000; | ||
546 | cpu->id_mmfr3 = 0x02102211; | ||
547 | - cpu->id_isar0 = 0x02101110; | ||
548 | - cpu->id_isar1 = 0x13112111; | ||
549 | - cpu->id_isar2 = 0x21232042; | ||
550 | - cpu->id_isar3 = 0x01112131; | ||
551 | - cpu->id_isar4 = 0x00011142; | ||
552 | - cpu->id_isar5 = 0x00011121; | ||
553 | - cpu->id_aa64pfr0 = 0x00002222; | ||
554 | + cpu->isar.id_isar0 = 0x02101110; | ||
555 | + cpu->isar.id_isar1 = 0x13112111; | ||
556 | + cpu->isar.id_isar2 = 0x21232042; | ||
557 | + cpu->isar.id_isar3 = 0x01112131; | ||
558 | + cpu->isar.id_isar4 = 0x00011142; | ||
559 | + cpu->isar.id_isar5 = 0x00011121; | ||
560 | + cpu->isar.id_aa64pfr0 = 0x00002222; | ||
561 | cpu->id_aa64dfr0 = 0x10305106; | ||
562 | cpu->pmceid0 = 0x00000000; | ||
563 | cpu->pmceid1 = 0x00000000; | ||
564 | - cpu->id_aa64isar0 = 0x00011120; | ||
565 | + cpu->isar.id_aa64isar0 = 0x00011120; | ||
566 | cpu->id_aa64mmfr0 = 0x00001124; | ||
567 | cpu->dbgdidr = 0x3516d000; | ||
568 | cpu->clidr = 0x0a200023; | ||
569 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
570 | index XXXXXXX..XXXXXXX 100644 | ||
571 | --- a/target/arm/helper.c | ||
572 | +++ b/target/arm/helper.c | ||
573 | @@ -XXX,XX +XXX,XX @@ static uint64_t id_pfr1_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
574 | static uint64_t id_aa64pfr0_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
575 | { | ||
576 | ARMCPU *cpu = arm_env_get_cpu(env); | ||
577 | - uint64_t pfr0 = cpu->id_aa64pfr0; | ||
578 | + uint64_t pfr0 = cpu->isar.id_aa64pfr0; | ||
579 | |||
580 | if (env->gicv3state) { | ||
581 | pfr0 |= 1 << 24; | ||
582 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
583 | { .name = "ID_ISAR0", .state = ARM_CP_STATE_BOTH, | ||
584 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 0, | ||
585 | .access = PL1_R, .type = ARM_CP_CONST, | ||
586 | - .resetvalue = cpu->id_isar0 }, | ||
587 | + .resetvalue = cpu->isar.id_isar0 }, | ||
588 | { .name = "ID_ISAR1", .state = ARM_CP_STATE_BOTH, | ||
589 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 1, | ||
590 | .access = PL1_R, .type = ARM_CP_CONST, | ||
591 | - .resetvalue = cpu->id_isar1 }, | ||
592 | + .resetvalue = cpu->isar.id_isar1 }, | ||
593 | { .name = "ID_ISAR2", .state = ARM_CP_STATE_BOTH, | ||
594 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 2, | ||
595 | .access = PL1_R, .type = ARM_CP_CONST, | ||
596 | - .resetvalue = cpu->id_isar2 }, | ||
597 | + .resetvalue = cpu->isar.id_isar2 }, | ||
598 | { .name = "ID_ISAR3", .state = ARM_CP_STATE_BOTH, | ||
599 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 3, | ||
600 | .access = PL1_R, .type = ARM_CP_CONST, | ||
601 | - .resetvalue = cpu->id_isar3 }, | ||
602 | + .resetvalue = cpu->isar.id_isar3 }, | ||
603 | { .name = "ID_ISAR4", .state = ARM_CP_STATE_BOTH, | ||
604 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 4, | ||
605 | .access = PL1_R, .type = ARM_CP_CONST, | ||
606 | - .resetvalue = cpu->id_isar4 }, | ||
607 | + .resetvalue = cpu->isar.id_isar4 }, | ||
608 | { .name = "ID_ISAR5", .state = ARM_CP_STATE_BOTH, | ||
609 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 5, | ||
610 | .access = PL1_R, .type = ARM_CP_CONST, | ||
611 | - .resetvalue = cpu->id_isar5 }, | ||
612 | + .resetvalue = cpu->isar.id_isar5 }, | ||
613 | { .name = "ID_MMFR4", .state = ARM_CP_STATE_BOTH, | ||
614 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 6, | ||
615 | .access = PL1_R, .type = ARM_CP_CONST, | ||
616 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
617 | { .name = "ID_ISAR6", .state = ARM_CP_STATE_BOTH, | ||
618 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 7, | ||
619 | .access = PL1_R, .type = ARM_CP_CONST, | ||
620 | - .resetvalue = cpu->id_isar6 }, | ||
621 | + .resetvalue = cpu->isar.id_isar6 }, | ||
622 | REGINFO_SENTINEL | ||
623 | }; | ||
624 | define_arm_cp_regs(cpu, v6_idregs); | ||
625 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
626 | { .name = "ID_AA64PFR1_EL1", .state = ARM_CP_STATE_AA64, | ||
627 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 1, | ||
628 | .access = PL1_R, .type = ARM_CP_CONST, | ||
629 | - .resetvalue = cpu->id_aa64pfr1}, | ||
630 | + .resetvalue = cpu->isar.id_aa64pfr1}, | ||
631 | { .name = "ID_AA64PFR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, | ||
632 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 4, .opc2 = 2, | ||
633 | .access = PL1_R, .type = ARM_CP_CONST, | ||
634 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
635 | { .name = "ID_AA64ISAR0_EL1", .state = ARM_CP_STATE_AA64, | ||
636 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 0, | ||
637 | .access = PL1_R, .type = ARM_CP_CONST, | ||
638 | - .resetvalue = cpu->id_aa64isar0 }, | ||
639 | + .resetvalue = cpu->isar.id_aa64isar0 }, | ||
640 | { .name = "ID_AA64ISAR1_EL1", .state = ARM_CP_STATE_AA64, | ||
641 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 1, | ||
642 | .access = PL1_R, .type = ARM_CP_CONST, | ||
643 | - .resetvalue = cpu->id_aa64isar1 }, | ||
644 | + .resetvalue = cpu->isar.id_aa64isar1 }, | ||
645 | { .name = "ID_AA64ISAR2_EL1_RESERVED", .state = ARM_CP_STATE_AA64, | ||
646 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 6, .opc2 = 2, | ||
647 | .access = PL1_R, .type = ARM_CP_CONST, | ||
648 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
649 | { .name = "MVFR0_EL1", .state = ARM_CP_STATE_AA64, | ||
650 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 0, | ||
651 | .access = PL1_R, .type = ARM_CP_CONST, | ||
652 | - .resetvalue = cpu->mvfr0 }, | ||
653 | + .resetvalue = cpu->isar.mvfr0 }, | ||
654 | { .name = "MVFR1_EL1", .state = ARM_CP_STATE_AA64, | ||
655 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 1, | ||
656 | .access = PL1_R, .type = ARM_CP_CONST, | ||
657 | - .resetvalue = cpu->mvfr1 }, | ||
658 | + .resetvalue = cpu->isar.mvfr1 }, | ||
659 | { .name = "MVFR2_EL1", .state = ARM_CP_STATE_AA64, | ||
660 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 2, | ||
661 | .access = PL1_R, .type = ARM_CP_CONST, | ||
662 | - .resetvalue = cpu->mvfr2 }, | ||
663 | + .resetvalue = cpu->isar.mvfr2 }, | ||
664 | { .name = "MVFR3_EL1_RESERVED", .state = ARM_CP_STATE_AA64, | ||
665 | .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 3, | ||
666 | .access = PL1_R, .type = ARM_CP_CONST, | ||
667 | -- | 408 | -- |
668 | 2.19.1 | 409 | 2.20.1 |
669 | 410 | ||
670 | 411 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | Move expanders for VBSL, VBIT, and VBIF from translate-a64.c. | 3 | The CPRMAN PLLs generate a clock based on a prescaler, a multiplier and |
4 | a divider. The prescaler doubles the parent (xosc) frequency, then the | ||
5 | multiplier/divider are applied. The multiplier has an integer and a | ||
6 | fractional part. | ||
4 | 7 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | This commit also implements the CPRMAN CM_LOCK register. This register |
6 | Message-id: 20181011205206.3552-9-richard.henderson@linaro.org | 9 | reports which PLL is currently locked. We consider a PLL has being |
7 | 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> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 18 | --- |
10 | target/arm/translate.h | 6 ++ | 19 | include/hw/misc/bcm2835_cprman_internals.h | 8 +++ |
11 | target/arm/translate-a64.c | 61 -------------- | 20 | hw/misc/bcm2835_cprman.c | 64 +++++++++++++++++++++- |
12 | target/arm/translate.c | 162 +++++++++++++++++++++++++++---------- | 21 | 2 files changed, 71 insertions(+), 1 deletion(-) |
13 | 3 files changed, 124 insertions(+), 105 deletions(-) | ||
14 | 22 | ||
15 | diff --git a/target/arm/translate.h b/target/arm/translate.h | 23 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h |
16 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate.h | 25 | --- a/include/hw/misc/bcm2835_cprman_internals.h |
18 | +++ b/target/arm/translate.h | 26 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
19 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i32 get_ahp_flag(void) | 27 | @@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240) |
20 | return ret; | 28 | REG32(A2W_PLLH_FRAC, 0x1260) |
21 | } | 29 | REG32(A2W_PLLB_FRAC, 0x12e0) |
22 | 30 | ||
23 | + | 31 | +/* misc registers */ |
24 | +/* Vector operations shared between ARM and AArch64. */ | 32 | +REG32(CM_LOCK, 0x114) |
25 | +extern const GVecGen3 bsl_op; | 33 | + FIELD(CM_LOCK, FLOCKH, 12, 1) |
26 | +extern const GVecGen3 bit_op; | 34 | + FIELD(CM_LOCK, FLOCKD, 11, 1) |
27 | +extern const GVecGen3 bif_op; | 35 | + FIELD(CM_LOCK, FLOCKC, 10, 1) |
36 | + FIELD(CM_LOCK, FLOCKB, 9, 1) | ||
37 | + FIELD(CM_LOCK, FLOCKA, 8, 1) | ||
28 | + | 38 | + |
29 | /* | 39 | /* |
30 | * Forward to the isar_feature_* tests given a DisasContext pointer. | 40 | * This field is common to all registers. Each register write value must match |
31 | */ | 41 | * the CPRMAN_PASSWORD magic value in its 8 MSB. |
32 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 42 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c |
33 | index XXXXXXX..XXXXXXX 100644 | 43 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/target/arm/translate-a64.c | 44 | --- a/hw/misc/bcm2835_cprman.c |
35 | +++ b/target/arm/translate-a64.c | 45 | +++ b/hw/misc/bcm2835_cprman.c |
36 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_three_reg_diff(DisasContext *s, uint32_t insn) | 46 | @@ -XXX,XX +XXX,XX @@ |
37 | } | 47 | |
38 | } | 48 | /* PLL */ |
39 | 49 | ||
40 | -static void gen_bsl_i64(TCGv_i64 rd, TCGv_i64 rn, TCGv_i64 rm) | 50 | +static bool pll_is_locked(const CprmanPllState *pll) |
41 | -{ | ||
42 | - tcg_gen_xor_i64(rn, rn, rm); | ||
43 | - tcg_gen_and_i64(rn, rn, rd); | ||
44 | - tcg_gen_xor_i64(rd, rm, rn); | ||
45 | -} | ||
46 | - | ||
47 | -static void gen_bit_i64(TCGv_i64 rd, TCGv_i64 rn, TCGv_i64 rm) | ||
48 | -{ | ||
49 | - tcg_gen_xor_i64(rn, rn, rd); | ||
50 | - tcg_gen_and_i64(rn, rn, rm); | ||
51 | - tcg_gen_xor_i64(rd, rd, rn); | ||
52 | -} | ||
53 | - | ||
54 | -static void gen_bif_i64(TCGv_i64 rd, TCGv_i64 rn, TCGv_i64 rm) | ||
55 | -{ | ||
56 | - tcg_gen_xor_i64(rn, rn, rd); | ||
57 | - tcg_gen_andc_i64(rn, rn, rm); | ||
58 | - tcg_gen_xor_i64(rd, rd, rn); | ||
59 | -} | ||
60 | - | ||
61 | -static void gen_bsl_vec(unsigned vece, TCGv_vec rd, TCGv_vec rn, TCGv_vec rm) | ||
62 | -{ | ||
63 | - tcg_gen_xor_vec(vece, rn, rn, rm); | ||
64 | - tcg_gen_and_vec(vece, rn, rn, rd); | ||
65 | - tcg_gen_xor_vec(vece, rd, rm, rn); | ||
66 | -} | ||
67 | - | ||
68 | -static void gen_bit_vec(unsigned vece, TCGv_vec rd, TCGv_vec rn, TCGv_vec rm) | ||
69 | -{ | ||
70 | - tcg_gen_xor_vec(vece, rn, rn, rd); | ||
71 | - tcg_gen_and_vec(vece, rn, rn, rm); | ||
72 | - tcg_gen_xor_vec(vece, rd, rd, rn); | ||
73 | -} | ||
74 | - | ||
75 | -static void gen_bif_vec(unsigned vece, TCGv_vec rd, TCGv_vec rn, TCGv_vec rm) | ||
76 | -{ | ||
77 | - tcg_gen_xor_vec(vece, rn, rn, rd); | ||
78 | - tcg_gen_andc_vec(vece, rn, rn, rm); | ||
79 | - tcg_gen_xor_vec(vece, rd, rd, rn); | ||
80 | -} | ||
81 | - | ||
82 | /* Logic op (opcode == 3) subgroup of C3.6.16. */ | ||
83 | static void disas_simd_3same_logic(DisasContext *s, uint32_t insn) | ||
84 | { | ||
85 | - static const GVecGen3 bsl_op = { | ||
86 | - .fni8 = gen_bsl_i64, | ||
87 | - .fniv = gen_bsl_vec, | ||
88 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
89 | - .load_dest = true | ||
90 | - }; | ||
91 | - static const GVecGen3 bit_op = { | ||
92 | - .fni8 = gen_bit_i64, | ||
93 | - .fniv = gen_bit_vec, | ||
94 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
95 | - .load_dest = true | ||
96 | - }; | ||
97 | - static const GVecGen3 bif_op = { | ||
98 | - .fni8 = gen_bif_i64, | ||
99 | - .fniv = gen_bif_vec, | ||
100 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
101 | - .load_dest = true | ||
102 | - }; | ||
103 | - | ||
104 | int rd = extract32(insn, 0, 5); | ||
105 | int rn = extract32(insn, 5, 5); | ||
106 | int rm = extract32(insn, 16, 5); | ||
107 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/target/arm/translate.c | ||
110 | +++ b/target/arm/translate.c | ||
111 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | ||
112 | return 0; | ||
113 | } | ||
114 | |||
115 | -/* Bitwise select. dest = c ? t : f. Clobbers T and F. */ | ||
116 | -static void gen_neon_bsl(TCGv_i32 dest, TCGv_i32 t, TCGv_i32 f, TCGv_i32 c) | ||
117 | -{ | ||
118 | - tcg_gen_and_i32(t, t, c); | ||
119 | - tcg_gen_andc_i32(f, f, c); | ||
120 | - tcg_gen_or_i32(dest, t, f); | ||
121 | -} | ||
122 | - | ||
123 | static inline void gen_neon_narrow(int size, TCGv_i32 dest, TCGv_i64 src) | ||
124 | { | ||
125 | switch (size) { | ||
126 | @@ -XXX,XX +XXX,XX @@ static int do_v81_helper(DisasContext *s, gen_helper_gvec_3_ptr *fn, | ||
127 | return 1; | ||
128 | } | ||
129 | |||
130 | +/* | ||
131 | + * Expanders for VBitOps_VBIF, VBIT, VBSL. | ||
132 | + */ | ||
133 | +static void gen_bsl_i64(TCGv_i64 rd, TCGv_i64 rn, TCGv_i64 rm) | ||
134 | +{ | 51 | +{ |
135 | + tcg_gen_xor_i64(rn, rn, rm); | 52 | + return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN) |
136 | + tcg_gen_and_i64(rn, rn, rd); | 53 | + && !FIELD_EX32(*pll->reg_cm, CM_PLLx, ANARST); |
137 | + tcg_gen_xor_i64(rd, rm, rn); | ||
138 | +} | 54 | +} |
139 | + | 55 | + |
140 | +static void gen_bit_i64(TCGv_i64 rd, TCGv_i64 rn, TCGv_i64 rm) | 56 | static void pll_update(CprmanPllState *pll) |
57 | { | ||
58 | - clock_update(pll->out, 0); | ||
59 | + uint64_t freq, ndiv, fdiv, pdiv; | ||
60 | + | ||
61 | + if (!pll_is_locked(pll)) { | ||
62 | + clock_update(pll->out, 0); | ||
63 | + return; | ||
64 | + } | ||
65 | + | ||
66 | + pdiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PDIV); | ||
67 | + | ||
68 | + if (!pdiv) { | ||
69 | + clock_update(pll->out, 0); | ||
70 | + return; | ||
71 | + } | ||
72 | + | ||
73 | + ndiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, NDIV); | ||
74 | + fdiv = FIELD_EX32(*pll->reg_a2w_frac, A2W_PLLx_FRAC, FRAC); | ||
75 | + | ||
76 | + if (pll->reg_a2w_ana[1] & pll->prediv_mask) { | ||
77 | + /* The prescaler doubles the parent frequency */ | ||
78 | + ndiv *= 2; | ||
79 | + fdiv *= 2; | ||
80 | + } | ||
81 | + | ||
82 | + /* | ||
83 | + * We have a multiplier with an integer part (ndiv) and a fractional part | ||
84 | + * (fdiv), and a divider (pdiv). | ||
85 | + */ | ||
86 | + freq = clock_get_hz(pll->xosc_in) * | ||
87 | + ((ndiv << R_A2W_PLLx_FRAC_FRAC_LENGTH) + fdiv); | ||
88 | + freq /= pdiv; | ||
89 | + freq >>= R_A2W_PLLx_FRAC_FRAC_LENGTH; | ||
90 | + | ||
91 | + clock_update_hz(pll->out, freq); | ||
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) | ||
141 | +{ | 100 | +{ |
142 | + tcg_gen_xor_i64(rn, rn, rd); | 101 | + static const int CM_LOCK_MAPPING[CPRMAN_NUM_PLL] = { |
143 | + tcg_gen_and_i64(rn, rn, rm); | 102 | + [CPRMAN_PLLA] = R_CM_LOCK_FLOCKA_SHIFT, |
144 | + tcg_gen_xor_i64(rd, rd, rn); | 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; | ||
145 | +} | 117 | +} |
146 | + | 118 | + |
147 | +static void gen_bif_i64(TCGv_i64 rd, TCGv_i64 rn, TCGv_i64 rm) | 119 | static uint64_t cprman_read(void *opaque, hwaddr offset, |
148 | +{ | 120 | unsigned size) |
149 | + tcg_gen_xor_i64(rn, rn, rd); | 121 | { |
150 | + tcg_gen_andc_i64(rn, rn, rm); | 122 | @@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset, |
151 | + tcg_gen_xor_i64(rd, rd, rn); | 123 | size_t idx = offset / sizeof(uint32_t); |
152 | +} | 124 | |
125 | switch (idx) { | ||
126 | + case R_CM_LOCK: | ||
127 | + r = get_cm_lock(s); | ||
128 | + break; | ||
153 | + | 129 | + |
154 | +static void gen_bsl_vec(unsigned vece, TCGv_vec rd, TCGv_vec rn, TCGv_vec rm) | 130 | default: |
155 | +{ | 131 | r = s->regs[idx]; |
156 | + tcg_gen_xor_vec(vece, rn, rn, rm); | 132 | } |
157 | + tcg_gen_and_vec(vece, rn, rn, rd); | ||
158 | + tcg_gen_xor_vec(vece, rd, rm, rn); | ||
159 | +} | ||
160 | + | ||
161 | +static void gen_bit_vec(unsigned vece, TCGv_vec rd, TCGv_vec rn, TCGv_vec rm) | ||
162 | +{ | ||
163 | + tcg_gen_xor_vec(vece, rn, rn, rd); | ||
164 | + tcg_gen_and_vec(vece, rn, rn, rm); | ||
165 | + tcg_gen_xor_vec(vece, rd, rd, rn); | ||
166 | +} | ||
167 | + | ||
168 | +static void gen_bif_vec(unsigned vece, TCGv_vec rd, TCGv_vec rn, TCGv_vec rm) | ||
169 | +{ | ||
170 | + tcg_gen_xor_vec(vece, rn, rn, rd); | ||
171 | + tcg_gen_andc_vec(vece, rn, rn, rm); | ||
172 | + tcg_gen_xor_vec(vece, rd, rd, rn); | ||
173 | +} | ||
174 | + | ||
175 | +const GVecGen3 bsl_op = { | ||
176 | + .fni8 = gen_bsl_i64, | ||
177 | + .fniv = gen_bsl_vec, | ||
178 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
179 | + .load_dest = true | ||
180 | +}; | ||
181 | + | ||
182 | +const GVecGen3 bit_op = { | ||
183 | + .fni8 = gen_bit_i64, | ||
184 | + .fniv = gen_bit_vec, | ||
185 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
186 | + .load_dest = true | ||
187 | +}; | ||
188 | + | ||
189 | +const GVecGen3 bif_op = { | ||
190 | + .fni8 = gen_bif_i64, | ||
191 | + .fniv = gen_bif_vec, | ||
192 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
193 | + .load_dest = true | ||
194 | +}; | ||
195 | + | ||
196 | + | ||
197 | /* Translate a NEON data processing instruction. Return nonzero if the | ||
198 | instruction is invalid. | ||
199 | We process data in a mixture of 32-bit and 64-bit chunks. | ||
200 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
201 | { | ||
202 | int op; | ||
203 | int q; | ||
204 | - int rd, rn, rm; | ||
205 | + int rd, rn, rm, rd_ofs, rn_ofs, rm_ofs; | ||
206 | int size; | ||
207 | int shift; | ||
208 | int pass; | ||
209 | int count; | ||
210 | int pairwise; | ||
211 | int u; | ||
212 | + int vec_size; | ||
213 | uint32_t imm, mask; | ||
214 | TCGv_i32 tmp, tmp2, tmp3, tmp4, tmp5; | ||
215 | TCGv_ptr ptr1, ptr2, ptr3; | ||
216 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
217 | VFP_DREG_N(rn, insn); | ||
218 | VFP_DREG_M(rm, insn); | ||
219 | size = (insn >> 20) & 3; | ||
220 | + vec_size = q ? 16 : 8; | ||
221 | + rd_ofs = neon_reg_offset(rd, 0); | ||
222 | + rn_ofs = neon_reg_offset(rn, 0); | ||
223 | + rm_ofs = neon_reg_offset(rm, 0); | ||
224 | + | ||
225 | if ((insn & (1 << 23)) == 0) { | ||
226 | /* Three register same length. */ | ||
227 | op = ((insn >> 7) & 0x1e) | ((insn >> 4) & 1); | ||
228 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
229 | q, rd, rn, rm); | ||
230 | } | ||
231 | return 1; | ||
232 | + | ||
233 | + case NEON_3R_LOGIC: /* Logic ops. */ | ||
234 | + switch ((u << 2) | size) { | ||
235 | + case 0: /* VAND */ | ||
236 | + tcg_gen_gvec_and(0, rd_ofs, rn_ofs, rm_ofs, | ||
237 | + vec_size, vec_size); | ||
238 | + break; | ||
239 | + case 1: /* VBIC */ | ||
240 | + tcg_gen_gvec_andc(0, rd_ofs, rn_ofs, rm_ofs, | ||
241 | + vec_size, vec_size); | ||
242 | + break; | ||
243 | + case 2: | ||
244 | + if (rn == rm) { | ||
245 | + /* VMOV */ | ||
246 | + tcg_gen_gvec_mov(0, rd_ofs, rn_ofs, vec_size, vec_size); | ||
247 | + } else { | ||
248 | + /* VORR */ | ||
249 | + tcg_gen_gvec_or(0, rd_ofs, rn_ofs, rm_ofs, | ||
250 | + vec_size, vec_size); | ||
251 | + } | ||
252 | + break; | ||
253 | + case 3: /* VORN */ | ||
254 | + tcg_gen_gvec_orc(0, rd_ofs, rn_ofs, rm_ofs, | ||
255 | + vec_size, vec_size); | ||
256 | + break; | ||
257 | + case 4: /* VEOR */ | ||
258 | + tcg_gen_gvec_xor(0, rd_ofs, rn_ofs, rm_ofs, | ||
259 | + vec_size, vec_size); | ||
260 | + break; | ||
261 | + case 5: /* VBSL */ | ||
262 | + tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, | ||
263 | + vec_size, vec_size, &bsl_op); | ||
264 | + break; | ||
265 | + case 6: /* VBIT */ | ||
266 | + tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, | ||
267 | + vec_size, vec_size, &bit_op); | ||
268 | + break; | ||
269 | + case 7: /* VBIF */ | ||
270 | + tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, | ||
271 | + vec_size, vec_size, &bif_op); | ||
272 | + break; | ||
273 | + } | ||
274 | + return 0; | ||
275 | } | ||
276 | - if (size == 3 && op != NEON_3R_LOGIC) { | ||
277 | + if (size == 3) { | ||
278 | /* 64-bit element instructions. */ | ||
279 | for (pass = 0; pass < (q ? 2 : 1); pass++) { | ||
280 | neon_load_reg64(cpu_V0, rn + pass); | ||
281 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
282 | case NEON_3R_VRHADD: | ||
283 | GEN_NEON_INTEGER_OP(rhadd); | ||
284 | break; | ||
285 | - case NEON_3R_LOGIC: /* Logic ops. */ | ||
286 | - switch ((u << 2) | size) { | ||
287 | - case 0: /* VAND */ | ||
288 | - tcg_gen_and_i32(tmp, tmp, tmp2); | ||
289 | - break; | ||
290 | - case 1: /* BIC */ | ||
291 | - tcg_gen_andc_i32(tmp, tmp, tmp2); | ||
292 | - break; | ||
293 | - case 2: /* VORR */ | ||
294 | - tcg_gen_or_i32(tmp, tmp, tmp2); | ||
295 | - break; | ||
296 | - case 3: /* VORN */ | ||
297 | - tcg_gen_orc_i32(tmp, tmp, tmp2); | ||
298 | - break; | ||
299 | - case 4: /* VEOR */ | ||
300 | - tcg_gen_xor_i32(tmp, tmp, tmp2); | ||
301 | - break; | ||
302 | - case 5: /* VBSL */ | ||
303 | - tmp3 = neon_load_reg(rd, pass); | ||
304 | - gen_neon_bsl(tmp, tmp, tmp2, tmp3); | ||
305 | - tcg_temp_free_i32(tmp3); | ||
306 | - break; | ||
307 | - case 6: /* VBIT */ | ||
308 | - tmp3 = neon_load_reg(rd, pass); | ||
309 | - gen_neon_bsl(tmp, tmp, tmp3, tmp2); | ||
310 | - tcg_temp_free_i32(tmp3); | ||
311 | - break; | ||
312 | - case 7: /* VBIF */ | ||
313 | - tmp3 = neon_load_reg(rd, pass); | ||
314 | - gen_neon_bsl(tmp, tmp3, tmp, tmp2); | ||
315 | - tcg_temp_free_i32(tmp3); | ||
316 | - break; | ||
317 | - } | ||
318 | - break; | ||
319 | case NEON_3R_VHSUB: | ||
320 | GEN_NEON_INTEGER_OP(hsub); | ||
321 | break; | ||
322 | -- | 133 | -- |
323 | 2.19.1 | 134 | 2.20.1 |
324 | 135 | ||
325 | 136 | diff view generated by jsdifflib |
1 | For AArch32, exception return happens through certain kinds | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | of CPSR write. We don't currently have any CPU_LOG_INT logging | 2 | |
3 | of these events (unlike AArch64, where we log in the ERET | 3 | PLLs are composed of multiple channels. Each channel outputs one clock |
4 | instruction). Add some suitable logging. | 4 | signal. They are modeled as one device taking the PLL generated clock as |
5 | 5 | input, and outputting a new clock. | |
6 | This will log exception returns like this: | 6 | |
7 | Exception return from AArch32 hyp to usr PC 0x80100374 | 7 | A channel shares the CM register with its parent PLL, and has its own |
8 | 8 | A2W_CTRL register. A write to the CM register will trigger an update of | |
9 | paralleling the existing logging in the exception_return | 9 | the PLL and all its channels, while a write to an A2W_CTRL channel |
10 | helper for AArch64 exception returns: | 10 | register will update the required channel only. |
11 | Exception return from AArch64 EL2 to AArch64 EL0 PC 0x8003045c | 11 | |
12 | Exception return from AArch64 EL2 to AArch32 EL0 PC 0x8003045c | 12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
13 | 13 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | |
14 | (Note that an AArch32 exception return can only be | 14 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
15 | AArch32->AArch32, never to AArch64.) | 15 | Tested-by: Guenter Roeck <linux@roeck-us.net> |
16 | |||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
19 | Message-id: 20181012144235.19646-2-peter.maydell@linaro.org | ||
20 | --- | 17 | --- |
21 | target/arm/internals.h | 18 ++++++++++++++++++ | 18 | include/hw/misc/bcm2835_cprman.h | 44 ++++++ |
22 | target/arm/helper.c | 10 ++++++++++ | 19 | include/hw/misc/bcm2835_cprman_internals.h | 146 +++++++++++++++++++ |
23 | target/arm/translate.c | 7 +------ | 20 | hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++-- |
24 | 3 files changed, 29 insertions(+), 6 deletions(-) | 21 | 3 files changed, 337 insertions(+), 8 deletions(-) |
25 | 22 | ||
26 | diff --git a/target/arm/internals.h b/target/arm/internals.h | 23 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h |
27 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/target/arm/internals.h | 25 | --- a/include/hw/misc/bcm2835_cprman.h |
29 | +++ b/target/arm/internals.h | 26 | +++ b/include/hw/misc/bcm2835_cprman.h |
30 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t v7m_sp_limit(CPUARMState *env) | 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; | ||
31 | } | 429 | } |
32 | } | 430 | } |
33 | 431 | ||
34 | +/** | 432 | -#undef CASE_PLL_REGS |
35 | + * aarch32_mode_name(): Return name of the AArch32 CPU mode | 433 | +#undef CASE_PLL_A2W_REGS |
36 | + * @psr: Program Status Register indicating CPU mode | 434 | |
37 | + * | 435 | static const MemoryRegionOps cprman_ops = { |
38 | + * Returns, for debug logging purposes, a printable representation | 436 | .read = cprman_read, |
39 | + * of the AArch32 CPU mode ("svc", "usr", etc) as indicated by | 437 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) |
40 | + * the low bits of the specified PSR. | 438 | device_cold_reset(DEVICE(&s->plls[i])); |
41 | + */ | 439 | } |
42 | +static inline const char *aarch32_mode_name(uint32_t psr) | 440 | |
43 | +{ | 441 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { |
44 | + static const char cpu_mode_names[16][4] = { | 442 | + device_cold_reset(DEVICE(&s->channels[i])); |
45 | + "usr", "fiq", "irq", "svc", "???", "???", "mon", "abt", | 443 | + } |
46 | + "???", "???", "hyp", "und", "???", "???", "???", "sys" | 444 | + |
47 | + }; | 445 | clock_update_hz(s->xosc, s->xosc_freq); |
48 | + | 446 | } |
49 | + return cpu_mode_names[psr & 0xf]; | 447 | |
50 | +} | 448 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) |
51 | + | 449 | set_pll_init_info(s, &s->plls[i], i); |
52 | #endif | 450 | } |
53 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 451 | |
54 | index XXXXXXX..XXXXXXX 100644 | 452 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { |
55 | --- a/target/arm/helper.c | 453 | + object_initialize_child(obj, PLL_CHANNEL_INIT_INFO[i].name, |
56 | +++ b/target/arm/helper.c | 454 | + &s->channels[i], |
57 | @@ -XXX,XX +XXX,XX @@ void cpsr_write(CPUARMState *env, uint32_t val, uint32_t mask, | 455 | + TYPE_CPRMAN_PLL_CHANNEL); |
58 | mask |= CPSR_IL; | 456 | + set_pll_channel_init_info(s, &s->channels[i], i); |
59 | val |= CPSR_IL; | 457 | + } |
60 | } | 458 | + |
61 | + qemu_log_mask(LOG_GUEST_ERROR, | 459 | s->xosc = clock_new(obj, "xosc"); |
62 | + "Illegal AArch32 mode switch attempt from %s to %s\n", | 460 | |
63 | + aarch32_mode_name(env->uncached_cpsr), | 461 | memory_region_init_io(&s->iomem, obj, &cprman_ops, |
64 | + aarch32_mode_name(val)); | 462 | @@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp) |
65 | } else { | 463 | return; |
66 | + qemu_log_mask(CPU_LOG_INT, "%s %s to %s PC 0x%" PRIx32 "\n", | ||
67 | + write_type == CPSRWriteExceptionReturn ? | ||
68 | + "Exception return from AArch32" : | ||
69 | + "AArch32 mode switch from", | ||
70 | + aarch32_mode_name(env->uncached_cpsr), | ||
71 | + aarch32_mode_name(val), env->regs[15]); | ||
72 | switch_mode(env, val & CPSR_M); | ||
73 | } | 464 | } |
74 | } | 465 | } |
75 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 466 | + |
76 | index XXXXXXX..XXXXXXX 100644 | 467 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { |
77 | --- a/target/arm/translate.c | 468 | + CprmanPllChannelState *channel = &s->channels[i]; |
78 | +++ b/target/arm/translate.c | 469 | + CprmanPll parent = PLL_CHANNEL_INIT_INFO[i].parent; |
79 | @@ -XXX,XX +XXX,XX @@ void gen_intermediate_code(CPUState *cpu, TranslationBlock *tb) | 470 | + Clock *parent_clk = s->plls[parent].out; |
80 | translator_loop(ops, &dc.base, cpu, tb); | 471 | + |
81 | } | 472 | + clock_set_source(channel->pll_in, parent_clk); |
82 | 473 | + | |
83 | -static const char *cpu_mode_names[16] = { | 474 | + if (!qdev_realize(DEVICE(channel), NULL, errp)) { |
84 | - "usr", "fiq", "irq", "svc", "???", "???", "mon", "abt", | 475 | + return; |
85 | - "???", "???", "hyp", "und", "???", "???", "???", "sys" | 476 | + } |
86 | -}; | 477 | + } |
87 | - | 478 | } |
88 | void arm_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, | 479 | |
89 | int flags) | 480 | static const VMStateDescription cprman_vmstate = { |
481 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) | ||
90 | { | 482 | { |
91 | @@ -XXX,XX +XXX,XX @@ void arm_cpu_dump_state(CPUState *cs, FILE *f, fprintf_function cpu_fprintf, | 483 | type_register_static(&cprman_info); |
92 | psr & CPSR_V ? 'V' : '-', | 484 | type_register_static(&cprman_pll_info); |
93 | psr & CPSR_T ? 'T' : 'A', | 485 | + type_register_static(&cprman_pll_channel_info); |
94 | ns_status, | 486 | } |
95 | - cpu_mode_names[psr & 0xf], (psr & 0x10) ? 32 : 26); | 487 | |
96 | + aarch32_mode_name(psr), (psr & 0x10) ? 32 : 26); | 488 | type_init(cprman_register_types); |
97 | } | ||
98 | |||
99 | if (flags & CPU_DUMP_FPU) { | ||
100 | -- | 489 | -- |
101 | 2.19.1 | 490 | 2.20.1 |
102 | 491 | ||
103 | 492 | diff view generated by jsdifflib |
1 | For traps of FP/SIMD instructions to AArch32 Hyp mode, the syndrome | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | provided in HSR has more information than is reported to AArch64. | ||
3 | Specifically, there are extra fields TA and coproc which indicate | ||
4 | whether the trapped instruction was FP or SIMD. Add this extra | ||
5 | information to the syndromes we construct, and mask it out when | ||
6 | taking the exception to AArch64. | ||
7 | 2 | ||
3 | A PLL channel is able to further divide the generated PLL frequency. | ||
4 | The divider is given in the CTRL_A2W register. Some channels have an | ||
5 | additional fixed divider which is always applied to the signal. | ||
6 | |||
7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
10 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20181012144235.19646-11-peter.maydell@linaro.org | ||
11 | --- | 12 | --- |
12 | target/arm/internals.h | 14 +++++++++++++- | 13 | hw/misc/bcm2835_cprman.c | 33 ++++++++++++++++++++++++++++++++- |
13 | target/arm/helper.c | 9 +++++++++ | 14 | 1 file changed, 32 insertions(+), 1 deletion(-) |
14 | target/arm/translate.c | 8 ++++---- | ||
15 | 3 files changed, 26 insertions(+), 5 deletions(-) | ||
16 | 15 | ||
17 | diff --git a/target/arm/internals.h b/target/arm/internals.h | 16 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c |
18 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/arm/internals.h | 18 | --- a/hw/misc/bcm2835_cprman.c |
20 | +++ b/target/arm/internals.h | 19 | +++ b/hw/misc/bcm2835_cprman.c |
21 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t syn_get_ec(uint32_t syn) | 20 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { |
22 | * few cases the value in HSR for exceptions taken to AArch32 Hyp | 21 | |
23 | * mode differs slightly, and we fix this up when populating HSR in | 22 | /* PLL channel */ |
24 | * arm_cpu_do_interrupt_aarch32_hyp(). | 23 | |
25 | + * The exception is FP/SIMD access traps -- these report extra information | 24 | +static bool pll_channel_is_enabled(CprmanPllChannelState *channel) |
26 | + * when taking an exception to AArch32. For those we include the extra coproc | 25 | +{ |
27 | + * and TA fields, and mask them out when taking the exception to AArch64. | 26 | + /* |
28 | */ | 27 | + * XXX I'm not sure of the purpose of the LOAD field. The Linux driver does |
29 | static inline uint32_t syn_uncategorized(void) | 28 | + * not set it when enabling the channel, but does clear it when disabling |
30 | { | 29 | + * it. |
31 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t syn_cp15_rrt_trap(int cv, int cond, int opc1, int crm, | 30 | + */ |
32 | 31 | + return !FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DISABLE) | |
33 | static inline uint32_t syn_fp_access_trap(int cv, int cond, bool is_16bit) | 32 | + && !(*channel->reg_cm & channel->hold_mask); |
34 | { | ||
35 | + /* AArch32 FP trap or any AArch64 FP/SIMD trap: TA == 0 coproc == 0xa */ | ||
36 | return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT) | ||
37 | | (is_16bit ? 0 : ARM_EL_IL) | ||
38 | - | (cv << 24) | (cond << 20); | ||
39 | + | (cv << 24) | (cond << 20) | 0xa; | ||
40 | +} | 33 | +} |
41 | + | 34 | + |
42 | +static inline uint32_t syn_simd_access_trap(int cv, int cond, bool is_16bit) | 35 | static void pll_channel_update(CprmanPllChannelState *channel) |
43 | +{ | 36 | { |
44 | + /* AArch32 SIMD trap: TA == 1 coproc == 0 */ | 37 | - clock_update(channel->out, 0); |
45 | + return (EC_ADVSIMDFPACCESSTRAP << ARM_EL_EC_SHIFT) | 38 | + uint64_t freq, div; |
46 | + | (is_16bit ? 0 : ARM_EL_IL) | 39 | + |
47 | + | (cv << 24) | (cond << 20) | (1 << 5); | 40 | + if (!pll_channel_is_enabled(channel)) { |
41 | + clock_update(channel->out, 0); | ||
42 | + return; | ||
43 | + } | ||
44 | + | ||
45 | + div = FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DIV); | ||
46 | + | ||
47 | + if (!div) { | ||
48 | + /* | ||
49 | + * It seems that when the divider value is 0, it is considered as | ||
50 | + * being maximum by the hardware (see the Linux driver). | ||
51 | + */ | ||
52 | + div = R_A2W_PLLx_CHANNELy_DIV_MASK; | ||
53 | + } | ||
54 | + | ||
55 | + /* Some channels have an additional fixed divider */ | ||
56 | + freq = clock_get_hz(channel->pll_in) / (div * channel->fixed_divider); | ||
57 | + | ||
58 | + clock_update_hz(channel->out, freq); | ||
48 | } | 59 | } |
49 | 60 | ||
50 | static inline uint32_t syn_sve_access_trap(void) | 61 | /* Update a PLL and all its channels */ |
51 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/arm/helper.c | ||
54 | +++ b/target/arm/helper.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch64(CPUState *cs) | ||
56 | case EXCP_HVC: | ||
57 | case EXCP_HYP_TRAP: | ||
58 | case EXCP_SMC: | ||
59 | + if (syn_get_ec(env->exception.syndrome) == EC_ADVSIMDFPACCESSTRAP) { | ||
60 | + /* | ||
61 | + * QEMU internal FP/SIMD syndromes from AArch32 include the | ||
62 | + * TA and coproc fields which are only exposed if the exception | ||
63 | + * is taken to AArch32 Hyp mode. Mask them out to get a valid | ||
64 | + * AArch64 format syndrome. | ||
65 | + */ | ||
66 | + env->exception.syndrome &= ~MAKE_64BIT_MASK(0, 20); | ||
67 | + } | ||
68 | env->cp15.esr_el[new_el] = env->exception.syndrome; | ||
69 | break; | ||
70 | case EXCP_IRQ: | ||
71 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
72 | index XXXXXXX..XXXXXXX 100644 | ||
73 | --- a/target/arm/translate.c | ||
74 | +++ b/target/arm/translate.c | ||
75 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_ls_insn(DisasContext *s, uint32_t insn) | ||
76 | */ | ||
77 | if (s->fp_excp_el) { | ||
78 | gen_exception_insn(s, 4, EXCP_UDEF, | ||
79 | - syn_fp_access_trap(1, 0xe, false), s->fp_excp_el); | ||
80 | + syn_simd_access_trap(1, 0xe, false), s->fp_excp_el); | ||
81 | return 0; | ||
82 | } | ||
83 | |||
84 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
85 | */ | ||
86 | if (s->fp_excp_el) { | ||
87 | gen_exception_insn(s, 4, EXCP_UDEF, | ||
88 | - syn_fp_access_trap(1, 0xe, false), s->fp_excp_el); | ||
89 | + syn_simd_access_trap(1, 0xe, false), s->fp_excp_el); | ||
90 | return 0; | ||
91 | } | ||
92 | |||
93 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_3same_ext(DisasContext *s, uint32_t insn) | ||
94 | |||
95 | if (s->fp_excp_el) { | ||
96 | gen_exception_insn(s, 4, EXCP_UDEF, | ||
97 | - syn_fp_access_trap(1, 0xe, false), s->fp_excp_el); | ||
98 | + syn_simd_access_trap(1, 0xe, false), s->fp_excp_el); | ||
99 | return 0; | ||
100 | } | ||
101 | if (!s->vfp_enabled) { | ||
102 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_insn_2reg_scalar_ext(DisasContext *s, uint32_t insn) | ||
103 | |||
104 | if (s->fp_excp_el) { | ||
105 | gen_exception_insn(s, 4, EXCP_UDEF, | ||
106 | - syn_fp_access_trap(1, 0xe, false), s->fp_excp_el); | ||
107 | + syn_simd_access_trap(1, 0xe, false), s->fp_excp_el); | ||
108 | return 0; | ||
109 | } | ||
110 | if (!s->vfp_enabled) { | ||
111 | -- | 62 | -- |
112 | 2.19.1 | 63 | 2.20.1 |
113 | 64 | ||
114 | 65 | diff view generated by jsdifflib |
1 | The HCR.FB virtualization configuration register bit requests that | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | TLB maintenance, branch predictor invalidate-all and icache | 2 | |
3 | invalidate-all operations performed in NS EL1 should be upgraded | 3 | The clock multiplexers are the last clock stage in the CPRMAN. Each mux |
4 | from "local CPU only to "broadcast within Inner Shareable domain". | 4 | outputs one clock signal that goes out of the CPRMAN to the SoC |
5 | For QEMU we NOP the branch predictor and icache operations, so | 5 | peripherals. |
6 | we only need to upgrade the TLB invalidates: | 6 | |
7 | AArch32 TLBIALL, TLBIMVA, TLBIASID, DTLBIALL, DTLBIMVA, DTLBIASID, | 7 | Each mux has at most 10 sources. The sources 0 to 3 are common to all |
8 | ITLBIALL, ITLBIMVA, ITLBIASID, TLBIMVAA, TLBIMVAL, TLBIMVAAL | 8 | muxes. They are: |
9 | AArch64 TLBI VMALLE1, TLBI VAE1, TLBI ASIDE1, TLBI VAAE1, | 9 | 0. ground (no clock signal) |
10 | TLBI VALE1, TLBI VAALE1 | 10 | 1. the main oscillator (xosc) |
11 | 11 | 2. "test debug 0" clock | |
12 | 3. "test debug 1" clock | ||
13 | |||
14 | Test debug 0 and 1 are actual clock muxes that can be used as sources to | ||
15 | other muxes (for debug purpose). | ||
16 | |||
17 | Sources 4 to 9 are mux specific and can be unpopulated (grounded). Those | ||
18 | sources are fed by the PLL channels outputs. | ||
19 | |||
20 | One corner case exists for DSI0E and DSI0P muxes. They have their source | ||
21 | number 4 connected to an intermediate multiplexer that can select | ||
22 | between PLLA-DSI0 and PLLD-DSI0 channel. This multiplexer is called | ||
23 | DSI0HSCK and is not a clock mux as such. It is really a simple mux from | ||
24 | the hardware point of view (see https://elinux.org/The_Undocumented_Pi). | ||
25 | This mux is not implemented in this commit. | ||
26 | |||
27 | Note that there is some muxes for which sources are unknown (because of | ||
28 | a lack of documentation). For those cases all the sources are connected | ||
29 | to ground in this implementation. | ||
30 | |||
31 | Each clock mux output is exported by the CPRMAN at the qdev level, | ||
32 | adding the suffix '-out' to the mux name to form the output clock name. | ||
33 | (E.g. the 'uart' mux sees its output exported as 'uart-out' at the | ||
34 | CPRMAN level.) | ||
35 | |||
36 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
37 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
38 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
39 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 40 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 20181012144235.19646-4-peter.maydell@linaro.org | ||
15 | --- | 41 | --- |
16 | target/arm/helper.c | 191 +++++++++++++++++++++++++++----------------- | 42 | include/hw/misc/bcm2835_cprman.h | 85 +++++ |
17 | 1 file changed, 116 insertions(+), 75 deletions(-) | 43 | include/hw/misc/bcm2835_cprman_internals.h | 422 +++++++++++++++++++++ |
18 | 44 | hw/misc/bcm2835_cprman.c | 151 ++++++++ | |
19 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 45 | 3 files changed, 658 insertions(+) |
46 | |||
47 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/helper.c | 49 | --- a/include/hw/misc/bcm2835_cprman.h |
22 | +++ b/target/arm/helper.c | 50 | +++ b/include/hw/misc/bcm2835_cprman.h |
23 | @@ -XXX,XX +XXX,XX @@ static void contextidr_write(CPUARMState *env, const ARMCPRegInfo *ri, | 51 | @@ -XXX,XX +XXX,XX @@ typedef enum CprmanPllChannel { |
24 | raw_write(env, ri, value); | 52 | CPRMAN_PLLB_CHANNEL_ARM, |
53 | |||
54 | CPRMAN_NUM_PLL_CHANNEL, | ||
55 | + | ||
56 | + /* Special values used when connecting clock sources to clocks */ | ||
57 | + CPRMAN_CLOCK_SRC_NORMAL = -1, | ||
58 | + CPRMAN_CLOCK_SRC_FORCE_GROUND = -2, | ||
59 | + CPRMAN_CLOCK_SRC_DSI0HSCK = -3, | ||
60 | } CprmanPllChannel; | ||
61 | |||
62 | +typedef enum CprmanClockMux { | ||
63 | + CPRMAN_CLOCK_GNRIC, | ||
64 | + CPRMAN_CLOCK_VPU, | ||
65 | + CPRMAN_CLOCK_SYS, | ||
66 | + CPRMAN_CLOCK_PERIA, | ||
67 | + CPRMAN_CLOCK_PERII, | ||
68 | + CPRMAN_CLOCK_H264, | ||
69 | + CPRMAN_CLOCK_ISP, | ||
70 | + CPRMAN_CLOCK_V3D, | ||
71 | + CPRMAN_CLOCK_CAM0, | ||
72 | + CPRMAN_CLOCK_CAM1, | ||
73 | + CPRMAN_CLOCK_CCP2, | ||
74 | + CPRMAN_CLOCK_DSI0E, | ||
75 | + CPRMAN_CLOCK_DSI0P, | ||
76 | + CPRMAN_CLOCK_DPI, | ||
77 | + CPRMAN_CLOCK_GP0, | ||
78 | + CPRMAN_CLOCK_GP1, | ||
79 | + CPRMAN_CLOCK_GP2, | ||
80 | + CPRMAN_CLOCK_HSM, | ||
81 | + CPRMAN_CLOCK_OTP, | ||
82 | + CPRMAN_CLOCK_PCM, | ||
83 | + CPRMAN_CLOCK_PWM, | ||
84 | + CPRMAN_CLOCK_SLIM, | ||
85 | + CPRMAN_CLOCK_SMI, | ||
86 | + CPRMAN_CLOCK_TEC, | ||
87 | + CPRMAN_CLOCK_TD0, | ||
88 | + CPRMAN_CLOCK_TD1, | ||
89 | + CPRMAN_CLOCK_TSENS, | ||
90 | + CPRMAN_CLOCK_TIMER, | ||
91 | + CPRMAN_CLOCK_UART, | ||
92 | + CPRMAN_CLOCK_VEC, | ||
93 | + CPRMAN_CLOCK_PULSE, | ||
94 | + CPRMAN_CLOCK_SDC, | ||
95 | + CPRMAN_CLOCK_ARM, | ||
96 | + CPRMAN_CLOCK_AVEO, | ||
97 | + CPRMAN_CLOCK_EMMC, | ||
98 | + CPRMAN_CLOCK_EMMC2, | ||
99 | + | ||
100 | + CPRMAN_NUM_CLOCK_MUX | ||
101 | +} CprmanClockMux; | ||
102 | + | ||
103 | +typedef enum CprmanClockMuxSource { | ||
104 | + CPRMAN_CLOCK_SRC_GND = 0, | ||
105 | + CPRMAN_CLOCK_SRC_XOSC, | ||
106 | + CPRMAN_CLOCK_SRC_TD0, | ||
107 | + CPRMAN_CLOCK_SRC_TD1, | ||
108 | + CPRMAN_CLOCK_SRC_PLLA, | ||
109 | + CPRMAN_CLOCK_SRC_PLLC, | ||
110 | + CPRMAN_CLOCK_SRC_PLLD, | ||
111 | + CPRMAN_CLOCK_SRC_PLLH, | ||
112 | + CPRMAN_CLOCK_SRC_PLLC_CORE1, | ||
113 | + CPRMAN_CLOCK_SRC_PLLC_CORE2, | ||
114 | + | ||
115 | + CPRMAN_NUM_CLOCK_MUX_SRC | ||
116 | +} CprmanClockMuxSource; | ||
117 | + | ||
118 | typedef struct CprmanPllState { | ||
119 | /*< private >*/ | ||
120 | DeviceState parent_obj; | ||
121 | @@ -XXX,XX +XXX,XX @@ typedef struct CprmanPllChannelState { | ||
122 | Clock *out; | ||
123 | } CprmanPllChannelState; | ||
124 | |||
125 | +typedef struct CprmanClockMuxState { | ||
126 | + /*< private >*/ | ||
127 | + DeviceState parent_obj; | ||
128 | + | ||
129 | + /*< public >*/ | ||
130 | + CprmanClockMux id; | ||
131 | + | ||
132 | + uint32_t *reg_ctl; | ||
133 | + uint32_t *reg_div; | ||
134 | + int int_bits; | ||
135 | + int frac_bits; | ||
136 | + | ||
137 | + Clock *srcs[CPRMAN_NUM_CLOCK_MUX_SRC]; | ||
138 | + Clock *out; | ||
139 | + | ||
140 | + /* | ||
141 | + * Used by clock srcs update callback to retrieve both the clock and the | ||
142 | + * source number. | ||
143 | + */ | ||
144 | + struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC]; | ||
145 | +} CprmanClockMuxState; | ||
146 | + | ||
147 | struct BCM2835CprmanState { | ||
148 | /*< private >*/ | ||
149 | SysBusDevice parent_obj; | ||
150 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | ||
151 | |||
152 | CprmanPllState plls[CPRMAN_NUM_PLL]; | ||
153 | CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL]; | ||
154 | + CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX]; | ||
155 | |||
156 | uint32_t regs[CPRMAN_NUM_REGS]; | ||
157 | uint32_t xosc_freq; | ||
158 | |||
159 | Clock *xosc; | ||
160 | + Clock *gnd; | ||
161 | }; | ||
162 | |||
163 | #endif | ||
164 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
165 | index XXXXXXX..XXXXXXX 100644 | ||
166 | --- a/include/hw/misc/bcm2835_cprman_internals.h | ||
167 | +++ b/include/hw/misc/bcm2835_cprman_internals.h | ||
168 | @@ -XXX,XX +XXX,XX @@ | ||
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; | ||
25 | } | 276 | } |
26 | 277 | ||
27 | -static void tlbiall_write(CPUARMState *env, const ARMCPRegInfo *ri, | 278 | +/* Clock mux init info */ |
28 | - uint64_t value) | 279 | +typedef struct ClockMuxInitInfo { |
29 | -{ | 280 | + const char *name; |
30 | - /* Invalidate all (TLBIALL) */ | 281 | + size_t cm_offset; /* cm_offset[0]->CM_CTL, cm_offset[1]->CM_DIV */ |
31 | - ARMCPU *cpu = arm_env_get_cpu(env); | 282 | + int int_bits; |
32 | - | 283 | + int frac_bits; |
33 | - tlb_flush(CPU(cpu)); | 284 | + |
34 | -} | 285 | + CprmanPllChannel src_mapping[CPRMAN_NUM_CLOCK_MUX_SRC]; |
35 | - | 286 | +} ClockMuxInitInfo; |
36 | -static void tlbimva_write(CPUARMState *env, const ARMCPRegInfo *ri, | 287 | + |
37 | - uint64_t value) | ||
38 | -{ | ||
39 | - /* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */ | ||
40 | - ARMCPU *cpu = arm_env_get_cpu(env); | ||
41 | - | ||
42 | - tlb_flush_page(CPU(cpu), value & TARGET_PAGE_MASK); | ||
43 | -} | ||
44 | - | ||
45 | -static void tlbiasid_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
46 | - uint64_t value) | ||
47 | -{ | ||
48 | - /* Invalidate by ASID (TLBIASID) */ | ||
49 | - ARMCPU *cpu = arm_env_get_cpu(env); | ||
50 | - | ||
51 | - tlb_flush(CPU(cpu)); | ||
52 | -} | ||
53 | - | ||
54 | -static void tlbimvaa_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
55 | - uint64_t value) | ||
56 | -{ | ||
57 | - /* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */ | ||
58 | - ARMCPU *cpu = arm_env_get_cpu(env); | ||
59 | - | ||
60 | - tlb_flush_page(CPU(cpu), value & TARGET_PAGE_MASK); | ||
61 | -} | ||
62 | - | ||
63 | /* IS variants of TLB operations must affect all cores */ | ||
64 | static void tlbiall_is_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
65 | uint64_t value) | ||
66 | @@ -XXX,XX +XXX,XX @@ static void tlbimvaa_is_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
67 | tlb_flush_page_all_cpus_synced(cs, value & TARGET_PAGE_MASK); | ||
68 | } | ||
69 | |||
70 | +/* | 288 | +/* |
71 | + * Non-IS variants of TLB operations are upgraded to | 289 | + * Each clock mux can have up to 10 sources. Sources 0 to 3 are always the |
72 | + * IS versions if we are at NS EL1 and HCR_EL2.FB is set to | 290 | + * same (ground, xosc, td0, td1). Sources 4 to 9 are mux specific, and are not |
73 | + * force broadcast of these operations. | 291 | + * always populated. The following macros catch all those cases. |
74 | + */ | 292 | + */ |
75 | +static bool tlb_force_broadcast(CPUARMState *env) | 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) | ||
76 | +{ | 605 | +{ |
77 | + return (env->cp15.hcr_el2 & HCR_FB) && | 606 | + mux->id = id; |
78 | + arm_current_el(env) == 1 && arm_is_secure_below_el3(env); | 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; | ||
79 | +} | 611 | +} |
80 | + | 612 | + |
81 | +static void tlbiall_write(CPUARMState *env, const ARMCPRegInfo *ri, | 613 | #endif |
82 | + uint64_t value) | 614 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c |
615 | index XXXXXXX..XXXXXXX 100644 | ||
616 | --- a/hw/misc/bcm2835_cprman.c | ||
617 | +++ b/hw/misc/bcm2835_cprman.c | ||
618 | @@ -XXX,XX +XXX,XX @@ | ||
619 | * | ||
620 | * The page at https://elinux.org/The_Undocumented_Pi gives the actual clock | ||
621 | * tree configuration. | ||
622 | + * | ||
623 | + * The CPRMAN exposes clock outputs with the name of the clock mux suffixed | ||
624 | + * with "-out" (e.g. "uart-out", "h264-out", ...). | ||
625 | */ | ||
626 | |||
627 | #include "qemu/osdep.h" | ||
628 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = { | ||
629 | }; | ||
630 | |||
631 | |||
632 | +/* clock mux */ | ||
633 | + | ||
634 | +static void clock_mux_update(CprmanClockMuxState *mux) | ||
83 | +{ | 635 | +{ |
84 | + /* Invalidate all (TLBIALL) */ | 636 | + clock_update(mux->out, 0); |
85 | + ARMCPU *cpu = arm_env_get_cpu(env); | ||
86 | + | ||
87 | + if (tlb_force_broadcast(env)) { | ||
88 | + tlbiall_is_write(env, NULL, value); | ||
89 | + return; | ||
90 | + } | ||
91 | + | ||
92 | + tlb_flush(CPU(cpu)); | ||
93 | +} | 637 | +} |
94 | + | 638 | + |
95 | +static void tlbimva_write(CPUARMState *env, const ARMCPRegInfo *ri, | 639 | +static void clock_mux_src_update(void *opaque) |
96 | + uint64_t value) | ||
97 | +{ | 640 | +{ |
98 | + /* Invalidate single TLB entry by MVA and ASID (TLBIMVA) */ | 641 | + CprmanClockMuxState **backref = opaque; |
99 | + ARMCPU *cpu = arm_env_get_cpu(env); | 642 | + CprmanClockMuxState *s = *backref; |
100 | + | 643 | + |
101 | + if (tlb_force_broadcast(env)) { | 644 | + clock_mux_update(s); |
102 | + tlbimva_is_write(env, NULL, value); | ||
103 | + return; | ||
104 | + } | ||
105 | + | ||
106 | + tlb_flush_page(CPU(cpu), value & TARGET_PAGE_MASK); | ||
107 | +} | 645 | +} |
108 | + | 646 | + |
109 | +static void tlbiasid_write(CPUARMState *env, const ARMCPRegInfo *ri, | 647 | +static void clock_mux_init(Object *obj) |
110 | + uint64_t value) | ||
111 | +{ | 648 | +{ |
112 | + /* Invalidate by ASID (TLBIASID) */ | 649 | + CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj); |
113 | + ARMCPU *cpu = arm_env_get_cpu(env); | 650 | + size_t i; |
114 | + | 651 | + |
115 | + if (tlb_force_broadcast(env)) { | 652 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) { |
116 | + tlbiasid_is_write(env, NULL, value); | 653 | + char *name = g_strdup_printf("srcs[%zu]", i); |
117 | + return; | 654 | + s->backref[i] = s; |
118 | + } | 655 | + s->srcs[i] = qdev_init_clock_in(DEVICE(s), name, |
119 | + | 656 | + clock_mux_src_update, |
120 | + tlb_flush(CPU(cpu)); | 657 | + &s->backref[i]); |
658 | + g_free(name); | ||
659 | + } | ||
660 | + | ||
661 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); | ||
121 | +} | 662 | +} |
122 | + | 663 | + |
123 | +static void tlbimvaa_write(CPUARMState *env, const ARMCPRegInfo *ri, | 664 | +static const VMStateDescription clock_mux_vmstate = { |
124 | + uint64_t value) | 665 | + .name = TYPE_CPRMAN_CLOCK_MUX, |
666 | + .version_id = 1, | ||
667 | + .minimum_version_id = 1, | ||
668 | + .fields = (VMStateField[]) { | ||
669 | + VMSTATE_ARRAY_CLOCK(srcs, CprmanClockMuxState, | ||
670 | + CPRMAN_NUM_CLOCK_MUX_SRC), | ||
671 | + VMSTATE_END_OF_LIST() | ||
672 | + } | ||
673 | +}; | ||
674 | + | ||
675 | +static void clock_mux_class_init(ObjectClass *klass, void *data) | ||
125 | +{ | 676 | +{ |
126 | + /* Invalidate single entry by MVA, all ASIDs (TLBIMVAA) */ | 677 | + DeviceClass *dc = DEVICE_CLASS(klass); |
127 | + ARMCPU *cpu = arm_env_get_cpu(env); | 678 | + |
128 | + | 679 | + dc->vmsd = &clock_mux_vmstate; |
129 | + if (tlb_force_broadcast(env)) { | ||
130 | + tlbimvaa_is_write(env, NULL, value); | ||
131 | + return; | ||
132 | + } | ||
133 | + | ||
134 | + tlb_flush_page(CPU(cpu), value & TARGET_PAGE_MASK); | ||
135 | +} | 680 | +} |
136 | + | 681 | + |
137 | static void tlbiall_nsnh_write(CPUARMState *env, const ARMCPRegInfo *ri, | 682 | +static const TypeInfo cprman_clock_mux_info = { |
138 | uint64_t value) | 683 | + .name = TYPE_CPRMAN_CLOCK_MUX, |
139 | { | 684 | + .parent = TYPE_DEVICE, |
140 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult aa64_cacheop_access(CPUARMState *env, | 685 | + .instance_size = sizeof(CprmanClockMuxState), |
141 | * Page D4-1736 (DDI0487A.b) | 686 | + .class_init = clock_mux_class_init, |
142 | */ | 687 | + .instance_init = clock_mux_init, |
143 | 688 | +}; | |
144 | -static void tlbi_aa64_vmalle1_write(CPUARMState *env, const ARMCPRegInfo *ri, | 689 | + |
145 | - uint64_t value) | 690 | + |
146 | -{ | 691 | /* CPRMAN "top level" model */ |
147 | - CPUState *cs = ENV_GET_CPU(env); | 692 | |
148 | - | 693 | static uint32_t get_cm_lock(const BCM2835CprmanState *s) |
149 | - if (arm_is_secure_below_el3(env)) { | 694 | @@ -XXX,XX +XXX,XX @@ static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx) |
150 | - tlb_flush_by_mmuidx(cs, | ||
151 | - ARMMMUIdxBit_S1SE1 | | ||
152 | - ARMMMUIdxBit_S1SE0); | ||
153 | - } else { | ||
154 | - tlb_flush_by_mmuidx(cs, | ||
155 | - ARMMMUIdxBit_S12NSE1 | | ||
156 | - ARMMMUIdxBit_S12NSE0); | ||
157 | - } | ||
158 | -} | ||
159 | - | ||
160 | static void tlbi_aa64_vmalle1is_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
161 | uint64_t value) | ||
162 | { | ||
163 | @@ -XXX,XX +XXX,XX @@ static void tlbi_aa64_vmalle1is_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
164 | } | 695 | } |
165 | } | 696 | } |
166 | 697 | ||
167 | +static void tlbi_aa64_vmalle1_write(CPUARMState *env, const ARMCPRegInfo *ri, | 698 | +static inline void update_mux_from_cm(BCM2835CprmanState *s, size_t idx) |
168 | + uint64_t value) | ||
169 | +{ | 699 | +{ |
170 | + CPUState *cs = ENV_GET_CPU(env); | 700 | + size_t i; |
171 | + | 701 | + |
172 | + if (tlb_force_broadcast(env)) { | 702 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { |
173 | + tlbi_aa64_vmalle1_write(env, NULL, value); | 703 | + if ((CLOCK_MUX_INIT_INFO[i].cm_offset == idx) || |
174 | + return; | 704 | + (CLOCK_MUX_INIT_INFO[i].cm_offset + 4 == idx)) { |
175 | + } | 705 | + /* matches CM_CTL or CM_DIV mux register */ |
176 | + | 706 | + clock_mux_update(&s->clock_muxes[i]); |
177 | + if (arm_is_secure_below_el3(env)) { | 707 | + return; |
178 | + tlb_flush_by_mmuidx(cs, | 708 | + } |
179 | + ARMMMUIdxBit_S1SE1 | | ||
180 | + ARMMMUIdxBit_S1SE0); | ||
181 | + } else { | ||
182 | + tlb_flush_by_mmuidx(cs, | ||
183 | + ARMMMUIdxBit_S12NSE1 | | ||
184 | + ARMMMUIdxBit_S12NSE0); | ||
185 | + } | 709 | + } |
186 | +} | 710 | +} |
187 | + | 711 | + |
188 | static void tlbi_aa64_alle1_write(CPUARMState *env, const ARMCPRegInfo *ri, | 712 | #define CASE_PLL_A2W_REGS(pll_) \ |
189 | uint64_t value) | 713 | case R_A2W_ ## pll_ ## _CTRL: \ |
190 | { | 714 | case R_A2W_ ## pll_ ## _ANA0: \ |
191 | @@ -XXX,XX +XXX,XX @@ static void tlbi_aa64_alle3is_write(CPUARMState *env, const ARMCPRegInfo *ri, | 715 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, |
192 | tlb_flush_by_mmuidx_all_cpus_synced(cs, ARMMMUIdxBit_S1E3); | 716 | case R_A2W_PLLB_ARM: |
193 | } | 717 | update_channel_from_a2w(s, idx); |
194 | 718 | break; | |
195 | -static void tlbi_aa64_vae1_write(CPUARMState *env, const ARMCPRegInfo *ri, | 719 | + |
196 | - uint64_t value) | 720 | + case R_CM_GNRICCTL ... R_CM_SMIDIV: |
197 | -{ | 721 | + case R_CM_TCNTCNT ... R_CM_VECDIV: |
198 | - /* Invalidate by VA, EL1&0 (AArch64 version). | 722 | + case R_CM_PULSECTL ... R_CM_PULSEDIV: |
199 | - * Currently handles all of VAE1, VAAE1, VAALE1 and VALE1, | 723 | + case R_CM_SDCCTL ... R_CM_ARMCTL: |
200 | - * since we don't support flush-for-specific-ASID-only or | 724 | + case R_CM_AVEOCTL ... R_CM_EMMCDIV: |
201 | - * flush-last-level-only. | 725 | + case R_CM_EMMC2CTL ... R_CM_EMMC2DIV: |
202 | - */ | 726 | + update_mux_from_cm(s, idx); |
203 | - ARMCPU *cpu = arm_env_get_cpu(env); | 727 | + break; |
204 | - CPUState *cs = CPU(cpu); | ||
205 | - uint64_t pageaddr = sextract64(value << 12, 0, 56); | ||
206 | - | ||
207 | - if (arm_is_secure_below_el3(env)) { | ||
208 | - tlb_flush_page_by_mmuidx(cs, pageaddr, | ||
209 | - ARMMMUIdxBit_S1SE1 | | ||
210 | - ARMMMUIdxBit_S1SE0); | ||
211 | - } else { | ||
212 | - tlb_flush_page_by_mmuidx(cs, pageaddr, | ||
213 | - ARMMMUIdxBit_S12NSE1 | | ||
214 | - ARMMMUIdxBit_S12NSE0); | ||
215 | - } | ||
216 | -} | ||
217 | - | ||
218 | static void tlbi_aa64_vae2_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
219 | uint64_t value) | ||
220 | { | ||
221 | @@ -XXX,XX +XXX,XX @@ static void tlbi_aa64_vae1is_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
222 | } | 728 | } |
223 | } | 729 | } |
224 | 730 | ||
225 | +static void tlbi_aa64_vae1_write(CPUARMState *env, const ARMCPRegInfo *ri, | 731 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) |
226 | + uint64_t value) | 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) | ||
227 | +{ | 773 | +{ |
228 | + /* Invalidate by VA, EL1&0 (AArch64 version). | 774 | + size_t i; |
229 | + * Currently handles all of VAE1, VAAE1, VAALE1 and VALE1, | 775 | + Clock *td0 = s->clock_muxes[CPRMAN_CLOCK_TD0].out; |
230 | + * since we don't support flush-for-specific-ASID-only or | 776 | + Clock *td1 = s->clock_muxes[CPRMAN_CLOCK_TD1].out; |
231 | + * flush-last-level-only. | 777 | + |
232 | + */ | 778 | + /* For sources from 0 to 3. Source 4 to 9 are mux specific */ |
233 | + ARMCPU *cpu = arm_env_get_cpu(env); | 779 | + Clock * const CLK_SRC_MAPPING[] = { |
234 | + CPUState *cs = CPU(cpu); | 780 | + [CPRMAN_CLOCK_SRC_GND] = s->gnd, |
235 | + uint64_t pageaddr = sextract64(value << 12, 0, 56); | 781 | + [CPRMAN_CLOCK_SRC_XOSC] = s->xosc, |
236 | + | 782 | + [CPRMAN_CLOCK_SRC_TD0] = td0, |
237 | + if (tlb_force_broadcast(env)) { | 783 | + [CPRMAN_CLOCK_SRC_TD1] = td1, |
238 | + tlbi_aa64_vae1is_write(env, NULL, value); | 784 | + }; |
239 | + return; | 785 | + |
240 | + } | 786 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) { |
241 | + | 787 | + CprmanPllChannel mapping = clk_mapping[i]; |
242 | + if (arm_is_secure_below_el3(env)) { | 788 | + Clock *src; |
243 | + tlb_flush_page_by_mmuidx(cs, pageaddr, | 789 | + |
244 | + ARMMMUIdxBit_S1SE1 | | 790 | + if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) { |
245 | + ARMMMUIdxBit_S1SE0); | 791 | + src = s->gnd; |
246 | + } else { | 792 | + } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) { |
247 | + tlb_flush_page_by_mmuidx(cs, pageaddr, | 793 | + src = s->gnd; /* TODO */ |
248 | + ARMMMUIdxBit_S12NSE1 | | 794 | + } else if (i < CPRMAN_CLOCK_SRC_PLLA) { |
249 | + ARMMMUIdxBit_S12NSE0); | 795 | + src = CLK_SRC_MAPPING[i]; |
796 | + } else { | ||
797 | + src = s->channels[mapping].out; | ||
798 | + } | ||
799 | + | ||
800 | + clock_set_source(mux->srcs[i], src); | ||
250 | + } | 801 | + } |
251 | +} | 802 | +} |
252 | + | 803 | + |
253 | static void tlbi_aa64_vae2is_write(CPUARMState *env, const ARMCPRegInfo *ri, | 804 | static void cprman_realize(DeviceState *dev, Error **errp) |
254 | uint64_t value) | ||
255 | { | 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); | ||
256 | -- | 832 | -- |
257 | 2.19.1 | 833 | 2.20.1 |
258 | 834 | ||
259 | 835 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | Having V6 alone imply jazelle was wrong for cortex-m0. | 3 | A clock mux can be configured to select one of its 10 sources through |
4 | Change to an assertion for V6 & !M. | 4 | the CM_CTL register. It also embeds yet another clock divider, composed |
5 | of an integer part and a fractional part. The number of bits of each | ||
6 | part is mux dependent. | ||
5 | 7 | ||
6 | This was harmless, because the only place we tested ARM_FEATURE_JAZELLE | 8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
7 | was for 'bxj' in disas_arm(), which is unreachable for M-profile cores. | 9 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
8 | 10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | |
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 11 | Tested-by: Guenter Roeck <linux@roeck-us.net> |
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-id: 20181016223115.24100-6-richard.henderson@linaro.org | ||
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 13 | --- |
15 | target/arm/cpu.h | 6 +++++- | 14 | hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++- |
16 | target/arm/cpu.c | 17 ++++++++++++++--- | 15 | 1 file changed, 52 insertions(+), 1 deletion(-) |
17 | target/arm/translate.c | 2 +- | ||
18 | 3 files changed, 20 insertions(+), 5 deletions(-) | ||
19 | 16 | ||
20 | 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 |
21 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/arm/cpu.h | 19 | --- a/hw/misc/bcm2835_cprman.c |
23 | +++ b/target/arm/cpu.h | 20 | +++ b/hw/misc/bcm2835_cprman.c |
24 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 21 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = { |
25 | ARM_FEATURE_PMU, /* has PMU support */ | 22 | |
26 | ARM_FEATURE_VBAR, /* has cp15 VBAR */ | 23 | /* clock mux */ |
27 | ARM_FEATURE_M_SECURITY, /* M profile Security Extension */ | 24 | |
28 | - ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ | 25 | +static bool clock_mux_is_enabled(CprmanClockMuxState *mux) |
29 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | ||
30 | ARM_FEATURE_V8_FP16, /* implements v8.2 half-precision float */ | ||
31 | ARM_FEATURE_M_MAIN, /* M profile Main Extension */ | ||
32 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_arm_div(const ARMISARegisters *id) | ||
33 | return FIELD_EX32(id->id_isar0, ID_ISAR0, DIVIDE) > 1; | ||
34 | } | ||
35 | |||
36 | +static inline bool isar_feature_jazelle(const ARMISARegisters *id) | ||
37 | +{ | 26 | +{ |
38 | + return FIELD_EX32(id->id_isar1, ID_ISAR1, JAZELLE) != 0; | 27 | + return FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, ENABLE); |
39 | +} | 28 | +} |
40 | + | 29 | + |
41 | static inline bool isar_feature_aa32_aes(const ARMISARegisters *id) | 30 | static void clock_mux_update(CprmanClockMuxState *mux) |
42 | { | 31 | { |
43 | return FIELD_EX32(id->id_isar5, ID_ISAR5, AES) != 0; | 32 | - clock_update(mux->out, 0); |
44 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 33 | + uint64_t freq; |
45 | index XXXXXXX..XXXXXXX 100644 | 34 | + uint32_t div, src = FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, SRC); |
46 | --- a/target/arm/cpu.c | 35 | + bool enabled = clock_mux_is_enabled(mux); |
47 | +++ b/target/arm/cpu.c | 36 | + |
48 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) | 37 | + *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled); |
49 | } | 38 | + |
50 | if (arm_feature(env, ARM_FEATURE_V6)) { | 39 | + if (!enabled) { |
51 | set_feature(env, ARM_FEATURE_V5); | 40 | + clock_update(mux->out, 0); |
52 | - set_feature(env, ARM_FEATURE_JAZELLE); | 41 | + return; |
53 | if (!arm_feature(env, ARM_FEATURE_M)) { | 42 | + } |
54 | + assert(cpu_isar_feature(jazelle, cpu)); | 43 | + |
55 | set_feature(env, ARM_FEATURE_AUXCR); | 44 | + freq = clock_get_hz(mux->srcs[src]); |
56 | } | 45 | + |
57 | } | 46 | + if (mux->int_bits == 0 && mux->frac_bits == 0) { |
58 | @@ -XXX,XX +XXX,XX @@ static void arm926_initfn(Object *obj) | 47 | + clock_update_hz(mux->out, freq); |
59 | set_feature(&cpu->env, ARM_FEATURE_VFP); | 48 | + return; |
60 | set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS); | 49 | + } |
61 | set_feature(&cpu->env, ARM_FEATURE_CACHE_TEST_CLEAN); | ||
62 | - set_feature(&cpu->env, ARM_FEATURE_JAZELLE); | ||
63 | cpu->midr = 0x41069265; | ||
64 | cpu->reset_fpsid = 0x41011090; | ||
65 | cpu->ctr = 0x1dd20d2; | ||
66 | cpu->reset_sctlr = 0x00090078; | ||
67 | + | 50 | + |
68 | + /* | 51 | + /* |
69 | + * ARMv5 does not have the ID_ISAR registers, but we can still | 52 | + * The divider has an integer and a fractional part. The size of each part |
70 | + * set the field to indicate Jazelle support within QEMU. | 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 | ||
71 | + */ | 62 | + */ |
72 | + cpu->isar.id_isar1 = FIELD_DP32(cpu->isar.id_isar1, ID_ISAR1, JAZELLE, 1); | 63 | + div = extract32(*mux->reg_div, |
64 | + R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits, | ||
65 | + mux->int_bits + mux->frac_bits); | ||
66 | + | ||
67 | + if (!div) { | ||
68 | + clock_update(mux->out, 0); | ||
69 | + return; | ||
70 | + } | ||
71 | + | ||
72 | + freq = muldiv64(freq, 1 << mux->frac_bits, div); | ||
73 | + | ||
74 | + clock_update_hz(mux->out, freq); | ||
73 | } | 75 | } |
74 | 76 | ||
75 | static void arm946_initfn(Object *obj) | 77 | static void clock_mux_src_update(void *opaque) |
76 | @@ -XXX,XX +XXX,XX @@ static void arm1026_initfn(Object *obj) | 78 | { |
77 | set_feature(&cpu->env, ARM_FEATURE_AUXCR); | 79 | CprmanClockMuxState **backref = opaque; |
78 | set_feature(&cpu->env, ARM_FEATURE_DUMMY_C15_REGS); | 80 | CprmanClockMuxState *s = *backref; |
79 | set_feature(&cpu->env, ARM_FEATURE_CACHE_TEST_CLEAN); | 81 | + CprmanClockMuxSource src = backref - s->backref; |
80 | - set_feature(&cpu->env, ARM_FEATURE_JAZELLE); | ||
81 | cpu->midr = 0x4106a262; | ||
82 | cpu->reset_fpsid = 0x410110a0; | ||
83 | cpu->ctr = 0x1dd20d2; | ||
84 | cpu->reset_sctlr = 0x00090078; | ||
85 | cpu->reset_auxcr = 1; | ||
86 | + | 82 | + |
87 | + /* | 83 | + if (FIELD_EX32(*s->reg_ctl, CM_CLOCKx_CTL, SRC) != src) { |
88 | + * ARMv5 does not have the ID_ISAR registers, but we can still | 84 | + return; |
89 | + * set the field to indicate Jazelle support within QEMU. | 85 | + } |
90 | + */ | 86 | |
91 | + cpu->isar.id_isar1 = FIELD_DP32(cpu->isar.id_isar1, ID_ISAR1, JAZELLE, 1); | 87 | clock_mux_update(s); |
92 | + | 88 | } |
93 | { | ||
94 | /* The 1026 had an IFAR at c6,c0,0,1 rather than the ARMv6 c6,c0,0,2 */ | ||
95 | ARMCPRegInfo ifar = { | ||
96 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/target/arm/translate.c | ||
99 | +++ b/target/arm/translate.c | ||
100 | @@ -XXX,XX +XXX,XX @@ | ||
101 | #define ENABLE_ARCH_5 arm_dc_feature(s, ARM_FEATURE_V5) | ||
102 | /* currently all emulated v5 cores are also v5TE, so don't bother */ | ||
103 | #define ENABLE_ARCH_5TE arm_dc_feature(s, ARM_FEATURE_V5) | ||
104 | -#define ENABLE_ARCH_5J arm_dc_feature(s, ARM_FEATURE_JAZELLE) | ||
105 | +#define ENABLE_ARCH_5J dc_isar_feature(jazelle, s) | ||
106 | #define ENABLE_ARCH_6 arm_dc_feature(s, ARM_FEATURE_V6) | ||
107 | #define ENABLE_ARCH_6K arm_dc_feature(s, ARM_FEATURE_V6K) | ||
108 | #define ENABLE_ARCH_6T2 arm_dc_feature(s, ARM_FEATURE_THUMB2) | ||
109 | -- | 89 | -- |
110 | 2.19.1 | 90 | 2.20.1 |
111 | 91 | ||
112 | 92 | diff view generated by jsdifflib |
1 | The HCR.DC virtualization configuration register bit has the | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | following effects: | 2 | |
3 | * SCTLR.M behaves as if it is 0 for all purposes except | 3 | This simple mux sits between the PLL channels and the DSI0E and DSI0P |
4 | direct reads of the bit | 4 | clock muxes. This mux selects between PLLA-DSI0 and PLLD-DSI0 channel |
5 | * HCR.VM behaves as if it is 1 for all purposes except | 5 | and outputs the selected signal to source number 4 of DSI0E/P clock |
6 | direct reads of the bit | 6 | muxes. It is controlled by the cm_dsi0hsck register. |
7 | * the memory type produced by the first stage of the EL1&EL0 | 7 | |
8 | translation regime is Normal Non-Shareable, | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
9 | Inner Write-Back Read-Allocate Write-Allocate, | 9 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
10 | Outer Write-Back Read-Allocate Write-Allocate. | 10 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
11 | 11 | Tested-by: Guenter Roeck <linux@roeck-us.net> | |
12 | Implement this behaviour. | ||
13 | |||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
16 | Message-id: 20181012144235.19646-5-peter.maydell@linaro.org | ||
17 | --- | 13 | --- |
18 | target/arm/helper.c | 23 +++++++++++++++++++++-- | 14 | include/hw/misc/bcm2835_cprman.h | 15 +++++ |
19 | 1 file changed, 21 insertions(+), 2 deletions(-) | 15 | include/hw/misc/bcm2835_cprman_internals.h | 6 ++ |
20 | 16 | hw/misc/bcm2835_cprman.c | 74 +++++++++++++++++++++- | |
21 | 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 | ||
22 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/arm/helper.c | 21 | --- a/include/hw/misc/bcm2835_cprman.h |
24 | +++ b/target/arm/helper.c | 22 | +++ b/include/hw/misc/bcm2835_cprman.h |
25 | @@ -XXX,XX +XXX,XX @@ static uint64_t do_ats_write(CPUARMState *env, uint64_t value, | 23 | @@ -XXX,XX +XXX,XX @@ typedef struct CprmanClockMuxState { |
26 | * * The Non-secure TTBCR.EAE bit is set to 1 | 24 | struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC]; |
27 | * * The implementation includes EL2, and the value of HCR.VM is 1 | 25 | } CprmanClockMuxState; |
28 | * | 26 | |
29 | + * (Note that HCR.DC makes HCR.VM behave as if it is 1.) | 27 | +typedef struct CprmanDsi0HsckMuxState { |
30 | + * | 28 | + /*< private >*/ |
31 | * ATS1Hx always uses the 64bit format (not supported yet). | 29 | + DeviceState parent_obj; |
32 | */ | 30 | + |
33 | format64 = arm_s1_regime_using_lpae_format(env, mmu_idx); | 31 | + /*< public >*/ |
34 | 32 | + CprmanClockMux id; | |
35 | if (arm_feature(env, ARM_FEATURE_EL2)) { | 33 | + |
36 | if (mmu_idx == ARMMMUIdx_S12NSE0 || mmu_idx == ARMMMUIdx_S12NSE1) { | 34 | + uint32_t *reg_cm; |
37 | - format64 |= env->cp15.hcr_el2 & HCR_VM; | 35 | + |
38 | + format64 |= env->cp15.hcr_el2 & (HCR_VM | HCR_DC); | 36 | + Clock *plla_in; |
39 | } else { | 37 | + Clock *plld_in; |
40 | format64 |= arm_current_el(env) == 2; | 38 | + Clock *out; |
41 | } | 39 | +} CprmanDsi0HsckMuxState; |
42 | @@ -XXX,XX +XXX,XX @@ static inline bool regime_translation_disabled(CPUARMState *env, | 40 | + |
43 | } | 41 | struct BCM2835CprmanState { |
44 | 42 | /*< private >*/ | |
45 | if (mmu_idx == ARMMMUIdx_S2NS) { | 43 | SysBusDevice parent_obj; |
46 | - return (env->cp15.hcr_el2 & HCR_VM) == 0; | 44 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { |
47 | + /* HCR.DC means HCR.VM behaves as 1 */ | 45 | CprmanPllState plls[CPRMAN_NUM_PLL]; |
48 | + return (env->cp15.hcr_el2 & (HCR_DC | HCR_VM)) == 0; | 46 | CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL]; |
49 | } | 47 | CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX]; |
50 | 48 | + CprmanDsi0HsckMuxState dsi0hsck_mux; | |
51 | if (env->cp15.hcr_el2 & HCR_TGE) { | 49 | |
52 | @@ -XXX,XX +XXX,XX @@ static inline bool regime_translation_disabled(CPUARMState *env, | 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 | } | ||
155 | } | ||
156 | |||
157 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) | ||
158 | device_cold_reset(DEVICE(&s->channels[i])); | ||
159 | } | ||
160 | |||
161 | + device_cold_reset(DEVICE(&s->dsi0hsck_mux)); | ||
162 | + | ||
163 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
164 | device_cold_reset(DEVICE(&s->clock_muxes[i])); | ||
165 | } | ||
166 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) | ||
167 | set_pll_channel_init_info(s, &s->channels[i], i); | ||
168 | } | ||
169 | |||
170 | + object_initialize_child(obj, "dsi0hsck-mux", | ||
171 | + &s->dsi0hsck_mux, TYPE_CPRMAN_DSI0HSCK_MUX); | ||
172 | + s->dsi0hsck_mux.reg_cm = &s->regs[R_CM_DSI0HSCK]; | ||
173 | + | ||
174 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
175 | char *alias; | ||
176 | |||
177 | @@ -XXX,XX +XXX,XX @@ static void connect_mux_sources(BCM2835CprmanState *s, | ||
178 | if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) { | ||
179 | src = s->gnd; | ||
180 | } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) { | ||
181 | - src = s->gnd; /* TODO */ | ||
182 | + src = s->dsi0hsck_mux.out; | ||
183 | } else if (i < CPRMAN_CLOCK_SRC_PLLA) { | ||
184 | src = CLK_SRC_MAPPING[i]; | ||
185 | } else { | ||
186 | @@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp) | ||
53 | } | 187 | } |
54 | } | 188 | } |
55 | 189 | ||
56 | + if ((env->cp15.hcr_el2 & HCR_DC) && | 190 | + clock_set_source(s->dsi0hsck_mux.plla_in, |
57 | + (mmu_idx == ARMMMUIdx_S1NSE0 || mmu_idx == ARMMMUIdx_S1NSE1)) { | 191 | + s->channels[CPRMAN_PLLA_CHANNEL_DSI0].out); |
58 | + /* HCR.DC means SCTLR_EL1.M behaves as 0 */ | 192 | + clock_set_source(s->dsi0hsck_mux.plld_in, |
59 | + return true; | 193 | + s->channels[CPRMAN_PLLD_CHANNEL_DSI0].out); |
194 | + | ||
195 | + if (!qdev_realize(DEVICE(&s->dsi0hsck_mux), NULL, errp)) { | ||
196 | + return; | ||
60 | + } | 197 | + } |
61 | + | 198 | + |
62 | return (regime_sctlr(env, mmu_idx) & SCTLR_M) == 0; | 199 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { |
200 | CprmanClockMuxState *clock_mux = &s->clock_muxes[i]; | ||
201 | |||
202 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) | ||
203 | type_register_static(&cprman_pll_info); | ||
204 | type_register_static(&cprman_pll_channel_info); | ||
205 | type_register_static(&cprman_clock_mux_info); | ||
206 | + type_register_static(&cprman_dsi0hsck_mux_info); | ||
63 | } | 207 | } |
64 | 208 | ||
65 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr(CPUARMState *env, target_ulong address, | 209 | type_init(cprman_register_types); |
66 | |||
67 | /* Combine the S1 and S2 cache attributes, if needed */ | ||
68 | if (!ret && cacheattrs != NULL) { | ||
69 | + if (env->cp15.hcr_el2 & HCR_DC) { | ||
70 | + /* | ||
71 | + * HCR.DC forces the first stage attributes to | ||
72 | + * Normal Non-Shareable, | ||
73 | + * Inner Write-Back Read-Allocate Write-Allocate, | ||
74 | + * Outer Write-Back Read-Allocate Write-Allocate. | ||
75 | + */ | ||
76 | + cacheattrs->attrs = 0xff; | ||
77 | + cacheattrs->shareability = 0; | ||
78 | + } | ||
79 | *cacheattrs = combine_cacheattrs(*cacheattrs, cacheattrs2); | ||
80 | } | ||
81 | |||
82 | -- | 210 | -- |
83 | 2.19.1 | 211 | 2.20.1 |
84 | 212 | ||
85 | 213 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | Move ssra_op and usra_op expanders from translate-a64.c. | 3 | Those reset values have been extracted from a Raspberry Pi 3 model B |
4 | 4 | v1.2, using the 2020-08-20 version of raspios. The dump was done using | |
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | the debugfs interface of the CPRMAN driver in Linux (under |
6 | Message-id: 20181011205206.3552-14-richard.henderson@linaro.org | 6 | '/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 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> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 26 | --- |
10 | target/arm/translate.h | 2 + | 27 | include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++ |
11 | target/arm/translate-a64.c | 106 ---------------------------- | 28 | hw/misc/bcm2835_cprman.c | 31 +++ |
12 | target/arm/translate.c | 139 ++++++++++++++++++++++++++++++++++--- | 29 | 2 files changed, 300 insertions(+) |
13 | 3 files changed, 130 insertions(+), 117 deletions(-) | 30 | |
14 | 31 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | |
15 | diff --git a/target/arm/translate.h b/target/arm/translate.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate.h | 33 | --- a/include/hw/misc/bcm2835_cprman_internals.h |
18 | +++ b/target/arm/translate.h | 34 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
19 | @@ -XXX,XX +XXX,XX @@ static inline TCGv_i32 get_ahp_flag(void) | 35 | @@ -XXX,XX +XXX,XX @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s, |
20 | extern const GVecGen3 bsl_op; | 36 | mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits; |
21 | extern const GVecGen3 bit_op; | 37 | } |
22 | extern const GVecGen3 bif_op; | 38 | |
23 | +extern const GVecGen2i ssra_op[4]; | 39 | + |
24 | +extern const GVecGen2i usra_op[4]; | 40 | +/* |
25 | 41 | + * Object reset info | |
26 | /* | 42 | + * Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the |
27 | * Forward to the isar_feature_* tests given a DisasContext pointer. | 43 | + * clk debugfs interface in Linux. |
28 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 44 | + */ |
45 | +typedef struct PLLResetInfo { | ||
46 | + uint32_t cm; | ||
47 | + uint32_t a2w_ctrl; | ||
48 | + uint32_t a2w_ana[4]; | ||
49 | + uint32_t a2w_frac; | ||
50 | +} PLLResetInfo; | ||
51 | + | ||
52 | +static const PLLResetInfo PLL_RESET_INFO[] = { | ||
53 | + [CPRMAN_PLLA] = { | ||
54 | + .cm = 0x0000008a, | ||
55 | + .a2w_ctrl = 0x0002103a, | ||
56 | + .a2w_frac = 0x00098000, | ||
57 | + .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 } | ||
58 | + }, | ||
59 | + | ||
60 | + [CPRMAN_PLLC] = { | ||
61 | + .cm = 0x00000228, | ||
62 | + .a2w_ctrl = 0x0002103e, | ||
63 | + .a2w_frac = 0x00080000, | ||
64 | + .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 } | ||
65 | + }, | ||
66 | + | ||
67 | + [CPRMAN_PLLD] = { | ||
68 | + .cm = 0x0000020a, | ||
69 | + .a2w_ctrl = 0x00021034, | ||
70 | + .a2w_frac = 0x00015556, | ||
71 | + .a2w_ana = { 0x00000000, 0x00144000, 0x00000000, 0x00000100 } | ||
72 | + }, | ||
73 | + | ||
74 | + [CPRMAN_PLLH] = { | ||
75 | + .cm = 0x00000000, | ||
76 | + .a2w_ctrl = 0x0002102d, | ||
77 | + .a2w_frac = 0x00000000, | ||
78 | + .a2w_ana = { 0x00900000, 0x0000000c, 0x00000000, 0x00000000 } | ||
79 | + }, | ||
80 | + | ||
81 | + [CPRMAN_PLLB] = { | ||
82 | + /* unknown */ | ||
83 | + .cm = 0x00000000, | ||
84 | + .a2w_ctrl = 0x00000000, | ||
85 | + .a2w_frac = 0x00000000, | ||
86 | + .a2w_ana = { 0x00000000, 0x00000000, 0x00000000, 0x00000000 } | ||
87 | + } | ||
88 | +}; | ||
89 | + | ||
90 | +typedef struct PLLChannelResetInfo { | ||
91 | + /* | ||
92 | + * Even though a PLL channel has a CM register, it shares it with its | ||
93 | + * parent PLL. The parent already takes care of the reset value. | ||
94 | + */ | ||
95 | + uint32_t a2w_ctrl; | ||
96 | +} PLLChannelResetInfo; | ||
97 | + | ||
98 | +static const PLLChannelResetInfo PLL_CHANNEL_RESET_INFO[] = { | ||
99 | + [CPRMAN_PLLA_CHANNEL_DSI0] = { .a2w_ctrl = 0x00000100 }, | ||
100 | + [CPRMAN_PLLA_CHANNEL_CORE] = { .a2w_ctrl = 0x00000003 }, | ||
101 | + [CPRMAN_PLLA_CHANNEL_PER] = { .a2w_ctrl = 0x00000000 }, /* unknown */ | ||
102 | + [CPRMAN_PLLA_CHANNEL_CCP2] = { .a2w_ctrl = 0x00000100 }, | ||
103 | + | ||
104 | + [CPRMAN_PLLC_CHANNEL_CORE2] = { .a2w_ctrl = 0x00000100 }, | ||
105 | + [CPRMAN_PLLC_CHANNEL_CORE1] = { .a2w_ctrl = 0x00000100 }, | ||
106 | + [CPRMAN_PLLC_CHANNEL_PER] = { .a2w_ctrl = 0x00000002 }, | ||
107 | + [CPRMAN_PLLC_CHANNEL_CORE0] = { .a2w_ctrl = 0x00000002 }, | ||
108 | + | ||
109 | + [CPRMAN_PLLD_CHANNEL_DSI0] = { .a2w_ctrl = 0x00000100 }, | ||
110 | + [CPRMAN_PLLD_CHANNEL_CORE] = { .a2w_ctrl = 0x00000004 }, | ||
111 | + [CPRMAN_PLLD_CHANNEL_PER] = { .a2w_ctrl = 0x00000004 }, | ||
112 | + [CPRMAN_PLLD_CHANNEL_DSI1] = { .a2w_ctrl = 0x00000100 }, | ||
113 | + | ||
114 | + [CPRMAN_PLLH_CHANNEL_AUX] = { .a2w_ctrl = 0x00000004 }, | ||
115 | + [CPRMAN_PLLH_CHANNEL_RCAL] = { .a2w_ctrl = 0x00000000 }, | ||
116 | + [CPRMAN_PLLH_CHANNEL_PIX] = { .a2w_ctrl = 0x00000000 }, | ||
117 | + | ||
118 | + [CPRMAN_PLLB_CHANNEL_ARM] = { .a2w_ctrl = 0x00000000 }, /* unknown */ | ||
119 | +}; | ||
120 | + | ||
121 | +typedef struct ClockMuxResetInfo { | ||
122 | + uint32_t cm_ctl; | ||
123 | + uint32_t cm_div; | ||
124 | +} ClockMuxResetInfo; | ||
125 | + | ||
126 | +static const ClockMuxResetInfo CLOCK_MUX_RESET_INFO[] = { | ||
127 | + [CPRMAN_CLOCK_GNRIC] = { | ||
128 | + .cm_ctl = 0, /* unknown */ | ||
129 | + .cm_div = 0 | ||
130 | + }, | ||
131 | + | ||
132 | + [CPRMAN_CLOCK_VPU] = { | ||
133 | + .cm_ctl = 0x00000245, | ||
134 | + .cm_div = 0x00003000, | ||
135 | + }, | ||
136 | + | ||
137 | + [CPRMAN_CLOCK_SYS] = { | ||
138 | + .cm_ctl = 0, /* unknown */ | ||
139 | + .cm_div = 0 | ||
140 | + }, | ||
141 | + | ||
142 | + [CPRMAN_CLOCK_PERIA] = { | ||
143 | + .cm_ctl = 0, /* unknown */ | ||
144 | + .cm_div = 0 | ||
145 | + }, | ||
146 | + | ||
147 | + [CPRMAN_CLOCK_PERII] = { | ||
148 | + .cm_ctl = 0, /* unknown */ | ||
149 | + .cm_div = 0 | ||
150 | + }, | ||
151 | + | ||
152 | + [CPRMAN_CLOCK_H264] = { | ||
153 | + .cm_ctl = 0x00000244, | ||
154 | + .cm_div = 0x00003000, | ||
155 | + }, | ||
156 | + | ||
157 | + [CPRMAN_CLOCK_ISP] = { | ||
158 | + .cm_ctl = 0x00000244, | ||
159 | + .cm_div = 0x00003000, | ||
160 | + }, | ||
161 | + | ||
162 | + [CPRMAN_CLOCK_V3D] = { | ||
163 | + .cm_ctl = 0, /* unknown */ | ||
164 | + .cm_div = 0 | ||
165 | + }, | ||
166 | + | ||
167 | + [CPRMAN_CLOCK_CAM0] = { | ||
168 | + .cm_ctl = 0x00000000, | ||
169 | + .cm_div = 0x00000000, | ||
170 | + }, | ||
171 | + | ||
172 | + [CPRMAN_CLOCK_CAM1] = { | ||
173 | + .cm_ctl = 0x00000000, | ||
174 | + .cm_div = 0x00000000, | ||
175 | + }, | ||
176 | + | ||
177 | + [CPRMAN_CLOCK_CCP2] = { | ||
178 | + .cm_ctl = 0, /* unknown */ | ||
179 | + .cm_div = 0 | ||
180 | + }, | ||
181 | + | ||
182 | + [CPRMAN_CLOCK_DSI0E] = { | ||
183 | + .cm_ctl = 0x00000000, | ||
184 | + .cm_div = 0x00000000, | ||
185 | + }, | ||
186 | + | ||
187 | + [CPRMAN_CLOCK_DSI0P] = { | ||
188 | + .cm_ctl = 0x00000000, | ||
189 | + .cm_div = 0x00000000, | ||
190 | + }, | ||
191 | + | ||
192 | + [CPRMAN_CLOCK_DPI] = { | ||
193 | + .cm_ctl = 0x00000000, | ||
194 | + .cm_div = 0x00000000, | ||
195 | + }, | ||
196 | + | ||
197 | + [CPRMAN_CLOCK_GP0] = { | ||
198 | + .cm_ctl = 0x00000200, | ||
199 | + .cm_div = 0x00000000, | ||
200 | + }, | ||
201 | + | ||
202 | + [CPRMAN_CLOCK_GP1] = { | ||
203 | + .cm_ctl = 0x00000096, | ||
204 | + .cm_div = 0x00014000, | ||
205 | + }, | ||
206 | + | ||
207 | + [CPRMAN_CLOCK_GP2] = { | ||
208 | + .cm_ctl = 0x00000291, | ||
209 | + .cm_div = 0x00249f00, | ||
210 | + }, | ||
211 | + | ||
212 | + [CPRMAN_CLOCK_HSM] = { | ||
213 | + .cm_ctl = 0x00000000, | ||
214 | + .cm_div = 0x00000000, | ||
215 | + }, | ||
216 | + | ||
217 | + [CPRMAN_CLOCK_OTP] = { | ||
218 | + .cm_ctl = 0x00000091, | ||
219 | + .cm_div = 0x00004000, | ||
220 | + }, | ||
221 | + | ||
222 | + [CPRMAN_CLOCK_PCM] = { | ||
223 | + .cm_ctl = 0x00000200, | ||
224 | + .cm_div = 0x00000000, | ||
225 | + }, | ||
226 | + | ||
227 | + [CPRMAN_CLOCK_PWM] = { | ||
228 | + .cm_ctl = 0x00000200, | ||
229 | + .cm_div = 0x00000000, | ||
230 | + }, | ||
231 | + | ||
232 | + [CPRMAN_CLOCK_SLIM] = { | ||
233 | + .cm_ctl = 0x00000200, | ||
234 | + .cm_div = 0x00000000, | ||
235 | + }, | ||
236 | + | ||
237 | + [CPRMAN_CLOCK_SMI] = { | ||
238 | + .cm_ctl = 0x00000000, | ||
239 | + .cm_div = 0x00000000, | ||
240 | + }, | ||
241 | + | ||
242 | + [CPRMAN_CLOCK_TEC] = { | ||
243 | + .cm_ctl = 0x00000000, | ||
244 | + .cm_div = 0x00000000, | ||
245 | + }, | ||
246 | + | ||
247 | + [CPRMAN_CLOCK_TD0] = { | ||
248 | + .cm_ctl = 0, /* unknown */ | ||
249 | + .cm_div = 0 | ||
250 | + }, | ||
251 | + | ||
252 | + [CPRMAN_CLOCK_TD1] = { | ||
253 | + .cm_ctl = 0, /* unknown */ | ||
254 | + .cm_div = 0 | ||
255 | + }, | ||
256 | + | ||
257 | + [CPRMAN_CLOCK_TSENS] = { | ||
258 | + .cm_ctl = 0x00000091, | ||
259 | + .cm_div = 0x0000a000, | ||
260 | + }, | ||
261 | + | ||
262 | + [CPRMAN_CLOCK_TIMER] = { | ||
263 | + .cm_ctl = 0x00000291, | ||
264 | + .cm_div = 0x00013333, | ||
265 | + }, | ||
266 | + | ||
267 | + [CPRMAN_CLOCK_UART] = { | ||
268 | + .cm_ctl = 0x00000296, | ||
269 | + .cm_div = 0x0000a6ab, | ||
270 | + }, | ||
271 | + | ||
272 | + [CPRMAN_CLOCK_VEC] = { | ||
273 | + .cm_ctl = 0x00000097, | ||
274 | + .cm_div = 0x00002000, | ||
275 | + }, | ||
276 | + | ||
277 | + [CPRMAN_CLOCK_PULSE] = { | ||
278 | + .cm_ctl = 0, /* unknown */ | ||
279 | + .cm_div = 0 | ||
280 | + }, | ||
281 | + | ||
282 | + [CPRMAN_CLOCK_SDC] = { | ||
283 | + .cm_ctl = 0x00004006, | ||
284 | + .cm_div = 0x00003000, | ||
285 | + }, | ||
286 | + | ||
287 | + [CPRMAN_CLOCK_ARM] = { | ||
288 | + .cm_ctl = 0, /* unknown */ | ||
289 | + .cm_div = 0 | ||
290 | + }, | ||
291 | + | ||
292 | + [CPRMAN_CLOCK_AVEO] = { | ||
293 | + .cm_ctl = 0x00000000, | ||
294 | + .cm_div = 0x00000000, | ||
295 | + }, | ||
296 | + | ||
297 | + [CPRMAN_CLOCK_EMMC] = { | ||
298 | + .cm_ctl = 0x00000295, | ||
299 | + .cm_div = 0x00006000, | ||
300 | + }, | ||
301 | + | ||
302 | + [CPRMAN_CLOCK_EMMC2] = { | ||
303 | + .cm_ctl = 0, /* unknown */ | ||
304 | + .cm_div = 0 | ||
305 | + }, | ||
306 | +}; | ||
307 | + | ||
308 | #endif | ||
309 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | 310 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/translate-a64.c | 311 | --- a/hw/misc/bcm2835_cprman.c |
31 | +++ b/target/arm/translate-a64.c | 312 | +++ b/hw/misc/bcm2835_cprman.c |
32 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_scalar_two_reg_misc(DisasContext *s, uint32_t insn) | 313 | @@ -XXX,XX +XXX,XX @@ |
33 | } | 314 | |
34 | } | 315 | /* PLL */ |
35 | 316 | ||
36 | -static void gen_ssra8_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | 317 | +static void pll_reset(DeviceState *dev) |
37 | -{ | ||
38 | - tcg_gen_vec_sar8i_i64(a, a, shift); | ||
39 | - tcg_gen_vec_add8_i64(d, d, a); | ||
40 | -} | ||
41 | - | ||
42 | -static void gen_ssra16_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
43 | -{ | ||
44 | - tcg_gen_vec_sar16i_i64(a, a, shift); | ||
45 | - tcg_gen_vec_add16_i64(d, d, a); | ||
46 | -} | ||
47 | - | ||
48 | -static void gen_ssra32_i32(TCGv_i32 d, TCGv_i32 a, int32_t shift) | ||
49 | -{ | ||
50 | - tcg_gen_sari_i32(a, a, shift); | ||
51 | - tcg_gen_add_i32(d, d, a); | ||
52 | -} | ||
53 | - | ||
54 | -static void gen_ssra64_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
55 | -{ | ||
56 | - tcg_gen_sari_i64(a, a, shift); | ||
57 | - tcg_gen_add_i64(d, d, a); | ||
58 | -} | ||
59 | - | ||
60 | -static void gen_ssra_vec(unsigned vece, TCGv_vec d, TCGv_vec a, int64_t sh) | ||
61 | -{ | ||
62 | - tcg_gen_sari_vec(vece, a, a, sh); | ||
63 | - tcg_gen_add_vec(vece, d, d, a); | ||
64 | -} | ||
65 | - | ||
66 | -static void gen_usra8_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
67 | -{ | ||
68 | - tcg_gen_vec_shr8i_i64(a, a, shift); | ||
69 | - tcg_gen_vec_add8_i64(d, d, a); | ||
70 | -} | ||
71 | - | ||
72 | -static void gen_usra16_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
73 | -{ | ||
74 | - tcg_gen_vec_shr16i_i64(a, a, shift); | ||
75 | - tcg_gen_vec_add16_i64(d, d, a); | ||
76 | -} | ||
77 | - | ||
78 | -static void gen_usra32_i32(TCGv_i32 d, TCGv_i32 a, int32_t shift) | ||
79 | -{ | ||
80 | - tcg_gen_shri_i32(a, a, shift); | ||
81 | - tcg_gen_add_i32(d, d, a); | ||
82 | -} | ||
83 | - | ||
84 | -static void gen_usra64_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
85 | -{ | ||
86 | - tcg_gen_shri_i64(a, a, shift); | ||
87 | - tcg_gen_add_i64(d, d, a); | ||
88 | -} | ||
89 | - | ||
90 | -static void gen_usra_vec(unsigned vece, TCGv_vec d, TCGv_vec a, int64_t sh) | ||
91 | -{ | ||
92 | - tcg_gen_shri_vec(vece, a, a, sh); | ||
93 | - tcg_gen_add_vec(vece, d, d, a); | ||
94 | -} | ||
95 | - | ||
96 | static void gen_shr8_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
97 | { | ||
98 | uint64_t mask = dup_const(MO_8, 0xff >> shift); | ||
99 | @@ -XXX,XX +XXX,XX @@ static void gen_shr_ins_vec(unsigned vece, TCGv_vec d, TCGv_vec a, int64_t sh) | ||
100 | static void handle_vec_simd_shri(DisasContext *s, bool is_q, bool is_u, | ||
101 | int immh, int immb, int opcode, int rn, int rd) | ||
102 | { | ||
103 | - static const GVecGen2i ssra_op[4] = { | ||
104 | - { .fni8 = gen_ssra8_i64, | ||
105 | - .fniv = gen_ssra_vec, | ||
106 | - .load_dest = true, | ||
107 | - .opc = INDEX_op_sari_vec, | ||
108 | - .vece = MO_8 }, | ||
109 | - { .fni8 = gen_ssra16_i64, | ||
110 | - .fniv = gen_ssra_vec, | ||
111 | - .load_dest = true, | ||
112 | - .opc = INDEX_op_sari_vec, | ||
113 | - .vece = MO_16 }, | ||
114 | - { .fni4 = gen_ssra32_i32, | ||
115 | - .fniv = gen_ssra_vec, | ||
116 | - .load_dest = true, | ||
117 | - .opc = INDEX_op_sari_vec, | ||
118 | - .vece = MO_32 }, | ||
119 | - { .fni8 = gen_ssra64_i64, | ||
120 | - .fniv = gen_ssra_vec, | ||
121 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
122 | - .load_dest = true, | ||
123 | - .opc = INDEX_op_sari_vec, | ||
124 | - .vece = MO_64 }, | ||
125 | - }; | ||
126 | - static const GVecGen2i usra_op[4] = { | ||
127 | - { .fni8 = gen_usra8_i64, | ||
128 | - .fniv = gen_usra_vec, | ||
129 | - .load_dest = true, | ||
130 | - .opc = INDEX_op_shri_vec, | ||
131 | - .vece = MO_8, }, | ||
132 | - { .fni8 = gen_usra16_i64, | ||
133 | - .fniv = gen_usra_vec, | ||
134 | - .load_dest = true, | ||
135 | - .opc = INDEX_op_shri_vec, | ||
136 | - .vece = MO_16, }, | ||
137 | - { .fni4 = gen_usra32_i32, | ||
138 | - .fniv = gen_usra_vec, | ||
139 | - .load_dest = true, | ||
140 | - .opc = INDEX_op_shri_vec, | ||
141 | - .vece = MO_32, }, | ||
142 | - { .fni8 = gen_usra64_i64, | ||
143 | - .fniv = gen_usra_vec, | ||
144 | - .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
145 | - .load_dest = true, | ||
146 | - .opc = INDEX_op_shri_vec, | ||
147 | - .vece = MO_64, }, | ||
148 | - }; | ||
149 | static const GVecGen2i sri_op[4] = { | ||
150 | { .fni8 = gen_shr8_ins_i64, | ||
151 | .fniv = gen_shr_ins_vec, | ||
152 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
153 | index XXXXXXX..XXXXXXX 100644 | ||
154 | --- a/target/arm/translate.c | ||
155 | +++ b/target/arm/translate.c | ||
156 | @@ -XXX,XX +XXX,XX @@ const GVecGen3 bif_op = { | ||
157 | .load_dest = true | ||
158 | }; | ||
159 | |||
160 | +static void gen_ssra8_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
161 | +{ | 318 | +{ |
162 | + tcg_gen_vec_sar8i_i64(a, a, shift); | 319 | + CprmanPllState *s = CPRMAN_PLL(dev); |
163 | + tcg_gen_vec_add8_i64(d, d, a); | 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; | ||
164 | +} | 326 | +} |
165 | + | 327 | + |
166 | +static void gen_ssra16_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | 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) | ||
167 | +{ | 344 | +{ |
168 | + tcg_gen_vec_sar16i_i64(a, a, shift); | 345 | + CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(dev); |
169 | + tcg_gen_vec_add16_i64(d, d, a); | 346 | + const PLLChannelResetInfo *info = &PLL_CHANNEL_RESET_INFO[s->id]; |
347 | + | ||
348 | + *s->reg_a2w_ctrl = info->a2w_ctrl; | ||
170 | +} | 349 | +} |
171 | + | 350 | + |
172 | +static void gen_ssra32_i32(TCGv_i32 d, TCGv_i32 a, int32_t shift) | 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) | ||
173 | +{ | 367 | +{ |
174 | + tcg_gen_sari_i32(a, a, shift); | 368 | + CprmanClockMuxState *clock = CPRMAN_CLOCK_MUX(dev); |
175 | + tcg_gen_add_i32(d, d, a); | 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; | ||
176 | +} | 373 | +} |
177 | + | 374 | + |
178 | +static void gen_ssra64_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | 375 | static void clock_mux_init(Object *obj) |
179 | +{ | 376 | { |
180 | + tcg_gen_sari_i64(a, a, shift); | 377 | CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj); |
181 | + tcg_gen_add_i64(d, d, a); | 378 | @@ -XXX,XX +XXX,XX @@ static void clock_mux_class_init(ObjectClass *klass, void *data) |
182 | +} | 379 | { |
183 | + | 380 | DeviceClass *dc = DEVICE_CLASS(klass); |
184 | +static void gen_ssra_vec(unsigned vece, TCGv_vec d, TCGv_vec a, int64_t sh) | 381 | |
185 | +{ | 382 | + dc->reset = clock_mux_reset; |
186 | + tcg_gen_sari_vec(vece, a, a, sh); | 383 | dc->vmsd = &clock_mux_vmstate; |
187 | + tcg_gen_add_vec(vece, d, d, a); | 384 | } |
188 | +} | 385 | |
189 | + | ||
190 | +const GVecGen2i ssra_op[4] = { | ||
191 | + { .fni8 = gen_ssra8_i64, | ||
192 | + .fniv = gen_ssra_vec, | ||
193 | + .load_dest = true, | ||
194 | + .opc = INDEX_op_sari_vec, | ||
195 | + .vece = MO_8 }, | ||
196 | + { .fni8 = gen_ssra16_i64, | ||
197 | + .fniv = gen_ssra_vec, | ||
198 | + .load_dest = true, | ||
199 | + .opc = INDEX_op_sari_vec, | ||
200 | + .vece = MO_16 }, | ||
201 | + { .fni4 = gen_ssra32_i32, | ||
202 | + .fniv = gen_ssra_vec, | ||
203 | + .load_dest = true, | ||
204 | + .opc = INDEX_op_sari_vec, | ||
205 | + .vece = MO_32 }, | ||
206 | + { .fni8 = gen_ssra64_i64, | ||
207 | + .fniv = gen_ssra_vec, | ||
208 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
209 | + .load_dest = true, | ||
210 | + .opc = INDEX_op_sari_vec, | ||
211 | + .vece = MO_64 }, | ||
212 | +}; | ||
213 | + | ||
214 | +static void gen_usra8_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
215 | +{ | ||
216 | + tcg_gen_vec_shr8i_i64(a, a, shift); | ||
217 | + tcg_gen_vec_add8_i64(d, d, a); | ||
218 | +} | ||
219 | + | ||
220 | +static void gen_usra16_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
221 | +{ | ||
222 | + tcg_gen_vec_shr16i_i64(a, a, shift); | ||
223 | + tcg_gen_vec_add16_i64(d, d, a); | ||
224 | +} | ||
225 | + | ||
226 | +static void gen_usra32_i32(TCGv_i32 d, TCGv_i32 a, int32_t shift) | ||
227 | +{ | ||
228 | + tcg_gen_shri_i32(a, a, shift); | ||
229 | + tcg_gen_add_i32(d, d, a); | ||
230 | +} | ||
231 | + | ||
232 | +static void gen_usra64_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
233 | +{ | ||
234 | + tcg_gen_shri_i64(a, a, shift); | ||
235 | + tcg_gen_add_i64(d, d, a); | ||
236 | +} | ||
237 | + | ||
238 | +static void gen_usra_vec(unsigned vece, TCGv_vec d, TCGv_vec a, int64_t sh) | ||
239 | +{ | ||
240 | + tcg_gen_shri_vec(vece, a, a, sh); | ||
241 | + tcg_gen_add_vec(vece, d, d, a); | ||
242 | +} | ||
243 | + | ||
244 | +const GVecGen2i usra_op[4] = { | ||
245 | + { .fni8 = gen_usra8_i64, | ||
246 | + .fniv = gen_usra_vec, | ||
247 | + .load_dest = true, | ||
248 | + .opc = INDEX_op_shri_vec, | ||
249 | + .vece = MO_8, }, | ||
250 | + { .fni8 = gen_usra16_i64, | ||
251 | + .fniv = gen_usra_vec, | ||
252 | + .load_dest = true, | ||
253 | + .opc = INDEX_op_shri_vec, | ||
254 | + .vece = MO_16, }, | ||
255 | + { .fni4 = gen_usra32_i32, | ||
256 | + .fniv = gen_usra_vec, | ||
257 | + .load_dest = true, | ||
258 | + .opc = INDEX_op_shri_vec, | ||
259 | + .vece = MO_32, }, | ||
260 | + { .fni8 = gen_usra64_i64, | ||
261 | + .fniv = gen_usra_vec, | ||
262 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
263 | + .load_dest = true, | ||
264 | + .opc = INDEX_op_shri_vec, | ||
265 | + .vece = MO_64, }, | ||
266 | +}; | ||
267 | |||
268 | /* Translate a NEON data processing instruction. Return nonzero if the | ||
269 | instruction is invalid. | ||
270 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
271 | } | ||
272 | return 0; | ||
273 | |||
274 | + case 1: /* VSRA */ | ||
275 | + /* Right shift comes here negative. */ | ||
276 | + shift = -shift; | ||
277 | + /* Shifts larger than the element size are architecturally | ||
278 | + * valid. Unsigned results in all zeros; signed results | ||
279 | + * in all sign bits. | ||
280 | + */ | ||
281 | + if (!u) { | ||
282 | + tcg_gen_gvec_2i(rd_ofs, rm_ofs, vec_size, vec_size, | ||
283 | + MIN(shift, (8 << size) - 1), | ||
284 | + &ssra_op[size]); | ||
285 | + } else if (shift >= 8 << size) { | ||
286 | + /* rd += 0 */ | ||
287 | + } else { | ||
288 | + tcg_gen_gvec_2i(rd_ofs, rm_ofs, vec_size, vec_size, | ||
289 | + shift, &usra_op[size]); | ||
290 | + } | ||
291 | + return 0; | ||
292 | + | ||
293 | case 5: /* VSHL, VSLI */ | ||
294 | if (!u) { /* VSHL */ | ||
295 | /* Shifts larger than the element size are | ||
296 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
297 | neon_load_reg64(cpu_V0, rm + pass); | ||
298 | tcg_gen_movi_i64(cpu_V1, imm); | ||
299 | switch (op) { | ||
300 | - case 1: /* VSRA */ | ||
301 | - if (u) | ||
302 | - gen_helper_neon_shl_u64(cpu_V0, cpu_V0, cpu_V1); | ||
303 | - else | ||
304 | - gen_helper_neon_shl_s64(cpu_V0, cpu_V0, cpu_V1); | ||
305 | - break; | ||
306 | case 2: /* VRSHR */ | ||
307 | case 3: /* VRSRA */ | ||
308 | if (u) | ||
309 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
310 | default: | ||
311 | g_assert_not_reached(); | ||
312 | } | ||
313 | - if (op == 1 || op == 3) { | ||
314 | + if (op == 3) { | ||
315 | /* Accumulate. */ | ||
316 | neon_load_reg64(cpu_V1, rd + pass); | ||
317 | tcg_gen_add_i64(cpu_V0, cpu_V0, cpu_V1); | ||
318 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
319 | tmp2 = tcg_temp_new_i32(); | ||
320 | tcg_gen_movi_i32(tmp2, imm); | ||
321 | switch (op) { | ||
322 | - case 1: /* VSRA */ | ||
323 | - GEN_NEON_INTEGER_OP(shl); | ||
324 | - break; | ||
325 | case 2: /* VRSHR */ | ||
326 | case 3: /* VRSRA */ | ||
327 | GEN_NEON_INTEGER_OP(rshl); | ||
328 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
329 | } | ||
330 | tcg_temp_free_i32(tmp2); | ||
331 | |||
332 | - if (op == 1 || op == 3) { | ||
333 | + if (op == 3) { | ||
334 | /* Accumulate. */ | ||
335 | tmp2 = neon_load_reg(rd, pass); | ||
336 | gen_neon_add(size, tmp, tmp2); | ||
337 | -- | 386 | -- |
338 | 2.19.1 | 387 | 2.20.1 |
339 | 388 | ||
340 | 389 | diff view generated by jsdifflib |
1 | From: Dongjiu Geng <gengdongjiu@huawei.com> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | This patch extends the qemu-kvm state sync logic with support for | 3 | Add a clock input to the PL011 UART so we can compute the current baud |
4 | KVM_GET/SET_VCPU_EVENTS, giving access to yet missing SError exception. | 4 | rate and trace it. This is intended for developers who wish to use QEMU |
5 | And also it can support the exception state migration. | 5 | to e.g. debug their firmware or to figure out the baud rate configured |
6 | by an unknown/closed source binary. | ||
6 | 7 | ||
7 | The SError exception states include SError pending state and ESR value, | 8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | the kvm_put/get_vcpu_events() will be called when set or get system | 9 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
9 | registers. When do migration, if source machine has SError pending, | 10 | Tested-by: Guenter Roeck <linux@roeck-us.net> |
10 | QEMU will do this migration regardless whether the target machine supports | 11 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
11 | to specify guest ESR value, because if target machine does not support that, | ||
12 | it can also inject the SError with zero ESR value. | ||
13 | |||
14 | Signed-off-by: Dongjiu Geng <gengdongjiu@huawei.com> | ||
15 | Reviewed-by: Andrew Jones <drjones@redhat.com> | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Message-id: 1538067351-23931-3-git-send-email-gengdongjiu@huawei.com | ||
18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
19 | --- | 13 | --- |
20 | target/arm/cpu.h | 7 ++++++ | 14 | include/hw/char/pl011.h | 1 + |
21 | target/arm/kvm_arm.h | 24 ++++++++++++++++++ | 15 | hw/char/pl011.c | 45 +++++++++++++++++++++++++++++++++++++++++ |
22 | target/arm/kvm.c | 60 ++++++++++++++++++++++++++++++++++++++++++++ | 16 | hw/char/trace-events | 1 + |
23 | target/arm/kvm32.c | 13 ++++++++++ | 17 | 3 files changed, 47 insertions(+) |
24 | target/arm/kvm64.c | 13 ++++++++++ | ||
25 | target/arm/machine.c | 22 ++++++++++++++++ | ||
26 | 6 files changed, 139 insertions(+) | ||
27 | 18 | ||
28 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 19 | diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h |
29 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/cpu.h | 21 | --- a/include/hw/char/pl011.h |
31 | +++ b/target/arm/cpu.h | 22 | +++ b/include/hw/char/pl011.h |
32 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | 23 | @@ -XXX,XX +XXX,XX @@ struct PL011State { |
33 | */ | 24 | int read_trigger; |
34 | } exception; | 25 | CharBackend chr; |
35 | 26 | qemu_irq irq[6]; | |
36 | + /* Information associated with an SError */ | 27 | + Clock *clk; |
37 | + struct { | 28 | const unsigned char *id; |
38 | + uint8_t pending; | 29 | }; |
39 | + uint8_t has_esr; | 30 | |
40 | + uint64_t esr; | 31 | diff --git a/hw/char/pl011.c b/hw/char/pl011.c |
41 | + } serror; | 32 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/hw/char/pl011.c | ||
34 | +++ b/hw/char/pl011.c | ||
35 | @@ -XXX,XX +XXX,XX @@ | ||
36 | #include "hw/char/pl011.h" | ||
37 | #include "hw/irq.h" | ||
38 | #include "hw/sysbus.h" | ||
39 | +#include "hw/qdev-clock.h" | ||
40 | #include "migration/vmstate.h" | ||
41 | #include "chardev/char-fe.h" | ||
42 | #include "qemu/log.h" | ||
43 | @@ -XXX,XX +XXX,XX @@ static void pl011_set_read_trigger(PL011State *s) | ||
44 | s->read_trigger = 1; | ||
45 | } | ||
46 | |||
47 | +static unsigned int pl011_get_baudrate(const PL011State *s) | ||
48 | +{ | ||
49 | + uint64_t clk; | ||
42 | + | 50 | + |
43 | /* Thumb-2 EE state. */ | 51 | + if (s->fbrd == 0) { |
44 | uint32_t teecr; | ||
45 | uint32_t teehbr; | ||
46 | diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/target/arm/kvm_arm.h | ||
49 | +++ b/target/arm/kvm_arm.h | ||
50 | @@ -XXX,XX +XXX,XX @@ bool write_kvmstate_to_list(ARMCPU *cpu); | ||
51 | */ | ||
52 | void kvm_arm_reset_vcpu(ARMCPU *cpu); | ||
53 | |||
54 | +/** | ||
55 | + * kvm_arm_init_serror_injection: | ||
56 | + * @cs: CPUState | ||
57 | + * | ||
58 | + * Check whether KVM can set guest SError syndrome. | ||
59 | + */ | ||
60 | +void kvm_arm_init_serror_injection(CPUState *cs); | ||
61 | + | ||
62 | +/** | ||
63 | + * kvm_get_vcpu_events: | ||
64 | + * @cpu: ARMCPU | ||
65 | + * | ||
66 | + * Get VCPU related state from kvm. | ||
67 | + */ | ||
68 | +int kvm_get_vcpu_events(ARMCPU *cpu); | ||
69 | + | ||
70 | +/** | ||
71 | + * kvm_put_vcpu_events: | ||
72 | + * @cpu: ARMCPU | ||
73 | + * | ||
74 | + * Put VCPU related state to kvm. | ||
75 | + */ | ||
76 | +int kvm_put_vcpu_events(ARMCPU *cpu); | ||
77 | + | ||
78 | #ifdef CONFIG_KVM | ||
79 | /** | ||
80 | * kvm_arm_create_scratch_host_vcpu: | ||
81 | diff --git a/target/arm/kvm.c b/target/arm/kvm.c | ||
82 | index XXXXXXX..XXXXXXX 100644 | ||
83 | --- a/target/arm/kvm.c | ||
84 | +++ b/target/arm/kvm.c | ||
85 | @@ -XXX,XX +XXX,XX @@ const KVMCapabilityInfo kvm_arch_required_capabilities[] = { | ||
86 | }; | ||
87 | |||
88 | static bool cap_has_mp_state; | ||
89 | +static bool cap_has_inject_serror_esr; | ||
90 | |||
91 | static ARMHostCPUFeatures arm_host_cpu_features; | ||
92 | |||
93 | @@ -XXX,XX +XXX,XX @@ int kvm_arm_vcpu_init(CPUState *cs) | ||
94 | return kvm_vcpu_ioctl(cs, KVM_ARM_VCPU_INIT, &init); | ||
95 | } | ||
96 | |||
97 | +void kvm_arm_init_serror_injection(CPUState *cs) | ||
98 | +{ | ||
99 | + cap_has_inject_serror_esr = kvm_check_extension(cs->kvm_state, | ||
100 | + KVM_CAP_ARM_INJECT_SERROR_ESR); | ||
101 | +} | ||
102 | + | ||
103 | bool kvm_arm_create_scratch_host_vcpu(const uint32_t *cpus_to_try, | ||
104 | int *fdarray, | ||
105 | struct kvm_vcpu_init *init) | ||
106 | @@ -XXX,XX +XXX,XX @@ int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu) | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | +int kvm_put_vcpu_events(ARMCPU *cpu) | ||
111 | +{ | ||
112 | + CPUARMState *env = &cpu->env; | ||
113 | + struct kvm_vcpu_events events; | ||
114 | + int ret; | ||
115 | + | ||
116 | + if (!kvm_has_vcpu_events()) { | ||
117 | + return 0; | 52 | + return 0; |
118 | + } | 53 | + } |
119 | + | 54 | + |
120 | + memset(&events, 0, sizeof(events)); | 55 | + clk = clock_get_hz(s->clk); |
121 | + events.exception.serror_pending = env->serror.pending; | 56 | + return (clk / ((s->ibrd << 6) + s->fbrd)) << 2; |
122 | + | ||
123 | + /* Inject SError to guest with specified syndrome if host kernel | ||
124 | + * supports it, otherwise inject SError without syndrome. | ||
125 | + */ | ||
126 | + if (cap_has_inject_serror_esr) { | ||
127 | + events.exception.serror_has_esr = env->serror.has_esr; | ||
128 | + events.exception.serror_esr = env->serror.esr; | ||
129 | + } | ||
130 | + | ||
131 | + ret = kvm_vcpu_ioctl(CPU(cpu), KVM_SET_VCPU_EVENTS, &events); | ||
132 | + if (ret) { | ||
133 | + error_report("failed to put vcpu events"); | ||
134 | + } | ||
135 | + | ||
136 | + return ret; | ||
137 | +} | 57 | +} |
138 | + | 58 | + |
139 | +int kvm_get_vcpu_events(ARMCPU *cpu) | 59 | +static void pl011_trace_baudrate_change(const PL011State *s) |
140 | +{ | 60 | +{ |
141 | + CPUARMState *env = &cpu->env; | 61 | + trace_pl011_baudrate_change(pl011_get_baudrate(s), |
142 | + struct kvm_vcpu_events events; | 62 | + clock_get_hz(s->clk), |
143 | + int ret; | 63 | + s->ibrd, s->fbrd); |
144 | + | ||
145 | + if (!kvm_has_vcpu_events()) { | ||
146 | + return 0; | ||
147 | + } | ||
148 | + | ||
149 | + memset(&events, 0, sizeof(events)); | ||
150 | + ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_VCPU_EVENTS, &events); | ||
151 | + if (ret) { | ||
152 | + error_report("failed to get vcpu events"); | ||
153 | + return ret; | ||
154 | + } | ||
155 | + | ||
156 | + env->serror.pending = events.exception.serror_pending; | ||
157 | + env->serror.has_esr = events.exception.serror_has_esr; | ||
158 | + env->serror.esr = events.exception.serror_esr; | ||
159 | + | ||
160 | + return 0; | ||
161 | +} | 64 | +} |
162 | + | 65 | + |
163 | void kvm_arch_pre_run(CPUState *cs, struct kvm_run *run) | 66 | static void pl011_write(void *opaque, hwaddr offset, |
67 | uint64_t value, unsigned size) | ||
164 | { | 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); | ||
165 | } | 83 | } |
166 | diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c | 84 | |
167 | index XXXXXXX..XXXXXXX 100644 | 85 | +static void pl011_clock_update(void *opaque) |
168 | --- a/target/arm/kvm32.c | 86 | +{ |
169 | +++ b/target/arm/kvm32.c | 87 | + PL011State *s = PL011(opaque); |
170 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) | ||
171 | } | ||
172 | cpu->mp_affinity = mpidr & ARM32_AFFINITY_MASK; | ||
173 | |||
174 | + /* Check whether userspace can specify guest syndrome value */ | ||
175 | + kvm_arm_init_serror_injection(cs); | ||
176 | + | 88 | + |
177 | return kvm_arm_init_cpreg_list(cpu); | 89 | + pl011_trace_baudrate_change(s); |
178 | } | ||
179 | |||
180 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level) | ||
181 | return ret; | ||
182 | } | ||
183 | |||
184 | + ret = kvm_put_vcpu_events(cpu); | ||
185 | + if (ret) { | ||
186 | + return ret; | ||
187 | + } | ||
188 | + | ||
189 | /* Note that we do not call write_cpustate_to_list() | ||
190 | * here, so we are only writing the tuple list back to | ||
191 | * KVM. This is safe because nothing can change the | ||
192 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_get_registers(CPUState *cs) | ||
193 | } | ||
194 | vfp_set_fpscr(env, fpscr); | ||
195 | |||
196 | + ret = kvm_get_vcpu_events(cpu); | ||
197 | + if (ret) { | ||
198 | + return ret; | ||
199 | + } | ||
200 | + | ||
201 | if (!write_kvmstate_to_list(cpu)) { | ||
202 | return EINVAL; | ||
203 | } | ||
204 | diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c | ||
205 | index XXXXXXX..XXXXXXX 100644 | ||
206 | --- a/target/arm/kvm64.c | ||
207 | +++ b/target/arm/kvm64.c | ||
208 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) | ||
209 | |||
210 | kvm_arm_init_debug(cs); | ||
211 | |||
212 | + /* Check whether user space can specify guest syndrome value */ | ||
213 | + kvm_arm_init_serror_injection(cs); | ||
214 | + | ||
215 | return kvm_arm_init_cpreg_list(cpu); | ||
216 | } | ||
217 | |||
218 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_put_registers(CPUState *cs, int level) | ||
219 | return ret; | ||
220 | } | ||
221 | |||
222 | + ret = kvm_put_vcpu_events(cpu); | ||
223 | + if (ret) { | ||
224 | + return ret; | ||
225 | + } | ||
226 | + | ||
227 | if (!write_list_to_kvmstate(cpu, level)) { | ||
228 | return EINVAL; | ||
229 | } | ||
230 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_get_registers(CPUState *cs) | ||
231 | } | ||
232 | vfp_set_fpcr(env, fpr); | ||
233 | |||
234 | + ret = kvm_get_vcpu_events(cpu); | ||
235 | + if (ret) { | ||
236 | + return ret; | ||
237 | + } | ||
238 | + | ||
239 | if (!write_kvmstate_to_list(cpu)) { | ||
240 | return EINVAL; | ||
241 | } | ||
242 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
243 | index XXXXXXX..XXXXXXX 100644 | ||
244 | --- a/target/arm/machine.c | ||
245 | +++ b/target/arm/machine.c | ||
246 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_sve = { | ||
247 | }; | ||
248 | #endif /* AARCH64 */ | ||
249 | |||
250 | +static bool serror_needed(void *opaque) | ||
251 | +{ | ||
252 | + ARMCPU *cpu = opaque; | ||
253 | + CPUARMState *env = &cpu->env; | ||
254 | + | ||
255 | + return env->serror.pending != 0; | ||
256 | +} | 90 | +} |
257 | + | 91 | + |
258 | +static const VMStateDescription vmstate_serror = { | 92 | static const MemoryRegionOps pl011_ops = { |
259 | + .name = "cpu/serror", | 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", | ||
260 | + .version_id = 1, | 100 | + .version_id = 1, |
261 | + .minimum_version_id = 1, | 101 | + .minimum_version_id = 1, |
262 | + .needed = serror_needed, | ||
263 | + .fields = (VMStateField[]) { | 102 | + .fields = (VMStateField[]) { |
264 | + VMSTATE_UINT8(env.serror.pending, ARMCPU), | 103 | + VMSTATE_CLOCK(clk, PL011State), |
265 | + VMSTATE_UINT8(env.serror.has_esr, ARMCPU), | ||
266 | + VMSTATE_UINT64(env.serror.esr, ARMCPU), | ||
267 | + VMSTATE_END_OF_LIST() | 104 | + VMSTATE_END_OF_LIST() |
268 | + } | 105 | + } |
269 | +}; | 106 | +}; |
270 | + | 107 | + |
271 | static bool m_needed(void *opaque) | 108 | static const VMStateDescription vmstate_pl011 = { |
272 | { | 109 | .name = "pl011", |
273 | ARMCPU *cpu = opaque; | 110 | .version_id = 2, |
274 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_arm_cpu = { | 111 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pl011 = { |
275 | #ifdef TARGET_AARCH64 | 112 | VMSTATE_INT32(read_count, PL011State), |
276 | &vmstate_sve, | 113 | VMSTATE_INT32(read_trigger, PL011State), |
277 | #endif | 114 | VMSTATE_END_OF_LIST() |
278 | + &vmstate_serror, | 115 | + }, |
279 | NULL | 116 | + .subsections = (const VMStateDescription * []) { |
117 | + &vmstate_pl011_clock, | ||
118 | + NULL | ||
280 | } | 119 | } |
281 | }; | 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" | ||
282 | -- | 143 | -- |
283 | 2.19.1 | 144 | 2.20.1 |
284 | 145 | ||
285 | 146 | diff view generated by jsdifflib |
1 | From: Markus Armbruster <armbru@redhat.com> | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | Device models aren't supposed to go on fishing expeditions for | 3 | Connect the 'uart-out' clock from the CPRMAN to the PL011 instance. |
4 | backends. They should expose suitable properties for the user to set. | ||
5 | For onboard devices, board code sets them. | ||
6 | 4 | ||
7 | Device ssi-sd picks up its block backend in its init() method with | 5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | drive_get_next() instead. This mistake is already marked FIXME since | 6 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
9 | commit af9e40a. | 7 | Tested-by: Guenter Roeck <linux@roeck-us.net> |
10 | 8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | |
11 | Unset user_creatable to remove the mistake from our external | ||
12 | interface. Since the SSI bus doesn't support hotplug, only -device | ||
13 | can be affected. Only certain ARM machines have ssi-sd and provide an | ||
14 | SSI bus for it; this patch breaks -device ssi-sd for these machines. | ||
15 | No actual use of -device ssi-sd is known. | ||
16 | |||
17 | Signed-off-by: Markus Armbruster <armbru@redhat.com> | ||
18 | Acked-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Acked-by: Thomas Huth <thuth@redhat.com> | ||
20 | Message-id: 20181009060835.4608-1-armbru@redhat.com | ||
21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
22 | --- | 10 | --- |
23 | hw/sd/ssi-sd.c | 2 ++ | 11 | hw/arm/bcm2835_peripherals.c | 2 ++ |
24 | 1 file changed, 2 insertions(+) | 12 | 1 file changed, 2 insertions(+) |
25 | 13 | ||
26 | diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c | 14 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c |
27 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/hw/sd/ssi-sd.c | 16 | --- a/hw/arm/bcm2835_peripherals.c |
29 | +++ b/hw/sd/ssi-sd.c | 17 | +++ b/hw/arm/bcm2835_peripherals.c |
30 | @@ -XXX,XX +XXX,XX @@ static void ssi_sd_class_init(ObjectClass *klass, void *data) | 18 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) |
31 | k->cs_polarity = SSI_CS_LOW; | 19 | } |
32 | dc->vmsd = &vmstate_ssi_sd; | 20 | memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET, |
33 | dc->reset = ssi_sd_reset; | 21 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0)); |
34 | + /* Reason: init() method uses drive_get_next() */ | 22 | + qdev_connect_clock_in(DEVICE(&s->uart0), "clk", |
35 | + dc->user_creatable = false; | 23 | + qdev_get_clock_out(DEVICE(&s->cprman), "uart-out")); |
36 | } | 24 | |
37 | 25 | memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET, | |
38 | static const TypeInfo ssi_sd_info = { | 26 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0)); |
39 | -- | 27 | -- |
40 | 2.19.1 | 28 | 2.20.1 |
41 | 29 | ||
42 | 30 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Shashi Mallela <shashi.mallela@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | This is done generically in translator_loop. | 3 | Generic watchdog device model implementation as per ARM SBSA v6.0 |
4 | 4 | ||
5 | Reported-by: Laurent Desnogues <laurent.desnogues@gmail.com> | 5 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> |
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Message-id: 20201027015927.29495-2-shashi.mallela@linaro.org |
7 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
8 | Message-id: 20181011205206.3552-3-richard.henderson@linaro.org | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 9 | --- |
12 | target/arm/translate-a64.c | 1 - | 10 | include/hw/watchdog/sbsa_gwdt.h | 79 +++++++++ |
13 | target/arm/translate.c | 1 - | 11 | hw/watchdog/sbsa_gwdt.c | 293 ++++++++++++++++++++++++++++++++ |
14 | 2 files changed, 2 deletions(-) | 12 | hw/arm/Kconfig | 1 + |
13 | hw/watchdog/Kconfig | 3 + | ||
14 | hw/watchdog/meson.build | 1 + | ||
15 | 5 files changed, 377 insertions(+) | ||
16 | create mode 100644 include/hw/watchdog/sbsa_gwdt.h | ||
17 | create mode 100644 hw/watchdog/sbsa_gwdt.c | ||
15 | 18 | ||
16 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 19 | diff --git a/include/hw/watchdog/sbsa_gwdt.h b/include/hw/watchdog/sbsa_gwdt.h |
20 | new file mode 100644 | ||
21 | index XXXXXXX..XXXXXXX | ||
22 | --- /dev/null | ||
23 | +++ b/include/hw/watchdog/sbsa_gwdt.h | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | +/* | ||
26 | + * Copyright (c) 2020 Linaro Limited | ||
27 | + * | ||
28 | + * Authors: | ||
29 | + * Shashi Mallela <shashi.mallela@linaro.org> | ||
30 | + * | ||
31 | + * This work is licensed under the terms of the GNU GPL, version 2 or (at your | ||
32 | + * option) any later version. See the COPYING file in the top-level directory. | ||
33 | + * | ||
34 | + */ | ||
35 | + | ||
36 | +#ifndef WDT_SBSA_GWDT_H | ||
37 | +#define WDT_SBSA_GWDT_H | ||
38 | + | ||
39 | +#include "qemu/bitops.h" | ||
40 | +#include "hw/sysbus.h" | ||
41 | +#include "hw/irq.h" | ||
42 | + | ||
43 | +#define TYPE_WDT_SBSA "sbsa_gwdt" | ||
44 | +#define SBSA_GWDT(obj) \ | ||
45 | + OBJECT_CHECK(SBSA_GWDTState, (obj), TYPE_WDT_SBSA) | ||
46 | +#define SBSA_GWDT_CLASS(klass) \ | ||
47 | + OBJECT_CLASS_CHECK(SBSA_GWDTClass, (klass), TYPE_WDT_SBSA) | ||
48 | +#define SBSA_GWDT_GET_CLASS(obj) \ | ||
49 | + OBJECT_GET_CLASS(SBSA_GWDTClass, (obj), TYPE_WDT_SBSA) | ||
50 | + | ||
51 | +/* SBSA Generic Watchdog register definitions */ | ||
52 | +/* refresh frame */ | ||
53 | +#define SBSA_GWDT_WRR 0x000 | ||
54 | + | ||
55 | +/* control frame */ | ||
56 | +#define SBSA_GWDT_WCS 0x000 | ||
57 | +#define SBSA_GWDT_WOR 0x008 | ||
58 | +#define SBSA_GWDT_WORU 0x00C | ||
59 | +#define SBSA_GWDT_WCV 0x010 | ||
60 | +#define SBSA_GWDT_WCVU 0x014 | ||
61 | + | ||
62 | +/* Watchdog Interface Identification Register */ | ||
63 | +#define SBSA_GWDT_W_IIDR 0xFCC | ||
64 | + | ||
65 | +/* Watchdog Control and Status Register Bits */ | ||
66 | +#define SBSA_GWDT_WCS_EN BIT(0) | ||
67 | +#define SBSA_GWDT_WCS_WS0 BIT(1) | ||
68 | +#define SBSA_GWDT_WCS_WS1 BIT(2) | ||
69 | + | ||
70 | +#define SBSA_GWDT_WOR_MASK 0x0000FFFF | ||
71 | + | ||
72 | +/* | ||
73 | + * Watchdog Interface Identification Register definition | ||
74 | + * considering JEP106 code for ARM in Bits [11:0] | ||
75 | + */ | ||
76 | +#define SBSA_GWDT_ID 0x1043B | ||
77 | + | ||
78 | +/* 2 Separate memory regions for each of refresh & control register frames */ | ||
79 | +#define SBSA_GWDT_RMMIO_SIZE 0x1000 | ||
80 | +#define SBSA_GWDT_CMMIO_SIZE 0x1000 | ||
81 | + | ||
82 | +#define SBSA_TIMER_FREQ 62500000 /* Hz */ | ||
83 | + | ||
84 | +typedef struct SBSA_GWDTState { | ||
85 | + /* <private> */ | ||
86 | + SysBusDevice parent_obj; | ||
87 | + | ||
88 | + /*< public >*/ | ||
89 | + MemoryRegion rmmio; | ||
90 | + MemoryRegion cmmio; | ||
91 | + qemu_irq irq; | ||
92 | + | ||
93 | + QEMUTimer *timer; | ||
94 | + | ||
95 | + uint32_t id; | ||
96 | + uint32_t wcs; | ||
97 | + uint32_t worl; | ||
98 | + uint32_t woru; | ||
99 | + uint32_t wcvl; | ||
100 | + uint32_t wcvu; | ||
101 | +} SBSA_GWDTState; | ||
102 | + | ||
103 | +#endif /* WDT_SBSA_GWDT_H */ | ||
104 | diff --git a/hw/watchdog/sbsa_gwdt.c b/hw/watchdog/sbsa_gwdt.c | ||
105 | new file mode 100644 | ||
106 | index XXXXXXX..XXXXXXX | ||
107 | --- /dev/null | ||
108 | +++ b/hw/watchdog/sbsa_gwdt.c | ||
109 | @@ -XXX,XX +XXX,XX @@ | ||
110 | +/* | ||
111 | + * Generic watchdog device model for SBSA | ||
112 | + * | ||
113 | + * The watchdog device has been implemented as revision 1 variant of | ||
114 | + * the ARM SBSA specification v6.0 | ||
115 | + * (https://developer.arm.com/documentation/den0029/d?lang=en) | ||
116 | + * | ||
117 | + * Copyright Linaro.org 2020 | ||
118 | + * | ||
119 | + * Authors: | ||
120 | + * Shashi Mallela <shashi.mallela@linaro.org> | ||
121 | + * | ||
122 | + * This work is licensed under the terms of the GNU GPL, version 2 or (at your | ||
123 | + * option) any later version. See the COPYING file in the top-level directory. | ||
124 | + * | ||
125 | + */ | ||
126 | + | ||
127 | +#include "qemu/osdep.h" | ||
128 | +#include "sysemu/reset.h" | ||
129 | +#include "sysemu/watchdog.h" | ||
130 | +#include "hw/watchdog/sbsa_gwdt.h" | ||
131 | +#include "qemu/timer.h" | ||
132 | +#include "migration/vmstate.h" | ||
133 | +#include "qemu/log.h" | ||
134 | +#include "qemu/module.h" | ||
135 | + | ||
136 | +static WatchdogTimerModel model = { | ||
137 | + .wdt_name = TYPE_WDT_SBSA, | ||
138 | + .wdt_description = "SBSA-compliant generic watchdog device", | ||
139 | +}; | ||
140 | + | ||
141 | +static const VMStateDescription vmstate_sbsa_gwdt = { | ||
142 | + .name = "sbsa-gwdt", | ||
143 | + .version_id = 1, | ||
144 | + .minimum_version_id = 1, | ||
145 | + .fields = (VMStateField[]) { | ||
146 | + VMSTATE_TIMER_PTR(timer, SBSA_GWDTState), | ||
147 | + VMSTATE_UINT32(wcs, SBSA_GWDTState), | ||
148 | + VMSTATE_UINT32(worl, SBSA_GWDTState), | ||
149 | + VMSTATE_UINT32(woru, SBSA_GWDTState), | ||
150 | + VMSTATE_UINT32(wcvl, SBSA_GWDTState), | ||
151 | + VMSTATE_UINT32(wcvu, SBSA_GWDTState), | ||
152 | + VMSTATE_END_OF_LIST() | ||
153 | + } | ||
154 | +}; | ||
155 | + | ||
156 | +typedef enum WdtRefreshType { | ||
157 | + EXPLICIT_REFRESH = 0, | ||
158 | + TIMEOUT_REFRESH = 1, | ||
159 | +} WdtRefreshType; | ||
160 | + | ||
161 | +static uint64_t sbsa_gwdt_rread(void *opaque, hwaddr addr, unsigned int size) | ||
162 | +{ | ||
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 | + } | ||
332 | + watchdog_perform_action(); | ||
333 | + } | ||
334 | +} | ||
335 | + | ||
336 | +static const MemoryRegionOps sbsa_gwdt_rops = { | ||
337 | + .read = sbsa_gwdt_rread, | ||
338 | + .write = sbsa_gwdt_rwrite, | ||
339 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
340 | + .valid.min_access_size = 4, | ||
341 | + .valid.max_access_size = 4, | ||
342 | + .valid.unaligned = false, | ||
343 | +}; | ||
344 | + | ||
345 | +static const MemoryRegionOps sbsa_gwdt_ops = { | ||
346 | + .read = sbsa_gwdt_read, | ||
347 | + .write = sbsa_gwdt_write, | ||
348 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
349 | + .valid.min_access_size = 4, | ||
350 | + .valid.max_access_size = 4, | ||
351 | + .valid.unaligned = false, | ||
352 | +}; | ||
353 | + | ||
354 | +static void wdt_sbsa_gwdt_realize(DeviceState *dev, Error **errp) | ||
355 | +{ | ||
356 | + SBSA_GWDTState *s = SBSA_GWDT(dev); | ||
357 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
358 | + | ||
359 | + memory_region_init_io(&s->rmmio, OBJECT(dev), | ||
360 | + &sbsa_gwdt_rops, s, | ||
361 | + "sbsa_gwdt.refresh", | ||
362 | + SBSA_GWDT_RMMIO_SIZE); | ||
363 | + | ||
364 | + memory_region_init_io(&s->cmmio, OBJECT(dev), | ||
365 | + &sbsa_gwdt_ops, s, | ||
366 | + "sbsa_gwdt.control", | ||
367 | + SBSA_GWDT_CMMIO_SIZE); | ||
368 | + | ||
369 | + sysbus_init_mmio(sbd, &s->rmmio); | ||
370 | + sysbus_init_mmio(sbd, &s->cmmio); | ||
371 | + | ||
372 | + sysbus_init_irq(sbd, &s->irq); | ||
373 | + | ||
374 | + s->timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sbsa_gwdt_timer_sysinterrupt, | ||
375 | + dev); | ||
376 | +} | ||
377 | + | ||
378 | +static void wdt_sbsa_gwdt_class_init(ObjectClass *klass, void *data) | ||
379 | +{ | ||
380 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
381 | + | ||
382 | + dc->realize = wdt_sbsa_gwdt_realize; | ||
383 | + dc->reset = wdt_sbsa_gwdt_reset; | ||
384 | + dc->hotpluggable = false; | ||
385 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); | ||
386 | + dc->vmsd = &vmstate_sbsa_gwdt; | ||
387 | +} | ||
388 | + | ||
389 | +static const TypeInfo wdt_sbsa_gwdt_info = { | ||
390 | + .class_init = wdt_sbsa_gwdt_class_init, | ||
391 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
392 | + .name = TYPE_WDT_SBSA, | ||
393 | + .instance_size = sizeof(SBSA_GWDTState), | ||
394 | +}; | ||
395 | + | ||
396 | +static void wdt_sbsa_gwdt_register_types(void) | ||
397 | +{ | ||
398 | + watchdog_add_model(&model); | ||
399 | + type_register_static(&wdt_sbsa_gwdt_info); | ||
400 | +} | ||
401 | + | ||
402 | +type_init(wdt_sbsa_gwdt_register_types) | ||
403 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
17 | index XXXXXXX..XXXXXXX 100644 | 404 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/translate-a64.c | 405 | --- a/hw/arm/Kconfig |
19 | +++ b/target/arm/translate-a64.c | 406 | +++ b/hw/arm/Kconfig |
20 | @@ -XXX,XX +XXX,XX @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, | 407 | @@ -XXX,XX +XXX,XX @@ config SBSA_REF |
21 | 408 | select PL031 # RTC | |
22 | static void aarch64_tr_tb_start(DisasContextBase *db, CPUState *cpu) | 409 | select PL061 # GPIO |
23 | { | 410 | select USB_EHCI_SYSBUS |
24 | - tcg_clear_temp_count(); | 411 | + select WDT_SBSA |
25 | } | 412 | |
26 | 413 | config SABRELITE | |
27 | static void aarch64_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) | 414 | bool |
28 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 415 | diff --git a/hw/watchdog/Kconfig b/hw/watchdog/Kconfig |
29 | index XXXXXXX..XXXXXXX 100644 | 416 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/translate.c | 417 | --- a/hw/watchdog/Kconfig |
31 | +++ b/target/arm/translate.c | 418 | +++ b/hw/watchdog/Kconfig |
32 | @@ -XXX,XX +XXX,XX @@ static void arm_tr_tb_start(DisasContextBase *dcbase, CPUState *cpu) | 419 | @@ -XXX,XX +XXX,XX @@ config WDT_DIAG288 |
33 | tcg_gen_movi_i32(tmp, 0); | 420 | |
34 | store_cpu_field(tmp, condexec_bits); | 421 | config WDT_IMX2 |
35 | } | 422 | bool |
36 | - tcg_clear_temp_count(); | 423 | + |
37 | } | 424 | +config WDT_SBSA |
38 | 425 | + bool | |
39 | static void arm_tr_insn_start(DisasContextBase *dcbase, CPUState *cpu) | 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')) | ||
40 | -- | 435 | -- |
41 | 2.19.1 | 436 | 2.20.1 |
42 | 437 | ||
43 | 438 | diff view generated by jsdifflib |
1 | The HCR_EL2 VI and VF bits are supposed to track whether there is | 1 | From: Shashi Mallela <shashi.mallela@linaro.org> |
---|---|---|---|
2 | a pending virtual IRQ or virtual FIQ. For QEMU we store the | ||
3 | pending VIRQ/VFIQ status in cs->interrupt_request, so this means: | ||
4 | * if the register is read we must get these bit values from | ||
5 | cs->interrupt_request | ||
6 | * if the register is written then we must write the bit | ||
7 | values back into cs->interrupt_request | ||
8 | 2 | ||
3 | Included the newly implemented SBSA generic watchdog device model into | ||
4 | SBSA platform | ||
5 | |||
6 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Message-id: 20201027015927.29495-3-shashi.mallela@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-id: 20181012144235.19646-7-peter.maydell@linaro.org | ||
12 | --- | 10 | --- |
13 | target/arm/helper.c | 47 +++++++++++++++++++++++++++++++++++++++++---- | 11 | hw/arm/sbsa-ref.c | 23 +++++++++++++++++++++++ |
14 | 1 file changed, 43 insertions(+), 4 deletions(-) | 12 | 1 file changed, 23 insertions(+) |
15 | 13 | ||
16 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 14 | diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c |
17 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/helper.c | 16 | --- a/hw/arm/sbsa-ref.c |
19 | +++ b/target/arm/helper.c | 17 | +++ b/hw/arm/sbsa-ref.c |
20 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el3_no_el2_v8_cp_reginfo[] = { | 18 | @@ -XXX,XX +XXX,XX @@ |
21 | static void hcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) | 19 | #include "hw/qdev-properties.h" |
22 | { | 20 | #include "hw/usb.h" |
23 | ARMCPU *cpu = arm_env_get_cpu(env); | 21 | #include "hw/char/pl011.h" |
24 | + CPUState *cs = ENV_GET_CPU(env); | 22 | +#include "hw/watchdog/sbsa_gwdt.h" |
25 | uint64_t valid_mask = HCR_MASK; | 23 | #include "net/net.h" |
26 | 24 | #include "qom/object.h" | |
27 | if (arm_feature(env, ARM_FEATURE_EL3)) { | 25 | |
28 | @@ -XXX,XX +XXX,XX @@ static void hcr_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) | 26 | @@ -XXX,XX +XXX,XX @@ enum { |
29 | /* Clear RES0 bits. */ | 27 | SBSA_GIC_DIST, |
30 | value &= valid_mask; | 28 | SBSA_GIC_REDIST, |
31 | 29 | SBSA_SECURE_EC, | |
32 | + /* | 30 | + SBSA_GWDT, |
33 | + * VI and VF are kept in cs->interrupt_request. Modifying that | 31 | + SBSA_GWDT_REFRESH, |
34 | + * requires that we have the iothread lock, which is done by | 32 | + SBSA_GWDT_CONTROL, |
35 | + * marking the reginfo structs as ARM_CP_IO. | 33 | SBSA_SMMU, |
36 | + * Note that if a write to HCR pends a VIRQ or VFIQ it is never | 34 | SBSA_UART, |
37 | + * possible for it to be taken immediately, because VIRQ and | 35 | SBSA_RTC, |
38 | + * VFIQ are masked unless running at EL0 or EL1, and HCR | 36 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = { |
39 | + * can only be written at EL2. | 37 | [SBSA_GIC_DIST] = { 0x40060000, 0x00010000 }, |
40 | + */ | 38 | [SBSA_GIC_REDIST] = { 0x40080000, 0x04000000 }, |
41 | + g_assert(qemu_mutex_iothread_locked()); | 39 | [SBSA_SECURE_EC] = { 0x50000000, 0x00001000 }, |
42 | + if (value & HCR_VI) { | 40 | + [SBSA_GWDT_REFRESH] = { 0x50010000, 0x00001000 }, |
43 | + cs->interrupt_request |= CPU_INTERRUPT_VIRQ; | 41 | + [SBSA_GWDT_CONTROL] = { 0x50011000, 0x00001000 }, |
44 | + } else { | 42 | [SBSA_UART] = { 0x60000000, 0x00001000 }, |
45 | + cs->interrupt_request &= ~CPU_INTERRUPT_VIRQ; | 43 | [SBSA_RTC] = { 0x60010000, 0x00001000 }, |
46 | + } | 44 | [SBSA_GPIO] = { 0x60020000, 0x00001000 }, |
47 | + if (value & HCR_VF) { | 45 | @@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = { |
48 | + cs->interrupt_request |= CPU_INTERRUPT_VFIQ; | 46 | [SBSA_AHCI] = 10, |
49 | + } else { | 47 | [SBSA_EHCI] = 11, |
50 | + cs->interrupt_request &= ~CPU_INTERRUPT_VFIQ; | 48 | [SBSA_SMMU] = 12, /* ... to 15 */ |
51 | + } | 49 | + [SBSA_GWDT] = 16, |
52 | + value &= ~(HCR_VI | HCR_VF); | 50 | }; |
51 | |||
52 | static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx) | ||
53 | @@ -XXX,XX +XXX,XX @@ static void create_rtc(const SBSAMachineState *sms) | ||
54 | sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic, irq)); | ||
55 | } | ||
56 | |||
57 | +static void create_wdt(const SBSAMachineState *sms) | ||
58 | +{ | ||
59 | + hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base; | ||
60 | + hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base; | ||
61 | + DeviceState *dev = qdev_new(TYPE_WDT_SBSA); | ||
62 | + SysBusDevice *s = SYS_BUS_DEVICE(dev); | ||
63 | + int irq = sbsa_ref_irqmap[SBSA_GWDT]; | ||
53 | + | 64 | + |
54 | /* These bits change the MMU setup: | 65 | + sysbus_realize_and_unref(s, &error_fatal); |
55 | * HCR_VM enables stage 2 translation | 66 | + sysbus_mmio_map(s, 0, rbase); |
56 | * HCR_PTW forbids certain page-table setups | 67 | + sysbus_mmio_map(s, 1, cbase); |
57 | @@ -XXX,XX +XXX,XX @@ static void hcr_writelow(CPUARMState *env, const ARMCPRegInfo *ri, | 68 | + sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq)); |
58 | hcr_write(env, NULL, value); | ||
59 | } | ||
60 | |||
61 | +static uint64_t hcr_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
62 | +{ | ||
63 | + /* The VI and VF bits live in cs->interrupt_request */ | ||
64 | + uint64_t ret = env->cp15.hcr_el2 & ~(HCR_VI | HCR_VF); | ||
65 | + CPUState *cs = ENV_GET_CPU(env); | ||
66 | + | ||
67 | + if (cs->interrupt_request & CPU_INTERRUPT_VIRQ) { | ||
68 | + ret |= HCR_VI; | ||
69 | + } | ||
70 | + if (cs->interrupt_request & CPU_INTERRUPT_VFIQ) { | ||
71 | + ret |= HCR_VF; | ||
72 | + } | ||
73 | + return ret; | ||
74 | +} | 69 | +} |
75 | + | 70 | + |
76 | static const ARMCPRegInfo el2_cp_reginfo[] = { | 71 | static DeviceState *gpio_key_dev; |
77 | { .name = "HCR_EL2", .state = ARM_CP_STATE_AA64, | 72 | static void sbsa_ref_powerdown_req(Notifier *n, void *opaque) |
78 | + .type = ARM_CP_IO, | 73 | { |
79 | .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 0, | 74 | @@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine) |
80 | .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.hcr_el2), | 75 | |
81 | - .writefn = hcr_write }, | 76 | create_rtc(sms); |
82 | + .writefn = hcr_write, .readfn = hcr_read }, | 77 | |
83 | { .name = "HCR", .state = ARM_CP_STATE_AA32, | 78 | + create_wdt(sms); |
84 | - .type = ARM_CP_ALIAS, | 79 | + |
85 | + .type = ARM_CP_ALIAS | ARM_CP_IO, | 80 | create_gpio(sms); |
86 | .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 0, | 81 | |
87 | .access = PL2_RW, .fieldoffset = offsetof(CPUARMState, cp15.hcr_el2), | 82 | create_ahci(sms); |
88 | - .writefn = hcr_writelow }, | ||
89 | + .writefn = hcr_writelow, .readfn = hcr_read }, | ||
90 | { .name = "ELR_EL2", .state = ARM_CP_STATE_AA64, | ||
91 | .type = ARM_CP_ALIAS, | ||
92 | .opc0 = 3, .opc1 = 4, .crn = 4, .crm = 0, .opc2 = 1, | ||
93 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = { | ||
94 | |||
95 | static const ARMCPRegInfo el2_v8_cp_reginfo[] = { | ||
96 | { .name = "HCR2", .state = ARM_CP_STATE_AA32, | ||
97 | - .type = ARM_CP_ALIAS, | ||
98 | + .type = ARM_CP_ALIAS | ARM_CP_IO, | ||
99 | .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 4, | ||
100 | .access = PL2_RW, | ||
101 | .fieldoffset = offsetofhigh32(CPUARMState, cp15.hcr_el2), | ||
102 | -- | 83 | -- |
103 | 2.19.1 | 84 | 2.20.1 |
104 | 85 | ||
105 | 86 | diff view generated by jsdifflib |
1 | Create and use a utility function to extract the EC field | 1 | In ptimer_reload(), we call the callback function provided by the |
---|---|---|---|
2 | from a syndrome, rather than open-coding the shift. | 2 | timer device that is using the ptimer. This callback might disable |
3 | the ptimer. The code mostly handles this correctly, except that | ||
4 | we'll still print the warning about "Timer with delta zero, | ||
5 | disabling" if the now-disabled timer happened to be set such that it | ||
6 | would fire again immediately if it were enabled (eg because the | ||
7 | limit/reload value is zero). | ||
8 | |||
9 | Suppress the spurious warning message and the unnecessary | ||
10 | repeat-deletion of the underlying timer in this case. | ||
3 | 11 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
6 | Message-id: 20181012144235.19646-9-peter.maydell@linaro.org | 14 | Message-id: 20201015151829.14656-2-peter.maydell@linaro.org |
7 | --- | 15 | --- |
8 | target/arm/internals.h | 5 +++++ | 16 | hw/core/ptimer.c | 4 ++++ |
9 | target/arm/helper.c | 4 ++-- | 17 | 1 file changed, 4 insertions(+) |
10 | target/arm/kvm64.c | 2 +- | ||
11 | target/arm/op_helper.c | 2 +- | ||
12 | 4 files changed, 9 insertions(+), 4 deletions(-) | ||
13 | 18 | ||
14 | diff --git a/target/arm/internals.h b/target/arm/internals.h | 19 | diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c |
15 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/internals.h | 21 | --- a/hw/core/ptimer.c |
17 | +++ b/target/arm/internals.h | 22 | +++ b/hw/core/ptimer.c |
18 | @@ -XXX,XX +XXX,XX @@ enum arm_exception_class { | 23 | @@ -XXX,XX +XXX,XX @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) |
19 | #define ARM_EL_IL (1 << ARM_EL_IL_SHIFT) | ||
20 | #define ARM_EL_ISV (1 << ARM_EL_ISV_SHIFT) | ||
21 | |||
22 | +static inline uint32_t syn_get_ec(uint32_t syn) | ||
23 | +{ | ||
24 | + return syn >> ARM_EL_EC_SHIFT; | ||
25 | +} | ||
26 | + | ||
27 | /* Utility functions for constructing various kinds of syndrome value. | ||
28 | * Note that in general we follow the AArch64 syndrome values; in a | ||
29 | * few cases the value in HSR for exceptions taken to AArch32 Hyp | ||
30 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/target/arm/helper.c | ||
33 | +++ b/target/arm/helper.c | ||
34 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_do_interrupt_aarch32(CPUState *cs) | ||
35 | uint32_t moe; | ||
36 | |||
37 | /* If this is a debug exception we must update the DBGDSCR.MOE bits */ | ||
38 | - switch (env->exception.syndrome >> ARM_EL_EC_SHIFT) { | ||
39 | + switch (syn_get_ec(env->exception.syndrome)) { | ||
40 | case EC_BREAKPOINT: | ||
41 | case EC_BREAKPOINT_SAME_EL: | ||
42 | moe = 1; | ||
43 | @@ -XXX,XX +XXX,XX @@ void arm_cpu_do_interrupt(CPUState *cs) | ||
44 | if (qemu_loglevel_mask(CPU_LOG_INT) | ||
45 | && !excp_is_internal(cs->exception_index)) { | ||
46 | qemu_log_mask(CPU_LOG_INT, "...with ESR 0x%x/0x%" PRIx32 "\n", | ||
47 | - env->exception.syndrome >> ARM_EL_EC_SHIFT, | ||
48 | + syn_get_ec(env->exception.syndrome), | ||
49 | env->exception.syndrome); | ||
50 | } | 24 | } |
51 | 25 | ||
52 | diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c | 26 | if (delta == 0) { |
53 | index XXXXXXX..XXXXXXX 100644 | 27 | + if (s->enabled == 0) { |
54 | --- a/target/arm/kvm64.c | 28 | + /* trigger callback disabled the timer already */ |
55 | +++ b/target/arm/kvm64.c | 29 | + return; |
56 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_remove_sw_breakpoint(CPUState *cs, struct kvm_sw_breakpoint *bp) | 30 | + } |
57 | 31 | if (!qtest_enabled()) { | |
58 | bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit) | 32 | fprintf(stderr, "Timer with delta zero, disabling\n"); |
59 | { | ||
60 | - int hsr_ec = debug_exit->hsr >> ARM_EL_EC_SHIFT; | ||
61 | + int hsr_ec = syn_get_ec(debug_exit->hsr); | ||
62 | ARMCPU *cpu = ARM_CPU(cs); | ||
63 | CPUClass *cc = CPU_GET_CLASS(cs); | ||
64 | CPUARMState *env = &cpu->env; | ||
65 | diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/target/arm/op_helper.c | ||
68 | +++ b/target/arm/op_helper.c | ||
69 | @@ -XXX,XX +XXX,XX @@ void raise_exception(CPUARMState *env, uint32_t excp, | ||
70 | * (see DDI0478C.a D1.10.4) | ||
71 | */ | ||
72 | target_el = 2; | ||
73 | - if (syndrome >> ARM_EL_EC_SHIFT == EC_ADVSIMDFPACCESSTRAP) { | ||
74 | + if (syn_get_ec(syndrome) == EC_ADVSIMDFPACCESSTRAP) { | ||
75 | syndrome = syn_uncategorized(); | ||
76 | } | 33 | } |
77 | } | ||
78 | -- | 34 | -- |
79 | 2.19.1 | 35 | 2.20.1 |
80 | 36 | ||
81 | 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 |