1 | Another lump of target-arm patches. I still have some patches in | 1 | The following changes since commit ec397e90d21269037280633b6058d1f280e27667: |
---|---|---|---|
2 | my to-review queue, but this is a big enough set that I wanted | ||
3 | to send it out. | ||
4 | 2 | ||
5 | thanks | 3 | Merge remote-tracking branch 'remotes/alistair/tags/pull-riscv-to-apply-20210901-2' into staging (2021-09-01 08:33:02 +0100) |
6 | -- PMM | ||
7 | |||
8 | The following changes since commit 04bb7fe2bf55bdf66d5b7a5a719b40bbb4048178: | ||
9 | |||
10 | Merge remote-tracking branch 'remotes/rth/tags/pull-tcg-20180208' into staging (2018-02-08 17:41:15 +0000) | ||
11 | 4 | ||
12 | are available in the Git repository at: | 5 | are available in the Git repository at: |
13 | 6 | ||
14 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180209 | 7 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210901 |
15 | 8 | ||
16 | for you to fetch changes up to bbba7757bacc9f890a3f028d328b4b429dbe78ec: | 9 | for you to fetch changes up to 683754c7b61f9e2ff098720ec80c9ab86c54663d: |
17 | 10 | ||
18 | hw/core/generic-loader: Allow PC to be set on command line (2018-02-09 10:55:40 +0000) | 11 | arm: Remove system_clock_scale global (2021-09-01 11:08:21 +0100) |
19 | 12 | ||
20 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
21 | target-arm queue: | 14 | * Refactor M-profile systick to use Clocks instead of system_clock_scale global |
22 | * Support M profile derived exceptions on exception entry and exit | 15 | * clock: Provide builtin multiplier/divider |
23 | * Implement AArch64 v8.2 crypto insns (SHA-512, SHA-3, SM3, SM4) | 16 | * Add A64FX processor model |
24 | * Implement working i.MX6 SD controller | 17 | * Enable MVE emulation in Cortex-M55 |
25 | * Various devices preparatory to i.MX7 support | 18 | * hw: Add compat machines for 6.2 |
26 | * Preparatory patches for SVE emulation | 19 | * hw/intc/arm_gicv3: Replace mis-used MEMTX_* constants by booleans |
27 | * v8M: Fix bug in implementation of 'TT' insn | 20 | * hw/arm/raspi: Remove deprecated raspi2/raspi3 aliases |
28 | * Give useful error if user tries to use userspace GICv3 with KVM | ||
29 | 21 | ||
30 | ---------------------------------------------------------------- | 22 | ---------------------------------------------------------------- |
31 | Andrey Smirnov (10): | 23 | Peter Maydell (43): |
32 | sdhci: Add i.MX specific subtype of SDHCI | 24 | target/arm: Implement MVE VADD (floating-point) |
33 | hw: i.MX: Convert i.MX6 to use TYPE_IMX_USDHC | 25 | target/arm: Implement MVE VSUB, VMUL, VABD, VMAXNM, VMINNM |
34 | i.MX: Add code to emulate i.MX7 CCM, PMU and ANALOG IP blocks | 26 | target/arm: Implement MVE VCADD |
35 | i.MX: Add code to emulate i.MX2 watchdog IP block | 27 | target/arm: Implement MVE VFMA and VFMS |
36 | i.MX: Add code to emulate i.MX7 SNVS IP-block | 28 | target/arm: Implement MVE VCMUL and VCMLA |
37 | i.MX: Add code to emulate GPCv2 IP block | 29 | target/arm: Implement MVE VMAXNMA and VMINNMA |
38 | i.MX: Add i.MX7 GPT variant | 30 | target/arm: Implement MVE scalar fp insns |
39 | i.MX: Add implementation of i.MX7 GPR IP block | 31 | target/arm: Implement MVE fp-with-scalar VFMA, VFMAS |
40 | usb: Add basic code to emulate Chipidea USB IP | 32 | softfloat: Remove assertion preventing silencing of NaN in default-NaN mode |
41 | hw/arm: Move virt's PSCI DT fixup code to arm/boot.c | 33 | target/arm: Implement MVE FP max/min across vector |
34 | target/arm: Implement MVE fp vector comparisons | ||
35 | target/arm: Implement MVE fp scalar comparisons | ||
36 | target/arm: Implement MVE VCVT between floating and fixed point | ||
37 | target/arm: Implement MVE VCVT between fp and integer | ||
38 | target/arm: Implement MVE VCVT with specified rounding mode | ||
39 | target/arm: Implement MVE VCVT between single and half precision | ||
40 | target/arm: Implement MVE VRINT insns | ||
41 | target/arm: Enable MVE in Cortex-M55 | ||
42 | arm: Move M-profile RAS register block into its own device | ||
43 | arm: Move systick device creation from NVIC to ARMv7M object | ||
44 | arm: Move system PPB container handling to armv7m | ||
45 | hw/timer/armv7m_systick: Add usual QEMU interface comment | ||
46 | hw/timer/armv7m_systick: Add input clocks | ||
47 | hw/arm/armv7m: Create input clocks | ||
48 | armsse: Wire up systick cpuclk clock | ||
49 | hw/arm/mps2.c: Connect up armv7m clocks | ||
50 | clock: Provide builtin multiplier/divider | ||
51 | hw/arm: Don't allocate separate MemoryRegions in stm32 SoC realize | ||
52 | hw/arm/stm32f100: Wire up sysclk and refclk | ||
53 | hw/arm/stm32f205: Wire up sysclk and refclk | ||
54 | hw/arm/stm32f405: Wire up sysclk and refclk | ||
55 | hw/arm/stm32vldiscovery: Delete trailing blank line | ||
56 | hw/arm/nrf51: Wire up sysclk | ||
57 | hw/arm/stellaris: split stellaris_sys_init() | ||
58 | hw/arm/stellaris: Wire sysclk up to armv7m | ||
59 | hw/arm/msf2_soc: Don't allocate separate MemoryRegions | ||
60 | hw/arm/msf2: Use Clock input to MSF2_SOC instead of m3clk property | ||
61 | hw/arm/msf2-soc: Wire up refclk | ||
62 | hw/timer/armv7m_systick: Use clock inputs instead of system_clock_scale | ||
63 | hw/arm/stellaris: Fix code style issues in GPTM code | ||
64 | hw/arm/stellaris: Split stellaris-gptm into its own file | ||
65 | hw/timer/stellaris-gptm: Use Clock input instead of system_clock_scale | ||
66 | arm: Remove system_clock_scale global | ||
42 | 67 | ||
43 | Ard Biesheuvel (5): | 68 | Philippe Mathieu-Daudé (4): |
44 | target/arm: implement SHA-512 instructions | 69 | tests: Remove uses of deprecated raspi2/raspi3 machine names |
45 | target/arm: implement SHA-3 instructions | 70 | hw/arm/raspi: Remove deprecated raspi2/raspi3 aliases |
46 | target/arm: implement SM3 instructions | 71 | hw/intc/arm_gicv3_dist: Rename 64-bit accessors with 'q' suffix |
47 | target/arm: implement SM4 instructions | 72 | hw/intc/arm_gicv3: Replace mis-used MEMTX_* constants by booleans |
48 | target/arm: enable user-mode SHA-3, SM3, SM4 and SHA-512 instruction support | ||
49 | 73 | ||
50 | Christoffer Dall (1): | 74 | Shuuichirou Ishii (3): |
51 | target/arm/kvm: gic: Prevent creating userspace GICv3 with KVM | 75 | target-arm: Add support for Fujitsu A64FX |
76 | hw/arm/virt: target-arm: Add A64FX processor support to virt machine | ||
77 | tests/arm-cpu-features: Add A64FX processor related tests | ||
52 | 78 | ||
53 | Peter Maydell (9): | 79 | Yanan Wang (1): |
54 | target/arm: Add armv7m_nvic_set_pending_derived() | 80 | hw: Add compat machines for 6.2 |
55 | target/arm: Split "get pending exception info" from "acknowledge it" | ||
56 | target/arm: Add ignore_stackfaults argument to v7m_exception_taken() | ||
57 | target/arm: Make v7M exception entry stack push check MPU | ||
58 | target/arm: Make v7m_push_callee_stack() honour MPU | ||
59 | target/arm: Make exception vector loads honour the SAU | ||
60 | target/arm: Handle exceptions during exception stack pop | ||
61 | target/arm/translate.c: Fix missing 'break' for TT insns | ||
62 | hw/core/generic-loader: Allow PC to be set on command line | ||
63 | 81 | ||
64 | Richard Henderson (5): | 82 | docs/about/deprecated.rst | 7 - |
65 | target/arm: Expand vector registers for SVE | 83 | docs/about/removed-features.rst | 7 + |
66 | target/arm: Add predicate registers for SVE | 84 | docs/devel/clocks.rst | 23 ++ |
67 | target/arm: Add SVE to migration state | 85 | docs/devel/qgraph.rst | 38 +- |
68 | target/arm: Add ZCR_ELx | 86 | docs/system/arm/virt.rst | 1 + |
69 | target/arm: Add SVE state to TB->FLAGS | 87 | include/hw/arm/armv7m.h | 24 ++ |
88 | include/hw/arm/msf2-soc.h | 8 +- | ||
89 | include/hw/arm/nrf51_soc.h | 2 + | ||
90 | include/hw/arm/stm32f100_soc.h | 8 + | ||
91 | include/hw/arm/stm32f205_soc.h | 8 + | ||
92 | include/hw/arm/stm32f405_soc.h | 3 + | ||
93 | include/hw/boards.h | 3 + | ||
94 | include/hw/clock.h | 29 ++ | ||
95 | include/hw/i386/pc.h | 3 + | ||
96 | include/hw/intc/armv7m_nvic.h | 8 - | ||
97 | include/hw/misc/armv7m_ras.h | 37 ++ | ||
98 | include/hw/timer/armv7m_systick.h | 36 +- | ||
99 | include/hw/timer/stellaris-gptm.h | 51 +++ | ||
100 | target/arm/helper-mve.h | 142 +++++++ | ||
101 | target/arm/translate.h | 6 + | ||
102 | tests/qtest/libqos/qgraph.h | 6 +- | ||
103 | tests/qtest/libqos/qgraph_internal.h | 2 +- | ||
104 | target/arm/mve.decode | 297 +++++++++++++-- | ||
105 | hw/arm/armsse.c | 20 +- | ||
106 | hw/arm/armv7m.c | 260 ++++++++++++- | ||
107 | hw/arm/mps2.c | 17 +- | ||
108 | hw/arm/msf2-soc.c | 68 ++-- | ||
109 | hw/arm/msf2-som.c | 7 +- | ||
110 | hw/arm/netduino2.c | 12 +- | ||
111 | hw/arm/netduinoplus2.c | 12 +- | ||
112 | hw/arm/nrf51_soc.c | 20 +- | ||
113 | hw/arm/raspi.c | 2 - | ||
114 | hw/arm/stellaris.c | 396 +++---------------- | ||
115 | hw/arm/stm32f100_soc.c | 47 ++- | ||
116 | hw/arm/stm32f205_soc.c | 47 ++- | ||
117 | hw/arm/stm32f405_soc.c | 30 ++ | ||
118 | hw/arm/stm32vldiscovery.c | 13 +- | ||
119 | hw/arm/virt.c | 12 +- | ||
120 | hw/core/clock-vmstate.c | 40 +- | ||
121 | hw/core/clock.c | 31 +- | ||
122 | hw/core/machine.c | 3 + | ||
123 | hw/i386/pc.c | 3 + | ||
124 | hw/i386/pc_piix.c | 14 +- | ||
125 | hw/i386/pc_q35.c | 13 +- | ||
126 | hw/intc/arm_gicv3_dist.c | 205 +++++----- | ||
127 | hw/intc/armv7m_nvic.c | 274 +------------- | ||
128 | hw/misc/armv7m_ras.c | 93 +++++ | ||
129 | hw/ppc/spapr.c | 17 +- | ||
130 | hw/s390x/s390-virtio-ccw.c | 14 +- | ||
131 | hw/timer/armv7m_systick.c | 118 ++++-- | ||
132 | hw/timer/stellaris-gptm.c | 332 ++++++++++++++++ | ||
133 | target/arm/cpu64.c | 48 +++ | ||
134 | target/arm/cpu_tcg.c | 7 +- | ||
135 | target/arm/mve_helper.c | 650 ++++++++++++++++++++++++++++++++ | ||
136 | target/arm/translate-mve.c | 277 +++++++++++++- | ||
137 | target/arm/translate-neon.c | 6 - | ||
138 | tests/qtest/arm-cpu-features.c | 13 + | ||
139 | tests/qtest/boot-serial-test.c | 2 +- | ||
140 | tests/qtest/libqos/arm-raspi2-machine.c | 8 +- | ||
141 | tests/unit/test-qgraph.c | 2 +- | ||
142 | fpu/softfloat-specialize.c.inc | 1 - | ||
143 | MAINTAINERS | 2 + | ||
144 | hw/arm/Kconfig | 1 + | ||
145 | hw/core/trace-events | 1 + | ||
146 | hw/misc/meson.build | 2 + | ||
147 | hw/timer/Kconfig | 3 + | ||
148 | hw/timer/meson.build | 1 + | ||
149 | tests/acceptance/boot_linux_console.py | 6 +- | ||
150 | 68 files changed, 2928 insertions(+), 971 deletions(-) | ||
151 | create mode 100644 include/hw/misc/armv7m_ras.h | ||
152 | create mode 100644 include/hw/timer/stellaris-gptm.h | ||
153 | create mode 100644 hw/misc/armv7m_ras.c | ||
154 | create mode 100644 hw/timer/stellaris-gptm.c | ||
70 | 155 | ||
71 | hw/intc/Makefile.objs | 2 +- | ||
72 | hw/misc/Makefile.objs | 4 + | ||
73 | hw/usb/Makefile.objs | 1 + | ||
74 | hw/sd/sdhci-internal.h | 23 ++ | ||
75 | include/hw/intc/imx_gpcv2.h | 22 ++ | ||
76 | include/hw/misc/imx2_wdt.h | 33 +++ | ||
77 | include/hw/misc/imx7_ccm.h | 139 +++++++++++ | ||
78 | include/hw/misc/imx7_gpr.h | 28 +++ | ||
79 | include/hw/misc/imx7_snvs.h | 35 +++ | ||
80 | include/hw/sd/sdhci.h | 13 ++ | ||
81 | include/hw/timer/imx_gpt.h | 1 + | ||
82 | include/hw/usb/chipidea.h | 16 ++ | ||
83 | target/arm/cpu.h | 120 ++++++++-- | ||
84 | target/arm/helper.h | 12 + | ||
85 | target/arm/kvm_arm.h | 4 + | ||
86 | target/arm/translate.h | 2 + | ||
87 | hw/arm/boot.c | 65 ++++++ | ||
88 | hw/arm/fsl-imx6.c | 2 +- | ||
89 | hw/arm/virt.c | 61 ----- | ||
90 | hw/core/generic-loader.c | 2 +- | ||
91 | hw/intc/armv7m_nvic.c | 98 +++++++- | ||
92 | hw/intc/imx_gpcv2.c | 125 ++++++++++ | ||
93 | hw/misc/imx2_wdt.c | 89 +++++++ | ||
94 | hw/misc/imx7_ccm.c | 277 ++++++++++++++++++++++ | ||
95 | hw/misc/imx7_gpr.c | 124 ++++++++++ | ||
96 | hw/misc/imx7_snvs.c | 83 +++++++ | ||
97 | hw/sd/sdhci.c | 230 ++++++++++++++++++- | ||
98 | hw/timer/imx_gpt.c | 25 ++ | ||
99 | hw/usb/chipidea.c | 176 ++++++++++++++ | ||
100 | linux-user/elfload.c | 19 ++ | ||
101 | target/arm/cpu64.c | 4 + | ||
102 | target/arm/crypto_helper.c | 277 +++++++++++++++++++++- | ||
103 | target/arm/helper.c | 548 +++++++++++++++++++++++++++++++++++++------- | ||
104 | target/arm/machine.c | 88 ++++++- | ||
105 | target/arm/translate-a64.c | 350 +++++++++++++++++++++++++++- | ||
106 | target/arm/translate.c | 8 +- | ||
107 | hw/intc/trace-events | 5 +- | ||
108 | hw/misc/trace-events | 4 + | ||
109 | 38 files changed, 2928 insertions(+), 187 deletions(-) | ||
110 | create mode 100644 include/hw/intc/imx_gpcv2.h | ||
111 | create mode 100644 include/hw/misc/imx2_wdt.h | ||
112 | create mode 100644 include/hw/misc/imx7_ccm.h | ||
113 | create mode 100644 include/hw/misc/imx7_gpr.h | ||
114 | create mode 100644 include/hw/misc/imx7_snvs.h | ||
115 | create mode 100644 include/hw/usb/chipidea.h | ||
116 | create mode 100644 hw/intc/imx_gpcv2.c | ||
117 | create mode 100644 hw/misc/imx2_wdt.c | ||
118 | create mode 100644 hw/misc/imx7_ccm.c | ||
119 | create mode 100644 hw/misc/imx7_gpr.c | ||
120 | create mode 100644 hw/misc/imx7_snvs.c | ||
121 | create mode 100644 hw/usb/chipidea.c | ||
122 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | |
2 | |||
3 | Commit 155e1c82ed0 deprecated the raspi2/raspi3 machine names. | ||
4 | Use the recommended new names: raspi2b and raspi3b. | ||
5 | |||
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Thomas Huth <thuth@redhat.com> | ||
8 | Reviewed-by: Willian Rampazzo <willianr@redhat.com> | ||
9 | Message-id: 20210827060815.2384760-2-f4bug@amsat.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | docs/devel/qgraph.rst | 38 ++++++++++++------------- | ||
13 | tests/qtest/libqos/qgraph.h | 6 ++-- | ||
14 | tests/qtest/libqos/qgraph_internal.h | 2 +- | ||
15 | tests/qtest/boot-serial-test.c | 2 +- | ||
16 | tests/qtest/libqos/arm-raspi2-machine.c | 8 +++--- | ||
17 | tests/unit/test-qgraph.c | 2 +- | ||
18 | tests/acceptance/boot_linux_console.py | 6 ++-- | ||
19 | 7 files changed, 32 insertions(+), 32 deletions(-) | ||
20 | |||
21 | diff --git a/docs/devel/qgraph.rst b/docs/devel/qgraph.rst | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/docs/devel/qgraph.rst | ||
24 | +++ b/docs/devel/qgraph.rst | ||
25 | @@ -XXX,XX +XXX,XX @@ Nodes | ||
26 | |||
27 | A node can be of four types: | ||
28 | |||
29 | -- **QNODE_MACHINE**: for example ``arm/raspi2`` | ||
30 | +- **QNODE_MACHINE**: for example ``arm/raspi2b`` | ||
31 | - **QNODE_DRIVER**: for example ``generic-sdhci`` | ||
32 | - **QNODE_INTERFACE**: for example ``sdhci`` (interface for all ``-sdhci`` | ||
33 | drivers). | ||
34 | @@ -XXX,XX +XXX,XX @@ It is possible to troubleshoot unavailable tests by running:: | ||
35 | # |-> dest='i440FX-pcihost' type=0 (node=0x5591421117f0) | ||
36 | # src='' | ||
37 | # |-> dest='x86_64/pc' type=0 (node=0x559142111600) | ||
38 | - # |-> dest='arm/raspi2' type=0 (node=0x559142110740) | ||
39 | + # |-> dest='arm/raspi2b' type=0 (node=0x559142110740) | ||
40 | ... | ||
41 | # } | ||
42 | # ALL QGRAPH NODES: { | ||
43 | # name='virtio-net-tests/announce-self' type=3 cmd_line='(null)' [available] | ||
44 | - # name='arm/raspi2' type=0 cmd_line='-M raspi2 ' [UNAVAILABLE] | ||
45 | + # name='arm/raspi2b' type=0 cmd_line='-M raspi2b ' [UNAVAILABLE] | ||
46 | ... | ||
47 | # } | ||
48 | |||
49 | @@ -XXX,XX +XXX,XX @@ qgraph path in the "ALL QGRAPH EDGES" output as follows: '' -> 'x86_64/pc' -> | ||
50 | 'virtio-net'. The root of the qgraph is '' and the depth first search begins | ||
51 | there. | ||
52 | |||
53 | -The ``arm/raspi`` machine node is listed as "UNAVAILABLE". Although it is | ||
54 | -reachable from the root via '' -> 'arm/raspi2' the node is unavailable because | ||
55 | +The ``arm/raspi2b`` machine node is listed as "UNAVAILABLE". Although it is | ||
56 | +reachable from the root via '' -> 'arm/raspi2b' the node is unavailable because | ||
57 | the QEMU binary did not list it when queried by the framework. This is expected | ||
58 | because we used the ``qemu-system-x86_64`` binary which does not support ARM | ||
59 | machine types. | ||
60 | @@ -XXX,XX +XXX,XX @@ Here we continue the ``sdhci`` use case, with the following scenario: | ||
61 | - ``sdhci-test`` aims to test the ``read[q,w], writeq`` functions | ||
62 | offered by the ``sdhci`` drivers. | ||
63 | - The current ``sdhci`` device is supported by both ``x86_64/pc`` and ``ARM`` | ||
64 | - (in this example we focus on the ``arm-raspi2``) machines. | ||
65 | + (in this example we focus on the ``arm-raspi2b``) machines. | ||
66 | - QEMU offers 2 types of drivers: ``QSDHCI_MemoryMapped`` for ``ARM`` and | ||
67 | ``QSDHCI_PCI`` for ``x86_64/pc``. Both implement the | ||
68 | ``read[q,w], writeq`` functions. | ||
69 | @@ -XXX,XX +XXX,XX @@ In order to implement such scenario in qgraph, the test developer needs to: | ||
70 | all the pci drivers available) | ||
71 | |||
72 | ``sdhci-pci --consumes--> pci-bus`` | ||
73 | -- Create an ``arm/raspi2`` machine node. This machine ``contains`` | ||
74 | +- Create an ``arm/raspi2b`` machine node. This machine ``contains`` | ||
75 | a ``generic-sdhci`` memory mapped ``sdhci`` driver node, representing | ||
76 | ``QSDHCI_MemoryMapped``. | ||
77 | |||
78 | - ``arm/raspi2 --contains--> generic-sdhci`` | ||
79 | + ``arm/raspi2b --contains--> generic-sdhci`` | ||
80 | - Create the ``sdhci`` interface node. This interface offers the | ||
81 | functions that are shared by all ``sdhci`` devices. | ||
82 | The interface is produced by ``sdhci-pci`` and ``generic-sdhci``, | ||
83 | @@ -XXX,XX +XXX,XX @@ In order to implement such scenario in qgraph, the test developer needs to: | ||
84 | |||
85 | ``sdhci-test --consumes--> sdhci`` | ||
86 | |||
87 | -``arm-raspi2`` machine, simplified from | ||
88 | +``arm-raspi2b`` machine, simplified from | ||
89 | ``tests/qtest/libqos/arm-raspi2-machine.c``:: | ||
90 | |||
91 | #include "qgraph.h" | ||
92 | @@ -XXX,XX +XXX,XX @@ In order to implement such scenario in qgraph, the test developer needs to: | ||
93 | return &machine->alloc; | ||
94 | } | ||
95 | |||
96 | - fprintf(stderr, "%s not present in arm/raspi2\n", interface); | ||
97 | + fprintf(stderr, "%s not present in arm/raspi2b\n", interface); | ||
98 | g_assert_not_reached(); | ||
99 | } | ||
100 | |||
101 | @@ -XXX,XX +XXX,XX @@ In order to implement such scenario in qgraph, the test developer needs to: | ||
102 | return &machine->sdhci.obj; | ||
103 | } | ||
104 | |||
105 | - fprintf(stderr, "%s not present in arm/raspi2\n", device); | ||
106 | + fprintf(stderr, "%s not present in arm/raspi2b\n", device); | ||
107 | g_assert_not_reached(); | ||
108 | } | ||
109 | |||
110 | @@ -XXX,XX +XXX,XX @@ In order to implement such scenario in qgraph, the test developer needs to: | ||
111 | |||
112 | static void raspi2_register_nodes(void) | ||
113 | { | ||
114 | - /* arm/raspi2 --contains--> generic-sdhci */ | ||
115 | - qos_node_create_machine("arm/raspi2", | ||
116 | + /* arm/raspi2b --contains--> generic-sdhci */ | ||
117 | + qos_node_create_machine("arm/raspi2b", | ||
118 | qos_create_machine_arm_raspi2); | ||
119 | - qos_node_contains("arm/raspi2", "generic-sdhci", NULL); | ||
120 | + qos_node_contains("arm/raspi2b", "generic-sdhci", NULL); | ||
121 | } | ||
122 | |||
123 | libqos_init(raspi2_register_nodes); | ||
124 | @@ -XXX,XX +XXX,XX @@ In the above example, all possible types of relations are created:: | ||
125 | | | ||
126 | +--produces-- + | ||
127 | | | ||
128 | - arm/raspi2 --contains--> generic-sdhci | ||
129 | + arm/raspi2b --contains--> generic-sdhci | ||
130 | |||
131 | or inverting the consumes edge in consumed_by:: | ||
132 | |||
133 | @@ -XXX,XX +XXX,XX @@ or inverting the consumes edge in consumed_by:: | ||
134 | | | ||
135 | +--produces-- + | ||
136 | | | ||
137 | - arm/raspi2 --contains--> generic-sdhci | ||
138 | + arm/raspi2b --contains--> generic-sdhci | ||
139 | |||
140 | Adding a new test | ||
141 | """"""""""""""""" | ||
142 | @@ -XXX,XX +XXX,XX @@ Final graph will be like this:: | ||
143 | | | ||
144 | +--produces-- + | ||
145 | | | ||
146 | - arm/raspi2 --contains--> generic-sdhci | ||
147 | + arm/raspi2b --contains--> generic-sdhci | ||
148 | |||
149 | or inverting the consumes edge in consumed_by:: | ||
150 | |||
151 | @@ -XXX,XX +XXX,XX @@ or inverting the consumes edge in consumed_by:: | ||
152 | | | ||
153 | +--produces-- + | ||
154 | | | ||
155 | - arm/raspi2 --contains--> generic-sdhci | ||
156 | + arm/raspi2b --contains--> generic-sdhci | ||
157 | |||
158 | Assuming there the binary is | ||
159 | ``QTEST_QEMU_BINARY=./qemu-system-x86_64`` | ||
160 | @@ -XXX,XX +XXX,XX @@ a valid test path will be: | ||
161 | |||
162 | and for the binary ``QTEST_QEMU_BINARY=./qemu-system-arm``: | ||
163 | |||
164 | -``/arm/raspi2/generic-sdhci/sdhci/sdhci-test`` | ||
165 | +``/arm/raspi2b/generic-sdhci/sdhci/sdhci-test`` | ||
166 | |||
167 | Additional examples are also in ``test-qgraph.c`` | ||
168 | |||
169 | diff --git a/tests/qtest/libqos/qgraph.h b/tests/qtest/libqos/qgraph.h | ||
170 | index XXXXXXX..XXXXXXX 100644 | ||
171 | --- a/tests/qtest/libqos/qgraph.h | ||
172 | +++ b/tests/qtest/libqos/qgraph.h | ||
173 | @@ -XXX,XX +XXX,XX @@ void qos_node_create_driver_named(const char *name, const char *qemu_name, | ||
174 | * This function can be useful when there are multiple devices | ||
175 | * with the same node name contained in a machine/other node | ||
176 | * | ||
177 | - * For example, if ``arm/raspi2`` contains 2 ``generic-sdhci`` | ||
178 | + * For example, if ``arm/raspi2b`` contains 2 ``generic-sdhci`` | ||
179 | * devices, the right commands will be: | ||
180 | * | ||
181 | * .. code:: | ||
182 | * | ||
183 | - * qos_node_create_machine("arm/raspi2"); | ||
184 | + * qos_node_create_machine("arm/raspi2b"); | ||
185 | * qos_node_create_driver("generic-sdhci", constructor); | ||
186 | * // assume rest of the fields are set NULL | ||
187 | * QOSGraphEdgeOptions op1 = { .edge_name = "emmc" }; | ||
188 | * QOSGraphEdgeOptions op2 = { .edge_name = "sdcard" }; | ||
189 | - * qos_node_contains("arm/raspi2", "generic-sdhci", &op1, &op2, NULL); | ||
190 | + * qos_node_contains("arm/raspi2b", "generic-sdhci", &op1, &op2, NULL); | ||
191 | * | ||
192 | * Of course this also requires that the @container's get_device function | ||
193 | * should implement a case for "emmc" and "sdcard". | ||
194 | diff --git a/tests/qtest/libqos/qgraph_internal.h b/tests/qtest/libqos/qgraph_internal.h | ||
195 | index XXXXXXX..XXXXXXX 100644 | ||
196 | --- a/tests/qtest/libqos/qgraph_internal.h | ||
197 | +++ b/tests/qtest/libqos/qgraph_internal.h | ||
198 | @@ -XXX,XX +XXX,XX @@ void qos_graph_foreach_test_path(QOSTestCallback fn); | ||
199 | /** | ||
200 | * qos_get_machine_type(): return QEMU machine type for a machine node. | ||
201 | * This function requires every machine @name to be in the form | ||
202 | - * <arch>/<machine_name>, like "arm/raspi2" or "x86_64/pc". | ||
203 | + * <arch>/<machine_name>, like "arm/raspi2b" or "x86_64/pc". | ||
204 | * | ||
205 | * The function will validate the format and return a pointer to | ||
206 | * @machine to <machine_name>. For example, when passed "x86_64/pc" | ||
207 | diff --git a/tests/qtest/boot-serial-test.c b/tests/qtest/boot-serial-test.c | ||
208 | index XXXXXXX..XXXXXXX 100644 | ||
209 | --- a/tests/qtest/boot-serial-test.c | ||
210 | +++ b/tests/qtest/boot-serial-test.c | ||
211 | @@ -XXX,XX +XXX,XX @@ static testdef_t tests[] = { | ||
212 | sizeof(kernel_pls3adsp1800), kernel_pls3adsp1800 }, | ||
213 | { "microblazeel", "petalogix-ml605", "", "TT", | ||
214 | sizeof(kernel_plml605), kernel_plml605 }, | ||
215 | - { "arm", "raspi2", "", "TT", sizeof(bios_raspi2), 0, bios_raspi2 }, | ||
216 | + { "arm", "raspi2b", "", "TT", sizeof(bios_raspi2), 0, bios_raspi2 }, | ||
217 | /* For hppa, force bios to output to serial by disabling graphics. */ | ||
218 | { "hppa", "hppa", "-vga none", "SeaBIOS wants SYSTEM HALT" }, | ||
219 | { "aarch64", "virt", "-cpu max", "TT", sizeof(kernel_aarch64), | ||
220 | diff --git a/tests/qtest/libqos/arm-raspi2-machine.c b/tests/qtest/libqos/arm-raspi2-machine.c | ||
221 | index XXXXXXX..XXXXXXX 100644 | ||
222 | --- a/tests/qtest/libqos/arm-raspi2-machine.c | ||
223 | +++ b/tests/qtest/libqos/arm-raspi2-machine.c | ||
224 | @@ -XXX,XX +XXX,XX @@ static void *raspi2_get_driver(void *object, const char *interface) | ||
225 | return &machine->alloc; | ||
226 | } | ||
227 | |||
228 | - fprintf(stderr, "%s not present in arm/raspi2\n", interface); | ||
229 | + fprintf(stderr, "%s not present in arm/raspi2b\n", interface); | ||
230 | g_assert_not_reached(); | ||
231 | } | ||
232 | |||
233 | @@ -XXX,XX +XXX,XX @@ static QOSGraphObject *raspi2_get_device(void *obj, const char *device) | ||
234 | return &machine->sdhci.obj; | ||
235 | } | ||
236 | |||
237 | - fprintf(stderr, "%s not present in arm/raspi2\n", device); | ||
238 | + fprintf(stderr, "%s not present in arm/raspi2b\n", device); | ||
239 | g_assert_not_reached(); | ||
240 | } | ||
241 | |||
242 | @@ -XXX,XX +XXX,XX @@ static void *qos_create_machine_arm_raspi2(QTestState *qts) | ||
243 | |||
244 | static void raspi2_register_nodes(void) | ||
245 | { | ||
246 | - qos_node_create_machine("arm/raspi2", qos_create_machine_arm_raspi2); | ||
247 | - qos_node_contains("arm/raspi2", "generic-sdhci", NULL); | ||
248 | + qos_node_create_machine("arm/raspi2b", qos_create_machine_arm_raspi2); | ||
249 | + qos_node_contains("arm/raspi2b", "generic-sdhci", NULL); | ||
250 | } | ||
251 | |||
252 | libqos_init(raspi2_register_nodes); | ||
253 | diff --git a/tests/unit/test-qgraph.c b/tests/unit/test-qgraph.c | ||
254 | index XXXXXXX..XXXXXXX 100644 | ||
255 | --- a/tests/unit/test-qgraph.c | ||
256 | +++ b/tests/unit/test-qgraph.c | ||
257 | @@ -XXX,XX +XXX,XX @@ | ||
258 | #include "../qtest/libqos/qgraph_internal.h" | ||
259 | |||
260 | #define MACHINE_PC "x86_64/pc" | ||
261 | -#define MACHINE_RASPI2 "arm/raspi2" | ||
262 | +#define MACHINE_RASPI2 "arm/raspi2b" | ||
263 | #define I440FX "i440FX-pcihost" | ||
264 | #define PCIBUS_PC "pcibus-pc" | ||
265 | #define SDHCI "sdhci" | ||
266 | diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py | ||
267 | index XXXXXXX..XXXXXXX 100644 | ||
268 | --- a/tests/acceptance/boot_linux_console.py | ||
269 | +++ b/tests/acceptance/boot_linux_console.py | ||
270 | @@ -XXX,XX +XXX,XX @@ def do_test_arm_raspi2(self, uart_id): | ||
271 | def test_arm_raspi2_uart0(self): | ||
272 | """ | ||
273 | :avocado: tags=arch:arm | ||
274 | - :avocado: tags=machine:raspi2 | ||
275 | + :avocado: tags=machine:raspi2b | ||
276 | :avocado: tags=device:pl011 | ||
277 | :avocado: tags=accel:tcg | ||
278 | """ | ||
279 | @@ -XXX,XX +XXX,XX @@ def test_arm_raspi2_uart0(self): | ||
280 | def test_arm_raspi2_initrd(self): | ||
281 | """ | ||
282 | :avocado: tags=arch:arm | ||
283 | - :avocado: tags=machine:raspi2 | ||
284 | + :avocado: tags=machine:raspi2b | ||
285 | """ | ||
286 | deb_url = ('http://archive.raspberrypi.org/debian/' | ||
287 | 'pool/main/r/raspberrypi-firmware/' | ||
288 | @@ -XXX,XX +XXX,XX @@ def test_arm_orangepi_uboot_netbsd9(self): | ||
289 | def test_aarch64_raspi3_atf(self): | ||
290 | """ | ||
291 | :avocado: tags=arch:aarch64 | ||
292 | - :avocado: tags=machine:raspi3 | ||
293 | + :avocado: tags=machine:raspi3b | ||
294 | :avocado: tags=cpu:cortex-a53 | ||
295 | :avocado: tags=device:pl011 | ||
296 | :avocado: tags=atf | ||
297 | -- | ||
298 | 2.20.1 | ||
299 | |||
300 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
1 | 2 | ||
3 | Remove the raspi2/raspi3 machine aliases, | ||
4 | deprecated since commit 155e1c82ed0. | ||
5 | |||
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Message-id: 20210827060815.2384760-3-f4bug@amsat.org | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | docs/about/deprecated.rst | 7 ------- | ||
12 | docs/about/removed-features.rst | 7 +++++++ | ||
13 | hw/arm/raspi.c | 2 -- | ||
14 | 3 files changed, 7 insertions(+), 9 deletions(-) | ||
15 | |||
16 | diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/docs/about/deprecated.rst | ||
19 | +++ b/docs/about/deprecated.rst | ||
20 | @@ -XXX,XX +XXX,XX @@ this CPU is also deprecated. | ||
21 | System emulator machines | ||
22 | ------------------------ | ||
23 | |||
24 | -Raspberry Pi ``raspi2`` and ``raspi3`` machines (since 5.2) | ||
25 | -''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' | ||
26 | - | ||
27 | -The Raspberry Pi machines come in various models (A, A+, B, B+). To be able | ||
28 | -to distinguish which model QEMU is implementing, the ``raspi2`` and ``raspi3`` | ||
29 | -machines have been renamed ``raspi2b`` and ``raspi3b``. | ||
30 | - | ||
31 | Aspeed ``swift-bmc`` machine (since 6.1) | ||
32 | '''''''''''''''''''''''''''''''''''''''' | ||
33 | |||
34 | diff --git a/docs/about/removed-features.rst b/docs/about/removed-features.rst | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/docs/about/removed-features.rst | ||
37 | +++ b/docs/about/removed-features.rst | ||
38 | @@ -XXX,XX +XXX,XX @@ This machine has been renamed ``fuloong2e``. | ||
39 | These machine types were very old and likely could not be used for live | ||
40 | migration from old QEMU versions anymore. Use a newer machine type instead. | ||
41 | |||
42 | +Raspberry Pi ``raspi2`` and ``raspi3`` machines (removed in 6.2) | ||
43 | +'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' | ||
44 | + | ||
45 | +The Raspberry Pi machines come in various models (A, A+, B, B+). To be able | ||
46 | +to distinguish which model QEMU is implementing, the ``raspi2`` and ``raspi3`` | ||
47 | +machines have been renamed ``raspi2b`` and ``raspi3b``. | ||
48 | + | ||
49 | |||
50 | linux-user mode CPUs | ||
51 | -------------------- | ||
52 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/hw/arm/raspi.c | ||
55 | +++ b/hw/arm/raspi.c | ||
56 | @@ -XXX,XX +XXX,XX @@ static void raspi2b_machine_class_init(ObjectClass *oc, void *data) | ||
57 | MachineClass *mc = MACHINE_CLASS(oc); | ||
58 | RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); | ||
59 | |||
60 | - mc->alias = "raspi2"; | ||
61 | rmc->board_rev = 0xa21041; | ||
62 | raspi_machine_class_common_init(mc, rmc->board_rev); | ||
63 | }; | ||
64 | @@ -XXX,XX +XXX,XX @@ static void raspi3b_machine_class_init(ObjectClass *oc, void *data) | ||
65 | MachineClass *mc = MACHINE_CLASS(oc); | ||
66 | RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); | ||
67 | |||
68 | - mc->alias = "raspi3"; | ||
69 | rmc->board_rev = 0xa02082; | ||
70 | raspi_machine_class_common_init(mc, rmc->board_rev); | ||
71 | }; | ||
72 | -- | ||
73 | 2.20.1 | ||
74 | |||
75 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Change vfp.regs as a uint64_t to vfp.zregs as an ARMVectorReg. | 3 | QEMU load/store API (docs/devel/loads-stores.rst) uses the 'q' |
4 | The previous patches have made the change in representation | 4 | suffix for 64-bit accesses. Rename the current 'll' suffix to |
5 | relatively painless. | 5 | have the GIC dist accessors better match the rest of the codebase. |
6 | 6 | ||
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 7 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Message-id: 20210826180704.2131949-2-philmd@redhat.com |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Message-id: 20180123035349.24538-2-richard.henderson@linaro.org | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 10 | --- |
13 | target/arm/cpu.h | 59 +++++++++++++++++++++++++++++++--------------- | 11 | hw/intc/arm_gicv3_dist.c | 12 ++++++------ |
14 | target/arm/machine.c | 35 ++++++++++++++++++++++++++- | 12 | 1 file changed, 6 insertions(+), 6 deletions(-) |
15 | target/arm/translate-a64.c | 8 +++---- | ||
16 | target/arm/translate.c | 7 +++--- | ||
17 | 4 files changed, 81 insertions(+), 28 deletions(-) | ||
18 | 13 | ||
19 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 14 | diff --git a/hw/intc/arm_gicv3_dist.c b/hw/intc/arm_gicv3_dist.c |
20 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/cpu.h | 16 | --- a/hw/intc/arm_gicv3_dist.c |
22 | +++ b/target/arm/cpu.h | 17 | +++ b/hw/intc/arm_gicv3_dist.c |
23 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 18 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writel(GICv3State *s, hwaddr offset, |
24 | uint32_t base_mask; | ||
25 | } TCR; | ||
26 | |||
27 | +/* Define a maximum sized vector register. | ||
28 | + * For 32-bit, this is a 128-bit NEON/AdvSIMD register. | ||
29 | + * For 64-bit, this is a 2048-bit SVE register. | ||
30 | + * | ||
31 | + * Note that the mapping between S, D, and Q views of the register bank | ||
32 | + * differs between AArch64 and AArch32. | ||
33 | + * In AArch32: | ||
34 | + * Qn = regs[n].d[1]:regs[n].d[0] | ||
35 | + * Dn = regs[n / 2].d[n & 1] | ||
36 | + * Sn = regs[n / 4].d[n % 4 / 2], | ||
37 | + * bits 31..0 for even n, and bits 63..32 for odd n | ||
38 | + * (and regs[16] to regs[31] are inaccessible) | ||
39 | + * In AArch64: | ||
40 | + * Zn = regs[n].d[*] | ||
41 | + * Qn = regs[n].d[1]:regs[n].d[0] | ||
42 | + * Dn = regs[n].d[0] | ||
43 | + * Sn = regs[n].d[0] bits 31..0 | ||
44 | + * | ||
45 | + * This corresponds to the architecturally defined mapping between | ||
46 | + * the two execution states, and means we do not need to explicitly | ||
47 | + * map these registers when changing states. | ||
48 | + * | ||
49 | + * Align the data for use with TCG host vector operations. | ||
50 | + */ | ||
51 | + | ||
52 | +#ifdef TARGET_AARCH64 | ||
53 | +# define ARM_MAX_VQ 16 | ||
54 | +#else | ||
55 | +# define ARM_MAX_VQ 1 | ||
56 | +#endif | ||
57 | + | ||
58 | +typedef struct ARMVectorReg { | ||
59 | + uint64_t d[2 * ARM_MAX_VQ] QEMU_ALIGNED(16); | ||
60 | +} ARMVectorReg; | ||
61 | + | ||
62 | + | ||
63 | typedef struct CPUARMState { | ||
64 | /* Regs for current mode. */ | ||
65 | uint32_t regs[16]; | ||
66 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | ||
67 | |||
68 | /* VFP coprocessor state. */ | ||
69 | struct { | ||
70 | - /* VFP/Neon register state. Note that the mapping between S, D and Q | ||
71 | - * views of the register bank differs between AArch64 and AArch32: | ||
72 | - * In AArch32: | ||
73 | - * Qn = regs[2n+1]:regs[2n] | ||
74 | - * Dn = regs[n] | ||
75 | - * Sn = regs[n/2] bits 31..0 for even n, and bits 63..32 for odd n | ||
76 | - * (and regs[32] to regs[63] are inaccessible) | ||
77 | - * In AArch64: | ||
78 | - * Qn = regs[2n+1]:regs[2n] | ||
79 | - * Dn = regs[2n] | ||
80 | - * Sn = regs[2n] bits 31..0 | ||
81 | - * This corresponds to the architecturally defined mapping between | ||
82 | - * the two execution states, and means we do not need to explicitly | ||
83 | - * map these registers when changing states. | ||
84 | - */ | ||
85 | - uint64_t regs[64] QEMU_ALIGNED(16); | ||
86 | + ARMVectorReg zregs[32]; | ||
87 | |||
88 | uint32_t xregs[16]; | ||
89 | /* We store these fpcsr fields separately for convenience. */ | ||
90 | @@ -XXX,XX +XXX,XX @@ static inline void *arm_get_el_change_hook_opaque(ARMCPU *cpu) | ||
91 | */ | ||
92 | static inline uint64_t *aa32_vfp_dreg(CPUARMState *env, unsigned regno) | ||
93 | { | ||
94 | - return &env->vfp.regs[regno]; | ||
95 | + return &env->vfp.zregs[regno >> 1].d[regno & 1]; | ||
96 | } | ||
97 | |||
98 | /** | ||
99 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t *aa32_vfp_dreg(CPUARMState *env, unsigned regno) | ||
100 | */ | ||
101 | static inline uint64_t *aa32_vfp_qreg(CPUARMState *env, unsigned regno) | ||
102 | { | ||
103 | - return &env->vfp.regs[2 * regno]; | ||
104 | + return &env->vfp.zregs[regno].d[0]; | ||
105 | } | ||
106 | |||
107 | /** | ||
108 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t *aa32_vfp_qreg(CPUARMState *env, unsigned regno) | ||
109 | */ | ||
110 | static inline uint64_t *aa64_vfp_qreg(CPUARMState *env, unsigned regno) | ||
111 | { | ||
112 | - return &env->vfp.regs[2 * regno]; | ||
113 | + return &env->vfp.zregs[regno].d[0]; | ||
114 | } | ||
115 | |||
116 | #endif | ||
117 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/target/arm/machine.c | ||
120 | +++ b/target/arm/machine.c | ||
121 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_vfp = { | ||
122 | .minimum_version_id = 3, | ||
123 | .needed = vfp_needed, | ||
124 | .fields = (VMStateField[]) { | ||
125 | - VMSTATE_UINT64_ARRAY(env.vfp.regs, ARMCPU, 64), | ||
126 | + /* For compatibility, store Qn out of Zn here. */ | ||
127 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[0].d, ARMCPU, 0, 2), | ||
128 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[1].d, ARMCPU, 0, 2), | ||
129 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[2].d, ARMCPU, 0, 2), | ||
130 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[3].d, ARMCPU, 0, 2), | ||
131 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[4].d, ARMCPU, 0, 2), | ||
132 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[5].d, ARMCPU, 0, 2), | ||
133 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[6].d, ARMCPU, 0, 2), | ||
134 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[7].d, ARMCPU, 0, 2), | ||
135 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[8].d, ARMCPU, 0, 2), | ||
136 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[9].d, ARMCPU, 0, 2), | ||
137 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[10].d, ARMCPU, 0, 2), | ||
138 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[11].d, ARMCPU, 0, 2), | ||
139 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[12].d, ARMCPU, 0, 2), | ||
140 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[13].d, ARMCPU, 0, 2), | ||
141 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[14].d, ARMCPU, 0, 2), | ||
142 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[15].d, ARMCPU, 0, 2), | ||
143 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[16].d, ARMCPU, 0, 2), | ||
144 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[17].d, ARMCPU, 0, 2), | ||
145 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[18].d, ARMCPU, 0, 2), | ||
146 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[19].d, ARMCPU, 0, 2), | ||
147 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[20].d, ARMCPU, 0, 2), | ||
148 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[21].d, ARMCPU, 0, 2), | ||
149 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[22].d, ARMCPU, 0, 2), | ||
150 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[23].d, ARMCPU, 0, 2), | ||
151 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[24].d, ARMCPU, 0, 2), | ||
152 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[25].d, ARMCPU, 0, 2), | ||
153 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[26].d, ARMCPU, 0, 2), | ||
154 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[27].d, ARMCPU, 0, 2), | ||
155 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[28].d, ARMCPU, 0, 2), | ||
156 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[29].d, ARMCPU, 0, 2), | ||
157 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[30].d, ARMCPU, 0, 2), | ||
158 | + VMSTATE_UINT64_SUB_ARRAY(env.vfp.zregs[31].d, ARMCPU, 0, 2), | ||
159 | + | ||
160 | /* The xregs array is a little awkward because element 1 (FPSCR) | ||
161 | * requires a specific accessor, so we have to split it up in | ||
162 | * the vmstate: | ||
163 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
164 | index XXXXXXX..XXXXXXX 100644 | ||
165 | --- a/target/arm/translate-a64.c | ||
166 | +++ b/target/arm/translate-a64.c | ||
167 | @@ -XXX,XX +XXX,XX @@ static inline int vec_reg_offset(DisasContext *s, int regno, | ||
168 | { | ||
169 | int offs = 0; | ||
170 | #ifdef HOST_WORDS_BIGENDIAN | ||
171 | - /* This is complicated slightly because vfp.regs[2n] is | ||
172 | - * still the low half and vfp.regs[2n+1] the high half | ||
173 | + /* This is complicated slightly because vfp.zregs[n].d[0] is | ||
174 | + * still the low half and vfp.zregs[n].d[1] the high half | ||
175 | * of the 128 bit vector, even on big endian systems. | ||
176 | * Calculate the offset assuming a fully bigendian 128 bits, | ||
177 | * then XOR to account for the order of the two 64 bit halves. | ||
178 | @@ -XXX,XX +XXX,XX @@ static inline int vec_reg_offset(DisasContext *s, int regno, | ||
179 | #else | ||
180 | offs += element * (1 << size); | ||
181 | #endif | ||
182 | - offs += offsetof(CPUARMState, vfp.regs[regno * 2]); | ||
183 | + offs += offsetof(CPUARMState, vfp.zregs[regno]); | ||
184 | assert_fp_access_checked(s); | ||
185 | return offs; | ||
186 | } | ||
187 | @@ -XXX,XX +XXX,XX @@ static inline int vec_reg_offset(DisasContext *s, int regno, | ||
188 | static inline int vec_full_reg_offset(DisasContext *s, int regno) | ||
189 | { | ||
190 | assert_fp_access_checked(s); | ||
191 | - return offsetof(CPUARMState, vfp.regs[regno * 2]); | ||
192 | + return offsetof(CPUARMState, vfp.zregs[regno]); | ||
193 | } | ||
194 | |||
195 | /* Return a newly allocated pointer to the vector register. */ | ||
196 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
197 | index XXXXXXX..XXXXXXX 100644 | ||
198 | --- a/target/arm/translate.c | ||
199 | +++ b/target/arm/translate.c | ||
200 | @@ -XXX,XX +XXX,XX @@ static inline void gen_vfp_st(DisasContext *s, int dp, TCGv_i32 addr) | ||
201 | } | 19 | } |
202 | } | 20 | } |
203 | 21 | ||
204 | -static inline long | 22 | -static MemTxResult gicd_writell(GICv3State *s, hwaddr offset, |
205 | -vfp_reg_offset (int dp, int reg) | 23 | - uint64_t value, MemTxAttrs attrs) |
206 | +static inline long vfp_reg_offset(bool dp, unsigned reg) | 24 | +static MemTxResult gicd_writeq(GICv3State *s, hwaddr offset, |
25 | + uint64_t value, MemTxAttrs attrs) | ||
207 | { | 26 | { |
208 | if (dp) { | 27 | /* Our only 64-bit registers are GICD_IROUTER<n> */ |
209 | - return offsetof(CPUARMState, vfp.regs[reg]); | 28 | int irq; |
210 | + return offsetof(CPUARMState, vfp.zregs[reg >> 1].d[reg & 1]); | 29 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writell(GICv3State *s, hwaddr offset, |
211 | } else { | 30 | } |
212 | - long ofs = offsetof(CPUARMState, vfp.regs[reg >> 1]); | 31 | } |
213 | + long ofs = offsetof(CPUARMState, vfp.zregs[reg >> 2].d[(reg >> 1) & 1]); | 32 | |
214 | if (reg & 1) { | 33 | -static MemTxResult gicd_readll(GICv3State *s, hwaddr offset, |
215 | ofs += offsetof(CPU_DoubleU, l.upper); | 34 | - uint64_t *data, MemTxAttrs attrs) |
216 | } else { | 35 | +static MemTxResult gicd_readq(GICv3State *s, hwaddr offset, |
36 | + uint64_t *data, MemTxAttrs attrs) | ||
37 | { | ||
38 | /* Our only 64-bit registers are GICD_IROUTER<n> */ | ||
39 | int irq; | ||
40 | @@ -XXX,XX +XXX,XX @@ MemTxResult gicv3_dist_read(void *opaque, hwaddr offset, uint64_t *data, | ||
41 | r = gicd_readl(s, offset, data, attrs); | ||
42 | break; | ||
43 | case 8: | ||
44 | - r = gicd_readll(s, offset, data, attrs); | ||
45 | + r = gicd_readq(s, offset, data, attrs); | ||
46 | break; | ||
47 | default: | ||
48 | r = MEMTX_ERROR; | ||
49 | @@ -XXX,XX +XXX,XX @@ MemTxResult gicv3_dist_write(void *opaque, hwaddr offset, uint64_t data, | ||
50 | r = gicd_writel(s, offset, data, attrs); | ||
51 | break; | ||
52 | case 8: | ||
53 | - r = gicd_writell(s, offset, data, attrs); | ||
54 | + r = gicd_writeq(s, offset, data, attrs); | ||
55 | break; | ||
56 | default: | ||
57 | r = MEMTX_ERROR; | ||
217 | -- | 58 | -- |
218 | 2.16.1 | 59 | 2.20.1 |
219 | 60 | ||
220 | 61 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
1 | 2 | ||
3 | Quoting Peter Maydell: | ||
4 | |||
5 | These MEMTX_* aren't from the memory transaction API functions; | ||
6 | they're just being used by gicd_readl() and friends as a way to | ||
7 | indicate a success/failure so that the actual MemoryRegionOps | ||
8 | read/write fns like gicv3_dist_read() can log a guest error. | ||
9 | Arguably this is a bit of a misuse of the MEMTX_* constants and | ||
10 | perhaps we should have gicd_readl etc return a bool instead. | ||
11 | |||
12 | Follow his suggestion and replace the MEMTX_* constants by | ||
13 | boolean values, simplifying a bit the gicv3_dist_read() / | ||
14 | gicv3_dist_write() handlers. | ||
15 | |||
16 | Suggested-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
18 | Message-id: 20210826180704.2131949-3-philmd@redhat.com | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
20 | --- | ||
21 | hw/intc/arm_gicv3_dist.c | 201 +++++++++++++++++++++------------------ | ||
22 | 1 file changed, 106 insertions(+), 95 deletions(-) | ||
23 | |||
24 | diff --git a/hw/intc/arm_gicv3_dist.c b/hw/intc/arm_gicv3_dist.c | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/hw/intc/arm_gicv3_dist.c | ||
27 | +++ b/hw/intc/arm_gicv3_dist.c | ||
28 | @@ -XXX,XX +XXX,XX @@ static void gicd_write_irouter(GICv3State *s, MemTxAttrs attrs, int irq, | ||
29 | gicv3_update(s, irq, 1); | ||
30 | } | ||
31 | |||
32 | -static MemTxResult gicd_readb(GICv3State *s, hwaddr offset, | ||
33 | - uint64_t *data, MemTxAttrs attrs) | ||
34 | +/** | ||
35 | + * gicd_readb | ||
36 | + * gicd_readw | ||
37 | + * gicd_readl | ||
38 | + * gicd_readq | ||
39 | + * gicd_writeb | ||
40 | + * gicd_writew | ||
41 | + * gicd_writel | ||
42 | + * gicd_writeq | ||
43 | + * | ||
44 | + * Return %true if the operation succeeded, %false otherwise. | ||
45 | + */ | ||
46 | + | ||
47 | +static bool gicd_readb(GICv3State *s, hwaddr offset, | ||
48 | + uint64_t *data, MemTxAttrs attrs) | ||
49 | { | ||
50 | /* Most GICv3 distributor registers do not support byte accesses. */ | ||
51 | switch (offset) { | ||
52 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readb(GICv3State *s, hwaddr offset, | ||
53 | /* This GIC implementation always has affinity routing enabled, | ||
54 | * so these registers are all RAZ/WI. | ||
55 | */ | ||
56 | - return MEMTX_OK; | ||
57 | + return true; | ||
58 | case GICD_IPRIORITYR ... GICD_IPRIORITYR + 0x3ff: | ||
59 | *data = gicd_read_ipriorityr(s, attrs, offset - GICD_IPRIORITYR); | ||
60 | - return MEMTX_OK; | ||
61 | + return true; | ||
62 | default: | ||
63 | - return MEMTX_ERROR; | ||
64 | + return false; | ||
65 | } | ||
66 | } | ||
67 | |||
68 | -static MemTxResult gicd_writeb(GICv3State *s, hwaddr offset, | ||
69 | - uint64_t value, MemTxAttrs attrs) | ||
70 | +static bool gicd_writeb(GICv3State *s, hwaddr offset, | ||
71 | + uint64_t value, MemTxAttrs attrs) | ||
72 | { | ||
73 | /* Most GICv3 distributor registers do not support byte accesses. */ | ||
74 | switch (offset) { | ||
75 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writeb(GICv3State *s, hwaddr offset, | ||
76 | /* This GIC implementation always has affinity routing enabled, | ||
77 | * so these registers are all RAZ/WI. | ||
78 | */ | ||
79 | - return MEMTX_OK; | ||
80 | + return true; | ||
81 | case GICD_IPRIORITYR ... GICD_IPRIORITYR + 0x3ff: | ||
82 | { | ||
83 | int irq = offset - GICD_IPRIORITYR; | ||
84 | |||
85 | if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
86 | - return MEMTX_OK; | ||
87 | + return true; | ||
88 | } | ||
89 | gicd_write_ipriorityr(s, attrs, irq, value); | ||
90 | gicv3_update(s, irq, 1); | ||
91 | - return MEMTX_OK; | ||
92 | + return true; | ||
93 | } | ||
94 | default: | ||
95 | - return MEMTX_ERROR; | ||
96 | + return false; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | -static MemTxResult gicd_readw(GICv3State *s, hwaddr offset, | ||
101 | - uint64_t *data, MemTxAttrs attrs) | ||
102 | +static bool gicd_readw(GICv3State *s, hwaddr offset, | ||
103 | + uint64_t *data, MemTxAttrs attrs) | ||
104 | { | ||
105 | /* Only GICD_SETSPI_NSR, GICD_CLRSPI_NSR, GICD_SETSPI_SR and GICD_SETSPI_NSR | ||
106 | * support 16 bit accesses, and those registers are all part of the | ||
107 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readw(GICv3State *s, hwaddr offset, | ||
108 | * implement (ie for us GICD_TYPER.MBIS == 0), so for us they are | ||
109 | * reserved. | ||
110 | */ | ||
111 | - return MEMTX_ERROR; | ||
112 | + return false; | ||
113 | } | ||
114 | |||
115 | -static MemTxResult gicd_writew(GICv3State *s, hwaddr offset, | ||
116 | - uint64_t value, MemTxAttrs attrs) | ||
117 | +static bool gicd_writew(GICv3State *s, hwaddr offset, | ||
118 | + uint64_t value, MemTxAttrs attrs) | ||
119 | { | ||
120 | /* Only GICD_SETSPI_NSR, GICD_CLRSPI_NSR, GICD_SETSPI_SR and GICD_SETSPI_NSR | ||
121 | * support 16 bit accesses, and those registers are all part of the | ||
122 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writew(GICv3State *s, hwaddr offset, | ||
123 | * implement (ie for us GICD_TYPER.MBIS == 0), so for us they are | ||
124 | * reserved. | ||
125 | */ | ||
126 | - return MEMTX_ERROR; | ||
127 | + return false; | ||
128 | } | ||
129 | |||
130 | -static MemTxResult gicd_readl(GICv3State *s, hwaddr offset, | ||
131 | - uint64_t *data, MemTxAttrs attrs) | ||
132 | +static bool gicd_readl(GICv3State *s, hwaddr offset, | ||
133 | + uint64_t *data, MemTxAttrs attrs) | ||
134 | { | ||
135 | /* Almost all GICv3 distributor registers are 32-bit. | ||
136 | * Note that WO registers must return an UNKNOWN value on reads, | ||
137 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readl(GICv3State *s, hwaddr offset, | ||
138 | } else { | ||
139 | *data = s->gicd_ctlr; | ||
140 | } | ||
141 | - return MEMTX_OK; | ||
142 | + return true; | ||
143 | case GICD_TYPER: | ||
144 | { | ||
145 | /* For this implementation: | ||
146 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readl(GICv3State *s, hwaddr offset, | ||
147 | |||
148 | *data = (1 << 25) | (1 << 24) | (sec_extn << 10) | | ||
149 | (0xf << 19) | itlinesnumber; | ||
150 | - return MEMTX_OK; | ||
151 | + return true; | ||
152 | } | ||
153 | case GICD_IIDR: | ||
154 | /* We claim to be an ARM r0p0 with a zero ProductID. | ||
155 | * This is the same as an r0p0 GIC-500. | ||
156 | */ | ||
157 | *data = gicv3_iidr(); | ||
158 | - return MEMTX_OK; | ||
159 | + return true; | ||
160 | case GICD_STATUSR: | ||
161 | /* RAZ/WI for us (this is an optional register and our implementation | ||
162 | * does not track RO/WO/reserved violations to report them to the guest) | ||
163 | */ | ||
164 | *data = 0; | ||
165 | - return MEMTX_OK; | ||
166 | + return true; | ||
167 | case GICD_IGROUPR ... GICD_IGROUPR + 0x7f: | ||
168 | { | ||
169 | int irq; | ||
170 | |||
171 | if (!attrs.secure && !(s->gicd_ctlr & GICD_CTLR_DS)) { | ||
172 | *data = 0; | ||
173 | - return MEMTX_OK; | ||
174 | + return true; | ||
175 | } | ||
176 | /* RAZ/WI for SGIs, PPIs, unimplemented irqs */ | ||
177 | irq = (offset - GICD_IGROUPR) * 8; | ||
178 | if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
179 | *data = 0; | ||
180 | - return MEMTX_OK; | ||
181 | + return true; | ||
182 | } | ||
183 | *data = *gic_bmp_ptr32(s->group, irq); | ||
184 | - return MEMTX_OK; | ||
185 | + return true; | ||
186 | } | ||
187 | case GICD_ISENABLER ... GICD_ISENABLER + 0x7f: | ||
188 | *data = gicd_read_bitmap_reg(s, attrs, s->enabled, NULL, | ||
189 | offset - GICD_ISENABLER); | ||
190 | - return MEMTX_OK; | ||
191 | + return true; | ||
192 | case GICD_ICENABLER ... GICD_ICENABLER + 0x7f: | ||
193 | *data = gicd_read_bitmap_reg(s, attrs, s->enabled, NULL, | ||
194 | offset - GICD_ICENABLER); | ||
195 | - return MEMTX_OK; | ||
196 | + return true; | ||
197 | case GICD_ISPENDR ... GICD_ISPENDR + 0x7f: | ||
198 | *data = gicd_read_bitmap_reg(s, attrs, s->pending, mask_nsacr_ge1, | ||
199 | offset - GICD_ISPENDR); | ||
200 | - return MEMTX_OK; | ||
201 | + return true; | ||
202 | case GICD_ICPENDR ... GICD_ICPENDR + 0x7f: | ||
203 | *data = gicd_read_bitmap_reg(s, attrs, s->pending, mask_nsacr_ge2, | ||
204 | offset - GICD_ICPENDR); | ||
205 | - return MEMTX_OK; | ||
206 | + return true; | ||
207 | case GICD_ISACTIVER ... GICD_ISACTIVER + 0x7f: | ||
208 | *data = gicd_read_bitmap_reg(s, attrs, s->active, mask_nsacr_ge2, | ||
209 | offset - GICD_ISACTIVER); | ||
210 | - return MEMTX_OK; | ||
211 | + return true; | ||
212 | case GICD_ICACTIVER ... GICD_ICACTIVER + 0x7f: | ||
213 | *data = gicd_read_bitmap_reg(s, attrs, s->active, mask_nsacr_ge2, | ||
214 | offset - GICD_ICACTIVER); | ||
215 | - return MEMTX_OK; | ||
216 | + return true; | ||
217 | case GICD_IPRIORITYR ... GICD_IPRIORITYR + 0x3ff: | ||
218 | { | ||
219 | int i, irq = offset - GICD_IPRIORITYR; | ||
220 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readl(GICv3State *s, hwaddr offset, | ||
221 | value |= gicd_read_ipriorityr(s, attrs, i); | ||
222 | } | ||
223 | *data = value; | ||
224 | - return MEMTX_OK; | ||
225 | + return true; | ||
226 | } | ||
227 | case GICD_ITARGETSR ... GICD_ITARGETSR + 0x3ff: | ||
228 | /* RAZ/WI since affinity routing is always enabled */ | ||
229 | *data = 0; | ||
230 | - return MEMTX_OK; | ||
231 | + return true; | ||
232 | case GICD_ICFGR ... GICD_ICFGR + 0xff: | ||
233 | { | ||
234 | /* Here only the even bits are used; odd bits are RES0 */ | ||
235 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readl(GICv3State *s, hwaddr offset, | ||
236 | |||
237 | if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
238 | *data = 0; | ||
239 | - return MEMTX_OK; | ||
240 | + return true; | ||
241 | } | ||
242 | |||
243 | /* Since our edge_trigger bitmap is one bit per irq, we only need | ||
244 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readl(GICv3State *s, hwaddr offset, | ||
245 | value = extract32(value, (irq & 0x1f) ? 16 : 0, 16); | ||
246 | value = half_shuffle32(value) << 1; | ||
247 | *data = value; | ||
248 | - return MEMTX_OK; | ||
249 | + return true; | ||
250 | } | ||
251 | case GICD_IGRPMODR ... GICD_IGRPMODR + 0xff: | ||
252 | { | ||
253 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readl(GICv3State *s, hwaddr offset, | ||
254 | * security enabled and this is an NS access | ||
255 | */ | ||
256 | *data = 0; | ||
257 | - return MEMTX_OK; | ||
258 | + return true; | ||
259 | } | ||
260 | /* RAZ/WI for SGIs, PPIs, unimplemented irqs */ | ||
261 | irq = (offset - GICD_IGRPMODR) * 8; | ||
262 | if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
263 | *data = 0; | ||
264 | - return MEMTX_OK; | ||
265 | + return true; | ||
266 | } | ||
267 | *data = *gic_bmp_ptr32(s->grpmod, irq); | ||
268 | - return MEMTX_OK; | ||
269 | + return true; | ||
270 | } | ||
271 | case GICD_NSACR ... GICD_NSACR + 0xff: | ||
272 | { | ||
273 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readl(GICv3State *s, hwaddr offset, | ||
274 | |||
275 | if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
276 | *data = 0; | ||
277 | - return MEMTX_OK; | ||
278 | + return true; | ||
279 | } | ||
280 | |||
281 | if ((s->gicd_ctlr & GICD_CTLR_DS) || !attrs.secure) { | ||
282 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readl(GICv3State *s, hwaddr offset, | ||
283 | * security enabled and this is an NS access | ||
284 | */ | ||
285 | *data = 0; | ||
286 | - return MEMTX_OK; | ||
287 | + return true; | ||
288 | } | ||
289 | |||
290 | *data = s->gicd_nsacr[irq / 16]; | ||
291 | - return MEMTX_OK; | ||
292 | + return true; | ||
293 | } | ||
294 | case GICD_CPENDSGIR ... GICD_CPENDSGIR + 0xf: | ||
295 | case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf: | ||
296 | /* RAZ/WI since affinity routing is always enabled */ | ||
297 | *data = 0; | ||
298 | - return MEMTX_OK; | ||
299 | + return true; | ||
300 | case GICD_IROUTER ... GICD_IROUTER + 0x1fdf: | ||
301 | { | ||
302 | uint64_t r; | ||
303 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readl(GICv3State *s, hwaddr offset, | ||
304 | } else { | ||
305 | *data = (uint32_t)r; | ||
306 | } | ||
307 | - return MEMTX_OK; | ||
308 | + return true; | ||
309 | } | ||
310 | case GICD_IDREGS ... GICD_IDREGS + 0x2f: | ||
311 | /* ID registers */ | ||
312 | *data = gicv3_idreg(offset - GICD_IDREGS); | ||
313 | - return MEMTX_OK; | ||
314 | + return true; | ||
315 | case GICD_SGIR: | ||
316 | /* WO registers, return unknown value */ | ||
317 | qemu_log_mask(LOG_GUEST_ERROR, | ||
318 | "%s: invalid guest read from WO register at offset " | ||
319 | TARGET_FMT_plx "\n", __func__, offset); | ||
320 | *data = 0; | ||
321 | - return MEMTX_OK; | ||
322 | + return true; | ||
323 | default: | ||
324 | - return MEMTX_ERROR; | ||
325 | + return false; | ||
326 | } | ||
327 | } | ||
328 | |||
329 | -static MemTxResult gicd_writel(GICv3State *s, hwaddr offset, | ||
330 | - uint64_t value, MemTxAttrs attrs) | ||
331 | +static bool gicd_writel(GICv3State *s, hwaddr offset, | ||
332 | + uint64_t value, MemTxAttrs attrs) | ||
333 | { | ||
334 | /* Almost all GICv3 distributor registers are 32-bit. Note that | ||
335 | * RO registers must ignore writes, not abort. | ||
336 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writel(GICv3State *s, hwaddr offset, | ||
337 | s->gicd_ctlr &= ~(GICD_CTLR_EN_GRP1S | GICD_CTLR_ARE_NS); | ||
338 | } | ||
339 | gicv3_full_update(s); | ||
340 | - return MEMTX_OK; | ||
341 | + return true; | ||
342 | } | ||
343 | case GICD_STATUSR: | ||
344 | /* RAZ/WI for our implementation */ | ||
345 | - return MEMTX_OK; | ||
346 | + return true; | ||
347 | case GICD_IGROUPR ... GICD_IGROUPR + 0x7f: | ||
348 | { | ||
349 | int irq; | ||
350 | |||
351 | if (!attrs.secure && !(s->gicd_ctlr & GICD_CTLR_DS)) { | ||
352 | - return MEMTX_OK; | ||
353 | + return true; | ||
354 | } | ||
355 | /* RAZ/WI for SGIs, PPIs, unimplemented irqs */ | ||
356 | irq = (offset - GICD_IGROUPR) * 8; | ||
357 | if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
358 | - return MEMTX_OK; | ||
359 | + return true; | ||
360 | } | ||
361 | *gic_bmp_ptr32(s->group, irq) = value; | ||
362 | gicv3_update(s, irq, 32); | ||
363 | - return MEMTX_OK; | ||
364 | + return true; | ||
365 | } | ||
366 | case GICD_ISENABLER ... GICD_ISENABLER + 0x7f: | ||
367 | gicd_write_set_bitmap_reg(s, attrs, s->enabled, NULL, | ||
368 | offset - GICD_ISENABLER, value); | ||
369 | - return MEMTX_OK; | ||
370 | + return true; | ||
371 | case GICD_ICENABLER ... GICD_ICENABLER + 0x7f: | ||
372 | gicd_write_clear_bitmap_reg(s, attrs, s->enabled, NULL, | ||
373 | offset - GICD_ICENABLER, value); | ||
374 | - return MEMTX_OK; | ||
375 | + return true; | ||
376 | case GICD_ISPENDR ... GICD_ISPENDR + 0x7f: | ||
377 | gicd_write_set_bitmap_reg(s, attrs, s->pending, mask_nsacr_ge1, | ||
378 | offset - GICD_ISPENDR, value); | ||
379 | - return MEMTX_OK; | ||
380 | + return true; | ||
381 | case GICD_ICPENDR ... GICD_ICPENDR + 0x7f: | ||
382 | gicd_write_clear_bitmap_reg(s, attrs, s->pending, mask_nsacr_ge2, | ||
383 | offset - GICD_ICPENDR, value); | ||
384 | - return MEMTX_OK; | ||
385 | + return true; | ||
386 | case GICD_ISACTIVER ... GICD_ISACTIVER + 0x7f: | ||
387 | gicd_write_set_bitmap_reg(s, attrs, s->active, NULL, | ||
388 | offset - GICD_ISACTIVER, value); | ||
389 | - return MEMTX_OK; | ||
390 | + return true; | ||
391 | case GICD_ICACTIVER ... GICD_ICACTIVER + 0x7f: | ||
392 | gicd_write_clear_bitmap_reg(s, attrs, s->active, NULL, | ||
393 | offset - GICD_ICACTIVER, value); | ||
394 | - return MEMTX_OK; | ||
395 | + return true; | ||
396 | case GICD_IPRIORITYR ... GICD_IPRIORITYR + 0x3ff: | ||
397 | { | ||
398 | int i, irq = offset - GICD_IPRIORITYR; | ||
399 | |||
400 | if (irq < GIC_INTERNAL || irq + 3 >= s->num_irq) { | ||
401 | - return MEMTX_OK; | ||
402 | + return true; | ||
403 | } | ||
404 | |||
405 | for (i = irq; i < irq + 4; i++, value >>= 8) { | ||
406 | gicd_write_ipriorityr(s, attrs, i, value); | ||
407 | } | ||
408 | gicv3_update(s, irq, 4); | ||
409 | - return MEMTX_OK; | ||
410 | + return true; | ||
411 | } | ||
412 | case GICD_ITARGETSR ... GICD_ITARGETSR + 0x3ff: | ||
413 | /* RAZ/WI since affinity routing is always enabled */ | ||
414 | - return MEMTX_OK; | ||
415 | + return true; | ||
416 | case GICD_ICFGR ... GICD_ICFGR + 0xff: | ||
417 | { | ||
418 | /* Here only the odd bits are used; even bits are RES0 */ | ||
419 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writel(GICv3State *s, hwaddr offset, | ||
420 | uint32_t mask, oldval; | ||
421 | |||
422 | if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
423 | - return MEMTX_OK; | ||
424 | + return true; | ||
425 | } | ||
426 | |||
427 | /* Since our edge_trigger bitmap is one bit per irq, our input | ||
428 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writel(GICv3State *s, hwaddr offset, | ||
429 | oldval = *gic_bmp_ptr32(s->edge_trigger, (irq & ~0x1f)); | ||
430 | value = (oldval & ~mask) | (value & mask); | ||
431 | *gic_bmp_ptr32(s->edge_trigger, irq & ~0x1f) = value; | ||
432 | - return MEMTX_OK; | ||
433 | + return true; | ||
434 | } | ||
435 | case GICD_IGRPMODR ... GICD_IGRPMODR + 0xff: | ||
436 | { | ||
437 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writel(GICv3State *s, hwaddr offset, | ||
438 | /* RAZ/WI if security disabled, or if | ||
439 | * security enabled and this is an NS access | ||
440 | */ | ||
441 | - return MEMTX_OK; | ||
442 | + return true; | ||
443 | } | ||
444 | /* RAZ/WI for SGIs, PPIs, unimplemented irqs */ | ||
445 | irq = (offset - GICD_IGRPMODR) * 8; | ||
446 | if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
447 | - return MEMTX_OK; | ||
448 | + return true; | ||
449 | } | ||
450 | *gic_bmp_ptr32(s->grpmod, irq) = value; | ||
451 | gicv3_update(s, irq, 32); | ||
452 | - return MEMTX_OK; | ||
453 | + return true; | ||
454 | } | ||
455 | case GICD_NSACR ... GICD_NSACR + 0xff: | ||
456 | { | ||
457 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writel(GICv3State *s, hwaddr offset, | ||
458 | int irq = (offset - GICD_NSACR) * 4; | ||
459 | |||
460 | if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
461 | - return MEMTX_OK; | ||
462 | + return true; | ||
463 | } | ||
464 | |||
465 | if ((s->gicd_ctlr & GICD_CTLR_DS) || !attrs.secure) { | ||
466 | /* RAZ/WI if security disabled, or if | ||
467 | * security enabled and this is an NS access | ||
468 | */ | ||
469 | - return MEMTX_OK; | ||
470 | + return true; | ||
471 | } | ||
472 | |||
473 | s->gicd_nsacr[irq / 16] = value; | ||
474 | /* No update required as this only affects access permission checks */ | ||
475 | - return MEMTX_OK; | ||
476 | + return true; | ||
477 | } | ||
478 | case GICD_SGIR: | ||
479 | /* RES0 if affinity routing is enabled */ | ||
480 | - return MEMTX_OK; | ||
481 | + return true; | ||
482 | case GICD_CPENDSGIR ... GICD_CPENDSGIR + 0xf: | ||
483 | case GICD_SPENDSGIR ... GICD_SPENDSGIR + 0xf: | ||
484 | /* RAZ/WI since affinity routing is always enabled */ | ||
485 | - return MEMTX_OK; | ||
486 | + return true; | ||
487 | case GICD_IROUTER ... GICD_IROUTER + 0x1fdf: | ||
488 | { | ||
489 | uint64_t r; | ||
490 | int irq = (offset - GICD_IROUTER) / 8; | ||
491 | |||
492 | if (irq < GIC_INTERNAL || irq >= s->num_irq) { | ||
493 | - return MEMTX_OK; | ||
494 | + return true; | ||
495 | } | ||
496 | |||
497 | /* Write half of the 64-bit register */ | ||
498 | r = gicd_read_irouter(s, attrs, irq); | ||
499 | r = deposit64(r, (offset & 7) ? 32 : 0, 32, value); | ||
500 | gicd_write_irouter(s, attrs, irq, r); | ||
501 | - return MEMTX_OK; | ||
502 | + return true; | ||
503 | } | ||
504 | case GICD_IDREGS ... GICD_IDREGS + 0x2f: | ||
505 | case GICD_TYPER: | ||
506 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writel(GICv3State *s, hwaddr offset, | ||
507 | qemu_log_mask(LOG_GUEST_ERROR, | ||
508 | "%s: invalid guest write to RO register at offset " | ||
509 | TARGET_FMT_plx "\n", __func__, offset); | ||
510 | - return MEMTX_OK; | ||
511 | + return true; | ||
512 | default: | ||
513 | - return MEMTX_ERROR; | ||
514 | + return false; | ||
515 | } | ||
516 | } | ||
517 | |||
518 | -static MemTxResult gicd_writeq(GICv3State *s, hwaddr offset, | ||
519 | - uint64_t value, MemTxAttrs attrs) | ||
520 | +static bool gicd_writeq(GICv3State *s, hwaddr offset, | ||
521 | + uint64_t value, MemTxAttrs attrs) | ||
522 | { | ||
523 | /* Our only 64-bit registers are GICD_IROUTER<n> */ | ||
524 | int irq; | ||
525 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writeq(GICv3State *s, hwaddr offset, | ||
526 | case GICD_IROUTER ... GICD_IROUTER + 0x1fdf: | ||
527 | irq = (offset - GICD_IROUTER) / 8; | ||
528 | gicd_write_irouter(s, attrs, irq, value); | ||
529 | - return MEMTX_OK; | ||
530 | + return true; | ||
531 | default: | ||
532 | - return MEMTX_ERROR; | ||
533 | + return false; | ||
534 | } | ||
535 | } | ||
536 | |||
537 | -static MemTxResult gicd_readq(GICv3State *s, hwaddr offset, | ||
538 | - uint64_t *data, MemTxAttrs attrs) | ||
539 | +static bool gicd_readq(GICv3State *s, hwaddr offset, | ||
540 | + uint64_t *data, MemTxAttrs attrs) | ||
541 | { | ||
542 | /* Our only 64-bit registers are GICD_IROUTER<n> */ | ||
543 | int irq; | ||
544 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_readq(GICv3State *s, hwaddr offset, | ||
545 | case GICD_IROUTER ... GICD_IROUTER + 0x1fdf: | ||
546 | irq = (offset - GICD_IROUTER) / 8; | ||
547 | *data = gicd_read_irouter(s, attrs, irq); | ||
548 | - return MEMTX_OK; | ||
549 | + return true; | ||
550 | default: | ||
551 | - return MEMTX_ERROR; | ||
552 | + return false; | ||
553 | } | ||
554 | } | ||
555 | |||
556 | @@ -XXX,XX +XXX,XX @@ MemTxResult gicv3_dist_read(void *opaque, hwaddr offset, uint64_t *data, | ||
557 | unsigned size, MemTxAttrs attrs) | ||
558 | { | ||
559 | GICv3State *s = (GICv3State *)opaque; | ||
560 | - MemTxResult r; | ||
561 | + bool r; | ||
562 | |||
563 | switch (size) { | ||
564 | case 1: | ||
565 | @@ -XXX,XX +XXX,XX @@ MemTxResult gicv3_dist_read(void *opaque, hwaddr offset, uint64_t *data, | ||
566 | r = gicd_readq(s, offset, data, attrs); | ||
567 | break; | ||
568 | default: | ||
569 | - r = MEMTX_ERROR; | ||
570 | + r = false; | ||
571 | break; | ||
572 | } | ||
573 | |||
574 | - if (r == MEMTX_ERROR) { | ||
575 | + if (!r) { | ||
576 | qemu_log_mask(LOG_GUEST_ERROR, | ||
577 | "%s: invalid guest read at offset " TARGET_FMT_plx | ||
578 | "size %u\n", __func__, offset, size); | ||
579 | @@ -XXX,XX +XXX,XX @@ MemTxResult gicv3_dist_read(void *opaque, hwaddr offset, uint64_t *data, | ||
580 | * trigger the guest-error logging but don't return it to | ||
581 | * the caller, or we'll cause a spurious guest data abort. | ||
582 | */ | ||
583 | - r = MEMTX_OK; | ||
584 | *data = 0; | ||
585 | } else { | ||
586 | trace_gicv3_dist_read(offset, *data, size, attrs.secure); | ||
587 | } | ||
588 | - return r; | ||
589 | + return MEMTX_OK; | ||
590 | } | ||
591 | |||
592 | MemTxResult gicv3_dist_write(void *opaque, hwaddr offset, uint64_t data, | ||
593 | unsigned size, MemTxAttrs attrs) | ||
594 | { | ||
595 | GICv3State *s = (GICv3State *)opaque; | ||
596 | - MemTxResult r; | ||
597 | + bool r; | ||
598 | |||
599 | switch (size) { | ||
600 | case 1: | ||
601 | @@ -XXX,XX +XXX,XX @@ MemTxResult gicv3_dist_write(void *opaque, hwaddr offset, uint64_t data, | ||
602 | r = gicd_writeq(s, offset, data, attrs); | ||
603 | break; | ||
604 | default: | ||
605 | - r = MEMTX_ERROR; | ||
606 | + r = false; | ||
607 | break; | ||
608 | } | ||
609 | |||
610 | - if (r == MEMTX_ERROR) { | ||
611 | + if (!r) { | ||
612 | qemu_log_mask(LOG_GUEST_ERROR, | ||
613 | "%s: invalid guest write at offset " TARGET_FMT_plx | ||
614 | "size %u\n", __func__, offset, size); | ||
615 | @@ -XXX,XX +XXX,XX @@ MemTxResult gicv3_dist_write(void *opaque, hwaddr offset, uint64_t data, | ||
616 | * trigger the guest-error logging but don't return it to | ||
617 | * the caller, or we'll cause a spurious guest data abort. | ||
618 | */ | ||
619 | - r = MEMTX_OK; | ||
620 | } else { | ||
621 | trace_gicv3_dist_write(offset, data, size, attrs.secure); | ||
622 | } | ||
623 | - return r; | ||
624 | + return MEMTX_OK; | ||
625 | } | ||
626 | |||
627 | void gicv3_dist_set_irq(GICv3State *s, int irq, int level) | ||
628 | -- | ||
629 | 2.20.1 | ||
630 | |||
631 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Yanan Wang <wangyanan55@huawei.com> | |
2 | |||
3 | Add 6.2 machine types for arm/i440fx/q35/s390x/spapr. | ||
4 | |||
5 | Signed-off-by: Yanan Wang <wangyanan55@huawei.com> | ||
6 | Acked-by: David Gibson <david@gibson.dropbear.id.au> | ||
7 | Reviewed-by: Andrew Jones <drjones@redhat.com> | ||
8 | Reviewed-by: Cornelia Huck <cohuck@redhat.com> | ||
9 | Reviewed-by: Pankaj Gupta <pankaj.gupta@ionos.com> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | include/hw/boards.h | 3 +++ | ||
13 | include/hw/i386/pc.h | 3 +++ | ||
14 | hw/arm/virt.c | 11 +++++++++-- | ||
15 | hw/core/machine.c | 3 +++ | ||
16 | hw/i386/pc.c | 3 +++ | ||
17 | hw/i386/pc_piix.c | 14 +++++++++++++- | ||
18 | hw/i386/pc_q35.c | 13 ++++++++++++- | ||
19 | hw/ppc/spapr.c | 17 ++++++++++++++--- | ||
20 | hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- | ||
21 | 9 files changed, 73 insertions(+), 8 deletions(-) | ||
22 | |||
23 | diff --git a/include/hw/boards.h b/include/hw/boards.h | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/include/hw/boards.h | ||
26 | +++ b/include/hw/boards.h | ||
27 | @@ -XXX,XX +XXX,XX @@ struct MachineState { | ||
28 | } \ | ||
29 | type_init(machine_initfn##_register_types) | ||
30 | |||
31 | +extern GlobalProperty hw_compat_6_1[]; | ||
32 | +extern const size_t hw_compat_6_1_len; | ||
33 | + | ||
34 | extern GlobalProperty hw_compat_6_0[]; | ||
35 | extern const size_t hw_compat_6_0_len; | ||
36 | |||
37 | diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/include/hw/i386/pc.h | ||
40 | +++ b/include/hw/i386/pc.h | ||
41 | @@ -XXX,XX +XXX,XX @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size); | ||
42 | void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid, | ||
43 | const CPUArchIdList *apic_ids, GArray *entry); | ||
44 | |||
45 | +extern GlobalProperty pc_compat_6_1[]; | ||
46 | +extern const size_t pc_compat_6_1_len; | ||
47 | + | ||
48 | extern GlobalProperty pc_compat_6_0[]; | ||
49 | extern const size_t pc_compat_6_0_len; | ||
50 | |||
51 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/hw/arm/virt.c | ||
54 | +++ b/hw/arm/virt.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static void machvirt_machine_init(void) | ||
56 | } | ||
57 | type_init(machvirt_machine_init); | ||
58 | |||
59 | -static void virt_machine_6_1_options(MachineClass *mc) | ||
60 | +static void virt_machine_6_2_options(MachineClass *mc) | ||
61 | { | ||
62 | } | ||
63 | -DEFINE_VIRT_MACHINE_AS_LATEST(6, 1) | ||
64 | +DEFINE_VIRT_MACHINE_AS_LATEST(6, 2) | ||
65 | + | ||
66 | +static void virt_machine_6_1_options(MachineClass *mc) | ||
67 | +{ | ||
68 | + virt_machine_6_2_options(mc); | ||
69 | + compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); | ||
70 | +} | ||
71 | +DEFINE_VIRT_MACHINE(6, 1) | ||
72 | |||
73 | static void virt_machine_6_0_options(MachineClass *mc) | ||
74 | { | ||
75 | diff --git a/hw/core/machine.c b/hw/core/machine.c | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/hw/core/machine.c | ||
78 | +++ b/hw/core/machine.c | ||
79 | @@ -XXX,XX +XXX,XX @@ | ||
80 | #include "hw/virtio/virtio.h" | ||
81 | #include "hw/virtio/virtio-pci.h" | ||
82 | |||
83 | +GlobalProperty hw_compat_6_1[] = {}; | ||
84 | +const size_t hw_compat_6_1_len = G_N_ELEMENTS(hw_compat_6_1); | ||
85 | + | ||
86 | GlobalProperty hw_compat_6_0[] = { | ||
87 | { "gpex-pcihost", "allow-unmapped-accesses", "false" }, | ||
88 | { "i8042", "extended-state", "false"}, | ||
89 | diff --git a/hw/i386/pc.c b/hw/i386/pc.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/hw/i386/pc.c | ||
92 | +++ b/hw/i386/pc.c | ||
93 | @@ -XXX,XX +XXX,XX @@ | ||
94 | #include "trace.h" | ||
95 | #include CONFIG_DEVICES | ||
96 | |||
97 | +GlobalProperty pc_compat_6_1[] = {}; | ||
98 | +const size_t pc_compat_6_1_len = G_N_ELEMENTS(pc_compat_6_1); | ||
99 | + | ||
100 | GlobalProperty pc_compat_6_0[] = { | ||
101 | { "qemu64" "-" TYPE_X86_CPU, "family", "6" }, | ||
102 | { "qemu64" "-" TYPE_X86_CPU, "model", "6" }, | ||
103 | diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c | ||
104 | index XXXXXXX..XXXXXXX 100644 | ||
105 | --- a/hw/i386/pc_piix.c | ||
106 | +++ b/hw/i386/pc_piix.c | ||
107 | @@ -XXX,XX +XXX,XX @@ static void pc_i440fx_machine_options(MachineClass *m) | ||
108 | machine_class_allow_dynamic_sysbus_dev(m, TYPE_VMBUS_BRIDGE); | ||
109 | } | ||
110 | |||
111 | -static void pc_i440fx_6_1_machine_options(MachineClass *m) | ||
112 | +static void pc_i440fx_6_2_machine_options(MachineClass *m) | ||
113 | { | ||
114 | PCMachineClass *pcmc = PC_MACHINE_CLASS(m); | ||
115 | pc_i440fx_machine_options(m); | ||
116 | @@ -XXX,XX +XXX,XX @@ static void pc_i440fx_6_1_machine_options(MachineClass *m) | ||
117 | pcmc->default_cpu_version = 1; | ||
118 | } | ||
119 | |||
120 | +DEFINE_I440FX_MACHINE(v6_2, "pc-i440fx-6.2", NULL, | ||
121 | + pc_i440fx_6_2_machine_options); | ||
122 | + | ||
123 | +static void pc_i440fx_6_1_machine_options(MachineClass *m) | ||
124 | +{ | ||
125 | + pc_i440fx_6_2_machine_options(m); | ||
126 | + m->alias = NULL; | ||
127 | + m->is_default = false; | ||
128 | + compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len); | ||
129 | + compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len); | ||
130 | +} | ||
131 | + | ||
132 | DEFINE_I440FX_MACHINE(v6_1, "pc-i440fx-6.1", NULL, | ||
133 | pc_i440fx_6_1_machine_options); | ||
134 | |||
135 | diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c | ||
136 | index XXXXXXX..XXXXXXX 100644 | ||
137 | --- a/hw/i386/pc_q35.c | ||
138 | +++ b/hw/i386/pc_q35.c | ||
139 | @@ -XXX,XX +XXX,XX @@ static void pc_q35_machine_options(MachineClass *m) | ||
140 | m->max_cpus = 288; | ||
141 | } | ||
142 | |||
143 | -static void pc_q35_6_1_machine_options(MachineClass *m) | ||
144 | +static void pc_q35_6_2_machine_options(MachineClass *m) | ||
145 | { | ||
146 | PCMachineClass *pcmc = PC_MACHINE_CLASS(m); | ||
147 | pc_q35_machine_options(m); | ||
148 | @@ -XXX,XX +XXX,XX @@ static void pc_q35_6_1_machine_options(MachineClass *m) | ||
149 | pcmc->default_cpu_version = 1; | ||
150 | } | ||
151 | |||
152 | +DEFINE_Q35_MACHINE(v6_2, "pc-q35-6.2", NULL, | ||
153 | + pc_q35_6_2_machine_options); | ||
154 | + | ||
155 | +static void pc_q35_6_1_machine_options(MachineClass *m) | ||
156 | +{ | ||
157 | + pc_q35_6_2_machine_options(m); | ||
158 | + m->alias = NULL; | ||
159 | + compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len); | ||
160 | + compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len); | ||
161 | +} | ||
162 | + | ||
163 | DEFINE_Q35_MACHINE(v6_1, "pc-q35-6.1", NULL, | ||
164 | pc_q35_6_1_machine_options); | ||
165 | |||
166 | diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c | ||
167 | index XXXXXXX..XXXXXXX 100644 | ||
168 | --- a/hw/ppc/spapr.c | ||
169 | +++ b/hw/ppc/spapr.c | ||
170 | @@ -XXX,XX +XXX,XX @@ static void spapr_machine_latest_class_options(MachineClass *mc) | ||
171 | type_init(spapr_machine_register_##suffix) | ||
172 | |||
173 | /* | ||
174 | - * pseries-6.1 | ||
175 | + * pseries-6.2 | ||
176 | */ | ||
177 | -static void spapr_machine_6_1_class_options(MachineClass *mc) | ||
178 | +static void spapr_machine_6_2_class_options(MachineClass *mc) | ||
179 | { | ||
180 | /* Defaults for the latest behaviour inherited from the base class */ | ||
181 | } | ||
182 | |||
183 | -DEFINE_SPAPR_MACHINE(6_1, "6.1", true); | ||
184 | +DEFINE_SPAPR_MACHINE(6_2, "6.2", true); | ||
185 | + | ||
186 | +/* | ||
187 | + * pseries-6.1 | ||
188 | + */ | ||
189 | +static void spapr_machine_6_1_class_options(MachineClass *mc) | ||
190 | +{ | ||
191 | + spapr_machine_6_2_class_options(mc); | ||
192 | + compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); | ||
193 | +} | ||
194 | + | ||
195 | +DEFINE_SPAPR_MACHINE(6_1, "6.1", false); | ||
196 | |||
197 | /* | ||
198 | * pseries-6.0 | ||
199 | diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c | ||
200 | index XXXXXXX..XXXXXXX 100644 | ||
201 | --- a/hw/s390x/s390-virtio-ccw.c | ||
202 | +++ b/hw/s390x/s390-virtio-ccw.c | ||
203 | @@ -XXX,XX +XXX,XX @@ bool css_migration_enabled(void) | ||
204 | } \ | ||
205 | type_init(ccw_machine_register_##suffix) | ||
206 | |||
207 | +static void ccw_machine_6_2_instance_options(MachineState *machine) | ||
208 | +{ | ||
209 | +} | ||
210 | + | ||
211 | +static void ccw_machine_6_2_class_options(MachineClass *mc) | ||
212 | +{ | ||
213 | +} | ||
214 | +DEFINE_CCW_MACHINE(6_2, "6.2", true); | ||
215 | + | ||
216 | static void ccw_machine_6_1_instance_options(MachineState *machine) | ||
217 | { | ||
218 | + ccw_machine_6_2_instance_options(machine); | ||
219 | } | ||
220 | |||
221 | static void ccw_machine_6_1_class_options(MachineClass *mc) | ||
222 | { | ||
223 | + ccw_machine_6_2_class_options(mc); | ||
224 | + compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); | ||
225 | } | ||
226 | -DEFINE_CCW_MACHINE(6_1, "6.1", true); | ||
227 | +DEFINE_CCW_MACHINE(6_1, "6.1", false); | ||
228 | |||
229 | static void ccw_machine_6_0_instance_options(MachineState *machine) | ||
230 | { | ||
231 | -- | ||
232 | 2.20.1 | ||
233 | |||
234 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | Implement the MVE VADD (floating-point) insn. Handling of this is |
---|---|---|---|
2 | similar to the 2-operand integer insns, except that we must take care | ||
3 | to only update the floating point exception status if the least | ||
4 | significant bit of the predicate mask for each element is active. | ||
2 | 5 | ||
3 | Add both SVE exception state and vector length. | 6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Message-id: 20180123035349.24538-6-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 8 | --- |
10 | target/arm/cpu.h | 8 ++++++++ | 9 | target/arm/helper-mve.h | 3 +++ |
11 | target/arm/translate.h | 2 ++ | 10 | target/arm/translate.h | 6 ++++++ |
12 | target/arm/helper.c | 25 ++++++++++++++++++++++++- | 11 | target/arm/mve.decode | 10 ++++++++++ |
13 | target/arm/translate-a64.c | 2 ++ | 12 | target/arm/mve_helper.c | 40 +++++++++++++++++++++++++++++++++++++ |
14 | 4 files changed, 36 insertions(+), 1 deletion(-) | 13 | target/arm/translate-mve.c | 17 ++++++++++++++++ |
14 | target/arm/translate-neon.c | 6 ------ | ||
15 | 6 files changed, 76 insertions(+), 6 deletions(-) | ||
15 | 16 | ||
16 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 17 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
17 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/cpu.h | 19 | --- a/target/arm/helper-mve.h |
19 | +++ b/target/arm/cpu.h | 20 | +++ b/target/arm/helper-mve.h |
20 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_cpu_data_is_big_endian(CPUARMState *env) | 21 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vhcadd270b, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
21 | #define ARM_TBFLAG_TBI0_MASK (0x1ull << ARM_TBFLAG_TBI0_SHIFT) | 22 | DEF_HELPER_FLAGS_4(mve_vhcadd270h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
22 | #define ARM_TBFLAG_TBI1_SHIFT 1 /* TBI1 for EL0/1 */ | 23 | DEF_HELPER_FLAGS_4(mve_vhcadd270w, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
23 | #define ARM_TBFLAG_TBI1_MASK (0x1ull << ARM_TBFLAG_TBI1_SHIFT) | 24 | |
24 | +#define ARM_TBFLAG_SVEEXC_EL_SHIFT 2 | 25 | +DEF_HELPER_FLAGS_4(mve_vfaddh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
25 | +#define ARM_TBFLAG_SVEEXC_EL_MASK (0x3 << ARM_TBFLAG_SVEEXC_EL_SHIFT) | 26 | +DEF_HELPER_FLAGS_4(mve_vfadds, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
26 | +#define ARM_TBFLAG_ZCR_LEN_SHIFT 4 | 27 | + |
27 | +#define ARM_TBFLAG_ZCR_LEN_MASK (0xf << ARM_TBFLAG_ZCR_LEN_SHIFT) | 28 | DEF_HELPER_FLAGS_4(mve_vadd_scalarb, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
28 | 29 | DEF_HELPER_FLAGS_4(mve_vadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | |
29 | /* some convenience accessor macros */ | 30 | DEF_HELPER_FLAGS_4(mve_vadd_scalarw, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
30 | #define ARM_TBFLAG_AARCH64_STATE(F) \ | ||
31 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_cpu_data_is_big_endian(CPUARMState *env) | ||
32 | (((F) & ARM_TBFLAG_TBI0_MASK) >> ARM_TBFLAG_TBI0_SHIFT) | ||
33 | #define ARM_TBFLAG_TBI1(F) \ | ||
34 | (((F) & ARM_TBFLAG_TBI1_MASK) >> ARM_TBFLAG_TBI1_SHIFT) | ||
35 | +#define ARM_TBFLAG_SVEEXC_EL(F) \ | ||
36 | + (((F) & ARM_TBFLAG_SVEEXC_EL_MASK) >> ARM_TBFLAG_SVEEXC_EL_SHIFT) | ||
37 | +#define ARM_TBFLAG_ZCR_LEN(F) \ | ||
38 | + (((F) & ARM_TBFLAG_ZCR_LEN_MASK) >> ARM_TBFLAG_ZCR_LEN_SHIFT) | ||
39 | |||
40 | static inline bool bswap_code(bool sctlr_b) | ||
41 | { | ||
42 | diff --git a/target/arm/translate.h b/target/arm/translate.h | 31 | diff --git a/target/arm/translate.h b/target/arm/translate.h |
43 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/target/arm/translate.h | 33 | --- a/target/arm/translate.h |
45 | +++ b/target/arm/translate.h | 34 | +++ b/target/arm/translate.h |
46 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | 35 | @@ -XXX,XX +XXX,XX @@ static inline int rsub_8(DisasContext *s, int x) |
47 | bool tbi1; /* TBI1 for EL0/1, not used for EL2/3 */ | 36 | return 8 - x; |
48 | bool ns; /* Use non-secure CPREG bank on access */ | 37 | } |
49 | int fp_excp_el; /* FP exception EL or 0 if enabled */ | 38 | |
50 | + int sve_excp_el; /* SVE exception EL or 0 if enabled */ | 39 | +static inline int neon_3same_fp_size(DisasContext *s, int x) |
51 | + int sve_len; /* SVE vector length in bytes */ | 40 | +{ |
52 | /* Flag indicating that exceptions from secure mode are routed to EL3. */ | 41 | + /* Convert 0==fp32, 1==fp16 into a MO_* value */ |
53 | bool secure_routed_to_el3; | 42 | + return MO_32 - x; |
54 | bool vfp_enabled; /* FP enabled via FPSCR.EN */ | 43 | +} |
55 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 44 | + |
45 | static inline int arm_dc_feature(DisasContext *dc, int feature) | ||
46 | { | ||
47 | return (dc->features & (1ULL << feature)) != 0; | ||
48 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
56 | index XXXXXXX..XXXXXXX 100644 | 49 | index XXXXXXX..XXXXXXX 100644 |
57 | --- a/target/arm/helper.c | 50 | --- a/target/arm/mve.decode |
58 | +++ b/target/arm/helper.c | 51 | +++ b/target/arm/mve.decode |
59 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | 52 | @@ -XXX,XX +XXX,XX @@ |
60 | target_ulong *cs_base, uint32_t *pflags) | 53 | # VQDMULL has size in bit 28: 0 for 16 bit, 1 for 32 bit |
54 | %size_28 28:1 !function=plus_1 | ||
55 | |||
56 | +# 2 operand fp insns have size in bit 20: 1 for 16 bit, 0 for 32 bit, | ||
57 | +# like Neon FP insns. | ||
58 | +%2op_fp_size 20:1 !function=neon_3same_fp_size | ||
59 | + | ||
60 | # 1imm format immediate | ||
61 | %imm_28_16_0 28:1 16:3 0:4 | ||
62 | |||
63 | @@ -XXX,XX +XXX,XX @@ | ||
64 | |||
65 | @vmaxv .... .... .... size:2 .. rda:4 .... .... .... &vmaxv qm=%qm | ||
66 | |||
67 | +@2op_fp .... .... .... .... .... .... .... .... &2op \ | ||
68 | + qd=%qd qn=%qn qm=%qm size=%2op_fp_size | ||
69 | + | ||
70 | # Vector loads and stores | ||
71 | |||
72 | # Widening loads and narrowing stores: | ||
73 | @@ -XXX,XX +XXX,XX @@ VCMPGE_scalar 1111 1110 0 . .. ... 1 ... 1 1111 0 1 0 0 .... @vcmp_scalar | ||
74 | VCMPLT_scalar 1111 1110 0 . .. ... 1 ... 1 1111 1 1 0 0 .... @vcmp_scalar | ||
75 | VCMPGT_scalar 1111 1110 0 . .. ... 1 ... 1 1111 0 1 1 0 .... @vcmp_scalar | ||
76 | VCMPLE_scalar 1111 1110 0 . .. ... 1 ... 1 1111 1 1 1 0 .... @vcmp_scalar | ||
77 | + | ||
78 | +# 2-operand FP | ||
79 | +VADD_fp 1110 1111 0 . 0 . ... 0 ... 0 1101 . 1 . 0 ... 0 @2op_fp | ||
80 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
81 | index XXXXXXX..XXXXXXX 100644 | ||
82 | --- a/target/arm/mve_helper.c | ||
83 | +++ b/target/arm/mve_helper.c | ||
84 | @@ -XXX,XX +XXX,XX @@ | ||
85 | #include "exec/cpu_ldst.h" | ||
86 | #include "exec/exec-all.h" | ||
87 | #include "tcg/tcg.h" | ||
88 | +#include "fpu/softfloat.h" | ||
89 | |||
90 | static uint16_t mve_eci_mask(CPUARMState *env) | ||
61 | { | 91 | { |
62 | ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | 92 | @@ -XXX,XX +XXX,XX @@ DO_VMAXMINA(vmaxaw, 4, int32_t, uint32_t, DO_MAX) |
63 | + int fp_el = fp_exception_el(env); | 93 | DO_VMAXMINA(vminab, 1, int8_t, uint8_t, DO_MIN) |
64 | uint32_t flags; | 94 | DO_VMAXMINA(vminah, 2, int16_t, uint16_t, DO_MIN) |
65 | 95 | DO_VMAXMINA(vminaw, 4, int32_t, uint32_t, DO_MIN) | |
66 | if (is_a64(env)) { | ||
67 | + int sve_el = sve_exception_el(env); | ||
68 | + uint32_t zcr_len; | ||
69 | + | 96 | + |
70 | *pc = env->pc; | 97 | +/* |
71 | flags = ARM_TBFLAG_AARCH64_STATE_MASK; | 98 | + * 2-operand floating point. Note that if an element is partially |
72 | /* Get control bits for tagged addresses */ | 99 | + * predicated we must do the FP operation to update the non-predicated |
73 | flags |= (arm_regime_tbi0(env, mmu_idx) << ARM_TBFLAG_TBI0_SHIFT); | 100 | + * bytes, but we must be careful to avoid updating the FP exception |
74 | flags |= (arm_regime_tbi1(env, mmu_idx) << ARM_TBFLAG_TBI1_SHIFT); | 101 | + * state unless byte 0 of the element was unpredicated. |
75 | + flags |= sve_el << ARM_TBFLAG_SVEEXC_EL_SHIFT; | 102 | + */ |
103 | +#define DO_2OP_FP(OP, ESIZE, TYPE, FN) \ | ||
104 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ | ||
105 | + void *vd, void *vn, void *vm) \ | ||
106 | + { \ | ||
107 | + TYPE *d = vd, *n = vn, *m = vm; \ | ||
108 | + TYPE r; \ | ||
109 | + uint16_t mask = mve_element_mask(env); \ | ||
110 | + unsigned e; \ | ||
111 | + float_status *fpst; \ | ||
112 | + float_status scratch_fpst; \ | ||
113 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ | ||
114 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ | ||
115 | + continue; \ | ||
116 | + } \ | ||
117 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | ||
118 | + &env->vfp.standard_fp_status; \ | ||
119 | + if (!(mask & 1)) { \ | ||
120 | + /* We need the result but without updating flags */ \ | ||
121 | + scratch_fpst = *fpst; \ | ||
122 | + fpst = &scratch_fpst; \ | ||
123 | + } \ | ||
124 | + r = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], fpst); \ | ||
125 | + mergemask(&d[H##ESIZE(e)], r, mask); \ | ||
126 | + } \ | ||
127 | + mve_advance_vpt(env); \ | ||
128 | + } | ||
76 | + | 129 | + |
77 | + /* If SVE is disabled, but FP is enabled, | 130 | +#define DO_2OP_FP_ALL(OP, FN) \ |
78 | + then the effective len is 0. */ | 131 | + DO_2OP_FP(OP##h, 2, float16, float16_##FN) \ |
79 | + if (sve_el != 0 && fp_el == 0) { | 132 | + DO_2OP_FP(OP##s, 4, float32, float32_##FN) |
80 | + zcr_len = 0; | ||
81 | + } else { | ||
82 | + int current_el = arm_current_el(env); | ||
83 | + | 133 | + |
84 | + zcr_len = env->vfp.zcr_el[current_el <= 1 ? 1 : current_el]; | 134 | +DO_2OP_FP_ALL(vfadd, add) |
85 | + zcr_len &= 0xf; | 135 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
86 | + if (current_el < 2 && arm_feature(env, ARM_FEATURE_EL2)) { | ||
87 | + zcr_len = MIN(zcr_len, 0xf & (uint32_t)env->vfp.zcr_el[2]); | ||
88 | + } | ||
89 | + if (current_el < 3 && arm_feature(env, ARM_FEATURE_EL3)) { | ||
90 | + zcr_len = MIN(zcr_len, 0xf & (uint32_t)env->vfp.zcr_el[3]); | ||
91 | + } | ||
92 | + } | ||
93 | + flags |= zcr_len << ARM_TBFLAG_ZCR_LEN_SHIFT; | ||
94 | } else { | ||
95 | *pc = env->regs[15]; | ||
96 | flags = (env->thumb << ARM_TBFLAG_THUMB_SHIFT) | ||
97 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
98 | if (arm_cpu_data_is_big_endian(env)) { | ||
99 | flags |= ARM_TBFLAG_BE_DATA_MASK; | ||
100 | } | ||
101 | - flags |= fp_exception_el(env) << ARM_TBFLAG_FPEXC_EL_SHIFT; | ||
102 | + flags |= fp_el << ARM_TBFLAG_FPEXC_EL_SHIFT; | ||
103 | |||
104 | if (arm_v7m_is_handler_mode(env)) { | ||
105 | flags |= ARM_TBFLAG_HANDLER_MASK; | ||
106 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
107 | index XXXXXXX..XXXXXXX 100644 | 136 | index XXXXXXX..XXXXXXX 100644 |
108 | --- a/target/arm/translate-a64.c | 137 | --- a/target/arm/translate-mve.c |
109 | +++ b/target/arm/translate-a64.c | 138 | +++ b/target/arm/translate-mve.c |
110 | @@ -XXX,XX +XXX,XX @@ static int aarch64_tr_init_disas_context(DisasContextBase *dcbase, | 139 | @@ -XXX,XX +XXX,XX @@ static bool trans_VSBCI(DisasContext *s, arg_2op *a) |
111 | dc->user = (dc->current_el == 0); | 140 | return do_2op(s, a, gen_helper_mve_vsbci); |
112 | #endif | 141 | } |
113 | dc->fp_excp_el = ARM_TBFLAG_FPEXC_EL(dc->base.tb->flags); | 142 | |
114 | + dc->sve_excp_el = ARM_TBFLAG_SVEEXC_EL(dc->base.tb->flags); | 143 | +#define DO_2OP_FP(INSN, FN) \ |
115 | + dc->sve_len = (ARM_TBFLAG_ZCR_LEN(dc->base.tb->flags) + 1) * 16; | 144 | + static bool trans_##INSN(DisasContext *s, arg_2op *a) \ |
116 | dc->vec_len = 0; | 145 | + { \ |
117 | dc->vec_stride = 0; | 146 | + static MVEGenTwoOpFn * const fns[] = { \ |
118 | dc->cp_regs = arm_cpu->cp_regs; | 147 | + NULL, \ |
148 | + gen_helper_mve_##FN##h, \ | ||
149 | + gen_helper_mve_##FN##s, \ | ||
150 | + NULL, \ | ||
151 | + }; \ | ||
152 | + if (!dc_isar_feature(aa32_mve_fp, s)) { \ | ||
153 | + return false; \ | ||
154 | + } \ | ||
155 | + return do_2op(s, a, fns[a->size]); \ | ||
156 | + } | ||
157 | + | ||
158 | +DO_2OP_FP(VADD_fp, vfadd) | ||
159 | + | ||
160 | static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, | ||
161 | MVEGenTwoOpScalarFn fn) | ||
162 | { | ||
163 | diff --git a/target/arm/translate-neon.c b/target/arm/translate-neon.c | ||
164 | index XXXXXXX..XXXXXXX 100644 | ||
165 | --- a/target/arm/translate-neon.c | ||
166 | +++ b/target/arm/translate-neon.c | ||
167 | @@ -XXX,XX +XXX,XX @@ | ||
168 | #include "translate.h" | ||
169 | #include "translate-a32.h" | ||
170 | |||
171 | -static inline int neon_3same_fp_size(DisasContext *s, int x) | ||
172 | -{ | ||
173 | - /* Convert 0==fp32, 1==fp16 into a MO_* value */ | ||
174 | - return MO_32 - x; | ||
175 | -} | ||
176 | - | ||
177 | /* Include the generated Neon decoder */ | ||
178 | #include "decode-neon-dp.c.inc" | ||
179 | #include "decode-neon-ls.c.inc" | ||
119 | -- | 180 | -- |
120 | 2.16.1 | 181 | 2.20.1 |
121 | 182 | ||
122 | 183 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | Implement more simple 2-operand floating point MVE insns. |
---|---|---|---|
2 | 2 | ||
3 | Add code to emulate SNVS IP-block. Currently only the bits needed to | 3 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
4 | be able to emulate machine shutdown are implemented. | ||
5 | |||
6 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Cc: Jason Wang <jasowang@redhat.com> | ||
8 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
10 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Cc: qemu-devel@nongnu.org | ||
12 | Cc: qemu-arm@nongnu.org | ||
13 | Cc: yurovsky@gmail.com | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 5 | --- |
18 | hw/misc/Makefile.objs | 1 + | 6 | target/arm/helper-mve.h | 15 +++++++++++++++ |
19 | include/hw/misc/imx7_snvs.h | 35 +++++++++++++++++++ | 7 | target/arm/mve.decode | 6 ++++++ |
20 | hw/misc/imx7_snvs.c | 83 +++++++++++++++++++++++++++++++++++++++++++++ | 8 | target/arm/mve_helper.c | 16 ++++++++++++++++ |
21 | 3 files changed, 119 insertions(+) | 9 | target/arm/translate-mve.c | 5 +++++ |
22 | create mode 100644 include/hw/misc/imx7_snvs.h | 10 | 4 files changed, 42 insertions(+) |
23 | create mode 100644 hw/misc/imx7_snvs.c | ||
24 | 11 | ||
25 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 12 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
26 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/hw/misc/Makefile.objs | 14 | --- a/target/arm/helper-mve.h |
28 | +++ b/hw/misc/Makefile.objs | 15 | +++ b/target/arm/helper-mve.h |
29 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx6_ccm.o | 16 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vhcadd270w, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
30 | obj-$(CONFIG_IMX) += imx6_src.o | 17 | DEF_HELPER_FLAGS_4(mve_vfaddh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
31 | obj-$(CONFIG_IMX) += imx7_ccm.o | 18 | DEF_HELPER_FLAGS_4(mve_vfadds, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
32 | obj-$(CONFIG_IMX) += imx2_wdt.o | 19 | |
33 | +obj-$(CONFIG_IMX) += imx7_snvs.o | 20 | +DEF_HELPER_FLAGS_4(mve_vfsubh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
34 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | 21 | +DEF_HELPER_FLAGS_4(mve_vfsubs, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
35 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | ||
36 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | ||
37 | diff --git a/include/hw/misc/imx7_snvs.h b/include/hw/misc/imx7_snvs.h | ||
38 | new file mode 100644 | ||
39 | index XXXXXXX..XXXXXXX | ||
40 | --- /dev/null | ||
41 | +++ b/include/hw/misc/imx7_snvs.h | ||
42 | @@ -XXX,XX +XXX,XX @@ | ||
43 | +/* | ||
44 | + * Copyright (c) 2017, Impinj, Inc. | ||
45 | + * | ||
46 | + * i.MX7 SNVS block emulation code | ||
47 | + * | ||
48 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
49 | + * | ||
50 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
51 | + * See the COPYING file in the top-level directory. | ||
52 | + */ | ||
53 | + | 22 | + |
54 | +#ifndef IMX7_SNVS_H | 23 | +DEF_HELPER_FLAGS_4(mve_vfmulh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
55 | +#define IMX7_SNVS_H | 24 | +DEF_HELPER_FLAGS_4(mve_vfmuls, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
56 | + | 25 | + |
57 | +#include "qemu/bitops.h" | 26 | +DEF_HELPER_FLAGS_4(mve_vfabdh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
58 | +#include "hw/sysbus.h" | 27 | +DEF_HELPER_FLAGS_4(mve_vfabds, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
59 | + | 28 | + |
29 | +DEF_HELPER_FLAGS_4(mve_vmaxnmh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
30 | +DEF_HELPER_FLAGS_4(mve_vmaxnms, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
60 | + | 31 | + |
61 | +enum IMX7SNVSRegisters { | 32 | +DEF_HELPER_FLAGS_4(mve_vminnmh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
62 | + SNVS_LPCR = 0x38, | 33 | +DEF_HELPER_FLAGS_4(mve_vminnms, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
63 | + SNVS_LPCR_TOP = BIT(6), | ||
64 | + SNVS_LPCR_DP_EN = BIT(5) | ||
65 | +}; | ||
66 | + | 34 | + |
67 | +#define TYPE_IMX7_SNVS "imx7.snvs" | 35 | DEF_HELPER_FLAGS_4(mve_vadd_scalarb, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
68 | +#define IMX7_SNVS(obj) OBJECT_CHECK(IMX7SNVSState, (obj), TYPE_IMX7_SNVS) | 36 | DEF_HELPER_FLAGS_4(mve_vadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
37 | DEF_HELPER_FLAGS_4(mve_vadd_scalarw, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
38 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/target/arm/mve.decode | ||
41 | +++ b/target/arm/mve.decode | ||
42 | @@ -XXX,XX +XXX,XX @@ VCMPLE_scalar 1111 1110 0 . .. ... 1 ... 1 1111 1 1 1 0 .... @vcmp_scalar | ||
43 | |||
44 | # 2-operand FP | ||
45 | VADD_fp 1110 1111 0 . 0 . ... 0 ... 0 1101 . 1 . 0 ... 0 @2op_fp | ||
46 | +VSUB_fp 1110 1111 0 . 1 . ... 0 ... 0 1101 . 1 . 0 ... 0 @2op_fp | ||
47 | +VMUL_fp 1111 1111 0 . 0 . ... 0 ... 0 1101 . 1 . 1 ... 0 @2op_fp | ||
48 | +VABD_fp 1111 1111 0 . 1 . ... 0 ... 0 1101 . 1 . 0 ... 0 @2op_fp | ||
69 | + | 49 | + |
70 | +typedef struct IMX7SNVSState { | 50 | +VMAXNM 1111 1111 0 . 0 . ... 0 ... 0 1111 . 1 . 1 ... 0 @2op_fp |
71 | + /* <private> */ | 51 | +VMINNM 1111 1111 0 . 1 . ... 0 ... 0 1111 . 1 . 1 ... 0 @2op_fp |
72 | + SysBusDevice parent_obj; | 52 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c |
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/target/arm/mve_helper.c | ||
55 | +++ b/target/arm/mve_helper.c | ||
56 | @@ -XXX,XX +XXX,XX @@ DO_VMAXMINA(vminaw, 4, int32_t, uint32_t, DO_MIN) | ||
57 | DO_2OP_FP(OP##s, 4, float32, float32_##FN) | ||
58 | |||
59 | DO_2OP_FP_ALL(vfadd, add) | ||
60 | +DO_2OP_FP_ALL(vfsub, sub) | ||
61 | +DO_2OP_FP_ALL(vfmul, mul) | ||
73 | + | 62 | + |
74 | + MemoryRegion mmio; | 63 | +static inline float16 float16_abd(float16 a, float16 b, float_status *s) |
75 | +} IMX7SNVSState; | ||
76 | + | ||
77 | +#endif /* IMX7_SNVS_H */ | ||
78 | diff --git a/hw/misc/imx7_snvs.c b/hw/misc/imx7_snvs.c | ||
79 | new file mode 100644 | ||
80 | index XXXXXXX..XXXXXXX | ||
81 | --- /dev/null | ||
82 | +++ b/hw/misc/imx7_snvs.c | ||
83 | @@ -XXX,XX +XXX,XX @@ | ||
84 | +/* | ||
85 | + * IMX7 Secure Non-Volatile Storage | ||
86 | + * | ||
87 | + * Copyright (c) 2018, Impinj, Inc. | ||
88 | + * | ||
89 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
90 | + * | ||
91 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
92 | + * See the COPYING file in the top-level directory. | ||
93 | + * | ||
94 | + * Bare minimum emulation code needed to support being able to shut | ||
95 | + * down linux guest gracefully. | ||
96 | + */ | ||
97 | + | ||
98 | +#include "qemu/osdep.h" | ||
99 | +#include "hw/misc/imx7_snvs.h" | ||
100 | +#include "qemu/log.h" | ||
101 | +#include "sysemu/sysemu.h" | ||
102 | + | ||
103 | +static uint64_t imx7_snvs_read(void *opaque, hwaddr offset, unsigned size) | ||
104 | +{ | 64 | +{ |
105 | + return 0; | 65 | + return float16_abs(float16_sub(a, b, s)); |
106 | +} | 66 | +} |
107 | + | 67 | + |
108 | +static void imx7_snvs_write(void *opaque, hwaddr offset, | 68 | +static inline float32 float32_abd(float32 a, float32 b, float_status *s) |
109 | + uint64_t v, unsigned size) | ||
110 | +{ | 69 | +{ |
111 | + const uint32_t value = v; | 70 | + return float32_abs(float32_sub(a, b, s)); |
112 | + const uint32_t mask = SNVS_LPCR_TOP | SNVS_LPCR_DP_EN; | ||
113 | + | ||
114 | + if (offset == SNVS_LPCR && ((value & mask) == mask)) { | ||
115 | + qemu_system_shutdown_request(SHUTDOWN_CAUSE_GUEST_SHUTDOWN); | ||
116 | + } | ||
117 | +} | 71 | +} |
118 | + | 72 | + |
119 | +static const struct MemoryRegionOps imx7_snvs_ops = { | 73 | +DO_2OP_FP_ALL(vfabd, abd) |
120 | + .read = imx7_snvs_read, | 74 | +DO_2OP_FP_ALL(vmaxnm, maxnum) |
121 | + .write = imx7_snvs_write, | 75 | +DO_2OP_FP_ALL(vminnm, minnum) |
122 | + .endianness = DEVICE_NATIVE_ENDIAN, | 76 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
123 | + .impl = { | 77 | index XXXXXXX..XXXXXXX 100644 |
124 | + /* | 78 | --- a/target/arm/translate-mve.c |
125 | + * Our device would not work correctly if the guest was doing | 79 | +++ b/target/arm/translate-mve.c |
126 | + * unaligned access. This might not be a limitation on the real | 80 | @@ -XXX,XX +XXX,XX @@ static bool trans_VSBCI(DisasContext *s, arg_2op *a) |
127 | + * device but in practice there is no reason for a guest to access | 81 | } |
128 | + * this device unaligned. | 82 | |
129 | + */ | 83 | DO_2OP_FP(VADD_fp, vfadd) |
130 | + .min_access_size = 4, | 84 | +DO_2OP_FP(VSUB_fp, vfsub) |
131 | + .max_access_size = 4, | 85 | +DO_2OP_FP(VMUL_fp, vfmul) |
132 | + .unaligned = false, | 86 | +DO_2OP_FP(VABD_fp, vfabd) |
133 | + }, | 87 | +DO_2OP_FP(VMAXNM, vmaxnm) |
134 | +}; | 88 | +DO_2OP_FP(VMINNM, vminnm) |
135 | + | 89 | |
136 | +static void imx7_snvs_init(Object *obj) | 90 | static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, |
137 | +{ | 91 | MVEGenTwoOpScalarFn fn) |
138 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
139 | + IMX7SNVSState *s = IMX7_SNVS(obj); | ||
140 | + | ||
141 | + memory_region_init_io(&s->mmio, obj, &imx7_snvs_ops, s, | ||
142 | + TYPE_IMX7_SNVS, 0x1000); | ||
143 | + | ||
144 | + sysbus_init_mmio(sd, &s->mmio); | ||
145 | +} | ||
146 | + | ||
147 | +static void imx7_snvs_class_init(ObjectClass *klass, void *data) | ||
148 | +{ | ||
149 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
150 | + | ||
151 | + dc->desc = "i.MX7 Secure Non-Volatile Storage Module"; | ||
152 | +} | ||
153 | + | ||
154 | +static const TypeInfo imx7_snvs_info = { | ||
155 | + .name = TYPE_IMX7_SNVS, | ||
156 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
157 | + .instance_size = sizeof(IMX7SNVSState), | ||
158 | + .instance_init = imx7_snvs_init, | ||
159 | + .class_init = imx7_snvs_class_init, | ||
160 | +}; | ||
161 | + | ||
162 | +static void imx7_snvs_register_type(void) | ||
163 | +{ | ||
164 | + type_register_static(&imx7_snvs_info); | ||
165 | +} | ||
166 | +type_init(imx7_snvs_register_type) | ||
167 | -- | 92 | -- |
168 | 2.16.1 | 93 | 2.20.1 |
169 | 94 | ||
170 | 95 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Implement the MVE VCADD insn. Note that here the size bit is the | ||
2 | opposite sense to the other 2-operand fp insns. | ||
1 | 3 | ||
4 | We don't check for the sz == 1 && Qd == Qm UNPREDICTABLE case, | ||
5 | because that would mean we can't use the DO_2OP_FP macro in | ||
6 | translate-mve.c. | ||
7 | |||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | target/arm/helper-mve.h | 6 ++++++ | ||
12 | target/arm/mve.decode | 8 ++++++++ | ||
13 | target/arm/mve_helper.c | 40 ++++++++++++++++++++++++++++++++++++++ | ||
14 | target/arm/translate-mve.c | 4 +++- | ||
15 | 4 files changed, 57 insertions(+), 1 deletion(-) | ||
16 | |||
17 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/arm/helper-mve.h | ||
20 | +++ b/target/arm/helper-mve.h | ||
21 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vmaxnms, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
22 | DEF_HELPER_FLAGS_4(mve_vminnmh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
23 | DEF_HELPER_FLAGS_4(mve_vminnms, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
24 | |||
25 | +DEF_HELPER_FLAGS_4(mve_vfcadd90h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
26 | +DEF_HELPER_FLAGS_4(mve_vfcadd90s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
27 | + | ||
28 | +DEF_HELPER_FLAGS_4(mve_vfcadd270h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
29 | +DEF_HELPER_FLAGS_4(mve_vfcadd270s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
30 | + | ||
31 | DEF_HELPER_FLAGS_4(mve_vadd_scalarb, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
32 | DEF_HELPER_FLAGS_4(mve_vadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
33 | DEF_HELPER_FLAGS_4(mve_vadd_scalarw, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
34 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/target/arm/mve.decode | ||
37 | +++ b/target/arm/mve.decode | ||
38 | @@ -XXX,XX +XXX,XX @@ | ||
39 | # 2 operand fp insns have size in bit 20: 1 for 16 bit, 0 for 32 bit, | ||
40 | # like Neon FP insns. | ||
41 | %2op_fp_size 20:1 !function=neon_3same_fp_size | ||
42 | +# VCADD is an exception, where bit 20 is 0 for 16 bit and 1 for 32 bit | ||
43 | +%2op_fp_size_rev 20:1 !function=plus_1 | ||
44 | |||
45 | # 1imm format immediate | ||
46 | %imm_28_16_0 28:1 16:3 0:4 | ||
47 | @@ -XXX,XX +XXX,XX @@ | ||
48 | @2op_fp .... .... .... .... .... .... .... .... &2op \ | ||
49 | qd=%qd qn=%qn qm=%qm size=%2op_fp_size | ||
50 | |||
51 | +@2op_fp_size_rev .... .... .... .... .... .... .... .... &2op \ | ||
52 | + qd=%qd qn=%qn qm=%qm size=%2op_fp_size_rev | ||
53 | + | ||
54 | # Vector loads and stores | ||
55 | |||
56 | # Widening loads and narrowing stores: | ||
57 | @@ -XXX,XX +XXX,XX @@ VABD_fp 1111 1111 0 . 1 . ... 0 ... 0 1101 . 1 . 0 ... 0 @2op_fp | ||
58 | |||
59 | VMAXNM 1111 1111 0 . 0 . ... 0 ... 0 1111 . 1 . 1 ... 0 @2op_fp | ||
60 | VMINNM 1111 1111 0 . 1 . ... 0 ... 0 1111 . 1 . 1 ... 0 @2op_fp | ||
61 | + | ||
62 | +VCADD90_fp 1111 1100 1 . 0 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
63 | +VCADD270_fp 1111 1101 1 . 0 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
64 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/target/arm/mve_helper.c | ||
67 | +++ b/target/arm/mve_helper.c | ||
68 | @@ -XXX,XX +XXX,XX @@ static inline float32 float32_abd(float32 a, float32 b, float_status *s) | ||
69 | DO_2OP_FP_ALL(vfabd, abd) | ||
70 | DO_2OP_FP_ALL(vmaxnm, maxnum) | ||
71 | DO_2OP_FP_ALL(vminnm, minnum) | ||
72 | + | ||
73 | +#define DO_VCADD_FP(OP, ESIZE, TYPE, FN0, FN1) \ | ||
74 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ | ||
75 | + void *vd, void *vn, void *vm) \ | ||
76 | + { \ | ||
77 | + TYPE *d = vd, *n = vn, *m = vm; \ | ||
78 | + TYPE r[16 / ESIZE]; \ | ||
79 | + uint16_t tm, mask = mve_element_mask(env); \ | ||
80 | + unsigned e; \ | ||
81 | + float_status *fpst; \ | ||
82 | + float_status scratch_fpst; \ | ||
83 | + /* Calculate all results first to avoid overwriting inputs */ \ | ||
84 | + for (e = 0, tm = mask; e < 16 / ESIZE; e++, tm >>= ESIZE) { \ | ||
85 | + if ((tm & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ | ||
86 | + r[e] = 0; \ | ||
87 | + continue; \ | ||
88 | + } \ | ||
89 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | ||
90 | + &env->vfp.standard_fp_status; \ | ||
91 | + if (!(tm & 1)) { \ | ||
92 | + /* We need the result but without updating flags */ \ | ||
93 | + scratch_fpst = *fpst; \ | ||
94 | + fpst = &scratch_fpst; \ | ||
95 | + } \ | ||
96 | + if (!(e & 1)) { \ | ||
97 | + r[e] = FN0(n[H##ESIZE(e)], m[H##ESIZE(e + 1)], fpst); \ | ||
98 | + } else { \ | ||
99 | + r[e] = FN1(n[H##ESIZE(e)], m[H##ESIZE(e - 1)], fpst); \ | ||
100 | + } \ | ||
101 | + } \ | ||
102 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ | ||
103 | + mergemask(&d[H##ESIZE(e)], r[e], mask); \ | ||
104 | + } \ | ||
105 | + mve_advance_vpt(env); \ | ||
106 | + } | ||
107 | + | ||
108 | +DO_VCADD_FP(vfcadd90h, 2, float16, float16_sub, float16_add) | ||
109 | +DO_VCADD_FP(vfcadd90s, 4, float32, float32_sub, float32_add) | ||
110 | +DO_VCADD_FP(vfcadd270h, 2, float16, float16_add, float16_sub) | ||
111 | +DO_VCADD_FP(vfcadd270s, 4, float32, float32_add, float32_sub) | ||
112 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
113 | index XXXXXXX..XXXXXXX 100644 | ||
114 | --- a/target/arm/translate-mve.c | ||
115 | +++ b/target/arm/translate-mve.c | ||
116 | @@ -XXX,XX +XXX,XX @@ DO_2OP_FP(VMUL_fp, vfmul) | ||
117 | DO_2OP_FP(VABD_fp, vfabd) | ||
118 | DO_2OP_FP(VMAXNM, vmaxnm) | ||
119 | DO_2OP_FP(VMINNM, vminnm) | ||
120 | +DO_2OP_FP(VCADD90_fp, vfcadd90) | ||
121 | +DO_2OP_FP(VCADD270_fp, vfcadd270) | ||
122 | |||
123 | static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, | ||
124 | MVEGenTwoOpScalarFn fn) | ||
125 | @@ -XXX,XX +XXX,XX @@ static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, | ||
126 | return true; | ||
127 | } | ||
128 | |||
129 | -#define DO_2OP_SCALAR(INSN, FN) \ | ||
130 | +#define DO_2OP_SCALAR(INSN, FN) \ | ||
131 | static bool trans_##INSN(DisasContext *s, arg_2scalar *a) \ | ||
132 | { \ | ||
133 | static MVEGenTwoOpScalarFn * const fns[] = { \ | ||
134 | -- | ||
135 | 2.20.1 | ||
136 | |||
137 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | Implement the MVE VFMA and VFMS insns. |
---|---|---|---|
2 | 2 | ||
3 | Add code to emulate Chipidea USB IP (used in i.MX SoCs). Tested to | 3 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
4 | work against: | ||
5 | |||
6 | -usb -drive if=none,id=stick,file=usb.img,format=raw -device \ | ||
7 | usb-storage,bus=usb-bus.0,drive=stick | ||
8 | |||
9 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Cc: Jason Wang <jasowang@redhat.com> | ||
11 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
12 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
13 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
14 | Cc: qemu-devel@nongnu.org | ||
15 | Cc: qemu-arm@nongnu.org | ||
16 | Cc: yurovsky@gmail.com | ||
17 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 5 | --- |
21 | hw/usb/Makefile.objs | 1 + | 6 | target/arm/helper-mve.h | 6 ++++++ |
22 | include/hw/usb/chipidea.h | 16 +++++ | 7 | target/arm/mve.decode | 3 +++ |
23 | hw/usb/chipidea.c | 176 ++++++++++++++++++++++++++++++++++++++++++++++ | 8 | target/arm/mve_helper.c | 37 +++++++++++++++++++++++++++++++++++++ |
24 | 3 files changed, 193 insertions(+) | 9 | target/arm/translate-mve.c | 2 ++ |
25 | create mode 100644 include/hw/usb/chipidea.h | 10 | 4 files changed, 48 insertions(+) |
26 | create mode 100644 hw/usb/chipidea.c | ||
27 | 11 | ||
28 | diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs | 12 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
29 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/usb/Makefile.objs | 14 | --- a/target/arm/helper-mve.h |
31 | +++ b/hw/usb/Makefile.objs | 15 | +++ b/target/arm/helper-mve.h |
32 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_USB_XHCI_NEC) += hcd-xhci-nec.o | 16 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vfcadd90s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
33 | common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o | 17 | DEF_HELPER_FLAGS_4(mve_vfcadd270h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
34 | 18 | DEF_HELPER_FLAGS_4(mve_vfcadd270s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | |
35 | obj-$(CONFIG_TUSB6010) += tusb6010.o | 19 | |
36 | +obj-$(CONFIG_IMX) += chipidea.o | 20 | +DEF_HELPER_FLAGS_4(mve_vfmah, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
37 | 21 | +DEF_HELPER_FLAGS_4(mve_vfmas, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | |
38 | # emulated usb devices | ||
39 | common-obj-$(CONFIG_USB) += dev-hub.o | ||
40 | diff --git a/include/hw/usb/chipidea.h b/include/hw/usb/chipidea.h | ||
41 | new file mode 100644 | ||
42 | index XXXXXXX..XXXXXXX | ||
43 | --- /dev/null | ||
44 | +++ b/include/hw/usb/chipidea.h | ||
45 | @@ -XXX,XX +XXX,XX @@ | ||
46 | +#ifndef CHIPIDEA_H | ||
47 | +#define CHIPIDEA_H | ||
48 | + | 22 | + |
49 | +#include "hw/usb/hcd-ehci.h" | 23 | +DEF_HELPER_FLAGS_4(mve_vfmsh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
24 | +DEF_HELPER_FLAGS_4(mve_vfmss, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
50 | + | 25 | + |
51 | +typedef struct ChipideaState { | 26 | DEF_HELPER_FLAGS_4(mve_vadd_scalarb, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
52 | + /*< private >*/ | 27 | DEF_HELPER_FLAGS_4(mve_vadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
53 | + EHCISysBusState parent_obj; | 28 | DEF_HELPER_FLAGS_4(mve_vadd_scalarw, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
29 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/arm/mve.decode | ||
32 | +++ b/target/arm/mve.decode | ||
33 | @@ -XXX,XX +XXX,XX @@ VMINNM 1111 1111 0 . 1 . ... 0 ... 0 1111 . 1 . 1 ... 0 @2op_fp | ||
34 | |||
35 | VCADD90_fp 1111 1100 1 . 0 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
36 | VCADD270_fp 1111 1101 1 . 0 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
54 | + | 37 | + |
55 | + MemoryRegion iomem[3]; | 38 | +VFMA 1110 1111 0 . 0 . ... 0 ... 0 1100 . 1 . 1 ... 0 @2op_fp |
56 | +} ChipideaState; | 39 | +VFMS 1110 1111 0 . 1 . ... 0 ... 0 1100 . 1 . 1 ... 0 @2op_fp |
40 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/target/arm/mve_helper.c | ||
43 | +++ b/target/arm/mve_helper.c | ||
44 | @@ -XXX,XX +XXX,XX @@ DO_VCADD_FP(vfcadd90h, 2, float16, float16_sub, float16_add) | ||
45 | DO_VCADD_FP(vfcadd90s, 4, float32, float32_sub, float32_add) | ||
46 | DO_VCADD_FP(vfcadd270h, 2, float16, float16_add, float16_sub) | ||
47 | DO_VCADD_FP(vfcadd270s, 4, float32, float32_add, float32_sub) | ||
57 | + | 48 | + |
58 | +#define TYPE_CHIPIDEA "usb-chipidea" | 49 | +#define DO_VFMA(OP, ESIZE, TYPE, CHS) \ |
59 | +#define CHIPIDEA(obj) OBJECT_CHECK(ChipideaState, (obj), TYPE_CHIPIDEA) | 50 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ |
60 | + | 51 | + void *vd, void *vn, void *vm) \ |
61 | +#endif /* CHIPIDEA_H */ | 52 | + { \ |
62 | diff --git a/hw/usb/chipidea.c b/hw/usb/chipidea.c | 53 | + TYPE *d = vd, *n = vn, *m = vm; \ |
63 | new file mode 100644 | 54 | + TYPE r; \ |
64 | index XXXXXXX..XXXXXXX | 55 | + uint16_t mask = mve_element_mask(env); \ |
65 | --- /dev/null | 56 | + unsigned e; \ |
66 | +++ b/hw/usb/chipidea.c | 57 | + float_status *fpst; \ |
67 | @@ -XXX,XX +XXX,XX @@ | 58 | + float_status scratch_fpst; \ |
68 | +/* | 59 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ |
69 | + * Copyright (c) 2018, Impinj, Inc. | 60 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ |
70 | + * | 61 | + continue; \ |
71 | + * Chipidea USB block emulation code | 62 | + } \ |
72 | + * | 63 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ |
73 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 64 | + &env->vfp.standard_fp_status; \ |
74 | + * | 65 | + if (!(mask & 1)) { \ |
75 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 66 | + /* We need the result but without updating flags */ \ |
76 | + * See the COPYING file in the top-level directory. | 67 | + scratch_fpst = *fpst; \ |
77 | + */ | 68 | + fpst = &scratch_fpst; \ |
78 | + | 69 | + } \ |
79 | +#include "qemu/osdep.h" | 70 | + r = n[H##ESIZE(e)]; \ |
80 | +#include "hw/usb/hcd-ehci.h" | 71 | + if (CHS) { \ |
81 | +#include "hw/usb/chipidea.h" | 72 | + r = TYPE##_chs(r); \ |
82 | +#include "qemu/log.h" | 73 | + } \ |
83 | + | 74 | + r = TYPE##_muladd(r, m[H##ESIZE(e)], d[H##ESIZE(e)], \ |
84 | +enum { | 75 | + 0, fpst); \ |
85 | + CHIPIDEA_USBx_DCIVERSION = 0x000, | 76 | + mergemask(&d[H##ESIZE(e)], r, mask); \ |
86 | + CHIPIDEA_USBx_DCCPARAMS = 0x004, | 77 | + } \ |
87 | + CHIPIDEA_USBx_DCCPARAMS_HC = BIT(8), | 78 | + mve_advance_vpt(env); \ |
88 | +}; | ||
89 | + | ||
90 | +static uint64_t chipidea_read(void *opaque, hwaddr offset, | ||
91 | + unsigned size) | ||
92 | +{ | ||
93 | + return 0; | ||
94 | +} | ||
95 | + | ||
96 | +static void chipidea_write(void *opaque, hwaddr offset, | ||
97 | + uint64_t value, unsigned size) | ||
98 | +{ | ||
99 | +} | ||
100 | + | ||
101 | +static const struct MemoryRegionOps chipidea_ops = { | ||
102 | + .read = chipidea_read, | ||
103 | + .write = chipidea_write, | ||
104 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
105 | + .impl = { | ||
106 | + /* | ||
107 | + * Our device would not work correctly if the guest was doing | ||
108 | + * unaligned access. This might not be a limitation on the | ||
109 | + * real device but in practice there is no reason for a guest | ||
110 | + * to access this device unaligned. | ||
111 | + */ | ||
112 | + .min_access_size = 4, | ||
113 | + .max_access_size = 4, | ||
114 | + .unaligned = false, | ||
115 | + }, | ||
116 | +}; | ||
117 | + | ||
118 | +static uint64_t chipidea_dc_read(void *opaque, hwaddr offset, | ||
119 | + unsigned size) | ||
120 | +{ | ||
121 | + switch (offset) { | ||
122 | + case CHIPIDEA_USBx_DCIVERSION: | ||
123 | + return 0x1; | ||
124 | + case CHIPIDEA_USBx_DCCPARAMS: | ||
125 | + /* | ||
126 | + * Real hardware (at least i.MX7) will also report the | ||
127 | + * controller as "Device Capable" (and 8 supported endpoints), | ||
128 | + * but there doesn't seem to be much point in doing so, since | ||
129 | + * we don't emulate that part. | ||
130 | + */ | ||
131 | + return CHIPIDEA_USBx_DCCPARAMS_HC; | ||
132 | + } | 79 | + } |
133 | + | 80 | + |
134 | + return 0; | 81 | +DO_VFMA(vfmah, 2, float16, false) |
135 | +} | 82 | +DO_VFMA(vfmas, 4, float32, false) |
136 | + | 83 | +DO_VFMA(vfmsh, 2, float16, true) |
137 | +static void chipidea_dc_write(void *opaque, hwaddr offset, | 84 | +DO_VFMA(vfmss, 4, float32, true) |
138 | + uint64_t value, unsigned size) | 85 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
139 | +{ | 86 | index XXXXXXX..XXXXXXX 100644 |
140 | +} | 87 | --- a/target/arm/translate-mve.c |
141 | + | 88 | +++ b/target/arm/translate-mve.c |
142 | +static const struct MemoryRegionOps chipidea_dc_ops = { | 89 | @@ -XXX,XX +XXX,XX @@ DO_2OP_FP(VMAXNM, vmaxnm) |
143 | + .read = chipidea_dc_read, | 90 | DO_2OP_FP(VMINNM, vminnm) |
144 | + .write = chipidea_dc_write, | 91 | DO_2OP_FP(VCADD90_fp, vfcadd90) |
145 | + .endianness = DEVICE_NATIVE_ENDIAN, | 92 | DO_2OP_FP(VCADD270_fp, vfcadd270) |
146 | + .impl = { | 93 | +DO_2OP_FP(VFMA, vfma) |
147 | + /* | 94 | +DO_2OP_FP(VFMS, vfms) |
148 | + * Our device would not work correctly if the guest was doing | 95 | |
149 | + * unaligned access. This might not be a limitation on the real | 96 | static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, |
150 | + * device but in practice there is no reason for a guest to access | 97 | MVEGenTwoOpScalarFn fn) |
151 | + * this device unaligned. | ||
152 | + */ | ||
153 | + .min_access_size = 4, | ||
154 | + .max_access_size = 4, | ||
155 | + .unaligned = false, | ||
156 | + }, | ||
157 | +}; | ||
158 | + | ||
159 | +static void chipidea_init(Object *obj) | ||
160 | +{ | ||
161 | + EHCIState *ehci = &SYS_BUS_EHCI(obj)->ehci; | ||
162 | + ChipideaState *ci = CHIPIDEA(obj); | ||
163 | + int i; | ||
164 | + | ||
165 | + for (i = 0; i < ARRAY_SIZE(ci->iomem); i++) { | ||
166 | + const struct { | ||
167 | + const char *name; | ||
168 | + hwaddr offset; | ||
169 | + uint64_t size; | ||
170 | + const struct MemoryRegionOps *ops; | ||
171 | + } regions[ARRAY_SIZE(ci->iomem)] = { | ||
172 | + /* | ||
173 | + * Registers located between offsets 0x000 and 0xFC | ||
174 | + */ | ||
175 | + { | ||
176 | + .name = TYPE_CHIPIDEA ".misc", | ||
177 | + .offset = 0x000, | ||
178 | + .size = 0x100, | ||
179 | + .ops = &chipidea_ops, | ||
180 | + }, | ||
181 | + /* | ||
182 | + * Registers located between offsets 0x1A4 and 0x1DC | ||
183 | + */ | ||
184 | + { | ||
185 | + .name = TYPE_CHIPIDEA ".endpoints", | ||
186 | + .offset = 0x1A4, | ||
187 | + .size = 0x1DC - 0x1A4 + 4, | ||
188 | + .ops = &chipidea_ops, | ||
189 | + }, | ||
190 | + /* | ||
191 | + * USB_x_DCIVERSION and USB_x_DCCPARAMS | ||
192 | + */ | ||
193 | + { | ||
194 | + .name = TYPE_CHIPIDEA ".dc", | ||
195 | + .offset = 0x120, | ||
196 | + .size = 8, | ||
197 | + .ops = &chipidea_dc_ops, | ||
198 | + }, | ||
199 | + }; | ||
200 | + | ||
201 | + memory_region_init_io(&ci->iomem[i], | ||
202 | + obj, | ||
203 | + regions[i].ops, | ||
204 | + ci, | ||
205 | + regions[i].name, | ||
206 | + regions[i].size); | ||
207 | + | ||
208 | + memory_region_add_subregion(&ehci->mem, | ||
209 | + regions[i].offset, | ||
210 | + &ci->iomem[i]); | ||
211 | + } | ||
212 | +} | ||
213 | + | ||
214 | +static void chipidea_class_init(ObjectClass *klass, void *data) | ||
215 | +{ | ||
216 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
217 | + SysBusEHCIClass *sec = SYS_BUS_EHCI_CLASS(klass); | ||
218 | + | ||
219 | + /* | ||
220 | + * Offsets used were taken from i.MX7Dual Applications Processor | ||
221 | + * Reference Manual, Rev 0.1, p. 3177, Table 11-59 | ||
222 | + */ | ||
223 | + sec->capsbase = 0x100; | ||
224 | + sec->opregbase = 0x140; | ||
225 | + sec->portnr = 1; | ||
226 | + | ||
227 | + set_bit(DEVICE_CATEGORY_USB, dc->categories); | ||
228 | + dc->desc = "Chipidea USB Module"; | ||
229 | +} | ||
230 | + | ||
231 | +static const TypeInfo chipidea_info = { | ||
232 | + .name = TYPE_CHIPIDEA, | ||
233 | + .parent = TYPE_SYS_BUS_EHCI, | ||
234 | + .instance_size = sizeof(ChipideaState), | ||
235 | + .instance_init = chipidea_init, | ||
236 | + .class_init = chipidea_class_init, | ||
237 | +}; | ||
238 | + | ||
239 | +static void chipidea_register_type(void) | ||
240 | +{ | ||
241 | + type_register_static(&chipidea_info); | ||
242 | +} | ||
243 | +type_init(chipidea_register_type) | ||
244 | -- | 98 | -- |
245 | 2.16.1 | 99 | 2.20.1 |
246 | 100 | ||
247 | 101 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Implement the MVE VCMUL and VCMLA insns. | |
2 | |||
3 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | --- | ||
6 | target/arm/helper-mve.h | 18 ++++++++ | ||
7 | target/arm/mve.decode | 35 ++++++++++++---- | ||
8 | target/arm/mve_helper.c | 86 ++++++++++++++++++++++++++++++++++++++ | ||
9 | target/arm/translate-mve.c | 8 ++++ | ||
10 | 4 files changed, 139 insertions(+), 8 deletions(-) | ||
11 | |||
12 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/arm/helper-mve.h | ||
15 | +++ b/target/arm/helper-mve.h | ||
16 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vfmas, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
17 | DEF_HELPER_FLAGS_4(mve_vfmsh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
18 | DEF_HELPER_FLAGS_4(mve_vfmss, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
19 | |||
20 | +DEF_HELPER_FLAGS_4(mve_vcmul0h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
21 | +DEF_HELPER_FLAGS_4(mve_vcmul0s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
22 | +DEF_HELPER_FLAGS_4(mve_vcmul90h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
23 | +DEF_HELPER_FLAGS_4(mve_vcmul90s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
24 | +DEF_HELPER_FLAGS_4(mve_vcmul180h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
25 | +DEF_HELPER_FLAGS_4(mve_vcmul180s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
26 | +DEF_HELPER_FLAGS_4(mve_vcmul270h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
27 | +DEF_HELPER_FLAGS_4(mve_vcmul270s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
28 | + | ||
29 | +DEF_HELPER_FLAGS_4(mve_vcmla0h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
30 | +DEF_HELPER_FLAGS_4(mve_vcmla0s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
31 | +DEF_HELPER_FLAGS_4(mve_vcmla90h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
32 | +DEF_HELPER_FLAGS_4(mve_vcmla90s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
33 | +DEF_HELPER_FLAGS_4(mve_vcmla180h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
34 | +DEF_HELPER_FLAGS_4(mve_vcmla180s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
35 | +DEF_HELPER_FLAGS_4(mve_vcmla270h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
36 | +DEF_HELPER_FLAGS_4(mve_vcmla270s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
37 | + | ||
38 | DEF_HELPER_FLAGS_4(mve_vadd_scalarb, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
39 | DEF_HELPER_FLAGS_4(mve_vadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
40 | DEF_HELPER_FLAGS_4(mve_vadd_scalarw, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
41 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/target/arm/mve.decode | ||
44 | +++ b/target/arm/mve.decode | ||
45 | @@ -XXX,XX +XXX,XX @@ VQSHL_U 111 1 1111 0 . .. ... 0 ... 0 0100 . 1 . 1 ... 0 @2op_rev | ||
46 | VQRSHL_S 111 0 1111 0 . .. ... 0 ... 0 0101 . 1 . 1 ... 0 @2op_rev | ||
47 | VQRSHL_U 111 1 1111 0 . .. ... 0 ... 0 0101 . 1 . 1 ... 0 @2op_rev | ||
48 | |||
49 | -VQDMLADH 1110 1110 0 . .. ... 0 ... 0 1110 . 0 . 0 ... 0 @2op | ||
50 | -VQDMLADHX 1110 1110 0 . .. ... 0 ... 1 1110 . 0 . 0 ... 0 @2op | ||
51 | -VQRDMLADH 1110 1110 0 . .. ... 0 ... 0 1110 . 0 . 0 ... 1 @2op | ||
52 | -VQRDMLADHX 1110 1110 0 . .. ... 0 ... 1 1110 . 0 . 0 ... 1 @2op | ||
53 | +{ | ||
54 | + VCMUL0 111 . 1110 0 . 11 ... 0 ... 0 1110 . 0 . 0 ... 0 @2op_sz28 | ||
55 | + VQDMLADH 1110 1110 0 . .. ... 0 ... 0 1110 . 0 . 0 ... 0 @2op | ||
56 | + VQDMLSDH 1111 1110 0 . .. ... 0 ... 0 1110 . 0 . 0 ... 0 @2op | ||
57 | +} | ||
58 | |||
59 | -VQDMLSDH 1111 1110 0 . .. ... 0 ... 0 1110 . 0 . 0 ... 0 @2op | ||
60 | -VQDMLSDHX 1111 1110 0 . .. ... 0 ... 1 1110 . 0 . 0 ... 0 @2op | ||
61 | -VQRDMLSDH 1111 1110 0 . .. ... 0 ... 0 1110 . 0 . 0 ... 1 @2op | ||
62 | -VQRDMLSDHX 1111 1110 0 . .. ... 0 ... 1 1110 . 0 . 0 ... 1 @2op | ||
63 | +{ | ||
64 | + VCMUL180 111 . 1110 0 . 11 ... 0 ... 1 1110 . 0 . 0 ... 0 @2op_sz28 | ||
65 | + VQDMLADHX 111 0 1110 0 . .. ... 0 ... 1 1110 . 0 . 0 ... 0 @2op | ||
66 | + VQDMLSDHX 111 1 1110 0 . .. ... 0 ... 1 1110 . 0 . 0 ... 0 @2op | ||
67 | +} | ||
68 | + | ||
69 | +{ | ||
70 | + VCMUL90 111 . 1110 0 . 11 ... 0 ... 0 1110 . 0 . 0 ... 1 @2op_sz28 | ||
71 | + VQRDMLADH 111 0 1110 0 . .. ... 0 ... 0 1110 . 0 . 0 ... 1 @2op | ||
72 | + VQRDMLSDH 111 1 1110 0 . .. ... 0 ... 0 1110 . 0 . 0 ... 1 @2op | ||
73 | +} | ||
74 | + | ||
75 | +{ | ||
76 | + VCMUL270 111 . 1110 0 . 11 ... 0 ... 1 1110 . 0 . 0 ... 1 @2op_sz28 | ||
77 | + VQRDMLADHX 111 0 1110 0 . .. ... 0 ... 1 1110 . 0 . 0 ... 1 @2op | ||
78 | + VQRDMLSDHX 111 1 1110 0 . .. ... 0 ... 1 1110 . 0 . 0 ... 1 @2op | ||
79 | +} | ||
80 | |||
81 | VQDMULLB 111 . 1110 0 . 11 ... 0 ... 0 1111 . 0 . 0 ... 1 @2op_sz28 | ||
82 | VQDMULLT 111 . 1110 0 . 11 ... 0 ... 1 1111 . 0 . 0 ... 1 @2op_sz28 | ||
83 | @@ -XXX,XX +XXX,XX @@ VCADD270_fp 1111 1101 1 . 0 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_ | ||
84 | |||
85 | VFMA 1110 1111 0 . 0 . ... 0 ... 0 1100 . 1 . 1 ... 0 @2op_fp | ||
86 | VFMS 1110 1111 0 . 1 . ... 0 ... 0 1100 . 1 . 1 ... 0 @2op_fp | ||
87 | + | ||
88 | +VCMLA0 1111 110 00 . 1 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
89 | +VCMLA90 1111 110 01 . 1 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
90 | +VCMLA180 1111 110 10 . 1 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
91 | +VCMLA270 1111 110 11 . 1 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
92 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/target/arm/mve_helper.c | ||
95 | +++ b/target/arm/mve_helper.c | ||
96 | @@ -XXX,XX +XXX,XX @@ DO_VFMA(vfmah, 2, float16, false) | ||
97 | DO_VFMA(vfmas, 4, float32, false) | ||
98 | DO_VFMA(vfmsh, 2, float16, true) | ||
99 | DO_VFMA(vfmss, 4, float32, true) | ||
100 | + | ||
101 | +#define DO_VCMLA(OP, ESIZE, TYPE, ROT, FN) \ | ||
102 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ | ||
103 | + void *vd, void *vn, void *vm) \ | ||
104 | + { \ | ||
105 | + TYPE *d = vd, *n = vn, *m = vm; \ | ||
106 | + TYPE r0, r1, e1, e2, e3, e4; \ | ||
107 | + uint16_t mask = mve_element_mask(env); \ | ||
108 | + unsigned e; \ | ||
109 | + float_status *fpst0, *fpst1; \ | ||
110 | + float_status scratch_fpst; \ | ||
111 | + /* We loop through pairs of elements at a time */ \ | ||
112 | + for (e = 0; e < 16 / ESIZE; e += 2, mask >>= ESIZE * 2) { \ | ||
113 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE * 2)) == 0) { \ | ||
114 | + continue; \ | ||
115 | + } \ | ||
116 | + fpst0 = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | ||
117 | + &env->vfp.standard_fp_status; \ | ||
118 | + fpst1 = fpst0; \ | ||
119 | + if (!(mask & 1)) { \ | ||
120 | + scratch_fpst = *fpst0; \ | ||
121 | + fpst0 = &scratch_fpst; \ | ||
122 | + } \ | ||
123 | + if (!(mask & (1 << ESIZE))) { \ | ||
124 | + scratch_fpst = *fpst1; \ | ||
125 | + fpst1 = &scratch_fpst; \ | ||
126 | + } \ | ||
127 | + switch (ROT) { \ | ||
128 | + case 0: \ | ||
129 | + e1 = m[H##ESIZE(e)]; \ | ||
130 | + e2 = n[H##ESIZE(e)]; \ | ||
131 | + e3 = m[H##ESIZE(e + 1)]; \ | ||
132 | + e4 = n[H##ESIZE(e)]; \ | ||
133 | + break; \ | ||
134 | + case 1: \ | ||
135 | + e1 = TYPE##_chs(m[H##ESIZE(e + 1)]); \ | ||
136 | + e2 = n[H##ESIZE(e + 1)]; \ | ||
137 | + e3 = m[H##ESIZE(e)]; \ | ||
138 | + e4 = n[H##ESIZE(e + 1)]; \ | ||
139 | + break; \ | ||
140 | + case 2: \ | ||
141 | + e1 = TYPE##_chs(m[H##ESIZE(e)]); \ | ||
142 | + e2 = n[H##ESIZE(e)]; \ | ||
143 | + e3 = TYPE##_chs(m[H##ESIZE(e + 1)]); \ | ||
144 | + e4 = n[H##ESIZE(e)]; \ | ||
145 | + break; \ | ||
146 | + case 3: \ | ||
147 | + e1 = m[H##ESIZE(e + 1)]; \ | ||
148 | + e2 = n[H##ESIZE(e + 1)]; \ | ||
149 | + e3 = TYPE##_chs(m[H##ESIZE(e)]); \ | ||
150 | + e4 = n[H##ESIZE(e + 1)]; \ | ||
151 | + break; \ | ||
152 | + default: \ | ||
153 | + g_assert_not_reached(); \ | ||
154 | + } \ | ||
155 | + r0 = FN(e2, e1, d[H##ESIZE(e)], fpst0); \ | ||
156 | + r1 = FN(e4, e3, d[H##ESIZE(e + 1)], fpst1); \ | ||
157 | + mergemask(&d[H##ESIZE(e)], r0, mask); \ | ||
158 | + mergemask(&d[H##ESIZE(e + 1)], r1, mask >> ESIZE); \ | ||
159 | + } \ | ||
160 | + mve_advance_vpt(env); \ | ||
161 | + } | ||
162 | + | ||
163 | +#define DO_VCMULH(N, M, D, S) float16_mul(N, M, S) | ||
164 | +#define DO_VCMULS(N, M, D, S) float32_mul(N, M, S) | ||
165 | + | ||
166 | +#define DO_VCMLAH(N, M, D, S) float16_muladd(N, M, D, 0, S) | ||
167 | +#define DO_VCMLAS(N, M, D, S) float32_muladd(N, M, D, 0, S) | ||
168 | + | ||
169 | +DO_VCMLA(vcmul0h, 2, float16, 0, DO_VCMULH) | ||
170 | +DO_VCMLA(vcmul0s, 4, float32, 0, DO_VCMULS) | ||
171 | +DO_VCMLA(vcmul90h, 2, float16, 1, DO_VCMULH) | ||
172 | +DO_VCMLA(vcmul90s, 4, float32, 1, DO_VCMULS) | ||
173 | +DO_VCMLA(vcmul180h, 2, float16, 2, DO_VCMULH) | ||
174 | +DO_VCMLA(vcmul180s, 4, float32, 2, DO_VCMULS) | ||
175 | +DO_VCMLA(vcmul270h, 2, float16, 3, DO_VCMULH) | ||
176 | +DO_VCMLA(vcmul270s, 4, float32, 3, DO_VCMULS) | ||
177 | + | ||
178 | +DO_VCMLA(vcmla0h, 2, float16, 0, DO_VCMLAH) | ||
179 | +DO_VCMLA(vcmla0s, 4, float32, 0, DO_VCMLAS) | ||
180 | +DO_VCMLA(vcmla90h, 2, float16, 1, DO_VCMLAH) | ||
181 | +DO_VCMLA(vcmla90s, 4, float32, 1, DO_VCMLAS) | ||
182 | +DO_VCMLA(vcmla180h, 2, float16, 2, DO_VCMLAH) | ||
183 | +DO_VCMLA(vcmla180s, 4, float32, 2, DO_VCMLAS) | ||
184 | +DO_VCMLA(vcmla270h, 2, float16, 3, DO_VCMLAH) | ||
185 | +DO_VCMLA(vcmla270s, 4, float32, 3, DO_VCMLAS) | ||
186 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
187 | index XXXXXXX..XXXXXXX 100644 | ||
188 | --- a/target/arm/translate-mve.c | ||
189 | +++ b/target/arm/translate-mve.c | ||
190 | @@ -XXX,XX +XXX,XX @@ DO_2OP_FP(VCADD90_fp, vfcadd90) | ||
191 | DO_2OP_FP(VCADD270_fp, vfcadd270) | ||
192 | DO_2OP_FP(VFMA, vfma) | ||
193 | DO_2OP_FP(VFMS, vfms) | ||
194 | +DO_2OP_FP(VCMUL0, vcmul0) | ||
195 | +DO_2OP_FP(VCMUL90, vcmul90) | ||
196 | +DO_2OP_FP(VCMUL180, vcmul180) | ||
197 | +DO_2OP_FP(VCMUL270, vcmul270) | ||
198 | +DO_2OP_FP(VCMLA0, vcmla0) | ||
199 | +DO_2OP_FP(VCMLA90, vcmla90) | ||
200 | +DO_2OP_FP(VCMLA180, vcmla180) | ||
201 | +DO_2OP_FP(VCMLA270, vcmla270) | ||
202 | |||
203 | static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, | ||
204 | MVEGenTwoOpScalarFn fn) | ||
205 | -- | ||
206 | 2.20.1 | ||
207 | |||
208 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | Implement the MVE VMAXNMA and VMINNMA insns; these are 2-operand, but |
---|---|---|---|
2 | the destination register must be the same as one of the source | ||
3 | registers. | ||
2 | 4 | ||
3 | Add enough code to emulate i.MX2 watchdog IP block so it would be | 5 | We defer the decode of the size in bit 28 to the individual insn |
4 | possible to reboot the machine running Linux Guest. | 6 | patterns rather than doing it in the format, because otherwise we |
7 | would have a single insn pattern that overlapped with two groups (eg | ||
8 | VMAXNMA with the VMULH_S and VMULH_U groups). Having two insn | ||
9 | patterns per insn seems clearer than a complex multilevel nesting | ||
10 | of overlapping and non-overlapping groups. | ||
5 | 11 | ||
6 | Cc: Peter Maydell <peter.maydell@linaro.org> | 12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Cc: Jason Wang <jasowang@redhat.com> | ||
8 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
10 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Cc: qemu-devel@nongnu.org | ||
12 | Cc: qemu-arm@nongnu.org | ||
13 | Cc: yurovsky@gmail.com | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
16 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | --- | 14 | --- |
19 | hw/misc/Makefile.objs | 1 + | 15 | target/arm/helper-mve.h | 6 ++++++ |
20 | include/hw/misc/imx2_wdt.h | 33 +++++++++++++++++ | 16 | target/arm/mve.decode | 11 +++++++++++ |
21 | hw/misc/imx2_wdt.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++ | 17 | target/arm/mve_helper.c | 23 +++++++++++++++++++++++ |
22 | 3 files changed, 123 insertions(+) | 18 | target/arm/translate-mve.c | 2 ++ |
23 | create mode 100644 include/hw/misc/imx2_wdt.h | 19 | 4 files changed, 42 insertions(+) |
24 | create mode 100644 hw/misc/imx2_wdt.c | ||
25 | 20 | ||
26 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 21 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
27 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/hw/misc/Makefile.objs | 23 | --- a/target/arm/helper-mve.h |
29 | +++ b/hw/misc/Makefile.objs | 24 | +++ b/target/arm/helper-mve.h |
30 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx25_ccm.o | 25 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vmaxnms, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
31 | obj-$(CONFIG_IMX) += imx6_ccm.o | 26 | DEF_HELPER_FLAGS_4(mve_vminnmh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
32 | obj-$(CONFIG_IMX) += imx6_src.o | 27 | DEF_HELPER_FLAGS_4(mve_vminnms, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
33 | obj-$(CONFIG_IMX) += imx7_ccm.o | 28 | |
34 | +obj-$(CONFIG_IMX) += imx2_wdt.o | 29 | +DEF_HELPER_FLAGS_4(mve_vmaxnmah, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
35 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | 30 | +DEF_HELPER_FLAGS_4(mve_vmaxnmas, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
36 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | 31 | + |
37 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | 32 | +DEF_HELPER_FLAGS_4(mve_vminnmah, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
38 | diff --git a/include/hw/misc/imx2_wdt.h b/include/hw/misc/imx2_wdt.h | 33 | +DEF_HELPER_FLAGS_4(mve_vminnmas, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
39 | new file mode 100644 | 34 | + |
40 | index XXXXXXX..XXXXXXX | 35 | DEF_HELPER_FLAGS_4(mve_vfcadd90h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
41 | --- /dev/null | 36 | DEF_HELPER_FLAGS_4(mve_vfcadd90s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
42 | +++ b/include/hw/misc/imx2_wdt.h | 37 | |
38 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
39 | index XXXXXXX..XXXXXXX 100644 | ||
40 | --- a/target/arm/mve.decode | ||
41 | +++ b/target/arm/mve.decode | ||
43 | @@ -XXX,XX +XXX,XX @@ | 42 | @@ -XXX,XX +XXX,XX @@ |
44 | +/* | 43 | @2op_fp_size_rev .... .... .... .... .... .... .... .... &2op \ |
45 | + * Copyright (c) 2017, Impinj, Inc. | 44 | qd=%qd qn=%qn qm=%qm size=%2op_fp_size_rev |
46 | + * | 45 | |
47 | + * i.MX2 Watchdog IP block | 46 | +# 2-operand, but Qd and Qn share a field. Size is in bit 28, but we |
48 | + * | 47 | +# don't decode it in this format |
49 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 48 | +@vmaxnma .... .... .... .... .... .... .... .... &2op \ |
50 | + * | 49 | + qd=%qd qn=%qd qm=%qm |
51 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
52 | + * See the COPYING file in the top-level directory. | ||
53 | + */ | ||
54 | + | 50 | + |
55 | +#ifndef IMX2_WDT_H | 51 | # Vector loads and stores |
56 | +#define IMX2_WDT_H | 52 | |
53 | # Widening loads and narrowing stores: | ||
54 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op | ||
55 | # The VSHLL T2 encoding is not a @2op pattern, but is here because it | ||
56 | # overlaps what would be size=0b11 VMULH/VRMULH | ||
57 | { | ||
58 | + VMAXNMA 111 0 1110 0 . 11 1111 ... 0 1110 1 0 . 0 ... 1 @vmaxnma size=2 | ||
57 | + | 59 | + |
58 | +#include "hw/sysbus.h" | 60 | VSHLL_BS 111 0 1110 0 . 11 .. 01 ... 0 1110 0 0 . 0 ... 1 @2_shll_esize_b |
61 | VSHLL_BS 111 0 1110 0 . 11 .. 01 ... 0 1110 0 0 . 0 ... 1 @2_shll_esize_h | ||
62 | |||
63 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op | ||
64 | } | ||
65 | |||
66 | { | ||
67 | + VMAXNMA 111 1 1110 0 . 11 1111 ... 0 1110 1 0 . 0 ... 1 @vmaxnma size=1 | ||
59 | + | 68 | + |
60 | +#define TYPE_IMX2_WDT "imx2.wdt" | 69 | VSHLL_BU 111 1 1110 0 . 11 .. 01 ... 0 1110 0 0 . 0 ... 1 @2_shll_esize_b |
61 | +#define IMX2_WDT(obj) OBJECT_CHECK(IMX2WdtState, (obj), TYPE_IMX2_WDT) | 70 | VSHLL_BU 111 1 1110 0 . 11 .. 01 ... 0 1110 0 0 . 0 ... 1 @2_shll_esize_h |
62 | + | 71 | |
63 | +enum IMX2WdtRegisters { | 72 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op |
64 | + IMX2_WDT_WCR = 0x0000, | 73 | } |
65 | + IMX2_WDT_REG_NUM = 0x0008 / sizeof(uint16_t) + 1, | 74 | |
66 | +}; | 75 | { |
67 | + | 76 | + VMINNMA 111 0 1110 0 . 11 1111 ... 1 1110 1 0 . 0 ... 1 @vmaxnma size=2 |
68 | + | 77 | VSHLL_TS 111 0 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_b |
69 | +typedef struct IMX2WdtState { | 78 | VSHLL_TS 111 0 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_h |
70 | + /* <private> */ | 79 | |
71 | + SysBusDevice parent_obj; | 80 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op |
72 | + | 81 | } |
73 | + MemoryRegion mmio; | 82 | |
74 | +} IMX2WdtState; | 83 | { |
75 | + | 84 | + VMINNMA 111 1 1110 0 . 11 1111 ... 1 1110 1 0 . 0 ... 1 @vmaxnma size=1 |
76 | +#endif /* IMX7_SNVS_H */ | 85 | VSHLL_TU 111 1 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_b |
77 | diff --git a/hw/misc/imx2_wdt.c b/hw/misc/imx2_wdt.c | 86 | VSHLL_TU 111 1 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_h |
78 | new file mode 100644 | 87 | |
79 | index XXXXXXX..XXXXXXX | 88 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c |
80 | --- /dev/null | 89 | index XXXXXXX..XXXXXXX 100644 |
81 | +++ b/hw/misc/imx2_wdt.c | 90 | --- a/target/arm/mve_helper.c |
82 | @@ -XXX,XX +XXX,XX @@ | 91 | +++ b/target/arm/mve_helper.c |
83 | +/* | 92 | @@ -XXX,XX +XXX,XX @@ DO_2OP_FP_ALL(vfabd, abd) |
84 | + * Copyright (c) 2018, Impinj, Inc. | 93 | DO_2OP_FP_ALL(vmaxnm, maxnum) |
85 | + * | 94 | DO_2OP_FP_ALL(vminnm, minnum) |
86 | + * i.MX2 Watchdog IP block | 95 | |
87 | + * | 96 | +static inline float16 float16_maxnuma(float16 a, float16 b, float_status *s) |
88 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
89 | + * | ||
90 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
91 | + * See the COPYING file in the top-level directory. | ||
92 | + */ | ||
93 | + | ||
94 | +#include "qemu/osdep.h" | ||
95 | +#include "qemu/bitops.h" | ||
96 | +#include "sysemu/watchdog.h" | ||
97 | + | ||
98 | +#include "hw/misc/imx2_wdt.h" | ||
99 | + | ||
100 | +#define IMX2_WDT_WCR_WDA BIT(5) /* -> External Reset WDOG_B */ | ||
101 | +#define IMX2_WDT_WCR_SRS BIT(4) /* -> Software Reset Signal */ | ||
102 | + | ||
103 | +static uint64_t imx2_wdt_read(void *opaque, hwaddr addr, | ||
104 | + unsigned int size) | ||
105 | +{ | 97 | +{ |
106 | + return 0; | 98 | + return float16_maxnum(float16_abs(a), float16_abs(b), s); |
107 | +} | 99 | +} |
108 | + | 100 | + |
109 | +static void imx2_wdt_write(void *opaque, hwaddr addr, | 101 | +static inline float32 float32_maxnuma(float32 a, float32 b, float_status *s) |
110 | + uint64_t value, unsigned int size) | ||
111 | +{ | 102 | +{ |
112 | + if (addr == IMX2_WDT_WCR && | 103 | + return float32_maxnum(float32_abs(a), float32_abs(b), s); |
113 | + (value & (IMX2_WDT_WCR_WDA | IMX2_WDT_WCR_SRS))) { | ||
114 | + watchdog_perform_action(); | ||
115 | + } | ||
116 | +} | 104 | +} |
117 | + | 105 | + |
118 | +static const MemoryRegionOps imx2_wdt_ops = { | 106 | +static inline float16 float16_minnuma(float16 a, float16 b, float_status *s) |
119 | + .read = imx2_wdt_read, | ||
120 | + .write = imx2_wdt_write, | ||
121 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
122 | + .impl = { | ||
123 | + /* | ||
124 | + * Our device would not work correctly if the guest was doing | ||
125 | + * unaligned access. This might not be a limitation on the | ||
126 | + * real device but in practice there is no reason for a guest | ||
127 | + * to access this device unaligned. | ||
128 | + */ | ||
129 | + .min_access_size = 4, | ||
130 | + .max_access_size = 4, | ||
131 | + .unaligned = false, | ||
132 | + }, | ||
133 | +}; | ||
134 | + | ||
135 | +static void imx2_wdt_realize(DeviceState *dev, Error **errp) | ||
136 | +{ | 107 | +{ |
137 | + IMX2WdtState *s = IMX2_WDT(dev); | 108 | + return float16_minnum(float16_abs(a), float16_abs(b), s); |
138 | + | ||
139 | + memory_region_init_io(&s->mmio, OBJECT(dev), | ||
140 | + &imx2_wdt_ops, s, | ||
141 | + TYPE_IMX2_WDT".mmio", | ||
142 | + IMX2_WDT_REG_NUM * sizeof(uint16_t)); | ||
143 | + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mmio); | ||
144 | +} | 109 | +} |
145 | + | 110 | + |
146 | +static void imx2_wdt_class_init(ObjectClass *klass, void *data) | 111 | +static inline float32 float32_minnuma(float32 a, float32 b, float_status *s) |
147 | +{ | 112 | +{ |
148 | + DeviceClass *dc = DEVICE_CLASS(klass); | 113 | + return float32_minnum(float32_abs(a), float32_abs(b), s); |
149 | + | ||
150 | + dc->realize = imx2_wdt_realize; | ||
151 | + set_bit(DEVICE_CATEGORY_MISC, dc->categories); | ||
152 | +} | 114 | +} |
153 | + | 115 | + |
154 | +static const TypeInfo imx2_wdt_info = { | 116 | +DO_2OP_FP_ALL(vmaxnma, maxnuma) |
155 | + .name = TYPE_IMX2_WDT, | 117 | +DO_2OP_FP_ALL(vminnma, minnuma) |
156 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
157 | + .instance_size = sizeof(IMX2WdtState), | ||
158 | + .class_init = imx2_wdt_class_init, | ||
159 | +}; | ||
160 | + | 118 | + |
161 | +static WatchdogTimerModel model = { | 119 | #define DO_VCADD_FP(OP, ESIZE, TYPE, FN0, FN1) \ |
162 | + .wdt_name = "imx2-watchdog", | 120 | void HELPER(glue(mve_, OP))(CPUARMState *env, \ |
163 | + .wdt_description = "i.MX2 Watchdog", | 121 | void *vd, void *vn, void *vm) \ |
164 | +}; | 122 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
165 | + | 123 | index XXXXXXX..XXXXXXX 100644 |
166 | +static void imx2_wdt_register_type(void) | 124 | --- a/target/arm/translate-mve.c |
167 | +{ | 125 | +++ b/target/arm/translate-mve.c |
168 | + watchdog_add_model(&model); | 126 | @@ -XXX,XX +XXX,XX @@ DO_2OP_FP(VCMLA0, vcmla0) |
169 | + type_register_static(&imx2_wdt_info); | 127 | DO_2OP_FP(VCMLA90, vcmla90) |
170 | +} | 128 | DO_2OP_FP(VCMLA180, vcmla180) |
171 | +type_init(imx2_wdt_register_type) | 129 | DO_2OP_FP(VCMLA270, vcmla270) |
130 | +DO_2OP_FP(VMAXNMA, vmaxnma) | ||
131 | +DO_2OP_FP(VMINNMA, vminnma) | ||
132 | |||
133 | static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, | ||
134 | MVEGenTwoOpScalarFn fn) | ||
172 | -- | 135 | -- |
173 | 2.16.1 | 136 | 2.20.1 |
174 | 137 | ||
175 | 138 | diff view generated by jsdifflib |
1 | Currently armv7m_nvic_acknowledge_irq() does three things: | 1 | Implement the MVE scalar floating point insns VADD, VSUB and VMUL. |
---|---|---|---|
2 | * make the current highest priority pending interrupt active | ||
3 | * return a bool indicating whether that interrupt is targeting | ||
4 | Secure or NonSecure state | ||
5 | * implicitly tell the caller which is the highest priority | ||
6 | pending interrupt by setting env->v7m.exception | ||
7 | |||
8 | We need to split these jobs, because v7m_exception_taken() | ||
9 | needs to know whether the pending interrupt targets Secure so | ||
10 | it can choose to stack callee-saves registers or not, but it | ||
11 | must not make the interrupt active until after it has done | ||
12 | that stacking, in case the stacking causes a derived exception. | ||
13 | Similarly, it needs to know the number of the pending interrupt | ||
14 | so it can read the correct vector table entry before the | ||
15 | interrupt is made active, because vector table reads might | ||
16 | also cause a derived exception. | ||
17 | |||
18 | Create a new armv7m_nvic_get_pending_irq_info() function which simply | ||
19 | returns information about the highest priority pending interrupt, and | ||
20 | use it to rearrange the v7m_exception_taken() code so we don't | ||
21 | acknowledge the exception until we've done all the things which could | ||
22 | possibly cause a derived exception. | ||
23 | 2 | ||
24 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
25 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
26 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
27 | Message-id: 1517324542-6607-3-git-send-email-peter.maydell@linaro.org | ||
28 | --- | 5 | --- |
29 | target/arm/cpu.h | 19 ++++++++++++++++--- | 6 | target/arm/helper-mve.h | 9 +++++++++ |
30 | hw/intc/armv7m_nvic.c | 30 +++++++++++++++++++++++------- | 7 | target/arm/mve.decode | 27 +++++++++++++++++++++------ |
31 | target/arm/helper.c | 16 ++++++++++++---- | 8 | target/arm/mve_helper.c | 35 +++++++++++++++++++++++++++++++++++ |
32 | hw/intc/trace-events | 3 ++- | 9 | target/arm/translate-mve.c | 20 ++++++++++++++++++++ |
33 | 4 files changed, 53 insertions(+), 15 deletions(-) | 10 | 4 files changed, 85 insertions(+), 6 deletions(-) |
34 | 11 | ||
35 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 12 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
36 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
37 | --- a/target/arm/cpu.h | 14 | --- a/target/arm/helper-mve.h |
38 | +++ b/target/arm/cpu.h | 15 | +++ b/target/arm/helper-mve.h |
39 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure); | 16 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(mve_vcmpgt_scalarw, TCG_CALL_NO_WG, void, env, ptr, i32) |
40 | * a different exception). | 17 | DEF_HELPER_FLAGS_3(mve_vcmple_scalarb, TCG_CALL_NO_WG, void, env, ptr, i32) |
41 | */ | 18 | DEF_HELPER_FLAGS_3(mve_vcmple_scalarh, TCG_CALL_NO_WG, void, env, ptr, i32) |
42 | void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure); | 19 | DEF_HELPER_FLAGS_3(mve_vcmple_scalarw, TCG_CALL_NO_WG, void, env, ptr, i32) |
43 | +/** | 20 | + |
44 | + * armv7m_nvic_get_pending_irq_info: return highest priority pending | 21 | +DEF_HELPER_FLAGS_4(mve_vfadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
45 | + * exception, and whether it targets Secure state | 22 | +DEF_HELPER_FLAGS_4(mve_vfadd_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
46 | + * @opaque: the NVIC | 23 | + |
47 | + * @pirq: set to pending exception number | 24 | +DEF_HELPER_FLAGS_4(mve_vfsub_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
48 | + * @ptargets_secure: set to whether pending exception targets Secure | 25 | +DEF_HELPER_FLAGS_4(mve_vfsub_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
49 | + * | 26 | + |
50 | + * This function writes the number of the highest priority pending | 27 | +DEF_HELPER_FLAGS_4(mve_vfmul_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
51 | + * exception (the one which would be made active by | 28 | +DEF_HELPER_FLAGS_4(mve_vfmul_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
52 | + * armv7m_nvic_acknowledge_irq()) to @pirq, and sets @ptargets_secure | 29 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode |
53 | + * to true if the current highest priority pending exception should | ||
54 | + * be taken to Secure state, false for NS. | ||
55 | + */ | ||
56 | +void armv7m_nvic_get_pending_irq_info(void *opaque, int *pirq, | ||
57 | + bool *ptargets_secure); | ||
58 | /** | ||
59 | * armv7m_nvic_acknowledge_irq: make highest priority pending exception active | ||
60 | * @opaque: the NVIC | ||
61 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure); | ||
62 | * Move the current highest priority pending exception from the pending | ||
63 | * state to the active state, and update v7m.exception to indicate that | ||
64 | * it is the exception currently being handled. | ||
65 | - * | ||
66 | - * Returns: true if exception should be taken to Secure state, false for NS | ||
67 | */ | ||
68 | -bool armv7m_nvic_acknowledge_irq(void *opaque); | ||
69 | +void armv7m_nvic_acknowledge_irq(void *opaque); | ||
70 | /** | ||
71 | * armv7m_nvic_complete_irq: complete specified interrupt or exception | ||
72 | * @opaque: the NVIC | ||
73 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/hw/intc/armv7m_nvic.c | 31 | --- a/target/arm/mve.decode |
76 | +++ b/hw/intc/armv7m_nvic.c | 32 | +++ b/target/arm/mve.decode |
77 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure) | 33 | @@ -XXX,XX +XXX,XX @@ |
34 | %2op_fp_size 20:1 !function=neon_3same_fp_size | ||
35 | # VCADD is an exception, where bit 20 is 0 for 16 bit and 1 for 32 bit | ||
36 | %2op_fp_size_rev 20:1 !function=plus_1 | ||
37 | +# FP scalars have size in bit 28, 1 for 16 bit, 0 for 32 bit | ||
38 | +%2op_fp_scalar_size 28:1 !function=neon_3same_fp_size | ||
39 | |||
40 | # 1imm format immediate | ||
41 | %imm_28_16_0 28:1 16:3 0:4 | ||
42 | @@ -XXX,XX +XXX,XX @@ | ||
43 | @vmaxnma .... .... .... .... .... .... .... .... &2op \ | ||
44 | qd=%qd qn=%qd qm=%qm | ||
45 | |||
46 | +@2op_fp_scalar .... .... .... .... .... .... .... rm:4 &2scalar \ | ||
47 | + qd=%qd qn=%qn size=%2op_fp_scalar_size | ||
48 | + | ||
49 | # Vector loads and stores | ||
50 | |||
51 | # Widening loads and narrowing stores: | ||
52 | @@ -XXX,XX +XXX,XX @@ VSUB_scalar 1110 1110 0 . .. ... 1 ... 1 1111 . 100 .... @2scalar | ||
53 | VBRSR 1111 1110 0 . .. ... 1 ... 1 1110 . 110 .... @2scalar | ||
78 | } | 54 | } |
79 | 55 | ||
80 | /* Make pending IRQ active. */ | 56 | -VHADD_S_scalar 1110 1110 0 . .. ... 0 ... 0 1111 . 100 .... @2scalar |
81 | -bool armv7m_nvic_acknowledge_irq(void *opaque) | 57 | -VHADD_U_scalar 1111 1110 0 . .. ... 0 ... 0 1111 . 100 .... @2scalar |
82 | +void armv7m_nvic_acknowledge_irq(void *opaque) | 58 | -VHSUB_S_scalar 1110 1110 0 . .. ... 0 ... 1 1111 . 100 .... @2scalar |
83 | { | 59 | -VHSUB_U_scalar 1111 1110 0 . .. ... 0 ... 1 1111 . 100 .... @2scalar |
84 | NVICState *s = (NVICState *)opaque; | 60 | +{ |
85 | CPUARMState *env = &s->cpu->env; | 61 | + VADD_fp_scalar 111 . 1110 0 . 11 ... 0 ... 0 1111 . 100 .... @2op_fp_scalar |
86 | const int pending = s->vectpending; | 62 | + VHADD_S_scalar 1110 1110 0 . .. ... 0 ... 0 1111 . 100 .... @2scalar |
87 | const int running = nvic_exec_prio(s); | 63 | + VHADD_U_scalar 1111 1110 0 . .. ... 0 ... 0 1111 . 100 .... @2scalar |
88 | VecInfo *vec; | ||
89 | - bool targets_secure; | ||
90 | |||
91 | assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq); | ||
92 | |||
93 | if (s->vectpending_is_s_banked) { | ||
94 | vec = &s->sec_vectors[pending]; | ||
95 | - targets_secure = true; | ||
96 | } else { | ||
97 | vec = &s->vectors[pending]; | ||
98 | - targets_secure = !exc_is_banked(s->vectpending) && | ||
99 | - exc_targets_secure(s, s->vectpending); | ||
100 | } | ||
101 | |||
102 | assert(vec->enabled); | ||
103 | @@ -XXX,XX +XXX,XX @@ bool armv7m_nvic_acknowledge_irq(void *opaque) | ||
104 | |||
105 | assert(s->vectpending_prio < running); | ||
106 | |||
107 | - trace_nvic_acknowledge_irq(pending, s->vectpending_prio, targets_secure); | ||
108 | + trace_nvic_acknowledge_irq(pending, s->vectpending_prio); | ||
109 | |||
110 | vec->active = 1; | ||
111 | vec->pending = 0; | ||
112 | @@ -XXX,XX +XXX,XX @@ bool armv7m_nvic_acknowledge_irq(void *opaque) | ||
113 | write_v7m_exception(env, s->vectpending); | ||
114 | |||
115 | nvic_irq_update(s); | ||
116 | +} | 64 | +} |
117 | + | 65 | + |
118 | +void armv7m_nvic_get_pending_irq_info(void *opaque, | ||
119 | + int *pirq, bool *ptargets_secure) | ||
120 | +{ | 66 | +{ |
121 | + NVICState *s = (NVICState *)opaque; | 67 | + VSUB_fp_scalar 111 . 1110 0 . 11 ... 0 ... 1 1111 . 100 .... @2op_fp_scalar |
122 | + const int pending = s->vectpending; | 68 | + VHSUB_S_scalar 1110 1110 0 . .. ... 0 ... 1 1111 . 100 .... @2scalar |
123 | + bool targets_secure; | 69 | + VHSUB_U_scalar 1111 1110 0 . .. ... 0 ... 1 1111 . 100 .... @2scalar |
70 | +} | ||
71 | |||
72 | { | ||
73 | VQADD_S_scalar 1110 1110 0 . .. ... 0 ... 0 1111 . 110 .... @2scalar | ||
74 | @@ -XXX,XX +XXX,XX @@ VHSUB_U_scalar 1111 1110 0 . .. ... 0 ... 1 1111 . 100 .... @2scalar | ||
75 | size=%size_28 | ||
76 | } | ||
77 | |||
78 | -VQDMULH_scalar 1110 1110 0 . .. ... 1 ... 0 1110 . 110 .... @2scalar | ||
79 | -VQRDMULH_scalar 1111 1110 0 . .. ... 1 ... 0 1110 . 110 .... @2scalar | ||
80 | +{ | ||
81 | + VMUL_fp_scalar 111 . 1110 0 . 11 ... 1 ... 0 1110 . 110 .... @2op_fp_scalar | ||
82 | + VQDMULH_scalar 1110 1110 0 . .. ... 1 ... 0 1110 . 110 .... @2scalar | ||
83 | + VQRDMULH_scalar 1111 1110 0 . .. ... 1 ... 0 1110 . 110 .... @2scalar | ||
84 | +} | ||
85 | |||
86 | # The U bit (28) is don't-care because it does not affect the result | ||
87 | VMLA 111- 1110 0 . .. ... 1 ... 0 1110 . 100 .... @2scalar | ||
88 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
89 | index XXXXXXX..XXXXXXX 100644 | ||
90 | --- a/target/arm/mve_helper.c | ||
91 | +++ b/target/arm/mve_helper.c | ||
92 | @@ -XXX,XX +XXX,XX @@ DO_VCMLA(vcmla180h, 2, float16, 2, DO_VCMLAH) | ||
93 | DO_VCMLA(vcmla180s, 4, float32, 2, DO_VCMLAS) | ||
94 | DO_VCMLA(vcmla270h, 2, float16, 3, DO_VCMLAH) | ||
95 | DO_VCMLA(vcmla270s, 4, float32, 3, DO_VCMLAS) | ||
124 | + | 96 | + |
125 | + assert(pending > ARMV7M_EXCP_RESET && pending < s->num_irq); | 97 | +#define DO_2OP_FP_SCALAR(OP, ESIZE, TYPE, FN) \ |
126 | + | 98 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ |
127 | + if (s->vectpending_is_s_banked) { | 99 | + void *vd, void *vn, uint32_t rm) \ |
128 | + targets_secure = true; | 100 | + { \ |
129 | + } else { | 101 | + TYPE *d = vd, *n = vn; \ |
130 | + targets_secure = !exc_is_banked(pending) && | 102 | + TYPE r, m = rm; \ |
131 | + exc_targets_secure(s, pending); | 103 | + uint16_t mask = mve_element_mask(env); \ |
104 | + unsigned e; \ | ||
105 | + float_status *fpst; \ | ||
106 | + float_status scratch_fpst; \ | ||
107 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ | ||
108 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ | ||
109 | + continue; \ | ||
110 | + } \ | ||
111 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | ||
112 | + &env->vfp.standard_fp_status; \ | ||
113 | + if (!(mask & 1)) { \ | ||
114 | + /* We need the result but without updating flags */ \ | ||
115 | + scratch_fpst = *fpst; \ | ||
116 | + fpst = &scratch_fpst; \ | ||
117 | + } \ | ||
118 | + r = FN(n[H##ESIZE(e)], m, fpst); \ | ||
119 | + mergemask(&d[H##ESIZE(e)], r, mask); \ | ||
120 | + } \ | ||
121 | + mve_advance_vpt(env); \ | ||
132 | + } | 122 | + } |
133 | + | 123 | + |
134 | + trace_nvic_get_pending_irq_info(pending, targets_secure); | 124 | +#define DO_2OP_FP_SCALAR_ALL(OP, FN) \ |
135 | 125 | + DO_2OP_FP_SCALAR(OP##h, 2, float16, float16_##FN) \ | |
136 | - return targets_secure; | 126 | + DO_2OP_FP_SCALAR(OP##s, 4, float32, float32_##FN) |
137 | + *ptargets_secure = targets_secure; | 127 | + |
138 | + *pirq = pending; | 128 | +DO_2OP_FP_SCALAR_ALL(vfadd_scalar, add) |
129 | +DO_2OP_FP_SCALAR_ALL(vfsub_scalar, sub) | ||
130 | +DO_2OP_FP_SCALAR_ALL(vfmul_scalar, mul) | ||
131 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
132 | index XXXXXXX..XXXXXXX 100644 | ||
133 | --- a/target/arm/translate-mve.c | ||
134 | +++ b/target/arm/translate-mve.c | ||
135 | @@ -XXX,XX +XXX,XX @@ static bool trans_VQDMULLT_scalar(DisasContext *s, arg_2scalar *a) | ||
136 | return do_2op_scalar(s, a, fns[a->size]); | ||
139 | } | 137 | } |
140 | 138 | ||
141 | int armv7m_nvic_complete_irq(void *opaque, int irq, bool secure) | 139 | + |
142 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 140 | +#define DO_2OP_FP_SCALAR(INSN, FN) \ |
143 | index XXXXXXX..XXXXXXX 100644 | 141 | + static bool trans_##INSN(DisasContext *s, arg_2scalar *a) \ |
144 | --- a/target/arm/helper.c | 142 | + { \ |
145 | +++ b/target/arm/helper.c | 143 | + static MVEGenTwoOpScalarFn * const fns[] = { \ |
146 | @@ -XXX,XX +XXX,XX @@ static uint32_t *get_v7m_sp_ptr(CPUARMState *env, bool secure, bool threadmode, | 144 | + NULL, \ |
147 | } | 145 | + gen_helper_mve_##FN##h, \ |
148 | } | 146 | + gen_helper_mve_##FN##s, \ |
149 | 147 | + NULL, \ | |
150 | -static uint32_t arm_v7m_load_vector(ARMCPU *cpu, bool targets_secure) | 148 | + }; \ |
151 | +static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 149 | + if (!dc_isar_feature(aa32_mve_fp, s)) { \ |
150 | + return false; \ | ||
151 | + } \ | ||
152 | + return do_2op_scalar(s, a, fns[a->size]); \ | ||
153 | + } | ||
154 | + | ||
155 | +DO_2OP_FP_SCALAR(VADD_fp_scalar, vfadd_scalar) | ||
156 | +DO_2OP_FP_SCALAR(VSUB_fp_scalar, vfsub_scalar) | ||
157 | +DO_2OP_FP_SCALAR(VMUL_fp_scalar, vfmul_scalar) | ||
158 | + | ||
159 | static bool do_long_dual_acc(DisasContext *s, arg_vmlaldav *a, | ||
160 | MVEGenLongDualAccOpFn *fn) | ||
152 | { | 161 | { |
153 | CPUState *cs = CPU(cpu); | ||
154 | CPUARMState *env = &cpu->env; | ||
155 | MemTxResult result; | ||
156 | - hwaddr vec = env->v7m.vecbase[targets_secure] + env->v7m.exception * 4; | ||
157 | + hwaddr vec = env->v7m.vecbase[targets_secure] + exc * 4; | ||
158 | uint32_t addr; | ||
159 | |||
160 | addr = address_space_ldl(cs->as, vec, | ||
161 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
162 | CPUARMState *env = &cpu->env; | ||
163 | uint32_t addr; | ||
164 | bool targets_secure; | ||
165 | + int exc; | ||
166 | |||
167 | - targets_secure = armv7m_nvic_acknowledge_irq(env->nvic); | ||
168 | + armv7m_nvic_get_pending_irq_info(env->nvic, &exc, &targets_secure); | ||
169 | |||
170 | if (arm_feature(env, ARM_FEATURE_V8)) { | ||
171 | if (arm_feature(env, ARM_FEATURE_M_SECURITY) && | ||
172 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
173 | } | ||
174 | } | ||
175 | |||
176 | + addr = arm_v7m_load_vector(cpu, exc, targets_secure); | ||
177 | + | ||
178 | + /* Now we've done everything that might cause a derived exception | ||
179 | + * we can go ahead and activate whichever exception we're going to | ||
180 | + * take (which might now be the derived exception). | ||
181 | + */ | ||
182 | + armv7m_nvic_acknowledge_irq(env->nvic); | ||
183 | + | ||
184 | /* Switch to target security state -- must do this before writing SPSEL */ | ||
185 | switch_v7m_security_state(env, targets_secure); | ||
186 | write_v7m_control_spsel(env, 0); | ||
187 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
188 | /* Clear IT bits */ | ||
189 | env->condexec_bits = 0; | ||
190 | env->regs[14] = lr; | ||
191 | - addr = arm_v7m_load_vector(cpu, targets_secure); | ||
192 | env->regs[15] = addr & 0xfffffffe; | ||
193 | env->thumb = addr & 1; | ||
194 | } | ||
195 | diff --git a/hw/intc/trace-events b/hw/intc/trace-events | ||
196 | index XXXXXXX..XXXXXXX 100644 | ||
197 | --- a/hw/intc/trace-events | ||
198 | +++ b/hw/intc/trace-events | ||
199 | @@ -XXX,XX +XXX,XX @@ nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled" | ||
200 | nvic_set_pending(int irq, bool secure, bool derived, int en, int prio) "NVIC set pending irq %d secure-bank %d derived %d (enabled: %d priority %d)" | ||
201 | nvic_clear_pending(int irq, bool secure, int en, int prio) "NVIC clear pending irq %d secure-bank %d (enabled: %d priority %d)" | ||
202 | nvic_set_pending_level(int irq) "NVIC set pending: irq %d higher prio than vectpending: setting irq line to 1" | ||
203 | -nvic_acknowledge_irq(int irq, int prio, bool targets_secure) "NVIC acknowledge IRQ: %d now active (prio %d targets_secure %d)" | ||
204 | +nvic_acknowledge_irq(int irq, int prio) "NVIC acknowledge IRQ: %d now active (prio %d)" | ||
205 | +nvic_get_pending_irq_info(int irq, bool secure) "NVIC next IRQ %d: targets_secure: %d" | ||
206 | nvic_complete_irq(int irq, bool secure) "NVIC complete IRQ %d (secure %d)" | ||
207 | nvic_set_irq_level(int irq, int level) "NVIC external irq %d level set to %d" | ||
208 | nvic_sysreg_read(uint64_t addr, uint32_t value, unsigned size) "NVIC sysreg read addr 0x%" PRIx64 " data 0x%" PRIx32 " size %u" | ||
209 | -- | 162 | -- |
210 | 2.16.1 | 163 | 2.20.1 |
211 | 164 | ||
212 | 165 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | Implement the MVE fp-with-scalar VFMA and VFMAS insns. |
---|---|---|---|
2 | 2 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | 3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | target/arm/helper-mve.h | 6 ++++++ | ||
7 | target/arm/mve.decode | 14 +++++++++++--- | ||
8 | target/arm/mve_helper.c | 37 +++++++++++++++++++++++++++++++++++++ | ||
9 | target/arm/translate-mve.c | 2 ++ | ||
10 | 4 files changed, 56 insertions(+), 3 deletions(-) | ||
4 | 11 | ||
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | 12 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
6 | Cc: Jason Wang <jasowang@redhat.com> | ||
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
10 | Cc: qemu-devel@nongnu.org | ||
11 | Cc: qemu-arm@nongnu.org | ||
12 | Cc: yurovsky@gmail.com | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | --- | ||
18 | include/hw/timer/imx_gpt.h | 1 + | ||
19 | hw/timer/imx_gpt.c | 25 +++++++++++++++++++++++++ | ||
20 | 2 files changed, 26 insertions(+) | ||
21 | |||
22 | diff --git a/include/hw/timer/imx_gpt.h b/include/hw/timer/imx_gpt.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/timer/imx_gpt.h | 14 | --- a/target/arm/helper-mve.h |
25 | +++ b/include/hw/timer/imx_gpt.h | 15 | +++ b/target/arm/helper-mve.h |
26 | @@ -XXX,XX +XXX,XX @@ | 16 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vfsub_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
27 | #define TYPE_IMX25_GPT "imx25.gpt" | 17 | |
28 | #define TYPE_IMX31_GPT "imx31.gpt" | 18 | DEF_HELPER_FLAGS_4(mve_vfmul_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
29 | #define TYPE_IMX6_GPT "imx6.gpt" | 19 | DEF_HELPER_FLAGS_4(mve_vfmul_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
30 | +#define TYPE_IMX7_GPT "imx7.gpt" | 20 | + |
31 | 21 | +DEF_HELPER_FLAGS_4(mve_vfma_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | |
32 | #define TYPE_IMX_GPT TYPE_IMX25_GPT | 22 | +DEF_HELPER_FLAGS_4(mve_vfma_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
33 | 23 | + | |
34 | diff --git a/hw/timer/imx_gpt.c b/hw/timer/imx_gpt.c | 24 | +DEF_HELPER_FLAGS_4(mve_vfmas_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
25 | +DEF_HELPER_FLAGS_4(mve_vfmas_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
26 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
35 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/hw/timer/imx_gpt.c | 28 | --- a/target/arm/mve.decode |
37 | +++ b/hw/timer/imx_gpt.c | 29 | +++ b/target/arm/mve.decode |
38 | @@ -XXX,XX +XXX,XX @@ static const IMXClk imx6_gpt_clocks[] = { | 30 | @@ -XXX,XX +XXX,XX @@ VSUB_scalar 1110 1110 0 . .. ... 1 ... 1 1111 . 100 .... @2scalar |
39 | CLK_HIGH, /* 111 reference clock */ | 31 | VQRDMULH_scalar 1111 1110 0 . .. ... 1 ... 0 1110 . 110 .... @2scalar |
40 | }; | ||
41 | |||
42 | +static const IMXClk imx7_gpt_clocks[] = { | ||
43 | + CLK_NONE, /* 000 No clock source */ | ||
44 | + CLK_IPG, /* 001 ipg_clk, 532MHz*/ | ||
45 | + CLK_IPG_HIGH, /* 010 ipg_clk_highfreq */ | ||
46 | + CLK_EXT, /* 011 External clock */ | ||
47 | + CLK_32k, /* 100 ipg_clk_32k */ | ||
48 | + CLK_HIGH, /* 101 reference clock */ | ||
49 | + CLK_NONE, /* 110 not defined */ | ||
50 | + CLK_NONE, /* 111 not defined */ | ||
51 | +}; | ||
52 | + | ||
53 | static void imx_gpt_set_freq(IMXGPTState *s) | ||
54 | { | ||
55 | uint32_t clksrc = extract32(s->cr, GPT_CR_CLKSRC_SHIFT, 3); | ||
56 | @@ -XXX,XX +XXX,XX @@ static void imx6_gpt_init(Object *obj) | ||
57 | s->clocks = imx6_gpt_clocks; | ||
58 | } | 32 | } |
59 | 33 | ||
60 | +static void imx7_gpt_init(Object *obj) | 34 | -# The U bit (28) is don't-care because it does not affect the result |
35 | -VMLA 111- 1110 0 . .. ... 1 ... 0 1110 . 100 .... @2scalar | ||
36 | -VMLAS 111- 1110 0 . .. ... 1 ... 1 1110 . 100 .... @2scalar | ||
61 | +{ | 37 | +{ |
62 | + IMXGPTState *s = IMX_GPT(obj); | 38 | + VFMA_scalar 111 . 1110 0 . 11 ... 1 ... 0 1110 . 100 .... @2op_fp_scalar |
63 | + | 39 | + # The U bit (28) is don't-care because it does not affect the result |
64 | + s->clocks = imx7_gpt_clocks; | 40 | + VMLA 111 - 1110 0 . .. ... 1 ... 0 1110 . 100 .... @2scalar |
65 | +} | 41 | +} |
66 | + | 42 | + |
67 | static const TypeInfo imx25_gpt_info = { | 43 | +{ |
68 | .name = TYPE_IMX25_GPT, | 44 | + VFMAS_scalar 111 . 1110 0 . 11 ... 1 ... 1 1110 . 100 .... @2op_fp_scalar |
69 | .parent = TYPE_SYS_BUS_DEVICE, | 45 | + # The U bit (28) is don't-care because it does not affect the result |
70 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo imx6_gpt_info = { | 46 | + VMLAS 111 - 1110 0 . .. ... 1 ... 1 1110 . 100 .... @2scalar |
71 | .instance_init = imx6_gpt_init, | 47 | +} |
72 | }; | 48 | |
73 | 49 | VQRDMLAH 1110 1110 0 . .. ... 0 ... 0 1110 . 100 .... @2scalar | |
74 | +static const TypeInfo imx7_gpt_info = { | 50 | VQRDMLASH 1110 1110 0 . .. ... 0 ... 1 1110 . 100 .... @2scalar |
75 | + .name = TYPE_IMX7_GPT, | 51 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c |
76 | + .parent = TYPE_IMX25_GPT, | 52 | index XXXXXXX..XXXXXXX 100644 |
77 | + .instance_init = imx7_gpt_init, | 53 | --- a/target/arm/mve_helper.c |
78 | +}; | 54 | +++ b/target/arm/mve_helper.c |
55 | @@ -XXX,XX +XXX,XX @@ DO_VCMLA(vcmla270s, 4, float32, 3, DO_VCMLAS) | ||
56 | DO_2OP_FP_SCALAR_ALL(vfadd_scalar, add) | ||
57 | DO_2OP_FP_SCALAR_ALL(vfsub_scalar, sub) | ||
58 | DO_2OP_FP_SCALAR_ALL(vfmul_scalar, mul) | ||
79 | + | 59 | + |
80 | static void imx_gpt_register_types(void) | 60 | +#define DO_2OP_FP_ACC_SCALAR(OP, ESIZE, TYPE, FN) \ |
81 | { | 61 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ |
82 | type_register_static(&imx25_gpt_info); | 62 | + void *vd, void *vn, uint32_t rm) \ |
83 | type_register_static(&imx31_gpt_info); | 63 | + { \ |
84 | type_register_static(&imx6_gpt_info); | 64 | + TYPE *d = vd, *n = vn; \ |
85 | + type_register_static(&imx7_gpt_info); | 65 | + TYPE r, m = rm; \ |
86 | } | 66 | + uint16_t mask = mve_element_mask(env); \ |
87 | 67 | + unsigned e; \ | |
88 | type_init(imx_gpt_register_types) | 68 | + float_status *fpst; \ |
69 | + float_status scratch_fpst; \ | ||
70 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ | ||
71 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ | ||
72 | + continue; \ | ||
73 | + } \ | ||
74 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | ||
75 | + &env->vfp.standard_fp_status; \ | ||
76 | + if (!(mask & 1)) { \ | ||
77 | + /* We need the result but without updating flags */ \ | ||
78 | + scratch_fpst = *fpst; \ | ||
79 | + fpst = &scratch_fpst; \ | ||
80 | + } \ | ||
81 | + r = FN(n[H##ESIZE(e)], m, d[H##ESIZE(e)], 0, fpst); \ | ||
82 | + mergemask(&d[H##ESIZE(e)], r, mask); \ | ||
83 | + } \ | ||
84 | + mve_advance_vpt(env); \ | ||
85 | + } | ||
86 | + | ||
87 | +/* VFMAS is vector * vector + scalar, so swap op2 and op3 */ | ||
88 | +#define DO_VFMAS_SCALARH(N, M, D, F, S) float16_muladd(N, D, M, F, S) | ||
89 | +#define DO_VFMAS_SCALARS(N, M, D, F, S) float32_muladd(N, D, M, F, S) | ||
90 | + | ||
91 | +/* VFMA is vector * scalar + vector */ | ||
92 | +DO_2OP_FP_ACC_SCALAR(vfma_scalarh, 2, float16, float16_muladd) | ||
93 | +DO_2OP_FP_ACC_SCALAR(vfma_scalars, 4, float32, float32_muladd) | ||
94 | +DO_2OP_FP_ACC_SCALAR(vfmas_scalarh, 2, float16, DO_VFMAS_SCALARH) | ||
95 | +DO_2OP_FP_ACC_SCALAR(vfmas_scalars, 4, float32, DO_VFMAS_SCALARS) | ||
96 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/target/arm/translate-mve.c | ||
99 | +++ b/target/arm/translate-mve.c | ||
100 | @@ -XXX,XX +XXX,XX @@ static bool trans_VQDMULLT_scalar(DisasContext *s, arg_2scalar *a) | ||
101 | DO_2OP_FP_SCALAR(VADD_fp_scalar, vfadd_scalar) | ||
102 | DO_2OP_FP_SCALAR(VSUB_fp_scalar, vfsub_scalar) | ||
103 | DO_2OP_FP_SCALAR(VMUL_fp_scalar, vfmul_scalar) | ||
104 | +DO_2OP_FP_SCALAR(VFMA_scalar, vfma_scalar) | ||
105 | +DO_2OP_FP_SCALAR(VFMAS_scalar, vfmas_scalar) | ||
106 | |||
107 | static bool do_long_dual_acc(DisasContext *s, arg_vmlaldav *a, | ||
108 | MVEGenLongDualAccOpFn *fn) | ||
89 | -- | 109 | -- |
90 | 2.16.1 | 110 | 2.20.1 |
91 | 111 | ||
92 | 112 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | In commit a777d6033447a we added an assertion to parts_silence_nan() that | ||
2 | prohibits calling float*_silence_nan() when in default-NaN mode. | ||
3 | This ties together a property of the output ("do we generate a default | ||
4 | NaN when the result is a NaN?") with an operation on an input ("silence | ||
5 | this input NaN"). | ||
1 | 6 | ||
7 | It's true that most of the time when in default-NaN mode you won't | ||
8 | need to silence an input NaN, because you can just produce the | ||
9 | default NaN as the result instead. But some functions like | ||
10 | float*_maxnum() are defined to be able to work with quiet NaNs, so | ||
11 | silencing an input SNaN is still reasonable. In particular, the | ||
12 | upcoming implementation of MVE VMAXNMV would fall over this assertion | ||
13 | if we didn't delete it. | ||
14 | |||
15 | Delete the assertion. | ||
16 | |||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
19 | --- | ||
20 | fpu/softfloat-specialize.c.inc | 1 - | ||
21 | 1 file changed, 1 deletion(-) | ||
22 | |||
23 | diff --git a/fpu/softfloat-specialize.c.inc b/fpu/softfloat-specialize.c.inc | ||
24 | index XXXXXXX..XXXXXXX 100644 | ||
25 | --- a/fpu/softfloat-specialize.c.inc | ||
26 | +++ b/fpu/softfloat-specialize.c.inc | ||
27 | @@ -XXX,XX +XXX,XX @@ static void parts128_default_nan(FloatParts128 *p, float_status *status) | ||
28 | static uint64_t parts_silence_nan_frac(uint64_t frac, float_status *status) | ||
29 | { | ||
30 | g_assert(!no_signaling_nans(status)); | ||
31 | - g_assert(!status->default_nan_mode); | ||
32 | |||
33 | /* The only snan_bit_is_one target without default_nan_mode is HPPA. */ | ||
34 | if (snan_bit_is_one(status)) { | ||
35 | -- | ||
36 | 2.20.1 | ||
37 | |||
38 | diff view generated by jsdifflib |
1 | The memory writes done to push registers on the stack | 1 | Implement the MVE VMAXNMV, VMINNMV, VMAXNMAV, VMINNMAV insns. These |
---|---|---|---|
2 | on exception entry in M profile CPUs are supposed to | 2 | calculate the maximum or minimum of floating point elements across a |
3 | go via MPU permissions checks, which may cause us to | 3 | vector, starting with a value in a general purpose register and |
4 | take a derived exception instead of the original one of | 4 | returning the result there. |
5 | the MPU lookup fails. We were implementing these as | 5 | |
6 | always-succeeds direct writes to physical memory. | 6 | The pseudocode silences a possible SNaN in the accumulating result |
7 | Rewrite v7m_push_stack() to do the necessary checks. | 7 | on every iteration (by calling FPConvertNaN), but we do it only |
8 | on the input ra, because if none of the inputs to float*_maxnum | ||
9 | or float*_minnum are SNaNs then the result can't be an SNaN. | ||
10 | |||
11 | Note that we can't use the float*_maxnuma() etc functions we defined | ||
12 | earlier for VMAXNMA and VMINNMA, because we mustn't take the absolute | ||
13 | value of the starting general-purpose register value, which could be | ||
14 | negative. | ||
8 | 15 | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 17 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
11 | Message-id: 1517324542-6607-5-git-send-email-peter.maydell@linaro.org | ||
12 | --- | 18 | --- |
13 | target/arm/helper.c | 103 ++++++++++++++++++++++++++++++++++++++++++++-------- | 19 | target/arm/helper-mve.h | 12 +++++++++++ |
14 | 1 file changed, 87 insertions(+), 16 deletions(-) | 20 | target/arm/mve.decode | 32 +++++++++++++++++++++------ |
21 | target/arm/mve_helper.c | 44 ++++++++++++++++++++++++++++++++++++++ | ||
22 | target/arm/translate-mve.c | 20 +++++++++++++++++ | ||
23 | 4 files changed, 102 insertions(+), 6 deletions(-) | ||
15 | 24 | ||
16 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 25 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
17 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/helper.c | 27 | --- a/target/arm/helper-mve.h |
19 | +++ b/target/arm/helper.c | 28 | +++ b/target/arm/helper-mve.h |
20 | @@ -XXX,XX +XXX,XX @@ uint32_t arm_phys_excp_target_el(CPUState *cs, uint32_t excp_idx, | 29 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(mve_vminavb, TCG_CALL_NO_WG, i32, env, ptr, i32) |
21 | return target_el; | 30 | DEF_HELPER_FLAGS_3(mve_vminavh, TCG_CALL_NO_WG, i32, env, ptr, i32) |
31 | DEF_HELPER_FLAGS_3(mve_vminavw, TCG_CALL_NO_WG, i32, env, ptr, i32) | ||
32 | |||
33 | +DEF_HELPER_FLAGS_3(mve_vmaxnmvh, TCG_CALL_NO_WG, i32, env, ptr, i32) | ||
34 | +DEF_HELPER_FLAGS_3(mve_vmaxnmvs, TCG_CALL_NO_WG, i32, env, ptr, i32) | ||
35 | + | ||
36 | +DEF_HELPER_FLAGS_3(mve_vminnmvh, TCG_CALL_NO_WG, i32, env, ptr, i32) | ||
37 | +DEF_HELPER_FLAGS_3(mve_vminnmvs, TCG_CALL_NO_WG, i32, env, ptr, i32) | ||
38 | + | ||
39 | +DEF_HELPER_FLAGS_3(mve_vmaxnmavh, TCG_CALL_NO_WG, i32, env, ptr, i32) | ||
40 | +DEF_HELPER_FLAGS_3(mve_vmaxnmavs, TCG_CALL_NO_WG, i32, env, ptr, i32) | ||
41 | + | ||
42 | +DEF_HELPER_FLAGS_3(mve_vminnmavh, TCG_CALL_NO_WG, i32, env, ptr, i32) | ||
43 | +DEF_HELPER_FLAGS_3(mve_vminnmavs, TCG_CALL_NO_WG, i32, env, ptr, i32) | ||
44 | + | ||
45 | DEF_HELPER_FLAGS_3(mve_vaddlv_s, TCG_CALL_NO_WG, i64, env, ptr, i64) | ||
46 | DEF_HELPER_FLAGS_3(mve_vaddlv_u, TCG_CALL_NO_WG, i64, env, ptr, i64) | ||
47 | |||
48 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/target/arm/mve.decode | ||
51 | +++ b/target/arm/mve.decode | ||
52 | @@ -XXX,XX +XXX,XX @@ | ||
53 | @vmaxnma .... .... .... .... .... .... .... .... &2op \ | ||
54 | qd=%qd qn=%qd qm=%qm | ||
55 | |||
56 | +# Here also we don't decode the bit 28 size in the format to avoid | ||
57 | +# awkward nested overlap groups | ||
58 | +@vmaxnmv .... .... .... .... rda:4 .... .... .... &vmaxv qm=%qm | ||
59 | + | ||
60 | @2op_fp_scalar .... .... .... .... .... .... .... rm:4 &2scalar \ | ||
61 | qd=%qd qn=%qn size=%2op_fp_scalar_size | ||
62 | |||
63 | @@ -XXX,XX +XXX,XX @@ VMLADAV_S 1110 1110 1111 ... 0 ... . 1111 . 0 . 0 ... 1 @vmladav_nosz | ||
64 | VMLADAV_U 1111 1110 1111 ... 0 ... . 1111 . 0 . 0 ... 1 @vmladav_nosz | ||
65 | |||
66 | { | ||
67 | - VMAXV_S 1110 1110 1110 .. 10 .... 1111 0 0 . 0 ... 0 @vmaxv | ||
68 | - VMINV_S 1110 1110 1110 .. 10 .... 1111 1 0 . 0 ... 0 @vmaxv | ||
69 | - VMAXAV 1110 1110 1110 .. 00 .... 1111 0 0 . 0 ... 0 @vmaxv | ||
70 | - VMINAV 1110 1110 1110 .. 00 .... 1111 1 0 . 0 ... 0 @vmaxv | ||
71 | + [ | ||
72 | + VMAXNMAV 1110 1110 1110 11 00 .... 1111 0 0 . 0 ... 0 @vmaxnmv size=2 | ||
73 | + VMINNMAV 1110 1110 1110 11 00 .... 1111 1 0 . 0 ... 0 @vmaxnmv size=2 | ||
74 | + VMAXNMV 1110 1110 1110 11 10 .... 1111 0 0 . 0 ... 0 @vmaxnmv size=2 | ||
75 | + VMINNMV 1110 1110 1110 11 10 .... 1111 1 0 . 0 ... 0 @vmaxnmv size=2 | ||
76 | + ] | ||
77 | + [ | ||
78 | + VMAXV_S 1110 1110 1110 .. 10 .... 1111 0 0 . 0 ... 0 @vmaxv | ||
79 | + VMINV_S 1110 1110 1110 .. 10 .... 1111 1 0 . 0 ... 0 @vmaxv | ||
80 | + VMAXAV 1110 1110 1110 .. 00 .... 1111 0 0 . 0 ... 0 @vmaxv | ||
81 | + VMINAV 1110 1110 1110 .. 00 .... 1111 1 0 . 0 ... 0 @vmaxv | ||
82 | + ] | ||
83 | VMLADAV_S 1110 1110 1111 ... 0 ... . 1111 . 0 . 0 ... 0 @vmladav_nosz | ||
84 | VRMLALDAVH_S 1110 1110 1 ... ... 0 ... . 1111 . 0 . 0 ... 0 @vmlaldav_nosz | ||
22 | } | 85 | } |
23 | 86 | ||
24 | -static void v7m_push(CPUARMState *env, uint32_t val) | ||
25 | +static bool v7m_stack_write(ARMCPU *cpu, uint32_t addr, uint32_t value, | ||
26 | + ARMMMUIdx mmu_idx, bool ignfault) | ||
27 | { | 87 | { |
28 | - CPUState *cs = CPU(arm_env_get_cpu(env)); | 88 | - VMAXV_U 1111 1110 1110 .. 10 .... 1111 0 0 . 0 ... 0 @vmaxv |
29 | + CPUState *cs = CPU(cpu); | 89 | - VMINV_U 1111 1110 1110 .. 10 .... 1111 1 0 . 0 ... 0 @vmaxv |
30 | + CPUARMState *env = &cpu->env; | 90 | + [ |
31 | + MemTxAttrs attrs = {}; | 91 | + VMAXNMAV 1111 1110 1110 11 00 .... 1111 0 0 . 0 ... 0 @vmaxnmv size=1 |
32 | + MemTxResult txres; | 92 | + VMINNMAV 1111 1110 1110 11 00 .... 1111 1 0 . 0 ... 0 @vmaxnmv size=1 |
33 | + target_ulong page_size; | 93 | + VMAXNMV 1111 1110 1110 11 10 .... 1111 0 0 . 0 ... 0 @vmaxnmv size=1 |
34 | + hwaddr physaddr; | 94 | + VMINNMV 1111 1110 1110 11 10 .... 1111 1 0 . 0 ... 0 @vmaxnmv size=1 |
35 | + int prot; | 95 | + ] |
36 | + ARMMMUFaultInfo fi; | 96 | + [ |
37 | + bool secure = mmu_idx & ARM_MMU_IDX_M_S; | 97 | + VMAXV_U 1111 1110 1110 .. 10 .... 1111 0 0 . 0 ... 0 @vmaxv |
38 | + int exc; | 98 | + VMINV_U 1111 1110 1110 .. 10 .... 1111 1 0 . 0 ... 0 @vmaxv |
39 | + bool exc_secure; | 99 | + ] |
40 | 100 | VMLADAV_U 1111 1110 1111 ... 0 ... . 1111 . 0 . 0 ... 0 @vmladav_nosz | |
41 | - env->regs[13] -= 4; | 101 | VRMLALDAVH_U 1111 1110 1 ... ... 0 ... . 1111 . 0 . 0 ... 0 @vmlaldav_nosz |
42 | - stl_phys(cs->as, env->regs[13], val); | 102 | } |
43 | + if (get_phys_addr(env, addr, MMU_DATA_STORE, mmu_idx, &physaddr, | 103 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c |
44 | + &attrs, &prot, &page_size, &fi, NULL)) { | 104 | index XXXXXXX..XXXXXXX 100644 |
45 | + /* MPU/SAU lookup failed */ | 105 | --- a/target/arm/mve_helper.c |
46 | + if (fi.type == ARMFault_QEMU_SFault) { | 106 | +++ b/target/arm/mve_helper.c |
47 | + qemu_log_mask(CPU_LOG_INT, | 107 | @@ -XXX,XX +XXX,XX @@ DO_2OP_FP_ACC_SCALAR(vfma_scalarh, 2, float16, float16_muladd) |
48 | + "...SecureFault with SFSR.AUVIOL during stacking\n"); | 108 | DO_2OP_FP_ACC_SCALAR(vfma_scalars, 4, float32, float32_muladd) |
49 | + env->v7m.sfsr |= R_V7M_SFSR_AUVIOL_MASK | R_V7M_SFSR_SFARVALID_MASK; | 109 | DO_2OP_FP_ACC_SCALAR(vfmas_scalarh, 2, float16, DO_VFMAS_SCALARH) |
50 | + env->v7m.sfar = addr; | 110 | DO_2OP_FP_ACC_SCALAR(vfmas_scalars, 4, float32, DO_VFMAS_SCALARS) |
51 | + exc = ARMV7M_EXCP_SECURE; | 111 | + |
52 | + exc_secure = false; | 112 | +/* Floating point max/min across vector. */ |
53 | + } else { | 113 | +#define DO_FP_VMAXMINV(OP, ESIZE, TYPE, ABS, FN) \ |
54 | + qemu_log_mask(CPU_LOG_INT, "...MemManageFault with CFSR.MSTKERR\n"); | 114 | + uint32_t HELPER(glue(mve_, OP))(CPUARMState *env, void *vm, \ |
55 | + env->v7m.cfsr[secure] |= R_V7M_CFSR_MSTKERR_MASK; | 115 | + uint32_t ra_in) \ |
56 | + exc = ARMV7M_EXCP_MEM; | 116 | + { \ |
57 | + exc_secure = secure; | 117 | + uint16_t mask = mve_element_mask(env); \ |
58 | + } | 118 | + unsigned e; \ |
59 | + goto pend_fault; | 119 | + TYPE *m = vm; \ |
120 | + TYPE ra = (TYPE)ra_in; \ | ||
121 | + float_status *fpst = (ESIZE == 2) ? \ | ||
122 | + &env->vfp.standard_fp_status_f16 : \ | ||
123 | + &env->vfp.standard_fp_status; \ | ||
124 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ | ||
125 | + if (mask & 1) { \ | ||
126 | + TYPE v = m[H##ESIZE(e)]; \ | ||
127 | + if (TYPE##_is_signaling_nan(ra, fpst)) { \ | ||
128 | + ra = TYPE##_silence_nan(ra, fpst); \ | ||
129 | + float_raise(float_flag_invalid, fpst); \ | ||
130 | + } \ | ||
131 | + if (TYPE##_is_signaling_nan(v, fpst)) { \ | ||
132 | + v = TYPE##_silence_nan(v, fpst); \ | ||
133 | + float_raise(float_flag_invalid, fpst); \ | ||
134 | + } \ | ||
135 | + if (ABS) { \ | ||
136 | + v = TYPE##_abs(v); \ | ||
137 | + } \ | ||
138 | + ra = FN(ra, v, fpst); \ | ||
139 | + } \ | ||
140 | + } \ | ||
141 | + mve_advance_vpt(env); \ | ||
142 | + return ra; \ | ||
143 | + } \ | ||
144 | + | ||
145 | +#define NOP(X) (X) | ||
146 | + | ||
147 | +DO_FP_VMAXMINV(vmaxnmvh, 2, float16, false, float16_maxnum) | ||
148 | +DO_FP_VMAXMINV(vmaxnmvs, 4, float32, false, float32_maxnum) | ||
149 | +DO_FP_VMAXMINV(vminnmvh, 2, float16, false, float16_minnum) | ||
150 | +DO_FP_VMAXMINV(vminnmvs, 4, float32, false, float32_minnum) | ||
151 | +DO_FP_VMAXMINV(vmaxnmavh, 2, float16, true, float16_maxnum) | ||
152 | +DO_FP_VMAXMINV(vmaxnmavs, 4, float32, true, float32_maxnum) | ||
153 | +DO_FP_VMAXMINV(vminnmavh, 2, float16, true, float16_minnum) | ||
154 | +DO_FP_VMAXMINV(vminnmavs, 4, float32, true, float32_minnum) | ||
155 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
156 | index XXXXXXX..XXXXXXX 100644 | ||
157 | --- a/target/arm/translate-mve.c | ||
158 | +++ b/target/arm/translate-mve.c | ||
159 | @@ -XXX,XX +XXX,XX @@ DO_VMAXV(VMINV_S, vminvs) | ||
160 | DO_VMAXV(VMINV_U, vminvu) | ||
161 | DO_VMAXV(VMINAV, vminav) | ||
162 | |||
163 | +#define DO_VMAXV_FP(INSN, FN) \ | ||
164 | + static bool trans_##INSN(DisasContext *s, arg_vmaxv *a) \ | ||
165 | + { \ | ||
166 | + static MVEGenVADDVFn * const fns[] = { \ | ||
167 | + NULL, \ | ||
168 | + gen_helper_mve_##FN##h, \ | ||
169 | + gen_helper_mve_##FN##s, \ | ||
170 | + NULL, \ | ||
171 | + }; \ | ||
172 | + if (!dc_isar_feature(aa32_mve_fp, s)) { \ | ||
173 | + return false; \ | ||
174 | + } \ | ||
175 | + return do_vmaxv(s, a, fns[a->size]); \ | ||
60 | + } | 176 | + } |
61 | + address_space_stl_le(arm_addressspace(cs, attrs), physaddr, value, | ||
62 | + attrs, &txres); | ||
63 | + if (txres != MEMTX_OK) { | ||
64 | + /* BusFault trying to write the data */ | ||
65 | + qemu_log_mask(CPU_LOG_INT, "...BusFault with BFSR.STKERR\n"); | ||
66 | + env->v7m.cfsr[M_REG_NS] |= R_V7M_CFSR_STKERR_MASK; | ||
67 | + exc = ARMV7M_EXCP_BUS; | ||
68 | + exc_secure = false; | ||
69 | + goto pend_fault; | ||
70 | + } | ||
71 | + return true; | ||
72 | + | 177 | + |
73 | +pend_fault: | 178 | +DO_VMAXV_FP(VMAXNMV, vmaxnmv) |
74 | + /* By pending the exception at this point we are making | 179 | +DO_VMAXV_FP(VMINNMV, vminnmv) |
75 | + * the IMPDEF choice "overridden exceptions pended" (see the | 180 | +DO_VMAXV_FP(VMAXNMAV, vmaxnmav) |
76 | + * MergeExcInfo() pseudocode). The other choice would be to not | 181 | +DO_VMAXV_FP(VMINNMAV, vminnmav) |
77 | + * pend them now and then make a choice about which to throw away | ||
78 | + * later if we have two derived exceptions. | ||
79 | + * The only case when we must not pend the exception but instead | ||
80 | + * throw it away is if we are doing the push of the callee registers | ||
81 | + * and we've already generated a derived exception. Even in this | ||
82 | + * case we will still update the fault status registers. | ||
83 | + */ | ||
84 | + if (!ignfault) { | ||
85 | + armv7m_nvic_set_pending_derived(env->nvic, exc, exc_secure); | ||
86 | + } | ||
87 | + return false; | ||
88 | } | ||
89 | |||
90 | /* Return true if we're using the process stack pointer (not the MSP) */ | ||
91 | @@ -XXX,XX +XXX,XX @@ static bool v7m_push_stack(ARMCPU *cpu) | ||
92 | * should ignore further stack faults trying to process | ||
93 | * that derived exception.) | ||
94 | */ | ||
95 | + bool stacked_ok; | ||
96 | CPUARMState *env = &cpu->env; | ||
97 | uint32_t xpsr = xpsr_read(env); | ||
98 | + uint32_t frameptr = env->regs[13]; | ||
99 | + ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
100 | |||
101 | /* Align stack pointer if the guest wants that */ | ||
102 | - if ((env->regs[13] & 4) && | ||
103 | + if ((frameptr & 4) && | ||
104 | (env->v7m.ccr[env->v7m.secure] & R_V7M_CCR_STKALIGN_MASK)) { | ||
105 | - env->regs[13] -= 4; | ||
106 | + frameptr -= 4; | ||
107 | xpsr |= XPSR_SPREALIGN; | ||
108 | } | ||
109 | - /* Switch to the handler mode. */ | ||
110 | - v7m_push(env, xpsr); | ||
111 | - v7m_push(env, env->regs[15]); | ||
112 | - v7m_push(env, env->regs[14]); | ||
113 | - v7m_push(env, env->regs[12]); | ||
114 | - v7m_push(env, env->regs[3]); | ||
115 | - v7m_push(env, env->regs[2]); | ||
116 | - v7m_push(env, env->regs[1]); | ||
117 | - v7m_push(env, env->regs[0]); | ||
118 | |||
119 | - return false; | ||
120 | + frameptr -= 0x20; | ||
121 | + | 182 | + |
122 | + /* Write as much of the stack frame as we can. If we fail a stack | 183 | static bool do_vabav(DisasContext *s, arg_vabav *a, MVEGenVABAVFn *fn) |
123 | + * write this will result in a derived exception being pended | 184 | { |
124 | + * (which may be taken in preference to the one we started with | 185 | /* Absolute difference accumulated across vector */ |
125 | + * if it has higher priority). | ||
126 | + */ | ||
127 | + stacked_ok = | ||
128 | + v7m_stack_write(cpu, frameptr, env->regs[0], mmu_idx, false) && | ||
129 | + v7m_stack_write(cpu, frameptr + 4, env->regs[1], mmu_idx, false) && | ||
130 | + v7m_stack_write(cpu, frameptr + 8, env->regs[2], mmu_idx, false) && | ||
131 | + v7m_stack_write(cpu, frameptr + 12, env->regs[3], mmu_idx, false) && | ||
132 | + v7m_stack_write(cpu, frameptr + 16, env->regs[12], mmu_idx, false) && | ||
133 | + v7m_stack_write(cpu, frameptr + 20, env->regs[14], mmu_idx, false) && | ||
134 | + v7m_stack_write(cpu, frameptr + 24, env->regs[15], mmu_idx, false) && | ||
135 | + v7m_stack_write(cpu, frameptr + 28, xpsr, mmu_idx, false); | ||
136 | + | ||
137 | + /* Update SP regardless of whether any of the stack accesses failed. | ||
138 | + * When we implement v8M stack limit checking then this attempt to | ||
139 | + * update SP might also fail and result in a derived exception. | ||
140 | + */ | ||
141 | + env->regs[13] = frameptr; | ||
142 | + | ||
143 | + return !stacked_ok; | ||
144 | } | ||
145 | |||
146 | static void do_v7m_exception_exit(ARMCPU *cpu) | ||
147 | -- | 186 | -- |
148 | 2.16.1 | 187 | 2.20.1 |
149 | 188 | ||
150 | 189 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Implement the MVE fp vector comparisons VCMP and VPT. | |
2 | |||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | target/arm/helper-mve.h | 18 +++++++++++ | ||
7 | target/arm/mve.decode | 39 +++++++++++++++++++---- | ||
8 | target/arm/mve_helper.c | 64 ++++++++++++++++++++++++++++++++++++++ | ||
9 | target/arm/translate-mve.c | 22 +++++++++++++ | ||
10 | 4 files changed, 137 insertions(+), 6 deletions(-) | ||
11 | |||
12 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/arm/helper-mve.h | ||
15 | +++ b/target/arm/helper-mve.h | ||
16 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(mve_vcmple_scalarb, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
17 | DEF_HELPER_FLAGS_3(mve_vcmple_scalarh, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
18 | DEF_HELPER_FLAGS_3(mve_vcmple_scalarw, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
19 | |||
20 | +DEF_HELPER_FLAGS_3(mve_vfcmpeqh, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
21 | +DEF_HELPER_FLAGS_3(mve_vfcmpeqs, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
22 | + | ||
23 | +DEF_HELPER_FLAGS_3(mve_vfcmpneh, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
24 | +DEF_HELPER_FLAGS_3(mve_vfcmpnes, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
25 | + | ||
26 | +DEF_HELPER_FLAGS_3(mve_vfcmpgeh, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
27 | +DEF_HELPER_FLAGS_3(mve_vfcmpges, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
28 | + | ||
29 | +DEF_HELPER_FLAGS_3(mve_vfcmplth, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
30 | +DEF_HELPER_FLAGS_3(mve_vfcmplts, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
31 | + | ||
32 | +DEF_HELPER_FLAGS_3(mve_vfcmpgth, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
33 | +DEF_HELPER_FLAGS_3(mve_vfcmpgts, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
34 | + | ||
35 | +DEF_HELPER_FLAGS_3(mve_vfcmpleh, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
36 | +DEF_HELPER_FLAGS_3(mve_vfcmples, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
37 | + | ||
38 | DEF_HELPER_FLAGS_4(mve_vfadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
39 | DEF_HELPER_FLAGS_4(mve_vfadd_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
40 | |||
41 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/target/arm/mve.decode | ||
44 | +++ b/target/arm/mve.decode | ||
45 | @@ -XXX,XX +XXX,XX @@ | ||
46 | @vcmp_scalar .... .... .. size:2 qn:3 . .... .... .... rm:4 &vcmp_scalar \ | ||
47 | mask=%mask_22_13 | ||
48 | |||
49 | +@vcmp_fp .... .... .... qn:3 . .... .... .... .... &vcmp \ | ||
50 | + qm=%qm size=%2op_fp_scalar_size mask=%mask_22_13 | ||
51 | + | ||
52 | @vmaxv .... .... .... size:2 .. rda:4 .... .... .... &vmaxv qm=%qm | ||
53 | |||
54 | @2op_fp .... .... .... .... .... .... .... .... &2op \ | ||
55 | @@ -XXX,XX +XXX,XX @@ VSHLC 111 0 1110 1 . 1 imm:5 ... 0 1111 1100 rdm:4 qd=%qd | ||
56 | # Comparisons. We expand out the conditions which are split across | ||
57 | # encodings T1, T2, T3 and the fc bits. These include VPT, which is | ||
58 | # effectively "VCMP then VPST". A plain "VCMP" has a mask field of zero. | ||
59 | -VCMPEQ 1111 1110 0 . .. ... 1 ... 0 1111 0 0 . 0 ... 0 @vcmp | ||
60 | -VCMPNE 1111 1110 0 . .. ... 1 ... 0 1111 1 0 . 0 ... 0 @vcmp | ||
61 | +{ | ||
62 | + VCMPEQ_fp 111 . 1110 0 . 11 ... 1 ... 0 1111 0 0 . 0 ... 0 @vcmp_fp | ||
63 | + VCMPEQ 111 1 1110 0 . .. ... 1 ... 0 1111 0 0 . 0 ... 0 @vcmp | ||
64 | +} | ||
65 | + | ||
66 | +{ | ||
67 | + VCMPNE_fp 111 . 1110 0 . 11 ... 1 ... 0 1111 1 0 . 0 ... 0 @vcmp_fp | ||
68 | + VCMPNE 111 1 1110 0 . .. ... 1 ... 0 1111 1 0 . 0 ... 0 @vcmp | ||
69 | +} | ||
70 | + | ||
71 | +{ | ||
72 | + VCMPGE_fp 111 . 1110 0 . 11 ... 1 ... 1 1111 0 0 . 0 ... 0 @vcmp_fp | ||
73 | + VCMPGE 111 1 1110 0 . .. ... 1 ... 1 1111 0 0 . 0 ... 0 @vcmp | ||
74 | +} | ||
75 | + | ||
76 | +{ | ||
77 | + VCMPLT_fp 111 . 1110 0 . 11 ... 1 ... 1 1111 1 0 . 0 ... 0 @vcmp_fp | ||
78 | + VCMPLT 111 1 1110 0 . .. ... 1 ... 1 1111 1 0 . 0 ... 0 @vcmp | ||
79 | +} | ||
80 | + | ||
81 | +{ | ||
82 | + VCMPGT_fp 111 . 1110 0 . 11 ... 1 ... 1 1111 0 0 . 0 ... 1 @vcmp_fp | ||
83 | + VCMPGT 111 1 1110 0 . .. ... 1 ... 1 1111 0 0 . 0 ... 1 @vcmp | ||
84 | +} | ||
85 | + | ||
86 | +{ | ||
87 | + VCMPLE_fp 111 . 1110 0 . 11 ... 1 ... 1 1111 1 0 . 0 ... 1 @vcmp_fp | ||
88 | + VCMPLE 1111 1110 0 . .. ... 1 ... 1 1111 1 0 . 0 ... 1 @vcmp | ||
89 | +} | ||
90 | + | ||
91 | { | ||
92 | VPSEL 1111 1110 0 . 11 ... 1 ... 0 1111 . 0 . 0 ... 1 @2op_nosz | ||
93 | VCMPCS 1111 1110 0 . .. ... 1 ... 0 1111 0 0 . 0 ... 1 @vcmp | ||
94 | VCMPHI 1111 1110 0 . .. ... 1 ... 0 1111 1 0 . 0 ... 1 @vcmp | ||
95 | } | ||
96 | -VCMPGE 1111 1110 0 . .. ... 1 ... 1 1111 0 0 . 0 ... 0 @vcmp | ||
97 | -VCMPLT 1111 1110 0 . .. ... 1 ... 1 1111 1 0 . 0 ... 0 @vcmp | ||
98 | -VCMPGT 1111 1110 0 . .. ... 1 ... 1 1111 0 0 . 0 ... 1 @vcmp | ||
99 | -VCMPLE 1111 1110 0 . .. ... 1 ... 1 1111 1 0 . 0 ... 1 @vcmp | ||
100 | |||
101 | { | ||
102 | VPNOT 1111 1110 0 0 11 000 1 000 0 1111 0100 1101 | ||
103 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
104 | index XXXXXXX..XXXXXXX 100644 | ||
105 | --- a/target/arm/mve_helper.c | ||
106 | +++ b/target/arm/mve_helper.c | ||
107 | @@ -XXX,XX +XXX,XX @@ DO_FP_VMAXMINV(vmaxnmavh, 2, float16, true, float16_maxnum) | ||
108 | DO_FP_VMAXMINV(vmaxnmavs, 4, float32, true, float32_maxnum) | ||
109 | DO_FP_VMAXMINV(vminnmavh, 2, float16, true, float16_minnum) | ||
110 | DO_FP_VMAXMINV(vminnmavs, 4, float32, true, float32_minnum) | ||
111 | + | ||
112 | +/* FP compares; note that all comparisons signal InvalidOp for QNaNs */ | ||
113 | +#define DO_VCMP_FP(OP, ESIZE, TYPE, FN) \ | ||
114 | + void HELPER(glue(mve_, OP))(CPUARMState *env, void *vn, void *vm) \ | ||
115 | + { \ | ||
116 | + TYPE *n = vn, *m = vm; \ | ||
117 | + uint16_t mask = mve_element_mask(env); \ | ||
118 | + uint16_t eci_mask = mve_eci_mask(env); \ | ||
119 | + uint16_t beatpred = 0; \ | ||
120 | + uint16_t emask = MAKE_64BIT_MASK(0, ESIZE); \ | ||
121 | + unsigned e; \ | ||
122 | + float_status *fpst; \ | ||
123 | + float_status scratch_fpst; \ | ||
124 | + bool r; \ | ||
125 | + for (e = 0; e < 16 / ESIZE; e++, emask <<= ESIZE) { \ | ||
126 | + if ((mask & emask) == 0) { \ | ||
127 | + continue; \ | ||
128 | + } \ | ||
129 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | ||
130 | + &env->vfp.standard_fp_status; \ | ||
131 | + if (!(mask & (1 << (e * ESIZE)))) { \ | ||
132 | + /* We need the result but without updating flags */ \ | ||
133 | + scratch_fpst = *fpst; \ | ||
134 | + fpst = &scratch_fpst; \ | ||
135 | + } \ | ||
136 | + r = FN(n[H##ESIZE(e)], m[H##ESIZE(e)], fpst); \ | ||
137 | + /* Comparison sets 0/1 bits for each byte in the element */ \ | ||
138 | + beatpred |= r * emask; \ | ||
139 | + } \ | ||
140 | + beatpred &= mask; \ | ||
141 | + env->v7m.vpr = (env->v7m.vpr & ~(uint32_t)eci_mask) | \ | ||
142 | + (beatpred & eci_mask); \ | ||
143 | + mve_advance_vpt(env); \ | ||
144 | + } | ||
145 | + | ||
146 | +/* | ||
147 | + * Some care is needed here to get the correct result for the unordered case. | ||
148 | + * Architecturally EQ, GE and GT are defined to be false for unordered, but | ||
149 | + * the NE, LT and LE comparisons are defined as simple logical inverses of | ||
150 | + * EQ, GE and GT and so they must return true for unordered. The softfloat | ||
151 | + * comparison functions float*_{eq,le,lt} all return false for unordered. | ||
152 | + */ | ||
153 | +#define DO_GE16(X, Y, S) float16_le(Y, X, S) | ||
154 | +#define DO_GE32(X, Y, S) float32_le(Y, X, S) | ||
155 | +#define DO_GT16(X, Y, S) float16_lt(Y, X, S) | ||
156 | +#define DO_GT32(X, Y, S) float32_lt(Y, X, S) | ||
157 | + | ||
158 | +DO_VCMP_FP(vfcmpeqh, 2, float16, float16_eq) | ||
159 | +DO_VCMP_FP(vfcmpeqs, 4, float32, float32_eq) | ||
160 | + | ||
161 | +DO_VCMP_FP(vfcmpneh, 2, float16, !float16_eq) | ||
162 | +DO_VCMP_FP(vfcmpnes, 4, float32, !float32_eq) | ||
163 | + | ||
164 | +DO_VCMP_FP(vfcmpgeh, 2, float16, DO_GE16) | ||
165 | +DO_VCMP_FP(vfcmpges, 4, float32, DO_GE32) | ||
166 | + | ||
167 | +DO_VCMP_FP(vfcmplth, 2, float16, !DO_GE16) | ||
168 | +DO_VCMP_FP(vfcmplts, 4, float32, !DO_GE32) | ||
169 | + | ||
170 | +DO_VCMP_FP(vfcmpgth, 2, float16, DO_GT16) | ||
171 | +DO_VCMP_FP(vfcmpgts, 4, float32, DO_GT32) | ||
172 | + | ||
173 | +DO_VCMP_FP(vfcmpleh, 2, float16, !DO_GT16) | ||
174 | +DO_VCMP_FP(vfcmples, 4, float32, !DO_GT32) | ||
175 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
176 | index XXXXXXX..XXXXXXX 100644 | ||
177 | --- a/target/arm/translate-mve.c | ||
178 | +++ b/target/arm/translate-mve.c | ||
179 | @@ -XXX,XX +XXX,XX @@ DO_VCMP(VCMPLT, vcmplt) | ||
180 | DO_VCMP(VCMPGT, vcmpgt) | ||
181 | DO_VCMP(VCMPLE, vcmple) | ||
182 | |||
183 | +#define DO_VCMP_FP(INSN, FN) \ | ||
184 | + static bool trans_##INSN(DisasContext *s, arg_vcmp *a) \ | ||
185 | + { \ | ||
186 | + static MVEGenCmpFn * const fns[] = { \ | ||
187 | + NULL, \ | ||
188 | + gen_helper_mve_##FN##h, \ | ||
189 | + gen_helper_mve_##FN##s, \ | ||
190 | + NULL, \ | ||
191 | + }; \ | ||
192 | + if (!dc_isar_feature(aa32_mve_fp, s)) { \ | ||
193 | + return false; \ | ||
194 | + } \ | ||
195 | + return do_vcmp(s, a, fns[a->size]); \ | ||
196 | + } | ||
197 | + | ||
198 | +DO_VCMP_FP(VCMPEQ_fp, vfcmpeq) | ||
199 | +DO_VCMP_FP(VCMPNE_fp, vfcmpne) | ||
200 | +DO_VCMP_FP(VCMPGE_fp, vfcmpge) | ||
201 | +DO_VCMP_FP(VCMPLT_fp, vfcmplt) | ||
202 | +DO_VCMP_FP(VCMPGT_fp, vfcmpgt) | ||
203 | +DO_VCMP_FP(VCMPLE_fp, vfcmple) | ||
204 | + | ||
205 | static bool do_vmaxv(DisasContext *s, arg_vmaxv *a, MVEGenVADDVFn fn) | ||
206 | { | ||
207 | /* | ||
208 | -- | ||
209 | 2.20.1 | ||
210 | |||
211 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Implement the MVE fp scalar comparisons VCMP and VPT. | |
2 | |||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | target/arm/helper-mve.h | 18 +++++++++++ | ||
7 | target/arm/mve.decode | 61 +++++++++++++++++++++++++++++-------- | ||
8 | target/arm/mve_helper.c | 62 ++++++++++++++++++++++++++++++-------- | ||
9 | target/arm/translate-mve.c | 14 +++++++++ | ||
10 | 4 files changed, 131 insertions(+), 24 deletions(-) | ||
11 | |||
12 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/target/arm/helper-mve.h | ||
15 | +++ b/target/arm/helper-mve.h | ||
16 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(mve_vfcmpgts, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
17 | DEF_HELPER_FLAGS_3(mve_vfcmpleh, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
18 | DEF_HELPER_FLAGS_3(mve_vfcmples, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
19 | |||
20 | +DEF_HELPER_FLAGS_3(mve_vfcmpeq_scalarh, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
21 | +DEF_HELPER_FLAGS_3(mve_vfcmpeq_scalars, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
22 | + | ||
23 | +DEF_HELPER_FLAGS_3(mve_vfcmpne_scalarh, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
24 | +DEF_HELPER_FLAGS_3(mve_vfcmpne_scalars, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
25 | + | ||
26 | +DEF_HELPER_FLAGS_3(mve_vfcmpge_scalarh, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
27 | +DEF_HELPER_FLAGS_3(mve_vfcmpge_scalars, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
28 | + | ||
29 | +DEF_HELPER_FLAGS_3(mve_vfcmplt_scalarh, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
30 | +DEF_HELPER_FLAGS_3(mve_vfcmplt_scalars, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
31 | + | ||
32 | +DEF_HELPER_FLAGS_3(mve_vfcmpgt_scalarh, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
33 | +DEF_HELPER_FLAGS_3(mve_vfcmpgt_scalars, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
34 | + | ||
35 | +DEF_HELPER_FLAGS_3(mve_vfcmple_scalarh, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
36 | +DEF_HELPER_FLAGS_3(mve_vfcmple_scalars, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
37 | + | ||
38 | DEF_HELPER_FLAGS_4(mve_vfadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
39 | DEF_HELPER_FLAGS_4(mve_vfadd_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
40 | |||
41 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/target/arm/mve.decode | ||
44 | +++ b/target/arm/mve.decode | ||
45 | @@ -XXX,XX +XXX,XX @@ | ||
46 | @vcmp_fp .... .... .... qn:3 . .... .... .... .... &vcmp \ | ||
47 | qm=%qm size=%2op_fp_scalar_size mask=%mask_22_13 | ||
48 | |||
49 | +# Bit 28 is a 2op_fp_scalar_size bit, but we do not decode it in this | ||
50 | +# format to avoid complicated overlapping-instruction-groups | ||
51 | +@vcmp_fp_scalar .... .... .... qn:3 . .... .... .... rm:4 &vcmp_scalar \ | ||
52 | + mask=%mask_22_13 | ||
53 | + | ||
54 | @vmaxv .... .... .... size:2 .. rda:4 .... .... .... &vmaxv qm=%qm | ||
55 | |||
56 | @2op_fp .... .... .... .... .... .... .... .... &2op \ | ||
57 | @@ -XXX,XX +XXX,XX @@ VDUP 1110 1110 1 0 10 ... 0 .... 1011 . 0 0 1 0000 @vdup size=2 | ||
58 | VIWDUP 1110 1110 0 . .. ... 1 ... 0 1111 . 110 ... . @viwdup | ||
59 | } | ||
60 | { | ||
61 | - VDDUP 1110 1110 0 . .. ... 1 ... 1 1111 . 110 111 . @vidup | ||
62 | - VDWDUP 1110 1110 0 . .. ... 1 ... 1 1111 . 110 ... . @viwdup | ||
63 | + VCMPGT_fp_scalar 1110 1110 0 . 11 ... 1 ... 1 1111 0110 .... @vcmp_fp_scalar size=2 | ||
64 | + VCMPLE_fp_scalar 1110 1110 0 . 11 ... 1 ... 1 1111 1110 .... @vcmp_fp_scalar size=2 | ||
65 | + VDDUP 1110 1110 0 . .. ... 1 ... 1 1111 . 110 111 . @vidup | ||
66 | + VDWDUP 1110 1110 0 . .. ... 1 ... 1 1111 . 110 ... . @viwdup | ||
67 | } | ||
68 | |||
69 | # multiply-add long dual accumulate | ||
70 | @@ -XXX,XX +XXX,XX @@ VMLADAV_U 1111 1110 1111 ... 0 ... . 1111 . 0 . 0 ... 1 @vmladav_nosz | ||
71 | |||
72 | # Scalar operations | ||
73 | |||
74 | -VADD_scalar 1110 1110 0 . .. ... 1 ... 0 1111 . 100 .... @2scalar | ||
75 | -VSUB_scalar 1110 1110 0 . .. ... 1 ... 1 1111 . 100 .... @2scalar | ||
76 | +{ | ||
77 | + VCMPEQ_fp_scalar 1110 1110 0 . 11 ... 1 ... 0 1111 0100 .... @vcmp_fp_scalar size=2 | ||
78 | + VCMPNE_fp_scalar 1110 1110 0 . 11 ... 1 ... 0 1111 1100 .... @vcmp_fp_scalar size=2 | ||
79 | + VADD_scalar 1110 1110 0 . .. ... 1 ... 0 1111 . 100 .... @2scalar | ||
80 | +} | ||
81 | + | ||
82 | +{ | ||
83 | + VCMPLT_fp_scalar 1110 1110 0 . 11 ... 1 ... 1 1111 1100 .... @vcmp_fp_scalar size=2 | ||
84 | + VCMPGE_fp_scalar 1110 1110 0 . 11 ... 1 ... 1 1111 0100 .... @vcmp_fp_scalar size=2 | ||
85 | + VSUB_scalar 1110 1110 0 . .. ... 1 ... 1 1111 . 100 .... @2scalar | ||
86 | +} | ||
87 | |||
88 | { | ||
89 | VSHL_S_scalar 1110 1110 0 . 11 .. 01 ... 1 1110 0110 .... @shl_scalar | ||
90 | @@ -XXX,XX +XXX,XX @@ VSHLC 111 0 1110 1 . 1 imm:5 ... 0 1111 1100 rdm:4 qd=%qd | ||
91 | } | ||
92 | |||
93 | { | ||
94 | - VPNOT 1111 1110 0 0 11 000 1 000 0 1111 0100 1101 | ||
95 | - VPST 1111 1110 0 . 11 000 1 ... 0 1111 0100 1101 mask=%mask_22_13 | ||
96 | - VCMPEQ_scalar 1111 1110 0 . .. ... 1 ... 0 1111 0 1 0 0 .... @vcmp_scalar | ||
97 | + VPNOT 1111 1110 0 0 11 000 1 000 0 1111 0100 1101 | ||
98 | + VPST 1111 1110 0 . 11 000 1 ... 0 1111 0100 1101 mask=%mask_22_13 | ||
99 | + VCMPEQ_fp_scalar 1111 1110 0 . 11 ... 1 ... 0 1111 0100 .... @vcmp_fp_scalar size=1 | ||
100 | + VCMPEQ_scalar 1111 1110 0 . .. ... 1 ... 0 1111 0100 .... @vcmp_scalar | ||
101 | } | ||
102 | -VCMPNE_scalar 1111 1110 0 . .. ... 1 ... 0 1111 1 1 0 0 .... @vcmp_scalar | ||
103 | + | ||
104 | +{ | ||
105 | + VCMPNE_fp_scalar 1111 1110 0 . 11 ... 1 ... 0 1111 1100 .... @vcmp_fp_scalar size=1 | ||
106 | + VCMPNE_scalar 1111 1110 0 . .. ... 1 ... 0 1111 1100 .... @vcmp_scalar | ||
107 | +} | ||
108 | + | ||
109 | +{ | ||
110 | + VCMPGT_fp_scalar 1111 1110 0 . 11 ... 1 ... 1 1111 0110 .... @vcmp_fp_scalar size=1 | ||
111 | + VCMPGT_scalar 1111 1110 0 . .. ... 1 ... 1 1111 0110 .... @vcmp_scalar | ||
112 | +} | ||
113 | + | ||
114 | +{ | ||
115 | + VCMPLE_fp_scalar 1111 1110 0 . 11 ... 1 ... 1 1111 1110 .... @vcmp_fp_scalar size=1 | ||
116 | + VCMPLE_scalar 1111 1110 0 . .. ... 1 ... 1 1111 1110 .... @vcmp_scalar | ||
117 | +} | ||
118 | + | ||
119 | +{ | ||
120 | + VCMPGE_fp_scalar 1111 1110 0 . 11 ... 1 ... 1 1111 0100 .... @vcmp_fp_scalar size=1 | ||
121 | + VCMPGE_scalar 1111 1110 0 . .. ... 1 ... 1 1111 0100 .... @vcmp_scalar | ||
122 | +} | ||
123 | +{ | ||
124 | + VCMPLT_fp_scalar 1111 1110 0 . 11 ... 1 ... 1 1111 1100 .... @vcmp_fp_scalar size=1 | ||
125 | + VCMPLT_scalar 1111 1110 0 . .. ... 1 ... 1 1111 1100 .... @vcmp_scalar | ||
126 | +} | ||
127 | + | ||
128 | VCMPCS_scalar 1111 1110 0 . .. ... 1 ... 0 1111 0 1 1 0 .... @vcmp_scalar | ||
129 | VCMPHI_scalar 1111 1110 0 . .. ... 1 ... 0 1111 1 1 1 0 .... @vcmp_scalar | ||
130 | -VCMPGE_scalar 1111 1110 0 . .. ... 1 ... 1 1111 0 1 0 0 .... @vcmp_scalar | ||
131 | -VCMPLT_scalar 1111 1110 0 . .. ... 1 ... 1 1111 1 1 0 0 .... @vcmp_scalar | ||
132 | -VCMPGT_scalar 1111 1110 0 . .. ... 1 ... 1 1111 0 1 1 0 .... @vcmp_scalar | ||
133 | -VCMPLE_scalar 1111 1110 0 . .. ... 1 ... 1 1111 1 1 1 0 .... @vcmp_scalar | ||
134 | |||
135 | # 2-operand FP | ||
136 | VADD_fp 1110 1111 0 . 0 . ... 0 ... 0 1101 . 1 . 0 ... 0 @2op_fp | ||
137 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
138 | index XXXXXXX..XXXXXXX 100644 | ||
139 | --- a/target/arm/mve_helper.c | ||
140 | +++ b/target/arm/mve_helper.c | ||
141 | @@ -XXX,XX +XXX,XX @@ DO_FP_VMAXMINV(vminnmavs, 4, float32, true, float32_minnum) | ||
142 | mve_advance_vpt(env); \ | ||
143 | } | ||
144 | |||
145 | +#define DO_VCMP_FP_SCALAR(OP, ESIZE, TYPE, FN) \ | ||
146 | + void HELPER(glue(mve_, OP))(CPUARMState *env, void *vn, \ | ||
147 | + uint32_t rm) \ | ||
148 | + { \ | ||
149 | + TYPE *n = vn; \ | ||
150 | + uint16_t mask = mve_element_mask(env); \ | ||
151 | + uint16_t eci_mask = mve_eci_mask(env); \ | ||
152 | + uint16_t beatpred = 0; \ | ||
153 | + uint16_t emask = MAKE_64BIT_MASK(0, ESIZE); \ | ||
154 | + unsigned e; \ | ||
155 | + float_status *fpst; \ | ||
156 | + float_status scratch_fpst; \ | ||
157 | + bool r; \ | ||
158 | + for (e = 0; e < 16 / ESIZE; e++, emask <<= ESIZE) { \ | ||
159 | + if ((mask & emask) == 0) { \ | ||
160 | + continue; \ | ||
161 | + } \ | ||
162 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | ||
163 | + &env->vfp.standard_fp_status; \ | ||
164 | + if (!(mask & (1 << (e * ESIZE)))) { \ | ||
165 | + /* We need the result but without updating flags */ \ | ||
166 | + scratch_fpst = *fpst; \ | ||
167 | + fpst = &scratch_fpst; \ | ||
168 | + } \ | ||
169 | + r = FN(n[H##ESIZE(e)], (TYPE)rm, fpst); \ | ||
170 | + /* Comparison sets 0/1 bits for each byte in the element */ \ | ||
171 | + beatpred |= r * emask; \ | ||
172 | + } \ | ||
173 | + beatpred &= mask; \ | ||
174 | + env->v7m.vpr = (env->v7m.vpr & ~(uint32_t)eci_mask) | \ | ||
175 | + (beatpred & eci_mask); \ | ||
176 | + mve_advance_vpt(env); \ | ||
177 | + } | ||
178 | + | ||
179 | +#define DO_VCMP_FP_BOTH(VOP, SOP, ESIZE, TYPE, FN) \ | ||
180 | + DO_VCMP_FP(VOP, ESIZE, TYPE, FN) \ | ||
181 | + DO_VCMP_FP_SCALAR(SOP, ESIZE, TYPE, FN) | ||
182 | + | ||
183 | /* | ||
184 | * Some care is needed here to get the correct result for the unordered case. | ||
185 | * Architecturally EQ, GE and GT are defined to be false for unordered, but | ||
186 | @@ -XXX,XX +XXX,XX @@ DO_FP_VMAXMINV(vminnmavs, 4, float32, true, float32_minnum) | ||
187 | #define DO_GT16(X, Y, S) float16_lt(Y, X, S) | ||
188 | #define DO_GT32(X, Y, S) float32_lt(Y, X, S) | ||
189 | |||
190 | -DO_VCMP_FP(vfcmpeqh, 2, float16, float16_eq) | ||
191 | -DO_VCMP_FP(vfcmpeqs, 4, float32, float32_eq) | ||
192 | +DO_VCMP_FP_BOTH(vfcmpeqh, vfcmpeq_scalarh, 2, float16, float16_eq) | ||
193 | +DO_VCMP_FP_BOTH(vfcmpeqs, vfcmpeq_scalars, 4, float32, float32_eq) | ||
194 | |||
195 | -DO_VCMP_FP(vfcmpneh, 2, float16, !float16_eq) | ||
196 | -DO_VCMP_FP(vfcmpnes, 4, float32, !float32_eq) | ||
197 | +DO_VCMP_FP_BOTH(vfcmpneh, vfcmpne_scalarh, 2, float16, !float16_eq) | ||
198 | +DO_VCMP_FP_BOTH(vfcmpnes, vfcmpne_scalars, 4, float32, !float32_eq) | ||
199 | |||
200 | -DO_VCMP_FP(vfcmpgeh, 2, float16, DO_GE16) | ||
201 | -DO_VCMP_FP(vfcmpges, 4, float32, DO_GE32) | ||
202 | +DO_VCMP_FP_BOTH(vfcmpgeh, vfcmpge_scalarh, 2, float16, DO_GE16) | ||
203 | +DO_VCMP_FP_BOTH(vfcmpges, vfcmpge_scalars, 4, float32, DO_GE32) | ||
204 | |||
205 | -DO_VCMP_FP(vfcmplth, 2, float16, !DO_GE16) | ||
206 | -DO_VCMP_FP(vfcmplts, 4, float32, !DO_GE32) | ||
207 | +DO_VCMP_FP_BOTH(vfcmplth, vfcmplt_scalarh, 2, float16, !DO_GE16) | ||
208 | +DO_VCMP_FP_BOTH(vfcmplts, vfcmplt_scalars, 4, float32, !DO_GE32) | ||
209 | |||
210 | -DO_VCMP_FP(vfcmpgth, 2, float16, DO_GT16) | ||
211 | -DO_VCMP_FP(vfcmpgts, 4, float32, DO_GT32) | ||
212 | +DO_VCMP_FP_BOTH(vfcmpgth, vfcmpgt_scalarh, 2, float16, DO_GT16) | ||
213 | +DO_VCMP_FP_BOTH(vfcmpgts, vfcmpgt_scalars, 4, float32, DO_GT32) | ||
214 | |||
215 | -DO_VCMP_FP(vfcmpleh, 2, float16, !DO_GT16) | ||
216 | -DO_VCMP_FP(vfcmples, 4, float32, !DO_GT32) | ||
217 | +DO_VCMP_FP_BOTH(vfcmpleh, vfcmple_scalarh, 2, float16, !DO_GT16) | ||
218 | +DO_VCMP_FP_BOTH(vfcmples, vfcmple_scalars, 4, float32, !DO_GT32) | ||
219 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
220 | index XXXXXXX..XXXXXXX 100644 | ||
221 | --- a/target/arm/translate-mve.c | ||
222 | +++ b/target/arm/translate-mve.c | ||
223 | @@ -XXX,XX +XXX,XX @@ DO_VCMP(VCMPLE, vcmple) | ||
224 | return false; \ | ||
225 | } \ | ||
226 | return do_vcmp(s, a, fns[a->size]); \ | ||
227 | + } \ | ||
228 | + static bool trans_##INSN##_scalar(DisasContext *s, \ | ||
229 | + arg_vcmp_scalar *a) \ | ||
230 | + { \ | ||
231 | + static MVEGenScalarCmpFn * const fns[] = { \ | ||
232 | + NULL, \ | ||
233 | + gen_helper_mve_##FN##_scalarh, \ | ||
234 | + gen_helper_mve_##FN##_scalars, \ | ||
235 | + NULL, \ | ||
236 | + }; \ | ||
237 | + if (!dc_isar_feature(aa32_mve_fp, s)) { \ | ||
238 | + return false; \ | ||
239 | + } \ | ||
240 | + return do_vcmp_scalar(s, a, fns[a->size]); \ | ||
241 | } | ||
242 | |||
243 | DO_VCMP_FP(VCMPEQ_fp, vfcmpeq) | ||
244 | -- | ||
245 | 2.20.1 | ||
246 | |||
247 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Implement the MVE VCVT insns which convert between floating and fixed | ||
2 | point. As with the Neon equivalents, these use essentially the same | ||
3 | constant encoding as right-shift-by-immediate. | ||
1 | 4 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | --- | ||
8 | target/arm/helper-mve.h | 9 +++++++++ | ||
9 | target/arm/mve.decode | 19 +++++++++++++++++++ | ||
10 | target/arm/mve_helper.c | 36 ++++++++++++++++++++++++++++++++++++ | ||
11 | target/arm/translate-mve.c | 18 ++++++++++++++++++ | ||
12 | 4 files changed, 82 insertions(+) | ||
13 | |||
14 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/target/arm/helper-mve.h | ||
17 | +++ b/target/arm/helper-mve.h | ||
18 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vfma_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
19 | |||
20 | DEF_HELPER_FLAGS_4(mve_vfmas_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
21 | DEF_HELPER_FLAGS_4(mve_vfmas_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
22 | + | ||
23 | +DEF_HELPER_FLAGS_4(mve_vcvt_sh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
24 | +DEF_HELPER_FLAGS_4(mve_vcvt_uh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
25 | +DEF_HELPER_FLAGS_4(mve_vcvt_hs, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
26 | +DEF_HELPER_FLAGS_4(mve_vcvt_hu, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
27 | +DEF_HELPER_FLAGS_4(mve_vcvt_sf, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
28 | +DEF_HELPER_FLAGS_4(mve_vcvt_uf, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
29 | +DEF_HELPER_FLAGS_4(mve_vcvt_fs, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
30 | +DEF_HELPER_FLAGS_4(mve_vcvt_fu, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
31 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/arm/mve.decode | ||
34 | +++ b/target/arm/mve.decode | ||
35 | @@ -XXX,XX +XXX,XX @@ VCMLA0 1111 110 00 . 1 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_ | ||
36 | VCMLA90 1111 110 01 . 1 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
37 | VCMLA180 1111 110 10 . 1 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
38 | VCMLA270 1111 110 11 . 1 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | ||
39 | + | ||
40 | +# floating-point <-> fixed-point conversions. Naming convention: | ||
41 | +# VCVT_<from><to>, S = signed int, U = unsigned int, H = halfprec, F = singleprec | ||
42 | +@vcvt .... .... .. 1 ..... .... .. 1 . .... .... &2shift \ | ||
43 | + qd=%qd qm=%qm shift=%rshift_i5 size=2 | ||
44 | +@vcvt_f16 .... .... .. 11 .... .... .. 0 . .... .... &2shift \ | ||
45 | + qd=%qd qm=%qm shift=%rshift_i4 size=1 | ||
46 | + | ||
47 | +VCVT_SH_fixed 1110 1111 1 . ...... ... 0 11 . 0 01 . 1 ... 0 @vcvt_f16 | ||
48 | +VCVT_UH_fixed 1111 1111 1 . ...... ... 0 11 . 0 01 . 1 ... 0 @vcvt_f16 | ||
49 | + | ||
50 | +VCVT_HS_fixed 1110 1111 1 . ...... ... 0 11 . 1 01 . 1 ... 0 @vcvt_f16 | ||
51 | +VCVT_HU_fixed 1111 1111 1 . ...... ... 0 11 . 1 01 . 1 ... 0 @vcvt_f16 | ||
52 | + | ||
53 | +VCVT_SF_fixed 1110 1111 1 . ...... ... 0 11 . 0 01 . 1 ... 0 @vcvt | ||
54 | +VCVT_UF_fixed 1111 1111 1 . ...... ... 0 11 . 0 01 . 1 ... 0 @vcvt | ||
55 | + | ||
56 | +VCVT_FS_fixed 1110 1111 1 . ...... ... 0 11 . 1 01 . 1 ... 0 @vcvt | ||
57 | +VCVT_FU_fixed 1111 1111 1 . ...... ... 0 11 . 1 01 . 1 ... 0 @vcvt | ||
58 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/target/arm/mve_helper.c | ||
61 | +++ b/target/arm/mve_helper.c | ||
62 | @@ -XXX,XX +XXX,XX @@ DO_VCMP_FP_BOTH(vfcmpgts, vfcmpgt_scalars, 4, float32, DO_GT32) | ||
63 | |||
64 | DO_VCMP_FP_BOTH(vfcmpleh, vfcmple_scalarh, 2, float16, !DO_GT16) | ||
65 | DO_VCMP_FP_BOTH(vfcmples, vfcmple_scalars, 4, float32, !DO_GT32) | ||
66 | + | ||
67 | +#define DO_VCVT_FIXED(OP, ESIZE, TYPE, FN) \ | ||
68 | + void HELPER(glue(mve_, OP))(CPUARMState *env, void *vd, void *vm, \ | ||
69 | + uint32_t shift) \ | ||
70 | + { \ | ||
71 | + TYPE *d = vd, *m = vm; \ | ||
72 | + TYPE r; \ | ||
73 | + uint16_t mask = mve_element_mask(env); \ | ||
74 | + unsigned e; \ | ||
75 | + float_status *fpst; \ | ||
76 | + float_status scratch_fpst; \ | ||
77 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ | ||
78 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ | ||
79 | + continue; \ | ||
80 | + } \ | ||
81 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | ||
82 | + &env->vfp.standard_fp_status; \ | ||
83 | + if (!(mask & 1)) { \ | ||
84 | + /* We need the result but without updating flags */ \ | ||
85 | + scratch_fpst = *fpst; \ | ||
86 | + fpst = &scratch_fpst; \ | ||
87 | + } \ | ||
88 | + r = FN(m[H##ESIZE(e)], shift, fpst); \ | ||
89 | + mergemask(&d[H##ESIZE(e)], r, mask); \ | ||
90 | + } \ | ||
91 | + mve_advance_vpt(env); \ | ||
92 | + } | ||
93 | + | ||
94 | +DO_VCVT_FIXED(vcvt_sh, 2, int16_t, helper_vfp_shtoh) | ||
95 | +DO_VCVT_FIXED(vcvt_uh, 2, uint16_t, helper_vfp_uhtoh) | ||
96 | +DO_VCVT_FIXED(vcvt_hs, 2, int16_t, helper_vfp_toshh_round_to_zero) | ||
97 | +DO_VCVT_FIXED(vcvt_hu, 2, uint16_t, helper_vfp_touhh_round_to_zero) | ||
98 | +DO_VCVT_FIXED(vcvt_sf, 4, int32_t, helper_vfp_sltos) | ||
99 | +DO_VCVT_FIXED(vcvt_uf, 4, uint32_t, helper_vfp_ultos) | ||
100 | +DO_VCVT_FIXED(vcvt_fs, 4, int32_t, helper_vfp_tosls_round_to_zero) | ||
101 | +DO_VCVT_FIXED(vcvt_fu, 4, uint32_t, helper_vfp_touls_round_to_zero) | ||
102 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
103 | index XXXXXXX..XXXXXXX 100644 | ||
104 | --- a/target/arm/translate-mve.c | ||
105 | +++ b/target/arm/translate-mve.c | ||
106 | @@ -XXX,XX +XXX,XX @@ DO_2SHIFT(VRSHRI_U, vrshli_u, true) | ||
107 | DO_2SHIFT(VSRI, vsri, false) | ||
108 | DO_2SHIFT(VSLI, vsli, false) | ||
109 | |||
110 | +#define DO_2SHIFT_FP(INSN, FN) \ | ||
111 | + static bool trans_##INSN(DisasContext *s, arg_2shift *a) \ | ||
112 | + { \ | ||
113 | + if (!dc_isar_feature(aa32_mve_fp, s)) { \ | ||
114 | + return false; \ | ||
115 | + } \ | ||
116 | + return do_2shift(s, a, gen_helper_mve_##FN, false); \ | ||
117 | + } | ||
118 | + | ||
119 | +DO_2SHIFT_FP(VCVT_SH_fixed, vcvt_sh) | ||
120 | +DO_2SHIFT_FP(VCVT_UH_fixed, vcvt_uh) | ||
121 | +DO_2SHIFT_FP(VCVT_HS_fixed, vcvt_hs) | ||
122 | +DO_2SHIFT_FP(VCVT_HU_fixed, vcvt_hu) | ||
123 | +DO_2SHIFT_FP(VCVT_SF_fixed, vcvt_sf) | ||
124 | +DO_2SHIFT_FP(VCVT_UF_fixed, vcvt_uf) | ||
125 | +DO_2SHIFT_FP(VCVT_FS_fixed, vcvt_fs) | ||
126 | +DO_2SHIFT_FP(VCVT_FU_fixed, vcvt_fu) | ||
127 | + | ||
128 | static bool do_2shift_scalar(DisasContext *s, arg_shl_scalar *a, | ||
129 | MVEGenTwoOpShiftFn *fn) | ||
130 | { | ||
131 | -- | ||
132 | 2.20.1 | ||
133 | |||
134 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Implement the MVE "VCVT (between floating-point and integer)" insn. | ||
1 | 2 | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | --- | ||
6 | target/arm/mve.decode | 7 +++++++ | ||
7 | target/arm/translate-mve.c | 32 ++++++++++++++++++++++++++++++++ | ||
8 | 2 files changed, 39 insertions(+) | ||
9 | |||
10 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
11 | index XXXXXXX..XXXXXXX 100644 | ||
12 | --- a/target/arm/mve.decode | ||
13 | +++ b/target/arm/mve.decode | ||
14 | @@ -XXX,XX +XXX,XX @@ VCVT_UF_fixed 1111 1111 1 . ...... ... 0 11 . 0 01 . 1 ... 0 @vcvt | ||
15 | |||
16 | VCVT_FS_fixed 1110 1111 1 . ...... ... 0 11 . 1 01 . 1 ... 0 @vcvt | ||
17 | VCVT_FU_fixed 1111 1111 1 . ...... ... 0 11 . 1 01 . 1 ... 0 @vcvt | ||
18 | + | ||
19 | +# VCVT between floating point and integer (halfprec and single); | ||
20 | +# VCVT_<from><to>, S = signed int, U = unsigned int, F = float | ||
21 | +VCVT_SF 1111 1111 1 . 11 .. 11 ... 0 011 00 1 . 0 ... 0 @1op | ||
22 | +VCVT_UF 1111 1111 1 . 11 .. 11 ... 0 011 01 1 . 0 ... 0 @1op | ||
23 | +VCVT_FS 1111 1111 1 . 11 .. 11 ... 0 011 10 1 . 0 ... 0 @1op | ||
24 | +VCVT_FU 1111 1111 1 . 11 .. 11 ... 0 011 11 1 . 0 ... 0 @1op | ||
25 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/target/arm/translate-mve.c | ||
28 | +++ b/target/arm/translate-mve.c | ||
29 | @@ -XXX,XX +XXX,XX @@ DO_1OP(VQNEG, vqneg) | ||
30 | DO_1OP(VMAXA, vmaxa) | ||
31 | DO_1OP(VMINA, vmina) | ||
32 | |||
33 | +/* | ||
34 | + * For simple float/int conversions we use the fixed-point | ||
35 | + * conversion helpers with a zero shift count | ||
36 | + */ | ||
37 | +#define DO_VCVT(INSN, HFN, SFN) \ | ||
38 | + static void gen_##INSN##h(TCGv_ptr env, TCGv_ptr qd, TCGv_ptr qm) \ | ||
39 | + { \ | ||
40 | + gen_helper_mve_##HFN(env, qd, qm, tcg_constant_i32(0)); \ | ||
41 | + } \ | ||
42 | + static void gen_##INSN##s(TCGv_ptr env, TCGv_ptr qd, TCGv_ptr qm) \ | ||
43 | + { \ | ||
44 | + gen_helper_mve_##SFN(env, qd, qm, tcg_constant_i32(0)); \ | ||
45 | + } \ | ||
46 | + static bool trans_##INSN(DisasContext *s, arg_1op *a) \ | ||
47 | + { \ | ||
48 | + static MVEGenOneOpFn * const fns[] = { \ | ||
49 | + NULL, \ | ||
50 | + gen_##INSN##h, \ | ||
51 | + gen_##INSN##s, \ | ||
52 | + NULL, \ | ||
53 | + }; \ | ||
54 | + if (!dc_isar_feature(aa32_mve_fp, s)) { \ | ||
55 | + return false; \ | ||
56 | + } \ | ||
57 | + return do_1op(s, a, fns[a->size]); \ | ||
58 | + } | ||
59 | + | ||
60 | +DO_VCVT(VCVT_SF, vcvt_sh, vcvt_sf) | ||
61 | +DO_VCVT(VCVT_UF, vcvt_uh, vcvt_uf) | ||
62 | +DO_VCVT(VCVT_FS, vcvt_hs, vcvt_fs) | ||
63 | +DO_VCVT(VCVT_FU, vcvt_hu, vcvt_fu) | ||
64 | + | ||
65 | /* Narrowing moves: only size 0 and 1 are valid */ | ||
66 | #define DO_VMOVN(INSN, FN) \ | ||
67 | static bool trans_##INSN(DisasContext *s, arg_1op *a) \ | ||
68 | -- | ||
69 | 2.20.1 | ||
70 | |||
71 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | Implement the MVE VCVT which converts from floating-point to integer |
---|---|---|---|
2 | using a rounding mode specified by the instruction. We implement | ||
3 | this similarly to the Neon equivalents, by passing the required | ||
4 | rounding mode as an extra integer parameter to the helper functions. | ||
2 | 5 | ||
3 | Define ZCR_EL[1-3]. | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | --- | ||
9 | target/arm/helper-mve.h | 5 ++++ | ||
10 | target/arm/mve.decode | 10 ++++++++ | ||
11 | target/arm/mve_helper.c | 38 ++++++++++++++++++++++++++++ | ||
12 | target/arm/translate-mve.c | 52 ++++++++++++++++++++++++++++++++++++++ | ||
13 | 4 files changed, 105 insertions(+) | ||
4 | 14 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 15 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Message-id: 20180123035349.24538-5-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | target/arm/cpu.h | 5 ++ | ||
11 | target/arm/helper.c | 131 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
12 | 2 files changed, 136 insertions(+) | ||
13 | |||
14 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/cpu.h | 17 | --- a/target/arm/helper-mve.h |
17 | +++ b/target/arm/cpu.h | 18 | +++ b/target/arm/helper-mve.h |
18 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | 19 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(mve_vminab, TCG_CALL_NO_WG, void, env, ptr, ptr) |
19 | */ | 20 | DEF_HELPER_FLAGS_3(mve_vminah, TCG_CALL_NO_WG, void, env, ptr, ptr) |
20 | float_status fp_status; | 21 | DEF_HELPER_FLAGS_3(mve_vminaw, TCG_CALL_NO_WG, void, env, ptr, ptr) |
21 | float_status standard_fp_status; | 22 | |
23 | +DEF_HELPER_FLAGS_4(mve_vcvt_rm_sh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
24 | +DEF_HELPER_FLAGS_4(mve_vcvt_rm_uh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
25 | +DEF_HELPER_FLAGS_4(mve_vcvt_rm_ss, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
26 | +DEF_HELPER_FLAGS_4(mve_vcvt_rm_us, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
22 | + | 27 | + |
23 | + /* ZCR_EL[1-3] */ | 28 | DEF_HELPER_FLAGS_3(mve_vmovnbb, TCG_CALL_NO_WG, void, env, ptr, ptr) |
24 | + uint64_t zcr_el[4]; | 29 | DEF_HELPER_FLAGS_3(mve_vmovnbh, TCG_CALL_NO_WG, void, env, ptr, ptr) |
25 | } vfp; | 30 | DEF_HELPER_FLAGS_3(mve_vmovntb, TCG_CALL_NO_WG, void, env, ptr, ptr) |
26 | uint64_t exclusive_addr; | 31 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode |
27 | uint64_t exclusive_val; | ||
28 | @@ -XXX,XX +XXX,XX @@ void pmccntr_sync(CPUARMState *env); | ||
29 | #define CPTR_TCPAC (1U << 31) | ||
30 | #define CPTR_TTA (1U << 20) | ||
31 | #define CPTR_TFP (1U << 10) | ||
32 | +#define CPTR_TZ (1U << 8) /* CPTR_EL2 */ | ||
33 | +#define CPTR_EZ (1U << 8) /* CPTR_EL3 */ | ||
34 | |||
35 | #define MDCR_EPMAD (1U << 21) | ||
36 | #define MDCR_EDAD (1U << 20) | ||
37 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
39 | --- a/target/arm/helper.c | 33 | --- a/target/arm/mve.decode |
40 | +++ b/target/arm/helper.c | 34 | +++ b/target/arm/mve.decode |
41 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo debug_lpae_cp_reginfo[] = { | 35 | @@ -XXX,XX +XXX,XX @@ VCVT_SF 1111 1111 1 . 11 .. 11 ... 0 011 00 1 . 0 ... 0 @1op |
42 | REGINFO_SENTINEL | 36 | VCVT_UF 1111 1111 1 . 11 .. 11 ... 0 011 01 1 . 0 ... 0 @1op |
43 | }; | 37 | VCVT_FS 1111 1111 1 . 11 .. 11 ... 0 011 10 1 . 0 ... 0 @1op |
44 | 38 | VCVT_FU 1111 1111 1 . 11 .. 11 ... 0 011 11 1 . 0 ... 0 @1op | |
45 | +/* Return the exception level to which SVE-disabled exceptions should | ||
46 | + * be taken, or 0 if SVE is enabled. | ||
47 | + */ | ||
48 | +static int sve_exception_el(CPUARMState *env) | ||
49 | +{ | ||
50 | +#ifndef CONFIG_USER_ONLY | ||
51 | + unsigned current_el = arm_current_el(env); | ||
52 | + | 39 | + |
53 | + /* The CPACR.ZEN controls traps to EL1: | 40 | +# VCVT from floating point to integer with specified rounding mode |
54 | + * 0, 2 : trap EL0 and EL1 accesses | 41 | +VCVTAS 1111 1111 1 . 11 .. 11 ... 000 00 0 1 . 0 ... 0 @1op |
55 | + * 1 : trap only EL0 accesses | 42 | +VCVTAU 1111 1111 1 . 11 .. 11 ... 000 00 1 1 . 0 ... 0 @1op |
56 | + * 3 : trap no accesses | 43 | +VCVTNS 1111 1111 1 . 11 .. 11 ... 000 01 0 1 . 0 ... 0 @1op |
57 | + */ | 44 | +VCVTNU 1111 1111 1 . 11 .. 11 ... 000 01 1 1 . 0 ... 0 @1op |
58 | + switch (extract32(env->cp15.cpacr_el1, 16, 2)) { | 45 | +VCVTPS 1111 1111 1 . 11 .. 11 ... 000 10 0 1 . 0 ... 0 @1op |
59 | + default: | 46 | +VCVTPU 1111 1111 1 . 11 .. 11 ... 000 10 1 1 . 0 ... 0 @1op |
60 | + if (current_el <= 1) { | 47 | +VCVTMS 1111 1111 1 . 11 .. 11 ... 000 11 0 1 . 0 ... 0 @1op |
61 | + /* Trap to PL1, which might be EL1 or EL3 */ | 48 | +VCVTMU 1111 1111 1 . 11 .. 11 ... 000 11 1 1 . 0 ... 0 @1op |
62 | + if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) { | 49 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c |
63 | + return 3; | 50 | index XXXXXXX..XXXXXXX 100644 |
64 | + } | 51 | --- a/target/arm/mve_helper.c |
65 | + return 1; | 52 | +++ b/target/arm/mve_helper.c |
66 | + } | 53 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_FIXED(vcvt_sf, 4, int32_t, helper_vfp_sltos) |
67 | + break; | 54 | DO_VCVT_FIXED(vcvt_uf, 4, uint32_t, helper_vfp_ultos) |
68 | + case 1: | 55 | DO_VCVT_FIXED(vcvt_fs, 4, int32_t, helper_vfp_tosls_round_to_zero) |
69 | + if (current_el == 0) { | 56 | DO_VCVT_FIXED(vcvt_fu, 4, uint32_t, helper_vfp_touls_round_to_zero) |
70 | + return 1; | 57 | + |
71 | + } | 58 | +/* VCVT with specified rmode */ |
72 | + break; | 59 | +#define DO_VCVT_RMODE(OP, ESIZE, TYPE, FN) \ |
73 | + case 3: | 60 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ |
74 | + break; | 61 | + void *vd, void *vm, uint32_t rmode) \ |
62 | + { \ | ||
63 | + TYPE *d = vd, *m = vm; \ | ||
64 | + TYPE r; \ | ||
65 | + uint16_t mask = mve_element_mask(env); \ | ||
66 | + unsigned e; \ | ||
67 | + float_status *fpst; \ | ||
68 | + float_status scratch_fpst; \ | ||
69 | + float_status *base_fpst = (ESIZE == 2) ? \ | ||
70 | + &env->vfp.standard_fp_status_f16 : \ | ||
71 | + &env->vfp.standard_fp_status; \ | ||
72 | + uint32_t prev_rmode = get_float_rounding_mode(base_fpst); \ | ||
73 | + set_float_rounding_mode(rmode, base_fpst); \ | ||
74 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ | ||
75 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ | ||
76 | + continue; \ | ||
77 | + } \ | ||
78 | + fpst = base_fpst; \ | ||
79 | + if (!(mask & 1)) { \ | ||
80 | + /* We need the result but without updating flags */ \ | ||
81 | + scratch_fpst = *fpst; \ | ||
82 | + fpst = &scratch_fpst; \ | ||
83 | + } \ | ||
84 | + r = FN(m[H##ESIZE(e)], 0, fpst); \ | ||
85 | + mergemask(&d[H##ESIZE(e)], r, mask); \ | ||
86 | + } \ | ||
87 | + set_float_rounding_mode(prev_rmode, base_fpst); \ | ||
88 | + mve_advance_vpt(env); \ | ||
75 | + } | 89 | + } |
76 | + | 90 | + |
77 | + /* Similarly for CPACR.FPEN, after having checked ZEN. */ | 91 | +DO_VCVT_RMODE(vcvt_rm_sh, 2, uint16_t, helper_vfp_toshh) |
78 | + switch (extract32(env->cp15.cpacr_el1, 20, 2)) { | 92 | +DO_VCVT_RMODE(vcvt_rm_uh, 2, uint16_t, helper_vfp_touhh) |
79 | + default: | 93 | +DO_VCVT_RMODE(vcvt_rm_ss, 4, uint32_t, helper_vfp_tosls) |
80 | + if (current_el <= 1) { | 94 | +DO_VCVT_RMODE(vcvt_rm_us, 4, uint32_t, helper_vfp_touls) |
81 | + if (arm_is_secure(env) && !arm_el_is_aa64(env, 3)) { | 95 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
82 | + return 3; | 96 | index XXXXXXX..XXXXXXX 100644 |
83 | + } | 97 | --- a/target/arm/translate-mve.c |
84 | + return 1; | 98 | +++ b/target/arm/translate-mve.c |
85 | + } | 99 | @@ -XXX,XX +XXX,XX @@ typedef void MVEGenCmpFn(TCGv_ptr, TCGv_ptr, TCGv_ptr); |
86 | + break; | 100 | typedef void MVEGenScalarCmpFn(TCGv_ptr, TCGv_ptr, TCGv_i32); |
87 | + case 1: | 101 | typedef void MVEGenVABAVFn(TCGv_i32, TCGv_ptr, TCGv_ptr, TCGv_ptr, TCGv_i32); |
88 | + if (current_el == 0) { | 102 | typedef void MVEGenDualAccOpFn(TCGv_i32, TCGv_ptr, TCGv_ptr, TCGv_ptr, TCGv_i32); |
89 | + return 1; | 103 | +typedef void MVEGenVCVTRmodeFn(TCGv_ptr, TCGv_ptr, TCGv_ptr, TCGv_i32); |
90 | + } | 104 | |
91 | + break; | 105 | /* Return the offset of a Qn register (same semantics as aa32_vfp_qreg()) */ |
92 | + case 3: | 106 | static inline long mve_qreg_offset(unsigned reg) |
93 | + break; | 107 | @@ -XXX,XX +XXX,XX @@ DO_VCVT(VCVT_UF, vcvt_uh, vcvt_uf) |
108 | DO_VCVT(VCVT_FS, vcvt_hs, vcvt_fs) | ||
109 | DO_VCVT(VCVT_FU, vcvt_hu, vcvt_fu) | ||
110 | |||
111 | +static bool do_vcvt_rmode(DisasContext *s, arg_1op *a, | ||
112 | + enum arm_fprounding rmode, bool u) | ||
113 | +{ | ||
114 | + /* | ||
115 | + * Handle VCVT fp to int with specified rounding mode. | ||
116 | + * This is a 1op fn but we must pass the rounding mode as | ||
117 | + * an immediate to the helper. | ||
118 | + */ | ||
119 | + TCGv_ptr qd, qm; | ||
120 | + static MVEGenVCVTRmodeFn * const fns[4][2] = { | ||
121 | + { NULL, NULL }, | ||
122 | + { gen_helper_mve_vcvt_rm_sh, gen_helper_mve_vcvt_rm_uh }, | ||
123 | + { gen_helper_mve_vcvt_rm_ss, gen_helper_mve_vcvt_rm_us }, | ||
124 | + { NULL, NULL }, | ||
125 | + }; | ||
126 | + MVEGenVCVTRmodeFn *fn = fns[a->size][u]; | ||
127 | + | ||
128 | + if (!dc_isar_feature(aa32_mve_fp, s) || | ||
129 | + !mve_check_qreg_bank(s, a->qd | a->qm) || | ||
130 | + !fn) { | ||
131 | + return false; | ||
94 | + } | 132 | + } |
95 | + | 133 | + |
96 | + /* CPTR_EL2. Check both TZ and TFP. */ | 134 | + if (!mve_eci_check(s) || !vfp_access_check(s)) { |
97 | + if (current_el <= 2 | 135 | + return true; |
98 | + && (env->cp15.cptr_el[2] & (CPTR_TFP | CPTR_TZ)) | ||
99 | + && !arm_is_secure_below_el3(env)) { | ||
100 | + return 2; | ||
101 | + } | 136 | + } |
102 | + | 137 | + |
103 | + /* CPTR_EL3. Check both EZ and TFP. */ | 138 | + qd = mve_qreg_ptr(a->qd); |
104 | + if (!(env->cp15.cptr_el[3] & CPTR_EZ) | 139 | + qm = mve_qreg_ptr(a->qm); |
105 | + || (env->cp15.cptr_el[3] & CPTR_TFP)) { | 140 | + fn(cpu_env, qd, qm, tcg_constant_i32(arm_rmode_to_sf(rmode))); |
106 | + return 3; | 141 | + tcg_temp_free_ptr(qd); |
107 | + } | 142 | + tcg_temp_free_ptr(qm); |
108 | +#endif | 143 | + mve_update_eci(s); |
109 | + return 0; | 144 | + return true; |
110 | +} | 145 | +} |
111 | + | 146 | + |
112 | +static CPAccessResult zcr_access(CPUARMState *env, const ARMCPRegInfo *ri, | 147 | +#define DO_VCVT_RMODE(INSN, RMODE, U) \ |
113 | + bool isread) | 148 | + static bool trans_##INSN(DisasContext *s, arg_1op *a) \ |
114 | +{ | 149 | + { \ |
115 | + switch (sve_exception_el(env)) { | 150 | + return do_vcvt_rmode(s, a, RMODE, U); \ |
116 | + case 3: | 151 | + } \ |
117 | + return CP_ACCESS_TRAP_EL3; | ||
118 | + case 2: | ||
119 | + return CP_ACCESS_TRAP_EL2; | ||
120 | + case 1: | ||
121 | + return CP_ACCESS_TRAP; | ||
122 | + } | ||
123 | + return CP_ACCESS_OK; | ||
124 | +} | ||
125 | + | 152 | + |
126 | +static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri, | 153 | +DO_VCVT_RMODE(VCVTAS, FPROUNDING_TIEAWAY, false) |
127 | + uint64_t value) | 154 | +DO_VCVT_RMODE(VCVTAU, FPROUNDING_TIEAWAY, true) |
128 | +{ | 155 | +DO_VCVT_RMODE(VCVTNS, FPROUNDING_TIEEVEN, false) |
129 | + /* Bits other than [3:0] are RAZ/WI. */ | 156 | +DO_VCVT_RMODE(VCVTNU, FPROUNDING_TIEEVEN, true) |
130 | + raw_write(env, ri, value & 0xf); | 157 | +DO_VCVT_RMODE(VCVTPS, FPROUNDING_POSINF, false) |
131 | +} | 158 | +DO_VCVT_RMODE(VCVTPU, FPROUNDING_POSINF, true) |
159 | +DO_VCVT_RMODE(VCVTMS, FPROUNDING_NEGINF, false) | ||
160 | +DO_VCVT_RMODE(VCVTMU, FPROUNDING_NEGINF, true) | ||
132 | + | 161 | + |
133 | +static const ARMCPRegInfo zcr_el1_reginfo = { | 162 | /* Narrowing moves: only size 0 and 1 are valid */ |
134 | + .name = "ZCR_EL1", .state = ARM_CP_STATE_AA64, | 163 | #define DO_VMOVN(INSN, FN) \ |
135 | + .opc0 = 3, .opc1 = 0, .crn = 1, .crm = 2, .opc2 = 0, | 164 | static bool trans_##INSN(DisasContext *s, arg_1op *a) \ |
136 | + .access = PL1_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | ||
137 | + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[1]), | ||
138 | + .writefn = zcr_write, .raw_writefn = raw_write | ||
139 | +}; | ||
140 | + | ||
141 | +static const ARMCPRegInfo zcr_el2_reginfo = { | ||
142 | + .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, | ||
143 | + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, | ||
144 | + .access = PL2_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | ||
145 | + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[2]), | ||
146 | + .writefn = zcr_write, .raw_writefn = raw_write | ||
147 | +}; | ||
148 | + | ||
149 | +static const ARMCPRegInfo zcr_no_el2_reginfo = { | ||
150 | + .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, | ||
151 | + .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, | ||
152 | + .access = PL2_RW, .type = ARM_CP_64BIT, | ||
153 | + .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore | ||
154 | +}; | ||
155 | + | ||
156 | +static const ARMCPRegInfo zcr_el3_reginfo = { | ||
157 | + .name = "ZCR_EL3", .state = ARM_CP_STATE_AA64, | ||
158 | + .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 2, .opc2 = 0, | ||
159 | + .access = PL3_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | ||
160 | + .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[3]), | ||
161 | + .writefn = zcr_write, .raw_writefn = raw_write | ||
162 | +}; | ||
163 | + | ||
164 | void hw_watchpoint_update(ARMCPU *cpu, int n) | ||
165 | { | ||
166 | CPUARMState *env = &cpu->env; | ||
167 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
168 | } | ||
169 | define_one_arm_cp_reg(cpu, &sctlr); | ||
170 | } | ||
171 | + | ||
172 | + if (arm_feature(env, ARM_FEATURE_SVE)) { | ||
173 | + define_one_arm_cp_reg(cpu, &zcr_el1_reginfo); | ||
174 | + if (arm_feature(env, ARM_FEATURE_EL2)) { | ||
175 | + define_one_arm_cp_reg(cpu, &zcr_el2_reginfo); | ||
176 | + } else { | ||
177 | + define_one_arm_cp_reg(cpu, &zcr_no_el2_reginfo); | ||
178 | + } | ||
179 | + if (arm_feature(env, ARM_FEATURE_EL3)) { | ||
180 | + define_one_arm_cp_reg(cpu, &zcr_el3_reginfo); | ||
181 | + } | ||
182 | + } | ||
183 | } | ||
184 | |||
185 | void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) | ||
186 | -- | 165 | -- |
187 | 2.16.1 | 166 | 2.20.1 |
188 | 167 | ||
189 | 168 | diff view generated by jsdifflib |
1 | In the v8M architecture, if the process of taking an exception | 1 | Implement the MVE VCVT instruction which converts between single |
---|---|---|---|
2 | results in a further exception this is called a derived exception | 2 | and half precision floating point. |
3 | (for example, an MPU exception when writing the exception frame to | ||
4 | memory). If the derived exception happens while pushing the initial | ||
5 | stack frame, we must ignore any subsequent possible exception | ||
6 | pushing the callee-saves registers. | ||
7 | |||
8 | In preparation for making the stack writes check for exceptions, | ||
9 | add a return value from v7m_push_stack() and a new parameter to | ||
10 | v7m_exception_taken(), so that the former can tell the latter that | ||
11 | it needs to ignore failures to write to the stack. We also plumb | ||
12 | the argument through to v7m_push_callee_stack(), which is where | ||
13 | the code to ignore the failures will be. | ||
14 | |||
15 | (Note that the v8M ARM pseudocode structures this slightly differently: | ||
16 | derived exceptions cause the attempt to process the original | ||
17 | exception to be abandoned; then at the top level it calls | ||
18 | DerivedLateArrival to prioritize the derived exception and call | ||
19 | TakeException from there. We choose to let the NVIC do the prioritization | ||
20 | and continue forward with a call to TakeException which will then | ||
21 | take either the original or the derived exception. The effect is | ||
22 | the same, but this structure works better for QEMU because we don't | ||
23 | have a convenient top level place to do the abandon-and-retry logic.) | ||
24 | 3 | ||
25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
26 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
27 | Message-id: 1517324542-6607-4-git-send-email-peter.maydell@linaro.org | ||
28 | --- | 6 | --- |
29 | target/arm/helper.c | 35 +++++++++++++++++++++++------------ | 7 | target/arm/helper-mve.h | 5 +++ |
30 | 1 file changed, 23 insertions(+), 12 deletions(-) | 8 | target/arm/mve.decode | 8 ++++ |
9 | target/arm/mve_helper.c | 81 ++++++++++++++++++++++++++++++++++++++ | ||
10 | target/arm/translate-mve.c | 14 +++++++ | ||
11 | 4 files changed, 108 insertions(+) | ||
31 | 12 | ||
32 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 13 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
33 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
34 | --- a/target/arm/helper.c | 15 | --- a/target/arm/helper-mve.h |
35 | +++ b/target/arm/helper.c | 16 | +++ b/target/arm/helper-mve.h |
36 | @@ -XXX,XX +XXX,XX @@ static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vcvt_rm_uh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
37 | return addr; | 18 | DEF_HELPER_FLAGS_4(mve_vcvt_rm_ss, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
19 | DEF_HELPER_FLAGS_4(mve_vcvt_rm_us, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
20 | |||
21 | +DEF_HELPER_FLAGS_3(mve_vcvtb_sh, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
22 | +DEF_HELPER_FLAGS_3(mve_vcvtt_sh, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
23 | +DEF_HELPER_FLAGS_3(mve_vcvtb_hs, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
24 | +DEF_HELPER_FLAGS_3(mve_vcvtt_hs, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
25 | + | ||
26 | DEF_HELPER_FLAGS_3(mve_vmovnbb, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
27 | DEF_HELPER_FLAGS_3(mve_vmovnbh, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
28 | DEF_HELPER_FLAGS_3(mve_vmovntb, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
29 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/arm/mve.decode | ||
32 | +++ b/target/arm/mve.decode | ||
33 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op | ||
34 | # The VSHLL T2 encoding is not a @2op pattern, but is here because it | ||
35 | # overlaps what would be size=0b11 VMULH/VRMULH | ||
36 | { | ||
37 | + VCVTB_SH 111 0 1110 0 . 11 1111 ... 0 1110 0 0 . 0 ... 1 @1op_nosz | ||
38 | + | ||
39 | VMAXNMA 111 0 1110 0 . 11 1111 ... 0 1110 1 0 . 0 ... 1 @vmaxnma size=2 | ||
40 | |||
41 | VSHLL_BS 111 0 1110 0 . 11 .. 01 ... 0 1110 0 0 . 0 ... 1 @2_shll_esize_b | ||
42 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op | ||
38 | } | 43 | } |
39 | 44 | ||
40 | -static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
41 | +static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
42 | + bool ignore_faults) | ||
43 | { | 45 | { |
44 | /* For v8M, push the callee-saves register part of the stack frame. | 46 | + VCVTB_HS 111 1 1110 0 . 11 1111 ... 0 1110 0 0 . 0 ... 1 @1op_nosz |
45 | * Compare the v8M pseudocode PushCalleeStack(). | 47 | + |
46 | @@ -XXX,XX +XXX,XX @@ static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain) | 48 | VMAXNMA 111 1 1110 0 . 11 1111 ... 0 1110 1 0 . 0 ... 1 @vmaxnma size=1 |
47 | *frame_sp_p = frameptr; | 49 | |
50 | VSHLL_BU 111 1 1110 0 . 11 .. 01 ... 0 1110 0 0 . 0 ... 1 @2_shll_esize_b | ||
51 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op | ||
48 | } | 52 | } |
49 | 53 | ||
50 | -static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
51 | +static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
52 | + bool ignore_stackfaults) | ||
53 | { | 54 | { |
54 | /* Do the "take the exception" parts of exception entry, | 55 | + VCVTT_SH 111 0 1110 0 . 11 1111 ... 1 1110 0 0 . 0 ... 1 @1op_nosz |
55 | * but not the pushing of state to the stack. This is | 56 | + |
56 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | 57 | VMINNMA 111 0 1110 0 . 11 1111 ... 1 1110 1 0 . 0 ... 1 @vmaxnma size=2 |
57 | */ | 58 | VSHLL_TS 111 0 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_b |
58 | if (lr & R_V7M_EXCRET_DCRS_MASK && | 59 | VSHLL_TS 111 0 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_h |
59 | !(dotailchain && (lr & R_V7M_EXCRET_ES_MASK))) { | 60 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op |
60 | - v7m_push_callee_stack(cpu, lr, dotailchain); | ||
61 | + v7m_push_callee_stack(cpu, lr, dotailchain, | ||
62 | + ignore_stackfaults); | ||
63 | } | ||
64 | lr |= R_V7M_EXCRET_DCRS_MASK; | ||
65 | } | ||
66 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain) | ||
67 | env->thumb = addr & 1; | ||
68 | } | 61 | } |
69 | 62 | ||
70 | -static void v7m_push_stack(ARMCPU *cpu) | ||
71 | +static bool v7m_push_stack(ARMCPU *cpu) | ||
72 | { | 63 | { |
73 | /* Do the "set up stack frame" part of exception entry, | 64 | + VCVTT_HS 111 1 1110 0 . 11 1111 ... 1 1110 0 0 . 0 ... 1 @1op_nosz |
74 | * similar to pseudocode PushStack(). | ||
75 | + * Return true if we generate a derived exception (and so | ||
76 | + * should ignore further stack faults trying to process | ||
77 | + * that derived exception.) | ||
78 | */ | ||
79 | CPUARMState *env = &cpu->env; | ||
80 | uint32_t xpsr = xpsr_read(env); | ||
81 | @@ -XXX,XX +XXX,XX @@ static void v7m_push_stack(ARMCPU *cpu) | ||
82 | v7m_push(env, env->regs[2]); | ||
83 | v7m_push(env, env->regs[1]); | ||
84 | v7m_push(env, env->regs[0]); | ||
85 | + | 65 | + |
86 | + return false; | 66 | VMINNMA 111 1 1110 0 . 11 1111 ... 1 1110 1 0 . 0 ... 1 @vmaxnma size=1 |
87 | } | 67 | VSHLL_TU 111 1 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_b |
88 | 68 | VSHLL_TU 111 1 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_h | |
89 | static void do_v7m_exception_exit(ARMCPU *cpu) | 69 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c |
90 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | 70 | index XXXXXXX..XXXXXXX 100644 |
91 | if (sfault) { | 71 | --- a/target/arm/mve_helper.c |
92 | env->v7m.sfsr |= R_V7M_SFSR_INVER_MASK; | 72 | +++ b/target/arm/mve_helper.c |
93 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SECURE, false); | 73 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_RMODE(vcvt_rm_sh, 2, uint16_t, helper_vfp_toshh) |
94 | - v7m_exception_taken(cpu, excret, true); | 74 | DO_VCVT_RMODE(vcvt_rm_uh, 2, uint16_t, helper_vfp_touhh) |
95 | + v7m_exception_taken(cpu, excret, true, false); | 75 | DO_VCVT_RMODE(vcvt_rm_ss, 4, uint32_t, helper_vfp_tosls) |
96 | qemu_log_mask(CPU_LOG_INT, "...taking SecureFault on existing " | 76 | DO_VCVT_RMODE(vcvt_rm_us, 4, uint32_t, helper_vfp_touls) |
97 | "stackframe: failed EXC_RETURN.ES validity check\n"); | ||
98 | return; | ||
99 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
100 | */ | ||
101 | env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK; | ||
102 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, env->v7m.secure); | ||
103 | - v7m_exception_taken(cpu, excret, true); | ||
104 | + v7m_exception_taken(cpu, excret, true, false); | ||
105 | qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on existing " | ||
106 | "stackframe: failed exception return integrity check\n"); | ||
107 | return; | ||
108 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
109 | /* Take a SecureFault on the current stack */ | ||
110 | env->v7m.sfsr |= R_V7M_SFSR_INVIS_MASK; | ||
111 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_SECURE, false); | ||
112 | - v7m_exception_taken(cpu, excret, true); | ||
113 | + v7m_exception_taken(cpu, excret, true, false); | ||
114 | qemu_log_mask(CPU_LOG_INT, "...taking SecureFault on existing " | ||
115 | "stackframe: failed exception return integrity " | ||
116 | "signature check\n"); | ||
117 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
118 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, | ||
119 | env->v7m.secure); | ||
120 | env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK; | ||
121 | - v7m_exception_taken(cpu, excret, true); | ||
122 | + v7m_exception_taken(cpu, excret, true, false); | ||
123 | qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on existing " | ||
124 | "stackframe: failed exception return integrity " | ||
125 | "check\n"); | ||
126 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
127 | /* Take an INVPC UsageFault by pushing the stack again; | ||
128 | * we know we're v7M so this is never a Secure UsageFault. | ||
129 | */ | ||
130 | + bool ignore_stackfaults; | ||
131 | + | 77 | + |
132 | assert(!arm_feature(env, ARM_FEATURE_V8)); | 78 | +/* |
133 | armv7m_nvic_set_pending(env->nvic, ARMV7M_EXCP_USAGE, false); | 79 | + * VCVT between halfprec and singleprec. As usual for halfprec |
134 | env->v7m.cfsr[env->v7m.secure] |= R_V7M_CFSR_INVPC_MASK; | 80 | + * conversions, FZ16 is ignored and AHP is observed. |
135 | - v7m_push_stack(cpu); | 81 | + */ |
136 | - v7m_exception_taken(cpu, excret, false); | 82 | +static void do_vcvt_sh(CPUARMState *env, void *vd, void *vm, int top) |
137 | + ignore_stackfaults = v7m_push_stack(cpu); | 83 | +{ |
138 | + v7m_exception_taken(cpu, excret, false, ignore_stackfaults); | 84 | + uint16_t *d = vd; |
139 | qemu_log_mask(CPU_LOG_INT, "...taking UsageFault on new stackframe: " | 85 | + uint32_t *m = vm; |
140 | "failed exception return integrity check\n"); | 86 | + uint16_t r; |
141 | return; | 87 | + uint16_t mask = mve_element_mask(env); |
142 | @@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) | 88 | + bool ieee = !(env->vfp.xregs[ARM_VFP_FPSCR] & FPCR_AHP); |
143 | ARMCPU *cpu = ARM_CPU(cs); | 89 | + unsigned e; |
144 | CPUARMState *env = &cpu->env; | 90 | + float_status *fpst; |
145 | uint32_t lr; | 91 | + float_status scratch_fpst; |
146 | + bool ignore_stackfaults; | 92 | + float_status *base_fpst = &env->vfp.standard_fp_status; |
147 | 93 | + bool old_fz = get_flush_to_zero(base_fpst); | |
148 | arm_log_exception(cs->exception_index); | 94 | + set_flush_to_zero(false, base_fpst); |
149 | 95 | + for (e = 0; e < 16 / 4; e++, mask >>= 4) { | |
150 | @@ -XXX,XX +XXX,XX @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) | 96 | + if ((mask & MAKE_64BIT_MASK(0, 4)) == 0) { |
151 | lr |= R_V7M_EXCRET_MODE_MASK; | 97 | + continue; |
152 | } | 98 | + } |
153 | 99 | + fpst = base_fpst; | |
154 | - v7m_push_stack(cpu); | 100 | + if (!(mask & 1)) { |
155 | - v7m_exception_taken(cpu, lr, false); | 101 | + /* We need the result but without updating flags */ |
156 | + ignore_stackfaults = v7m_push_stack(cpu); | 102 | + scratch_fpst = *fpst; |
157 | + v7m_exception_taken(cpu, lr, false, ignore_stackfaults); | 103 | + fpst = &scratch_fpst; |
158 | qemu_log_mask(CPU_LOG_INT, "... as %d\n", env->v7m.exception); | 104 | + } |
159 | } | 105 | + r = float32_to_float16(m[H4(e)], ieee, fpst); |
160 | 106 | + mergemask(&d[H2(e * 2 + top)], r, mask >> (top * 2)); | |
107 | + } | ||
108 | + set_flush_to_zero(old_fz, base_fpst); | ||
109 | + mve_advance_vpt(env); | ||
110 | +} | ||
111 | + | ||
112 | +static void do_vcvt_hs(CPUARMState *env, void *vd, void *vm, int top) | ||
113 | +{ | ||
114 | + uint32_t *d = vd; | ||
115 | + uint16_t *m = vm; | ||
116 | + uint32_t r; | ||
117 | + uint16_t mask = mve_element_mask(env); | ||
118 | + bool ieee = !(env->vfp.xregs[ARM_VFP_FPSCR] & FPCR_AHP); | ||
119 | + unsigned e; | ||
120 | + float_status *fpst; | ||
121 | + float_status scratch_fpst; | ||
122 | + float_status *base_fpst = &env->vfp.standard_fp_status; | ||
123 | + bool old_fiz = get_flush_inputs_to_zero(base_fpst); | ||
124 | + set_flush_inputs_to_zero(false, base_fpst); | ||
125 | + for (e = 0; e < 16 / 4; e++, mask >>= 4) { | ||
126 | + if ((mask & MAKE_64BIT_MASK(0, 4)) == 0) { | ||
127 | + continue; | ||
128 | + } | ||
129 | + fpst = base_fpst; | ||
130 | + if (!(mask & (1 << (top * 2)))) { | ||
131 | + /* We need the result but without updating flags */ | ||
132 | + scratch_fpst = *fpst; | ||
133 | + fpst = &scratch_fpst; | ||
134 | + } | ||
135 | + r = float16_to_float32(m[H2(e * 2 + top)], ieee, fpst); | ||
136 | + mergemask(&d[H4(e)], r, mask); | ||
137 | + } | ||
138 | + set_flush_inputs_to_zero(old_fiz, base_fpst); | ||
139 | + mve_advance_vpt(env); | ||
140 | +} | ||
141 | + | ||
142 | +void HELPER(mve_vcvtb_sh)(CPUARMState *env, void *vd, void *vm) | ||
143 | +{ | ||
144 | + do_vcvt_sh(env, vd, vm, 0); | ||
145 | +} | ||
146 | +void HELPER(mve_vcvtt_sh)(CPUARMState *env, void *vd, void *vm) | ||
147 | +{ | ||
148 | + do_vcvt_sh(env, vd, vm, 1); | ||
149 | +} | ||
150 | +void HELPER(mve_vcvtb_hs)(CPUARMState *env, void *vd, void *vm) | ||
151 | +{ | ||
152 | + do_vcvt_hs(env, vd, vm, 0); | ||
153 | +} | ||
154 | +void HELPER(mve_vcvtt_hs)(CPUARMState *env, void *vd, void *vm) | ||
155 | +{ | ||
156 | + do_vcvt_hs(env, vd, vm, 1); | ||
157 | +} | ||
158 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
159 | index XXXXXXX..XXXXXXX 100644 | ||
160 | --- a/target/arm/translate-mve.c | ||
161 | +++ b/target/arm/translate-mve.c | ||
162 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_RMODE(VCVTPU, FPROUNDING_POSINF, true) | ||
163 | DO_VCVT_RMODE(VCVTMS, FPROUNDING_NEGINF, false) | ||
164 | DO_VCVT_RMODE(VCVTMU, FPROUNDING_NEGINF, true) | ||
165 | |||
166 | +#define DO_VCVT_SH(INSN, FN) \ | ||
167 | + static bool trans_##INSN(DisasContext *s, arg_1op *a) \ | ||
168 | + { \ | ||
169 | + if (!dc_isar_feature(aa32_mve_fp, s)) { \ | ||
170 | + return false; \ | ||
171 | + } \ | ||
172 | + return do_1op(s, a, gen_helper_mve_##FN); \ | ||
173 | + } \ | ||
174 | + | ||
175 | +DO_VCVT_SH(VCVTB_SH, vcvtb_sh) | ||
176 | +DO_VCVT_SH(VCVTT_SH, vcvtt_sh) | ||
177 | +DO_VCVT_SH(VCVTB_HS, vcvtb_hs) | ||
178 | +DO_VCVT_SH(VCVTT_HS, vcvtt_hs) | ||
179 | + | ||
180 | /* Narrowing moves: only size 0 and 1 are valid */ | ||
181 | #define DO_VMOVN(INSN, FN) \ | ||
182 | static bool trans_##INSN(DisasContext *s, arg_1op *a) \ | ||
161 | -- | 183 | -- |
162 | 2.16.1 | 184 | 2.20.1 |
163 | 185 | ||
164 | 186 | diff view generated by jsdifflib |
1 | Handle possible MPU faults, SAU faults or bus errors when | 1 | Implement the MVE VRINT insns, which round floating point inputs |
---|---|---|---|
2 | popping register state off the stack during exception return. | 2 | to integer values, leaving them in floating point format. |
3 | 3 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Message-id: 1517324542-6607-8-git-send-email-peter.maydell@linaro.org | ||
7 | --- | 6 | --- |
8 | target/arm/helper.c | 115 ++++++++++++++++++++++++++++++++++++++++++---------- | 7 | target/arm/helper-mve.h | 6 +++++ |
9 | 1 file changed, 94 insertions(+), 21 deletions(-) | 8 | target/arm/mve.decode | 7 ++++++ |
9 | target/arm/mve_helper.c | 35 +++++++++++++++++++++++++++++ | ||
10 | target/arm/translate-mve.c | 45 ++++++++++++++++++++++++++++++++++++++ | ||
11 | 4 files changed, 93 insertions(+) | ||
10 | 12 | ||
11 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 13 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
12 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/helper.c | 15 | --- a/target/arm/helper-mve.h |
14 | +++ b/target/arm/helper.c | 16 | +++ b/target/arm/helper-mve.h |
15 | @@ -XXX,XX +XXX,XX @@ pend_fault: | 17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vcvt_sf, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
16 | return false; | 18 | DEF_HELPER_FLAGS_4(mve_vcvt_uf, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
19 | DEF_HELPER_FLAGS_4(mve_vcvt_fs, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
20 | DEF_HELPER_FLAGS_4(mve_vcvt_fu, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
21 | + | ||
22 | +DEF_HELPER_FLAGS_4(mve_vrint_rm_h, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
23 | +DEF_HELPER_FLAGS_4(mve_vrint_rm_s, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
24 | + | ||
25 | +DEF_HELPER_FLAGS_3(mve_vrintx_h, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
26 | +DEF_HELPER_FLAGS_3(mve_vrintx_s, TCG_CALL_NO_WG, void, env, ptr, ptr) | ||
27 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/target/arm/mve.decode | ||
30 | +++ b/target/arm/mve.decode | ||
31 | @@ -XXX,XX +XXX,XX @@ VCVTPS 1111 1111 1 . 11 .. 11 ... 000 10 0 1 . 0 ... 0 @1op | ||
32 | VCVTPU 1111 1111 1 . 11 .. 11 ... 000 10 1 1 . 0 ... 0 @1op | ||
33 | VCVTMS 1111 1111 1 . 11 .. 11 ... 000 11 0 1 . 0 ... 0 @1op | ||
34 | VCVTMU 1111 1111 1 . 11 .. 11 ... 000 11 1 1 . 0 ... 0 @1op | ||
35 | + | ||
36 | +VRINTN 1111 1111 1 . 11 .. 10 ... 001 000 1 . 0 ... 0 @1op | ||
37 | +VRINTX 1111 1111 1 . 11 .. 10 ... 001 001 1 . 0 ... 0 @1op | ||
38 | +VRINTA 1111 1111 1 . 11 .. 10 ... 001 010 1 . 0 ... 0 @1op | ||
39 | +VRINTZ 1111 1111 1 . 11 .. 10 ... 001 011 1 . 0 ... 0 @1op | ||
40 | +VRINTM 1111 1111 1 . 11 .. 10 ... 001 101 1 . 0 ... 0 @1op | ||
41 | +VRINTP 1111 1111 1 . 11 .. 10 ... 001 111 1 . 0 ... 0 @1op | ||
42 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/target/arm/mve_helper.c | ||
45 | +++ b/target/arm/mve_helper.c | ||
46 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_RMODE(vcvt_rm_uh, 2, uint16_t, helper_vfp_touhh) | ||
47 | DO_VCVT_RMODE(vcvt_rm_ss, 4, uint32_t, helper_vfp_tosls) | ||
48 | DO_VCVT_RMODE(vcvt_rm_us, 4, uint32_t, helper_vfp_touls) | ||
49 | |||
50 | +#define DO_VRINT_RM_H(M, F, S) helper_rinth(M, S) | ||
51 | +#define DO_VRINT_RM_S(M, F, S) helper_rints(M, S) | ||
52 | + | ||
53 | +DO_VCVT_RMODE(vrint_rm_h, 2, uint16_t, DO_VRINT_RM_H) | ||
54 | +DO_VCVT_RMODE(vrint_rm_s, 4, uint32_t, DO_VRINT_RM_S) | ||
55 | + | ||
56 | /* | ||
57 | * VCVT between halfprec and singleprec. As usual for halfprec | ||
58 | * conversions, FZ16 is ignored and AHP is observed. | ||
59 | @@ -XXX,XX +XXX,XX @@ void HELPER(mve_vcvtt_hs)(CPUARMState *env, void *vd, void *vm) | ||
60 | { | ||
61 | do_vcvt_hs(env, vd, vm, 1); | ||
17 | } | 62 | } |
18 | |||
19 | +static bool v7m_stack_read(ARMCPU *cpu, uint32_t *dest, uint32_t addr, | ||
20 | + ARMMMUIdx mmu_idx) | ||
21 | +{ | ||
22 | + CPUState *cs = CPU(cpu); | ||
23 | + CPUARMState *env = &cpu->env; | ||
24 | + MemTxAttrs attrs = {}; | ||
25 | + MemTxResult txres; | ||
26 | + target_ulong page_size; | ||
27 | + hwaddr physaddr; | ||
28 | + int prot; | ||
29 | + ARMMMUFaultInfo fi; | ||
30 | + bool secure = mmu_idx & ARM_MMU_IDX_M_S; | ||
31 | + int exc; | ||
32 | + bool exc_secure; | ||
33 | + uint32_t value; | ||
34 | + | 63 | + |
35 | + if (get_phys_addr(env, addr, MMU_DATA_LOAD, mmu_idx, &physaddr, | 64 | +#define DO_1OP_FP(OP, ESIZE, TYPE, FN) \ |
36 | + &attrs, &prot, &page_size, &fi, NULL)) { | 65 | + void HELPER(glue(mve_, OP))(CPUARMState *env, void *vd, void *vm) \ |
37 | + /* MPU/SAU lookup failed */ | 66 | + { \ |
38 | + if (fi.type == ARMFault_QEMU_SFault) { | 67 | + TYPE *d = vd, *m = vm; \ |
39 | + qemu_log_mask(CPU_LOG_INT, | 68 | + TYPE r; \ |
40 | + "...SecureFault with SFSR.AUVIOL during unstack\n"); | 69 | + uint16_t mask = mve_element_mask(env); \ |
41 | + env->v7m.sfsr |= R_V7M_SFSR_AUVIOL_MASK | R_V7M_SFSR_SFARVALID_MASK; | 70 | + unsigned e; \ |
42 | + env->v7m.sfar = addr; | 71 | + float_status *fpst; \ |
43 | + exc = ARMV7M_EXCP_SECURE; | 72 | + float_status scratch_fpst; \ |
44 | + exc_secure = false; | 73 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ |
45 | + } else { | 74 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ |
46 | + qemu_log_mask(CPU_LOG_INT, | 75 | + continue; \ |
47 | + "...MemManageFault with CFSR.MUNSTKERR\n"); | 76 | + } \ |
48 | + env->v7m.cfsr[secure] |= R_V7M_CFSR_MUNSTKERR_MASK; | 77 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ |
49 | + exc = ARMV7M_EXCP_MEM; | 78 | + &env->vfp.standard_fp_status; \ |
50 | + exc_secure = secure; | 79 | + if (!(mask & 1)) { \ |
51 | + } | 80 | + /* We need the result but without updating flags */ \ |
52 | + goto pend_fault; | 81 | + scratch_fpst = *fpst; \ |
82 | + fpst = &scratch_fpst; \ | ||
83 | + } \ | ||
84 | + r = FN(m[H##ESIZE(e)], fpst); \ | ||
85 | + mergemask(&d[H##ESIZE(e)], r, mask); \ | ||
86 | + } \ | ||
87 | + mve_advance_vpt(env); \ | ||
53 | + } | 88 | + } |
54 | + | 89 | + |
55 | + value = address_space_ldl(arm_addressspace(cs, attrs), physaddr, | 90 | +DO_1OP_FP(vrintx_h, 2, float16, float16_round_to_int) |
56 | + attrs, &txres); | 91 | +DO_1OP_FP(vrintx_s, 4, float32, float32_round_to_int) |
57 | + if (txres != MEMTX_OK) { | 92 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
58 | + /* BusFault trying to read the data */ | 93 | index XXXXXXX..XXXXXXX 100644 |
59 | + qemu_log_mask(CPU_LOG_INT, "...BusFault with BFSR.UNSTKERR\n"); | 94 | --- a/target/arm/translate-mve.c |
60 | + env->v7m.cfsr[M_REG_NS] |= R_V7M_CFSR_UNSTKERR_MASK; | 95 | +++ b/target/arm/translate-mve.c |
61 | + exc = ARMV7M_EXCP_BUS; | 96 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_SH(VCVTT_SH, vcvtt_sh) |
62 | + exc_secure = false; | 97 | DO_VCVT_SH(VCVTB_HS, vcvtb_hs) |
63 | + goto pend_fault; | 98 | DO_VCVT_SH(VCVTT_HS, vcvtt_hs) |
99 | |||
100 | +#define DO_VRINT(INSN, RMODE) \ | ||
101 | + static void gen_##INSN##h(TCGv_ptr env, TCGv_ptr qd, TCGv_ptr qm) \ | ||
102 | + { \ | ||
103 | + gen_helper_mve_vrint_rm_h(env, qd, qm, \ | ||
104 | + tcg_constant_i32(arm_rmode_to_sf(RMODE))); \ | ||
105 | + } \ | ||
106 | + static void gen_##INSN##s(TCGv_ptr env, TCGv_ptr qd, TCGv_ptr qm) \ | ||
107 | + { \ | ||
108 | + gen_helper_mve_vrint_rm_s(env, qd, qm, \ | ||
109 | + tcg_constant_i32(arm_rmode_to_sf(RMODE))); \ | ||
110 | + } \ | ||
111 | + static bool trans_##INSN(DisasContext *s, arg_1op *a) \ | ||
112 | + { \ | ||
113 | + static MVEGenOneOpFn * const fns[] = { \ | ||
114 | + NULL, \ | ||
115 | + gen_##INSN##h, \ | ||
116 | + gen_##INSN##s, \ | ||
117 | + NULL, \ | ||
118 | + }; \ | ||
119 | + if (!dc_isar_feature(aa32_mve_fp, s)) { \ | ||
120 | + return false; \ | ||
121 | + } \ | ||
122 | + return do_1op(s, a, fns[a->size]); \ | ||
64 | + } | 123 | + } |
65 | + | 124 | + |
66 | + *dest = value; | 125 | +DO_VRINT(VRINTN, FPROUNDING_TIEEVEN) |
67 | + return true; | 126 | +DO_VRINT(VRINTA, FPROUNDING_TIEAWAY) |
127 | +DO_VRINT(VRINTZ, FPROUNDING_ZERO) | ||
128 | +DO_VRINT(VRINTM, FPROUNDING_NEGINF) | ||
129 | +DO_VRINT(VRINTP, FPROUNDING_POSINF) | ||
68 | + | 130 | + |
69 | +pend_fault: | 131 | +static bool trans_VRINTX(DisasContext *s, arg_1op *a) |
70 | + /* By pending the exception at this point we are making | 132 | +{ |
71 | + * the IMPDEF choice "overridden exceptions pended" (see the | 133 | + static MVEGenOneOpFn * const fns[] = { |
72 | + * MergeExcInfo() pseudocode). The other choice would be to not | 134 | + NULL, |
73 | + * pend them now and then make a choice about which to throw away | 135 | + gen_helper_mve_vrintx_h, |
74 | + * later if we have two derived exceptions. | 136 | + gen_helper_mve_vrintx_s, |
75 | + */ | 137 | + NULL, |
76 | + armv7m_nvic_set_pending(env->nvic, exc, exc_secure); | 138 | + }; |
77 | + return false; | 139 | + if (!dc_isar_feature(aa32_mve_fp, s)) { |
140 | + return false; | ||
141 | + } | ||
142 | + return do_1op(s, a, fns[a->size]); | ||
78 | +} | 143 | +} |
79 | + | 144 | + |
80 | /* Return true if we're using the process stack pointer (not the MSP) */ | 145 | /* Narrowing moves: only size 0 and 1 are valid */ |
81 | static bool v7m_using_psp(CPUARMState *env) | 146 | #define DO_VMOVN(INSN, FN) \ |
82 | { | 147 | static bool trans_##INSN(DisasContext *s, arg_1op *a) \ |
83 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
84 | !return_to_handler, | ||
85 | return_to_sp_process); | ||
86 | uint32_t frameptr = *frame_sp_p; | ||
87 | + bool pop_ok = true; | ||
88 | + ARMMMUIdx mmu_idx; | ||
89 | + | ||
90 | + mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, return_to_secure, | ||
91 | + !return_to_handler); | ||
92 | |||
93 | if (!QEMU_IS_ALIGNED(frameptr, 8) && | ||
94 | arm_feature(env, ARM_FEATURE_V8)) { | ||
95 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
96 | return; | ||
97 | } | ||
98 | |||
99 | - env->regs[4] = ldl_phys(cs->as, frameptr + 0x8); | ||
100 | - env->regs[5] = ldl_phys(cs->as, frameptr + 0xc); | ||
101 | - env->regs[6] = ldl_phys(cs->as, frameptr + 0x10); | ||
102 | - env->regs[7] = ldl_phys(cs->as, frameptr + 0x14); | ||
103 | - env->regs[8] = ldl_phys(cs->as, frameptr + 0x18); | ||
104 | - env->regs[9] = ldl_phys(cs->as, frameptr + 0x1c); | ||
105 | - env->regs[10] = ldl_phys(cs->as, frameptr + 0x20); | ||
106 | - env->regs[11] = ldl_phys(cs->as, frameptr + 0x24); | ||
107 | + pop_ok = | ||
108 | + v7m_stack_read(cpu, &env->regs[4], frameptr + 0x8, mmu_idx) && | ||
109 | + v7m_stack_read(cpu, &env->regs[4], frameptr + 0x8, mmu_idx) && | ||
110 | + v7m_stack_read(cpu, &env->regs[5], frameptr + 0xc, mmu_idx) && | ||
111 | + v7m_stack_read(cpu, &env->regs[6], frameptr + 0x10, mmu_idx) && | ||
112 | + v7m_stack_read(cpu, &env->regs[7], frameptr + 0x14, mmu_idx) && | ||
113 | + v7m_stack_read(cpu, &env->regs[8], frameptr + 0x18, mmu_idx) && | ||
114 | + v7m_stack_read(cpu, &env->regs[9], frameptr + 0x1c, mmu_idx) && | ||
115 | + v7m_stack_read(cpu, &env->regs[10], frameptr + 0x20, mmu_idx) && | ||
116 | + v7m_stack_read(cpu, &env->regs[11], frameptr + 0x24, mmu_idx); | ||
117 | |||
118 | frameptr += 0x28; | ||
119 | } | ||
120 | |||
121 | - /* Pop registers. TODO: make these accesses use the correct | ||
122 | - * attributes and address space (S/NS, priv/unpriv) and handle | ||
123 | - * memory transaction failures. | ||
124 | - */ | ||
125 | - env->regs[0] = ldl_phys(cs->as, frameptr); | ||
126 | - env->regs[1] = ldl_phys(cs->as, frameptr + 0x4); | ||
127 | - env->regs[2] = ldl_phys(cs->as, frameptr + 0x8); | ||
128 | - env->regs[3] = ldl_phys(cs->as, frameptr + 0xc); | ||
129 | - env->regs[12] = ldl_phys(cs->as, frameptr + 0x10); | ||
130 | - env->regs[14] = ldl_phys(cs->as, frameptr + 0x14); | ||
131 | - env->regs[15] = ldl_phys(cs->as, frameptr + 0x18); | ||
132 | + /* Pop registers */ | ||
133 | + pop_ok = pop_ok && | ||
134 | + v7m_stack_read(cpu, &env->regs[0], frameptr, mmu_idx) && | ||
135 | + v7m_stack_read(cpu, &env->regs[1], frameptr + 0x4, mmu_idx) && | ||
136 | + v7m_stack_read(cpu, &env->regs[2], frameptr + 0x8, mmu_idx) && | ||
137 | + v7m_stack_read(cpu, &env->regs[3], frameptr + 0xc, mmu_idx) && | ||
138 | + v7m_stack_read(cpu, &env->regs[12], frameptr + 0x10, mmu_idx) && | ||
139 | + v7m_stack_read(cpu, &env->regs[14], frameptr + 0x14, mmu_idx) && | ||
140 | + v7m_stack_read(cpu, &env->regs[15], frameptr + 0x18, mmu_idx) && | ||
141 | + v7m_stack_read(cpu, &xpsr, frameptr + 0x1c, mmu_idx); | ||
142 | + | ||
143 | + if (!pop_ok) { | ||
144 | + /* v7m_stack_read() pended a fault, so take it (as a tail | ||
145 | + * chained exception on the same stack frame) | ||
146 | + */ | ||
147 | + v7m_exception_taken(cpu, excret, true, false); | ||
148 | + return; | ||
149 | + } | ||
150 | |||
151 | /* Returning from an exception with a PC with bit 0 set is defined | ||
152 | * behaviour on v8M (bit 0 is ignored), but for v7M it was specified | ||
153 | @@ -XXX,XX +XXX,XX @@ static void do_v7m_exception_exit(ARMCPU *cpu) | ||
154 | } | ||
155 | } | ||
156 | |||
157 | - xpsr = ldl_phys(cs->as, frameptr + 0x1c); | ||
158 | - | ||
159 | if (arm_feature(env, ARM_FEATURE_V8)) { | ||
160 | /* For v8M we have to check whether the xPSR exception field | ||
161 | * matches the EXCRET value for return to handler/thread | ||
162 | -- | 148 | -- |
163 | 2.16.1 | 149 | 2.20.1 |
164 | 150 | ||
165 | 151 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | We now have a complete MVE emulation, so we can enable it in our | ||
2 | Cortex-M55 model by setting the ID registers to match those of a | ||
3 | Cortex-M55 with full MVE support. | ||
1 | 4 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | --- | ||
8 | target/arm/cpu_tcg.c | 7 ++----- | ||
9 | 1 file changed, 2 insertions(+), 5 deletions(-) | ||
10 | |||
11 | diff --git a/target/arm/cpu_tcg.c b/target/arm/cpu_tcg.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/target/arm/cpu_tcg.c | ||
14 | +++ b/target/arm/cpu_tcg.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static void cortex_m55_initfn(Object *obj) | ||
16 | cpu->revidr = 0; | ||
17 | cpu->pmsav7_dregion = 16; | ||
18 | cpu->sau_sregion = 8; | ||
19 | - /* | ||
20 | - * These are the MVFR* values for the FPU, no MVE configuration; | ||
21 | - * we will update them later when we implement MVE | ||
22 | - */ | ||
23 | + /* These are the MVFR* values for the FPU + full MVE configuration */ | ||
24 | cpu->isar.mvfr0 = 0x10110221; | ||
25 | - cpu->isar.mvfr1 = 0x12100011; | ||
26 | + cpu->isar.mvfr1 = 0x12100211; | ||
27 | cpu->isar.mvfr2 = 0x00000040; | ||
28 | cpu->isar.id_pfr0 = 0x20000030; | ||
29 | cpu->isar.id_pfr1 = 0x00000230; | ||
30 | -- | ||
31 | 2.20.1 | ||
32 | |||
33 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | From: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> |
---|---|---|---|
2 | 2 | ||
3 | Add support for the new ARMv8.2 SHA-3, SM3, SM4 and SHA-512 instructions to | 3 | Add a definition for the Fujitsu A64FX processor. |
4 | AArch64 user mode emulation. | ||
5 | 4 | ||
6 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 5 | The A64FX processor does not implement the AArch32 Execution state, |
7 | Message-id: 20180207111729.15737-6-ard.biesheuvel@linaro.org | 6 | so there are no associated AArch32 Identification registers. |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | |
8 | For SVE, the A64FX processor supports only 128,256 and 512bit vector | ||
9 | lengths. | ||
10 | |||
11 | The Identification register values are defined based on the FX700, | ||
12 | and have been tested and confirmed. | ||
13 | |||
14 | Signed-off-by: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> | ||
15 | Reviewed-by: Andrew Jones <drjones@redhat.com> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 17 | --- |
11 | linux-user/elfload.c | 19 +++++++++++++++++++ | 18 | target/arm/cpu64.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ |
12 | target/arm/cpu64.c | 4 ++++ | 19 | 1 file changed, 48 insertions(+) |
13 | 2 files changed, 23 insertions(+) | ||
14 | 20 | ||
15 | diff --git a/linux-user/elfload.c b/linux-user/elfload.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/linux-user/elfload.c | ||
18 | +++ b/linux-user/elfload.c | ||
19 | @@ -XXX,XX +XXX,XX @@ enum { | ||
20 | ARM_HWCAP_A64_SHA1 = 1 << 5, | ||
21 | ARM_HWCAP_A64_SHA2 = 1 << 6, | ||
22 | ARM_HWCAP_A64_CRC32 = 1 << 7, | ||
23 | + ARM_HWCAP_A64_ATOMICS = 1 << 8, | ||
24 | + ARM_HWCAP_A64_FPHP = 1 << 9, | ||
25 | + ARM_HWCAP_A64_ASIMDHP = 1 << 10, | ||
26 | + ARM_HWCAP_A64_CPUID = 1 << 11, | ||
27 | + ARM_HWCAP_A64_ASIMDRDM = 1 << 12, | ||
28 | + ARM_HWCAP_A64_JSCVT = 1 << 13, | ||
29 | + ARM_HWCAP_A64_FCMA = 1 << 14, | ||
30 | + ARM_HWCAP_A64_LRCPC = 1 << 15, | ||
31 | + ARM_HWCAP_A64_DCPOP = 1 << 16, | ||
32 | + ARM_HWCAP_A64_SHA3 = 1 << 17, | ||
33 | + ARM_HWCAP_A64_SM3 = 1 << 18, | ||
34 | + ARM_HWCAP_A64_SM4 = 1 << 19, | ||
35 | + ARM_HWCAP_A64_ASIMDDP = 1 << 20, | ||
36 | + ARM_HWCAP_A64_SHA512 = 1 << 21, | ||
37 | + ARM_HWCAP_A64_SVE = 1 << 22, | ||
38 | }; | ||
39 | |||
40 | #define ELF_HWCAP get_elf_hwcap() | ||
41 | @@ -XXX,XX +XXX,XX @@ static uint32_t get_elf_hwcap(void) | ||
42 | GET_FEATURE(ARM_FEATURE_V8_SHA1, ARM_HWCAP_A64_SHA1); | ||
43 | GET_FEATURE(ARM_FEATURE_V8_SHA256, ARM_HWCAP_A64_SHA2); | ||
44 | GET_FEATURE(ARM_FEATURE_CRC, ARM_HWCAP_A64_CRC32); | ||
45 | + GET_FEATURE(ARM_FEATURE_V8_SHA3, ARM_HWCAP_A64_SHA3); | ||
46 | + GET_FEATURE(ARM_FEATURE_V8_SM3, ARM_HWCAP_A64_SM3); | ||
47 | + GET_FEATURE(ARM_FEATURE_V8_SM4, ARM_HWCAP_A64_SM4); | ||
48 | + GET_FEATURE(ARM_FEATURE_V8_SHA512, ARM_HWCAP_A64_SHA512); | ||
49 | #undef GET_FEATURE | ||
50 | |||
51 | return hwcaps; | ||
52 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | 21 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c |
53 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
54 | --- a/target/arm/cpu64.c | 23 | --- a/target/arm/cpu64.c |
55 | +++ b/target/arm/cpu64.c | 24 | +++ b/target/arm/cpu64.c |
56 | @@ -XXX,XX +XXX,XX @@ static void aarch64_any_initfn(Object *obj) | 25 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) |
57 | set_feature(&cpu->env, ARM_FEATURE_V8_AES); | 26 | cpu_max_set_sve_max_vq, NULL, NULL); |
58 | set_feature(&cpu->env, ARM_FEATURE_V8_SHA1); | 27 | } |
59 | set_feature(&cpu->env, ARM_FEATURE_V8_SHA256); | 28 | |
60 | + set_feature(&cpu->env, ARM_FEATURE_V8_SHA512); | 29 | +static void aarch64_a64fx_initfn(Object *obj) |
61 | + set_feature(&cpu->env, ARM_FEATURE_V8_SHA3); | 30 | +{ |
62 | + set_feature(&cpu->env, ARM_FEATURE_V8_SM3); | 31 | + ARMCPU *cpu = ARM_CPU(obj); |
63 | + set_feature(&cpu->env, ARM_FEATURE_V8_SM4); | 32 | + |
64 | set_feature(&cpu->env, ARM_FEATURE_V8_PMULL); | 33 | + cpu->dtb_compatible = "arm,a64fx"; |
65 | set_feature(&cpu->env, ARM_FEATURE_CRC); | 34 | + set_feature(&cpu->env, ARM_FEATURE_V8); |
66 | cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */ | 35 | + set_feature(&cpu->env, ARM_FEATURE_NEON); |
36 | + set_feature(&cpu->env, ARM_FEATURE_GENERIC_TIMER); | ||
37 | + set_feature(&cpu->env, ARM_FEATURE_AARCH64); | ||
38 | + set_feature(&cpu->env, ARM_FEATURE_EL2); | ||
39 | + set_feature(&cpu->env, ARM_FEATURE_EL3); | ||
40 | + set_feature(&cpu->env, ARM_FEATURE_PMU); | ||
41 | + cpu->midr = 0x461f0010; | ||
42 | + cpu->revidr = 0x00000000; | ||
43 | + cpu->ctr = 0x86668006; | ||
44 | + cpu->reset_sctlr = 0x30000180; | ||
45 | + cpu->isar.id_aa64pfr0 = 0x0000000101111111; /* No RAS Extensions */ | ||
46 | + cpu->isar.id_aa64pfr1 = 0x0000000000000000; | ||
47 | + cpu->isar.id_aa64dfr0 = 0x0000000010305408; | ||
48 | + cpu->isar.id_aa64dfr1 = 0x0000000000000000; | ||
49 | + cpu->id_aa64afr0 = 0x0000000000000000; | ||
50 | + cpu->id_aa64afr1 = 0x0000000000000000; | ||
51 | + cpu->isar.id_aa64mmfr0 = 0x0000000000001122; | ||
52 | + cpu->isar.id_aa64mmfr1 = 0x0000000011212100; | ||
53 | + cpu->isar.id_aa64mmfr2 = 0x0000000000001011; | ||
54 | + cpu->isar.id_aa64isar0 = 0x0000000010211120; | ||
55 | + cpu->isar.id_aa64isar1 = 0x0000000000010001; | ||
56 | + cpu->isar.id_aa64zfr0 = 0x0000000000000000; | ||
57 | + cpu->clidr = 0x0000000080000023; | ||
58 | + cpu->ccsidr[0] = 0x7007e01c; /* 64KB L1 dcache */ | ||
59 | + cpu->ccsidr[1] = 0x2007e01c; /* 64KB L1 icache */ | ||
60 | + cpu->ccsidr[2] = 0x70ffe07c; /* 8MB L2 cache */ | ||
61 | + cpu->dcz_blocksize = 6; /* 256 bytes */ | ||
62 | + cpu->gic_num_lrs = 4; | ||
63 | + cpu->gic_vpribits = 5; | ||
64 | + cpu->gic_vprebits = 5; | ||
65 | + | ||
66 | + /* Suppport of A64FX's vector length are 128,256 and 512bit only */ | ||
67 | + aarch64_add_sve_properties(obj); | ||
68 | + bitmap_zero(cpu->sve_vq_supported, ARM_MAX_VQ); | ||
69 | + set_bit(0, cpu->sve_vq_supported); /* 128bit */ | ||
70 | + set_bit(1, cpu->sve_vq_supported); /* 256bit */ | ||
71 | + set_bit(3, cpu->sve_vq_supported); /* 512bit */ | ||
72 | + | ||
73 | + /* TODO: Add A64FX specific HPC extension registers */ | ||
74 | +} | ||
75 | + | ||
76 | static const ARMCPUInfo aarch64_cpus[] = { | ||
77 | { .name = "cortex-a57", .initfn = aarch64_a57_initfn }, | ||
78 | { .name = "cortex-a53", .initfn = aarch64_a53_initfn }, | ||
79 | { .name = "cortex-a72", .initfn = aarch64_a72_initfn }, | ||
80 | + { .name = "a64fx", .initfn = aarch64_a64fx_initfn }, | ||
81 | { .name = "max", .initfn = aarch64_max_initfn }, | ||
82 | }; | ||
83 | |||
67 | -- | 84 | -- |
68 | 2.16.1 | 85 | 2.20.1 |
69 | 86 | ||
70 | 87 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | From: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> |
---|---|---|---|
2 | 2 | ||
3 | Move virt's PSCI DT fixup code to arm/boot.c and set this fixup to | 3 | Add -cpu a64fx to use A64FX processor when -machine virt option is |
4 | happen automatically for every board that doesn't mark "psci-conduit" | 4 | specified. In addition, add a64fx to the Supported guest CPU types |
5 | as disabled. This way emulated boards other than "virt" that rely on | 5 | in the virt.rst document. |
6 | PSIC for SMP could benefit from that code. | ||
7 | 6 | ||
8 | Cc: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> |
9 | Cc: Jason Wang <jasowang@redhat.com> | 8 | Reviewed-by: Andrew Jones <drjones@redhat.com> |
10 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
12 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
13 | Cc: qemu-devel@nongnu.org | ||
14 | Cc: qemu-arm@nongnu.org | ||
15 | Cc: yurovsky@gmail.com | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
18 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 10 | --- |
21 | hw/arm/boot.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | 11 | docs/system/arm/virt.rst | 1 + |
22 | hw/arm/virt.c | 61 ------------------------------------------------------- | 12 | hw/arm/virt.c | 1 + |
23 | 2 files changed, 65 insertions(+), 61 deletions(-) | 13 | 2 files changed, 2 insertions(+) |
24 | 14 | ||
25 | diff --git a/hw/arm/boot.c b/hw/arm/boot.c | 15 | diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst |
26 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/hw/arm/boot.c | 17 | --- a/docs/system/arm/virt.rst |
28 | +++ b/hw/arm/boot.c | 18 | +++ b/docs/system/arm/virt.rst |
29 | @@ -XXX,XX +XXX,XX @@ static void set_kernel_args_old(const struct arm_boot_info *info) | 19 | @@ -XXX,XX +XXX,XX @@ Supported guest CPU types: |
30 | } | 20 | - ``cortex-a53`` (64-bit) |
31 | } | 21 | - ``cortex-a57`` (64-bit) |
32 | 22 | - ``cortex-a72`` (64-bit) | |
33 | +static void fdt_add_psci_node(void *fdt) | 23 | +- ``a64fx`` (64-bit) |
34 | +{ | 24 | - ``host`` (with KVM only) |
35 | + uint32_t cpu_suspend_fn; | 25 | - ``max`` (same as ``host`` for KVM; best possible emulation with TCG) |
36 | + uint32_t cpu_off_fn; | 26 | |
37 | + uint32_t cpu_on_fn; | ||
38 | + uint32_t migrate_fn; | ||
39 | + ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(0)); | ||
40 | + const char *psci_method; | ||
41 | + int64_t psci_conduit; | ||
42 | + | ||
43 | + psci_conduit = object_property_get_int(OBJECT(armcpu), | ||
44 | + "psci-conduit", | ||
45 | + &error_abort); | ||
46 | + switch (psci_conduit) { | ||
47 | + case QEMU_PSCI_CONDUIT_DISABLED: | ||
48 | + return; | ||
49 | + case QEMU_PSCI_CONDUIT_HVC: | ||
50 | + psci_method = "hvc"; | ||
51 | + break; | ||
52 | + case QEMU_PSCI_CONDUIT_SMC: | ||
53 | + psci_method = "smc"; | ||
54 | + break; | ||
55 | + default: | ||
56 | + g_assert_not_reached(); | ||
57 | + } | ||
58 | + | ||
59 | + qemu_fdt_add_subnode(fdt, "/psci"); | ||
60 | + if (armcpu->psci_version == 2) { | ||
61 | + const char comp[] = "arm,psci-0.2\0arm,psci"; | ||
62 | + qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp)); | ||
63 | + | ||
64 | + cpu_off_fn = QEMU_PSCI_0_2_FN_CPU_OFF; | ||
65 | + if (arm_feature(&armcpu->env, ARM_FEATURE_AARCH64)) { | ||
66 | + cpu_suspend_fn = QEMU_PSCI_0_2_FN64_CPU_SUSPEND; | ||
67 | + cpu_on_fn = QEMU_PSCI_0_2_FN64_CPU_ON; | ||
68 | + migrate_fn = QEMU_PSCI_0_2_FN64_MIGRATE; | ||
69 | + } else { | ||
70 | + cpu_suspend_fn = QEMU_PSCI_0_2_FN_CPU_SUSPEND; | ||
71 | + cpu_on_fn = QEMU_PSCI_0_2_FN_CPU_ON; | ||
72 | + migrate_fn = QEMU_PSCI_0_2_FN_MIGRATE; | ||
73 | + } | ||
74 | + } else { | ||
75 | + qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci"); | ||
76 | + | ||
77 | + cpu_suspend_fn = QEMU_PSCI_0_1_FN_CPU_SUSPEND; | ||
78 | + cpu_off_fn = QEMU_PSCI_0_1_FN_CPU_OFF; | ||
79 | + cpu_on_fn = QEMU_PSCI_0_1_FN_CPU_ON; | ||
80 | + migrate_fn = QEMU_PSCI_0_1_FN_MIGRATE; | ||
81 | + } | ||
82 | + | ||
83 | + /* We adopt the PSCI spec's nomenclature, and use 'conduit' to refer | ||
84 | + * to the instruction that should be used to invoke PSCI functions. | ||
85 | + * However, the device tree binding uses 'method' instead, so that is | ||
86 | + * what we should use here. | ||
87 | + */ | ||
88 | + qemu_fdt_setprop_string(fdt, "/psci", "method", psci_method); | ||
89 | + | ||
90 | + qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend", cpu_suspend_fn); | ||
91 | + qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off", cpu_off_fn); | ||
92 | + qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on", cpu_on_fn); | ||
93 | + qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn); | ||
94 | +} | ||
95 | + | ||
96 | /** | ||
97 | * load_dtb() - load a device tree binary image into memory | ||
98 | * @addr: the address to load the image at | ||
99 | @@ -XXX,XX +XXX,XX @@ static int load_dtb(hwaddr addr, const struct arm_boot_info *binfo, | ||
100 | } | ||
101 | } | ||
102 | |||
103 | + fdt_add_psci_node(fdt); | ||
104 | + | ||
105 | if (binfo->modify_dtb) { | ||
106 | binfo->modify_dtb(binfo, fdt); | ||
107 | } | ||
108 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | 27 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c |
109 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
110 | --- a/hw/arm/virt.c | 29 | --- a/hw/arm/virt.c |
111 | +++ b/hw/arm/virt.c | 30 | +++ b/hw/arm/virt.c |
112 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(VirtMachineState *vms) | 31 | @@ -XXX,XX +XXX,XX @@ static const char *valid_cpus[] = { |
113 | } | 32 | ARM_CPU_TYPE_NAME("cortex-a53"), |
114 | } | 33 | ARM_CPU_TYPE_NAME("cortex-a57"), |
115 | 34 | ARM_CPU_TYPE_NAME("cortex-a72"), | |
116 | -static void fdt_add_psci_node(const VirtMachineState *vms) | 35 | + ARM_CPU_TYPE_NAME("a64fx"), |
117 | -{ | 36 | ARM_CPU_TYPE_NAME("host"), |
118 | - uint32_t cpu_suspend_fn; | 37 | ARM_CPU_TYPE_NAME("max"), |
119 | - uint32_t cpu_off_fn; | 38 | }; |
120 | - uint32_t cpu_on_fn; | ||
121 | - uint32_t migrate_fn; | ||
122 | - void *fdt = vms->fdt; | ||
123 | - ARMCPU *armcpu = ARM_CPU(qemu_get_cpu(0)); | ||
124 | - const char *psci_method; | ||
125 | - | ||
126 | - switch (vms->psci_conduit) { | ||
127 | - case QEMU_PSCI_CONDUIT_DISABLED: | ||
128 | - return; | ||
129 | - case QEMU_PSCI_CONDUIT_HVC: | ||
130 | - psci_method = "hvc"; | ||
131 | - break; | ||
132 | - case QEMU_PSCI_CONDUIT_SMC: | ||
133 | - psci_method = "smc"; | ||
134 | - break; | ||
135 | - default: | ||
136 | - g_assert_not_reached(); | ||
137 | - } | ||
138 | - | ||
139 | - qemu_fdt_add_subnode(fdt, "/psci"); | ||
140 | - if (armcpu->psci_version == 2) { | ||
141 | - const char comp[] = "arm,psci-0.2\0arm,psci"; | ||
142 | - qemu_fdt_setprop(fdt, "/psci", "compatible", comp, sizeof(comp)); | ||
143 | - | ||
144 | - cpu_off_fn = QEMU_PSCI_0_2_FN_CPU_OFF; | ||
145 | - if (arm_feature(&armcpu->env, ARM_FEATURE_AARCH64)) { | ||
146 | - cpu_suspend_fn = QEMU_PSCI_0_2_FN64_CPU_SUSPEND; | ||
147 | - cpu_on_fn = QEMU_PSCI_0_2_FN64_CPU_ON; | ||
148 | - migrate_fn = QEMU_PSCI_0_2_FN64_MIGRATE; | ||
149 | - } else { | ||
150 | - cpu_suspend_fn = QEMU_PSCI_0_2_FN_CPU_SUSPEND; | ||
151 | - cpu_on_fn = QEMU_PSCI_0_2_FN_CPU_ON; | ||
152 | - migrate_fn = QEMU_PSCI_0_2_FN_MIGRATE; | ||
153 | - } | ||
154 | - } else { | ||
155 | - qemu_fdt_setprop_string(fdt, "/psci", "compatible", "arm,psci"); | ||
156 | - | ||
157 | - cpu_suspend_fn = QEMU_PSCI_0_1_FN_CPU_SUSPEND; | ||
158 | - cpu_off_fn = QEMU_PSCI_0_1_FN_CPU_OFF; | ||
159 | - cpu_on_fn = QEMU_PSCI_0_1_FN_CPU_ON; | ||
160 | - migrate_fn = QEMU_PSCI_0_1_FN_MIGRATE; | ||
161 | - } | ||
162 | - | ||
163 | - /* We adopt the PSCI spec's nomenclature, and use 'conduit' to refer | ||
164 | - * to the instruction that should be used to invoke PSCI functions. | ||
165 | - * However, the device tree binding uses 'method' instead, so that is | ||
166 | - * what we should use here. | ||
167 | - */ | ||
168 | - qemu_fdt_setprop_string(fdt, "/psci", "method", psci_method); | ||
169 | - | ||
170 | - qemu_fdt_setprop_cell(fdt, "/psci", "cpu_suspend", cpu_suspend_fn); | ||
171 | - qemu_fdt_setprop_cell(fdt, "/psci", "cpu_off", cpu_off_fn); | ||
172 | - qemu_fdt_setprop_cell(fdt, "/psci", "cpu_on", cpu_on_fn); | ||
173 | - qemu_fdt_setprop_cell(fdt, "/psci", "migrate", migrate_fn); | ||
174 | -} | ||
175 | - | ||
176 | static void fdt_add_timer_nodes(const VirtMachineState *vms) | ||
177 | { | ||
178 | /* On real hardware these interrupts are level-triggered. | ||
179 | @@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine) | ||
180 | } | ||
181 | fdt_add_timer_nodes(vms); | ||
182 | fdt_add_cpu_nodes(vms); | ||
183 | - fdt_add_psci_node(vms); | ||
184 | |||
185 | memory_region_allocate_system_memory(ram, NULL, "mach-virt.ram", | ||
186 | machine->ram_size); | ||
187 | -- | 39 | -- |
188 | 2.16.1 | 40 | 2.20.1 |
189 | 41 | ||
190 | 42 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Add tests that the A64FX CPU model exposes the expected features. |
4 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 4 | |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Signed-off-by: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> |
6 | Message-id: 20180123035349.24538-3-richard.henderson@linaro.org | 6 | Reviewed-by: Andrew Jones <drjones@redhat.com> |
7 | [PMM: added commit message body] | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 9 | --- |
9 | target/arm/cpu.h | 12 ++++++++++++ | 10 | tests/qtest/arm-cpu-features.c | 13 +++++++++++++ |
10 | 1 file changed, 12 insertions(+) | 11 | 1 file changed, 13 insertions(+) |
11 | 12 | ||
12 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 13 | diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c |
13 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/cpu.h | 15 | --- a/tests/qtest/arm-cpu-features.c |
15 | +++ b/target/arm/cpu.h | 16 | +++ b/tests/qtest/arm-cpu-features.c |
16 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMVectorReg { | 17 | @@ -XXX,XX +XXX,XX @@ static void test_query_cpu_model_expansion(const void *data) |
17 | uint64_t d[2 * ARM_MAX_VQ] QEMU_ALIGNED(16); | 18 | assert_has_feature_enabled(qts, "cortex-a57", "pmu"); |
18 | } ARMVectorReg; | 19 | assert_has_feature_enabled(qts, "cortex-a57", "aarch64"); |
19 | 20 | ||
20 | +/* In AArch32 mode, predicate registers do not exist at all. */ | 21 | + assert_has_feature_enabled(qts, "a64fx", "pmu"); |
21 | +#ifdef TARGET_AARCH64 | 22 | + assert_has_feature_enabled(qts, "a64fx", "aarch64"); |
22 | +typedef struct ARMPredicateReg { | 23 | + /* |
23 | + uint64_t p[2 * ARM_MAX_VQ / 8] QEMU_ALIGNED(16); | 24 | + * A64FX does not support any other vector lengths besides those |
24 | +} ARMPredicateReg; | 25 | + * that are enabled by default(128bit, 256bits, 512bit). |
25 | +#endif | 26 | + */ |
27 | + assert_has_feature_enabled(qts, "a64fx", "sve"); | ||
28 | + assert_sve_vls(qts, "a64fx", 0xb, NULL); | ||
29 | + assert_error(qts, "a64fx", "cannot enable sve384", | ||
30 | + "{ 'sve384': true }"); | ||
31 | + assert_error(qts, "a64fx", "cannot enable sve640", | ||
32 | + "{ 'sve640': true }"); | ||
26 | + | 33 | + |
27 | 34 | sve_tests_default(qts, "max"); | |
28 | typedef struct CPUARMState { | 35 | pauth_tests_default(qts, "max"); |
29 | /* Regs for current mode. */ | 36 | |
30 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | ||
31 | struct { | ||
32 | ARMVectorReg zregs[32]; | ||
33 | |||
34 | +#ifdef TARGET_AARCH64 | ||
35 | + /* Store FFR as pregs[16] to make it easier to treat as any other. */ | ||
36 | + ARMPredicateReg pregs[17]; | ||
37 | +#endif | ||
38 | + | ||
39 | uint32_t xregs[16]; | ||
40 | /* We store these fpcsr fields separately for convenience. */ | ||
41 | int vec_len; | ||
42 | -- | 37 | -- |
43 | 2.16.1 | 38 | 2.20.1 |
44 | 39 | ||
45 | 40 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | Currently we implement the RAS register block within the NVIC device. |
---|---|---|---|
2 | It isn't really very tightly coupled with the NVIC proper, so instead | ||
3 | move it out into a sysbus device of its own and have the top level | ||
4 | ARMv7M container create it and map it into memory at the right | ||
5 | address. | ||
2 | 6 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
10 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
11 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> | ||
12 | Message-id: 20210812093356.1946-2-peter.maydell@linaro.org | ||
13 | --- | ||
14 | include/hw/arm/armv7m.h | 2 + | ||
15 | include/hw/intc/armv7m_nvic.h | 1 - | ||
16 | include/hw/misc/armv7m_ras.h | 37 ++++++++++++++ | ||
17 | hw/arm/armv7m.c | 12 +++++ | ||
18 | hw/intc/armv7m_nvic.c | 56 --------------------- | ||
19 | hw/misc/armv7m_ras.c | 93 +++++++++++++++++++++++++++++++++++ | ||
20 | MAINTAINERS | 2 + | ||
21 | hw/misc/meson.build | 2 + | ||
22 | 8 files changed, 148 insertions(+), 57 deletions(-) | ||
23 | create mode 100644 include/hw/misc/armv7m_ras.h | ||
24 | create mode 100644 hw/misc/armv7m_ras.c | ||
4 | 25 | ||
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | 26 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h |
6 | Cc: Jason Wang <jasowang@redhat.com> | 27 | index XXXXXXX..XXXXXXX 100644 |
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 28 | --- a/include/hw/arm/armv7m.h |
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | 29 | +++ b/include/hw/arm/armv7m.h |
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | 30 | @@ -XXX,XX +XXX,XX @@ |
10 | Cc: qemu-devel@nongnu.org | 31 | |
11 | Cc: qemu-arm@nongnu.org | 32 | #include "hw/sysbus.h" |
12 | Cc: yurovsky@gmail.com | 33 | #include "hw/intc/armv7m_nvic.h" |
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 34 | +#include "hw/misc/armv7m_ras.h" |
14 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | 35 | #include "target/arm/idau.h" |
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 36 | #include "qom/object.h" |
16 | --- | 37 | |
17 | hw/intc/Makefile.objs | 2 +- | 38 | @@ -XXX,XX +XXX,XX @@ struct ARMv7MState { |
18 | include/hw/intc/imx_gpcv2.h | 22 ++++++++ | 39 | NVICState nvic; |
19 | hw/intc/imx_gpcv2.c | 125 ++++++++++++++++++++++++++++++++++++++++++++ | 40 | BitBandState bitband[ARMV7M_NUM_BITBANDS]; |
20 | 3 files changed, 148 insertions(+), 1 deletion(-) | 41 | ARMCPU *cpu; |
21 | create mode 100644 include/hw/intc/imx_gpcv2.h | 42 | + ARMv7MRAS ras; |
22 | create mode 100644 hw/intc/imx_gpcv2.c | 43 | |
23 | 44 | /* MemoryRegion we pass to the CPU, with our devices layered on | |
24 | diff --git a/hw/intc/Makefile.objs b/hw/intc/Makefile.objs | 45 | * top of the ones the board provides in board_memory. |
25 | index XXXXXXX..XXXXXXX 100644 | 46 | diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h |
26 | --- a/hw/intc/Makefile.objs | 47 | index XXXXXXX..XXXXXXX 100644 |
27 | +++ b/hw/intc/Makefile.objs | 48 | --- a/include/hw/intc/armv7m_nvic.h |
28 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_XILINX) += xilinx_intc.o | 49 | +++ b/include/hw/intc/armv7m_nvic.h |
29 | common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-pmu-iomod-intc.o | 50 | @@ -XXX,XX +XXX,XX @@ struct NVICState { |
30 | common-obj-$(CONFIG_XLNX_ZYNQMP) += xlnx-zynqmp-ipi.o | 51 | MemoryRegion sysreg_ns_mem; |
31 | common-obj-$(CONFIG_ETRAXFS) += etraxfs_pic.o | 52 | MemoryRegion systickmem; |
32 | -common-obj-$(CONFIG_IMX) += imx_avic.o | 53 | MemoryRegion systick_ns_mem; |
33 | +common-obj-$(CONFIG_IMX) += imx_avic.o imx_gpcv2.o | 54 | - MemoryRegion ras_mem; |
34 | common-obj-$(CONFIG_LM32) += lm32_pic.o | 55 | MemoryRegion container; |
35 | common-obj-$(CONFIG_REALVIEW) += realview_gic.o | 56 | MemoryRegion defaultmem; |
36 | common-obj-$(CONFIG_SLAVIO) += slavio_intctl.o | 57 | |
37 | diff --git a/include/hw/intc/imx_gpcv2.h b/include/hw/intc/imx_gpcv2.h | 58 | diff --git a/include/hw/misc/armv7m_ras.h b/include/hw/misc/armv7m_ras.h |
38 | new file mode 100644 | 59 | new file mode 100644 |
39 | index XXXXXXX..XXXXXXX | 60 | index XXXXXXX..XXXXXXX |
40 | --- /dev/null | 61 | --- /dev/null |
41 | +++ b/include/hw/intc/imx_gpcv2.h | 62 | +++ b/include/hw/misc/armv7m_ras.h |
42 | @@ -XXX,XX +XXX,XX @@ | 63 | @@ -XXX,XX +XXX,XX @@ |
43 | +#ifndef IMX_GPCV2_H | 64 | +/* |
44 | +#define IMX_GPCV2_H | 65 | + * Arm M-profile RAS (Reliability, Availability and Serviceability) block |
66 | + * | ||
67 | + * Copyright (c) 2021 Linaro Limited | ||
68 | + * | ||
69 | + * This program is free software; you can redistribute it and/or modify | ||
70 | + * it under the terms of the GNU General Public License version 2 or | ||
71 | + * (at your option) any later version. | ||
72 | + */ | ||
73 | + | ||
74 | +/* | ||
75 | + * This is a model of the RAS register block of an M-profile CPU | ||
76 | + * (the registers starting at 0xE0005000 with ERRFRn). | ||
77 | + * | ||
78 | + * QEMU interface: | ||
79 | + * + sysbus MMIO region 0: the register bank | ||
80 | + * | ||
81 | + * The QEMU implementation currently provides "minimal RAS" only. | ||
82 | + */ | ||
83 | + | ||
84 | +#ifndef HW_MISC_ARMV7M_RAS_H | ||
85 | +#define HW_MISC_ARMV7M_RAS_H | ||
45 | + | 86 | + |
46 | +#include "hw/sysbus.h" | 87 | +#include "hw/sysbus.h" |
47 | + | 88 | + |
48 | +enum IMXGPCv2Registers { | 89 | +#define TYPE_ARMV7M_RAS "armv7m-ras" |
49 | + GPC_NUM = 0xE00 / sizeof(uint32_t), | 90 | +OBJECT_DECLARE_SIMPLE_TYPE(ARMv7MRAS, ARMV7M_RAS) |
50 | +}; | 91 | + |
51 | + | 92 | +struct ARMv7MRAS { |
52 | +typedef struct IMXGPCv2State { | ||
53 | + /*< private >*/ | 93 | + /*< private >*/ |
54 | + SysBusDevice parent_obj; | 94 | + SysBusDevice parent_obj; |
55 | + | 95 | + |
56 | + /*< public >*/ | 96 | + /*< public >*/ |
57 | + MemoryRegion iomem; | 97 | + MemoryRegion iomem; |
58 | + uint32_t regs[GPC_NUM]; | 98 | +}; |
59 | +} IMXGPCv2State; | 99 | + |
60 | + | 100 | +#endif |
61 | +#define TYPE_IMX_GPCV2 "imx-gpcv2" | 101 | diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c |
62 | +#define IMX_GPCV2(obj) OBJECT_CHECK(IMXGPCv2State, (obj), TYPE_IMX_GPCV2) | 102 | index XXXXXXX..XXXXXXX 100644 |
63 | + | 103 | --- a/hw/arm/armv7m.c |
64 | +#endif /* IMX_GPCV2_H */ | 104 | +++ b/hw/arm/armv7m.c |
65 | diff --git a/hw/intc/imx_gpcv2.c b/hw/intc/imx_gpcv2.c | 105 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) |
106 | memory_region_add_subregion(&s->container, 0xe0000000, | ||
107 | sysbus_mmio_get_region(sbd, 0)); | ||
108 | |||
109 | + /* If the CPU has RAS support, create the RAS register block */ | ||
110 | + if (cpu_isar_feature(aa32_ras, s->cpu)) { | ||
111 | + object_initialize_child(OBJECT(dev), "armv7m-ras", | ||
112 | + &s->ras, TYPE_ARMV7M_RAS); | ||
113 | + sbd = SYS_BUS_DEVICE(&s->ras); | ||
114 | + if (!sysbus_realize(sbd, errp)) { | ||
115 | + return; | ||
116 | + } | ||
117 | + memory_region_add_subregion_overlap(&s->container, 0xe0005000, | ||
118 | + sysbus_mmio_get_region(sbd, 0), 1); | ||
119 | + } | ||
120 | + | ||
121 | for (i = 0; i < ARRAY_SIZE(s->bitband); i++) { | ||
122 | if (s->enable_bitband) { | ||
123 | Object *obj = OBJECT(&s->bitband[i]); | ||
124 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | ||
125 | index XXXXXXX..XXXXXXX 100644 | ||
126 | --- a/hw/intc/armv7m_nvic.c | ||
127 | +++ b/hw/intc/armv7m_nvic.c | ||
128 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvic_systick_ops = { | ||
129 | .endianness = DEVICE_NATIVE_ENDIAN, | ||
130 | }; | ||
131 | |||
132 | - | ||
133 | -static MemTxResult ras_read(void *opaque, hwaddr addr, | ||
134 | - uint64_t *data, unsigned size, | ||
135 | - MemTxAttrs attrs) | ||
136 | -{ | ||
137 | - if (attrs.user) { | ||
138 | - return MEMTX_ERROR; | ||
139 | - } | ||
140 | - | ||
141 | - switch (addr) { | ||
142 | - case 0xe10: /* ERRIIDR */ | ||
143 | - /* architect field = Arm; product/variant/revision 0 */ | ||
144 | - *data = 0x43b; | ||
145 | - break; | ||
146 | - case 0xfc8: /* ERRDEVID */ | ||
147 | - /* Minimal RAS: we implement 0 error record indexes */ | ||
148 | - *data = 0; | ||
149 | - break; | ||
150 | - default: | ||
151 | - qemu_log_mask(LOG_UNIMP, "Read RAS register offset 0x%x\n", | ||
152 | - (uint32_t)addr); | ||
153 | - *data = 0; | ||
154 | - break; | ||
155 | - } | ||
156 | - return MEMTX_OK; | ||
157 | -} | ||
158 | - | ||
159 | -static MemTxResult ras_write(void *opaque, hwaddr addr, | ||
160 | - uint64_t value, unsigned size, | ||
161 | - MemTxAttrs attrs) | ||
162 | -{ | ||
163 | - if (attrs.user) { | ||
164 | - return MEMTX_ERROR; | ||
165 | - } | ||
166 | - | ||
167 | - switch (addr) { | ||
168 | - default: | ||
169 | - qemu_log_mask(LOG_UNIMP, "Write to RAS register offset 0x%x\n", | ||
170 | - (uint32_t)addr); | ||
171 | - break; | ||
172 | - } | ||
173 | - return MEMTX_OK; | ||
174 | -} | ||
175 | - | ||
176 | -static const MemoryRegionOps ras_ops = { | ||
177 | - .read_with_attrs = ras_read, | ||
178 | - .write_with_attrs = ras_write, | ||
179 | - .endianness = DEVICE_NATIVE_ENDIAN, | ||
180 | -}; | ||
181 | - | ||
182 | /* | ||
183 | * Unassigned portions of the PPB space are RAZ/WI for privileged | ||
184 | * accesses, and fault for non-privileged accesses. | ||
185 | @@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp) | ||
186 | &s->systick_ns_mem, 1); | ||
187 | } | ||
188 | |||
189 | - if (cpu_isar_feature(aa32_ras, s->cpu)) { | ||
190 | - memory_region_init_io(&s->ras_mem, OBJECT(s), | ||
191 | - &ras_ops, s, "nvic_ras", 0x1000); | ||
192 | - memory_region_add_subregion(&s->container, 0x5000, &s->ras_mem); | ||
193 | - } | ||
194 | - | ||
195 | sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->container); | ||
196 | } | ||
197 | |||
198 | diff --git a/hw/misc/armv7m_ras.c b/hw/misc/armv7m_ras.c | ||
66 | new file mode 100644 | 199 | new file mode 100644 |
67 | index XXXXXXX..XXXXXXX | 200 | index XXXXXXX..XXXXXXX |
68 | --- /dev/null | 201 | --- /dev/null |
69 | +++ b/hw/intc/imx_gpcv2.c | 202 | +++ b/hw/misc/armv7m_ras.c |
70 | @@ -XXX,XX +XXX,XX @@ | 203 | @@ -XXX,XX +XXX,XX @@ |
71 | +/* | 204 | +/* |
72 | + * Copyright (c) 2018, Impinj, Inc. | 205 | + * Arm M-profile RAS (Reliability, Availability and Serviceability) block |
73 | + * | 206 | + * |
74 | + * i.MX7 GPCv2 block emulation code | 207 | + * Copyright (c) 2021 Linaro Limited |
75 | + * | 208 | + * |
76 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 209 | + * This program is free software; you can redistribute it and/or modify |
77 | + * | 210 | + * it under the terms of the GNU General Public License version 2 or |
78 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 211 | + * (at your option) any later version. |
79 | + * See the COPYING file in the top-level directory. | ||
80 | + */ | 212 | + */ |
81 | + | 213 | + |
82 | +#include "qemu/osdep.h" | 214 | +#include "qemu/osdep.h" |
83 | +#include "hw/intc/imx_gpcv2.h" | 215 | +#include "hw/misc/armv7m_ras.h" |
84 | +#include "qemu/log.h" | 216 | +#include "qemu/log.h" |
85 | + | 217 | + |
86 | +#define GPC_PU_PGC_SW_PUP_REQ 0x0f8 | 218 | +static MemTxResult ras_read(void *opaque, hwaddr addr, |
87 | +#define GPC_PU_PGC_SW_PDN_REQ 0x104 | 219 | + uint64_t *data, unsigned size, |
88 | + | 220 | + MemTxAttrs attrs) |
89 | +#define USB_HSIC_PHY_SW_Pxx_REQ BIT(4) | 221 | +{ |
90 | +#define USB_OTG2_PHY_SW_Pxx_REQ BIT(3) | 222 | + if (attrs.user) { |
91 | +#define USB_OTG1_PHY_SW_Pxx_REQ BIT(2) | 223 | + return MEMTX_ERROR; |
92 | +#define PCIE_PHY_SW_Pxx_REQ BIT(1) | 224 | + } |
93 | +#define MIPI_PHY_SW_Pxx_REQ BIT(0) | 225 | + |
94 | + | 226 | + switch (addr) { |
95 | + | 227 | + case 0xe10: /* ERRIIDR */ |
96 | +static void imx_gpcv2_reset(DeviceState *dev) | 228 | + /* architect field = Arm; product/variant/revision 0 */ |
97 | +{ | 229 | + *data = 0x43b; |
98 | + IMXGPCv2State *s = IMX_GPCV2(dev); | 230 | + break; |
99 | + | 231 | + case 0xfc8: /* ERRDEVID */ |
100 | + memset(s->regs, 0, sizeof(s->regs)); | 232 | + /* Minimal RAS: we implement 0 error record indexes */ |
101 | +} | 233 | + *data = 0; |
102 | + | 234 | + break; |
103 | +static uint64_t imx_gpcv2_read(void *opaque, hwaddr offset, | 235 | + default: |
104 | + unsigned size) | 236 | + qemu_log_mask(LOG_UNIMP, "Read RAS register offset 0x%x\n", |
105 | +{ | 237 | + (uint32_t)addr); |
106 | + IMXGPCv2State *s = opaque; | 238 | + *data = 0; |
107 | + | 239 | + break; |
108 | + return s->regs[offset / sizeof(uint32_t)]; | 240 | + } |
109 | +} | 241 | + return MEMTX_OK; |
110 | + | 242 | +} |
111 | +static void imx_gpcv2_write(void *opaque, hwaddr offset, | 243 | + |
112 | + uint64_t value, unsigned size) | 244 | +static MemTxResult ras_write(void *opaque, hwaddr addr, |
113 | +{ | 245 | + uint64_t value, unsigned size, |
114 | + IMXGPCv2State *s = opaque; | 246 | + MemTxAttrs attrs) |
115 | + const size_t idx = offset / sizeof(uint32_t); | 247 | +{ |
116 | + | 248 | + if (attrs.user) { |
117 | + s->regs[idx] = value; | 249 | + return MEMTX_ERROR; |
118 | + | 250 | + } |
119 | + /* | 251 | + |
120 | + * Real HW will clear those bits once as a way to indicate that | 252 | + switch (addr) { |
121 | + * power up request is complete | 253 | + default: |
122 | + */ | 254 | + qemu_log_mask(LOG_UNIMP, "Write to RAS register offset 0x%x\n", |
123 | + if (offset == GPC_PU_PGC_SW_PUP_REQ || | 255 | + (uint32_t)addr); |
124 | + offset == GPC_PU_PGC_SW_PDN_REQ) { | 256 | + break; |
125 | + s->regs[idx] &= ~(USB_HSIC_PHY_SW_Pxx_REQ | | 257 | + } |
126 | + USB_OTG2_PHY_SW_Pxx_REQ | | 258 | + return MEMTX_OK; |
127 | + USB_OTG1_PHY_SW_Pxx_REQ | | 259 | +} |
128 | + PCIE_PHY_SW_Pxx_REQ | | 260 | + |
129 | + MIPI_PHY_SW_Pxx_REQ); | 261 | +static const MemoryRegionOps ras_ops = { |
130 | + } | 262 | + .read_with_attrs = ras_read, |
131 | +} | 263 | + .write_with_attrs = ras_write, |
132 | + | ||
133 | +static const struct MemoryRegionOps imx_gpcv2_ops = { | ||
134 | + .read = imx_gpcv2_read, | ||
135 | + .write = imx_gpcv2_write, | ||
136 | + .endianness = DEVICE_NATIVE_ENDIAN, | 264 | + .endianness = DEVICE_NATIVE_ENDIAN, |
137 | + .impl = { | ||
138 | + /* | ||
139 | + * Our device would not work correctly if the guest was doing | ||
140 | + * unaligned access. This might not be a limitation on the real | ||
141 | + * device but in practice there is no reason for a guest to access | ||
142 | + * this device unaligned. | ||
143 | + */ | ||
144 | + .min_access_size = 4, | ||
145 | + .max_access_size = 4, | ||
146 | + .unaligned = false, | ||
147 | + }, | ||
148 | +}; | 265 | +}; |
149 | + | 266 | + |
150 | +static void imx_gpcv2_init(Object *obj) | 267 | + |
151 | +{ | 268 | +static void armv7m_ras_init(Object *obj) |
152 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | 269 | +{ |
153 | + IMXGPCv2State *s = IMX_GPCV2(obj); | 270 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); |
154 | + | 271 | + ARMv7MRAS *s = ARMV7M_RAS(obj); |
155 | + memory_region_init_io(&s->iomem, | 272 | + |
156 | + obj, | 273 | + memory_region_init_io(&s->iomem, obj, &ras_ops, |
157 | + &imx_gpcv2_ops, | 274 | + s, "armv7m-ras", 0x1000); |
158 | + s, | 275 | + sysbus_init_mmio(sbd, &s->iomem); |
159 | + TYPE_IMX_GPCV2 ".iomem", | 276 | +} |
160 | + sizeof(s->regs)); | 277 | + |
161 | + sysbus_init_mmio(sd, &s->iomem); | 278 | +static void armv7m_ras_class_init(ObjectClass *klass, void *data) |
162 | +} | 279 | +{ |
163 | + | 280 | + /* This device has no state: no need for vmstate or reset */ |
164 | +static const VMStateDescription vmstate_imx_gpcv2 = { | 281 | +} |
165 | + .name = TYPE_IMX_GPCV2, | 282 | + |
166 | + .version_id = 1, | 283 | +static const TypeInfo armv7m_ras_info = { |
167 | + .minimum_version_id = 1, | 284 | + .name = TYPE_ARMV7M_RAS, |
168 | + .fields = (VMStateField[]) { | 285 | + .parent = TYPE_SYS_BUS_DEVICE, |
169 | + VMSTATE_UINT32_ARRAY(regs, IMXGPCv2State, GPC_NUM), | 286 | + .instance_size = sizeof(ARMv7MRAS), |
170 | + VMSTATE_END_OF_LIST() | 287 | + .instance_init = armv7m_ras_init, |
171 | + }, | 288 | + .class_init = armv7m_ras_class_init, |
172 | +}; | 289 | +}; |
173 | + | 290 | + |
174 | +static void imx_gpcv2_class_init(ObjectClass *klass, void *data) | 291 | +static void armv7m_ras_register_types(void) |
175 | +{ | 292 | +{ |
176 | + DeviceClass *dc = DEVICE_CLASS(klass); | 293 | + type_register_static(&armv7m_ras_info); |
177 | + | 294 | +} |
178 | + dc->reset = imx_gpcv2_reset; | 295 | + |
179 | + dc->vmsd = &vmstate_imx_gpcv2; | 296 | +type_init(armv7m_ras_register_types); |
180 | + dc->desc = "i.MX GPCv2 Module"; | 297 | diff --git a/MAINTAINERS b/MAINTAINERS |
181 | +} | 298 | index XXXXXXX..XXXXXXX 100644 |
182 | + | 299 | --- a/MAINTAINERS |
183 | +static const TypeInfo imx_gpcv2_info = { | 300 | +++ b/MAINTAINERS |
184 | + .name = TYPE_IMX_GPCV2, | 301 | @@ -XXX,XX +XXX,XX @@ F: hw/intc/gic_internal.h |
185 | + .parent = TYPE_SYS_BUS_DEVICE, | 302 | F: hw/misc/a9scu.c |
186 | + .instance_size = sizeof(IMXGPCv2State), | 303 | F: hw/misc/arm11scu.c |
187 | + .instance_init = imx_gpcv2_init, | 304 | F: hw/misc/arm_l2x0.c |
188 | + .class_init = imx_gpcv2_class_init, | 305 | +F: hw/misc/armv7m_ras.c |
189 | +}; | 306 | F: hw/timer/a9gtimer* |
190 | + | 307 | F: hw/timer/arm* |
191 | +static void imx_gpcv2_register_type(void) | 308 | F: include/hw/arm/arm*.h |
192 | +{ | 309 | @@ -XXX,XX +XXX,XX @@ F: include/hw/misc/arm11scu.h |
193 | + type_register_static(&imx_gpcv2_info); | 310 | F: include/hw/timer/a9gtimer.h |
194 | +} | 311 | F: include/hw/timer/arm_mptimer.h |
195 | +type_init(imx_gpcv2_register_type) | 312 | F: include/hw/timer/armv7m_systick.h |
313 | +F: include/hw/misc/armv7m_ras.h | ||
314 | F: tests/qtest/test-arm-mptimer.c | ||
315 | |||
316 | Exynos | ||
317 | diff --git a/hw/misc/meson.build b/hw/misc/meson.build | ||
318 | index XXXXXXX..XXXXXXX 100644 | ||
319 | --- a/hw/misc/meson.build | ||
320 | +++ b/hw/misc/meson.build | ||
321 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_INTEGRATOR_DEBUG', if_true: files('arm_integrator_d | ||
322 | softmmu_ss.add(when: 'CONFIG_A9SCU', if_true: files('a9scu.c')) | ||
323 | softmmu_ss.add(when: 'CONFIG_ARM11SCU', if_true: files('arm11scu.c')) | ||
324 | |||
325 | +softmmu_ss.add(when: 'CONFIG_ARM_V7M', if_true: files('armv7m_ras.c')) | ||
326 | + | ||
327 | # Mac devices | ||
328 | softmmu_ss.add(when: 'CONFIG_MOS6522', if_true: files('mos6522.c')) | ||
329 | |||
196 | -- | 330 | -- |
197 | 2.16.1 | 331 | 2.20.1 |
198 | 332 | ||
199 | 333 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | There's no particular reason why the NVIC should be owning the |
---|---|---|---|
2 | 2 | SysTick device objects; move them into the ARMv7M container object | |
3 | This implements emulation of the new SHA-512 instructions that have | 3 | instead, as part of consolidating the "create the devices which are |
4 | been added as an optional extensions to the ARMv8 Crypto Extensions | 4 | built into an M-profile CPU and map them into their architected |
5 | in ARM v8.2. | 5 | locations in the address space" work into one place. |
6 | 6 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 7 | This involves temporarily creating a duplicate copy of the |
8 | Message-id: 20180207111729.15737-2-ard.biesheuvel@linaro.org | 8 | nvic_sysreg_ns_ops struct and its read/write functions (renamed as |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | v7m_sysreg_ns_*), but we will delete the NVIC's copy of this code in |
10 | a subsequent patch. | ||
11 | |||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
15 | Message-id: 20210812093356.1946-3-peter.maydell@linaro.org | ||
11 | --- | 16 | --- |
12 | target/arm/cpu.h | 1 + | 17 | include/hw/arm/armv7m.h | 12 ++++ |
13 | target/arm/helper.h | 5 +++ | 18 | include/hw/intc/armv7m_nvic.h | 4 -- |
14 | target/arm/crypto_helper.c | 90 ++++++++++++++++++++++++++++++++++++- | 19 | hw/arm/armv7m.c | 125 ++++++++++++++++++++++++++++++++++ |
15 | target/arm/translate-a64.c | 110 +++++++++++++++++++++++++++++++++++++++++++++ | 20 | hw/intc/armv7m_nvic.c | 73 -------------------- |
16 | 4 files changed, 205 insertions(+), 1 deletion(-) | 21 | 4 files changed, 137 insertions(+), 77 deletions(-) |
17 | 22 | ||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 23 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h |
19 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/cpu.h | 25 | --- a/include/hw/arm/armv7m.h |
21 | +++ b/target/arm/cpu.h | 26 | +++ b/include/hw/arm/armv7m.h |
22 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 27 | @@ -XXX,XX +XXX,XX @@ struct ARMv7MState { |
23 | ARM_FEATURE_M_SECURITY, /* M profile Security Extension */ | 28 | BitBandState bitband[ARMV7M_NUM_BITBANDS]; |
24 | ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ | 29 | ARMCPU *cpu; |
25 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | 30 | ARMv7MRAS ras; |
26 | + ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | 31 | + SysTickState systick[M_REG_NUM_BANKS]; |
32 | |||
33 | /* MemoryRegion we pass to the CPU, with our devices layered on | ||
34 | * top of the ones the board provides in board_memory. | ||
35 | */ | ||
36 | MemoryRegion container; | ||
37 | + /* | ||
38 | + * MemoryRegion which passes the transaction to either the S or the | ||
39 | + * NS systick device depending on the transaction attributes | ||
40 | + */ | ||
41 | + MemoryRegion systickmem; | ||
42 | + /* | ||
43 | + * MemoryRegion which enforces the S/NS handling of the systick | ||
44 | + * device NS alias region and passes the transaction to the | ||
45 | + * NS systick device if appropriate. | ||
46 | + */ | ||
47 | + MemoryRegion systick_ns_mem; | ||
48 | |||
49 | /* Properties */ | ||
50 | char *cpu_type; | ||
51 | diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/include/hw/intc/armv7m_nvic.h | ||
54 | +++ b/include/hw/intc/armv7m_nvic.h | ||
55 | @@ -XXX,XX +XXX,XX @@ struct NVICState { | ||
56 | |||
57 | MemoryRegion sysregmem; | ||
58 | MemoryRegion sysreg_ns_mem; | ||
59 | - MemoryRegion systickmem; | ||
60 | - MemoryRegion systick_ns_mem; | ||
61 | MemoryRegion container; | ||
62 | MemoryRegion defaultmem; | ||
63 | |||
64 | uint32_t num_irq; | ||
65 | qemu_irq excpout; | ||
66 | qemu_irq sysresetreq; | ||
67 | - | ||
68 | - SysTickState systick[M_REG_NUM_BANKS]; | ||
27 | }; | 69 | }; |
28 | 70 | ||
29 | static inline int arm_feature(CPUARMState *env, int feature) | 71 | #endif |
30 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 72 | diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c |
31 | index XXXXXXX..XXXXXXX 100644 | 73 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/arm/helper.h | 74 | --- a/hw/arm/armv7m.c |
33 | +++ b/target/arm/helper.h | 75 | +++ b/hw/arm/armv7m.c |
34 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(crypto_sha256h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 76 | @@ -XXX,XX +XXX,XX @@ static const hwaddr bitband_output_addr[ARMV7M_NUM_BITBANDS] = { |
35 | DEF_HELPER_FLAGS_2(crypto_sha256su0, TCG_CALL_NO_RWG, void, ptr, ptr) | 77 | 0x22000000, 0x42000000 |
36 | DEF_HELPER_FLAGS_3(crypto_sha256su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 78 | }; |
37 | 79 | ||
38 | +DEF_HELPER_FLAGS_3(crypto_sha512h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 80 | +static MemTxResult v7m_sysreg_ns_write(void *opaque, hwaddr addr, |
39 | +DEF_HELPER_FLAGS_3(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 81 | + uint64_t value, unsigned size, |
40 | +DEF_HELPER_FLAGS_2(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr) | 82 | + MemTxAttrs attrs) |
41 | +DEF_HELPER_FLAGS_3(crypto_sha512su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
42 | + | ||
43 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | ||
44 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | ||
45 | DEF_HELPER_2(dc_zva, void, env, i64) | ||
46 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/target/arm/crypto_helper.c | ||
49 | +++ b/target/arm/crypto_helper.c | ||
50 | @@ -XXX,XX +XXX,XX @@ | ||
51 | /* | ||
52 | * crypto_helper.c - emulate v8 Crypto Extensions instructions | ||
53 | * | ||
54 | - * Copyright (C) 2013 - 2014 Linaro Ltd <ard.biesheuvel@linaro.org> | ||
55 | + * Copyright (C) 2013 - 2018 Linaro Ltd <ard.biesheuvel@linaro.org> | ||
56 | * | ||
57 | * This library is free software; you can redistribute it and/or | ||
58 | * modify it under the terms of the GNU Lesser General Public | ||
59 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha256su1)(void *vd, void *vn, void *vm) | ||
60 | rd[0] = d.l[0]; | ||
61 | rd[1] = d.l[1]; | ||
62 | } | ||
63 | + | ||
64 | +/* | ||
65 | + * The SHA-512 logical functions (same as above but using 64-bit operands) | ||
66 | + */ | ||
67 | + | ||
68 | +static uint64_t cho512(uint64_t x, uint64_t y, uint64_t z) | ||
69 | +{ | 83 | +{ |
70 | + return (x & (y ^ z)) ^ z; | 84 | + MemoryRegion *mr = opaque; |
85 | + | ||
86 | + if (attrs.secure) { | ||
87 | + /* S accesses to the alias act like NS accesses to the real region */ | ||
88 | + attrs.secure = 0; | ||
89 | + return memory_region_dispatch_write(mr, addr, value, | ||
90 | + size_memop(size) | MO_TE, attrs); | ||
91 | + } else { | ||
92 | + /* NS attrs are RAZ/WI for privileged, and BusFault for user */ | ||
93 | + if (attrs.user) { | ||
94 | + return MEMTX_ERROR; | ||
95 | + } | ||
96 | + return MEMTX_OK; | ||
97 | + } | ||
71 | +} | 98 | +} |
72 | + | 99 | + |
73 | +static uint64_t maj512(uint64_t x, uint64_t y, uint64_t z) | 100 | +static MemTxResult v7m_sysreg_ns_read(void *opaque, hwaddr addr, |
101 | + uint64_t *data, unsigned size, | ||
102 | + MemTxAttrs attrs) | ||
74 | +{ | 103 | +{ |
75 | + return (x & y) | ((x | y) & z); | 104 | + MemoryRegion *mr = opaque; |
105 | + | ||
106 | + if (attrs.secure) { | ||
107 | + /* S accesses to the alias act like NS accesses to the real region */ | ||
108 | + attrs.secure = 0; | ||
109 | + return memory_region_dispatch_read(mr, addr, data, | ||
110 | + size_memop(size) | MO_TE, attrs); | ||
111 | + } else { | ||
112 | + /* NS attrs are RAZ/WI for privileged, and BusFault for user */ | ||
113 | + if (attrs.user) { | ||
114 | + return MEMTX_ERROR; | ||
115 | + } | ||
116 | + *data = 0; | ||
117 | + return MEMTX_OK; | ||
118 | + } | ||
76 | +} | 119 | +} |
77 | + | 120 | + |
78 | +static uint64_t S0_512(uint64_t x) | 121 | +static const MemoryRegionOps v7m_sysreg_ns_ops = { |
122 | + .read_with_attrs = v7m_sysreg_ns_read, | ||
123 | + .write_with_attrs = v7m_sysreg_ns_write, | ||
124 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
125 | +}; | ||
126 | + | ||
127 | +static MemTxResult v7m_systick_write(void *opaque, hwaddr addr, | ||
128 | + uint64_t value, unsigned size, | ||
129 | + MemTxAttrs attrs) | ||
79 | +{ | 130 | +{ |
80 | + return ror64(x, 28) ^ ror64(x, 34) ^ ror64(x, 39); | 131 | + ARMv7MState *s = opaque; |
132 | + MemoryRegion *mr; | ||
133 | + | ||
134 | + /* Direct the access to the correct systick */ | ||
135 | + mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->systick[attrs.secure]), 0); | ||
136 | + return memory_region_dispatch_write(mr, addr, value, | ||
137 | + size_memop(size) | MO_TE, attrs); | ||
81 | +} | 138 | +} |
82 | + | 139 | + |
83 | +static uint64_t S1_512(uint64_t x) | 140 | +static MemTxResult v7m_systick_read(void *opaque, hwaddr addr, |
141 | + uint64_t *data, unsigned size, | ||
142 | + MemTxAttrs attrs) | ||
84 | +{ | 143 | +{ |
85 | + return ror64(x, 14) ^ ror64(x, 18) ^ ror64(x, 41); | 144 | + ARMv7MState *s = opaque; |
145 | + MemoryRegion *mr; | ||
146 | + | ||
147 | + /* Direct the access to the correct systick */ | ||
148 | + mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->systick[attrs.secure]), 0); | ||
149 | + return memory_region_dispatch_read(mr, addr, data, size_memop(size) | MO_TE, | ||
150 | + attrs); | ||
86 | +} | 151 | +} |
87 | + | 152 | + |
88 | +static uint64_t s0_512(uint64_t x) | 153 | +static const MemoryRegionOps v7m_systick_ops = { |
89 | +{ | 154 | + .read_with_attrs = v7m_systick_read, |
90 | + return ror64(x, 1) ^ ror64(x, 8) ^ (x >> 7); | 155 | + .write_with_attrs = v7m_systick_write, |
91 | +} | 156 | + .endianness = DEVICE_NATIVE_ENDIAN, |
92 | + | 157 | +}; |
93 | +static uint64_t s1_512(uint64_t x) | 158 | + |
94 | +{ | 159 | static void armv7m_instance_init(Object *obj) |
95 | + return ror64(x, 19) ^ ror64(x, 61) ^ (x >> 6); | 160 | { |
96 | +} | 161 | ARMv7MState *s = ARMV7M(obj); |
97 | + | 162 | @@ -XXX,XX +XXX,XX @@ static void armv7m_instance_init(Object *obj) |
98 | +void HELPER(crypto_sha512h)(void *vd, void *vn, void *vm) | 163 | object_property_add_alias(obj, "num-irq", |
99 | +{ | 164 | OBJECT(&s->nvic), "num-irq"); |
100 | + uint64_t *rd = vd; | 165 | |
101 | + uint64_t *rn = vn; | 166 | + object_initialize_child(obj, "systick-reg-ns", &s->systick[M_REG_NS], |
102 | + uint64_t *rm = vm; | 167 | + TYPE_SYSTICK); |
103 | + uint64_t d0 = rd[0]; | 168 | + /* |
104 | + uint64_t d1 = rd[1]; | 169 | + * We can't initialize the secure systick here, as we don't know |
105 | + | 170 | + * yet if we need it. |
106 | + d1 += S1_512(rm[1]) + cho512(rm[1], rn[0], rn[1]); | 171 | + */ |
107 | + d0 += S1_512(d1 + rm[0]) + cho512(d1 + rm[0], rm[1], rn[0]); | 172 | + |
108 | + | 173 | for (i = 0; i < ARRAY_SIZE(s->bitband); i++) { |
109 | + rd[0] = d0; | 174 | object_initialize_child(obj, "bitband[*]", &s->bitband[i], |
110 | + rd[1] = d1; | 175 | TYPE_BITBAND); |
111 | +} | 176 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) |
112 | + | 177 | memory_region_add_subregion(&s->container, 0xe0000000, |
113 | +void HELPER(crypto_sha512h2)(void *vd, void *vn, void *vm) | 178 | sysbus_mmio_get_region(sbd, 0)); |
114 | +{ | 179 | |
115 | + uint64_t *rd = vd; | 180 | + /* Create and map the systick devices */ |
116 | + uint64_t *rn = vn; | 181 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), errp)) { |
117 | + uint64_t *rm = vm; | 182 | + return; |
118 | + uint64_t d0 = rd[0]; | 183 | + } |
119 | + uint64_t d1 = rd[1]; | 184 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), 0, |
120 | + | 185 | + qdev_get_gpio_in_named(DEVICE(&s->nvic), |
121 | + d1 += S0_512(rm[0]) + maj512(rn[0], rm[1], rm[0]); | 186 | + "systick-trigger", M_REG_NS)); |
122 | + d0 += S0_512(d1) + maj512(d1, rm[0], rm[1]); | 187 | + |
123 | + | 188 | + if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY)) { |
124 | + rd[0] = d0; | 189 | + /* |
125 | + rd[1] = d1; | 190 | + * We couldn't init the secure systick device in instance_init |
126 | +} | 191 | + * as we didn't know then if the CPU had the security extensions; |
127 | + | 192 | + * so we have to do it here. |
128 | +void HELPER(crypto_sha512su0)(void *vd, void *vn) | 193 | + */ |
129 | +{ | 194 | + object_initialize_child(OBJECT(dev), "systick-reg-s", |
130 | + uint64_t *rd = vd; | 195 | + &s->systick[M_REG_S], TYPE_SYSTICK); |
131 | + uint64_t *rn = vn; | 196 | + |
132 | + uint64_t d0 = rd[0]; | 197 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_S]), errp)) { |
133 | + uint64_t d1 = rd[1]; | ||
134 | + | ||
135 | + d0 += s0_512(rd[1]); | ||
136 | + d1 += s0_512(rn[0]); | ||
137 | + | ||
138 | + rd[0] = d0; | ||
139 | + rd[1] = d1; | ||
140 | +} | ||
141 | + | ||
142 | +void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm) | ||
143 | +{ | ||
144 | + uint64_t *rd = vd; | ||
145 | + uint64_t *rn = vn; | ||
146 | + uint64_t *rm = vm; | ||
147 | + | ||
148 | + rd[0] += s1_512(rn[0]) + rm[0]; | ||
149 | + rd[1] += s1_512(rn[1]) + rm[1]; | ||
150 | +} | ||
151 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
152 | index XXXXXXX..XXXXXXX 100644 | ||
153 | --- a/target/arm/translate-a64.c | ||
154 | +++ b/target/arm/translate-a64.c | ||
155 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn) | ||
156 | tcg_temp_free_ptr(tcg_rn_ptr); | ||
157 | } | ||
158 | |||
159 | +/* Crypto three-reg SHA512 | ||
160 | + * 31 21 20 16 15 14 13 12 11 10 9 5 4 0 | ||
161 | + * +-----------------------+------+---+---+-----+--------+------+------+ | ||
162 | + * | 1 1 0 0 1 1 1 0 0 1 1 | Rm | 1 | O | 0 0 | opcode | Rn | Rd | | ||
163 | + * +-----------------------+------+---+---+-----+--------+------+------+ | ||
164 | + */ | ||
165 | +static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
166 | +{ | ||
167 | + int opcode = extract32(insn, 10, 2); | ||
168 | + int o = extract32(insn, 14, 1); | ||
169 | + int rm = extract32(insn, 16, 5); | ||
170 | + int rn = extract32(insn, 5, 5); | ||
171 | + int rd = extract32(insn, 0, 5); | ||
172 | + int feature; | ||
173 | + CryptoThreeOpFn *genfn; | ||
174 | + | ||
175 | + if (o == 0) { | ||
176 | + switch (opcode) { | ||
177 | + case 0: /* SHA512H */ | ||
178 | + feature = ARM_FEATURE_V8_SHA512; | ||
179 | + genfn = gen_helper_crypto_sha512h; | ||
180 | + break; | ||
181 | + case 1: /* SHA512H2 */ | ||
182 | + feature = ARM_FEATURE_V8_SHA512; | ||
183 | + genfn = gen_helper_crypto_sha512h2; | ||
184 | + break; | ||
185 | + case 2: /* SHA512SU1 */ | ||
186 | + feature = ARM_FEATURE_V8_SHA512; | ||
187 | + genfn = gen_helper_crypto_sha512su1; | ||
188 | + break; | ||
189 | + default: | ||
190 | + unallocated_encoding(s); | ||
191 | + return; | 198 | + return; |
192 | + } | 199 | + } |
193 | + } else { | 200 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->systick[M_REG_S]), 0, |
194 | + unallocated_encoding(s); | 201 | + qdev_get_gpio_in_named(DEVICE(&s->nvic), |
195 | + return; | 202 | + "systick-trigger", M_REG_S)); |
196 | + } | 203 | + } |
197 | + | 204 | + |
198 | + if (!arm_dc_feature(s, feature)) { | 205 | + memory_region_init_io(&s->systickmem, OBJECT(s), |
199 | + unallocated_encoding(s); | 206 | + &v7m_systick_ops, s, |
200 | + return; | 207 | + "v7m_systick", 0xe0); |
201 | + } | 208 | + |
202 | + | 209 | + memory_region_add_subregion_overlap(&s->container, 0xe000e010, |
203 | + if (!fp_access_check(s)) { | 210 | + &s->systickmem, 1); |
204 | + return; | 211 | + if (arm_feature(&s->cpu->env, ARM_FEATURE_V8)) { |
205 | + } | 212 | + memory_region_init_io(&s->systick_ns_mem, OBJECT(s), |
206 | + | 213 | + &v7m_sysreg_ns_ops, &s->systickmem, |
207 | + if (genfn) { | 214 | + "v7m_systick_ns", 0xe0); |
208 | + TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | 215 | + memory_region_add_subregion_overlap(&s->container, 0xe002e010, |
209 | + | 216 | + &s->systick_ns_mem, 1); |
210 | + tcg_rd_ptr = vec_full_reg_ptr(s, rd); | 217 | + } |
211 | + tcg_rn_ptr = vec_full_reg_ptr(s, rn); | 218 | + |
212 | + tcg_rm_ptr = vec_full_reg_ptr(s, rm); | 219 | /* If the CPU has RAS support, create the RAS register block */ |
213 | + | 220 | if (cpu_isar_feature(aa32_ras, s->cpu)) { |
214 | + genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr); | 221 | object_initialize_child(OBJECT(dev), "armv7m-ras", |
215 | + | 222 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c |
216 | + tcg_temp_free_ptr(tcg_rd_ptr); | 223 | index XXXXXXX..XXXXXXX 100644 |
217 | + tcg_temp_free_ptr(tcg_rn_ptr); | 224 | --- a/hw/intc/armv7m_nvic.c |
218 | + tcg_temp_free_ptr(tcg_rm_ptr); | 225 | +++ b/hw/intc/armv7m_nvic.c |
219 | + } else { | 226 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvic_sysreg_ns_ops = { |
220 | + g_assert_not_reached(); | 227 | .endianness = DEVICE_NATIVE_ENDIAN, |
221 | + } | ||
222 | +} | ||
223 | + | ||
224 | +/* Crypto two-reg SHA512 | ||
225 | + * 31 12 11 10 9 5 4 0 | ||
226 | + * +-----------------------------------------+--------+------+------+ | ||
227 | + * | 1 1 0 0 1 1 1 0 1 1 0 0 0 0 0 0 1 0 0 0 | opcode | Rn | Rd | | ||
228 | + * +-----------------------------------------+--------+------+------+ | ||
229 | + */ | ||
230 | +static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | ||
231 | +{ | ||
232 | + int opcode = extract32(insn, 10, 2); | ||
233 | + int rn = extract32(insn, 5, 5); | ||
234 | + int rd = extract32(insn, 0, 5); | ||
235 | + TCGv_ptr tcg_rd_ptr, tcg_rn_ptr; | ||
236 | + int feature; | ||
237 | + CryptoTwoOpFn *genfn; | ||
238 | + | ||
239 | + switch (opcode) { | ||
240 | + case 0: /* SHA512SU0 */ | ||
241 | + feature = ARM_FEATURE_V8_SHA512; | ||
242 | + genfn = gen_helper_crypto_sha512su0; | ||
243 | + break; | ||
244 | + default: | ||
245 | + unallocated_encoding(s); | ||
246 | + return; | ||
247 | + } | ||
248 | + | ||
249 | + if (!arm_dc_feature(s, feature)) { | ||
250 | + unallocated_encoding(s); | ||
251 | + return; | ||
252 | + } | ||
253 | + | ||
254 | + if (!fp_access_check(s)) { | ||
255 | + return; | ||
256 | + } | ||
257 | + | ||
258 | + tcg_rd_ptr = vec_full_reg_ptr(s, rd); | ||
259 | + tcg_rn_ptr = vec_full_reg_ptr(s, rn); | ||
260 | + | ||
261 | + genfn(tcg_rd_ptr, tcg_rn_ptr); | ||
262 | + | ||
263 | + tcg_temp_free_ptr(tcg_rd_ptr); | ||
264 | + tcg_temp_free_ptr(tcg_rn_ptr); | ||
265 | +} | ||
266 | + | ||
267 | /* C3.6 Data processing - SIMD, inc Crypto | ||
268 | * | ||
269 | * As the decode gets a little complex we are using a table based | ||
270 | @@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = { | ||
271 | { 0x4e280800, 0xff3e0c00, disas_crypto_aes }, | ||
272 | { 0x5e000000, 0xff208c00, disas_crypto_three_reg_sha }, | ||
273 | { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha }, | ||
274 | + { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 }, | ||
275 | + { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, | ||
276 | { 0x00000000, 0x00000000, NULL } | ||
277 | }; | 228 | }; |
278 | 229 | ||
230 | -static MemTxResult nvic_systick_write(void *opaque, hwaddr addr, | ||
231 | - uint64_t value, unsigned size, | ||
232 | - MemTxAttrs attrs) | ||
233 | -{ | ||
234 | - NVICState *s = opaque; | ||
235 | - MemoryRegion *mr; | ||
236 | - | ||
237 | - /* Direct the access to the correct systick */ | ||
238 | - mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->systick[attrs.secure]), 0); | ||
239 | - return memory_region_dispatch_write(mr, addr, value, | ||
240 | - size_memop(size) | MO_TE, attrs); | ||
241 | -} | ||
242 | - | ||
243 | -static MemTxResult nvic_systick_read(void *opaque, hwaddr addr, | ||
244 | - uint64_t *data, unsigned size, | ||
245 | - MemTxAttrs attrs) | ||
246 | -{ | ||
247 | - NVICState *s = opaque; | ||
248 | - MemoryRegion *mr; | ||
249 | - | ||
250 | - /* Direct the access to the correct systick */ | ||
251 | - mr = sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->systick[attrs.secure]), 0); | ||
252 | - return memory_region_dispatch_read(mr, addr, data, size_memop(size) | MO_TE, | ||
253 | - attrs); | ||
254 | -} | ||
255 | - | ||
256 | -static const MemoryRegionOps nvic_systick_ops = { | ||
257 | - .read_with_attrs = nvic_systick_read, | ||
258 | - .write_with_attrs = nvic_systick_write, | ||
259 | - .endianness = DEVICE_NATIVE_ENDIAN, | ||
260 | -}; | ||
261 | - | ||
262 | /* | ||
263 | * Unassigned portions of the PPB space are RAZ/WI for privileged | ||
264 | * accesses, and fault for non-privileged accesses. | ||
265 | @@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp) | ||
266 | |||
267 | s->num_prio_bits = arm_feature(&s->cpu->env, ARM_FEATURE_V7) ? 8 : 2; | ||
268 | |||
269 | - if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), errp)) { | ||
270 | - return; | ||
271 | - } | ||
272 | - sysbus_connect_irq(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), 0, | ||
273 | - qdev_get_gpio_in_named(dev, "systick-trigger", | ||
274 | - M_REG_NS)); | ||
275 | - | ||
276 | - if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY)) { | ||
277 | - /* We couldn't init the secure systick device in instance_init | ||
278 | - * as we didn't know then if the CPU had the security extensions; | ||
279 | - * so we have to do it here. | ||
280 | - */ | ||
281 | - object_initialize_child(OBJECT(dev), "systick-reg-s", | ||
282 | - &s->systick[M_REG_S], TYPE_SYSTICK); | ||
283 | - | ||
284 | - if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_S]), errp)) { | ||
285 | - return; | ||
286 | - } | ||
287 | - sysbus_connect_irq(SYS_BUS_DEVICE(&s->systick[M_REG_S]), 0, | ||
288 | - qdev_get_gpio_in_named(dev, "systick-trigger", | ||
289 | - M_REG_S)); | ||
290 | - } | ||
291 | - | ||
292 | /* | ||
293 | * This device provides a single sysbus memory region which | ||
294 | * represents the whole of the "System PPB" space. This is the | ||
295 | @@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp) | ||
296 | "nvic_sysregs", 0x1000); | ||
297 | memory_region_add_subregion(&s->container, 0xe000, &s->sysregmem); | ||
298 | |||
299 | - memory_region_init_io(&s->systickmem, OBJECT(s), | ||
300 | - &nvic_systick_ops, s, | ||
301 | - "nvic_systick", 0xe0); | ||
302 | - | ||
303 | - memory_region_add_subregion_overlap(&s->container, 0xe010, | ||
304 | - &s->systickmem, 1); | ||
305 | - | ||
306 | if (arm_feature(&s->cpu->env, ARM_FEATURE_V8)) { | ||
307 | memory_region_init_io(&s->sysreg_ns_mem, OBJECT(s), | ||
308 | &nvic_sysreg_ns_ops, &s->sysregmem, | ||
309 | "nvic_sysregs_ns", 0x1000); | ||
310 | memory_region_add_subregion(&s->container, 0x2e000, &s->sysreg_ns_mem); | ||
311 | - memory_region_init_io(&s->systick_ns_mem, OBJECT(s), | ||
312 | - &nvic_sysreg_ns_ops, &s->systickmem, | ||
313 | - "nvic_systick_ns", 0xe0); | ||
314 | - memory_region_add_subregion_overlap(&s->container, 0x2e010, | ||
315 | - &s->systick_ns_mem, 1); | ||
316 | } | ||
317 | |||
318 | sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->container); | ||
319 | @@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_instance_init(Object *obj) | ||
320 | NVICState *nvic = NVIC(obj); | ||
321 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
322 | |||
323 | - object_initialize_child(obj, "systick-reg-ns", &nvic->systick[M_REG_NS], | ||
324 | - TYPE_SYSTICK); | ||
325 | - /* We can't initialize the secure systick here, as we don't know | ||
326 | - * yet if we need it. | ||
327 | - */ | ||
328 | - | ||
329 | sysbus_init_irq(sbd, &nvic->excpout); | ||
330 | qdev_init_gpio_out_named(dev, &nvic->sysresetreq, "SYSRESETREQ", 1); | ||
331 | qdev_init_gpio_in_named(dev, nvic_systick_trigger, "systick-trigger", | ||
279 | -- | 332 | -- |
280 | 2.16.1 | 333 | 2.20.1 |
281 | 334 | ||
282 | 335 | diff view generated by jsdifflib |
1 | In order to support derived exceptions (exceptions generated in | 1 | Instead of having the NVIC device provide a single sysbus memory |
---|---|---|---|
2 | the course of trying to take an exception), we need to be able | 2 | region covering the whole of the "System PPB" space, which implements |
3 | to handle prioritizing whether to take the original exception | 3 | the default behaviour for unimplemented ranges and provides the NS |
4 | or the derived exception. | 4 | alias window to the sysregs as well as the main sysreg MR, move this |
5 | 5 | handling to the container armv7m device. The NVIC now provides a | |
6 | We do this by introducing a new function | 6 | single memory region which just implements the system registers. |
7 | armv7m_nvic_set_pending_derived() which the exception-taking code in | 7 | This consolidates all the handling of "map various devices in the |
8 | helper.c will call when a derived exception occurs. Derived | 8 | PPB" into the armv7m container where it belongs. |
9 | exceptions are dealt with mostly like normal pending exceptions, so | ||
10 | we share the implementation with the armv7m_nvic_set_pending() | ||
11 | function. | ||
12 | |||
13 | Note that the way we structure this is significantly different | ||
14 | from the v8M Arm ARM pseudocode: that does all the prioritization | ||
15 | logic in the DerivedLateArrival() function, whereas we choose to | ||
16 | let the existing "identify highest priority exception" logic | ||
17 | do the prioritization for us. The effect is the same, though. | ||
18 | 9 | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 11 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> |
21 | Message-id: 1517324542-6607-2-git-send-email-peter.maydell@linaro.org | 12 | Reviewed-by: Luc Michel <luc@lmichel.fr> |
13 | Message-id: 20210812093356.1946-4-peter.maydell@linaro.org | ||
22 | --- | 14 | --- |
23 | target/arm/cpu.h | 13 ++++++++++ | 15 | include/hw/arm/armv7m.h | 4 + |
24 | hw/intc/armv7m_nvic.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++-- | 16 | include/hw/intc/armv7m_nvic.h | 3 - |
25 | hw/intc/trace-events | 2 +- | 17 | hw/arm/armv7m.c | 100 ++++++++++++++++++++++- |
26 | 3 files changed, 80 insertions(+), 3 deletions(-) | 18 | hw/intc/armv7m_nvic.c | 145 +--------------------------------- |
19 | 4 files changed, 107 insertions(+), 145 deletions(-) | ||
27 | 20 | ||
28 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 21 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h |
29 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/cpu.h | 23 | --- a/include/hw/arm/armv7m.h |
31 | +++ b/target/arm/cpu.h | 24 | +++ b/include/hw/arm/armv7m.h |
32 | @@ -XXX,XX +XXX,XX @@ static inline bool armv7m_nvic_can_take_pending_exception(void *opaque) | 25 | @@ -XXX,XX +XXX,XX @@ struct ARMv7MState { |
33 | * of architecturally banked exceptions. | 26 | * NS systick device if appropriate. |
34 | */ | 27 | */ |
35 | void armv7m_nvic_set_pending(void *opaque, int irq, bool secure); | 28 | MemoryRegion systick_ns_mem; |
36 | +/** | 29 | + /* Ditto, for the sysregs region provided by the NVIC */ |
37 | + * armv7m_nvic_set_pending_derived: mark this derived exception as pending | 30 | + MemoryRegion sysreg_ns_mem; |
38 | + * @opaque: the NVIC | 31 | + /* MR providing default PPB behaviour */ |
39 | + * @irq: the exception number to mark pending | 32 | + MemoryRegion defaultmem; |
40 | + * @secure: false for non-banked exceptions or for the nonsecure | 33 | |
41 | + * version of a banked exception, true for the secure version of a banked | 34 | /* Properties */ |
42 | + * exception. | 35 | char *cpu_type; |
43 | + * | 36 | diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h |
44 | + * Similar to armv7m_nvic_set_pending(), but specifically for derived | 37 | index XXXXXXX..XXXXXXX 100644 |
45 | + * exceptions (exceptions generated in the course of trying to take | 38 | --- a/include/hw/intc/armv7m_nvic.h |
46 | + * a different exception). | 39 | +++ b/include/hw/intc/armv7m_nvic.h |
40 | @@ -XXX,XX +XXX,XX @@ struct NVICState { | ||
41 | int vectpending_prio; /* group prio of the exeception in vectpending */ | ||
42 | |||
43 | MemoryRegion sysregmem; | ||
44 | - MemoryRegion sysreg_ns_mem; | ||
45 | - MemoryRegion container; | ||
46 | - MemoryRegion defaultmem; | ||
47 | |||
48 | uint32_t num_irq; | ||
49 | qemu_irq excpout; | ||
50 | diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/hw/arm/armv7m.c | ||
53 | +++ b/hw/arm/armv7m.c | ||
54 | @@ -XXX,XX +XXX,XX @@ | ||
55 | #include "sysemu/reset.h" | ||
56 | #include "qemu/error-report.h" | ||
57 | #include "qemu/module.h" | ||
58 | +#include "qemu/log.h" | ||
59 | #include "target/arm/idau.h" | ||
60 | |||
61 | /* Bitbanded IO. Each word corresponds to a single bit. */ | ||
62 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps v7m_systick_ops = { | ||
63 | .endianness = DEVICE_NATIVE_ENDIAN, | ||
64 | }; | ||
65 | |||
66 | +/* | ||
67 | + * Unassigned portions of the PPB space are RAZ/WI for privileged | ||
68 | + * accesses, and fault for non-privileged accesses. | ||
47 | + */ | 69 | + */ |
48 | +void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure); | 70 | +static MemTxResult ppb_default_read(void *opaque, hwaddr addr, |
49 | /** | 71 | + uint64_t *data, unsigned size, |
50 | * armv7m_nvic_acknowledge_irq: make highest priority pending exception active | 72 | + MemTxAttrs attrs) |
51 | * @opaque: the NVIC | 73 | +{ |
74 | + qemu_log_mask(LOG_UNIMP, "Read of unassigned area of PPB: offset 0x%x\n", | ||
75 | + (uint32_t)addr); | ||
76 | + if (attrs.user) { | ||
77 | + return MEMTX_ERROR; | ||
78 | + } | ||
79 | + *data = 0; | ||
80 | + return MEMTX_OK; | ||
81 | +} | ||
82 | + | ||
83 | +static MemTxResult ppb_default_write(void *opaque, hwaddr addr, | ||
84 | + uint64_t value, unsigned size, | ||
85 | + MemTxAttrs attrs) | ||
86 | +{ | ||
87 | + qemu_log_mask(LOG_UNIMP, "Write of unassigned area of PPB: offset 0x%x\n", | ||
88 | + (uint32_t)addr); | ||
89 | + if (attrs.user) { | ||
90 | + return MEMTX_ERROR; | ||
91 | + } | ||
92 | + return MEMTX_OK; | ||
93 | +} | ||
94 | + | ||
95 | +static const MemoryRegionOps ppb_default_ops = { | ||
96 | + .read_with_attrs = ppb_default_read, | ||
97 | + .write_with_attrs = ppb_default_write, | ||
98 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
99 | + .valid.min_access_size = 1, | ||
100 | + .valid.max_access_size = 8, | ||
101 | +}; | ||
102 | + | ||
103 | static void armv7m_instance_init(Object *obj) | ||
104 | { | ||
105 | ARMv7MState *s = ARMV7M(obj); | ||
106 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) | ||
107 | qdev_pass_gpios(DEVICE(&s->nvic), dev, "SYSRESETREQ"); | ||
108 | qdev_pass_gpios(DEVICE(&s->nvic), dev, "NMI"); | ||
109 | |||
110 | + /* | ||
111 | + * We map various devices into the container MR at their architected | ||
112 | + * addresses. In particular, we map everything corresponding to the | ||
113 | + * "System PPB" space. This is the range from 0xe0000000 to 0xe00fffff | ||
114 | + * and includes the NVIC, the System Control Space (system registers), | ||
115 | + * the systick timer, and for CPUs with the Security extension an NS | ||
116 | + * banked version of all of these. | ||
117 | + * | ||
118 | + * The default behaviour for unimplemented registers/ranges | ||
119 | + * (for instance the Data Watchpoint and Trace unit at 0xe0001000) | ||
120 | + * is to RAZ/WI for privileged access and BusFault for non-privileged | ||
121 | + * access. | ||
122 | + * | ||
123 | + * The NVIC and System Control Space (SCS) starts at 0xe000e000 | ||
124 | + * and looks like this: | ||
125 | + * 0x004 - ICTR | ||
126 | + * 0x010 - 0xff - systick | ||
127 | + * 0x100..0x7ec - NVIC | ||
128 | + * 0x7f0..0xcff - Reserved | ||
129 | + * 0xd00..0xd3c - SCS registers | ||
130 | + * 0xd40..0xeff - Reserved or Not implemented | ||
131 | + * 0xf00 - STIR | ||
132 | + * | ||
133 | + * Some registers within this space are banked between security states. | ||
134 | + * In v8M there is a second range 0xe002e000..0xe002efff which is the | ||
135 | + * NonSecure alias SCS; secure accesses to this behave like NS accesses | ||
136 | + * to the main SCS range, and non-secure accesses (including when | ||
137 | + * the security extension is not implemented) are RAZ/WI. | ||
138 | + * Note that both the main SCS range and the alias range are defined | ||
139 | + * to be exempt from memory attribution (R_BLJT) and so the memory | ||
140 | + * transaction attribute always matches the current CPU security | ||
141 | + * state (attrs.secure == env->v7m.secure). In the v7m_sysreg_ns_ops | ||
142 | + * wrappers we change attrs.secure to indicate the NS access; so | ||
143 | + * generally code determining which banked register to use should | ||
144 | + * use attrs.secure; code determining actual behaviour of the system | ||
145 | + * should use env->v7m.secure. | ||
146 | + * | ||
147 | + * Within the PPB space, some MRs overlap, and the priority | ||
148 | + * of overlapping regions is: | ||
149 | + * - default region (for RAZ/WI and BusFault) : -1 | ||
150 | + * - system register regions (provided by the NVIC) : 0 | ||
151 | + * - systick : 1 | ||
152 | + * This is because the systick device is a small block of registers | ||
153 | + * in the middle of the other system control registers. | ||
154 | + */ | ||
155 | + | ||
156 | + memory_region_init_io(&s->defaultmem, OBJECT(s), &ppb_default_ops, s, | ||
157 | + "nvic-default", 0x100000); | ||
158 | + memory_region_add_subregion_overlap(&s->container, 0xe0000000, | ||
159 | + &s->defaultmem, -1); | ||
160 | + | ||
161 | /* Wire the NVIC up to the CPU */ | ||
162 | sbd = SYS_BUS_DEVICE(&s->nvic); | ||
163 | sysbus_connect_irq(sbd, 0, | ||
164 | qdev_get_gpio_in(DEVICE(s->cpu), ARM_CPU_IRQ)); | ||
165 | |||
166 | - memory_region_add_subregion(&s->container, 0xe0000000, | ||
167 | + memory_region_add_subregion(&s->container, 0xe000e000, | ||
168 | sysbus_mmio_get_region(sbd, 0)); | ||
169 | + if (arm_feature(&s->cpu->env, ARM_FEATURE_V8)) { | ||
170 | + /* Create the NS alias region for the NVIC sysregs */ | ||
171 | + memory_region_init_io(&s->sysreg_ns_mem, OBJECT(s), | ||
172 | + &v7m_sysreg_ns_ops, | ||
173 | + sysbus_mmio_get_region(sbd, 0), | ||
174 | + "nvic_sysregs_ns", 0x1000); | ||
175 | + memory_region_add_subregion(&s->container, 0xe002e000, | ||
176 | + &s->sysreg_ns_mem); | ||
177 | + } | ||
178 | |||
179 | /* Create and map the systick devices */ | ||
180 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), errp)) { | ||
52 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | 181 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c |
53 | index XXXXXXX..XXXXXXX 100644 | 182 | index XXXXXXX..XXXXXXX 100644 |
54 | --- a/hw/intc/armv7m_nvic.c | 183 | --- a/hw/intc/armv7m_nvic.c |
55 | +++ b/hw/intc/armv7m_nvic.c | 184 | +++ b/hw/intc/armv7m_nvic.c |
56 | @@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_clear_pending(void *opaque, int irq, bool secure) | 185 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvic_sysreg_ops = { |
57 | } | 186 | .endianness = DEVICE_NATIVE_ENDIAN, |
187 | }; | ||
188 | |||
189 | -static MemTxResult nvic_sysreg_ns_write(void *opaque, hwaddr addr, | ||
190 | - uint64_t value, unsigned size, | ||
191 | - MemTxAttrs attrs) | ||
192 | -{ | ||
193 | - MemoryRegion *mr = opaque; | ||
194 | - | ||
195 | - if (attrs.secure) { | ||
196 | - /* S accesses to the alias act like NS accesses to the real region */ | ||
197 | - attrs.secure = 0; | ||
198 | - return memory_region_dispatch_write(mr, addr, value, | ||
199 | - size_memop(size) | MO_TE, attrs); | ||
200 | - } else { | ||
201 | - /* NS attrs are RAZ/WI for privileged, and BusFault for user */ | ||
202 | - if (attrs.user) { | ||
203 | - return MEMTX_ERROR; | ||
204 | - } | ||
205 | - return MEMTX_OK; | ||
206 | - } | ||
207 | -} | ||
208 | - | ||
209 | -static MemTxResult nvic_sysreg_ns_read(void *opaque, hwaddr addr, | ||
210 | - uint64_t *data, unsigned size, | ||
211 | - MemTxAttrs attrs) | ||
212 | -{ | ||
213 | - MemoryRegion *mr = opaque; | ||
214 | - | ||
215 | - if (attrs.secure) { | ||
216 | - /* S accesses to the alias act like NS accesses to the real region */ | ||
217 | - attrs.secure = 0; | ||
218 | - return memory_region_dispatch_read(mr, addr, data, | ||
219 | - size_memop(size) | MO_TE, attrs); | ||
220 | - } else { | ||
221 | - /* NS attrs are RAZ/WI for privileged, and BusFault for user */ | ||
222 | - if (attrs.user) { | ||
223 | - return MEMTX_ERROR; | ||
224 | - } | ||
225 | - *data = 0; | ||
226 | - return MEMTX_OK; | ||
227 | - } | ||
228 | -} | ||
229 | - | ||
230 | -static const MemoryRegionOps nvic_sysreg_ns_ops = { | ||
231 | - .read_with_attrs = nvic_sysreg_ns_read, | ||
232 | - .write_with_attrs = nvic_sysreg_ns_write, | ||
233 | - .endianness = DEVICE_NATIVE_ENDIAN, | ||
234 | -}; | ||
235 | - | ||
236 | -/* | ||
237 | - * Unassigned portions of the PPB space are RAZ/WI for privileged | ||
238 | - * accesses, and fault for non-privileged accesses. | ||
239 | - */ | ||
240 | -static MemTxResult ppb_default_read(void *opaque, hwaddr addr, | ||
241 | - uint64_t *data, unsigned size, | ||
242 | - MemTxAttrs attrs) | ||
243 | -{ | ||
244 | - qemu_log_mask(LOG_UNIMP, "Read of unassigned area of PPB: offset 0x%x\n", | ||
245 | - (uint32_t)addr); | ||
246 | - if (attrs.user) { | ||
247 | - return MEMTX_ERROR; | ||
248 | - } | ||
249 | - *data = 0; | ||
250 | - return MEMTX_OK; | ||
251 | -} | ||
252 | - | ||
253 | -static MemTxResult ppb_default_write(void *opaque, hwaddr addr, | ||
254 | - uint64_t value, unsigned size, | ||
255 | - MemTxAttrs attrs) | ||
256 | -{ | ||
257 | - qemu_log_mask(LOG_UNIMP, "Write of unassigned area of PPB: offset 0x%x\n", | ||
258 | - (uint32_t)addr); | ||
259 | - if (attrs.user) { | ||
260 | - return MEMTX_ERROR; | ||
261 | - } | ||
262 | - return MEMTX_OK; | ||
263 | -} | ||
264 | - | ||
265 | -static const MemoryRegionOps ppb_default_ops = { | ||
266 | - .read_with_attrs = ppb_default_read, | ||
267 | - .write_with_attrs = ppb_default_write, | ||
268 | - .endianness = DEVICE_NATIVE_ENDIAN, | ||
269 | - .valid.min_access_size = 1, | ||
270 | - .valid.max_access_size = 8, | ||
271 | -}; | ||
272 | - | ||
273 | static int nvic_post_load(void *opaque, int version_id) | ||
274 | { | ||
275 | NVICState *s = opaque; | ||
276 | @@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_realize(DeviceState *dev, Error **errp) | ||
277 | s->num_prio_bits = arm_feature(&s->cpu->env, ARM_FEATURE_V7) ? 8 : 2; | ||
278 | |||
279 | /* | ||
280 | - * This device provides a single sysbus memory region which | ||
281 | - * represents the whole of the "System PPB" space. This is the | ||
282 | - * range from 0xe0000000 to 0xe00fffff and includes the NVIC, | ||
283 | - * the System Control Space (system registers), the systick timer, | ||
284 | - * and for CPUs with the Security extension an NS banked version | ||
285 | - * of all of these. | ||
286 | - * | ||
287 | - * The default behaviour for unimplemented registers/ranges | ||
288 | - * (for instance the Data Watchpoint and Trace unit at 0xe0001000) | ||
289 | - * is to RAZ/WI for privileged access and BusFault for non-privileged | ||
290 | - * access. | ||
291 | - * | ||
292 | - * The NVIC and System Control Space (SCS) starts at 0xe000e000 | ||
293 | - * and looks like this: | ||
294 | - * 0x004 - ICTR | ||
295 | - * 0x010 - 0xff - systick | ||
296 | - * 0x100..0x7ec - NVIC | ||
297 | - * 0x7f0..0xcff - Reserved | ||
298 | - * 0xd00..0xd3c - SCS registers | ||
299 | - * 0xd40..0xeff - Reserved or Not implemented | ||
300 | - * 0xf00 - STIR | ||
301 | - * | ||
302 | - * Some registers within this space are banked between security states. | ||
303 | - * In v8M there is a second range 0xe002e000..0xe002efff which is the | ||
304 | - * NonSecure alias SCS; secure accesses to this behave like NS accesses | ||
305 | - * to the main SCS range, and non-secure accesses (including when | ||
306 | - * the security extension is not implemented) are RAZ/WI. | ||
307 | - * Note that both the main SCS range and the alias range are defined | ||
308 | - * to be exempt from memory attribution (R_BLJT) and so the memory | ||
309 | - * transaction attribute always matches the current CPU security | ||
310 | - * state (attrs.secure == env->v7m.secure). In the nvic_sysreg_ns_ops | ||
311 | - * wrappers we change attrs.secure to indicate the NS access; so | ||
312 | - * generally code determining which banked register to use should | ||
313 | - * use attrs.secure; code determining actual behaviour of the system | ||
314 | - * should use env->v7m.secure. | ||
315 | - * | ||
316 | - * The container covers the whole PPB space. Within it the priority | ||
317 | - * of overlapping regions is: | ||
318 | - * - default region (for RAZ/WI and BusFault) : -1 | ||
319 | - * - system register regions : 0 | ||
320 | - * - systick : 1 | ||
321 | - * This is because the systick device is a small block of registers | ||
322 | - * in the middle of the other system control registers. | ||
323 | + * This device provides a single memory region which covers the | ||
324 | + * sysreg/NVIC registers from 0xE000E000 .. 0xE000EFFF, with the | ||
325 | + * exception of the systick timer registers 0xE000E010 .. 0xE000E0FF. | ||
326 | */ | ||
327 | - memory_region_init(&s->container, OBJECT(s), "nvic", 0x100000); | ||
328 | - memory_region_init_io(&s->defaultmem, OBJECT(s), &ppb_default_ops, s, | ||
329 | - "nvic-default", 0x100000); | ||
330 | - memory_region_add_subregion_overlap(&s->container, 0, &s->defaultmem, -1); | ||
331 | memory_region_init_io(&s->sysregmem, OBJECT(s), &nvic_sysreg_ops, s, | ||
332 | "nvic_sysregs", 0x1000); | ||
333 | - memory_region_add_subregion(&s->container, 0xe000, &s->sysregmem); | ||
334 | - | ||
335 | - if (arm_feature(&s->cpu->env, ARM_FEATURE_V8)) { | ||
336 | - memory_region_init_io(&s->sysreg_ns_mem, OBJECT(s), | ||
337 | - &nvic_sysreg_ns_ops, &s->sysregmem, | ||
338 | - "nvic_sysregs_ns", 0x1000); | ||
339 | - memory_region_add_subregion(&s->container, 0x2e000, &s->sysreg_ns_mem); | ||
340 | - } | ||
341 | - | ||
342 | - sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->container); | ||
343 | + sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->sysregmem); | ||
58 | } | 344 | } |
59 | 345 | ||
60 | -void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | 346 | static void armv7m_nvic_instance_init(Object *obj) |
61 | +static void do_armv7m_nvic_set_pending(void *opaque, int irq, bool secure, | ||
62 | + bool derived) | ||
63 | { | ||
64 | + /* Pend an exception, including possibly escalating it to HardFault. | ||
65 | + * | ||
66 | + * This function handles both "normal" pending of interrupts and | ||
67 | + * exceptions, and also derived exceptions (ones which occur as | ||
68 | + * a result of trying to take some other exception). | ||
69 | + * | ||
70 | + * If derived == true, the caller guarantees that we are part way through | ||
71 | + * trying to take an exception (but have not yet called | ||
72 | + * armv7m_nvic_acknowledge_irq() to make it active), and so: | ||
73 | + * - s->vectpending is the "original exception" we were trying to take | ||
74 | + * - irq is the "derived exception" | ||
75 | + * - nvic_exec_prio(s) gives the priority before exception entry | ||
76 | + * Here we handle the prioritization logic which the pseudocode puts | ||
77 | + * in the DerivedLateArrival() function. | ||
78 | + */ | ||
79 | + | ||
80 | NVICState *s = (NVICState *)opaque; | ||
81 | bool banked = exc_is_banked(irq); | ||
82 | VecInfo *vec; | ||
83 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | ||
84 | |||
85 | vec = (banked && secure) ? &s->sec_vectors[irq] : &s->vectors[irq]; | ||
86 | |||
87 | - trace_nvic_set_pending(irq, secure, vec->enabled, vec->prio); | ||
88 | + trace_nvic_set_pending(irq, secure, derived, vec->enabled, vec->prio); | ||
89 | + | ||
90 | + if (derived) { | ||
91 | + /* Derived exceptions are always synchronous. */ | ||
92 | + assert(irq >= ARMV7M_EXCP_HARD && irq < ARMV7M_EXCP_PENDSV); | ||
93 | + | ||
94 | + if (irq == ARMV7M_EXCP_DEBUG && | ||
95 | + exc_group_prio(s, vec->prio, secure) >= nvic_exec_prio(s)) { | ||
96 | + /* DebugMonitorFault, but its priority is lower than the | ||
97 | + * preempted exception priority: just ignore it. | ||
98 | + */ | ||
99 | + return; | ||
100 | + } | ||
101 | + | ||
102 | + if (irq == ARMV7M_EXCP_HARD && vec->prio >= s->vectpending_prio) { | ||
103 | + /* If this is a terminal exception (one which means we cannot | ||
104 | + * take the original exception, like a failure to read its | ||
105 | + * vector table entry), then we must take the derived exception. | ||
106 | + * If the derived exception can't take priority over the | ||
107 | + * original exception, then we go into Lockup. | ||
108 | + * | ||
109 | + * For QEMU, we rely on the fact that a derived exception is | ||
110 | + * terminal if and only if it's reported to us as HardFault, | ||
111 | + * which saves having to have an extra argument is_terminal | ||
112 | + * that we'd only use in one place. | ||
113 | + */ | ||
114 | + cpu_abort(&s->cpu->parent_obj, | ||
115 | + "Lockup: can't take terminal derived exception " | ||
116 | + "(original exception priority %d)\n", | ||
117 | + s->vectpending_prio); | ||
118 | + } | ||
119 | + /* We now continue with the same code as for a normal pending | ||
120 | + * exception, which will cause us to pend the derived exception. | ||
121 | + * We'll then take either the original or the derived exception | ||
122 | + * based on which is higher priority by the usual mechanism | ||
123 | + * for selecting the highest priority pending interrupt. | ||
124 | + */ | ||
125 | + } | ||
126 | |||
127 | if (irq >= ARMV7M_EXCP_HARD && irq < ARMV7M_EXCP_PENDSV) { | ||
128 | /* If a synchronous exception is pending then it may be | ||
129 | @@ -XXX,XX +XXX,XX @@ void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | ||
130 | } | ||
131 | } | ||
132 | |||
133 | +void armv7m_nvic_set_pending(void *opaque, int irq, bool secure) | ||
134 | +{ | ||
135 | + do_armv7m_nvic_set_pending(opaque, irq, secure, false); | ||
136 | +} | ||
137 | + | ||
138 | +void armv7m_nvic_set_pending_derived(void *opaque, int irq, bool secure) | ||
139 | +{ | ||
140 | + do_armv7m_nvic_set_pending(opaque, irq, secure, true); | ||
141 | +} | ||
142 | + | ||
143 | /* Make pending IRQ active. */ | ||
144 | bool armv7m_nvic_acknowledge_irq(void *opaque) | ||
145 | { | ||
146 | diff --git a/hw/intc/trace-events b/hw/intc/trace-events | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/hw/intc/trace-events | ||
149 | +++ b/hw/intc/trace-events | ||
150 | @@ -XXX,XX +XXX,XX @@ nvic_set_prio(int irq, bool secure, uint8_t prio) "NVIC set irq %d secure-bank % | ||
151 | nvic_irq_update(int vectpending, int pendprio, int exception_prio, int level) "NVIC vectpending %d pending prio %d exception_prio %d: setting irq line to %d" | ||
152 | nvic_escalate_prio(int irq, int irqprio, int runprio) "NVIC escalating irq %d to HardFault: insufficient priority %d >= %d" | ||
153 | nvic_escalate_disabled(int irq) "NVIC escalating irq %d to HardFault: disabled" | ||
154 | -nvic_set_pending(int irq, bool secure, int en, int prio) "NVIC set pending irq %d secure-bank %d (enabled: %d priority %d)" | ||
155 | +nvic_set_pending(int irq, bool secure, bool derived, int en, int prio) "NVIC set pending irq %d secure-bank %d derived %d (enabled: %d priority %d)" | ||
156 | nvic_clear_pending(int irq, bool secure, int en, int prio) "NVIC clear pending irq %d secure-bank %d (enabled: %d priority %d)" | ||
157 | nvic_set_pending_level(int irq) "NVIC set pending: irq %d higher prio than vectpending: setting irq line to 1" | ||
158 | nvic_acknowledge_irq(int irq, int prio, bool targets_secure) "NVIC acknowledge IRQ: %d now active (prio %d targets_secure %d)" | ||
159 | -- | 347 | -- |
160 | 2.16.1 | 348 | 2.20.1 |
161 | 349 | ||
162 | 350 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Add the usual-style QEMU interface comment documenting what | ||
2 | properties, etc, this device exposes. | ||
1 | 3 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
6 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
7 | Message-id: 20210812093356.1946-5-peter.maydell@linaro.org | ||
8 | --- | ||
9 | include/hw/timer/armv7m_systick.h | 7 +++++++ | ||
10 | 1 file changed, 7 insertions(+) | ||
11 | |||
12 | diff --git a/include/hw/timer/armv7m_systick.h b/include/hw/timer/armv7m_systick.h | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/include/hw/timer/armv7m_systick.h | ||
15 | +++ b/include/hw/timer/armv7m_systick.h | ||
16 | @@ -XXX,XX +XXX,XX @@ | ||
17 | |||
18 | OBJECT_DECLARE_SIMPLE_TYPE(SysTickState, SYSTICK) | ||
19 | |||
20 | +/* | ||
21 | + * QEMU interface: | ||
22 | + * + sysbus MMIO region 0 is the register interface (covering | ||
23 | + * the registers which are mapped at address 0xE000E010) | ||
24 | + * + sysbus IRQ 0 is the interrupt line to the NVIC | ||
25 | + */ | ||
26 | + | ||
27 | struct SysTickState { | ||
28 | /*< private >*/ | ||
29 | SysBusDevice parent_obj; | ||
30 | -- | ||
31 | 2.20.1 | ||
32 | |||
33 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | The v7M systick timer can be programmed to run from either of |
---|---|---|---|
2 | two clocks: | ||
3 | * an "external reference clock" (when SYST_CSR.CLKSOURCE == 0) | ||
4 | * the main CPU clock (when SYST_CSR.CLKSOURCE == 1) | ||
2 | 5 | ||
3 | IP block found on several generations of i.MX family does not use | 6 | Our implementation currently hardwires the external reference clock |
4 | vanilla SDHCI implementation and it comes with a number of quirks. | 7 | to be 1MHz, and allows boards to set the main CPU clock frequency via |
8 | the global 'system_clock_scale'. (Most boards set that to a constant | ||
9 | value; the Stellaris boards allow the guest to reprogram it via the | ||
10 | board-specific RCC registers). | ||
5 | 11 | ||
6 | Introduce i.MX SDHCI subtype of SDHCI block to add code necessary to | 12 | As the first step in converting this to use the Clock infrastructure, |
7 | support unmodified Linux guest driver. | 13 | add input clocks to the systick device for the reference clock and |
14 | the CPU clock. The device implementation ignores them; once we have | ||
15 | made all the users of the device correctly wire up the new Clocks we | ||
16 | will switch the implementation to use them and ignore the old | ||
17 | system_clock_scale. | ||
8 | 18 | ||
9 | Cc: Peter Maydell <peter.maydell@linaro.org> | 19 | This is a migration compat break for all M-profile boards, because of |
10 | Cc: Jason Wang <jasowang@redhat.com> | 20 | the addition of the new clock objects to the vmstate struct. |
11 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 21 | |
12 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
13 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
14 | Cc: qemu-devel@nongnu.org | ||
15 | Cc: qemu-arm@nongnu.org | ||
16 | Cc: yurovsky@gmail.com | ||
17 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
19 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
20 | [PMM: define and use ESDHC_UNDOCUMENTED_REG27] | ||
21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 22 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
23 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
24 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
25 | Message-id: 20210812093356.1946-6-peter.maydell@linaro.org | ||
22 | --- | 26 | --- |
23 | hw/sd/sdhci-internal.h | 23 +++++ | 27 | include/hw/timer/armv7m_systick.h | 7 +++++++ |
24 | include/hw/sd/sdhci.h | 13 +++ | 28 | hw/timer/armv7m_systick.c | 10 ++++++++-- |
25 | hw/sd/sdhci.c | 230 ++++++++++++++++++++++++++++++++++++++++++++++++- | 29 | 2 files changed, 15 insertions(+), 2 deletions(-) |
26 | 3 files changed, 265 insertions(+), 1 deletion(-) | ||
27 | 30 | ||
28 | diff --git a/hw/sd/sdhci-internal.h b/hw/sd/sdhci-internal.h | 31 | diff --git a/include/hw/timer/armv7m_systick.h b/include/hw/timer/armv7m_systick.h |
29 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/sd/sdhci-internal.h | 33 | --- a/include/hw/timer/armv7m_systick.h |
31 | +++ b/hw/sd/sdhci-internal.h | 34 | +++ b/include/hw/timer/armv7m_systick.h |
32 | @@ -XXX,XX +XXX,XX @@ | 35 | @@ -XXX,XX +XXX,XX @@ |
33 | 36 | #include "hw/sysbus.h" | |
34 | /* R/W Host control Register 0x0 */ | 37 | #include "qom/object.h" |
35 | #define SDHC_HOSTCTL 0x28 | 38 | #include "hw/ptimer.h" |
36 | +#define SDHC_CTRL_LED 0x01 | 39 | +#include "hw/clock.h" |
37 | #define SDHC_CTRL_DMA_CHECK_MASK 0x18 | 40 | |
38 | #define SDHC_CTRL_SDMA 0x00 | 41 | #define TYPE_SYSTICK "armv7m_systick" |
39 | #define SDHC_CTRL_ADMA1_32 0x08 | 42 | |
40 | #define SDHC_CTRL_ADMA2_32 0x10 | 43 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(SysTickState, SYSTICK) |
41 | #define SDHC_CTRL_ADMA2_64 0x18 | 44 | * + sysbus MMIO region 0 is the register interface (covering |
42 | #define SDHC_DMA_TYPE(x) ((x) & SDHC_CTRL_DMA_CHECK_MASK) | 45 | * the registers which are mapped at address 0xE000E010) |
43 | +#define SDHC_CTRL_4BITBUS 0x02 | 46 | * + sysbus IRQ 0 is the interrupt line to the NVIC |
44 | +#define SDHC_CTRL_8BITBUS 0x20 | 47 | + * + Clock input "refclk" is the external reference clock |
45 | +#define SDHC_CTRL_CDTEST_INS 0x40 | 48 | + * (used when SYST_CSR.CLKSOURCE == 0) |
46 | +#define SDHC_CTRL_CDTEST_EN 0x80 | 49 | + * + Clock input "cpuclk" is the main CPU clock |
47 | + | 50 | + * (used when SYST_CSR.CLKSOURCE == 1) |
48 | 51 | */ | |
49 | /* R/W Power Control Register 0x0 */ | 52 | |
50 | #define SDHC_PWRCON 0x29 | 53 | struct SysTickState { |
51 | @@ -XXX,XX +XXX,XX @@ enum { | 54 | @@ -XXX,XX +XXX,XX @@ struct SysTickState { |
52 | sdhc_gap_write = 2 /* SDHC stopped at block gap during write operation */ | 55 | ptimer_state *ptimer; |
56 | MemoryRegion iomem; | ||
57 | qemu_irq irq; | ||
58 | + Clock *refclk; | ||
59 | + Clock *cpuclk; | ||
53 | }; | 60 | }; |
54 | 61 | ||
55 | +extern const VMStateDescription sdhci_vmstate; | 62 | /* |
56 | + | 63 | diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c |
57 | + | ||
58 | +#define ESDHC_MIX_CTRL 0x48 | ||
59 | +#define ESDHC_VENDOR_SPEC 0xc0 | ||
60 | +#define ESDHC_DLL_CTRL 0x60 | ||
61 | + | ||
62 | +#define ESDHC_TUNING_CTRL 0xcc | ||
63 | +#define ESDHC_TUNE_CTRL_STATUS 0x68 | ||
64 | +#define ESDHC_WTMK_LVL 0x44 | ||
65 | + | ||
66 | +/* Undocumented register used by guests working around erratum ERR004536 */ | ||
67 | +#define ESDHC_UNDOCUMENTED_REG27 0x6c | ||
68 | + | ||
69 | +#define ESDHC_CTRL_4BITBUS (0x1 << 1) | ||
70 | +#define ESDHC_CTRL_8BITBUS (0x2 << 1) | ||
71 | + | ||
72 | #endif | ||
73 | diff --git a/include/hw/sd/sdhci.h b/include/hw/sd/sdhci.h | ||
74 | index XXXXXXX..XXXXXXX 100644 | 64 | index XXXXXXX..XXXXXXX 100644 |
75 | --- a/include/hw/sd/sdhci.h | 65 | --- a/hw/timer/armv7m_systick.c |
76 | +++ b/include/hw/sd/sdhci.h | 66 | +++ b/hw/timer/armv7m_systick.c |
77 | @@ -XXX,XX +XXX,XX @@ typedef struct SDHCIState { | 67 | @@ -XXX,XX +XXX,XX @@ |
78 | AddressSpace sysbus_dma_as; | 68 | #include "migration/vmstate.h" |
79 | AddressSpace *dma_as; | 69 | #include "hw/irq.h" |
80 | MemoryRegion *dma_mr; | 70 | #include "hw/sysbus.h" |
81 | + const MemoryRegionOps *io_ops; | 71 | +#include "hw/qdev-clock.h" |
82 | 72 | #include "qemu/timer.h" | |
83 | QEMUTimer *insert_timer; /* timer for 'changing' sd card. */ | 73 | #include "qemu/log.h" |
84 | QEMUTimer *transfer_timer; | 74 | #include "qemu/module.h" |
85 | @@ -XXX,XX +XXX,XX @@ typedef struct SDHCIState { | 75 | @@ -XXX,XX +XXX,XX @@ static void systick_instance_init(Object *obj) |
86 | 76 | memory_region_init_io(&s->iomem, obj, &systick_ops, s, "systick", 0xe0); | |
87 | /* Configurable properties */ | 77 | sysbus_init_mmio(sbd, &s->iomem); |
88 | bool pending_insert_quirk; /* Quirk for Raspberry Pi card insert int */ | ||
89 | + uint32_t quirks; | ||
90 | } SDHCIState; | ||
91 | |||
92 | +/* | ||
93 | + * Controller does not provide transfer-complete interrupt when not | ||
94 | + * busy. | ||
95 | + * | ||
96 | + * NOTE: This definition is taken out of Linux kernel and so the | ||
97 | + * original bit number is preserved | ||
98 | + */ | ||
99 | +#define SDHCI_QUIRK_NO_BUSY_IRQ BIT(14) | ||
100 | + | ||
101 | #define TYPE_PCI_SDHCI "sdhci-pci" | ||
102 | #define PCI_SDHCI(obj) OBJECT_CHECK(SDHCIState, (obj), TYPE_PCI_SDHCI) | ||
103 | |||
104 | @@ -XXX,XX +XXX,XX @@ typedef struct SDHCIState { | ||
105 | #define SYSBUS_SDHCI(obj) \ | ||
106 | OBJECT_CHECK(SDHCIState, (obj), TYPE_SYSBUS_SDHCI) | ||
107 | |||
108 | +#define TYPE_IMX_USDHC "imx-usdhc" | ||
109 | + | ||
110 | #endif /* SDHCI_H */ | ||
111 | diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/hw/sd/sdhci.c | ||
114 | +++ b/hw/sd/sdhci.c | ||
115 | @@ -XXX,XX +XXX,XX @@ static void sdhci_send_command(SDHCIState *s) | ||
116 | } | ||
117 | } | ||
118 | |||
119 | - if ((s->norintstsen & SDHC_NISEN_TRSCMP) && | ||
120 | + if (!(s->quirks & SDHCI_QUIRK_NO_BUSY_IRQ) && | ||
121 | + (s->norintstsen & SDHC_NISEN_TRSCMP) && | ||
122 | (s->cmdreg & SDHC_CMD_RESPONSE) == SDHC_CMD_RSP_WITH_BUSY) { | ||
123 | s->norintsts |= SDHC_NIS_TRSCMP; | ||
124 | } | ||
125 | @@ -XXX,XX +XXX,XX @@ static void sdhci_initfn(SDHCIState *s) | ||
126 | |||
127 | s->insert_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sdhci_raise_insertion_irq, s); | ||
128 | s->transfer_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, sdhci_data_transfer, s); | ||
129 | + | ||
130 | + s->io_ops = &sdhci_mmio_ops; | ||
131 | } | ||
132 | |||
133 | static void sdhci_uninitfn(SDHCIState *s) | ||
134 | @@ -XXX,XX +XXX,XX @@ static void sdhci_sysbus_realize(DeviceState *dev, Error ** errp) | ||
135 | } | ||
136 | |||
137 | sysbus_init_irq(sbd, &s->irq); | 78 | sysbus_init_irq(sbd, &s->irq); |
138 | + | 79 | + |
139 | + memory_region_init_io(&s->iomem, OBJECT(s), s->io_ops, s, "sdhci", | 80 | + s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", NULL, NULL, 0); |
140 | + SDHC_REGISTERS_MAP_SIZE); | 81 | + s->cpuclk = qdev_init_clock_in(DEVICE(obj), "cpuclk", NULL, NULL, 0); |
141 | + | ||
142 | sysbus_init_mmio(sbd, &s->iomem); | ||
143 | } | 82 | } |
144 | 83 | ||
145 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo sdhci_bus_info = { | 84 | static void systick_realize(DeviceState *dev, Error **errp) |
146 | .class_init = sdhci_bus_class_init, | 85 | @@ -XXX,XX +XXX,XX @@ static void systick_realize(DeviceState *dev, Error **errp) |
147 | }; | 86 | |
148 | 87 | static const VMStateDescription vmstate_systick = { | |
149 | +static uint64_t usdhc_read(void *opaque, hwaddr offset, unsigned size) | 88 | .name = "armv7m_systick", |
150 | +{ | 89 | - .version_id = 2, |
151 | + SDHCIState *s = SYSBUS_SDHCI(opaque); | 90 | - .minimum_version_id = 2, |
152 | + uint32_t ret; | 91 | + .version_id = 3, |
153 | + uint16_t hostctl; | 92 | + .minimum_version_id = 3, |
154 | + | 93 | .fields = (VMStateField[]) { |
155 | + switch (offset) { | 94 | + VMSTATE_CLOCK(refclk, SysTickState), |
156 | + default: | 95 | + VMSTATE_CLOCK(cpuclk, SysTickState), |
157 | + return sdhci_read(opaque, offset, size); | 96 | VMSTATE_UINT32(control, SysTickState), |
158 | + | 97 | VMSTATE_INT64(tick, SysTickState), |
159 | + case SDHC_HOSTCTL: | 98 | VMSTATE_PTIMER(ptimer, SysTickState), |
160 | + /* | ||
161 | + * For a detailed explanation on the following bit | ||
162 | + * manipulation code see comments in a similar part of | ||
163 | + * usdhc_write() | ||
164 | + */ | ||
165 | + hostctl = SDHC_DMA_TYPE(s->hostctl) << (8 - 3); | ||
166 | + | ||
167 | + if (s->hostctl & SDHC_CTRL_8BITBUS) { | ||
168 | + hostctl |= ESDHC_CTRL_8BITBUS; | ||
169 | + } | ||
170 | + | ||
171 | + if (s->hostctl & SDHC_CTRL_4BITBUS) { | ||
172 | + hostctl |= ESDHC_CTRL_4BITBUS; | ||
173 | + } | ||
174 | + | ||
175 | + ret = hostctl; | ||
176 | + ret |= (uint32_t)s->blkgap << 16; | ||
177 | + ret |= (uint32_t)s->wakcon << 24; | ||
178 | + | ||
179 | + break; | ||
180 | + | ||
181 | + case ESDHC_DLL_CTRL: | ||
182 | + case ESDHC_TUNE_CTRL_STATUS: | ||
183 | + case ESDHC_UNDOCUMENTED_REG27: | ||
184 | + case ESDHC_TUNING_CTRL: | ||
185 | + case ESDHC_VENDOR_SPEC: | ||
186 | + case ESDHC_MIX_CTRL: | ||
187 | + case ESDHC_WTMK_LVL: | ||
188 | + ret = 0; | ||
189 | + break; | ||
190 | + } | ||
191 | + | ||
192 | + return ret; | ||
193 | +} | ||
194 | + | ||
195 | +static void | ||
196 | +usdhc_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) | ||
197 | +{ | ||
198 | + SDHCIState *s = SYSBUS_SDHCI(opaque); | ||
199 | + uint8_t hostctl; | ||
200 | + uint32_t value = (uint32_t)val; | ||
201 | + | ||
202 | + switch (offset) { | ||
203 | + case ESDHC_DLL_CTRL: | ||
204 | + case ESDHC_TUNE_CTRL_STATUS: | ||
205 | + case ESDHC_UNDOCUMENTED_REG27: | ||
206 | + case ESDHC_TUNING_CTRL: | ||
207 | + case ESDHC_WTMK_LVL: | ||
208 | + case ESDHC_VENDOR_SPEC: | ||
209 | + break; | ||
210 | + | ||
211 | + case SDHC_HOSTCTL: | ||
212 | + /* | ||
213 | + * Here's What ESDHCI has at offset 0x28 (SDHC_HOSTCTL) | ||
214 | + * | ||
215 | + * 7 6 5 4 3 2 1 0 | ||
216 | + * |-----------+--------+--------+-----------+----------+---------| | ||
217 | + * | Card | Card | Endian | DATA3 | Data | Led | | ||
218 | + * | Detect | Detect | Mode | as Card | Transfer | Control | | ||
219 | + * | Signal | Test | | Detection | Width | | | ||
220 | + * | Selection | Level | | Pin | | | | ||
221 | + * |-----------+--------+--------+-----------+----------+---------| | ||
222 | + * | ||
223 | + * and 0x29 | ||
224 | + * | ||
225 | + * 15 10 9 8 | ||
226 | + * |----------+------| | ||
227 | + * | Reserved | DMA | | ||
228 | + * | | Sel. | | ||
229 | + * | | | | ||
230 | + * |----------+------| | ||
231 | + * | ||
232 | + * and here's what SDCHI spec expects those offsets to be: | ||
233 | + * | ||
234 | + * 0x28 (Host Control Register) | ||
235 | + * | ||
236 | + * 7 6 5 4 3 2 1 0 | ||
237 | + * |--------+--------+----------+------+--------+----------+---------| | ||
238 | + * | Card | Card | Extended | DMA | High | Data | LED | | ||
239 | + * | Detect | Detect | Data | Sel. | Speed | Transfer | Control | | ||
240 | + * | Signal | Test | Transfer | | Enable | Width | | | ||
241 | + * | Sel. | Level | Width | | | | | | ||
242 | + * |--------+--------+----------+------+--------+----------+---------| | ||
243 | + * | ||
244 | + * and 0x29 (Power Control Register) | ||
245 | + * | ||
246 | + * |----------------------------------| | ||
247 | + * | Power Control Register | | ||
248 | + * | | | ||
249 | + * | Description omitted, | | ||
250 | + * | since it has no analog in ESDHCI | | ||
251 | + * | | | ||
252 | + * |----------------------------------| | ||
253 | + * | ||
254 | + * Since offsets 0x2A and 0x2B should be compatible between | ||
255 | + * both IP specs we only need to reconcile least 16-bit of the | ||
256 | + * word we've been given. | ||
257 | + */ | ||
258 | + | ||
259 | + /* | ||
260 | + * First, save bits 7 6 and 0 since they are identical | ||
261 | + */ | ||
262 | + hostctl = value & (SDHC_CTRL_LED | | ||
263 | + SDHC_CTRL_CDTEST_INS | | ||
264 | + SDHC_CTRL_CDTEST_EN); | ||
265 | + /* | ||
266 | + * Second, split "Data Transfer Width" from bits 2 and 1 in to | ||
267 | + * bits 5 and 1 | ||
268 | + */ | ||
269 | + if (value & ESDHC_CTRL_8BITBUS) { | ||
270 | + hostctl |= SDHC_CTRL_8BITBUS; | ||
271 | + } | ||
272 | + | ||
273 | + if (value & ESDHC_CTRL_4BITBUS) { | ||
274 | + hostctl |= ESDHC_CTRL_4BITBUS; | ||
275 | + } | ||
276 | + | ||
277 | + /* | ||
278 | + * Third, move DMA select from bits 9 and 8 to bits 4 and 3 | ||
279 | + */ | ||
280 | + hostctl |= SDHC_DMA_TYPE(value >> (8 - 3)); | ||
281 | + | ||
282 | + /* | ||
283 | + * Now place the corrected value into low 16-bit of the value | ||
284 | + * we are going to give standard SDHCI write function | ||
285 | + * | ||
286 | + * NOTE: This transformation should be the inverse of what can | ||
287 | + * be found in drivers/mmc/host/sdhci-esdhc-imx.c in Linux | ||
288 | + * kernel | ||
289 | + */ | ||
290 | + value &= ~UINT16_MAX; | ||
291 | + value |= hostctl; | ||
292 | + value |= (uint16_t)s->pwrcon << 8; | ||
293 | + | ||
294 | + sdhci_write(opaque, offset, value, size); | ||
295 | + break; | ||
296 | + | ||
297 | + case ESDHC_MIX_CTRL: | ||
298 | + /* | ||
299 | + * So, when SD/MMC stack in Linux tries to write to "Transfer | ||
300 | + * Mode Register", ESDHC i.MX quirk code will translate it | ||
301 | + * into a write to ESDHC_MIX_CTRL, so we do the opposite in | ||
302 | + * order to get where we started | ||
303 | + * | ||
304 | + * Note that Auto CMD23 Enable bit is located in a wrong place | ||
305 | + * on i.MX, but since it is not used by QEMU we do not care. | ||
306 | + * | ||
307 | + * We don't want to call sdhci_write(.., SDHC_TRNMOD, ...) | ||
308 | + * here becuase it will result in a call to | ||
309 | + * sdhci_send_command(s) which we don't want. | ||
310 | + * | ||
311 | + */ | ||
312 | + s->trnmod = value & UINT16_MAX; | ||
313 | + break; | ||
314 | + case SDHC_TRNMOD: | ||
315 | + /* | ||
316 | + * Similar to above, but this time a write to "Command | ||
317 | + * Register" will be translated into a 4-byte write to | ||
318 | + * "Transfer Mode register" where lower 16-bit of value would | ||
319 | + * be set to zero. So what we do is fill those bits with | ||
320 | + * cached value from s->trnmod and let the SDHCI | ||
321 | + * infrastructure handle the rest | ||
322 | + */ | ||
323 | + sdhci_write(opaque, offset, val | s->trnmod, size); | ||
324 | + break; | ||
325 | + case SDHC_BLKSIZE: | ||
326 | + /* | ||
327 | + * ESDHCI does not implement "Host SDMA Buffer Boundary", and | ||
328 | + * Linux driver will try to zero this field out which will | ||
329 | + * break the rest of SDHCI emulation. | ||
330 | + * | ||
331 | + * Linux defaults to maximum possible setting (512K boundary) | ||
332 | + * and it seems to be the only option that i.MX IP implements, | ||
333 | + * so we artificially set it to that value. | ||
334 | + */ | ||
335 | + val |= 0x7 << 12; | ||
336 | + /* FALLTHROUGH */ | ||
337 | + default: | ||
338 | + sdhci_write(opaque, offset, val, size); | ||
339 | + break; | ||
340 | + } | ||
341 | +} | ||
342 | + | ||
343 | + | ||
344 | +static const MemoryRegionOps usdhc_mmio_ops = { | ||
345 | + .read = usdhc_read, | ||
346 | + .write = usdhc_write, | ||
347 | + .valid = { | ||
348 | + .min_access_size = 1, | ||
349 | + .max_access_size = 4, | ||
350 | + .unaligned = false | ||
351 | + }, | ||
352 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
353 | +}; | ||
354 | + | ||
355 | +static void imx_usdhc_init(Object *obj) | ||
356 | +{ | ||
357 | + SDHCIState *s = SYSBUS_SDHCI(obj); | ||
358 | + | ||
359 | + s->io_ops = &usdhc_mmio_ops; | ||
360 | + s->quirks = SDHCI_QUIRK_NO_BUSY_IRQ; | ||
361 | +} | ||
362 | + | ||
363 | +static const TypeInfo imx_usdhc_info = { | ||
364 | + .name = TYPE_IMX_USDHC, | ||
365 | + .parent = TYPE_SYSBUS_SDHCI, | ||
366 | + .instance_init = imx_usdhc_init, | ||
367 | +}; | ||
368 | + | ||
369 | static void sdhci_register_types(void) | ||
370 | { | ||
371 | type_register_static(&sdhci_pci_info); | ||
372 | type_register_static(&sdhci_sysbus_info); | ||
373 | type_register_static(&sdhci_bus_info); | ||
374 | + type_register_static(&imx_usdhc_info); | ||
375 | } | ||
376 | |||
377 | type_init(sdhci_register_types) | ||
378 | -- | 99 | -- |
379 | 2.16.1 | 100 | 2.20.1 |
380 | 101 | ||
381 | 102 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | Create input clocks on the armv7m container object which pass through |
---|---|---|---|
2 | to the systick timers, so that users of the armv7m object can specify | ||
3 | the clocks being used. | ||
2 | 4 | ||
3 | Save the high parts of the Zregs and all of the Pregs. | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | The ZCR_ELx registers are migrated via the CP mechanism. | 6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
7 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
8 | Message-id: 20210812093356.1946-7-peter.maydell@linaro.org | ||
9 | --- | ||
10 | include/hw/arm/armv7m.h | 6 ++++++ | ||
11 | hw/arm/armv7m.c | 23 +++++++++++++++++++++++ | ||
12 | 2 files changed, 29 insertions(+) | ||
5 | 13 | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 14 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h |
7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Message-id: 20180123035349.24538-4-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | target/arm/machine.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ | ||
13 | 1 file changed, 53 insertions(+) | ||
14 | |||
15 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/machine.c | 16 | --- a/include/hw/arm/armv7m.h |
18 | +++ b/target/arm/machine.c | 17 | +++ b/include/hw/arm/armv7m.h |
19 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_iwmmxt = { | 18 | @@ -XXX,XX +XXX,XX @@ |
19 | #include "hw/misc/armv7m_ras.h" | ||
20 | #include "target/arm/idau.h" | ||
21 | #include "qom/object.h" | ||
22 | +#include "hw/clock.h" | ||
23 | |||
24 | #define TYPE_BITBAND "ARM-bitband-memory" | ||
25 | OBJECT_DECLARE_SIMPLE_TYPE(BitBandState, BITBAND) | ||
26 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(ARMv7MState, ARMV7M) | ||
27 | * + Property "vfp": enable VFP (forwarded to CPU object) | ||
28 | * + Property "dsp": enable DSP (forwarded to CPU object) | ||
29 | * + Property "enable-bitband": expose bitbanded IO | ||
30 | + * + Clock input "refclk" is the external reference clock for the systick timers | ||
31 | + * + Clock input "cpuclk" is the main CPU clock | ||
32 | */ | ||
33 | struct ARMv7MState { | ||
34 | /*< private >*/ | ||
35 | @@ -XXX,XX +XXX,XX @@ struct ARMv7MState { | ||
36 | /* MR providing default PPB behaviour */ | ||
37 | MemoryRegion defaultmem; | ||
38 | |||
39 | + Clock *refclk; | ||
40 | + Clock *cpuclk; | ||
41 | + | ||
42 | /* Properties */ | ||
43 | char *cpu_type; | ||
44 | /* MemoryRegion the board provides to us (with its devices, RAM, etc) */ | ||
45 | diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/hw/arm/armv7m.c | ||
48 | +++ b/hw/arm/armv7m.c | ||
49 | @@ -XXX,XX +XXX,XX @@ | ||
50 | #include "hw/arm/boot.h" | ||
51 | #include "hw/loader.h" | ||
52 | #include "hw/qdev-properties.h" | ||
53 | +#include "hw/qdev-clock.h" | ||
54 | #include "elf.h" | ||
55 | #include "sysemu/reset.h" | ||
56 | #include "qemu/error-report.h" | ||
57 | #include "qemu/module.h" | ||
58 | #include "qemu/log.h" | ||
59 | #include "target/arm/idau.h" | ||
60 | +#include "migration/vmstate.h" | ||
61 | |||
62 | /* Bitbanded IO. Each word corresponds to a single bit. */ | ||
63 | |||
64 | @@ -XXX,XX +XXX,XX @@ static void armv7m_instance_init(Object *obj) | ||
65 | object_initialize_child(obj, "bitband[*]", &s->bitband[i], | ||
66 | TYPE_BITBAND); | ||
20 | } | 67 | } |
68 | + | ||
69 | + s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", NULL, NULL, 0); | ||
70 | + s->cpuclk = qdev_init_clock_in(DEVICE(obj), "cpuclk", NULL, NULL, 0); | ||
71 | } | ||
72 | |||
73 | static void armv7m_realize(DeviceState *dev, Error **errp) | ||
74 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) | ||
75 | } | ||
76 | |||
77 | /* Create and map the systick devices */ | ||
78 | + qdev_connect_clock_in(DEVICE(&s->systick[M_REG_NS]), "refclk", s->refclk); | ||
79 | + qdev_connect_clock_in(DEVICE(&s->systick[M_REG_NS]), "cpuclk", s->cpuclk); | ||
80 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), errp)) { | ||
81 | return; | ||
82 | } | ||
83 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) | ||
84 | */ | ||
85 | object_initialize_child(OBJECT(dev), "systick-reg-s", | ||
86 | &s->systick[M_REG_S], TYPE_SYSTICK); | ||
87 | + qdev_connect_clock_in(DEVICE(&s->systick[M_REG_S]), "refclk", | ||
88 | + s->refclk); | ||
89 | + qdev_connect_clock_in(DEVICE(&s->systick[M_REG_S]), "cpuclk", | ||
90 | + s->cpuclk); | ||
91 | |||
92 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_S]), errp)) { | ||
93 | return; | ||
94 | @@ -XXX,XX +XXX,XX @@ static Property armv7m_properties[] = { | ||
95 | DEFINE_PROP_END_OF_LIST(), | ||
21 | }; | 96 | }; |
22 | 97 | ||
23 | +#ifdef TARGET_AARCH64 | 98 | +static const VMStateDescription vmstate_armv7m = { |
24 | +/* The expression ARM_MAX_VQ - 2 is 0 for pure AArch32 build, | 99 | + .name = "armv7m", |
25 | + * and ARMPredicateReg is actively empty. This triggers errors | ||
26 | + * in the expansion of the VMSTATE macros. | ||
27 | + */ | ||
28 | + | ||
29 | +static bool sve_needed(void *opaque) | ||
30 | +{ | ||
31 | + ARMCPU *cpu = opaque; | ||
32 | + CPUARMState *env = &cpu->env; | ||
33 | + | ||
34 | + return arm_feature(env, ARM_FEATURE_SVE); | ||
35 | +} | ||
36 | + | ||
37 | +/* The first two words of each Zreg is stored in VFP state. */ | ||
38 | +static const VMStateDescription vmstate_zreg_hi_reg = { | ||
39 | + .name = "cpu/sve/zreg_hi", | ||
40 | + .version_id = 1, | 100 | + .version_id = 1, |
41 | + .minimum_version_id = 1, | 101 | + .minimum_version_id = 1, |
42 | + .fields = (VMStateField[]) { | 102 | + .fields = (VMStateField[]) { |
43 | + VMSTATE_UINT64_SUB_ARRAY(d, ARMVectorReg, 2, ARM_MAX_VQ - 2), | 103 | + VMSTATE_CLOCK(refclk, SysTickState), |
104 | + VMSTATE_CLOCK(cpuclk, SysTickState), | ||
44 | + VMSTATE_END_OF_LIST() | 105 | + VMSTATE_END_OF_LIST() |
45 | + } | 106 | + } |
46 | +}; | 107 | +}; |
47 | + | 108 | + |
48 | +static const VMStateDescription vmstate_preg_reg = { | 109 | static void armv7m_class_init(ObjectClass *klass, void *data) |
49 | + .name = "cpu/sve/preg", | ||
50 | + .version_id = 1, | ||
51 | + .minimum_version_id = 1, | ||
52 | + .fields = (VMStateField[]) { | ||
53 | + VMSTATE_UINT64_ARRAY(p, ARMPredicateReg, 2 * ARM_MAX_VQ / 8), | ||
54 | + VMSTATE_END_OF_LIST() | ||
55 | + } | ||
56 | +}; | ||
57 | + | ||
58 | +static const VMStateDescription vmstate_sve = { | ||
59 | + .name = "cpu/sve", | ||
60 | + .version_id = 1, | ||
61 | + .minimum_version_id = 1, | ||
62 | + .needed = sve_needed, | ||
63 | + .fields = (VMStateField[]) { | ||
64 | + VMSTATE_STRUCT_ARRAY(env.vfp.zregs, ARMCPU, 32, 0, | ||
65 | + vmstate_zreg_hi_reg, ARMVectorReg), | ||
66 | + VMSTATE_STRUCT_ARRAY(env.vfp.pregs, ARMCPU, 17, 0, | ||
67 | + vmstate_preg_reg, ARMPredicateReg), | ||
68 | + VMSTATE_END_OF_LIST() | ||
69 | + } | ||
70 | +}; | ||
71 | +#endif /* AARCH64 */ | ||
72 | + | ||
73 | static bool m_needed(void *opaque) | ||
74 | { | 110 | { |
75 | ARMCPU *cpu = opaque; | 111 | DeviceClass *dc = DEVICE_CLASS(klass); |
76 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_arm_cpu = { | 112 | |
77 | &vmstate_pmsav7, | 113 | dc->realize = armv7m_realize; |
78 | &vmstate_pmsav8, | 114 | + dc->vmsd = &vmstate_armv7m; |
79 | &vmstate_m_security, | 115 | device_class_set_props(dc, armv7m_properties); |
80 | +#ifdef TARGET_AARCH64 | 116 | } |
81 | + &vmstate_sve, | 117 | |
82 | +#endif | ||
83 | NULL | ||
84 | } | ||
85 | }; | ||
86 | -- | 118 | -- |
87 | 2.16.1 | 119 | 2.20.1 |
88 | 120 | ||
89 | 121 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Wire up the cpuclk for the systick devices to the SSE object's | ||
2 | existing mainclk clock. | ||
1 | 3 | ||
4 | We do not wire up the refclk because the SSE subsystems do not | ||
5 | provide a refclk. (This is documented in the IoTKit and SSE-200 | ||
6 | TRMs; the SSE-300 TRM doesn't mention it but we assume it follows the | ||
7 | same approach.) When we update the systick device later to honour "no | ||
8 | refclk connected" this will fix a minor emulation inaccuracy for the | ||
9 | SSE-based boards. | ||
10 | |||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
14 | Message-id: 20210812093356.1946-8-peter.maydell@linaro.org | ||
15 | --- | ||
16 | hw/arm/armsse.c | 3 +++ | ||
17 | 1 file changed, 3 insertions(+) | ||
18 | |||
19 | diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/hw/arm/armsse.c | ||
22 | +++ b/hw/arm/armsse.c | ||
23 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
24 | int j; | ||
25 | char *gpioname; | ||
26 | |||
27 | + qdev_connect_clock_in(cpudev, "cpuclk", s->mainclk); | ||
28 | + /* The SSE subsystems do not wire up a systick refclk */ | ||
29 | + | ||
30 | qdev_prop_set_uint32(cpudev, "num-irq", s->exp_numirq + NUM_SSE_IRQS); | ||
31 | /* | ||
32 | * In real hardware the initial Secure VTOR is set from the INITSVTOR* | ||
33 | -- | ||
34 | 2.20.1 | ||
35 | |||
36 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Connect up the armv7m clocks on the mps2-an385/386/500/511. | ||
1 | 2 | ||
3 | Connect up the armv7m object's clocks on the MPS boards defined in | ||
4 | mps2.c. The documentation for these FPGA images doesn't specify what | ||
5 | systick reference clock is used (if any), so for the moment we | ||
6 | provide a 1MHz refclock, which will result in no behavioural change | ||
7 | from the current hardwired 1MHz clock implemented in | ||
8 | armv7m_systick.c:systick_scale(). | ||
9 | |||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
12 | Message-id: 20210812093356.1946-9-peter.maydell@linaro.org | ||
13 | --- | ||
14 | hw/arm/mps2.c | 15 +++++++++++++++ | ||
15 | 1 file changed, 15 insertions(+) | ||
16 | |||
17 | diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/hw/arm/mps2.c | ||
20 | +++ b/hw/arm/mps2.c | ||
21 | @@ -XXX,XX +XXX,XX @@ struct MPS2MachineState { | ||
22 | CMSDKAPBWatchdog watchdog; | ||
23 | CMSDKAPBTimer timer[2]; | ||
24 | Clock *sysclk; | ||
25 | + Clock *refclk; | ||
26 | }; | ||
27 | |||
28 | #define TYPE_MPS2_MACHINE "mps2" | ||
29 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_TYPE(MPS2MachineState, MPS2MachineClass, MPS2_MACHINE) | ||
30 | /* Main SYSCLK frequency in Hz */ | ||
31 | #define SYSCLK_FRQ 25000000 | ||
32 | |||
33 | +/* | ||
34 | + * The Application Notes don't say anything about how the | ||
35 | + * systick reference clock is configured. (Quite possibly | ||
36 | + * they don't have one at all.) This 1MHz clock matches the | ||
37 | + * pre-existing behaviour that used to be hardcoded in the | ||
38 | + * armv7m_systick implementation. | ||
39 | + */ | ||
40 | +#define REFCLK_FRQ (1 * 1000 * 1000) | ||
41 | + | ||
42 | /* Initialize the auxiliary RAM region @mr and map it into | ||
43 | * the memory map at @base. | ||
44 | */ | ||
45 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | ||
46 | mms->sysclk = clock_new(OBJECT(machine), "SYSCLK"); | ||
47 | clock_set_hz(mms->sysclk, SYSCLK_FRQ); | ||
48 | |||
49 | + mms->refclk = clock_new(OBJECT(machine), "REFCLK"); | ||
50 | + clock_set_hz(mms->refclk, REFCLK_FRQ); | ||
51 | + | ||
52 | /* The FPGA images have an odd combination of different RAMs, | ||
53 | * because in hardware they are different implementations and | ||
54 | * connected to different buses, giving varying performance/size | ||
55 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | ||
56 | default: | ||
57 | g_assert_not_reached(); | ||
58 | } | ||
59 | + qdev_connect_clock_in(armv7m, "cpuclk", mms->sysclk); | ||
60 | + qdev_connect_clock_in(armv7m, "refclk", mms->refclk); | ||
61 | qdev_prop_set_string(armv7m, "cpu-type", machine->cpu_type); | ||
62 | qdev_prop_set_bit(armv7m, "enable-bitband", true); | ||
63 | object_property_set_link(OBJECT(&mms->armv7m), "memory", | ||
64 | -- | ||
65 | 2.20.1 | ||
66 | |||
67 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | It is quite common for a clock tree to involve possibly programmable |
---|---|---|---|
2 | 2 | clock multipliers or dividers, where the frequency of a clock is for | |
3 | Add minimal code needed to allow upstream Linux guest to boot. | 3 | instance divided by 8 to produce a slower clock to feed to a |
4 | 4 | particular device. | |
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | 5 | |
6 | Cc: Jason Wang <jasowang@redhat.com> | 6 | Currently we provide no convenient mechanism for modelling this. You |
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | can implement it by having an input Clock and an output Clock, and |
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | 8 | manually setting the period of the output clock in the period-changed |
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | 9 | callback of the input clock, but that's quite clunky. |
10 | Cc: qemu-devel@nongnu.org | 10 | |
11 | Cc: qemu-arm@nongnu.org | 11 | This patch adds support in the Clock objects themselves for setting a |
12 | Cc: yurovsky@gmail.com | 12 | multiplier or divider. The effect of setting this on a clock is that |
13 | when the clock's period is changed, all the children of the clock are | ||
14 | set to period * multiplier / divider, rather than being set to the | ||
15 | same period as the parent clock. | ||
16 | |||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
19 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 20 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 21 | Reviewed-by: Luc Michel <luc@lmichel.fr> |
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | 22 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> |
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 23 | Message-id: 20210812093356.1946-10-peter.maydell@linaro.org |
17 | --- | 24 | --- |
18 | hw/misc/Makefile.objs | 1 + | 25 | docs/devel/clocks.rst | 23 +++++++++++++++++++++++ |
19 | include/hw/misc/imx7_gpr.h | 28 ++++++++++ | 26 | include/hw/clock.h | 29 +++++++++++++++++++++++++++++ |
20 | hw/misc/imx7_gpr.c | 124 +++++++++++++++++++++++++++++++++++++++++++++ | 27 | hw/core/clock-vmstate.c | 40 +++++++++++++++++++++++++++++++++++++++- |
21 | hw/misc/trace-events | 4 ++ | 28 | hw/core/clock.c | 31 +++++++++++++++++++++++++++---- |
22 | 4 files changed, 157 insertions(+) | 29 | hw/core/trace-events | 1 + |
23 | create mode 100644 include/hw/misc/imx7_gpr.h | 30 | 5 files changed, 119 insertions(+), 5 deletions(-) |
24 | create mode 100644 hw/misc/imx7_gpr.c | 31 | |
25 | 32 | diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst | |
26 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 33 | index XXXXXXX..XXXXXXX 100644 |
27 | index XXXXXXX..XXXXXXX 100644 | 34 | --- a/docs/devel/clocks.rst |
28 | --- a/hw/misc/Makefile.objs | 35 | +++ b/docs/devel/clocks.rst |
29 | +++ b/hw/misc/Makefile.objs | 36 | @@ -XXX,XX +XXX,XX @@ clocks get the new clock period value: *Clock 2*, *Clock 3* and *Clock 4*. |
30 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx6_src.o | 37 | It is not possible to disconnect a clock or to change the clock connection |
31 | obj-$(CONFIG_IMX) += imx7_ccm.o | 38 | after it is connected. |
32 | obj-$(CONFIG_IMX) += imx2_wdt.o | 39 | |
33 | obj-$(CONFIG_IMX) += imx7_snvs.o | 40 | +Clock multiplier and divider settings |
34 | +obj-$(CONFIG_IMX) += imx7_gpr.o | 41 | +------------------------------------- |
35 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | 42 | + |
36 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | 43 | +By default, when clocks are connected together, the child |
37 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | 44 | +clocks run with the same period as their source (parent) clock. |
38 | diff --git a/include/hw/misc/imx7_gpr.h b/include/hw/misc/imx7_gpr.h | 45 | +The Clock API supports a built-in period multiplier/divider |
39 | new file mode 100644 | 46 | +mechanism so you can configure a clock to make its children |
40 | index XXXXXXX..XXXXXXX | 47 | +run at a different period from its own. If you call the |
41 | --- /dev/null | 48 | +``clock_set_mul_div()`` function you can specify the clock's |
42 | +++ b/include/hw/misc/imx7_gpr.h | 49 | +multiplier and divider values. The children of that clock |
50 | +will all run with a period of ``parent_period * multiplier / divider``. | ||
51 | +For instance, if the clock has a frequency of 8MHz and you set its | ||
52 | +multiplier to 2 and its divider to 3, the child clocks will run | ||
53 | +at 12MHz. | ||
54 | + | ||
55 | +You can change the multiplier and divider of a clock at runtime, | ||
56 | +so you can use this to model clock controller devices which | ||
57 | +have guest-programmable frequency multipliers or dividers. | ||
58 | + | ||
59 | +Note that ``clock_set_mul_div()`` does not automatically call | ||
60 | +``clock_propagate()``. If you make a runtime change to the | ||
61 | +multiplier or divider you must call clock_propagate() yourself. | ||
62 | + | ||
63 | Unconnected input clocks | ||
64 | ------------------------ | ||
65 | |||
66 | diff --git a/include/hw/clock.h b/include/hw/clock.h | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/include/hw/clock.h | ||
69 | +++ b/include/hw/clock.h | ||
70 | @@ -XXX,XX +XXX,XX @@ struct Clock { | ||
71 | void *callback_opaque; | ||
72 | unsigned int callback_events; | ||
73 | |||
74 | + /* Ratio of the parent clock to run the child clocks at */ | ||
75 | + uint32_t multiplier; | ||
76 | + uint32_t divider; | ||
77 | + | ||
78 | /* Clocks are organized in a clock tree */ | ||
79 | Clock *source; | ||
80 | QLIST_HEAD(, Clock) children; | ||
81 | @@ -XXX,XX +XXX,XX @@ static inline bool clock_is_enabled(const Clock *clk) | ||
82 | */ | ||
83 | char *clock_display_freq(Clock *clk); | ||
84 | |||
85 | +/** | ||
86 | + * clock_set_mul_div: set multiplier/divider for child clocks | ||
87 | + * @clk: clock | ||
88 | + * @multiplier: multiplier value | ||
89 | + * @divider: divider value | ||
90 | + * | ||
91 | + * By default, a Clock's children will all run with the same period | ||
92 | + * as their parent. This function allows you to adjust the multiplier | ||
93 | + * and divider used to derive the child clock frequency. | ||
94 | + * For example, setting a multiplier of 2 and a divider of 3 | ||
95 | + * will run child clocks with a period 2/3 of the parent clock, | ||
96 | + * so if the parent clock is an 8MHz clock the children will | ||
97 | + * be 12MHz. | ||
98 | + * | ||
99 | + * Setting the multiplier to 0 will stop the child clocks. | ||
100 | + * Setting the divider to 0 is a programming error (diagnosed with | ||
101 | + * an assertion failure). | ||
102 | + * Setting a multiplier value that results in the child period | ||
103 | + * overflowing is not diagnosed. | ||
104 | + * | ||
105 | + * Note that this function does not call clock_propagate(); the | ||
106 | + * caller should do that if necessary. | ||
107 | + */ | ||
108 | +void clock_set_mul_div(Clock *clk, uint32_t multiplier, uint32_t divider); | ||
109 | + | ||
110 | #endif /* QEMU_HW_CLOCK_H */ | ||
111 | diff --git a/hw/core/clock-vmstate.c b/hw/core/clock-vmstate.c | ||
112 | index XXXXXXX..XXXXXXX 100644 | ||
113 | --- a/hw/core/clock-vmstate.c | ||
114 | +++ b/hw/core/clock-vmstate.c | ||
43 | @@ -XXX,XX +XXX,XX @@ | 115 | @@ -XXX,XX +XXX,XX @@ |
44 | +/* | 116 | #include "migration/vmstate.h" |
45 | + * Copyright (c) 2017, Impinj, Inc. | 117 | #include "hw/clock.h" |
46 | + * | 118 | |
47 | + * i.MX7 GPR IP block emulation code | 119 | +static bool muldiv_needed(void *opaque) |
48 | + * | 120 | +{ |
49 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 121 | + Clock *clk = opaque; |
50 | + * | 122 | + |
51 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 123 | + return clk->multiplier != 1 || clk->divider != 1; |
52 | + * See the COPYING file in the top-level directory. | 124 | +} |
53 | + */ | 125 | + |
54 | + | 126 | +static int clock_pre_load(void *opaque) |
55 | +#ifndef IMX7_GPR_H | 127 | +{ |
56 | +#define IMX7_GPR_H | 128 | + Clock *clk = opaque; |
57 | + | 129 | + /* |
58 | +#include "qemu/bitops.h" | 130 | + * The initial out-of-reset settings of the Clock might have been |
59 | +#include "hw/sysbus.h" | 131 | + * configured by the device to be different from what we set |
60 | + | 132 | + * in clock_initfn(), so we must here set the default values to |
61 | +#define TYPE_IMX7_GPR "imx7.gpr" | 133 | + * be used if they are not in the inbound migration state. |
62 | +#define IMX7_GPR(obj) OBJECT_CHECK(IMX7GPRState, (obj), TYPE_IMX7_GPR) | 134 | + */ |
63 | + | 135 | + clk->multiplier = 1; |
64 | +typedef struct IMX7GPRState { | 136 | + clk->divider = 1; |
65 | + /* <private> */ | ||
66 | + SysBusDevice parent_obj; | ||
67 | + | ||
68 | + MemoryRegion mmio; | ||
69 | +} IMX7GPRState; | ||
70 | + | ||
71 | +#endif /* IMX7_GPR_H */ | ||
72 | diff --git a/hw/misc/imx7_gpr.c b/hw/misc/imx7_gpr.c | ||
73 | new file mode 100644 | ||
74 | index XXXXXXX..XXXXXXX | ||
75 | --- /dev/null | ||
76 | +++ b/hw/misc/imx7_gpr.c | ||
77 | @@ -XXX,XX +XXX,XX @@ | ||
78 | +/* | ||
79 | + * Copyright (c) 2018, Impinj, Inc. | ||
80 | + * | ||
81 | + * i.MX7 GPR IP block emulation code | ||
82 | + * | ||
83 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
84 | + * | ||
85 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
86 | + * See the COPYING file in the top-level directory. | ||
87 | + * | ||
88 | + * Bare minimum emulation code needed to support being able to shut | ||
89 | + * down linux guest gracefully. | ||
90 | + */ | ||
91 | + | ||
92 | +#include "qemu/osdep.h" | ||
93 | +#include "hw/misc/imx7_gpr.h" | ||
94 | +#include "qemu/log.h" | ||
95 | +#include "sysemu/sysemu.h" | ||
96 | + | ||
97 | +#include "trace.h" | ||
98 | + | ||
99 | +enum IMX7GPRRegisters { | ||
100 | + IOMUXC_GPR0 = 0x00, | ||
101 | + IOMUXC_GPR1 = 0x04, | ||
102 | + IOMUXC_GPR2 = 0x08, | ||
103 | + IOMUXC_GPR3 = 0x0c, | ||
104 | + IOMUXC_GPR4 = 0x10, | ||
105 | + IOMUXC_GPR5 = 0x14, | ||
106 | + IOMUXC_GPR6 = 0x18, | ||
107 | + IOMUXC_GPR7 = 0x1c, | ||
108 | + IOMUXC_GPR8 = 0x20, | ||
109 | + IOMUXC_GPR9 = 0x24, | ||
110 | + IOMUXC_GPR10 = 0x28, | ||
111 | + IOMUXC_GPR11 = 0x2c, | ||
112 | + IOMUXC_GPR12 = 0x30, | ||
113 | + IOMUXC_GPR13 = 0x34, | ||
114 | + IOMUXC_GPR14 = 0x38, | ||
115 | + IOMUXC_GPR15 = 0x3c, | ||
116 | + IOMUXC_GPR16 = 0x40, | ||
117 | + IOMUXC_GPR17 = 0x44, | ||
118 | + IOMUXC_GPR18 = 0x48, | ||
119 | + IOMUXC_GPR19 = 0x4c, | ||
120 | + IOMUXC_GPR20 = 0x50, | ||
121 | + IOMUXC_GPR21 = 0x54, | ||
122 | + IOMUXC_GPR22 = 0x58, | ||
123 | +}; | ||
124 | + | ||
125 | +#define IMX7D_GPR1_IRQ_MASK BIT(12) | ||
126 | +#define IMX7D_GPR1_ENET1_TX_CLK_SEL_MASK BIT(13) | ||
127 | +#define IMX7D_GPR1_ENET2_TX_CLK_SEL_MASK BIT(14) | ||
128 | +#define IMX7D_GPR1_ENET_TX_CLK_SEL_MASK (0x3 << 13) | ||
129 | +#define IMX7D_GPR1_ENET1_CLK_DIR_MASK BIT(17) | ||
130 | +#define IMX7D_GPR1_ENET2_CLK_DIR_MASK BIT(18) | ||
131 | +#define IMX7D_GPR1_ENET_CLK_DIR_MASK (0x3 << 17) | ||
132 | + | ||
133 | +#define IMX7D_GPR5_CSI_MUX_CONTROL_MIPI BIT(4) | ||
134 | +#define IMX7D_GPR12_PCIE_PHY_REFCLK_SEL BIT(5) | ||
135 | +#define IMX7D_GPR22_PCIE_PHY_PLL_LOCKED BIT(31) | ||
136 | + | ||
137 | + | ||
138 | +static uint64_t imx7_gpr_read(void *opaque, hwaddr offset, unsigned size) | ||
139 | +{ | ||
140 | + trace_imx7_gpr_read(offset); | ||
141 | + | ||
142 | + if (offset == IOMUXC_GPR22) { | ||
143 | + return IMX7D_GPR22_PCIE_PHY_PLL_LOCKED; | ||
144 | + } | ||
145 | + | 137 | + |
146 | + return 0; | 138 | + return 0; |
147 | +} | 139 | +} |
148 | + | 140 | + |
149 | +static void imx7_gpr_write(void *opaque, hwaddr offset, | 141 | +const VMStateDescription vmstate_muldiv = { |
150 | + uint64_t v, unsigned size) | 142 | + .name = "clock/muldiv", |
151 | +{ | 143 | + .version_id = 1, |
152 | + trace_imx7_gpr_write(offset, v); | 144 | + .minimum_version_id = 1, |
153 | +} | 145 | + .needed = muldiv_needed, |
154 | + | 146 | + .fields = (VMStateField[]) { |
155 | +static const struct MemoryRegionOps imx7_gpr_ops = { | 147 | + VMSTATE_UINT32(multiplier, Clock), |
156 | + .read = imx7_gpr_read, | 148 | + VMSTATE_UINT32(divider, Clock), |
157 | + .write = imx7_gpr_write, | ||
158 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
159 | + .impl = { | ||
160 | + /* | ||
161 | + * Our device would not work correctly if the guest was doing | ||
162 | + * unaligned access. This might not be a limitation on the | ||
163 | + * real device but in practice there is no reason for a guest | ||
164 | + * to access this device unaligned. | ||
165 | + */ | ||
166 | + .min_access_size = 4, | ||
167 | + .max_access_size = 4, | ||
168 | + .unaligned = false, | ||
169 | + }, | 149 | + }, |
170 | +}; | 150 | +}; |
171 | + | 151 | + |
172 | +static void imx7_gpr_init(Object *obj) | 152 | const VMStateDescription vmstate_clock = { |
173 | +{ | 153 | .name = "clock", |
174 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | 154 | .version_id = 0, |
175 | + IMX7GPRState *s = IMX7_GPR(obj); | 155 | .minimum_version_id = 0, |
176 | + | 156 | + .pre_load = clock_pre_load, |
177 | + memory_region_init_io(&s->mmio, obj, &imx7_gpr_ops, s, | 157 | .fields = (VMStateField[]) { |
178 | + TYPE_IMX7_GPR, 64 * 1024); | 158 | VMSTATE_UINT64(period, Clock), |
179 | + sysbus_init_mmio(sd, &s->mmio); | 159 | VMSTATE_END_OF_LIST() |
180 | +} | 160 | - } |
181 | + | 161 | + }, |
182 | +static void imx7_gpr_class_init(ObjectClass *klass, void *data) | 162 | + .subsections = (const VMStateDescription*[]) { |
183 | +{ | 163 | + &vmstate_muldiv, |
184 | + DeviceClass *dc = DEVICE_CLASS(klass); | 164 | + NULL |
185 | + | 165 | + }, |
186 | + dc->desc = "i.MX7 General Purpose Registers Module"; | 166 | }; |
187 | +} | 167 | diff --git a/hw/core/clock.c b/hw/core/clock.c |
188 | + | 168 | index XXXXXXX..XXXXXXX 100644 |
189 | +static const TypeInfo imx7_gpr_info = { | 169 | --- a/hw/core/clock.c |
190 | + .name = TYPE_IMX7_GPR, | 170 | +++ b/hw/core/clock.c |
191 | + .parent = TYPE_SYS_BUS_DEVICE, | 171 | @@ -XXX,XX +XXX,XX @@ bool clock_set(Clock *clk, uint64_t period) |
192 | + .instance_size = sizeof(IMX7GPRState), | 172 | return true; |
193 | + .instance_init = imx7_gpr_init, | 173 | } |
194 | + .class_init = imx7_gpr_class_init, | 174 | |
195 | +}; | 175 | +static uint64_t clock_get_child_period(Clock *clk) |
196 | + | 176 | +{ |
197 | +static void imx7_gpr_register_type(void) | 177 | + /* |
198 | +{ | 178 | + * Return the period to be used for child clocks, which is the parent |
199 | + type_register_static(&imx7_gpr_info); | 179 | + * clock period adjusted for for multiplier and divider effects. |
200 | +} | 180 | + */ |
201 | +type_init(imx7_gpr_register_type) | 181 | + return muldiv64(clk->period, clk->multiplier, clk->divider); |
202 | diff --git a/hw/misc/trace-events b/hw/misc/trace-events | 182 | +} |
203 | index XXXXXXX..XXXXXXX 100644 | 183 | + |
204 | --- a/hw/misc/trace-events | 184 | static void clock_call_callback(Clock *clk, ClockEvent event) |
205 | +++ b/hw/misc/trace-events | 185 | { |
206 | @@ -XXX,XX +XXX,XX @@ mps2_scc_cfg_read(unsigned function, unsigned device, uint32_t value) "MPS2 SCC | 186 | /* |
207 | msf2_sysreg_write(uint64_t offset, uint32_t val, uint32_t prev) "msf2-sysreg write: addr 0x%08" HWADDR_PRIx " data 0x%" PRIx32 " prev 0x%" PRIx32 | 187 | @@ -XXX,XX +XXX,XX @@ static void clock_call_callback(Clock *clk, ClockEvent event) |
208 | msf2_sysreg_read(uint64_t offset, uint32_t val) "msf2-sysreg read: addr 0x%08" HWADDR_PRIx " data 0x%08" PRIx32 | 188 | static void clock_propagate_period(Clock *clk, bool call_callbacks) |
209 | msf2_sysreg_write_pll_status(void) "Invalid write to read only PLL status register" | 189 | { |
210 | + | 190 | Clock *child; |
211 | +#hw/misc/imx7_gpr.c | 191 | + uint64_t child_period = clock_get_child_period(clk); |
212 | +imx7_gpr_read(uint64_t offset) "addr 0x%08" HWADDR_PRIx | 192 | |
213 | +imx7_gpr_write(uint64_t offset, uint64_t value) "addr 0x%08" HWADDR_PRIx "value 0x%08" HWADDR_PRIx | 193 | QLIST_FOREACH(child, &clk->children, sibling) { |
194 | - if (child->period != clk->period) { | ||
195 | + if (child->period != child_period) { | ||
196 | if (call_callbacks) { | ||
197 | clock_call_callback(child, ClockPreUpdate); | ||
198 | } | ||
199 | - child->period = clk->period; | ||
200 | + child->period = child_period; | ||
201 | trace_clock_update(CLOCK_PATH(child), CLOCK_PATH(clk), | ||
202 | - CLOCK_PERIOD_TO_HZ(clk->period), | ||
203 | + CLOCK_PERIOD_TO_HZ(child->period), | ||
204 | call_callbacks); | ||
205 | if (call_callbacks) { | ||
206 | clock_call_callback(child, ClockUpdate); | ||
207 | @@ -XXX,XX +XXX,XX @@ void clock_set_source(Clock *clk, Clock *src) | ||
208 | |||
209 | trace_clock_set_source(CLOCK_PATH(clk), CLOCK_PATH(src)); | ||
210 | |||
211 | - clk->period = src->period; | ||
212 | + clk->period = clock_get_child_period(src); | ||
213 | QLIST_INSERT_HEAD(&src->children, clk, sibling); | ||
214 | clk->source = src; | ||
215 | clock_propagate_period(clk, false); | ||
216 | @@ -XXX,XX +XXX,XX @@ char *clock_display_freq(Clock *clk) | ||
217 | return freq_to_str(clock_get_hz(clk)); | ||
218 | } | ||
219 | |||
220 | +void clock_set_mul_div(Clock *clk, uint32_t multiplier, uint32_t divider) | ||
221 | +{ | ||
222 | + assert(divider != 0); | ||
223 | + | ||
224 | + trace_clock_set_mul_div(CLOCK_PATH(clk), clk->multiplier, multiplier, | ||
225 | + clk->divider, divider); | ||
226 | + clk->multiplier = multiplier; | ||
227 | + clk->divider = divider; | ||
228 | +} | ||
229 | + | ||
230 | static void clock_initfn(Object *obj) | ||
231 | { | ||
232 | Clock *clk = CLOCK(obj); | ||
233 | |||
234 | + clk->multiplier = 1; | ||
235 | + clk->divider = 1; | ||
236 | + | ||
237 | QLIST_INIT(&clk->children); | ||
238 | } | ||
239 | |||
240 | diff --git a/hw/core/trace-events b/hw/core/trace-events | ||
241 | index XXXXXXX..XXXXXXX 100644 | ||
242 | --- a/hw/core/trace-events | ||
243 | +++ b/hw/core/trace-events | ||
244 | @@ -XXX,XX +XXX,XX @@ clock_disconnect(const char *clk) "'%s'" | ||
245 | clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', %"PRIu64"Hz->%"PRIu64"Hz" | ||
246 | clock_propagate(const char *clk) "'%s'" | ||
247 | clock_update(const char *clk, const char *src, uint64_t hz, int cb) "'%s', src='%s', val=%"PRIu64"Hz cb=%d" | ||
248 | +clock_set_mul_div(const char *clk, uint32_t oldmul, uint32_t mul, uint32_t olddiv, uint32_t div) "'%s', mul: %u -> %u, div: %u -> %u" | ||
214 | -- | 249 | -- |
215 | 2.16.1 | 250 | 2.20.1 |
216 | 251 | ||
217 | 252 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | In the realize methods of the stm32f100 and stm32f205 SoC objects, we | ||
2 | call g_new() to create new MemoryRegion objects for the sram, flash, | ||
3 | and flash_alias. This is unnecessary (and leaves open the | ||
4 | possibility of leaking the allocations if we exit from realize with | ||
5 | an error). Make these MemoryRegions member fields of the device | ||
6 | state struct instead, as stm32f405 already does. | ||
1 | 7 | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
12 | Message-id: 20210812093356.1946-11-peter.maydell@linaro.org | ||
13 | --- | ||
14 | include/hw/arm/stm32f100_soc.h | 4 ++++ | ||
15 | include/hw/arm/stm32f205_soc.h | 4 ++++ | ||
16 | hw/arm/stm32f100_soc.c | 17 +++++++---------- | ||
17 | hw/arm/stm32f205_soc.c | 17 +++++++---------- | ||
18 | 4 files changed, 22 insertions(+), 20 deletions(-) | ||
19 | |||
20 | diff --git a/include/hw/arm/stm32f100_soc.h b/include/hw/arm/stm32f100_soc.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/include/hw/arm/stm32f100_soc.h | ||
23 | +++ b/include/hw/arm/stm32f100_soc.h | ||
24 | @@ -XXX,XX +XXX,XX @@ struct STM32F100State { | ||
25 | |||
26 | STM32F2XXUsartState usart[STM_NUM_USARTS]; | ||
27 | STM32F2XXSPIState spi[STM_NUM_SPIS]; | ||
28 | + | ||
29 | + MemoryRegion sram; | ||
30 | + MemoryRegion flash; | ||
31 | + MemoryRegion flash_alias; | ||
32 | }; | ||
33 | |||
34 | #endif | ||
35 | diff --git a/include/hw/arm/stm32f205_soc.h b/include/hw/arm/stm32f205_soc.h | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/include/hw/arm/stm32f205_soc.h | ||
38 | +++ b/include/hw/arm/stm32f205_soc.h | ||
39 | @@ -XXX,XX +XXX,XX @@ struct STM32F205State { | ||
40 | STM32F2XXSPIState spi[STM_NUM_SPIS]; | ||
41 | |||
42 | qemu_or_irq *adc_irqs; | ||
43 | + | ||
44 | + MemoryRegion sram; | ||
45 | + MemoryRegion flash; | ||
46 | + MemoryRegion flash_alias; | ||
47 | }; | ||
48 | |||
49 | #endif | ||
50 | diff --git a/hw/arm/stm32f100_soc.c b/hw/arm/stm32f100_soc.c | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/hw/arm/stm32f100_soc.c | ||
53 | +++ b/hw/arm/stm32f100_soc.c | ||
54 | @@ -XXX,XX +XXX,XX @@ static void stm32f100_soc_realize(DeviceState *dev_soc, Error **errp) | ||
55 | int i; | ||
56 | |||
57 | MemoryRegion *system_memory = get_system_memory(); | ||
58 | - MemoryRegion *sram = g_new(MemoryRegion, 1); | ||
59 | - MemoryRegion *flash = g_new(MemoryRegion, 1); | ||
60 | - MemoryRegion *flash_alias = g_new(MemoryRegion, 1); | ||
61 | |||
62 | /* | ||
63 | * Init flash region | ||
64 | * Flash starts at 0x08000000 and then is aliased to boot memory at 0x0 | ||
65 | */ | ||
66 | - memory_region_init_rom(flash, OBJECT(dev_soc), "STM32F100.flash", | ||
67 | + memory_region_init_rom(&s->flash, OBJECT(dev_soc), "STM32F100.flash", | ||
68 | FLASH_SIZE, &error_fatal); | ||
69 | - memory_region_init_alias(flash_alias, OBJECT(dev_soc), | ||
70 | - "STM32F100.flash.alias", flash, 0, FLASH_SIZE); | ||
71 | - memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, flash); | ||
72 | - memory_region_add_subregion(system_memory, 0, flash_alias); | ||
73 | + memory_region_init_alias(&s->flash_alias, OBJECT(dev_soc), | ||
74 | + "STM32F100.flash.alias", &s->flash, 0, FLASH_SIZE); | ||
75 | + memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, &s->flash); | ||
76 | + memory_region_add_subregion(system_memory, 0, &s->flash_alias); | ||
77 | |||
78 | /* Init SRAM region */ | ||
79 | - memory_region_init_ram(sram, NULL, "STM32F100.sram", SRAM_SIZE, | ||
80 | + memory_region_init_ram(&s->sram, NULL, "STM32F100.sram", SRAM_SIZE, | ||
81 | &error_fatal); | ||
82 | - memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, sram); | ||
83 | + memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, &s->sram); | ||
84 | |||
85 | /* Init ARMv7m */ | ||
86 | armv7m = DEVICE(&s->armv7m); | ||
87 | diff --git a/hw/arm/stm32f205_soc.c b/hw/arm/stm32f205_soc.c | ||
88 | index XXXXXXX..XXXXXXX 100644 | ||
89 | --- a/hw/arm/stm32f205_soc.c | ||
90 | +++ b/hw/arm/stm32f205_soc.c | ||
91 | @@ -XXX,XX +XXX,XX @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp) | ||
92 | int i; | ||
93 | |||
94 | MemoryRegion *system_memory = get_system_memory(); | ||
95 | - MemoryRegion *sram = g_new(MemoryRegion, 1); | ||
96 | - MemoryRegion *flash = g_new(MemoryRegion, 1); | ||
97 | - MemoryRegion *flash_alias = g_new(MemoryRegion, 1); | ||
98 | |||
99 | - memory_region_init_rom(flash, OBJECT(dev_soc), "STM32F205.flash", | ||
100 | + memory_region_init_rom(&s->flash, OBJECT(dev_soc), "STM32F205.flash", | ||
101 | FLASH_SIZE, &error_fatal); | ||
102 | - memory_region_init_alias(flash_alias, OBJECT(dev_soc), | ||
103 | - "STM32F205.flash.alias", flash, 0, FLASH_SIZE); | ||
104 | + memory_region_init_alias(&s->flash_alias, OBJECT(dev_soc), | ||
105 | + "STM32F205.flash.alias", &s->flash, 0, FLASH_SIZE); | ||
106 | |||
107 | - memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, flash); | ||
108 | - memory_region_add_subregion(system_memory, 0, flash_alias); | ||
109 | + memory_region_add_subregion(system_memory, FLASH_BASE_ADDRESS, &s->flash); | ||
110 | + memory_region_add_subregion(system_memory, 0, &s->flash_alias); | ||
111 | |||
112 | - memory_region_init_ram(sram, NULL, "STM32F205.sram", SRAM_SIZE, | ||
113 | + memory_region_init_ram(&s->sram, NULL, "STM32F205.sram", SRAM_SIZE, | ||
114 | &error_fatal); | ||
115 | - memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, sram); | ||
116 | + memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, &s->sram); | ||
117 | |||
118 | armv7m = DEVICE(&s->armv7m); | ||
119 | qdev_prop_set_uint32(armv7m, "num-irq", 96); | ||
120 | -- | ||
121 | 2.20.1 | ||
122 | |||
123 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | Wire up the sysclk and refclk for the stm32f100 SoC. This SoC always |
---|---|---|---|
2 | runs the systick refclk at 1/8 the frequency of the main CPU clock, | ||
3 | so the board code only needs to provide a single sysclk clock. | ||
2 | 4 | ||
3 | This implements emulation of the new SM4 instructions that have | 5 | Because there is only one board using this SoC, we convert the SoC |
4 | been added as an optional extension to the ARMv8 Crypto Extensions | 6 | and the board together, rather than splitting it into "add clock to |
5 | in ARM v8.2. | 7 | SoC; connect clock in board; add error check in SoC code that clock |
8 | is wired up". | ||
6 | 9 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 10 | When the systick device starts honouring its clock inputs, this will |
8 | Message-id: 20180207111729.15737-5-ard.biesheuvel@linaro.org | 11 | fix an emulation inaccuracy in the stm32vldiscovery board where the |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 12 | systick reference clock was running at 1MHz rather than 3MHz. |
13 | |||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
17 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
18 | Message-id: 20210812093356.1946-12-peter.maydell@linaro.org | ||
11 | --- | 19 | --- |
12 | target/arm/cpu.h | 1 + | 20 | include/hw/arm/stm32f100_soc.h | 4 ++++ |
13 | target/arm/helper.h | 3 ++ | 21 | hw/arm/stm32f100_soc.c | 30 ++++++++++++++++++++++++++++++ |
14 | target/arm/crypto_helper.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ | 22 | hw/arm/stm32vldiscovery.c | 12 +++++++----- |
15 | target/arm/translate-a64.c | 8 ++++ | 23 | 3 files changed, 41 insertions(+), 5 deletions(-) |
16 | 4 files changed, 103 insertions(+) | ||
17 | 24 | ||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 25 | diff --git a/include/hw/arm/stm32f100_soc.h b/include/hw/arm/stm32f100_soc.h |
19 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/cpu.h | 27 | --- a/include/hw/arm/stm32f100_soc.h |
21 | +++ b/target/arm/cpu.h | 28 | +++ b/include/hw/arm/stm32f100_soc.h |
22 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 29 | @@ -XXX,XX +XXX,XX @@ |
23 | ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | 30 | #include "hw/ssi/stm32f2xx_spi.h" |
24 | ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | 31 | #include "hw/arm/armv7m.h" |
25 | ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ | 32 | #include "qom/object.h" |
26 | + ARM_FEATURE_V8_SM4, /* implements SM4 part of v8 Crypto Extensions */ | 33 | +#include "hw/clock.h" |
34 | |||
35 | #define TYPE_STM32F100_SOC "stm32f100-soc" | ||
36 | OBJECT_DECLARE_SIMPLE_TYPE(STM32F100State, STM32F100_SOC) | ||
37 | @@ -XXX,XX +XXX,XX @@ struct STM32F100State { | ||
38 | MemoryRegion sram; | ||
39 | MemoryRegion flash; | ||
40 | MemoryRegion flash_alias; | ||
41 | + | ||
42 | + Clock *sysclk; | ||
43 | + Clock *refclk; | ||
27 | }; | 44 | }; |
28 | 45 | ||
29 | static inline int arm_feature(CPUARMState *env, int feature) | 46 | #endif |
30 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 47 | diff --git a/hw/arm/stm32f100_soc.c b/hw/arm/stm32f100_soc.c |
31 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/arm/helper.h | 49 | --- a/hw/arm/stm32f100_soc.c |
33 | +++ b/target/arm/helper.h | 50 | +++ b/hw/arm/stm32f100_soc.c |
34 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) | 51 | @@ -XXX,XX +XXX,XX @@ |
35 | DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 52 | #include "exec/address-spaces.h" |
36 | DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 53 | #include "hw/arm/stm32f100_soc.h" |
37 | 54 | #include "hw/qdev-properties.h" | |
38 | +DEF_HELPER_FLAGS_2(crypto_sm4e, TCG_CALL_NO_RWG, void, ptr, ptr) | 55 | +#include "hw/qdev-clock.h" |
39 | +DEF_HELPER_FLAGS_3(crypto_sm4ekey, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 56 | #include "hw/misc/unimp.h" |
57 | #include "sysemu/sysemu.h" | ||
58 | |||
59 | @@ -XXX,XX +XXX,XX @@ static void stm32f100_soc_initfn(Object *obj) | ||
60 | for (i = 0; i < STM_NUM_SPIS; i++) { | ||
61 | object_initialize_child(obj, "spi[*]", &s->spi[i], TYPE_STM32F2XX_SPI); | ||
62 | } | ||
40 | + | 63 | + |
41 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 64 | + s->sysclk = qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0); |
42 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 65 | + s->refclk = qdev_init_clock_in(DEVICE(s), "refclk", NULL, NULL, 0); |
43 | DEF_HELPER_2(dc_zva, void, env, i64) | ||
44 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/arm/crypto_helper.c | ||
47 | +++ b/target/arm/crypto_helper.c | ||
48 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, | ||
49 | rd[0] = d.l[0]; | ||
50 | rd[1] = d.l[1]; | ||
51 | } | 66 | } |
52 | + | 67 | |
53 | +static uint8_t const sm4_sbox[] = { | 68 | static void stm32f100_soc_realize(DeviceState *dev_soc, Error **errp) |
54 | + 0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, | 69 | @@ -XXX,XX +XXX,XX @@ static void stm32f100_soc_realize(DeviceState *dev_soc, Error **errp) |
55 | + 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05, | 70 | |
56 | + 0x2b, 0x67, 0x9a, 0x76, 0x2a, 0xbe, 0x04, 0xc3, | 71 | MemoryRegion *system_memory = get_system_memory(); |
57 | + 0xaa, 0x44, 0x13, 0x26, 0x49, 0x86, 0x06, 0x99, | 72 | |
58 | + 0x9c, 0x42, 0x50, 0xf4, 0x91, 0xef, 0x98, 0x7a, | 73 | + /* |
59 | + 0x33, 0x54, 0x0b, 0x43, 0xed, 0xcf, 0xac, 0x62, | 74 | + * We use s->refclk internally and only define it with qdev_init_clock_in() |
60 | + 0xe4, 0xb3, 0x1c, 0xa9, 0xc9, 0x08, 0xe8, 0x95, | 75 | + * so it is correctly parented and not leaked on an init/deinit; it is not |
61 | + 0x80, 0xdf, 0x94, 0xfa, 0x75, 0x8f, 0x3f, 0xa6, | 76 | + * intended as an externally exposed clock. |
62 | + 0x47, 0x07, 0xa7, 0xfc, 0xf3, 0x73, 0x17, 0xba, | 77 | + */ |
63 | + 0x83, 0x59, 0x3c, 0x19, 0xe6, 0x85, 0x4f, 0xa8, | 78 | + if (clock_has_source(s->refclk)) { |
64 | + 0x68, 0x6b, 0x81, 0xb2, 0x71, 0x64, 0xda, 0x8b, | 79 | + error_setg(errp, "refclk clock must not be wired up by the board code"); |
65 | + 0xf8, 0xeb, 0x0f, 0x4b, 0x70, 0x56, 0x9d, 0x35, | 80 | + return; |
66 | + 0x1e, 0x24, 0x0e, 0x5e, 0x63, 0x58, 0xd1, 0xa2, | ||
67 | + 0x25, 0x22, 0x7c, 0x3b, 0x01, 0x21, 0x78, 0x87, | ||
68 | + 0xd4, 0x00, 0x46, 0x57, 0x9f, 0xd3, 0x27, 0x52, | ||
69 | + 0x4c, 0x36, 0x02, 0xe7, 0xa0, 0xc4, 0xc8, 0x9e, | ||
70 | + 0xea, 0xbf, 0x8a, 0xd2, 0x40, 0xc7, 0x38, 0xb5, | ||
71 | + 0xa3, 0xf7, 0xf2, 0xce, 0xf9, 0x61, 0x15, 0xa1, | ||
72 | + 0xe0, 0xae, 0x5d, 0xa4, 0x9b, 0x34, 0x1a, 0x55, | ||
73 | + 0xad, 0x93, 0x32, 0x30, 0xf5, 0x8c, 0xb1, 0xe3, | ||
74 | + 0x1d, 0xf6, 0xe2, 0x2e, 0x82, 0x66, 0xca, 0x60, | ||
75 | + 0xc0, 0x29, 0x23, 0xab, 0x0d, 0x53, 0x4e, 0x6f, | ||
76 | + 0xd5, 0xdb, 0x37, 0x45, 0xde, 0xfd, 0x8e, 0x2f, | ||
77 | + 0x03, 0xff, 0x6a, 0x72, 0x6d, 0x6c, 0x5b, 0x51, | ||
78 | + 0x8d, 0x1b, 0xaf, 0x92, 0xbb, 0xdd, 0xbc, 0x7f, | ||
79 | + 0x11, 0xd9, 0x5c, 0x41, 0x1f, 0x10, 0x5a, 0xd8, | ||
80 | + 0x0a, 0xc1, 0x31, 0x88, 0xa5, 0xcd, 0x7b, 0xbd, | ||
81 | + 0x2d, 0x74, 0xd0, 0x12, 0xb8, 0xe5, 0xb4, 0xb0, | ||
82 | + 0x89, 0x69, 0x97, 0x4a, 0x0c, 0x96, 0x77, 0x7e, | ||
83 | + 0x65, 0xb9, 0xf1, 0x09, 0xc5, 0x6e, 0xc6, 0x84, | ||
84 | + 0x18, 0xf0, 0x7d, 0xec, 0x3a, 0xdc, 0x4d, 0x20, | ||
85 | + 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48, | ||
86 | +}; | ||
87 | + | ||
88 | +void HELPER(crypto_sm4e)(void *vd, void *vn) | ||
89 | +{ | ||
90 | + uint64_t *rd = vd; | ||
91 | + uint64_t *rn = vn; | ||
92 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
93 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
94 | + uint32_t t, i; | ||
95 | + | ||
96 | + for (i = 0; i < 4; i++) { | ||
97 | + t = CR_ST_WORD(d, (i + 1) % 4) ^ | ||
98 | + CR_ST_WORD(d, (i + 2) % 4) ^ | ||
99 | + CR_ST_WORD(d, (i + 3) % 4) ^ | ||
100 | + CR_ST_WORD(n, i); | ||
101 | + | ||
102 | + t = sm4_sbox[t & 0xff] | | ||
103 | + sm4_sbox[(t >> 8) & 0xff] << 8 | | ||
104 | + sm4_sbox[(t >> 16) & 0xff] << 16 | | ||
105 | + sm4_sbox[(t >> 24) & 0xff] << 24; | ||
106 | + | ||
107 | + CR_ST_WORD(d, i) ^= t ^ rol32(t, 2) ^ rol32(t, 10) ^ rol32(t, 18) ^ | ||
108 | + rol32(t, 24); | ||
109 | + } | 81 | + } |
110 | + | 82 | + |
111 | + rd[0] = d.l[0]; | 83 | + if (!clock_has_source(s->sysclk)) { |
112 | + rd[1] = d.l[1]; | 84 | + error_setg(errp, "sysclk clock must be wired up by the board code"); |
113 | +} | 85 | + return; |
114 | + | ||
115 | +void HELPER(crypto_sm4ekey)(void *vd, void *vn, void* vm) | ||
116 | +{ | ||
117 | + uint64_t *rd = vd; | ||
118 | + uint64_t *rn = vn; | ||
119 | + uint64_t *rm = vm; | ||
120 | + union CRYPTO_STATE d; | ||
121 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
122 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
123 | + uint32_t t, i; | ||
124 | + | ||
125 | + d = n; | ||
126 | + for (i = 0; i < 4; i++) { | ||
127 | + t = CR_ST_WORD(d, (i + 1) % 4) ^ | ||
128 | + CR_ST_WORD(d, (i + 2) % 4) ^ | ||
129 | + CR_ST_WORD(d, (i + 3) % 4) ^ | ||
130 | + CR_ST_WORD(m, i); | ||
131 | + | ||
132 | + t = sm4_sbox[t & 0xff] | | ||
133 | + sm4_sbox[(t >> 8) & 0xff] << 8 | | ||
134 | + sm4_sbox[(t >> 16) & 0xff] << 16 | | ||
135 | + sm4_sbox[(t >> 24) & 0xff] << 24; | ||
136 | + | ||
137 | + CR_ST_WORD(d, i) ^= t ^ rol32(t, 13) ^ rol32(t, 23); | ||
138 | + } | 86 | + } |
139 | + | 87 | + |
140 | + rd[0] = d.l[0]; | 88 | + /* |
141 | + rd[1] = d.l[1]; | 89 | + * TODO: ideally we should model the SoC RCC and its ability to |
142 | +} | 90 | + * change the sysclk frequency and define different sysclk sources. |
143 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 91 | + */ |
92 | + | ||
93 | + /* The refclk always runs at frequency HCLK / 8 */ | ||
94 | + clock_set_mul_div(s->refclk, 8, 1); | ||
95 | + clock_set_source(s->refclk, s->sysclk); | ||
96 | + | ||
97 | /* | ||
98 | * Init flash region | ||
99 | * Flash starts at 0x08000000 and then is aliased to boot memory at 0x0 | ||
100 | @@ -XXX,XX +XXX,XX @@ static void stm32f100_soc_realize(DeviceState *dev_soc, Error **errp) | ||
101 | qdev_prop_set_uint32(armv7m, "num-irq", 61); | ||
102 | qdev_prop_set_string(armv7m, "cpu-type", s->cpu_type); | ||
103 | qdev_prop_set_bit(armv7m, "enable-bitband", true); | ||
104 | + qdev_connect_clock_in(armv7m, "cpuclk", s->sysclk); | ||
105 | + qdev_connect_clock_in(armv7m, "refclk", s->refclk); | ||
106 | object_property_set_link(OBJECT(&s->armv7m), "memory", | ||
107 | OBJECT(get_system_memory()), &error_abort); | ||
108 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->armv7m), errp)) { | ||
109 | diff --git a/hw/arm/stm32vldiscovery.c b/hw/arm/stm32vldiscovery.c | ||
144 | index XXXXXXX..XXXXXXX 100644 | 110 | index XXXXXXX..XXXXXXX 100644 |
145 | --- a/target/arm/translate-a64.c | 111 | --- a/hw/arm/stm32vldiscovery.c |
146 | +++ b/target/arm/translate-a64.c | 112 | +++ b/hw/arm/stm32vldiscovery.c |
147 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 113 | @@ -XXX,XX +XXX,XX @@ |
148 | feature = ARM_FEATURE_V8_SM3; | 114 | #include "qapi/error.h" |
149 | genfn = gen_helper_crypto_sm3partw2; | 115 | #include "hw/boards.h" |
150 | break; | 116 | #include "hw/qdev-properties.h" |
151 | + case 2: /* SM4EKEY */ | 117 | +#include "hw/qdev-clock.h" |
152 | + feature = ARM_FEATURE_V8_SM4; | 118 | #include "qemu/error-report.h" |
153 | + genfn = gen_helper_crypto_sm4ekey; | 119 | #include "hw/arm/stm32f100_soc.h" |
154 | + break; | 120 | #include "hw/arm/boot.h" |
155 | default: | 121 | @@ -XXX,XX +XXX,XX @@ |
156 | unallocated_encoding(s); | 122 | static void stm32vldiscovery_init(MachineState *machine) |
157 | return; | 123 | { |
158 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | 124 | DeviceState *dev; |
159 | feature = ARM_FEATURE_V8_SHA512; | 125 | + Clock *sysclk; |
160 | genfn = gen_helper_crypto_sha512su0; | 126 | |
161 | break; | 127 | - /* |
162 | + case 1: /* SM4E */ | 128 | - * TODO: ideally we would model the SoC RCC and let it handle |
163 | + feature = ARM_FEATURE_V8_SM4; | 129 | - * system_clock_scale, including its ability to define different |
164 | + genfn = gen_helper_crypto_sm4e; | 130 | - * possible SYSCLK sources. |
165 | + break; | 131 | - */ |
166 | default: | 132 | system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; |
167 | unallocated_encoding(s); | 133 | |
168 | return; | 134 | + /* This clock doesn't need migration because it is fixed-frequency */ |
135 | + sysclk = clock_new(OBJECT(machine), "SYSCLK"); | ||
136 | + clock_set_hz(sysclk, SYSCLK_FRQ); | ||
137 | + | ||
138 | dev = qdev_new(TYPE_STM32F100_SOC); | ||
139 | qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m3")); | ||
140 | + qdev_connect_clock_in(dev, "sysclk", sysclk); | ||
141 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); | ||
142 | |||
143 | armv7m_load_kernel(ARM_CPU(first_cpu), | ||
169 | -- | 144 | -- |
170 | 2.16.1 | 145 | 2.20.1 |
171 | 146 | ||
172 | 147 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | Wire up the sysclk and refclk for the stm32f205 SoC. This SoC always |
---|---|---|---|
2 | runs the systick refclk at 1/8 the frequency of the main CPU clock, | ||
3 | so the board code only needs to provide a single sysclk clock. | ||
2 | 4 | ||
3 | This implements emulation of the new SM3 instructions that have | 5 | Because there is only one board using this SoC, we convert the SoC |
4 | been added as an optional extension to the ARMv8 Crypto Extensions | 6 | and the board together, rather than splitting it into "add clock to |
5 | in ARM v8.2. | 7 | SoC; connect clock in board; add error check in SoC code that clock |
8 | is wired up". | ||
6 | 9 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 10 | When the systick device starts honouring its clock inputs, this will |
8 | Message-id: 20180207111729.15737-4-ard.biesheuvel@linaro.org | 11 | fix an emulation inaccuracy in the netduino2 board where the systick |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 12 | reference clock was running at 1MHz rather than 15MHz. |
13 | |||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
17 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
18 | Message-id: 20210812093356.1946-13-peter.maydell@linaro.org | ||
11 | --- | 19 | --- |
12 | target/arm/cpu.h | 1 + | 20 | include/hw/arm/stm32f205_soc.h | 4 ++++ |
13 | target/arm/helper.h | 4 ++ | 21 | hw/arm/netduino2.c | 12 +++++++----- |
14 | target/arm/crypto_helper.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++ | 22 | hw/arm/stm32f205_soc.c | 30 ++++++++++++++++++++++++++++++ |
15 | target/arm/translate-a64.c | 88 ++++++++++++++++++++++++++++++++++++++++-- | 23 | 3 files changed, 41 insertions(+), 5 deletions(-) |
16 | 4 files changed, 186 insertions(+), 3 deletions(-) | ||
17 | 24 | ||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 25 | diff --git a/include/hw/arm/stm32f205_soc.h b/include/hw/arm/stm32f205_soc.h |
19 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/target/arm/cpu.h | 27 | --- a/include/hw/arm/stm32f205_soc.h |
21 | +++ b/target/arm/cpu.h | 28 | +++ b/include/hw/arm/stm32f205_soc.h |
22 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 29 | @@ -XXX,XX +XXX,XX @@ |
23 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | 30 | #include "hw/or-irq.h" |
24 | ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | 31 | #include "hw/ssi/stm32f2xx_spi.h" |
25 | ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | 32 | #include "hw/arm/armv7m.h" |
26 | + ARM_FEATURE_V8_SM3, /* implements SM3 part of v8 Crypto Extensions */ | 33 | +#include "hw/clock.h" |
34 | #include "qom/object.h" | ||
35 | |||
36 | #define TYPE_STM32F205_SOC "stm32f205-soc" | ||
37 | @@ -XXX,XX +XXX,XX @@ struct STM32F205State { | ||
38 | MemoryRegion sram; | ||
39 | MemoryRegion flash; | ||
40 | MemoryRegion flash_alias; | ||
41 | + | ||
42 | + Clock *sysclk; | ||
43 | + Clock *refclk; | ||
27 | }; | 44 | }; |
28 | 45 | ||
29 | static inline int arm_feature(CPUARMState *env, int feature) | 46 | #endif |
30 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 47 | diff --git a/hw/arm/netduino2.c b/hw/arm/netduino2.c |
31 | index XXXXXXX..XXXXXXX 100644 | 48 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/target/arm/helper.h | 49 | --- a/hw/arm/netduino2.c |
33 | +++ b/target/arm/helper.h | 50 | +++ b/hw/arm/netduino2.c |
34 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 51 | @@ -XXX,XX +XXX,XX @@ |
35 | DEF_HELPER_FLAGS_2(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr) | 52 | #include "qapi/error.h" |
36 | DEF_HELPER_FLAGS_3(crypto_sha512su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 53 | #include "hw/boards.h" |
37 | 54 | #include "hw/qdev-properties.h" | |
38 | +DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) | 55 | +#include "hw/qdev-clock.h" |
39 | +DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 56 | #include "qemu/error-report.h" |
40 | +DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 57 | #include "hw/arm/stm32f205_soc.h" |
58 | #include "hw/arm/boot.h" | ||
59 | @@ -XXX,XX +XXX,XX @@ | ||
60 | static void netduino2_init(MachineState *machine) | ||
61 | { | ||
62 | DeviceState *dev; | ||
63 | + Clock *sysclk; | ||
64 | |||
65 | - /* | ||
66 | - * TODO: ideally we would model the SoC RCC and let it handle | ||
67 | - * system_clock_scale, including its ability to define different | ||
68 | - * possible SYSCLK sources. | ||
69 | - */ | ||
70 | system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; | ||
71 | |||
72 | + /* This clock doesn't need migration because it is fixed-frequency */ | ||
73 | + sysclk = clock_new(OBJECT(machine), "SYSCLK"); | ||
74 | + clock_set_hz(sysclk, SYSCLK_FRQ); | ||
41 | + | 75 | + |
42 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 76 | dev = qdev_new(TYPE_STM32F205_SOC); |
43 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 77 | qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m3")); |
44 | DEF_HELPER_2(dc_zva, void, env, i64) | 78 | + qdev_connect_clock_in(dev, "sysclk", sysclk); |
45 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | 79 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
80 | |||
81 | armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, | ||
82 | diff --git a/hw/arm/stm32f205_soc.c b/hw/arm/stm32f205_soc.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | 83 | index XXXXXXX..XXXXXXX 100644 |
47 | --- a/target/arm/crypto_helper.c | 84 | --- a/hw/arm/stm32f205_soc.c |
48 | +++ b/target/arm/crypto_helper.c | 85 | +++ b/hw/arm/stm32f205_soc.c |
49 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm) | 86 | @@ -XXX,XX +XXX,XX @@ |
50 | rd[0] += s1_512(rn[0]) + rm[0]; | 87 | #include "exec/address-spaces.h" |
51 | rd[1] += s1_512(rn[1]) + rm[1]; | 88 | #include "hw/arm/stm32f205_soc.h" |
89 | #include "hw/qdev-properties.h" | ||
90 | +#include "hw/qdev-clock.h" | ||
91 | #include "sysemu/sysemu.h" | ||
92 | |||
93 | /* At the moment only Timer 2 to 5 are modelled */ | ||
94 | @@ -XXX,XX +XXX,XX @@ static void stm32f205_soc_initfn(Object *obj) | ||
95 | for (i = 0; i < STM_NUM_SPIS; i++) { | ||
96 | object_initialize_child(obj, "spi[*]", &s->spi[i], TYPE_STM32F2XX_SPI); | ||
97 | } | ||
98 | + | ||
99 | + s->sysclk = qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0); | ||
100 | + s->refclk = qdev_init_clock_in(DEVICE(s), "refclk", NULL, NULL, 0); | ||
52 | } | 101 | } |
53 | + | 102 | |
54 | +void HELPER(crypto_sm3partw1)(void *vd, void *vn, void *vm) | 103 | static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp) |
55 | +{ | 104 | @@ -XXX,XX +XXX,XX @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp) |
56 | + uint64_t *rd = vd; | 105 | |
57 | + uint64_t *rn = vn; | 106 | MemoryRegion *system_memory = get_system_memory(); |
58 | + uint64_t *rm = vm; | 107 | |
59 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | 108 | + /* |
60 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | 109 | + * We use s->refclk internally and only define it with qdev_init_clock_in() |
61 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | 110 | + * so it is correctly parented and not leaked on an init/deinit; it is not |
62 | + uint32_t t; | 111 | + * intended as an externally exposed clock. |
63 | + | 112 | + */ |
64 | + t = CR_ST_WORD(d, 0) ^ CR_ST_WORD(n, 0) ^ ror32(CR_ST_WORD(m, 1), 17); | 113 | + if (clock_has_source(s->refclk)) { |
65 | + CR_ST_WORD(d, 0) = t ^ ror32(t, 17) ^ ror32(t, 9); | 114 | + error_setg(errp, "refclk clock must not be wired up by the board code"); |
66 | + | ||
67 | + t = CR_ST_WORD(d, 1) ^ CR_ST_WORD(n, 1) ^ ror32(CR_ST_WORD(m, 2), 17); | ||
68 | + CR_ST_WORD(d, 1) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
69 | + | ||
70 | + t = CR_ST_WORD(d, 2) ^ CR_ST_WORD(n, 2) ^ ror32(CR_ST_WORD(m, 3), 17); | ||
71 | + CR_ST_WORD(d, 2) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
72 | + | ||
73 | + t = CR_ST_WORD(d, 3) ^ CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(d, 0), 17); | ||
74 | + CR_ST_WORD(d, 3) = t ^ ror32(t, 17) ^ ror32(t, 9); | ||
75 | + | ||
76 | + rd[0] = d.l[0]; | ||
77 | + rd[1] = d.l[1]; | ||
78 | +} | ||
79 | + | ||
80 | +void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm) | ||
81 | +{ | ||
82 | + uint64_t *rd = vd; | ||
83 | + uint64_t *rn = vn; | ||
84 | + uint64_t *rm = vm; | ||
85 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
86 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
87 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
88 | + uint32_t t = CR_ST_WORD(n, 0) ^ ror32(CR_ST_WORD(m, 0), 25); | ||
89 | + | ||
90 | + CR_ST_WORD(d, 0) ^= t; | ||
91 | + CR_ST_WORD(d, 1) ^= CR_ST_WORD(n, 1) ^ ror32(CR_ST_WORD(m, 1), 25); | ||
92 | + CR_ST_WORD(d, 2) ^= CR_ST_WORD(n, 2) ^ ror32(CR_ST_WORD(m, 2), 25); | ||
93 | + CR_ST_WORD(d, 3) ^= CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(m, 3), 25) ^ | ||
94 | + ror32(t, 17) ^ ror32(t, 2) ^ ror32(t, 26); | ||
95 | + | ||
96 | + rd[0] = d.l[0]; | ||
97 | + rd[1] = d.l[1]; | ||
98 | +} | ||
99 | + | ||
100 | +void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, | ||
101 | + uint32_t opcode) | ||
102 | +{ | ||
103 | + uint64_t *rd = vd; | ||
104 | + uint64_t *rn = vn; | ||
105 | + uint64_t *rm = vm; | ||
106 | + union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
107 | + union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
108 | + union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
109 | + uint32_t t; | ||
110 | + | ||
111 | + assert(imm2 < 4); | ||
112 | + | ||
113 | + if (opcode == 0 || opcode == 2) { | ||
114 | + /* SM3TT1A, SM3TT2A */ | ||
115 | + t = par(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); | ||
116 | + } else if (opcode == 1) { | ||
117 | + /* SM3TT1B */ | ||
118 | + t = maj(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); | ||
119 | + } else if (opcode == 3) { | ||
120 | + /* SM3TT2B */ | ||
121 | + t = cho(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); | ||
122 | + } else { | ||
123 | + g_assert_not_reached(); | ||
124 | + } | ||
125 | + | ||
126 | + t += CR_ST_WORD(d, 0) + CR_ST_WORD(m, imm2); | ||
127 | + | ||
128 | + CR_ST_WORD(d, 0) = CR_ST_WORD(d, 1); | ||
129 | + | ||
130 | + if (opcode < 2) { | ||
131 | + /* SM3TT1A, SM3TT1B */ | ||
132 | + t += CR_ST_WORD(n, 3) ^ ror32(CR_ST_WORD(d, 3), 20); | ||
133 | + | ||
134 | + CR_ST_WORD(d, 1) = ror32(CR_ST_WORD(d, 2), 23); | ||
135 | + } else { | ||
136 | + /* SM3TT2A, SM3TT2B */ | ||
137 | + t += CR_ST_WORD(n, 3); | ||
138 | + t ^= rol32(t, 9) ^ rol32(t, 17); | ||
139 | + | ||
140 | + CR_ST_WORD(d, 1) = ror32(CR_ST_WORD(d, 2), 13); | ||
141 | + } | ||
142 | + | ||
143 | + CR_ST_WORD(d, 2) = CR_ST_WORD(d, 3); | ||
144 | + CR_ST_WORD(d, 3) = t; | ||
145 | + | ||
146 | + rd[0] = d.l[0]; | ||
147 | + rd[1] = d.l[1]; | ||
148 | +} | ||
149 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
150 | index XXXXXXX..XXXXXXX 100644 | ||
151 | --- a/target/arm/translate-a64.c | ||
152 | +++ b/target/arm/translate-a64.c | ||
153 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
154 | break; | ||
155 | } | ||
156 | } else { | ||
157 | - unallocated_encoding(s); | ||
158 | - return; | ||
159 | + switch (opcode) { | ||
160 | + case 0: /* SM3PARTW1 */ | ||
161 | + feature = ARM_FEATURE_V8_SM3; | ||
162 | + genfn = gen_helper_crypto_sm3partw1; | ||
163 | + break; | ||
164 | + case 1: /* SM3PARTW2 */ | ||
165 | + feature = ARM_FEATURE_V8_SM3; | ||
166 | + genfn = gen_helper_crypto_sm3partw2; | ||
167 | + break; | ||
168 | + default: | ||
169 | + unallocated_encoding(s); | ||
170 | + return; | ||
171 | + } | ||
172 | } | ||
173 | |||
174 | if (!arm_dc_feature(s, feature)) { | ||
175 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) | ||
176 | case 1: /* BCAX */ | ||
177 | feature = ARM_FEATURE_V8_SHA3; | ||
178 | break; | ||
179 | + case 2: /* SM3SS1 */ | ||
180 | + feature = ARM_FEATURE_V8_SM3; | ||
181 | + break; | ||
182 | default: | ||
183 | unallocated_encoding(s); | ||
184 | return; | ||
185 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) | ||
186 | tcg_temp_free_i64(tcg_res[0]); | ||
187 | tcg_temp_free_i64(tcg_res[1]); | ||
188 | } else { | ||
189 | - g_assert_not_reached(); | ||
190 | + TCGv_i32 tcg_op1, tcg_op2, tcg_op3, tcg_res, tcg_zero; | ||
191 | + | ||
192 | + tcg_op1 = tcg_temp_new_i32(); | ||
193 | + tcg_op2 = tcg_temp_new_i32(); | ||
194 | + tcg_op3 = tcg_temp_new_i32(); | ||
195 | + tcg_res = tcg_temp_new_i32(); | ||
196 | + tcg_zero = tcg_const_i32(0); | ||
197 | + | ||
198 | + read_vec_element_i32(s, tcg_op1, rn, 3, MO_32); | ||
199 | + read_vec_element_i32(s, tcg_op2, rm, 3, MO_32); | ||
200 | + read_vec_element_i32(s, tcg_op3, ra, 3, MO_32); | ||
201 | + | ||
202 | + tcg_gen_rotri_i32(tcg_res, tcg_op1, 20); | ||
203 | + tcg_gen_add_i32(tcg_res, tcg_res, tcg_op2); | ||
204 | + tcg_gen_add_i32(tcg_res, tcg_res, tcg_op3); | ||
205 | + tcg_gen_rotri_i32(tcg_res, tcg_res, 25); | ||
206 | + | ||
207 | + write_vec_element_i32(s, tcg_zero, rd, 0, MO_32); | ||
208 | + write_vec_element_i32(s, tcg_zero, rd, 1, MO_32); | ||
209 | + write_vec_element_i32(s, tcg_zero, rd, 2, MO_32); | ||
210 | + write_vec_element_i32(s, tcg_res, rd, 3, MO_32); | ||
211 | + | ||
212 | + tcg_temp_free_i32(tcg_op1); | ||
213 | + tcg_temp_free_i32(tcg_op2); | ||
214 | + tcg_temp_free_i32(tcg_op3); | ||
215 | + tcg_temp_free_i32(tcg_res); | ||
216 | + tcg_temp_free_i32(tcg_zero); | ||
217 | } | ||
218 | } | ||
219 | |||
220 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_xar(DisasContext *s, uint32_t insn) | ||
221 | tcg_temp_free_i64(tcg_res[1]); | ||
222 | } | ||
223 | |||
224 | +/* Crypto three-reg imm2 | ||
225 | + * 31 21 20 16 15 14 13 12 11 10 9 5 4 0 | ||
226 | + * +-----------------------+------+-----+------+--------+------+------+ | ||
227 | + * | 1 1 0 0 1 1 1 0 0 1 0 | Rm | 1 0 | imm2 | opcode | Rn | Rd | | ||
228 | + * +-----------------------+------+-----+------+--------+------+------+ | ||
229 | + */ | ||
230 | +static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn) | ||
231 | +{ | ||
232 | + int opcode = extract32(insn, 10, 2); | ||
233 | + int imm2 = extract32(insn, 12, 2); | ||
234 | + int rm = extract32(insn, 16, 5); | ||
235 | + int rn = extract32(insn, 5, 5); | ||
236 | + int rd = extract32(insn, 0, 5); | ||
237 | + TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | ||
238 | + TCGv_i32 tcg_imm2, tcg_opcode; | ||
239 | + | ||
240 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_SM3)) { | ||
241 | + unallocated_encoding(s); | ||
242 | + return; | 115 | + return; |
243 | + } | 116 | + } |
244 | + | 117 | + |
245 | + if (!fp_access_check(s)) { | 118 | + if (!clock_has_source(s->sysclk)) { |
119 | + error_setg(errp, "sysclk clock must be wired up by the board code"); | ||
246 | + return; | 120 | + return; |
247 | + } | 121 | + } |
248 | + | 122 | + |
249 | + tcg_rd_ptr = vec_full_reg_ptr(s, rd); | 123 | + /* |
250 | + tcg_rn_ptr = vec_full_reg_ptr(s, rn); | 124 | + * TODO: ideally we should model the SoC RCC and its ability to |
251 | + tcg_rm_ptr = vec_full_reg_ptr(s, rm); | 125 | + * change the sysclk frequency and define different sysclk sources. |
252 | + tcg_imm2 = tcg_const_i32(imm2); | 126 | + */ |
253 | + tcg_opcode = tcg_const_i32(opcode); | ||
254 | + | 127 | + |
255 | + gen_helper_crypto_sm3tt(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr, tcg_imm2, | 128 | + /* The refclk always runs at frequency HCLK / 8 */ |
256 | + tcg_opcode); | 129 | + clock_set_mul_div(s->refclk, 8, 1); |
130 | + clock_set_source(s->refclk, s->sysclk); | ||
257 | + | 131 | + |
258 | + tcg_temp_free_ptr(tcg_rd_ptr); | 132 | memory_region_init_rom(&s->flash, OBJECT(dev_soc), "STM32F205.flash", |
259 | + tcg_temp_free_ptr(tcg_rn_ptr); | 133 | FLASH_SIZE, &error_fatal); |
260 | + tcg_temp_free_ptr(tcg_rm_ptr); | 134 | memory_region_init_alias(&s->flash_alias, OBJECT(dev_soc), |
261 | + tcg_temp_free_i32(tcg_imm2); | 135 | @@ -XXX,XX +XXX,XX @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp) |
262 | + tcg_temp_free_i32(tcg_opcode); | 136 | qdev_prop_set_uint32(armv7m, "num-irq", 96); |
263 | +} | 137 | qdev_prop_set_string(armv7m, "cpu-type", s->cpu_type); |
264 | + | 138 | qdev_prop_set_bit(armv7m, "enable-bitband", true); |
265 | /* C3.6 Data processing - SIMD, inc Crypto | 139 | + qdev_connect_clock_in(armv7m, "cpuclk", s->sysclk); |
266 | * | 140 | + qdev_connect_clock_in(armv7m, "refclk", s->refclk); |
267 | * As the decode gets a little complex we are using a table based | 141 | object_property_set_link(OBJECT(&s->armv7m), "memory", |
268 | @@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = { | 142 | OBJECT(get_system_memory()), &error_abort); |
269 | { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, | 143 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->armv7m), errp)) { |
270 | { 0xce000000, 0xff808000, disas_crypto_four_reg }, | ||
271 | { 0xce800000, 0xffe00000, disas_crypto_xar }, | ||
272 | + { 0xce408000, 0xffe0c000, disas_crypto_three_reg_imm2 }, | ||
273 | { 0x00000000, 0x00000000, NULL } | ||
274 | }; | ||
275 | |||
276 | -- | 144 | -- |
277 | 2.16.1 | 145 | 2.20.1 |
278 | 146 | ||
279 | 147 | diff view generated by jsdifflib |
1 | From: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 1 | Wire up the sysclk and refclk for the stm32f405 SoC. This SoC always |
---|---|---|---|
2 | runs the systick refclk at 1/8 the frequency of the main CPU clock, | ||
3 | so the board code only needs to provide a single sysclk clock. | ||
2 | 4 | ||
3 | This implements emulation of the new SHA-3 instructions that have | 5 | Because there is only one board using this SoC, we convert the SoC |
4 | been added as an optional extensions to the ARMv8 Crypto Extensions | 6 | and the board together, rather than splitting it into "add clock to |
5 | in ARM v8.2. | 7 | SoC; connect clock in board; add error check in SoC code that clock |
8 | is wired up". | ||
6 | 9 | ||
7 | Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> | 10 | When the systick device starts honouring its clock inputs, this will |
8 | Message-id: 20180207111729.15737-3-ard.biesheuvel@linaro.org | 11 | fix an emulation inaccuracy in the netduinoplus2 board where the |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 12 | systick reference clock was running at 1MHz rather than 21MHz. |
13 | |||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
17 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
18 | Message-id: 20210812093356.1946-14-peter.maydell@linaro.org | ||
11 | --- | 19 | --- |
12 | target/arm/cpu.h | 1 + | 20 | include/hw/arm/stm32f405_soc.h | 3 +++ |
13 | target/arm/translate-a64.c | 148 +++++++++++++++++++++++++++++++++++++++++++-- | 21 | hw/arm/netduinoplus2.c | 12 +++++++----- |
14 | 2 files changed, 145 insertions(+), 4 deletions(-) | 22 | hw/arm/stm32f405_soc.c | 30 ++++++++++++++++++++++++++++++ |
23 | 3 files changed, 40 insertions(+), 5 deletions(-) | ||
15 | 24 | ||
16 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 25 | diff --git a/include/hw/arm/stm32f405_soc.h b/include/hw/arm/stm32f405_soc.h |
17 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/cpu.h | 27 | --- a/include/hw/arm/stm32f405_soc.h |
19 | +++ b/target/arm/cpu.h | 28 | +++ b/include/hw/arm/stm32f405_soc.h |
20 | @@ -XXX,XX +XXX,XX @@ enum arm_features { | 29 | @@ -XXX,XX +XXX,XX @@ struct STM32F405State { |
21 | ARM_FEATURE_JAZELLE, /* has (trivial) Jazelle implementation */ | 30 | MemoryRegion sram; |
22 | ARM_FEATURE_SVE, /* has Scalable Vector Extension */ | 31 | MemoryRegion flash; |
23 | ARM_FEATURE_V8_SHA512, /* implements SHA512 part of v8 Crypto Extensions */ | 32 | MemoryRegion flash_alias; |
24 | + ARM_FEATURE_V8_SHA3, /* implements SHA3 part of v8 Crypto Extensions */ | 33 | + |
34 | + Clock *sysclk; | ||
35 | + Clock *refclk; | ||
25 | }; | 36 | }; |
26 | 37 | ||
27 | static inline int arm_feature(CPUARMState *env, int feature) | 38 | #endif |
28 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 39 | diff --git a/hw/arm/netduinoplus2.c b/hw/arm/netduinoplus2.c |
29 | index XXXXXXX..XXXXXXX 100644 | 40 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/translate-a64.c | 41 | --- a/hw/arm/netduinoplus2.c |
31 | +++ b/target/arm/translate-a64.c | 42 | +++ b/hw/arm/netduinoplus2.c |
32 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 43 | @@ -XXX,XX +XXX,XX @@ |
33 | feature = ARM_FEATURE_V8_SHA512; | 44 | #include "qapi/error.h" |
34 | genfn = gen_helper_crypto_sha512su1; | 45 | #include "hw/boards.h" |
35 | break; | 46 | #include "hw/qdev-properties.h" |
36 | - default: | 47 | +#include "hw/qdev-clock.h" |
37 | - unallocated_encoding(s); | 48 | #include "qemu/error-report.h" |
38 | - return; | 49 | #include "hw/arm/stm32f405_soc.h" |
39 | + case 3: /* RAX1 */ | 50 | #include "hw/arm/boot.h" |
40 | + feature = ARM_FEATURE_V8_SHA3; | 51 | @@ -XXX,XX +XXX,XX @@ |
41 | + genfn = NULL; | 52 | static void netduinoplus2_init(MachineState *machine) |
42 | + break; | 53 | { |
43 | } | 54 | DeviceState *dev; |
44 | } else { | 55 | + Clock *sysclk; |
45 | unallocated_encoding(s); | 56 | |
46 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 57 | - /* |
47 | tcg_temp_free_ptr(tcg_rn_ptr); | 58 | - * TODO: ideally we would model the SoC RCC and let it handle |
48 | tcg_temp_free_ptr(tcg_rm_ptr); | 59 | - * system_clock_scale, including its ability to define different |
49 | } else { | 60 | - * possible SYSCLK sources. |
50 | - g_assert_not_reached(); | 61 | - */ |
51 | + TCGv_i64 tcg_op1, tcg_op2, tcg_res[2]; | 62 | system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; |
52 | + int pass; | 63 | |
64 | + /* This clock doesn't need migration because it is fixed-frequency */ | ||
65 | + sysclk = clock_new(OBJECT(machine), "SYSCLK"); | ||
66 | + clock_set_hz(sysclk, SYSCLK_FRQ); | ||
53 | + | 67 | + |
54 | + tcg_op1 = tcg_temp_new_i64(); | 68 | dev = qdev_new(TYPE_STM32F405_SOC); |
55 | + tcg_op2 = tcg_temp_new_i64(); | 69 | qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m4")); |
56 | + tcg_res[0] = tcg_temp_new_i64(); | 70 | + qdev_connect_clock_in(dev, "sysclk", sysclk); |
57 | + tcg_res[1] = tcg_temp_new_i64(); | 71 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
72 | |||
73 | armv7m_load_kernel(ARM_CPU(first_cpu), | ||
74 | diff --git a/hw/arm/stm32f405_soc.c b/hw/arm/stm32f405_soc.c | ||
75 | index XXXXXXX..XXXXXXX 100644 | ||
76 | --- a/hw/arm/stm32f405_soc.c | ||
77 | +++ b/hw/arm/stm32f405_soc.c | ||
78 | @@ -XXX,XX +XXX,XX @@ | ||
79 | #include "exec/address-spaces.h" | ||
80 | #include "sysemu/sysemu.h" | ||
81 | #include "hw/arm/stm32f405_soc.h" | ||
82 | +#include "hw/qdev-clock.h" | ||
83 | #include "hw/misc/unimp.h" | ||
84 | |||
85 | #define SYSCFG_ADD 0x40013800 | ||
86 | @@ -XXX,XX +XXX,XX @@ static void stm32f405_soc_initfn(Object *obj) | ||
87 | } | ||
88 | |||
89 | object_initialize_child(obj, "exti", &s->exti, TYPE_STM32F4XX_EXTI); | ||
58 | + | 90 | + |
59 | + for (pass = 0; pass < 2; pass++) { | 91 | + s->sysclk = qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0); |
60 | + read_vec_element(s, tcg_op1, rn, pass, MO_64); | 92 | + s->refclk = qdev_init_clock_in(DEVICE(s), "refclk", NULL, NULL, 0); |
61 | + read_vec_element(s, tcg_op2, rm, pass, MO_64); | ||
62 | + | ||
63 | + tcg_gen_rotli_i64(tcg_res[pass], tcg_op2, 1); | ||
64 | + tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1); | ||
65 | + } | ||
66 | + write_vec_element(s, tcg_res[0], rd, 0, MO_64); | ||
67 | + write_vec_element(s, tcg_res[1], rd, 1, MO_64); | ||
68 | + | ||
69 | + tcg_temp_free_i64(tcg_op1); | ||
70 | + tcg_temp_free_i64(tcg_op2); | ||
71 | + tcg_temp_free_i64(tcg_res[0]); | ||
72 | + tcg_temp_free_i64(tcg_res[1]); | ||
73 | } | ||
74 | } | 93 | } |
75 | 94 | ||
76 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | 95 | static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp) |
77 | tcg_temp_free_ptr(tcg_rn_ptr); | 96 | @@ -XXX,XX +XXX,XX @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp) |
78 | } | 97 | Error *err = NULL; |
79 | 98 | int i; | |
80 | +/* Crypto four-register | 99 | |
81 | + * 31 23 22 21 20 16 15 14 10 9 5 4 0 | 100 | + /* |
82 | + * +-------------------+-----+------+---+------+------+------+ | 101 | + * We use s->refclk internally and only define it with qdev_init_clock_in() |
83 | + * | 1 1 0 0 1 1 1 0 0 | Op0 | Rm | 0 | Ra | Rn | Rd | | 102 | + * so it is correctly parented and not leaked on an init/deinit; it is not |
84 | + * +-------------------+-----+------+---+------+------+------+ | 103 | + * intended as an externally exposed clock. |
85 | + */ | 104 | + */ |
86 | +static void disas_crypto_four_reg(DisasContext *s, uint32_t insn) | 105 | + if (clock_has_source(s->refclk)) { |
87 | +{ | 106 | + error_setg(errp, "refclk clock must not be wired up by the board code"); |
88 | + int op0 = extract32(insn, 21, 2); | ||
89 | + int rm = extract32(insn, 16, 5); | ||
90 | + int ra = extract32(insn, 10, 5); | ||
91 | + int rn = extract32(insn, 5, 5); | ||
92 | + int rd = extract32(insn, 0, 5); | ||
93 | + int feature; | ||
94 | + | ||
95 | + switch (op0) { | ||
96 | + case 0: /* EOR3 */ | ||
97 | + case 1: /* BCAX */ | ||
98 | + feature = ARM_FEATURE_V8_SHA3; | ||
99 | + break; | ||
100 | + default: | ||
101 | + unallocated_encoding(s); | ||
102 | + return; | 107 | + return; |
103 | + } | 108 | + } |
104 | + | 109 | + |
105 | + if (!arm_dc_feature(s, feature)) { | 110 | + if (!clock_has_source(s->sysclk)) { |
106 | + unallocated_encoding(s); | 111 | + error_setg(errp, "sysclk clock must be wired up by the board code"); |
107 | + return; | 112 | + return; |
108 | + } | 113 | + } |
109 | + | 114 | + |
110 | + if (!fp_access_check(s)) { | 115 | + /* |
111 | + return; | 116 | + * TODO: ideally we should model the SoC RCC and its ability to |
112 | + } | 117 | + * change the sysclk frequency and define different sysclk sources. |
118 | + */ | ||
113 | + | 119 | + |
114 | + if (op0 < 2) { | 120 | + /* The refclk always runs at frequency HCLK / 8 */ |
115 | + TCGv_i64 tcg_op1, tcg_op2, tcg_op3, tcg_res[2]; | 121 | + clock_set_mul_div(s->refclk, 8, 1); |
116 | + int pass; | 122 | + clock_set_source(s->refclk, s->sysclk); |
117 | + | 123 | + |
118 | + tcg_op1 = tcg_temp_new_i64(); | 124 | memory_region_init_rom(&s->flash, OBJECT(dev_soc), "STM32F405.flash", |
119 | + tcg_op2 = tcg_temp_new_i64(); | 125 | FLASH_SIZE, &err); |
120 | + tcg_op3 = tcg_temp_new_i64(); | 126 | if (err != NULL) { |
121 | + tcg_res[0] = tcg_temp_new_i64(); | 127 | @@ -XXX,XX +XXX,XX @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp) |
122 | + tcg_res[1] = tcg_temp_new_i64(); | 128 | qdev_prop_set_uint32(armv7m, "num-irq", 96); |
123 | + | 129 | qdev_prop_set_string(armv7m, "cpu-type", s->cpu_type); |
124 | + for (pass = 0; pass < 2; pass++) { | 130 | qdev_prop_set_bit(armv7m, "enable-bitband", true); |
125 | + read_vec_element(s, tcg_op1, rn, pass, MO_64); | 131 | + qdev_connect_clock_in(armv7m, "cpuclk", s->sysclk); |
126 | + read_vec_element(s, tcg_op2, rm, pass, MO_64); | 132 | + qdev_connect_clock_in(armv7m, "refclk", s->refclk); |
127 | + read_vec_element(s, tcg_op3, ra, pass, MO_64); | 133 | object_property_set_link(OBJECT(&s->armv7m), "memory", |
128 | + | 134 | OBJECT(system_memory), &error_abort); |
129 | + if (op0 == 0) { | 135 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->armv7m), errp)) { |
130 | + /* EOR3 */ | ||
131 | + tcg_gen_xor_i64(tcg_res[pass], tcg_op2, tcg_op3); | ||
132 | + } else { | ||
133 | + /* BCAX */ | ||
134 | + tcg_gen_andc_i64(tcg_res[pass], tcg_op2, tcg_op3); | ||
135 | + } | ||
136 | + tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1); | ||
137 | + } | ||
138 | + write_vec_element(s, tcg_res[0], rd, 0, MO_64); | ||
139 | + write_vec_element(s, tcg_res[1], rd, 1, MO_64); | ||
140 | + | ||
141 | + tcg_temp_free_i64(tcg_op1); | ||
142 | + tcg_temp_free_i64(tcg_op2); | ||
143 | + tcg_temp_free_i64(tcg_op3); | ||
144 | + tcg_temp_free_i64(tcg_res[0]); | ||
145 | + tcg_temp_free_i64(tcg_res[1]); | ||
146 | + } else { | ||
147 | + g_assert_not_reached(); | ||
148 | + } | ||
149 | +} | ||
150 | + | ||
151 | +/* Crypto XAR | ||
152 | + * 31 21 20 16 15 10 9 5 4 0 | ||
153 | + * +-----------------------+------+--------+------+------+ | ||
154 | + * | 1 1 0 0 1 1 1 0 1 0 0 | Rm | imm6 | Rn | Rd | | ||
155 | + * +-----------------------+------+--------+------+------+ | ||
156 | + */ | ||
157 | +static void disas_crypto_xar(DisasContext *s, uint32_t insn) | ||
158 | +{ | ||
159 | + int rm = extract32(insn, 16, 5); | ||
160 | + int imm6 = extract32(insn, 10, 6); | ||
161 | + int rn = extract32(insn, 5, 5); | ||
162 | + int rd = extract32(insn, 0, 5); | ||
163 | + TCGv_i64 tcg_op1, tcg_op2, tcg_res[2]; | ||
164 | + int pass; | ||
165 | + | ||
166 | + if (!arm_dc_feature(s, ARM_FEATURE_V8_SHA3)) { | ||
167 | + unallocated_encoding(s); | ||
168 | + return; | ||
169 | + } | ||
170 | + | ||
171 | + if (!fp_access_check(s)) { | ||
172 | + return; | ||
173 | + } | ||
174 | + | ||
175 | + tcg_op1 = tcg_temp_new_i64(); | ||
176 | + tcg_op2 = tcg_temp_new_i64(); | ||
177 | + tcg_res[0] = tcg_temp_new_i64(); | ||
178 | + tcg_res[1] = tcg_temp_new_i64(); | ||
179 | + | ||
180 | + for (pass = 0; pass < 2; pass++) { | ||
181 | + read_vec_element(s, tcg_op1, rn, pass, MO_64); | ||
182 | + read_vec_element(s, tcg_op2, rm, pass, MO_64); | ||
183 | + | ||
184 | + tcg_gen_xor_i64(tcg_res[pass], tcg_op1, tcg_op2); | ||
185 | + tcg_gen_rotri_i64(tcg_res[pass], tcg_res[pass], imm6); | ||
186 | + } | ||
187 | + write_vec_element(s, tcg_res[0], rd, 0, MO_64); | ||
188 | + write_vec_element(s, tcg_res[1], rd, 1, MO_64); | ||
189 | + | ||
190 | + tcg_temp_free_i64(tcg_op1); | ||
191 | + tcg_temp_free_i64(tcg_op2); | ||
192 | + tcg_temp_free_i64(tcg_res[0]); | ||
193 | + tcg_temp_free_i64(tcg_res[1]); | ||
194 | +} | ||
195 | + | ||
196 | /* C3.6 Data processing - SIMD, inc Crypto | ||
197 | * | ||
198 | * As the decode gets a little complex we are using a table based | ||
199 | @@ -XXX,XX +XXX,XX @@ static const AArch64DecodeTable data_proc_simd[] = { | ||
200 | { 0x5e280800, 0xff3e0c00, disas_crypto_two_reg_sha }, | ||
201 | { 0xce608000, 0xffe0b000, disas_crypto_three_reg_sha512 }, | ||
202 | { 0xcec08000, 0xfffff000, disas_crypto_two_reg_sha512 }, | ||
203 | + { 0xce000000, 0xff808000, disas_crypto_four_reg }, | ||
204 | + { 0xce800000, 0xffe00000, disas_crypto_xar }, | ||
205 | { 0x00000000, 0x00000000, NULL } | ||
206 | }; | ||
207 | |||
208 | -- | 136 | -- |
209 | 2.16.1 | 137 | 2.20.1 |
210 | 138 | ||
211 | 139 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Delete the trailing blank line at the end of the source file. | ||
1 | 2 | ||
3 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
6 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
7 | Message-id: 20210812093356.1946-15-peter.maydell@linaro.org | ||
8 | --- | ||
9 | hw/arm/stm32vldiscovery.c | 1 - | ||
10 | 1 file changed, 1 deletion(-) | ||
11 | |||
12 | diff --git a/hw/arm/stm32vldiscovery.c b/hw/arm/stm32vldiscovery.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/hw/arm/stm32vldiscovery.c | ||
15 | +++ b/hw/arm/stm32vldiscovery.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static void stm32vldiscovery_machine_init(MachineClass *mc) | ||
17 | } | ||
18 | |||
19 | DEFINE_MACHINE("stm32vldiscovery", stm32vldiscovery_machine_init) | ||
20 | - | ||
21 | -- | ||
22 | 2.20.1 | ||
23 | |||
24 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Wire up the sysclk input to the armv7m object. | ||
1 | 2 | ||
3 | Strictly this SoC should not have a systick device at all, but our | ||
4 | armv7m container object doesn't currently support disabling the | ||
5 | systick device. For the moment, add a TODO comment, but note that | ||
6 | this is why we aren't wiring up a refclk (no need for one). | ||
7 | |||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
10 | Message-id: 20210812093356.1946-16-peter.maydell@linaro.org | ||
11 | --- | ||
12 | include/hw/arm/nrf51_soc.h | 2 ++ | ||
13 | hw/arm/nrf51_soc.c | 20 ++++++++++++++++++++ | ||
14 | 2 files changed, 22 insertions(+) | ||
15 | |||
16 | diff --git a/include/hw/arm/nrf51_soc.h b/include/hw/arm/nrf51_soc.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/include/hw/arm/nrf51_soc.h | ||
19 | +++ b/include/hw/arm/nrf51_soc.h | ||
20 | @@ -XXX,XX +XXX,XX @@ | ||
21 | #include "hw/gpio/nrf51_gpio.h" | ||
22 | #include "hw/nvram/nrf51_nvm.h" | ||
23 | #include "hw/timer/nrf51_timer.h" | ||
24 | +#include "hw/clock.h" | ||
25 | #include "qom/object.h" | ||
26 | |||
27 | #define TYPE_NRF51_SOC "nrf51-soc" | ||
28 | @@ -XXX,XX +XXX,XX @@ struct NRF51State { | ||
29 | |||
30 | MemoryRegion container; | ||
31 | |||
32 | + Clock *sysclk; | ||
33 | }; | ||
34 | |||
35 | #endif | ||
36 | diff --git a/hw/arm/nrf51_soc.c b/hw/arm/nrf51_soc.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/hw/arm/nrf51_soc.c | ||
39 | +++ b/hw/arm/nrf51_soc.c | ||
40 | @@ -XXX,XX +XXX,XX @@ | ||
41 | #include "qapi/error.h" | ||
42 | #include "hw/arm/boot.h" | ||
43 | #include "hw/sysbus.h" | ||
44 | +#include "hw/qdev-clock.h" | ||
45 | #include "hw/misc/unimp.h" | ||
46 | #include "qemu/log.h" | ||
47 | |||
48 | @@ -XXX,XX +XXX,XX @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp) | ||
49 | return; | ||
50 | } | ||
51 | |||
52 | + /* | ||
53 | + * HCLK on this SoC is fixed, so we set up sysclk ourselves and | ||
54 | + * the board shouldn't connect it. | ||
55 | + */ | ||
56 | + if (clock_has_source(s->sysclk)) { | ||
57 | + error_setg(errp, "sysclk clock must not be wired up by the board code"); | ||
58 | + return; | ||
59 | + } | ||
60 | + /* This clock doesn't need migration because it is fixed-frequency */ | ||
61 | + clock_set_hz(s->sysclk, HCLK_FRQ); | ||
62 | + qdev_connect_clock_in(DEVICE(&s->cpu), "cpuclk", s->sysclk); | ||
63 | + /* | ||
64 | + * This SoC has no systick device, so don't connect refclk. | ||
65 | + * TODO: model the lack of systick (currently the armv7m object | ||
66 | + * will always provide one). | ||
67 | + */ | ||
68 | + | ||
69 | system_clock_scale = NANOSECONDS_PER_SECOND / HCLK_FRQ; | ||
70 | |||
71 | object_property_set_link(OBJECT(&s->cpu), "memory", OBJECT(&s->container), | ||
72 | @@ -XXX,XX +XXX,XX @@ static void nrf51_soc_init(Object *obj) | ||
73 | TYPE_NRF51_TIMER); | ||
74 | |||
75 | } | ||
76 | + | ||
77 | + s->sysclk = qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0); | ||
78 | } | ||
79 | |||
80 | static Property nrf51_soc_properties[] = { | ||
81 | -- | ||
82 | 2.20.1 | ||
83 | |||
84 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | Currently the stellaris_sys_init() function creates the |
---|---|---|---|
2 | TYPE_STELLARIS_SYS object, sets its properties, realizes it, maps its | ||
3 | MMIO region and connects its IRQ. In order to support wiring the | ||
4 | sysclk up to the armv7m object, we need to split this function apart, | ||
5 | because to connect the clock output of the STELLARIS_SYS object to | ||
6 | the armv7m object we need to create the STELLARIS_SYS object before | ||
7 | the armv7m object, but we can't wire up the IRQ until after we've | ||
8 | created the armv7m object. | ||
2 | 9 | ||
3 | Convert i.MX6 to use TYPE_IMX_USDHC since that's what real HW comes | 10 | Remove the stellaris_sys_init() function, and instead put the |
4 | with. | 11 | create/configure/realize parts before we create the armv7m object and |
12 | the mmio/irq connection parts afterwards. | ||
5 | 13 | ||
6 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Cc: Jason Wang <jasowang@redhat.com> | ||
8 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
10 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
11 | Cc: qemu-devel@nongnu.org | ||
12 | Cc: qemu-arm@nongnu.org | ||
13 | Cc: yurovsky@gmail.com | ||
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
16 | Message-id: 20210812093356.1946-17-peter.maydell@linaro.org | ||
17 | --- | 17 | --- |
18 | hw/arm/fsl-imx6.c | 2 +- | 18 | hw/arm/stellaris.c | 56 +++++++++++++++++++++------------------------- |
19 | 1 file changed, 1 insertion(+), 1 deletion(-) | 19 | 1 file changed, 25 insertions(+), 31 deletions(-) |
20 | 20 | ||
21 | diff --git a/hw/arm/fsl-imx6.c b/hw/arm/fsl-imx6.c | 21 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c |
22 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/arm/fsl-imx6.c | 23 | --- a/hw/arm/stellaris.c |
24 | +++ b/hw/arm/fsl-imx6.c | 24 | +++ b/hw/arm/stellaris.c |
25 | @@ -XXX,XX +XXX,XX @@ static void fsl_imx6_init(Object *obj) | 25 | @@ -XXX,XX +XXX,XX @@ static void stellaris_sys_instance_init(Object *obj) |
26 | s->sysclk = qdev_init_clock_out(DEVICE(s), "SYSCLK"); | ||
27 | } | ||
28 | |||
29 | -static DeviceState *stellaris_sys_init(uint32_t base, qemu_irq irq, | ||
30 | - stellaris_board_info *board, | ||
31 | - uint8_t *macaddr) | ||
32 | -{ | ||
33 | - DeviceState *dev = qdev_new(TYPE_STELLARIS_SYS); | ||
34 | - SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
35 | - | ||
36 | - /* Most devices come preprogrammed with a MAC address in the user data. */ | ||
37 | - qdev_prop_set_uint32(dev, "user0", | ||
38 | - macaddr[0] | (macaddr[1] << 8) | (macaddr[2] << 16)); | ||
39 | - qdev_prop_set_uint32(dev, "user1", | ||
40 | - macaddr[3] | (macaddr[4] << 8) | (macaddr[5] << 16)); | ||
41 | - qdev_prop_set_uint32(dev, "did0", board->did0); | ||
42 | - qdev_prop_set_uint32(dev, "did1", board->did1); | ||
43 | - qdev_prop_set_uint32(dev, "dc0", board->dc0); | ||
44 | - qdev_prop_set_uint32(dev, "dc1", board->dc1); | ||
45 | - qdev_prop_set_uint32(dev, "dc2", board->dc2); | ||
46 | - qdev_prop_set_uint32(dev, "dc3", board->dc3); | ||
47 | - qdev_prop_set_uint32(dev, "dc4", board->dc4); | ||
48 | - | ||
49 | - sysbus_realize_and_unref(sbd, &error_fatal); | ||
50 | - sysbus_mmio_map(sbd, 0, base); | ||
51 | - sysbus_connect_irq(sbd, 0, irq); | ||
52 | - | ||
53 | - return dev; | ||
54 | -} | ||
55 | - | ||
56 | /* I2C controller. */ | ||
57 | |||
58 | #define TYPE_STELLARIS_I2C "stellaris-i2c" | ||
59 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
60 | DeviceState *ssys_dev; | ||
61 | int i; | ||
62 | int j; | ||
63 | + uint8_t *macaddr; | ||
64 | |||
65 | MemoryRegion *sram = g_new(MemoryRegion, 1); | ||
66 | MemoryRegion *flash = g_new(MemoryRegion, 1); | ||
67 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
68 | &error_fatal); | ||
69 | memory_region_add_subregion(system_memory, 0x20000000, sram); | ||
70 | |||
71 | + /* | ||
72 | + * Create the system-registers object early, because we will | ||
73 | + * need its sysclk output. | ||
74 | + */ | ||
75 | + ssys_dev = qdev_new(TYPE_STELLARIS_SYS); | ||
76 | + /* Most devices come preprogrammed with a MAC address in the user data. */ | ||
77 | + macaddr = nd_table[0].macaddr.a; | ||
78 | + qdev_prop_set_uint32(ssys_dev, "user0", | ||
79 | + macaddr[0] | (macaddr[1] << 8) | (macaddr[2] << 16)); | ||
80 | + qdev_prop_set_uint32(ssys_dev, "user1", | ||
81 | + macaddr[3] | (macaddr[4] << 8) | (macaddr[5] << 16)); | ||
82 | + qdev_prop_set_uint32(ssys_dev, "did0", board->did0); | ||
83 | + qdev_prop_set_uint32(ssys_dev, "did1", board->did1); | ||
84 | + qdev_prop_set_uint32(ssys_dev, "dc0", board->dc0); | ||
85 | + qdev_prop_set_uint32(ssys_dev, "dc1", board->dc1); | ||
86 | + qdev_prop_set_uint32(ssys_dev, "dc2", board->dc2); | ||
87 | + qdev_prop_set_uint32(ssys_dev, "dc3", board->dc3); | ||
88 | + qdev_prop_set_uint32(ssys_dev, "dc4", board->dc4); | ||
89 | + sysbus_realize_and_unref(SYS_BUS_DEVICE(ssys_dev), &error_fatal); | ||
90 | + | ||
91 | nvic = qdev_new(TYPE_ARMV7M); | ||
92 | qdev_prop_set_uint32(nvic, "num-irq", NUM_IRQ_LINES); | ||
93 | qdev_prop_set_string(nvic, "cpu-type", ms->cpu_type); | ||
94 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
95 | /* This will exit with an error if the user passed us a bad cpu_type */ | ||
96 | sysbus_realize_and_unref(SYS_BUS_DEVICE(nvic), &error_fatal); | ||
97 | |||
98 | + /* Now we can wire up the IRQ and MMIO of the system registers */ | ||
99 | + sysbus_mmio_map(SYS_BUS_DEVICE(ssys_dev), 0, 0x400fe000); | ||
100 | + sysbus_connect_irq(SYS_BUS_DEVICE(ssys_dev), 0, qdev_get_gpio_in(nvic, 28)); | ||
101 | + | ||
102 | if (board->dc1 & (1 << 16)) { | ||
103 | dev = sysbus_create_varargs(TYPE_STELLARIS_ADC, 0x40038000, | ||
104 | qdev_get_gpio_in(nvic, 14), | ||
105 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
106 | } | ||
26 | } | 107 | } |
27 | 108 | ||
28 | for (i = 0; i < FSL_IMX6_NUM_ESDHCS; i++) { | 109 | - ssys_dev = stellaris_sys_init(0x400fe000, qdev_get_gpio_in(nvic, 28), |
29 | - object_initialize(&s->esdhc[i], sizeof(s->esdhc[i]), TYPE_SYSBUS_SDHCI); | 110 | - board, nd_table[0].macaddr.a); |
30 | + object_initialize(&s->esdhc[i], sizeof(s->esdhc[i]), TYPE_IMX_USDHC); | 111 | - |
31 | qdev_set_parent_bus(DEVICE(&s->esdhc[i]), sysbus_get_default()); | 112 | - |
32 | snprintf(name, NAME_SIZE, "sdhc%d", i + 1); | 113 | if (board->dc1 & (1 << 3)) { /* watchdog present */ |
33 | object_property_add_child(obj, name, OBJECT(&s->esdhc[i]), NULL); | 114 | dev = qdev_new(TYPE_LUMINARY_WATCHDOG); |
115 | |||
34 | -- | 116 | -- |
35 | 2.16.1 | 117 | 2.20.1 |
36 | 118 | ||
37 | 119 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Connect the sysclk to the armv7m object. This board's SoC does not | ||
2 | connect up the systick reference clock, so we don't need to connect a | ||
3 | refclk. | ||
1 | 4 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
7 | Message-id: 20210812093356.1946-18-peter.maydell@linaro.org | ||
8 | --- | ||
9 | hw/arm/stellaris.c | 5 ++++- | ||
10 | 1 file changed, 4 insertions(+), 1 deletion(-) | ||
11 | |||
12 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/hw/arm/stellaris.c | ||
15 | +++ b/hw/arm/stellaris.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
17 | DeviceState *ssys_dev; | ||
18 | int i; | ||
19 | int j; | ||
20 | - uint8_t *macaddr; | ||
21 | + const uint8_t *macaddr; | ||
22 | |||
23 | MemoryRegion *sram = g_new(MemoryRegion, 1); | ||
24 | MemoryRegion *flash = g_new(MemoryRegion, 1); | ||
25 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
26 | qdev_prop_set_uint32(nvic, "num-irq", NUM_IRQ_LINES); | ||
27 | qdev_prop_set_string(nvic, "cpu-type", ms->cpu_type); | ||
28 | qdev_prop_set_bit(nvic, "enable-bitband", true); | ||
29 | + qdev_connect_clock_in(nvic, "cpuclk", | ||
30 | + qdev_get_clock_out(ssys_dev, "SYSCLK")); | ||
31 | + /* This SoC does not connect the systick reference clock */ | ||
32 | object_property_set_link(OBJECT(nvic), "memory", | ||
33 | OBJECT(get_system_memory()), &error_abort); | ||
34 | /* This will exit with an error if the user passed us a bad cpu_type */ | ||
35 | -- | ||
36 | 2.20.1 | ||
37 | |||
38 | diff view generated by jsdifflib |
1 | The documentation for the generic loader claims that you can | 1 | In the realize method of the msf2-soc SoC object, we call g_new() to |
---|---|---|---|
2 | set the PC for a CPU with an option of the form | 2 | create new MemoryRegion objects for the nvm, nvm_alias, and sram. |
3 | -device loader,cpu-num=0,addr=0x10000004 | 3 | This is unnecessary; make these MemoryRegions member fields of the |
4 | 4 | device state struct instead. | |
5 | However if you try this QEMU complains: | ||
6 | cpu_num must be specified when setting a program counter | ||
7 | |||
8 | This is because we were testing against 0 rather than CPU_NONE. | ||
9 | 5 | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | 7 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> |
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Message-id: 20210812093356.1946-19-peter.maydell@linaro.org |
13 | Message-id: 20180205150426.20542-1-peter.maydell@linaro.org | ||
14 | --- | 9 | --- |
15 | hw/core/generic-loader.c | 2 +- | 10 | include/hw/arm/msf2-soc.h | 4 ++++ |
16 | 1 file changed, 1 insertion(+), 1 deletion(-) | 11 | hw/arm/msf2-soc.c | 17 +++++++---------- |
12 | 2 files changed, 11 insertions(+), 10 deletions(-) | ||
17 | 13 | ||
18 | diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c | 14 | diff --git a/include/hw/arm/msf2-soc.h b/include/hw/arm/msf2-soc.h |
19 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/core/generic-loader.c | 16 | --- a/include/hw/arm/msf2-soc.h |
21 | +++ b/hw/core/generic-loader.c | 17 | +++ b/include/hw/arm/msf2-soc.h |
22 | @@ -XXX,XX +XXX,XX @@ static void generic_loader_realize(DeviceState *dev, Error **errp) | 18 | @@ -XXX,XX +XXX,XX @@ struct MSF2State { |
23 | error_setg(errp, "data can not be specified when setting a " | 19 | MSSTimerState timer; |
24 | "program counter"); | 20 | MSSSpiState spi[MSF2_NUM_SPIS]; |
25 | return; | 21 | MSF2EmacState emac; |
26 | - } else if (!s->cpu_num) { | 22 | + |
27 | + } else if (s->cpu_num == CPU_NONE) { | 23 | + MemoryRegion nvm; |
28 | error_setg(errp, "cpu_num must be specified when setting a " | 24 | + MemoryRegion nvm_alias; |
29 | "program counter"); | 25 | + MemoryRegion sram; |
30 | return; | 26 | }; |
27 | |||
28 | #endif | ||
29 | diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/hw/arm/msf2-soc.c | ||
32 | +++ b/hw/arm/msf2-soc.c | ||
33 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | ||
34 | int i; | ||
35 | |||
36 | MemoryRegion *system_memory = get_system_memory(); | ||
37 | - MemoryRegion *nvm = g_new(MemoryRegion, 1); | ||
38 | - MemoryRegion *nvm_alias = g_new(MemoryRegion, 1); | ||
39 | - MemoryRegion *sram = g_new(MemoryRegion, 1); | ||
40 | |||
41 | - memory_region_init_rom(nvm, OBJECT(dev_soc), "MSF2.eNVM", s->envm_size, | ||
42 | + memory_region_init_rom(&s->nvm, OBJECT(dev_soc), "MSF2.eNVM", s->envm_size, | ||
43 | &error_fatal); | ||
44 | /* | ||
45 | * On power-on, the eNVM region 0x60000000 is automatically | ||
46 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | ||
47 | * start address (0x0). We do not support remapping other eNVM, | ||
48 | * eSRAM and DDR regions by guest(via Sysreg) currently. | ||
49 | */ | ||
50 | - memory_region_init_alias(nvm_alias, OBJECT(dev_soc), "MSF2.eNVM", nvm, 0, | ||
51 | - s->envm_size); | ||
52 | + memory_region_init_alias(&s->nvm_alias, OBJECT(dev_soc), "MSF2.eNVM", | ||
53 | + &s->nvm, 0, s->envm_size); | ||
54 | |||
55 | - memory_region_add_subregion(system_memory, ENVM_BASE_ADDRESS, nvm); | ||
56 | - memory_region_add_subregion(system_memory, 0, nvm_alias); | ||
57 | + memory_region_add_subregion(system_memory, ENVM_BASE_ADDRESS, &s->nvm); | ||
58 | + memory_region_add_subregion(system_memory, 0, &s->nvm_alias); | ||
59 | |||
60 | - memory_region_init_ram(sram, NULL, "MSF2.eSRAM", s->esram_size, | ||
61 | + memory_region_init_ram(&s->sram, NULL, "MSF2.eSRAM", s->esram_size, | ||
62 | &error_fatal); | ||
63 | - memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, sram); | ||
64 | + memory_region_add_subregion(system_memory, SRAM_BASE_ADDRESS, &s->sram); | ||
65 | |||
66 | armv7m = DEVICE(&s->armv7m); | ||
67 | qdev_prop_set_uint32(armv7m, "num-irq", 81); | ||
31 | -- | 68 | -- |
32 | 2.16.1 | 69 | 2.20.1 |
33 | 70 | ||
34 | 71 | diff view generated by jsdifflib |
1 | Make the load of the exception vector from the vector table honour | 1 | Instead of passing the MSF2 SoC an integer property specifying the |
---|---|---|---|
2 | the SAU and any bus error on the load (possibly provoking a derived | 2 | CPU clock rate, pass it a Clock instead. This lets us wire that |
3 | exception), rather than simply aborting if the load fails. | 3 | clock up to the armv7m object. |
4 | 4 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> |
7 | Message-id: 1517324542-6607-7-git-send-email-peter.maydell@linaro.org | 7 | Message-id: 20210812093356.1946-20-peter.maydell@linaro.org |
8 | --- | 8 | --- |
9 | target/arm/helper.c | 71 +++++++++++++++++++++++++++++++++++++++++------------ | 9 | include/hw/arm/msf2-soc.h | 3 ++- |
10 | 1 file changed, 55 insertions(+), 16 deletions(-) | 10 | hw/arm/msf2-soc.c | 28 +++++++++++++++++----------- |
11 | hw/arm/msf2-som.c | 7 ++++++- | ||
12 | 3 files changed, 25 insertions(+), 13 deletions(-) | ||
11 | 13 | ||
12 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 14 | diff --git a/include/hw/arm/msf2-soc.h b/include/hw/arm/msf2-soc.h |
13 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/helper.c | 16 | --- a/include/hw/arm/msf2-soc.h |
15 | +++ b/target/arm/helper.c | 17 | +++ b/include/hw/arm/msf2-soc.h |
16 | @@ -XXX,XX +XXX,XX @@ static uint32_t *get_v7m_sp_ptr(CPUARMState *env, bool secure, bool threadmode, | 18 | @@ -XXX,XX +XXX,XX @@ |
19 | #include "hw/misc/msf2-sysreg.h" | ||
20 | #include "hw/ssi/mss-spi.h" | ||
21 | #include "hw/net/msf2-emac.h" | ||
22 | +#include "hw/clock.h" | ||
23 | #include "qom/object.h" | ||
24 | |||
25 | #define TYPE_MSF2_SOC "msf2-soc" | ||
26 | @@ -XXX,XX +XXX,XX @@ struct MSF2State { | ||
27 | uint64_t envm_size; | ||
28 | uint64_t esram_size; | ||
29 | |||
30 | - uint32_t m3clk; | ||
31 | + Clock *m3clk; | ||
32 | uint8_t apb0div; | ||
33 | uint8_t apb1div; | ||
34 | |||
35 | diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/hw/arm/msf2-soc.c | ||
38 | +++ b/hw/arm/msf2-soc.c | ||
39 | @@ -XXX,XX +XXX,XX @@ | ||
40 | #include "hw/char/serial.h" | ||
41 | #include "hw/arm/msf2-soc.h" | ||
42 | #include "hw/misc/unimp.h" | ||
43 | +#include "hw/qdev-clock.h" | ||
44 | #include "sysemu/sysemu.h" | ||
45 | |||
46 | #define MSF2_TIMER_BASE 0x40004000 | ||
47 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_initfn(Object *obj) | ||
17 | } | 48 | } |
49 | |||
50 | object_initialize_child(obj, "emac", &s->emac, TYPE_MSS_EMAC); | ||
51 | + | ||
52 | + s->m3clk = qdev_init_clock_in(DEVICE(obj), "m3clk", NULL, NULL, 0); | ||
18 | } | 53 | } |
19 | 54 | ||
20 | -static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 55 | static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) |
21 | +static bool arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure, | 56 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) |
22 | + uint32_t *pvec) | 57 | |
23 | { | 58 | MemoryRegion *system_memory = get_system_memory(); |
24 | CPUState *cs = CPU(cpu); | 59 | |
25 | CPUARMState *env = &cpu->env; | 60 | + if (!clock_has_source(s->m3clk)) { |
26 | MemTxResult result; | 61 | + error_setg(errp, "m3clk must be wired up by the board code"); |
27 | - hwaddr vec = env->v7m.vecbase[targets_secure] + exc * 4; | 62 | + return; |
28 | - uint32_t addr; | ||
29 | + uint32_t addr = env->v7m.vecbase[targets_secure] + exc * 4; | ||
30 | + uint32_t vector_entry; | ||
31 | + MemTxAttrs attrs = {}; | ||
32 | + ARMMMUIdx mmu_idx; | ||
33 | + bool exc_secure; | ||
34 | + | ||
35 | + mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, targets_secure, true); | ||
36 | |||
37 | - addr = address_space_ldl(cs->as, vec, | ||
38 | - MEMTXATTRS_UNSPECIFIED, &result); | ||
39 | + /* We don't do a get_phys_addr() here because the rules for vector | ||
40 | + * loads are special: they always use the default memory map, and | ||
41 | + * the default memory map permits reads from all addresses. | ||
42 | + * Since there's no easy way to pass through to pmsav8_mpu_lookup() | ||
43 | + * that we want this special case which would always say "yes", | ||
44 | + * we just do the SAU lookup here followed by a direct physical load. | ||
45 | + */ | ||
46 | + attrs.secure = targets_secure; | ||
47 | + attrs.user = false; | ||
48 | + | ||
49 | + if (arm_feature(env, ARM_FEATURE_M_SECURITY)) { | ||
50 | + V8M_SAttributes sattrs = {}; | ||
51 | + | ||
52 | + v8m_security_lookup(env, addr, MMU_DATA_LOAD, mmu_idx, &sattrs); | ||
53 | + if (sattrs.ns) { | ||
54 | + attrs.secure = false; | ||
55 | + } else if (!targets_secure) { | ||
56 | + /* NS access to S memory */ | ||
57 | + goto load_fail; | ||
58 | + } | ||
59 | + } | 63 | + } |
60 | + | 64 | + |
61 | + vector_entry = address_space_ldl(arm_addressspace(cs, attrs), addr, | 65 | memory_region_init_rom(&s->nvm, OBJECT(dev_soc), "MSF2.eNVM", s->envm_size, |
62 | + attrs, &result); | 66 | &error_fatal); |
63 | if (result != MEMTX_OK) { | 67 | /* |
64 | - /* Architecturally this should cause a HardFault setting HSFR.VECTTBL, | 68 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) |
65 | - * which would then be immediately followed by our failing to load | 69 | qdev_prop_set_uint32(armv7m, "num-irq", 81); |
66 | - * the entry vector for that HardFault, which is a Lockup case. | 70 | qdev_prop_set_string(armv7m, "cpu-type", s->cpu_type); |
67 | - * Since we don't model Lockup, we just report this guest error | 71 | qdev_prop_set_bit(armv7m, "enable-bitband", true); |
68 | - * via cpu_abort(). | 72 | + qdev_connect_clock_in(armv7m, "cpuclk", s->m3clk); |
69 | - */ | 73 | object_property_set_link(OBJECT(&s->armv7m), "memory", |
70 | - cpu_abort(cs, "Failed to read from %s exception vector table " | 74 | OBJECT(get_system_memory()), &error_abort); |
71 | - "entry %08x\n", targets_secure ? "secure" : "nonsecure", | 75 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->armv7m), errp)) { |
72 | - (unsigned)vec); | ||
73 | + goto load_fail; | ||
74 | } | ||
75 | - return addr; | ||
76 | + *pvec = vector_entry; | ||
77 | + return true; | ||
78 | + | ||
79 | +load_fail: | ||
80 | + /* All vector table fetch fails are reported as HardFault, with | ||
81 | + * HFSR.VECTTBL and .FORCED set. (FORCED is set because | ||
82 | + * technically the underlying exception is a MemManage or BusFault | ||
83 | + * that is escalated to HardFault.) This is a terminal exception, | ||
84 | + * so we will either take the HardFault immediately or else enter | ||
85 | + * lockup (the latter case is handled in armv7m_nvic_set_pending_derived()). | ||
86 | + */ | ||
87 | + exc_secure = targets_secure || | ||
88 | + !(cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK); | ||
89 | + env->v7m.hfsr |= R_V7M_HFSR_VECTTBL_MASK | R_V7M_HFSR_FORCED_MASK; | ||
90 | + armv7m_nvic_set_pending_derived(env->nvic, ARMV7M_EXCP_HARD, exc_secure); | ||
91 | + return false; | ||
92 | } | ||
93 | |||
94 | static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
95 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
96 | return; | 76 | return; |
97 | } | 77 | } |
98 | 78 | ||
99 | - addr = arm_v7m_load_vector(cpu, exc, targets_secure); | 79 | - if (!s->m3clk) { |
100 | + if (!arm_v7m_load_vector(cpu, exc, targets_secure, &addr)) { | 80 | - error_setg(errp, "Invalid m3clk value"); |
101 | + /* Vector load failed: derived exception */ | 81 | - error_append_hint(errp, "m3clk can not be zero\n"); |
102 | + v7m_exception_taken(cpu, lr, true, true); | 82 | - return; |
103 | + return; | 83 | - } |
104 | + } | 84 | - |
105 | 85 | - system_clock_scale = NANOSECONDS_PER_SECOND / s->m3clk; | |
106 | /* Now we've done everything that might cause a derived exception | 86 | + system_clock_scale = clock_ticks_to_ns(s->m3clk, 1); |
107 | * we can go ahead and activate whichever exception we're going to | 87 | |
88 | for (i = 0; i < MSF2_NUM_UARTS; i++) { | ||
89 | if (serial_hd(i)) { | ||
90 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | ||
91 | } | ||
92 | |||
93 | dev = DEVICE(&s->timer); | ||
94 | - /* APB0 clock is the timer input clock */ | ||
95 | - qdev_prop_set_uint32(dev, "clock-frequency", s->m3clk / s->apb0div); | ||
96 | + /* | ||
97 | + * APB0 clock is the timer input clock. | ||
98 | + * TODO: ideally the MSF2 timer device should use a Clock rather than a | ||
99 | + * clock-frequency integer property. | ||
100 | + */ | ||
101 | + qdev_prop_set_uint32(dev, "clock-frequency", | ||
102 | + clock_get_hz(s->m3clk) / s->apb0div); | ||
103 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->timer), errp)) { | ||
104 | return; | ||
105 | } | ||
106 | @@ -XXX,XX +XXX,XX @@ static Property m2sxxx_soc_properties[] = { | ||
107 | DEFINE_PROP_UINT64("eNVM-size", MSF2State, envm_size, MSF2_ENVM_MAX_SIZE), | ||
108 | DEFINE_PROP_UINT64("eSRAM-size", MSF2State, esram_size, | ||
109 | MSF2_ESRAM_MAX_SIZE), | ||
110 | - /* Libero GUI shows 100Mhz as default for clocks */ | ||
111 | - DEFINE_PROP_UINT32("m3clk", MSF2State, m3clk, 100 * 1000000), | ||
112 | /* default divisors in Libero GUI */ | ||
113 | DEFINE_PROP_UINT8("apb0div", MSF2State, apb0div, 2), | ||
114 | DEFINE_PROP_UINT8("apb1div", MSF2State, apb1div, 2), | ||
115 | diff --git a/hw/arm/msf2-som.c b/hw/arm/msf2-som.c | ||
116 | index XXXXXXX..XXXXXXX 100644 | ||
117 | --- a/hw/arm/msf2-som.c | ||
118 | +++ b/hw/arm/msf2-som.c | ||
119 | @@ -XXX,XX +XXX,XX @@ | ||
120 | #include "hw/boards.h" | ||
121 | #include "hw/qdev-properties.h" | ||
122 | #include "hw/arm/boot.h" | ||
123 | +#include "hw/qdev-clock.h" | ||
124 | #include "exec/address-spaces.h" | ||
125 | #include "hw/arm/msf2-soc.h" | ||
126 | |||
127 | @@ -XXX,XX +XXX,XX @@ static void emcraft_sf2_s2s010_init(MachineState *machine) | ||
128 | BusState *spi_bus; | ||
129 | MemoryRegion *sysmem = get_system_memory(); | ||
130 | MemoryRegion *ddr = g_new(MemoryRegion, 1); | ||
131 | + Clock *m3clk; | ||
132 | |||
133 | if (strcmp(machine->cpu_type, mc->default_cpu_type) != 0) { | ||
134 | error_report("This board can only be used with CPU %s", | ||
135 | @@ -XXX,XX +XXX,XX @@ static void emcraft_sf2_s2s010_init(MachineState *machine) | ||
136 | * in Libero. CPU clock is divided by APB0 and APB1 divisors for | ||
137 | * peripherals. Emcraft's SoM kit comes with these settings by default. | ||
138 | */ | ||
139 | - qdev_prop_set_uint32(dev, "m3clk", 142 * 1000000); | ||
140 | + /* This clock doesn't need migration because it is fixed-frequency */ | ||
141 | + m3clk = clock_new(OBJECT(machine), "m3clk"); | ||
142 | + clock_set_hz(m3clk, 142 * 1000000); | ||
143 | + qdev_connect_clock_in(dev, "m3clk", m3clk); | ||
144 | qdev_prop_set_uint32(dev, "apb0div", 2); | ||
145 | qdev_prop_set_uint32(dev, "apb1div", 2); | ||
146 | |||
108 | -- | 147 | -- |
109 | 2.16.1 | 148 | 2.20.1 |
110 | 149 | ||
111 | 150 | diff view generated by jsdifflib |
1 | Make v7m_push_callee_stack() honour the MPU by using the | 1 | Wire up the refclk for the msf2 SoC. This SoC runs the refclk at a |
---|---|---|---|
2 | new v7m_stack_write() function. We return a flag to indicate | 2 | frequency which is programmably either /4, /8, /16 or /32 of the main |
3 | whether the pushes failed, which we can then use in | 3 | CPU clock. We don't currently model the register which allows the |
4 | v7m_exception_taken() to cause us to handle the derived | 4 | guest to set the divisor, so implement the refclk as a fixed /32 of |
5 | exception correctly. | 5 | the CPU clock (which is the value of the divisor at reset). |
6 | 6 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> |
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Message-id: 20210812093356.1946-21-peter.maydell@linaro.org |
10 | Message-id: 1517324542-6607-6-git-send-email-peter.maydell@linaro.org | ||
11 | --- | 10 | --- |
12 | target/arm/helper.c | 64 ++++++++++++++++++++++++++++++++++++++++------------- | 11 | include/hw/arm/msf2-soc.h | 1 + |
13 | 1 file changed, 49 insertions(+), 15 deletions(-) | 12 | hw/arm/msf2-soc.c | 23 +++++++++++++++++++++++ |
13 | 2 files changed, 24 insertions(+) | ||
14 | 14 | ||
15 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 15 | diff --git a/include/hw/arm/msf2-soc.h b/include/hw/arm/msf2-soc.h |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/helper.c | 17 | --- a/include/hw/arm/msf2-soc.h |
18 | +++ b/target/arm/helper.c | 18 | +++ b/include/hw/arm/msf2-soc.h |
19 | @@ -XXX,XX +XXX,XX @@ static uint32_t arm_v7m_load_vector(ARMCPU *cpu, int exc, bool targets_secure) | 19 | @@ -XXX,XX +XXX,XX @@ struct MSF2State { |
20 | return addr; | 20 | uint64_t esram_size; |
21 | |||
22 | Clock *m3clk; | ||
23 | + Clock *refclk; | ||
24 | uint8_t apb0div; | ||
25 | uint8_t apb1div; | ||
26 | |||
27 | diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/hw/arm/msf2-soc.c | ||
30 | +++ b/hw/arm/msf2-soc.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_initfn(Object *obj) | ||
32 | object_initialize_child(obj, "emac", &s->emac, TYPE_MSS_EMAC); | ||
33 | |||
34 | s->m3clk = qdev_init_clock_in(DEVICE(obj), "m3clk", NULL, NULL, 0); | ||
35 | + s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", NULL, NULL, 0); | ||
21 | } | 36 | } |
22 | 37 | ||
23 | -static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | 38 | static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) |
24 | +static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | 39 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) |
25 | bool ignore_faults) | 40 | return; |
26 | { | ||
27 | /* For v8M, push the callee-saves register part of the stack frame. | ||
28 | @@ -XXX,XX +XXX,XX @@ static void v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
29 | * In the tailchaining case this may not be the current stack. | ||
30 | */ | ||
31 | CPUARMState *env = &cpu->env; | ||
32 | - CPUState *cs = CPU(cpu); | ||
33 | uint32_t *frame_sp_p; | ||
34 | uint32_t frameptr; | ||
35 | + ARMMMUIdx mmu_idx; | ||
36 | + bool stacked_ok; | ||
37 | |||
38 | if (dotailchain) { | ||
39 | - frame_sp_p = get_v7m_sp_ptr(env, true, | ||
40 | - lr & R_V7M_EXCRET_MODE_MASK, | ||
41 | + bool mode = lr & R_V7M_EXCRET_MODE_MASK; | ||
42 | + bool priv = !(env->v7m.control[M_REG_S] & R_V7M_CONTROL_NPRIV_MASK) || | ||
43 | + !mode; | ||
44 | + | ||
45 | + mmu_idx = arm_v7m_mmu_idx_for_secstate_and_priv(env, M_REG_S, priv); | ||
46 | + frame_sp_p = get_v7m_sp_ptr(env, M_REG_S, mode, | ||
47 | lr & R_V7M_EXCRET_SPSEL_MASK); | ||
48 | } else { | ||
49 | + mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
50 | frame_sp_p = &env->regs[13]; | ||
51 | } | 41 | } |
52 | 42 | ||
53 | frameptr = *frame_sp_p - 0x28; | 43 | + /* |
54 | 44 | + * We use s->refclk internally and only define it with qdev_init_clock_in() | |
55 | - stl_phys(cs->as, frameptr, 0xfefa125b); | 45 | + * so it is correctly parented and not leaked on an init/deinit; it is not |
56 | - stl_phys(cs->as, frameptr + 0x8, env->regs[4]); | 46 | + * intended as an externally exposed clock. |
57 | - stl_phys(cs->as, frameptr + 0xc, env->regs[5]); | ||
58 | - stl_phys(cs->as, frameptr + 0x10, env->regs[6]); | ||
59 | - stl_phys(cs->as, frameptr + 0x14, env->regs[7]); | ||
60 | - stl_phys(cs->as, frameptr + 0x18, env->regs[8]); | ||
61 | - stl_phys(cs->as, frameptr + 0x1c, env->regs[9]); | ||
62 | - stl_phys(cs->as, frameptr + 0x20, env->regs[10]); | ||
63 | - stl_phys(cs->as, frameptr + 0x24, env->regs[11]); | ||
64 | + /* Write as much of the stack frame as we can. A write failure may | ||
65 | + * cause us to pend a derived exception. | ||
66 | + */ | 47 | + */ |
67 | + stacked_ok = | 48 | + if (clock_has_source(s->refclk)) { |
68 | + v7m_stack_write(cpu, frameptr, 0xfefa125b, mmu_idx, ignore_faults) && | 49 | + error_setg(errp, "refclk must not be wired up by the board code"); |
69 | + v7m_stack_write(cpu, frameptr + 0x8, env->regs[4], mmu_idx, | ||
70 | + ignore_faults) && | ||
71 | + v7m_stack_write(cpu, frameptr + 0xc, env->regs[5], mmu_idx, | ||
72 | + ignore_faults) && | ||
73 | + v7m_stack_write(cpu, frameptr + 0x10, env->regs[6], mmu_idx, | ||
74 | + ignore_faults) && | ||
75 | + v7m_stack_write(cpu, frameptr + 0x14, env->regs[7], mmu_idx, | ||
76 | + ignore_faults) && | ||
77 | + v7m_stack_write(cpu, frameptr + 0x18, env->regs[8], mmu_idx, | ||
78 | + ignore_faults) && | ||
79 | + v7m_stack_write(cpu, frameptr + 0x1c, env->regs[9], mmu_idx, | ||
80 | + ignore_faults) && | ||
81 | + v7m_stack_write(cpu, frameptr + 0x20, env->regs[10], mmu_idx, | ||
82 | + ignore_faults) && | ||
83 | + v7m_stack_write(cpu, frameptr + 0x24, env->regs[11], mmu_idx, | ||
84 | + ignore_faults); | ||
85 | |||
86 | + /* Update SP regardless of whether any of the stack accesses failed. | ||
87 | + * When we implement v8M stack limit checking then this attempt to | ||
88 | + * update SP might also fail and result in a derived exception. | ||
89 | + */ | ||
90 | *frame_sp_p = frameptr; | ||
91 | + | ||
92 | + return !stacked_ok; | ||
93 | } | ||
94 | |||
95 | static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
96 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
97 | uint32_t addr; | ||
98 | bool targets_secure; | ||
99 | int exc; | ||
100 | + bool push_failed = false; | ||
101 | |||
102 | armv7m_nvic_get_pending_irq_info(env->nvic, &exc, &targets_secure); | ||
103 | |||
104 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
105 | */ | ||
106 | if (lr & R_V7M_EXCRET_DCRS_MASK && | ||
107 | !(dotailchain && (lr & R_V7M_EXCRET_ES_MASK))) { | ||
108 | - v7m_push_callee_stack(cpu, lr, dotailchain, | ||
109 | - ignore_stackfaults); | ||
110 | + push_failed = v7m_push_callee_stack(cpu, lr, dotailchain, | ||
111 | + ignore_stackfaults); | ||
112 | } | ||
113 | lr |= R_V7M_EXCRET_DCRS_MASK; | ||
114 | } | ||
115 | @@ -XXX,XX +XXX,XX @@ static void v7m_exception_taken(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
116 | } | ||
117 | } | ||
118 | |||
119 | + if (push_failed && !ignore_stackfaults) { | ||
120 | + /* Derived exception on callee-saves register stacking: | ||
121 | + * we might now want to take a different exception which | ||
122 | + * targets a different security state, so try again from the top. | ||
123 | + */ | ||
124 | + v7m_exception_taken(cpu, lr, true, true); | ||
125 | + return; | 50 | + return; |
126 | + } | 51 | + } |
127 | + | 52 | + |
128 | addr = arm_v7m_load_vector(cpu, exc, targets_secure); | 53 | + /* |
129 | 54 | + * TODO: ideally we should model the SoC SYSTICK_CR register at 0xe0042038, | |
130 | /* Now we've done everything that might cause a derived exception | 55 | + * which allows the guest to program the divisor between the m3clk and |
56 | + * the systick refclk to either /4, /8, /16 or /32, as well as setting | ||
57 | + * the value the guest can read in the STCALIB register. Currently we | ||
58 | + * implement the divisor as a fixed /32, which matches the reset value | ||
59 | + * of SYSTICK_CR. | ||
60 | + */ | ||
61 | + clock_set_mul_div(s->refclk, 32, 1); | ||
62 | + clock_set_source(s->refclk, s->m3clk); | ||
63 | + | ||
64 | memory_region_init_rom(&s->nvm, OBJECT(dev_soc), "MSF2.eNVM", s->envm_size, | ||
65 | &error_fatal); | ||
66 | /* | ||
67 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | ||
68 | qdev_prop_set_string(armv7m, "cpu-type", s->cpu_type); | ||
69 | qdev_prop_set_bit(armv7m, "enable-bitband", true); | ||
70 | qdev_connect_clock_in(armv7m, "cpuclk", s->m3clk); | ||
71 | + qdev_connect_clock_in(armv7m, "refclk", s->refclk); | ||
72 | object_property_set_link(OBJECT(&s->armv7m), "memory", | ||
73 | OBJECT(get_system_memory()), &error_abort); | ||
74 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->armv7m), errp)) { | ||
131 | -- | 75 | -- |
132 | 2.16.1 | 76 | 2.20.1 |
133 | 77 | ||
134 | 78 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | Now that all users of the systick devices wire up the clock inputs, | |
2 | use those instead of the system_clock_scale and the hardwired 1MHz | ||
3 | value for the reference clock. | ||
4 | |||
5 | This will fix various board models where we were incorrectly | ||
6 | providing a 1MHz reference clock instead of some other value or | ||
7 | instead of providing no reference clock at all. | ||
8 | |||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> | ||
11 | Message-id: 20210812093356.1946-22-peter.maydell@linaro.org | ||
12 | --- | ||
13 | hw/timer/armv7m_systick.c | 112 ++++++++++++++++++++++++++++---------- | ||
14 | 1 file changed, 84 insertions(+), 28 deletions(-) | ||
15 | |||
16 | diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/timer/armv7m_systick.c | ||
19 | +++ b/hw/timer/armv7m_systick.c | ||
20 | @@ -XXX,XX +XXX,XX @@ | ||
21 | #include "qemu/timer.h" | ||
22 | #include "qemu/log.h" | ||
23 | #include "qemu/module.h" | ||
24 | +#include "qapi/error.h" | ||
25 | #include "trace.h" | ||
26 | |||
27 | -/* qemu timers run at 1GHz. We want something closer to 1MHz. */ | ||
28 | -#define SYSTICK_SCALE 1000ULL | ||
29 | - | ||
30 | #define SYSTICK_ENABLE (1 << 0) | ||
31 | #define SYSTICK_TICKINT (1 << 1) | ||
32 | #define SYSTICK_CLKSOURCE (1 << 2) | ||
33 | #define SYSTICK_COUNTFLAG (1 << 16) | ||
34 | |||
35 | +#define SYSCALIB_NOREF (1U << 31) | ||
36 | +#define SYSCALIB_SKEW (1U << 30) | ||
37 | +#define SYSCALIB_TENMS ((1U << 24) - 1) | ||
38 | + | ||
39 | int system_clock_scale; | ||
40 | |||
41 | -/* Conversion factor from qemu timer to SysTick frequencies. */ | ||
42 | -static inline int64_t systick_scale(SysTickState *s) | ||
43 | +static void systick_set_period_from_clock(SysTickState *s) | ||
44 | { | ||
45 | + /* | ||
46 | + * Set the ptimer period from whichever clock is selected. | ||
47 | + * Must be called from within a ptimer transaction block. | ||
48 | + */ | ||
49 | if (s->control & SYSTICK_CLKSOURCE) { | ||
50 | - return system_clock_scale; | ||
51 | + ptimer_set_period_from_clock(s->ptimer, s->cpuclk, 1); | ||
52 | } else { | ||
53 | - return 1000; | ||
54 | + ptimer_set_period_from_clock(s->ptimer, s->refclk, 1); | ||
55 | } | ||
56 | } | ||
57 | |||
58 | @@ -XXX,XX +XXX,XX @@ static MemTxResult systick_read(void *opaque, hwaddr addr, uint64_t *data, | ||
59 | val = ptimer_get_count(s->ptimer); | ||
60 | break; | ||
61 | case 0xc: /* SysTick Calibration Value. */ | ||
62 | - val = 10000; | ||
63 | + /* | ||
64 | + * In real hardware it is possible to make this register report | ||
65 | + * a different value from what the reference clock is actually | ||
66 | + * running at. We don't model that (which usually happens due | ||
67 | + * to integration errors in the real hardware) and instead always | ||
68 | + * report the theoretical correct value as described in the | ||
69 | + * knowledgebase article at | ||
70 | + * https://developer.arm.com/documentation/ka001325/latest | ||
71 | + * If necessary, we could implement an extra QOM property on this | ||
72 | + * device to force the STCALIB value to something different from | ||
73 | + * the "correct" value. | ||
74 | + */ | ||
75 | + if (!clock_has_source(s->refclk)) { | ||
76 | + val = SYSCALIB_NOREF; | ||
77 | + break; | ||
78 | + } | ||
79 | + val = clock_ns_to_ticks(s->refclk, 10 * SCALE_MS) - 1; | ||
80 | + val &= SYSCALIB_TENMS; | ||
81 | + if (clock_ticks_to_ns(s->refclk, val + 1) != 10 * SCALE_MS) { | ||
82 | + /* report that tick count does not yield exactly 10ms */ | ||
83 | + val |= SYSCALIB_SKEW; | ||
84 | + } | ||
85 | break; | ||
86 | default: | ||
87 | val = 0; | ||
88 | @@ -XXX,XX +XXX,XX @@ static MemTxResult systick_write(void *opaque, hwaddr addr, | ||
89 | { | ||
90 | uint32_t oldval; | ||
91 | |||
92 | + if (!clock_has_source(s->refclk)) { | ||
93 | + /* This bit is always 1 if there is no external refclk */ | ||
94 | + value |= SYSTICK_CLKSOURCE; | ||
95 | + } | ||
96 | + | ||
97 | ptimer_transaction_begin(s->ptimer); | ||
98 | oldval = s->control; | ||
99 | s->control &= 0xfffffff8; | ||
100 | @@ -XXX,XX +XXX,XX @@ static MemTxResult systick_write(void *opaque, hwaddr addr, | ||
101 | |||
102 | if ((oldval ^ value) & SYSTICK_ENABLE) { | ||
103 | if (value & SYSTICK_ENABLE) { | ||
104 | - /* | ||
105 | - * Always reload the period in case board code has | ||
106 | - * changed system_clock_scale. If we ever replace that | ||
107 | - * global with a more sensible API then we might be able | ||
108 | - * to set the period only when it actually changes. | ||
109 | - */ | ||
110 | - ptimer_set_period(s->ptimer, systick_scale(s)); | ||
111 | ptimer_run(s->ptimer, 0); | ||
112 | } else { | ||
113 | ptimer_stop(s->ptimer); | ||
114 | } | ||
115 | - } else if ((oldval ^ value) & SYSTICK_CLKSOURCE) { | ||
116 | - ptimer_set_period(s->ptimer, systick_scale(s)); | ||
117 | + } | ||
118 | + | ||
119 | + if ((oldval ^ value) & SYSTICK_CLKSOURCE) { | ||
120 | + systick_set_period_from_clock(s); | ||
121 | } | ||
122 | ptimer_transaction_commit(s->ptimer); | ||
123 | break; | ||
124 | @@ -XXX,XX +XXX,XX @@ static void systick_reset(DeviceState *dev) | ||
125 | { | ||
126 | SysTickState *s = SYSTICK(dev); | ||
127 | |||
128 | - /* | ||
129 | - * Forgetting to set system_clock_scale is always a board code | ||
130 | - * bug. We can't check this earlier because for some boards | ||
131 | - * (like stellaris) it is not yet configured at the point where | ||
132 | - * the systick device is realized. | ||
133 | - */ | ||
134 | - assert(system_clock_scale != 0); | ||
135 | - | ||
136 | ptimer_transaction_begin(s->ptimer); | ||
137 | s->control = 0; | ||
138 | + if (!clock_has_source(s->refclk)) { | ||
139 | + /* This bit is always 1 if there is no external refclk */ | ||
140 | + s->control |= SYSTICK_CLKSOURCE; | ||
141 | + } | ||
142 | ptimer_stop(s->ptimer); | ||
143 | ptimer_set_count(s->ptimer, 0); | ||
144 | ptimer_set_limit(s->ptimer, 0, 0); | ||
145 | - ptimer_set_period(s->ptimer, systick_scale(s)); | ||
146 | + systick_set_period_from_clock(s); | ||
147 | + ptimer_transaction_commit(s->ptimer); | ||
148 | +} | ||
149 | + | ||
150 | +static void systick_cpuclk_update(void *opaque, ClockEvent event) | ||
151 | +{ | ||
152 | + SysTickState *s = SYSTICK(opaque); | ||
153 | + | ||
154 | + if (!(s->control & SYSTICK_CLKSOURCE)) { | ||
155 | + /* currently using refclk, we can ignore cpuclk changes */ | ||
156 | + } | ||
157 | + | ||
158 | + ptimer_transaction_begin(s->ptimer); | ||
159 | + ptimer_set_period_from_clock(s->ptimer, s->cpuclk, 1); | ||
160 | + ptimer_transaction_commit(s->ptimer); | ||
161 | +} | ||
162 | + | ||
163 | +static void systick_refclk_update(void *opaque, ClockEvent event) | ||
164 | +{ | ||
165 | + SysTickState *s = SYSTICK(opaque); | ||
166 | + | ||
167 | + if (s->control & SYSTICK_CLKSOURCE) { | ||
168 | + /* currently using cpuclk, we can ignore refclk changes */ | ||
169 | + } | ||
170 | + | ||
171 | + ptimer_transaction_begin(s->ptimer); | ||
172 | + ptimer_set_period_from_clock(s->ptimer, s->refclk, 1); | ||
173 | ptimer_transaction_commit(s->ptimer); | ||
174 | } | ||
175 | |||
176 | @@ -XXX,XX +XXX,XX @@ static void systick_instance_init(Object *obj) | ||
177 | sysbus_init_mmio(sbd, &s->iomem); | ||
178 | sysbus_init_irq(sbd, &s->irq); | ||
179 | |||
180 | - s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", NULL, NULL, 0); | ||
181 | - s->cpuclk = qdev_init_clock_in(DEVICE(obj), "cpuclk", NULL, NULL, 0); | ||
182 | + s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", | ||
183 | + systick_refclk_update, s, ClockUpdate); | ||
184 | + s->cpuclk = qdev_init_clock_in(DEVICE(obj), "cpuclk", | ||
185 | + systick_cpuclk_update, s, ClockUpdate); | ||
186 | } | ||
187 | |||
188 | static void systick_realize(DeviceState *dev, Error **errp) | ||
189 | @@ -XXX,XX +XXX,XX @@ static void systick_realize(DeviceState *dev, Error **errp) | ||
190 | PTIMER_POLICY_NO_COUNTER_ROUND_DOWN | | ||
191 | PTIMER_POLICY_NO_IMMEDIATE_RELOAD | | ||
192 | PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT); | ||
193 | + | ||
194 | + if (!clock_has_source(s->cpuclk)) { | ||
195 | + error_setg(errp, "systick: cpuclk must be connected"); | ||
196 | + return; | ||
197 | + } | ||
198 | + /* It's OK not to connect the refclk */ | ||
199 | } | ||
200 | |||
201 | static const VMStateDescription vmstate_systick = { | ||
202 | -- | ||
203 | 2.20.1 | ||
204 | |||
205 | diff view generated by jsdifflib |
1 | The code where we added the TT instruction was accidentally | 1 | Fix the code style issues in the Stellaris general purpose timer |
---|---|---|---|
2 | missing a 'break', which meant that after generating the code | 2 | module code, so that when we move it to a different file in a |
3 | to execute the TT we would fall through to 'goto illegal_op' | 3 | following patch checkpatch doesn't complain. |
4 | and generate code to take an UNDEF insn. | ||
5 | 4 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 6 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> |
8 | Message-id: 20180206103941.13985-1-peter.maydell@linaro.org | 7 | Message-id: 20210812093356.1946-23-peter.maydell@linaro.org |
9 | --- | 8 | --- |
10 | target/arm/translate.c | 1 + | 9 | hw/arm/stellaris.c | 13 ++++++++----- |
11 | 1 file changed, 1 insertion(+) | 10 | 1 file changed, 8 insertions(+), 5 deletions(-) |
12 | 11 | ||
13 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 12 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c |
14 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/translate.c | 14 | --- a/hw/arm/stellaris.c |
16 | +++ b/target/arm/translate.c | 15 | +++ b/hw/arm/stellaris.c |
17 | @@ -XXX,XX +XXX,XX @@ static void disas_thumb2_insn(DisasContext *s, uint32_t insn) | 16 | @@ -XXX,XX +XXX,XX @@ static void gptm_stop(gptm_state *s, int n) |
18 | tcg_temp_free_i32(addr); | 17 | static void gptm_reload(gptm_state *s, int n, int reset) |
19 | tcg_temp_free_i32(op); | 18 | { |
20 | store_reg(s, rd, ttresp); | 19 | int64_t tick; |
21 | + break; | 20 | - if (reset) |
22 | } | 21 | + if (reset) { |
23 | goto illegal_op; | 22 | tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
24 | } | 23 | - else |
24 | + } else { | ||
25 | tick = s->tick[n]; | ||
26 | + } | ||
27 | |||
28 | if (s->config == 0) { | ||
29 | /* 32-bit CountDown. */ | ||
30 | @@ -XXX,XX +XXX,XX @@ static void gptm_write(void *opaque, hwaddr offset, | ||
31 | gptm_state *s = (gptm_state *)opaque; | ||
32 | uint32_t oldval; | ||
33 | |||
34 | - /* The timers should be disabled before changing the configuration. | ||
35 | - We take advantage of this and defer everything until the timer | ||
36 | - is enabled. */ | ||
37 | + /* | ||
38 | + * The timers should be disabled before changing the configuration. | ||
39 | + * We take advantage of this and defer everything until the timer | ||
40 | + * is enabled. | ||
41 | + */ | ||
42 | switch (offset) { | ||
43 | case 0x00: /* CFG */ | ||
44 | s->config = value; | ||
25 | -- | 45 | -- |
26 | 2.16.1 | 46 | 2.20.1 |
27 | 47 | ||
28 | 48 | diff view generated by jsdifflib |
1 | From: Andrey Smirnov <andrew.smirnov@gmail.com> | 1 | The implementation of the Stellaris general purpose timer module |
---|---|---|---|
2 | device stellaris-gptm is currently in the same source file as the | ||
3 | board model. Split it out into its own source file in hw/timer. | ||
2 | 4 | ||
3 | Add minimal code needed to allow upstream Linux guest to boot. | 5 | Apart from the new file comment headers and the Kconfig and |
6 | meson.build changes, this is just code movement. | ||
4 | 7 | ||
5 | Cc: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Cc: Jason Wang <jasowang@redhat.com> | ||
7 | Cc: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Cc: Marcel Apfelbaum <marcel.apfelbaum@zoho.com> | ||
9 | Cc: Michael S. Tsirkin <mst@redhat.com> | ||
10 | Cc: qemu-devel@nongnu.org | ||
11 | Cc: qemu-arm@nongnu.org | ||
12 | Cc: yurovsky@gmail.com | ||
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> | ||
10 | Message-id: 20210812093356.1946-24-peter.maydell@linaro.org | ||
16 | --- | 11 | --- |
17 | hw/misc/Makefile.objs | 1 + | 12 | include/hw/timer/stellaris-gptm.h | 48 +++++ |
18 | include/hw/misc/imx7_ccm.h | 139 +++++++++++++++++++++++ | 13 | hw/arm/stellaris.c | 321 +----------------------------- |
19 | hw/misc/imx7_ccm.c | 277 +++++++++++++++++++++++++++++++++++++++++++++ | 14 | hw/timer/stellaris-gptm.c | 314 +++++++++++++++++++++++++++++ |
20 | 3 files changed, 417 insertions(+) | 15 | hw/arm/Kconfig | 1 + |
21 | create mode 100644 include/hw/misc/imx7_ccm.h | 16 | hw/timer/Kconfig | 3 + |
22 | create mode 100644 hw/misc/imx7_ccm.c | 17 | hw/timer/meson.build | 1 + |
18 | 6 files changed, 368 insertions(+), 320 deletions(-) | ||
19 | create mode 100644 include/hw/timer/stellaris-gptm.h | ||
20 | create mode 100644 hw/timer/stellaris-gptm.c | ||
23 | 21 | ||
24 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | 22 | diff --git a/include/hw/timer/stellaris-gptm.h b/include/hw/timer/stellaris-gptm.h |
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/hw/misc/Makefile.objs | ||
27 | +++ b/hw/misc/Makefile.objs | ||
28 | @@ -XXX,XX +XXX,XX @@ obj-$(CONFIG_IMX) += imx31_ccm.o | ||
29 | obj-$(CONFIG_IMX) += imx25_ccm.o | ||
30 | obj-$(CONFIG_IMX) += imx6_ccm.o | ||
31 | obj-$(CONFIG_IMX) += imx6_src.o | ||
32 | +obj-$(CONFIG_IMX) += imx7_ccm.o | ||
33 | obj-$(CONFIG_MILKYMIST) += milkymist-hpdmc.o | ||
34 | obj-$(CONFIG_MILKYMIST) += milkymist-pfpu.o | ||
35 | obj-$(CONFIG_MAINSTONE) += mst_fpga.o | ||
36 | diff --git a/include/hw/misc/imx7_ccm.h b/include/hw/misc/imx7_ccm.h | ||
37 | new file mode 100644 | 23 | new file mode 100644 |
38 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
39 | --- /dev/null | 25 | --- /dev/null |
40 | +++ b/include/hw/misc/imx7_ccm.h | 26 | +++ b/include/hw/timer/stellaris-gptm.h |
41 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
42 | +/* | 28 | +/* |
43 | + * Copyright (c) 2017, Impinj, Inc. | 29 | + * Luminary Micro Stellaris General Purpose Timer Module |
44 | + * | 30 | + * |
45 | + * i.MX7 CCM, PMU and ANALOG IP blocks emulation code | 31 | + * Copyright (c) 2006 CodeSourcery. |
32 | + * Written by Paul Brook | ||
46 | + * | 33 | + * |
47 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 34 | + * This code is licensed under the GPL. |
48 | + * | ||
49 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
50 | + * See the COPYING file in the top-level directory. | ||
51 | + */ | 35 | + */ |
52 | + | 36 | + |
53 | +#ifndef IMX7_CCM_H | 37 | +#ifndef HW_TIMER_STELLARIS_GPTM_H |
54 | +#define IMX7_CCM_H | 38 | +#define HW_TIMER_STELLARIS_GPTM_H |
55 | + | 39 | + |
56 | +#include "hw/misc/imx_ccm.h" | 40 | +#include "qom/object.h" |
57 | +#include "qemu/bitops.h" | 41 | +#include "hw/sysbus.h" |
58 | + | 42 | +#include "hw/irq.h" |
59 | +enum IMX7AnalogRegisters { | 43 | + |
60 | + ANALOG_PLL_ARM, | 44 | +#define TYPE_STELLARIS_GPTM "stellaris-gptm" |
61 | + ANALOG_PLL_ARM_SET, | 45 | +OBJECT_DECLARE_SIMPLE_TYPE(gptm_state, STELLARIS_GPTM) |
62 | + ANALOG_PLL_ARM_CLR, | 46 | + |
63 | + ANALOG_PLL_ARM_TOG, | 47 | +/* |
64 | + ANALOG_PLL_DDR, | 48 | + * QEMU interface: |
65 | + ANALOG_PLL_DDR_SET, | 49 | + * + sysbus MMIO region 0: register bank |
66 | + ANALOG_PLL_DDR_CLR, | 50 | + * + sysbus IRQ 0: timer interrupt |
67 | + ANALOG_PLL_DDR_TOG, | 51 | + * + unnamed GPIO output 0: trigger output for the ADC |
68 | + ANALOG_PLL_DDR_SS, | 52 | + */ |
69 | + ANALOG_PLL_DDR_SS_SET, | 53 | +struct gptm_state { |
70 | + ANALOG_PLL_DDR_SS_CLR, | 54 | + SysBusDevice parent_obj; |
71 | + ANALOG_PLL_DDR_SS_TOG, | 55 | + |
72 | + ANALOG_PLL_DDR_NUM, | 56 | + MemoryRegion iomem; |
73 | + ANALOG_PLL_DDR_NUM_SET, | 57 | + uint32_t config; |
74 | + ANALOG_PLL_DDR_NUM_CLR, | 58 | + uint32_t mode[2]; |
75 | + ANALOG_PLL_DDR_NUM_TOG, | 59 | + uint32_t control; |
76 | + ANALOG_PLL_DDR_DENOM, | 60 | + uint32_t state; |
77 | + ANALOG_PLL_DDR_DENOM_SET, | 61 | + uint32_t mask; |
78 | + ANALOG_PLL_DDR_DENOM_CLR, | 62 | + uint32_t load[2]; |
79 | + ANALOG_PLL_DDR_DENOM_TOG, | 63 | + uint32_t match[2]; |
80 | + ANALOG_PLL_480, | 64 | + uint32_t prescale[2]; |
81 | + ANALOG_PLL_480_SET, | 65 | + uint32_t match_prescale[2]; |
82 | + ANALOG_PLL_480_CLR, | 66 | + uint32_t rtc; |
83 | + ANALOG_PLL_480_TOG, | 67 | + int64_t tick[2]; |
84 | + ANALOG_PLL_480A, | 68 | + struct gptm_state *opaque[2]; |
85 | + ANALOG_PLL_480A_SET, | 69 | + QEMUTimer *timer[2]; |
86 | + ANALOG_PLL_480A_CLR, | 70 | + /* The timers have an alternate output used to trigger the ADC. */ |
87 | + ANALOG_PLL_480A_TOG, | 71 | + qemu_irq trigger; |
88 | + ANALOG_PLL_480B, | 72 | + qemu_irq irq; |
89 | + ANALOG_PLL_480B_SET, | ||
90 | + ANALOG_PLL_480B_CLR, | ||
91 | + ANALOG_PLL_480B_TOG, | ||
92 | + ANALOG_PLL_ENET, | ||
93 | + ANALOG_PLL_ENET_SET, | ||
94 | + ANALOG_PLL_ENET_CLR, | ||
95 | + ANALOG_PLL_ENET_TOG, | ||
96 | + ANALOG_PLL_AUDIO, | ||
97 | + ANALOG_PLL_AUDIO_SET, | ||
98 | + ANALOG_PLL_AUDIO_CLR, | ||
99 | + ANALOG_PLL_AUDIO_TOG, | ||
100 | + ANALOG_PLL_AUDIO_SS, | ||
101 | + ANALOG_PLL_AUDIO_SS_SET, | ||
102 | + ANALOG_PLL_AUDIO_SS_CLR, | ||
103 | + ANALOG_PLL_AUDIO_SS_TOG, | ||
104 | + ANALOG_PLL_AUDIO_NUM, | ||
105 | + ANALOG_PLL_AUDIO_NUM_SET, | ||
106 | + ANALOG_PLL_AUDIO_NUM_CLR, | ||
107 | + ANALOG_PLL_AUDIO_NUM_TOG, | ||
108 | + ANALOG_PLL_AUDIO_DENOM, | ||
109 | + ANALOG_PLL_AUDIO_DENOM_SET, | ||
110 | + ANALOG_PLL_AUDIO_DENOM_CLR, | ||
111 | + ANALOG_PLL_AUDIO_DENOM_TOG, | ||
112 | + ANALOG_PLL_VIDEO, | ||
113 | + ANALOG_PLL_VIDEO_SET, | ||
114 | + ANALOG_PLL_VIDEO_CLR, | ||
115 | + ANALOG_PLL_VIDEO_TOG, | ||
116 | + ANALOG_PLL_VIDEO_SS, | ||
117 | + ANALOG_PLL_VIDEO_SS_SET, | ||
118 | + ANALOG_PLL_VIDEO_SS_CLR, | ||
119 | + ANALOG_PLL_VIDEO_SS_TOG, | ||
120 | + ANALOG_PLL_VIDEO_NUM, | ||
121 | + ANALOG_PLL_VIDEO_NUM_SET, | ||
122 | + ANALOG_PLL_VIDEO_NUM_CLR, | ||
123 | + ANALOG_PLL_VIDEO_NUM_TOG, | ||
124 | + ANALOG_PLL_VIDEO_DENOM, | ||
125 | + ANALOG_PLL_VIDEO_DENOM_SET, | ||
126 | + ANALOG_PLL_VIDEO_DENOM_CLR, | ||
127 | + ANALOG_PLL_VIDEO_DENOM_TOG, | ||
128 | + ANALOG_PLL_MISC0, | ||
129 | + ANALOG_PLL_MISC0_SET, | ||
130 | + ANALOG_PLL_MISC0_CLR, | ||
131 | + ANALOG_PLL_MISC0_TOG, | ||
132 | + | ||
133 | + ANALOG_DIGPROG = 0x800 / sizeof(uint32_t), | ||
134 | + ANALOG_MAX, | ||
135 | + | ||
136 | + ANALOG_PLL_LOCK = BIT(31) | ||
137 | +}; | 73 | +}; |
138 | + | 74 | + |
139 | +enum IMX7CCMRegisters { | 75 | +#endif |
140 | + CCM_MAX = 0xBE00 / sizeof(uint32_t) + 1, | 76 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c |
141 | +}; | 77 | index XXXXXXX..XXXXXXX 100644 |
142 | + | 78 | --- a/hw/arm/stellaris.c |
143 | +enum IMX7PMURegisters { | 79 | +++ b/hw/arm/stellaris.c |
144 | + PMU_MAX = 0x140 / sizeof(uint32_t), | 80 | @@ -XXX,XX +XXX,XX @@ |
145 | +}; | 81 | #include "hw/watchdog/cmsdk-apb-watchdog.h" |
146 | + | 82 | #include "migration/vmstate.h" |
147 | +#define TYPE_IMX7_CCM "imx7.ccm" | 83 | #include "hw/misc/unimp.h" |
148 | +#define IMX7_CCM(obj) OBJECT_CHECK(IMX7CCMState, (obj), TYPE_IMX7_CCM) | 84 | +#include "hw/timer/stellaris-gptm.h" |
149 | + | 85 | #include "hw/qdev-clock.h" |
150 | +typedef struct IMX7CCMState { | 86 | #include "qom/object.h" |
151 | + /* <private> */ | 87 | |
152 | + IMXCCMState parent_obj; | 88 | @@ -XXX,XX +XXX,XX @@ typedef const struct { |
153 | + | 89 | uint32_t peripherals; |
154 | + /* <public> */ | 90 | } stellaris_board_info; |
155 | + MemoryRegion iomem; | 91 | |
156 | + | 92 | -/* General purpose timer module. */ |
157 | + uint32_t ccm[CCM_MAX]; | 93 | - |
158 | +} IMX7CCMState; | 94 | -#define TYPE_STELLARIS_GPTM "stellaris-gptm" |
159 | + | 95 | -OBJECT_DECLARE_SIMPLE_TYPE(gptm_state, STELLARIS_GPTM) |
160 | + | 96 | - |
161 | +#define TYPE_IMX7_ANALOG "imx7.analog" | 97 | -struct gptm_state { |
162 | +#define IMX7_ANALOG(obj) OBJECT_CHECK(IMX7AnalogState, (obj), TYPE_IMX7_ANALOG) | 98 | - SysBusDevice parent_obj; |
163 | + | 99 | - |
164 | +typedef struct IMX7AnalogState { | 100 | - MemoryRegion iomem; |
165 | + /* <private> */ | 101 | - uint32_t config; |
166 | + IMXCCMState parent_obj; | 102 | - uint32_t mode[2]; |
167 | + | 103 | - uint32_t control; |
168 | + /* <public> */ | 104 | - uint32_t state; |
169 | + struct { | 105 | - uint32_t mask; |
170 | + MemoryRegion container; | 106 | - uint32_t load[2]; |
171 | + MemoryRegion analog; | 107 | - uint32_t match[2]; |
172 | + MemoryRegion digprog; | 108 | - uint32_t prescale[2]; |
173 | + MemoryRegion pmu; | 109 | - uint32_t match_prescale[2]; |
174 | + } mmio; | 110 | - uint32_t rtc; |
175 | + | 111 | - int64_t tick[2]; |
176 | + uint32_t analog[ANALOG_MAX]; | 112 | - struct gptm_state *opaque[2]; |
177 | + uint32_t pmu[PMU_MAX]; | 113 | - QEMUTimer *timer[2]; |
178 | +} IMX7AnalogState; | 114 | - /* The timers have an alternate output used to trigger the ADC. */ |
179 | + | 115 | - qemu_irq trigger; |
180 | +#endif /* IMX7_CCM_H */ | 116 | - qemu_irq irq; |
181 | diff --git a/hw/misc/imx7_ccm.c b/hw/misc/imx7_ccm.c | 117 | -}; |
118 | - | ||
119 | -static void gptm_update_irq(gptm_state *s) | ||
120 | -{ | ||
121 | - int level; | ||
122 | - level = (s->state & s->mask) != 0; | ||
123 | - qemu_set_irq(s->irq, level); | ||
124 | -} | ||
125 | - | ||
126 | -static void gptm_stop(gptm_state *s, int n) | ||
127 | -{ | ||
128 | - timer_del(s->timer[n]); | ||
129 | -} | ||
130 | - | ||
131 | -static void gptm_reload(gptm_state *s, int n, int reset) | ||
132 | -{ | ||
133 | - int64_t tick; | ||
134 | - if (reset) { | ||
135 | - tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
136 | - } else { | ||
137 | - tick = s->tick[n]; | ||
138 | - } | ||
139 | - | ||
140 | - if (s->config == 0) { | ||
141 | - /* 32-bit CountDown. */ | ||
142 | - uint32_t count; | ||
143 | - count = s->load[0] | (s->load[1] << 16); | ||
144 | - tick += (int64_t)count * system_clock_scale; | ||
145 | - } else if (s->config == 1) { | ||
146 | - /* 32-bit RTC. 1Hz tick. */ | ||
147 | - tick += NANOSECONDS_PER_SECOND; | ||
148 | - } else if (s->mode[n] == 0xa) { | ||
149 | - /* PWM mode. Not implemented. */ | ||
150 | - } else { | ||
151 | - qemu_log_mask(LOG_UNIMP, | ||
152 | - "GPTM: 16-bit timer mode unimplemented: 0x%x\n", | ||
153 | - s->mode[n]); | ||
154 | - return; | ||
155 | - } | ||
156 | - s->tick[n] = tick; | ||
157 | - timer_mod(s->timer[n], tick); | ||
158 | -} | ||
159 | - | ||
160 | -static void gptm_tick(void *opaque) | ||
161 | -{ | ||
162 | - gptm_state **p = (gptm_state **)opaque; | ||
163 | - gptm_state *s; | ||
164 | - int n; | ||
165 | - | ||
166 | - s = *p; | ||
167 | - n = p - s->opaque; | ||
168 | - if (s->config == 0) { | ||
169 | - s->state |= 1; | ||
170 | - if ((s->control & 0x20)) { | ||
171 | - /* Output trigger. */ | ||
172 | - qemu_irq_pulse(s->trigger); | ||
173 | - } | ||
174 | - if (s->mode[0] & 1) { | ||
175 | - /* One-shot. */ | ||
176 | - s->control &= ~1; | ||
177 | - } else { | ||
178 | - /* Periodic. */ | ||
179 | - gptm_reload(s, 0, 0); | ||
180 | - } | ||
181 | - } else if (s->config == 1) { | ||
182 | - /* RTC. */ | ||
183 | - uint32_t match; | ||
184 | - s->rtc++; | ||
185 | - match = s->match[0] | (s->match[1] << 16); | ||
186 | - if (s->rtc > match) | ||
187 | - s->rtc = 0; | ||
188 | - if (s->rtc == 0) { | ||
189 | - s->state |= 8; | ||
190 | - } | ||
191 | - gptm_reload(s, 0, 0); | ||
192 | - } else if (s->mode[n] == 0xa) { | ||
193 | - /* PWM mode. Not implemented. */ | ||
194 | - } else { | ||
195 | - qemu_log_mask(LOG_UNIMP, | ||
196 | - "GPTM: 16-bit timer mode unimplemented: 0x%x\n", | ||
197 | - s->mode[n]); | ||
198 | - } | ||
199 | - gptm_update_irq(s); | ||
200 | -} | ||
201 | - | ||
202 | -static uint64_t gptm_read(void *opaque, hwaddr offset, | ||
203 | - unsigned size) | ||
204 | -{ | ||
205 | - gptm_state *s = (gptm_state *)opaque; | ||
206 | - | ||
207 | - switch (offset) { | ||
208 | - case 0x00: /* CFG */ | ||
209 | - return s->config; | ||
210 | - case 0x04: /* TAMR */ | ||
211 | - return s->mode[0]; | ||
212 | - case 0x08: /* TBMR */ | ||
213 | - return s->mode[1]; | ||
214 | - case 0x0c: /* CTL */ | ||
215 | - return s->control; | ||
216 | - case 0x18: /* IMR */ | ||
217 | - return s->mask; | ||
218 | - case 0x1c: /* RIS */ | ||
219 | - return s->state; | ||
220 | - case 0x20: /* MIS */ | ||
221 | - return s->state & s->mask; | ||
222 | - case 0x24: /* CR */ | ||
223 | - return 0; | ||
224 | - case 0x28: /* TAILR */ | ||
225 | - return s->load[0] | ((s->config < 4) ? (s->load[1] << 16) : 0); | ||
226 | - case 0x2c: /* TBILR */ | ||
227 | - return s->load[1]; | ||
228 | - case 0x30: /* TAMARCHR */ | ||
229 | - return s->match[0] | ((s->config < 4) ? (s->match[1] << 16) : 0); | ||
230 | - case 0x34: /* TBMATCHR */ | ||
231 | - return s->match[1]; | ||
232 | - case 0x38: /* TAPR */ | ||
233 | - return s->prescale[0]; | ||
234 | - case 0x3c: /* TBPR */ | ||
235 | - return s->prescale[1]; | ||
236 | - case 0x40: /* TAPMR */ | ||
237 | - return s->match_prescale[0]; | ||
238 | - case 0x44: /* TBPMR */ | ||
239 | - return s->match_prescale[1]; | ||
240 | - case 0x48: /* TAR */ | ||
241 | - if (s->config == 1) { | ||
242 | - return s->rtc; | ||
243 | - } | ||
244 | - qemu_log_mask(LOG_UNIMP, | ||
245 | - "GPTM: read of TAR but timer read not supported\n"); | ||
246 | - return 0; | ||
247 | - case 0x4c: /* TBR */ | ||
248 | - qemu_log_mask(LOG_UNIMP, | ||
249 | - "GPTM: read of TBR but timer read not supported\n"); | ||
250 | - return 0; | ||
251 | - default: | ||
252 | - qemu_log_mask(LOG_GUEST_ERROR, | ||
253 | - "GPTM: read at bad offset 0x02%" HWADDR_PRIx "\n", | ||
254 | - offset); | ||
255 | - return 0; | ||
256 | - } | ||
257 | -} | ||
258 | - | ||
259 | -static void gptm_write(void *opaque, hwaddr offset, | ||
260 | - uint64_t value, unsigned size) | ||
261 | -{ | ||
262 | - gptm_state *s = (gptm_state *)opaque; | ||
263 | - uint32_t oldval; | ||
264 | - | ||
265 | - /* | ||
266 | - * The timers should be disabled before changing the configuration. | ||
267 | - * We take advantage of this and defer everything until the timer | ||
268 | - * is enabled. | ||
269 | - */ | ||
270 | - switch (offset) { | ||
271 | - case 0x00: /* CFG */ | ||
272 | - s->config = value; | ||
273 | - break; | ||
274 | - case 0x04: /* TAMR */ | ||
275 | - s->mode[0] = value; | ||
276 | - break; | ||
277 | - case 0x08: /* TBMR */ | ||
278 | - s->mode[1] = value; | ||
279 | - break; | ||
280 | - case 0x0c: /* CTL */ | ||
281 | - oldval = s->control; | ||
282 | - s->control = value; | ||
283 | - /* TODO: Implement pause. */ | ||
284 | - if ((oldval ^ value) & 1) { | ||
285 | - if (value & 1) { | ||
286 | - gptm_reload(s, 0, 1); | ||
287 | - } else { | ||
288 | - gptm_stop(s, 0); | ||
289 | - } | ||
290 | - } | ||
291 | - if (((oldval ^ value) & 0x100) && s->config >= 4) { | ||
292 | - if (value & 0x100) { | ||
293 | - gptm_reload(s, 1, 1); | ||
294 | - } else { | ||
295 | - gptm_stop(s, 1); | ||
296 | - } | ||
297 | - } | ||
298 | - break; | ||
299 | - case 0x18: /* IMR */ | ||
300 | - s->mask = value & 0x77; | ||
301 | - gptm_update_irq(s); | ||
302 | - break; | ||
303 | - case 0x24: /* CR */ | ||
304 | - s->state &= ~value; | ||
305 | - break; | ||
306 | - case 0x28: /* TAILR */ | ||
307 | - s->load[0] = value & 0xffff; | ||
308 | - if (s->config < 4) { | ||
309 | - s->load[1] = value >> 16; | ||
310 | - } | ||
311 | - break; | ||
312 | - case 0x2c: /* TBILR */ | ||
313 | - s->load[1] = value & 0xffff; | ||
314 | - break; | ||
315 | - case 0x30: /* TAMARCHR */ | ||
316 | - s->match[0] = value & 0xffff; | ||
317 | - if (s->config < 4) { | ||
318 | - s->match[1] = value >> 16; | ||
319 | - } | ||
320 | - break; | ||
321 | - case 0x34: /* TBMATCHR */ | ||
322 | - s->match[1] = value >> 16; | ||
323 | - break; | ||
324 | - case 0x38: /* TAPR */ | ||
325 | - s->prescale[0] = value; | ||
326 | - break; | ||
327 | - case 0x3c: /* TBPR */ | ||
328 | - s->prescale[1] = value; | ||
329 | - break; | ||
330 | - case 0x40: /* TAPMR */ | ||
331 | - s->match_prescale[0] = value; | ||
332 | - break; | ||
333 | - case 0x44: /* TBPMR */ | ||
334 | - s->match_prescale[0] = value; | ||
335 | - break; | ||
336 | - default: | ||
337 | - qemu_log_mask(LOG_GUEST_ERROR, | ||
338 | - "GPTM: write at bad offset 0x02%" HWADDR_PRIx "\n", | ||
339 | - offset); | ||
340 | - } | ||
341 | - gptm_update_irq(s); | ||
342 | -} | ||
343 | - | ||
344 | -static const MemoryRegionOps gptm_ops = { | ||
345 | - .read = gptm_read, | ||
346 | - .write = gptm_write, | ||
347 | - .endianness = DEVICE_NATIVE_ENDIAN, | ||
348 | -}; | ||
349 | - | ||
350 | -static const VMStateDescription vmstate_stellaris_gptm = { | ||
351 | - .name = "stellaris_gptm", | ||
352 | - .version_id = 1, | ||
353 | - .minimum_version_id = 1, | ||
354 | - .fields = (VMStateField[]) { | ||
355 | - VMSTATE_UINT32(config, gptm_state), | ||
356 | - VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), | ||
357 | - VMSTATE_UINT32(control, gptm_state), | ||
358 | - VMSTATE_UINT32(state, gptm_state), | ||
359 | - VMSTATE_UINT32(mask, gptm_state), | ||
360 | - VMSTATE_UNUSED(8), | ||
361 | - VMSTATE_UINT32_ARRAY(load, gptm_state, 2), | ||
362 | - VMSTATE_UINT32_ARRAY(match, gptm_state, 2), | ||
363 | - VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2), | ||
364 | - VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2), | ||
365 | - VMSTATE_UINT32(rtc, gptm_state), | ||
366 | - VMSTATE_INT64_ARRAY(tick, gptm_state, 2), | ||
367 | - VMSTATE_TIMER_PTR_ARRAY(timer, gptm_state, 2), | ||
368 | - VMSTATE_END_OF_LIST() | ||
369 | - } | ||
370 | -}; | ||
371 | - | ||
372 | -static void stellaris_gptm_init(Object *obj) | ||
373 | -{ | ||
374 | - DeviceState *dev = DEVICE(obj); | ||
375 | - gptm_state *s = STELLARIS_GPTM(obj); | ||
376 | - SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
377 | - | ||
378 | - sysbus_init_irq(sbd, &s->irq); | ||
379 | - qdev_init_gpio_out(dev, &s->trigger, 1); | ||
380 | - | ||
381 | - memory_region_init_io(&s->iomem, obj, &gptm_ops, s, | ||
382 | - "gptm", 0x1000); | ||
383 | - sysbus_init_mmio(sbd, &s->iomem); | ||
384 | - | ||
385 | - s->opaque[0] = s->opaque[1] = s; | ||
386 | -} | ||
387 | - | ||
388 | -static void stellaris_gptm_realize(DeviceState *dev, Error **errp) | ||
389 | -{ | ||
390 | - gptm_state *s = STELLARIS_GPTM(dev); | ||
391 | - s->timer[0] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[0]); | ||
392 | - s->timer[1] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[1]); | ||
393 | -} | ||
394 | - | ||
395 | /* System controller. */ | ||
396 | |||
397 | #define TYPE_STELLARIS_SYS "stellaris-sys" | ||
398 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo stellaris_i2c_info = { | ||
399 | .class_init = stellaris_i2c_class_init, | ||
400 | }; | ||
401 | |||
402 | -static void stellaris_gptm_class_init(ObjectClass *klass, void *data) | ||
403 | -{ | ||
404 | - DeviceClass *dc = DEVICE_CLASS(klass); | ||
405 | - | ||
406 | - dc->vmsd = &vmstate_stellaris_gptm; | ||
407 | - dc->realize = stellaris_gptm_realize; | ||
408 | -} | ||
409 | - | ||
410 | -static const TypeInfo stellaris_gptm_info = { | ||
411 | - .name = TYPE_STELLARIS_GPTM, | ||
412 | - .parent = TYPE_SYS_BUS_DEVICE, | ||
413 | - .instance_size = sizeof(gptm_state), | ||
414 | - .instance_init = stellaris_gptm_init, | ||
415 | - .class_init = stellaris_gptm_class_init, | ||
416 | -}; | ||
417 | - | ||
418 | static void stellaris_adc_class_init(ObjectClass *klass, void *data) | ||
419 | { | ||
420 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
421 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo stellaris_sys_info = { | ||
422 | static void stellaris_register_types(void) | ||
423 | { | ||
424 | type_register_static(&stellaris_i2c_info); | ||
425 | - type_register_static(&stellaris_gptm_info); | ||
426 | type_register_static(&stellaris_adc_info); | ||
427 | type_register_static(&stellaris_sys_info); | ||
428 | } | ||
429 | diff --git a/hw/timer/stellaris-gptm.c b/hw/timer/stellaris-gptm.c | ||
182 | new file mode 100644 | 430 | new file mode 100644 |
183 | index XXXXXXX..XXXXXXX | 431 | index XXXXXXX..XXXXXXX |
184 | --- /dev/null | 432 | --- /dev/null |
185 | +++ b/hw/misc/imx7_ccm.c | 433 | +++ b/hw/timer/stellaris-gptm.c |
186 | @@ -XXX,XX +XXX,XX @@ | 434 | @@ -XXX,XX +XXX,XX @@ |
187 | +/* | 435 | +/* |
188 | + * Copyright (c) 2018, Impinj, Inc. | 436 | + * Luminary Micro Stellaris General Purpose Timer Module |
189 | + * | 437 | + * |
190 | + * i.MX7 CCM, PMU and ANALOG IP blocks emulation code | 438 | + * Copyright (c) 2006 CodeSourcery. |
439 | + * Written by Paul Brook | ||
191 | + * | 440 | + * |
192 | + * Author: Andrey Smirnov <andrew.smirnov@gmail.com> | 441 | + * This code is licensed under the GPL. |
193 | + * | ||
194 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
195 | + * See the COPYING file in the top-level directory. | ||
196 | + */ | 442 | + */ |
197 | + | 443 | + |
198 | +#include "qemu/osdep.h" | 444 | +#include "qemu/osdep.h" |
199 | +#include "qemu/log.h" | 445 | +#include "qemu/log.h" |
200 | + | 446 | +#include "qemu/timer.h" |
201 | +#include "hw/misc/imx7_ccm.h" | 447 | +#include "migration/vmstate.h" |
202 | + | 448 | +#include "hw/timer/stellaris-gptm.h" |
203 | +static void imx7_analog_reset(DeviceState *dev) | 449 | +#include "hw/timer/armv7m_systick.h" /* Needed only for system_clock_scale */ |
204 | +{ | 450 | + |
205 | + IMX7AnalogState *s = IMX7_ANALOG(dev); | 451 | +static void gptm_update_irq(gptm_state *s) |
206 | + | 452 | +{ |
207 | + memset(s->pmu, 0, sizeof(s->pmu)); | 453 | + int level; |
208 | + memset(s->analog, 0, sizeof(s->analog)); | 454 | + level = (s->state & s->mask) != 0; |
209 | + | 455 | + qemu_set_irq(s->irq, level); |
210 | + s->analog[ANALOG_PLL_ARM] = 0x00002042; | 456 | +} |
211 | + s->analog[ANALOG_PLL_DDR] = 0x0060302c; | 457 | + |
212 | + s->analog[ANALOG_PLL_DDR_SS] = 0x00000000; | 458 | +static void gptm_stop(gptm_state *s, int n) |
213 | + s->analog[ANALOG_PLL_DDR_NUM] = 0x06aaac4d; | 459 | +{ |
214 | + s->analog[ANALOG_PLL_DDR_DENOM] = 0x100003ec; | 460 | + timer_del(s->timer[n]); |
215 | + s->analog[ANALOG_PLL_480] = 0x00002000; | 461 | +} |
216 | + s->analog[ANALOG_PLL_480A] = 0x52605a56; | 462 | + |
217 | + s->analog[ANALOG_PLL_480B] = 0x52525216; | 463 | +static void gptm_reload(gptm_state *s, int n, int reset) |
218 | + s->analog[ANALOG_PLL_ENET] = 0x00001fc0; | 464 | +{ |
219 | + s->analog[ANALOG_PLL_AUDIO] = 0x0001301b; | 465 | + int64_t tick; |
220 | + s->analog[ANALOG_PLL_AUDIO_SS] = 0x00000000; | 466 | + if (reset) { |
221 | + s->analog[ANALOG_PLL_AUDIO_NUM] = 0x05f5e100; | 467 | + tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
222 | + s->analog[ANALOG_PLL_AUDIO_DENOM] = 0x2964619c; | 468 | + } else { |
223 | + s->analog[ANALOG_PLL_VIDEO] = 0x0008201b; | 469 | + tick = s->tick[n]; |
224 | + s->analog[ANALOG_PLL_VIDEO_SS] = 0x00000000; | 470 | + } |
225 | + s->analog[ANALOG_PLL_VIDEO_NUM] = 0x0000f699; | 471 | + |
226 | + s->analog[ANALOG_PLL_VIDEO_DENOM] = 0x000f4240; | 472 | + if (s->config == 0) { |
227 | + s->analog[ANALOG_PLL_MISC0] = 0x00000000; | 473 | + /* 32-bit CountDown. */ |
228 | + | 474 | + uint32_t count; |
229 | + /* all PLLs need to be locked */ | 475 | + count = s->load[0] | (s->load[1] << 16); |
230 | + s->analog[ANALOG_PLL_ARM] |= ANALOG_PLL_LOCK; | 476 | + tick += (int64_t)count * system_clock_scale; |
231 | + s->analog[ANALOG_PLL_DDR] |= ANALOG_PLL_LOCK; | 477 | + } else if (s->config == 1) { |
232 | + s->analog[ANALOG_PLL_480] |= ANALOG_PLL_LOCK; | 478 | + /* 32-bit RTC. 1Hz tick. */ |
233 | + s->analog[ANALOG_PLL_480A] |= ANALOG_PLL_LOCK; | 479 | + tick += NANOSECONDS_PER_SECOND; |
234 | + s->analog[ANALOG_PLL_480B] |= ANALOG_PLL_LOCK; | 480 | + } else if (s->mode[n] == 0xa) { |
235 | + s->analog[ANALOG_PLL_ENET] |= ANALOG_PLL_LOCK; | 481 | + /* PWM mode. Not implemented. */ |
236 | + s->analog[ANALOG_PLL_AUDIO] |= ANALOG_PLL_LOCK; | 482 | + } else { |
237 | + s->analog[ANALOG_PLL_VIDEO] |= ANALOG_PLL_LOCK; | 483 | + qemu_log_mask(LOG_UNIMP, |
238 | + s->analog[ANALOG_PLL_MISC0] |= ANALOG_PLL_LOCK; | 484 | + "GPTM: 16-bit timer mode unimplemented: 0x%x\n", |
485 | + s->mode[n]); | ||
486 | + return; | ||
487 | + } | ||
488 | + s->tick[n] = tick; | ||
489 | + timer_mod(s->timer[n], tick); | ||
490 | +} | ||
491 | + | ||
492 | +static void gptm_tick(void *opaque) | ||
493 | +{ | ||
494 | + gptm_state **p = (gptm_state **)opaque; | ||
495 | + gptm_state *s; | ||
496 | + int n; | ||
497 | + | ||
498 | + s = *p; | ||
499 | + n = p - s->opaque; | ||
500 | + if (s->config == 0) { | ||
501 | + s->state |= 1; | ||
502 | + if ((s->control & 0x20)) { | ||
503 | + /* Output trigger. */ | ||
504 | + qemu_irq_pulse(s->trigger); | ||
505 | + } | ||
506 | + if (s->mode[0] & 1) { | ||
507 | + /* One-shot. */ | ||
508 | + s->control &= ~1; | ||
509 | + } else { | ||
510 | + /* Periodic. */ | ||
511 | + gptm_reload(s, 0, 0); | ||
512 | + } | ||
513 | + } else if (s->config == 1) { | ||
514 | + /* RTC. */ | ||
515 | + uint32_t match; | ||
516 | + s->rtc++; | ||
517 | + match = s->match[0] | (s->match[1] << 16); | ||
518 | + if (s->rtc > match) | ||
519 | + s->rtc = 0; | ||
520 | + if (s->rtc == 0) { | ||
521 | + s->state |= 8; | ||
522 | + } | ||
523 | + gptm_reload(s, 0, 0); | ||
524 | + } else if (s->mode[n] == 0xa) { | ||
525 | + /* PWM mode. Not implemented. */ | ||
526 | + } else { | ||
527 | + qemu_log_mask(LOG_UNIMP, | ||
528 | + "GPTM: 16-bit timer mode unimplemented: 0x%x\n", | ||
529 | + s->mode[n]); | ||
530 | + } | ||
531 | + gptm_update_irq(s); | ||
532 | +} | ||
533 | + | ||
534 | +static uint64_t gptm_read(void *opaque, hwaddr offset, | ||
535 | + unsigned size) | ||
536 | +{ | ||
537 | + gptm_state *s = (gptm_state *)opaque; | ||
538 | + | ||
539 | + switch (offset) { | ||
540 | + case 0x00: /* CFG */ | ||
541 | + return s->config; | ||
542 | + case 0x04: /* TAMR */ | ||
543 | + return s->mode[0]; | ||
544 | + case 0x08: /* TBMR */ | ||
545 | + return s->mode[1]; | ||
546 | + case 0x0c: /* CTL */ | ||
547 | + return s->control; | ||
548 | + case 0x18: /* IMR */ | ||
549 | + return s->mask; | ||
550 | + case 0x1c: /* RIS */ | ||
551 | + return s->state; | ||
552 | + case 0x20: /* MIS */ | ||
553 | + return s->state & s->mask; | ||
554 | + case 0x24: /* CR */ | ||
555 | + return 0; | ||
556 | + case 0x28: /* TAILR */ | ||
557 | + return s->load[0] | ((s->config < 4) ? (s->load[1] << 16) : 0); | ||
558 | + case 0x2c: /* TBILR */ | ||
559 | + return s->load[1]; | ||
560 | + case 0x30: /* TAMARCHR */ | ||
561 | + return s->match[0] | ((s->config < 4) ? (s->match[1] << 16) : 0); | ||
562 | + case 0x34: /* TBMATCHR */ | ||
563 | + return s->match[1]; | ||
564 | + case 0x38: /* TAPR */ | ||
565 | + return s->prescale[0]; | ||
566 | + case 0x3c: /* TBPR */ | ||
567 | + return s->prescale[1]; | ||
568 | + case 0x40: /* TAPMR */ | ||
569 | + return s->match_prescale[0]; | ||
570 | + case 0x44: /* TBPMR */ | ||
571 | + return s->match_prescale[1]; | ||
572 | + case 0x48: /* TAR */ | ||
573 | + if (s->config == 1) { | ||
574 | + return s->rtc; | ||
575 | + } | ||
576 | + qemu_log_mask(LOG_UNIMP, | ||
577 | + "GPTM: read of TAR but timer read not supported\n"); | ||
578 | + return 0; | ||
579 | + case 0x4c: /* TBR */ | ||
580 | + qemu_log_mask(LOG_UNIMP, | ||
581 | + "GPTM: read of TBR but timer read not supported\n"); | ||
582 | + return 0; | ||
583 | + default: | ||
584 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
585 | + "GPTM: read at bad offset 0x02%" HWADDR_PRIx "\n", | ||
586 | + offset); | ||
587 | + return 0; | ||
588 | + } | ||
589 | +} | ||
590 | + | ||
591 | +static void gptm_write(void *opaque, hwaddr offset, | ||
592 | + uint64_t value, unsigned size) | ||
593 | +{ | ||
594 | + gptm_state *s = (gptm_state *)opaque; | ||
595 | + uint32_t oldval; | ||
239 | + | 596 | + |
240 | + /* | 597 | + /* |
241 | + * Since I couldn't find any info about this in the reference | 598 | + * The timers should be disabled before changing the configuration. |
242 | + * manual the value of this register is based strictly on matching | 599 | + * We take advantage of this and defer everything until the timer |
243 | + * what Linux kernel expects it to be. | 600 | + * is enabled. |
244 | + */ | 601 | + */ |
245 | + s->analog[ANALOG_DIGPROG] = 0x720000; | 602 | + switch (offset) { |
246 | + /* | 603 | + case 0x00: /* CFG */ |
247 | + * Set revision to be 1.0 (Arbitrary choice, no particular | 604 | + s->config = value; |
248 | + * reason). | 605 | + break; |
249 | + */ | 606 | + case 0x04: /* TAMR */ |
250 | + s->analog[ANALOG_DIGPROG] |= 0x000010; | 607 | + s->mode[0] = value; |
251 | +} | 608 | + break; |
252 | + | 609 | + case 0x08: /* TBMR */ |
253 | +static void imx7_ccm_reset(DeviceState *dev) | 610 | + s->mode[1] = value; |
254 | +{ | 611 | + break; |
255 | + IMX7CCMState *s = IMX7_CCM(dev); | 612 | + case 0x0c: /* CTL */ |
256 | + | 613 | + oldval = s->control; |
257 | + memset(s->ccm, 0, sizeof(s->ccm)); | 614 | + s->control = value; |
258 | +} | 615 | + /* TODO: Implement pause. */ |
259 | + | 616 | + if ((oldval ^ value) & 1) { |
260 | +#define CCM_INDEX(offset) (((offset) & ~(hwaddr)0xF) / sizeof(uint32_t)) | 617 | + if (value & 1) { |
261 | +#define CCM_BITOP(offset) ((offset) & (hwaddr)0xF) | 618 | + gptm_reload(s, 0, 1); |
262 | + | 619 | + } else { |
263 | +enum { | 620 | + gptm_stop(s, 0); |
264 | + CCM_BITOP_NONE = 0x00, | 621 | + } |
265 | + CCM_BITOP_SET = 0x04, | 622 | + } |
266 | + CCM_BITOP_CLR = 0x08, | 623 | + if (((oldval ^ value) & 0x100) && s->config >= 4) { |
267 | + CCM_BITOP_TOG = 0x0C, | 624 | + if (value & 0x100) { |
625 | + gptm_reload(s, 1, 1); | ||
626 | + } else { | ||
627 | + gptm_stop(s, 1); | ||
628 | + } | ||
629 | + } | ||
630 | + break; | ||
631 | + case 0x18: /* IMR */ | ||
632 | + s->mask = value & 0x77; | ||
633 | + gptm_update_irq(s); | ||
634 | + break; | ||
635 | + case 0x24: /* CR */ | ||
636 | + s->state &= ~value; | ||
637 | + break; | ||
638 | + case 0x28: /* TAILR */ | ||
639 | + s->load[0] = value & 0xffff; | ||
640 | + if (s->config < 4) { | ||
641 | + s->load[1] = value >> 16; | ||
642 | + } | ||
643 | + break; | ||
644 | + case 0x2c: /* TBILR */ | ||
645 | + s->load[1] = value & 0xffff; | ||
646 | + break; | ||
647 | + case 0x30: /* TAMARCHR */ | ||
648 | + s->match[0] = value & 0xffff; | ||
649 | + if (s->config < 4) { | ||
650 | + s->match[1] = value >> 16; | ||
651 | + } | ||
652 | + break; | ||
653 | + case 0x34: /* TBMATCHR */ | ||
654 | + s->match[1] = value >> 16; | ||
655 | + break; | ||
656 | + case 0x38: /* TAPR */ | ||
657 | + s->prescale[0] = value; | ||
658 | + break; | ||
659 | + case 0x3c: /* TBPR */ | ||
660 | + s->prescale[1] = value; | ||
661 | + break; | ||
662 | + case 0x40: /* TAPMR */ | ||
663 | + s->match_prescale[0] = value; | ||
664 | + break; | ||
665 | + case 0x44: /* TBPMR */ | ||
666 | + s->match_prescale[0] = value; | ||
667 | + break; | ||
668 | + default: | ||
669 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
670 | + "GPTM: write at bad offset 0x02%" HWADDR_PRIx "\n", | ||
671 | + offset); | ||
672 | + } | ||
673 | + gptm_update_irq(s); | ||
674 | +} | ||
675 | + | ||
676 | +static const MemoryRegionOps gptm_ops = { | ||
677 | + .read = gptm_read, | ||
678 | + .write = gptm_write, | ||
679 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
268 | +}; | 680 | +}; |
269 | + | 681 | + |
270 | +static uint64_t imx7_set_clr_tog_read(void *opaque, hwaddr offset, | 682 | +static const VMStateDescription vmstate_stellaris_gptm = { |
271 | + unsigned size) | 683 | + .name = "stellaris_gptm", |
272 | +{ | ||
273 | + const uint32_t *mmio = opaque; | ||
274 | + | ||
275 | + return mmio[CCM_INDEX(offset)]; | ||
276 | +} | ||
277 | + | ||
278 | +static void imx7_set_clr_tog_write(void *opaque, hwaddr offset, | ||
279 | + uint64_t value, unsigned size) | ||
280 | +{ | ||
281 | + const uint8_t bitop = CCM_BITOP(offset); | ||
282 | + const uint32_t index = CCM_INDEX(offset); | ||
283 | + uint32_t *mmio = opaque; | ||
284 | + | ||
285 | + switch (bitop) { | ||
286 | + case CCM_BITOP_NONE: | ||
287 | + mmio[index] = value; | ||
288 | + break; | ||
289 | + case CCM_BITOP_SET: | ||
290 | + mmio[index] |= value; | ||
291 | + break; | ||
292 | + case CCM_BITOP_CLR: | ||
293 | + mmio[index] &= ~value; | ||
294 | + break; | ||
295 | + case CCM_BITOP_TOG: | ||
296 | + mmio[index] ^= value; | ||
297 | + break; | ||
298 | + }; | ||
299 | +} | ||
300 | + | ||
301 | +static const struct MemoryRegionOps imx7_set_clr_tog_ops = { | ||
302 | + .read = imx7_set_clr_tog_read, | ||
303 | + .write = imx7_set_clr_tog_write, | ||
304 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
305 | + .impl = { | ||
306 | + /* | ||
307 | + * Our device would not work correctly if the guest was doing | ||
308 | + * unaligned access. This might not be a limitation on the real | ||
309 | + * device but in practice there is no reason for a guest to access | ||
310 | + * this device unaligned. | ||
311 | + */ | ||
312 | + .min_access_size = 4, | ||
313 | + .max_access_size = 4, | ||
314 | + .unaligned = false, | ||
315 | + }, | ||
316 | +}; | ||
317 | + | ||
318 | +static const struct MemoryRegionOps imx7_digprog_ops = { | ||
319 | + .read = imx7_set_clr_tog_read, | ||
320 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
321 | + .impl = { | ||
322 | + .min_access_size = 4, | ||
323 | + .max_access_size = 4, | ||
324 | + .unaligned = false, | ||
325 | + }, | ||
326 | +}; | ||
327 | + | ||
328 | +static void imx7_ccm_init(Object *obj) | ||
329 | +{ | ||
330 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
331 | + IMX7CCMState *s = IMX7_CCM(obj); | ||
332 | + | ||
333 | + memory_region_init_io(&s->iomem, | ||
334 | + obj, | ||
335 | + &imx7_set_clr_tog_ops, | ||
336 | + s->ccm, | ||
337 | + TYPE_IMX7_CCM ".ccm", | ||
338 | + sizeof(s->ccm)); | ||
339 | + | ||
340 | + sysbus_init_mmio(sd, &s->iomem); | ||
341 | +} | ||
342 | + | ||
343 | +static void imx7_analog_init(Object *obj) | ||
344 | +{ | ||
345 | + SysBusDevice *sd = SYS_BUS_DEVICE(obj); | ||
346 | + IMX7AnalogState *s = IMX7_ANALOG(obj); | ||
347 | + | ||
348 | + memory_region_init(&s->mmio.container, obj, TYPE_IMX7_ANALOG, | ||
349 | + 0x10000); | ||
350 | + | ||
351 | + memory_region_init_io(&s->mmio.analog, | ||
352 | + obj, | ||
353 | + &imx7_set_clr_tog_ops, | ||
354 | + s->analog, | ||
355 | + TYPE_IMX7_ANALOG, | ||
356 | + sizeof(s->analog)); | ||
357 | + | ||
358 | + memory_region_add_subregion(&s->mmio.container, | ||
359 | + 0x60, &s->mmio.analog); | ||
360 | + | ||
361 | + memory_region_init_io(&s->mmio.pmu, | ||
362 | + obj, | ||
363 | + &imx7_set_clr_tog_ops, | ||
364 | + s->pmu, | ||
365 | + TYPE_IMX7_ANALOG ".pmu", | ||
366 | + sizeof(s->pmu)); | ||
367 | + | ||
368 | + memory_region_add_subregion(&s->mmio.container, | ||
369 | + 0x200, &s->mmio.pmu); | ||
370 | + | ||
371 | + memory_region_init_io(&s->mmio.digprog, | ||
372 | + obj, | ||
373 | + &imx7_digprog_ops, | ||
374 | + &s->analog[ANALOG_DIGPROG], | ||
375 | + TYPE_IMX7_ANALOG ".digprog", | ||
376 | + sizeof(uint32_t)); | ||
377 | + | ||
378 | + memory_region_add_subregion_overlap(&s->mmio.container, | ||
379 | + 0x800, &s->mmio.digprog, 10); | ||
380 | + | ||
381 | + | ||
382 | + sysbus_init_mmio(sd, &s->mmio.container); | ||
383 | +} | ||
384 | + | ||
385 | +static const VMStateDescription vmstate_imx7_ccm = { | ||
386 | + .name = TYPE_IMX7_CCM, | ||
387 | + .version_id = 1, | 684 | + .version_id = 1, |
388 | + .minimum_version_id = 1, | 685 | + .minimum_version_id = 1, |
389 | + .fields = (VMStateField[]) { | 686 | + .fields = (VMStateField[]) { |
390 | + VMSTATE_UINT32_ARRAY(ccm, IMX7CCMState, CCM_MAX), | 687 | + VMSTATE_UINT32(config, gptm_state), |
688 | + VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), | ||
689 | + VMSTATE_UINT32(control, gptm_state), | ||
690 | + VMSTATE_UINT32(state, gptm_state), | ||
691 | + VMSTATE_UINT32(mask, gptm_state), | ||
692 | + VMSTATE_UNUSED(8), | ||
693 | + VMSTATE_UINT32_ARRAY(load, gptm_state, 2), | ||
694 | + VMSTATE_UINT32_ARRAY(match, gptm_state, 2), | ||
695 | + VMSTATE_UINT32_ARRAY(prescale, gptm_state, 2), | ||
696 | + VMSTATE_UINT32_ARRAY(match_prescale, gptm_state, 2), | ||
697 | + VMSTATE_UINT32(rtc, gptm_state), | ||
698 | + VMSTATE_INT64_ARRAY(tick, gptm_state, 2), | ||
699 | + VMSTATE_TIMER_PTR_ARRAY(timer, gptm_state, 2), | ||
391 | + VMSTATE_END_OF_LIST() | 700 | + VMSTATE_END_OF_LIST() |
392 | + }, | 701 | + } |
393 | +}; | 702 | +}; |
394 | + | 703 | + |
395 | +static uint32_t imx7_ccm_get_clock_frequency(IMXCCMState *dev, IMXClk clock) | 704 | +static void stellaris_gptm_init(Object *obj) |
396 | +{ | 705 | +{ |
397 | + /* | 706 | + DeviceState *dev = DEVICE(obj); |
398 | + * This function is "consumed" by GPT emulation code, however on | 707 | + gptm_state *s = STELLARIS_GPTM(obj); |
399 | + * i.MX7 each GPT block can have their own clock root. This means | 708 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); |
400 | + * that this functions needs somehow to know requester's identity | 709 | + |
401 | + * and the way to pass it: be it via additional IMXClk constants | 710 | + sysbus_init_irq(sbd, &s->irq); |
402 | + * or by adding another argument to this method needs to be | 711 | + qdev_init_gpio_out(dev, &s->trigger, 1); |
403 | + * figured out | 712 | + |
404 | + */ | 713 | + memory_region_init_io(&s->iomem, obj, &gptm_ops, s, |
405 | + qemu_log_mask(LOG_GUEST_ERROR, "[%s]%s: Not implemented\n", | 714 | + "gptm", 0x1000); |
406 | + TYPE_IMX7_CCM, __func__); | 715 | + sysbus_init_mmio(sbd, &s->iomem); |
407 | + return 0; | 716 | + |
408 | +} | 717 | + s->opaque[0] = s->opaque[1] = s; |
409 | + | 718 | +} |
410 | +static void imx7_ccm_class_init(ObjectClass *klass, void *data) | 719 | + |
720 | +static void stellaris_gptm_realize(DeviceState *dev, Error **errp) | ||
721 | +{ | ||
722 | + gptm_state *s = STELLARIS_GPTM(dev); | ||
723 | + s->timer[0] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[0]); | ||
724 | + s->timer[1] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[1]); | ||
725 | +} | ||
726 | + | ||
727 | +static void stellaris_gptm_class_init(ObjectClass *klass, void *data) | ||
411 | +{ | 728 | +{ |
412 | + DeviceClass *dc = DEVICE_CLASS(klass); | 729 | + DeviceClass *dc = DEVICE_CLASS(klass); |
413 | + IMXCCMClass *ccm = IMX_CCM_CLASS(klass); | 730 | + |
414 | + | 731 | + dc->vmsd = &vmstate_stellaris_gptm; |
415 | + dc->reset = imx7_ccm_reset; | 732 | + dc->realize = stellaris_gptm_realize; |
416 | + dc->vmsd = &vmstate_imx7_ccm; | 733 | +} |
417 | + dc->desc = "i.MX7 Clock Control Module"; | 734 | + |
418 | + | 735 | +static const TypeInfo stellaris_gptm_info = { |
419 | + ccm->get_clock_frequency = imx7_ccm_get_clock_frequency; | 736 | + .name = TYPE_STELLARIS_GPTM, |
420 | +} | 737 | + .parent = TYPE_SYS_BUS_DEVICE, |
421 | + | 738 | + .instance_size = sizeof(gptm_state), |
422 | +static const TypeInfo imx7_ccm_info = { | 739 | + .instance_init = stellaris_gptm_init, |
423 | + .name = TYPE_IMX7_CCM, | 740 | + .class_init = stellaris_gptm_class_init, |
424 | + .parent = TYPE_IMX_CCM, | ||
425 | + .instance_size = sizeof(IMX7CCMState), | ||
426 | + .instance_init = imx7_ccm_init, | ||
427 | + .class_init = imx7_ccm_class_init, | ||
428 | +}; | 741 | +}; |
429 | + | 742 | + |
430 | +static const VMStateDescription vmstate_imx7_analog = { | 743 | +static void stellaris_gptm_register_types(void) |
431 | + .name = TYPE_IMX7_ANALOG, | 744 | +{ |
432 | + .version_id = 1, | 745 | + type_register_static(&stellaris_gptm_info); |
433 | + .minimum_version_id = 1, | 746 | +} |
434 | + .fields = (VMStateField[]) { | 747 | + |
435 | + VMSTATE_UINT32_ARRAY(analog, IMX7AnalogState, ANALOG_MAX), | 748 | +type_init(stellaris_gptm_register_types) |
436 | + VMSTATE_UINT32_ARRAY(pmu, IMX7AnalogState, PMU_MAX), | 749 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig |
437 | + VMSTATE_END_OF_LIST() | 750 | index XXXXXXX..XXXXXXX 100644 |
438 | + }, | 751 | --- a/hw/arm/Kconfig |
439 | +}; | 752 | +++ b/hw/arm/Kconfig |
440 | + | 753 | @@ -XXX,XX +XXX,XX @@ config STELLARIS |
441 | +static void imx7_analog_class_init(ObjectClass *klass, void *data) | 754 | select SSI_SD |
442 | +{ | 755 | select STELLARIS_INPUT |
443 | + DeviceClass *dc = DEVICE_CLASS(klass); | 756 | select STELLARIS_ENET # ethernet |
444 | + | 757 | + select STELLARIS_GPTM # general purpose timer module |
445 | + dc->reset = imx7_analog_reset; | 758 | select UNIMP |
446 | + dc->vmsd = &vmstate_imx7_analog; | 759 | |
447 | + dc->desc = "i.MX7 Analog Module"; | 760 | config STM32VLDISCOVERY |
448 | +} | 761 | diff --git a/hw/timer/Kconfig b/hw/timer/Kconfig |
449 | + | 762 | index XXXXXXX..XXXXXXX 100644 |
450 | +static const TypeInfo imx7_analog_info = { | 763 | --- a/hw/timer/Kconfig |
451 | + .name = TYPE_IMX7_ANALOG, | 764 | +++ b/hw/timer/Kconfig |
452 | + .parent = TYPE_SYS_BUS_DEVICE, | 765 | @@ -XXX,XX +XXX,XX @@ config SSE_COUNTER |
453 | + .instance_size = sizeof(IMX7AnalogState), | 766 | config SSE_TIMER |
454 | + .instance_init = imx7_analog_init, | 767 | bool |
455 | + .class_init = imx7_analog_class_init, | 768 | |
456 | +}; | 769 | +config STELLARIS_GPTM |
457 | + | 770 | + bool |
458 | +static void imx7_ccm_register_type(void) | 771 | + |
459 | +{ | 772 | config AVR_TIMER16 |
460 | + type_register_static(&imx7_ccm_info); | 773 | bool |
461 | + type_register_static(&imx7_analog_info); | 774 | diff --git a/hw/timer/meson.build b/hw/timer/meson.build |
462 | +} | 775 | index XXXXXXX..XXXXXXX 100644 |
463 | +type_init(imx7_ccm_register_type) | 776 | --- a/hw/timer/meson.build |
777 | +++ b/hw/timer/meson.build | ||
778 | @@ -XXX,XX +XXX,XX @@ softmmu_ss.add(when: 'CONFIG_SH_TIMER', if_true: files('sh_timer.c')) | ||
779 | softmmu_ss.add(when: 'CONFIG_SLAVIO', if_true: files('slavio_timer.c')) | ||
780 | softmmu_ss.add(when: 'CONFIG_SSE_COUNTER', if_true: files('sse-counter.c')) | ||
781 | softmmu_ss.add(when: 'CONFIG_SSE_TIMER', if_true: files('sse-timer.c')) | ||
782 | +softmmu_ss.add(when: 'CONFIG_STELLARIS_GPTM', if_true: files('stellaris-gptm.c')) | ||
783 | softmmu_ss.add(when: 'CONFIG_STM32F2XX_TIMER', if_true: files('stm32f2xx_timer.c')) | ||
784 | softmmu_ss.add(when: 'CONFIG_XILINX', if_true: files('xilinx_timer.c')) | ||
785 | specific_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_timer.c')) | ||
464 | -- | 786 | -- |
465 | 2.16.1 | 787 | 2.20.1 |
466 | 788 | ||
467 | 789 | diff view generated by jsdifflib |
1 | From: Christoffer Dall <christoffer.dall@linaro.org> | 1 | The stellaris-gptm timer currently uses system_clock_scale for one of |
---|---|---|---|
2 | its timer modes where the timer runs at the CPU clock rate. Make it | ||
3 | use a Clock input instead. | ||
2 | 4 | ||
3 | KVM doesn't support emulating a GICv3 in userspace, only GICv2. We | 5 | We don't try to make the timer handle changes in the clock frequency |
4 | currently attempt this anyway, and as a result a KVM guest doesn't | 6 | while the downcounter is running. This is not a change in behaviour |
5 | receive interrupts and the user is left wondering why. Report an error | 7 | from the previous system_clock_scale implementation -- we will pick |
6 | to the user if this particular combination is requested. | 8 | up the new frequency only when the downcounter hits zero. Handling |
9 | dynamic clock changes when the counter is running would require state | ||
10 | that the current gptm implementation doesn't have. | ||
7 | 11 | ||
8 | Signed-off-by: Christoffer Dall <christoffer.dall@linaro.org> | ||
9 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
10 | Message-id: 20180201205307.30343-1-christoffer.dall@linaro.org | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> | ||
14 | Message-id: 20210812093356.1946-25-peter.maydell@linaro.org | ||
12 | --- | 15 | --- |
13 | target/arm/kvm_arm.h | 4 ++++ | 16 | include/hw/timer/stellaris-gptm.h | 3 +++ |
14 | 1 file changed, 4 insertions(+) | 17 | hw/arm/stellaris.c | 12 +++++++++--- |
18 | hw/timer/stellaris-gptm.c | 26 ++++++++++++++++++++++---- | ||
19 | 3 files changed, 34 insertions(+), 7 deletions(-) | ||
15 | 20 | ||
16 | diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h | 21 | diff --git a/include/hw/timer/stellaris-gptm.h b/include/hw/timer/stellaris-gptm.h |
17 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/kvm_arm.h | 23 | --- a/include/hw/timer/stellaris-gptm.h |
19 | +++ b/target/arm/kvm_arm.h | 24 | +++ b/include/hw/timer/stellaris-gptm.h |
20 | @@ -XXX,XX +XXX,XX @@ static inline const char *gicv3_class_name(void) | 25 | @@ -XXX,XX +XXX,XX @@ |
21 | exit(1); | 26 | #include "qom/object.h" |
27 | #include "hw/sysbus.h" | ||
28 | #include "hw/irq.h" | ||
29 | +#include "hw/clock.h" | ||
30 | |||
31 | #define TYPE_STELLARIS_GPTM "stellaris-gptm" | ||
32 | OBJECT_DECLARE_SIMPLE_TYPE(gptm_state, STELLARIS_GPTM) | ||
33 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(gptm_state, STELLARIS_GPTM) | ||
34 | * + sysbus MMIO region 0: register bank | ||
35 | * + sysbus IRQ 0: timer interrupt | ||
36 | * + unnamed GPIO output 0: trigger output for the ADC | ||
37 | + * + Clock input "clk": the 32-bit countdown timer runs at this speed | ||
38 | */ | ||
39 | struct gptm_state { | ||
40 | SysBusDevice parent_obj; | ||
41 | @@ -XXX,XX +XXX,XX @@ struct gptm_state { | ||
42 | /* The timers have an alternate output used to trigger the ADC. */ | ||
43 | qemu_irq trigger; | ||
44 | qemu_irq irq; | ||
45 | + Clock *clk; | ||
46 | }; | ||
47 | |||
22 | #endif | 48 | #endif |
23 | } else { | 49 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c |
24 | + if (kvm_enabled()) { | 50 | index XXXXXXX..XXXXXXX 100644 |
25 | + error_report("Userspace GICv3 is not supported with KVM"); | 51 | --- a/hw/arm/stellaris.c |
26 | + exit(1); | 52 | +++ b/hw/arm/stellaris.c |
27 | + } | 53 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) |
28 | return "arm-gicv3"; | ||
29 | } | 54 | } |
55 | for (i = 0; i < 4; i++) { | ||
56 | if (board->dc2 & (0x10000 << i)) { | ||
57 | - dev = sysbus_create_simple(TYPE_STELLARIS_GPTM, | ||
58 | - 0x40030000 + i * 0x1000, | ||
59 | - qdev_get_gpio_in(nvic, timer_irq[i])); | ||
60 | + SysBusDevice *sbd; | ||
61 | + | ||
62 | + dev = qdev_new(TYPE_STELLARIS_GPTM); | ||
63 | + sbd = SYS_BUS_DEVICE(dev); | ||
64 | + qdev_connect_clock_in(dev, "clk", | ||
65 | + qdev_get_clock_out(ssys_dev, "SYSCLK")); | ||
66 | + sysbus_realize_and_unref(sbd, &error_fatal); | ||
67 | + sysbus_mmio_map(sbd, 0, 0x40030000 + i * 0x1000); | ||
68 | + sysbus_connect_irq(sbd, 0, qdev_get_gpio_in(nvic, timer_irq[i])); | ||
69 | /* TODO: This is incorrect, but we get away with it because | ||
70 | the ADC output is only ever pulsed. */ | ||
71 | qdev_connect_gpio_out(dev, 0, adc); | ||
72 | diff --git a/hw/timer/stellaris-gptm.c b/hw/timer/stellaris-gptm.c | ||
73 | index XXXXXXX..XXXXXXX 100644 | ||
74 | --- a/hw/timer/stellaris-gptm.c | ||
75 | +++ b/hw/timer/stellaris-gptm.c | ||
76 | @@ -XXX,XX +XXX,XX @@ | ||
77 | #include "qemu/osdep.h" | ||
78 | #include "qemu/log.h" | ||
79 | #include "qemu/timer.h" | ||
80 | +#include "qapi/error.h" | ||
81 | #include "migration/vmstate.h" | ||
82 | +#include "hw/qdev-clock.h" | ||
83 | #include "hw/timer/stellaris-gptm.h" | ||
84 | -#include "hw/timer/armv7m_systick.h" /* Needed only for system_clock_scale */ | ||
85 | |||
86 | static void gptm_update_irq(gptm_state *s) | ||
87 | { | ||
88 | @@ -XXX,XX +XXX,XX @@ static void gptm_reload(gptm_state *s, int n, int reset) | ||
89 | /* 32-bit CountDown. */ | ||
90 | uint32_t count; | ||
91 | count = s->load[0] | (s->load[1] << 16); | ||
92 | - tick += (int64_t)count * system_clock_scale; | ||
93 | + tick += clock_ticks_to_ns(s->clk, count); | ||
94 | } else if (s->config == 1) { | ||
95 | /* 32-bit RTC. 1Hz tick. */ | ||
96 | tick += NANOSECONDS_PER_SECOND; | ||
97 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps gptm_ops = { | ||
98 | |||
99 | static const VMStateDescription vmstate_stellaris_gptm = { | ||
100 | .name = "stellaris_gptm", | ||
101 | - .version_id = 1, | ||
102 | - .minimum_version_id = 1, | ||
103 | + .version_id = 2, | ||
104 | + .minimum_version_id = 2, | ||
105 | .fields = (VMStateField[]) { | ||
106 | VMSTATE_UINT32(config, gptm_state), | ||
107 | VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), | ||
108 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_stellaris_gptm = { | ||
109 | VMSTATE_UINT32(rtc, gptm_state), | ||
110 | VMSTATE_INT64_ARRAY(tick, gptm_state, 2), | ||
111 | VMSTATE_TIMER_PTR_ARRAY(timer, gptm_state, 2), | ||
112 | + VMSTATE_CLOCK(clk, gptm_state), | ||
113 | VMSTATE_END_OF_LIST() | ||
114 | } | ||
115 | }; | ||
116 | @@ -XXX,XX +XXX,XX @@ static void stellaris_gptm_init(Object *obj) | ||
117 | sysbus_init_mmio(sbd, &s->iomem); | ||
118 | |||
119 | s->opaque[0] = s->opaque[1] = s; | ||
120 | + | ||
121 | + /* | ||
122 | + * TODO: in an ideal world we would model the effects of changing | ||
123 | + * the input clock frequency while the countdown timer is active. | ||
124 | + * The best way to do this would be to convert the device to use | ||
125 | + * ptimer instead of hand-rolling its own timer. This would also | ||
126 | + * make it easy to implement reading the current count from the | ||
127 | + * TAR and TBR registers. | ||
128 | + */ | ||
129 | + s->clk = qdev_init_clock_in(dev, "clk", NULL, NULL, 0); | ||
130 | } | ||
131 | |||
132 | static void stellaris_gptm_realize(DeviceState *dev, Error **errp) | ||
133 | { | ||
134 | gptm_state *s = STELLARIS_GPTM(dev); | ||
135 | + | ||
136 | + if (!clock_has_source(s->clk)) { | ||
137 | + error_setg(errp, "stellaris-gptm: clk must be connected"); | ||
138 | + return; | ||
139 | + } | ||
140 | + | ||
141 | s->timer[0] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[0]); | ||
142 | s->timer[1] = timer_new_ns(QEMU_CLOCK_VIRTUAL, gptm_tick, &s->opaque[1]); | ||
30 | } | 143 | } |
31 | -- | 144 | -- |
32 | 2.16.1 | 145 | 2.20.1 |
33 | 146 | ||
34 | 147 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | All the devices that used to use system_clock_scale have now been | |
2 | converted to use Clock inputs instead, so the global is no longer | ||
3 | needed; remove it and all the code that sets it. | ||
4 | |||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Message-id: 20210812093356.1946-26-peter.maydell@linaro.org | ||
8 | --- | ||
9 | include/hw/timer/armv7m_systick.h | 22 ---------------------- | ||
10 | hw/arm/armsse.c | 17 +---------------- | ||
11 | hw/arm/mps2.c | 2 -- | ||
12 | hw/arm/msf2-soc.c | 2 -- | ||
13 | hw/arm/netduino2.c | 2 -- | ||
14 | hw/arm/netduinoplus2.c | 2 -- | ||
15 | hw/arm/nrf51_soc.c | 2 -- | ||
16 | hw/arm/stellaris.c | 7 ++++--- | ||
17 | hw/arm/stm32vldiscovery.c | 2 -- | ||
18 | hw/timer/armv7m_systick.c | 2 -- | ||
19 | 10 files changed, 5 insertions(+), 55 deletions(-) | ||
20 | |||
21 | diff --git a/include/hw/timer/armv7m_systick.h b/include/hw/timer/armv7m_systick.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/include/hw/timer/armv7m_systick.h | ||
24 | +++ b/include/hw/timer/armv7m_systick.h | ||
25 | @@ -XXX,XX +XXX,XX @@ struct SysTickState { | ||
26 | Clock *cpuclk; | ||
27 | }; | ||
28 | |||
29 | -/* | ||
30 | - * Multiplication factor to convert from system clock ticks to qemu timer | ||
31 | - * ticks. This should be set (by board code, usually) to a value | ||
32 | - * equal to NANOSECONDS_PER_SECOND / frq, where frq is the clock frequency | ||
33 | - * in Hz of the CPU. | ||
34 | - * | ||
35 | - * This value is used by the systick device when it is running in | ||
36 | - * its "use the CPU clock" mode (ie when SYST_CSR.CLKSOURCE == 1) to | ||
37 | - * set how fast the timer should tick. | ||
38 | - * | ||
39 | - * TODO: we should refactor this so that rather than using a global | ||
40 | - * we use a device property or something similar. This is complicated | ||
41 | - * because (a) the property would need to be plumbed through from the | ||
42 | - * board code down through various layers to the systick device | ||
43 | - * and (b) the property needs to be modifiable after realize, because | ||
44 | - * the stellaris board uses this to implement the behaviour where the | ||
45 | - * guest can reprogram the PLL registers to downclock the CPU, and the | ||
46 | - * systick device needs to react accordingly. Possibly this should | ||
47 | - * be deferred until we have a good API for modelling clock trees. | ||
48 | - */ | ||
49 | -extern int system_clock_scale; | ||
50 | - | ||
51 | #endif | ||
52 | diff --git a/hw/arm/armsse.c b/hw/arm/armsse.c | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/hw/arm/armsse.c | ||
55 | +++ b/hw/arm/armsse.c | ||
56 | @@ -XXX,XX +XXX,XX @@ static void armsse_forward_sec_resp_cfg(ARMSSE *s) | ||
57 | qdev_connect_gpio_out(dev_splitter, 2, s->sec_resp_cfg_in); | ||
58 | } | ||
59 | |||
60 | -static void armsse_mainclk_update(void *opaque, ClockEvent event) | ||
61 | -{ | ||
62 | - ARMSSE *s = ARM_SSE(opaque); | ||
63 | - | ||
64 | - /* | ||
65 | - * Set system_clock_scale from our Clock input; this is what | ||
66 | - * controls the tick rate of the CPU SysTick timer. | ||
67 | - */ | ||
68 | - system_clock_scale = clock_ticks_to_ns(s->mainclk, 1); | ||
69 | -} | ||
70 | - | ||
71 | static void armsse_init(Object *obj) | ||
72 | { | ||
73 | ARMSSE *s = ARM_SSE(obj); | ||
74 | @@ -XXX,XX +XXX,XX @@ static void armsse_init(Object *obj) | ||
75 | assert(info->sram_banks <= MAX_SRAM_BANKS); | ||
76 | assert(info->num_cpus <= SSE_MAX_CPUS); | ||
77 | |||
78 | - s->mainclk = qdev_init_clock_in(DEVICE(s), "MAINCLK", | ||
79 | - armsse_mainclk_update, s, ClockUpdate); | ||
80 | + s->mainclk = qdev_init_clock_in(DEVICE(s), "MAINCLK", NULL, NULL, 0); | ||
81 | s->s32kclk = qdev_init_clock_in(DEVICE(s), "S32KCLK", NULL, NULL, 0); | ||
82 | |||
83 | memory_region_init(&s->container, obj, "armsse-container", UINT64_MAX); | ||
84 | @@ -XXX,XX +XXX,XX @@ static void armsse_realize(DeviceState *dev, Error **errp) | ||
85 | * devices in the ARMSSE. | ||
86 | */ | ||
87 | sysbus_init_mmio(SYS_BUS_DEVICE(s), &s->container); | ||
88 | - | ||
89 | - /* Set initial system_clock_scale from MAINCLK */ | ||
90 | - armsse_mainclk_update(s, ClockUpdate); | ||
91 | } | ||
92 | |||
93 | static void armsse_idau_check(IDAUInterface *ii, uint32_t address, | ||
94 | diff --git a/hw/arm/mps2.c b/hw/arm/mps2.c | ||
95 | index XXXXXXX..XXXXXXX 100644 | ||
96 | --- a/hw/arm/mps2.c | ||
97 | +++ b/hw/arm/mps2.c | ||
98 | @@ -XXX,XX +XXX,XX @@ static void mps2_common_init(MachineState *machine) | ||
99 | qdev_get_gpio_in(armv7m, | ||
100 | mmc->fpga_type == FPGA_AN511 ? 47 : 13)); | ||
101 | |||
102 | - system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; | ||
103 | - | ||
104 | armv7m_load_kernel(ARM_CPU(first_cpu), machine->kernel_filename, | ||
105 | 0x400000); | ||
106 | } | ||
107 | diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c | ||
108 | index XXXXXXX..XXXXXXX 100644 | ||
109 | --- a/hw/arm/msf2-soc.c | ||
110 | +++ b/hw/arm/msf2-soc.c | ||
111 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | ||
112 | return; | ||
113 | } | ||
114 | |||
115 | - system_clock_scale = clock_ticks_to_ns(s->m3clk, 1); | ||
116 | - | ||
117 | for (i = 0; i < MSF2_NUM_UARTS; i++) { | ||
118 | if (serial_hd(i)) { | ||
119 | serial_mm_init(get_system_memory(), uart_addr[i], 2, | ||
120 | diff --git a/hw/arm/netduino2.c b/hw/arm/netduino2.c | ||
121 | index XXXXXXX..XXXXXXX 100644 | ||
122 | --- a/hw/arm/netduino2.c | ||
123 | +++ b/hw/arm/netduino2.c | ||
124 | @@ -XXX,XX +XXX,XX @@ static void netduino2_init(MachineState *machine) | ||
125 | DeviceState *dev; | ||
126 | Clock *sysclk; | ||
127 | |||
128 | - system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; | ||
129 | - | ||
130 | /* This clock doesn't need migration because it is fixed-frequency */ | ||
131 | sysclk = clock_new(OBJECT(machine), "SYSCLK"); | ||
132 | clock_set_hz(sysclk, SYSCLK_FRQ); | ||
133 | diff --git a/hw/arm/netduinoplus2.c b/hw/arm/netduinoplus2.c | ||
134 | index XXXXXXX..XXXXXXX 100644 | ||
135 | --- a/hw/arm/netduinoplus2.c | ||
136 | +++ b/hw/arm/netduinoplus2.c | ||
137 | @@ -XXX,XX +XXX,XX @@ static void netduinoplus2_init(MachineState *machine) | ||
138 | DeviceState *dev; | ||
139 | Clock *sysclk; | ||
140 | |||
141 | - system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; | ||
142 | - | ||
143 | /* This clock doesn't need migration because it is fixed-frequency */ | ||
144 | sysclk = clock_new(OBJECT(machine), "SYSCLK"); | ||
145 | clock_set_hz(sysclk, SYSCLK_FRQ); | ||
146 | diff --git a/hw/arm/nrf51_soc.c b/hw/arm/nrf51_soc.c | ||
147 | index XXXXXXX..XXXXXXX 100644 | ||
148 | --- a/hw/arm/nrf51_soc.c | ||
149 | +++ b/hw/arm/nrf51_soc.c | ||
150 | @@ -XXX,XX +XXX,XX @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp) | ||
151 | * will always provide one). | ||
152 | */ | ||
153 | |||
154 | - system_clock_scale = NANOSECONDS_PER_SECOND / HCLK_FRQ; | ||
155 | - | ||
156 | object_property_set_link(OBJECT(&s->cpu), "memory", OBJECT(&s->container), | ||
157 | &error_abort); | ||
158 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->cpu), errp)) { | ||
159 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c | ||
160 | index XXXXXXX..XXXXXXX 100644 | ||
161 | --- a/hw/arm/stellaris.c | ||
162 | +++ b/hw/arm/stellaris.c | ||
163 | @@ -XXX,XX +XXX,XX @@ static bool ssys_use_rcc2(ssys_state *s) | ||
164 | */ | ||
165 | static void ssys_calculate_system_clock(ssys_state *s, bool propagate_clock) | ||
166 | { | ||
167 | + int period_ns; | ||
168 | /* | ||
169 | * SYSDIV field specifies divisor: 0 == /1, 1 == /2, etc. Input | ||
170 | * clock is 200MHz, which is a period of 5 ns. Dividing the clock | ||
171 | * frequency by X is the same as multiplying the period by X. | ||
172 | */ | ||
173 | if (ssys_use_rcc2(s)) { | ||
174 | - system_clock_scale = 5 * (((s->rcc2 >> 23) & 0x3f) + 1); | ||
175 | + period_ns = 5 * (((s->rcc2 >> 23) & 0x3f) + 1); | ||
176 | } else { | ||
177 | - system_clock_scale = 5 * (((s->rcc >> 23) & 0xf) + 1); | ||
178 | + period_ns = 5 * (((s->rcc >> 23) & 0xf) + 1); | ||
179 | } | ||
180 | - clock_set_ns(s->sysclk, system_clock_scale); | ||
181 | + clock_set_ns(s->sysclk, period_ns); | ||
182 | if (propagate_clock) { | ||
183 | clock_propagate(s->sysclk); | ||
184 | } | ||
185 | diff --git a/hw/arm/stm32vldiscovery.c b/hw/arm/stm32vldiscovery.c | ||
186 | index XXXXXXX..XXXXXXX 100644 | ||
187 | --- a/hw/arm/stm32vldiscovery.c | ||
188 | +++ b/hw/arm/stm32vldiscovery.c | ||
189 | @@ -XXX,XX +XXX,XX @@ static void stm32vldiscovery_init(MachineState *machine) | ||
190 | DeviceState *dev; | ||
191 | Clock *sysclk; | ||
192 | |||
193 | - system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; | ||
194 | - | ||
195 | /* This clock doesn't need migration because it is fixed-frequency */ | ||
196 | sysclk = clock_new(OBJECT(machine), "SYSCLK"); | ||
197 | clock_set_hz(sysclk, SYSCLK_FRQ); | ||
198 | diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c | ||
199 | index XXXXXXX..XXXXXXX 100644 | ||
200 | --- a/hw/timer/armv7m_systick.c | ||
201 | +++ b/hw/timer/armv7m_systick.c | ||
202 | @@ -XXX,XX +XXX,XX @@ | ||
203 | #define SYSCALIB_SKEW (1U << 30) | ||
204 | #define SYSCALIB_TENMS ((1U << 24) - 1) | ||
205 | |||
206 | -int system_clock_scale; | ||
207 | - | ||
208 | static void systick_set_period_from_clock(SysTickState *s) | ||
209 | { | ||
210 | /* | ||
211 | -- | ||
212 | 2.20.1 | ||
213 | |||
214 | diff view generated by jsdifflib |