1 | Just my fp16 work, plus some small stuff for the sbsa-ref board; | 1 | Last minute pullreq for arm related patches; quite large because |
---|---|---|---|
2 | but my rule of thumb is to send a pullreq once I get over about | 2 | there were several series that only just made it through code review |
3 | 30 patches... | 3 | in time. |
4 | 4 | ||
5 | thanks | ||
5 | -- PMM | 6 | -- PMM |
6 | 7 | ||
7 | The following changes since commit 2f4c51c0f384d7888a04b4815861e6d5fd244d75: | 8 | The following changes since commit 091e3e3dbc499d84c004e1c50bc9870af37f6e99: |
8 | 9 | ||
9 | Merge remote-tracking branch 'remotes/kraxel/tags/usb-20200831-pull-request' into staging (2020-08-31 19:39:13 +0100) | 10 | Merge remote-tracking branch 'remotes/ericb/tags/pull-bitmaps-2020-10-26' into staging (2020-10-26 22:36:35 +0000) |
10 | 11 | ||
11 | are available in the Git repository at: | 12 | are available in the Git repository at: |
12 | 13 | ||
13 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200901 | 14 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20201027-1 |
14 | 15 | ||
15 | for you to fetch changes up to 3f462bf0f6ea6382dd1502d4eb1fcd33c8e774f5: | 16 | for you to fetch changes up to 32bd322a0134ed89db00f2b9b3894982db3dedcb: |
16 | 17 | ||
17 | hw/arm/sbsa-ref : Add embedded controller in secure memory (2020-09-01 14:01:34 +0100) | 18 | hw/timer/armv7m_systick: Rewrite to use ptimers (2020-10-27 11:15:31 +0000) |
18 | 19 | ||
19 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
20 | target-arm queue: | 21 | target-arm queue: |
21 | * Implement fp16 support for AArch32 VFP and Neon | 22 | * raspi: add model of cprman clock manager |
22 | * hw/arm/sbsa-ref: add "reg" property to DT cpu nodes | 23 | * sbsa-ref: add an SBSA generic watchdog device |
23 | * hw/arm/sbsa-ref : Add embedded controller in secure memory | 24 | * arm/trace: Fix hex printing |
25 | * raspi: Add models of Pi 3 model A+, Pi Zero and Pi A+ | ||
26 | * hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly | ||
27 | * Nuvoton NPCM7xx: Add USB, RNG, GPIO and watchdog support | ||
28 | * hw/arm: fix min_cpus for xlnx-versal-virt platform | ||
29 | * hw/arm/highbank: Silence warnings about missing fallthrough statements | ||
30 | * linux-user: Support Aarch64 BTI | ||
31 | * Armv7M systick: fix corner case bugs by rewriting to use ptimer | ||
24 | 32 | ||
25 | ---------------------------------------------------------------- | 33 | ---------------------------------------------------------------- |
26 | Graeme Gregory (2): | 34 | Dr. David Alan Gilbert (1): |
27 | hw/misc/sbsa_ec : Add an embedded controller for sbsa-ref | 35 | arm/trace: Fix hex printing |
28 | hw/arm/sbsa-ref : Add embedded controller in secure memory | ||
29 | 36 | ||
30 | Leif Lindholm (1): | 37 | Hao Wu (1): |
31 | hw/arm/sbsa-ref: add "reg" property to DT cpu nodes | 38 | hw/timer: Adding watchdog for NPCM7XX Timer. |
32 | 39 | ||
33 | Peter Maydell (44): | 40 | Havard Skinnemoen (4): |
34 | target/arm: Remove local definitions of float constants | 41 | Move npcm7xx_timer_reached_zero call out of npcm7xx_timer_pause |
35 | target/arm: Use correct ID register check for aa32_fp16_arith | 42 | hw/misc: Add npcm7xx random number generator |
36 | target/arm: Implement VFP fp16 for VFP_BINOP operations | 43 | hw/arm/npcm7xx: Add EHCI and OHCI controllers |
37 | target/arm: Implement VFP fp16 VMLA, VMLS, VNMLS, VNMLA, VNMUL | 44 | hw/gpio: Add GPIO model for Nuvoton NPCM7xx |
38 | target/arm: Macroify trans functions for VFMA, VFMS, VFNMA, VFNMS | ||
39 | target/arm: Implement VFP fp16 for fused-multiply-add | ||
40 | target/arm: Macroify uses of do_vfp_2op_sp() and do_vfp_2op_dp() | ||
41 | target/arm: Implement VFP fp16 for VABS, VNEG, VSQRT | ||
42 | target/arm: Implement VFP fp16 for VMOV immediate | ||
43 | target/arm: Implement VFP fp16 VCMP | ||
44 | target/arm: Implement VFP fp16 VLDR and VSTR | ||
45 | target/arm: Implement VFP fp16 VCVT between float and integer | ||
46 | target/arm: Make VFP_CONV_FIX macros take separate float type and float size | ||
47 | target/arm: Use macros instead of open-coding fp16 conversion helpers | ||
48 | target/arm: Implement VFP fp16 VCVT between float and fixed-point | ||
49 | target/arm: Implement VFP vp16 VCVT-with-specified-rounding-mode | ||
50 | target/arm: Implement VFP fp16 VSEL | ||
51 | target/arm: Implement VFP fp16 VRINT* | ||
52 | target/arm: Implement new VFP fp16 insn VINS | ||
53 | target/arm: Implement new VFP fp16 insn VMOVX | ||
54 | target/arm: Implement VFP fp16 VMOV between gp and halfprec registers | ||
55 | target/arm: Implement FP16 for Neon VADD, VSUB, VABD, VMUL | ||
56 | target/arm: Implement fp16 for Neon VRECPE, VRSQRTE using gvec | ||
57 | target/arm: Implement fp16 for Neon VABS, VNEG of floats | ||
58 | target/arm: Implement fp16 for VCEQ, VCGE, VCGT comparisons | ||
59 | target/arm: Implement fp16 for VACGE, VACGT | ||
60 | target/arm: Implement fp16 for Neon VMAX, VMIN | ||
61 | target/arm: Implement fp16 for Neon VMAXNM, VMINNM | ||
62 | target/arm: Implement fp16 for Neon VMLA, VMLS operations | ||
63 | target/arm: Implement fp16 for Neon VFMA, VMFS | ||
64 | target/arm: Implement fp16 for Neon fp compare-vs-0 | ||
65 | target/arm: Implement fp16 for Neon VRECPS | ||
66 | target/arm: Implement fp16 for Neon VRSQRTS | ||
67 | target/arm: Implement fp16 for Neon pairwise fp ops | ||
68 | target/arm: Implement fp16 for Neon float-integer VCVT | ||
69 | target/arm: Convert Neon VCVT fixed-point to gvec | ||
70 | target/arm: Implement fp16 for Neon VCVT fixed-point | ||
71 | target/arm: Implement fp16 for Neon VCVT with rounding modes | ||
72 | target/arm: Implement fp16 for Neon VRINT-with-specified-rounding-mode | ||
73 | target/arm: Implement fp16 for Neon VRINTX | ||
74 | target/arm/vec_helper: Handle oprsz less than 16 bytes in indexed operations | ||
75 | target/arm/vec_helper: Add gvec fp indexed multiply-and-add operations | ||
76 | target/arm: Implement fp16 for Neon VMUL, VMLA, VMLS | ||
77 | target/arm: Enable FP16 in '-cpu max' | ||
78 | 45 | ||
79 | target/arm/cpu.h | 7 +- | 46 | Luc Michel (14): |
80 | target/arm/helper.h | 133 ++++++- | 47 | hw/core/clock: provide the VMSTATE_ARRAY_CLOCK macro |
81 | target/arm/neon-dp.decode | 8 +- | 48 | hw/core/clock: trace clock values in Hz instead of ns |
82 | target/arm/vfp-uncond.decode | 27 +- | 49 | hw/arm/raspi: fix CPRMAN base address |
83 | target/arm/vfp.decode | 34 +- | 50 | hw/arm/raspi: add a skeleton implementation of the CPRMAN |
84 | hw/arm/sbsa-ref.c | 43 ++- | 51 | hw/misc/bcm2835_cprman: add a PLL skeleton implementation |
85 | hw/misc/sbsa_ec.c | 98 +++++ | 52 | hw/misc/bcm2835_cprman: implement PLLs behaviour |
86 | target/arm/cpu.c | 3 +- | 53 | hw/misc/bcm2835_cprman: add a PLL channel skeleton implementation |
87 | target/arm/cpu64.c | 10 +- | 54 | hw/misc/bcm2835_cprman: implement PLL channels behaviour |
88 | target/arm/helper-a64.c | 11 - | 55 | hw/misc/bcm2835_cprman: add a clock mux skeleton implementation |
89 | target/arm/translate-sve.c | 4 - | 56 | hw/misc/bcm2835_cprman: implement clock mux behaviour |
90 | target/arm/vec_helper.c | 431 ++++++++++++++++++++- | 57 | hw/misc/bcm2835_cprman: add the DSI0HSCK multiplexer |
91 | target/arm/vfp_helper.c | 244 +++++------- | 58 | hw/misc/bcm2835_cprman: add sane reset values to the registers |
92 | hw/misc/meson.build | 2 + | 59 | hw/char/pl011: add a clock input |
93 | target/arm/translate-neon.c.inc | 755 +++++++++++++------------------------ | 60 | hw/arm/bcm2835_peripherals: connect the UART clock |
94 | target/arm/translate-vfp.c.inc | 810 ++++++++++++++++++++++++++++++++++++---- | ||
95 | 16 files changed, 1819 insertions(+), 801 deletions(-) | ||
96 | create mode 100644 hw/misc/sbsa_ec.c | ||
97 | 61 | ||
62 | Pavel Dovgalyuk (1): | ||
63 | hw/arm: fix min_cpus for xlnx-versal-virt platform | ||
64 | |||
65 | Peter Maydell (2): | ||
66 | hw/core/ptimer: Support ptimer being disabled by timer callback | ||
67 | hw/timer/armv7m_systick: Rewrite to use ptimers | ||
68 | |||
69 | Philippe Mathieu-Daudé (10): | ||
70 | linux-user/elfload: Avoid leaking interp_name using GLib memory API | ||
71 | hw/arm/bcm2836: Restrict BCM283XInfo declaration to C source | ||
72 | hw/arm/bcm2836: QOM'ify more by adding class_init() to each SoC type | ||
73 | hw/arm/bcm2836: Introduce BCM283XClass::core_count | ||
74 | hw/arm/bcm2836: Only provide "enabled-cpus" property to multicore SoCs | ||
75 | hw/arm/bcm2836: Split out common realize() code | ||
76 | hw/arm/bcm2836: Introduce the BCM2835 SoC | ||
77 | hw/arm/raspi: Add the Raspberry Pi A+ machine | ||
78 | hw/arm/raspi: Add the Raspberry Pi Zero machine | ||
79 | hw/arm/raspi: Add the Raspberry Pi 3 model A+ | ||
80 | |||
81 | Richard Henderson (11): | ||
82 | linux-user/aarch64: Reset btype for signals | ||
83 | linux-user: Set PAGE_TARGET_1 for TARGET_PROT_BTI | ||
84 | include/elf: Add defines related to GNU property notes for AArch64 | ||
85 | linux-user/elfload: Fix coding style in load_elf_image | ||
86 | linux-user/elfload: Adjust iteration over phdr | ||
87 | linux-user/elfload: Move PT_INTERP detection to first loop | ||
88 | linux-user/elfload: Use Error for load_elf_image | ||
89 | linux-user/elfload: Use Error for load_elf_interp | ||
90 | linux-user/elfload: Parse NT_GNU_PROPERTY_TYPE_0 notes | ||
91 | linux-user/elfload: Parse GNU_PROPERTY_AARCH64_FEATURE_1_AND | ||
92 | tests/tcg/aarch64: Add bti smoke tests | ||
93 | |||
94 | Shashi Mallela (2): | ||
95 | hw/watchdog: Implement SBSA watchdog device | ||
96 | hw/arm/sbsa-ref: add SBSA watchdog device | ||
97 | |||
98 | Thomas Huth (1): | ||
99 | hw/arm/highbank: Silence warnings about missing fallthrough statements | ||
100 | |||
101 | Zenghui Yu (1): | ||
102 | hw/arm/smmuv3: Set the restoration priority of the vSMMUv3 explicitly | ||
103 | |||
104 | docs/system/arm/nuvoton.rst | 6 +- | ||
105 | hw/usb/hcd-ehci.h | 1 + | ||
106 | include/elf.h | 22 + | ||
107 | include/exec/cpu-all.h | 2 + | ||
108 | include/hw/arm/bcm2835_peripherals.h | 5 +- | ||
109 | include/hw/arm/bcm2836.h | 9 +- | ||
110 | include/hw/arm/npcm7xx.h | 8 + | ||
111 | include/hw/arm/raspi_platform.h | 5 +- | ||
112 | include/hw/char/pl011.h | 1 + | ||
113 | include/hw/clock.h | 5 + | ||
114 | include/hw/gpio/npcm7xx_gpio.h | 55 ++ | ||
115 | include/hw/misc/bcm2835_cprman.h | 210 ++++++ | ||
116 | include/hw/misc/bcm2835_cprman_internals.h | 1019 ++++++++++++++++++++++++++++ | ||
117 | include/hw/misc/npcm7xx_clk.h | 2 + | ||
118 | include/hw/misc/npcm7xx_rng.h | 34 + | ||
119 | include/hw/timer/armv7m_systick.h | 3 +- | ||
120 | include/hw/timer/npcm7xx_timer.h | 48 +- | ||
121 | include/hw/watchdog/sbsa_gwdt.h | 79 +++ | ||
122 | linux-user/qemu.h | 4 + | ||
123 | linux-user/syscall_defs.h | 4 + | ||
124 | target/arm/cpu.h | 5 + | ||
125 | hw/arm/bcm2835_peripherals.c | 15 +- | ||
126 | hw/arm/bcm2836.c | 182 +++-- | ||
127 | hw/arm/highbank.c | 2 + | ||
128 | hw/arm/npcm7xx.c | 126 +++- | ||
129 | hw/arm/raspi.c | 41 ++ | ||
130 | hw/arm/sbsa-ref.c | 23 + | ||
131 | hw/arm/smmuv3.c | 1 + | ||
132 | hw/arm/xlnx-versal-virt.c | 1 + | ||
133 | hw/char/pl011.c | 45 ++ | ||
134 | hw/core/clock.c | 6 +- | ||
135 | hw/core/ptimer.c | 4 + | ||
136 | hw/gpio/npcm7xx_gpio.c | 424 ++++++++++++ | ||
137 | hw/misc/bcm2835_cprman.c | 808 ++++++++++++++++++++++ | ||
138 | hw/misc/npcm7xx_clk.c | 28 + | ||
139 | hw/misc/npcm7xx_rng.c | 180 +++++ | ||
140 | hw/timer/armv7m_systick.c | 124 ++-- | ||
141 | hw/timer/npcm7xx_timer.c | 270 ++++++-- | ||
142 | hw/usb/hcd-ehci-sysbus.c | 19 + | ||
143 | hw/watchdog/sbsa_gwdt.c | 293 ++++++++ | ||
144 | linux-user/aarch64/signal.c | 10 +- | ||
145 | linux-user/elfload.c | 326 +++++++-- | ||
146 | linux-user/mmap.c | 16 + | ||
147 | target/arm/translate-a64.c | 6 +- | ||
148 | tests/qtest/npcm7xx_gpio-test.c | 385 +++++++++++ | ||
149 | tests/qtest/npcm7xx_rng-test.c | 278 ++++++++ | ||
150 | tests/qtest/npcm7xx_watchdog_timer-test.c | 319 +++++++++ | ||
151 | tests/tcg/aarch64/bti-1.c | 62 ++ | ||
152 | tests/tcg/aarch64/bti-2.c | 116 ++++ | ||
153 | tests/tcg/aarch64/bti-crt.inc.c | 51 ++ | ||
154 | MAINTAINERS | 1 + | ||
155 | hw/arm/Kconfig | 1 + | ||
156 | hw/arm/trace-events | 2 +- | ||
157 | hw/char/trace-events | 1 + | ||
158 | hw/core/trace-events | 4 +- | ||
159 | hw/gpio/meson.build | 1 + | ||
160 | hw/gpio/trace-events | 7 + | ||
161 | hw/misc/meson.build | 2 + | ||
162 | hw/misc/trace-events | 9 + | ||
163 | hw/watchdog/Kconfig | 3 + | ||
164 | hw/watchdog/meson.build | 1 + | ||
165 | tests/qtest/meson.build | 6 +- | ||
166 | tests/tcg/aarch64/Makefile.target | 10 + | ||
167 | tests/tcg/configure.sh | 4 + | ||
168 | 64 files changed, 5461 insertions(+), 279 deletions(-) | ||
169 | create mode 100644 include/hw/gpio/npcm7xx_gpio.h | ||
170 | create mode 100644 include/hw/misc/bcm2835_cprman.h | ||
171 | create mode 100644 include/hw/misc/bcm2835_cprman_internals.h | ||
172 | create mode 100644 include/hw/misc/npcm7xx_rng.h | ||
173 | create mode 100644 include/hw/watchdog/sbsa_gwdt.h | ||
174 | create mode 100644 hw/gpio/npcm7xx_gpio.c | ||
175 | create mode 100644 hw/misc/bcm2835_cprman.c | ||
176 | create mode 100644 hw/misc/npcm7xx_rng.c | ||
177 | create mode 100644 hw/watchdog/sbsa_gwdt.c | ||
178 | create mode 100644 tests/qtest/npcm7xx_gpio-test.c | ||
179 | create mode 100644 tests/qtest/npcm7xx_rng-test.c | ||
180 | create mode 100644 tests/qtest/npcm7xx_watchdog_timer-test.c | ||
181 | create mode 100644 tests/tcg/aarch64/bti-1.c | ||
182 | create mode 100644 tests/tcg/aarch64/bti-2.c | ||
183 | create mode 100644 tests/tcg/aarch64/bti-crt.inc.c | ||
184 | diff view generated by jsdifflib |
1 | Convert the Neon VRINT-with-specified-rounding-mode insns to gvec, | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | and use this to implement the fp16 versions. | ||
3 | 2 | ||
3 | The kernel sets btype for the signal handler as if for a call. | ||
4 | |||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20201021173749.111103-2-richard.henderson@linaro.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-41-peter.maydell@linaro.org | ||
7 | --- | 9 | --- |
8 | target/arm/helper.h | 4 +- | 10 | linux-user/aarch64/signal.c | 10 ++++++++-- |
9 | target/arm/vec_helper.c | 21 +++++++++++ | 11 | 1 file changed, 8 insertions(+), 2 deletions(-) |
10 | target/arm/vfp_helper.c | 17 --------- | ||
11 | target/arm/translate-neon.c.inc | 67 +++------------------------------ | ||
12 | 4 files changed, 30 insertions(+), 79 deletions(-) | ||
13 | 12 | ||
14 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 13 | diff --git a/linux-user/aarch64/signal.c b/linux-user/aarch64/signal.c |
15 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/helper.h | 15 | --- a/linux-user/aarch64/signal.c |
17 | +++ b/target/arm/helper.h | 16 | +++ b/linux-user/aarch64/signal.c |
18 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(vfp_sqtoh, f16, i64, i32, ptr) | 17 | @@ -XXX,XX +XXX,XX @@ static void target_setup_frame(int usig, struct target_sigaction *ka, |
19 | DEF_HELPER_3(vfp_uqtoh, f16, i64, i32, ptr) | 18 | + offsetof(struct target_rt_frame_record, tramp); |
20 | 19 | } | |
21 | DEF_HELPER_FLAGS_2(set_rmode, TCG_CALL_NO_RWG, i32, i32, ptr) | 20 | env->xregs[0] = usig; |
22 | -DEF_HELPER_FLAGS_2(set_neon_rmode, TCG_CALL_NO_RWG, i32, i32, env) | 21 | - env->xregs[31] = frame_addr; |
23 | 22 | env->xregs[29] = frame_addr + fr_ofs; | |
24 | DEF_HELPER_FLAGS_3(vfp_fcvt_f16_to_f32, TCG_CALL_NO_RWG, f32, f16, ptr, i32) | 23 | - env->pc = ka->_sa_handler; |
25 | DEF_HELPER_FLAGS_3(vfp_fcvt_f32_to_f16, TCG_CALL_NO_RWG, f16, f32, ptr, i32) | 24 | env->xregs[30] = return_addr; |
26 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(gvec_vcvt_rm_us, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 25 | + env->xregs[31] = frame_addr; |
27 | DEF_HELPER_FLAGS_4(gvec_vcvt_rm_sh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 26 | + env->pc = ka->_sa_handler; |
28 | DEF_HELPER_FLAGS_4(gvec_vcvt_rm_uh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
29 | |||
30 | +DEF_HELPER_FLAGS_4(gvec_vrint_rm_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
31 | +DEF_HELPER_FLAGS_4(gvec_vrint_rm_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
32 | + | 27 | + |
33 | DEF_HELPER_FLAGS_4(gvec_frecpe_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 28 | + /* Invoke the signal handler as if by indirect call. */ |
34 | DEF_HELPER_FLAGS_4(gvec_frecpe_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 29 | + if (cpu_isar_feature(aa64_bti, env_archcpu(env))) { |
35 | DEF_HELPER_FLAGS_4(gvec_frecpe_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 30 | + env->btype = 2; |
36 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/arm/vec_helper.c | ||
39 | +++ b/target/arm/vec_helper.c | ||
40 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_RMODE(gvec_vcvt_rm_sh, helper_vfp_toshh, uint16_t) | ||
41 | DO_VCVT_RMODE(gvec_vcvt_rm_uh, helper_vfp_touhh, uint16_t) | ||
42 | |||
43 | #undef DO_VCVT_RMODE | ||
44 | + | ||
45 | +#define DO_VRINT_RMODE(NAME, FUNC, TYPE) \ | ||
46 | + void HELPER(NAME)(void *vd, void *vn, void *stat, uint32_t desc) \ | ||
47 | + { \ | ||
48 | + float_status *fpst = stat; \ | ||
49 | + intptr_t i, oprsz = simd_oprsz(desc); \ | ||
50 | + uint32_t rmode = simd_data(desc); \ | ||
51 | + uint32_t prev_rmode = get_float_rounding_mode(fpst); \ | ||
52 | + TYPE *d = vd, *n = vn; \ | ||
53 | + set_float_rounding_mode(rmode, fpst); \ | ||
54 | + for (i = 0; i < oprsz / sizeof(TYPE); i++) { \ | ||
55 | + d[i] = FUNC(n[i], fpst); \ | ||
56 | + } \ | ||
57 | + set_float_rounding_mode(prev_rmode, fpst); \ | ||
58 | + clear_tail(d, oprsz, simd_maxsz(desc)); \ | ||
59 | + } | 31 | + } |
60 | + | 32 | + |
61 | +DO_VRINT_RMODE(gvec_vrint_rm_h, helper_rinth, uint16_t) | 33 | if (info) { |
62 | +DO_VRINT_RMODE(gvec_vrint_rm_s, helper_rints, uint32_t) | 34 | tswap_siginfo(&frame->info, info); |
63 | + | 35 | env->xregs[1] = frame_addr + offsetof(struct target_rt_sigframe, info); |
64 | +#undef DO_VRINT_RMODE | ||
65 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/target/arm/vfp_helper.c | ||
68 | +++ b/target/arm/vfp_helper.c | ||
69 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(set_rmode)(uint32_t rmode, void *fpstp) | ||
70 | return prev_rmode; | ||
71 | } | ||
72 | |||
73 | -/* Set the current fp rounding mode in the standard fp status and return | ||
74 | - * the old one. This is for NEON instructions that need to change the | ||
75 | - * rounding mode but wish to use the standard FPSCR values for everything | ||
76 | - * else. Always set the rounding mode back to the correct value after | ||
77 | - * modifying it. | ||
78 | - * The argument is a softfloat float_round_ value. | ||
79 | - */ | ||
80 | -uint32_t HELPER(set_neon_rmode)(uint32_t rmode, CPUARMState *env) | ||
81 | -{ | ||
82 | - float_status *fp_status = &env->vfp.standard_fp_status; | ||
83 | - | ||
84 | - uint32_t prev_rmode = get_float_rounding_mode(fp_status); | ||
85 | - set_float_rounding_mode(rmode, fp_status); | ||
86 | - | ||
87 | - return prev_rmode; | ||
88 | -} | ||
89 | - | ||
90 | /* Half precision conversions. */ | ||
91 | float32 HELPER(vfp_fcvt_f16_to_f32)(uint32_t a, void *fpstp, uint32_t ahp_mode) | ||
92 | { | ||
93 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
94 | index XXXXXXX..XXXXXXX 100644 | ||
95 | --- a/target/arm/translate-neon.c.inc | ||
96 | +++ b/target/arm/translate-neon.c.inc | ||
97 | @@ -XXX,XX +XXX,XX @@ static bool trans_VRINTX(DisasContext *s, arg_2misc *a) | ||
98 | return do_2misc_fp(s, a, gen_helper_rints_exact); | ||
99 | } | ||
100 | |||
101 | -static bool do_vrint(DisasContext *s, arg_2misc *a, int rmode) | ||
102 | -{ | ||
103 | - /* | ||
104 | - * Handle a VRINT* operation by iterating 32 bits at a time, | ||
105 | - * with a specified rounding mode in operation. | ||
106 | - */ | ||
107 | - int pass; | ||
108 | - TCGv_ptr fpst; | ||
109 | - TCGv_i32 tcg_rmode; | ||
110 | - | ||
111 | - if (!arm_dc_feature(s, ARM_FEATURE_NEON) || | ||
112 | - !arm_dc_feature(s, ARM_FEATURE_V8)) { | ||
113 | - return false; | ||
114 | - } | ||
115 | - | ||
116 | - /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
117 | - if (!dc_isar_feature(aa32_simd_r32, s) && | ||
118 | - ((a->vd | a->vm) & 0x10)) { | ||
119 | - return false; | ||
120 | - } | ||
121 | - | ||
122 | - if (a->size != 2) { | ||
123 | - /* TODO: FP16 will be the size == 1 case */ | ||
124 | - return false; | ||
125 | - } | ||
126 | - | ||
127 | - if ((a->vd | a->vm) & a->q) { | ||
128 | - return false; | ||
129 | - } | ||
130 | - | ||
131 | - if (!vfp_access_check(s)) { | ||
132 | - return true; | ||
133 | - } | ||
134 | - | ||
135 | - fpst = fpstatus_ptr(FPST_STD); | ||
136 | - tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode)); | ||
137 | - gen_helper_set_neon_rmode(tcg_rmode, tcg_rmode, cpu_env); | ||
138 | - for (pass = 0; pass < (a->q ? 4 : 2); pass++) { | ||
139 | - TCGv_i32 tmp = neon_load_reg(a->vm, pass); | ||
140 | - gen_helper_rints(tmp, tmp, fpst); | ||
141 | - neon_store_reg(a->vd, pass, tmp); | ||
142 | - } | ||
143 | - gen_helper_set_neon_rmode(tcg_rmode, tcg_rmode, cpu_env); | ||
144 | - tcg_temp_free_i32(tcg_rmode); | ||
145 | - tcg_temp_free_ptr(fpst); | ||
146 | - | ||
147 | - return true; | ||
148 | -} | ||
149 | - | ||
150 | -#define DO_VRINT(INSN, RMODE) \ | ||
151 | - static bool trans_##INSN(DisasContext *s, arg_2misc *a) \ | ||
152 | - { \ | ||
153 | - return do_vrint(s, a, RMODE); \ | ||
154 | - } | ||
155 | - | ||
156 | -DO_VRINT(VRINTN, FPROUNDING_TIEEVEN) | ||
157 | -DO_VRINT(VRINTA, FPROUNDING_TIEAWAY) | ||
158 | -DO_VRINT(VRINTZ, FPROUNDING_ZERO) | ||
159 | -DO_VRINT(VRINTM, FPROUNDING_NEGINF) | ||
160 | -DO_VRINT(VRINTP, FPROUNDING_POSINF) | ||
161 | - | ||
162 | #define DO_VEC_RMODE(INSN, RMODE, OP) \ | ||
163 | static void gen_##INSN(unsigned vece, uint32_t rd_ofs, \ | ||
164 | uint32_t rm_ofs, \ | ||
165 | @@ -XXX,XX +XXX,XX @@ DO_VEC_RMODE(VCVTPS, FPROUNDING_POSINF, vcvt_rm_s) | ||
166 | DO_VEC_RMODE(VCVTMU, FPROUNDING_NEGINF, vcvt_rm_u) | ||
167 | DO_VEC_RMODE(VCVTMS, FPROUNDING_NEGINF, vcvt_rm_s) | ||
168 | |||
169 | +DO_VEC_RMODE(VRINTN, FPROUNDING_TIEEVEN, vrint_rm_) | ||
170 | +DO_VEC_RMODE(VRINTA, FPROUNDING_TIEAWAY, vrint_rm_) | ||
171 | +DO_VEC_RMODE(VRINTZ, FPROUNDING_ZERO, vrint_rm_) | ||
172 | +DO_VEC_RMODE(VRINTM, FPROUNDING_NEGINF, vrint_rm_) | ||
173 | +DO_VEC_RMODE(VRINTP, FPROUNDING_POSINF, vrint_rm_) | ||
174 | + | ||
175 | static bool trans_VSWP(DisasContext *s, arg_2misc *a) | ||
176 | { | ||
177 | TCGv_i64 rm, rd; | ||
178 | -- | 36 | -- |
179 | 2.20.1 | 37 | 2.20.1 |
180 | 38 | ||
181 | 39 | diff view generated by jsdifflib |
1 | The aa32_fp16_arith feature check function currently looks at the | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | AArch64 ID_AA64PFR0 register. This is (as the comment notes) not | ||
3 | correct. The bogus check was put in mostly to allow testing of the | ||
4 | fp16 variants of the VCMLA instructions and it was something of | ||
5 | a mistake that we allowed them to exist in master. | ||
6 | 2 | ||
7 | Switch the feature check function to testing VMFR1.FPHP, which is | 3 | Transform the prot bit to a qemu internal page bit, and save |
8 | what it ought to be. | 4 | it in the page tables. |
9 | 5 | ||
10 | This will remove emulation of the VCMLA and VCADD insns from | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
11 | AArch32 code running on an AArch64 '-cpu max' using system emulation. | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
12 | (They were never enabled for aarch32 linux-user and system-emulation.) | 8 | Message-id: 20201021173749.111103-3-richard.henderson@linaro.org |
13 | Since we weren't advertising their existence via the AArch32 ID | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | register, well-behaved guests wouldn't have been using them anyway. | 10 | --- |
11 | include/exec/cpu-all.h | 2 ++ | ||
12 | linux-user/syscall_defs.h | 4 ++++ | ||
13 | target/arm/cpu.h | 5 +++++ | ||
14 | linux-user/mmap.c | 16 ++++++++++++++++ | ||
15 | target/arm/translate-a64.c | 6 +++--- | ||
16 | 5 files changed, 30 insertions(+), 3 deletions(-) | ||
15 | 17 | ||
16 | Once we have implemented all the AArch32 support for the FP16 extension | 18 | diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h |
17 | we will advertise it in the MVFR1 ID register field, which will reenable | 19 | index XXXXXXX..XXXXXXX 100644 |
18 | these insns along with all the others. | 20 | --- a/include/exec/cpu-all.h |
19 | 21 | +++ b/include/exec/cpu-all.h | |
20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 22 | @@ -XXX,XX +XXX,XX @@ extern intptr_t qemu_host_page_mask; |
21 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 23 | /* FIXME: Code that sets/uses this is broken and needs to go away. */ |
22 | Message-id: 20200828183354.27913-3-peter.maydell@linaro.org | 24 | #define PAGE_RESERVED 0x0020 |
23 | --- | 25 | #endif |
24 | target/arm/cpu.h | 7 +------ | 26 | +/* Target-specific bits that will be used via page_get_flags(). */ |
25 | 1 file changed, 1 insertion(+), 6 deletions(-) | 27 | +#define PAGE_TARGET_1 0x0080 |
26 | 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 */ | ||
27 | 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 |
28 | index XXXXXXX..XXXXXXX 100644 | 47 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/target/arm/cpu.h | 48 | --- a/target/arm/cpu.h |
30 | +++ b/target/arm/cpu.h | 49 | +++ b/target/arm/cpu.h |
31 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa32_predinv(const ARMISARegisters *id) | 50 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) |
32 | 51 | #define arm_tlb_bti_gp(x) (typecheck_memtxattrs(x)->target_tlb_bit0) | |
33 | static inline bool isar_feature_aa32_fp16_arith(const ARMISARegisters *id) | 52 | #define arm_tlb_mte_tagged(x) (typecheck_memtxattrs(x)->target_tlb_bit1) |
53 | |||
54 | +/* | ||
55 | + * AArch64 usage of the PAGE_TARGET_* bits for linux-user. | ||
56 | + */ | ||
57 | +#define PAGE_BTI PAGE_TARGET_1 | ||
58 | + | ||
59 | /* | ||
60 | * Naming convention for isar_feature functions: | ||
61 | * Functions which test 32-bit ID registers should have _aa32_ in | ||
62 | diff --git a/linux-user/mmap.c b/linux-user/mmap.c | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/linux-user/mmap.c | ||
65 | +++ b/linux-user/mmap.c | ||
66 | @@ -XXX,XX +XXX,XX @@ static int validate_prot_to_pageflags(int *host_prot, int prot) | ||
67 | *host_prot = (prot & (PROT_READ | PROT_WRITE)) | ||
68 | | (prot & PROT_EXEC ? PROT_READ : 0); | ||
69 | |||
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; | ||
87 | } | ||
88 | |||
89 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/target/arm/translate-a64.c | ||
92 | +++ b/target/arm/translate-a64.c | ||
93 | @@ -XXX,XX +XXX,XX @@ static void disas_data_proc_simd_fp(DisasContext *s, uint32_t insn) | ||
94 | */ | ||
95 | static bool is_guarded_page(CPUARMState *env, DisasContext *s) | ||
34 | { | 96 | { |
35 | - /* | 97 | -#ifdef CONFIG_USER_ONLY |
36 | - * This is a placeholder for use by VCMA until the rest of | 98 | - return false; /* FIXME */ |
37 | - * the ARMv8.2-FP16 extension is implemented for aa32 mode. | 99 | -#else |
38 | - * At which point we can properly set and check MVFR1.FPHP. | 100 | uint64_t addr = s->base.pc_first; |
39 | - */ | 101 | +#ifdef CONFIG_USER_ONLY |
40 | - return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, FP) == 1; | 102 | + return page_get_flags(addr) & PAGE_BTI; |
41 | + return FIELD_EX32(id->mvfr1, MVFR1, FPHP) >= 3; | 103 | +#else |
42 | } | 104 | int mmu_idx = arm_to_core_mmu_idx(s->mmu_idx); |
43 | 105 | unsigned int index = tlb_index(env, mmu_idx, addr); | |
44 | static inline bool isar_feature_aa32_vfp_simd(const ARMISARegisters *id) | 106 | CPUTLBEntry *entry = tlb_entry(env, mmu_idx, addr); |
45 | -- | 107 | -- |
46 | 2.20.1 | 108 | 2.20.1 |
47 | 109 | ||
48 | 110 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | These are all of the defines required to parse | ||
4 | GNU_PROPERTY_AARCH64_FEATURE_1_AND, copied from binutils. | ||
5 | Other missing defines related to other GNU program headers | ||
6 | and notes are elided for now. | ||
7 | |||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20201021173749.111103-4-richard.henderson@linaro.org | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | include/elf.h | 22 ++++++++++++++++++++++ | ||
14 | 1 file changed, 22 insertions(+) | ||
15 | |||
16 | diff --git a/include/elf.h b/include/elf.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/elf.h | ||
19 | +++ b/include/elf.h | ||
20 | @@ -XXX,XX +XXX,XX @@ typedef int64_t Elf64_Sxword; | ||
21 | #define PT_NOTE 4 | ||
22 | #define PT_SHLIB 5 | ||
23 | #define PT_PHDR 6 | ||
24 | +#define PT_LOOS 0x60000000 | ||
25 | +#define PT_HIOS 0x6fffffff | ||
26 | #define PT_LOPROC 0x70000000 | ||
27 | #define PT_HIPROC 0x7fffffff | ||
28 | |||
29 | +#define PT_GNU_PROPERTY (PT_LOOS + 0x474e553) | ||
30 | + | ||
31 | #define PT_MIPS_REGINFO 0x70000000 | ||
32 | #define PT_MIPS_RTPROC 0x70000001 | ||
33 | #define PT_MIPS_OPTIONS 0x70000002 | ||
34 | @@ -XXX,XX +XXX,XX @@ typedef struct elf64_shdr { | ||
35 | #define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */ | ||
36 | #define NT_ARM_SVE 0x405 /* ARM Scalable Vector Extension regs */ | ||
37 | |||
38 | +/* Defined note types for GNU systems. */ | ||
39 | + | ||
40 | +#define NT_GNU_PROPERTY_TYPE_0 5 /* Program property */ | ||
41 | + | ||
42 | +/* Values used in GNU .note.gnu.property notes (NT_GNU_PROPERTY_TYPE_0). */ | ||
43 | + | ||
44 | +#define GNU_PROPERTY_STACK_SIZE 1 | ||
45 | +#define GNU_PROPERTY_NO_COPY_ON_PROTECTED 2 | ||
46 | + | ||
47 | +#define GNU_PROPERTY_LOPROC 0xc0000000 | ||
48 | +#define GNU_PROPERTY_HIPROC 0xdfffffff | ||
49 | +#define GNU_PROPERTY_LOUSER 0xe0000000 | ||
50 | +#define GNU_PROPERTY_HIUSER 0xffffffff | ||
51 | + | ||
52 | +#define GNU_PROPERTY_AARCH64_FEATURE_1_AND 0xc0000000 | ||
53 | +#define GNU_PROPERTY_AARCH64_FEATURE_1_BTI (1u << 0) | ||
54 | +#define GNU_PROPERTY_AARCH64_FEATURE_1_PAC (1u << 1) | ||
55 | + | ||
56 | /* | ||
57 | * Physical entry point into the kernel. | ||
58 | * | ||
59 | -- | ||
60 | 2.20.1 | ||
61 | |||
62 | diff view generated by jsdifflib |
1 | Convert the Neon VCVT with-specified-rounding-mode instructions | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | to gvec, and use this to implement fp16 support for them. | ||
3 | 2 | ||
3 | Fix an unlikely memory leak in load_elf_image(). | ||
4 | |||
5 | Fixes: bf858897b7 ("linux-user: Re-use load_elf_image for the main binary.") | ||
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20201021173749.111103-5-richard.henderson@linaro.org | ||
9 | Message-Id: <20201003174944.1972444-1-f4bug@amsat.org> | ||
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
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> | ||
6 | Message-id: 20200828183354.27913-40-peter.maydell@linaro.org | ||
7 | --- | 13 | --- |
8 | target/arm/helper.h | 5 ++ | 14 | linux-user/elfload.c | 8 ++++---- |
9 | target/arm/vec_helper.c | 23 +++++++ | 15 | 1 file changed, 4 insertions(+), 4 deletions(-) |
10 | target/arm/translate-neon.c.inc | 105 ++++++++++++-------------------- | ||
11 | 3 files changed, 66 insertions(+), 67 deletions(-) | ||
12 | 16 | ||
13 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 17 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
14 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.h | 19 | --- a/linux-user/elfload.c |
16 | +++ b/target/arm/helper.h | 20 | +++ b/linux-user/elfload.c |
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(gvec_vcvt_uh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 21 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
18 | DEF_HELPER_FLAGS_4(gvec_vcvt_hs, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 22 | info->brk = vaddr_em; |
19 | DEF_HELPER_FLAGS_4(gvec_vcvt_hu, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 23 | } |
20 | 24 | } else if (eppnt->p_type == PT_INTERP && pinterp_name) { | |
21 | +DEF_HELPER_FLAGS_4(gvec_vcvt_rm_ss, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 25 | - char *interp_name; |
22 | +DEF_HELPER_FLAGS_4(gvec_vcvt_rm_us, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 26 | + g_autofree char *interp_name = NULL; |
23 | +DEF_HELPER_FLAGS_4(gvec_vcvt_rm_sh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 27 | |
24 | +DEF_HELPER_FLAGS_4(gvec_vcvt_rm_uh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 28 | if (*pinterp_name) { |
25 | + | 29 | errmsg = "Multiple PT_INTERP entries"; |
26 | DEF_HELPER_FLAGS_4(gvec_frecpe_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 30 | goto exit_errmsg; |
27 | DEF_HELPER_FLAGS_4(gvec_frecpe_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 31 | } |
28 | DEF_HELPER_FLAGS_4(gvec_frecpe_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 32 | - interp_name = malloc(eppnt->p_filesz); |
29 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 33 | + interp_name = g_malloc(eppnt->p_filesz); |
30 | index XXXXXXX..XXXXXXX 100644 | 34 | if (!interp_name) { |
31 | --- a/target/arm/vec_helper.c | 35 | goto exit_perror; |
32 | +++ b/target/arm/vec_helper.c | 36 | } |
33 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_FIXED(gvec_vcvt_hs, helper_vfp_toshh_round_to_zero, uint16_t) | 37 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
34 | DO_VCVT_FIXED(gvec_vcvt_hu, helper_vfp_touhh_round_to_zero, uint16_t) | 38 | errmsg = "Invalid PT_INTERP entry"; |
35 | 39 | goto exit_errmsg; | |
36 | #undef DO_VCVT_FIXED | 40 | } |
37 | + | 41 | - *pinterp_name = interp_name; |
38 | +#define DO_VCVT_RMODE(NAME, FUNC, TYPE) \ | 42 | + *pinterp_name = g_steal_pointer(&interp_name); |
39 | + void HELPER(NAME)(void *vd, void *vn, void *stat, uint32_t desc) \ | 43 | #ifdef TARGET_MIPS |
40 | + { \ | 44 | } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { |
41 | + float_status *fpst = stat; \ | 45 | Mips_elf_abiflags_v0 abiflags; |
42 | + intptr_t i, oprsz = simd_oprsz(desc); \ | 46 | @@ -XXX,XX +XXX,XX @@ int load_elf_binary(struct linux_binprm *bprm, struct image_info *info) |
43 | + uint32_t rmode = simd_data(desc); \ | 47 | if (elf_interpreter) { |
44 | + uint32_t prev_rmode = get_float_rounding_mode(fpst); \ | 48 | info->load_bias = interp_info.load_bias; |
45 | + TYPE *d = vd, *n = vn; \ | 49 | info->entry = interp_info.entry; |
46 | + set_float_rounding_mode(rmode, fpst); \ | 50 | - free(elf_interpreter); |
47 | + for (i = 0; i < oprsz / sizeof(TYPE); i++) { \ | 51 | + g_free(elf_interpreter); |
48 | + d[i] = FUNC(n[i], 0, fpst); \ | ||
49 | + } \ | ||
50 | + set_float_rounding_mode(prev_rmode, fpst); \ | ||
51 | + clear_tail(d, oprsz, simd_maxsz(desc)); \ | ||
52 | + } | ||
53 | + | ||
54 | +DO_VCVT_RMODE(gvec_vcvt_rm_ss, helper_vfp_tosls, uint32_t) | ||
55 | +DO_VCVT_RMODE(gvec_vcvt_rm_us, helper_vfp_touls, uint32_t) | ||
56 | +DO_VCVT_RMODE(gvec_vcvt_rm_sh, helper_vfp_toshh, uint16_t) | ||
57 | +DO_VCVT_RMODE(gvec_vcvt_rm_uh, helper_vfp_touhh, uint16_t) | ||
58 | + | ||
59 | +#undef DO_VCVT_RMODE | ||
60 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/target/arm/translate-neon.c.inc | ||
63 | +++ b/target/arm/translate-neon.c.inc | ||
64 | @@ -XXX,XX +XXX,XX @@ DO_VRINT(VRINTZ, FPROUNDING_ZERO) | ||
65 | DO_VRINT(VRINTM, FPROUNDING_NEGINF) | ||
66 | DO_VRINT(VRINTP, FPROUNDING_POSINF) | ||
67 | |||
68 | -static bool do_vcvt(DisasContext *s, arg_2misc *a, int rmode, bool is_signed) | ||
69 | -{ | ||
70 | - /* | ||
71 | - * Handle a VCVT* operation by iterating 32 bits at a time, | ||
72 | - * with a specified rounding mode in operation. | ||
73 | - */ | ||
74 | - int pass; | ||
75 | - TCGv_ptr fpst; | ||
76 | - TCGv_i32 tcg_rmode, tcg_shift; | ||
77 | - | ||
78 | - if (!arm_dc_feature(s, ARM_FEATURE_NEON) || | ||
79 | - !arm_dc_feature(s, ARM_FEATURE_V8)) { | ||
80 | - return false; | ||
81 | +#define DO_VEC_RMODE(INSN, RMODE, OP) \ | ||
82 | + static void gen_##INSN(unsigned vece, uint32_t rd_ofs, \ | ||
83 | + uint32_t rm_ofs, \ | ||
84 | + uint32_t oprsz, uint32_t maxsz) \ | ||
85 | + { \ | ||
86 | + static gen_helper_gvec_2_ptr * const fns[4] = { \ | ||
87 | + NULL, \ | ||
88 | + gen_helper_gvec_##OP##h, \ | ||
89 | + gen_helper_gvec_##OP##s, \ | ||
90 | + NULL, \ | ||
91 | + }; \ | ||
92 | + TCGv_ptr fpst; \ | ||
93 | + fpst = fpstatus_ptr(vece == 1 ? FPST_STD_F16 : FPST_STD); \ | ||
94 | + tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, oprsz, maxsz, \ | ||
95 | + arm_rmode_to_sf(RMODE), fns[vece]); \ | ||
96 | + tcg_temp_free_ptr(fpst); \ | ||
97 | + } \ | ||
98 | + static bool trans_##INSN(DisasContext *s, arg_2misc *a) \ | ||
99 | + { \ | ||
100 | + if (!arm_dc_feature(s, ARM_FEATURE_V8)) { \ | ||
101 | + return false; \ | ||
102 | + } \ | ||
103 | + if (a->size == MO_16) { \ | ||
104 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { \ | ||
105 | + return false; \ | ||
106 | + } \ | ||
107 | + } else if (a->size != MO_32) { \ | ||
108 | + return false; \ | ||
109 | + } \ | ||
110 | + return do_2misc_vec(s, a, gen_##INSN); \ | ||
111 | } | 52 | } |
112 | 53 | ||
113 | - /* UNDEF accesses to D16-D31 if they don't exist. */ | 54 | #ifdef USE_ELF_CORE_DUMP |
114 | - if (!dc_isar_feature(aa32_simd_r32, s) && | ||
115 | - ((a->vd | a->vm) & 0x10)) { | ||
116 | - return false; | ||
117 | - } | ||
118 | - | ||
119 | - if (a->size != 2) { | ||
120 | - /* TODO: FP16 will be the size == 1 case */ | ||
121 | - return false; | ||
122 | - } | ||
123 | - | ||
124 | - if ((a->vd | a->vm) & a->q) { | ||
125 | - return false; | ||
126 | - } | ||
127 | - | ||
128 | - if (!vfp_access_check(s)) { | ||
129 | - return true; | ||
130 | - } | ||
131 | - | ||
132 | - fpst = fpstatus_ptr(FPST_STD); | ||
133 | - tcg_shift = tcg_const_i32(0); | ||
134 | - tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rmode)); | ||
135 | - gen_helper_set_neon_rmode(tcg_rmode, tcg_rmode, cpu_env); | ||
136 | - for (pass = 0; pass < (a->q ? 4 : 2); pass++) { | ||
137 | - TCGv_i32 tmp = neon_load_reg(a->vm, pass); | ||
138 | - if (is_signed) { | ||
139 | - gen_helper_vfp_tosls(tmp, tmp, tcg_shift, fpst); | ||
140 | - } else { | ||
141 | - gen_helper_vfp_touls(tmp, tmp, tcg_shift, fpst); | ||
142 | - } | ||
143 | - neon_store_reg(a->vd, pass, tmp); | ||
144 | - } | ||
145 | - gen_helper_set_neon_rmode(tcg_rmode, tcg_rmode, cpu_env); | ||
146 | - tcg_temp_free_i32(tcg_rmode); | ||
147 | - tcg_temp_free_i32(tcg_shift); | ||
148 | - tcg_temp_free_ptr(fpst); | ||
149 | - | ||
150 | - return true; | ||
151 | -} | ||
152 | - | ||
153 | -#define DO_VCVT(INSN, RMODE, SIGNED) \ | ||
154 | - static bool trans_##INSN(DisasContext *s, arg_2misc *a) \ | ||
155 | - { \ | ||
156 | - return do_vcvt(s, a, RMODE, SIGNED); \ | ||
157 | - } | ||
158 | - | ||
159 | -DO_VCVT(VCVTAU, FPROUNDING_TIEAWAY, false) | ||
160 | -DO_VCVT(VCVTAS, FPROUNDING_TIEAWAY, true) | ||
161 | -DO_VCVT(VCVTNU, FPROUNDING_TIEEVEN, false) | ||
162 | -DO_VCVT(VCVTNS, FPROUNDING_TIEEVEN, true) | ||
163 | -DO_VCVT(VCVTPU, FPROUNDING_POSINF, false) | ||
164 | -DO_VCVT(VCVTPS, FPROUNDING_POSINF, true) | ||
165 | -DO_VCVT(VCVTMU, FPROUNDING_NEGINF, false) | ||
166 | -DO_VCVT(VCVTMS, FPROUNDING_NEGINF, true) | ||
167 | +DO_VEC_RMODE(VCVTAU, FPROUNDING_TIEAWAY, vcvt_rm_u) | ||
168 | +DO_VEC_RMODE(VCVTAS, FPROUNDING_TIEAWAY, vcvt_rm_s) | ||
169 | +DO_VEC_RMODE(VCVTNU, FPROUNDING_TIEEVEN, vcvt_rm_u) | ||
170 | +DO_VEC_RMODE(VCVTNS, FPROUNDING_TIEEVEN, vcvt_rm_s) | ||
171 | +DO_VEC_RMODE(VCVTPU, FPROUNDING_POSINF, vcvt_rm_u) | ||
172 | +DO_VEC_RMODE(VCVTPS, FPROUNDING_POSINF, vcvt_rm_s) | ||
173 | +DO_VEC_RMODE(VCVTMU, FPROUNDING_NEGINF, vcvt_rm_u) | ||
174 | +DO_VEC_RMODE(VCVTMS, FPROUNDING_NEGINF, vcvt_rm_s) | ||
175 | |||
176 | static bool trans_VSWP(DisasContext *s, arg_2misc *a) | ||
177 | { | ||
178 | -- | 55 | -- |
179 | 2.20.1 | 56 | 2.20.1 |
180 | 57 | ||
181 | 58 | diff view generated by jsdifflib |
1 | Set the MVFR1 ID register FPHP and SIMDHP fields to indicate | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | that our "-cpu max" has v8.2-FP16. | ||
3 | 2 | ||
3 | Fixing this now will clarify following patches. | ||
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20201021173749.111103-6-richard.henderson@linaro.org | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-46-peter.maydell@linaro.org | ||
7 | --- | 9 | --- |
8 | target/arm/cpu.c | 3 ++- | 10 | linux-user/elfload.c | 12 +++++++++--- |
9 | target/arm/cpu64.c | 10 ++++------ | 11 | 1 file changed, 9 insertions(+), 3 deletions(-) |
10 | 2 files changed, 6 insertions(+), 7 deletions(-) | ||
11 | 12 | ||
12 | 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 |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/cpu.c | 15 | --- a/linux-user/elfload.c |
15 | +++ b/target/arm/cpu.c | 16 | +++ b/linux-user/elfload.c |
16 | @@ -XXX,XX +XXX,XX @@ static void arm_max_initfn(Object *obj) | 17 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
17 | cpu->isar.id_isar6 = t; | 18 | abi_ulong vaddr, vaddr_po, vaddr_ps, vaddr_ef, vaddr_em, vaddr_len; |
18 | 19 | int elf_prot = 0; | |
19 | t = cpu->isar.mvfr1; | 20 | |
20 | - t = FIELD_DP32(t, MVFR1, FPHP, 2); /* v8.0 FP support */ | 21 | - if (eppnt->p_flags & PF_R) elf_prot = PROT_READ; |
21 | + t = FIELD_DP32(t, MVFR1, FPHP, 3); /* v8.2-FP16 */ | 22 | - if (eppnt->p_flags & PF_W) elf_prot |= PROT_WRITE; |
22 | + t = FIELD_DP32(t, MVFR1, SIMDHP, 2); /* v8.2-FP16 */ | 23 | - if (eppnt->p_flags & PF_X) elf_prot |= PROT_EXEC; |
23 | cpu->isar.mvfr1 = t; | 24 | + if (eppnt->p_flags & PF_R) { |
24 | 25 | + elf_prot |= PROT_READ; | |
25 | t = cpu->isar.mvfr2; | 26 | + } |
26 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | 27 | + if (eppnt->p_flags & PF_W) { |
27 | index XXXXXXX..XXXXXXX 100644 | 28 | + elf_prot |= PROT_WRITE; |
28 | --- a/target/arm/cpu64.c | 29 | + } |
29 | +++ b/target/arm/cpu64.c | 30 | + if (eppnt->p_flags & PF_X) { |
30 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) | 31 | + elf_prot |= PROT_EXEC; |
31 | u = FIELD_DP32(u, ID_DFR0, PERFMON, 5); /* v8.4-PMU */ | 32 | + } |
32 | cpu->isar.id_dfr0 = u; | 33 | |
33 | 34 | vaddr = load_bias + eppnt->p_vaddr; | |
34 | - /* | 35 | vaddr_po = TARGET_ELF_PAGEOFFSET(vaddr); |
35 | - * FIXME: We do not yet support ARMv8.2-fp16 for AArch32 yet, | ||
36 | - * so do not set MVFR1.FPHP. Strictly speaking this is not legal, | ||
37 | - * but it is also not legal to enable SVE without support for FP16, | ||
38 | - * and enabling SVE in system mode is more useful in the short term. | ||
39 | - */ | ||
40 | + u = cpu->isar.mvfr1; | ||
41 | + u = FIELD_DP32(u, MVFR1, FPHP, 3); /* v8.2-FP16 */ | ||
42 | + u = FIELD_DP32(u, MVFR1, SIMDHP, 2); /* v8.2-FP16 */ | ||
43 | + cpu->isar.mvfr1 = u; | ||
44 | |||
45 | #ifdef CONFIG_USER_ONLY | ||
46 | /* For usermode -cpu max we can use a larger and more efficient DCZ | ||
47 | -- | 36 | -- |
48 | 2.20.1 | 37 | 2.20.1 |
49 | 38 | ||
50 | 39 | diff view generated by jsdifflib |
1 | Convert the Neon pairwise fp ops to use a single gvic-style | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | helper to do the full operation instead of one helper call | ||
3 | for each 32-bit part. This allows us to use the same | ||
4 | framework to implement the fp16. | ||
5 | 2 | ||
3 | The second loop uses a loop induction variable, and the first | ||
4 | does not. Transform the first to match the second, to simplify | ||
5 | a following patch moving code between them. | ||
6 | |||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20201021173749.111103-7-richard.henderson@linaro.org | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20200828183354.27913-36-peter.maydell@linaro.org | ||
9 | --- | 11 | --- |
10 | target/arm/helper.h | 7 +++++ | 12 | linux-user/elfload.c | 9 +++++---- |
11 | target/arm/vec_helper.c | 45 +++++++++++++++++++++++++++++++++ | 13 | 1 file changed, 5 insertions(+), 4 deletions(-) |
12 | target/arm/translate-neon.c.inc | 42 ++++++++++++------------------ | ||
13 | 3 files changed, 68 insertions(+), 26 deletions(-) | ||
14 | 14 | ||
15 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/helper.h | 17 | --- a/linux-user/elfload.c |
18 | +++ b/target/arm/helper.h | 18 | +++ b/linux-user/elfload.c |
19 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fcmlas_idx, TCG_CALL_NO_RWG, | 19 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
20 | DEF_HELPER_FLAGS_5(gvec_fcmlad, TCG_CALL_NO_RWG, | 20 | loaddr = -1, hiaddr = 0; |
21 | void, ptr, ptr, ptr, ptr, i32) | 21 | info->alignment = 0; |
22 | 22 | for (i = 0; i < ehdr->e_phnum; ++i) { | |
23 | +DEF_HELPER_FLAGS_5(neon_paddh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 23 | - if (phdr[i].p_type == PT_LOAD) { |
24 | +DEF_HELPER_FLAGS_5(neon_pmaxh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 24 | - abi_ulong a = phdr[i].p_vaddr - phdr[i].p_offset; |
25 | +DEF_HELPER_FLAGS_5(neon_pminh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 25 | + struct elf_phdr *eppnt = phdr + i; |
26 | +DEF_HELPER_FLAGS_5(neon_padds, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 26 | + if (eppnt->p_type == PT_LOAD) { |
27 | +DEF_HELPER_FLAGS_5(neon_pmaxs, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 27 | + abi_ulong a = eppnt->p_vaddr - eppnt->p_offset; |
28 | +DEF_HELPER_FLAGS_5(neon_pmins, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 28 | if (a < loaddr) { |
29 | + | 29 | loaddr = a; |
30 | DEF_HELPER_FLAGS_4(gvec_frecpe_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 30 | } |
31 | DEF_HELPER_FLAGS_4(gvec_frecpe_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 31 | - a = phdr[i].p_vaddr + phdr[i].p_memsz; |
32 | DEF_HELPER_FLAGS_4(gvec_frecpe_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 32 | + a = eppnt->p_vaddr + eppnt->p_memsz; |
33 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 33 | if (a > hiaddr) { |
34 | index XXXXXXX..XXXXXXX 100644 | 34 | hiaddr = a; |
35 | --- a/target/arm/vec_helper.c | 35 | } |
36 | +++ b/target/arm/vec_helper.c | 36 | ++info->nsegs; |
37 | @@ -XXX,XX +XXX,XX @@ DO_ABA(gvec_uaba_s, uint32_t) | 37 | - info->alignment |= phdr[i].p_align; |
38 | DO_ABA(gvec_uaba_d, uint64_t) | 38 | + info->alignment |= eppnt->p_align; |
39 | 39 | } | |
40 | #undef DO_ABA | ||
41 | + | ||
42 | +#define DO_NEON_PAIRWISE(NAME, OP) \ | ||
43 | + void HELPER(NAME##s)(void *vd, void *vn, void *vm, \ | ||
44 | + void *stat, uint32_t oprsz) \ | ||
45 | + { \ | ||
46 | + float_status *fpst = stat; \ | ||
47 | + float32 *d = vd; \ | ||
48 | + float32 *n = vn; \ | ||
49 | + float32 *m = vm; \ | ||
50 | + float32 r0, r1; \ | ||
51 | + \ | ||
52 | + /* Read all inputs before writing outputs in case vm == vd */ \ | ||
53 | + r0 = float32_##OP(n[H4(0)], n[H4(1)], fpst); \ | ||
54 | + r1 = float32_##OP(m[H4(0)], m[H4(1)], fpst); \ | ||
55 | + \ | ||
56 | + d[H4(0)] = r0; \ | ||
57 | + d[H4(1)] = r1; \ | ||
58 | + } \ | ||
59 | + \ | ||
60 | + void HELPER(NAME##h)(void *vd, void *vn, void *vm, \ | ||
61 | + void *stat, uint32_t oprsz) \ | ||
62 | + { \ | ||
63 | + float_status *fpst = stat; \ | ||
64 | + float16 *d = vd; \ | ||
65 | + float16 *n = vn; \ | ||
66 | + float16 *m = vm; \ | ||
67 | + float16 r0, r1, r2, r3; \ | ||
68 | + \ | ||
69 | + /* Read all inputs before writing outputs in case vm == vd */ \ | ||
70 | + r0 = float16_##OP(n[H2(0)], n[H2(1)], fpst); \ | ||
71 | + r1 = float16_##OP(n[H2(2)], n[H2(3)], fpst); \ | ||
72 | + r2 = float16_##OP(m[H2(0)], m[H2(1)], fpst); \ | ||
73 | + r3 = float16_##OP(m[H2(2)], m[H2(3)], fpst); \ | ||
74 | + \ | ||
75 | + d[H4(0)] = r0; \ | ||
76 | + d[H4(1)] = r1; \ | ||
77 | + d[H4(2)] = r2; \ | ||
78 | + d[H4(3)] = r3; \ | ||
79 | + } | ||
80 | + | ||
81 | +DO_NEON_PAIRWISE(neon_padd, add) | ||
82 | +DO_NEON_PAIRWISE(neon_pmax, max) | ||
83 | +DO_NEON_PAIRWISE(neon_pmin, min) | ||
84 | + | ||
85 | +#undef DO_NEON_PAIRWISE | ||
86 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/target/arm/translate-neon.c.inc | ||
89 | +++ b/target/arm/translate-neon.c.inc | ||
90 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMINNM_fp_3s(DisasContext *s, arg_3same *a) | ||
91 | return do_3same(s, a, gen_VMINNM_fp32_3s); | ||
92 | } | ||
93 | |||
94 | -static bool do_3same_fp_pair(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn) | ||
95 | +static bool do_3same_fp_pair(DisasContext *s, arg_3same *a, | ||
96 | + gen_helper_gvec_3_ptr *fn) | ||
97 | { | ||
98 | - /* FP operations handled pairwise 32 bits at a time */ | ||
99 | - TCGv_i32 tmp, tmp2, tmp3; | ||
100 | + /* FP pairwise operations */ | ||
101 | TCGv_ptr fpstatus; | ||
102 | |||
103 | if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | ||
104 | @@ -XXX,XX +XXX,XX @@ static bool do_3same_fp_pair(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn) | ||
105 | |||
106 | assert(a->q == 0); /* enforced by decode patterns */ | ||
107 | |||
108 | - /* | ||
109 | - * Note that we have to be careful not to clobber the source operands | ||
110 | - * in the "vm == vd" case by storing the result of the first pass too | ||
111 | - * early. Since Q is 0 there are always just two passes, so instead | ||
112 | - * of a complicated loop over each pass we just unroll. | ||
113 | - */ | ||
114 | - fpstatus = fpstatus_ptr(FPST_STD); | ||
115 | - tmp = neon_load_reg(a->vn, 0); | ||
116 | - tmp2 = neon_load_reg(a->vn, 1); | ||
117 | - fn(tmp, tmp, tmp2, fpstatus); | ||
118 | - tcg_temp_free_i32(tmp2); | ||
119 | |||
120 | - tmp3 = neon_load_reg(a->vm, 0); | ||
121 | - tmp2 = neon_load_reg(a->vm, 1); | ||
122 | - fn(tmp3, tmp3, tmp2, fpstatus); | ||
123 | - tcg_temp_free_i32(tmp2); | ||
124 | + fpstatus = fpstatus_ptr(a->size != 0 ? FPST_STD_F16 : FPST_STD); | ||
125 | + tcg_gen_gvec_3_ptr(vfp_reg_offset(1, a->vd), | ||
126 | + vfp_reg_offset(1, a->vn), | ||
127 | + vfp_reg_offset(1, a->vm), | ||
128 | + fpstatus, 8, 8, 0, fn); | ||
129 | tcg_temp_free_ptr(fpstatus); | ||
130 | |||
131 | - neon_store_reg(a->vd, 0, tmp); | ||
132 | - neon_store_reg(a->vd, 1, tmp3); | ||
133 | return true; | ||
134 | } | ||
135 | |||
136 | @@ -XXX,XX +XXX,XX @@ static bool do_3same_fp_pair(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn) | ||
137 | static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \ | ||
138 | { \ | ||
139 | if (a->size != 0) { \ | ||
140 | - /* TODO fp16 support */ \ | ||
141 | - return false; \ | ||
142 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { \ | ||
143 | + return false; \ | ||
144 | + } \ | ||
145 | + return do_3same_fp_pair(s, a, FUNC##h); \ | ||
146 | } \ | ||
147 | - return do_3same_fp_pair(s, a, FUNC); \ | ||
148 | + return do_3same_fp_pair(s, a, FUNC##s); \ | ||
149 | } | 40 | } |
150 | 41 | ||
151 | -DO_3S_FP_PAIR(VPADD, gen_helper_vfp_adds) | ||
152 | -DO_3S_FP_PAIR(VPMAX, gen_helper_vfp_maxs) | ||
153 | -DO_3S_FP_PAIR(VPMIN, gen_helper_vfp_mins) | ||
154 | +DO_3S_FP_PAIR(VPADD, gen_helper_neon_padd) | ||
155 | +DO_3S_FP_PAIR(VPMAX, gen_helper_neon_pmax) | ||
156 | +DO_3S_FP_PAIR(VPMIN, gen_helper_neon_pmin) | ||
157 | |||
158 | static bool do_vector_2sh(DisasContext *s, arg_2reg_shift *a, GVecGen2iFn *fn) | ||
159 | { | ||
160 | -- | 42 | -- |
161 | 2.20.1 | 43 | 2.20.1 |
162 | 44 | ||
163 | 45 | diff view generated by jsdifflib |
1 | Convert the Neon floating point VMAXNM and VMINNM insns to | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | using a gvec helper and use this to implement the fp16 case. | ||
3 | 2 | ||
3 | For BTI, we need to know if the executable is static or dynamic, | ||
4 | which means looking for PT_INTERP earlier. | ||
5 | |||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20201021173749.111103-8-richard.henderson@linaro.org | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-30-peter.maydell@linaro.org | ||
7 | --- | 10 | --- |
8 | target/arm/helper.h | 6 ++++++ | 11 | linux-user/elfload.c | 60 +++++++++++++++++++++++--------------------- |
9 | target/arm/vec_helper.c | 6 ++++++ | 12 | 1 file changed, 31 insertions(+), 29 deletions(-) |
10 | target/arm/translate-neon.c.inc | 23 +++++++++++++++-------- | ||
11 | 3 files changed, 27 insertions(+), 8 deletions(-) | ||
12 | 13 | ||
13 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 14 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.h | 16 | --- a/linux-user/elfload.c |
16 | +++ b/target/arm/helper.h | 17 | +++ b/linux-user/elfload.c |
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fmax_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 18 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
18 | DEF_HELPER_FLAGS_5(gvec_fmin_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 19 | |
19 | DEF_HELPER_FLAGS_5(gvec_fmin_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 20 | mmap_lock(); |
20 | 21 | ||
21 | +DEF_HELPER_FLAGS_5(gvec_fmaxnum_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 22 | - /* Find the maximum size of the image and allocate an appropriate |
22 | +DEF_HELPER_FLAGS_5(gvec_fmaxnum_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 23 | - amount of memory to handle that. */ |
24 | + /* | ||
25 | + * Find the maximum size of the image and allocate an appropriate | ||
26 | + * amount of memory to handle that. Locate the interpreter, if any. | ||
27 | + */ | ||
28 | loaddr = -1, hiaddr = 0; | ||
29 | info->alignment = 0; | ||
30 | for (i = 0; i < ehdr->e_phnum; ++i) { | ||
31 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
32 | } | ||
33 | ++info->nsegs; | ||
34 | info->alignment |= eppnt->p_align; | ||
35 | + } else if (eppnt->p_type == PT_INTERP && pinterp_name) { | ||
36 | + g_autofree char *interp_name = NULL; | ||
23 | + | 37 | + |
24 | +DEF_HELPER_FLAGS_5(gvec_fminnum_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 38 | + if (*pinterp_name) { |
25 | +DEF_HELPER_FLAGS_5(gvec_fminnum_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 39 | + errmsg = "Multiple PT_INTERP entries"; |
40 | + goto exit_errmsg; | ||
41 | + } | ||
42 | + interp_name = g_malloc(eppnt->p_filesz); | ||
43 | + if (!interp_name) { | ||
44 | + goto exit_perror; | ||
45 | + } | ||
26 | + | 46 | + |
27 | DEF_HELPER_FLAGS_5(gvec_ftsmul_h, TCG_CALL_NO_RWG, | 47 | + if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { |
28 | void, ptr, ptr, ptr, ptr, i32) | 48 | + memcpy(interp_name, bprm_buf + eppnt->p_offset, |
29 | DEF_HELPER_FLAGS_5(gvec_ftsmul_s, TCG_CALL_NO_RWG, | 49 | + eppnt->p_filesz); |
30 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 50 | + } else { |
31 | index XXXXXXX..XXXXXXX 100644 | 51 | + retval = pread(image_fd, interp_name, eppnt->p_filesz, |
32 | --- a/target/arm/vec_helper.c | 52 | + eppnt->p_offset); |
33 | +++ b/target/arm/vec_helper.c | 53 | + if (retval != eppnt->p_filesz) { |
34 | @@ -XXX,XX +XXX,XX @@ DO_3OP(gvec_fmax_s, float32_max, float32) | 54 | + goto exit_perror; |
35 | DO_3OP(gvec_fmin_h, float16_min, float16) | 55 | + } |
36 | DO_3OP(gvec_fmin_s, float32_min, float32) | 56 | + } |
37 | 57 | + if (interp_name[eppnt->p_filesz - 1] != 0) { | |
38 | +DO_3OP(gvec_fmaxnum_h, float16_maxnum, float16) | 58 | + errmsg = "Invalid PT_INTERP entry"; |
39 | +DO_3OP(gvec_fmaxnum_s, float32_maxnum, float32) | 59 | + goto exit_errmsg; |
40 | + | 60 | + } |
41 | +DO_3OP(gvec_fminnum_h, float16_minnum, float16) | 61 | + *pinterp_name = g_steal_pointer(&interp_name); |
42 | +DO_3OP(gvec_fminnum_s, float32_minnum, float32) | 62 | } |
43 | + | ||
44 | #ifdef TARGET_AARCH64 | ||
45 | |||
46 | DO_3OP(gvec_recps_h, helper_recpsf_f16, float16) | ||
47 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/target/arm/translate-neon.c.inc | ||
50 | +++ b/target/arm/translate-neon.c.inc | ||
51 | @@ -XXX,XX +XXX,XX @@ static void gen_VMLS_fp_3s(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, | ||
52 | DO_3S_FP(VMLA, gen_VMLA_fp_3s, true) | ||
53 | DO_3S_FP(VMLS, gen_VMLS_fp_3s, true) | ||
54 | |||
55 | +WRAP_FP_GVEC(gen_VMAXNM_fp32_3s, FPST_STD, gen_helper_gvec_fmaxnum_s) | ||
56 | +WRAP_FP_GVEC(gen_VMAXNM_fp16_3s, FPST_STD_F16, gen_helper_gvec_fmaxnum_h) | ||
57 | +WRAP_FP_GVEC(gen_VMINNM_fp32_3s, FPST_STD, gen_helper_gvec_fminnum_s) | ||
58 | +WRAP_FP_GVEC(gen_VMINNM_fp16_3s, FPST_STD_F16, gen_helper_gvec_fminnum_h) | ||
59 | + | ||
60 | static bool trans_VMAXNM_fp_3s(DisasContext *s, arg_3same *a) | ||
61 | { | ||
62 | if (!arm_dc_feature(s, ARM_FEATURE_V8)) { | ||
63 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMAXNM_fp_3s(DisasContext *s, arg_3same *a) | ||
64 | } | 63 | } |
65 | 64 | ||
66 | if (a->size != 0) { | 65 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
67 | - /* TODO fp16 support */ | 66 | if (vaddr_em > info->brk) { |
68 | - return false; | 67 | info->brk = vaddr_em; |
69 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 68 | } |
70 | + return false; | 69 | - } else if (eppnt->p_type == PT_INTERP && pinterp_name) { |
71 | + } | 70 | - g_autofree char *interp_name = NULL; |
72 | + return do_3same(s, a, gen_VMAXNM_fp16_3s); | ||
73 | } | ||
74 | - | 71 | - |
75 | - return do_3same_fp(s, a, gen_helper_vfp_maxnums, false); | 72 | - if (*pinterp_name) { |
76 | + return do_3same(s, a, gen_VMAXNM_fp32_3s); | 73 | - errmsg = "Multiple PT_INTERP entries"; |
77 | } | 74 | - goto exit_errmsg; |
78 | 75 | - } | |
79 | static bool trans_VMINNM_fp_3s(DisasContext *s, arg_3same *a) | 76 | - interp_name = g_malloc(eppnt->p_filesz); |
80 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMINNM_fp_3s(DisasContext *s, arg_3same *a) | 77 | - if (!interp_name) { |
81 | } | 78 | - goto exit_perror; |
82 | 79 | - } | |
83 | if (a->size != 0) { | ||
84 | - /* TODO fp16 support */ | ||
85 | - return false; | ||
86 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | ||
87 | + return false; | ||
88 | + } | ||
89 | + return do_3same(s, a, gen_VMINNM_fp16_3s); | ||
90 | } | ||
91 | - | 80 | - |
92 | - return do_3same_fp(s, a, gen_helper_vfp_minnums, false); | 81 | - if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { |
93 | + return do_3same(s, a, gen_VMINNM_fp32_3s); | 82 | - memcpy(interp_name, bprm_buf + eppnt->p_offset, |
94 | } | 83 | - eppnt->p_filesz); |
95 | 84 | - } else { | |
96 | WRAP_ENV_FN(gen_VRECPS_tramp, gen_helper_recps_f32) | 85 | - retval = pread(image_fd, interp_name, eppnt->p_filesz, |
86 | - eppnt->p_offset); | ||
87 | - if (retval != eppnt->p_filesz) { | ||
88 | - goto exit_perror; | ||
89 | - } | ||
90 | - } | ||
91 | - if (interp_name[eppnt->p_filesz - 1] != 0) { | ||
92 | - errmsg = "Invalid PT_INTERP entry"; | ||
93 | - goto exit_errmsg; | ||
94 | - } | ||
95 | - *pinterp_name = g_steal_pointer(&interp_name); | ||
96 | #ifdef TARGET_MIPS | ||
97 | } else if (eppnt->p_type == PT_MIPS_ABIFLAGS) { | ||
98 | Mips_elf_abiflags_v0 abiflags; | ||
97 | -- | 99 | -- |
98 | 2.20.1 | 100 | 2.20.1 |
99 | 101 | ||
100 | 102 | diff view generated by jsdifflib |
1 | Add gvec helpers for doing Neon-style indexed non-fused fp | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | multiply-and-accumulate operations. | ||
3 | 2 | ||
3 | This is a bit clearer than open-coding some of this | ||
4 | with a bare c string. | ||
5 | |||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20201021173749.111103-9-richard.henderson@linaro.org | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Message-id: 20200828183354.27913-44-peter.maydell@linaro.org | ||
6 | --- | 10 | --- |
7 | target/arm/helper.h | 10 ++++++++++ | 11 | linux-user/elfload.c | 37 ++++++++++++++++++++----------------- |
8 | target/arm/vec_helper.c | 27 ++++++++++++++++++++++----- | 12 | 1 file changed, 20 insertions(+), 17 deletions(-) |
9 | 2 files changed, 32 insertions(+), 5 deletions(-) | ||
10 | 13 | ||
11 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 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/helper.h | 16 | --- a/linux-user/elfload.c |
14 | +++ b/target/arm/helper.h | 17 | +++ b/linux-user/elfload.c |
15 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fmul_idx_s, TCG_CALL_NO_RWG, | 18 | @@ -XXX,XX +XXX,XX @@ |
16 | DEF_HELPER_FLAGS_5(gvec_fmul_idx_d, TCG_CALL_NO_RWG, | 19 | #include "qemu/guest-random.h" |
17 | void, ptr, ptr, ptr, ptr, i32) | 20 | #include "qemu/units.h" |
18 | 21 | #include "qemu/selfmap.h" | |
19 | +DEF_HELPER_FLAGS_5(gvec_fmla_nf_idx_h, TCG_CALL_NO_RWG, | 22 | +#include "qapi/error.h" |
20 | + void, ptr, ptr, ptr, ptr, i32) | 23 | |
21 | +DEF_HELPER_FLAGS_5(gvec_fmla_nf_idx_s, TCG_CALL_NO_RWG, | 24 | #ifdef _ARCH_PPC64 |
22 | + void, ptr, ptr, ptr, ptr, i32) | 25 | #undef ARCH_DLINFO |
26 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
27 | struct elf_phdr *phdr; | ||
28 | abi_ulong load_addr, load_bias, loaddr, hiaddr, error; | ||
29 | int i, retval; | ||
30 | - const char *errmsg; | ||
31 | + Error *err = NULL; | ||
32 | |||
33 | /* First of all, some simple consistency checks */ | ||
34 | - errmsg = "Invalid ELF image for this architecture"; | ||
35 | if (!elf_check_ident(ehdr)) { | ||
36 | + error_setg(&err, "Invalid ELF image for this architecture"); | ||
37 | goto exit_errmsg; | ||
38 | } | ||
39 | bswap_ehdr(ehdr); | ||
40 | if (!elf_check_ehdr(ehdr)) { | ||
41 | + error_setg(&err, "Invalid ELF image for this architecture"); | ||
42 | goto exit_errmsg; | ||
43 | } | ||
44 | |||
45 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
46 | g_autofree char *interp_name = NULL; | ||
47 | |||
48 | if (*pinterp_name) { | ||
49 | - errmsg = "Multiple PT_INTERP entries"; | ||
50 | + error_setg(&err, "Multiple PT_INTERP entries"); | ||
51 | goto exit_errmsg; | ||
52 | } | ||
23 | + | 53 | + |
24 | +DEF_HELPER_FLAGS_5(gvec_fmls_nf_idx_h, TCG_CALL_NO_RWG, | 54 | interp_name = g_malloc(eppnt->p_filesz); |
25 | + void, ptr, ptr, ptr, ptr, i32) | 55 | - if (!interp_name) { |
26 | +DEF_HELPER_FLAGS_5(gvec_fmls_nf_idx_s, TCG_CALL_NO_RWG, | 56 | - goto exit_perror; |
27 | + void, ptr, ptr, ptr, ptr, i32) | 57 | - } |
28 | + | 58 | |
29 | DEF_HELPER_FLAGS_6(gvec_fmla_idx_h, TCG_CALL_NO_RWG, | 59 | if (eppnt->p_offset + eppnt->p_filesz <= BPRM_BUF_SIZE) { |
30 | void, ptr, ptr, ptr, ptr, ptr, i32) | 60 | memcpy(interp_name, bprm_buf + eppnt->p_offset, |
31 | DEF_HELPER_FLAGS_6(gvec_fmla_idx_s, TCG_CALL_NO_RWG, | 61 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
32 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 62 | retval = pread(image_fd, interp_name, eppnt->p_filesz, |
33 | index XXXXXXX..XXXXXXX 100644 | 63 | eppnt->p_offset); |
34 | --- a/target/arm/vec_helper.c | 64 | if (retval != eppnt->p_filesz) { |
35 | +++ b/target/arm/vec_helper.c | 65 | - goto exit_perror; |
36 | @@ -XXX,XX +XXX,XX @@ DO_MLA_IDX(gvec_mls_idx_d, uint64_t, -, ) | 66 | + goto exit_read; |
37 | 67 | } | |
38 | #undef DO_MLA_IDX | 68 | } |
39 | 69 | if (interp_name[eppnt->p_filesz - 1] != 0) { | |
40 | -#define DO_FMUL_IDX(NAME, TYPE, H) \ | 70 | - errmsg = "Invalid PT_INTERP entry"; |
41 | +#define DO_FMUL_IDX(NAME, ADD, TYPE, H) \ | 71 | + error_setg(&err, "Invalid PT_INTERP entry"); |
42 | void HELPER(NAME)(void *vd, void *vn, void *vm, void *stat, uint32_t desc) \ | 72 | goto exit_errmsg; |
43 | { \ | 73 | } |
44 | intptr_t i, j, oprsz = simd_oprsz(desc); \ | 74 | *pinterp_name = g_steal_pointer(&interp_name); |
45 | @@ -XXX,XX +XXX,XX @@ void HELPER(NAME)(void *vd, void *vn, void *vm, void *stat, uint32_t desc) \ | 75 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
46 | for (i = 0; i < oprsz / sizeof(TYPE); i += segment) { \ | 76 | (ehdr->e_type == ET_EXEC ? MAP_FIXED : 0), |
47 | TYPE mm = m[H(i + idx)]; \ | 77 | -1, 0); |
48 | for (j = 0; j < segment; j++) { \ | 78 | if (load_addr == -1) { |
49 | - d[i + j] = TYPE##_mul(n[i + j], mm, stat); \ | 79 | - goto exit_perror; |
50 | + d[i + j] = TYPE##_##ADD(d[i + j], \ | 80 | + goto exit_mmap; |
51 | + TYPE##_mul(n[i + j], mm, stat), stat); \ | 81 | } |
52 | } \ | 82 | load_bias = load_addr - loaddr; |
53 | } \ | 83 | |
54 | clear_tail(d, oprsz, simd_maxsz(desc)); \ | 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); | ||
55 | } | 131 | } |
56 | 132 | ||
57 | -DO_FMUL_IDX(gvec_fmul_idx_h, float16, H2) | ||
58 | -DO_FMUL_IDX(gvec_fmul_idx_s, float32, H4) | ||
59 | -DO_FMUL_IDX(gvec_fmul_idx_d, float64, ) | ||
60 | +#define float16_nop(N, M, S) (M) | ||
61 | +#define float32_nop(N, M, S) (M) | ||
62 | +#define float64_nop(N, M, S) (M) | ||
63 | |||
64 | +DO_FMUL_IDX(gvec_fmul_idx_h, nop, float16, H2) | ||
65 | +DO_FMUL_IDX(gvec_fmul_idx_s, nop, float32, H4) | ||
66 | +DO_FMUL_IDX(gvec_fmul_idx_d, nop, float64, ) | ||
67 | + | ||
68 | +/* | ||
69 | + * Non-fused multiply-accumulate operations, for Neon. NB that unlike | ||
70 | + * the fused ops below they assume accumulate both from and into Vd. | ||
71 | + */ | ||
72 | +DO_FMUL_IDX(gvec_fmla_nf_idx_h, add, float16, H2) | ||
73 | +DO_FMUL_IDX(gvec_fmla_nf_idx_s, add, float32, H4) | ||
74 | +DO_FMUL_IDX(gvec_fmls_nf_idx_h, sub, float16, H2) | ||
75 | +DO_FMUL_IDX(gvec_fmls_nf_idx_s, sub, float32, H4) | ||
76 | + | ||
77 | +#undef float16_nop | ||
78 | +#undef float32_nop | ||
79 | +#undef float64_nop | ||
80 | #undef DO_FMUL_IDX | ||
81 | |||
82 | #define DO_FMLA_IDX(NAME, TYPE, H) \ | ||
83 | -- | 133 | -- |
84 | 2.20.1 | 134 | 2.20.1 |
85 | 135 | ||
86 | 136 | diff view generated by jsdifflib |
1 | Implement the fp16 versions of the VFP VSEL instruction. | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
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 | |||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20201021173749.111103-10-richard.henderson@linaro.org | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20200828183354.27913-18-peter.maydell@linaro.org | ||
6 | --- | 11 | --- |
7 | target/arm/vfp-uncond.decode | 6 ++++-- | 12 | linux-user/elfload.c | 15 ++++++++------- |
8 | target/arm/translate-vfp.c.inc | 16 ++++++++++++---- | 13 | 1 file changed, 8 insertions(+), 7 deletions(-) |
9 | 2 files changed, 16 insertions(+), 6 deletions(-) | ||
10 | 14 | ||
11 | diff --git a/target/arm/vfp-uncond.decode b/target/arm/vfp-uncond.decode | 15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c |
12 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/vfp-uncond.decode | 17 | --- a/linux-user/elfload.c |
14 | +++ b/target/arm/vfp-uncond.decode | 18 | +++ b/linux-user/elfload.c |
15 | @@ -XXX,XX +XXX,XX @@ | 19 | @@ -XXX,XX +XXX,XX @@ static void load_elf_interp(const char *filename, struct image_info *info, |
16 | @vfp_dnm_s ................................ vm=%vm_sp vn=%vn_sp vd=%vd_sp | 20 | char bprm_buf[BPRM_BUF_SIZE]) |
17 | @vfp_dnm_d ................................ vm=%vm_dp vn=%vn_dp vd=%vd_dp | ||
18 | |||
19 | +VSEL 1111 1110 0. cc:2 .... .... 1001 .0.0 .... \ | ||
20 | + vm=%vm_sp vn=%vn_sp vd=%vd_sp sz=1 | ||
21 | VSEL 1111 1110 0. cc:2 .... .... 1010 .0.0 .... \ | ||
22 | - vm=%vm_sp vn=%vn_sp vd=%vd_sp dp=0 | ||
23 | + vm=%vm_sp vn=%vn_sp vd=%vd_sp sz=2 | ||
24 | VSEL 1111 1110 0. cc:2 .... .... 1011 .0.0 .... \ | ||
25 | - vm=%vm_dp vn=%vn_dp vd=%vd_dp dp=1 | ||
26 | + vm=%vm_dp vn=%vn_dp vd=%vd_dp sz=3 | ||
27 | |||
28 | VMAXNM_hp 1111 1110 1.00 .... .... 1001 .0.0 .... @vfp_dnm_s | ||
29 | VMINNM_hp 1111 1110 1.00 .... .... 1001 .1.0 .... @vfp_dnm_s | ||
30 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/target/arm/translate-vfp.c.inc | ||
33 | +++ b/target/arm/translate-vfp.c.inc | ||
34 | @@ -XXX,XX +XXX,XX @@ static bool vfp_access_check(DisasContext *s) | ||
35 | static bool trans_VSEL(DisasContext *s, arg_VSEL *a) | ||
36 | { | 21 | { |
37 | uint32_t rd, rn, rm; | 22 | int fd, retval; |
38 | - bool dp = a->dp; | 23 | + Error *err = NULL; |
39 | + int sz = a->sz; | 24 | |
40 | 25 | fd = open(path(filename), O_RDONLY); | |
41 | if (!dc_isar_feature(aa32_vsel, s)) { | 26 | if (fd < 0) { |
42 | return false; | 27 | - goto exit_perror; |
28 | + error_setg_file_open(&err, errno, filename); | ||
29 | + error_report_err(err); | ||
30 | + exit(-1); | ||
43 | } | 31 | } |
44 | 32 | ||
45 | - if (dp && !dc_isar_feature(aa32_fpdp_v2, s)) { | 33 | retval = read(fd, bprm_buf, BPRM_BUF_SIZE); |
46 | + if (sz == 3 && !dc_isar_feature(aa32_fpdp_v2, s)) { | 34 | if (retval < 0) { |
47 | + return false; | 35 | - goto exit_perror; |
48 | + } | 36 | + error_setg_errno(&err, errno, "Error reading file header"); |
37 | + error_reportf_err(err, "%s: ", filename); | ||
38 | + exit(-1); | ||
39 | } | ||
49 | + | 40 | + |
50 | + if (sz == 1 && !dc_isar_feature(aa32_fp16_arith, s)) { | 41 | if (retval < BPRM_BUF_SIZE) { |
51 | return false; | 42 | memset(bprm_buf + retval, 0, BPRM_BUF_SIZE - retval); |
52 | } | 43 | } |
53 | 44 | ||
54 | /* UNDEF accesses to D16-D31 if they don't exist */ | 45 | load_elf_image(filename, fd, info, NULL, bprm_buf); |
55 | - if (dp && !dc_isar_feature(aa32_simd_r32, s) && | 46 | - return; |
56 | + if (sz == 3 && !dc_isar_feature(aa32_simd_r32, s) && | 47 | - |
57 | ((a->vm | a->vn | a->vd) & 0x10)) { | 48 | - exit_perror: |
58 | return false; | 49 | - fprintf(stderr, "%s: %s\n", filename, strerror(errno)); |
59 | } | 50 | - exit(-1); |
60 | @@ -XXX,XX +XXX,XX @@ static bool trans_VSEL(DisasContext *s, arg_VSEL *a) | 51 | } |
61 | return true; | 52 | |
62 | } | 53 | static int symfind(const void *s0, const void *s1) |
63 | |||
64 | - if (dp) { | ||
65 | + if (sz == 3) { | ||
66 | TCGv_i64 frn, frm, dest; | ||
67 | TCGv_i64 tmp, zero, zf, nf, vf; | ||
68 | |||
69 | @@ -XXX,XX +XXX,XX @@ static bool trans_VSEL(DisasContext *s, arg_VSEL *a) | ||
70 | tcg_temp_free_i32(tmp); | ||
71 | break; | ||
72 | } | ||
73 | + /* For fp16 the top half is always zeroes */ | ||
74 | + if (sz == 1) { | ||
75 | + tcg_gen_andi_i32(dest, dest, 0xffff); | ||
76 | + } | ||
77 | neon_store_reg32(dest, rd); | ||
78 | tcg_temp_free_i32(frn); | ||
79 | tcg_temp_free_i32(frm); | ||
80 | -- | 54 | -- |
81 | 2.20.1 | 55 | 2.20.1 |
82 | 56 | ||
83 | 57 | diff view generated by jsdifflib |
1 | Implement VFP fp16 support for fused multiply-add insns | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | VFNMA, VFNMS, VFMA, VFMS. | 2 | |
3 | 3 | This is generic support, with the code disabled for all targets. | |
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20201021173749.111103-11-richard.henderson@linaro.org | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-7-peter.maydell@linaro.org | ||
7 | --- | 9 | --- |
8 | target/arm/helper.h | 1 + | 10 | linux-user/qemu.h | 4 ++ |
9 | target/arm/vfp.decode | 5 +++ | 11 | linux-user/elfload.c | 157 +++++++++++++++++++++++++++++++++++++++++++ |
10 | target/arm/vfp_helper.c | 7 ++++ | 12 | 2 files changed, 161 insertions(+) |
11 | target/arm/translate-vfp.c.inc | 64 ++++++++++++++++++++++++++++++++++ | 13 | |
12 | 4 files changed, 77 insertions(+) | 14 | diff --git a/linux-user/qemu.h b/linux-user/qemu.h |
13 | |||
14 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/helper.h | 16 | --- a/linux-user/qemu.h |
17 | +++ b/target/arm/helper.h | 17 | +++ b/linux-user/qemu.h |
18 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(vfp_fcvt_f64_to_f16, TCG_CALL_NO_RWG, f16, f64, ptr, i32) | 18 | @@ -XXX,XX +XXX,XX @@ struct image_info { |
19 | 19 | abi_ulong interpreter_loadmap_addr; | |
20 | DEF_HELPER_4(vfp_muladdd, f64, f64, f64, f64, ptr) | 20 | abi_ulong interpreter_pt_dynamic_addr; |
21 | DEF_HELPER_4(vfp_muladds, f32, f32, f32, f32, ptr) | 21 | struct image_info *other_info; |
22 | +DEF_HELPER_4(vfp_muladdh, f16, f16, f16, f16, ptr) | 22 | + |
23 | 23 | + /* For target-specific processing of NT_GNU_PROPERTY_TYPE_0. */ | |
24 | DEF_HELPER_3(recps_f32, f32, env, f32, f32) | 24 | + uint32_t note_flags; |
25 | DEF_HELPER_3(rsqrts_f32, f32, env, f32, f32) | 25 | + |
26 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | 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 | ||
27 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/target/arm/vfp.decode | 31 | --- a/linux-user/elfload.c |
29 | +++ b/target/arm/vfp.decode | 32 | +++ b/linux-user/elfload.c |
30 | @@ -XXX,XX +XXX,XX @@ VDIV_hp ---- 1110 1.00 .... .... 1001 .0.0 .... @vfp_dnm_s | 33 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, |
31 | VDIV_sp ---- 1110 1.00 .... .... 1010 .0.0 .... @vfp_dnm_s | 34 | |
32 | VDIV_dp ---- 1110 1.00 .... .... 1011 .0.0 .... @vfp_dnm_d | 35 | #include "elf.h" |
33 | 36 | ||
34 | +VFMA_hp ---- 1110 1.10 .... .... 1001 .0. 0 .... @vfp_dnm_s | 37 | +static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, |
35 | +VFMS_hp ---- 1110 1.10 .... .... 1001 .1. 0 .... @vfp_dnm_s | 38 | + const uint32_t *data, |
36 | +VFNMA_hp ---- 1110 1.01 .... .... 1001 .0. 0 .... @vfp_dnm_s | 39 | + struct image_info *info, |
37 | +VFNMS_hp ---- 1110 1.01 .... .... 1001 .1. 0 .... @vfp_dnm_s | 40 | + Error **errp) |
38 | + | 41 | +{ |
39 | VFMA_sp ---- 1110 1.10 .... .... 1010 .0. 0 .... @vfp_dnm_s | 42 | + g_assert_not_reached(); |
40 | VFMS_sp ---- 1110 1.10 .... .... 1010 .1. 0 .... @vfp_dnm_s | 43 | +} |
41 | VFNMA_sp ---- 1110 1.01 .... .... 1010 .0. 0 .... @vfp_dnm_s | 44 | +#define ARCH_USE_GNU_PROPERTY 0 |
42 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | 45 | + |
43 | index XXXXXXX..XXXXXXX 100644 | 46 | struct exec |
44 | --- a/target/arm/vfp_helper.c | 47 | { |
45 | +++ b/target/arm/vfp_helper.c | 48 | unsigned int a_info; /* Use macros N_MAGIC, etc for access */ |
46 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(rsqrte_u32)(uint32_t a) | 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); | ||
47 | } | 51 | } |
48 | 52 | ||
49 | /* VFPv4 fused multiply-accumulate */ | 53 | +enum { |
50 | +dh_ctype_f16 VFP_HELPER(muladd, h)(dh_ctype_f16 a, dh_ctype_f16 b, | 54 | + /* The string "GNU\0" as a magic number. */ |
51 | + dh_ctype_f16 c, void *fpstp) | 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) | ||
52 | +{ | 68 | +{ |
53 | + float_status *fpst = fpstp; | 69 | + uint32_t pr_type, pr_datasz, step; |
54 | + return float16_muladd(a, b, c, 0, fpst); | 70 | + |
71 | + if (*off > datasz || !QEMU_IS_ALIGNED(*off, ELF_GNU_PROPERTY_ALIGN)) { | ||
72 | + goto error_data; | ||
73 | + } | ||
74 | + datasz -= *off; | ||
75 | + data += *off / sizeof(uint32_t); | ||
76 | + | ||
77 | + if (datasz < 2 * sizeof(uint32_t)) { | ||
78 | + goto error_data; | ||
79 | + } | ||
80 | + pr_type = data[0]; | ||
81 | + pr_datasz = data[1]; | ||
82 | + data += 2; | ||
83 | + datasz -= 2 * sizeof(uint32_t); | ||
84 | + step = ROUND_UP(pr_datasz, ELF_GNU_PROPERTY_ALIGN); | ||
85 | + if (step > datasz) { | ||
86 | + goto error_data; | ||
87 | + } | ||
88 | + | ||
89 | + /* Properties are supposed to be unique and sorted on pr_type. */ | ||
90 | + if (have_prev_type && pr_type <= *prev_type) { | ||
91 | + if (pr_type == *prev_type) { | ||
92 | + error_setg(errp, "Duplicate property in PT_GNU_PROPERTY"); | ||
93 | + } else { | ||
94 | + error_setg(errp, "Unsorted property in PT_GNU_PROPERTY"); | ||
95 | + } | ||
96 | + return false; | ||
97 | + } | ||
98 | + *prev_type = pr_type; | ||
99 | + | ||
100 | + if (!arch_parse_elf_property(pr_type, pr_datasz, data, info, errp)) { | ||
101 | + return false; | ||
102 | + } | ||
103 | + | ||
104 | + *off += 2 * sizeof(uint32_t) + step; | ||
105 | + return true; | ||
106 | + | ||
107 | + error_data: | ||
108 | + error_setg(errp, "Ill-formed property in PT_GNU_PROPERTY"); | ||
109 | + return false; | ||
55 | +} | 110 | +} |
56 | + | 111 | + |
57 | float32 VFP_HELPER(muladd, s)(float32 a, float32 b, float32 c, void *fpstp) | 112 | +/* Process NT_GNU_PROPERTY_TYPE_0. */ |
58 | { | 113 | +static bool parse_elf_properties(int image_fd, |
59 | float_status *fpst = fpstp; | 114 | + struct image_info *info, |
60 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 115 | + const struct elf_phdr *phdr, |
61 | index XXXXXXX..XXXXXXX 100644 | 116 | + char bprm_buf[BPRM_BUF_SIZE], |
62 | --- a/target/arm/translate-vfp.c.inc | 117 | + Error **errp) |
63 | +++ b/target/arm/translate-vfp.c.inc | ||
64 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMAXNM_dp(DisasContext *s, arg_VMAXNM_dp *a) | ||
65 | a->vd, a->vn, a->vm, false); | ||
66 | } | ||
67 | |||
68 | +static bool do_vfm_hp(DisasContext *s, arg_VFMA_sp *a, bool neg_n, bool neg_d) | ||
69 | +{ | 118 | +{ |
119 | + union { | ||
120 | + struct elf_note nhdr; | ||
121 | + uint32_t data[NOTE_DATA_SZ / sizeof(uint32_t)]; | ||
122 | + } note; | ||
123 | + | ||
124 | + int n, off, datasz; | ||
125 | + bool have_prev_type; | ||
126 | + uint32_t prev_type; | ||
127 | + | ||
128 | + /* Unless the arch requires properties, ignore them. */ | ||
129 | + if (!ARCH_USE_GNU_PROPERTY) { | ||
130 | + return true; | ||
131 | + } | ||
132 | + | ||
133 | + /* If the properties are crazy large, that's too bad. */ | ||
134 | + n = phdr->p_filesz; | ||
135 | + if (n > sizeof(note)) { | ||
136 | + error_setg(errp, "PT_GNU_PROPERTY too large"); | ||
137 | + return false; | ||
138 | + } | ||
139 | + if (n < sizeof(note.nhdr)) { | ||
140 | + error_setg(errp, "PT_GNU_PROPERTY too small"); | ||
141 | + return false; | ||
142 | + } | ||
143 | + | ||
144 | + if (phdr->p_offset + n <= BPRM_BUF_SIZE) { | ||
145 | + memcpy(¬e, bprm_buf + phdr->p_offset, n); | ||
146 | + } else { | ||
147 | + ssize_t len = pread(image_fd, ¬e, n, phdr->p_offset); | ||
148 | + if (len != n) { | ||
149 | + error_setg_errno(errp, errno, "Error reading file header"); | ||
150 | + return false; | ||
151 | + } | ||
152 | + } | ||
153 | + | ||
70 | + /* | 154 | + /* |
71 | + * VFNMA : fd = muladd(-fd, fn, fm) | 155 | + * The contents of a valid PT_GNU_PROPERTY is a sequence |
72 | + * VFNMS : fd = muladd(-fd, -fn, fm) | 156 | + * of uint32_t -- swap them all now. |
73 | + * VFMA : fd = muladd( fd, fn, fm) | ||
74 | + * VFMS : fd = muladd( fd, -fn, fm) | ||
75 | + * | ||
76 | + * These are fused multiply-add, and must be done as one floating | ||
77 | + * point operation with no rounding between the multiplication and | ||
78 | + * addition steps. NB that doing the negations here as separate | ||
79 | + * steps is correct : an input NaN should come out with its sign | ||
80 | + * bit flipped if it is a negated-input. | ||
81 | + */ | 157 | + */ |
82 | + TCGv_ptr fpst; | 158 | +#ifdef BSWAP_NEEDED |
83 | + TCGv_i32 vn, vm, vd; | 159 | + for (int i = 0; i < n / 4; i++) { |
160 | + bswap32s(note.data + i); | ||
161 | + } | ||
162 | +#endif | ||
84 | + | 163 | + |
85 | + /* | 164 | + /* |
86 | + * Present in VFPv4 only, and only with the FP16 extension. | 165 | + * Note that nhdr is 3 words, and that the "name" described by namesz |
87 | + * Note that we can't rely on the SIMDFMAC check alone, because | 166 | + * immediately follows nhdr and is thus at the 4th word. Further, all |
88 | + * in a Neon-no-VFP core that ID register field will be non-zero. | 167 | + * of the inputs to the kernel's round_up are multiples of 4. |
89 | + */ | 168 | + */ |
90 | + if (!dc_isar_feature(aa32_fp16_arith, s) || | 169 | + if (note.nhdr.n_type != NT_GNU_PROPERTY_TYPE_0 || |
91 | + !dc_isar_feature(aa32_simdfmac, s) || | 170 | + note.nhdr.n_namesz != NOTE_NAME_SZ || |
92 | + !dc_isar_feature(aa32_fpsp_v2, s)) { | 171 | + note.data[3] != GNU0_MAGIC) { |
93 | + return false; | 172 | + error_setg(errp, "Invalid note in PT_GNU_PROPERTY"); |
94 | + } | 173 | + return false; |
95 | + | 174 | + } |
96 | + if (s->vec_len != 0 || s->vec_stride != 0) { | 175 | + off = sizeof(note.nhdr) + NOTE_NAME_SZ; |
97 | + return false; | 176 | + |
98 | + } | 177 | + datasz = note.nhdr.n_descsz + off; |
99 | + | 178 | + if (datasz > n) { |
100 | + if (!vfp_access_check(s)) { | 179 | + error_setg(errp, "Invalid note size in PT_GNU_PROPERTY"); |
101 | + return true; | 180 | + return false; |
102 | + } | 181 | + } |
103 | + | 182 | + |
104 | + vn = tcg_temp_new_i32(); | 183 | + have_prev_type = false; |
105 | + vm = tcg_temp_new_i32(); | 184 | + prev_type = 0; |
106 | + vd = tcg_temp_new_i32(); | 185 | + while (1) { |
107 | + | 186 | + if (off == datasz) { |
108 | + neon_load_reg32(vn, a->vn); | 187 | + return true; /* end, exit ok */ |
109 | + neon_load_reg32(vm, a->vm); | 188 | + } |
110 | + if (neg_n) { | 189 | + if (!parse_elf_property(note.data, &off, datasz, info, |
111 | + /* VFNMS, VFMS */ | 190 | + have_prev_type, &prev_type, errp)) { |
112 | + gen_helper_vfp_negh(vn, vn); | 191 | + return false; |
113 | + } | 192 | + } |
114 | + neon_load_reg32(vd, a->vd); | 193 | + have_prev_type = true; |
115 | + if (neg_d) { | 194 | + } |
116 | + /* VFNMA, VFNMS */ | ||
117 | + gen_helper_vfp_negh(vd, vd); | ||
118 | + } | ||
119 | + fpst = fpstatus_ptr(FPST_FPCR_F16); | ||
120 | + gen_helper_vfp_muladdh(vd, vn, vm, vd, fpst); | ||
121 | + neon_store_reg32(vd, a->vd); | ||
122 | + | ||
123 | + tcg_temp_free_ptr(fpst); | ||
124 | + tcg_temp_free_i32(vn); | ||
125 | + tcg_temp_free_i32(vm); | ||
126 | + tcg_temp_free_i32(vd); | ||
127 | + | ||
128 | + return true; | ||
129 | +} | 195 | +} |
130 | + | 196 | + |
131 | static bool do_vfm_sp(DisasContext *s, arg_VFMA_sp *a, bool neg_n, bool neg_d) | 197 | /* Load an ELF image into the address space. |
132 | { | 198 | |
133 | /* | 199 | IMAGE_NAME is the filename of the image, to use in error messages. |
134 | @@ -XXX,XX +XXX,XX @@ static bool do_vfm_dp(DisasContext *s, arg_VFMA_dp *a, bool neg_n, bool neg_d) | 200 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, |
135 | MAKE_ONE_VFM_TRANS_FN(VFNMA, PREC, false, true) \ | 201 | goto exit_errmsg; |
136 | MAKE_ONE_VFM_TRANS_FN(VFNMS, PREC, true, true) | 202 | } |
137 | 203 | *pinterp_name = g_steal_pointer(&interp_name); | |
138 | +MAKE_VFM_TRANS_FNS(hp) | 204 | + } else if (eppnt->p_type == PT_GNU_PROPERTY) { |
139 | MAKE_VFM_TRANS_FNS(sp) | 205 | + if (!parse_elf_properties(image_fd, info, eppnt, bprm_buf, &err)) { |
140 | MAKE_VFM_TRANS_FNS(dp) | 206 | + goto exit_errmsg; |
207 | + } | ||
208 | } | ||
209 | } | ||
141 | 210 | ||
142 | -- | 211 | -- |
143 | 2.20.1 | 212 | 2.20.1 |
144 | 213 | ||
145 | 214 | diff view generated by jsdifflib |
1 | The fp16 extension includes a new instruction VMOVX, which copies the | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | upper 16 bits of a 32-bit source VFP register into the lower 16 | ||
3 | bits of the destination and zeroes the high half of the destination. | ||
4 | Implement it. | ||
5 | 2 | ||
3 | Use the new generic support for NT_GNU_PROPERTY_TYPE_0. | ||
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20201021173749.111103-12-richard.henderson@linaro.org | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20200828183354.27913-21-peter.maydell@linaro.org | ||
9 | --- | 9 | --- |
10 | target/arm/vfp-uncond.decode | 3 +++ | 10 | linux-user/elfload.c | 48 ++++++++++++++++++++++++++++++++++++++++++-- |
11 | target/arm/translate-vfp.c.inc | 25 +++++++++++++++++++++++++ | 11 | 1 file changed, 46 insertions(+), 2 deletions(-) |
12 | 2 files changed, 28 insertions(+) | ||
13 | 12 | ||
14 | diff --git a/target/arm/vfp-uncond.decode b/target/arm/vfp-uncond.decode | 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/vfp-uncond.decode | 15 | --- a/linux-user/elfload.c |
17 | +++ b/target/arm/vfp-uncond.decode | 16 | +++ b/linux-user/elfload.c |
18 | @@ -XXX,XX +XXX,XX @@ VCVT 1111 1110 1.11 11 rm:2 .... 1010 op:1 1.0 .... \ | 17 | @@ -XXX,XX +XXX,XX @@ static void elf_core_copy_regs(target_elf_gregset_t *regs, |
19 | VCVT 1111 1110 1.11 11 rm:2 .... 1011 op:1 1.0 .... \ | 18 | |
20 | vm=%vm_dp vd=%vd_sp sz=3 | 19 | #include "elf.h" |
21 | 20 | ||
22 | +VMOVX 1111 1110 1.11 0000 .... 1010 01 . 0 .... \ | 21 | +/* We must delay the following stanzas until after "elf.h". */ |
23 | + vd=%vd_sp vm=%vm_sp | 22 | +#if defined(TARGET_AARCH64) |
24 | + | 23 | + |
25 | VINS 1111 1110 1.11 0000 .... 1010 11 . 0 .... \ | 24 | +static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, |
26 | vd=%vd_sp vm=%vm_sp | 25 | + const uint32_t *data, |
27 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 26 | + struct image_info *info, |
28 | index XXXXXXX..XXXXXXX 100644 | 27 | + Error **errp) |
29 | --- a/target/arm/translate-vfp.c.inc | ||
30 | +++ b/target/arm/translate-vfp.c.inc | ||
31 | @@ -XXX,XX +XXX,XX @@ static bool trans_VINS(DisasContext *s, arg_VINS *a) | ||
32 | tcg_temp_free_i32(rd); | ||
33 | return true; | ||
34 | } | ||
35 | + | ||
36 | +static bool trans_VMOVX(DisasContext *s, arg_VINS *a) | ||
37 | +{ | 28 | +{ |
38 | + TCGv_i32 rm; | 29 | + if (pr_type == GNU_PROPERTY_AARCH64_FEATURE_1_AND) { |
39 | + | 30 | + if (pr_datasz != sizeof(uint32_t)) { |
40 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 31 | + error_setg(errp, "Ill-formed GNU_PROPERTY_AARCH64_FEATURE_1_AND"); |
41 | + return false; | 32 | + return false; |
33 | + } | ||
34 | + /* We will extract GNU_PROPERTY_AARCH64_FEATURE_1_BTI later. */ | ||
35 | + info->note_flags = *data; | ||
42 | + } | 36 | + } |
43 | + | ||
44 | + if (s->vec_len != 0 || s->vec_stride != 0) { | ||
45 | + return false; | ||
46 | + } | ||
47 | + | ||
48 | + if (!vfp_access_check(s)) { | ||
49 | + return true; | ||
50 | + } | ||
51 | + | ||
52 | + /* Set Vd to high half of Vm */ | ||
53 | + rm = tcg_temp_new_i32(); | ||
54 | + neon_load_reg32(rm, a->vm); | ||
55 | + tcg_gen_shri_i32(rm, rm, 16); | ||
56 | + neon_store_reg32(rm, a->vd); | ||
57 | + tcg_temp_free_i32(rm); | ||
58 | + return true; | 37 | + return true; |
59 | +} | 38 | +} |
39 | +#define ARCH_USE_GNU_PROPERTY 1 | ||
40 | + | ||
41 | +#else | ||
42 | + | ||
43 | static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
44 | const uint32_t *data, | ||
45 | struct image_info *info, | ||
46 | @@ -XXX,XX +XXX,XX @@ static bool arch_parse_elf_property(uint32_t pr_type, uint32_t pr_datasz, | ||
47 | } | ||
48 | #define ARCH_USE_GNU_PROPERTY 0 | ||
49 | |||
50 | +#endif | ||
51 | + | ||
52 | struct exec | ||
53 | { | ||
54 | unsigned int a_info; /* Use macros N_MAGIC, etc for access */ | ||
55 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
56 | struct elfhdr *ehdr = (struct elfhdr *)bprm_buf; | ||
57 | struct elf_phdr *phdr; | ||
58 | abi_ulong load_addr, load_bias, loaddr, hiaddr, error; | ||
59 | - int i, retval; | ||
60 | + int i, retval, prot_exec; | ||
61 | Error *err = NULL; | ||
62 | |||
63 | /* First of all, some simple consistency checks */ | ||
64 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
65 | info->brk = 0; | ||
66 | info->elf_flags = ehdr->e_flags; | ||
67 | |||
68 | + prot_exec = PROT_EXEC; | ||
69 | +#ifdef TARGET_AARCH64 | ||
70 | + /* | ||
71 | + * If the BTI feature is present, this indicates that the executable | ||
72 | + * pages of the startup binary should be mapped with PROT_BTI, so that | ||
73 | + * branch targets are enforced. | ||
74 | + * | ||
75 | + * The startup binary is either the interpreter or the static executable. | ||
76 | + * The interpreter is responsible for all pages of a dynamic executable. | ||
77 | + * | ||
78 | + * Elf notes are backward compatible to older cpus. | ||
79 | + * Do not enable BTI unless it is supported. | ||
80 | + */ | ||
81 | + if ((info->note_flags & GNU_PROPERTY_AARCH64_FEATURE_1_BTI) | ||
82 | + && (pinterp_name == NULL || *pinterp_name == 0) | ||
83 | + && cpu_isar_feature(aa64_bti, ARM_CPU(thread_cpu))) { | ||
84 | + prot_exec |= TARGET_PROT_BTI; | ||
85 | + } | ||
86 | +#endif | ||
87 | + | ||
88 | for (i = 0; i < ehdr->e_phnum; i++) { | ||
89 | struct elf_phdr *eppnt = phdr + i; | ||
90 | if (eppnt->p_type == PT_LOAD) { | ||
91 | @@ -XXX,XX +XXX,XX @@ static void load_elf_image(const char *image_name, int image_fd, | ||
92 | elf_prot |= PROT_WRITE; | ||
93 | } | ||
94 | if (eppnt->p_flags & PF_X) { | ||
95 | - elf_prot |= PROT_EXEC; | ||
96 | + elf_prot |= prot_exec; | ||
97 | } | ||
98 | |||
99 | vaddr = load_bias + eppnt->p_vaddr; | ||
60 | -- | 100 | -- |
61 | 2.20.1 | 101 | 2.20.1 |
62 | 102 | ||
63 | 103 | diff view generated by jsdifflib |
1 | In the gvec helper functions for indexed operations, for AArch32 | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | Neon the oprsz (total size of the vector) can be less than 16 bytes | 2 | |
3 | if the operation is on a D reg. Since the inner loop in these | 3 | The note test requires gcc 10 for -mbranch-protection=standard. |
4 | helpers always goes from 0 to segment, we must clamp it based | 4 | The mmap test uses PROT_BTI and does not require special compiler support. |
5 | on oprsz to avoid processing a full 16 byte segment when asked to | 5 | |
6 | handle an 8 byte wide vector. | 6 | Acked-by: Alex Bennée <alex.bennee@linaro.org> |
7 | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | |
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20201021173749.111103-13-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20200828183354.27913-43-peter.maydell@linaro.org | ||
11 | --- | 11 | --- |
12 | target/arm/vec_helper.c | 12 ++++++++---- | 12 | tests/tcg/aarch64/bti-1.c | 62 ++++++++++++++++ |
13 | 1 file changed, 8 insertions(+), 4 deletions(-) | 13 | tests/tcg/aarch64/bti-2.c | 116 ++++++++++++++++++++++++++++++ |
14 | 14 | tests/tcg/aarch64/bti-crt.inc.c | 51 +++++++++++++ | |
15 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.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 | ||
16 | index XXXXXXX..XXXXXXX 100644 | 270 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/vec_helper.c | 271 | --- a/tests/tcg/aarch64/Makefile.target |
18 | +++ b/target/arm/vec_helper.c | 272 | +++ b/tests/tcg/aarch64/Makefile.target |
19 | @@ -XXX,XX +XXX,XX @@ DO_MULADD(gvec_vfms_s, float32_mulsub_f, float32) | 273 | @@ -XXX,XX +XXX,XX @@ run-pauth-%: QEMU_OPTS += -cpu max |
20 | #define DO_MUL_IDX(NAME, TYPE, H) \ | 274 | run-plugin-pauth-%: QEMU_OPTS += -cpu max |
21 | void HELPER(NAME)(void *vd, void *vn, void *vm, uint32_t desc) \ | 275 | endif |
22 | { \ | 276 | |
23 | - intptr_t i, j, oprsz = simd_oprsz(desc), segment = 16 / sizeof(TYPE); \ | 277 | +# BTI Tests |
24 | + intptr_t i, j, oprsz = simd_oprsz(desc); \ | 278 | +# bti-1 tests the elf notes, so we require special compiler support. |
25 | + intptr_t segment = MIN(16, oprsz) / sizeof(TYPE); \ | 279 | +ifneq ($(DOCKER_IMAGE)$(CROSS_CC_HAS_ARMV8_BTI),) |
26 | intptr_t idx = simd_data(desc); \ | 280 | +AARCH64_TESTS += bti-1 |
27 | TYPE *d = vd, *n = vn, *m = vm; \ | 281 | +bti-1: CFLAGS += -mbranch-protection=standard |
28 | for (i = 0; i < oprsz / sizeof(TYPE); i += segment) { \ | 282 | +bti-1: LDFLAGS += -nostdlib |
29 | @@ -XXX,XX +XXX,XX @@ DO_MUL_IDX(gvec_mul_idx_d, uint64_t, ) | 283 | +endif |
30 | #define DO_MLA_IDX(NAME, TYPE, OP, H) \ | 284 | +# bti-2 tests PROT_BTI, so no special compiler support required. |
31 | void HELPER(NAME)(void *vd, void *vn, void *vm, void *va, uint32_t desc) \ | 285 | +AARCH64_TESTS += bti-2 |
32 | { \ | 286 | + |
33 | - intptr_t i, j, oprsz = simd_oprsz(desc), segment = 16 / sizeof(TYPE); \ | 287 | # Semihosting smoke test for linux-user |
34 | + intptr_t i, j, oprsz = simd_oprsz(desc); \ | 288 | AARCH64_TESTS += semihosting |
35 | + intptr_t segment = MIN(16, oprsz) / sizeof(TYPE); \ | 289 | run-semihosting: semihosting |
36 | intptr_t idx = simd_data(desc); \ | 290 | diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh |
37 | TYPE *d = vd, *n = vn, *m = vm, *a = va; \ | 291 | index XXXXXXX..XXXXXXX 100755 |
38 | for (i = 0; i < oprsz / sizeof(TYPE); i += segment) { \ | 292 | --- a/tests/tcg/configure.sh |
39 | @@ -XXX,XX +XXX,XX @@ DO_MLA_IDX(gvec_mls_idx_d, uint64_t, -, ) | 293 | +++ b/tests/tcg/configure.sh |
40 | #define DO_FMUL_IDX(NAME, TYPE, H) \ | 294 | @@ -XXX,XX +XXX,XX @@ for target in $target_list; do |
41 | void HELPER(NAME)(void *vd, void *vn, void *vm, void *stat, uint32_t desc) \ | 295 | -march=armv8.3-a -o $TMPE $TMPC; then |
42 | { \ | 296 | echo "CROSS_CC_HAS_ARMV8_3=y" >> $config_target_mak |
43 | - intptr_t i, j, oprsz = simd_oprsz(desc), segment = 16 / sizeof(TYPE); \ | 297 | fi |
44 | + intptr_t i, j, oprsz = simd_oprsz(desc); \ | 298 | + if do_compiler "$target_compiler" $target_compiler_cflags \ |
45 | + intptr_t segment = MIN(16, oprsz) / sizeof(TYPE); \ | 299 | + -mbranch-protection=standard -o $TMPE $TMPC; then |
46 | intptr_t idx = simd_data(desc); \ | 300 | + echo "CROSS_CC_HAS_ARMV8_BTI=y" >> $config_target_mak |
47 | TYPE *d = vd, *n = vn, *m = vm; \ | 301 | + fi |
48 | for (i = 0; i < oprsz / sizeof(TYPE); i += segment) { \ | 302 | ;; |
49 | @@ -XXX,XX +XXX,XX @@ DO_FMUL_IDX(gvec_fmul_idx_d, float64, ) | 303 | esac |
50 | void HELPER(NAME)(void *vd, void *vn, void *vm, void *va, \ | 304 | |
51 | void *stat, uint32_t desc) \ | ||
52 | { \ | ||
53 | - intptr_t i, j, oprsz = simd_oprsz(desc), segment = 16 / sizeof(TYPE); \ | ||
54 | + intptr_t i, j, oprsz = simd_oprsz(desc); \ | ||
55 | + intptr_t segment = MIN(16, oprsz) / sizeof(TYPE); \ | ||
56 | TYPE op1_neg = extract32(desc, SIMD_DATA_SHIFT, 1); \ | ||
57 | intptr_t idx = desc >> (SIMD_DATA_SHIFT + 1); \ | ||
58 | TYPE *d = vd, *n = vn, *m = vm, *a = va; \ | ||
59 | -- | 305 | -- |
60 | 2.20.1 | 306 | 2.20.1 |
61 | 307 | ||
62 | 308 | diff view generated by jsdifflib |
1 | Convert the Neon VRINTX insn to use gvec, and use this to implement | 1 | From: Thomas Huth <thuth@redhat.com> |
---|---|---|---|
2 | fp16 support for it. | ||
3 | 2 | ||
3 | When compiling with -Werror=implicit-fallthrough, gcc complains about | ||
4 | missing fallthrough annotations in this file. Looking at the code, | ||
5 | the fallthrough is very likely intended here, so add some comments | ||
6 | to silence the compiler warnings. | ||
7 | |||
8 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
9 | Message-id: 20201020105938.23209-1-thuth@redhat.com | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-42-peter.maydell@linaro.org | ||
7 | --- | 12 | --- |
8 | target/arm/helper.h | 3 +++ | 13 | hw/arm/highbank.c | 2 ++ |
9 | target/arm/vec_helper.c | 3 +++ | 14 | 1 file changed, 2 insertions(+) |
10 | target/arm/translate-neon.c.inc | 45 +++------------------------------ | ||
11 | 3 files changed, 9 insertions(+), 42 deletions(-) | ||
12 | 15 | ||
13 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 16 | diff --git a/hw/arm/highbank.c b/hw/arm/highbank.c |
14 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.h | 18 | --- a/hw/arm/highbank.c |
16 | +++ b/target/arm/helper.h | 19 | +++ b/hw/arm/highbank.c |
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(gvec_vcvt_rm_uh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 20 | @@ -XXX,XX +XXX,XX @@ static void hb_reset_secondary(ARMCPU *cpu, const struct arm_boot_info *info) |
18 | DEF_HELPER_FLAGS_4(gvec_vrint_rm_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 21 | address_space_stl_notdirty(&address_space_memory, |
19 | DEF_HELPER_FLAGS_4(gvec_vrint_rm_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 22 | SMP_BOOT_REG + 0x30, 0, |
20 | 23 | MEMTXATTRS_UNSPECIFIED, NULL); | |
21 | +DEF_HELPER_FLAGS_4(gvec_vrintx_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 24 | + /* fallthrough */ |
22 | +DEF_HELPER_FLAGS_4(gvec_vrintx_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 25 | case 3: |
23 | + | 26 | address_space_stl_notdirty(&address_space_memory, |
24 | DEF_HELPER_FLAGS_4(gvec_frecpe_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 27 | SMP_BOOT_REG + 0x20, 0, |
25 | DEF_HELPER_FLAGS_4(gvec_frecpe_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 28 | MEMTXATTRS_UNSPECIFIED, NULL); |
26 | DEF_HELPER_FLAGS_4(gvec_frecpe_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 29 | + /* fallthrough */ |
27 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 30 | case 2: |
28 | index XXXXXXX..XXXXXXX 100644 | 31 | address_space_stl_notdirty(&address_space_memory, |
29 | --- a/target/arm/vec_helper.c | 32 | SMP_BOOT_REG + 0x10, 0, |
30 | +++ b/target/arm/vec_helper.c | ||
31 | @@ -XXX,XX +XXX,XX @@ DO_2OP(gvec_frsqrte_h, helper_rsqrte_f16, float16) | ||
32 | DO_2OP(gvec_frsqrte_s, helper_rsqrte_f32, float32) | ||
33 | DO_2OP(gvec_frsqrte_d, helper_rsqrte_f64, float64) | ||
34 | |||
35 | +DO_2OP(gvec_vrintx_h, float16_round_to_int, float16) | ||
36 | +DO_2OP(gvec_vrintx_s, float32_round_to_int, float32) | ||
37 | + | ||
38 | DO_2OP(gvec_sitos, helper_vfp_sitos, int32_t) | ||
39 | DO_2OP(gvec_uitos, helper_vfp_uitos, uint32_t) | ||
40 | DO_2OP(gvec_tosizs, helper_vfp_tosizs, float32) | ||
41 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/target/arm/translate-neon.c.inc | ||
44 | +++ b/target/arm/translate-neon.c.inc | ||
45 | @@ -XXX,XX +XXX,XX @@ static bool trans_VQNEG(DisasContext *s, arg_2misc *a) | ||
46 | return do_2misc(s, a, fn[a->size]); | ||
47 | } | ||
48 | |||
49 | -static bool do_2misc_fp(DisasContext *s, arg_2misc *a, | ||
50 | - NeonGenOneSingleOpFn *fn) | ||
51 | -{ | ||
52 | - int pass; | ||
53 | - TCGv_ptr fpst; | ||
54 | - | ||
55 | - /* Handle a 2-reg-misc operation by iterating 32 bits at a time */ | ||
56 | - if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | ||
57 | - return false; | ||
58 | - } | ||
59 | - | ||
60 | - /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
61 | - if (!dc_isar_feature(aa32_simd_r32, s) && | ||
62 | - ((a->vd | a->vm) & 0x10)) { | ||
63 | - return false; | ||
64 | - } | ||
65 | - | ||
66 | - if (a->size != 2) { | ||
67 | - /* TODO: FP16 will be the size == 1 case */ | ||
68 | - return false; | ||
69 | - } | ||
70 | - | ||
71 | - if ((a->vd | a->vm) & a->q) { | ||
72 | - return false; | ||
73 | - } | ||
74 | - | ||
75 | - if (!vfp_access_check(s)) { | ||
76 | - return true; | ||
77 | - } | ||
78 | - | ||
79 | - fpst = fpstatus_ptr(FPST_STD); | ||
80 | - for (pass = 0; pass < (a->q ? 4 : 2); pass++) { | ||
81 | - TCGv_i32 tmp = neon_load_reg(a->vm, pass); | ||
82 | - fn(tmp, tmp, fpst); | ||
83 | - neon_store_reg(a->vd, pass, tmp); | ||
84 | - } | ||
85 | - tcg_temp_free_ptr(fpst); | ||
86 | - | ||
87 | - return true; | ||
88 | -} | ||
89 | - | ||
90 | #define DO_2MISC_FP_VEC(INSN, HFUNC, SFUNC) \ | ||
91 | static void gen_##INSN(unsigned vece, uint32_t rd_ofs, \ | ||
92 | uint32_t rm_ofs, \ | ||
93 | @@ -XXX,XX +XXX,XX @@ DO_2MISC_FP_VEC(VCVT_FU, gen_helper_gvec_ustoh, gen_helper_gvec_uitos) | ||
94 | DO_2MISC_FP_VEC(VCVT_SF, gen_helper_gvec_tosszh, gen_helper_gvec_tosizs) | ||
95 | DO_2MISC_FP_VEC(VCVT_UF, gen_helper_gvec_touszh, gen_helper_gvec_touizs) | ||
96 | |||
97 | +DO_2MISC_FP_VEC(VRINTX_impl, gen_helper_gvec_vrintx_h, gen_helper_gvec_vrintx_s) | ||
98 | + | ||
99 | static bool trans_VRINTX(DisasContext *s, arg_2misc *a) | ||
100 | { | ||
101 | if (!arm_dc_feature(s, ARM_FEATURE_V8)) { | ||
102 | return false; | ||
103 | } | ||
104 | - return do_2misc_fp(s, a, gen_helper_rints_exact); | ||
105 | + return trans_VRINTX_impl(s, a); | ||
106 | } | ||
107 | |||
108 | #define DO_VEC_RMODE(INSN, RMODE, OP) \ | ||
109 | -- | 33 | -- |
110 | 2.20.1 | 34 | 2.20.1 |
111 | 35 | ||
112 | 36 | diff view generated by jsdifflib |
1 | Implement fp16 for the Neon VCVT insns which convert between | 1 | From: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> |
---|---|---|---|
2 | float and fixed-point. | ||
3 | 2 | ||
3 | This patch sets min_cpus field for xlnx-versal-virt platform, | ||
4 | because it always creates XLNX_VERSAL_NR_ACPUS cpus even with | ||
5 | -smp 1 command line option. | ||
6 | |||
7 | Signed-off-by: Pavel Dovgalyuk <pavel.dovgalyuk@ispras.ru> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
10 | Message-id: 160343854912.8460.17915238517799132371.stgit@pasha-ThinkPad-X280 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-39-peter.maydell@linaro.org | ||
7 | --- | 12 | --- |
8 | target/arm/helper.h | 5 +++++ | 13 | hw/arm/xlnx-versal-virt.c | 1 + |
9 | target/arm/neon-dp.decode | 8 +++++++- | 14 | 1 file changed, 1 insertion(+) |
10 | target/arm/vec_helper.c | 4 ++++ | ||
11 | target/arm/translate-neon.c.inc | 5 +++++ | ||
12 | 4 files changed, 21 insertions(+), 1 deletion(-) | ||
13 | 15 | ||
14 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 16 | diff --git a/hw/arm/xlnx-versal-virt.c b/hw/arm/xlnx-versal-virt.c |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/helper.h | 18 | --- a/hw/arm/xlnx-versal-virt.c |
17 | +++ b/target/arm/helper.h | 19 | +++ b/hw/arm/xlnx-versal-virt.c |
18 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(gvec_vcvt_uf, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 20 | @@ -XXX,XX +XXX,XX @@ static void versal_virt_machine_class_init(ObjectClass *oc, void *data) |
19 | DEF_HELPER_FLAGS_4(gvec_vcvt_fs, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 21 | |
20 | DEF_HELPER_FLAGS_4(gvec_vcvt_fu, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 22 | mc->desc = "Xilinx Versal Virtual development board"; |
21 | 23 | mc->init = versal_virt_init; | |
22 | +DEF_HELPER_FLAGS_4(gvec_vcvt_sh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 24 | + mc->min_cpus = XLNX_VERSAL_NR_ACPUS; |
23 | +DEF_HELPER_FLAGS_4(gvec_vcvt_uh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 25 | mc->max_cpus = XLNX_VERSAL_NR_ACPUS; |
24 | +DEF_HELPER_FLAGS_4(gvec_vcvt_hs, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 26 | mc->default_cpus = XLNX_VERSAL_NR_ACPUS; |
25 | +DEF_HELPER_FLAGS_4(gvec_vcvt_hu, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 27 | mc->no_cdrom = true; |
26 | + | ||
27 | DEF_HELPER_FLAGS_4(gvec_frecpe_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
28 | DEF_HELPER_FLAGS_4(gvec_frecpe_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
29 | DEF_HELPER_FLAGS_4(gvec_frecpe_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
30 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/target/arm/neon-dp.decode | ||
33 | +++ b/target/arm/neon-dp.decode | ||
34 | @@ -XXX,XX +XXX,XX @@ VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp | ||
35 | # We use size=0 for fp32 and size=1 for fp16 to match the 3-same encodings. | ||
36 | @2reg_vcvt .... ... . . . 1 ..... .... .... . q:1 . . .... \ | ||
37 | &2reg_shift vm=%vm_dp vd=%vd_dp size=0 shift=%neon_rshift_i5 | ||
38 | +@2reg_vcvt_f16 .... ... . . . 11 .... .... .... . q:1 . . .... \ | ||
39 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=1 shift=%neon_rshift_i4 | ||
40 | |||
41 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_d | ||
42 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_s | ||
43 | @@ -XXX,XX +XXX,XX @@ VSHLL_U_2sh 1111 001 1 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_h | ||
44 | VSHLL_U_2sh 1111 001 1 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_b | ||
45 | |||
46 | # VCVT fixed<->float conversions | ||
47 | -# TODO: FP16 fixed<->float conversions are opc==0b1100 and 0b1101 | ||
48 | +VCVT_SH_2sh 1111 001 0 1 . ...... .... 1100 0 . . 1 .... @2reg_vcvt_f16 | ||
49 | +VCVT_UH_2sh 1111 001 1 1 . ...... .... 1100 0 . . 1 .... @2reg_vcvt_f16 | ||
50 | +VCVT_HS_2sh 1111 001 0 1 . ...... .... 1101 0 . . 1 .... @2reg_vcvt_f16 | ||
51 | +VCVT_HU_2sh 1111 001 1 1 . ...... .... 1101 0 . . 1 .... @2reg_vcvt_f16 | ||
52 | + | ||
53 | VCVT_SF_2sh 1111 001 0 1 . ...... .... 1110 0 . . 1 .... @2reg_vcvt | ||
54 | VCVT_UF_2sh 1111 001 1 1 . ...... .... 1110 0 . . 1 .... @2reg_vcvt | ||
55 | VCVT_FS_2sh 1111 001 0 1 . ...... .... 1111 0 . . 1 .... @2reg_vcvt | ||
56 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/target/arm/vec_helper.c | ||
59 | +++ b/target/arm/vec_helper.c | ||
60 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_FIXED(gvec_vcvt_sf, helper_vfp_sltos, uint32_t) | ||
61 | DO_VCVT_FIXED(gvec_vcvt_uf, helper_vfp_ultos, uint32_t) | ||
62 | DO_VCVT_FIXED(gvec_vcvt_fs, helper_vfp_tosls_round_to_zero, uint32_t) | ||
63 | DO_VCVT_FIXED(gvec_vcvt_fu, helper_vfp_touls_round_to_zero, uint32_t) | ||
64 | +DO_VCVT_FIXED(gvec_vcvt_sh, helper_vfp_shtoh, uint16_t) | ||
65 | +DO_VCVT_FIXED(gvec_vcvt_uh, helper_vfp_uhtoh, uint16_t) | ||
66 | +DO_VCVT_FIXED(gvec_vcvt_hs, helper_vfp_toshh_round_to_zero, uint16_t) | ||
67 | +DO_VCVT_FIXED(gvec_vcvt_hu, helper_vfp_touhh_round_to_zero, uint16_t) | ||
68 | |||
69 | #undef DO_VCVT_FIXED | ||
70 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/target/arm/translate-neon.c.inc | ||
73 | +++ b/target/arm/translate-neon.c.inc | ||
74 | @@ -XXX,XX +XXX,XX @@ DO_FP_2SH(VCVT_UF, gen_helper_gvec_vcvt_uf) | ||
75 | DO_FP_2SH(VCVT_FS, gen_helper_gvec_vcvt_fs) | ||
76 | DO_FP_2SH(VCVT_FU, gen_helper_gvec_vcvt_fu) | ||
77 | |||
78 | +DO_FP_2SH(VCVT_SH, gen_helper_gvec_vcvt_sh) | ||
79 | +DO_FP_2SH(VCVT_UH, gen_helper_gvec_vcvt_uh) | ||
80 | +DO_FP_2SH(VCVT_HS, gen_helper_gvec_vcvt_hs) | ||
81 | +DO_FP_2SH(VCVT_HU, gen_helper_gvec_vcvt_hu) | ||
82 | + | ||
83 | static uint64_t asimd_imm_const(uint32_t imm, int cmode, int op) | ||
84 | { | ||
85 | /* | ||
86 | -- | 28 | -- |
87 | 2.20.1 | 29 | 2.20.1 |
88 | 30 | ||
89 | 31 | diff view generated by jsdifflib |
1 | Convert the Neon float-integer VCVT insns to gvec, and use this | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | to implement fp16 support for them. | ||
3 | 2 | ||
4 | Note that unlike the VFP int<->fp16 VCVT insns we converted | 3 | This allows us to reuse npcm7xx_timer_pause for the watchdog timer. |
5 | earlier and which convert to/from a 32-bit integer, these | ||
6 | Neon insns convert to/from 16-bit integers. So we can use | ||
7 | the existing vfp conversion helpers for the f32<->u32/i32 | ||
8 | case but need to provide our own for f16<->u16/i16. | ||
9 | 4 | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Message-id: 20200828183354.27913-37-peter.maydell@linaro.org | ||
13 | --- | 8 | --- |
14 | target/arm/helper.h | 9 +++++++++ | 9 | hw/timer/npcm7xx_timer.c | 6 +++--- |
15 | target/arm/vec_helper.c | 29 +++++++++++++++++++++++++++++ | 10 | 1 file changed, 3 insertions(+), 3 deletions(-) |
16 | target/arm/translate-neon.c.inc | 15 ++++----------- | ||
17 | 3 files changed, 42 insertions(+), 11 deletions(-) | ||
18 | 11 | ||
19 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 12 | diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c |
20 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/helper.h | 14 | --- a/hw/timer/npcm7xx_timer.c |
22 | +++ b/target/arm/helper.h | 15 | +++ b/hw/timer/npcm7xx_timer.c |
23 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(neon_padds, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 16 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t) |
24 | DEF_HELPER_FLAGS_5(neon_pmaxs, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 17 | timer_del(&t->qtimer); |
25 | DEF_HELPER_FLAGS_5(neon_pmins, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 18 | now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
26 | 19 | t->remaining_ns = t->expires_ns - now; | |
27 | +DEF_HELPER_FLAGS_4(gvec_sstoh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 20 | - if (t->remaining_ns <= 0) { |
28 | +DEF_HELPER_FLAGS_4(gvec_sitos, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 21 | - npcm7xx_timer_reached_zero(t); |
29 | +DEF_HELPER_FLAGS_4(gvec_ustoh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 22 | - } |
30 | +DEF_HELPER_FLAGS_4(gvec_uitos, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
31 | +DEF_HELPER_FLAGS_4(gvec_tosszh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
32 | +DEF_HELPER_FLAGS_4(gvec_tosizs, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
33 | +DEF_HELPER_FLAGS_4(gvec_touszh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
34 | +DEF_HELPER_FLAGS_4(gvec_touizs, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
35 | + | ||
36 | DEF_HELPER_FLAGS_4(gvec_frecpe_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
37 | DEF_HELPER_FLAGS_4(gvec_frecpe_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
38 | DEF_HELPER_FLAGS_4(gvec_frecpe_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
39 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/target/arm/vec_helper.c | ||
42 | +++ b/target/arm/vec_helper.c | ||
43 | @@ -XXX,XX +XXX,XX @@ static uint32_t float32_acgt(float32 op1, float32 op2, float_status *stat) | ||
44 | return -float32_lt(float32_abs(op2), float32_abs(op1), stat); | ||
45 | } | 23 | } |
46 | 24 | ||
47 | +static int16_t vfp_tosszh(float16 x, void *fpstp) | 25 | /* |
48 | +{ | 26 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) |
49 | + float_status *fpst = fpstp; | 27 | } else { |
50 | + if (float16_is_any_nan(x)) { | 28 | t->tcsr &= ~NPCM7XX_TCSR_CACT; |
51 | + float_raise(float_flag_invalid, fpst); | 29 | npcm7xx_timer_pause(t); |
52 | + return 0; | 30 | + if (t->remaining_ns <= 0) { |
53 | + } | 31 | + npcm7xx_timer_reached_zero(t); |
54 | + return float16_to_int16_round_to_zero(x, fpst); | 32 | + } |
55 | +} | 33 | } |
56 | + | 34 | } |
57 | +static uint16_t vfp_touszh(float16 x, void *fpstp) | ||
58 | +{ | ||
59 | + float_status *fpst = fpstp; | ||
60 | + if (float16_is_any_nan(x)) { | ||
61 | + float_raise(float_flag_invalid, fpst); | ||
62 | + return 0; | ||
63 | + } | ||
64 | + return float16_to_uint16_round_to_zero(x, fpst); | ||
65 | +} | ||
66 | + | ||
67 | #define DO_2OP(NAME, FUNC, TYPE) \ | ||
68 | void HELPER(NAME)(void *vd, void *vn, void *stat, uint32_t desc) \ | ||
69 | { \ | ||
70 | @@ -XXX,XX +XXX,XX @@ DO_2OP(gvec_frsqrte_h, helper_rsqrte_f16, float16) | ||
71 | DO_2OP(gvec_frsqrte_s, helper_rsqrte_f32, float32) | ||
72 | DO_2OP(gvec_frsqrte_d, helper_rsqrte_f64, float64) | ||
73 | |||
74 | +DO_2OP(gvec_sitos, helper_vfp_sitos, int32_t) | ||
75 | +DO_2OP(gvec_uitos, helper_vfp_uitos, uint32_t) | ||
76 | +DO_2OP(gvec_tosizs, helper_vfp_tosizs, float32) | ||
77 | +DO_2OP(gvec_touizs, helper_vfp_touizs, float32) | ||
78 | +DO_2OP(gvec_sstoh, int16_to_float16, int16_t) | ||
79 | +DO_2OP(gvec_ustoh, uint16_to_float16, uint16_t) | ||
80 | +DO_2OP(gvec_tosszh, vfp_tosszh, float16) | ||
81 | +DO_2OP(gvec_touszh, vfp_touszh, float16) | ||
82 | + | ||
83 | #define WRAP_CMP0_FWD(FN, CMPOP, TYPE) \ | ||
84 | static TYPE TYPE##_##FN##0(TYPE op, float_status *stat) \ | ||
85 | { \ | ||
86 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/target/arm/translate-neon.c.inc | ||
89 | +++ b/target/arm/translate-neon.c.inc | ||
90 | @@ -XXX,XX +XXX,XX @@ static bool do_2misc_fp(DisasContext *s, arg_2misc *a, | ||
91 | return true; | ||
92 | } | 35 | } |
93 | |||
94 | -#define DO_2MISC_FP(INSN, FUNC) \ | ||
95 | - static bool trans_##INSN(DisasContext *s, arg_2misc *a) \ | ||
96 | - { \ | ||
97 | - return do_2misc_fp(s, a, FUNC); \ | ||
98 | - } | ||
99 | - | ||
100 | -DO_2MISC_FP(VCVT_FS, gen_helper_vfp_sitos) | ||
101 | -DO_2MISC_FP(VCVT_FU, gen_helper_vfp_uitos) | ||
102 | -DO_2MISC_FP(VCVT_SF, gen_helper_vfp_tosizs) | ||
103 | -DO_2MISC_FP(VCVT_UF, gen_helper_vfp_touizs) | ||
104 | - | ||
105 | #define DO_2MISC_FP_VEC(INSN, HFUNC, SFUNC) \ | ||
106 | static void gen_##INSN(unsigned vece, uint32_t rd_ofs, \ | ||
107 | uint32_t rm_ofs, \ | ||
108 | @@ -XXX,XX +XXX,XX @@ DO_2MISC_FP_VEC(VCGE0_F, gen_helper_gvec_fcge0_h, gen_helper_gvec_fcge0_s) | ||
109 | DO_2MISC_FP_VEC(VCEQ0_F, gen_helper_gvec_fceq0_h, gen_helper_gvec_fceq0_s) | ||
110 | DO_2MISC_FP_VEC(VCLT0_F, gen_helper_gvec_fclt0_h, gen_helper_gvec_fclt0_s) | ||
111 | DO_2MISC_FP_VEC(VCLE0_F, gen_helper_gvec_fcle0_h, gen_helper_gvec_fcle0_s) | ||
112 | +DO_2MISC_FP_VEC(VCVT_FS, gen_helper_gvec_sstoh, gen_helper_gvec_sitos) | ||
113 | +DO_2MISC_FP_VEC(VCVT_FU, gen_helper_gvec_ustoh, gen_helper_gvec_uitos) | ||
114 | +DO_2MISC_FP_VEC(VCVT_SF, gen_helper_gvec_tosszh, gen_helper_gvec_tosizs) | ||
115 | +DO_2MISC_FP_VEC(VCVT_UF, gen_helper_gvec_touszh, gen_helper_gvec_touizs) | ||
116 | |||
117 | static bool trans_VRINTX(DisasContext *s, arg_2misc *a) | ||
118 | { | ||
119 | -- | 36 | -- |
120 | 2.20.1 | 37 | 2.20.1 |
121 | 38 | ||
122 | 39 | diff view generated by jsdifflib |
1 | Implmeent VFP fp16 support for simple binary-operator VFP insns VADD, | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | VSUB, VMUL, VDIV, VMINNM and VMAXNM: | ||
3 | 2 | ||
4 | * make the VFP_BINOP() macro generate float16 helpers as well as | 3 | The watchdog is part of NPCM7XX's timer module. Its behavior is |
5 | float32 and float64 | 4 | controlled by the WTCR register in the timer. |
6 | * implement a do_vfp_3op_hp() function similar to the existing | ||
7 | do_vfp_3op_sp() | ||
8 | * add decode for the half-precision insn patterns | ||
9 | 5 | ||
10 | Note that the VFP_BINOP macro use creates a couple of unused helper | 6 | When enabled, the watchdog issues an interrupt signal after a pre-set |
11 | functions vfp_maxh and vfp_minh, but they're small so it's not worth | 7 | amount of cycles, and issues a reset signal shortly after that. |
12 | splitting the BINOP operations into "needs halfprec" and "no | ||
13 | halfprec" groups. | ||
14 | 8 | ||
9 | Reviewed-by: Tyrone Ting <kfting@nuvoton.com> | ||
10 | Signed-off-by: Hao Wu <wuhaotsh@google.com> | ||
11 | Signed-off-by: Havard Skinnemoen <hskinnemoen@google.com> | ||
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | [PMM: deleted blank line at end of npcm_watchdog_timer-test.c] | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
17 | Message-id: 20200828183354.27913-4-peter.maydell@linaro.org | ||
18 | --- | 15 | --- |
19 | target/arm/helper.h | 8 ++++ | 16 | include/hw/misc/npcm7xx_clk.h | 2 + |
20 | target/arm/vfp-uncond.decode | 3 ++ | 17 | include/hw/timer/npcm7xx_timer.h | 48 +++- |
21 | target/arm/vfp.decode | 4 ++ | 18 | hw/arm/npcm7xx.c | 12 + |
22 | target/arm/vfp_helper.c | 5 ++ | 19 | hw/misc/npcm7xx_clk.c | 28 ++ |
23 | target/arm/translate-vfp.c.inc | 86 ++++++++++++++++++++++++++++++++++ | 20 | hw/timer/npcm7xx_timer.c | 266 ++++++++++++++---- |
24 | 5 files changed, 106 insertions(+) | 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 | ||
25 | 26 | ||
26 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 27 | diff --git a/include/hw/misc/npcm7xx_clk.h b/include/hw/misc/npcm7xx_clk.h |
27 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/target/arm/helper.h | 29 | --- a/include/hw/misc/npcm7xx_clk.h |
29 | +++ b/target/arm/helper.h | 30 | +++ b/include/hw/misc/npcm7xx_clk.h |
30 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(probe_access, TCG_CALL_NO_WG, void, env, tl, i32, i32, i32) | 31 | @@ -XXX,XX +XXX,XX @@ |
31 | DEF_HELPER_1(vfp_get_fpscr, i32, env) | 32 | */ |
32 | DEF_HELPER_2(vfp_set_fpscr, void, env, i32) | 33 | #define NPCM7XX_CLK_NR_REGS (0x70 / sizeof(uint32_t)) |
33 | 34 | ||
34 | +DEF_HELPER_3(vfp_addh, f16, f16, f16, ptr) | 35 | +#define NPCM7XX_WATCHDOG_RESET_GPIO_IN "npcm7xx-clk-watchdog-reset-gpio-in" |
35 | DEF_HELPER_3(vfp_adds, f32, f32, f32, ptr) | 36 | + |
36 | DEF_HELPER_3(vfp_addd, f64, f64, f64, ptr) | 37 | typedef struct NPCM7xxCLKState { |
37 | +DEF_HELPER_3(vfp_subh, f16, f16, f16, ptr) | 38 | SysBusDevice parent; |
38 | DEF_HELPER_3(vfp_subs, f32, f32, f32, ptr) | 39 | |
39 | DEF_HELPER_3(vfp_subd, f64, f64, f64, ptr) | 40 | diff --git a/include/hw/timer/npcm7xx_timer.h b/include/hw/timer/npcm7xx_timer.h |
40 | +DEF_HELPER_3(vfp_mulh, f16, f16, f16, ptr) | ||
41 | DEF_HELPER_3(vfp_muls, f32, f32, f32, ptr) | ||
42 | DEF_HELPER_3(vfp_muld, f64, f64, f64, ptr) | ||
43 | +DEF_HELPER_3(vfp_divh, f16, f16, f16, ptr) | ||
44 | DEF_HELPER_3(vfp_divs, f32, f32, f32, ptr) | ||
45 | DEF_HELPER_3(vfp_divd, f64, f64, f64, ptr) | ||
46 | +DEF_HELPER_3(vfp_maxh, f16, f16, f16, ptr) | ||
47 | DEF_HELPER_3(vfp_maxs, f32, f32, f32, ptr) | ||
48 | DEF_HELPER_3(vfp_maxd, f64, f64, f64, ptr) | ||
49 | +DEF_HELPER_3(vfp_minh, f16, f16, f16, ptr) | ||
50 | DEF_HELPER_3(vfp_mins, f32, f32, f32, ptr) | ||
51 | DEF_HELPER_3(vfp_mind, f64, f64, f64, ptr) | ||
52 | +DEF_HELPER_3(vfp_maxnumh, f16, f16, f16, ptr) | ||
53 | DEF_HELPER_3(vfp_maxnums, f32, f32, f32, ptr) | ||
54 | DEF_HELPER_3(vfp_maxnumd, f64, f64, f64, ptr) | ||
55 | +DEF_HELPER_3(vfp_minnumh, f16, f16, f16, ptr) | ||
56 | DEF_HELPER_3(vfp_minnums, f32, f32, f32, ptr) | ||
57 | DEF_HELPER_3(vfp_minnumd, f64, f64, f64, ptr) | ||
58 | DEF_HELPER_1(vfp_negs, f32, f32) | ||
59 | diff --git a/target/arm/vfp-uncond.decode b/target/arm/vfp-uncond.decode | ||
60 | index XXXXXXX..XXXXXXX 100644 | 41 | index XXXXXXX..XXXXXXX 100644 |
61 | --- a/target/arm/vfp-uncond.decode | 42 | --- a/include/hw/timer/npcm7xx_timer.h |
62 | +++ b/target/arm/vfp-uncond.decode | 43 | +++ b/include/hw/timer/npcm7xx_timer.h |
63 | @@ -XXX,XX +XXX,XX @@ VSEL 1111 1110 0. cc:2 .... .... 1010 .0.0 .... \ | 44 | @@ -XXX,XX +XXX,XX @@ |
64 | VSEL 1111 1110 0. cc:2 .... .... 1011 .0.0 .... \ | 45 | */ |
65 | vm=%vm_dp vn=%vn_dp vd=%vd_dp dp=1 | 46 | #define NPCM7XX_TIMER_NR_REGS (0x54 / sizeof(uint32_t)) |
66 | 47 | ||
67 | +VMAXNM_hp 1111 1110 1.00 .... .... 1001 .0.0 .... @vfp_dnm_s | 48 | +/* The basic watchdog timer period is 2^14 clock cycles. */ |
68 | +VMINNM_hp 1111 1110 1.00 .... .... 1001 .1.0 .... @vfp_dnm_s | 49 | +#define NPCM7XX_WATCHDOG_BASETIME_SHIFT 14 |
69 | + | 50 | + |
70 | VMAXNM_sp 1111 1110 1.00 .... .... 1010 .0.0 .... @vfp_dnm_s | 51 | +#define NPCM7XX_WATCHDOG_RESET_GPIO_OUT "npcm7xx-clk-watchdog-reset-gpio-out" |
71 | VMINNM_sp 1111 1110 1.00 .... .... 1010 .1.0 .... @vfp_dnm_s | 52 | + |
72 | 53 | typedef struct NPCM7xxTimerCtrlState NPCM7xxTimerCtrlState; | |
73 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | 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 | ||
74 | index XXXXXXX..XXXXXXX 100644 | 133 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/target/arm/vfp.decode | 134 | --- a/hw/arm/npcm7xx.c |
76 | +++ b/target/arm/vfp.decode | 135 | +++ b/hw/arm/npcm7xx.c |
77 | @@ -XXX,XX +XXX,XX @@ VNMLS_dp ---- 1110 0.01 .... .... 1011 .0.0 .... @vfp_dnm_d | 136 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { |
78 | VNMLA_sp ---- 1110 0.01 .... .... 1010 .1.0 .... @vfp_dnm_s | 137 | NPCM7XX_TIMER12_IRQ, |
79 | VNMLA_dp ---- 1110 0.01 .... .... 1011 .1.0 .... @vfp_dnm_d | 138 | NPCM7XX_TIMER13_IRQ, |
80 | 139 | NPCM7XX_TIMER14_IRQ, | |
81 | +VMUL_hp ---- 1110 0.10 .... .... 1001 .0.0 .... @vfp_dnm_s | 140 | + NPCM7XX_WDG0_IRQ = 47, /* Timer Module 0 Watchdog */ |
82 | VMUL_sp ---- 1110 0.10 .... .... 1010 .0.0 .... @vfp_dnm_s | 141 | + NPCM7XX_WDG1_IRQ, /* Timer Module 1 Watchdog */ |
83 | VMUL_dp ---- 1110 0.10 .... .... 1011 .0.0 .... @vfp_dnm_d | 142 | + NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ |
84 | 143 | }; | |
85 | VNMUL_sp ---- 1110 0.10 .... .... 1010 .1.0 .... @vfp_dnm_s | 144 | |
86 | VNMUL_dp ---- 1110 0.10 .... .... 1011 .1.0 .... @vfp_dnm_d | 145 | /* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ |
87 | 146 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | |
88 | +VADD_hp ---- 1110 0.11 .... .... 1001 .0.0 .... @vfp_dnm_s | 147 | qemu_irq irq = npcm7xx_irq(s, first_irq + j); |
89 | VADD_sp ---- 1110 0.11 .... .... 1010 .0.0 .... @vfp_dnm_s | 148 | sysbus_connect_irq(sbd, j, irq); |
90 | VADD_dp ---- 1110 0.11 .... .... 1011 .0.0 .... @vfp_dnm_d | 149 | } |
91 | 150 | + | |
92 | +VSUB_hp ---- 1110 0.11 .... .... 1001 .1.0 .... @vfp_dnm_s | 151 | + /* IRQ for watchdogs */ |
93 | VSUB_sp ---- 1110 0.11 .... .... 1010 .1.0 .... @vfp_dnm_s | 152 | + sysbus_connect_irq(sbd, NPCM7XX_TIMERS_PER_CTRL, |
94 | VSUB_dp ---- 1110 0.11 .... .... 1011 .1.0 .... @vfp_dnm_d | 153 | + npcm7xx_irq(s, NPCM7XX_WDG0_IRQ + i)); |
95 | 154 | + /* GPIO that connects clk module with watchdog */ | |
96 | +VDIV_hp ---- 1110 1.00 .... .... 1001 .0.0 .... @vfp_dnm_s | 155 | + qdev_connect_gpio_out_named(DEVICE(&s->tim[i]), |
97 | VDIV_sp ---- 1110 1.00 .... .... 1010 .0.0 .... @vfp_dnm_s | 156 | + NPCM7XX_WATCHDOG_RESET_GPIO_OUT, 0, |
98 | VDIV_dp ---- 1110 1.00 .... .... 1011 .0.0 .... @vfp_dnm_d | 157 | + qdev_get_gpio_in_named(DEVICE(&s->clk), |
99 | 158 | + NPCM7XX_WATCHDOG_RESET_GPIO_IN, i)); | |
100 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | 159 | } |
160 | |||
161 | /* UART0..3 (16550 compatible) */ | ||
162 | diff --git a/hw/misc/npcm7xx_clk.c b/hw/misc/npcm7xx_clk.c | ||
101 | index XXXXXXX..XXXXXXX 100644 | 163 | index XXXXXXX..XXXXXXX 100644 |
102 | --- a/target/arm/vfp_helper.c | 164 | --- a/hw/misc/npcm7xx_clk.c |
103 | +++ b/target/arm/vfp_helper.c | 165 | +++ b/hw/misc/npcm7xx_clk.c |
104 | @@ -XXX,XX +XXX,XX @@ void vfp_set_fpscr(CPUARMState *env, uint32_t val) | 166 | @@ -XXX,XX +XXX,XX @@ |
105 | #define VFP_HELPER(name, p) HELPER(glue(glue(vfp_,name),p)) | 167 | #include "qemu/osdep.h" |
106 | 168 | ||
107 | #define VFP_BINOP(name) \ | 169 | #include "hw/misc/npcm7xx_clk.h" |
108 | +dh_ctype_f16 VFP_HELPER(name, h)(dh_ctype_f16 a, dh_ctype_f16 b, void *fpstp) \ | 170 | +#include "hw/timer/npcm7xx_timer.h" |
109 | +{ \ | 171 | #include "migration/vmstate.h" |
110 | + float_status *fpst = fpstp; \ | 172 | #include "qemu/error-report.h" |
111 | + return float16_ ## name(a, b, fpst); \ | 173 | #include "qemu/log.h" |
112 | +} \ | 174 | @@ -XXX,XX +XXX,XX @@ |
113 | float32 VFP_HELPER(name, s)(float32 a, float32 b, void *fpstp) \ | 175 | #include "qemu/timer.h" |
114 | { \ | 176 | #include "qemu/units.h" |
115 | float_status *fpst = fpstp; \ | 177 | #include "trace.h" |
116 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 178 | +#include "sysemu/watchdog.h" |
179 | |||
180 | #define PLLCON_LOKI BIT(31) | ||
181 | #define PLLCON_LOKS BIT(30) | ||
182 | @@ -XXX,XX +XXX,XX @@ static const uint32_t cold_reset_values[NPCM7XX_CLK_NR_REGS] = { | ||
183 | [NPCM7XX_CLK_AHBCKFI] = 0x000000c8, | ||
184 | }; | ||
185 | |||
186 | +/* Register Field Definitions */ | ||
187 | +#define NPCM7XX_CLK_WDRCR_CA9C BIT(0) /* Cortex A9 Cores */ | ||
188 | + | ||
189 | +/* The number of watchdogs that can trigger a reset. */ | ||
190 | +#define NPCM7XX_NR_WATCHDOGS (3) | ||
191 | + | ||
192 | static uint64_t npcm7xx_clk_read(void *opaque, hwaddr offset, unsigned size) | ||
193 | { | ||
194 | uint32_t reg = offset / sizeof(uint32_t); | ||
195 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_write(void *opaque, hwaddr offset, | ||
196 | s->regs[reg] = value; | ||
197 | } | ||
198 | |||
199 | +/* Perform reset action triggered by a watchdog */ | ||
200 | +static void npcm7xx_clk_perform_watchdog_reset(void *opaque, int n, | ||
201 | + int level) | ||
202 | +{ | ||
203 | + NPCM7xxCLKState *clk = NPCM7XX_CLK(opaque); | ||
204 | + uint32_t rcr; | ||
205 | + | ||
206 | + g_assert(n >= 0 && n <= NPCM7XX_NR_WATCHDOGS); | ||
207 | + rcr = clk->regs[NPCM7XX_CLK_WD0RCR + n]; | ||
208 | + if (rcr & NPCM7XX_CLK_WDRCR_CA9C) { | ||
209 | + watchdog_perform_action(); | ||
210 | + } else { | ||
211 | + qemu_log_mask(LOG_UNIMP, | ||
212 | + "%s: only CPU reset is implemented. (requested 0x%" PRIx32")\n", | ||
213 | + __func__, rcr); | ||
214 | + } | ||
215 | +} | ||
216 | + | ||
217 | static const struct MemoryRegionOps npcm7xx_clk_ops = { | ||
218 | .read = npcm7xx_clk_read, | ||
219 | .write = npcm7xx_clk_write, | ||
220 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_clk_init(Object *obj) | ||
221 | memory_region_init_io(&s->iomem, obj, &npcm7xx_clk_ops, s, | ||
222 | TYPE_NPCM7XX_CLK, 4 * KiB); | ||
223 | sysbus_init_mmio(&s->parent, &s->iomem); | ||
224 | + qdev_init_gpio_in_named(DEVICE(s), npcm7xx_clk_perform_watchdog_reset, | ||
225 | + NPCM7XX_WATCHDOG_RESET_GPIO_IN, NPCM7XX_NR_WATCHDOGS); | ||
226 | } | ||
227 | |||
228 | static const VMStateDescription vmstate_npcm7xx_clk = { | ||
229 | diff --git a/hw/timer/npcm7xx_timer.c b/hw/timer/npcm7xx_timer.c | ||
117 | index XXXXXXX..XXXXXXX 100644 | 230 | index XXXXXXX..XXXXXXX 100644 |
118 | --- a/target/arm/translate-vfp.c.inc | 231 | --- a/hw/timer/npcm7xx_timer.c |
119 | +++ b/target/arm/translate-vfp.c.inc | 232 | +++ b/hw/timer/npcm7xx_timer.c |
120 | @@ -XXX,XX +XXX,XX @@ static bool do_vfp_3op_sp(DisasContext *s, VFPGen3OpSPFn *fn, | 233 | @@ -XXX,XX +XXX,XX @@ |
121 | return true; | 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; | ||
122 | } | 294 | } |
123 | 295 | ||
124 | +static bool do_vfp_3op_hp(DisasContext *s, VFPGen3OpSPFn *fn, | 296 | +static uint32_t npcm7xx_watchdog_timer_prescaler(const NPCM7xxWatchdogTimer *t) |
125 | + int vd, int vn, int vm, bool reads_vd) | 297 | +{ |
126 | +{ | 298 | + switch (NPCM7XX_WTCR_WTCLK(t->wtcr)) { |
299 | + case 0: | ||
300 | + return 1; | ||
301 | + case 1: | ||
302 | + return 256; | ||
303 | + case 2: | ||
304 | + return 2048; | ||
305 | + case 3: | ||
306 | + return 65536; | ||
307 | + default: | ||
308 | + g_assert_not_reached(); | ||
309 | + } | ||
310 | +} | ||
311 | + | ||
312 | +static void npcm7xx_watchdog_timer_reset_cycles(NPCM7xxWatchdogTimer *t, | ||
313 | + int64_t cycles) | ||
314 | +{ | ||
315 | + uint32_t prescaler = npcm7xx_watchdog_timer_prescaler(t); | ||
316 | + int64_t ns = (NANOSECONDS_PER_SECOND / NPCM7XX_TIMER_REF_HZ) * cycles; | ||
317 | + | ||
127 | + /* | 318 | + /* |
128 | + * Do a half-precision operation. Functionally this is | 319 | + * The reset function always clears the current timer. The caller of the |
129 | + * the same as do_vfp_3op_sp(), except: | 320 | + * this needs to decide whether to start the watchdog timer based on |
130 | + * - it uses the FPST_FPCR_F16 | 321 | + * specific flag in WTCR. |
131 | + * - it doesn't need the VFP vector handling (fp16 is a | ||
132 | + * v8 feature, and in v8 VFP vectors don't exist) | ||
133 | + * - it does the aa32_fp16_arith feature test | ||
134 | + */ | 322 | + */ |
135 | + TCGv_i32 f0, f1, fd; | 323 | + npcm7xx_timer_clear(&t->base_timer); |
136 | + TCGv_ptr fpst; | 324 | + |
137 | + | 325 | + ns *= prescaler; |
138 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 326 | + t->base_timer.remaining_ns = ns; |
139 | + return false; | 327 | +} |
328 | + | ||
329 | +static void npcm7xx_watchdog_timer_reset(NPCM7xxWatchdogTimer *t) | ||
330 | +{ | ||
331 | + int64_t cycles = 1; | ||
332 | + uint32_t s = NPCM7XX_WTCR_WTIS(t->wtcr); | ||
333 | + | ||
334 | + g_assert(s <= 3); | ||
335 | + | ||
336 | + cycles <<= NPCM7XX_WATCHDOG_BASETIME_SHIFT; | ||
337 | + cycles <<= 2 * s; | ||
338 | + | ||
339 | + npcm7xx_watchdog_timer_reset_cycles(t, cycles); | ||
340 | +} | ||
341 | + | ||
342 | /* | ||
343 | * Raise the interrupt line if there's a pending interrupt and interrupts are | ||
344 | * enabled for this timer. If not, lower it. | ||
345 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_check_interrupt(NPCM7xxTimer *t) | ||
346 | trace_npcm7xx_timer_irq(DEVICE(tc)->canonical_path, index, pending); | ||
347 | } | ||
348 | |||
349 | -/* Start or resume the timer. */ | ||
350 | -static void npcm7xx_timer_start(NPCM7xxTimer *t) | ||
351 | -{ | ||
352 | - int64_t now; | ||
353 | - | ||
354 | - now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
355 | - t->expires_ns = now + t->remaining_ns; | ||
356 | - timer_mod(&t->qtimer, t->expires_ns); | ||
357 | -} | ||
358 | - | ||
359 | /* | ||
360 | * Called when the counter reaches zero. Sets the interrupt flag, and either | ||
361 | * restarts or disables the timer. | ||
362 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t) | ||
363 | tc->tisr |= BIT(index); | ||
364 | |||
365 | if (t->tcsr & NPCM7XX_TCSR_PERIODIC) { | ||
366 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); | ||
367 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); | ||
368 | if (t->tcsr & NPCM7XX_TCSR_CEN) { | ||
369 | - npcm7xx_timer_start(t); | ||
370 | + npcm7xx_timer_start(&t->base_timer); | ||
371 | } | ||
372 | } else { | ||
373 | t->tcsr &= ~(NPCM7XX_TCSR_CEN | NPCM7XX_TCSR_CACT); | ||
374 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_reached_zero(NPCM7xxTimer *t) | ||
375 | npcm7xx_timer_check_interrupt(t); | ||
376 | } | ||
377 | |||
378 | -/* Stop counting. Record the time remaining so we can continue later. */ | ||
379 | -static void npcm7xx_timer_pause(NPCM7xxTimer *t) | ||
380 | -{ | ||
381 | - int64_t now; | ||
382 | - | ||
383 | - timer_del(&t->qtimer); | ||
384 | - now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
385 | - t->remaining_ns = t->expires_ns - now; | ||
386 | -} | ||
387 | |||
388 | /* | ||
389 | * Restart the timer from its initial value. If the timer was enabled and stays | ||
390 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_pause(NPCM7xxTimer *t) | ||
391 | */ | ||
392 | static void npcm7xx_timer_restart(NPCM7xxTimer *t, uint32_t old_tcsr) | ||
393 | { | ||
394 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); | ||
395 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, t->ticr); | ||
396 | |||
397 | if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { | ||
398 | - npcm7xx_timer_start(t); | ||
399 | + npcm7xx_timer_start(&t->base_timer); | ||
400 | } | ||
401 | } | ||
402 | |||
403 | @@ -XXX,XX +XXX,XX @@ static uint32_t npcm7xx_timer_read_tdr(NPCM7xxTimer *t) | ||
404 | if (t->tcsr & NPCM7XX_TCSR_CEN) { | ||
405 | int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
406 | |||
407 | - return npcm7xx_timer_ns_to_count(t, t->expires_ns - now); | ||
408 | + return npcm7xx_timer_ns_to_count(t, t->base_timer.expires_ns - now); | ||
409 | } | ||
410 | |||
411 | - return npcm7xx_timer_ns_to_count(t, t->remaining_ns); | ||
412 | + return npcm7xx_timer_ns_to_count(t, t->base_timer.remaining_ns); | ||
413 | } | ||
414 | |||
415 | static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) | ||
416 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) | ||
417 | |||
418 | if (npcm7xx_tcsr_prescaler(old_tcsr) != npcm7xx_tcsr_prescaler(new_tcsr)) { | ||
419 | /* Recalculate time remaining based on the current TDR value. */ | ||
420 | - t->remaining_ns = npcm7xx_timer_count_to_ns(t, tdr); | ||
421 | + t->base_timer.remaining_ns = npcm7xx_timer_count_to_ns(t, tdr); | ||
422 | if (old_tcsr & t->tcsr & NPCM7XX_TCSR_CEN) { | ||
423 | - npcm7xx_timer_start(t); | ||
424 | + npcm7xx_timer_start(&t->base_timer); | ||
425 | } | ||
426 | } | ||
427 | |||
428 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tcsr(NPCM7xxTimer *t, uint32_t new_tcsr) | ||
429 | if ((old_tcsr ^ new_tcsr) & NPCM7XX_TCSR_CEN) { | ||
430 | if (new_tcsr & NPCM7XX_TCSR_CEN) { | ||
431 | t->tcsr |= NPCM7XX_TCSR_CACT; | ||
432 | - npcm7xx_timer_start(t); | ||
433 | + npcm7xx_timer_start(&t->base_timer); | ||
434 | } else { | ||
435 | t->tcsr &= ~NPCM7XX_TCSR_CACT; | ||
436 | - npcm7xx_timer_pause(t); | ||
437 | - if (t->remaining_ns <= 0) { | ||
438 | + npcm7xx_timer_pause(&t->base_timer); | ||
439 | + if (t->base_timer.remaining_ns <= 0) { | ||
440 | npcm7xx_timer_reached_zero(t); | ||
441 | } | ||
442 | } | ||
443 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_write_tisr(NPCM7xxTimerCtrlState *s, uint32_t value) | ||
444 | if (value & (1U << i)) { | ||
445 | npcm7xx_timer_check_interrupt(&s->timer[i]); | ||
446 | } | ||
447 | + | ||
448 | } | ||
449 | } | ||
450 | |||
451 | +static void npcm7xx_timer_write_wtcr(NPCM7xxWatchdogTimer *t, uint32_t new_wtcr) | ||
452 | +{ | ||
453 | + uint32_t old_wtcr = t->wtcr; | ||
454 | + | ||
455 | + /* | ||
456 | + * WTIF and WTRF are cleared by writing 1. Writing 0 makes these bits | ||
457 | + * unchanged. | ||
458 | + */ | ||
459 | + if (new_wtcr & NPCM7XX_WTCR_WTIF) { | ||
460 | + new_wtcr &= ~NPCM7XX_WTCR_WTIF; | ||
461 | + } else if (old_wtcr & NPCM7XX_WTCR_WTIF) { | ||
462 | + new_wtcr |= NPCM7XX_WTCR_WTIF; | ||
140 | + } | 463 | + } |
141 | + | 464 | + if (new_wtcr & NPCM7XX_WTCR_WTRF) { |
142 | + if (s->vec_len != 0 || s->vec_stride != 0) { | 465 | + new_wtcr &= ~NPCM7XX_WTCR_WTRF; |
143 | + return false; | 466 | + } else if (old_wtcr & NPCM7XX_WTCR_WTRF) { |
467 | + new_wtcr |= NPCM7XX_WTCR_WTRF; | ||
144 | + } | 468 | + } |
145 | + | 469 | + |
146 | + if (!vfp_access_check(s)) { | 470 | + t->wtcr = new_wtcr; |
147 | + return true; | 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 | + } | ||
148 | + } | 484 | + } |
149 | + | 485 | + |
150 | + f0 = tcg_temp_new_i32(); | 486 | +} |
151 | + f1 = tcg_temp_new_i32(); | 487 | + |
152 | + fd = tcg_temp_new_i32(); | 488 | static hwaddr npcm7xx_tcsr_index(hwaddr reg) |
153 | + fpst = fpstatus_ptr(FPST_FPCR_F16); | 489 | { |
154 | + | 490 | switch (reg) { |
155 | + neon_load_reg32(f0, vn); | 491 | @@ -XXX,XX +XXX,XX @@ static uint64_t npcm7xx_timer_read(void *opaque, hwaddr offset, unsigned size) |
156 | + neon_load_reg32(f1, vm); | 492 | break; |
157 | + | 493 | |
158 | + if (reads_vd) { | 494 | case NPCM7XX_TIMER_WTCR: |
159 | + neon_load_reg32(fd, vd); | 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 | + } | ||
160 | + } | 553 | + } |
161 | + fn(fd, f0, f1, fpst); | ||
162 | + neon_store_reg32(fd, vd); | ||
163 | + | ||
164 | + tcg_temp_free_i32(f0); | ||
165 | + tcg_temp_free_i32(f1); | ||
166 | + tcg_temp_free_i32(fd); | ||
167 | + tcg_temp_free_ptr(fpst); | ||
168 | + | ||
169 | + return true; | ||
170 | +} | ||
171 | + | ||
172 | static bool do_vfp_3op_dp(DisasContext *s, VFPGen3OpDPFn *fn, | ||
173 | int vd, int vn, int vm, bool reads_vd) | ||
174 | { | ||
175 | @@ -XXX,XX +XXX,XX @@ static bool trans_VNMLA_dp(DisasContext *s, arg_VNMLA_dp *a) | ||
176 | return do_vfp_3op_dp(s, gen_VNMLA_dp, a->vd, a->vn, a->vm, true); | ||
177 | } | 554 | } |
178 | 555 | ||
179 | +static bool trans_VMUL_hp(DisasContext *s, arg_VMUL_sp *a) | 556 | static void npcm7xx_timer_hold_reset(Object *obj) |
180 | +{ | 557 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_hold_reset(Object *obj) |
181 | + return do_vfp_3op_hp(s, gen_helper_vfp_mulh, a->vd, a->vn, a->vm, false); | 558 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { |
182 | +} | 559 | qemu_irq_lower(s->timer[i].irq); |
183 | + | 560 | } |
184 | static bool trans_VMUL_sp(DisasContext *s, arg_VMUL_sp *a) | 561 | + qemu_irq_lower(s->watchdog_timer.irq); |
185 | { | ||
186 | return do_vfp_3op_sp(s, gen_helper_vfp_muls, a->vd, a->vn, a->vm, false); | ||
187 | @@ -XXX,XX +XXX,XX @@ static bool trans_VNMUL_dp(DisasContext *s, arg_VNMUL_dp *a) | ||
188 | return do_vfp_3op_dp(s, gen_VNMUL_dp, a->vd, a->vn, a->vm, false); | ||
189 | } | 562 | } |
190 | 563 | ||
191 | +static bool trans_VADD_hp(DisasContext *s, arg_VADD_sp *a) | 564 | static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) |
192 | +{ | 565 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_timer_realize(DeviceState *dev, Error **errp) |
193 | + return do_vfp_3op_hp(s, gen_helper_vfp_addh, a->vd, a->vn, a->vm, false); | 566 | NPCM7xxTimerCtrlState *s = NPCM7XX_TIMER(dev); |
194 | +} | 567 | SysBusDevice *sbd = &s->parent; |
195 | + | 568 | int i; |
196 | static bool trans_VADD_sp(DisasContext *s, arg_VADD_sp *a) | 569 | + NPCM7xxWatchdogTimer *w; |
197 | { | 570 | |
198 | return do_vfp_3op_sp(s, gen_helper_vfp_adds, a->vd, a->vn, a->vm, false); | 571 | for (i = 0; i < NPCM7XX_TIMERS_PER_CTRL; i++) { |
199 | @@ -XXX,XX +XXX,XX @@ static bool trans_VADD_dp(DisasContext *s, arg_VADD_dp *a) | 572 | NPCM7xxTimer *t = &s->timer[i]; |
200 | return do_vfp_3op_dp(s, gen_helper_vfp_addd, a->vd, a->vn, a->vm, false); | 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); | ||
201 | } | 591 | } |
202 | 592 | ||
203 | +static bool trans_VSUB_hp(DisasContext *s, arg_VSUB_sp *a) | 593 | -static const VMStateDescription vmstate_npcm7xx_timer = { |
204 | +{ | 594 | - .name = "npcm7xx-timer", |
205 | + return do_vfp_3op_hp(s, gen_helper_vfp_subh, a->vd, a->vn, a->vm, false); | 595 | +static const VMStateDescription vmstate_npcm7xx_base_timer = { |
206 | +} | 596 | + .name = "npcm7xx-base-timer", |
207 | + | 597 | .version_id = 0, |
208 | static bool trans_VSUB_sp(DisasContext *s, arg_VSUB_sp *a) | 598 | .minimum_version_id = 0, |
209 | { | 599 | .fields = (VMStateField[]) { |
210 | return do_vfp_3op_sp(s, gen_helper_vfp_subs, a->vd, a->vn, a->vm, false); | 600 | - VMSTATE_TIMER(qtimer, NPCM7xxTimer), |
211 | @@ -XXX,XX +XXX,XX @@ static bool trans_VSUB_dp(DisasContext *s, arg_VSUB_dp *a) | 601 | - VMSTATE_INT64(expires_ns, NPCM7xxTimer), |
212 | return do_vfp_3op_dp(s, gen_helper_vfp_subd, a->vd, a->vn, a->vm, false); | 602 | - VMSTATE_INT64(remaining_ns, NPCM7xxTimer), |
213 | } | 603 | + VMSTATE_TIMER(qtimer, NPCM7xxBaseTimer), |
214 | 604 | + VMSTATE_INT64(expires_ns, NPCM7xxBaseTimer), | |
215 | +static bool trans_VDIV_hp(DisasContext *s, arg_VDIV_sp *a) | 605 | + VMSTATE_INT64(remaining_ns, NPCM7xxBaseTimer), |
216 | +{ | 606 | + VMSTATE_END_OF_LIST(), |
217 | + return do_vfp_3op_hp(s, gen_helper_vfp_divh, a->vd, a->vn, a->vm, false); | 607 | + }, |
218 | +} | 608 | +}; |
219 | + | 609 | + |
220 | static bool trans_VDIV_sp(DisasContext *s, arg_VDIV_sp *a) | 610 | +static const VMStateDescription vmstate_npcm7xx_timer = { |
221 | { | 611 | + .name = "npcm7xx-timer", |
222 | return do_vfp_3op_sp(s, gen_helper_vfp_divs, a->vd, a->vn, a->vm, false); | 612 | + .version_id = 1, |
223 | @@ -XXX,XX +XXX,XX @@ static bool trans_VDIV_dp(DisasContext *s, arg_VDIV_dp *a) | 613 | + .minimum_version_id = 1, |
224 | return do_vfp_3op_dp(s, gen_helper_vfp_divd, a->vd, a->vn, a->vm, false); | 614 | + .fields = (VMStateField[]) { |
225 | } | 615 | + VMSTATE_STRUCT(base_timer, NPCM7xxTimer, |
226 | 616 | + 0, vmstate_npcm7xx_base_timer, | |
227 | +static bool trans_VMINNM_hp(DisasContext *s, arg_VMINNM_sp *a) | 617 | + NPCM7xxBaseTimer), |
228 | +{ | 618 | VMSTATE_UINT32(tcsr, NPCM7xxTimer), |
229 | + if (!dc_isar_feature(aa32_vminmaxnm, s)) { | 619 | VMSTATE_UINT32(ticr, NPCM7xxTimer), |
230 | + return false; | 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 | ||
231 | + } | 713 | + } |
232 | + return do_vfp_3op_hp(s, gen_helper_vfp_minnumh, | 714 | +}; |
233 | + a->vd, a->vn, a->vm, false); | 715 | + |
234 | +} | 716 | +static int watchdog_index(const Watchdog *wd) |
235 | + | 717 | +{ |
236 | +static bool trans_VMAXNM_hp(DisasContext *s, arg_VMAXNM_sp *a) | 718 | + ptrdiff_t diff = wd - watchdog_list; |
237 | +{ | 719 | + |
238 | + if (!dc_isar_feature(aa32_vminmaxnm, s)) { | 720 | + g_assert(diff >= 0 && diff < ARRAY_SIZE(watchdog_list)); |
239 | + return false; | 721 | + |
722 | + return diff; | ||
723 | +} | ||
724 | + | ||
725 | +static uint32_t watchdog_read_wtcr(QTestState *qts, const Watchdog *wd) | ||
726 | +{ | ||
727 | + return qtest_readl(qts, wd->base_addr + WTCR_OFFSET); | ||
728 | +} | ||
729 | + | ||
730 | +static void watchdog_write_wtcr(QTestState *qts, const Watchdog *wd, | ||
731 | + uint32_t value) | ||
732 | +{ | ||
733 | + qtest_writel(qts, wd->base_addr + WTCR_OFFSET, value); | ||
734 | +} | ||
735 | + | ||
736 | +static uint32_t watchdog_prescaler(QTestState *qts, const Watchdog *wd) | ||
737 | +{ | ||
738 | + switch (extract32(watchdog_read_wtcr(qts, wd), 10, 2)) { | ||
739 | + case 0: | ||
740 | + return 1; | ||
741 | + case 1: | ||
742 | + return 256; | ||
743 | + case 2: | ||
744 | + return 2048; | ||
745 | + case 3: | ||
746 | + return 65536; | ||
747 | + default: | ||
748 | + g_assert_not_reached(); | ||
240 | + } | 749 | + } |
241 | + return do_vfp_3op_hp(s, gen_helper_vfp_maxnumh, | 750 | +} |
242 | + a->vd, a->vn, a->vm, false); | 751 | + |
243 | +} | 752 | +static QDict *get_watchdog_action(QTestState *qts) |
244 | + | 753 | +{ |
245 | static bool trans_VMINNM_sp(DisasContext *s, arg_VMINNM_sp *a) | 754 | + QDict *ev = qtest_qmp_eventwait_ref(qts, "WATCHDOG"); |
246 | { | 755 | + QDict *data; |
247 | if (!dc_isar_feature(aa32_vminmaxnm, s)) { | 756 | + |
757 | + data = qdict_get_qdict(ev, "data"); | ||
758 | + qobject_ref(data); | ||
759 | + qobject_unref(ev); | ||
760 | + return data; | ||
761 | +} | ||
762 | + | ||
763 | +#define RESET_CYCLES 1024 | ||
764 | +static uint32_t watchdog_interrupt_cycles(QTestState *qts, const Watchdog *wd) | ||
765 | +{ | ||
766 | + uint32_t wtis = extract32(watchdog_read_wtcr(qts, wd), 4, 2); | ||
767 | + return 1 << (14 + 2 * wtis); | ||
768 | +} | ||
769 | + | ||
770 | +static int64_t watchdog_calculate_steps(uint32_t count, uint32_t prescale) | ||
771 | +{ | ||
772 | + return (NANOSECONDS_PER_SECOND / REF_HZ) * count * prescale; | ||
773 | +} | ||
774 | + | ||
775 | +static int64_t watchdog_interrupt_steps(QTestState *qts, const Watchdog *wd) | ||
776 | +{ | ||
777 | + return watchdog_calculate_steps(watchdog_interrupt_cycles(qts, wd), | ||
778 | + watchdog_prescaler(qts, wd)); | ||
779 | +} | ||
780 | + | ||
781 | +/* Check wtcr can be reset to default value */ | ||
782 | +static void test_init(gconstpointer watchdog) | ||
783 | +{ | ||
784 | + const Watchdog *wd = watchdog; | ||
785 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | ||
786 | + | ||
787 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
788 | + | ||
789 | + watchdog_write_wtcr(qts, wd, WTCLK(1) | WTRF | WTIF | WTR); | ||
790 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(1)); | ||
791 | + | ||
792 | + qtest_quit(qts); | ||
793 | +} | ||
794 | + | ||
795 | +/* Check a watchdog can generate interrupt and reset actions */ | ||
796 | +static void test_reset_action(gconstpointer watchdog) | ||
797 | +{ | ||
798 | + const Watchdog *wd = watchdog; | ||
799 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | ||
800 | + QDict *ad; | ||
801 | + | ||
802 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
803 | + | ||
804 | + watchdog_write_wtcr(qts, wd, | ||
805 | + WTCLK(0) | WTE | WTRF | WTRE | WTIF | WTIE | WTR); | ||
806 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, | ||
807 | + WTCLK(0) | WTE | WTRE | WTIE); | ||
808 | + | ||
809 | + /* Check a watchdog can generate an interrupt */ | ||
810 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); | ||
811 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, | ||
812 | + WTCLK(0) | WTE | WTIF | WTIE | WTRE); | ||
813 | + g_assert_true(qtest_get_irq(qts, wd->irq)); | ||
814 | + | ||
815 | + /* Check a watchdog can generate a reset signal */ | ||
816 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, | ||
817 | + watchdog_prescaler(qts, wd))); | ||
818 | + ad = get_watchdog_action(qts); | ||
819 | + /* The signal is a reset signal */ | ||
820 | + g_assert_false(strcmp(qdict_get_str(ad, "action"), "reset")); | ||
821 | + qobject_unref(ad); | ||
822 | + qtest_qmp_eventwait(qts, "RESET"); | ||
823 | + /* | ||
824 | + * Make sure WTCR is reset to default except for WTRF bit which shouldn't | ||
825 | + * be reset. | ||
826 | + */ | ||
827 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(1) | WTRF); | ||
828 | + qtest_quit(qts); | ||
829 | +} | ||
830 | + | ||
831 | +/* Check a watchdog works with all possible WTCLK prescalers and WTIS cycles */ | ||
832 | +static void test_prescaler(gconstpointer watchdog) | ||
833 | +{ | ||
834 | + const Watchdog *wd = watchdog; | ||
835 | + | ||
836 | + for (int wtclk = 0; wtclk < 4; ++wtclk) { | ||
837 | + for (int wtis = 0; wtis < 4; ++wtis) { | ||
838 | + QTestState *qts = qtest_init("-machine quanta-gsj"); | ||
839 | + | ||
840 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
841 | + watchdog_write_wtcr(qts, wd, | ||
842 | + WTCLK(wtclk) | WTE | WTIF | WTIS(wtis) | WTIE | WTR); | ||
843 | + /* | ||
844 | + * The interrupt doesn't fire until watchdog_interrupt_steps() | ||
845 | + * cycles passed | ||
846 | + */ | ||
847 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd) - 1); | ||
848 | + g_assert_false(watchdog_read_wtcr(qts, wd) & WTIF); | ||
849 | + g_assert_false(qtest_get_irq(qts, wd->irq)); | ||
850 | + qtest_clock_step(qts, 1); | ||
851 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
852 | + g_assert_true(qtest_get_irq(qts, wd->irq)); | ||
853 | + | ||
854 | + qtest_quit(qts); | ||
855 | + } | ||
856 | + } | ||
857 | +} | ||
858 | + | ||
859 | +/* | ||
860 | + * Check a watchdog doesn't fire if corresponding flags (WTIE and WTRE) are not | ||
861 | + * set. | ||
862 | + */ | ||
863 | +static void test_enabling_flags(gconstpointer watchdog) | ||
864 | +{ | ||
865 | + const Watchdog *wd = watchdog; | ||
866 | + QTestState *qts; | ||
867 | + | ||
868 | + /* Neither WTIE or WTRE is set, no interrupt or reset should happen */ | ||
869 | + qts = qtest_init("-machine quanta-gsj"); | ||
870 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
871 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTRF | WTR); | ||
872 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); | ||
873 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
874 | + g_assert_false(qtest_get_irq(qts, wd->irq)); | ||
875 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, | ||
876 | + watchdog_prescaler(qts, wd))); | ||
877 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
878 | + g_assert_false(watchdog_read_wtcr(qts, wd) & WTRF); | ||
879 | + qtest_quit(qts); | ||
880 | + | ||
881 | + /* Only WTIE is set, interrupt is triggered but reset should not happen */ | ||
882 | + qts = qtest_init("-machine quanta-gsj"); | ||
883 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
884 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTIE | WTRF | WTR); | ||
885 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); | ||
886 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
887 | + g_assert_true(qtest_get_irq(qts, wd->irq)); | ||
888 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, | ||
889 | + watchdog_prescaler(qts, wd))); | ||
890 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
891 | + g_assert_false(watchdog_read_wtcr(qts, wd) & WTRF); | ||
892 | + qtest_quit(qts); | ||
893 | + | ||
894 | + /* Only WTRE is set, interrupt is triggered but reset should not happen */ | ||
895 | + qts = qtest_init("-machine quanta-gsj"); | ||
896 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
897 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTRE | WTRF | WTR); | ||
898 | + qtest_clock_step(qts, watchdog_interrupt_steps(qts, wd)); | ||
899 | + g_assert_true(watchdog_read_wtcr(qts, wd) & WTIF); | ||
900 | + g_assert_false(qtest_get_irq(qts, wd->irq)); | ||
901 | + qtest_clock_step(qts, watchdog_calculate_steps(RESET_CYCLES, | ||
902 | + watchdog_prescaler(qts, wd))); | ||
903 | + g_assert_false(strcmp(qdict_get_str(get_watchdog_action(qts), "action"), | ||
904 | + "reset")); | ||
905 | + qtest_qmp_eventwait(qts, "RESET"); | ||
906 | + qtest_quit(qts); | ||
907 | + | ||
908 | + /* | ||
909 | + * The case when both flags are set is already tested in | ||
910 | + * test_reset_action(). | ||
911 | + */ | ||
912 | +} | ||
913 | + | ||
914 | +/* Check a watchdog can pause and resume by setting WTE bits */ | ||
915 | +static void test_pause(gconstpointer watchdog) | ||
916 | +{ | ||
917 | + const Watchdog *wd = watchdog; | ||
918 | + QTestState *qts; | ||
919 | + int64_t remaining_steps, steps; | ||
920 | + | ||
921 | + qts = qtest_init("-machine quanta-gsj"); | ||
922 | + qtest_irq_intercept_in(qts, "/machine/soc/a9mpcore/gic"); | ||
923 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIF | WTIE | WTRF | WTR); | ||
924 | + remaining_steps = watchdog_interrupt_steps(qts, wd); | ||
925 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTE | WTIE); | ||
926 | + | ||
927 | + /* Run for half of the execution period. */ | ||
928 | + steps = remaining_steps / 2; | ||
929 | + remaining_steps -= steps; | ||
930 | + qtest_clock_step(qts, steps); | ||
931 | + | ||
932 | + /* Pause the watchdog */ | ||
933 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTIE); | ||
934 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTIE); | ||
935 | + | ||
936 | + /* Run for a long period of time, the watchdog shouldn't fire */ | ||
937 | + qtest_clock_step(qts, steps << 4); | ||
938 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTIE); | ||
939 | + g_assert_false(qtest_get_irq(qts, wd->irq)); | ||
940 | + | ||
941 | + /* Resume the watchdog */ | ||
942 | + watchdog_write_wtcr(qts, wd, WTCLK(0) | WTE | WTIE); | ||
943 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, WTCLK(0) | WTE | WTIE); | ||
944 | + | ||
945 | + /* Run for the reset of the execution period, the watchdog should fire */ | ||
946 | + qtest_clock_step(qts, remaining_steps); | ||
947 | + g_assert_cmphex(watchdog_read_wtcr(qts, wd), ==, | ||
948 | + WTCLK(0) | WTE | WTIF | WTIE); | ||
949 | + g_assert_true(qtest_get_irq(qts, wd->irq)); | ||
950 | + | ||
951 | + qtest_quit(qts); | ||
952 | +} | ||
953 | + | ||
954 | +static void watchdog_add_test(const char *name, const Watchdog* wd, | ||
955 | + GTestDataFunc fn) | ||
956 | +{ | ||
957 | + g_autofree char *full_name = g_strdup_printf( | ||
958 | + "npcm7xx_watchdog_timer[%d]/%s", watchdog_index(wd), name); | ||
959 | + qtest_add_data_func(full_name, wd, fn); | ||
960 | +} | ||
961 | +#define add_test(name, td) watchdog_add_test(#name, td, test_##name) | ||
962 | + | ||
963 | +int main(int argc, char **argv) | ||
964 | +{ | ||
965 | + g_test_init(&argc, &argv, NULL); | ||
966 | + g_test_set_nonfatal_assertions(); | ||
967 | + | ||
968 | + for (int i = 0; i < ARRAY_SIZE(watchdog_list); ++i) { | ||
969 | + const Watchdog *wd = &watchdog_list[i]; | ||
970 | + | ||
971 | + add_test(init, wd); | ||
972 | + add_test(reset_action, wd); | ||
973 | + add_test(prescaler, wd); | ||
974 | + add_test(enabling_flags, wd); | ||
975 | + add_test(pause, wd); | ||
976 | + } | ||
977 | + | ||
978 | + return g_test_run(); | ||
979 | +} | ||
980 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
981 | index XXXXXXX..XXXXXXX 100644 | ||
982 | --- a/MAINTAINERS | ||
983 | +++ b/MAINTAINERS | ||
984 | @@ -XXX,XX +XXX,XX @@ L: qemu-arm@nongnu.org | ||
985 | S: Supported | ||
986 | F: hw/*/npcm7xx* | ||
987 | F: include/hw/*/npcm7xx* | ||
988 | +F: tests/qtest/npcm7xx* | ||
989 | F: pc-bios/npcm7xx_bootrom.bin | ||
990 | F: roms/vbootrom | ||
991 | |||
992 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
993 | index XXXXXXX..XXXXXXX 100644 | ||
994 | --- a/tests/qtest/meson.build | ||
995 | +++ b/tests/qtest/meson.build | ||
996 | @@ -XXX,XX +XXX,XX @@ qtests_sparc64 = \ | ||
997 | (config_all_devices.has_key('CONFIG_ISA_TESTDEV') ? ['endianness-test'] : []) + \ | ||
998 | ['prom-env-test', 'boot-serial-test'] | ||
999 | |||
1000 | -qtests_npcm7xx = ['npcm7xx_timer-test'] | ||
1001 | +qtests_npcm7xx = ['npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] | ||
1002 | qtests_arm = \ | ||
1003 | (config_all_devices.has_key('CONFIG_PFLASH_CFI02') ? ['pflash-cfi02-test'] : []) + \ | ||
1004 | (config_all_devices.has_key('CONFIG_NPCM7XX') ? qtests_npcm7xx : []) + \ | ||
248 | -- | 1005 | -- |
249 | 2.20.1 | 1006 | 2.20.1 |
250 | 1007 | ||
251 | 1008 | diff view generated by jsdifflib |
1 | Convert the Neon float-point VMAX and VMIN insns over to using | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | a gvec helper, and use this to implement the fp16 case. | ||
3 | 2 | ||
3 | The RNG module returns a byte of randomness when the Data Valid bit is | ||
4 | set. | ||
5 | |||
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. | ||
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> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-29-peter.maydell@linaro.org | ||
7 | --- | 16 | --- |
8 | target/arm/helper.h | 6 ++++++ | 17 | docs/system/arm/nuvoton.rst | 2 +- |
9 | target/arm/vec_helper.c | 6 ++++++ | 18 | include/hw/arm/npcm7xx.h | 2 + |
10 | target/arm/translate-neon.c.inc | 5 ++--- | 19 | include/hw/misc/npcm7xx_rng.h | 34 ++++ |
11 | 3 files changed, 14 insertions(+), 3 deletions(-) | 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 | ||
12 | 30 | ||
13 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 31 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
14 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.h | 33 | --- a/docs/system/arm/nuvoton.rst |
16 | +++ b/target/arm/helper.h | 34 | +++ b/docs/system/arm/nuvoton.rst |
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_facge_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 35 | @@ -XXX,XX +XXX,XX @@ Supported devices |
18 | DEF_HELPER_FLAGS_5(gvec_facgt_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 36 | * DDR4 memory controller (dummy interface indicating memory training is done) |
19 | DEF_HELPER_FLAGS_5(gvec_facgt_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 37 | * OTP controllers (no protection features) |
20 | 38 | * Flash Interface Unit (FIU; no protection features) | |
21 | +DEF_HELPER_FLAGS_5(gvec_fmax_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 39 | + * Random Number Generator (RNG) |
22 | +DEF_HELPER_FLAGS_5(gvec_fmax_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 40 | |
23 | + | 41 | Missing devices |
24 | +DEF_HELPER_FLAGS_5(gvec_fmin_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 42 | --------------- |
25 | +DEF_HELPER_FLAGS_5(gvec_fmin_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 43 | @@ -XXX,XX +XXX,XX @@ Missing devices |
26 | + | 44 | * Peripheral SPI controller (PSPI) |
27 | DEF_HELPER_FLAGS_5(gvec_ftsmul_h, TCG_CALL_NO_RWG, | 45 | * Analog to Digital Converter (ADC) |
28 | void, ptr, ptr, ptr, ptr, i32) | 46 | * SD/MMC host |
29 | DEF_HELPER_FLAGS_5(gvec_ftsmul_s, TCG_CALL_NO_RWG, | 47 | - * Random Number Generator (RNG) |
30 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 48 | * PECI interface |
49 | * Pulse Width Modulation (PWM) | ||
50 | * Tachometer | ||
51 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/arm/vec_helper.c | 53 | --- a/include/hw/arm/npcm7xx.h |
33 | +++ b/target/arm/vec_helper.c | 54 | +++ b/include/hw/arm/npcm7xx.h |
34 | @@ -XXX,XX +XXX,XX @@ DO_3OP(gvec_facge_s, float32_acge, float32) | 55 | @@ -XXX,XX +XXX,XX @@ |
35 | DO_3OP(gvec_facgt_h, float16_acgt, float16) | 56 | #include "hw/mem/npcm7xx_mc.h" |
36 | DO_3OP(gvec_facgt_s, float32_acgt, float32) | 57 | #include "hw/misc/npcm7xx_clk.h" |
37 | 58 | #include "hw/misc/npcm7xx_gcr.h" | |
38 | +DO_3OP(gvec_fmax_h, float16_max, float16) | 59 | +#include "hw/misc/npcm7xx_rng.h" |
39 | +DO_3OP(gvec_fmax_s, float32_max, float32) | 60 | #include "hw/nvram/npcm7xx_otp.h" |
40 | + | 61 | #include "hw/timer/npcm7xx_timer.h" |
41 | +DO_3OP(gvec_fmin_h, float16_min, float16) | 62 | #include "hw/ssi/npcm7xx_fiu.h" |
42 | +DO_3OP(gvec_fmin_s, float32_min, float32) | 63 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { |
43 | + | 64 | NPCM7xxOTPState key_storage; |
44 | #ifdef TARGET_AARCH64 | 65 | NPCM7xxOTPState fuse_array; |
45 | 66 | NPCM7xxMCState mc; | |
46 | DO_3OP(gvec_recps_h, helper_recpsf_f16, float16) | 67 | + NPCM7xxRNGState rng; |
47 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | 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 | ||
48 | index XXXXXXX..XXXXXXX 100644 | 112 | index XXXXXXX..XXXXXXX 100644 |
49 | --- a/target/arm/translate-neon.c.inc | 113 | --- a/hw/arm/npcm7xx.c |
50 | +++ b/target/arm/translate-neon.c.inc | 114 | +++ b/hw/arm/npcm7xx.c |
51 | @@ -XXX,XX +XXX,XX @@ DO_3S_FP_GVEC(VCGE, gen_helper_gvec_fcge_s, gen_helper_gvec_fcge_h) | 115 | @@ -XXX,XX +XXX,XX @@ |
52 | DO_3S_FP_GVEC(VCGT, gen_helper_gvec_fcgt_s, gen_helper_gvec_fcgt_h) | 116 | #define NPCM7XX_GCR_BA (0xf0800000) |
53 | DO_3S_FP_GVEC(VACGE, gen_helper_gvec_facge_s, gen_helper_gvec_facge_h) | 117 | #define NPCM7XX_CLK_BA (0xf0801000) |
54 | DO_3S_FP_GVEC(VACGT, gen_helper_gvec_facgt_s, gen_helper_gvec_facgt_h) | 118 | #define NPCM7XX_MC_BA (0xf0824000) |
55 | +DO_3S_FP_GVEC(VMAX, gen_helper_gvec_fmax_s, gen_helper_gvec_fmax_h) | 119 | +#define NPCM7XX_RNG_BA (0xf000b000) |
56 | +DO_3S_FP_GVEC(VMIN, gen_helper_gvec_fmin_s, gen_helper_gvec_fmin_h) | 120 | |
57 | 121 | /* Internal AHB SRAM */ | |
58 | /* | 122 | #define NPCM7XX_RAM3_BA (0xc0008000) |
59 | * For all the functions using this macro, size == 1 means fp16, | 123 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) |
60 | @@ -XXX,XX +XXX,XX @@ DO_3S_FP_GVEC(VACGT, gen_helper_gvec_facgt_s, gen_helper_gvec_facgt_h) | 124 | object_initialize_child(obj, "otp2", &s->fuse_array, |
61 | return do_3same_fp(s, a, FUNC, READS_VD); \ | 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); | ||
62 | } | 133 | } |
63 | 134 | ||
64 | -DO_3S_FP(VMAX, gen_helper_vfp_maxs, false) | 135 | + /* Random Number Generator. Cannot fail. */ |
65 | -DO_3S_FP(VMIN, gen_helper_vfp_mins, false) | 136 | + sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); |
66 | - | 137 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); |
67 | static void gen_VMLA_fp_3s(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, | 138 | + |
68 | TCGv_ptr fpstatus) | 139 | /* |
69 | { | 140 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects |
141 | * specified, but this is a programming error. | ||
142 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
143 | create_unimplemented_device("npcm7xx.vdmx", 0xe0800000, 4 * KiB); | ||
144 | create_unimplemented_device("npcm7xx.pcierc", 0xe1000000, 64 * KiB); | ||
145 | create_unimplemented_device("npcm7xx.kcs", 0xf0007000, 4 * KiB); | ||
146 | - create_unimplemented_device("npcm7xx.rng", 0xf000b000, 4 * KiB); | ||
147 | create_unimplemented_device("npcm7xx.adc", 0xf000c000, 4 * KiB); | ||
148 | create_unimplemented_device("npcm7xx.gfxi", 0xf000e000, 4 * KiB); | ||
149 | create_unimplemented_device("npcm7xx.gpio[0]", 0xf0010000, 4 * KiB); | ||
150 | diff --git a/hw/misc/npcm7xx_rng.c b/hw/misc/npcm7xx_rng.c | ||
151 | new file mode 100644 | ||
152 | index XXXXXXX..XXXXXXX | ||
153 | --- /dev/null | ||
154 | +++ b/hw/misc/npcm7xx_rng.c | ||
155 | @@ -XXX,XX +XXX,XX @@ | ||
156 | +/* | ||
157 | + * Nuvoton NPCM7xx Random Number Generator. | ||
158 | + * | ||
159 | + * Copyright 2020 Google LLC | ||
160 | + * | ||
161 | + * This program is free software; you can redistribute it and/or modify it | ||
162 | + * under the terms of the GNU General Public License as published by the | ||
163 | + * Free Software Foundation; either version 2 of the License, or | ||
164 | + * (at your option) any later version. | ||
165 | + * | ||
166 | + * This program is distributed in the hope that it will be useful, but WITHOUT | ||
167 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
168 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
169 | + * for more details. | ||
170 | + */ | ||
171 | + | ||
172 | +#include "qemu/osdep.h" | ||
173 | + | ||
174 | +#include "hw/misc/npcm7xx_rng.h" | ||
175 | +#include "migration/vmstate.h" | ||
176 | +#include "qemu/bitops.h" | ||
177 | +#include "qemu/guest-random.h" | ||
178 | +#include "qemu/log.h" | ||
179 | +#include "qemu/module.h" | ||
180 | +#include "qemu/units.h" | ||
181 | + | ||
182 | +#include "trace.h" | ||
183 | + | ||
184 | +#define NPCM7XX_RNG_REGS_SIZE (4 * KiB) | ||
185 | + | ||
186 | +#define NPCM7XX_RNGCS (0x00) | ||
187 | +#define NPCM7XX_RNGCS_CLKP(rv) extract32(rv, 2, 4) | ||
188 | +#define NPCM7XX_RNGCS_DVALID BIT(1) | ||
189 | +#define NPCM7XX_RNGCS_RNGE BIT(0) | ||
190 | + | ||
191 | +#define NPCM7XX_RNGD (0x04) | ||
192 | +#define NPCM7XX_RNGMODE (0x08) | ||
193 | +#define NPCM7XX_RNGMODE_NORMAL (0x02) | ||
194 | + | ||
195 | +static bool npcm7xx_rng_is_enabled(NPCM7xxRNGState *s) | ||
196 | +{ | ||
197 | + return (s->rngcs & NPCM7XX_RNGCS_RNGE) && | ||
198 | + (s->rngmode == NPCM7XX_RNGMODE_NORMAL); | ||
199 | +} | ||
200 | + | ||
201 | +static uint64_t npcm7xx_rng_read(void *opaque, hwaddr offset, unsigned size) | ||
202 | +{ | ||
203 | + NPCM7xxRNGState *s = opaque; | ||
204 | + uint64_t value = 0; | ||
205 | + | ||
206 | + switch (offset) { | ||
207 | + case NPCM7XX_RNGCS: | ||
208 | + /* | ||
209 | + * If the RNG is enabled, but we don't have any valid random data, try | ||
210 | + * obtaining some and update the DVALID bit accordingly. | ||
211 | + */ | ||
212 | + if (!npcm7xx_rng_is_enabled(s)) { | ||
213 | + s->rngcs &= ~NPCM7XX_RNGCS_DVALID; | ||
214 | + } else if (!(s->rngcs & NPCM7XX_RNGCS_DVALID)) { | ||
215 | + uint8_t byte = 0; | ||
216 | + | ||
217 | + if (qemu_guest_getrandom(&byte, sizeof(byte), NULL) == 0) { | ||
218 | + s->rngd = byte; | ||
219 | + s->rngcs |= NPCM7XX_RNGCS_DVALID; | ||
220 | + } | ||
221 | + } | ||
222 | + value = s->rngcs; | ||
223 | + break; | ||
224 | + case NPCM7XX_RNGD: | ||
225 | + if (npcm7xx_rng_is_enabled(s) && s->rngcs & NPCM7XX_RNGCS_DVALID) { | ||
226 | + s->rngcs &= ~NPCM7XX_RNGCS_DVALID; | ||
227 | + value = s->rngd; | ||
228 | + s->rngd = 0; | ||
229 | + } | ||
230 | + break; | ||
231 | + case NPCM7XX_RNGMODE: | ||
232 | + value = s->rngmode; | ||
233 | + break; | ||
234 | + | ||
235 | + default: | ||
236 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
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 : []) + \ | ||
70 | -- | 663 | -- |
71 | 2.20.1 | 664 | 2.20.1 |
72 | 665 | ||
73 | 666 | diff view generated by jsdifflib |
1 | Convert the Neon VRSQRTS insn to using a gvec helper, | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | and use this to implement the fp16 case. | ||
3 | 2 | ||
4 | As with VRECPS, we adjust the phrasing of the new implementation | 3 | The NPCM730 and NPCM750 chips have a single USB host port shared between |
5 | slightly so that the fp32 version parallels the fp16 one. | 4 | a USB 2.0 EHCI host controller and a USB 1.1 OHCI host controller. This |
5 | adds support for both of them. | ||
6 | 6 | ||
7 | Testing notes: | ||
8 | * With -device usb-kbd, qemu will automatically insert a full-speed | ||
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> | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20200828183354.27913-35-peter.maydell@linaro.org | ||
10 | --- | 24 | --- |
11 | target/arm/helper.h | 4 +++- | 25 | docs/system/arm/nuvoton.rst | 2 +- |
12 | target/arm/vec_helper.c | 30 ++++++++++++++++++++++++++++++ | 26 | hw/usb/hcd-ehci.h | 1 + |
13 | target/arm/vfp_helper.c | 15 --------------- | 27 | include/hw/arm/npcm7xx.h | 4 ++++ |
14 | target/arm/translate-neon.c.inc | 21 +-------------------- | 28 | hw/arm/npcm7xx.c | 27 +++++++++++++++++++++++++-- |
15 | 4 files changed, 34 insertions(+), 36 deletions(-) | 29 | hw/usb/hcd-ehci-sysbus.c | 19 +++++++++++++++++++ |
30 | 5 files changed, 50 insertions(+), 3 deletions(-) | ||
16 | 31 | ||
17 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 32 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
18 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/arm/helper.h | 34 | --- a/docs/system/arm/nuvoton.rst |
20 | +++ b/target/arm/helper.h | 35 | +++ b/docs/system/arm/nuvoton.rst |
21 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_4(vfp_muladdd, f64, f64, f64, f64, ptr) | 36 | @@ -XXX,XX +XXX,XX @@ Supported devices |
22 | DEF_HELPER_4(vfp_muladds, f32, f32, f32, f32, ptr) | 37 | * OTP controllers (no protection features) |
23 | DEF_HELPER_4(vfp_muladdh, f16, f16, f16, f16, ptr) | 38 | * Flash Interface Unit (FIU; no protection features) |
24 | 39 | * Random Number Generator (RNG) | |
25 | -DEF_HELPER_3(rsqrts_f32, f32, env, f32, f32) | 40 | + * USB host (USBH) |
26 | DEF_HELPER_FLAGS_2(recpe_f16, TCG_CALL_NO_RWG, f16, f16, ptr) | 41 | |
27 | DEF_HELPER_FLAGS_2(recpe_f32, TCG_CALL_NO_RWG, f32, f32, ptr) | 42 | Missing devices |
28 | DEF_HELPER_FLAGS_2(recpe_f64, TCG_CALL_NO_RWG, f64, f64, ptr) | 43 | --------------- |
29 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fminnum_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i3 | 44 | @@ -XXX,XX +XXX,XX @@ Missing devices |
30 | DEF_HELPER_FLAGS_5(gvec_recps_nf_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 45 | * eSPI slave interface |
31 | DEF_HELPER_FLAGS_5(gvec_recps_nf_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 46 | |
32 | 47 | * Ethernet controllers (GMAC and EMC) | |
33 | +DEF_HELPER_FLAGS_5(gvec_rsqrts_nf_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 48 | - * USB host (USBH) |
34 | +DEF_HELPER_FLAGS_5(gvec_rsqrts_nf_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 49 | * USB device (USBD) |
50 | * SMBus controller (SMBF) | ||
51 | * Peripheral SPI controller (PSPI) | ||
52 | diff --git a/hw/usb/hcd-ehci.h b/hw/usb/hcd-ehci.h | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/hw/usb/hcd-ehci.h | ||
55 | +++ b/hw/usb/hcd-ehci.h | ||
56 | @@ -XXX,XX +XXX,XX @@ struct EHCIPCIState { | ||
57 | #define TYPE_PLATFORM_EHCI "platform-ehci-usb" | ||
58 | #define TYPE_EXYNOS4210_EHCI "exynos4210-ehci-usb" | ||
59 | #define TYPE_AW_H3_EHCI "aw-h3-ehci-usb" | ||
60 | +#define TYPE_NPCM7XX_EHCI "npcm7xx-ehci-usb" | ||
61 | #define TYPE_TEGRA2_EHCI "tegra2-ehci-usb" | ||
62 | #define TYPE_PPC4xx_EHCI "ppc4xx-ehci-usb" | ||
63 | #define TYPE_FUSBH200_EHCI "fusbh200-ehci-usb" | ||
64 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/include/hw/arm/npcm7xx.h | ||
67 | +++ b/include/hw/arm/npcm7xx.h | ||
68 | @@ -XXX,XX +XXX,XX @@ | ||
69 | #include "hw/nvram/npcm7xx_otp.h" | ||
70 | #include "hw/timer/npcm7xx_timer.h" | ||
71 | #include "hw/ssi/npcm7xx_fiu.h" | ||
72 | +#include "hw/usb/hcd-ehci.h" | ||
73 | +#include "hw/usb/hcd-ohci.h" | ||
74 | #include "target/arm/cpu.h" | ||
75 | |||
76 | #define NPCM7XX_MAX_NUM_CPUS (2) | ||
77 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { | ||
78 | NPCM7xxOTPState fuse_array; | ||
79 | NPCM7xxMCState mc; | ||
80 | NPCM7xxRNGState rng; | ||
81 | + EHCISysBusState ehci; | ||
82 | + OHCISysBusState ohci; | ||
83 | NPCM7xxFIUState fiu[2]; | ||
84 | } NPCM7xxState; | ||
85 | |||
86 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/hw/arm/npcm7xx.c | ||
89 | +++ b/hw/arm/npcm7xx.c | ||
90 | @@ -XXX,XX +XXX,XX @@ | ||
91 | #define NPCM7XX_MC_BA (0xf0824000) | ||
92 | #define NPCM7XX_RNG_BA (0xf000b000) | ||
93 | |||
94 | +/* USB Host modules */ | ||
95 | +#define NPCM7XX_EHCI_BA (0xf0806000) | ||
96 | +#define NPCM7XX_OHCI_BA (0xf0807000) | ||
35 | + | 97 | + |
36 | DEF_HELPER_FLAGS_5(gvec_fmla_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 98 | /* Internal AHB SRAM */ |
37 | DEF_HELPER_FLAGS_5(gvec_fmla_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 99 | #define NPCM7XX_RAM3_BA (0xc0008000) |
38 | 100 | #define NPCM7XX_RAM3_SZ (4 * KiB) | |
39 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 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); | ||
112 | } | ||
113 | |||
114 | + object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); | ||
115 | + object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); | ||
116 | + | ||
117 | QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm7xx_fiu) != ARRAY_SIZE(s->fiu)); | ||
118 | for (i = 0; i < ARRAY_SIZE(s->fiu); i++) { | ||
119 | object_initialize_child(obj, npcm7xx_fiu[i].name, &s->fiu[i], | ||
120 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
121 | sysbus_realize(SYS_BUS_DEVICE(&s->rng), &error_abort); | ||
122 | sysbus_mmio_map(SYS_BUS_DEVICE(&s->rng), 0, NPCM7XX_RNG_BA); | ||
123 | |||
124 | + /* USB Host */ | ||
125 | + object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true, | ||
126 | + &error_abort); | ||
127 | + sysbus_realize(SYS_BUS_DEVICE(&s->ehci), &error_abort); | ||
128 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ehci), 0, NPCM7XX_EHCI_BA); | ||
129 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ehci), 0, | ||
130 | + npcm7xx_irq(s, NPCM7XX_EHCI_IRQ)); | ||
131 | + | ||
132 | + object_property_set_str(OBJECT(&s->ohci), "masterbus", "usb-bus.0", | ||
133 | + &error_abort); | ||
134 | + object_property_set_uint(OBJECT(&s->ohci), "num-ports", 1, &error_abort); | ||
135 | + sysbus_realize(SYS_BUS_DEVICE(&s->ohci), &error_abort); | ||
136 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->ohci), 0, NPCM7XX_OHCI_BA); | ||
137 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->ohci), 0, | ||
138 | + npcm7xx_irq(s, NPCM7XX_OHCI_IRQ)); | ||
139 | + | ||
140 | /* | ||
141 | * Flash Interface Unit (FIU). Can fail if incorrect number of chip selects | ||
142 | * specified, but this is a programming error. | ||
143 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) | ||
144 | create_unimplemented_device("npcm7xx.mcphy", 0xf05f0000, 64 * KiB); | ||
145 | create_unimplemented_device("npcm7xx.gmac1", 0xf0802000, 8 * KiB); | ||
146 | create_unimplemented_device("npcm7xx.gmac2", 0xf0804000, 8 * KiB); | ||
147 | - create_unimplemented_device("npcm7xx.ehci", 0xf0806000, 4 * KiB); | ||
148 | - create_unimplemented_device("npcm7xx.ohci", 0xf0807000, 4 * KiB); | ||
149 | create_unimplemented_device("npcm7xx.vcd", 0xf0810000, 64 * KiB); | ||
150 | create_unimplemented_device("npcm7xx.ece", 0xf0820000, 8 * KiB); | ||
151 | create_unimplemented_device("npcm7xx.vdma", 0xf0822000, 8 * KiB); | ||
152 | diff --git a/hw/usb/hcd-ehci-sysbus.c b/hw/usb/hcd-ehci-sysbus.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | 153 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/target/arm/vec_helper.c | 154 | --- a/hw/usb/hcd-ehci-sysbus.c |
42 | +++ b/target/arm/vec_helper.c | 155 | +++ b/hw/usb/hcd-ehci-sysbus.c |
43 | @@ -XXX,XX +XXX,XX @@ static float32 float32_recps_nf(float32 op1, float32 op2, float_status *stat) | 156 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo ehci_aw_h3_type_info = { |
44 | return float32_sub(float32_two, float32_mul(op1, op2, stat), stat); | 157 | .class_init = ehci_aw_h3_class_init, |
45 | } | 158 | }; |
46 | 159 | ||
47 | +/* Reciprocal square-root step. AArch32 non-fused semantics. */ | 160 | +static void ehci_npcm7xx_class_init(ObjectClass *oc, void *data) |
48 | +static float16 float16_rsqrts_nf(float16 op1, float16 op2, float_status *stat) | ||
49 | +{ | 161 | +{ |
50 | + op1 = float16_squash_input_denormal(op1, stat); | 162 | + SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc); |
51 | + op2 = float16_squash_input_denormal(op2, stat); | 163 | + DeviceClass *dc = DEVICE_CLASS(oc); |
52 | + | 164 | + |
53 | + if ((float16_is_infinity(op1) && float16_is_zero(op2)) || | 165 | + sec->capsbase = 0x0; |
54 | + (float16_is_infinity(op2) && float16_is_zero(op1))) { | 166 | + sec->opregbase = 0x10; |
55 | + return float16_one_point_five; | 167 | + sec->portscbase = 0x44; |
56 | + } | 168 | + sec->portnr = 1; |
57 | + op1 = float16_sub(float16_three, float16_mul(op1, op2, stat), stat); | 169 | + set_bit(DEVICE_CATEGORY_USB, dc->categories); |
58 | + return float16_div(op1, float16_two, stat); | ||
59 | +} | 170 | +} |
60 | + | 171 | + |
61 | +static float32 float32_rsqrts_nf(float32 op1, float32 op2, float_status *stat) | 172 | +static const TypeInfo ehci_npcm7xx_type_info = { |
62 | +{ | 173 | + .name = TYPE_NPCM7XX_EHCI, |
63 | + op1 = float32_squash_input_denormal(op1, stat); | 174 | + .parent = TYPE_SYS_BUS_EHCI, |
64 | + op2 = float32_squash_input_denormal(op2, stat); | 175 | + .class_init = ehci_npcm7xx_class_init, |
176 | +}; | ||
65 | + | 177 | + |
66 | + if ((float32_is_infinity(op1) && float32_is_zero(op2)) || | 178 | static void ehci_tegra2_class_init(ObjectClass *oc, void *data) |
67 | + (float32_is_infinity(op2) && float32_is_zero(op1))) { | ||
68 | + return float32_one_point_five; | ||
69 | + } | ||
70 | + op1 = float32_sub(float32_three, float32_mul(op1, op2, stat), stat); | ||
71 | + return float32_div(op1, float32_two, stat); | ||
72 | +} | ||
73 | + | ||
74 | #define DO_3OP(NAME, FUNC, TYPE) \ | ||
75 | void HELPER(NAME)(void *vd, void *vn, void *vm, void *stat, uint32_t desc) \ | ||
76 | { \ | ||
77 | @@ -XXX,XX +XXX,XX @@ DO_3OP(gvec_fminnum_s, float32_minnum, float32) | ||
78 | DO_3OP(gvec_recps_nf_h, float16_recps_nf, float16) | ||
79 | DO_3OP(gvec_recps_nf_s, float32_recps_nf, float32) | ||
80 | |||
81 | +DO_3OP(gvec_rsqrts_nf_h, float16_rsqrts_nf, float16) | ||
82 | +DO_3OP(gvec_rsqrts_nf_s, float32_rsqrts_nf, float32) | ||
83 | + | ||
84 | #ifdef TARGET_AARCH64 | ||
85 | |||
86 | DO_3OP(gvec_recps_h, helper_recpsf_f16, float16) | ||
87 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | ||
88 | index XXXXXXX..XXXXXXX 100644 | ||
89 | --- a/target/arm/vfp_helper.c | ||
90 | +++ b/target/arm/vfp_helper.c | ||
91 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(vfp_fcvt_f64_to_f16)(float64 a, void *fpstp, uint32_t ahp_mode) | ||
92 | return r; | ||
93 | } | ||
94 | |||
95 | -float32 HELPER(rsqrts_f32)(CPUARMState *env, float32 a, float32 b) | ||
96 | -{ | ||
97 | - float_status *s = &env->vfp.standard_fp_status; | ||
98 | - float32 product; | ||
99 | - if ((float32_is_infinity(a) && float32_is_zero_or_denormal(b)) || | ||
100 | - (float32_is_infinity(b) && float32_is_zero_or_denormal(a))) { | ||
101 | - if (!(float32_is_zero(a) || float32_is_zero(b))) { | ||
102 | - float_raise(float_flag_input_denormal, s); | ||
103 | - } | ||
104 | - return float32_one_point_five; | ||
105 | - } | ||
106 | - product = float32_mul(a, b, s); | ||
107 | - return float32_div(float32_sub(float32_three, product, s), float32_two, s); | ||
108 | -} | ||
109 | - | ||
110 | /* NEON helpers. */ | ||
111 | |||
112 | /* Constants 256 and 512 are used in some helpers; we avoid relying on | ||
113 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/target/arm/translate-neon.c.inc | ||
116 | +++ b/target/arm/translate-neon.c.inc | ||
117 | @@ -XXX,XX +XXX,XX @@ DO_3S_FP_GVEC(VMLS, gen_helper_gvec_fmls_s, gen_helper_gvec_fmls_h) | ||
118 | DO_3S_FP_GVEC(VFMA, gen_helper_gvec_vfma_s, gen_helper_gvec_vfma_h) | ||
119 | DO_3S_FP_GVEC(VFMS, gen_helper_gvec_vfms_s, gen_helper_gvec_vfms_h) | ||
120 | DO_3S_FP_GVEC(VRECPS, gen_helper_gvec_recps_nf_s, gen_helper_gvec_recps_nf_h) | ||
121 | +DO_3S_FP_GVEC(VRSQRTS, gen_helper_gvec_rsqrts_nf_s, gen_helper_gvec_rsqrts_nf_h) | ||
122 | |||
123 | WRAP_FP_GVEC(gen_VMAXNM_fp32_3s, FPST_STD, gen_helper_gvec_fmaxnum_s) | ||
124 | WRAP_FP_GVEC(gen_VMAXNM_fp16_3s, FPST_STD_F16, gen_helper_gvec_fmaxnum_h) | ||
125 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMINNM_fp_3s(DisasContext *s, arg_3same *a) | ||
126 | return do_3same(s, a, gen_VMINNM_fp32_3s); | ||
127 | } | ||
128 | |||
129 | -WRAP_ENV_FN(gen_VRSQRTS_tramp, gen_helper_rsqrts_f32) | ||
130 | - | ||
131 | -static void gen_VRSQRTS_fp_3s(unsigned vece, uint32_t rd_ofs, | ||
132 | - uint32_t rn_ofs, uint32_t rm_ofs, | ||
133 | - uint32_t oprsz, uint32_t maxsz) | ||
134 | -{ | ||
135 | - static const GVecGen3 ops = { .fni4 = gen_VRSQRTS_tramp }; | ||
136 | - tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, &ops); | ||
137 | -} | ||
138 | - | ||
139 | -static bool trans_VRSQRTS_fp_3s(DisasContext *s, arg_3same *a) | ||
140 | -{ | ||
141 | - if (a->size != 0) { | ||
142 | - /* TODO fp16 support */ | ||
143 | - return false; | ||
144 | - } | ||
145 | - | ||
146 | - return do_3same(s, a, gen_VRSQRTS_fp_3s); | ||
147 | -} | ||
148 | - | ||
149 | static bool do_3same_fp_pair(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn) | ||
150 | { | 179 | { |
151 | /* FP operations handled pairwise 32 bits at a time */ | 180 | SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(oc); |
181 | @@ -XXX,XX +XXX,XX @@ static void ehci_sysbus_register_types(void) | ||
182 | type_register_static(&ehci_platform_type_info); | ||
183 | type_register_static(&ehci_exynos4210_type_info); | ||
184 | type_register_static(&ehci_aw_h3_type_info); | ||
185 | + type_register_static(&ehci_npcm7xx_type_info); | ||
186 | type_register_static(&ehci_tegra2_type_info); | ||
187 | type_register_static(&ehci_ppc4xx_type_info); | ||
188 | type_register_static(&ehci_fusbh200_type_info); | ||
152 | -- | 189 | -- |
153 | 2.20.1 | 190 | 2.20.1 |
154 | 191 | ||
155 | 192 | diff view generated by jsdifflib |
1 | Implement the VFP fp16 variant of VMOV that transfers a 16-bit | 1 | From: Havard Skinnemoen <hskinnemoen@google.com> |
---|---|---|---|
2 | value between a general purpose register and a VFP register. | ||
3 | 2 | ||
4 | Note that Rt == 15 is UNPREDICTABLE; since this insn is v8 and later | 3 | The NPCM7xx chips have multiple GPIO controllers that are mostly |
5 | only we have no need to replicate the old "updates CPSR.NZCV" | 4 | identical except for some minor differences like the reset values of |
6 | behaviour that the singleprec version of this insn does. | 5 | some registers. Each controller controls up to 32 pins. |
7 | 6 | ||
7 | Each individual pin is modeled as a pair of unnamed GPIOs -- one for | ||
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> | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20200828183354.27913-22-peter.maydell@linaro.org | ||
11 | --- | 16 | --- |
12 | target/arm/vfp.decode | 1 + | 17 | docs/system/arm/nuvoton.rst | 2 +- |
13 | target/arm/translate-vfp.c.inc | 34 ++++++++++++++++++++++++++++++++++ | 18 | include/hw/arm/npcm7xx.h | 2 + |
14 | 2 files changed, 35 insertions(+) | 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 | ||
15 | 30 | ||
16 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | 31 | diff --git a/docs/system/arm/nuvoton.rst b/docs/system/arm/nuvoton.rst |
17 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/vfp.decode | 33 | --- a/docs/system/arm/nuvoton.rst |
19 | +++ b/target/arm/vfp.decode | 34 | +++ b/docs/system/arm/nuvoton.rst |
20 | @@ -XXX,XX +XXX,XX @@ VDUP ---- 1110 1 b:1 q:1 0 .... rt:4 1011 . 0 e:1 1 0000 \ | 35 | @@ -XXX,XX +XXX,XX @@ Supported devices |
21 | vn=%vn_dp | 36 | * Flash Interface Unit (FIU; no protection features) |
22 | 37 | * Random Number Generator (RNG) | |
23 | VMSR_VMRS ---- 1110 111 l:1 reg:4 rt:4 1010 0001 0000 | 38 | * USB host (USBH) |
24 | +VMOV_half ---- 1110 000 l:1 .... rt:4 1001 . 001 0000 vn=%vn_sp | 39 | + * GPIO controller |
25 | VMOV_single ---- 1110 000 l:1 .... rt:4 1010 . 001 0000 vn=%vn_sp | 40 | |
26 | 41 | Missing devices | |
27 | VMOV_64_sp ---- 1100 010 op:1 rt2:4 rt:4 1010 00.1 .... vm=%vm_sp | 42 | --------------- |
28 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 43 | |
44 | - * GPIO controller | ||
45 | * LPC/eSPI host-to-BMC interface, including | ||
46 | |||
47 | * Keyboard and mouse controller interface (KBCI) | ||
48 | diff --git a/include/hw/arm/npcm7xx.h b/include/hw/arm/npcm7xx.h | ||
29 | index XXXXXXX..XXXXXXX 100644 | 49 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/translate-vfp.c.inc | 50 | --- a/include/hw/arm/npcm7xx.h |
31 | +++ b/target/arm/translate-vfp.c.inc | 51 | +++ b/include/hw/arm/npcm7xx.h |
32 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMSR_VMRS(DisasContext *s, arg_VMSR_VMRS *a) | 52 | @@ -XXX,XX +XXX,XX @@ |
33 | return true; | 53 | |
34 | } | 54 | #include "hw/boards.h" |
35 | 55 | #include "hw/cpu/a9mpcore.h" | |
36 | +static bool trans_VMOV_half(DisasContext *s, arg_VMOV_single *a) | 56 | +#include "hw/gpio/npcm7xx_gpio.h" |
37 | +{ | 57 | #include "hw/mem/npcm7xx_mc.h" |
38 | + TCGv_i32 tmp; | 58 | #include "hw/misc/npcm7xx_clk.h" |
39 | + | 59 | #include "hw/misc/npcm7xx_gcr.h" |
40 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 60 | @@ -XXX,XX +XXX,XX @@ typedef struct NPCM7xxState { |
41 | + return false; | 61 | NPCM7xxOTPState fuse_array; |
62 | NPCM7xxMCState mc; | ||
63 | NPCM7xxRNGState rng; | ||
64 | + NPCM7xxGPIOState gpio[8]; | ||
65 | EHCISysBusState ehci; | ||
66 | OHCISysBusState ohci; | ||
67 | NPCM7xxFIUState fiu[2]; | ||
68 | diff --git a/include/hw/gpio/npcm7xx_gpio.h b/include/hw/gpio/npcm7xx_gpio.h | ||
69 | new file mode 100644 | ||
70 | index XXXXXXX..XXXXXXX | ||
71 | --- /dev/null | ||
72 | +++ b/include/hw/gpio/npcm7xx_gpio.h | ||
73 | @@ -XXX,XX +XXX,XX @@ | ||
74 | +/* | ||
75 | + * Nuvoton NPCM7xx General Purpose Input / Output (GPIO) | ||
76 | + * | ||
77 | + * Copyright 2020 Google LLC | ||
78 | + * | ||
79 | + * This program is free software; you can redistribute it and/or | ||
80 | + * modify it under the terms of the GNU General Public License | ||
81 | + * version 2 as published by the Free Software Foundation. | ||
82 | + * | ||
83 | + * This program is distributed in the hope that it will be useful, | ||
84 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
85 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
86 | + * GNU General Public License for more details. | ||
87 | + */ | ||
88 | +#ifndef NPCM7XX_GPIO_H | ||
89 | +#define NPCM7XX_GPIO_H | ||
90 | + | ||
91 | +#include "exec/memory.h" | ||
92 | +#include "hw/sysbus.h" | ||
93 | + | ||
94 | +/* Number of pins managed by each controller. */ | ||
95 | +#define NPCM7XX_GPIO_NR_PINS (32) | ||
96 | + | ||
97 | +/* | ||
98 | + * Number of registers in our device state structure. Don't change this without | ||
99 | + * incrementing the version_id in the vmstate. | ||
100 | + */ | ||
101 | +#define NPCM7XX_GPIO_NR_REGS (0x80 / sizeof(uint32_t)) | ||
102 | + | ||
103 | +typedef struct NPCM7xxGPIOState { | ||
104 | + SysBusDevice parent; | ||
105 | + | ||
106 | + /* Properties to be defined by the SoC */ | ||
107 | + uint32_t reset_pu; | ||
108 | + uint32_t reset_pd; | ||
109 | + uint32_t reset_osrc; | ||
110 | + uint32_t reset_odsc; | ||
111 | + | ||
112 | + MemoryRegion mmio; | ||
113 | + | ||
114 | + qemu_irq irq; | ||
115 | + qemu_irq output[NPCM7XX_GPIO_NR_PINS]; | ||
116 | + | ||
117 | + uint32_t pin_level; | ||
118 | + uint32_t ext_level; | ||
119 | + uint32_t ext_driven; | ||
120 | + | ||
121 | + uint32_t regs[NPCM7XX_GPIO_NR_REGS]; | ||
122 | +} NPCM7xxGPIOState; | ||
123 | + | ||
124 | +#define TYPE_NPCM7XX_GPIO "npcm7xx-gpio" | ||
125 | +#define NPCM7XX_GPIO(obj) \ | ||
126 | + OBJECT_CHECK(NPCM7xxGPIOState, (obj), TYPE_NPCM7XX_GPIO) | ||
127 | + | ||
128 | +#endif /* NPCM7XX_GPIO_H */ | ||
129 | diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c | ||
130 | index XXXXXXX..XXXXXXX 100644 | ||
131 | --- a/hw/arm/npcm7xx.c | ||
132 | +++ b/hw/arm/npcm7xx.c | ||
133 | @@ -XXX,XX +XXX,XX @@ enum NPCM7xxInterrupt { | ||
134 | NPCM7XX_WDG2_IRQ, /* Timer Module 2 Watchdog */ | ||
135 | NPCM7XX_EHCI_IRQ = 61, | ||
136 | NPCM7XX_OHCI_IRQ = 62, | ||
137 | + NPCM7XX_GPIO0_IRQ = 116, | ||
138 | + NPCM7XX_GPIO1_IRQ, | ||
139 | + NPCM7XX_GPIO2_IRQ, | ||
140 | + NPCM7XX_GPIO3_IRQ, | ||
141 | + NPCM7XX_GPIO4_IRQ, | ||
142 | + NPCM7XX_GPIO5_IRQ, | ||
143 | + NPCM7XX_GPIO6_IRQ, | ||
144 | + NPCM7XX_GPIO7_IRQ, | ||
145 | }; | ||
146 | |||
147 | /* Total number of GIC interrupts, including internal Cortex-A9 interrupts. */ | ||
148 | @@ -XXX,XX +XXX,XX @@ static const hwaddr npcm7xx_fiu3_flash_addr[] = { | ||
149 | 0xb8000000, /* CS3 */ | ||
150 | }; | ||
151 | |||
152 | +static const struct { | ||
153 | + hwaddr regs_addr; | ||
154 | + uint32_t unconnected_pins; | ||
155 | + uint32_t reset_pu; | ||
156 | + uint32_t reset_pd; | ||
157 | + uint32_t reset_osrc; | ||
158 | + uint32_t reset_odsc; | ||
159 | +} npcm7xx_gpio[] = { | ||
160 | + { | ||
161 | + .regs_addr = 0xf0010000, | ||
162 | + .reset_pu = 0xff03ffff, | ||
163 | + .reset_pd = 0x00fc0000, | ||
164 | + }, { | ||
165 | + .regs_addr = 0xf0011000, | ||
166 | + .unconnected_pins = 0x0000001e, | ||
167 | + .reset_pu = 0xfefffe07, | ||
168 | + .reset_pd = 0x010001e0, | ||
169 | + }, { | ||
170 | + .regs_addr = 0xf0012000, | ||
171 | + .reset_pu = 0x780fffff, | ||
172 | + .reset_pd = 0x07f00000, | ||
173 | + .reset_odsc = 0x00700000, | ||
174 | + }, { | ||
175 | + .regs_addr = 0xf0013000, | ||
176 | + .reset_pu = 0x00fc0000, | ||
177 | + .reset_pd = 0xff000000, | ||
178 | + }, { | ||
179 | + .regs_addr = 0xf0014000, | ||
180 | + .reset_pu = 0xffffffff, | ||
181 | + }, { | ||
182 | + .regs_addr = 0xf0015000, | ||
183 | + .reset_pu = 0xbf83f801, | ||
184 | + .reset_pd = 0x007c0000, | ||
185 | + .reset_osrc = 0x000000f1, | ||
186 | + .reset_odsc = 0x3f9f80f1, | ||
187 | + }, { | ||
188 | + .regs_addr = 0xf0016000, | ||
189 | + .reset_pu = 0xfc00f801, | ||
190 | + .reset_pd = 0x000007fe, | ||
191 | + .reset_odsc = 0x00000800, | ||
192 | + }, { | ||
193 | + .regs_addr = 0xf0017000, | ||
194 | + .unconnected_pins = 0xffffff00, | ||
195 | + .reset_pu = 0x0000007f, | ||
196 | + .reset_osrc = 0x0000007f, | ||
197 | + .reset_odsc = 0x0000007f, | ||
198 | + }, | ||
199 | +}; | ||
200 | + | ||
201 | static const struct { | ||
202 | const char *name; | ||
203 | hwaddr regs_addr; | ||
204 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_init(Object *obj) | ||
205 | object_initialize_child(obj, "tim[*]", &s->tim[i], TYPE_NPCM7XX_TIMER); | ||
206 | } | ||
207 | |||
208 | + for (i = 0; i < ARRAY_SIZE(s->gpio); i++) { | ||
209 | + object_initialize_child(obj, "gpio[*]", &s->gpio[i], TYPE_NPCM7XX_GPIO); | ||
42 | + } | 210 | + } |
43 | + | 211 | + |
44 | + if (a->rt == 15) { | 212 | object_initialize_child(obj, "ehci", &s->ehci, TYPE_NPCM7XX_EHCI); |
45 | + /* UNPREDICTABLE; we choose to UNDEF */ | 213 | object_initialize_child(obj, "ohci", &s->ohci, TYPE_SYSBUS_OHCI); |
46 | + return false; | 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)); | ||
47 | + } | 236 | + } |
48 | + | 237 | + |
49 | + if (!vfp_access_check(s)) { | 238 | /* USB Host */ |
50 | + return true; | 239 | object_property_set_bool(OBJECT(&s->ehci), "companion-enable", true, |
240 | &error_abort); | ||
241 | diff --git a/hw/gpio/npcm7xx_gpio.c b/hw/gpio/npcm7xx_gpio.c | ||
242 | new file mode 100644 | ||
243 | index XXXXXXX..XXXXXXX | ||
244 | --- /dev/null | ||
245 | +++ b/hw/gpio/npcm7xx_gpio.c | ||
246 | @@ -XXX,XX +XXX,XX @@ | ||
247 | +/* | ||
248 | + * Nuvoton NPCM7xx General Purpose Input / Output (GPIO) | ||
249 | + * | ||
250 | + * Copyright 2020 Google LLC | ||
251 | + * | ||
252 | + * This program is free software; you can redistribute it and/or | ||
253 | + * modify it under the terms of the GNU General Public License | ||
254 | + * version 2 as published by the Free Software Foundation. | ||
255 | + * | ||
256 | + * This program is distributed in the hope that it will be useful, | ||
257 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
258 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
259 | + * GNU General Public License for more details. | ||
260 | + */ | ||
261 | + | ||
262 | +#include "qemu/osdep.h" | ||
263 | + | ||
264 | +#include "hw/gpio/npcm7xx_gpio.h" | ||
265 | +#include "hw/irq.h" | ||
266 | +#include "hw/qdev-properties.h" | ||
267 | +#include "migration/vmstate.h" | ||
268 | +#include "qapi/error.h" | ||
269 | +#include "qemu/log.h" | ||
270 | +#include "qemu/module.h" | ||
271 | +#include "qemu/units.h" | ||
272 | +#include "trace.h" | ||
273 | + | ||
274 | +/* 32-bit register indices. */ | ||
275 | +enum NPCM7xxGPIORegister { | ||
276 | + NPCM7XX_GPIO_TLOCK1, | ||
277 | + NPCM7XX_GPIO_DIN, | ||
278 | + NPCM7XX_GPIO_POL, | ||
279 | + NPCM7XX_GPIO_DOUT, | ||
280 | + NPCM7XX_GPIO_OE, | ||
281 | + NPCM7XX_GPIO_OTYP, | ||
282 | + NPCM7XX_GPIO_MP, | ||
283 | + NPCM7XX_GPIO_PU, | ||
284 | + NPCM7XX_GPIO_PD, | ||
285 | + NPCM7XX_GPIO_DBNC, | ||
286 | + NPCM7XX_GPIO_EVTYP, | ||
287 | + NPCM7XX_GPIO_EVBE, | ||
288 | + NPCM7XX_GPIO_OBL0, | ||
289 | + NPCM7XX_GPIO_OBL1, | ||
290 | + NPCM7XX_GPIO_OBL2, | ||
291 | + NPCM7XX_GPIO_OBL3, | ||
292 | + NPCM7XX_GPIO_EVEN, | ||
293 | + NPCM7XX_GPIO_EVENS, | ||
294 | + NPCM7XX_GPIO_EVENC, | ||
295 | + NPCM7XX_GPIO_EVST, | ||
296 | + NPCM7XX_GPIO_SPLCK, | ||
297 | + NPCM7XX_GPIO_MPLCK, | ||
298 | + NPCM7XX_GPIO_IEM, | ||
299 | + NPCM7XX_GPIO_OSRC, | ||
300 | + NPCM7XX_GPIO_ODSC, | ||
301 | + NPCM7XX_GPIO_DOS = 0x68 / sizeof(uint32_t), | ||
302 | + NPCM7XX_GPIO_DOC, | ||
303 | + NPCM7XX_GPIO_OES, | ||
304 | + NPCM7XX_GPIO_OEC, | ||
305 | + NPCM7XX_GPIO_TLOCK2 = 0x7c / sizeof(uint32_t), | ||
306 | + NPCM7XX_GPIO_REGS_END, | ||
307 | +}; | ||
308 | + | ||
309 | +#define NPCM7XX_GPIO_REGS_SIZE (4 * KiB) | ||
310 | + | ||
311 | +#define NPCM7XX_GPIO_LOCK_MAGIC1 (0xc0defa73) | ||
312 | +#define NPCM7XX_GPIO_LOCK_MAGIC2 (0xc0de1248) | ||
313 | + | ||
314 | +static void npcm7xx_gpio_update_events(NPCM7xxGPIOState *s, uint32_t din_diff) | ||
315 | +{ | ||
316 | + uint32_t din_new = s->regs[NPCM7XX_GPIO_DIN]; | ||
317 | + | ||
318 | + /* Trigger on high level */ | ||
319 | + s->regs[NPCM7XX_GPIO_EVST] |= din_new & ~s->regs[NPCM7XX_GPIO_EVTYP]; | ||
320 | + /* Trigger on both edges */ | ||
321 | + s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & s->regs[NPCM7XX_GPIO_EVTYP] | ||
322 | + & s->regs[NPCM7XX_GPIO_EVBE]); | ||
323 | + /* Trigger on rising edge */ | ||
324 | + s->regs[NPCM7XX_GPIO_EVST] |= (din_diff & din_new | ||
325 | + & s->regs[NPCM7XX_GPIO_EVTYP]); | ||
326 | + | ||
327 | + trace_npcm7xx_gpio_update_events(DEVICE(s)->canonical_path, | ||
328 | + s->regs[NPCM7XX_GPIO_EVST], | ||
329 | + s->regs[NPCM7XX_GPIO_EVEN]); | ||
330 | + qemu_set_irq(s->irq, !!(s->regs[NPCM7XX_GPIO_EVST] | ||
331 | + & s->regs[NPCM7XX_GPIO_EVEN])); | ||
332 | +} | ||
333 | + | ||
334 | +static void npcm7xx_gpio_update_pins(NPCM7xxGPIOState *s, uint32_t diff) | ||
335 | +{ | ||
336 | + uint32_t drive_en; | ||
337 | + uint32_t drive_lvl; | ||
338 | + uint32_t not_driven; | ||
339 | + uint32_t undefined; | ||
340 | + uint32_t pin_diff; | ||
341 | + uint32_t din_old; | ||
342 | + | ||
343 | + /* Calculate level of each pin driven by GPIO controller. */ | ||
344 | + drive_lvl = s->regs[NPCM7XX_GPIO_DOUT] ^ s->regs[NPCM7XX_GPIO_POL]; | ||
345 | + /* If OTYP=1, only drive low (open drain) */ | ||
346 | + drive_en = s->regs[NPCM7XX_GPIO_OE] & ~(s->regs[NPCM7XX_GPIO_OTYP] | ||
347 | + & drive_lvl); | ||
348 | + /* | ||
349 | + * If a pin is driven to opposite levels by the GPIO controller and the | ||
350 | + * external driver, the result is undefined. | ||
351 | + */ | ||
352 | + undefined = drive_en & s->ext_driven & (drive_lvl ^ s->ext_level); | ||
353 | + if (undefined) { | ||
354 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
355 | + "%s: pins have multiple drivers: 0x%" PRIx32 "\n", | ||
356 | + DEVICE(s)->canonical_path, undefined); | ||
51 | + } | 357 | + } |
52 | + | 358 | + |
53 | + if (a->l) { | 359 | + not_driven = ~(drive_en | s->ext_driven); |
54 | + /* VFP to general purpose register */ | 360 | + pin_diff = s->pin_level; |
55 | + tmp = tcg_temp_new_i32(); | 361 | + |
56 | + neon_load_reg32(tmp, a->vn); | 362 | + /* Set pins to externally driven level. */ |
57 | + tcg_gen_andi_i32(tmp, tmp, 0xffff); | 363 | + s->pin_level = s->ext_level & s->ext_driven; |
58 | + store_reg(s, a->rt, tmp); | 364 | + /* Set internally driven pins, ignoring any conflicts. */ |
59 | + } else { | 365 | + s->pin_level |= drive_lvl & drive_en; |
60 | + /* general purpose register to VFP */ | 366 | + /* Pull up undriven pins with internal pull-up enabled. */ |
61 | + tmp = load_reg(s, a->rt); | 367 | + s->pin_level |= not_driven & s->regs[NPCM7XX_GPIO_PU]; |
62 | + tcg_gen_andi_i32(tmp, tmp, 0xffff); | 368 | + /* Pins not driven, pulled up or pulled down are undefined */ |
63 | + neon_store_reg32(tmp, a->vn); | 369 | + undefined |= not_driven & ~(s->regs[NPCM7XX_GPIO_PU] |
64 | + tcg_temp_free_i32(tmp); | 370 | + | s->regs[NPCM7XX_GPIO_PD]); |
371 | + | ||
372 | + /* If any pins changed state, update the outgoing GPIOs. */ | ||
373 | + pin_diff ^= s->pin_level; | ||
374 | + pin_diff |= undefined & diff; | ||
375 | + if (pin_diff) { | ||
376 | + int i; | ||
377 | + | ||
378 | + for (i = 0; i < NPCM7XX_GPIO_NR_PINS; i++) { | ||
379 | + uint32_t mask = BIT(i); | ||
380 | + if (pin_diff & mask) { | ||
381 | + int level = (undefined & mask) ? -1 : !!(s->pin_level & mask); | ||
382 | + trace_npcm7xx_gpio_set_output(DEVICE(s)->canonical_path, | ||
383 | + i, level); | ||
384 | + qemu_set_irq(s->output[i], level); | ||
385 | + } | ||
386 | + } | ||
65 | + } | 387 | + } |
66 | + | 388 | + |
67 | + return true; | 389 | + /* Calculate new value of DIN after masking and polarity setting. */ |
68 | +} | 390 | + din_old = s->regs[NPCM7XX_GPIO_DIN]; |
69 | + | 391 | + s->regs[NPCM7XX_GPIO_DIN] = ((s->pin_level & s->regs[NPCM7XX_GPIO_IEM]) |
70 | static bool trans_VMOV_single(DisasContext *s, arg_VMOV_single *a) | 392 | + ^ s->regs[NPCM7XX_GPIO_POL]); |
71 | { | 393 | + |
72 | TCGv_i32 tmp; | 394 | + /* See if any new events triggered because of all this. */ |
395 | + npcm7xx_gpio_update_events(s, din_old ^ s->regs[NPCM7XX_GPIO_DIN]); | ||
396 | +} | ||
397 | + | ||
398 | +static bool npcm7xx_gpio_is_locked(NPCM7xxGPIOState *s) | ||
399 | +{ | ||
400 | + return s->regs[NPCM7XX_GPIO_TLOCK1] == 1; | ||
401 | +} | ||
402 | + | ||
403 | +static uint64_t npcm7xx_gpio_regs_read(void *opaque, hwaddr addr, | ||
404 | + unsigned int size) | ||
405 | +{ | ||
406 | + hwaddr reg = addr / sizeof(uint32_t); | ||
407 | + NPCM7xxGPIOState *s = opaque; | ||
408 | + uint64_t value = 0; | ||
409 | + | ||
410 | + switch (reg) { | ||
411 | + case NPCM7XX_GPIO_TLOCK1 ... NPCM7XX_GPIO_EVEN: | ||
412 | + case NPCM7XX_GPIO_EVST ... NPCM7XX_GPIO_ODSC: | ||
413 | + value = s->regs[reg]; | ||
414 | + break; | ||
415 | + | ||
416 | + case NPCM7XX_GPIO_EVENS ... NPCM7XX_GPIO_EVENC: | ||
417 | + case NPCM7XX_GPIO_DOS ... NPCM7XX_GPIO_TLOCK2: | ||
418 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
419 | + "%s: read from write-only register 0x%" HWADDR_PRIx "\n", | ||
420 | + DEVICE(s)->canonical_path, addr); | ||
421 | + break; | ||
422 | + | ||
423 | + default: | ||
424 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
425 | + "%s: read from invalid offset 0x%" HWADDR_PRIx "\n", | ||
426 | + DEVICE(s)->canonical_path, addr); | ||
427 | + break; | ||
428 | + } | ||
429 | + | ||
430 | + trace_npcm7xx_gpio_read(DEVICE(s)->canonical_path, addr, value); | ||
431 | + | ||
432 | + return value; | ||
433 | +} | ||
434 | + | ||
435 | +static void npcm7xx_gpio_regs_write(void *opaque, hwaddr addr, uint64_t v, | ||
436 | + unsigned int size) | ||
437 | +{ | ||
438 | + hwaddr reg = addr / sizeof(uint32_t); | ||
439 | + NPCM7xxGPIOState *s = opaque; | ||
440 | + uint32_t value = v; | ||
441 | + uint32_t diff; | ||
442 | + | ||
443 | + trace_npcm7xx_gpio_write(DEVICE(s)->canonical_path, addr, v); | ||
444 | + | ||
445 | + if (npcm7xx_gpio_is_locked(s)) { | ||
446 | + switch (reg) { | ||
447 | + case NPCM7XX_GPIO_TLOCK1: | ||
448 | + if (s->regs[NPCM7XX_GPIO_TLOCK2] == NPCM7XX_GPIO_LOCK_MAGIC2 && | ||
449 | + value == NPCM7XX_GPIO_LOCK_MAGIC1) { | ||
450 | + s->regs[NPCM7XX_GPIO_TLOCK1] = 0; | ||
451 | + s->regs[NPCM7XX_GPIO_TLOCK2] = 0; | ||
452 | + } | ||
453 | + break; | ||
454 | + | ||
455 | + case NPCM7XX_GPIO_TLOCK2: | ||
456 | + s->regs[reg] = value; | ||
457 | + break; | ||
458 | + | ||
459 | + default: | ||
460 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
461 | + "%s: write to locked register @ 0x%" HWADDR_PRIx "\n", | ||
462 | + DEVICE(s)->canonical_path, addr); | ||
463 | + break; | ||
464 | + } | ||
465 | + | ||
466 | + return; | ||
467 | + } | ||
468 | + | ||
469 | + diff = s->regs[reg] ^ value; | ||
470 | + | ||
471 | + switch (reg) { | ||
472 | + case NPCM7XX_GPIO_TLOCK1: | ||
473 | + case NPCM7XX_GPIO_TLOCK2: | ||
474 | + s->regs[NPCM7XX_GPIO_TLOCK1] = 1; | ||
475 | + s->regs[NPCM7XX_GPIO_TLOCK2] = 0; | ||
476 | + break; | ||
477 | + | ||
478 | + case NPCM7XX_GPIO_DIN: | ||
479 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
480 | + "%s: write to read-only register @ 0x%" HWADDR_PRIx "\n", | ||
481 | + DEVICE(s)->canonical_path, addr); | ||
482 | + break; | ||
483 | + | ||
484 | + case NPCM7XX_GPIO_POL: | ||
485 | + case NPCM7XX_GPIO_DOUT: | ||
486 | + case NPCM7XX_GPIO_OE: | ||
487 | + case NPCM7XX_GPIO_OTYP: | ||
488 | + case NPCM7XX_GPIO_PU: | ||
489 | + case NPCM7XX_GPIO_PD: | ||
490 | + case NPCM7XX_GPIO_IEM: | ||
491 | + s->regs[reg] = value; | ||
492 | + npcm7xx_gpio_update_pins(s, diff); | ||
493 | + break; | ||
494 | + | ||
495 | + case NPCM7XX_GPIO_DOS: | ||
496 | + s->regs[NPCM7XX_GPIO_DOUT] |= value; | ||
497 | + npcm7xx_gpio_update_pins(s, value); | ||
498 | + break; | ||
499 | + case NPCM7XX_GPIO_DOC: | ||
500 | + s->regs[NPCM7XX_GPIO_DOUT] &= ~value; | ||
501 | + npcm7xx_gpio_update_pins(s, value); | ||
502 | + break; | ||
503 | + case NPCM7XX_GPIO_OES: | ||
504 | + s->regs[NPCM7XX_GPIO_OE] |= value; | ||
505 | + npcm7xx_gpio_update_pins(s, value); | ||
506 | + break; | ||
507 | + case NPCM7XX_GPIO_OEC: | ||
508 | + s->regs[NPCM7XX_GPIO_OE] &= ~value; | ||
509 | + npcm7xx_gpio_update_pins(s, value); | ||
510 | + break; | ||
511 | + | ||
512 | + case NPCM7XX_GPIO_EVTYP: | ||
513 | + case NPCM7XX_GPIO_EVBE: | ||
514 | + case NPCM7XX_GPIO_EVEN: | ||
515 | + s->regs[reg] = value; | ||
516 | + npcm7xx_gpio_update_events(s, 0); | ||
517 | + break; | ||
518 | + | ||
519 | + case NPCM7XX_GPIO_EVENS: | ||
520 | + s->regs[NPCM7XX_GPIO_EVEN] |= value; | ||
521 | + npcm7xx_gpio_update_events(s, 0); | ||
522 | + break; | ||
523 | + case NPCM7XX_GPIO_EVENC: | ||
524 | + s->regs[NPCM7XX_GPIO_EVEN] &= ~value; | ||
525 | + npcm7xx_gpio_update_events(s, 0); | ||
526 | + break; | ||
527 | + | ||
528 | + case NPCM7XX_GPIO_EVST: | ||
529 | + s->regs[reg] &= ~value; | ||
530 | + npcm7xx_gpio_update_events(s, 0); | ||
531 | + break; | ||
532 | + | ||
533 | + case NPCM7XX_GPIO_MP: | ||
534 | + case NPCM7XX_GPIO_DBNC: | ||
535 | + case NPCM7XX_GPIO_OSRC: | ||
536 | + case NPCM7XX_GPIO_ODSC: | ||
537 | + /* Nothing to do; just store the value. */ | ||
538 | + s->regs[reg] = value; | ||
539 | + break; | ||
540 | + | ||
541 | + case NPCM7XX_GPIO_OBL0: | ||
542 | + case NPCM7XX_GPIO_OBL1: | ||
543 | + case NPCM7XX_GPIO_OBL2: | ||
544 | + case NPCM7XX_GPIO_OBL3: | ||
545 | + s->regs[reg] = value; | ||
546 | + qemu_log_mask(LOG_UNIMP, "%s: Blinking is not implemented\n", | ||
547 | + __func__); | ||
548 | + break; | ||
549 | + | ||
550 | + case NPCM7XX_GPIO_SPLCK: | ||
551 | + case NPCM7XX_GPIO_MPLCK: | ||
552 | + qemu_log_mask(LOG_UNIMP, "%s: Per-pin lock is not implemented\n", | ||
553 | + __func__); | ||
554 | + break; | ||
555 | + | ||
556 | + default: | ||
557 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
558 | + "%s: write to invalid offset 0x%" HWADDR_PRIx "\n", | ||
559 | + DEVICE(s)->canonical_path, addr); | ||
560 | + break; | ||
561 | + } | ||
562 | +} | ||
563 | + | ||
564 | +static const MemoryRegionOps npcm7xx_gpio_regs_ops = { | ||
565 | + .read = npcm7xx_gpio_regs_read, | ||
566 | + .write = npcm7xx_gpio_regs_write, | ||
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 = \ | ||
73 | -- | 1105 | -- |
74 | 2.20.1 | 1106 | 2.20.1 |
75 | 1107 | ||
76 | 1108 | diff view generated by jsdifflib |
1 | Convert the neon floating-point vector compare-vs-0 insns VCEQ0, | 1 | From: Zenghui Yu <yuzenghui@huawei.com> |
---|---|---|---|
2 | VCGT0, VCLE0, VCGE0 and VCLT0 to use a gvec helper, and use this to | ||
3 | implement the fp16 case. | ||
4 | 2 | ||
3 | Ensure the vSMMUv3 will be restored before all PCIe devices so that DMA | ||
4 | translation can work properly during migration. | ||
5 | |||
6 | Signed-off-by: Zenghui Yu <yuzenghui@huawei.com> | ||
7 | Message-id: 20201019091508.197-1-yuzenghui@huawei.com | ||
8 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20200828183354.27913-33-peter.maydell@linaro.org | ||
8 | --- | 10 | --- |
9 | target/arm/helper.h | 15 +++++++++++++++ | 11 | hw/arm/smmuv3.c | 1 + |
10 | target/arm/vec_helper.c | 25 +++++++++++++++++++++++++ | 12 | 1 file changed, 1 insertion(+) |
11 | target/arm/translate-neon.c.inc | 33 +++++---------------------------- | ||
12 | 3 files changed, 45 insertions(+), 28 deletions(-) | ||
13 | 13 | ||
14 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 14 | diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/helper.h | 16 | --- a/hw/arm/smmuv3.c |
17 | +++ b/target/arm/helper.h | 17 | +++ b/hw/arm/smmuv3.c |
18 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(gvec_frsqrte_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 18 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_smmuv3 = { |
19 | DEF_HELPER_FLAGS_4(gvec_frsqrte_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 19 | .name = "smmuv3", |
20 | DEF_HELPER_FLAGS_4(gvec_frsqrte_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 20 | .version_id = 1, |
21 | 21 | .minimum_version_id = 1, | |
22 | +DEF_HELPER_FLAGS_4(gvec_fcgt0_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 22 | + .priority = MIG_PRI_IOMMU, |
23 | +DEF_HELPER_FLAGS_4(gvec_fcgt0_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 23 | .fields = (VMStateField[]) { |
24 | + | 24 | VMSTATE_UINT32(features, SMMUv3State), |
25 | +DEF_HELPER_FLAGS_4(gvec_fcge0_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 25 | VMSTATE_UINT8(sid_size, SMMUv3State), |
26 | +DEF_HELPER_FLAGS_4(gvec_fcge0_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
27 | + | ||
28 | +DEF_HELPER_FLAGS_4(gvec_fceq0_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
29 | +DEF_HELPER_FLAGS_4(gvec_fceq0_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
30 | + | ||
31 | +DEF_HELPER_FLAGS_4(gvec_fcle0_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
32 | +DEF_HELPER_FLAGS_4(gvec_fcle0_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
33 | + | ||
34 | +DEF_HELPER_FLAGS_4(gvec_fclt0_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
35 | +DEF_HELPER_FLAGS_4(gvec_fclt0_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
36 | + | ||
37 | DEF_HELPER_FLAGS_5(gvec_fadd_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | ||
38 | DEF_HELPER_FLAGS_5(gvec_fadd_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | ||
39 | DEF_HELPER_FLAGS_5(gvec_fadd_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | ||
40 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/target/arm/vec_helper.c | ||
43 | +++ b/target/arm/vec_helper.c | ||
44 | @@ -XXX,XX +XXX,XX @@ DO_2OP(gvec_frsqrte_h, helper_rsqrte_f16, float16) | ||
45 | DO_2OP(gvec_frsqrte_s, helper_rsqrte_f32, float32) | ||
46 | DO_2OP(gvec_frsqrte_d, helper_rsqrte_f64, float64) | ||
47 | |||
48 | +#define WRAP_CMP0_FWD(FN, CMPOP, TYPE) \ | ||
49 | + static TYPE TYPE##_##FN##0(TYPE op, float_status *stat) \ | ||
50 | + { \ | ||
51 | + return TYPE##_##CMPOP(op, TYPE##_zero, stat); \ | ||
52 | + } | ||
53 | + | ||
54 | +#define WRAP_CMP0_REV(FN, CMPOP, TYPE) \ | ||
55 | + static TYPE TYPE##_##FN##0(TYPE op, float_status *stat) \ | ||
56 | + { \ | ||
57 | + return TYPE##_##CMPOP(TYPE##_zero, op, stat); \ | ||
58 | + } | ||
59 | + | ||
60 | +#define DO_2OP_CMP0(FN, CMPOP, DIRN) \ | ||
61 | + WRAP_CMP0_##DIRN(FN, CMPOP, float16) \ | ||
62 | + WRAP_CMP0_##DIRN(FN, CMPOP, float32) \ | ||
63 | + DO_2OP(gvec_f##FN##0_h, float16_##FN##0, float16) \ | ||
64 | + DO_2OP(gvec_f##FN##0_s, float32_##FN##0, float32) | ||
65 | + | ||
66 | +DO_2OP_CMP0(cgt, cgt, FWD) | ||
67 | +DO_2OP_CMP0(cge, cge, FWD) | ||
68 | +DO_2OP_CMP0(ceq, ceq, FWD) | ||
69 | +DO_2OP_CMP0(clt, cgt, REV) | ||
70 | +DO_2OP_CMP0(cle, cge, REV) | ||
71 | + | ||
72 | #undef DO_2OP | ||
73 | +#undef DO_2OP_CMP0 | ||
74 | |||
75 | /* Floating-point trigonometric starting value. | ||
76 | * See the ARM ARM pseudocode function FPTrigSMul. | ||
77 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/target/arm/translate-neon.c.inc | ||
80 | +++ b/target/arm/translate-neon.c.inc | ||
81 | @@ -XXX,XX +XXX,XX @@ DO_2MISC_FP(VCVT_UF, gen_helper_vfp_touizs) | ||
82 | |||
83 | DO_2MISC_FP_VEC(VRECPE_F, gen_helper_gvec_frecpe_h, gen_helper_gvec_frecpe_s) | ||
84 | DO_2MISC_FP_VEC(VRSQRTE_F, gen_helper_gvec_frsqrte_h, gen_helper_gvec_frsqrte_s) | ||
85 | +DO_2MISC_FP_VEC(VCGT0_F, gen_helper_gvec_fcgt0_h, gen_helper_gvec_fcgt0_s) | ||
86 | +DO_2MISC_FP_VEC(VCGE0_F, gen_helper_gvec_fcge0_h, gen_helper_gvec_fcge0_s) | ||
87 | +DO_2MISC_FP_VEC(VCEQ0_F, gen_helper_gvec_fceq0_h, gen_helper_gvec_fceq0_s) | ||
88 | +DO_2MISC_FP_VEC(VCLT0_F, gen_helper_gvec_fclt0_h, gen_helper_gvec_fclt0_s) | ||
89 | +DO_2MISC_FP_VEC(VCLE0_F, gen_helper_gvec_fcle0_h, gen_helper_gvec_fcle0_s) | ||
90 | |||
91 | static bool trans_VRINTX(DisasContext *s, arg_2misc *a) | ||
92 | { | ||
93 | @@ -XXX,XX +XXX,XX @@ static bool trans_VRINTX(DisasContext *s, arg_2misc *a) | ||
94 | return do_2misc_fp(s, a, gen_helper_rints_exact); | ||
95 | } | ||
96 | |||
97 | -#define WRAP_FP_CMP0_FWD(WRAPNAME, FUNC) \ | ||
98 | - static void WRAPNAME(TCGv_i32 d, TCGv_i32 m, TCGv_ptr fpst) \ | ||
99 | - { \ | ||
100 | - TCGv_i32 zero = tcg_const_i32(0); \ | ||
101 | - FUNC(d, m, zero, fpst); \ | ||
102 | - tcg_temp_free_i32(zero); \ | ||
103 | - } | ||
104 | -#define WRAP_FP_CMP0_REV(WRAPNAME, FUNC) \ | ||
105 | - static void WRAPNAME(TCGv_i32 d, TCGv_i32 m, TCGv_ptr fpst) \ | ||
106 | - { \ | ||
107 | - TCGv_i32 zero = tcg_const_i32(0); \ | ||
108 | - FUNC(d, zero, m, fpst); \ | ||
109 | - tcg_temp_free_i32(zero); \ | ||
110 | - } | ||
111 | - | ||
112 | -#define DO_FP_CMP0(INSN, FUNC, REV) \ | ||
113 | - WRAP_FP_CMP0_##REV(gen_##INSN, FUNC) \ | ||
114 | - static bool trans_##INSN(DisasContext *s, arg_2misc *a) \ | ||
115 | - { \ | ||
116 | - return do_2misc_fp(s, a, gen_##INSN); \ | ||
117 | - } | ||
118 | - | ||
119 | -DO_FP_CMP0(VCGT0_F, gen_helper_neon_cgt_f32, FWD) | ||
120 | -DO_FP_CMP0(VCGE0_F, gen_helper_neon_cge_f32, FWD) | ||
121 | -DO_FP_CMP0(VCEQ0_F, gen_helper_neon_ceq_f32, FWD) | ||
122 | -DO_FP_CMP0(VCLE0_F, gen_helper_neon_cge_f32, REV) | ||
123 | -DO_FP_CMP0(VCLT0_F, gen_helper_neon_cgt_f32, REV) | ||
124 | - | ||
125 | static bool do_vrint(DisasContext *s, arg_2misc *a, int rmode) | ||
126 | { | ||
127 | /* | ||
128 | -- | 26 | -- |
129 | 2.20.1 | 27 | 2.20.1 |
130 | 28 | ||
131 | 29 | diff view generated by jsdifflib |
1 | Convert the neon floating-point vector operations VFMA and VFMS | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | to use a gvec helper, and use this to implement the fp16 case. | ||
3 | 2 | ||
4 | This is the last use of do_3same_fp() so we can now delete | 3 | No code out of bcm2836.c uses (or requires) the BCM283XInfo |
5 | that function. | 4 | declarations. Move it locally to the C source file. |
6 | 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 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20200828183354.27913-32-peter.maydell@linaro.org | ||
10 | --- | 10 | --- |
11 | target/arm/helper.h | 6 +++ | 11 | include/hw/arm/bcm2836.h | 8 -------- |
12 | target/arm/vec_helper.c | 33 +++++++++++- | 12 | hw/arm/bcm2836.c | 14 ++++++++++++++ |
13 | target/arm/translate-neon.c.inc | 92 +-------------------------------- | 13 | 2 files changed, 14 insertions(+), 8 deletions(-) |
14 | 3 files changed, 40 insertions(+), 91 deletions(-) | ||
15 | 14 | ||
16 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 15 | diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h |
17 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/helper.h | 17 | --- a/include/hw/arm/bcm2836.h |
19 | +++ b/target/arm/helper.h | 18 | +++ b/include/hw/arm/bcm2836.h |
20 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fmla_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 19 | @@ -XXX,XX +XXX,XX @@ struct BCM283XState { |
21 | DEF_HELPER_FLAGS_5(gvec_fmls_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 20 | BCM2835PeripheralState peripherals; |
22 | DEF_HELPER_FLAGS_5(gvec_fmls_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 21 | }; |
23 | 22 | ||
24 | +DEF_HELPER_FLAGS_5(gvec_vfma_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 23 | -typedef struct BCM283XInfo BCM283XInfo; |
25 | +DEF_HELPER_FLAGS_5(gvec_vfma_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 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; | ||
26 | + | 41 | + |
27 | +DEF_HELPER_FLAGS_5(gvec_vfms_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 42 | +typedef struct BCM283XClass { |
28 | +DEF_HELPER_FLAGS_5(gvec_vfms_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 43 | + /*< private >*/ |
44 | + DeviceClass parent_class; | ||
45 | + /*< public >*/ | ||
46 | + const BCM283XInfo *info; | ||
47 | +} BCM283XClass; | ||
29 | + | 48 | + |
30 | DEF_HELPER_FLAGS_5(gvec_ftsmul_h, TCG_CALL_NO_RWG, | 49 | struct BCM283XInfo { |
31 | void, ptr, ptr, ptr, ptr, i32) | 50 | const char *name; |
32 | DEF_HELPER_FLAGS_5(gvec_ftsmul_s, TCG_CALL_NO_RWG, | 51 | const char *cpu_type; |
33 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 52 | @@ -XXX,XX +XXX,XX @@ struct BCM283XInfo { |
34 | index XXXXXXX..XXXXXXX 100644 | 53 | int clusterid; |
35 | --- a/target/arm/vec_helper.c | 54 | }; |
36 | +++ b/target/arm/vec_helper.c | 55 | |
37 | @@ -XXX,XX +XXX,XX @@ static float32 float32_mulsub_nf(float32 dest, float32 op1, float32 op2, | 56 | +#define BCM283X_CLASS(klass) \ |
38 | return float32_sub(dest, float32_mul(op1, op2, stat), stat); | 57 | + OBJECT_CLASS_CHECK(BCM283XClass, (klass), TYPE_BCM283X) |
39 | } | 58 | +#define BCM283X_GET_CLASS(obj) \ |
40 | 59 | + OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) | |
41 | -#define DO_MULADD(NAME, FUNC, TYPE) \ | ||
42 | +/* Fused versions; these have the semantics Neon VFMA/VFMS want */ | ||
43 | +static float16 float16_muladd_f(float16 dest, float16 op1, float16 op2, | ||
44 | + float_status *stat) | ||
45 | +{ | ||
46 | + return float16_muladd(op1, op2, dest, 0, stat); | ||
47 | +} | ||
48 | + | 60 | + |
49 | +static float32 float32_muladd_f(float32 dest, float32 op1, float32 op2, | 61 | static const BCM283XInfo bcm283x_socs[] = { |
50 | + float_status *stat) | 62 | { |
51 | +{ | 63 | .name = TYPE_BCM2836, |
52 | + return float32_muladd(op1, op2, dest, 0, stat); | ||
53 | +} | ||
54 | + | ||
55 | +static float16 float16_mulsub_f(float16 dest, float16 op1, float16 op2, | ||
56 | + float_status *stat) | ||
57 | +{ | ||
58 | + return float16_muladd(float16_chs(op1), op2, dest, 0, stat); | ||
59 | +} | ||
60 | + | ||
61 | +static float32 float32_mulsub_f(float32 dest, float32 op1, float32 op2, | ||
62 | + float_status *stat) | ||
63 | +{ | ||
64 | + return float32_muladd(float32_chs(op1), op2, dest, 0, stat); | ||
65 | +} | ||
66 | + | ||
67 | +#define DO_MULADD(NAME, FUNC, TYPE) \ | ||
68 | void HELPER(NAME)(void *vd, void *vn, void *vm, void *stat, uint32_t desc) \ | ||
69 | { \ | ||
70 | intptr_t i, oprsz = simd_oprsz(desc); \ | ||
71 | @@ -XXX,XX +XXX,XX @@ DO_MULADD(gvec_fmla_s, float32_muladd_nf, float32) | ||
72 | DO_MULADD(gvec_fmls_h, float16_mulsub_nf, float16) | ||
73 | DO_MULADD(gvec_fmls_s, float32_mulsub_nf, float32) | ||
74 | |||
75 | +DO_MULADD(gvec_vfma_h, float16_muladd_f, float16) | ||
76 | +DO_MULADD(gvec_vfma_s, float32_muladd_f, float32) | ||
77 | + | ||
78 | +DO_MULADD(gvec_vfms_h, float16_mulsub_f, float16) | ||
79 | +DO_MULADD(gvec_vfms_s, float32_mulsub_f, float32) | ||
80 | + | ||
81 | /* For the indexed ops, SVE applies the index per 128-bit vector segment. | ||
82 | * For AdvSIMD, there is of course only one such vector segment. | ||
83 | */ | ||
84 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/target/arm/translate-neon.c.inc | ||
87 | +++ b/target/arm/translate-neon.c.inc | ||
88 | @@ -XXX,XX +XXX,XX @@ DO_3SAME_PAIR(VPADD, padd_u) | ||
89 | DO_3SAME_VQDMULH(VQDMULH, qdmulh) | ||
90 | DO_3SAME_VQDMULH(VQRDMULH, qrdmulh) | ||
91 | |||
92 | -static bool do_3same_fp(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn, | ||
93 | - bool reads_vd) | ||
94 | -{ | ||
95 | - /* | ||
96 | - * FP operations handled elementwise 32 bits at a time. | ||
97 | - * If reads_vd is true then the old value of Vd will be | ||
98 | - * loaded before calling the callback function. This is | ||
99 | - * used for multiply-accumulate type operations. | ||
100 | - */ | ||
101 | - TCGv_i32 tmp, tmp2; | ||
102 | - int pass; | ||
103 | - | ||
104 | - if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | ||
105 | - return false; | ||
106 | - } | ||
107 | - | ||
108 | - /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
109 | - if (!dc_isar_feature(aa32_simd_r32, s) && | ||
110 | - ((a->vd | a->vn | a->vm) & 0x10)) { | ||
111 | - return false; | ||
112 | - } | ||
113 | - | ||
114 | - if ((a->vn | a->vm | a->vd) & a->q) { | ||
115 | - return false; | ||
116 | - } | ||
117 | - | ||
118 | - if (!vfp_access_check(s)) { | ||
119 | - return true; | ||
120 | - } | ||
121 | - | ||
122 | - TCGv_ptr fpstatus = fpstatus_ptr(FPST_STD); | ||
123 | - for (pass = 0; pass < (a->q ? 4 : 2); pass++) { | ||
124 | - tmp = neon_load_reg(a->vn, pass); | ||
125 | - tmp2 = neon_load_reg(a->vm, pass); | ||
126 | - if (reads_vd) { | ||
127 | - TCGv_i32 tmp_rd = neon_load_reg(a->vd, pass); | ||
128 | - fn(tmp_rd, tmp, tmp2, fpstatus); | ||
129 | - neon_store_reg(a->vd, pass, tmp_rd); | ||
130 | - tcg_temp_free_i32(tmp); | ||
131 | - } else { | ||
132 | - fn(tmp, tmp, tmp2, fpstatus); | ||
133 | - neon_store_reg(a->vd, pass, tmp); | ||
134 | - } | ||
135 | - tcg_temp_free_i32(tmp2); | ||
136 | - } | ||
137 | - tcg_temp_free_ptr(fpstatus); | ||
138 | - return true; | ||
139 | -} | ||
140 | - | ||
141 | #define WRAP_FP_GVEC(WRAPNAME, FPST, FUNC) \ | ||
142 | static void WRAPNAME(unsigned vece, uint32_t rd_ofs, \ | ||
143 | uint32_t rn_ofs, uint32_t rm_ofs, \ | ||
144 | @@ -XXX,XX +XXX,XX @@ DO_3S_FP_GVEC(VMAX, gen_helper_gvec_fmax_s, gen_helper_gvec_fmax_h) | ||
145 | DO_3S_FP_GVEC(VMIN, gen_helper_gvec_fmin_s, gen_helper_gvec_fmin_h) | ||
146 | DO_3S_FP_GVEC(VMLA, gen_helper_gvec_fmla_s, gen_helper_gvec_fmla_h) | ||
147 | DO_3S_FP_GVEC(VMLS, gen_helper_gvec_fmls_s, gen_helper_gvec_fmls_h) | ||
148 | +DO_3S_FP_GVEC(VFMA, gen_helper_gvec_vfma_s, gen_helper_gvec_vfma_h) | ||
149 | +DO_3S_FP_GVEC(VFMS, gen_helper_gvec_vfms_s, gen_helper_gvec_vfms_h) | ||
150 | |||
151 | WRAP_FP_GVEC(gen_VMAXNM_fp32_3s, FPST_STD, gen_helper_gvec_fmaxnum_s) | ||
152 | WRAP_FP_GVEC(gen_VMAXNM_fp16_3s, FPST_STD_F16, gen_helper_gvec_fmaxnum_h) | ||
153 | @@ -XXX,XX +XXX,XX @@ static bool trans_VRSQRTS_fp_3s(DisasContext *s, arg_3same *a) | ||
154 | return do_3same(s, a, gen_VRSQRTS_fp_3s); | ||
155 | } | ||
156 | |||
157 | -static void gen_VFMA_fp_3s(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, | ||
158 | - TCGv_ptr fpstatus) | ||
159 | -{ | ||
160 | - gen_helper_vfp_muladds(vd, vn, vm, vd, fpstatus); | ||
161 | -} | ||
162 | - | ||
163 | -static bool trans_VFMA_fp_3s(DisasContext *s, arg_3same *a) | ||
164 | -{ | ||
165 | - if (!dc_isar_feature(aa32_simdfmac, s)) { | ||
166 | - return false; | ||
167 | - } | ||
168 | - | ||
169 | - if (a->size != 0) { | ||
170 | - /* TODO fp16 support */ | ||
171 | - return false; | ||
172 | - } | ||
173 | - | ||
174 | - return do_3same_fp(s, a, gen_VFMA_fp_3s, true); | ||
175 | -} | ||
176 | - | ||
177 | -static void gen_VFMS_fp_3s(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, | ||
178 | - TCGv_ptr fpstatus) | ||
179 | -{ | ||
180 | - gen_helper_vfp_negs(vn, vn); | ||
181 | - gen_helper_vfp_muladds(vd, vn, vm, vd, fpstatus); | ||
182 | -} | ||
183 | - | ||
184 | -static bool trans_VFMS_fp_3s(DisasContext *s, arg_3same *a) | ||
185 | -{ | ||
186 | - if (!dc_isar_feature(aa32_simdfmac, s)) { | ||
187 | - return false; | ||
188 | - } | ||
189 | - | ||
190 | - if (a->size != 0) { | ||
191 | - /* TODO fp16 support */ | ||
192 | - return false; | ||
193 | - } | ||
194 | - | ||
195 | - return do_3same_fp(s, a, gen_VFMS_fp_3s, true); | ||
196 | -} | ||
197 | - | ||
198 | static bool do_3same_fp_pair(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn) | ||
199 | { | ||
200 | /* FP operations handled pairwise 32 bits at a time */ | ||
201 | -- | 64 | -- |
202 | 2.20.1 | 65 | 2.20.1 |
203 | 66 | ||
204 | 67 | diff view generated by jsdifflib |
1 | We already have gvec helpers for floating point VRECPE and | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | VRQSRTE, so convert the Neon decoder to use them and | 2 | |
3 | add the fp16 support. | 3 | Remove usage of TypeInfo::class_data. Instead fill the fields in |
4 | 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 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20200828183354.27913-25-peter.maydell@linaro.org | ||
8 | --- | 14 | --- |
9 | target/arm/translate-neon.c.inc | 31 +++++++++++++++++++++++++++++-- | 15 | hw/arm/bcm2836.c | 108 ++++++++++++++++++++++------------------------- |
10 | 1 file changed, 29 insertions(+), 2 deletions(-) | 16 | 1 file changed, 51 insertions(+), 57 deletions(-) |
11 | 17 | ||
12 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | 18 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
13 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/translate-neon.c.inc | 20 | --- a/hw/arm/bcm2836.c |
15 | +++ b/target/arm/translate-neon.c.inc | 21 | +++ b/hw/arm/bcm2836.c |
16 | @@ -XXX,XX +XXX,XX @@ static bool do_2misc_fp(DisasContext *s, arg_2misc *a, | 22 | @@ -XXX,XX +XXX,XX @@ |
17 | return do_2misc_fp(s, a, FUNC); \ | 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); | ||
18 | } | 79 | } |
19 | 80 | ||
20 | -DO_2MISC_FP(VRECPE_F, gen_helper_recpe_f32) | 81 | object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL); |
21 | -DO_2MISC_FP(VRSQRTE_F, gen_helper_rsqrte_f32) | 82 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) |
22 | DO_2MISC_FP(VCVT_FS, gen_helper_vfp_sitos) | 83 | { |
23 | DO_2MISC_FP(VCVT_FU, gen_helper_vfp_uitos) | 84 | BCM283XState *s = BCM283X(dev); |
24 | DO_2MISC_FP(VCVT_SF, gen_helper_vfp_tosizs) | 85 | BCM283XClass *bc = BCM283X_GET_CLASS(dev); |
25 | DO_2MISC_FP(VCVT_UF, gen_helper_vfp_touizs) | 86 | - const BCM283XInfo *info = bc->info; |
26 | 87 | Object *obj; | |
27 | +#define DO_2MISC_FP_VEC(INSN, HFUNC, SFUNC) \ | 88 | int n; |
28 | + static void gen_##INSN(unsigned vece, uint32_t rd_ofs, \ | 89 | |
29 | + uint32_t rm_ofs, \ | 90 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) |
30 | + uint32_t oprsz, uint32_t maxsz) \ | 91 | "sd-bus"); |
31 | + { \ | 92 | |
32 | + static gen_helper_gvec_2_ptr * const fns[4] = { \ | 93 | sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0, |
33 | + NULL, HFUNC, SFUNC, NULL, \ | 94 | - info->peri_base, 1); |
34 | + }; \ | 95 | + bc->peri_base, 1); |
35 | + TCGv_ptr fpst; \ | 96 | |
36 | + fpst = fpstatus_ptr(vece == MO_16 ? FPST_STD_F16 : FPST_STD); \ | 97 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ |
37 | + tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, oprsz, maxsz, 0, \ | 98 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) { |
38 | + fns[vece]); \ | 99 | return; |
39 | + tcg_temp_free_ptr(fpst); \ | 100 | } |
40 | + } \ | 101 | |
41 | + static bool trans_##INSN(DisasContext *s, arg_2misc *a) \ | 102 | - sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, info->ctrl_base); |
42 | + { \ | 103 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->control), 0, bc->ctrl_base); |
43 | + if (a->size == MO_16) { \ | 104 | |
44 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { \ | 105 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0, |
45 | + return false; \ | 106 | qdev_get_gpio_in_named(DEVICE(&s->control), "gpu-irq", 0)); |
46 | + } \ | 107 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) |
47 | + } else if (a->size != MO_32) { \ | 108 | |
48 | + return false; \ | 109 | for (n = 0; n < BCM283X_NCPUS; n++) { |
49 | + } \ | 110 | /* TODO: this should be converted to a property of ARM_CPU */ |
50 | + return do_2misc_vec(s, a, gen_##INSN); \ | 111 | - s->cpu[n].core.mp_affinity = (info->clusterid << 8) | n; |
51 | + } | 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); | ||
52 | + | 145 | + |
53 | +DO_2MISC_FP_VEC(VRECPE_F, gen_helper_gvec_frecpe_h, gen_helper_gvec_frecpe_s) | 146 | + bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"); |
54 | +DO_2MISC_FP_VEC(VRSQRTE_F, gen_helper_gvec_frsqrte_h, gen_helper_gvec_frsqrte_s) | 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 | ||
55 | + | 179 | + |
56 | static bool trans_VRINTX(DisasContext *s, arg_2misc *a) | 180 | +static const TypeInfo bcm283x_types[] = { |
57 | { | 181 | + { |
58 | if (!arm_dc_feature(s, ARM_FEATURE_V8)) { | 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) | ||
59 | -- | 205 | -- |
60 | 2.20.1 | 206 | 2.20.1 |
61 | 207 | ||
62 | 208 | diff view generated by jsdifflib |
1 | Convert the Neon floating-point VMLA and VMLS insns over to using a | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | gvec helper, and use this to implement the fp16 case. | ||
3 | 2 | ||
3 | The BCM2835 has only one core. Introduce the core_count field to | ||
4 | be able to use values different than BCM283X_NCPUS (4). | ||
5 | |||
6 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
7 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20201024170127.3592182-4-f4bug@amsat.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-31-peter.maydell@linaro.org | ||
7 | --- | 10 | --- |
8 | target/arm/helper.h | 6 +++++ | 11 | hw/arm/bcm2836.c | 5 ++++- |
9 | target/arm/vec_helper.c | 42 +++++++++++++++++++++++++++++++++ | 12 | 1 file changed, 4 insertions(+), 1 deletion(-) |
10 | target/arm/translate-neon.c.inc | 33 ++------------------------ | ||
11 | 3 files changed, 50 insertions(+), 31 deletions(-) | ||
12 | 13 | ||
13 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 14 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.h | 16 | --- a/hw/arm/bcm2836.c |
16 | +++ b/target/arm/helper.h | 17 | +++ b/hw/arm/bcm2836.c |
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fmaxnum_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i3 | 18 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass { |
18 | DEF_HELPER_FLAGS_5(gvec_fminnum_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 19 | /*< public >*/ |
19 | DEF_HELPER_FLAGS_5(gvec_fminnum_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 20 | const char *name; |
20 | 21 | const char *cpu_type; | |
21 | +DEF_HELPER_FLAGS_5(gvec_fmla_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 22 | + unsigned core_count; |
22 | +DEF_HELPER_FLAGS_5(gvec_fmla_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 23 | hwaddr peri_base; /* Peripheral base address seen by the CPU */ |
23 | + | 24 | hwaddr ctrl_base; /* Interrupt controller and mailboxes etc. */ |
24 | +DEF_HELPER_FLAGS_5(gvec_fmls_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 25 | int clusterid; |
25 | +DEF_HELPER_FLAGS_5(gvec_fmls_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 26 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) |
26 | + | 27 | BCM283XClass *bc = BCM283X_GET_CLASS(obj); |
27 | DEF_HELPER_FLAGS_5(gvec_ftsmul_h, TCG_CALL_NO_RWG, | 28 | int n; |
28 | void, ptr, ptr, ptr, ptr, i32) | 29 | |
29 | DEF_HELPER_FLAGS_5(gvec_ftsmul_s, TCG_CALL_NO_RWG, | 30 | - for (n = 0; n < BCM283X_NCPUS; n++) { |
30 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 31 | + for (n = 0; n < bc->core_count; n++) { |
31 | index XXXXXXX..XXXXXXX 100644 | 32 | object_initialize_child(obj, "cpu[*]", &s->cpu[n].core, |
32 | --- a/target/arm/vec_helper.c | 33 | bc->cpu_type); |
33 | +++ b/target/arm/vec_helper.c | 34 | } |
34 | @@ -XXX,XX +XXX,XX @@ DO_3OP(gvec_rsqrts_d, helper_rsqrtsf_f64, float64) | 35 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data) |
35 | #endif | 36 | BCM283XClass *bc = BCM283X_CLASS(oc); |
36 | #undef DO_3OP | 37 | |
37 | 38 | bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a7"); | |
38 | +/* Non-fused multiply-add (unlike float16_muladd etc, which are fused) */ | 39 | + bc->core_count = BCM283X_NCPUS; |
39 | +static float16 float16_muladd_nf(float16 dest, float16 op1, float16 op2, | 40 | bc->peri_base = 0x3f000000; |
40 | + float_status *stat) | 41 | bc->ctrl_base = 0x40000000; |
41 | +{ | 42 | bc->clusterid = 0xf; |
42 | + return float16_add(dest, float16_mul(op1, op2, stat), stat); | 43 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) |
43 | +} | 44 | BCM283XClass *bc = BCM283X_CLASS(oc); |
44 | + | 45 | |
45 | +static float32 float32_muladd_nf(float32 dest, float32 op1, float32 op2, | 46 | bc->cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"); |
46 | + float_status *stat) | 47 | + bc->core_count = BCM283X_NCPUS; |
47 | +{ | 48 | bc->peri_base = 0x3f000000; |
48 | + return float32_add(dest, float32_mul(op1, op2, stat), stat); | 49 | bc->ctrl_base = 0x40000000; |
49 | +} | 50 | bc->clusterid = 0x0; |
50 | + | ||
51 | +static float16 float16_mulsub_nf(float16 dest, float16 op1, float16 op2, | ||
52 | + float_status *stat) | ||
53 | +{ | ||
54 | + return float16_sub(dest, float16_mul(op1, op2, stat), stat); | ||
55 | +} | ||
56 | + | ||
57 | +static float32 float32_mulsub_nf(float32 dest, float32 op1, float32 op2, | ||
58 | + float_status *stat) | ||
59 | +{ | ||
60 | + return float32_sub(dest, float32_mul(op1, op2, stat), stat); | ||
61 | +} | ||
62 | + | ||
63 | +#define DO_MULADD(NAME, FUNC, TYPE) \ | ||
64 | +void HELPER(NAME)(void *vd, void *vn, void *vm, void *stat, uint32_t desc) \ | ||
65 | +{ \ | ||
66 | + intptr_t i, oprsz = simd_oprsz(desc); \ | ||
67 | + TYPE *d = vd, *n = vn, *m = vm; \ | ||
68 | + for (i = 0; i < oprsz / sizeof(TYPE); i++) { \ | ||
69 | + d[i] = FUNC(d[i], n[i], m[i], stat); \ | ||
70 | + } \ | ||
71 | + clear_tail(d, oprsz, simd_maxsz(desc)); \ | ||
72 | +} | ||
73 | + | ||
74 | +DO_MULADD(gvec_fmla_h, float16_muladd_nf, float16) | ||
75 | +DO_MULADD(gvec_fmla_s, float32_muladd_nf, float32) | ||
76 | + | ||
77 | +DO_MULADD(gvec_fmls_h, float16_mulsub_nf, float16) | ||
78 | +DO_MULADD(gvec_fmls_s, float32_mulsub_nf, float32) | ||
79 | + | ||
80 | /* For the indexed ops, SVE applies the index per 128-bit vector segment. | ||
81 | * For AdvSIMD, there is of course only one such vector segment. | ||
82 | */ | ||
83 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/target/arm/translate-neon.c.inc | ||
86 | +++ b/target/arm/translate-neon.c.inc | ||
87 | @@ -XXX,XX +XXX,XX @@ DO_3S_FP_GVEC(VACGE, gen_helper_gvec_facge_s, gen_helper_gvec_facge_h) | ||
88 | DO_3S_FP_GVEC(VACGT, gen_helper_gvec_facgt_s, gen_helper_gvec_facgt_h) | ||
89 | DO_3S_FP_GVEC(VMAX, gen_helper_gvec_fmax_s, gen_helper_gvec_fmax_h) | ||
90 | DO_3S_FP_GVEC(VMIN, gen_helper_gvec_fmin_s, gen_helper_gvec_fmin_h) | ||
91 | - | ||
92 | -/* | ||
93 | - * For all the functions using this macro, size == 1 means fp16, | ||
94 | - * which is an architecture extension we don't implement yet. | ||
95 | - */ | ||
96 | -#define DO_3S_FP(INSN,FUNC,READS_VD) \ | ||
97 | - static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \ | ||
98 | - { \ | ||
99 | - if (a->size != 0) { \ | ||
100 | - /* TODO fp16 support */ \ | ||
101 | - return false; \ | ||
102 | - } \ | ||
103 | - return do_3same_fp(s, a, FUNC, READS_VD); \ | ||
104 | - } | ||
105 | - | ||
106 | -static void gen_VMLA_fp_3s(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, | ||
107 | - TCGv_ptr fpstatus) | ||
108 | -{ | ||
109 | - gen_helper_vfp_muls(vn, vn, vm, fpstatus); | ||
110 | - gen_helper_vfp_adds(vd, vd, vn, fpstatus); | ||
111 | -} | ||
112 | - | ||
113 | -static void gen_VMLS_fp_3s(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, | ||
114 | - TCGv_ptr fpstatus) | ||
115 | -{ | ||
116 | - gen_helper_vfp_muls(vn, vn, vm, fpstatus); | ||
117 | - gen_helper_vfp_subs(vd, vd, vn, fpstatus); | ||
118 | -} | ||
119 | - | ||
120 | -DO_3S_FP(VMLA, gen_VMLA_fp_3s, true) | ||
121 | -DO_3S_FP(VMLS, gen_VMLS_fp_3s, true) | ||
122 | +DO_3S_FP_GVEC(VMLA, gen_helper_gvec_fmla_s, gen_helper_gvec_fmla_h) | ||
123 | +DO_3S_FP_GVEC(VMLS, gen_helper_gvec_fmls_s, gen_helper_gvec_fmls_h) | ||
124 | |||
125 | WRAP_FP_GVEC(gen_VMAXNM_fp32_3s, FPST_STD, gen_helper_gvec_fmaxnum_s) | ||
126 | WRAP_FP_GVEC(gen_VMAXNM_fp16_3s, FPST_STD_F16, gen_helper_gvec_fmaxnum_h) | ||
127 | -- | 51 | -- |
128 | 2.20.1 | 52 | 2.20.1 |
129 | 53 | ||
130 | 54 | diff view generated by jsdifflib |
1 | Implement FP16 support for the Neon insns which use the DO_3S_FP_GVEC | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | macro: VADD, VSUB, VABD, VMUL. | ||
3 | 2 | ||
4 | For VABD this requires us to implement a new gvec_fabd_h helper | 3 | It makes no sense to set enabled-cpus=0 on single core SoCs. |
5 | using the machinery we have already for the other helpers. | ||
6 | 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 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20200828183354.27913-24-peter.maydell@linaro.org | ||
10 | --- | 9 | --- |
11 | target/arm/helper.h | 1 + | 10 | hw/arm/bcm2836.c | 15 +++++++-------- |
12 | target/arm/vec_helper.c | 6 ++++++ | 11 | 1 file changed, 7 insertions(+), 8 deletions(-) |
13 | target/arm/translate-neon.c.inc | 36 +++++++++++++++++---------------- | ||
14 | 3 files changed, 26 insertions(+), 17 deletions(-) | ||
15 | 12 | ||
16 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 13 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
17 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/helper.h | 15 | --- a/hw/arm/bcm2836.c |
19 | +++ b/target/arm/helper.h | 16 | +++ b/hw/arm/bcm2836.c |
20 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fmul_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 17 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM283XClass { |
21 | DEF_HELPER_FLAGS_5(gvec_fmul_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 18 | #define BCM283X_GET_CLASS(obj) \ |
22 | DEF_HELPER_FLAGS_5(gvec_fmul_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 19 | OBJECT_GET_CLASS(BCM283XClass, (obj), TYPE_BCM283X) |
23 | 20 | ||
24 | +DEF_HELPER_FLAGS_5(gvec_fabd_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 21 | +static Property bcm2836_enabled_cores_property = |
25 | DEF_HELPER_FLAGS_5(gvec_fabd_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 22 | + DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, 0); |
26 | 23 | + | |
27 | DEF_HELPER_FLAGS_5(gvec_ftsmul_h, TCG_CALL_NO_RWG, | 24 | static void bcm2836_init(Object *obj) |
28 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 25 | { |
29 | index XXXXXXX..XXXXXXX 100644 | 26 | BCM283XState *s = BCM283X(obj); |
30 | --- a/target/arm/vec_helper.c | 27 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) |
31 | +++ b/target/arm/vec_helper.c | 28 | object_initialize_child(obj, "cpu[*]", &s->cpu[n].core, |
32 | @@ -XXX,XX +XXX,XX @@ static float64 float64_ftsmul(float64 op1, uint64_t op2, float_status *stat) | 29 | bc->cpu_type); |
33 | return result; | 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 | } | ||
34 | } | 40 | } |
35 | 41 | ||
36 | +static float16 float16_abd(float16 op1, float16 op2, float_status *stat) | 42 | -static Property bcm2836_props[] = { |
37 | +{ | 43 | - DEFINE_PROP_UINT32("enabled-cpus", BCM283XState, enabled_cpus, |
38 | + return float16_abs(float16_sub(op1, op2, stat)); | 44 | - BCM283X_NCPUS), |
39 | +} | 45 | - DEFINE_PROP_END_OF_LIST() |
40 | + | 46 | -}; |
41 | static float32 float32_abd(float32 op1, float32 op2, float_status *stat) | 47 | - |
48 | static void bcm283x_class_init(ObjectClass *oc, void *data) | ||
42 | { | 49 | { |
43 | return float32_abs(float32_sub(op1, op2, stat)); | 50 | DeviceClass *dc = DEVICE_CLASS(oc); |
44 | @@ -XXX,XX +XXX,XX @@ DO_3OP(gvec_ftsmul_h, float16_ftsmul, float16) | 51 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_class_init(ObjectClass *oc, void *data) |
45 | DO_3OP(gvec_ftsmul_s, float32_ftsmul, float32) | 52 | bc->ctrl_base = 0x40000000; |
46 | DO_3OP(gvec_ftsmul_d, float64_ftsmul, float64) | 53 | bc->clusterid = 0xf; |
47 | 54 | dc->realize = bcm2836_realize; | |
48 | +DO_3OP(gvec_fabd_h, float16_abd, float16) | 55 | - device_class_set_props(dc, bcm2836_props); |
49 | DO_3OP(gvec_fabd_s, float32_abd, float32) | 56 | }; |
50 | 57 | ||
51 | #ifdef TARGET_AARCH64 | 58 | #ifdef TARGET_AARCH64 |
52 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | 59 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) |
53 | index XXXXXXX..XXXXXXX 100644 | 60 | bc->ctrl_base = 0x40000000; |
54 | --- a/target/arm/translate-neon.c.inc | 61 | bc->clusterid = 0x0; |
55 | +++ b/target/arm/translate-neon.c.inc | 62 | dc->realize = bcm2836_realize; |
56 | @@ -XXX,XX +XXX,XX @@ static bool do_3same_fp(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn, | 63 | - device_class_set_props(dc, bcm2836_props); |
57 | return true; | 64 | }; |
58 | } | 65 | #endif |
59 | 66 | ||
60 | -/* | ||
61 | - * For all the functions using this macro, size == 1 means fp16, | ||
62 | - * which is an architecture extension we don't implement yet. | ||
63 | - */ | ||
64 | -#define DO_3S_FP_GVEC(INSN,FUNC) \ | ||
65 | - static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \ | ||
66 | - uint32_t rn_ofs, uint32_t rm_ofs, \ | ||
67 | - uint32_t oprsz, uint32_t maxsz) \ | ||
68 | +#define WRAP_FP_GVEC(WRAPNAME, FPST, FUNC) \ | ||
69 | + static void WRAPNAME(unsigned vece, uint32_t rd_ofs, \ | ||
70 | + uint32_t rn_ofs, uint32_t rm_ofs, \ | ||
71 | + uint32_t oprsz, uint32_t maxsz) \ | ||
72 | { \ | ||
73 | - TCGv_ptr fpst = fpstatus_ptr(FPST_STD); \ | ||
74 | + TCGv_ptr fpst = fpstatus_ptr(FPST); \ | ||
75 | tcg_gen_gvec_3_ptr(rd_ofs, rn_ofs, rm_ofs, fpst, \ | ||
76 | oprsz, maxsz, 0, FUNC); \ | ||
77 | tcg_temp_free_ptr(fpst); \ | ||
78 | - } \ | ||
79 | + } | ||
80 | + | ||
81 | +#define DO_3S_FP_GVEC(INSN,SFUNC,HFUNC) \ | ||
82 | + WRAP_FP_GVEC(gen_##INSN##_fp32_3s, FPST_STD, SFUNC) \ | ||
83 | + WRAP_FP_GVEC(gen_##INSN##_fp16_3s, FPST_STD_F16, HFUNC) \ | ||
84 | static bool trans_##INSN##_fp_3s(DisasContext *s, arg_3same *a) \ | ||
85 | { \ | ||
86 | if (a->size != 0) { \ | ||
87 | - /* TODO fp16 support */ \ | ||
88 | - return false; \ | ||
89 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { \ | ||
90 | + return false; \ | ||
91 | + } \ | ||
92 | + return do_3same(s, a, gen_##INSN##_fp16_3s); \ | ||
93 | } \ | ||
94 | - return do_3same(s, a, gen_##INSN##_3s); \ | ||
95 | + return do_3same(s, a, gen_##INSN##_fp32_3s); \ | ||
96 | } | ||
97 | |||
98 | |||
99 | -DO_3S_FP_GVEC(VADD, gen_helper_gvec_fadd_s) | ||
100 | -DO_3S_FP_GVEC(VSUB, gen_helper_gvec_fsub_s) | ||
101 | -DO_3S_FP_GVEC(VABD, gen_helper_gvec_fabd_s) | ||
102 | -DO_3S_FP_GVEC(VMUL, gen_helper_gvec_fmul_s) | ||
103 | +DO_3S_FP_GVEC(VADD, gen_helper_gvec_fadd_s, gen_helper_gvec_fadd_h) | ||
104 | +DO_3S_FP_GVEC(VSUB, gen_helper_gvec_fsub_s, gen_helper_gvec_fsub_h) | ||
105 | +DO_3S_FP_GVEC(VABD, gen_helper_gvec_fabd_s, gen_helper_gvec_fabd_h) | ||
106 | +DO_3S_FP_GVEC(VMUL, gen_helper_gvec_fmul_s, gen_helper_gvec_fmul_h) | ||
107 | |||
108 | /* | ||
109 | * For all the functions using this macro, size == 1 means fp16, | ||
110 | -- | 67 | -- |
111 | 2.20.1 | 68 | 2.20.1 |
112 | 69 | ||
113 | 70 | diff view generated by jsdifflib |
1 | Convert the Neon floating-point VMUL, VMLA and VMLS to use gvec, | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | and use this to implement fp16 support. | ||
3 | 2 | ||
3 | The realize() function is clearly composed of two parts, | ||
4 | each described by a comment: | ||
5 | |||
6 | void realize() | ||
7 | { | ||
8 | /* common peripherals from bcm2835 */ | ||
9 | ... | ||
10 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ | ||
11 | ... | ||
12 | } | ||
13 | |||
14 | Split the two part, so we can reuse the common part with other | ||
15 | SoCs from this family. | ||
16 | |||
17 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
18 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Message-id: 20201024170127.3592182-6-f4bug@amsat.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-45-peter.maydell@linaro.org | ||
7 | --- | 21 | --- |
8 | target/arm/translate-neon.c.inc | 114 ++++++++++++++++---------------- | 22 | hw/arm/bcm2836.c | 22 ++++++++++++++++++---- |
9 | 1 file changed, 57 insertions(+), 57 deletions(-) | 23 | 1 file changed, 18 insertions(+), 4 deletions(-) |
10 | 24 | ||
11 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | 25 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
12 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate-neon.c.inc | 27 | --- a/hw/arm/bcm2836.c |
14 | +++ b/target/arm/translate-neon.c.inc | 28 | +++ b/hw/arm/bcm2836.c |
15 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMLS_2sc(DisasContext *s, arg_2scalar *a) | 29 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) |
16 | return do_2scalar(s, a, opfn[a->size], accfn[a->size]); | 30 | qdev_prop_set_uint32(DEVICE(obj), "enabled-cpus", bc->core_count); |
31 | } | ||
32 | |||
33 | - object_initialize_child(obj, "control", &s->control, TYPE_BCM2836_CONTROL); | ||
34 | + if (bc->ctrl_base) { | ||
35 | + object_initialize_child(obj, "control", &s->control, | ||
36 | + TYPE_BCM2836_CONTROL); | ||
37 | + } | ||
38 | |||
39 | object_initialize_child(obj, "peripherals", &s->peripherals, | ||
40 | TYPE_BCM2835_PERIPHERALS); | ||
41 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_init(Object *obj) | ||
42 | "vcram-size"); | ||
17 | } | 43 | } |
18 | 44 | ||
19 | -/* | 45 | -static void bcm2836_realize(DeviceState *dev, Error **errp) |
20 | - * Rather than have a float-specific version of do_2scalar just for | 46 | +static bool bcm283x_common_realize(DeviceState *dev, Error **errp) |
21 | - * three insns, we wrap a NeonGenTwoSingleOpFn to turn it into | 47 | { |
22 | - * a NeonGenTwoOpFn. | 48 | BCM283XState *s = BCM283X(dev); |
23 | - */ | 49 | BCM283XClass *bc = BCM283X_GET_CLASS(dev); |
24 | -#define WRAP_FP_FN(WRAPNAME, FUNC) \ | 50 | Object *obj; |
25 | - static void WRAPNAME(TCGv_i32 rd, TCGv_i32 rn, TCGv_i32 rm) \ | 51 | - int n; |
26 | - { \ | 52 | |
27 | - TCGv_ptr fpstatus = fpstatus_ptr(FPST_STD); \ | 53 | /* common peripherals from bcm2835 */ |
28 | - FUNC(rd, rn, rm, fpstatus); \ | 54 | |
29 | - tcg_temp_free_ptr(fpstatus); \ | 55 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) |
30 | +static bool do_2scalar_fp_vec(DisasContext *s, arg_2scalar *a, | 56 | object_property_add_const_link(OBJECT(&s->peripherals), "ram", obj); |
31 | + gen_helper_gvec_3_ptr *fn) | 57 | |
32 | +{ | 58 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->peripherals), errp)) { |
33 | + /* Two registers and a scalar, using gvec */ | 59 | - return; |
34 | + int vec_size = a->q ? 16 : 8; | ||
35 | + int rd_ofs = neon_reg_offset(a->vd, 0); | ||
36 | + int rn_ofs = neon_reg_offset(a->vn, 0); | ||
37 | + int rm_ofs; | ||
38 | + int idx; | ||
39 | + TCGv_ptr fpstatus; | ||
40 | + | ||
41 | + if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | ||
42 | + return false; | 60 | + return false; |
43 | } | 61 | } |
44 | 62 | ||
45 | -WRAP_FP_FN(gen_VMUL_F_mul, gen_helper_vfp_muls) | 63 | object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->peripherals), |
46 | -WRAP_FP_FN(gen_VMUL_F_add, gen_helper_vfp_adds) | 64 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) |
47 | -WRAP_FP_FN(gen_VMUL_F_sub, gen_helper_vfp_subs) | 65 | |
48 | + /* UNDEF accesses to D16-D31 if they don't exist. */ | 66 | sysbus_mmio_map_overlap(SYS_BUS_DEVICE(&s->peripherals), 0, |
49 | + if (!dc_isar_feature(aa32_simd_r32, s) && | 67 | bc->peri_base, 1); |
50 | + ((a->vd | a->vn | a->vm) & 0x10)) { | 68 | + return true; |
51 | + return false; | 69 | +} |
70 | + | ||
71 | +static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
72 | +{ | ||
73 | + BCM283XState *s = BCM283X(dev); | ||
74 | + BCM283XClass *bc = BCM283X_GET_CLASS(dev); | ||
75 | + int n; | ||
76 | + | ||
77 | + if (!bcm283x_common_realize(dev, errp)) { | ||
78 | + return; | ||
52 | + } | 79 | + } |
53 | 80 | ||
54 | -static bool trans_VMUL_F_2sc(DisasContext *s, arg_2scalar *a) | 81 | /* bcm2836 interrupt controller (and mailboxes, etc.) */ |
55 | -{ | 82 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->control), errp)) { |
56 | - static NeonGenTwoOpFn * const opfn[] = { | ||
57 | - NULL, | ||
58 | - NULL, /* TODO: fp16 support */ | ||
59 | - gen_VMUL_F_mul, | ||
60 | - NULL, | ||
61 | - }; | ||
62 | + if (!fn) { | ||
63 | + /* Bad size (including size == 3, which is a different insn group) */ | ||
64 | + return false; | ||
65 | + } | ||
66 | |||
67 | - return do_2scalar(s, a, opfn[a->size], NULL); | ||
68 | + if (a->q && ((a->vd | a->vn) & 1)) { | ||
69 | + return false; | ||
70 | + } | ||
71 | + | ||
72 | + if (!vfp_access_check(s)) { | ||
73 | + return true; | ||
74 | + } | ||
75 | + | ||
76 | + /* a->vm is M:Vm, which encodes both register and index */ | ||
77 | + idx = extract32(a->vm, a->size + 2, 2); | ||
78 | + a->vm = extract32(a->vm, 0, a->size + 2); | ||
79 | + rm_ofs = neon_reg_offset(a->vm, 0); | ||
80 | + | ||
81 | + fpstatus = fpstatus_ptr(a->size == 1 ? FPST_STD_F16 : FPST_STD); | ||
82 | + tcg_gen_gvec_3_ptr(rd_ofs, rn_ofs, rm_ofs, fpstatus, | ||
83 | + vec_size, vec_size, idx, fn); | ||
84 | + tcg_temp_free_ptr(fpstatus); | ||
85 | + return true; | ||
86 | } | ||
87 | |||
88 | -static bool trans_VMLA_F_2sc(DisasContext *s, arg_2scalar *a) | ||
89 | -{ | ||
90 | - static NeonGenTwoOpFn * const opfn[] = { | ||
91 | - NULL, | ||
92 | - NULL, /* TODO: fp16 support */ | ||
93 | - gen_VMUL_F_mul, | ||
94 | - NULL, | ||
95 | - }; | ||
96 | - static NeonGenTwoOpFn * const accfn[] = { | ||
97 | - NULL, | ||
98 | - NULL, /* TODO: fp16 support */ | ||
99 | - gen_VMUL_F_add, | ||
100 | - NULL, | ||
101 | - }; | ||
102 | +#define DO_VMUL_F_2sc(NAME, FUNC) \ | ||
103 | + static bool trans_##NAME##_F_2sc(DisasContext *s, arg_2scalar *a) \ | ||
104 | + { \ | ||
105 | + static gen_helper_gvec_3_ptr * const opfn[] = { \ | ||
106 | + NULL, \ | ||
107 | + gen_helper_##FUNC##_h, \ | ||
108 | + gen_helper_##FUNC##_s, \ | ||
109 | + NULL, \ | ||
110 | + }; \ | ||
111 | + if (a->size == MO_16 && !dc_isar_feature(aa32_fp16_arith, s)) { \ | ||
112 | + return false; \ | ||
113 | + } \ | ||
114 | + return do_2scalar_fp_vec(s, a, opfn[a->size]); \ | ||
115 | + } | ||
116 | |||
117 | - return do_2scalar(s, a, opfn[a->size], accfn[a->size]); | ||
118 | -} | ||
119 | - | ||
120 | -static bool trans_VMLS_F_2sc(DisasContext *s, arg_2scalar *a) | ||
121 | -{ | ||
122 | - static NeonGenTwoOpFn * const opfn[] = { | ||
123 | - NULL, | ||
124 | - NULL, /* TODO: fp16 support */ | ||
125 | - gen_VMUL_F_mul, | ||
126 | - NULL, | ||
127 | - }; | ||
128 | - static NeonGenTwoOpFn * const accfn[] = { | ||
129 | - NULL, | ||
130 | - NULL, /* TODO: fp16 support */ | ||
131 | - gen_VMUL_F_sub, | ||
132 | - NULL, | ||
133 | - }; | ||
134 | - | ||
135 | - return do_2scalar(s, a, opfn[a->size], accfn[a->size]); | ||
136 | -} | ||
137 | +DO_VMUL_F_2sc(VMUL, gvec_fmul_idx) | ||
138 | +DO_VMUL_F_2sc(VMLA, gvec_fmla_nf_idx) | ||
139 | +DO_VMUL_F_2sc(VMLS, gvec_fmls_nf_idx) | ||
140 | |||
141 | WRAP_ENV_FN(gen_VQDMULH_16, gen_helper_neon_qdmulh_s16) | ||
142 | WRAP_ENV_FN(gen_VQDMULH_32, gen_helper_neon_qdmulh_s32) | ||
143 | -- | 83 | -- |
144 | 2.20.1 | 84 | 2.20.1 |
145 | 85 | ||
146 | 86 | diff view generated by jsdifflib |
1 | Implement the fp16 versions of the VFP VCVT instruction forms which | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | convert between floating point and integer. | ||
3 | 2 | ||
3 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
4 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
5 | Message-id: 20201024170127.3592182-7-f4bug@amsat.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-13-peter.maydell@linaro.org | ||
7 | --- | 7 | --- |
8 | target/arm/vfp.decode | 4 +++ | 8 | include/hw/arm/bcm2836.h | 1 + |
9 | target/arm/translate-vfp.c.inc | 65 ++++++++++++++++++++++++++++++++++ | 9 | hw/arm/bcm2836.c | 34 ++++++++++++++++++++++++++++++++++ |
10 | 2 files changed, 69 insertions(+) | 10 | hw/arm/raspi.c | 2 ++ |
11 | 3 files changed, 37 insertions(+) | ||
11 | 12 | ||
12 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | 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/vfp.decode | 15 | --- a/include/hw/arm/bcm2836.h |
15 | +++ b/target/arm/vfp.decode | 16 | +++ b/include/hw/arm/bcm2836.h |
16 | @@ -XXX,XX +XXX,XX @@ VCVT_sp ---- 1110 1.11 0111 .... 1010 11.0 .... @vfp_dm_ds | 17 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(BCM283XState, BCM283XClass, BCM283X) |
17 | VCVT_dp ---- 1110 1.11 0111 .... 1011 11.0 .... @vfp_dm_sd | 18 | * them, code using these devices should always handle them via the |
18 | 19 | * BCM283x base class, so they have no BCM2836(obj) etc macros. | |
19 | # VCVT from integer to floating point: Vm always single; Vd depends on size | 20 | */ |
20 | +VCVT_int_hp ---- 1110 1.11 1000 .... 1001 s:1 1.0 .... \ | 21 | +#define TYPE_BCM2835 "bcm2835" |
21 | + vd=%vd_sp vm=%vm_sp | 22 | #define TYPE_BCM2836 "bcm2836" |
22 | VCVT_int_sp ---- 1110 1.11 1000 .... 1010 s:1 1.0 .... \ | 23 | #define TYPE_BCM2837 "bcm2837" |
23 | vd=%vd_sp vm=%vm_sp | 24 | |
24 | VCVT_int_dp ---- 1110 1.11 1000 .... 1011 s:1 1.0 .... \ | 25 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c |
25 | @@ -XXX,XX +XXX,XX @@ VCVT_fix_dp ---- 1110 1.11 1.1. .... 1011 .1.0 .... \ | ||
26 | vd=%vd_dp imm=%vm_sp opc=%vcvt_fix_op | ||
27 | |||
28 | # VCVT float to integer (VCVT and VCVTR): Vd always single; Vd depends on size | ||
29 | +VCVT_hp_int ---- 1110 1.11 110 s:1 .... 1001 rz:1 1.0 .... \ | ||
30 | + vd=%vd_sp vm=%vm_sp | ||
31 | VCVT_sp_int ---- 1110 1.11 110 s:1 .... 1010 rz:1 1.0 .... \ | ||
32 | vd=%vd_sp vm=%vm_sp | ||
33 | VCVT_dp_int ---- 1110 1.11 110 s:1 .... 1011 rz:1 1.0 .... \ | ||
34 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | ||
35 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/target/arm/translate-vfp.c.inc | 27 | --- a/hw/arm/bcm2836.c |
37 | +++ b/target/arm/translate-vfp.c.inc | 28 | +++ b/hw/arm/bcm2836.c |
38 | @@ -XXX,XX +XXX,XX @@ static bool trans_VCVT_dp(DisasContext *s, arg_VCVT_dp *a) | 29 | @@ -XXX,XX +XXX,XX @@ static bool bcm283x_common_realize(DeviceState *dev, Error **errp) |
39 | return true; | 30 | return true; |
40 | } | 31 | } |
41 | 32 | ||
42 | +static bool trans_VCVT_int_hp(DisasContext *s, arg_VCVT_int_sp *a) | 33 | +static void bcm2835_realize(DeviceState *dev, Error **errp) |
43 | +{ | 34 | +{ |
44 | + TCGv_i32 vm; | 35 | + BCM283XState *s = BCM283X(dev); |
45 | + TCGv_ptr fpst; | ||
46 | + | 36 | + |
47 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 37 | + if (!bcm283x_common_realize(dev, errp)) { |
48 | + return false; | 38 | + return; |
49 | + } | 39 | + } |
50 | + | 40 | + |
51 | + if (!vfp_access_check(s)) { | 41 | + if (!qdev_realize(DEVICE(&s->cpu[0].core), NULL, errp)) { |
52 | + return true; | 42 | + return; |
53 | + } | 43 | + } |
54 | + | 44 | + |
55 | + vm = tcg_temp_new_i32(); | 45 | + /* Connect irq/fiq outputs from the interrupt controller. */ |
56 | + neon_load_reg32(vm, a->vm); | 46 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 0, |
57 | + fpst = fpstatus_ptr(FPST_FPCR_F16); | 47 | + qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_IRQ)); |
58 | + if (a->s) { | 48 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->peripherals), 1, |
59 | + /* i32 -> f16 */ | 49 | + qdev_get_gpio_in(DEVICE(&s->cpu[0].core), ARM_CPU_FIQ)); |
60 | + gen_helper_vfp_sitoh(vm, vm, fpst); | ||
61 | + } else { | ||
62 | + /* u32 -> f16 */ | ||
63 | + gen_helper_vfp_uitoh(vm, vm, fpst); | ||
64 | + } | ||
65 | + neon_store_reg32(vm, a->vd); | ||
66 | + tcg_temp_free_i32(vm); | ||
67 | + tcg_temp_free_ptr(fpst); | ||
68 | + return true; | ||
69 | +} | 50 | +} |
70 | + | 51 | + |
71 | static bool trans_VCVT_int_sp(DisasContext *s, arg_VCVT_int_sp *a) | 52 | static void bcm2836_realize(DeviceState *dev, Error **errp) |
72 | { | 53 | { |
73 | TCGv_i32 vm; | 54 | BCM283XState *s = BCM283X(dev); |
74 | @@ -XXX,XX +XXX,XX @@ static bool trans_VCVT_fix_dp(DisasContext *s, arg_VCVT_fix_dp *a) | 55 | @@ -XXX,XX +XXX,XX @@ static void bcm283x_class_init(ObjectClass *oc, void *data) |
75 | return true; | 56 | dc->user_creatable = false; |
76 | } | 57 | } |
77 | 58 | ||
78 | +static bool trans_VCVT_hp_int(DisasContext *s, arg_VCVT_sp_int *a) | 59 | +static void bcm2835_class_init(ObjectClass *oc, void *data) |
79 | +{ | 60 | +{ |
80 | + TCGv_i32 vm; | 61 | + DeviceClass *dc = DEVICE_CLASS(oc); |
81 | + TCGv_ptr fpst; | 62 | + BCM283XClass *bc = BCM283X_CLASS(oc); |
82 | + | 63 | + |
83 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 64 | + bc->cpu_type = ARM_CPU_TYPE_NAME("arm1176"); |
84 | + return false; | 65 | + bc->core_count = 1; |
85 | + } | 66 | + bc->peri_base = 0x20000000; |
67 | + dc->realize = bcm2835_realize; | ||
68 | +}; | ||
86 | + | 69 | + |
87 | + if (!vfp_access_check(s)) { | 70 | static void bcm2836_class_init(ObjectClass *oc, void *data) |
88 | + return true; | ||
89 | + } | ||
90 | + | ||
91 | + fpst = fpstatus_ptr(FPST_FPCR_F16); | ||
92 | + vm = tcg_temp_new_i32(); | ||
93 | + neon_load_reg32(vm, a->vm); | ||
94 | + | ||
95 | + if (a->s) { | ||
96 | + if (a->rz) { | ||
97 | + gen_helper_vfp_tosizh(vm, vm, fpst); | ||
98 | + } else { | ||
99 | + gen_helper_vfp_tosih(vm, vm, fpst); | ||
100 | + } | ||
101 | + } else { | ||
102 | + if (a->rz) { | ||
103 | + gen_helper_vfp_touizh(vm, vm, fpst); | ||
104 | + } else { | ||
105 | + gen_helper_vfp_touih(vm, vm, fpst); | ||
106 | + } | ||
107 | + } | ||
108 | + neon_store_reg32(vm, a->vd); | ||
109 | + tcg_temp_free_i32(vm); | ||
110 | + tcg_temp_free_ptr(fpst); | ||
111 | + return true; | ||
112 | +} | ||
113 | + | ||
114 | static bool trans_VCVT_sp_int(DisasContext *s, arg_VCVT_sp_int *a) | ||
115 | { | 71 | { |
116 | TCGv_i32 vm; | 72 | DeviceClass *dc = DEVICE_CLASS(oc); |
73 | @@ -XXX,XX +XXX,XX @@ static void bcm2837_class_init(ObjectClass *oc, void *data) | ||
74 | |||
75 | static const TypeInfo bcm283x_types[] = { | ||
76 | { | ||
77 | + .name = TYPE_BCM2835, | ||
78 | + .parent = TYPE_BCM283X, | ||
79 | + .class_init = bcm2835_class_init, | ||
80 | + }, { | ||
81 | .name = TYPE_BCM2836, | ||
82 | .parent = TYPE_BCM283X, | ||
83 | .class_init = bcm2836_class_init, | ||
84 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
85 | index XXXXXXX..XXXXXXX 100644 | ||
86 | --- a/hw/arm/raspi.c | ||
87 | +++ b/hw/arm/raspi.c | ||
88 | @@ -XXX,XX +XXX,XX @@ FIELD(REV_CODE, MEMORY_SIZE, 20, 3); | ||
89 | FIELD(REV_CODE, STYLE, 23, 1); | ||
90 | |||
91 | typedef enum RaspiProcessorId { | ||
92 | + PROCESSOR_ID_BCM2835 = 0, | ||
93 | PROCESSOR_ID_BCM2836 = 1, | ||
94 | PROCESSOR_ID_BCM2837 = 2, | ||
95 | } RaspiProcessorId; | ||
96 | @@ -XXX,XX +XXX,XX @@ static const struct { | ||
97 | const char *type; | ||
98 | int cores_count; | ||
99 | } soc_property[] = { | ||
100 | + [PROCESSOR_ID_BCM2835] = {TYPE_BCM2835, 1}, | ||
101 | [PROCESSOR_ID_BCM2836] = {TYPE_BCM2836, BCM283X_NCPUS}, | ||
102 | [PROCESSOR_ID_BCM2837] = {TYPE_BCM2837, BCM283X_NCPUS}, | ||
103 | }; | ||
117 | -- | 104 | -- |
118 | 2.20.1 | 105 | 2.20.1 |
119 | 106 | ||
120 | 107 | diff view generated by jsdifflib |
1 | The fp16 extension includes a new instruction VINS, which copies the | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | lower 16 bits of a 32-bit source VFP register into the upper 16 bits | ||
3 | of the destination. Implement it. | ||
4 | 2 | ||
3 | The Pi A is almost the first machine released. | ||
4 | It uses a BCM2835 SoC which includes a ARMv6Z core. | ||
5 | |||
6 | Example booting the machine using content from [*] | ||
7 | (we use the device tree from the B model): | ||
8 | |||
9 | $ qemu-system-arm -M raspi1ap -serial stdio \ | ||
10 | -kernel raspberrypi/firmware/boot/kernel.img \ | ||
11 | -dtb raspberrypi/firmware/boot/bcm2708-rpi-b-plus.dtb \ | ||
12 | -append 'earlycon=pl011,0x20201000 console=ttyAMA0' | ||
13 | [ 0.000000] Booting Linux on physical CPU 0x0 | ||
14 | [ 0.000000] Linux version 4.19.118+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1311 Mon Apr 27 14:16:15 BST 2020 | ||
15 | [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d | ||
16 | [ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache | ||
17 | [ 0.000000] OF: fdt: Machine model: Raspberry Pi Model B+ | ||
18 | ... | ||
19 | |||
20 | [*] http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20200512-2_armhf.deb | ||
21 | |||
22 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | ||
23 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
24 | Message-id: 20201024170127.3592182-8-f4bug@amsat.org | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20200828183354.27913-20-peter.maydell@linaro.org | ||
8 | --- | 26 | --- |
9 | target/arm/vfp-uncond.decode | 3 +++ | 27 | hw/arm/raspi.c | 13 +++++++++++++ |
10 | target/arm/translate-vfp.c.inc | 28 ++++++++++++++++++++++++++++ | 28 | 1 file changed, 13 insertions(+) |
11 | 2 files changed, 31 insertions(+) | ||
12 | 29 | ||
13 | diff --git a/target/arm/vfp-uncond.decode b/target/arm/vfp-uncond.decode | 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/vfp-uncond.decode | 32 | --- a/hw/arm/raspi.c |
16 | +++ b/target/arm/vfp-uncond.decode | 33 | +++ b/hw/arm/raspi.c |
17 | @@ -XXX,XX +XXX,XX @@ VCVT 1111 1110 1.11 11 rm:2 .... 1010 op:1 1.0 .... \ | 34 | @@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc, |
18 | vm=%vm_sp vd=%vd_sp sz=2 | 35 | mc->default_ram_id = "ram"; |
19 | VCVT 1111 1110 1.11 11 rm:2 .... 1011 op:1 1.0 .... \ | 36 | }; |
20 | vm=%vm_dp vd=%vd_sp sz=3 | 37 | |
38 | +static void raspi1ap_machine_class_init(ObjectClass *oc, void *data) | ||
39 | +{ | ||
40 | + MachineClass *mc = MACHINE_CLASS(oc); | ||
41 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); | ||
21 | + | 42 | + |
22 | +VINS 1111 1110 1.11 0000 .... 1010 11 . 0 .... \ | 43 | + rmc->board_rev = 0x900021; /* Revision 1.1 */ |
23 | + vd=%vd_sp vm=%vm_sp | 44 | + raspi_machine_class_common_init(mc, rmc->board_rev); |
24 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 45 | +}; |
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/target/arm/translate-vfp.c.inc | ||
27 | +++ b/target/arm/translate-vfp.c.inc | ||
28 | @@ -XXX,XX +XXX,XX @@ static bool trans_NOCP(DisasContext *s, arg_NOCP *a) | ||
29 | |||
30 | return false; | ||
31 | } | ||
32 | + | 46 | + |
33 | +static bool trans_VINS(DisasContext *s, arg_VINS *a) | 47 | static void raspi2b_machine_class_init(ObjectClass *oc, void *data) |
34 | +{ | 48 | { |
35 | + TCGv_i32 rd, rm; | 49 | MachineClass *mc = MACHINE_CLASS(oc); |
36 | + | 50 | @@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data) |
37 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 51 | |
38 | + return false; | 52 | static const TypeInfo raspi_machine_types[] = { |
39 | + } | 53 | { |
40 | + | 54 | + .name = MACHINE_TYPE_NAME("raspi1ap"), |
41 | + if (s->vec_len != 0 || s->vec_stride != 0) { | 55 | + .parent = TYPE_RASPI_MACHINE, |
42 | + return false; | 56 | + .class_init = raspi1ap_machine_class_init, |
43 | + } | 57 | + }, { |
44 | + | 58 | .name = MACHINE_TYPE_NAME("raspi2b"), |
45 | + if (!vfp_access_check(s)) { | 59 | .parent = TYPE_RASPI_MACHINE, |
46 | + return true; | 60 | .class_init = raspi2b_machine_class_init, |
47 | + } | ||
48 | + | ||
49 | + /* Insert low half of Vm into high half of Vd */ | ||
50 | + rm = tcg_temp_new_i32(); | ||
51 | + rd = tcg_temp_new_i32(); | ||
52 | + neon_load_reg32(rm, a->vm); | ||
53 | + neon_load_reg32(rd, a->vd); | ||
54 | + tcg_gen_deposit_i32(rd, rd, rm, 16, 16); | ||
55 | + neon_store_reg32(rd, a->vd); | ||
56 | + tcg_temp_free_i32(rm); | ||
57 | + tcg_temp_free_i32(rd); | ||
58 | + return true; | ||
59 | +} | ||
60 | -- | 61 | -- |
61 | 2.20.1 | 62 | 2.20.1 |
62 | 63 | ||
63 | 64 | diff view generated by jsdifflib |
1 | Implement the fp16 versions of the VFP VCVT instruction forms which | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | convert between floating point and fixed-point. | ||
3 | 2 | ||
3 | Similarly to the Pi A, the Pi Zero uses a BCM2835 SoC (ARMv6Z core). | ||
4 | |||
5 | The only difference between the revision 1.2 and 1.3 is the latter | ||
6 | exposes a CSI camera connector. As we do not implement the Unicam | ||
7 | peripheral, there is no point in exposing a camera connector :) | ||
8 | Therefore we choose to model the 1.2 revision. | ||
9 | |||
10 | Example booting the machine using content from [*]: | ||
11 | |||
12 | $ qemu-system-arm -M raspi0 -serial stdio \ | ||
13 | -kernel raspberrypi/firmware/boot/kernel.img \ | ||
14 | -dtb raspberrypi/firmware/boot/bcm2708-rpi-zero.dtb \ | ||
15 | -append 'printk.time=0 earlycon=pl011,0x20201000 console=ttyAMA0' | ||
16 | [ 0.000000] Booting Linux on physical CPU 0x0 | ||
17 | [ 0.000000] Linux version 4.19.118+ (dom@buildbot) (gcc version 4.9.3 (crosstool-NG crosstool-ng-1.22.0-88-g8460611)) #1311 Mon Apr 27 14:16:15 BST 2020 | ||
18 | [ 0.000000] CPU: ARMv6-compatible processor [410fb767] revision 7 (ARMv7), cr=00c5387d | ||
19 | [ 0.000000] CPU: VIPT aliasing data cache, unknown instruction cache | ||
20 | [ 0.000000] OF: fdt: Machine model: Raspberry Pi Zero | ||
21 | ... | ||
22 | |||
23 | [*] http://archive.raspberrypi.org/debian/pool/main/r/raspberrypi-firmware/raspberrypi-kernel_1.20200512-2_armhf.deb | ||
24 | |||
25 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | ||
26 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> | ||
27 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
28 | Message-id: 20201024170127.3592182-9-f4bug@amsat.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 29 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-16-peter.maydell@linaro.org | ||
7 | --- | 30 | --- |
8 | target/arm/vfp.decode | 2 ++ | 31 | hw/arm/raspi.c | 13 +++++++++++++ |
9 | target/arm/translate-vfp.c.inc | 59 ++++++++++++++++++++++++++++++++++ | 32 | 1 file changed, 13 insertions(+) |
10 | 2 files changed, 61 insertions(+) | ||
11 | 33 | ||
12 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | 34 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
13 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/vfp.decode | 36 | --- a/hw/arm/raspi.c |
15 | +++ b/target/arm/vfp.decode | 37 | +++ b/hw/arm/raspi.c |
16 | @@ -XXX,XX +XXX,XX @@ VJCVT ---- 1110 1.11 1001 .... 1011 11.0 .... @vfp_dm_sd | 38 | @@ -XXX,XX +XXX,XX @@ static void raspi_machine_class_common_init(MachineClass *mc, |
17 | # We assemble bits 18 (op), 16 (u) and 7 (sx) into a single opc field | 39 | mc->default_ram_id = "ram"; |
18 | # for the convenience of the trans_VCVT_fix functions. | 40 | }; |
19 | %vcvt_fix_op 18:1 16:1 7:1 | 41 | |
20 | +VCVT_fix_hp ---- 1110 1.11 1.1. .... 1001 .1.0 .... \ | 42 | +static void raspi0_machine_class_init(ObjectClass *oc, void *data) |
21 | + vd=%vd_sp imm=%vm_sp opc=%vcvt_fix_op | ||
22 | VCVT_fix_sp ---- 1110 1.11 1.1. .... 1010 .1.0 .... \ | ||
23 | vd=%vd_sp imm=%vm_sp opc=%vcvt_fix_op | ||
24 | VCVT_fix_dp ---- 1110 1.11 1.1. .... 1011 .1.0 .... \ | ||
25 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/target/arm/translate-vfp.c.inc | ||
28 | +++ b/target/arm/translate-vfp.c.inc | ||
29 | @@ -XXX,XX +XXX,XX @@ static bool trans_VJCVT(DisasContext *s, arg_VJCVT *a) | ||
30 | return true; | ||
31 | } | ||
32 | |||
33 | +static bool trans_VCVT_fix_hp(DisasContext *s, arg_VCVT_fix_sp *a) | ||
34 | +{ | 43 | +{ |
35 | + TCGv_i32 vd, shift; | 44 | + MachineClass *mc = MACHINE_CLASS(oc); |
36 | + TCGv_ptr fpst; | 45 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); |
37 | + int frac_bits; | ||
38 | + | 46 | + |
39 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 47 | + rmc->board_rev = 0x920092; /* Revision 1.2 */ |
40 | + return false; | 48 | + raspi_machine_class_common_init(mc, rmc->board_rev); |
41 | + } | 49 | +}; |
42 | + | 50 | + |
43 | + if (!vfp_access_check(s)) { | 51 | static void raspi1ap_machine_class_init(ObjectClass *oc, void *data) |
44 | + return true; | ||
45 | + } | ||
46 | + | ||
47 | + frac_bits = (a->opc & 1) ? (32 - a->imm) : (16 - a->imm); | ||
48 | + | ||
49 | + vd = tcg_temp_new_i32(); | ||
50 | + neon_load_reg32(vd, a->vd); | ||
51 | + | ||
52 | + fpst = fpstatus_ptr(FPST_FPCR_F16); | ||
53 | + shift = tcg_const_i32(frac_bits); | ||
54 | + | ||
55 | + /* Switch on op:U:sx bits */ | ||
56 | + switch (a->opc) { | ||
57 | + case 0: | ||
58 | + gen_helper_vfp_shtoh(vd, vd, shift, fpst); | ||
59 | + break; | ||
60 | + case 1: | ||
61 | + gen_helper_vfp_sltoh(vd, vd, shift, fpst); | ||
62 | + break; | ||
63 | + case 2: | ||
64 | + gen_helper_vfp_uhtoh(vd, vd, shift, fpst); | ||
65 | + break; | ||
66 | + case 3: | ||
67 | + gen_helper_vfp_ultoh(vd, vd, shift, fpst); | ||
68 | + break; | ||
69 | + case 4: | ||
70 | + gen_helper_vfp_toshh_round_to_zero(vd, vd, shift, fpst); | ||
71 | + break; | ||
72 | + case 5: | ||
73 | + gen_helper_vfp_toslh_round_to_zero(vd, vd, shift, fpst); | ||
74 | + break; | ||
75 | + case 6: | ||
76 | + gen_helper_vfp_touhh_round_to_zero(vd, vd, shift, fpst); | ||
77 | + break; | ||
78 | + case 7: | ||
79 | + gen_helper_vfp_toulh_round_to_zero(vd, vd, shift, fpst); | ||
80 | + break; | ||
81 | + default: | ||
82 | + g_assert_not_reached(); | ||
83 | + } | ||
84 | + | ||
85 | + neon_store_reg32(vd, a->vd); | ||
86 | + tcg_temp_free_i32(vd); | ||
87 | + tcg_temp_free_i32(shift); | ||
88 | + tcg_temp_free_ptr(fpst); | ||
89 | + return true; | ||
90 | +} | ||
91 | + | ||
92 | static bool trans_VCVT_fix_sp(DisasContext *s, arg_VCVT_fix_sp *a) | ||
93 | { | 52 | { |
94 | TCGv_i32 vd, shift; | 53 | MachineClass *mc = MACHINE_CLASS(oc); |
54 | @@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data) | ||
55 | |||
56 | static const TypeInfo raspi_machine_types[] = { | ||
57 | { | ||
58 | + .name = MACHINE_TYPE_NAME("raspi0"), | ||
59 | + .parent = TYPE_RASPI_MACHINE, | ||
60 | + .class_init = raspi0_machine_class_init, | ||
61 | + }, { | ||
62 | .name = MACHINE_TYPE_NAME("raspi1ap"), | ||
63 | .parent = TYPE_RASPI_MACHINE, | ||
64 | .class_init = raspi1ap_machine_class_init, | ||
95 | -- | 65 | -- |
96 | 2.20.1 | 66 | 2.20.1 |
97 | 67 | ||
98 | 68 | diff view generated by jsdifflib |
1 | From: Leif Lindholm <leif@nuviainc.com> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | The sbsa-ref platform uses a minimal device tree to pass amount of memory | 3 | The Pi 3A+ is a stripped down version of the 3B: |
4 | as well as number of cpus to the firmware. However, when dumping that | 4 | - 512 MiB of RAM instead of 1 GiB |
5 | minimal dtb (with -M sbsa-virt,dumpdtb=<file>), the resulting blob | 5 | - no on-board ethernet chipset |
6 | generates a warning when decompiled by dtc due to lack of reg property. | ||
7 | 6 | ||
8 | Add a simple reg property per cpu, representing a 64-bit MPIDR_EL1. | 7 | Add it as it is a closer match to what we model. |
9 | 8 | ||
10 | This also ends up being cleaner than having the firmware calculating its | 9 | Reviewed-by: Igor Mammedov <imammedo@redhat.com> |
11 | own IDs for generating APCI. | 10 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
12 | 11 | Message-id: 20201024170127.3592182-10-f4bug@amsat.org | |
13 | Signed-off-by: Leif Lindholm <leif@nuviainc.com> | ||
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Message-id: 20200827124335.30586-1-leif@nuviainc.com | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 13 | --- |
18 | hw/arm/sbsa-ref.c | 29 +++++++++++++++++++++++------ | 14 | hw/arm/raspi.c | 13 +++++++++++++ |
19 | 1 file changed, 23 insertions(+), 6 deletions(-) | 15 | 1 file changed, 13 insertions(+) |
20 | 16 | ||
21 | diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c | 17 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
22 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/arm/sbsa-ref.c | 19 | --- a/hw/arm/raspi.c |
24 | +++ b/hw/arm/sbsa-ref.c | 20 | +++ b/hw/arm/raspi.c |
25 | @@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = { | 21 | @@ -XXX,XX +XXX,XX @@ static void raspi2b_machine_class_init(ObjectClass *oc, void *data) |
26 | [SBSA_EHCI] = 11, | ||
27 | }; | 22 | }; |
28 | 23 | ||
29 | +static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx) | 24 | #ifdef TARGET_AARCH64 |
25 | +static void raspi3ap_machine_class_init(ObjectClass *oc, void *data) | ||
30 | +{ | 26 | +{ |
31 | + uint8_t clustersz = ARM_DEFAULT_CPUS_PER_CLUSTER; | 27 | + MachineClass *mc = MACHINE_CLASS(oc); |
32 | + return arm_cpu_mp_affinity(idx, clustersz); | 28 | + RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); |
33 | +} | ||
34 | + | 29 | + |
35 | /* | 30 | + rmc->board_rev = 0x9020e0; /* Revision 1.0 */ |
36 | * Firmware on this machine only uses ACPI table to load OS, these limited | 31 | + raspi_machine_class_common_init(mc, rmc->board_rev); |
37 | * device tree nodes are just to let firmware know the info which varies from | 32 | +}; |
38 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(SBSAMachineState *sms) | 33 | + |
39 | g_free(matrix); | 34 | static void raspi3b_machine_class_init(ObjectClass *oc, void *data) |
40 | } | ||
41 | |||
42 | + /* | ||
43 | + * From Documentation/devicetree/bindings/arm/cpus.yaml | ||
44 | + * On ARM v8 64-bit systems this property is required | ||
45 | + * and matches the MPIDR_EL1 register affinity bits. | ||
46 | + * | ||
47 | + * * If cpus node's #address-cells property is set to 2 | ||
48 | + * | ||
49 | + * The first reg cell bits [7:0] must be set to | ||
50 | + * bits [39:32] of MPIDR_EL1. | ||
51 | + * | ||
52 | + * The second reg cell bits [23:0] must be set to | ||
53 | + * bits [23:0] of MPIDR_EL1. | ||
54 | + */ | ||
55 | qemu_fdt_add_subnode(sms->fdt, "/cpus"); | ||
56 | + qemu_fdt_setprop_cell(sms->fdt, "/cpus", "#address-cells", 2); | ||
57 | + qemu_fdt_setprop_cell(sms->fdt, "/cpus", "#size-cells", 0x0); | ||
58 | |||
59 | for (cpu = sms->smp_cpus - 1; cpu >= 0; cpu--) { | ||
60 | char *nodename = g_strdup_printf("/cpus/cpu@%d", cpu); | ||
61 | ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(cpu)); | ||
62 | CPUState *cs = CPU(armcpu); | ||
63 | + uint64_t mpidr = sbsa_ref_cpu_mp_affinity(sms, cpu); | ||
64 | |||
65 | qemu_fdt_add_subnode(sms->fdt, nodename); | ||
66 | + qemu_fdt_setprop_u64(sms->fdt, nodename, "reg", mpidr); | ||
67 | |||
68 | if (ms->possible_cpus->cpus[cs->cpu_index].props.has_node_id) { | ||
69 | qemu_fdt_setprop_cell(sms->fdt, nodename, "numa-node-id", | ||
70 | @@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine) | ||
71 | arm_load_kernel(ARM_CPU(first_cpu), machine, &sms->bootinfo); | ||
72 | } | ||
73 | |||
74 | -static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx) | ||
75 | -{ | ||
76 | - uint8_t clustersz = ARM_DEFAULT_CPUS_PER_CLUSTER; | ||
77 | - return arm_cpu_mp_affinity(idx, clustersz); | ||
78 | -} | ||
79 | - | ||
80 | static const CPUArchIdList *sbsa_ref_possible_cpu_arch_ids(MachineState *ms) | ||
81 | { | 35 | { |
82 | unsigned int max_cpus = ms->smp.max_cpus; | 36 | MachineClass *mc = MACHINE_CLASS(oc); |
37 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo raspi_machine_types[] = { | ||
38 | .parent = TYPE_RASPI_MACHINE, | ||
39 | .class_init = raspi2b_machine_class_init, | ||
40 | #ifdef TARGET_AARCH64 | ||
41 | + }, { | ||
42 | + .name = MACHINE_TYPE_NAME("raspi3ap"), | ||
43 | + .parent = TYPE_RASPI_MACHINE, | ||
44 | + .class_init = raspi3ap_machine_class_init, | ||
45 | }, { | ||
46 | .name = MACHINE_TYPE_NAME("raspi3b"), | ||
47 | .parent = TYPE_RASPI_MACHINE, | ||
83 | -- | 48 | -- |
84 | 2.20.1 | 49 | 2.20.1 |
85 | 50 | ||
86 | 51 | diff view generated by jsdifflib |
1 | Now the VFP_CONV_FIX macros can handle fp16's distinction between the | 1 | From: "Dr. David Alan Gilbert" <dgilbert@redhat.com> |
---|---|---|---|
2 | width of the operation and the width of the type used to pass operands, | ||
3 | use the macros rather than the open-coded functions. | ||
4 | 2 | ||
5 | This creates an extra six helper functions, all of which we are going | 3 | Use of 0x%d - make up our mind as 0x%x |
6 | to need for the AArch32 VFP fp16 instructions. | ||
7 | 4 | ||
5 | Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com> | ||
6 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Acked-by: Eric Auger <eric.auger@redhat.com> | ||
8 | Message-id: 20201014193355.53074-1-dgilbert@redhat.com | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20200828183354.27913-15-peter.maydell@linaro.org | ||
11 | --- | 10 | --- |
12 | target/arm/helper.h | 6 +++ | 11 | hw/arm/trace-events | 2 +- |
13 | target/arm/vfp_helper.c | 86 +++-------------------------------------- | 12 | 1 file changed, 1 insertion(+), 1 deletion(-) |
14 | 2 files changed, 12 insertions(+), 80 deletions(-) | ||
15 | 13 | ||
16 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 14 | diff --git a/hw/arm/trace-events b/hw/arm/trace-events |
17 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/helper.h | 16 | --- a/hw/arm/trace-events |
19 | +++ b/target/arm/helper.h | 17 | +++ b/hw/arm/trace-events |
20 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(vfp_tosizh, s32, f16, ptr) | 18 | @@ -XXX,XX +XXX,XX @@ smmuv3_get_cd(uint64_t addr) "CD addr: 0x%"PRIx64 |
21 | DEF_HELPER_2(vfp_tosizs, s32, f32, ptr) | 19 | smmuv3_decode_cd(uint32_t oas) "oas=%d" |
22 | DEF_HELPER_2(vfp_tosizd, s32, f64, ptr) | 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" |
23 | 21 | smmuv3_cmdq_cfgi_ste(int streamid) "streamid =%d" | |
24 | +DEF_HELPER_3(vfp_toshh_round_to_zero, i32, f16, i32, ptr) | 22 | -smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%d - end=0x%d" |
25 | +DEF_HELPER_3(vfp_toslh_round_to_zero, i32, f16, i32, ptr) | 23 | +smmuv3_cmdq_cfgi_ste_range(int start, int end) "start=0x%x - end=0x%x" |
26 | +DEF_HELPER_3(vfp_touhh_round_to_zero, i32, f16, i32, ptr) | 24 | smmuv3_cmdq_cfgi_cd(uint32_t sid) "streamid = %d" |
27 | +DEF_HELPER_3(vfp_toulh_round_to_zero, i32, f16, i32, ptr) | 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)" |
28 | DEF_HELPER_3(vfp_toshs_round_to_zero, i32, f32, i32, ptr) | 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)" |
29 | DEF_HELPER_3(vfp_tosls_round_to_zero, i32, f32, i32, ptr) | ||
30 | DEF_HELPER_3(vfp_touhs_round_to_zero, i32, f32, i32, ptr) | ||
31 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(vfp_sqtod, f64, i64, i32, ptr) | ||
32 | DEF_HELPER_3(vfp_uhtod, f64, i64, i32, ptr) | ||
33 | DEF_HELPER_3(vfp_ultod, f64, i64, i32, ptr) | ||
34 | DEF_HELPER_3(vfp_uqtod, f64, i64, i32, ptr) | ||
35 | +DEF_HELPER_3(vfp_shtoh, f16, i32, i32, ptr) | ||
36 | +DEF_HELPER_3(vfp_uhtoh, f16, i32, i32, ptr) | ||
37 | DEF_HELPER_3(vfp_sltoh, f16, i32, i32, ptr) | ||
38 | DEF_HELPER_3(vfp_ultoh, f16, i32, i32, ptr) | ||
39 | DEF_HELPER_3(vfp_sqtoh, f16, i64, i32, ptr) | ||
40 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/target/arm/vfp_helper.c | ||
43 | +++ b/target/arm/vfp_helper.c | ||
44 | @@ -XXX,XX +XXX,XX @@ VFP_CONV_FIX_A64(sq, s, 32, float32, 64, int64) | ||
45 | VFP_CONV_FIX(uh, s, 32, float32, 32, uint16) | ||
46 | VFP_CONV_FIX(ul, s, 32, float32, 32, uint32) | ||
47 | VFP_CONV_FIX_A64(uq, s, 32, float32, 64, uint64) | ||
48 | +VFP_CONV_FIX(sh, h, 16, dh_ctype_f16, 32, int16) | ||
49 | +VFP_CONV_FIX(sl, h, 16, dh_ctype_f16, 32, int32) | ||
50 | +VFP_CONV_FIX_A64(sq, h, 16, dh_ctype_f16, 64, int64) | ||
51 | +VFP_CONV_FIX(uh, h, 16, dh_ctype_f16, 32, uint16) | ||
52 | +VFP_CONV_FIX(ul, h, 16, dh_ctype_f16, 32, uint32) | ||
53 | +VFP_CONV_FIX_A64(uq, h, 16, dh_ctype_f16, 64, uint64) | ||
54 | |||
55 | #undef VFP_CONV_FIX | ||
56 | #undef VFP_CONV_FIX_FLOAT | ||
57 | #undef VFP_CONV_FLOAT_FIX_ROUND | ||
58 | #undef VFP_CONV_FIX_A64 | ||
59 | |||
60 | -uint32_t HELPER(vfp_sltoh)(uint32_t x, uint32_t shift, void *fpst) | ||
61 | -{ | ||
62 | - return int32_to_float16_scalbn(x, -shift, fpst); | ||
63 | -} | ||
64 | - | ||
65 | -uint32_t HELPER(vfp_ultoh)(uint32_t x, uint32_t shift, void *fpst) | ||
66 | -{ | ||
67 | - return uint32_to_float16_scalbn(x, -shift, fpst); | ||
68 | -} | ||
69 | - | ||
70 | -uint32_t HELPER(vfp_sqtoh)(uint64_t x, uint32_t shift, void *fpst) | ||
71 | -{ | ||
72 | - return int64_to_float16_scalbn(x, -shift, fpst); | ||
73 | -} | ||
74 | - | ||
75 | -uint32_t HELPER(vfp_uqtoh)(uint64_t x, uint32_t shift, void *fpst) | ||
76 | -{ | ||
77 | - return uint64_to_float16_scalbn(x, -shift, fpst); | ||
78 | -} | ||
79 | - | ||
80 | -uint32_t HELPER(vfp_toshh)(uint32_t x, uint32_t shift, void *fpst) | ||
81 | -{ | ||
82 | - if (unlikely(float16_is_any_nan(x))) { | ||
83 | - float_raise(float_flag_invalid, fpst); | ||
84 | - return 0; | ||
85 | - } | ||
86 | - return float16_to_int16_scalbn(x, get_float_rounding_mode(fpst), | ||
87 | - shift, fpst); | ||
88 | -} | ||
89 | - | ||
90 | -uint32_t HELPER(vfp_touhh)(uint32_t x, uint32_t shift, void *fpst) | ||
91 | -{ | ||
92 | - if (unlikely(float16_is_any_nan(x))) { | ||
93 | - float_raise(float_flag_invalid, fpst); | ||
94 | - return 0; | ||
95 | - } | ||
96 | - return float16_to_uint16_scalbn(x, get_float_rounding_mode(fpst), | ||
97 | - shift, fpst); | ||
98 | -} | ||
99 | - | ||
100 | -uint32_t HELPER(vfp_toslh)(uint32_t x, uint32_t shift, void *fpst) | ||
101 | -{ | ||
102 | - if (unlikely(float16_is_any_nan(x))) { | ||
103 | - float_raise(float_flag_invalid, fpst); | ||
104 | - return 0; | ||
105 | - } | ||
106 | - return float16_to_int32_scalbn(x, get_float_rounding_mode(fpst), | ||
107 | - shift, fpst); | ||
108 | -} | ||
109 | - | ||
110 | -uint32_t HELPER(vfp_toulh)(uint32_t x, uint32_t shift, void *fpst) | ||
111 | -{ | ||
112 | - if (unlikely(float16_is_any_nan(x))) { | ||
113 | - float_raise(float_flag_invalid, fpst); | ||
114 | - return 0; | ||
115 | - } | ||
116 | - return float16_to_uint32_scalbn(x, get_float_rounding_mode(fpst), | ||
117 | - shift, fpst); | ||
118 | -} | ||
119 | - | ||
120 | -uint64_t HELPER(vfp_tosqh)(uint32_t x, uint32_t shift, void *fpst) | ||
121 | -{ | ||
122 | - if (unlikely(float16_is_any_nan(x))) { | ||
123 | - float_raise(float_flag_invalid, fpst); | ||
124 | - return 0; | ||
125 | - } | ||
126 | - return float16_to_int64_scalbn(x, get_float_rounding_mode(fpst), | ||
127 | - shift, fpst); | ||
128 | -} | ||
129 | - | ||
130 | -uint64_t HELPER(vfp_touqh)(uint32_t x, uint32_t shift, void *fpst) | ||
131 | -{ | ||
132 | - if (unlikely(float16_is_any_nan(x))) { | ||
133 | - float_raise(float_flag_invalid, fpst); | ||
134 | - return 0; | ||
135 | - } | ||
136 | - return float16_to_uint64_scalbn(x, get_float_rounding_mode(fpst), | ||
137 | - shift, fpst); | ||
138 | -} | ||
139 | - | ||
140 | /* Set the current fp rounding mode and return the old one. | ||
141 | * The argument is a softfloat float_round_ value. | ||
142 | */ | ||
143 | -- | 27 | -- |
144 | 2.20.1 | 28 | 2.20.1 |
145 | 29 | ||
146 | 30 | diff view generated by jsdifflib |
1 | Currently the VFP_CONV_FIX macros take a single fsz argument for the | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | size of the float type, which is used both to select the name of | ||
3 | the functions to call (eg float32_is_any_nan()) and also for the | ||
4 | type to use for the float inputs and outputs (eg float32). | ||
5 | 2 | ||
6 | Separate these into fsz and ftype arguments, so that we can use them | 3 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
7 | for fp16, which uses 'float16' in the function names but is still | 4 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> |
8 | passing inputs and outputs in a 32-bit sized type. | 5 | Signed-off-by: Luc Michel <luc@lmichel.fr> |
6 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
7 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | include/hw/clock.h | 5 +++++ | ||
11 | 1 file changed, 5 insertions(+) | ||
9 | 12 | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | diff --git a/include/hw/clock.h b/include/hw/clock.h |
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Message-id: 20200828183354.27913-14-peter.maydell@linaro.org | ||
13 | --- | ||
14 | target/arm/vfp_helper.c | 46 ++++++++++++++++++++--------------------- | ||
15 | 1 file changed, 23 insertions(+), 23 deletions(-) | ||
16 | |||
17 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/arm/vfp_helper.c | 15 | --- a/include/hw/clock.h |
20 | +++ b/target/arm/vfp_helper.c | 16 | +++ b/include/hw/clock.h |
21 | @@ -XXX,XX +XXX,XX @@ float32 VFP_HELPER(fcvts, d)(float64 x, CPUARMState *env) | 17 | @@ -XXX,XX +XXX,XX @@ extern const VMStateDescription vmstate_clock; |
22 | } | 18 | VMSTATE_CLOCK_V(field, state, 0) |
23 | 19 | #define VMSTATE_CLOCK_V(field, state, version) \ | |
24 | /* VFP3 fixed point conversion. */ | 20 | VMSTATE_STRUCT_POINTER_V(field, state, version, vmstate_clock, Clock) |
25 | -#define VFP_CONV_FIX_FLOAT(name, p, fsz, isz, itype) \ | 21 | +#define VMSTATE_ARRAY_CLOCK(field, state, num) \ |
26 | -float##fsz HELPER(vfp_##name##to##p)(uint##isz##_t x, uint32_t shift, \ | 22 | + VMSTATE_ARRAY_CLOCK_V(field, state, num, 0) |
27 | +#define VFP_CONV_FIX_FLOAT(name, p, fsz, ftype, isz, itype) \ | 23 | +#define VMSTATE_ARRAY_CLOCK_V(field, state, num, version) \ |
28 | +ftype HELPER(vfp_##name##to##p)(uint##isz##_t x, uint32_t shift, \ | 24 | + VMSTATE_ARRAY_OF_POINTER_TO_STRUCT(field, state, num, version, \ |
29 | void *fpstp) \ | 25 | + vmstate_clock, Clock) |
30 | { return itype##_to_##float##fsz##_scalbn(x, -shift, fpstp); } | 26 | |
31 | 27 | /** | |
32 | -#define VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, isz, itype, ROUND, suff) \ | 28 | * clock_setup_canonical_path: |
33 | -uint##isz##_t HELPER(vfp_to##name##p##suff)(float##fsz x, uint32_t shift, \ | ||
34 | +#define VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, ftype, isz, itype, ROUND, suff) \ | ||
35 | +uint##isz##_t HELPER(vfp_to##name##p##suff)(ftype x, uint32_t shift, \ | ||
36 | void *fpst) \ | ||
37 | { \ | ||
38 | if (unlikely(float##fsz##_is_any_nan(x))) { \ | ||
39 | @@ -XXX,XX +XXX,XX @@ uint##isz##_t HELPER(vfp_to##name##p##suff)(float##fsz x, uint32_t shift, \ | ||
40 | return float##fsz##_to_##itype##_scalbn(x, ROUND, shift, fpst); \ | ||
41 | } | ||
42 | |||
43 | -#define VFP_CONV_FIX(name, p, fsz, isz, itype) \ | ||
44 | -VFP_CONV_FIX_FLOAT(name, p, fsz, isz, itype) \ | ||
45 | -VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, isz, itype, \ | ||
46 | +#define VFP_CONV_FIX(name, p, fsz, ftype, isz, itype) \ | ||
47 | +VFP_CONV_FIX_FLOAT(name, p, fsz, ftype, isz, itype) \ | ||
48 | +VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, ftype, isz, itype, \ | ||
49 | float_round_to_zero, _round_to_zero) \ | ||
50 | -VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, isz, itype, \ | ||
51 | +VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, ftype, isz, itype, \ | ||
52 | get_float_rounding_mode(fpst), ) | ||
53 | |||
54 | -#define VFP_CONV_FIX_A64(name, p, fsz, isz, itype) \ | ||
55 | -VFP_CONV_FIX_FLOAT(name, p, fsz, isz, itype) \ | ||
56 | -VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, isz, itype, \ | ||
57 | +#define VFP_CONV_FIX_A64(name, p, fsz, ftype, isz, itype) \ | ||
58 | +VFP_CONV_FIX_FLOAT(name, p, fsz, ftype, isz, itype) \ | ||
59 | +VFP_CONV_FLOAT_FIX_ROUND(name, p, fsz, ftype, isz, itype, \ | ||
60 | get_float_rounding_mode(fpst), ) | ||
61 | |||
62 | -VFP_CONV_FIX(sh, d, 64, 64, int16) | ||
63 | -VFP_CONV_FIX(sl, d, 64, 64, int32) | ||
64 | -VFP_CONV_FIX_A64(sq, d, 64, 64, int64) | ||
65 | -VFP_CONV_FIX(uh, d, 64, 64, uint16) | ||
66 | -VFP_CONV_FIX(ul, d, 64, 64, uint32) | ||
67 | -VFP_CONV_FIX_A64(uq, d, 64, 64, uint64) | ||
68 | -VFP_CONV_FIX(sh, s, 32, 32, int16) | ||
69 | -VFP_CONV_FIX(sl, s, 32, 32, int32) | ||
70 | -VFP_CONV_FIX_A64(sq, s, 32, 64, int64) | ||
71 | -VFP_CONV_FIX(uh, s, 32, 32, uint16) | ||
72 | -VFP_CONV_FIX(ul, s, 32, 32, uint32) | ||
73 | -VFP_CONV_FIX_A64(uq, s, 32, 64, uint64) | ||
74 | +VFP_CONV_FIX(sh, d, 64, float64, 64, int16) | ||
75 | +VFP_CONV_FIX(sl, d, 64, float64, 64, int32) | ||
76 | +VFP_CONV_FIX_A64(sq, d, 64, float64, 64, int64) | ||
77 | +VFP_CONV_FIX(uh, d, 64, float64, 64, uint16) | ||
78 | +VFP_CONV_FIX(ul, d, 64, float64, 64, uint32) | ||
79 | +VFP_CONV_FIX_A64(uq, d, 64, float64, 64, uint64) | ||
80 | +VFP_CONV_FIX(sh, s, 32, float32, 32, int16) | ||
81 | +VFP_CONV_FIX(sl, s, 32, float32, 32, int32) | ||
82 | +VFP_CONV_FIX_A64(sq, s, 32, float32, 64, int64) | ||
83 | +VFP_CONV_FIX(uh, s, 32, float32, 32, uint16) | ||
84 | +VFP_CONV_FIX(ul, s, 32, float32, 32, uint32) | ||
85 | +VFP_CONV_FIX_A64(uq, s, 32, float32, 64, uint64) | ||
86 | |||
87 | #undef VFP_CONV_FIX | ||
88 | #undef VFP_CONV_FIX_FLOAT | ||
89 | -- | 29 | -- |
90 | 2.20.1 | 30 | 2.20.1 |
91 | 31 | ||
92 | 32 | diff view generated by jsdifflib |
1 | Rewrite Neon VABS/VNEG of floats to use gvec logical AND and XOR, so | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | that we can implement the fp16 version of the insns. | ||
3 | 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> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-26-peter.maydell@linaro.org | ||
7 | --- | 20 | --- |
8 | target/arm/translate-neon.c.inc | 34 +++++++++++++++++++++++++++------ | 21 | hw/core/clock.c | 6 +++--- |
9 | 1 file changed, 28 insertions(+), 6 deletions(-) | 22 | hw/core/trace-events | 4 ++-- |
23 | 2 files changed, 5 insertions(+), 5 deletions(-) | ||
10 | 24 | ||
11 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | 25 | diff --git a/hw/core/clock.c b/hw/core/clock.c |
12 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate-neon.c.inc | 27 | --- a/hw/core/clock.c |
14 | +++ b/target/arm/translate-neon.c.inc | 28 | +++ b/hw/core/clock.c |
15 | @@ -XXX,XX +XXX,XX @@ static bool trans_VCNT(DisasContext *s, arg_2misc *a) | 29 | @@ -XXX,XX +XXX,XX @@ bool clock_set(Clock *clk, uint64_t period) |
16 | return do_2misc(s, a, gen_helper_neon_cnt_u8); | 30 | if (clk->period == period) { |
17 | } | ||
18 | |||
19 | +static void gen_VABS_F(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs, | ||
20 | + uint32_t oprsz, uint32_t maxsz) | ||
21 | +{ | ||
22 | + tcg_gen_gvec_andi(vece, rd_ofs, rm_ofs, | ||
23 | + vece == MO_16 ? 0x7fff : 0x7fffffff, | ||
24 | + oprsz, maxsz); | ||
25 | +} | ||
26 | + | ||
27 | static bool trans_VABS_F(DisasContext *s, arg_2misc *a) | ||
28 | { | ||
29 | - if (a->size != 2) { | ||
30 | + if (a->size == MO_16) { | ||
31 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | ||
32 | + return false; | ||
33 | + } | ||
34 | + } else if (a->size != MO_32) { | ||
35 | return false; | 31 | return false; |
36 | } | 32 | } |
37 | - /* TODO: FP16 : size == 1 */ | 33 | - trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_NS(clk->period), |
38 | - return do_2misc(s, a, gen_helper_vfp_abss); | 34 | - CLOCK_PERIOD_TO_NS(period)); |
39 | + return do_2misc_vec(s, a, gen_VABS_F); | 35 | + trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_HZ(clk->period), |
40 | +} | 36 | + CLOCK_PERIOD_TO_HZ(period)); |
41 | + | 37 | clk->period = period; |
42 | +static void gen_VNEG_F(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs, | 38 | |
43 | + uint32_t oprsz, uint32_t maxsz) | 39 | return true; |
44 | +{ | 40 | @@ -XXX,XX +XXX,XX @@ static void clock_propagate_period(Clock *clk, bool call_callbacks) |
45 | + tcg_gen_gvec_xori(vece, rd_ofs, rm_ofs, | 41 | if (child->period != clk->period) { |
46 | + vece == MO_16 ? 0x8000 : 0x80000000, | 42 | child->period = clk->period; |
47 | + oprsz, maxsz); | 43 | trace_clock_update(CLOCK_PATH(child), CLOCK_PATH(clk), |
48 | } | 44 | - CLOCK_PERIOD_TO_NS(clk->period), |
49 | 45 | + CLOCK_PERIOD_TO_HZ(clk->period), | |
50 | static bool trans_VNEG_F(DisasContext *s, arg_2misc *a) | 46 | call_callbacks); |
51 | { | 47 | if (call_callbacks && child->callback) { |
52 | - if (a->size != 2) { | 48 | child->callback(child->callback_opaque); |
53 | + if (a->size == MO_16) { | 49 | diff --git a/hw/core/trace-events b/hw/core/trace-events |
54 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 50 | index XXXXXXX..XXXXXXX 100644 |
55 | + return false; | 51 | --- a/hw/core/trace-events |
56 | + } | 52 | +++ b/hw/core/trace-events |
57 | + } else if (a->size != MO_32) { | 53 | @@ -XXX,XX +XXX,XX @@ resettable_transitional_function(void *obj, const char *objtype) "obj=%p(%s)" |
58 | return false; | 54 | # clock.c |
59 | } | 55 | clock_set_source(const char *clk, const char *src) "'%s', src='%s'" |
60 | - /* TODO: FP16 : size == 1 */ | 56 | clock_disconnect(const char *clk) "'%s'" |
61 | - return do_2misc(s, a, gen_helper_vfp_negs); | 57 | -clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', ns=%"PRIu64"->%"PRIu64 |
62 | + return do_2misc_vec(s, a, gen_VNEG_F); | 58 | +clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', %"PRIu64"Hz->%"PRIu64"Hz" |
63 | } | 59 | clock_propagate(const char *clk) "'%s'" |
64 | 60 | -clock_update(const char *clk, const char *src, uint64_t val, int cb) "'%s', src='%s', ns=%"PRIu64", cb=%d" | |
65 | static bool trans_VRECPE(DisasContext *s, arg_2misc *a) | 61 | +clock_update(const char *clk, const char *src, uint64_t hz, int cb) "'%s', src='%s', val=%"PRIu64"Hz cb=%d" |
66 | -- | 62 | -- |
67 | 2.20.1 | 63 | 2.20.1 |
68 | 64 | ||
69 | 65 | diff view generated by jsdifflib |
1 | Macroify the uses of do_vfp_2op_sp() and do_vfp_2op_dp(); this will | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | make it easier to add the halfprec support. | ||
3 | 2 | ||
3 | The CPRMAN (clock controller) was mapped at the watchdog/power manager | ||
4 | address. It was also split into two unimplemented peripherals (CM and | ||
5 | A2W) but this is really the same one, as shown by this extract of the | ||
6 | Raspberry Pi 3 Linux device tree: | ||
7 | |||
8 | watchdog@7e100000 { | ||
9 | compatible = "brcm,bcm2835-pm\0brcm,bcm2835-pm-wdt"; | ||
10 | [...] | ||
11 | reg = <0x7e100000 0x114 0x7e00a000 0x24>; | ||
12 | [...] | ||
13 | }; | ||
14 | |||
15 | [...] | ||
16 | cprman@7e101000 { | ||
17 | compatible = "brcm,bcm2835-cprman"; | ||
18 | [...] | ||
19 | reg = <0x7e101000 0x2000>; | ||
20 | [...] | ||
21 | }; | ||
22 | |||
23 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
24 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
25 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
26 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 27 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200828183354.27913-8-peter.maydell@linaro.org | ||
7 | --- | 28 | --- |
8 | target/arm/translate-vfp.c.inc | 49 ++++++++++------------------------ | 29 | include/hw/arm/bcm2835_peripherals.h | 2 +- |
9 | 1 file changed, 14 insertions(+), 35 deletions(-) | 30 | include/hw/arm/raspi_platform.h | 5 ++--- |
31 | hw/arm/bcm2835_peripherals.c | 4 ++-- | ||
32 | 3 files changed, 5 insertions(+), 6 deletions(-) | ||
10 | 33 | ||
11 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 34 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h |
12 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/translate-vfp.c.inc | 36 | --- a/include/hw/arm/bcm2835_peripherals.h |
14 | +++ b/target/arm/translate-vfp.c.inc | 37 | +++ b/include/hw/arm/bcm2835_peripherals.h |
15 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMOV_imm_dp(DisasContext *s, arg_VMOV_imm_dp *a) | 38 | @@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState { |
16 | return true; | 39 | BCM2835MphiState mphi; |
17 | } | 40 | UnimplementedDeviceState txp; |
18 | 41 | UnimplementedDeviceState armtmr; | |
19 | -static bool trans_VMOV_reg_sp(DisasContext *s, arg_VMOV_reg_sp *a) | 42 | + UnimplementedDeviceState powermgt; |
20 | -{ | 43 | UnimplementedDeviceState cprman; |
21 | - return do_vfp_2op_sp(s, tcg_gen_mov_i32, a->vd, a->vm); | 44 | - UnimplementedDeviceState a2w; |
22 | -} | 45 | PL011State uart0; |
23 | +#define DO_VFP_2OP(INSN, PREC, FN) \ | 46 | BCM2835AuxState aux; |
24 | + static bool trans_##INSN##_##PREC(DisasContext *s, \ | 47 | BCM2835FBState fb; |
25 | + arg_##INSN##_##PREC *a) \ | 48 | diff --git a/include/hw/arm/raspi_platform.h b/include/hw/arm/raspi_platform.h |
26 | + { \ | 49 | index XXXXXXX..XXXXXXX 100644 |
27 | + return do_vfp_2op_##PREC(s, FN, a->vd, a->vm); \ | 50 | --- a/include/hw/arm/raspi_platform.h |
28 | + } | 51 | +++ b/include/hw/arm/raspi_platform.h |
29 | 52 | @@ -XXX,XX +XXX,XX @@ | |
30 | -static bool trans_VMOV_reg_dp(DisasContext *s, arg_VMOV_reg_dp *a) | 53 | #define ARMCTRL_TIMER0_1_OFFSET (ARM_OFFSET + 0x400) /* Timer 0 and 1 (SP804) */ |
31 | -{ | 54 | #define ARMCTRL_0_SBM_OFFSET (ARM_OFFSET + 0x800) /* User 0 (ARM) Semaphores |
32 | - return do_vfp_2op_dp(s, tcg_gen_mov_i64, a->vd, a->vm); | 55 | * Doorbells & Mailboxes */ |
33 | -} | 56 | -#define CPRMAN_OFFSET 0x100000 /* Power Management, Watchdog */ |
34 | +DO_VFP_2OP(VMOV_reg, sp, tcg_gen_mov_i32) | 57 | -#define CM_OFFSET 0x101000 /* Clock Management */ |
35 | +DO_VFP_2OP(VMOV_reg, dp, tcg_gen_mov_i64) | 58 | -#define A2W_OFFSET 0x102000 /* Reset controller */ |
36 | 59 | +#define PM_OFFSET 0x100000 /* Power Management */ | |
37 | -static bool trans_VABS_sp(DisasContext *s, arg_VABS_sp *a) | 60 | +#define CPRMAN_OFFSET 0x101000 /* Clock Management */ |
38 | -{ | 61 | #define AVS_OFFSET 0x103000 /* Audio Video Standard */ |
39 | - return do_vfp_2op_sp(s, gen_helper_vfp_abss, a->vd, a->vm); | 62 | #define RNG_OFFSET 0x104000 |
40 | -} | 63 | #define GPIO_OFFSET 0x200000 |
41 | +DO_VFP_2OP(VABS, sp, gen_helper_vfp_abss) | 64 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c |
42 | +DO_VFP_2OP(VABS, dp, gen_helper_vfp_absd) | 65 | index XXXXXXX..XXXXXXX 100644 |
43 | 66 | --- a/hw/arm/bcm2835_peripherals.c | |
44 | -static bool trans_VABS_dp(DisasContext *s, arg_VABS_dp *a) | 67 | +++ b/hw/arm/bcm2835_peripherals.c |
45 | -{ | 68 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) |
46 | - return do_vfp_2op_dp(s, gen_helper_vfp_absd, a->vd, a->vm); | 69 | |
47 | -} | 70 | create_unimp(s, &s->txp, "bcm2835-txp", TXP_OFFSET, 0x1000); |
48 | - | 71 | create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); |
49 | -static bool trans_VNEG_sp(DisasContext *s, arg_VNEG_sp *a) | 72 | - create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x1000); |
50 | -{ | 73 | - create_unimp(s, &s->a2w, "bcm2835-a2w", A2W_OFFSET, 0x1000); |
51 | - return do_vfp_2op_sp(s, gen_helper_vfp_negs, a->vd, a->vm); | 74 | + create_unimp(s, &s->powermgt, "bcm2835-powermgt", PM_OFFSET, 0x114); |
52 | -} | 75 | + create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x2000); |
53 | - | 76 | create_unimp(s, &s->i2s, "bcm2835-i2s", I2S_OFFSET, 0x100); |
54 | -static bool trans_VNEG_dp(DisasContext *s, arg_VNEG_dp *a) | 77 | create_unimp(s, &s->smi, "bcm2835-smi", SMI_OFFSET, 0x100); |
55 | -{ | 78 | create_unimp(s, &s->spi[0], "bcm2835-spi0", SPI0_OFFSET, 0x20); |
56 | - return do_vfp_2op_dp(s, gen_helper_vfp_negd, a->vd, a->vm); | ||
57 | -} | ||
58 | +DO_VFP_2OP(VNEG, sp, gen_helper_vfp_negs) | ||
59 | +DO_VFP_2OP(VNEG, dp, gen_helper_vfp_negd) | ||
60 | |||
61 | static void gen_VSQRT_sp(TCGv_i32 vd, TCGv_i32 vm) | ||
62 | { | ||
63 | gen_helper_vfp_sqrts(vd, vm, cpu_env); | ||
64 | } | ||
65 | |||
66 | -static bool trans_VSQRT_sp(DisasContext *s, arg_VSQRT_sp *a) | ||
67 | -{ | ||
68 | - return do_vfp_2op_sp(s, gen_VSQRT_sp, a->vd, a->vm); | ||
69 | -} | ||
70 | - | ||
71 | static void gen_VSQRT_dp(TCGv_i64 vd, TCGv_i64 vm) | ||
72 | { | ||
73 | gen_helper_vfp_sqrtd(vd, vm, cpu_env); | ||
74 | } | ||
75 | |||
76 | -static bool trans_VSQRT_dp(DisasContext *s, arg_VSQRT_dp *a) | ||
77 | -{ | ||
78 | - return do_vfp_2op_dp(s, gen_VSQRT_dp, a->vd, a->vm); | ||
79 | -} | ||
80 | +DO_VFP_2OP(VSQRT, sp, gen_VSQRT_sp) | ||
81 | +DO_VFP_2OP(VSQRT, dp, gen_VSQRT_dp) | ||
82 | |||
83 | static bool trans_VCMP_sp(DisasContext *s, arg_VCMP_sp *a) | ||
84 | { | ||
85 | -- | 79 | -- |
86 | 2.20.1 | 80 | 2.20.1 |
87 | 81 | ||
88 | 82 | diff view generated by jsdifflib |
1 | Implement the fp16 versions of the VFP VLDR/VSTR (immediate). | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 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> | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20200828183354.27913-12-peter.maydell@linaro.org | ||
6 | --- | 16 | --- |
7 | target/arm/vfp.decode | 3 +-- | 17 | include/hw/arm/bcm2835_peripherals.h | 3 +- |
8 | target/arm/translate-vfp.c.inc | 35 ++++++++++++++++++++++++++++++++++ | 18 | include/hw/misc/bcm2835_cprman.h | 37 +++++ |
9 | 2 files changed, 36 insertions(+), 2 deletions(-) | 19 | include/hw/misc/bcm2835_cprman_internals.h | 24 +++ |
10 | 20 | hw/arm/bcm2835_peripherals.c | 11 +- | |
11 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | 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 | ||
12 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/vfp.decode | 31 | --- a/include/hw/arm/bcm2835_peripherals.h |
14 | +++ b/target/arm/vfp.decode | 32 | +++ b/include/hw/arm/bcm2835_peripherals.h |
15 | @@ -XXX,XX +XXX,XX @@ VMOV_single ---- 1110 000 l:1 .... rt:4 1010 . 001 0000 vn=%vn_sp | 33 | @@ -XXX,XX +XXX,XX @@ |
16 | VMOV_64_sp ---- 1100 010 op:1 rt2:4 rt:4 1010 00.1 .... vm=%vm_sp | 34 | #include "hw/misc/bcm2835_mbox.h" |
17 | VMOV_64_dp ---- 1100 010 op:1 rt2:4 rt:4 1011 00.1 .... vm=%vm_dp | 35 | #include "hw/misc/bcm2835_mphi.h" |
18 | 36 | #include "hw/misc/bcm2835_thermal.h" | |
19 | -# Note that the half-precision variants of VLDR and VSTR are | 37 | +#include "hw/misc/bcm2835_cprman.h" |
20 | -# not part of this decodetree at all because they have bits [9:8] == 0b01 | 38 | #include "hw/sd/sdhci.h" |
21 | +VLDR_VSTR_hp ---- 1101 u:1 .0 l:1 rn:4 .... 1001 imm:8 vd=%vd_sp | 39 | #include "hw/sd/bcm2835_sdhost.h" |
22 | VLDR_VSTR_sp ---- 1101 u:1 .0 l:1 rn:4 .... 1010 imm:8 vd=%vd_sp | 40 | #include "hw/gpio/bcm2835_gpio.h" |
23 | VLDR_VSTR_dp ---- 1101 u:1 .0 l:1 rn:4 .... 1011 imm:8 vd=%vd_dp | 41 | @@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState { |
24 | 42 | UnimplementedDeviceState txp; | |
25 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 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 | ||
26 | index XXXXXXX..XXXXXXX 100644 | 124 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/target/arm/translate-vfp.c.inc | 125 | --- a/hw/arm/bcm2835_peripherals.c |
28 | +++ b/target/arm/translate-vfp.c.inc | 126 | +++ b/hw/arm/bcm2835_peripherals.c |
29 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMOV_64_dp(DisasContext *s, arg_VMOV_64_dp *a) | 127 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj) |
30 | return true; | 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)); | ||
31 | } | 136 | } |
32 | 137 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | |
33 | +static bool trans_VLDR_VSTR_hp(DisasContext *s, arg_VLDR_VSTR_sp *a) | 138 | return; |
34 | +{ | 139 | } |
35 | + uint32_t offset; | 140 | |
36 | + TCGv_i32 addr, tmp; | 141 | + /* CPRMAN clock manager */ |
37 | + | 142 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->cprman), errp)) { |
38 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 143 | + return; |
39 | + return false; | ||
40 | + } | 144 | + } |
41 | + | 145 | + memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET, |
42 | + if (!vfp_access_check(s)) { | 146 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0)); |
43 | + return true; | 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]; | ||
44 | + } | 227 | + } |
45 | + | 228 | + |
46 | + /* imm8 field is offset/2 for fp16, unlike fp32 and fp64 */ | 229 | + trace_bcm2835_cprman_read(offset, r); |
47 | + offset = a->imm << 1; | 230 | + return r; |
48 | + if (!a->u) { | 231 | +} |
49 | + offset = -offset; | 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; | ||
50 | + } | 242 | + } |
51 | + | 243 | + |
52 | + /* For thumb, use of PC is UNPREDICTABLE. */ | 244 | + value &= ~R_CPRMAN_PASSWORD_MASK; |
53 | + addr = add_reg_for_lit(s, a->rn, offset); | 245 | + |
54 | + tmp = tcg_temp_new_i32(); | 246 | + trace_bcm2835_cprman_write(offset, value); |
55 | + if (a->l) { | 247 | + s->regs[idx] = value; |
56 | + gen_aa32_ld16u(s, tmp, addr, get_mem_index(s)); | 248 | + |
57 | + neon_store_reg32(tmp, a->vd); | 249 | +} |
58 | + } else { | 250 | + |
59 | + neon_load_reg32(tmp, a->vd); | 251 | +static const MemoryRegionOps cprman_ops = { |
60 | + gen_aa32_st16(s, tmp, addr, get_mem_index(s)); | 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() | ||
61 | + } | 297 | + } |
62 | + tcg_temp_free_i32(tmp); | 298 | +}; |
63 | + tcg_temp_free_i32(addr); | 299 | + |
64 | + | 300 | +static Property cprman_properties[] = { |
65 | + return true; | 301 | + DEFINE_PROP_UINT32("xosc-freq-hz", BCM2835CprmanState, xosc_freq, 19200000), |
66 | +} | 302 | + DEFINE_PROP_END_OF_LIST() |
67 | + | 303 | +}; |
68 | static bool trans_VLDR_VSTR_sp(DisasContext *s, arg_VLDR_VSTR_sp *a) | 304 | + |
69 | { | 305 | +static void cprman_class_init(ObjectClass *klass, void *data) |
70 | uint32_t offset; | 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 | ||
71 | -- | 353 | -- |
72 | 2.20.1 | 354 | 2.20.1 |
73 | 355 | ||
74 | 356 | diff view generated by jsdifflib |
1 | Implement fp16 versions of the VFP VMLA, VMLS, VNMLS, VNMLA, VNMUL | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | instructions. (These are all the remaining ones which we implement | 2 | |
3 | via do_vfp_3op_[hsd]p().) | 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 | |||
6 | This commit adds a skeleton implementation for the PLLs as sub-devices | ||
7 | of the CPRMAN. The PLLs are instantiated and connected internally to the | ||
8 | main oscillator. | ||
9 | |||
10 | Each PLL has 6 registers : CM, A2W_CTRL, A2W_ANA[0,1,2,3], A2W_FRAC. A | ||
11 | write to any of them triggers a call to the (not yet implemented) | ||
12 | pll_update function. | ||
13 | |||
14 | If the main oscillator changes frequency, an update is also triggered. | ||
15 | |||
16 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
18 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
19 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20200828183354.27913-5-peter.maydell@linaro.org | ||
8 | --- | 21 | --- |
9 | target/arm/helper.h | 1 + | 22 | include/hw/misc/bcm2835_cprman.h | 29 +++++ |
10 | target/arm/vfp.decode | 5 ++ | 23 | include/hw/misc/bcm2835_cprman_internals.h | 144 +++++++++++++++++++++ |
11 | target/arm/vfp_helper.c | 5 ++ | 24 | hw/misc/bcm2835_cprman.c | 108 ++++++++++++++++ |
12 | target/arm/translate-vfp.c.inc | 84 ++++++++++++++++++++++++++++++++++ | 25 | 3 files changed, 281 insertions(+) |
13 | 4 files changed, 95 insertions(+) | 26 | |
14 | 27 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | |
15 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/helper.h | 29 | --- a/include/hw/misc/bcm2835_cprman.h |
18 | +++ b/target/arm/helper.h | 30 | +++ b/include/hw/misc/bcm2835_cprman.h |
19 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(vfp_maxnumd, f64, f64, f64, ptr) | 31 | @@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(BCM2835CprmanState, CPRMAN, |
20 | DEF_HELPER_3(vfp_minnumh, f16, f16, f16, ptr) | 32 | |
21 | DEF_HELPER_3(vfp_minnums, f32, f32, f32, ptr) | 33 | #define CPRMAN_NUM_REGS (0x2000 / sizeof(uint32_t)) |
22 | DEF_HELPER_3(vfp_minnumd, f64, f64, f64, ptr) | 34 | |
23 | +DEF_HELPER_1(vfp_negh, f16, f16) | 35 | +typedef enum CprmanPll { |
24 | DEF_HELPER_1(vfp_negs, f32, f32) | 36 | + CPRMAN_PLLA = 0, |
25 | DEF_HELPER_1(vfp_negd, f64, f64) | 37 | + CPRMAN_PLLC, |
26 | DEF_HELPER_1(vfp_abss, f32, f32) | 38 | + CPRMAN_PLLD, |
27 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | 39 | + CPRMAN_PLLH, |
40 | + CPRMAN_PLLB, | ||
41 | + | ||
42 | + CPRMAN_NUM_PLL | ||
43 | +} CprmanPll; | ||
44 | + | ||
45 | +typedef struct CprmanPllState { | ||
46 | + /*< private >*/ | ||
47 | + DeviceState parent_obj; | ||
48 | + | ||
49 | + /*< public >*/ | ||
50 | + CprmanPll id; | ||
51 | + | ||
52 | + uint32_t *reg_cm; | ||
53 | + uint32_t *reg_a2w_ctrl; | ||
54 | + uint32_t *reg_a2w_ana; /* ANA[0] .. ANA[3] */ | ||
55 | + uint32_t prediv_mask; /* prediv bit in ana[1] */ | ||
56 | + uint32_t *reg_a2w_frac; | ||
57 | + | ||
58 | + Clock *xosc_in; | ||
59 | + Clock *out; | ||
60 | +} CprmanPllState; | ||
61 | + | ||
62 | struct BCM2835CprmanState { | ||
63 | /*< private >*/ | ||
64 | SysBusDevice parent_obj; | ||
65 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | ||
66 | /*< public >*/ | ||
67 | MemoryRegion iomem; | ||
68 | |||
69 | + CprmanPllState plls[CPRMAN_NUM_PLL]; | ||
70 | + | ||
71 | uint32_t regs[CPRMAN_NUM_REGS]; | ||
72 | uint32_t xosc_freq; | ||
73 | |||
74 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | 75 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/target/arm/vfp.decode | 76 | --- a/include/hw/misc/bcm2835_cprman_internals.h |
30 | +++ b/target/arm/vfp.decode | 77 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
31 | @@ -XXX,XX +XXX,XX @@ VLDM_VSTM_dp ---- 1101 0.1 l:1 rn:4 .... 1011 imm:8 \ | 78 | @@ -XXX,XX +XXX,XX @@ |
32 | vd=%vd_dp p=1 u=0 w=1 | 79 | #include "hw/registerfields.h" |
33 | 80 | #include "hw/misc/bcm2835_cprman.h" | |
34 | # 3-register VFP data-processing; bits [23,21:20,6] identify the operation. | 81 | |
35 | +VMLA_hp ---- 1110 0.00 .... .... 1001 .0.0 .... @vfp_dnm_s | 82 | +#define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" |
36 | VMLA_sp ---- 1110 0.00 .... .... 1010 .0.0 .... @vfp_dnm_s | 83 | + |
37 | VMLA_dp ---- 1110 0.00 .... .... 1011 .0.0 .... @vfp_dnm_d | 84 | +DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, |
38 | 85 | + TYPE_CPRMAN_PLL) | |
39 | +VMLS_hp ---- 1110 0.00 .... .... 1001 .1.0 .... @vfp_dnm_s | 86 | + |
40 | VMLS_sp ---- 1110 0.00 .... .... 1010 .1.0 .... @vfp_dnm_s | 87 | /* Register map */ |
41 | VMLS_dp ---- 1110 0.00 .... .... 1011 .1.0 .... @vfp_dnm_d | 88 | |
42 | 89 | +/* PLLs */ | |
43 | +VNMLS_hp ---- 1110 0.01 .... .... 1001 .0.0 .... @vfp_dnm_s | 90 | +REG32(CM_PLLA, 0x104) |
44 | VNMLS_sp ---- 1110 0.01 .... .... 1010 .0.0 .... @vfp_dnm_s | 91 | + FIELD(CM_PLLA, LOADDSI0, 0, 1) |
45 | VNMLS_dp ---- 1110 0.01 .... .... 1011 .0.0 .... @vfp_dnm_d | 92 | + FIELD(CM_PLLA, HOLDDSI0, 1, 1) |
46 | 93 | + FIELD(CM_PLLA, LOADCCP2, 2, 1) | |
47 | +VNMLA_hp ---- 1110 0.01 .... .... 1001 .1.0 .... @vfp_dnm_s | 94 | + FIELD(CM_PLLA, HOLDCCP2, 3, 1) |
48 | VNMLA_sp ---- 1110 0.01 .... .... 1010 .1.0 .... @vfp_dnm_s | 95 | + FIELD(CM_PLLA, LOADCORE, 4, 1) |
49 | VNMLA_dp ---- 1110 0.01 .... .... 1011 .1.0 .... @vfp_dnm_d | 96 | + FIELD(CM_PLLA, HOLDCORE, 5, 1) |
50 | 97 | + FIELD(CM_PLLA, LOADPER, 6, 1) | |
51 | @@ -XXX,XX +XXX,XX @@ VMUL_hp ---- 1110 0.10 .... .... 1001 .0.0 .... @vfp_dnm_s | 98 | + FIELD(CM_PLLA, HOLDPER, 7, 1) |
52 | VMUL_sp ---- 1110 0.10 .... .... 1010 .0.0 .... @vfp_dnm_s | 99 | + FIELD(CM_PLLx, ANARST, 8, 1) |
53 | VMUL_dp ---- 1110 0.10 .... .... 1011 .0.0 .... @vfp_dnm_d | 100 | +REG32(CM_PLLC, 0x108) |
54 | 101 | + FIELD(CM_PLLC, LOADCORE0, 0, 1) | |
55 | +VNMUL_hp ---- 1110 0.10 .... .... 1001 .1.0 .... @vfp_dnm_s | 102 | + FIELD(CM_PLLC, HOLDCORE0, 1, 1) |
56 | VNMUL_sp ---- 1110 0.10 .... .... 1010 .1.0 .... @vfp_dnm_s | 103 | + FIELD(CM_PLLC, LOADCORE1, 2, 1) |
57 | VNMUL_dp ---- 1110 0.10 .... .... 1011 .1.0 .... @vfp_dnm_d | 104 | + FIELD(CM_PLLC, HOLDCORE1, 3, 1) |
58 | 105 | + FIELD(CM_PLLC, LOADCORE2, 4, 1) | |
59 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | 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 | ||
60 | index XXXXXXX..XXXXXXX 100644 | 237 | index XXXXXXX..XXXXXXX 100644 |
61 | --- a/target/arm/vfp_helper.c | 238 | --- a/hw/misc/bcm2835_cprman.c |
62 | +++ b/target/arm/vfp_helper.c | 239 | +++ b/hw/misc/bcm2835_cprman.c |
63 | @@ -XXX,XX +XXX,XX @@ VFP_BINOP(minnum) | 240 | @@ -XXX,XX +XXX,XX @@ |
64 | VFP_BINOP(maxnum) | 241 | #include "hw/misc/bcm2835_cprman_internals.h" |
65 | #undef VFP_BINOP | 242 | #include "trace.h" |
66 | 243 | ||
67 | +dh_ctype_f16 VFP_HELPER(neg, h)(dh_ctype_f16 a) | 244 | +/* PLL */ |
68 | +{ | 245 | + |
69 | + return float16_chs(a); | 246 | +static void pll_update(CprmanPllState *pll) |
70 | +} | 247 | +{ |
71 | + | 248 | + clock_update(pll->out, 0); |
72 | float32 VFP_HELPER(neg, s)(float32 a) | 249 | +} |
250 | + | ||
251 | +static void pll_xosc_update(void *opaque) | ||
252 | +{ | ||
253 | + pll_update(CPRMAN_PLL(opaque)); | ||
254 | +} | ||
255 | + | ||
256 | +static void pll_init(Object *obj) | ||
257 | +{ | ||
258 | + CprmanPllState *s = CPRMAN_PLL(obj); | ||
259 | + | ||
260 | + s->xosc_in = qdev_init_clock_in(DEVICE(s), "xosc-in", pll_xosc_update, s); | ||
261 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); | ||
262 | +} | ||
263 | + | ||
264 | +static const VMStateDescription pll_vmstate = { | ||
265 | + .name = TYPE_CPRMAN_PLL, | ||
266 | + .version_id = 1, | ||
267 | + .minimum_version_id = 1, | ||
268 | + .fields = (VMStateField[]) { | ||
269 | + VMSTATE_CLOCK(xosc_in, CprmanPllState), | ||
270 | + VMSTATE_END_OF_LIST() | ||
271 | + } | ||
272 | +}; | ||
273 | + | ||
274 | +static void pll_class_init(ObjectClass *klass, void *data) | ||
275 | +{ | ||
276 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
277 | + | ||
278 | + dc->vmsd = &pll_vmstate; | ||
279 | +} | ||
280 | + | ||
281 | +static const TypeInfo cprman_pll_info = { | ||
282 | + .name = TYPE_CPRMAN_PLL, | ||
283 | + .parent = TYPE_DEVICE, | ||
284 | + .instance_size = sizeof(CprmanPllState), | ||
285 | + .class_init = pll_class_init, | ||
286 | + .instance_init = pll_init, | ||
287 | +}; | ||
288 | + | ||
289 | + | ||
290 | /* CPRMAN "top level" model */ | ||
291 | |||
292 | static uint64_t cprman_read(void *opaque, hwaddr offset, | ||
293 | @@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset, | ||
294 | return r; | ||
295 | } | ||
296 | |||
297 | +#define CASE_PLL_REGS(pll_) \ | ||
298 | + case R_CM_ ## pll_: \ | ||
299 | + case R_A2W_ ## pll_ ## _CTRL: \ | ||
300 | + case R_A2W_ ## pll_ ## _ANA0: \ | ||
301 | + case R_A2W_ ## pll_ ## _ANA1: \ | ||
302 | + case R_A2W_ ## pll_ ## _ANA2: \ | ||
303 | + case R_A2W_ ## pll_ ## _ANA3: \ | ||
304 | + case R_A2W_ ## pll_ ## _FRAC | ||
305 | + | ||
306 | static void cprman_write(void *opaque, hwaddr offset, | ||
307 | uint64_t value, unsigned size) | ||
73 | { | 308 | { |
74 | return float32_chs(a); | 309 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, |
75 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 310 | trace_bcm2835_cprman_write(offset, value); |
76 | index XXXXXXX..XXXXXXX 100644 | 311 | s->regs[idx] = value; |
77 | --- a/target/arm/translate-vfp.c.inc | 312 | |
78 | +++ b/target/arm/translate-vfp.c.inc | 313 | + switch (idx) { |
79 | @@ -XXX,XX +XXX,XX @@ static bool do_vfp_2op_dp(DisasContext *s, VFPGen2OpDPFn *fn, int vd, int vm) | 314 | + CASE_PLL_REGS(PLLA) : |
80 | return true; | 315 | + pll_update(&s->plls[CPRMAN_PLLA]); |
316 | + break; | ||
317 | + | ||
318 | + CASE_PLL_REGS(PLLC) : | ||
319 | + pll_update(&s->plls[CPRMAN_PLLC]); | ||
320 | + break; | ||
321 | + | ||
322 | + CASE_PLL_REGS(PLLD) : | ||
323 | + pll_update(&s->plls[CPRMAN_PLLD]); | ||
324 | + break; | ||
325 | + | ||
326 | + CASE_PLL_REGS(PLLH) : | ||
327 | + pll_update(&s->plls[CPRMAN_PLLH]); | ||
328 | + break; | ||
329 | + | ||
330 | + CASE_PLL_REGS(PLLB) : | ||
331 | + pll_update(&s->plls[CPRMAN_PLLB]); | ||
332 | + break; | ||
333 | + } | ||
81 | } | 334 | } |
82 | 335 | ||
83 | +static void gen_VMLA_hp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst) | 336 | +#undef CASE_PLL_REGS |
84 | +{ | 337 | + |
85 | + /* Note that order of inputs to the add matters for NaNs */ | 338 | static const MemoryRegionOps cprman_ops = { |
86 | + TCGv_i32 tmp = tcg_temp_new_i32(); | 339 | .read = cprman_read, |
87 | + | 340 | .write = cprman_write, |
88 | + gen_helper_vfp_mulh(tmp, vn, vm, fpst); | 341 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps cprman_ops = { |
89 | + gen_helper_vfp_addh(vd, vd, tmp, fpst); | 342 | static void cprman_reset(DeviceState *dev) |
90 | + tcg_temp_free_i32(tmp); | ||
91 | +} | ||
92 | + | ||
93 | +static bool trans_VMLA_hp(DisasContext *s, arg_VMLA_sp *a) | ||
94 | +{ | ||
95 | + return do_vfp_3op_hp(s, gen_VMLA_hp, a->vd, a->vn, a->vm, true); | ||
96 | +} | ||
97 | + | ||
98 | static void gen_VMLA_sp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst) | ||
99 | { | 343 | { |
100 | /* Note that order of inputs to the add matters for NaNs */ | 344 | BCM2835CprmanState *s = CPRMAN(dev); |
101 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMLA_dp(DisasContext *s, arg_VMLA_dp *a) | 345 | + size_t i; |
102 | return do_vfp_3op_dp(s, gen_VMLA_dp, a->vd, a->vn, a->vm, true); | 346 | |
347 | memset(s->regs, 0, sizeof(s->regs)); | ||
348 | |||
349 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { | ||
350 | + device_cold_reset(DEVICE(&s->plls[i])); | ||
351 | + } | ||
352 | + | ||
353 | clock_update_hz(s->xosc, s->xosc_freq); | ||
103 | } | 354 | } |
104 | 355 | ||
105 | +static void gen_VMLS_hp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst) | 356 | static void cprman_init(Object *obj) |
106 | +{ | ||
107 | + /* | ||
108 | + * VMLS: vd = vd + -(vn * vm) | ||
109 | + * Note that order of inputs to the add matters for NaNs. | ||
110 | + */ | ||
111 | + TCGv_i32 tmp = tcg_temp_new_i32(); | ||
112 | + | ||
113 | + gen_helper_vfp_mulh(tmp, vn, vm, fpst); | ||
114 | + gen_helper_vfp_negh(tmp, tmp); | ||
115 | + gen_helper_vfp_addh(vd, vd, tmp, fpst); | ||
116 | + tcg_temp_free_i32(tmp); | ||
117 | +} | ||
118 | + | ||
119 | +static bool trans_VMLS_hp(DisasContext *s, arg_VMLS_sp *a) | ||
120 | +{ | ||
121 | + return do_vfp_3op_hp(s, gen_VMLS_hp, a->vd, a->vn, a->vm, true); | ||
122 | +} | ||
123 | + | ||
124 | static void gen_VMLS_sp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst) | ||
125 | { | 357 | { |
126 | /* | 358 | BCM2835CprmanState *s = CPRMAN(obj); |
127 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMLS_dp(DisasContext *s, arg_VMLS_dp *a) | 359 | + size_t i; |
128 | return do_vfp_3op_dp(s, gen_VMLS_dp, a->vd, a->vn, a->vm, true); | 360 | + |
361 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { | ||
362 | + object_initialize_child(obj, PLL_INIT_INFO[i].name, | ||
363 | + &s->plls[i], TYPE_CPRMAN_PLL); | ||
364 | + set_pll_init_info(s, &s->plls[i], i); | ||
365 | + } | ||
366 | |||
367 | s->xosc = clock_new(obj, "xosc"); | ||
368 | |||
369 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) | ||
370 | sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); | ||
129 | } | 371 | } |
130 | 372 | ||
131 | +static void gen_VNMLS_hp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst) | 373 | +static void cprman_realize(DeviceState *dev, Error **errp) |
132 | +{ | 374 | +{ |
133 | + /* | 375 | + BCM2835CprmanState *s = CPRMAN(dev); |
134 | + * VNMLS: -fd + (fn * fm) | 376 | + size_t i; |
135 | + * Note that it isn't valid to replace (-A + B) with (B - A) or similar | 377 | + |
136 | + * plausible looking simplifications because this will give wrong results | 378 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { |
137 | + * for NaNs. | 379 | + CprmanPllState *pll = &s->plls[i]; |
138 | + */ | 380 | + |
139 | + TCGv_i32 tmp = tcg_temp_new_i32(); | 381 | + clock_set_source(pll->xosc_in, s->xosc); |
140 | + | 382 | + |
141 | + gen_helper_vfp_mulh(tmp, vn, vm, fpst); | 383 | + if (!qdev_realize(DEVICE(pll), NULL, errp)) { |
142 | + gen_helper_vfp_negh(vd, vd); | 384 | + return; |
143 | + gen_helper_vfp_addh(vd, vd, tmp, fpst); | 385 | + } |
144 | + tcg_temp_free_i32(tmp); | 386 | + } |
145 | +} | 387 | +} |
146 | + | 388 | + |
147 | +static bool trans_VNMLS_hp(DisasContext *s, arg_VNMLS_sp *a) | 389 | static const VMStateDescription cprman_vmstate = { |
148 | +{ | 390 | .name = TYPE_BCM2835_CPRMAN, |
149 | + return do_vfp_3op_hp(s, gen_VNMLS_hp, a->vd, a->vn, a->vm, true); | 391 | .version_id = 1, |
150 | +} | 392 | @@ -XXX,XX +XXX,XX @@ static void cprman_class_init(ObjectClass *klass, void *data) |
151 | + | ||
152 | static void gen_VNMLS_sp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst) | ||
153 | { | 393 | { |
154 | /* | 394 | DeviceClass *dc = DEVICE_CLASS(klass); |
155 | @@ -XXX,XX +XXX,XX @@ static bool trans_VNMLS_dp(DisasContext *s, arg_VNMLS_dp *a) | 395 | |
156 | return do_vfp_3op_dp(s, gen_VNMLS_dp, a->vd, a->vn, a->vm, true); | 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); | ||
157 | } | 405 | } |
158 | 406 | ||
159 | +static void gen_VNMLA_hp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst) | 407 | type_init(cprman_register_types); |
160 | +{ | ||
161 | + /* VNMLA: -fd + -(fn * fm) */ | ||
162 | + TCGv_i32 tmp = tcg_temp_new_i32(); | ||
163 | + | ||
164 | + gen_helper_vfp_mulh(tmp, vn, vm, fpst); | ||
165 | + gen_helper_vfp_negh(tmp, tmp); | ||
166 | + gen_helper_vfp_negh(vd, vd); | ||
167 | + gen_helper_vfp_addh(vd, vd, tmp, fpst); | ||
168 | + tcg_temp_free_i32(tmp); | ||
169 | +} | ||
170 | + | ||
171 | +static bool trans_VNMLA_hp(DisasContext *s, arg_VNMLA_sp *a) | ||
172 | +{ | ||
173 | + return do_vfp_3op_hp(s, gen_VNMLA_hp, a->vd, a->vn, a->vm, true); | ||
174 | +} | ||
175 | + | ||
176 | static void gen_VNMLA_sp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst) | ||
177 | { | ||
178 | /* VNMLA: -fd + -(fn * fm) */ | ||
179 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMUL_dp(DisasContext *s, arg_VMUL_dp *a) | ||
180 | return do_vfp_3op_dp(s, gen_helper_vfp_muld, a->vd, a->vn, a->vm, false); | ||
181 | } | ||
182 | |||
183 | +static void gen_VNMUL_hp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst) | ||
184 | +{ | ||
185 | + /* VNMUL: -(fn * fm) */ | ||
186 | + gen_helper_vfp_mulh(vd, vn, vm, fpst); | ||
187 | + gen_helper_vfp_negh(vd, vd); | ||
188 | +} | ||
189 | + | ||
190 | +static bool trans_VNMUL_hp(DisasContext *s, arg_VNMUL_sp *a) | ||
191 | +{ | ||
192 | + return do_vfp_3op_hp(s, gen_VNMUL_hp, a->vd, a->vn, a->vm, false); | ||
193 | +} | ||
194 | + | ||
195 | static void gen_VNMUL_sp(TCGv_i32 vd, TCGv_i32 vn, TCGv_i32 vm, TCGv_ptr fpst) | ||
196 | { | ||
197 | /* VNMUL: -(fn * fm) */ | ||
198 | -- | 408 | -- |
199 | 2.20.1 | 409 | 2.20.1 |
200 | 410 | ||
201 | 411 | diff view generated by jsdifflib |
1 | Implement fp16 version of VCMP. | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | The CPRMAN PLLs generate a clock based on a prescaler, a multiplier and | ||
4 | a divider. The prescaler doubles the parent (xosc) frequency, then the | ||
5 | multiplier/divider are applied. The multiplier has an integer and a | ||
6 | fractional part. | ||
7 | |||
8 | This commit also implements the CPRMAN CM_LOCK register. This register | ||
9 | reports which PLL is currently locked. We consider a PLL has being | ||
10 | locked as soon as it is enabled (on real hardware, there is a delay | ||
11 | after turning a PLL on, for it to stabilize). | ||
12 | |||
13 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
14 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
16 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20200828183354.27913-11-peter.maydell@linaro.org | ||
6 | --- | 18 | --- |
7 | target/arm/helper.h | 2 ++ | 19 | include/hw/misc/bcm2835_cprman_internals.h | 8 +++ |
8 | target/arm/vfp.decode | 2 ++ | 20 | hw/misc/bcm2835_cprman.c | 64 +++++++++++++++++++++- |
9 | target/arm/vfp_helper.c | 15 +++++++------ | 21 | 2 files changed, 71 insertions(+), 1 deletion(-) |
10 | target/arm/translate-vfp.c.inc | 39 ++++++++++++++++++++++++++++++++++ | ||
11 | 4 files changed, 51 insertions(+), 7 deletions(-) | ||
12 | 22 | ||
13 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 23 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h |
14 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.h | 25 | --- a/include/hw/misc/bcm2835_cprman_internals.h |
16 | +++ b/target/arm/helper.h | 26 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_1(vfp_absd, f64, f64) | 27 | @@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240) |
18 | DEF_HELPER_2(vfp_sqrth, f16, f16, env) | 28 | REG32(A2W_PLLH_FRAC, 0x1260) |
19 | DEF_HELPER_2(vfp_sqrts, f32, f32, env) | 29 | REG32(A2W_PLLB_FRAC, 0x12e0) |
20 | DEF_HELPER_2(vfp_sqrtd, f64, f64, env) | 30 | |
21 | +DEF_HELPER_3(vfp_cmph, void, f16, f16, env) | 31 | +/* misc registers */ |
22 | DEF_HELPER_3(vfp_cmps, void, f32, f32, env) | 32 | +REG32(CM_LOCK, 0x114) |
23 | DEF_HELPER_3(vfp_cmpd, void, f64, f64, env) | 33 | + FIELD(CM_LOCK, FLOCKH, 12, 1) |
24 | +DEF_HELPER_3(vfp_cmpeh, void, f16, f16, env) | 34 | + FIELD(CM_LOCK, FLOCKD, 11, 1) |
25 | DEF_HELPER_3(vfp_cmpes, void, f32, f32, env) | 35 | + FIELD(CM_LOCK, FLOCKC, 10, 1) |
26 | DEF_HELPER_3(vfp_cmped, void, f64, f64, env) | 36 | + FIELD(CM_LOCK, FLOCKB, 9, 1) |
27 | 37 | + FIELD(CM_LOCK, FLOCKA, 8, 1) | |
28 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | 38 | + |
39 | /* | ||
40 | * This field is common to all registers. Each register write value must match | ||
41 | * the CPRMAN_PASSWORD magic value in its 8 MSB. | ||
42 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | 43 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/vfp.decode | 44 | --- a/hw/misc/bcm2835_cprman.c |
31 | +++ b/target/arm/vfp.decode | 45 | +++ b/hw/misc/bcm2835_cprman.c |
32 | @@ -XXX,XX +XXX,XX @@ VSQRT_hp ---- 1110 1.11 0001 .... 1001 11.0 .... @vfp_dm_ss | 46 | @@ -XXX,XX +XXX,XX @@ |
33 | VSQRT_sp ---- 1110 1.11 0001 .... 1010 11.0 .... @vfp_dm_ss | 47 | |
34 | VSQRT_dp ---- 1110 1.11 0001 .... 1011 11.0 .... @vfp_dm_dd | 48 | /* PLL */ |
35 | 49 | ||
36 | +VCMP_hp ---- 1110 1.11 010 z:1 .... 1001 e:1 1.0 .... \ | 50 | +static bool pll_is_locked(const CprmanPllState *pll) |
37 | + vd=%vd_sp vm=%vm_sp | ||
38 | VCMP_sp ---- 1110 1.11 010 z:1 .... 1010 e:1 1.0 .... \ | ||
39 | vd=%vd_sp vm=%vm_sp | ||
40 | VCMP_dp ---- 1110 1.11 010 z:1 .... 1011 e:1 1.0 .... \ | ||
41 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/target/arm/vfp_helper.c | ||
44 | +++ b/target/arm/vfp_helper.c | ||
45 | @@ -XXX,XX +XXX,XX @@ static void softfloat_to_vfp_compare(CPUARMState *env, FloatRelation cmp) | ||
46 | } | ||
47 | |||
48 | /* XXX: check quiet/signaling case */ | ||
49 | -#define DO_VFP_cmp(p, type) \ | ||
50 | -void VFP_HELPER(cmp, p)(type a, type b, CPUARMState *env) \ | ||
51 | +#define DO_VFP_cmp(P, FLOATTYPE, ARGTYPE, FPST) \ | ||
52 | +void VFP_HELPER(cmp, P)(ARGTYPE a, ARGTYPE b, CPUARMState *env) \ | ||
53 | { \ | ||
54 | softfloat_to_vfp_compare(env, \ | ||
55 | - type ## _compare_quiet(a, b, &env->vfp.fp_status)); \ | ||
56 | + FLOATTYPE ## _compare_quiet(a, b, &env->vfp.FPST)); \ | ||
57 | } \ | ||
58 | -void VFP_HELPER(cmpe, p)(type a, type b, CPUARMState *env) \ | ||
59 | +void VFP_HELPER(cmpe, P)(ARGTYPE a, ARGTYPE b, CPUARMState *env) \ | ||
60 | { \ | ||
61 | softfloat_to_vfp_compare(env, \ | ||
62 | - type ## _compare(a, b, &env->vfp.fp_status)); \ | ||
63 | + FLOATTYPE ## _compare(a, b, &env->vfp.FPST)); \ | ||
64 | } | ||
65 | -DO_VFP_cmp(s, float32) | ||
66 | -DO_VFP_cmp(d, float64) | ||
67 | +DO_VFP_cmp(h, float16, dh_ctype_f16, fp_status_f16) | ||
68 | +DO_VFP_cmp(s, float32, float32, fp_status) | ||
69 | +DO_VFP_cmp(d, float64, float64, fp_status) | ||
70 | #undef DO_VFP_cmp | ||
71 | |||
72 | /* Integer to float and float to integer conversions */ | ||
73 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/target/arm/translate-vfp.c.inc | ||
76 | +++ b/target/arm/translate-vfp.c.inc | ||
77 | @@ -XXX,XX +XXX,XX @@ DO_VFP_2OP(VSQRT, hp, gen_VSQRT_hp) | ||
78 | DO_VFP_2OP(VSQRT, sp, gen_VSQRT_sp) | ||
79 | DO_VFP_2OP(VSQRT, dp, gen_VSQRT_dp) | ||
80 | |||
81 | +static bool trans_VCMP_hp(DisasContext *s, arg_VCMP_sp *a) | ||
82 | +{ | 51 | +{ |
83 | + TCGv_i32 vd, vm; | 52 | + return !FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PWRDN) |
53 | + && !FIELD_EX32(*pll->reg_cm, CM_PLLx, ANARST); | ||
54 | +} | ||
84 | + | 55 | + |
85 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 56 | static void pll_update(CprmanPllState *pll) |
86 | + return false; | 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; | ||
87 | + } | 64 | + } |
88 | + | 65 | + |
89 | + /* Vm/M bits must be zero for the Z variant */ | 66 | + pdiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, PDIV); |
90 | + if (a->z && a->vm != 0) { | 67 | + |
91 | + return false; | 68 | + if (!pdiv) { |
69 | + clock_update(pll->out, 0); | ||
70 | + return; | ||
92 | + } | 71 | + } |
93 | + | 72 | + |
94 | + if (!vfp_access_check(s)) { | 73 | + ndiv = FIELD_EX32(*pll->reg_a2w_ctrl, A2W_PLLx_CTRL, NDIV); |
95 | + return true; | 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; | ||
96 | + } | 80 | + } |
97 | + | 81 | + |
98 | + vd = tcg_temp_new_i32(); | 82 | + /* |
99 | + vm = tcg_temp_new_i32(); | 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; | ||
100 | + | 90 | + |
101 | + neon_load_reg32(vd, a->vd); | 91 | + clock_update_hz(pll->out, freq); |
102 | + if (a->z) { | 92 | } |
103 | + tcg_gen_movi_i32(vm, 0); | 93 | |
104 | + } else { | 94 | static void pll_xosc_update(void *opaque) |
105 | + neon_load_reg32(vm, a->vm); | 95 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { |
96 | |||
97 | /* CPRMAN "top level" model */ | ||
98 | |||
99 | +static uint32_t get_cm_lock(const BCM2835CprmanState *s) | ||
100 | +{ | ||
101 | + static const int CM_LOCK_MAPPING[CPRMAN_NUM_PLL] = { | ||
102 | + [CPRMAN_PLLA] = R_CM_LOCK_FLOCKA_SHIFT, | ||
103 | + [CPRMAN_PLLC] = R_CM_LOCK_FLOCKC_SHIFT, | ||
104 | + [CPRMAN_PLLD] = R_CM_LOCK_FLOCKD_SHIFT, | ||
105 | + [CPRMAN_PLLH] = R_CM_LOCK_FLOCKH_SHIFT, | ||
106 | + [CPRMAN_PLLB] = R_CM_LOCK_FLOCKB_SHIFT, | ||
107 | + }; | ||
108 | + | ||
109 | + uint32_t r = 0; | ||
110 | + size_t i; | ||
111 | + | ||
112 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { | ||
113 | + r |= pll_is_locked(&s->plls[i]) << CM_LOCK_MAPPING[i]; | ||
106 | + } | 114 | + } |
107 | + | 115 | + |
108 | + if (a->e) { | 116 | + return r; |
109 | + gen_helper_vfp_cmpeh(vd, vm, cpu_env); | ||
110 | + } else { | ||
111 | + gen_helper_vfp_cmph(vd, vm, cpu_env); | ||
112 | + } | ||
113 | + | ||
114 | + tcg_temp_free_i32(vd); | ||
115 | + tcg_temp_free_i32(vm); | ||
116 | + | ||
117 | + return true; | ||
118 | +} | 117 | +} |
119 | + | 118 | + |
120 | static bool trans_VCMP_sp(DisasContext *s, arg_VCMP_sp *a) | 119 | static uint64_t cprman_read(void *opaque, hwaddr offset, |
120 | unsigned size) | ||
121 | { | 121 | { |
122 | TCGv_i32 vd, vm; | 122 | @@ -XXX,XX +XXX,XX @@ static uint64_t cprman_read(void *opaque, hwaddr offset, |
123 | size_t idx = offset / sizeof(uint32_t); | ||
124 | |||
125 | switch (idx) { | ||
126 | + case R_CM_LOCK: | ||
127 | + r = get_cm_lock(s); | ||
128 | + break; | ||
129 | + | ||
130 | default: | ||
131 | r = s->regs[idx]; | ||
132 | } | ||
123 | -- | 133 | -- |
124 | 2.20.1 | 134 | 2.20.1 |
125 | 135 | ||
126 | 136 | diff view generated by jsdifflib |
1 | Convert the Neon VRECPS insn to using a gvec helper, and | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | use this to implement the fp16 case. | 2 | |
3 | 3 | PLLs are composed of multiple channels. Each channel outputs one clock | |
4 | The phrasing of the new float32_recps_nf() is slightly different from | 4 | signal. They are modeled as one device taking the PLL generated clock as |
5 | the old recps_f32() so that it parallels the f16 version; for f16 we | 5 | input, and outputting a new clock. |
6 | can't assume that flush-to-zero is always enabled. | 6 | |
7 | 7 | A channel shares the CM register with its parent PLL, and has its own | |
8 | A2W_CTRL register. A write to the CM register will trigger an update of | ||
9 | the PLL and all its channels, while a write to an A2W_CTRL channel | ||
10 | register will update the required channel only. | ||
11 | |||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
14 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
15 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20200828183354.27913-34-peter.maydell@linaro.org | ||
11 | --- | 17 | --- |
12 | target/arm/helper.h | 4 +++- | 18 | include/hw/misc/bcm2835_cprman.h | 44 ++++++ |
13 | target/arm/vec_helper.c | 31 +++++++++++++++++++++++++++++++ | 19 | include/hw/misc/bcm2835_cprman_internals.h | 146 +++++++++++++++++++ |
14 | target/arm/vfp_helper.c | 13 ------------- | 20 | hw/misc/bcm2835_cprman.c | 155 +++++++++++++++++++-- |
15 | target/arm/translate-neon.c.inc | 21 +-------------------- | 21 | 3 files changed, 337 insertions(+), 8 deletions(-) |
16 | 4 files changed, 35 insertions(+), 34 deletions(-) | 22 | |
17 | 23 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h | |
18 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/helper.h | 25 | --- a/include/hw/misc/bcm2835_cprman.h |
21 | +++ b/target/arm/helper.h | 26 | +++ b/include/hw/misc/bcm2835_cprman.h |
22 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_4(vfp_muladdd, f64, f64, f64, f64, ptr) | 27 | @@ -XXX,XX +XXX,XX @@ typedef enum CprmanPll { |
23 | DEF_HELPER_4(vfp_muladds, f32, f32, f32, f32, ptr) | 28 | CPRMAN_NUM_PLL |
24 | DEF_HELPER_4(vfp_muladdh, f16, f16, f16, f16, ptr) | 29 | } CprmanPll; |
25 | 30 | ||
26 | -DEF_HELPER_3(recps_f32, f32, env, f32, f32) | 31 | +typedef enum CprmanPllChannel { |
27 | DEF_HELPER_3(rsqrts_f32, f32, env, f32, f32) | 32 | + CPRMAN_PLLA_CHANNEL_DSI0 = 0, |
28 | DEF_HELPER_FLAGS_2(recpe_f16, TCG_CALL_NO_RWG, f16, f16, ptr) | 33 | + CPRMAN_PLLA_CHANNEL_CORE, |
29 | DEF_HELPER_FLAGS_2(recpe_f32, TCG_CALL_NO_RWG, f32, f32, ptr) | 34 | + CPRMAN_PLLA_CHANNEL_PER, |
30 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fmaxnum_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i3 | 35 | + CPRMAN_PLLA_CHANNEL_CCP2, |
31 | DEF_HELPER_FLAGS_5(gvec_fminnum_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 36 | + |
32 | DEF_HELPER_FLAGS_5(gvec_fminnum_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 37 | + CPRMAN_PLLC_CHANNEL_CORE2, |
33 | 38 | + CPRMAN_PLLC_CHANNEL_CORE1, | |
34 | +DEF_HELPER_FLAGS_5(gvec_recps_nf_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 39 | + CPRMAN_PLLC_CHANNEL_PER, |
35 | +DEF_HELPER_FLAGS_5(gvec_recps_nf_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 40 | + CPRMAN_PLLC_CHANNEL_CORE0, |
36 | + | 41 | + |
37 | DEF_HELPER_FLAGS_5(gvec_fmla_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 42 | + CPRMAN_PLLD_CHANNEL_DSI0, |
38 | DEF_HELPER_FLAGS_5(gvec_fmla_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 43 | + CPRMAN_PLLD_CHANNEL_CORE, |
39 | 44 | + CPRMAN_PLLD_CHANNEL_PER, | |
40 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 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 | ||
41 | index XXXXXXX..XXXXXXX 100644 | 93 | index XXXXXXX..XXXXXXX 100644 |
42 | --- a/target/arm/vec_helper.c | 94 | --- a/include/hw/misc/bcm2835_cprman_internals.h |
43 | +++ b/target/arm/vec_helper.c | 95 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
44 | @@ -XXX,XX +XXX,XX @@ static float32 float32_abd(float32 op1, float32 op2, float_status *stat) | 96 | @@ -XXX,XX +XXX,XX @@ |
45 | return float32_abs(float32_sub(op1, op2, stat)); | 97 | #include "hw/misc/bcm2835_cprman.h" |
46 | } | 98 | |
47 | 99 | #define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" | |
48 | +/* | 100 | +#define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel" |
49 | + * Reciprocal step. These are the AArch32 version which uses a | 101 | |
50 | + * non-fused multiply-and-subtract. | 102 | DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, |
51 | + */ | 103 | TYPE_CPRMAN_PLL) |
52 | +static float16 float16_recps_nf(float16 op1, float16 op2, float_status *stat) | 104 | +DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL, |
53 | +{ | 105 | + TYPE_CPRMAN_PLL_CHANNEL) |
54 | + op1 = float16_squash_input_denormal(op1, stat); | 106 | |
55 | + op2 = float16_squash_input_denormal(op2, stat); | 107 | /* Register map */ |
56 | + | 108 | |
57 | + if ((float16_is_infinity(op1) && float16_is_zero(op2)) || | 109 | @@ -XXX,XX +XXX,XX @@ REG32(A2W_PLLD_FRAC, 0x1240) |
58 | + (float16_is_infinity(op2) && float16_is_zero(op1))) { | 110 | REG32(A2W_PLLH_FRAC, 0x1260) |
59 | + return float16_two; | 111 | REG32(A2W_PLLB_FRAC, 0x12e0) |
60 | + } | 112 | |
61 | + return float16_sub(float16_two, float16_mul(op1, op2, stat), stat); | 113 | +/* PLL channels */ |
62 | +} | 114 | +REG32(A2W_PLLA_DSI0, 0x1300) |
63 | + | 115 | + FIELD(A2W_PLLx_CHANNELy, DIV, 0, 8) |
64 | +static float32 float32_recps_nf(float32 op1, float32 op2, float_status *stat) | 116 | + FIELD(A2W_PLLx_CHANNELy, DISABLE, 8, 1) |
65 | +{ | 117 | +REG32(A2W_PLLA_CORE, 0x1400) |
66 | + op1 = float32_squash_input_denormal(op1, stat); | 118 | +REG32(A2W_PLLA_PER, 0x1500) |
67 | + op2 = float32_squash_input_denormal(op2, stat); | 119 | +REG32(A2W_PLLA_CCP2, 0x1600) |
68 | + | 120 | + |
69 | + if ((float32_is_infinity(op1) && float32_is_zero(op2)) || | 121 | +REG32(A2W_PLLC_CORE2, 0x1320) |
70 | + (float32_is_infinity(op2) && float32_is_zero(op1))) { | 122 | +REG32(A2W_PLLC_CORE1, 0x1420) |
71 | + return float32_two; | 123 | +REG32(A2W_PLLC_PER, 0x1520) |
72 | + } | 124 | +REG32(A2W_PLLC_CORE0, 0x1620) |
73 | + return float32_sub(float32_two, float32_mul(op1, op2, stat), stat); | 125 | + |
74 | +} | 126 | +REG32(A2W_PLLD_DSI0, 0x1340) |
75 | + | 127 | +REG32(A2W_PLLD_CORE, 0x1440) |
76 | #define DO_3OP(NAME, FUNC, TYPE) \ | 128 | +REG32(A2W_PLLD_PER, 0x1540) |
77 | void HELPER(NAME)(void *vd, void *vn, void *vm, void *stat, uint32_t desc) \ | 129 | +REG32(A2W_PLLD_DSI1, 0x1640) |
78 | { \ | 130 | + |
79 | @@ -XXX,XX +XXX,XX @@ DO_3OP(gvec_fmaxnum_s, float32_maxnum, float32) | 131 | +REG32(A2W_PLLH_AUX, 0x1360) |
80 | DO_3OP(gvec_fminnum_h, float16_minnum, float16) | 132 | +REG32(A2W_PLLH_RCAL, 0x1460) |
81 | DO_3OP(gvec_fminnum_s, float32_minnum, float32) | 133 | +REG32(A2W_PLLH_PIX, 0x1560) |
82 | 134 | +REG32(A2W_PLLH_STS, 0x1660) | |
83 | +DO_3OP(gvec_recps_nf_h, float16_recps_nf, float16) | 135 | + |
84 | +DO_3OP(gvec_recps_nf_s, float32_recps_nf, float32) | 136 | +REG32(A2W_PLLB_ARM, 0x13e0) |
85 | + | 137 | + |
86 | #ifdef TARGET_AARCH64 | 138 | /* misc registers */ |
87 | 139 | REG32(CM_LOCK, 0x114) | |
88 | DO_3OP(gvec_recps_h, helper_recpsf_f16, float16) | 140 | FIELD(CM_LOCK, FLOCKH, 12, 1) |
89 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | 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 | ||
90 | index XXXXXXX..XXXXXXX 100644 | 265 | index XXXXXXX..XXXXXXX 100644 |
91 | --- a/target/arm/vfp_helper.c | 266 | --- a/hw/misc/bcm2835_cprman.c |
92 | +++ b/target/arm/vfp_helper.c | 267 | +++ b/hw/misc/bcm2835_cprman.c |
93 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(vfp_fcvt_f64_to_f16)(float64 a, void *fpstp, uint32_t ahp_mode) | 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, | ||
94 | return r; | 339 | return r; |
95 | } | 340 | } |
96 | 341 | ||
97 | -float32 HELPER(recps_f32)(CPUARMState *env, float32 a, float32 b) | 342 | -#define CASE_PLL_REGS(pll_) \ |
98 | -{ | 343 | - case R_CM_ ## pll_: \ |
99 | - float_status *s = &env->vfp.standard_fp_status; | 344 | +static inline void update_pll_and_channels_from_cm(BCM2835CprmanState *s, |
100 | - if ((float32_is_infinity(a) && float32_is_zero_or_denormal(b)) || | 345 | + size_t idx) |
101 | - (float32_is_infinity(b) && float32_is_zero_or_denormal(a))) { | 346 | +{ |
102 | - if (!(float32_is_zero(a) || float32_is_zero(b))) { | 347 | + size_t i; |
103 | - float_raise(float_flag_input_denormal, s); | 348 | + |
104 | - } | 349 | + for (i = 0; i < CPRMAN_NUM_PLL; i++) { |
105 | - return float32_two; | 350 | + if (PLL_INIT_INFO[i].cm_offset == idx) { |
106 | - } | 351 | + pll_update_all_channels(s, &s->plls[i]); |
107 | - return float32_sub(float32_two, float32_mul(a, b, s), s); | 352 | + return; |
108 | -} | 353 | + } |
109 | - | 354 | + } |
110 | float32 HELPER(rsqrts_f32)(CPUARMState *env, float32 a, float32 b) | 355 | +} |
356 | + | ||
357 | +static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx) | ||
358 | +{ | ||
359 | + size_t i; | ||
360 | + | ||
361 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | ||
362 | + if (PLL_CHANNEL_INIT_INFO[i].a2w_ctrl_offset == idx) { | ||
363 | + pll_channel_update(&s->channels[i]); | ||
364 | + return; | ||
365 | + } | ||
366 | + } | ||
367 | +} | ||
368 | + | ||
369 | +#define CASE_PLL_A2W_REGS(pll_) \ | ||
370 | case R_A2W_ ## pll_ ## _CTRL: \ | ||
371 | case R_A2W_ ## pll_ ## _ANA0: \ | ||
372 | case R_A2W_ ## pll_ ## _ANA1: \ | ||
373 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, | ||
374 | s->regs[idx] = value; | ||
375 | |||
376 | switch (idx) { | ||
377 | - CASE_PLL_REGS(PLLA) : | ||
378 | + case R_CM_PLLA ... R_CM_PLLH: | ||
379 | + case R_CM_PLLB: | ||
380 | + /* | ||
381 | + * A given CM_PLLx register is shared by both the PLL and the channels | ||
382 | + * of this PLL. | ||
383 | + */ | ||
384 | + update_pll_and_channels_from_cm(s, idx); | ||
385 | + break; | ||
386 | + | ||
387 | + CASE_PLL_A2W_REGS(PLLA) : | ||
388 | pll_update(&s->plls[CPRMAN_PLLA]); | ||
389 | break; | ||
390 | |||
391 | - CASE_PLL_REGS(PLLC) : | ||
392 | + CASE_PLL_A2W_REGS(PLLC) : | ||
393 | pll_update(&s->plls[CPRMAN_PLLC]); | ||
394 | break; | ||
395 | |||
396 | - CASE_PLL_REGS(PLLD) : | ||
397 | + CASE_PLL_A2W_REGS(PLLD) : | ||
398 | pll_update(&s->plls[CPRMAN_PLLD]); | ||
399 | break; | ||
400 | |||
401 | - CASE_PLL_REGS(PLLH) : | ||
402 | + CASE_PLL_A2W_REGS(PLLH) : | ||
403 | pll_update(&s->plls[CPRMAN_PLLH]); | ||
404 | break; | ||
405 | |||
406 | - CASE_PLL_REGS(PLLB) : | ||
407 | + CASE_PLL_A2W_REGS(PLLB) : | ||
408 | pll_update(&s->plls[CPRMAN_PLLB]); | ||
409 | break; | ||
410 | + | ||
411 | + case R_A2W_PLLA_DSI0: | ||
412 | + case R_A2W_PLLA_CORE: | ||
413 | + case R_A2W_PLLA_PER: | ||
414 | + case R_A2W_PLLA_CCP2: | ||
415 | + case R_A2W_PLLC_CORE2: | ||
416 | + case R_A2W_PLLC_CORE1: | ||
417 | + case R_A2W_PLLC_PER: | ||
418 | + case R_A2W_PLLC_CORE0: | ||
419 | + case R_A2W_PLLD_DSI0: | ||
420 | + case R_A2W_PLLD_CORE: | ||
421 | + case R_A2W_PLLD_PER: | ||
422 | + case R_A2W_PLLD_DSI1: | ||
423 | + case R_A2W_PLLH_AUX: | ||
424 | + case R_A2W_PLLH_RCAL: | ||
425 | + case R_A2W_PLLH_PIX: | ||
426 | + case R_A2W_PLLB_ARM: | ||
427 | + update_channel_from_a2w(s, idx); | ||
428 | + break; | ||
429 | } | ||
430 | } | ||
431 | |||
432 | -#undef CASE_PLL_REGS | ||
433 | +#undef CASE_PLL_A2W_REGS | ||
434 | |||
435 | static const MemoryRegionOps cprman_ops = { | ||
436 | .read = cprman_read, | ||
437 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) | ||
438 | device_cold_reset(DEVICE(&s->plls[i])); | ||
439 | } | ||
440 | |||
441 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | ||
442 | + device_cold_reset(DEVICE(&s->channels[i])); | ||
443 | + } | ||
444 | + | ||
445 | clock_update_hz(s->xosc, s->xosc_freq); | ||
446 | } | ||
447 | |||
448 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) | ||
449 | set_pll_init_info(s, &s->plls[i], i); | ||
450 | } | ||
451 | |||
452 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | ||
453 | + object_initialize_child(obj, PLL_CHANNEL_INIT_INFO[i].name, | ||
454 | + &s->channels[i], | ||
455 | + TYPE_CPRMAN_PLL_CHANNEL); | ||
456 | + set_pll_channel_init_info(s, &s->channels[i], i); | ||
457 | + } | ||
458 | + | ||
459 | s->xosc = clock_new(obj, "xosc"); | ||
460 | |||
461 | memory_region_init_io(&s->iomem, obj, &cprman_ops, | ||
462 | @@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp) | ||
463 | return; | ||
464 | } | ||
465 | } | ||
466 | + | ||
467 | + for (i = 0; i < CPRMAN_NUM_PLL_CHANNEL; i++) { | ||
468 | + CprmanPllChannelState *channel = &s->channels[i]; | ||
469 | + CprmanPll parent = PLL_CHANNEL_INIT_INFO[i].parent; | ||
470 | + Clock *parent_clk = s->plls[parent].out; | ||
471 | + | ||
472 | + clock_set_source(channel->pll_in, parent_clk); | ||
473 | + | ||
474 | + if (!qdev_realize(DEVICE(channel), NULL, errp)) { | ||
475 | + return; | ||
476 | + } | ||
477 | + } | ||
478 | } | ||
479 | |||
480 | static const VMStateDescription cprman_vmstate = { | ||
481 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) | ||
111 | { | 482 | { |
112 | float_status *s = &env->vfp.standard_fp_status; | 483 | type_register_static(&cprman_info); |
113 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | 484 | type_register_static(&cprman_pll_info); |
114 | index XXXXXXX..XXXXXXX 100644 | 485 | + type_register_static(&cprman_pll_channel_info); |
115 | --- a/target/arm/translate-neon.c.inc | 486 | } |
116 | +++ b/target/arm/translate-neon.c.inc | 487 | |
117 | @@ -XXX,XX +XXX,XX @@ DO_3S_FP_GVEC(VMLA, gen_helper_gvec_fmla_s, gen_helper_gvec_fmla_h) | 488 | type_init(cprman_register_types); |
118 | DO_3S_FP_GVEC(VMLS, gen_helper_gvec_fmls_s, gen_helper_gvec_fmls_h) | ||
119 | DO_3S_FP_GVEC(VFMA, gen_helper_gvec_vfma_s, gen_helper_gvec_vfma_h) | ||
120 | DO_3S_FP_GVEC(VFMS, gen_helper_gvec_vfms_s, gen_helper_gvec_vfms_h) | ||
121 | +DO_3S_FP_GVEC(VRECPS, gen_helper_gvec_recps_nf_s, gen_helper_gvec_recps_nf_h) | ||
122 | |||
123 | WRAP_FP_GVEC(gen_VMAXNM_fp32_3s, FPST_STD, gen_helper_gvec_fmaxnum_s) | ||
124 | WRAP_FP_GVEC(gen_VMAXNM_fp16_3s, FPST_STD_F16, gen_helper_gvec_fmaxnum_h) | ||
125 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMINNM_fp_3s(DisasContext *s, arg_3same *a) | ||
126 | return do_3same(s, a, gen_VMINNM_fp32_3s); | ||
127 | } | ||
128 | |||
129 | -WRAP_ENV_FN(gen_VRECPS_tramp, gen_helper_recps_f32) | ||
130 | - | ||
131 | -static void gen_VRECPS_fp_3s(unsigned vece, uint32_t rd_ofs, | ||
132 | - uint32_t rn_ofs, uint32_t rm_ofs, | ||
133 | - uint32_t oprsz, uint32_t maxsz) | ||
134 | -{ | ||
135 | - static const GVecGen3 ops = { .fni4 = gen_VRECPS_tramp }; | ||
136 | - tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, &ops); | ||
137 | -} | ||
138 | - | ||
139 | -static bool trans_VRECPS_fp_3s(DisasContext *s, arg_3same *a) | ||
140 | -{ | ||
141 | - if (a->size != 0) { | ||
142 | - /* TODO fp16 support */ | ||
143 | - return false; | ||
144 | - } | ||
145 | - | ||
146 | - return do_3same(s, a, gen_VRECPS_fp_3s); | ||
147 | -} | ||
148 | - | ||
149 | WRAP_ENV_FN(gen_VRSQRTS_tramp, gen_helper_rsqrts_f32) | ||
150 | |||
151 | static void gen_VRSQRTS_fp_3s(unsigned vece, uint32_t rd_ofs, | ||
152 | -- | 489 | -- |
153 | 2.20.1 | 490 | 2.20.1 |
154 | 491 | ||
155 | 492 | diff view generated by jsdifflib |
1 | Implement the fp16 version of the VFP VRINT* insns. | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 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> | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20200828183354.27913-19-peter.maydell@linaro.org | ||
6 | --- | 12 | --- |
7 | target/arm/helper.h | 2 + | 13 | hw/misc/bcm2835_cprman.c | 33 ++++++++++++++++++++++++++++++++- |
8 | target/arm/vfp-uncond.decode | 6 ++- | 14 | 1 file changed, 32 insertions(+), 1 deletion(-) |
9 | target/arm/vfp.decode | 3 ++ | ||
10 | target/arm/vfp_helper.c | 21 ++++++++ | ||
11 | target/arm/translate-vfp.c.inc | 98 +++++++++++++++++++++++++++++++--- | ||
12 | 5 files changed, 122 insertions(+), 8 deletions(-) | ||
13 | 15 | ||
14 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 16 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/helper.h | 18 | --- a/hw/misc/bcm2835_cprman.c |
17 | +++ b/target/arm/helper.h | 19 | +++ b/hw/misc/bcm2835_cprman.c |
18 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(shr_cc, i32, env, i32, i32) | 20 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_info = { |
19 | DEF_HELPER_3(sar_cc, i32, env, i32, i32) | 21 | |
20 | DEF_HELPER_3(ror_cc, i32, env, i32, i32) | 22 | /* PLL channel */ |
21 | 23 | ||
22 | +DEF_HELPER_FLAGS_2(rinth_exact, TCG_CALL_NO_RWG, f16, f16, ptr) | 24 | +static bool pll_channel_is_enabled(CprmanPllChannelState *channel) |
23 | DEF_HELPER_FLAGS_2(rints_exact, TCG_CALL_NO_RWG, f32, f32, ptr) | ||
24 | DEF_HELPER_FLAGS_2(rintd_exact, TCG_CALL_NO_RWG, f64, f64, ptr) | ||
25 | +DEF_HELPER_FLAGS_2(rinth, TCG_CALL_NO_RWG, f16, f16, ptr) | ||
26 | DEF_HELPER_FLAGS_2(rints, TCG_CALL_NO_RWG, f32, f32, ptr) | ||
27 | DEF_HELPER_FLAGS_2(rintd, TCG_CALL_NO_RWG, f64, f64, ptr) | ||
28 | |||
29 | diff --git a/target/arm/vfp-uncond.decode b/target/arm/vfp-uncond.decode | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/arm/vfp-uncond.decode | ||
32 | +++ b/target/arm/vfp-uncond.decode | ||
33 | @@ -XXX,XX +XXX,XX @@ VMINNM_sp 1111 1110 1.00 .... .... 1010 .1.0 .... @vfp_dnm_s | ||
34 | VMAXNM_dp 1111 1110 1.00 .... .... 1011 .0.0 .... @vfp_dnm_d | ||
35 | VMINNM_dp 1111 1110 1.00 .... .... 1011 .1.0 .... @vfp_dnm_d | ||
36 | |||
37 | +VRINT 1111 1110 1.11 10 rm:2 .... 1001 01.0 .... \ | ||
38 | + vm=%vm_sp vd=%vd_sp sz=1 | ||
39 | VRINT 1111 1110 1.11 10 rm:2 .... 1010 01.0 .... \ | ||
40 | - vm=%vm_sp vd=%vd_sp dp=0 | ||
41 | + vm=%vm_sp vd=%vd_sp sz=2 | ||
42 | VRINT 1111 1110 1.11 10 rm:2 .... 1011 01.0 .... \ | ||
43 | - vm=%vm_dp vd=%vd_dp dp=1 | ||
44 | + vm=%vm_dp vd=%vd_dp sz=3 | ||
45 | |||
46 | # VCVT float to int with specified rounding mode; Vd is always single-precision | ||
47 | VCVT 1111 1110 1.11 11 rm:2 .... 1001 op:1 1.0 .... \ | ||
48 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/target/arm/vfp.decode | ||
51 | +++ b/target/arm/vfp.decode | ||
52 | @@ -XXX,XX +XXX,XX @@ VCVT_f16_f32 ---- 1110 1.11 0011 .... 1010 t:1 1.0 .... \ | ||
53 | VCVT_f16_f64 ---- 1110 1.11 0011 .... 1011 t:1 1.0 .... \ | ||
54 | vd=%vd_sp vm=%vm_dp | ||
55 | |||
56 | +VRINTR_hp ---- 1110 1.11 0110 .... 1001 01.0 .... @vfp_dm_ss | ||
57 | VRINTR_sp ---- 1110 1.11 0110 .... 1010 01.0 .... @vfp_dm_ss | ||
58 | VRINTR_dp ---- 1110 1.11 0110 .... 1011 01.0 .... @vfp_dm_dd | ||
59 | |||
60 | +VRINTZ_hp ---- 1110 1.11 0110 .... 1001 11.0 .... @vfp_dm_ss | ||
61 | VRINTZ_sp ---- 1110 1.11 0110 .... 1010 11.0 .... @vfp_dm_ss | ||
62 | VRINTZ_dp ---- 1110 1.11 0110 .... 1011 11.0 .... @vfp_dm_dd | ||
63 | |||
64 | +VRINTX_hp ---- 1110 1.11 0111 .... 1001 01.0 .... @vfp_dm_ss | ||
65 | VRINTX_sp ---- 1110 1.11 0111 .... 1010 01.0 .... @vfp_dm_ss | ||
66 | VRINTX_dp ---- 1110 1.11 0111 .... 1011 01.0 .... @vfp_dm_dd | ||
67 | |||
68 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | ||
69 | index XXXXXXX..XXXXXXX 100644 | ||
70 | --- a/target/arm/vfp_helper.c | ||
71 | +++ b/target/arm/vfp_helper.c | ||
72 | @@ -XXX,XX +XXX,XX @@ float64 VFP_HELPER(muladd, d)(float64 a, float64 b, float64 c, void *fpstp) | ||
73 | } | ||
74 | |||
75 | /* ARMv8 round to integral */ | ||
76 | +dh_ctype_f16 HELPER(rinth_exact)(dh_ctype_f16 x, void *fp_status) | ||
77 | +{ | 25 | +{ |
78 | + return float16_round_to_int(x, fp_status); | 26 | + /* |
27 | + * XXX I'm not sure of the purpose of the LOAD field. The Linux driver does | ||
28 | + * not set it when enabling the channel, but does clear it when disabling | ||
29 | + * it. | ||
30 | + */ | ||
31 | + return !FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DISABLE) | ||
32 | + && !(*channel->reg_cm & channel->hold_mask); | ||
79 | +} | 33 | +} |
80 | + | 34 | + |
81 | float32 HELPER(rints_exact)(float32 x, void *fp_status) | 35 | static void pll_channel_update(CprmanPllChannelState *channel) |
82 | { | 36 | { |
83 | return float32_round_to_int(x, fp_status); | 37 | - clock_update(channel->out, 0); |
84 | @@ -XXX,XX +XXX,XX @@ float64 HELPER(rintd_exact)(float64 x, void *fp_status) | 38 | + uint64_t freq, div; |
85 | return float64_round_to_int(x, fp_status); | ||
86 | } | ||
87 | |||
88 | +dh_ctype_f16 HELPER(rinth)(dh_ctype_f16 x, void *fp_status) | ||
89 | +{ | ||
90 | + int old_flags = get_float_exception_flags(fp_status), new_flags; | ||
91 | + float16 ret; | ||
92 | + | 39 | + |
93 | + ret = float16_round_to_int(x, fp_status); | 40 | + if (!pll_channel_is_enabled(channel)) { |
94 | + | 41 | + clock_update(channel->out, 0); |
95 | + /* Suppress any inexact exceptions the conversion produced */ | 42 | + return; |
96 | + if (!(old_flags & float_flag_inexact)) { | ||
97 | + new_flags = get_float_exception_flags(fp_status); | ||
98 | + set_float_exception_flags(new_flags & ~float_flag_inexact, fp_status); | ||
99 | + } | 43 | + } |
100 | + | 44 | + |
101 | + return ret; | 45 | + div = FIELD_EX32(*channel->reg_a2w_ctrl, A2W_PLLx_CHANNELy, DIV); |
102 | +} | ||
103 | + | 46 | + |
104 | float32 HELPER(rints)(float32 x, void *fp_status) | 47 | + if (!div) { |
105 | { | 48 | + /* |
106 | int old_flags = get_float_exception_flags(fp_status), new_flags; | 49 | + * It seems that when the divider value is 0, it is considered as |
107 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 50 | + * being maximum by the hardware (see the Linux driver). |
108 | index XXXXXXX..XXXXXXX 100644 | 51 | + */ |
109 | --- a/target/arm/translate-vfp.c.inc | 52 | + div = R_A2W_PLLx_CHANNELy_DIV_MASK; |
110 | +++ b/target/arm/translate-vfp.c.inc | ||
111 | @@ -XXX,XX +XXX,XX @@ static const uint8_t fp_decode_rm[] = { | ||
112 | static bool trans_VRINT(DisasContext *s, arg_VRINT *a) | ||
113 | { | ||
114 | uint32_t rd, rm; | ||
115 | - bool dp = a->dp; | ||
116 | + int sz = a->sz; | ||
117 | TCGv_ptr fpst; | ||
118 | TCGv_i32 tcg_rmode; | ||
119 | int rounding = fp_decode_rm[a->rm]; | ||
120 | @@ -XXX,XX +XXX,XX @@ static bool trans_VRINT(DisasContext *s, arg_VRINT *a) | ||
121 | return false; | ||
122 | } | ||
123 | |||
124 | - if (dp && !dc_isar_feature(aa32_fpdp_v2, s)) { | ||
125 | + if (sz == 3 && !dc_isar_feature(aa32_fpdp_v2, s)) { | ||
126 | + return false; | ||
127 | + } | 53 | + } |
128 | + | 54 | + |
129 | + if (sz == 1 && !dc_isar_feature(aa32_fp16_arith, s)) { | 55 | + /* Some channels have an additional fixed divider */ |
130 | return false; | 56 | + freq = clock_get_hz(channel->pll_in) / (div * channel->fixed_divider); |
131 | } | 57 | + |
132 | 58 | + clock_update_hz(channel->out, freq); | |
133 | /* UNDEF accesses to D16-D31 if they don't exist */ | ||
134 | - if (dp && !dc_isar_feature(aa32_simd_r32, s) && | ||
135 | + if (sz == 3 && !dc_isar_feature(aa32_simd_r32, s) && | ||
136 | ((a->vm | a->vd) & 0x10)) { | ||
137 | return false; | ||
138 | } | ||
139 | @@ -XXX,XX +XXX,XX @@ static bool trans_VRINT(DisasContext *s, arg_VRINT *a) | ||
140 | return true; | ||
141 | } | ||
142 | |||
143 | - fpst = fpstatus_ptr(FPST_FPCR); | ||
144 | + if (sz == 1) { | ||
145 | + fpst = fpstatus_ptr(FPST_FPCR_F16); | ||
146 | + } else { | ||
147 | + fpst = fpstatus_ptr(FPST_FPCR); | ||
148 | + } | ||
149 | |||
150 | tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rounding)); | ||
151 | gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); | ||
152 | |||
153 | - if (dp) { | ||
154 | + if (sz == 3) { | ||
155 | TCGv_i64 tcg_op; | ||
156 | TCGv_i64 tcg_res; | ||
157 | tcg_op = tcg_temp_new_i64(); | ||
158 | @@ -XXX,XX +XXX,XX @@ static bool trans_VRINT(DisasContext *s, arg_VRINT *a) | ||
159 | tcg_op = tcg_temp_new_i32(); | ||
160 | tcg_res = tcg_temp_new_i32(); | ||
161 | neon_load_reg32(tcg_op, rm); | ||
162 | - gen_helper_rints(tcg_res, tcg_op, fpst); | ||
163 | + if (sz == 1) { | ||
164 | + gen_helper_rinth(tcg_res, tcg_op, fpst); | ||
165 | + } else { | ||
166 | + gen_helper_rints(tcg_res, tcg_op, fpst); | ||
167 | + } | ||
168 | neon_store_reg32(tcg_res, rd); | ||
169 | tcg_temp_free_i32(tcg_op); | ||
170 | tcg_temp_free_i32(tcg_res); | ||
171 | @@ -XXX,XX +XXX,XX @@ static bool trans_VCVT_f16_f64(DisasContext *s, arg_VCVT_f16_f64 *a) | ||
172 | return true; | ||
173 | } | 59 | } |
174 | 60 | ||
175 | +static bool trans_VRINTR_hp(DisasContext *s, arg_VRINTR_sp *a) | 61 | /* Update a PLL and all its channels */ |
176 | +{ | ||
177 | + TCGv_ptr fpst; | ||
178 | + TCGv_i32 tmp; | ||
179 | + | ||
180 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | ||
181 | + return false; | ||
182 | + } | ||
183 | + | ||
184 | + if (!vfp_access_check(s)) { | ||
185 | + return true; | ||
186 | + } | ||
187 | + | ||
188 | + tmp = tcg_temp_new_i32(); | ||
189 | + neon_load_reg32(tmp, a->vm); | ||
190 | + fpst = fpstatus_ptr(FPST_FPCR_F16); | ||
191 | + gen_helper_rinth(tmp, tmp, fpst); | ||
192 | + neon_store_reg32(tmp, a->vd); | ||
193 | + tcg_temp_free_ptr(fpst); | ||
194 | + tcg_temp_free_i32(tmp); | ||
195 | + return true; | ||
196 | +} | ||
197 | + | ||
198 | static bool trans_VRINTR_sp(DisasContext *s, arg_VRINTR_sp *a) | ||
199 | { | ||
200 | TCGv_ptr fpst; | ||
201 | @@ -XXX,XX +XXX,XX @@ static bool trans_VRINTR_dp(DisasContext *s, arg_VRINTR_dp *a) | ||
202 | return true; | ||
203 | } | ||
204 | |||
205 | +static bool trans_VRINTZ_hp(DisasContext *s, arg_VRINTZ_sp *a) | ||
206 | +{ | ||
207 | + TCGv_ptr fpst; | ||
208 | + TCGv_i32 tmp; | ||
209 | + TCGv_i32 tcg_rmode; | ||
210 | + | ||
211 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | ||
212 | + return false; | ||
213 | + } | ||
214 | + | ||
215 | + if (!vfp_access_check(s)) { | ||
216 | + return true; | ||
217 | + } | ||
218 | + | ||
219 | + tmp = tcg_temp_new_i32(); | ||
220 | + neon_load_reg32(tmp, a->vm); | ||
221 | + fpst = fpstatus_ptr(FPST_FPCR_F16); | ||
222 | + tcg_rmode = tcg_const_i32(float_round_to_zero); | ||
223 | + gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); | ||
224 | + gen_helper_rinth(tmp, tmp, fpst); | ||
225 | + gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); | ||
226 | + neon_store_reg32(tmp, a->vd); | ||
227 | + tcg_temp_free_ptr(fpst); | ||
228 | + tcg_temp_free_i32(tcg_rmode); | ||
229 | + tcg_temp_free_i32(tmp); | ||
230 | + return true; | ||
231 | +} | ||
232 | + | ||
233 | static bool trans_VRINTZ_sp(DisasContext *s, arg_VRINTZ_sp *a) | ||
234 | { | ||
235 | TCGv_ptr fpst; | ||
236 | @@ -XXX,XX +XXX,XX @@ static bool trans_VRINTZ_dp(DisasContext *s, arg_VRINTZ_dp *a) | ||
237 | return true; | ||
238 | } | ||
239 | |||
240 | +static bool trans_VRINTX_hp(DisasContext *s, arg_VRINTX_sp *a) | ||
241 | +{ | ||
242 | + TCGv_ptr fpst; | ||
243 | + TCGv_i32 tmp; | ||
244 | + | ||
245 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | ||
246 | + return false; | ||
247 | + } | ||
248 | + | ||
249 | + if (!vfp_access_check(s)) { | ||
250 | + return true; | ||
251 | + } | ||
252 | + | ||
253 | + tmp = tcg_temp_new_i32(); | ||
254 | + neon_load_reg32(tmp, a->vm); | ||
255 | + fpst = fpstatus_ptr(FPST_FPCR_F16); | ||
256 | + gen_helper_rinth_exact(tmp, tmp, fpst); | ||
257 | + neon_store_reg32(tmp, a->vd); | ||
258 | + tcg_temp_free_ptr(fpst); | ||
259 | + tcg_temp_free_i32(tmp); | ||
260 | + return true; | ||
261 | +} | ||
262 | + | ||
263 | static bool trans_VRINTX_sp(DisasContext *s, arg_VRINTX_sp *a) | ||
264 | { | ||
265 | TCGv_ptr fpst; | ||
266 | -- | 62 | -- |
267 | 2.20.1 | 63 | 2.20.1 |
268 | 64 | ||
269 | 65 | diff view generated by jsdifflib |
1 | Convert the Neon floating-point vector comparison ops VCEQ, | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | VCGE and VCGT over to using a gvec helper and use this to | 2 | |
3 | implement the fp16 case. | 3 | The clock multiplexers are the last clock stage in the CPRMAN. Each mux |
4 | 4 | outputs one clock signal that goes out of the CPRMAN to the SoC | |
5 | (We put the float16_ceq() etc functions above the DO_2OP() | 5 | peripherals. |
6 | macro definition because later when we convert the | 6 | |
7 | compare-against-zero instructions we'll want their | 7 | Each mux has at most 10 sources. The sources 0 to 3 are common to all |
8 | definitions to be visible at that point in the source file.) | 8 | muxes. They are: |
9 | 9 | 0. ground (no clock signal) | |
10 | 1. the main oscillator (xosc) | ||
11 | 2. "test debug 0" clock | ||
12 | 3. "test debug 1" clock | ||
13 | |||
14 | Test debug 0 and 1 are actual clock muxes that can be used as sources to | ||
15 | other muxes (for debug purpose). | ||
16 | |||
17 | Sources 4 to 9 are mux specific and can be unpopulated (grounded). Those | ||
18 | sources are fed by the PLL channels outputs. | ||
19 | |||
20 | One corner case exists for DSI0E and DSI0P muxes. They have their source | ||
21 | number 4 connected to an intermediate multiplexer that can select | ||
22 | between PLLA-DSI0 and PLLD-DSI0 channel. This multiplexer is called | ||
23 | DSI0HSCK and is not a clock mux as such. It is really a simple mux from | ||
24 | the hardware point of view (see https://elinux.org/The_Undocumented_Pi). | ||
25 | This mux is not implemented in this commit. | ||
26 | |||
27 | Note that there is some muxes for which sources are unknown (because of | ||
28 | a lack of documentation). For those cases all the sources are connected | ||
29 | to ground in this implementation. | ||
30 | |||
31 | Each clock mux output is exported by the CPRMAN at the qdev level, | ||
32 | adding the suffix '-out' to the mux name to form the output clock name. | ||
33 | (E.g. the 'uart' mux sees its output exported as 'uart-out' at the | ||
34 | CPRMAN level.) | ||
35 | |||
36 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
37 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
38 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
39 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 40 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Message-id: 20200828183354.27913-27-peter.maydell@linaro.org | ||
13 | --- | 41 | --- |
14 | target/arm/helper.h | 9 +++++++ | 42 | include/hw/misc/bcm2835_cprman.h | 85 +++++ |
15 | target/arm/vec_helper.c | 44 +++++++++++++++++++++++++++++++++ | 43 | include/hw/misc/bcm2835_cprman_internals.h | 422 +++++++++++++++++++++ |
16 | target/arm/translate-neon.c.inc | 6 ++--- | 44 | hw/misc/bcm2835_cprman.c | 151 ++++++++ |
17 | 3 files changed, 56 insertions(+), 3 deletions(-) | 45 | 3 files changed, 658 insertions(+) |
18 | 46 | ||
19 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 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.h | 49 | --- a/include/hw/misc/bcm2835_cprman.h |
22 | +++ b/target/arm/helper.h | 50 | +++ b/include/hw/misc/bcm2835_cprman.h |
23 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fmul_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 51 | @@ -XXX,XX +XXX,XX @@ typedef enum CprmanPllChannel { |
24 | DEF_HELPER_FLAGS_5(gvec_fabd_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 52 | CPRMAN_PLLB_CHANNEL_ARM, |
25 | DEF_HELPER_FLAGS_5(gvec_fabd_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 53 | |
26 | 54 | CPRMAN_NUM_PLL_CHANNEL, | |
27 | +DEF_HELPER_FLAGS_5(gvec_fceq_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 55 | + |
28 | +DEF_HELPER_FLAGS_5(gvec_fceq_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 56 | + /* Special values used when connecting clock sources to clocks */ |
29 | + | 57 | + CPRMAN_CLOCK_SRC_NORMAL = -1, |
30 | +DEF_HELPER_FLAGS_5(gvec_fcge_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 58 | + CPRMAN_CLOCK_SRC_FORCE_GROUND = -2, |
31 | +DEF_HELPER_FLAGS_5(gvec_fcge_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 59 | + CPRMAN_CLOCK_SRC_DSI0HSCK = -3, |
32 | + | 60 | } CprmanPllChannel; |
33 | +DEF_HELPER_FLAGS_5(gvec_fcgt_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 61 | |
34 | +DEF_HELPER_FLAGS_5(gvec_fcgt_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 62 | +typedef enum CprmanClockMux { |
35 | + | 63 | + CPRMAN_CLOCK_GNRIC, |
36 | DEF_HELPER_FLAGS_5(gvec_ftsmul_h, TCG_CALL_NO_RWG, | 64 | + CPRMAN_CLOCK_VPU, |
37 | void, ptr, ptr, ptr, ptr, i32) | 65 | + CPRMAN_CLOCK_SYS, |
38 | DEF_HELPER_FLAGS_5(gvec_ftsmul_s, TCG_CALL_NO_RWG, | 66 | + CPRMAN_CLOCK_PERIA, |
39 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 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 | ||
40 | index XXXXXXX..XXXXXXX 100644 | 165 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/target/arm/vec_helper.c | 166 | --- a/include/hw/misc/bcm2835_cprman_internals.h |
42 | +++ b/target/arm/vec_helper.c | 167 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
43 | @@ -XXX,XX +XXX,XX @@ void HELPER(gvec_fcmlad)(void *vd, void *vn, void *vm, | 168 | @@ -XXX,XX +XXX,XX @@ |
44 | clear_tail(d, opr_sz, simd_maxsz(desc)); | 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; | ||
45 | } | 276 | } |
46 | 277 | ||
278 | +/* Clock mux init info */ | ||
279 | +typedef struct ClockMuxInitInfo { | ||
280 | + const char *name; | ||
281 | + size_t cm_offset; /* cm_offset[0]->CM_CTL, cm_offset[1]->CM_DIV */ | ||
282 | + int int_bits; | ||
283 | + int frac_bits; | ||
284 | + | ||
285 | + CprmanPllChannel src_mapping[CPRMAN_NUM_CLOCK_MUX_SRC]; | ||
286 | +} ClockMuxInitInfo; | ||
287 | + | ||
47 | +/* | 288 | +/* |
48 | + * Floating point comparisons producing an integer result (all 1s or all 0s). | 289 | + * Each clock mux can have up to 10 sources. Sources 0 to 3 are always the |
49 | + * Note that EQ doesn't signal InvalidOp for QNaNs but GE and GT do. | 290 | + * same (ground, xosc, td0, td1). Sources 4 to 9 are mux specific, and are not |
50 | + * Softfloat routines return 0/1, which we convert to the 0/-1 Neon requires. | 291 | + * always populated. The following macros catch all those cases. |
51 | + */ | 292 | + */ |
52 | +static uint16_t float16_ceq(float16 op1, float16 op2, float_status *stat) | 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) | ||
53 | +{ | 605 | +{ |
54 | + return -float16_eq_quiet(op1, op2, stat); | 606 | + mux->id = id; |
607 | + mux->reg_ctl = &s->regs[CLOCK_MUX_INIT_INFO[id].cm_offset]; | ||
608 | + mux->reg_div = &s->regs[CLOCK_MUX_INIT_INFO[id].cm_offset + 1]; | ||
609 | + mux->int_bits = CLOCK_MUX_INIT_INFO[id].int_bits; | ||
610 | + mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits; | ||
55 | +} | 611 | +} |
56 | + | 612 | + |
57 | +static uint32_t float32_ceq(float32 op1, float32 op2, float_status *stat) | 613 | #endif |
614 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c | ||
615 | index XXXXXXX..XXXXXXX 100644 | ||
616 | --- a/hw/misc/bcm2835_cprman.c | ||
617 | +++ b/hw/misc/bcm2835_cprman.c | ||
618 | @@ -XXX,XX +XXX,XX @@ | ||
619 | * | ||
620 | * The page at https://elinux.org/The_Undocumented_Pi gives the actual clock | ||
621 | * tree configuration. | ||
622 | + * | ||
623 | + * The CPRMAN exposes clock outputs with the name of the clock mux suffixed | ||
624 | + * with "-out" (e.g. "uart-out", "h264-out", ...). | ||
625 | */ | ||
626 | |||
627 | #include "qemu/osdep.h" | ||
628 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = { | ||
629 | }; | ||
630 | |||
631 | |||
632 | +/* clock mux */ | ||
633 | + | ||
634 | +static void clock_mux_update(CprmanClockMuxState *mux) | ||
58 | +{ | 635 | +{ |
59 | + return -float32_eq_quiet(op1, op2, stat); | 636 | + clock_update(mux->out, 0); |
60 | +} | 637 | +} |
61 | + | 638 | + |
62 | +static uint16_t float16_cge(float16 op1, float16 op2, float_status *stat) | 639 | +static void clock_mux_src_update(void *opaque) |
63 | +{ | 640 | +{ |
64 | + return -float16_le(op2, op1, stat); | 641 | + CprmanClockMuxState **backref = opaque; |
642 | + CprmanClockMuxState *s = *backref; | ||
643 | + | ||
644 | + clock_mux_update(s); | ||
65 | +} | 645 | +} |
66 | + | 646 | + |
67 | +static uint32_t float32_cge(float32 op1, float32 op2, float_status *stat) | 647 | +static void clock_mux_init(Object *obj) |
68 | +{ | 648 | +{ |
69 | + return -float32_le(op2, op1, stat); | 649 | + CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj); |
650 | + size_t i; | ||
651 | + | ||
652 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) { | ||
653 | + char *name = g_strdup_printf("srcs[%zu]", i); | ||
654 | + s->backref[i] = s; | ||
655 | + s->srcs[i] = qdev_init_clock_in(DEVICE(s), name, | ||
656 | + clock_mux_src_update, | ||
657 | + &s->backref[i]); | ||
658 | + g_free(name); | ||
659 | + } | ||
660 | + | ||
661 | + s->out = qdev_init_clock_out(DEVICE(s), "out"); | ||
70 | +} | 662 | +} |
71 | + | 663 | + |
72 | +static uint16_t float16_cgt(float16 op1, float16 op2, float_status *stat) | 664 | +static const VMStateDescription clock_mux_vmstate = { |
665 | + .name = TYPE_CPRMAN_CLOCK_MUX, | ||
666 | + .version_id = 1, | ||
667 | + .minimum_version_id = 1, | ||
668 | + .fields = (VMStateField[]) { | ||
669 | + VMSTATE_ARRAY_CLOCK(srcs, CprmanClockMuxState, | ||
670 | + CPRMAN_NUM_CLOCK_MUX_SRC), | ||
671 | + VMSTATE_END_OF_LIST() | ||
672 | + } | ||
673 | +}; | ||
674 | + | ||
675 | +static void clock_mux_class_init(ObjectClass *klass, void *data) | ||
73 | +{ | 676 | +{ |
74 | + return -float16_lt(op2, op1, stat); | 677 | + DeviceClass *dc = DEVICE_CLASS(klass); |
678 | + | ||
679 | + dc->vmsd = &clock_mux_vmstate; | ||
75 | +} | 680 | +} |
76 | + | 681 | + |
77 | +static uint32_t float32_cgt(float32 op1, float32 op2, float_status *stat) | 682 | +static const TypeInfo cprman_clock_mux_info = { |
683 | + .name = TYPE_CPRMAN_CLOCK_MUX, | ||
684 | + .parent = TYPE_DEVICE, | ||
685 | + .instance_size = sizeof(CprmanClockMuxState), | ||
686 | + .class_init = clock_mux_class_init, | ||
687 | + .instance_init = clock_mux_init, | ||
688 | +}; | ||
689 | + | ||
690 | + | ||
691 | /* CPRMAN "top level" model */ | ||
692 | |||
693 | static uint32_t get_cm_lock(const BCM2835CprmanState *s) | ||
694 | @@ -XXX,XX +XXX,XX @@ static inline void update_channel_from_a2w(BCM2835CprmanState *s, size_t idx) | ||
695 | } | ||
696 | } | ||
697 | |||
698 | +static inline void update_mux_from_cm(BCM2835CprmanState *s, size_t idx) | ||
78 | +{ | 699 | +{ |
79 | + return -float32_lt(op2, op1, stat); | 700 | + size_t i; |
701 | + | ||
702 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
703 | + if ((CLOCK_MUX_INIT_INFO[i].cm_offset == idx) || | ||
704 | + (CLOCK_MUX_INIT_INFO[i].cm_offset + 4 == idx)) { | ||
705 | + /* matches CM_CTL or CM_DIV mux register */ | ||
706 | + clock_mux_update(&s->clock_muxes[i]); | ||
707 | + return; | ||
708 | + } | ||
709 | + } | ||
80 | +} | 710 | +} |
81 | + | 711 | + |
82 | #define DO_2OP(NAME, FUNC, TYPE) \ | 712 | #define CASE_PLL_A2W_REGS(pll_) \ |
83 | void HELPER(NAME)(void *vd, void *vn, void *stat, uint32_t desc) \ | 713 | case R_A2W_ ## pll_ ## _CTRL: \ |
84 | { \ | 714 | case R_A2W_ ## pll_ ## _ANA0: \ |
85 | @@ -XXX,XX +XXX,XX @@ DO_3OP(gvec_ftsmul_d, float64_ftsmul, float64) | 715 | @@ -XXX,XX +XXX,XX @@ static void cprman_write(void *opaque, hwaddr offset, |
86 | DO_3OP(gvec_fabd_h, float16_abd, float16) | 716 | case R_A2W_PLLB_ARM: |
87 | DO_3OP(gvec_fabd_s, float32_abd, float32) | 717 | update_channel_from_a2w(s, idx); |
88 | 718 | break; | |
89 | +DO_3OP(gvec_fceq_h, float16_ceq, float16) | 719 | + |
90 | +DO_3OP(gvec_fceq_s, float32_ceq, float32) | 720 | + case R_CM_GNRICCTL ... R_CM_SMIDIV: |
91 | + | 721 | + case R_CM_TCNTCNT ... R_CM_VECDIV: |
92 | +DO_3OP(gvec_fcge_h, float16_cge, float16) | 722 | + case R_CM_PULSECTL ... R_CM_PULSEDIV: |
93 | +DO_3OP(gvec_fcge_s, float32_cge, float32) | 723 | + case R_CM_SDCCTL ... R_CM_ARMCTL: |
94 | + | 724 | + case R_CM_AVEOCTL ... R_CM_EMMCDIV: |
95 | +DO_3OP(gvec_fcgt_h, float16_cgt, float16) | 725 | + case R_CM_EMMC2CTL ... R_CM_EMMC2DIV: |
96 | +DO_3OP(gvec_fcgt_s, float32_cgt, float32) | 726 | + update_mux_from_cm(s, idx); |
97 | + | 727 | + break; |
98 | #ifdef TARGET_AARCH64 | ||
99 | |||
100 | DO_3OP(gvec_recps_h, helper_recpsf_f16, float16) | ||
101 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
102 | index XXXXXXX..XXXXXXX 100644 | ||
103 | --- a/target/arm/translate-neon.c.inc | ||
104 | +++ b/target/arm/translate-neon.c.inc | ||
105 | @@ -XXX,XX +XXX,XX @@ DO_3S_FP_GVEC(VADD, gen_helper_gvec_fadd_s, gen_helper_gvec_fadd_h) | ||
106 | DO_3S_FP_GVEC(VSUB, gen_helper_gvec_fsub_s, gen_helper_gvec_fsub_h) | ||
107 | DO_3S_FP_GVEC(VABD, gen_helper_gvec_fabd_s, gen_helper_gvec_fabd_h) | ||
108 | DO_3S_FP_GVEC(VMUL, gen_helper_gvec_fmul_s, gen_helper_gvec_fmul_h) | ||
109 | +DO_3S_FP_GVEC(VCEQ, gen_helper_gvec_fceq_s, gen_helper_gvec_fceq_h) | ||
110 | +DO_3S_FP_GVEC(VCGE, gen_helper_gvec_fcge_s, gen_helper_gvec_fcge_h) | ||
111 | +DO_3S_FP_GVEC(VCGT, gen_helper_gvec_fcgt_s, gen_helper_gvec_fcgt_h) | ||
112 | |||
113 | /* | ||
114 | * For all the functions using this macro, size == 1 means fp16, | ||
115 | @@ -XXX,XX +XXX,XX @@ DO_3S_FP_GVEC(VMUL, gen_helper_gvec_fmul_s, gen_helper_gvec_fmul_h) | ||
116 | return do_3same_fp(s, a, FUNC, READS_VD); \ | ||
117 | } | 728 | } |
118 | 729 | } | |
119 | -DO_3S_FP(VCEQ, gen_helper_neon_ceq_f32, false) | 730 | |
120 | -DO_3S_FP(VCGE, gen_helper_neon_cge_f32, false) | 731 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) |
121 | -DO_3S_FP(VCGT, gen_helper_neon_cgt_f32, false) | 732 | device_cold_reset(DEVICE(&s->channels[i])); |
122 | DO_3S_FP(VACGE, gen_helper_neon_acge_f32, false) | 733 | } |
123 | DO_3S_FP(VACGT, gen_helper_neon_acgt_f32, false) | 734 | |
124 | DO_3S_FP(VMAX, gen_helper_vfp_maxs, false) | 735 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { |
736 | + device_cold_reset(DEVICE(&s->clock_muxes[i])); | ||
737 | + } | ||
738 | + | ||
739 | clock_update_hz(s->xosc, s->xosc_freq); | ||
740 | } | ||
741 | |||
742 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) | ||
743 | set_pll_channel_init_info(s, &s->channels[i], i); | ||
744 | } | ||
745 | |||
746 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
747 | + char *alias; | ||
748 | + | ||
749 | + object_initialize_child(obj, CLOCK_MUX_INIT_INFO[i].name, | ||
750 | + &s->clock_muxes[i], | ||
751 | + TYPE_CPRMAN_CLOCK_MUX); | ||
752 | + set_clock_mux_init_info(s, &s->clock_muxes[i], i); | ||
753 | + | ||
754 | + /* Expose muxes output as CPRMAN outputs */ | ||
755 | + alias = g_strdup_printf("%s-out", CLOCK_MUX_INIT_INFO[i].name); | ||
756 | + qdev_alias_clock(DEVICE(&s->clock_muxes[i]), "out", DEVICE(obj), alias); | ||
757 | + g_free(alias); | ||
758 | + } | ||
759 | + | ||
760 | s->xosc = clock_new(obj, "xosc"); | ||
761 | + s->gnd = clock_new(obj, "gnd"); | ||
762 | + | ||
763 | + clock_set(s->gnd, 0); | ||
764 | |||
765 | memory_region_init_io(&s->iomem, obj, &cprman_ops, | ||
766 | s, "bcm2835-cprman", 0x2000); | ||
767 | sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); | ||
768 | } | ||
769 | |||
770 | +static void connect_mux_sources(BCM2835CprmanState *s, | ||
771 | + CprmanClockMuxState *mux, | ||
772 | + const CprmanPllChannel *clk_mapping) | ||
773 | +{ | ||
774 | + size_t i; | ||
775 | + Clock *td0 = s->clock_muxes[CPRMAN_CLOCK_TD0].out; | ||
776 | + Clock *td1 = s->clock_muxes[CPRMAN_CLOCK_TD1].out; | ||
777 | + | ||
778 | + /* For sources from 0 to 3. Source 4 to 9 are mux specific */ | ||
779 | + Clock * const CLK_SRC_MAPPING[] = { | ||
780 | + [CPRMAN_CLOCK_SRC_GND] = s->gnd, | ||
781 | + [CPRMAN_CLOCK_SRC_XOSC] = s->xosc, | ||
782 | + [CPRMAN_CLOCK_SRC_TD0] = td0, | ||
783 | + [CPRMAN_CLOCK_SRC_TD1] = td1, | ||
784 | + }; | ||
785 | + | ||
786 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX_SRC; i++) { | ||
787 | + CprmanPllChannel mapping = clk_mapping[i]; | ||
788 | + Clock *src; | ||
789 | + | ||
790 | + if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) { | ||
791 | + src = s->gnd; | ||
792 | + } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) { | ||
793 | + src = s->gnd; /* TODO */ | ||
794 | + } else if (i < CPRMAN_CLOCK_SRC_PLLA) { | ||
795 | + src = CLK_SRC_MAPPING[i]; | ||
796 | + } else { | ||
797 | + src = s->channels[mapping].out; | ||
798 | + } | ||
799 | + | ||
800 | + clock_set_source(mux->srcs[i], src); | ||
801 | + } | ||
802 | +} | ||
803 | + | ||
804 | static void cprman_realize(DeviceState *dev, Error **errp) | ||
805 | { | ||
806 | BCM2835CprmanState *s = CPRMAN(dev); | ||
807 | @@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp) | ||
808 | return; | ||
809 | } | ||
810 | } | ||
811 | + | ||
812 | + for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { | ||
813 | + CprmanClockMuxState *clock_mux = &s->clock_muxes[i]; | ||
814 | + | ||
815 | + connect_mux_sources(s, clock_mux, CLOCK_MUX_INIT_INFO[i].src_mapping); | ||
816 | + | ||
817 | + if (!qdev_realize(DEVICE(clock_mux), NULL, errp)) { | ||
818 | + return; | ||
819 | + } | ||
820 | + } | ||
821 | } | ||
822 | |||
823 | static const VMStateDescription cprman_vmstate = { | ||
824 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) | ||
825 | type_register_static(&cprman_info); | ||
826 | type_register_static(&cprman_pll_info); | ||
827 | type_register_static(&cprman_pll_channel_info); | ||
828 | + type_register_static(&cprman_clock_mux_info); | ||
829 | } | ||
830 | |||
831 | type_init(cprman_register_types); | ||
125 | -- | 832 | -- |
126 | 2.20.1 | 833 | 2.20.1 |
127 | 834 | ||
128 | 835 | diff view generated by jsdifflib |
1 | Implement VFP fp16 support for the VMOV immediate insn. | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | 2 | ||
3 | A clock mux can be configured to select one of its 10 sources through | ||
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. | ||
7 | |||
8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
10 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20200828183354.27913-10-peter.maydell@linaro.org | ||
6 | --- | 13 | --- |
7 | target/arm/vfp.decode | 2 ++ | 14 | hw/misc/bcm2835_cprman.c | 53 +++++++++++++++++++++++++++++++++++++++- |
8 | target/arm/translate-vfp.c.inc | 22 ++++++++++++++++++++++ | 15 | 1 file changed, 52 insertions(+), 1 deletion(-) |
9 | 2 files changed, 24 insertions(+) | ||
10 | 16 | ||
11 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | 17 | diff --git a/hw/misc/bcm2835_cprman.c b/hw/misc/bcm2835_cprman.c |
12 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/vfp.decode | 19 | --- a/hw/misc/bcm2835_cprman.c |
14 | +++ b/target/arm/vfp.decode | 20 | +++ b/hw/misc/bcm2835_cprman.c |
15 | @@ -XXX,XX +XXX,XX @@ VFMS_dp ---- 1110 1.10 .... .... 1011 .1.0 .... @vfp_dnm_d | 21 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo cprman_pll_channel_info = { |
16 | VFNMA_dp ---- 1110 1.01 .... .... 1011 .0.0 .... @vfp_dnm_d | 22 | |
17 | VFNMS_dp ---- 1110 1.01 .... .... 1011 .1.0 .... @vfp_dnm_d | 23 | /* clock mux */ |
18 | 24 | ||
19 | +VMOV_imm_hp ---- 1110 1.11 .... .... 1001 0000 .... \ | 25 | +static bool clock_mux_is_enabled(CprmanClockMuxState *mux) |
20 | + vd=%vd_sp imm=%vmov_imm | ||
21 | VMOV_imm_sp ---- 1110 1.11 .... .... 1010 0000 .... \ | ||
22 | vd=%vd_sp imm=%vmov_imm | ||
23 | VMOV_imm_dp ---- 1110 1.11 .... .... 1011 0000 .... \ | ||
24 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/target/arm/translate-vfp.c.inc | ||
27 | +++ b/target/arm/translate-vfp.c.inc | ||
28 | @@ -XXX,XX +XXX,XX @@ MAKE_VFM_TRANS_FNS(hp) | ||
29 | MAKE_VFM_TRANS_FNS(sp) | ||
30 | MAKE_VFM_TRANS_FNS(dp) | ||
31 | |||
32 | +static bool trans_VMOV_imm_hp(DisasContext *s, arg_VMOV_imm_sp *a) | ||
33 | +{ | 26 | +{ |
34 | + TCGv_i32 fd; | 27 | + return FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, ENABLE); |
28 | +} | ||
35 | + | 29 | + |
36 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 30 | static void clock_mux_update(CprmanClockMuxState *mux) |
37 | + return false; | 31 | { |
32 | - clock_update(mux->out, 0); | ||
33 | + uint64_t freq; | ||
34 | + uint32_t div, src = FIELD_EX32(*mux->reg_ctl, CM_CLOCKx_CTL, SRC); | ||
35 | + bool enabled = clock_mux_is_enabled(mux); | ||
36 | + | ||
37 | + *mux->reg_ctl = FIELD_DP32(*mux->reg_ctl, CM_CLOCKx_CTL, BUSY, enabled); | ||
38 | + | ||
39 | + if (!enabled) { | ||
40 | + clock_update(mux->out, 0); | ||
41 | + return; | ||
38 | + } | 42 | + } |
39 | + | 43 | + |
40 | + if (s->vec_len != 0 || s->vec_stride != 0) { | 44 | + freq = clock_get_hz(mux->srcs[src]); |
41 | + return false; | 45 | + |
46 | + if (mux->int_bits == 0 && mux->frac_bits == 0) { | ||
47 | + clock_update_hz(mux->out, freq); | ||
48 | + return; | ||
42 | + } | 49 | + } |
43 | + | 50 | + |
44 | + if (!vfp_access_check(s)) { | 51 | + /* |
45 | + return true; | 52 | + * The divider has an integer and a fractional part. The size of each part |
53 | + * varies with the muxes (int_bits and frac_bits). Both parts are | ||
54 | + * concatenated, with the integer part always starting at bit 12. | ||
55 | + * | ||
56 | + * 31 12 11 0 | ||
57 | + * ------------------------------ | ||
58 | + * CM_DIV | | int | frac | | | ||
59 | + * ------------------------------ | ||
60 | + * <-----> <------> | ||
61 | + * int_bits frac_bits | ||
62 | + */ | ||
63 | + div = extract32(*mux->reg_div, | ||
64 | + R_CM_CLOCKx_DIV_FRAC_LENGTH - mux->frac_bits, | ||
65 | + mux->int_bits + mux->frac_bits); | ||
66 | + | ||
67 | + if (!div) { | ||
68 | + clock_update(mux->out, 0); | ||
69 | + return; | ||
46 | + } | 70 | + } |
47 | + | 71 | + |
48 | + fd = tcg_const_i32(vfp_expand_imm(MO_16, a->imm)); | 72 | + freq = muldiv64(freq, 1 << mux->frac_bits, div); |
49 | + neon_store_reg32(fd, a->vd); | ||
50 | + tcg_temp_free_i32(fd); | ||
51 | + return true; | ||
52 | +} | ||
53 | + | 73 | + |
54 | static bool trans_VMOV_imm_sp(DisasContext *s, arg_VMOV_imm_sp *a) | 74 | + clock_update_hz(mux->out, freq); |
75 | } | ||
76 | |||
77 | static void clock_mux_src_update(void *opaque) | ||
55 | { | 78 | { |
56 | uint32_t delta_d = 0; | 79 | CprmanClockMuxState **backref = opaque; |
80 | CprmanClockMuxState *s = *backref; | ||
81 | + CprmanClockMuxSource src = backref - s->backref; | ||
82 | + | ||
83 | + if (FIELD_EX32(*s->reg_ctl, CM_CLOCKx_CTL, SRC) != src) { | ||
84 | + return; | ||
85 | + } | ||
86 | |||
87 | clock_mux_update(s); | ||
88 | } | ||
57 | -- | 89 | -- |
58 | 2.20.1 | 90 | 2.20.1 |
59 | 91 | ||
60 | 92 | diff view generated by jsdifflib |
1 | Convert the Neon VCVT float<->fixed-point insns to a | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | gvec style, in preparation for adding fp16 support. | 2 | |
3 | 3 | This simple mux sits between the PLL channels and the DSI0E and DSI0P | |
4 | clock muxes. This mux selects between PLLA-DSI0 and PLLD-DSI0 channel | ||
5 | and outputs the selected signal to source number 4 of DSI0E/P clock | ||
6 | muxes. It is controlled by the cm_dsi0hsck register. | ||
7 | |||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
11 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
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> | ||
6 | Message-id: 20200828183354.27913-38-peter.maydell@linaro.org | ||
7 | --- | 13 | --- |
8 | target/arm/helper.h | 5 +++++ | 14 | include/hw/misc/bcm2835_cprman.h | 15 +++++ |
9 | target/arm/vec_helper.c | 20 +++++++++++++++++++ | 15 | include/hw/misc/bcm2835_cprman_internals.h | 6 ++ |
10 | target/arm/translate-neon.c.inc | 35 +++++++++++++++++---------------- | 16 | hw/misc/bcm2835_cprman.c | 74 +++++++++++++++++++++- |
11 | 3 files changed, 43 insertions(+), 17 deletions(-) | 17 | 3 files changed, 94 insertions(+), 1 deletion(-) |
12 | 18 | ||
13 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 19 | diff --git a/include/hw/misc/bcm2835_cprman.h b/include/hw/misc/bcm2835_cprman.h |
14 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.h | 21 | --- a/include/hw/misc/bcm2835_cprman.h |
16 | +++ b/target/arm/helper.h | 22 | +++ b/include/hw/misc/bcm2835_cprman.h |
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(gvec_tosizs, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 23 | @@ -XXX,XX +XXX,XX @@ typedef struct CprmanClockMuxState { |
18 | DEF_HELPER_FLAGS_4(gvec_touszh, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 24 | struct CprmanClockMuxState *backref[CPRMAN_NUM_CLOCK_MUX_SRC]; |
19 | DEF_HELPER_FLAGS_4(gvec_touizs, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 25 | } CprmanClockMuxState; |
20 | 26 | ||
21 | +DEF_HELPER_FLAGS_4(gvec_vcvt_sf, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 27 | +typedef struct CprmanDsi0HsckMuxState { |
22 | +DEF_HELPER_FLAGS_4(gvec_vcvt_uf, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 28 | + /*< private >*/ |
23 | +DEF_HELPER_FLAGS_4(gvec_vcvt_fs, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 29 | + DeviceState parent_obj; |
24 | +DEF_HELPER_FLAGS_4(gvec_vcvt_fu, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 30 | + |
25 | + | 31 | + /*< public >*/ |
26 | DEF_HELPER_FLAGS_4(gvec_frecpe_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 32 | + CprmanClockMux id; |
27 | DEF_HELPER_FLAGS_4(gvec_frecpe_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 33 | + |
28 | DEF_HELPER_FLAGS_4(gvec_frecpe_d, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 34 | + uint32_t *reg_cm; |
29 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 35 | + |
36 | + Clock *plla_in; | ||
37 | + Clock *plld_in; | ||
38 | + Clock *out; | ||
39 | +} CprmanDsi0HsckMuxState; | ||
40 | + | ||
41 | struct BCM2835CprmanState { | ||
42 | /*< private >*/ | ||
43 | SysBusDevice parent_obj; | ||
44 | @@ -XXX,XX +XXX,XX @@ struct BCM2835CprmanState { | ||
45 | CprmanPllState plls[CPRMAN_NUM_PLL]; | ||
46 | CprmanPllChannelState channels[CPRMAN_NUM_PLL_CHANNEL]; | ||
47 | CprmanClockMuxState clock_muxes[CPRMAN_NUM_CLOCK_MUX]; | ||
48 | + CprmanDsi0HsckMuxState dsi0hsck_mux; | ||
49 | |||
50 | uint32_t regs[CPRMAN_NUM_REGS]; | ||
51 | uint32_t xosc_freq; | ||
52 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | ||
30 | index XXXXXXX..XXXXXXX 100644 | 53 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/target/arm/vec_helper.c | 54 | --- a/include/hw/misc/bcm2835_cprman_internals.h |
32 | +++ b/target/arm/vec_helper.c | 55 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
33 | @@ -XXX,XX +XXX,XX @@ DO_NEON_PAIRWISE(neon_pmax, max) | 56 | @@ -XXX,XX +XXX,XX @@ |
34 | DO_NEON_PAIRWISE(neon_pmin, min) | 57 | #define TYPE_CPRMAN_PLL "bcm2835-cprman-pll" |
35 | 58 | #define TYPE_CPRMAN_PLL_CHANNEL "bcm2835-cprman-pll-channel" | |
36 | #undef DO_NEON_PAIRWISE | 59 | #define TYPE_CPRMAN_CLOCK_MUX "bcm2835-cprman-clock-mux" |
37 | + | 60 | +#define TYPE_CPRMAN_DSI0HSCK_MUX "bcm2835-cprman-dsi0hsck-mux" |
38 | +#define DO_VCVT_FIXED(NAME, FUNC, TYPE) \ | 61 | |
39 | + void HELPER(NAME)(void *vd, void *vn, void *stat, uint32_t desc) \ | 62 | DECLARE_INSTANCE_CHECKER(CprmanPllState, CPRMAN_PLL, |
40 | + { \ | 63 | TYPE_CPRMAN_PLL) |
41 | + intptr_t i, oprsz = simd_oprsz(desc); \ | 64 | @@ -XXX,XX +XXX,XX @@ DECLARE_INSTANCE_CHECKER(CprmanPllChannelState, CPRMAN_PLL_CHANNEL, |
42 | + int shift = simd_data(desc); \ | 65 | TYPE_CPRMAN_PLL_CHANNEL) |
43 | + TYPE *d = vd, *n = vn; \ | 66 | DECLARE_INSTANCE_CHECKER(CprmanClockMuxState, CPRMAN_CLOCK_MUX, |
44 | + float_status *fpst = stat; \ | 67 | TYPE_CPRMAN_CLOCK_MUX) |
45 | + for (i = 0; i < oprsz / sizeof(TYPE); i++) { \ | 68 | +DECLARE_INSTANCE_CHECKER(CprmanDsi0HsckMuxState, CPRMAN_DSI0HSCK_MUX, |
46 | + d[i] = FUNC(n[i], shift, fpst); \ | 69 | + TYPE_CPRMAN_DSI0HSCK_MUX) |
47 | + } \ | 70 | |
48 | + clear_tail(d, oprsz, simd_maxsz(desc)); \ | 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() | ||
49 | + } | 124 | + } |
50 | + | 125 | +}; |
51 | +DO_VCVT_FIXED(gvec_vcvt_sf, helper_vfp_sltos, uint32_t) | 126 | + |
52 | +DO_VCVT_FIXED(gvec_vcvt_uf, helper_vfp_ultos, uint32_t) | 127 | +static void dsi0hsck_mux_class_init(ObjectClass *klass, void *data) |
53 | +DO_VCVT_FIXED(gvec_vcvt_fs, helper_vfp_tosls_round_to_zero, uint32_t) | 128 | +{ |
54 | +DO_VCVT_FIXED(gvec_vcvt_fu, helper_vfp_touls_round_to_zero, uint32_t) | 129 | + DeviceClass *dc = DEVICE_CLASS(klass); |
55 | + | 130 | + |
56 | +#undef DO_VCVT_FIXED | 131 | + dc->vmsd = &dsi0hsck_mux_vmstate; |
57 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | 132 | +} |
58 | index XXXXXXX..XXXXXXX 100644 | 133 | + |
59 | --- a/target/arm/translate-neon.c.inc | 134 | +static const TypeInfo cprman_dsi0hsck_mux_info = { |
60 | +++ b/target/arm/translate-neon.c.inc | 135 | + .name = TYPE_CPRMAN_DSI0HSCK_MUX, |
61 | @@ -XXX,XX +XXX,XX @@ static bool trans_VSHLL_U_2sh(DisasContext *s, arg_2reg_shift *a) | 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 | } | ||
62 | } | 155 | } |
63 | 156 | ||
64 | static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a, | 157 | @@ -XXX,XX +XXX,XX @@ static void cprman_reset(DeviceState *dev) |
65 | - NeonGenTwoSingleOpFn *fn) | 158 | device_cold_reset(DEVICE(&s->channels[i])); |
66 | + gen_helper_gvec_2_ptr *fn) | 159 | } |
67 | { | 160 | |
68 | /* FP operations in 2-reg-and-shift group */ | 161 | + device_cold_reset(DEVICE(&s->dsi0hsck_mux)); |
69 | - TCGv_i32 tmp, shiftv; | 162 | + |
70 | - TCGv_ptr fpstatus; | 163 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { |
71 | - int pass; | 164 | device_cold_reset(DEVICE(&s->clock_muxes[i])); |
72 | + int vec_size = a->q ? 16 : 8; | 165 | } |
73 | + int rd_ofs = neon_reg_offset(a->vd, 0); | 166 | @@ -XXX,XX +XXX,XX @@ static void cprman_init(Object *obj) |
74 | + int rm_ofs = neon_reg_offset(a->vm, 0); | 167 | set_pll_channel_init_info(s, &s->channels[i], i); |
75 | + TCGv_ptr fpst; | 168 | } |
76 | 169 | ||
77 | if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | 170 | + object_initialize_child(obj, "dsi0hsck-mux", |
78 | return false; | 171 | + &s->dsi0hsck_mux, TYPE_CPRMAN_DSI0HSCK_MUX); |
79 | } | 172 | + s->dsi0hsck_mux.reg_cm = &s->regs[R_CM_DSI0HSCK]; |
80 | 173 | + | |
81 | + if (a->size != 0) { | 174 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { |
82 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 175 | char *alias; |
83 | + return false; | 176 | |
84 | + } | 177 | @@ -XXX,XX +XXX,XX @@ static void connect_mux_sources(BCM2835CprmanState *s, |
178 | if (mapping == CPRMAN_CLOCK_SRC_FORCE_GROUND) { | ||
179 | src = s->gnd; | ||
180 | } else if (mapping == CPRMAN_CLOCK_SRC_DSI0HSCK) { | ||
181 | - src = s->gnd; /* TODO */ | ||
182 | + src = s->dsi0hsck_mux.out; | ||
183 | } else if (i < CPRMAN_CLOCK_SRC_PLLA) { | ||
184 | src = CLK_SRC_MAPPING[i]; | ||
185 | } else { | ||
186 | @@ -XXX,XX +XXX,XX @@ static void cprman_realize(DeviceState *dev, Error **errp) | ||
187 | } | ||
188 | } | ||
189 | |||
190 | + clock_set_source(s->dsi0hsck_mux.plla_in, | ||
191 | + s->channels[CPRMAN_PLLA_CHANNEL_DSI0].out); | ||
192 | + clock_set_source(s->dsi0hsck_mux.plld_in, | ||
193 | + s->channels[CPRMAN_PLLD_CHANNEL_DSI0].out); | ||
194 | + | ||
195 | + if (!qdev_realize(DEVICE(&s->dsi0hsck_mux), NULL, errp)) { | ||
196 | + return; | ||
85 | + } | 197 | + } |
86 | + | 198 | + |
87 | /* UNDEF accesses to D16-D31 if they don't exist. */ | 199 | for (i = 0; i < CPRMAN_NUM_CLOCK_MUX; i++) { |
88 | if (!dc_isar_feature(aa32_simd_r32, s) && | 200 | CprmanClockMuxState *clock_mux = &s->clock_muxes[i]; |
89 | ((a->vd | a->vm) & 0x10)) { | 201 | |
90 | @@ -XXX,XX +XXX,XX @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a, | 202 | @@ -XXX,XX +XXX,XX @@ static void cprman_register_types(void) |
91 | return true; | 203 | type_register_static(&cprman_pll_info); |
92 | } | 204 | type_register_static(&cprman_pll_channel_info); |
93 | 205 | type_register_static(&cprman_clock_mux_info); | |
94 | - fpstatus = fpstatus_ptr(FPST_STD); | 206 | + type_register_static(&cprman_dsi0hsck_mux_info); |
95 | - shiftv = tcg_const_i32(a->shift); | ||
96 | - for (pass = 0; pass < (a->q ? 4 : 2); pass++) { | ||
97 | - tmp = neon_load_reg(a->vm, pass); | ||
98 | - fn(tmp, tmp, shiftv, fpstatus); | ||
99 | - neon_store_reg(a->vd, pass, tmp); | ||
100 | - } | ||
101 | - tcg_temp_free_ptr(fpstatus); | ||
102 | - tcg_temp_free_i32(shiftv); | ||
103 | + fpst = fpstatus_ptr(a->size ? FPST_STD_F16 : FPST_STD); | ||
104 | + tcg_gen_gvec_2_ptr(rd_ofs, rm_ofs, fpst, vec_size, vec_size, a->shift, fn); | ||
105 | + tcg_temp_free_ptr(fpst); | ||
106 | return true; | ||
107 | } | 207 | } |
108 | 208 | ||
109 | @@ -XXX,XX +XXX,XX @@ static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a, | 209 | type_init(cprman_register_types); |
110 | return do_fp_2sh(s, a, FUNC); \ | ||
111 | } | ||
112 | |||
113 | -DO_FP_2SH(VCVT_SF, gen_helper_vfp_sltos) | ||
114 | -DO_FP_2SH(VCVT_UF, gen_helper_vfp_ultos) | ||
115 | -DO_FP_2SH(VCVT_FS, gen_helper_vfp_tosls_round_to_zero) | ||
116 | -DO_FP_2SH(VCVT_FU, gen_helper_vfp_touls_round_to_zero) | ||
117 | +DO_FP_2SH(VCVT_SF, gen_helper_gvec_vcvt_sf) | ||
118 | +DO_FP_2SH(VCVT_UF, gen_helper_gvec_vcvt_uf) | ||
119 | +DO_FP_2SH(VCVT_FS, gen_helper_gvec_vcvt_fs) | ||
120 | +DO_FP_2SH(VCVT_FU, gen_helper_gvec_vcvt_fu) | ||
121 | |||
122 | static uint64_t asimd_imm_const(uint32_t imm, int cmode, int op) | ||
123 | { | ||
124 | -- | 210 | -- |
125 | 2.20.1 | 211 | 2.20.1 |
126 | 212 | ||
127 | 213 | diff view generated by jsdifflib |
1 | Convert the neon floating-point vector absolute comparison ops | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | VACGE and VACGT over to using a gvec hepler and use this to | 2 | |
3 | implement the fp16 case. | 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 | the debugfs interface of the CPRMAN driver in Linux (under | ||
6 | '/sys/kernel/debug/clk'). Each exposed clock tree stage (PLLs, channels | ||
7 | and muxes) can be observed by reading the 'regdump' file (e.g. | ||
8 | 'plla/regdump'). | ||
9 | |||
10 | Those values are set by the Raspberry Pi firmware at boot time (Linux | ||
11 | expects them to be set when it boots up). | ||
12 | |||
13 | Some stages are not exposed by the Linux driver (e.g. the PLL B). For | ||
14 | those, the reset values are unknown and left to 0 which implies a | ||
15 | disabled output. | ||
16 | |||
17 | Once booted in QEMU, the final clock tree is very similar to the one | ||
18 | visible on real hardware. The differences come from some unimplemented | ||
19 | devices for which the driver simply disable the corresponding clock. | ||
20 | |||
21 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
22 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
23 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
24 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20200828183354.27913-28-peter.maydell@linaro.org | ||
8 | --- | 26 | --- |
9 | target/arm/helper.h | 6 ++++++ | 27 | include/hw/misc/bcm2835_cprman_internals.h | 269 +++++++++++++++++++++ |
10 | target/arm/vec_helper.c | 26 ++++++++++++++++++++++++++ | 28 | hw/misc/bcm2835_cprman.c | 31 +++ |
11 | target/arm/translate-neon.c.inc | 4 ++-- | 29 | 2 files changed, 300 insertions(+) |
12 | 3 files changed, 34 insertions(+), 2 deletions(-) | 30 | |
13 | 31 | diff --git a/include/hw/misc/bcm2835_cprman_internals.h b/include/hw/misc/bcm2835_cprman_internals.h | |
14 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/helper.h | 33 | --- a/include/hw/misc/bcm2835_cprman_internals.h |
17 | +++ b/target/arm/helper.h | 34 | +++ b/include/hw/misc/bcm2835_cprman_internals.h |
18 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(gvec_fcge_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 35 | @@ -XXX,XX +XXX,XX @@ static inline void set_clock_mux_init_info(BCM2835CprmanState *s, |
19 | DEF_HELPER_FLAGS_5(gvec_fcgt_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 36 | mux->frac_bits = CLOCK_MUX_INIT_INFO[id].frac_bits; |
20 | DEF_HELPER_FLAGS_5(gvec_fcgt_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 37 | } |
21 | 38 | ||
22 | +DEF_HELPER_FLAGS_5(gvec_facge_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 39 | + |
23 | +DEF_HELPER_FLAGS_5(gvec_facge_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 40 | +/* |
24 | + | 41 | + * Object reset info |
25 | +DEF_HELPER_FLAGS_5(gvec_facgt_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 42 | + * Those values have been dumped from a Raspberry Pi 3 Model B v1.2 using the |
26 | +DEF_HELPER_FLAGS_5(gvec_facgt_s, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, ptr, i32) | 43 | + * clk debugfs interface in Linux. |
27 | + | 44 | + */ |
28 | DEF_HELPER_FLAGS_5(gvec_ftsmul_h, TCG_CALL_NO_RWG, | 45 | +typedef struct PLLResetInfo { |
29 | void, ptr, ptr, ptr, ptr, i32) | 46 | + uint32_t cm; |
30 | DEF_HELPER_FLAGS_5(gvec_ftsmul_s, TCG_CALL_NO_RWG, | 47 | + uint32_t a2w_ctrl; |
31 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | 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 | ||
32 | index XXXXXXX..XXXXXXX 100644 | 310 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/arm/vec_helper.c | 311 | --- a/hw/misc/bcm2835_cprman.c |
34 | +++ b/target/arm/vec_helper.c | 312 | +++ b/hw/misc/bcm2835_cprman.c |
35 | @@ -XXX,XX +XXX,XX @@ static uint32_t float32_cgt(float32 op1, float32 op2, float_status *stat) | 313 | @@ -XXX,XX +XXX,XX @@ |
36 | return -float32_lt(op2, op1, stat); | 314 | |
37 | } | 315 | /* PLL */ |
38 | 316 | ||
39 | +static uint16_t float16_acge(float16 op1, float16 op2, float_status *stat) | 317 | +static void pll_reset(DeviceState *dev) |
40 | +{ | 318 | +{ |
41 | + return -float16_le(float16_abs(op2), float16_abs(op1), stat); | 319 | + CprmanPllState *s = CPRMAN_PLL(dev); |
320 | + const PLLResetInfo *info = &PLL_RESET_INFO[s->id]; | ||
321 | + | ||
322 | + *s->reg_cm = info->cm; | ||
323 | + *s->reg_a2w_ctrl = info->a2w_ctrl; | ||
324 | + memcpy(s->reg_a2w_ana, info->a2w_ana, sizeof(info->a2w_ana)); | ||
325 | + *s->reg_a2w_frac = info->a2w_frac; | ||
42 | +} | 326 | +} |
43 | + | 327 | + |
44 | +static uint32_t float32_acge(float32 op1, float32 op2, float_status *stat) | 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) | ||
45 | +{ | 344 | +{ |
46 | + return -float32_le(float32_abs(op2), float32_abs(op1), stat); | 345 | + CprmanPllChannelState *s = CPRMAN_PLL_CHANNEL(dev); |
346 | + const PLLChannelResetInfo *info = &PLL_CHANNEL_RESET_INFO[s->id]; | ||
347 | + | ||
348 | + *s->reg_a2w_ctrl = info->a2w_ctrl; | ||
47 | +} | 349 | +} |
48 | + | 350 | + |
49 | +static uint16_t float16_acgt(float16 op1, float16 op2, float_status *stat) | 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) | ||
50 | +{ | 367 | +{ |
51 | + return -float16_lt(float16_abs(op2), float16_abs(op1), stat); | 368 | + CprmanClockMuxState *clock = CPRMAN_CLOCK_MUX(dev); |
369 | + const ClockMuxResetInfo *info = &CLOCK_MUX_RESET_INFO[clock->id]; | ||
370 | + | ||
371 | + *clock->reg_ctl = info->cm_ctl; | ||
372 | + *clock->reg_div = info->cm_div; | ||
52 | +} | 373 | +} |
53 | + | 374 | + |
54 | +static uint32_t float32_acgt(float32 op1, float32 op2, float_status *stat) | 375 | static void clock_mux_init(Object *obj) |
55 | +{ | 376 | { |
56 | + return -float32_lt(float32_abs(op2), float32_abs(op1), stat); | 377 | CprmanClockMuxState *s = CPRMAN_CLOCK_MUX(obj); |
57 | +} | 378 | @@ -XXX,XX +XXX,XX @@ static void clock_mux_class_init(ObjectClass *klass, void *data) |
58 | + | 379 | { |
59 | #define DO_2OP(NAME, FUNC, TYPE) \ | 380 | DeviceClass *dc = DEVICE_CLASS(klass); |
60 | void HELPER(NAME)(void *vd, void *vn, void *stat, uint32_t desc) \ | 381 | |
61 | { \ | 382 | + dc->reset = clock_mux_reset; |
62 | @@ -XXX,XX +XXX,XX @@ DO_3OP(gvec_fcge_s, float32_cge, float32) | 383 | dc->vmsd = &clock_mux_vmstate; |
63 | DO_3OP(gvec_fcgt_h, float16_cgt, float16) | 384 | } |
64 | DO_3OP(gvec_fcgt_s, float32_cgt, float32) | ||
65 | |||
66 | +DO_3OP(gvec_facge_h, float16_acge, float16) | ||
67 | +DO_3OP(gvec_facge_s, float32_acge, float32) | ||
68 | + | ||
69 | +DO_3OP(gvec_facgt_h, float16_acgt, float16) | ||
70 | +DO_3OP(gvec_facgt_s, float32_acgt, float32) | ||
71 | + | ||
72 | #ifdef TARGET_AARCH64 | ||
73 | |||
74 | DO_3OP(gvec_recps_h, helper_recpsf_f16, float16) | ||
75 | diff --git a/target/arm/translate-neon.c.inc b/target/arm/translate-neon.c.inc | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/target/arm/translate-neon.c.inc | ||
78 | +++ b/target/arm/translate-neon.c.inc | ||
79 | @@ -XXX,XX +XXX,XX @@ DO_3S_FP_GVEC(VMUL, gen_helper_gvec_fmul_s, gen_helper_gvec_fmul_h) | ||
80 | DO_3S_FP_GVEC(VCEQ, gen_helper_gvec_fceq_s, gen_helper_gvec_fceq_h) | ||
81 | DO_3S_FP_GVEC(VCGE, gen_helper_gvec_fcge_s, gen_helper_gvec_fcge_h) | ||
82 | DO_3S_FP_GVEC(VCGT, gen_helper_gvec_fcgt_s, gen_helper_gvec_fcgt_h) | ||
83 | +DO_3S_FP_GVEC(VACGE, gen_helper_gvec_facge_s, gen_helper_gvec_facge_h) | ||
84 | +DO_3S_FP_GVEC(VACGT, gen_helper_gvec_facgt_s, gen_helper_gvec_facgt_h) | ||
85 | |||
86 | /* | ||
87 | * For all the functions using this macro, size == 1 means fp16, | ||
88 | @@ -XXX,XX +XXX,XX @@ DO_3S_FP_GVEC(VCGT, gen_helper_gvec_fcgt_s, gen_helper_gvec_fcgt_h) | ||
89 | return do_3same_fp(s, a, FUNC, READS_VD); \ | ||
90 | } | ||
91 | |||
92 | -DO_3S_FP(VACGE, gen_helper_neon_acge_f32, false) | ||
93 | -DO_3S_FP(VACGT, gen_helper_neon_acgt_f32, false) | ||
94 | DO_3S_FP(VMAX, gen_helper_vfp_maxs, false) | ||
95 | DO_3S_FP(VMIN, gen_helper_vfp_mins, false) | ||
96 | 385 | ||
97 | -- | 386 | -- |
98 | 2.20.1 | 387 | 2.20.1 |
99 | 388 | ||
100 | 389 | diff view generated by jsdifflib |
1 | Implement VFP fp16 for VABS, VNEG and VSQRT. This is all | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | the fp16 insns that use the DO_VFP_2OP macro, because there | ||
3 | is no fp16 version of VMOV_reg. | ||
4 | 2 | ||
5 | Notes: | 3 | Add a clock input to the PL011 UART so we can compute the current baud |
6 | * the gen_helper_vfp_negh already exists as we needed to create | 4 | rate and trace it. This is intended for developers who wish to use QEMU |
7 | it for the fp16 multiply-add insns | 5 | to e.g. debug their firmware or to figure out the baud rate configured |
8 | * as usual we need to use the f16 version of the fp_status; | 6 | by an unknown/closed source binary. |
9 | this is only relevant for VSQRT | ||
10 | 7 | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
10 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
11 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Message-id: 20200828183354.27913-9-peter.maydell@linaro.org | ||
14 | --- | 13 | --- |
15 | target/arm/helper.h | 2 ++ | 14 | include/hw/char/pl011.h | 1 + |
16 | target/arm/vfp.decode | 3 +++ | 15 | hw/char/pl011.c | 45 +++++++++++++++++++++++++++++++++++++++++ |
17 | target/arm/vfp_helper.c | 10 +++++++++ | 16 | hw/char/trace-events | 1 + |
18 | target/arm/translate-vfp.c.inc | 40 ++++++++++++++++++++++++++++++++++ | 17 | 3 files changed, 47 insertions(+) |
19 | 4 files changed, 55 insertions(+) | ||
20 | 18 | ||
21 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 19 | diff --git a/include/hw/char/pl011.h b/include/hw/char/pl011.h |
22 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/arm/helper.h | 21 | --- a/include/hw/char/pl011.h |
24 | +++ b/target/arm/helper.h | 22 | +++ b/include/hw/char/pl011.h |
25 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_3(vfp_minnumd, f64, f64, f64, ptr) | 23 | @@ -XXX,XX +XXX,XX @@ struct PL011State { |
26 | DEF_HELPER_1(vfp_negh, f16, f16) | 24 | int read_trigger; |
27 | DEF_HELPER_1(vfp_negs, f32, f32) | 25 | CharBackend chr; |
28 | DEF_HELPER_1(vfp_negd, f64, f64) | 26 | qemu_irq irq[6]; |
29 | +DEF_HELPER_1(vfp_absh, f16, f16) | 27 | + Clock *clk; |
30 | DEF_HELPER_1(vfp_abss, f32, f32) | 28 | const unsigned char *id; |
31 | DEF_HELPER_1(vfp_absd, f64, f64) | 29 | }; |
32 | +DEF_HELPER_2(vfp_sqrth, f16, f16, env) | 30 | |
33 | DEF_HELPER_2(vfp_sqrts, f32, f32, env) | 31 | diff --git a/hw/char/pl011.c b/hw/char/pl011.c |
34 | DEF_HELPER_2(vfp_sqrtd, f64, f64, env) | ||
35 | DEF_HELPER_3(vfp_cmps, void, f32, f32, env) | ||
36 | diff --git a/target/arm/vfp.decode b/target/arm/vfp.decode | ||
37 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
38 | --- a/target/arm/vfp.decode | 33 | --- a/hw/char/pl011.c |
39 | +++ b/target/arm/vfp.decode | 34 | +++ b/hw/char/pl011.c |
40 | @@ -XXX,XX +XXX,XX @@ VMOV_imm_dp ---- 1110 1.11 .... .... 1011 0000 .... \ | 35 | @@ -XXX,XX +XXX,XX @@ |
41 | VMOV_reg_sp ---- 1110 1.11 0000 .... 1010 01.0 .... @vfp_dm_ss | 36 | #include "hw/char/pl011.h" |
42 | VMOV_reg_dp ---- 1110 1.11 0000 .... 1011 01.0 .... @vfp_dm_dd | 37 | #include "hw/irq.h" |
43 | 38 | #include "hw/sysbus.h" | |
44 | +VABS_hp ---- 1110 1.11 0000 .... 1001 11.0 .... @vfp_dm_ss | 39 | +#include "hw/qdev-clock.h" |
45 | VABS_sp ---- 1110 1.11 0000 .... 1010 11.0 .... @vfp_dm_ss | 40 | #include "migration/vmstate.h" |
46 | VABS_dp ---- 1110 1.11 0000 .... 1011 11.0 .... @vfp_dm_dd | 41 | #include "chardev/char-fe.h" |
47 | 42 | #include "qemu/log.h" | |
48 | +VNEG_hp ---- 1110 1.11 0001 .... 1001 01.0 .... @vfp_dm_ss | 43 | @@ -XXX,XX +XXX,XX @@ static void pl011_set_read_trigger(PL011State *s) |
49 | VNEG_sp ---- 1110 1.11 0001 .... 1010 01.0 .... @vfp_dm_ss | 44 | s->read_trigger = 1; |
50 | VNEG_dp ---- 1110 1.11 0001 .... 1011 01.0 .... @vfp_dm_dd | ||
51 | |||
52 | +VSQRT_hp ---- 1110 1.11 0001 .... 1001 11.0 .... @vfp_dm_ss | ||
53 | VSQRT_sp ---- 1110 1.11 0001 .... 1010 11.0 .... @vfp_dm_ss | ||
54 | VSQRT_dp ---- 1110 1.11 0001 .... 1011 11.0 .... @vfp_dm_dd | ||
55 | |||
56 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | ||
57 | index XXXXXXX..XXXXXXX 100644 | ||
58 | --- a/target/arm/vfp_helper.c | ||
59 | +++ b/target/arm/vfp_helper.c | ||
60 | @@ -XXX,XX +XXX,XX @@ float64 VFP_HELPER(neg, d)(float64 a) | ||
61 | return float64_chs(a); | ||
62 | } | 45 | } |
63 | 46 | ||
64 | +dh_ctype_f16 VFP_HELPER(abs, h)(dh_ctype_f16 a) | 47 | +static unsigned int pl011_get_baudrate(const PL011State *s) |
65 | +{ | 48 | +{ |
66 | + return float16_abs(a); | 49 | + uint64_t clk; |
50 | + | ||
51 | + if (s->fbrd == 0) { | ||
52 | + return 0; | ||
53 | + } | ||
54 | + | ||
55 | + clk = clock_get_hz(s->clk); | ||
56 | + return (clk / ((s->ibrd << 6) + s->fbrd)) << 2; | ||
67 | +} | 57 | +} |
68 | + | 58 | + |
69 | float32 VFP_HELPER(abs, s)(float32 a) | 59 | +static void pl011_trace_baudrate_change(const PL011State *s) |
70 | { | ||
71 | return float32_abs(a); | ||
72 | @@ -XXX,XX +XXX,XX @@ float64 VFP_HELPER(abs, d)(float64 a) | ||
73 | return float64_abs(a); | ||
74 | } | ||
75 | |||
76 | +dh_ctype_f16 VFP_HELPER(sqrt, h)(dh_ctype_f16 a, CPUARMState *env) | ||
77 | +{ | 60 | +{ |
78 | + return float16_sqrt(a, &env->vfp.fp_status_f16); | 61 | + trace_pl011_baudrate_change(pl011_get_baudrate(s), |
62 | + clock_get_hz(s->clk), | ||
63 | + s->ibrd, s->fbrd); | ||
79 | +} | 64 | +} |
80 | + | 65 | + |
81 | float32 VFP_HELPER(sqrt, s)(float32 a, CPUARMState *env) | 66 | static void pl011_write(void *opaque, hwaddr offset, |
67 | uint64_t value, unsigned size) | ||
82 | { | 68 | { |
83 | return float32_sqrt(a, &env->vfp.fp_status); | 69 | @@ -XXX,XX +XXX,XX @@ static void pl011_write(void *opaque, hwaddr offset, |
84 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 70 | break; |
85 | index XXXXXXX..XXXXXXX 100644 | 71 | case 9: /* UARTIBRD */ |
86 | --- a/target/arm/translate-vfp.c.inc | 72 | s->ibrd = value; |
87 | +++ b/target/arm/translate-vfp.c.inc | 73 | + pl011_trace_baudrate_change(s); |
88 | @@ -XXX,XX +XXX,XX @@ static bool do_vfp_2op_sp(DisasContext *s, VFPGen2OpSPFn *fn, int vd, int vm) | 74 | break; |
89 | return true; | 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); | ||
90 | } | 83 | } |
91 | 84 | ||
92 | +static bool do_vfp_2op_hp(DisasContext *s, VFPGen2OpSPFn *fn, int vd, int vm) | 85 | +static void pl011_clock_update(void *opaque) |
93 | +{ | 86 | +{ |
94 | + /* | 87 | + PL011State *s = PL011(opaque); |
95 | + * Do a half-precision operation. Functionally this is | ||
96 | + * the same as do_vfp_2op_sp(), except: | ||
97 | + * - it doesn't need the VFP vector handling (fp16 is a | ||
98 | + * v8 feature, and in v8 VFP vectors don't exist) | ||
99 | + * - it does the aa32_fp16_arith feature test | ||
100 | + */ | ||
101 | + TCGv_i32 f0; | ||
102 | + | 88 | + |
103 | + if (!dc_isar_feature(aa32_fp16_arith, s)) { | 89 | + pl011_trace_baudrate_change(s); |
104 | + return false; | ||
105 | + } | ||
106 | + | ||
107 | + if (s->vec_len != 0 || s->vec_stride != 0) { | ||
108 | + return false; | ||
109 | + } | ||
110 | + | ||
111 | + if (!vfp_access_check(s)) { | ||
112 | + return true; | ||
113 | + } | ||
114 | + | ||
115 | + f0 = tcg_temp_new_i32(); | ||
116 | + neon_load_reg32(f0, vm); | ||
117 | + fn(f0, f0); | ||
118 | + neon_store_reg32(f0, vd); | ||
119 | + tcg_temp_free_i32(f0); | ||
120 | + | ||
121 | + return true; | ||
122 | +} | 90 | +} |
123 | + | 91 | + |
124 | static bool do_vfp_2op_dp(DisasContext *s, VFPGen2OpDPFn *fn, int vd, int vm) | 92 | static const MemoryRegionOps pl011_ops = { |
125 | { | 93 | .read = pl011_read, |
126 | uint32_t delta_m = 0; | 94 | .write = pl011_write, |
127 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMOV_imm_dp(DisasContext *s, arg_VMOV_imm_dp *a) | 95 | .endianness = DEVICE_NATIVE_ENDIAN, |
128 | DO_VFP_2OP(VMOV_reg, sp, tcg_gen_mov_i32) | 96 | }; |
129 | DO_VFP_2OP(VMOV_reg, dp, tcg_gen_mov_i64) | 97 | |
130 | 98 | +static const VMStateDescription vmstate_pl011_clock = { | |
131 | +DO_VFP_2OP(VABS, hp, gen_helper_vfp_absh) | 99 | + .name = "pl011/clock", |
132 | DO_VFP_2OP(VABS, sp, gen_helper_vfp_abss) | 100 | + .version_id = 1, |
133 | DO_VFP_2OP(VABS, dp, gen_helper_vfp_absd) | 101 | + .minimum_version_id = 1, |
134 | 102 | + .fields = (VMStateField[]) { | |
135 | +DO_VFP_2OP(VNEG, hp, gen_helper_vfp_negh) | 103 | + VMSTATE_CLOCK(clk, PL011State), |
136 | DO_VFP_2OP(VNEG, sp, gen_helper_vfp_negs) | 104 | + VMSTATE_END_OF_LIST() |
137 | DO_VFP_2OP(VNEG, dp, gen_helper_vfp_negd) | 105 | + } |
138 | 106 | +}; | |
139 | +static void gen_VSQRT_hp(TCGv_i32 vd, TCGv_i32 vm) | ||
140 | +{ | ||
141 | + gen_helper_vfp_sqrth(vd, vm, cpu_env); | ||
142 | +} | ||
143 | + | 107 | + |
144 | static void gen_VSQRT_sp(TCGv_i32 vd, TCGv_i32 vm) | 108 | static const VMStateDescription vmstate_pl011 = { |
145 | { | 109 | .name = "pl011", |
146 | gen_helper_vfp_sqrts(vd, vm, cpu_env); | 110 | .version_id = 2, |
147 | @@ -XXX,XX +XXX,XX @@ static void gen_VSQRT_dp(TCGv_i64 vd, TCGv_i64 vm) | 111 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_pl011 = { |
148 | gen_helper_vfp_sqrtd(vd, vm, cpu_env); | 112 | VMSTATE_INT32(read_count, PL011State), |
149 | } | 113 | VMSTATE_INT32(read_trigger, PL011State), |
150 | 114 | VMSTATE_END_OF_LIST() | |
151 | +DO_VFP_2OP(VSQRT, hp, gen_VSQRT_hp) | 115 | + }, |
152 | DO_VFP_2OP(VSQRT, sp, gen_VSQRT_sp) | 116 | + .subsections = (const VMStateDescription * []) { |
153 | DO_VFP_2OP(VSQRT, dp, gen_VSQRT_dp) | 117 | + &vmstate_pl011_clock, |
154 | 118 | + NULL | |
119 | } | ||
120 | }; | ||
121 | |||
122 | @@ -XXX,XX +XXX,XX @@ static void pl011_init(Object *obj) | ||
123 | sysbus_init_irq(sbd, &s->irq[i]); | ||
124 | } | ||
125 | |||
126 | + s->clk = qdev_init_clock_in(DEVICE(obj), "clk", pl011_clock_update, s); | ||
127 | + | ||
128 | s->read_trigger = 1; | ||
129 | s->ifl = 0x12; | ||
130 | s->cr = 0x300; | ||
131 | diff --git a/hw/char/trace-events b/hw/char/trace-events | ||
132 | index XXXXXXX..XXXXXXX 100644 | ||
133 | --- a/hw/char/trace-events | ||
134 | +++ b/hw/char/trace-events | ||
135 | @@ -XXX,XX +XXX,XX @@ pl011_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" | ||
136 | pl011_can_receive(uint32_t lcr, int read_count, int r) "LCR 0x%08x read_count %d returning %d" | ||
137 | pl011_put_fifo(uint32_t c, int read_count) "new char 0x%x read_count now %d" | ||
138 | pl011_put_fifo_full(void) "FIFO now full, RXFF set" | ||
139 | +pl011_baudrate_change(unsigned int baudrate, uint64_t clock, uint32_t ibrd, uint32_t fbrd) "new baudrate %u (clk: %" PRIu64 "hz, ibrd: %" PRIu32 ", fbrd: %" PRIu32 ")" | ||
140 | |||
141 | # cmsdk-apb-uart.c | ||
142 | cmsdk_apb_uart_read(uint64_t offset, uint64_t data, unsigned size) "CMSDK APB UART read: offset 0x%" PRIx64 " data 0x%" PRIx64 " size %u" | ||
155 | -- | 143 | -- |
156 | 2.20.1 | 144 | 2.20.1 |
157 | 145 | ||
158 | 146 | diff view generated by jsdifflib |
1 | In several places the target/arm code defines local float constants | 1 | From: Luc Michel <luc@lmichel.fr> |
---|---|---|---|
2 | for 2, 3 and 1.5, which are also provided by include/fpu/softfloat.h. | ||
3 | Remove the unnecessary local duplicate versions. | ||
4 | 2 | ||
3 | Connect the 'uart-out' clock from the CPRMAN to the PL011 instance. | ||
4 | |||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Signed-off-by: Luc Michel <luc@lmichel.fr> | ||
7 | Tested-by: Guenter Roeck <linux@roeck-us.net> | ||
8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20200828183354.27913-2-peter.maydell@linaro.org | ||
8 | --- | 10 | --- |
9 | target/arm/helper-a64.c | 11 ----------- | 11 | hw/arm/bcm2835_peripherals.c | 2 ++ |
10 | target/arm/translate-sve.c | 4 ---- | 12 | 1 file changed, 2 insertions(+) |
11 | target/arm/vfp_helper.c | 4 ---- | ||
12 | 3 files changed, 19 deletions(-) | ||
13 | 13 | ||
14 | diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c | 14 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/helper-a64.c | 16 | --- a/hw/arm/bcm2835_peripherals.c |
17 | +++ b/target/arm/helper-a64.c | 17 | +++ b/hw/arm/bcm2835_peripherals.c |
18 | @@ -XXX,XX +XXX,XX @@ uint64_t HELPER(neon_cgt_f64)(float64 a, float64 b, void *fpstp) | 18 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) |
19 | * versions, these do a fully fused multiply-add or | 19 | } |
20 | * multiply-add-and-halve. | 20 | memory_region_add_subregion(&s->peri_mr, CPRMAN_OFFSET, |
21 | */ | 21 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cprman), 0)); |
22 | -#define float16_two make_float16(0x4000) | 22 | + qdev_connect_clock_in(DEVICE(&s->uart0), "clk", |
23 | -#define float16_three make_float16(0x4200) | 23 | + qdev_get_clock_out(DEVICE(&s->cprman), "uart-out")); |
24 | -#define float16_one_point_five make_float16(0x3e00) | 24 | |
25 | - | 25 | memory_region_add_subregion(&s->peri_mr, ARMCTRL_IC_OFFSET, |
26 | -#define float32_two make_float32(0x40000000) | 26 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->ic), 0)); |
27 | -#define float32_three make_float32(0x40400000) | ||
28 | -#define float32_one_point_five make_float32(0x3fc00000) | ||
29 | - | ||
30 | -#define float64_two make_float64(0x4000000000000000ULL) | ||
31 | -#define float64_three make_float64(0x4008000000000000ULL) | ||
32 | -#define float64_one_point_five make_float64(0x3FF8000000000000ULL) | ||
33 | |||
34 | uint32_t HELPER(recpsf_f16)(uint32_t a, uint32_t b, void *fpstp) | ||
35 | { | ||
36 | diff --git a/target/arm/translate-sve.c b/target/arm/translate-sve.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/arm/translate-sve.c | ||
39 | +++ b/target/arm/translate-sve.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static bool trans_##NAME##_zpzi(DisasContext *s, arg_rpri_esz *a) \ | ||
41 | return true; \ | ||
42 | } | ||
43 | |||
44 | -#define float16_two make_float16(0x4000) | ||
45 | -#define float32_two make_float32(0x40000000) | ||
46 | -#define float64_two make_float64(0x4000000000000000ULL) | ||
47 | - | ||
48 | DO_FP_IMM(FADD, fadds, half, one) | ||
49 | DO_FP_IMM(FSUB, fsubs, half, one) | ||
50 | DO_FP_IMM(FMUL, fmuls, half, two) | ||
51 | diff --git a/target/arm/vfp_helper.c b/target/arm/vfp_helper.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/arm/vfp_helper.c | ||
54 | +++ b/target/arm/vfp_helper.c | ||
55 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(vfp_fcvt_f64_to_f16)(float64 a, void *fpstp, uint32_t ahp_mode) | ||
56 | return r; | ||
57 | } | ||
58 | |||
59 | -#define float32_two make_float32(0x40000000) | ||
60 | -#define float32_three make_float32(0x40400000) | ||
61 | -#define float32_one_point_five make_float32(0x3fc00000) | ||
62 | - | ||
63 | float32 HELPER(recps_f32)(CPUARMState *env, float32 a, float32 b) | ||
64 | { | ||
65 | float_status *s = &env->vfp.standard_fp_status; | ||
66 | -- | 27 | -- |
67 | 2.20.1 | 28 | 2.20.1 |
68 | 29 | ||
69 | 30 | diff view generated by jsdifflib |
1 | From: Graeme Gregory <graeme@nuviainc.com> | 1 | From: Shashi Mallela <shashi.mallela@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | A difference between sbsa platform and the virt platform is PSCI is | 3 | Generic watchdog device model implementation as per ARM SBSA v6.0 |
4 | handled by ARM-TF in the sbsa platform. This means that the PSCI code | ||
5 | there needs to communicate some of the platform power changes down | ||
6 | to the qemu code for things like shutdown/reset control. | ||
7 | 4 | ||
8 | Space has been left to extend the EC if we find other use cases in | 5 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> |
9 | future where ARM-TF and qemu need to communicate. | 6 | Message-id: 20201027015927.29495-2-shashi.mallela@linaro.org |
10 | |||
11 | Signed-off-by: Graeme Gregory <graeme@nuviainc.com> | ||
12 | Reviewed-by: Leif Lindholm <leif@nuviainc.com> | ||
13 | Tested-by: Leif Lindholm <leif@nuviainc.com> | ||
14 | Message-id: 20200826141952.136164-2-graeme@nuviainc.com | ||
15 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 9 | --- |
18 | hw/misc/sbsa_ec.c | 98 +++++++++++++++++++++++++++++++++++++++++++++ | 10 | include/hw/watchdog/sbsa_gwdt.h | 79 +++++++++ |
19 | hw/misc/meson.build | 2 + | 11 | hw/watchdog/sbsa_gwdt.c | 293 ++++++++++++++++++++++++++++++++ |
20 | 2 files changed, 100 insertions(+) | 12 | hw/arm/Kconfig | 1 + |
21 | create mode 100644 hw/misc/sbsa_ec.c | 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 | ||
22 | 18 | ||
23 | diff --git a/hw/misc/sbsa_ec.c b/hw/misc/sbsa_ec.c | 19 | diff --git a/include/hw/watchdog/sbsa_gwdt.h b/include/hw/watchdog/sbsa_gwdt.h |
24 | new file mode 100644 | 20 | new file mode 100644 |
25 | index XXXXXXX..XXXXXXX | 21 | index XXXXXXX..XXXXXXX |
26 | --- /dev/null | 22 | --- /dev/null |
27 | +++ b/hw/misc/sbsa_ec.c | 23 | +++ b/include/hw/watchdog/sbsa_gwdt.h |
28 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ |
29 | +/* | 25 | +/* |
30 | + * ARM SBSA Reference Platform Embedded Controller | 26 | + * Copyright (c) 2020 Linaro Limited |
31 | + * | 27 | + * |
32 | + * A device to allow PSCI running in the secure side of sbsa-ref machine | 28 | + * Authors: |
33 | + * to communicate platform power states to qemu. | 29 | + * Shashi Mallela <shashi.mallela@linaro.org> |
34 | + * | 30 | + * |
35 | + * Copyright (c) 2020 Nuvia Inc | 31 | + * This work is licensed under the terms of the GNU GPL, version 2 or (at your |
36 | + * Written by Graeme Gregory <graeme@nuviainc.com> | 32 | + * option) any later version. See the COPYING file in the top-level directory. |
37 | + * | 33 | + * |
38 | + * SPDX-License-Identifer: GPL-2.0-or-later | ||
39 | + */ | 34 | + */ |
40 | + | 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 | + | ||
41 | +#include "qemu/osdep.h" | 127 | +#include "qemu/osdep.h" |
42 | +#include "qemu-common.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" | ||
43 | +#include "qemu/log.h" | 133 | +#include "qemu/log.h" |
44 | +#include "hw/sysbus.h" | 134 | +#include "qemu/module.h" |
45 | +#include "sysemu/runstate.h" | 135 | + |
46 | + | 136 | +static WatchdogTimerModel model = { |
47 | +typedef struct { | 137 | + .wdt_name = TYPE_WDT_SBSA, |
48 | + SysBusDevice parent_obj; | 138 | + .wdt_description = "SBSA-compliant generic watchdog device", |
49 | + MemoryRegion iomem; | ||
50 | +} SECUREECState; | ||
51 | + | ||
52 | +#define TYPE_SBSA_EC "sbsa-ec" | ||
53 | +#define SECURE_EC(obj) OBJECT_CHECK(SECUREECState, (obj), TYPE_SBSA_EC) | ||
54 | + | ||
55 | +enum sbsa_ec_powerstates { | ||
56 | + SBSA_EC_CMD_POWEROFF = 0x01, | ||
57 | + SBSA_EC_CMD_REBOOT = 0x02, | ||
58 | +}; | 139 | +}; |
59 | + | 140 | + |
60 | +static uint64_t sbsa_ec_read(void *opaque, hwaddr offset, unsigned size) | 141 | +static const VMStateDescription vmstate_sbsa_gwdt = { |
61 | +{ | 142 | + .name = "sbsa-gwdt", |
62 | + /* No use for this currently */ | 143 | + .version_id = 1, |
63 | + qemu_log_mask(LOG_GUEST_ERROR, "sbsa-ec: no readable registers"); | 144 | + .minimum_version_id = 1, |
64 | + return 0; | 145 | + .fields = (VMStateField[]) { |
65 | +} | 146 | + VMSTATE_TIMER_PTR(timer, SBSA_GWDTState), |
66 | + | 147 | + VMSTATE_UINT32(wcs, SBSA_GWDTState), |
67 | +static void sbsa_ec_write(void *opaque, hwaddr offset, | 148 | + VMSTATE_UINT32(worl, SBSA_GWDTState), |
68 | + uint64_t value, unsigned size) | 149 | + VMSTATE_UINT32(woru, SBSA_GWDTState), |
69 | +{ | 150 | + VMSTATE_UINT32(wcvl, SBSA_GWDTState), |
70 | + if (offset == 0) { /* PSCI machine power command register */ | 151 | + VMSTATE_UINT32(wcvu, SBSA_GWDTState), |
71 | + switch (value) { | 152 | + VMSTATE_END_OF_LIST() |
72 | + case SBSA_EC_CMD_POWEROFF: | 153 | + } |
73 | + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); | 154 | +}; |
74 | + break; | 155 | + |
75 | + case SBSA_EC_CMD_REBOOT: | 156 | +typedef enum WdtRefreshType { |
76 | + qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); | 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: | ||
77 | + break; | 328 | + break; |
78 | + default: | 329 | + default: |
79 | + qemu_log_mask(LOG_GUEST_ERROR, | 330 | + wdt_sbsa_gwdt_reset(DEVICE(s)); |
80 | + "sbsa-ec: unknown power command"); | ||
81 | + } | 331 | + } |
82 | + } else { | 332 | + watchdog_perform_action(); |
83 | + qemu_log_mask(LOG_GUEST_ERROR, "sbsa-ec: unknown EC register"); | 333 | + } |
84 | + } | 334 | +} |
85 | +} | 335 | + |
86 | + | 336 | +static const MemoryRegionOps sbsa_gwdt_rops = { |
87 | +static const MemoryRegionOps sbsa_ec_ops = { | 337 | + .read = sbsa_gwdt_rread, |
88 | + .read = sbsa_ec_read, | 338 | + .write = sbsa_gwdt_rwrite, |
89 | + .write = sbsa_ec_write, | 339 | + .endianness = DEVICE_LITTLE_ENDIAN, |
90 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
91 | + .valid.min_access_size = 4, | 340 | + .valid.min_access_size = 4, |
92 | + .valid.max_access_size = 4, | 341 | + .valid.max_access_size = 4, |
342 | + .valid.unaligned = false, | ||
93 | +}; | 343 | +}; |
94 | + | 344 | + |
95 | +static void sbsa_ec_init(Object *obj) | 345 | +static const MemoryRegionOps sbsa_gwdt_ops = { |
96 | +{ | 346 | + .read = sbsa_gwdt_read, |
97 | + SECUREECState *s = SECURE_EC(obj); | 347 | + .write = sbsa_gwdt_write, |
98 | + SysBusDevice *dev = SYS_BUS_DEVICE(obj); | 348 | + .endianness = DEVICE_LITTLE_ENDIAN, |
99 | + | 349 | + .valid.min_access_size = 4, |
100 | + memory_region_init_io(&s->iomem, obj, &sbsa_ec_ops, s, "sbsa-ec", | 350 | + .valid.max_access_size = 4, |
101 | + 0x1000); | 351 | + .valid.unaligned = false, |
102 | + sysbus_init_mmio(dev, &s->iomem); | 352 | +}; |
103 | +} | 353 | + |
104 | + | 354 | +static void wdt_sbsa_gwdt_realize(DeviceState *dev, Error **errp) |
105 | +static void sbsa_ec_class_init(ObjectClass *klass, void *data) | 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) | ||
106 | +{ | 379 | +{ |
107 | + DeviceClass *dc = DEVICE_CLASS(klass); | 380 | + DeviceClass *dc = DEVICE_CLASS(klass); |
108 | + | 381 | + |
109 | + /* No vmstate or reset required: device has no internal state */ | 382 | + dc->realize = wdt_sbsa_gwdt_realize; |
110 | + dc->user_creatable = false; | 383 | + dc->reset = wdt_sbsa_gwdt_reset; |
111 | +} | 384 | + dc->hotpluggable = false; |
112 | + | 385 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); |
113 | +static const TypeInfo sbsa_ec_info = { | 386 | + dc->vmsd = &vmstate_sbsa_gwdt; |
114 | + .name = TYPE_SBSA_EC, | 387 | +} |
115 | + .parent = TYPE_SYS_BUS_DEVICE, | 388 | + |
116 | + .instance_size = sizeof(SECUREECState), | 389 | +static const TypeInfo wdt_sbsa_gwdt_info = { |
117 | + .instance_init = sbsa_ec_init, | 390 | + .class_init = wdt_sbsa_gwdt_class_init, |
118 | + .class_init = sbsa_ec_class_init, | 391 | + .parent = TYPE_SYS_BUS_DEVICE, |
392 | + .name = TYPE_WDT_SBSA, | ||
393 | + .instance_size = sizeof(SBSA_GWDTState), | ||
119 | +}; | 394 | +}; |
120 | + | 395 | + |
121 | +static void sbsa_ec_register_type(void) | 396 | +static void wdt_sbsa_gwdt_register_types(void) |
122 | +{ | 397 | +{ |
123 | + type_register_static(&sbsa_ec_info); | 398 | + watchdog_add_model(&model); |
124 | +} | 399 | + type_register_static(&wdt_sbsa_gwdt_info); |
125 | + | 400 | +} |
126 | +type_init(sbsa_ec_register_type); | 401 | + |
127 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | 402 | +type_init(wdt_sbsa_gwdt_register_types) |
403 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
128 | index XXXXXXX..XXXXXXX 100644 | 404 | index XXXXXXX..XXXXXXX 100644 |
129 | --- a/hw/misc/meson.build | 405 | --- a/hw/arm/Kconfig |
130 | +++ b/hw/misc/meson.build | 406 | +++ b/hw/arm/Kconfig |
131 | @@ -XXX,XX +XXX,XX @@ specific_ss.add(when: 'CONFIG_MAC_VIA', if_true: files('mac_via.c')) | 407 | @@ -XXX,XX +XXX,XX @@ config SBSA_REF |
132 | 408 | select PL031 # RTC | |
133 | specific_ss.add(when: 'CONFIG_MIPS_CPS', if_true: files('mips_cmgcr.c', 'mips_cpc.c')) | 409 | select PL061 # GPIO |
134 | specific_ss.add(when: 'CONFIG_MIPS_ITU', if_true: files('mips_itu.c')) | 410 | select USB_EHCI_SYSBUS |
135 | + | 411 | + select WDT_SBSA |
136 | +specific_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa_ec.c')) | 412 | |
413 | config SABRELITE | ||
414 | bool | ||
415 | diff --git a/hw/watchdog/Kconfig b/hw/watchdog/Kconfig | ||
416 | index XXXXXXX..XXXXXXX 100644 | ||
417 | --- a/hw/watchdog/Kconfig | ||
418 | +++ b/hw/watchdog/Kconfig | ||
419 | @@ -XXX,XX +XXX,XX @@ config WDT_DIAG288 | ||
420 | |||
421 | config WDT_IMX2 | ||
422 | bool | ||
423 | + | ||
424 | +config WDT_SBSA | ||
425 | + bool | ||
426 | diff --git a/hw/watchdog/meson.build b/hw/watchdog/meson.build | ||
427 | index XXXXXXX..XXXXXXX 100644 | ||
428 | --- a/hw/watchdog/meson.build | ||
429 | +++ b/hw/watchdog/meson.build | ||
430 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_WDT_IB700', if_true: files('wdt_ib700.c')) | ||
431 | softmmu_ss.add(when: 'CONFIG_WDT_DIAG288', if_true: files('wdt_diag288.c')) | ||
432 | softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('wdt_aspeed.c')) | ||
433 | softmmu_ss.add(when: 'CONFIG_WDT_IMX2', if_true: files('wdt_imx2.c')) | ||
434 | +softmmu_ss.add(when: 'CONFIG_WDT_SBSA', if_true: files('sbsa_gwdt.c')) | ||
137 | -- | 435 | -- |
138 | 2.20.1 | 436 | 2.20.1 |
139 | 437 | ||
140 | 438 | diff view generated by jsdifflib |
1 | From: Graeme Gregory <graeme@nuviainc.com> | 1 | From: Shashi Mallela <shashi.mallela@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add the previously created sbsa-ec device to the sbsa-ref machine in | 3 | Included the newly implemented SBSA generic watchdog device model into |
4 | secure memory so the PSCI implementation in ARM-TF can access it, but | 4 | SBSA platform |
5 | not expose it to non secure firmware or OS except by via ARM-TF. | ||
6 | 5 | ||
7 | Signed-off-by: Graeme Gregory <graeme@nuviainc.com> | 6 | Signed-off-by: Shashi Mallela <shashi.mallela@linaro.org> |
8 | Reviewed-by: Leif Lindholm <leif@nuviainc.com> | ||
9 | Tested-by: Leif Lindholm <leif@nuviainc.com> | ||
10 | Message-id: 20200826141952.136164-3-graeme@nuviainc.com | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Message-id: 20201027015927.29495-3-shashi.mallela@linaro.org | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 10 | --- |
14 | hw/arm/sbsa-ref.c | 14 ++++++++++++++ | 11 | hw/arm/sbsa-ref.c | 23 +++++++++++++++++++++++ |
15 | 1 file changed, 14 insertions(+) | 12 | 1 file changed, 23 insertions(+) |
16 | 13 | ||
17 | diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c | 14 | diff --git a/hw/arm/sbsa-ref.c b/hw/arm/sbsa-ref.c |
18 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/hw/arm/sbsa-ref.c | 16 | --- a/hw/arm/sbsa-ref.c |
20 | +++ b/hw/arm/sbsa-ref.c | 17 | +++ b/hw/arm/sbsa-ref.c |
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | #include "hw/qdev-properties.h" | ||
20 | #include "hw/usb.h" | ||
21 | #include "hw/char/pl011.h" | ||
22 | +#include "hw/watchdog/sbsa_gwdt.h" | ||
23 | #include "net/net.h" | ||
24 | #include "qom/object.h" | ||
25 | |||
21 | @@ -XXX,XX +XXX,XX @@ enum { | 26 | @@ -XXX,XX +XXX,XX @@ enum { |
22 | SBSA_CPUPERIPHS, | ||
23 | SBSA_GIC_DIST, | 27 | SBSA_GIC_DIST, |
24 | SBSA_GIC_REDIST, | 28 | SBSA_GIC_REDIST, |
25 | + SBSA_SECURE_EC, | 29 | SBSA_SECURE_EC, |
30 | + SBSA_GWDT, | ||
31 | + SBSA_GWDT_REFRESH, | ||
32 | + SBSA_GWDT_CONTROL, | ||
26 | SBSA_SMMU, | 33 | SBSA_SMMU, |
27 | SBSA_UART, | 34 | SBSA_UART, |
28 | SBSA_RTC, | 35 | SBSA_RTC, |
29 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = { | 36 | @@ -XXX,XX +XXX,XX @@ static const MemMapEntry sbsa_ref_memmap[] = { |
30 | [SBSA_CPUPERIPHS] = { 0x40000000, 0x00040000 }, | ||
31 | [SBSA_GIC_DIST] = { 0x40060000, 0x00010000 }, | 37 | [SBSA_GIC_DIST] = { 0x40060000, 0x00010000 }, |
32 | [SBSA_GIC_REDIST] = { 0x40080000, 0x04000000 }, | 38 | [SBSA_GIC_REDIST] = { 0x40080000, 0x04000000 }, |
33 | + [SBSA_SECURE_EC] = { 0x50000000, 0x00001000 }, | 39 | [SBSA_SECURE_EC] = { 0x50000000, 0x00001000 }, |
40 | + [SBSA_GWDT_REFRESH] = { 0x50010000, 0x00001000 }, | ||
41 | + [SBSA_GWDT_CONTROL] = { 0x50011000, 0x00001000 }, | ||
34 | [SBSA_UART] = { 0x60000000, 0x00001000 }, | 42 | [SBSA_UART] = { 0x60000000, 0x00001000 }, |
35 | [SBSA_RTC] = { 0x60010000, 0x00001000 }, | 43 | [SBSA_RTC] = { 0x60010000, 0x00001000 }, |
36 | [SBSA_GPIO] = { 0x60020000, 0x00001000 }, | 44 | [SBSA_GPIO] = { 0x60020000, 0x00001000 }, |
37 | @@ -XXX,XX +XXX,XX @@ static void *sbsa_ref_dtb(const struct arm_boot_info *binfo, int *fdt_size) | 45 | @@ -XXX,XX +XXX,XX @@ static const int sbsa_ref_irqmap[] = { |
38 | return board->fdt; | 46 | [SBSA_AHCI] = 10, |
47 | [SBSA_EHCI] = 11, | ||
48 | [SBSA_SMMU] = 12, /* ... to 15 */ | ||
49 | + [SBSA_GWDT] = 16, | ||
50 | }; | ||
51 | |||
52 | static uint64_t sbsa_ref_cpu_mp_affinity(SBSAMachineState *sms, int idx) | ||
53 | @@ -XXX,XX +XXX,XX @@ static void create_rtc(const SBSAMachineState *sms) | ||
54 | sysbus_create_simple("pl031", base, qdev_get_gpio_in(sms->gic, irq)); | ||
39 | } | 55 | } |
40 | 56 | ||
41 | +static void create_secure_ec(MemoryRegion *mem) | 57 | +static void create_wdt(const SBSAMachineState *sms) |
42 | +{ | 58 | +{ |
43 | + hwaddr base = sbsa_ref_memmap[SBSA_SECURE_EC].base; | 59 | + hwaddr rbase = sbsa_ref_memmap[SBSA_GWDT_REFRESH].base; |
44 | + DeviceState *dev = qdev_new("sbsa-ec"); | 60 | + hwaddr cbase = sbsa_ref_memmap[SBSA_GWDT_CONTROL].base; |
61 | + DeviceState *dev = qdev_new(TYPE_WDT_SBSA); | ||
45 | + SysBusDevice *s = SYS_BUS_DEVICE(dev); | 62 | + SysBusDevice *s = SYS_BUS_DEVICE(dev); |
63 | + int irq = sbsa_ref_irqmap[SBSA_GWDT]; | ||
46 | + | 64 | + |
47 | + memory_region_add_subregion(mem, base, | 65 | + sysbus_realize_and_unref(s, &error_fatal); |
48 | + sysbus_mmio_get_region(s, 0)); | 66 | + sysbus_mmio_map(s, 0, rbase); |
67 | + sysbus_mmio_map(s, 1, cbase); | ||
68 | + sysbus_connect_irq(s, 0, qdev_get_gpio_in(sms->gic, irq)); | ||
49 | +} | 69 | +} |
50 | + | 70 | + |
51 | static void sbsa_ref_init(MachineState *machine) | 71 | static DeviceState *gpio_key_dev; |
72 | static void sbsa_ref_powerdown_req(Notifier *n, void *opaque) | ||
52 | { | 73 | { |
53 | unsigned int smp_cpus = machine->smp.cpus; | ||
54 | @@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine) | 74 | @@ -XXX,XX +XXX,XX @@ static void sbsa_ref_init(MachineState *machine) |
55 | 75 | ||
56 | create_pcie(sms); | 76 | create_rtc(sms); |
57 | 77 | ||
58 | + create_secure_ec(secure_sysmem); | 78 | + create_wdt(sms); |
59 | + | 79 | + |
60 | sms->bootinfo.ram_size = machine->ram_size; | 80 | create_gpio(sms); |
61 | sms->bootinfo.nb_cpus = smp_cpus; | 81 | |
62 | sms->bootinfo.board_id = -1; | 82 | create_ahci(sms); |
63 | -- | 83 | -- |
64 | 2.20.1 | 84 | 2.20.1 |
65 | 85 | ||
66 | 86 | diff view generated by jsdifflib |
1 | Implement the fp16 versions of the VFP VCVT instruction forms | 1 | In ptimer_reload(), we call the callback function provided by the |
---|---|---|---|
2 | which convert between floating point and integer with a specified | 2 | timer device that is using the ptimer. This callback might disable |
3 | rounding mode. | 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. | ||
4 | 11 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
7 | Message-id: 20200828183354.27913-17-peter.maydell@linaro.org | 14 | Message-id: 20201015151829.14656-2-peter.maydell@linaro.org |
8 | --- | 15 | --- |
9 | target/arm/vfp-uncond.decode | 6 ++++-- | 16 | hw/core/ptimer.c | 4 ++++ |
10 | target/arm/translate-vfp.c.inc | 32 ++++++++++++++++++++++++-------- | 17 | 1 file changed, 4 insertions(+) |
11 | 2 files changed, 28 insertions(+), 10 deletions(-) | ||
12 | 18 | ||
13 | diff --git a/target/arm/vfp-uncond.decode b/target/arm/vfp-uncond.decode | 19 | diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c |
14 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/vfp-uncond.decode | 21 | --- a/hw/core/ptimer.c |
16 | +++ b/target/arm/vfp-uncond.decode | 22 | +++ b/hw/core/ptimer.c |
17 | @@ -XXX,XX +XXX,XX @@ VRINT 1111 1110 1.11 10 rm:2 .... 1011 01.0 .... \ | 23 | @@ -XXX,XX +XXX,XX @@ static void ptimer_reload(ptimer_state *s, int delta_adjust) |
18 | vm=%vm_dp vd=%vd_dp dp=1 | ||
19 | |||
20 | # VCVT float to int with specified rounding mode; Vd is always single-precision | ||
21 | +VCVT 1111 1110 1.11 11 rm:2 .... 1001 op:1 1.0 .... \ | ||
22 | + vm=%vm_sp vd=%vd_sp sz=1 | ||
23 | VCVT 1111 1110 1.11 11 rm:2 .... 1010 op:1 1.0 .... \ | ||
24 | - vm=%vm_sp vd=%vd_sp dp=0 | ||
25 | + vm=%vm_sp vd=%vd_sp sz=2 | ||
26 | VCVT 1111 1110 1.11 11 rm:2 .... 1011 op:1 1.0 .... \ | ||
27 | - vm=%vm_dp vd=%vd_sp dp=1 | ||
28 | + vm=%vm_dp vd=%vd_sp sz=3 | ||
29 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/arm/translate-vfp.c.inc | ||
32 | +++ b/target/arm/translate-vfp.c.inc | ||
33 | @@ -XXX,XX +XXX,XX @@ static bool trans_VRINT(DisasContext *s, arg_VRINT *a) | ||
34 | static bool trans_VCVT(DisasContext *s, arg_VCVT *a) | ||
35 | { | ||
36 | uint32_t rd, rm; | ||
37 | - bool dp = a->dp; | ||
38 | + int sz = a->sz; | ||
39 | TCGv_ptr fpst; | ||
40 | TCGv_i32 tcg_rmode, tcg_shift; | ||
41 | int rounding = fp_decode_rm[a->rm]; | ||
42 | @@ -XXX,XX +XXX,XX @@ static bool trans_VCVT(DisasContext *s, arg_VCVT *a) | ||
43 | return false; | ||
44 | } | 24 | } |
45 | 25 | ||
46 | - if (dp && !dc_isar_feature(aa32_fpdp_v2, s)) { | 26 | if (delta == 0) { |
47 | + if (sz == 3 && !dc_isar_feature(aa32_fpdp_v2, s)) { | 27 | + if (s->enabled == 0) { |
48 | + return false; | 28 | + /* trigger callback disabled the timer already */ |
49 | + } | 29 | + return; |
50 | + | 30 | + } |
51 | + if (sz == 1 && !dc_isar_feature(aa32_fp16_arith, s)) { | 31 | if (!qtest_enabled()) { |
52 | return false; | 32 | fprintf(stderr, "Timer with delta zero, disabling\n"); |
53 | } | ||
54 | |||
55 | /* UNDEF accesses to D16-D31 if they don't exist */ | ||
56 | - if (dp && !dc_isar_feature(aa32_simd_r32, s) && (a->vm & 0x10)) { | ||
57 | + if (sz == 3 && !dc_isar_feature(aa32_simd_r32, s) && (a->vm & 0x10)) { | ||
58 | return false; | ||
59 | } | ||
60 | |||
61 | @@ -XXX,XX +XXX,XX @@ static bool trans_VCVT(DisasContext *s, arg_VCVT *a) | ||
62 | return true; | ||
63 | } | ||
64 | |||
65 | - fpst = fpstatus_ptr(FPST_FPCR); | ||
66 | + if (sz == 1) { | ||
67 | + fpst = fpstatus_ptr(FPST_FPCR_F16); | ||
68 | + } else { | ||
69 | + fpst = fpstatus_ptr(FPST_FPCR); | ||
70 | + } | ||
71 | |||
72 | tcg_shift = tcg_const_i32(0); | ||
73 | |||
74 | tcg_rmode = tcg_const_i32(arm_rmode_to_sf(rounding)); | ||
75 | gen_helper_set_rmode(tcg_rmode, tcg_rmode, fpst); | ||
76 | |||
77 | - if (dp) { | ||
78 | + if (sz == 3) { | ||
79 | TCGv_i64 tcg_double, tcg_res; | ||
80 | TCGv_i32 tcg_tmp; | ||
81 | tcg_double = tcg_temp_new_i64(); | ||
82 | @@ -XXX,XX +XXX,XX @@ static bool trans_VCVT(DisasContext *s, arg_VCVT *a) | ||
83 | tcg_single = tcg_temp_new_i32(); | ||
84 | tcg_res = tcg_temp_new_i32(); | ||
85 | neon_load_reg32(tcg_single, rm); | ||
86 | - if (is_signed) { | ||
87 | - gen_helper_vfp_tosls(tcg_res, tcg_single, tcg_shift, fpst); | ||
88 | + if (sz == 1) { | ||
89 | + if (is_signed) { | ||
90 | + gen_helper_vfp_toslh(tcg_res, tcg_single, tcg_shift, fpst); | ||
91 | + } else { | ||
92 | + gen_helper_vfp_toulh(tcg_res, tcg_single, tcg_shift, fpst); | ||
93 | + } | ||
94 | } else { | ||
95 | - gen_helper_vfp_touls(tcg_res, tcg_single, tcg_shift, fpst); | ||
96 | + if (is_signed) { | ||
97 | + gen_helper_vfp_tosls(tcg_res, tcg_single, tcg_shift, fpst); | ||
98 | + } else { | ||
99 | + gen_helper_vfp_touls(tcg_res, tcg_single, tcg_shift, fpst); | ||
100 | + } | ||
101 | } | 33 | } |
102 | neon_store_reg32(tcg_res, rd); | ||
103 | tcg_temp_free_i32(tcg_res); | ||
104 | -- | 34 | -- |
105 | 2.20.1 | 35 | 2.20.1 |
106 | 36 | ||
107 | 37 | diff view generated by jsdifflib |
1 | Macroify creation of the trans functions for single and double | 1 | The armv7m systick timer is a 24-bit decrementing, wrap-on-zero, |
---|---|---|---|
2 | precision VFMA, VFMS, VFNMA, VFNMS. The repetition was OK for | 2 | clear-on-write counter. Our current implementation has various |
3 | two sizes, but we're about to add halfprec and it will get a bit | 3 | bugs and dubious workarounds in it (for instance see |
4 | more than seems reasonable. | 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. | ||
5 | 25 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 26 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 27 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
8 | Message-id: 20200828183354.27913-6-peter.maydell@linaro.org | 28 | Message-id: 20201015151829.14656-3-peter.maydell@linaro.org |
9 | --- | 29 | --- |
10 | target/arm/translate-vfp.c.inc | 50 +++++++++------------------------- | 30 | include/hw/timer/armv7m_systick.h | 3 +- |
11 | 1 file changed, 13 insertions(+), 37 deletions(-) | 31 | hw/timer/armv7m_systick.c | 124 +++++++++++++----------------- |
12 | 32 | 2 files changed, 54 insertions(+), 73 deletions(-) | |
13 | diff --git a/target/arm/translate-vfp.c.inc b/target/arm/translate-vfp.c.inc | 33 | |
34 | diff --git a/include/hw/timer/armv7m_systick.h b/include/hw/timer/armv7m_systick.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | 35 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/translate-vfp.c.inc | 36 | --- a/include/hw/timer/armv7m_systick.h |
16 | +++ b/target/arm/translate-vfp.c.inc | 37 | +++ b/include/hw/timer/armv7m_systick.h |
17 | @@ -XXX,XX +XXX,XX @@ static bool do_vfm_sp(DisasContext *s, arg_VFMA_sp *a, bool neg_n, bool neg_d) | 38 | @@ -XXX,XX +XXX,XX @@ |
18 | return true; | 39 | |
19 | } | 40 | #include "hw/sysbus.h" |
20 | 41 | #include "qom/object.h" | |
21 | -static bool trans_VFMA_sp(DisasContext *s, arg_VFMA_sp *a) | 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) | ||
22 | -{ | 64 | -{ |
23 | - return do_vfm_sp(s, a, false, false); | 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); | ||
24 | -} | 81 | -} |
25 | - | 82 | - |
26 | -static bool trans_VFMS_sp(DisasContext *s, arg_VFMS_sp *a) | 83 | static void systick_timer_tick(void *opaque) |
27 | -{ | ||
28 | - return do_vfm_sp(s, a, true, false); | ||
29 | -} | ||
30 | - | ||
31 | -static bool trans_VFNMA_sp(DisasContext *s, arg_VFNMA_sp *a) | ||
32 | -{ | ||
33 | - return do_vfm_sp(s, a, false, true); | ||
34 | -} | ||
35 | - | ||
36 | -static bool trans_VFNMS_sp(DisasContext *s, arg_VFNMS_sp *a) | ||
37 | -{ | ||
38 | - return do_vfm_sp(s, a, true, true); | ||
39 | -} | ||
40 | - | ||
41 | static bool do_vfm_dp(DisasContext *s, arg_VFMA_dp *a, bool neg_n, bool neg_d) | ||
42 | { | 84 | { |
43 | /* | 85 | SysTickState *s = (SysTickState *)opaque; |
44 | @@ -XXX,XX +XXX,XX @@ static bool do_vfm_dp(DisasContext *s, arg_VFMA_dp *a, bool neg_n, bool neg_d) | 86 | @@ -XXX,XX +XXX,XX @@ static void systick_timer_tick(void *opaque) |
45 | return true; | 87 | /* Tell the NVIC to pend the SysTick exception */ |
46 | } | 88 | qemu_irq_pulse(s->irq); |
47 | 89 | } | |
48 | -static bool trans_VFMA_dp(DisasContext *s, arg_VFMA_dp *a) | 90 | - if (s->reload == 0) { |
49 | -{ | 91 | - s->control &= ~SYSTICK_ENABLE; |
50 | - return do_vfm_dp(s, a, false, false); | 92 | - } else { |
51 | -} | 93 | - systick_reload(s, 0); |
52 | +#define MAKE_ONE_VFM_TRANS_FN(INSN, PREC, NEGN, NEGD) \ | 94 | + if (ptimer_get_limit(s->ptimer) == 0) { |
53 | + static bool trans_##INSN##_##PREC(DisasContext *s, \ | 95 | + /* |
54 | + arg_##INSN##_##PREC *a) \ | 96 | + * Timer expiry with SYST_RVR zero disables the timer |
55 | + { \ | 97 | + * (but doesn't clear SYST_CSR.ENABLE) |
56 | + return do_vfm_##PREC(s, a, NEGN, NEGD); \ | 98 | + */ |
57 | + } | 99 | + ptimer_stop(s->ptimer); |
58 | 100 | } | |
59 | -static bool trans_VFMS_dp(DisasContext *s, arg_VFMS_dp *a) | 101 | } |
60 | -{ | 102 | |
61 | - return do_vfm_dp(s, a, true, false); | 103 | @@ -XXX,XX +XXX,XX @@ static MemTxResult systick_read(void *opaque, hwaddr addr, uint64_t *data, |
62 | -} | 104 | s->control &= ~SYSTICK_COUNTFLAG; |
63 | +#define MAKE_VFM_TRANS_FNS(PREC) \ | 105 | break; |
64 | + MAKE_ONE_VFM_TRANS_FN(VFMA, PREC, false, false) \ | 106 | case 0x4: /* SysTick Reload Value. */ |
65 | + MAKE_ONE_VFM_TRANS_FN(VFMS, PREC, true, false) \ | 107 | - val = s->reload; |
66 | + MAKE_ONE_VFM_TRANS_FN(VFNMA, PREC, false, true) \ | 108 | + val = ptimer_get_limit(s->ptimer); |
67 | + MAKE_ONE_VFM_TRANS_FN(VFNMS, PREC, true, true) | 109 | break; |
68 | 110 | case 0x8: /* SysTick Current Value. */ | |
69 | -static bool trans_VFNMA_dp(DisasContext *s, arg_VFNMA_dp *a) | 111 | - { |
70 | -{ | 112 | - int64_t t; |
71 | - return do_vfm_dp(s, a, false, true); | 113 | - |
72 | -} | 114 | - if ((s->control & SYSTICK_ENABLE) == 0) { |
73 | - | 115 | - val = 0; |
74 | -static bool trans_VFNMS_dp(DisasContext *s, arg_VFNMS_dp *a) | 116 | - break; |
75 | -{ | 117 | - } |
76 | - return do_vfm_dp(s, a, true, true); | 118 | - t = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
77 | -} | 119 | - if (t >= s->tick) { |
78 | +MAKE_VFM_TRANS_FNS(sp) | 120 | - val = 0; |
79 | +MAKE_VFM_TRANS_FNS(dp) | 121 | - break; |
80 | 122 | - } | |
81 | static bool trans_VMOV_imm_sp(DisasContext *s, arg_VMOV_imm_sp *a) | 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) | ||
82 | { | 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 | }; | ||
83 | -- | 250 | -- |
84 | 2.20.1 | 251 | 2.20.1 |
85 | 252 | ||
86 | 253 | diff view generated by jsdifflib |