1 | target-arm queue. The big thing here is the landing of the 3-phase | 1 | The following changes since commit ec397e90d21269037280633b6058d1f280e27667: |
---|---|---|---|
2 | reset patches... | ||
3 | 2 | ||
4 | -- PMM | 3 | Merge remote-tracking branch 'remotes/alistair/tags/pull-riscv-to-apply-20210901-2' into staging (2021-09-01 08:33:02 +0100) |
5 | |||
6 | The following changes since commit 204aa60b37c23a89e690d418f49787d274303ca7: | ||
7 | |||
8 | Merge remote-tracking branch 'remotes/amarkovic/tags/mips-queue-jan-29-2020' into staging (2020-01-30 14:18:45 +0000) | ||
9 | 4 | ||
10 | are available in the Git repository at: | 5 | are available in the Git repository at: |
11 | 6 | ||
12 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200130 | 7 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20210901 |
13 | 8 | ||
14 | for you to fetch changes up to dea101a1ae9968c9fec6ab0291489dad7c49f36f: | 9 | for you to fetch changes up to 683754c7b61f9e2ff098720ec80c9ab86c54663d: |
15 | 10 | ||
16 | target/arm/cpu: Add the kvm-no-adjvtime CPU property (2020-01-30 16:02:06 +0000) | 11 | arm: Remove system_clock_scale global (2021-09-01 11:08:21 +0100) |
17 | 12 | ||
18 | ---------------------------------------------------------------- | 13 | ---------------------------------------------------------------- |
19 | target-arm queue: | 14 | * Refactor M-profile systick to use Clocks instead of system_clock_scale global |
20 | * hw/core/or-irq: Fix incorrect assert forbidding num-lines == MAX_OR_LINES | 15 | * clock: Provide builtin multiplier/divider |
21 | * target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr | 16 | * Add A64FX processor model |
22 | * aspeed: some minor bugfixes | 17 | * Enable MVE emulation in Cortex-M55 |
23 | * aspeed: add eMMC controller model for AST2600 SoC | 18 | * hw: Add compat machines for 6.2 |
24 | * hw/arm/raspi: Remove obsolete use of -smp to set the soc 'enabled-cpus' | 19 | * hw/intc/arm_gicv3: Replace mis-used MEMTX_* constants by booleans |
25 | * New 3-phase reset API for device models | 20 | * hw/arm/raspi: Remove deprecated raspi2/raspi3 aliases |
26 | * hw/intc/arm_gicv3_kvm: Stop wrongly programming GICR_PENDBASER.PTZ bit | ||
27 | * Arm KVM: stop/restart the guest counter when the VM is stopped and started | ||
28 | 21 | ||
29 | ---------------------------------------------------------------- | 22 | ---------------------------------------------------------------- |
30 | Andrew Jeffery (2): | 23 | Peter Maydell (43): |
31 | hw/sd: Configure number of slots exposed by the ASPEED SDHCI model | 24 | target/arm: Implement MVE VADD (floating-point) |
32 | hw/arm: ast2600: Wire up the eMMC controller | 25 | target/arm: Implement MVE VSUB, VMUL, VABD, VMAXNM, VMINNM |
26 | target/arm: Implement MVE VCADD | ||
27 | target/arm: Implement MVE VFMA and VFMS | ||
28 | target/arm: Implement MVE VCMUL and VCMLA | ||
29 | target/arm: Implement MVE VMAXNMA and VMINNMA | ||
30 | target/arm: Implement MVE scalar fp insns | ||
31 | target/arm: Implement MVE fp-with-scalar VFMA, VFMAS | ||
32 | softfloat: Remove assertion preventing silencing of NaN in default-NaN mode | ||
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 | ||
33 | 67 | ||
34 | Andrew Jones (6): | 68 | Philippe Mathieu-Daudé (4): |
35 | target/arm/kvm: trivial: Clean up header documentation | 69 | tests: Remove uses of deprecated raspi2/raspi3 machine names |
36 | hw/arm/virt: Add missing 5.0 options call to 4.2 options | 70 | hw/arm/raspi: Remove deprecated raspi2/raspi3 aliases |
37 | target/arm/kvm64: kvm64 cpus have timer registers | 71 | hw/intc/arm_gicv3_dist: Rename 64-bit accessors with 'q' suffix |
38 | tests/arm-cpu-features: Check feature default values | 72 | hw/intc/arm_gicv3: Replace mis-used MEMTX_* constants by booleans |
39 | target/arm/kvm: Implement virtual time adjustment | ||
40 | target/arm/cpu: Add the kvm-no-adjvtime CPU property | ||
41 | 73 | ||
42 | Cédric Le Goater (2): | 74 | Shuuichirou Ishii (3): |
43 | ftgmac100: check RX and TX buffer alignment | 75 | target-arm: Add support for Fujitsu A64FX |
44 | hw/arm/aspeed: add a 'execute-in-place' property to boot directly from CE0 | 76 | hw/arm/virt: target-arm: Add A64FX processor support to virt machine |
77 | tests/arm-cpu-features: Add A64FX processor related tests | ||
45 | 78 | ||
46 | Damien Hedde (11): | 79 | Yanan Wang (1): |
47 | add device_legacy_reset function to prepare for reset api change | 80 | hw: Add compat machines for 6.2 |
48 | hw/core/qdev: add trace events to help with resettable transition | ||
49 | hw/core: create Resettable QOM interface | ||
50 | hw/core: add Resettable support to BusClass and DeviceClass | ||
51 | hw/core/resettable: add support for changing parent | ||
52 | hw/core/qdev: handle parent bus change regarding resettable | ||
53 | hw/core/qdev: update hotplug reset regarding resettable | ||
54 | hw/core: deprecate old reset functions and introduce new ones | ||
55 | docs/devel/reset.rst: add doc about Resettable interface | ||
56 | vl: replace deprecated qbus_reset_all registration | ||
57 | hw/s390x/ipl: replace deprecated qdev_reset_all registration | ||
58 | 81 | ||
59 | Joel Stanley (1): | 82 | docs/about/deprecated.rst | 7 - |
60 | misc/pca9552: Add qom set and get | 83 | docs/about/removed-features.rst | 7 + |
84 | docs/devel/clocks.rst | 23 ++ | ||
85 | docs/devel/qgraph.rst | 38 +- | ||
86 | docs/system/arm/virt.rst | 1 + | ||
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 | ||
61 | 155 | ||
62 | Peter Maydell (2): | ||
63 | hw/core/or-irq: Fix incorrect assert forbidding num-lines == MAX_OR_LINES | ||
64 | target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr | ||
65 | |||
66 | Philippe Mathieu-Daudé (1): | ||
67 | hw/arm/raspi: Remove obsolete use of -smp to set the soc 'enabled-cpus' | ||
68 | |||
69 | Zenghui Yu (1): | ||
70 | hw/intc/arm_gicv3_kvm: Stop wrongly programming GICR_PENDBASER.PTZ bit | ||
71 | |||
72 | hw/core/Makefile.objs | 1 + | ||
73 | tests/Makefile.include | 1 + | ||
74 | include/hw/arm/aspeed.h | 2 + | ||
75 | include/hw/arm/aspeed_soc.h | 2 + | ||
76 | include/hw/arm/virt.h | 1 + | ||
77 | include/hw/qdev-core.h | 58 +++++++- | ||
78 | include/hw/resettable.h | 247 +++++++++++++++++++++++++++++++++ | ||
79 | include/hw/sd/aspeed_sdhci.h | 1 + | ||
80 | target/arm/cpu.h | 7 + | ||
81 | target/arm/kvm_arm.h | 95 ++++++++++--- | ||
82 | hw/arm/aspeed.c | 72 ++++++++-- | ||
83 | hw/arm/aspeed_ast2600.c | 31 ++++- | ||
84 | hw/arm/aspeed_soc.c | 2 + | ||
85 | hw/arm/raspi.c | 2 - | ||
86 | hw/arm/virt.c | 9 ++ | ||
87 | hw/audio/intel-hda.c | 2 +- | ||
88 | hw/core/bus.c | 102 ++++++++++++++ | ||
89 | hw/core/or-irq.c | 2 +- | ||
90 | hw/core/qdev.c | 160 ++++++++++++++++++++-- | ||
91 | hw/core/resettable.c | 301 +++++++++++++++++++++++++++++++++++++++++ | ||
92 | hw/hyperv/hyperv.c | 2 +- | ||
93 | hw/i386/microvm.c | 2 +- | ||
94 | hw/i386/pc.c | 2 +- | ||
95 | hw/ide/microdrive.c | 8 +- | ||
96 | hw/intc/arm_gicv3_kvm.c | 11 +- | ||
97 | hw/intc/spapr_xive.c | 2 +- | ||
98 | hw/misc/pca9552.c | 90 ++++++++++++ | ||
99 | hw/net/ftgmac100.c | 13 ++ | ||
100 | hw/ppc/pnv_psi.c | 4 +- | ||
101 | hw/ppc/spapr_pci.c | 2 +- | ||
102 | hw/ppc/spapr_vio.c | 2 +- | ||
103 | hw/s390x/ipl.c | 10 +- | ||
104 | hw/s390x/s390-pci-inst.c | 2 +- | ||
105 | hw/scsi/vmw_pvscsi.c | 2 +- | ||
106 | hw/sd/aspeed_sdhci.c | 11 +- | ||
107 | hw/sd/omap_mmc.c | 2 +- | ||
108 | hw/sd/pl181.c | 2 +- | ||
109 | target/arm/arm-semi.c | 9 ++ | ||
110 | target/arm/cpu.c | 2 + | ||
111 | target/arm/cpu64.c | 1 + | ||
112 | target/arm/kvm.c | 120 ++++++++++++++++ | ||
113 | target/arm/kvm32.c | 3 + | ||
114 | target/arm/kvm64.c | 4 + | ||
115 | target/arm/machine.c | 7 + | ||
116 | target/arm/monitor.c | 1 + | ||
117 | tests/qtest/arm-cpu-features.c | 41 ++++-- | ||
118 | vl.c | 10 +- | ||
119 | docs/arm-cpu-features.rst | 37 ++++- | ||
120 | docs/devel/index.rst | 1 + | ||
121 | docs/devel/reset.rst | 289 +++++++++++++++++++++++++++++++++++++++ | ||
122 | hw/core/trace-events | 27 ++++ | ||
123 | 51 files changed, 1727 insertions(+), 90 deletions(-) | ||
124 | create mode 100644 include/hw/resettable.h | ||
125 | create mode 100644 hw/core/resettable.c | ||
126 | create mode 100644 docs/devel/reset.rst | ||
127 | 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 |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> |
---|---|---|---|
2 | 2 | ||
3 | Since we enabled parallel TCG code generation for softmmu (see | 3 | Remove the raspi2/raspi3 machine aliases, |
4 | commit 3468b59 "tcg: enable multiple TCG contexts in softmmu") | 4 | deprecated since commit 155e1c82ed0. |
5 | and its subsequent fix (commit 72649619 "add .min_cpus and | ||
6 | .default_cpus fields to machine_class"), the raspi machines are | ||
7 | restricted to always use their 4 cores: | ||
8 | 5 | ||
9 | See in hw/arm/raspi2 (with BCM283X_NCPUS set to 4): | ||
10 | |||
11 | 222 static void raspi2_machine_init(MachineClass *mc) | ||
12 | 223 { | ||
13 | 224 mc->desc = "Raspberry Pi 2"; | ||
14 | 230 mc->max_cpus = BCM283X_NCPUS; | ||
15 | 231 mc->min_cpus = BCM283X_NCPUS; | ||
16 | 232 mc->default_cpus = BCM283X_NCPUS; | ||
17 | 235 }; | ||
18 | 236 DEFINE_MACHINE("raspi2", raspi2_machine_init) | ||
19 | |||
20 | We can no longer use the -smp option, as we get: | ||
21 | |||
22 | $ qemu-system-arm -M raspi2 -smp 1 | ||
23 | qemu-system-arm: Invalid SMP CPUs 1. The min CPUs supported by machine 'raspi2' is 4 | ||
24 | |||
25 | Since we can not set the TYPE_BCM283x SOC "enabled-cpus" with -smp, | ||
26 | remove the unuseful code. | ||
27 | |||
28 | We can achieve the same by using the '-global bcm2836.enabled-cpus=1' | ||
29 | option. | ||
30 | |||
31 | Reported-by: Laurent Bonnans <laurent.bonnans@here.com> | ||
32 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
33 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Message-id: 20210827060815.2384760-3-f4bug@amsat.org |
34 | Message-id: 20200120235159.18510-2-f4bug@amsat.org | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
35 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
36 | --- | 10 | --- |
37 | hw/arm/raspi.c | 2 -- | 11 | docs/about/deprecated.rst | 7 ------- |
38 | 1 file changed, 2 deletions(-) | 12 | docs/about/removed-features.rst | 7 +++++++ |
13 | hw/arm/raspi.c | 2 -- | ||
14 | 3 files changed, 7 insertions(+), 9 deletions(-) | ||
39 | 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 | -------------------- | ||
40 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | 52 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c |
41 | index XXXXXXX..XXXXXXX 100644 | 53 | index XXXXXXX..XXXXXXX 100644 |
42 | --- a/hw/arm/raspi.c | 54 | --- a/hw/arm/raspi.c |
43 | +++ b/hw/arm/raspi.c | 55 | +++ b/hw/arm/raspi.c |
44 | @@ -XXX,XX +XXX,XX @@ static void raspi_init(MachineState *machine, int version) | 56 | @@ -XXX,XX +XXX,XX @@ static void raspi2b_machine_class_init(ObjectClass *oc, void *data) |
45 | /* Setup the SOC */ | 57 | MachineClass *mc = MACHINE_CLASS(oc); |
46 | object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(&s->ram), | 58 | RaspiMachineClass *rmc = RASPI_MACHINE_CLASS(oc); |
47 | &error_abort); | 59 | |
48 | - object_property_set_int(OBJECT(&s->soc), machine->smp.cpus, "enabled-cpus", | 60 | - mc->alias = "raspi2"; |
49 | - &error_abort); | 61 | rmc->board_rev = 0xa21041; |
50 | int board_rev = version == 3 ? 0xa02082 : 0xa21041; | 62 | raspi_machine_class_common_init(mc, rmc->board_rev); |
51 | object_property_set_int(OBJECT(&s->soc), board_rev, "board-rev", | 63 | }; |
52 | &error_abort); | 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 | }; | ||
53 | -- | 72 | -- |
54 | 2.20.1 | 73 | 2.20.1 |
55 | 74 | ||
56 | 75 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | In qdev_set_parent_bus(), when changing the parent bus of a | 3 | QEMU load/store API (docs/devel/loads-stores.rst) uses the 'q' |
4 | realized device, if the source and destination buses are not in the | 4 | suffix for 64-bit accesses. Rename the current 'll' suffix to |
5 | same reset state, some adaptations are required. This patch adds | 5 | have the GIC dist accessors better match the rest of the codebase. |
6 | needed call to resettable_change_parent() to make sure a device reset | ||
7 | state stays coherent with its parent bus. | ||
8 | 6 | ||
9 | The addition is a no-op if: | 7 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
10 | 1. the device being parented is not realized. | 8 | Message-id: 20210826180704.2131949-2-philmd@redhat.com |
11 | 2. the device is realized, but both buses are not under reset. | ||
12 | |||
13 | Case 2 means that as long as qdev_set_parent_bus() is called | ||
14 | during the machine realization procedure (which is before the | ||
15 | machine reset so nothing is in reset), it is a no op. | ||
16 | |||
17 | There are 52 call sites of qdev_set_parent_bus(). All but one fall | ||
18 | into the no-op case: | ||
19 | + 29 trivial calls related to virtio (in hw/{s390x,display,virtio}/ | ||
20 | {vhost,virtio}-xxx.c) to set a vdev(or vgpu) composing device | ||
21 | parent bus just before realizing the same vdev(vgpu). | ||
22 | + hw/core/qdev.c: when creating a device in qdev_try_create() | ||
23 | + hw/core/sysbus.c: when initializing a device in the sysbus | ||
24 | + hw/i386/amd_iommu.c: before realizing AMDVIState/pci | ||
25 | + hw/isa/piix4.c: before realizing PIIX4State/rtc | ||
26 | + hw/misc/auxbus.c: when creating an AUXBus | ||
27 | + hw/misc/auxbus.c: when creating an AUXBus child | ||
28 | + hw/misc/macio/macio.c: when initializing a MACIOState child | ||
29 | + hw/misc/macio/macio.c: before realizing NewWorldMacIOState/pmu | ||
30 | + hw/misc/macio/macio.c: before realizing NewWorldMacIOState/cuda | ||
31 | + hw/net/virtio-net.c: Used for migration when using the failover | ||
32 | mechanism to migration a vfio-pci/net. It is | ||
33 | a no-op because at this point the device is | ||
34 | already on the bus. | ||
35 | + hw/pci-host/designware.c: before realizing DesignwarePCIEHost/root | ||
36 | + hw/pci-host/gpex.c: before realizing GPEXHost/root | ||
37 | + hw/pci-host/prep.c: when initialiazing PREPPCIState/pci_dev | ||
38 | + hw/pci-host/q35.c: before realizing Q35PCIHost/mch | ||
39 | + hw/pci-host/versatile.c: when initializing PCIVPBState/pci_dev | ||
40 | + hw/pci-host/xilinx-pcie.c: before realizing XilinxPCIEHost/root | ||
41 | + hw/s390x/event-facility.c: when creating SCLPEventFacility/ | ||
42 | TYPE_SCLP_QUIESCE | ||
43 | + hw/s390x/event-facility.c: ditto with SCLPEventFacility/ | ||
44 | TYPE_SCLP_CPU_HOTPLUG | ||
45 | + hw/s390x/sclp.c: Not trivial because it is called on a SLCPDevice | ||
46 | just after realizing it. Ok because at this point the destination | ||
47 | bus (sysbus) is not in reset; the realize step is before the | ||
48 | machine reset. | ||
49 | + hw/sd/core.c: Not OK. Used in sdbus_reparent_card(). See below. | ||
50 | + hw/ssi/ssi.c: Used to put spi slave on spi bus and connect the cs | ||
51 | line in ssi_auto_connect_slave(). Ok because this function is only | ||
52 | used in realize step in hw/ssi/aspeed_smc.ci, hw/ssi/imx_spi.c, | ||
53 | hw/ssi/mss-spi.c, hw/ssi/xilinx_spi.c and hw/ssi/xilinx_spips.c. | ||
54 | + hw/xen/xen-legacy-backend.c: when creating a XenLegacyDevice device | ||
55 | + qdev-monitor.c: in device hotplug creation procedure before realize | ||
56 | |||
57 | Note that this commit alone will have no effect, right now there is no | ||
58 | use of resettable API to reset anything. So a bus will never be tagged | ||
59 | as in-reset by this same API. | ||
60 | |||
61 | The one place where side-effect will occurs is in hw/sd/core.c in | ||
62 | sdbus_reparent_card(). This function is only used in the raspi machines, | ||
63 | including during the sysbus reset procedure. This case will be | ||
64 | carrefully handled when doing the multiple phase reset transition. | ||
65 | |||
66 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
67 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
68 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
69 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
70 | Message-id: 20200123132823.1117486-7-damien.hedde@greensocs.com | ||
71 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
72 | --- | 10 | --- |
73 | hw/core/qdev.c | 16 +++++++++++----- | 11 | hw/intc/arm_gicv3_dist.c | 12 ++++++------ |
74 | 1 file changed, 11 insertions(+), 5 deletions(-) | 12 | 1 file changed, 6 insertions(+), 6 deletions(-) |
75 | 13 | ||
76 | diff --git a/hw/core/qdev.c b/hw/core/qdev.c | 14 | diff --git a/hw/intc/arm_gicv3_dist.c b/hw/intc/arm_gicv3_dist.c |
77 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
78 | --- a/hw/core/qdev.c | 16 | --- a/hw/intc/arm_gicv3_dist.c |
79 | +++ b/hw/core/qdev.c | 17 | +++ b/hw/intc/arm_gicv3_dist.c |
80 | @@ -XXX,XX +XXX,XX @@ static void bus_add_child(BusState *bus, DeviceState *child) | 18 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writel(GICv3State *s, hwaddr offset, |
81 | |||
82 | void qdev_set_parent_bus(DeviceState *dev, BusState *bus) | ||
83 | { | ||
84 | - bool replugging = dev->parent_bus != NULL; | ||
85 | + BusState *old_parent_bus = dev->parent_bus; | ||
86 | |||
87 | - if (replugging) { | ||
88 | + if (old_parent_bus) { | ||
89 | trace_qdev_update_parent_bus(dev, object_get_typename(OBJECT(dev)), | ||
90 | - dev->parent_bus, object_get_typename(OBJECT(dev->parent_bus)), | ||
91 | + old_parent_bus, object_get_typename(OBJECT(old_parent_bus)), | ||
92 | OBJECT(bus), object_get_typename(OBJECT(bus))); | ||
93 | /* | ||
94 | * Keep a reference to the device while it's not plugged into | ||
95 | * any bus, to avoid it potentially evaporating when it is | ||
96 | * dereffed in bus_remove_child(). | ||
97 | + * Also keep the ref of the parent bus until the end, so that | ||
98 | + * we can safely call resettable_change_parent() below. | ||
99 | */ | ||
100 | object_ref(OBJECT(dev)); | ||
101 | bus_remove_child(dev->parent_bus, dev); | ||
102 | - object_unref(OBJECT(dev->parent_bus)); | ||
103 | } | ||
104 | dev->parent_bus = bus; | ||
105 | object_ref(OBJECT(bus)); | ||
106 | bus_add_child(bus, dev); | ||
107 | - if (replugging) { | ||
108 | + if (dev->realized) { | ||
109 | + resettable_change_parent(OBJECT(dev), OBJECT(bus), | ||
110 | + OBJECT(old_parent_bus)); | ||
111 | + } | ||
112 | + if (old_parent_bus) { | ||
113 | + object_unref(OBJECT(old_parent_bus)); | ||
114 | object_unref(OBJECT(dev)); | ||
115 | } | 19 | } |
116 | } | 20 | } |
21 | |||
22 | -static MemTxResult gicd_writell(GICv3State *s, hwaddr offset, | ||
23 | - uint64_t value, MemTxAttrs attrs) | ||
24 | +static MemTxResult gicd_writeq(GICv3State *s, hwaddr offset, | ||
25 | + uint64_t value, MemTxAttrs attrs) | ||
26 | { | ||
27 | /* Our only 64-bit registers are GICD_IROUTER<n> */ | ||
28 | int irq; | ||
29 | @@ -XXX,XX +XXX,XX @@ static MemTxResult gicd_writell(GICv3State *s, hwaddr offset, | ||
30 | } | ||
31 | } | ||
32 | |||
33 | -static MemTxResult gicd_readll(GICv3State *s, hwaddr offset, | ||
34 | - uint64_t *data, MemTxAttrs attrs) | ||
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; | ||
117 | -- | 58 | -- |
118 | 2.20.1 | 59 | 2.20.1 |
119 | 60 | ||
120 | 61 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> |
---|---|---|---|
2 | 2 | ||
3 | Replace deprecated qbus_reset_all by resettable_cold_reset_fn for | 3 | Quoting Peter Maydell: |
4 | the sysbus reset registration. | ||
5 | 4 | ||
6 | Apart for the raspi machines, this does not impact the behavior | 5 | These MEMTX_* aren't from the memory transaction API functions; |
7 | because: | 6 | they're just being used by gicd_readl() and friends as a way to |
8 | + at this point resettable just calls the old reset methods of devices | 7 | indicate a success/failure so that the actual MemoryRegionOps |
9 | and buses in the same order as qdev/qbus. | 8 | read/write fns like gicv3_dist_read() can log a guest error. |
10 | + resettable handlers registered with qemu_register_reset are | 9 | Arguably this is a bit of a misuse of the MEMTX_* constants and |
11 | serialized; there is no interleaving. | 10 | perhaps we should have gicd_readl etc return a bool instead. |
12 | + eventual explicit calls to legacy reset API (device_reset or | ||
13 | qdev/qbus_reset) inside this reset handler will not be masked out | ||
14 | by resettable mechanism; they do not go through resettable api. | ||
15 | 11 | ||
16 | For the raspi machines, during the sysbus reset the sd-card is not | 12 | Follow his suggestion and replace the MEMTX_* constants by |
17 | reset twice anymore but only once. This is a consequence of switching | 13 | boolean values, simplifying a bit the gicv3_dist_read() / |
18 | both sysbus reset and changing parent to resettable; it detects the | 14 | gicv3_dist_write() handlers. |
19 | second reset is not needed. This has no impact on the state after | ||
20 | reset; the sd-card reset method only reset local state and query | ||
21 | information from the block backend. | ||
22 | 15 | ||
23 | The raspi reset change can be observed by using the following command | 16 | Suggested-by: Peter Maydell <peter.maydell@linaro.org> |
24 | (reset will occurs, then do Ctrl-C to end qemu; no firmware is | 17 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> |
25 | given here). | 18 | Message-id: 20210826180704.2131949-3-philmd@redhat.com |
26 | qemu-system-aarch64 -M raspi3 \ | ||
27 | -trace resettable_phase_hold_exec \ | ||
28 | -trace qdev_update_parent_bus \ | ||
29 | -trace resettable_change_parent \ | ||
30 | -trace qdev_reset -trace qbus_reset | ||
31 | |||
32 | Before the patch, the qdev/qbus_reset traces show when reset method are | ||
33 | called. After the patch, the resettable_phase_hold_exec show when reset | ||
34 | method are called. | ||
35 | |||
36 | The traced reset order of the raspi3 is listed below. I've added empty | ||
37 | lines and the tree structure. | ||
38 | |||
39 | +->bcm2835-peripherals reset | ||
40 | | | ||
41 | | +->sd-card reset | ||
42 | | +->sd-bus reset | ||
43 | +->bcm2835_gpio reset | ||
44 | | -> dev_update_parent_bus (move the sd-card on the sdhci-bus) | ||
45 | | -> resettable_change_parent | ||
46 | | | ||
47 | +->bcm2835-dma reset | ||
48 | | | ||
49 | | +->bcm2835-sdhost-bus reset | ||
50 | +->bcm2835-sdhost reset | ||
51 | | | ||
52 | | +->sd-card (reset ONLY BEFORE BEFORE THE PATCH) | ||
53 | | +->sdhci-bus reset | ||
54 | +->generic-sdhci reset | ||
55 | | | ||
56 | +->bcm2835-rng reset | ||
57 | +->bcm2835-property reset | ||
58 | +->bcm2835-fb reset | ||
59 | +->bcm2835-mbox reset | ||
60 | +->bcm2835-aux reset | ||
61 | +->pl011 reset | ||
62 | +->bcm2835-ic reset | ||
63 | +->bcm2836-control reset | ||
64 | System reset | ||
65 | |||
66 | In both case, the sd-card is reset (being on bcm2835_gpio/sd-bus) then moved | ||
67 | to generic-sdhci/sdhci-bus by the bcm2835_gpio reset method. | ||
68 | |||
69 | Before the patch, it is then reset again being part of generic-sdhci/sdhci-bus. | ||
70 | After the patch, it considered again for reset but its reset method is not | ||
71 | called because it is already flagged as reset. | ||
72 | |||
73 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
74 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
75 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
76 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
77 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
78 | Message-id: 20200123132823.1117486-11-damien.hedde@greensocs.com | ||
79 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
80 | --- | 20 | --- |
81 | vl.c | 10 +++++++++- | 21 | hw/intc/arm_gicv3_dist.c | 201 +++++++++++++++++++++------------------ |
82 | 1 file changed, 9 insertions(+), 1 deletion(-) | 22 | 1 file changed, 106 insertions(+), 95 deletions(-) |
83 | 23 | ||
84 | diff --git a/vl.c b/vl.c | 24 | diff --git a/hw/intc/arm_gicv3_dist.c b/hw/intc/arm_gicv3_dist.c |
85 | index XXXXXXX..XXXXXXX 100644 | 25 | index XXXXXXX..XXXXXXX 100644 |
86 | --- a/vl.c | 26 | --- a/hw/intc/arm_gicv3_dist.c |
87 | +++ b/vl.c | 27 | +++ b/hw/intc/arm_gicv3_dist.c |
88 | @@ -XXX,XX +XXX,XX @@ int main(int argc, char **argv, char **envp) | 28 | @@ -XXX,XX +XXX,XX @@ static void gicd_write_irouter(GICv3State *s, MemTxAttrs attrs, int irq, |
89 | 29 | gicv3_update(s, irq, 1); | |
90 | /* TODO: once all bus devices are qdevified, this should be done | 30 | } |
91 | * when bus is created by qdev.c */ | 31 | |
92 | - qemu_register_reset(qbus_reset_all_fn, sysbus_get_default()); | 32 | -static MemTxResult gicd_readb(GICv3State *s, hwaddr offset, |
93 | + /* | 33 | - uint64_t *data, MemTxAttrs attrs) |
94 | + * TODO: If we had a main 'reset container' that the whole system | 34 | +/** |
95 | + * lived in, we could reset that using the multi-phase reset | 35 | + * gicd_readb |
96 | + * APIs. For the moment, we just reset the sysbus, which will cause | 36 | + * gicd_readw |
97 | + * all devices hanging off it (and all their child buses, recursively) | 37 | + * gicd_readl |
98 | + * to be reset. Note that this will *not* reset any Device objects | 38 | + * gicd_readq |
99 | + * which are not attached to some part of the qbus tree! | 39 | + * gicd_writeb |
100 | + */ | 40 | + * gicd_writew |
101 | + qemu_register_reset(resettable_cold_reset_fn, sysbus_get_default()); | 41 | + * gicd_writel |
102 | qemu_run_machine_init_done_notifiers(); | 42 | + * gicd_writeq |
103 | 43 | + * | |
104 | if (rom_check_and_register_reset() != 0) { | 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) | ||
105 | -- | 628 | -- |
106 | 2.20.1 | 629 | 2.20.1 |
107 | 630 | ||
108 | 631 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | From: Yanan Wang <wangyanan55@huawei.com> |
---|---|---|---|
2 | 2 | ||
3 | Provide a temporary device_legacy_reset function doing what | 3 | Add 6.2 machine types for arm/i440fx/q35/s390x/spapr. |
4 | device_reset does to prepare for the transition with Resettable | 4 | |
5 | API. | 5 | Signed-off-by: Yanan Wang <wangyanan55@huawei.com> |
6 | |||
7 | All occurrence of device_reset in the code tree are also replaced | ||
8 | by device_legacy_reset. | ||
9 | |||
10 | The new resettable API has different prototype and semantics | ||
11 | (resetting child buses as well as the specified device). Subsequent | ||
12 | commits will make the changeover for each call site individually; once | ||
13 | that is complete device_legacy_reset() will be removed. | ||
14 | |||
15 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
18 | Acked-by: David Gibson <david@gibson.dropbear.id.au> | 6 | Acked-by: David Gibson <david@gibson.dropbear.id.au> |
19 | Acked-by: Cornelia Huck <cohuck@redhat.com> | 7 | Reviewed-by: Andrew Jones <drjones@redhat.com> |
20 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 8 | Reviewed-by: Cornelia Huck <cohuck@redhat.com> |
21 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 9 | Reviewed-by: Pankaj Gupta <pankaj.gupta@ionos.com> |
22 | Message-id: 20200123132823.1117486-2-damien.hedde@greensocs.com | ||
23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
24 | --- | 11 | --- |
25 | include/hw/qdev-core.h | 4 ++-- | 12 | include/hw/boards.h | 3 +++ |
26 | hw/audio/intel-hda.c | 2 +- | 13 | include/hw/i386/pc.h | 3 +++ |
27 | hw/core/qdev.c | 6 +++--- | 14 | hw/arm/virt.c | 11 +++++++++-- |
28 | hw/hyperv/hyperv.c | 2 +- | 15 | hw/core/machine.c | 3 +++ |
29 | hw/i386/microvm.c | 2 +- | 16 | hw/i386/pc.c | 3 +++ |
30 | hw/i386/pc.c | 2 +- | 17 | hw/i386/pc_piix.c | 14 +++++++++++++- |
31 | hw/ide/microdrive.c | 8 ++++---- | 18 | hw/i386/pc_q35.c | 13 ++++++++++++- |
32 | hw/intc/spapr_xive.c | 2 +- | 19 | hw/ppc/spapr.c | 17 ++++++++++++++--- |
33 | hw/ppc/pnv_psi.c | 4 ++-- | 20 | hw/s390x/s390-virtio-ccw.c | 14 +++++++++++++- |
34 | hw/ppc/spapr_pci.c | 2 +- | 21 | 9 files changed, 73 insertions(+), 8 deletions(-) |
35 | hw/ppc/spapr_vio.c | 2 +- | 22 | |
36 | hw/s390x/s390-pci-inst.c | 2 +- | 23 | diff --git a/include/hw/boards.h b/include/hw/boards.h |
37 | hw/scsi/vmw_pvscsi.c | 2 +- | 24 | index XXXXXXX..XXXXXXX 100644 |
38 | hw/sd/omap_mmc.c | 2 +- | 25 | --- a/include/hw/boards.h |
39 | hw/sd/pl181.c | 2 +- | 26 | +++ b/include/hw/boards.h |
40 | 15 files changed, 22 insertions(+), 22 deletions(-) | 27 | @@ -XXX,XX +XXX,XX @@ struct MachineState { |
41 | 28 | } \ | |
42 | diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h | 29 | type_init(machine_initfn##_register_types) |
43 | index XXXXXXX..XXXXXXX 100644 | 30 | |
44 | --- a/include/hw/qdev-core.h | 31 | +extern GlobalProperty hw_compat_6_1[]; |
45 | +++ b/include/hw/qdev-core.h | 32 | +extern const size_t hw_compat_6_1_len; |
46 | @@ -XXX,XX +XXX,XX @@ char *qdev_get_own_fw_dev_path_from_handler(BusState *bus, DeviceState *dev); | 33 | + |
47 | void qdev_machine_init(void); | 34 | extern GlobalProperty hw_compat_6_0[]; |
48 | 35 | extern const size_t hw_compat_6_0_len; | |
49 | /** | 36 | |
50 | - * @device_reset | 37 | diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h |
51 | + * device_legacy_reset: | 38 | index XXXXXXX..XXXXXXX 100644 |
52 | * | 39 | --- a/include/hw/i386/pc.h |
53 | * Reset a single device (by calling the reset method). | 40 | +++ b/include/hw/i386/pc.h |
54 | */ | 41 | @@ -XXX,XX +XXX,XX @@ void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size); |
55 | -void device_reset(DeviceState *dev); | 42 | void pc_madt_cpu_entry(AcpiDeviceIf *adev, int uid, |
56 | +void device_legacy_reset(DeviceState *dev); | 43 | const CPUArchIdList *apic_ids, GArray *entry); |
57 | 44 | ||
58 | void device_class_set_props(DeviceClass *dc, Property *props); | 45 | +extern GlobalProperty pc_compat_6_1[]; |
59 | 46 | +extern const size_t pc_compat_6_1_len; | |
60 | diff --git a/hw/audio/intel-hda.c b/hw/audio/intel-hda.c | 47 | + |
61 | index XXXXXXX..XXXXXXX 100644 | 48 | extern GlobalProperty pc_compat_6_0[]; |
62 | --- a/hw/audio/intel-hda.c | 49 | extern const size_t pc_compat_6_0_len; |
63 | +++ b/hw/audio/intel-hda.c | 50 | |
64 | @@ -XXX,XX +XXX,XX @@ static void intel_hda_reset(DeviceState *dev) | 51 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c |
65 | QTAILQ_FOREACH(kid, &d->codecs.qbus.children, sibling) { | 52 | index XXXXXXX..XXXXXXX 100644 |
66 | DeviceState *qdev = kid->child; | 53 | --- a/hw/arm/virt.c |
67 | cdev = HDA_CODEC_DEVICE(qdev); | 54 | +++ b/hw/arm/virt.c |
68 | - device_reset(DEVICE(cdev)); | 55 | @@ -XXX,XX +XXX,XX @@ static void machvirt_machine_init(void) |
69 | + device_legacy_reset(DEVICE(cdev)); | 56 | } |
70 | d->state_sts |= (1 << cdev->cad); | 57 | type_init(machvirt_machine_init); |
71 | } | 58 | |
72 | intel_hda_update_irq(d); | 59 | -static void virt_machine_6_1_options(MachineClass *mc) |
73 | diff --git a/hw/core/qdev.c b/hw/core/qdev.c | 60 | +static void virt_machine_6_2_options(MachineClass *mc) |
74 | index XXXXXXX..XXXXXXX 100644 | 61 | { |
75 | --- a/hw/core/qdev.c | 62 | } |
76 | +++ b/hw/core/qdev.c | 63 | -DEFINE_VIRT_MACHINE_AS_LATEST(6, 1) |
77 | @@ -XXX,XX +XXX,XX @@ HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev) | 64 | +DEFINE_VIRT_MACHINE_AS_LATEST(6, 2) |
78 | 65 | + | |
79 | static int qdev_reset_one(DeviceState *dev, void *opaque) | 66 | +static void virt_machine_6_1_options(MachineClass *mc) |
80 | { | 67 | +{ |
81 | - device_reset(dev); | 68 | + virt_machine_6_2_options(mc); |
82 | + device_legacy_reset(dev); | 69 | + compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); |
83 | 70 | +} | |
84 | return 0; | 71 | +DEFINE_VIRT_MACHINE(6, 1) |
85 | } | 72 | |
86 | @@ -XXX,XX +XXX,XX @@ static void device_set_realized(Object *obj, bool value, Error **errp) | 73 | static void virt_machine_6_0_options(MachineClass *mc) |
87 | } | 74 | { |
88 | } | 75 | diff --git a/hw/core/machine.c b/hw/core/machine.c |
89 | if (dev->hotplugged) { | 76 | index XXXXXXX..XXXXXXX 100644 |
90 | - device_reset(dev); | 77 | --- a/hw/core/machine.c |
91 | + device_legacy_reset(dev); | 78 | +++ b/hw/core/machine.c |
92 | } | 79 | @@ -XXX,XX +XXX,XX @@ |
93 | dev->pending_deleted_event = false; | 80 | #include "hw/virtio/virtio.h" |
94 | 81 | #include "hw/virtio/virtio-pci.h" | |
95 | @@ -XXX,XX +XXX,XX @@ void device_class_set_parent_unrealize(DeviceClass *dc, | 82 | |
96 | dc->unrealize = dev_unrealize; | 83 | +GlobalProperty hw_compat_6_1[] = {}; |
97 | } | 84 | +const size_t hw_compat_6_1_len = G_N_ELEMENTS(hw_compat_6_1); |
98 | 85 | + | |
99 | -void device_reset(DeviceState *dev) | 86 | GlobalProperty hw_compat_6_0[] = { |
100 | +void device_legacy_reset(DeviceState *dev) | 87 | { "gpex-pcihost", "allow-unmapped-accesses", "false" }, |
101 | { | 88 | { "i8042", "extended-state", "false"}, |
102 | DeviceClass *klass = DEVICE_GET_CLASS(dev); | ||
103 | |||
104 | diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c | ||
105 | index XXXXXXX..XXXXXXX 100644 | ||
106 | --- a/hw/hyperv/hyperv.c | ||
107 | +++ b/hw/hyperv/hyperv.c | ||
108 | @@ -XXX,XX +XXX,XX @@ void hyperv_synic_reset(CPUState *cs) | ||
109 | SynICState *synic = get_synic(cs); | ||
110 | |||
111 | if (synic) { | ||
112 | - device_reset(DEVICE(synic)); | ||
113 | + device_legacy_reset(DEVICE(synic)); | ||
114 | } | ||
115 | } | ||
116 | |||
117 | diff --git a/hw/i386/microvm.c b/hw/i386/microvm.c | ||
118 | index XXXXXXX..XXXXXXX 100644 | ||
119 | --- a/hw/i386/microvm.c | ||
120 | +++ b/hw/i386/microvm.c | ||
121 | @@ -XXX,XX +XXX,XX @@ static void microvm_machine_reset(MachineState *machine) | ||
122 | cpu = X86_CPU(cs); | ||
123 | |||
124 | if (cpu->apic_state) { | ||
125 | - device_reset(cpu->apic_state); | ||
126 | + device_legacy_reset(cpu->apic_state); | ||
127 | } | ||
128 | } | ||
129 | } | ||
130 | diff --git a/hw/i386/pc.c b/hw/i386/pc.c | 89 | diff --git a/hw/i386/pc.c b/hw/i386/pc.c |
131 | index XXXXXXX..XXXXXXX 100644 | 90 | index XXXXXXX..XXXXXXX 100644 |
132 | --- a/hw/i386/pc.c | 91 | --- a/hw/i386/pc.c |
133 | +++ b/hw/i386/pc.c | 92 | +++ b/hw/i386/pc.c |
134 | @@ -XXX,XX +XXX,XX @@ static void pc_machine_reset(MachineState *machine) | 93 | @@ -XXX,XX +XXX,XX @@ |
135 | cpu = X86_CPU(cs); | 94 | #include "trace.h" |
136 | 95 | #include CONFIG_DEVICES | |
137 | if (cpu->apic_state) { | 96 | |
138 | - device_reset(cpu->apic_state); | 97 | +GlobalProperty pc_compat_6_1[] = {}; |
139 | + device_legacy_reset(cpu->apic_state); | 98 | +const size_t pc_compat_6_1_len = G_N_ELEMENTS(pc_compat_6_1); |
140 | } | 99 | + |
141 | } | 100 | GlobalProperty pc_compat_6_0[] = { |
142 | } | 101 | { "qemu64" "-" TYPE_X86_CPU, "family", "6" }, |
143 | diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c | 102 | { "qemu64" "-" TYPE_X86_CPU, "model", "6" }, |
144 | index XXXXXXX..XXXXXXX 100644 | 103 | diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c |
145 | --- a/hw/ide/microdrive.c | 104 | index XXXXXXX..XXXXXXX 100644 |
146 | +++ b/hw/ide/microdrive.c | 105 | --- a/hw/i386/pc_piix.c |
147 | @@ -XXX,XX +XXX,XX @@ static void md_attr_write(PCMCIACardState *card, uint32_t at, uint8_t value) | 106 | +++ b/hw/i386/pc_piix.c |
148 | case 0x00: /* Configuration Option Register */ | 107 | @@ -XXX,XX +XXX,XX @@ static void pc_i440fx_machine_options(MachineClass *m) |
149 | s->opt = value & 0xcf; | 108 | machine_class_allow_dynamic_sysbus_dev(m, TYPE_VMBUS_BRIDGE); |
150 | if (value & OPT_SRESET) { | 109 | } |
151 | - device_reset(DEVICE(s)); | 110 | |
152 | + device_legacy_reset(DEVICE(s)); | 111 | -static void pc_i440fx_6_1_machine_options(MachineClass *m) |
153 | } | 112 | +static void pc_i440fx_6_2_machine_options(MachineClass *m) |
154 | md_interrupt_update(s); | 113 | { |
155 | break; | 114 | PCMachineClass *pcmc = PC_MACHINE_CLASS(m); |
156 | @@ -XXX,XX +XXX,XX @@ static void md_common_write(PCMCIACardState *card, uint32_t at, uint16_t value) | 115 | pc_i440fx_machine_options(m); |
157 | case 0xe: /* Device Control */ | 116 | @@ -XXX,XX +XXX,XX @@ static void pc_i440fx_6_1_machine_options(MachineClass *m) |
158 | s->ctrl = value; | 117 | pcmc->default_cpu_version = 1; |
159 | if (value & CTRL_SRST) { | 118 | } |
160 | - device_reset(DEVICE(s)); | 119 | |
161 | + device_legacy_reset(DEVICE(s)); | 120 | +DEFINE_I440FX_MACHINE(v6_2, "pc-i440fx-6.2", NULL, |
162 | } | 121 | + pc_i440fx_6_2_machine_options); |
163 | md_interrupt_update(s); | 122 | + |
164 | break; | 123 | +static void pc_i440fx_6_1_machine_options(MachineClass *m) |
165 | @@ -XXX,XX +XXX,XX @@ static int dscm1xxxx_attach(PCMCIACardState *card) | 124 | +{ |
166 | md->attr_base = pcc->cis[0x74] | (pcc->cis[0x76] << 8); | 125 | + pc_i440fx_6_2_machine_options(m); |
167 | md->io_base = 0x0; | 126 | + m->alias = NULL; |
168 | 127 | + m->is_default = false; | |
169 | - device_reset(DEVICE(md)); | 128 | + compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len); |
170 | + device_legacy_reset(DEVICE(md)); | 129 | + compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len); |
171 | md_interrupt_update(md); | 130 | +} |
172 | 131 | + | |
173 | return 0; | 132 | DEFINE_I440FX_MACHINE(v6_1, "pc-i440fx-6.1", NULL, |
174 | @@ -XXX,XX +XXX,XX @@ static int dscm1xxxx_detach(PCMCIACardState *card) | 133 | pc_i440fx_6_1_machine_options); |
175 | { | 134 | |
176 | MicroDriveState *md = MICRODRIVE(card); | 135 | diff --git a/hw/i386/pc_q35.c b/hw/i386/pc_q35.c |
177 | 136 | index XXXXXXX..XXXXXXX 100644 | |
178 | - device_reset(DEVICE(md)); | 137 | --- a/hw/i386/pc_q35.c |
179 | + device_legacy_reset(DEVICE(md)); | 138 | +++ b/hw/i386/pc_q35.c |
180 | return 0; | 139 | @@ -XXX,XX +XXX,XX @@ static void pc_q35_machine_options(MachineClass *m) |
181 | } | 140 | m->max_cpus = 288; |
182 | 141 | } | |
183 | diff --git a/hw/intc/spapr_xive.c b/hw/intc/spapr_xive.c | 142 | |
184 | index XXXXXXX..XXXXXXX 100644 | 143 | -static void pc_q35_6_1_machine_options(MachineClass *m) |
185 | --- a/hw/intc/spapr_xive.c | 144 | +static void pc_q35_6_2_machine_options(MachineClass *m) |
186 | +++ b/hw/intc/spapr_xive.c | 145 | { |
187 | @@ -XXX,XX +XXX,XX @@ static target_ulong h_int_reset(PowerPCCPU *cpu, | 146 | PCMachineClass *pcmc = PC_MACHINE_CLASS(m); |
188 | return H_PARAMETER; | 147 | pc_q35_machine_options(m); |
189 | } | 148 | @@ -XXX,XX +XXX,XX @@ static void pc_q35_6_1_machine_options(MachineClass *m) |
190 | 149 | pcmc->default_cpu_version = 1; | |
191 | - device_reset(DEVICE(xive)); | 150 | } |
192 | + device_legacy_reset(DEVICE(xive)); | 151 | |
193 | 152 | +DEFINE_Q35_MACHINE(v6_2, "pc-q35-6.2", NULL, | |
194 | if (kvm_irqchip_in_kernel()) { | 153 | + pc_q35_6_2_machine_options); |
195 | Error *local_err = NULL; | 154 | + |
196 | diff --git a/hw/ppc/pnv_psi.c b/hw/ppc/pnv_psi.c | 155 | +static void pc_q35_6_1_machine_options(MachineClass *m) |
197 | index XXXXXXX..XXXXXXX 100644 | 156 | +{ |
198 | --- a/hw/ppc/pnv_psi.c | 157 | + pc_q35_6_2_machine_options(m); |
199 | +++ b/hw/ppc/pnv_psi.c | 158 | + m->alias = NULL; |
200 | @@ -XXX,XX +XXX,XX @@ static void pnv_psi_reset(DeviceState *dev) | 159 | + compat_props_add(m->compat_props, hw_compat_6_1, hw_compat_6_1_len); |
201 | 160 | + compat_props_add(m->compat_props, pc_compat_6_1, pc_compat_6_1_len); | |
202 | static void pnv_psi_reset_handler(void *dev) | 161 | +} |
203 | { | 162 | + |
204 | - device_reset(DEVICE(dev)); | 163 | DEFINE_Q35_MACHINE(v6_1, "pc-q35-6.1", NULL, |
205 | + device_legacy_reset(DEVICE(dev)); | 164 | pc_q35_6_1_machine_options); |
206 | } | 165 | |
207 | 166 | diff --git a/hw/ppc/spapr.c b/hw/ppc/spapr.c | |
208 | static void pnv_psi_realize(DeviceState *dev, Error **errp) | 167 | index XXXXXXX..XXXXXXX 100644 |
209 | @@ -XXX,XX +XXX,XX @@ static void pnv_psi_p9_mmio_write(void *opaque, hwaddr addr, | 168 | --- a/hw/ppc/spapr.c |
210 | break; | 169 | +++ b/hw/ppc/spapr.c |
211 | case PSIHB9_INTERRUPT_CONTROL: | 170 | @@ -XXX,XX +XXX,XX @@ static void spapr_machine_latest_class_options(MachineClass *mc) |
212 | if (val & PSIHB9_IRQ_RESET) { | 171 | type_init(spapr_machine_register_##suffix) |
213 | - device_reset(DEVICE(&psi9->source)); | 172 | |
214 | + device_legacy_reset(DEVICE(&psi9->source)); | 173 | /* |
215 | } | 174 | - * pseries-6.1 |
216 | psi->regs[reg] = val; | 175 | + * pseries-6.2 |
217 | break; | 176 | */ |
218 | diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c | 177 | -static void spapr_machine_6_1_class_options(MachineClass *mc) |
219 | index XXXXXXX..XXXXXXX 100644 | 178 | +static void spapr_machine_6_2_class_options(MachineClass *mc) |
220 | --- a/hw/ppc/spapr_pci.c | 179 | { |
221 | +++ b/hw/ppc/spapr_pci.c | 180 | /* Defaults for the latest behaviour inherited from the base class */ |
222 | @@ -XXX,XX +XXX,XX @@ static int spapr_phb_children_reset(Object *child, void *opaque) | 181 | } |
223 | DeviceState *dev = (DeviceState *) object_dynamic_cast(child, TYPE_DEVICE); | 182 | |
224 | 183 | -DEFINE_SPAPR_MACHINE(6_1, "6.1", true); | |
225 | if (dev) { | 184 | +DEFINE_SPAPR_MACHINE(6_2, "6.2", true); |
226 | - device_reset(dev); | 185 | + |
227 | + device_legacy_reset(dev); | 186 | +/* |
228 | } | 187 | + * pseries-6.1 |
229 | 188 | + */ | |
230 | return 0; | 189 | +static void spapr_machine_6_1_class_options(MachineClass *mc) |
231 | diff --git a/hw/ppc/spapr_vio.c b/hw/ppc/spapr_vio.c | 190 | +{ |
232 | index XXXXXXX..XXXXXXX 100644 | 191 | + spapr_machine_6_2_class_options(mc); |
233 | --- a/hw/ppc/spapr_vio.c | 192 | + compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); |
234 | +++ b/hw/ppc/spapr_vio.c | 193 | +} |
235 | @@ -XXX,XX +XXX,XX @@ int spapr_vio_send_crq(SpaprVioDevice *dev, uint8_t *crq) | 194 | + |
236 | static void spapr_vio_quiesce_one(SpaprVioDevice *dev) | 195 | +DEFINE_SPAPR_MACHINE(6_1, "6.1", false); |
237 | { | 196 | |
238 | if (dev->tcet) { | 197 | /* |
239 | - device_reset(DEVICE(dev->tcet)); | 198 | * pseries-6.0 |
240 | + device_legacy_reset(DEVICE(dev->tcet)); | 199 | diff --git a/hw/s390x/s390-virtio-ccw.c b/hw/s390x/s390-virtio-ccw.c |
241 | } | 200 | index XXXXXXX..XXXXXXX 100644 |
242 | free_crq(dev); | 201 | --- a/hw/s390x/s390-virtio-ccw.c |
243 | } | 202 | +++ b/hw/s390x/s390-virtio-ccw.c |
244 | diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c | 203 | @@ -XXX,XX +XXX,XX @@ bool css_migration_enabled(void) |
245 | index XXXXXXX..XXXXXXX 100644 | 204 | } \ |
246 | --- a/hw/s390x/s390-pci-inst.c | 205 | type_init(ccw_machine_register_##suffix) |
247 | +++ b/hw/s390x/s390-pci-inst.c | 206 | |
248 | @@ -XXX,XX +XXX,XX @@ int clp_service_call(S390CPU *cpu, uint8_t r2, uintptr_t ra) | 207 | +static void ccw_machine_6_2_instance_options(MachineState *machine) |
249 | stw_p(&ressetpci->hdr.rsp, CLP_RC_SETPCIFN_FHOP); | 208 | +{ |
250 | goto out; | 209 | +} |
251 | } | 210 | + |
252 | - device_reset(DEVICE(pbdev)); | 211 | +static void ccw_machine_6_2_class_options(MachineClass *mc) |
253 | + device_legacy_reset(DEVICE(pbdev)); | 212 | +{ |
254 | pbdev->fh &= ~FH_MASK_ENABLE; | 213 | +} |
255 | pbdev->state = ZPCI_FS_DISABLED; | 214 | +DEFINE_CCW_MACHINE(6_2, "6.2", true); |
256 | stl_p(&ressetpci->fh, pbdev->fh); | 215 | + |
257 | diff --git a/hw/scsi/vmw_pvscsi.c b/hw/scsi/vmw_pvscsi.c | 216 | static void ccw_machine_6_1_instance_options(MachineState *machine) |
258 | index XXXXXXX..XXXXXXX 100644 | 217 | { |
259 | --- a/hw/scsi/vmw_pvscsi.c | 218 | + ccw_machine_6_2_instance_options(machine); |
260 | +++ b/hw/scsi/vmw_pvscsi.c | 219 | } |
261 | @@ -XXX,XX +XXX,XX @@ pvscsi_on_cmd_reset_device(PVSCSIState *s) | 220 | |
262 | 221 | static void ccw_machine_6_1_class_options(MachineClass *mc) | |
263 | if (sdev != NULL) { | 222 | { |
264 | s->resetting++; | 223 | + ccw_machine_6_2_class_options(mc); |
265 | - device_reset(&sdev->qdev); | 224 | + compat_props_add(mc->compat_props, hw_compat_6_1, hw_compat_6_1_len); |
266 | + device_legacy_reset(&sdev->qdev); | 225 | } |
267 | s->resetting--; | 226 | -DEFINE_CCW_MACHINE(6_1, "6.1", true); |
268 | return PVSCSI_COMMAND_PROCESSING_SUCCEEDED; | 227 | +DEFINE_CCW_MACHINE(6_1, "6.1", false); |
269 | } | 228 | |
270 | diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c | 229 | static void ccw_machine_6_0_instance_options(MachineState *machine) |
271 | index XXXXXXX..XXXXXXX 100644 | 230 | { |
272 | --- a/hw/sd/omap_mmc.c | ||
273 | +++ b/hw/sd/omap_mmc.c | ||
274 | @@ -XXX,XX +XXX,XX @@ void omap_mmc_reset(struct omap_mmc_s *host) | ||
275 | * into any bus, and we must reset it manually. When omap_mmc is | ||
276 | * QOMified this must move into the QOM reset function. | ||
277 | */ | ||
278 | - device_reset(DEVICE(host->card)); | ||
279 | + device_legacy_reset(DEVICE(host->card)); | ||
280 | } | ||
281 | |||
282 | static uint64_t omap_mmc_read(void *opaque, hwaddr offset, | ||
283 | diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c | ||
284 | index XXXXXXX..XXXXXXX 100644 | ||
285 | --- a/hw/sd/pl181.c | ||
286 | +++ b/hw/sd/pl181.c | ||
287 | @@ -XXX,XX +XXX,XX @@ static void pl181_reset(DeviceState *d) | ||
288 | /* Since we're still using the legacy SD API the card is not plugged | ||
289 | * into any bus, and we must reset it manually. | ||
290 | */ | ||
291 | - device_reset(DEVICE(s->card)); | ||
292 | + device_legacy_reset(DEVICE(s->card)); | ||
293 | } | ||
294 | |||
295 | static void pl181_init(Object *obj) | ||
296 | -- | 231 | -- |
297 | 2.20.1 | 232 | 2.20.1 |
298 | 233 | ||
299 | 234 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 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 | Deprecate device_legacy_reset(), qdev_reset_all() and | ||
4 | qbus_reset_all() to be replaced by new functions | ||
5 | device_cold_reset() and bus_cold_reset() which uses resettable API. | ||
6 | |||
7 | Also introduce resettable_cold_reset_fn() which may be used as a | ||
8 | replacement for qdev_reset_all_fn and qbus_reset_all_fn(). | ||
9 | |||
10 | Following patches will be needed to look at legacy reset call sites | ||
11 | and switch to resettable api. The legacy functions will be removed | ||
12 | when unused. | ||
13 | |||
14 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
15 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
16 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
18 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
19 | Message-id: 20200123132823.1117486-9-damien.hedde@greensocs.com | ||
20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
21 | --- | 8 | --- |
22 | include/hw/qdev-core.h | 27 +++++++++++++++++++++++++++ | 9 | target/arm/helper-mve.h | 3 +++ |
23 | include/hw/resettable.h | 9 +++++++++ | 10 | target/arm/translate.h | 6 ++++++ |
24 | hw/core/bus.c | 5 +++++ | 11 | target/arm/mve.decode | 10 ++++++++++ |
25 | hw/core/qdev.c | 5 +++++ | 12 | target/arm/mve_helper.c | 40 +++++++++++++++++++++++++++++++++++++ |
26 | hw/core/resettable.c | 5 +++++ | 13 | target/arm/translate-mve.c | 17 ++++++++++++++++ |
27 | 5 files changed, 51 insertions(+) | 14 | target/arm/translate-neon.c | 6 ------ |
15 | 6 files changed, 76 insertions(+), 6 deletions(-) | ||
28 | 16 | ||
29 | diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h | 17 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
30 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/include/hw/qdev-core.h | 19 | --- a/target/arm/helper-mve.h |
32 | +++ b/include/hw/qdev-core.h | 20 | +++ b/target/arm/helper-mve.h |
33 | @@ -XXX,XX +XXX,XX @@ int qdev_walk_children(DeviceState *dev, | 21 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vhcadd270b, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
34 | qdev_walkerfn *post_devfn, qbus_walkerfn *post_busfn, | 22 | DEF_HELPER_FLAGS_4(mve_vhcadd270h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
35 | void *opaque); | 23 | DEF_HELPER_FLAGS_4(mve_vhcadd270w, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
36 | 24 | ||
37 | +/** | 25 | +DEF_HELPER_FLAGS_4(mve_vfaddh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
38 | + * @qdev_reset_all: | 26 | +DEF_HELPER_FLAGS_4(mve_vfadds, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
39 | + * Reset @dev. See @qbus_reset_all() for more details. | ||
40 | + * | ||
41 | + * Note: This function is deprecated and will be removed when it becomes unused. | ||
42 | + * Please use device_cold_reset() now. | ||
43 | + */ | ||
44 | void qdev_reset_all(DeviceState *dev); | ||
45 | void qdev_reset_all_fn(void *opaque); | ||
46 | |||
47 | @@ -XXX,XX +XXX,XX @@ void qdev_reset_all_fn(void *opaque); | ||
48 | * hard reset means that qbus_reset_all will reset all state of the device. | ||
49 | * For PCI devices, for example, this will include the base address registers | ||
50 | * or configuration space. | ||
51 | + * | ||
52 | + * Note: This function is deprecated and will be removed when it becomes unused. | ||
53 | + * Please use bus_cold_reset() now. | ||
54 | */ | ||
55 | void qbus_reset_all(BusState *bus); | ||
56 | void qbus_reset_all_fn(void *opaque); | ||
57 | |||
58 | +/** | ||
59 | + * device_cold_reset: | ||
60 | + * Reset device @dev and perform a recursive processing using the resettable | ||
61 | + * interface. It triggers a RESET_TYPE_COLD. | ||
62 | + */ | ||
63 | +void device_cold_reset(DeviceState *dev); | ||
64 | + | 27 | + |
65 | +/** | 28 | DEF_HELPER_FLAGS_4(mve_vadd_scalarb, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
66 | + * bus_cold_reset: | 29 | DEF_HELPER_FLAGS_4(mve_vadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
67 | + * | 30 | DEF_HELPER_FLAGS_4(mve_vadd_scalarw, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
68 | + * Reset bus @bus and perform a recursive processing using the resettable | 31 | diff --git a/target/arm/translate.h b/target/arm/translate.h |
69 | + * interface. It triggers a RESET_TYPE_COLD. | ||
70 | + */ | ||
71 | +void bus_cold_reset(BusState *bus); | ||
72 | + | ||
73 | /** | ||
74 | * device_is_in_reset: | ||
75 | * Return true if the device @dev is currently being reset. | ||
76 | @@ -XXX,XX +XXX,XX @@ void qdev_machine_init(void); | ||
77 | * device_legacy_reset: | ||
78 | * | ||
79 | * Reset a single device (by calling the reset method). | ||
80 | + * Note: This function is deprecated and will be removed when it becomes unused. | ||
81 | + * Please use device_cold_reset() now. | ||
82 | */ | ||
83 | void device_legacy_reset(DeviceState *dev); | ||
84 | |||
85 | diff --git a/include/hw/resettable.h b/include/hw/resettable.h | ||
86 | index XXXXXXX..XXXXXXX 100644 | 32 | index XXXXXXX..XXXXXXX 100644 |
87 | --- a/include/hw/resettable.h | 33 | --- a/target/arm/translate.h |
88 | +++ b/include/hw/resettable.h | 34 | +++ b/target/arm/translate.h |
89 | @@ -XXX,XX +XXX,XX @@ bool resettable_is_in_reset(Object *obj); | 35 | @@ -XXX,XX +XXX,XX @@ static inline int rsub_8(DisasContext *s, int x) |
90 | */ | 36 | return 8 - x; |
91 | void resettable_change_parent(Object *obj, Object *newp, Object *oldp); | ||
92 | |||
93 | +/** | ||
94 | + * resettable_cold_reset_fn: | ||
95 | + * Helper to call resettable_reset((Object *) opaque, RESET_TYPE_COLD). | ||
96 | + * | ||
97 | + * This function is typically useful to register a reset handler with | ||
98 | + * qemu_register_reset. | ||
99 | + */ | ||
100 | +void resettable_cold_reset_fn(void *opaque); | ||
101 | + | ||
102 | /** | ||
103 | * resettable_class_set_parent_phases: | ||
104 | * | ||
105 | diff --git a/hw/core/bus.c b/hw/core/bus.c | ||
106 | index XXXXXXX..XXXXXXX 100644 | ||
107 | --- a/hw/core/bus.c | ||
108 | +++ b/hw/core/bus.c | ||
109 | @@ -XXX,XX +XXX,XX @@ int qbus_walk_children(BusState *bus, | ||
110 | return 0; | ||
111 | } | 37 | } |
112 | 38 | ||
113 | +void bus_cold_reset(BusState *bus) | 39 | +static inline int neon_3same_fp_size(DisasContext *s, int x) |
114 | +{ | 40 | +{ |
115 | + resettable_reset(OBJECT(bus), RESET_TYPE_COLD); | 41 | + /* Convert 0==fp32, 1==fp16 into a MO_* value */ |
42 | + return MO_32 - x; | ||
116 | +} | 43 | +} |
117 | + | 44 | + |
118 | bool bus_is_in_reset(BusState *bus) | 45 | static inline int arm_dc_feature(DisasContext *dc, int feature) |
119 | { | 46 | { |
120 | return resettable_is_in_reset(OBJECT(bus)); | 47 | return (dc->features & (1ULL << feature)) != 0; |
121 | diff --git a/hw/core/qdev.c b/hw/core/qdev.c | 48 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode |
122 | index XXXXXXX..XXXXXXX 100644 | 49 | index XXXXXXX..XXXXXXX 100644 |
123 | --- a/hw/core/qdev.c | 50 | --- a/target/arm/mve.decode |
124 | +++ b/hw/core/qdev.c | 51 | +++ b/target/arm/mve.decode |
125 | @@ -XXX,XX +XXX,XX @@ void qbus_reset_all_fn(void *opaque) | 52 | @@ -XXX,XX +XXX,XX @@ |
126 | qbus_reset_all(bus); | 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) | ||
91 | { | ||
92 | @@ -XXX,XX +XXX,XX @@ DO_VMAXMINA(vmaxaw, 4, int32_t, uint32_t, DO_MAX) | ||
93 | DO_VMAXMINA(vminab, 1, int8_t, uint8_t, DO_MIN) | ||
94 | DO_VMAXMINA(vminah, 2, int16_t, uint16_t, DO_MIN) | ||
95 | DO_VMAXMINA(vminaw, 4, int32_t, uint32_t, DO_MIN) | ||
96 | + | ||
97 | +/* | ||
98 | + * 2-operand floating point. Note that if an element is partially | ||
99 | + * predicated we must do the FP operation to update the non-predicated | ||
100 | + * bytes, but we must be careful to avoid updating the FP exception | ||
101 | + * state unless byte 0 of the element was unpredicated. | ||
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 | + } | ||
129 | + | ||
130 | +#define DO_2OP_FP_ALL(OP, FN) \ | ||
131 | + DO_2OP_FP(OP##h, 2, float16, float16_##FN) \ | ||
132 | + DO_2OP_FP(OP##s, 4, float32, float32_##FN) | ||
133 | + | ||
134 | +DO_2OP_FP_ALL(vfadd, add) | ||
135 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
136 | index XXXXXXX..XXXXXXX 100644 | ||
137 | --- a/target/arm/translate-mve.c | ||
138 | +++ b/target/arm/translate-mve.c | ||
139 | @@ -XXX,XX +XXX,XX @@ static bool trans_VSBCI(DisasContext *s, arg_2op *a) | ||
140 | return do_2op(s, a, gen_helper_mve_vsbci); | ||
127 | } | 141 | } |
128 | 142 | ||
129 | +void device_cold_reset(DeviceState *dev) | 143 | +#define DO_2OP_FP(INSN, FN) \ |
130 | +{ | 144 | + static bool trans_##INSN(DisasContext *s, arg_2op *a) \ |
131 | + resettable_reset(OBJECT(dev), RESET_TYPE_COLD); | 145 | + { \ |
132 | +} | 146 | + static MVEGenTwoOpFn * const fns[] = { \ |
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 | + } | ||
133 | + | 157 | + |
134 | bool device_is_in_reset(DeviceState *dev) | 158 | +DO_2OP_FP(VADD_fp, vfadd) |
159 | + | ||
160 | static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, | ||
161 | MVEGenTwoOpScalarFn fn) | ||
135 | { | 162 | { |
136 | return resettable_is_in_reset(OBJECT(dev)); | 163 | diff --git a/target/arm/translate-neon.c b/target/arm/translate-neon.c |
137 | diff --git a/hw/core/resettable.c b/hw/core/resettable.c | ||
138 | index XXXXXXX..XXXXXXX 100644 | 164 | index XXXXXXX..XXXXXXX 100644 |
139 | --- a/hw/core/resettable.c | 165 | --- a/target/arm/translate-neon.c |
140 | +++ b/hw/core/resettable.c | 166 | +++ b/target/arm/translate-neon.c |
141 | @@ -XXX,XX +XXX,XX @@ void resettable_change_parent(Object *obj, Object *newp, Object *oldp) | 167 | @@ -XXX,XX +XXX,XX @@ |
142 | } | 168 | #include "translate.h" |
143 | } | 169 | #include "translate-a32.h" |
144 | 170 | ||
145 | +void resettable_cold_reset_fn(void *opaque) | 171 | -static inline int neon_3same_fp_size(DisasContext *s, int x) |
146 | +{ | 172 | -{ |
147 | + resettable_reset((Object *) opaque, RESET_TYPE_COLD); | 173 | - /* Convert 0==fp32, 1==fp16 into a MO_* value */ |
148 | +} | 174 | - return MO_32 - x; |
149 | + | 175 | -} |
150 | void resettable_class_set_parent_phases(ResettableClass *rc, | 176 | - |
151 | ResettableEnterPhase enter, | 177 | /* Include the generated Neon decoder */ |
152 | ResettableHoldPhase hold, | 178 | #include "decode-neon-dp.c.inc" |
179 | #include "decode-neon-ls.c.inc" | ||
153 | -- | 180 | -- |
154 | 2.20.1 | 181 | 2.20.1 |
155 | 182 | ||
156 | 183 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | Implement more simple 2-operand floating point MVE insns. |
---|---|---|---|
2 | 2 | ||
3 | This commit adds support of Resettable interface to buses and devices: | ||
4 | + ResettableState structure is added in the Bus/Device state | ||
5 | + Resettable methods are implemented. | ||
6 | + device/bus_is_in_reset function defined | ||
7 | |||
8 | This commit allows to transition the objects to the new | ||
9 | multi-phase interface without changing the reset behavior at all. | ||
10 | Object single reset method can be split into the 3 different phases | ||
11 | but the 3 phases are still executed in a row for a given object. | ||
12 | From the qdev/qbus reset api point of view, nothing is changed. | ||
13 | qdev_reset_all() and qbus_reset_all() are not modified as well as | ||
14 | device_legacy_reset(). | ||
15 | |||
16 | Transition of an object must be done from parent class to child class. | ||
17 | Care has been taken to allow the transition of a parent class | ||
18 | without requiring the child classes to be transitioned at the same | ||
19 | time. Note that SysBus and SysBusDevice class do not need any transition | ||
20 | because they do not override the legacy reset method. | ||
21 | |||
22 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
23 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
24 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
25 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
26 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
27 | Message-id: 20200123132823.1117486-5-damien.hedde@greensocs.com | ||
28 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
29 | --- | 5 | --- |
30 | tests/Makefile.include | 1 + | 6 | target/arm/helper-mve.h | 15 +++++++++++++++ |
31 | include/hw/qdev-core.h | 27 ++++++++++++ | 7 | target/arm/mve.decode | 6 ++++++ |
32 | hw/core/bus.c | 97 ++++++++++++++++++++++++++++++++++++++++++ | 8 | target/arm/mve_helper.c | 16 ++++++++++++++++ |
33 | hw/core/qdev.c | 93 ++++++++++++++++++++++++++++++++++++++++ | 9 | target/arm/translate-mve.c | 5 +++++ |
34 | 4 files changed, 218 insertions(+) | 10 | 4 files changed, 42 insertions(+) |
35 | 11 | ||
36 | diff --git a/tests/Makefile.include b/tests/Makefile.include | 12 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
37 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
38 | --- a/tests/Makefile.include | 14 | --- a/target/arm/helper-mve.h |
39 | +++ b/tests/Makefile.include | 15 | +++ b/target/arm/helper-mve.h |
40 | @@ -XXX,XX +XXX,XX @@ tests/fp/%: | 16 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vhcadd270w, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
41 | tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ | 17 | DEF_HELPER_FLAGS_4(mve_vfaddh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
42 | hw/core/qdev.o hw/core/qdev-properties.o hw/core/hotplug.o\ | 18 | DEF_HELPER_FLAGS_4(mve_vfadds, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
43 | hw/core/bus.o \ | 19 | |
44 | + hw/core/resettable.o \ | 20 | +DEF_HELPER_FLAGS_4(mve_vfsubh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
45 | hw/core/irq.o \ | 21 | +DEF_HELPER_FLAGS_4(mve_vfsubs, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
46 | hw/core/fw-path-provider.o \ | 22 | + |
47 | hw/core/reset.o \ | 23 | +DEF_HELPER_FLAGS_4(mve_vfmulh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
48 | diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h | 24 | +DEF_HELPER_FLAGS_4(mve_vfmuls, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
25 | + | ||
26 | +DEF_HELPER_FLAGS_4(mve_vfabdh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
27 | +DEF_HELPER_FLAGS_4(mve_vfabds, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
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) | ||
31 | + | ||
32 | +DEF_HELPER_FLAGS_4(mve_vminnmh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
33 | +DEF_HELPER_FLAGS_4(mve_vminnms, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
34 | + | ||
35 | DEF_HELPER_FLAGS_4(mve_vadd_scalarb, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
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 | ||
49 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
50 | --- a/include/hw/qdev-core.h | 40 | --- a/target/arm/mve.decode |
51 | +++ b/include/hw/qdev-core.h | 41 | +++ b/target/arm/mve.decode |
52 | @@ -XXX,XX +XXX,XX @@ | 42 | @@ -XXX,XX +XXX,XX @@ VCMPLE_scalar 1111 1110 0 . .. ... 1 ... 1 1111 1 1 1 0 .... @vcmp_scalar |
53 | #include "qemu/bitmap.h" | 43 | |
54 | #include "qom/object.h" | 44 | # 2-operand FP |
55 | #include "hw/hotplug.h" | 45 | VADD_fp 1110 1111 0 . 0 . ... 0 ... 0 1101 . 1 . 0 ... 0 @2op_fp |
56 | +#include "hw/resettable.h" | 46 | +VSUB_fp 1110 1111 0 . 1 . ... 0 ... 0 1101 . 1 . 0 ... 0 @2op_fp |
57 | 47 | +VMUL_fp 1111 1111 0 . 0 . ... 0 ... 0 1101 . 1 . 1 ... 0 @2op_fp | |
58 | enum { | 48 | +VABD_fp 1111 1111 0 . 1 . ... 0 ... 0 1101 . 1 . 0 ... 0 @2op_fp |
59 | DEV_NVECTORS_UNSPECIFIED = -1, | ||
60 | @@ -XXX,XX +XXX,XX @@ typedef struct DeviceClass { | ||
61 | bool hotpluggable; | ||
62 | |||
63 | /* callbacks */ | ||
64 | + /* | ||
65 | + * Reset method here is deprecated and replaced by methods in the | ||
66 | + * resettable class interface to implement a multi-phase reset. | ||
67 | + * TODO: remove once every reset callback is unused | ||
68 | + */ | ||
69 | DeviceReset reset; | ||
70 | DeviceRealize realize; | ||
71 | DeviceUnrealize unrealize; | ||
72 | @@ -XXX,XX +XXX,XX @@ struct NamedGPIOList { | ||
73 | /** | ||
74 | * DeviceState: | ||
75 | * @realized: Indicates whether the device has been fully constructed. | ||
76 | + * @reset: ResettableState for the device; handled by Resettable interface. | ||
77 | * | ||
78 | * This structure should not be accessed directly. We declare it here | ||
79 | * so that it can be embedded in individual device state structures. | ||
80 | @@ -XXX,XX +XXX,XX @@ struct DeviceState { | ||
81 | int num_child_bus; | ||
82 | int instance_id_alias; | ||
83 | int alias_required_for_version; | ||
84 | + ResettableState reset; | ||
85 | }; | ||
86 | |||
87 | struct DeviceListener { | ||
88 | @@ -XXX,XX +XXX,XX @@ typedef struct BusChild { | ||
89 | /** | ||
90 | * BusState: | ||
91 | * @hotplug_handler: link to a hotplug handler associated with bus. | ||
92 | + * @reset: ResettableState for the bus; handled by Resettable interface. | ||
93 | */ | ||
94 | struct BusState { | ||
95 | Object obj; | ||
96 | @@ -XXX,XX +XXX,XX @@ struct BusState { | ||
97 | int num_children; | ||
98 | QTAILQ_HEAD(, BusChild) children; | ||
99 | QLIST_ENTRY(BusState) sibling; | ||
100 | + ResettableState reset; | ||
101 | }; | ||
102 | |||
103 | /** | ||
104 | @@ -XXX,XX +XXX,XX @@ void qdev_reset_all_fn(void *opaque); | ||
105 | void qbus_reset_all(BusState *bus); | ||
106 | void qbus_reset_all_fn(void *opaque); | ||
107 | |||
108 | +/** | ||
109 | + * device_is_in_reset: | ||
110 | + * Return true if the device @dev is currently being reset. | ||
111 | + */ | ||
112 | +bool device_is_in_reset(DeviceState *dev); | ||
113 | + | 49 | + |
114 | +/** | 50 | +VMAXNM 1111 1111 0 . 0 . ... 0 ... 0 1111 . 1 . 1 ... 0 @2op_fp |
115 | + * bus_is_in_reset: | 51 | +VMINNM 1111 1111 0 . 1 . ... 0 ... 0 1111 . 1 . 1 ... 0 @2op_fp |
116 | + * Return true if the bus @bus is currently being reset. | 52 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c |
117 | + */ | 53 | index XXXXXXX..XXXXXXX 100644 |
118 | +bool bus_is_in_reset(BusState *bus); | 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) | ||
119 | + | 62 | + |
120 | /* This should go away once we get rid of the NULL bus hack */ | 63 | +static inline float16 float16_abd(float16 a, float16 b, float_status *s) |
121 | BusState *sysbus_get_default(void); | ||
122 | |||
123 | @@ -XXX,XX +XXX,XX @@ void device_legacy_reset(DeviceState *dev); | ||
124 | |||
125 | void device_class_set_props(DeviceClass *dc, Property *props); | ||
126 | |||
127 | +/** | ||
128 | + * device_class_set_parent_reset: | ||
129 | + * TODO: remove the function when DeviceClass's reset method | ||
130 | + * is not used anymore. | ||
131 | + */ | ||
132 | void device_class_set_parent_reset(DeviceClass *dc, | ||
133 | DeviceReset dev_reset, | ||
134 | DeviceReset *parent_reset); | ||
135 | diff --git a/hw/core/bus.c b/hw/core/bus.c | ||
136 | index XXXXXXX..XXXXXXX 100644 | ||
137 | --- a/hw/core/bus.c | ||
138 | +++ b/hw/core/bus.c | ||
139 | @@ -XXX,XX +XXX,XX @@ int qbus_walk_children(BusState *bus, | ||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | +bool bus_is_in_reset(BusState *bus) | ||
144 | +{ | 64 | +{ |
145 | + return resettable_is_in_reset(OBJECT(bus)); | 65 | + return float16_abs(float16_sub(a, b, s)); |
146 | +} | 66 | +} |
147 | + | 67 | + |
148 | +static ResettableState *bus_get_reset_state(Object *obj) | 68 | +static inline float32 float32_abd(float32 a, float32 b, float_status *s) |
149 | +{ | 69 | +{ |
150 | + BusState *bus = BUS(obj); | 70 | + return float32_abs(float32_sub(a, b, s)); |
151 | + return &bus->reset; | ||
152 | +} | 71 | +} |
153 | + | 72 | + |
154 | +static void bus_reset_child_foreach(Object *obj, ResettableChildCallback cb, | 73 | +DO_2OP_FP_ALL(vfabd, abd) |
155 | + void *opaque, ResetType type) | 74 | +DO_2OP_FP_ALL(vmaxnm, maxnum) |
156 | +{ | 75 | +DO_2OP_FP_ALL(vminnm, minnum) |
157 | + BusState *bus = BUS(obj); | 76 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
158 | + BusChild *kid; | ||
159 | + | ||
160 | + QTAILQ_FOREACH(kid, &bus->children, sibling) { | ||
161 | + cb(OBJECT(kid->child), opaque, type); | ||
162 | + } | ||
163 | +} | ||
164 | + | ||
165 | static void qbus_realize(BusState *bus, DeviceState *parent, const char *name) | ||
166 | { | ||
167 | const char *typename = object_get_typename(OBJECT(bus)); | ||
168 | @@ -XXX,XX +XXX,XX @@ static char *default_bus_get_fw_dev_path(DeviceState *dev) | ||
169 | return g_strdup(object_get_typename(OBJECT(dev))); | ||
170 | } | ||
171 | |||
172 | +/** | ||
173 | + * bus_phases_reset: | ||
174 | + * Transition reset method for buses to allow moving | ||
175 | + * smoothly from legacy reset method to multi-phases | ||
176 | + */ | ||
177 | +static void bus_phases_reset(BusState *bus) | ||
178 | +{ | ||
179 | + ResettableClass *rc = RESETTABLE_GET_CLASS(bus); | ||
180 | + | ||
181 | + if (rc->phases.enter) { | ||
182 | + rc->phases.enter(OBJECT(bus), RESET_TYPE_COLD); | ||
183 | + } | ||
184 | + if (rc->phases.hold) { | ||
185 | + rc->phases.hold(OBJECT(bus)); | ||
186 | + } | ||
187 | + if (rc->phases.exit) { | ||
188 | + rc->phases.exit(OBJECT(bus)); | ||
189 | + } | ||
190 | +} | ||
191 | + | ||
192 | +static void bus_transitional_reset(Object *obj) | ||
193 | +{ | ||
194 | + BusClass *bc = BUS_GET_CLASS(obj); | ||
195 | + | ||
196 | + /* | ||
197 | + * This will call either @bus_phases_reset (for multi-phases transitioned | ||
198 | + * buses) or a bus's specific method for not-yet transitioned buses. | ||
199 | + * In both case, it does not reset children. | ||
200 | + */ | ||
201 | + if (bc->reset) { | ||
202 | + bc->reset(BUS(obj)); | ||
203 | + } | ||
204 | +} | ||
205 | + | ||
206 | +/** | ||
207 | + * bus_get_transitional_reset: | ||
208 | + * check if the bus's class is ready for multi-phase | ||
209 | + */ | ||
210 | +static ResettableTrFunction bus_get_transitional_reset(Object *obj) | ||
211 | +{ | ||
212 | + BusClass *dc = BUS_GET_CLASS(obj); | ||
213 | + if (dc->reset != bus_phases_reset) { | ||
214 | + /* | ||
215 | + * dc->reset has been overridden by a subclass, | ||
216 | + * the bus is not ready for multi phase yet. | ||
217 | + */ | ||
218 | + return bus_transitional_reset; | ||
219 | + } | ||
220 | + return NULL; | ||
221 | +} | ||
222 | + | ||
223 | static void bus_class_init(ObjectClass *class, void *data) | ||
224 | { | ||
225 | BusClass *bc = BUS_CLASS(class); | ||
226 | + ResettableClass *rc = RESETTABLE_CLASS(class); | ||
227 | |||
228 | class->unparent = bus_unparent; | ||
229 | bc->get_fw_dev_path = default_bus_get_fw_dev_path; | ||
230 | + | ||
231 | + rc->get_state = bus_get_reset_state; | ||
232 | + rc->child_foreach = bus_reset_child_foreach; | ||
233 | + | ||
234 | + /* | ||
235 | + * @bus_phases_reset is put as the default reset method below, allowing | ||
236 | + * to do the multi-phase transition from base classes to leaf classes. It | ||
237 | + * allows a legacy-reset Bus class to extend a multi-phases-reset | ||
238 | + * Bus class for the following reason: | ||
239 | + * + If a base class B has been moved to multi-phase, then it does not | ||
240 | + * override this default reset method and may have defined phase methods. | ||
241 | + * + A child class C (extending class B) which uses | ||
242 | + * bus_class_set_parent_reset() (or similar means) to override the | ||
243 | + * reset method will still work as expected. @bus_phases_reset function | ||
244 | + * will be registered as the parent reset method and effectively call | ||
245 | + * parent reset phases. | ||
246 | + */ | ||
247 | + bc->reset = bus_phases_reset; | ||
248 | + rc->get_transitional_function = bus_get_transitional_reset; | ||
249 | } | ||
250 | |||
251 | static void qbus_finalize(Object *obj) | ||
252 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo bus_info = { | ||
253 | .instance_init = qbus_initfn, | ||
254 | .instance_finalize = qbus_finalize, | ||
255 | .class_init = bus_class_init, | ||
256 | + .interfaces = (InterfaceInfo[]) { | ||
257 | + { TYPE_RESETTABLE_INTERFACE }, | ||
258 | + { } | ||
259 | + }, | ||
260 | }; | ||
261 | |||
262 | static void bus_register_types(void) | ||
263 | diff --git a/hw/core/qdev.c b/hw/core/qdev.c | ||
264 | index XXXXXXX..XXXXXXX 100644 | 77 | index XXXXXXX..XXXXXXX 100644 |
265 | --- a/hw/core/qdev.c | 78 | --- a/target/arm/translate-mve.c |
266 | +++ b/hw/core/qdev.c | 79 | +++ b/target/arm/translate-mve.c |
267 | @@ -XXX,XX +XXX,XX @@ void qbus_reset_all_fn(void *opaque) | 80 | @@ -XXX,XX +XXX,XX @@ static bool trans_VSBCI(DisasContext *s, arg_2op *a) |
268 | qbus_reset_all(bus); | ||
269 | } | ||
270 | |||
271 | +bool device_is_in_reset(DeviceState *dev) | ||
272 | +{ | ||
273 | + return resettable_is_in_reset(OBJECT(dev)); | ||
274 | +} | ||
275 | + | ||
276 | +static ResettableState *device_get_reset_state(Object *obj) | ||
277 | +{ | ||
278 | + DeviceState *dev = DEVICE(obj); | ||
279 | + return &dev->reset; | ||
280 | +} | ||
281 | + | ||
282 | +static void device_reset_child_foreach(Object *obj, ResettableChildCallback cb, | ||
283 | + void *opaque, ResetType type) | ||
284 | +{ | ||
285 | + DeviceState *dev = DEVICE(obj); | ||
286 | + BusState *bus; | ||
287 | + | ||
288 | + QLIST_FOREACH(bus, &dev->child_bus, sibling) { | ||
289 | + cb(OBJECT(bus), opaque, type); | ||
290 | + } | ||
291 | +} | ||
292 | + | ||
293 | /* can be used as ->unplug() callback for the simple cases */ | ||
294 | void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev, | ||
295 | DeviceState *dev, Error **errp) | ||
296 | @@ -XXX,XX +XXX,XX @@ device_vmstate_if_get_id(VMStateIf *obj) | ||
297 | return qdev_get_dev_path(dev); | ||
298 | } | ||
299 | |||
300 | +/** | ||
301 | + * device_phases_reset: | ||
302 | + * Transition reset method for devices to allow moving | ||
303 | + * smoothly from legacy reset method to multi-phases | ||
304 | + */ | ||
305 | +static void device_phases_reset(DeviceState *dev) | ||
306 | +{ | ||
307 | + ResettableClass *rc = RESETTABLE_GET_CLASS(dev); | ||
308 | + | ||
309 | + if (rc->phases.enter) { | ||
310 | + rc->phases.enter(OBJECT(dev), RESET_TYPE_COLD); | ||
311 | + } | ||
312 | + if (rc->phases.hold) { | ||
313 | + rc->phases.hold(OBJECT(dev)); | ||
314 | + } | ||
315 | + if (rc->phases.exit) { | ||
316 | + rc->phases.exit(OBJECT(dev)); | ||
317 | + } | ||
318 | +} | ||
319 | + | ||
320 | +static void device_transitional_reset(Object *obj) | ||
321 | +{ | ||
322 | + DeviceClass *dc = DEVICE_GET_CLASS(obj); | ||
323 | + | ||
324 | + /* | ||
325 | + * This will call either @device_phases_reset (for multi-phases transitioned | ||
326 | + * devices) or a device's specific method for not-yet transitioned devices. | ||
327 | + * In both case, it does not reset children. | ||
328 | + */ | ||
329 | + if (dc->reset) { | ||
330 | + dc->reset(DEVICE(obj)); | ||
331 | + } | ||
332 | +} | ||
333 | + | ||
334 | +/** | ||
335 | + * device_get_transitional_reset: | ||
336 | + * check if the device's class is ready for multi-phase | ||
337 | + */ | ||
338 | +static ResettableTrFunction device_get_transitional_reset(Object *obj) | ||
339 | +{ | ||
340 | + DeviceClass *dc = DEVICE_GET_CLASS(obj); | ||
341 | + if (dc->reset != device_phases_reset) { | ||
342 | + /* | ||
343 | + * dc->reset has been overridden by a subclass, | ||
344 | + * the device is not ready for multi phase yet. | ||
345 | + */ | ||
346 | + return device_transitional_reset; | ||
347 | + } | ||
348 | + return NULL; | ||
349 | +} | ||
350 | + | ||
351 | static void device_class_init(ObjectClass *class, void *data) | ||
352 | { | ||
353 | DeviceClass *dc = DEVICE_CLASS(class); | ||
354 | VMStateIfClass *vc = VMSTATE_IF_CLASS(class); | ||
355 | + ResettableClass *rc = RESETTABLE_CLASS(class); | ||
356 | |||
357 | class->unparent = device_unparent; | ||
358 | |||
359 | @@ -XXX,XX +XXX,XX @@ static void device_class_init(ObjectClass *class, void *data) | ||
360 | dc->hotpluggable = true; | ||
361 | dc->user_creatable = true; | ||
362 | vc->get_id = device_vmstate_if_get_id; | ||
363 | + rc->get_state = device_get_reset_state; | ||
364 | + rc->child_foreach = device_reset_child_foreach; | ||
365 | + | ||
366 | + /* | ||
367 | + * @device_phases_reset is put as the default reset method below, allowing | ||
368 | + * to do the multi-phase transition from base classes to leaf classes. It | ||
369 | + * allows a legacy-reset Device class to extend a multi-phases-reset | ||
370 | + * Device class for the following reason: | ||
371 | + * + If a base class B has been moved to multi-phase, then it does not | ||
372 | + * override this default reset method and may have defined phase methods. | ||
373 | + * + A child class C (extending class B) which uses | ||
374 | + * device_class_set_parent_reset() (or similar means) to override the | ||
375 | + * reset method will still work as expected. @device_phases_reset function | ||
376 | + * will be registered as the parent reset method and effectively call | ||
377 | + * parent reset phases. | ||
378 | + */ | ||
379 | + dc->reset = device_phases_reset; | ||
380 | + rc->get_transitional_function = device_get_transitional_reset; | ||
381 | |||
382 | object_class_property_add_bool(class, "realized", | ||
383 | device_get_realized, device_set_realized, | ||
384 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo device_type_info = { | ||
385 | .class_size = sizeof(DeviceClass), | ||
386 | .interfaces = (InterfaceInfo[]) { | ||
387 | { TYPE_VMSTATE_IF }, | ||
388 | + { TYPE_RESETTABLE_INTERFACE }, | ||
389 | { } | ||
390 | } | 81 | } |
391 | }; | 82 | |
83 | DO_2OP_FP(VADD_fp, vfadd) | ||
84 | +DO_2OP_FP(VSUB_fp, vfsub) | ||
85 | +DO_2OP_FP(VMUL_fp, vfmul) | ||
86 | +DO_2OP_FP(VABD_fp, vfabd) | ||
87 | +DO_2OP_FP(VMAXNM, vmaxnm) | ||
88 | +DO_2OP_FP(VMINNM, vminnm) | ||
89 | |||
90 | static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, | ||
91 | MVEGenTwoOpScalarFn fn) | ||
392 | -- | 92 | -- |
393 | 2.20.1 | 93 | 2.20.1 |
394 | 94 | ||
395 | 95 | diff view generated by jsdifflib |
1 | From: Andrew Jones <drjones@redhat.com> | 1 | Implement the MVE VCADD insn. Note that here the size bit is the |
---|---|---|---|
2 | opposite sense to the other 2-operand fp insns. | ||
2 | 3 | ||
3 | Signed-off-by: Andrew Jones <drjones@redhat.com> | 4 | We don't check for the sz == 1 && Qd == Qm UNPREDICTABLE case, |
4 | Message-id: 20200120101023.16030-2-drjones@redhat.com | 5 | because that would mean we can't use the DO_2OP_FP macro in |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | translate-mve.c. |
7 | |||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 10 | --- |
8 | target/arm/kvm_arm.h | 46 ++++++++++++++++++++++++++------------------ | 11 | target/arm/helper-mve.h | 6 ++++++ |
9 | 1 file changed, 27 insertions(+), 19 deletions(-) | 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(-) | ||
10 | 16 | ||
11 | diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h | 17 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
12 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/target/arm/kvm_arm.h | 19 | --- a/target/arm/helper-mve.h |
14 | +++ b/target/arm/kvm_arm.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 | ||
15 | @@ -XXX,XX +XXX,XX @@ | 38 | @@ -XXX,XX +XXX,XX @@ |
16 | int kvm_arm_vcpu_init(CPUState *cs); | 39 | # 2 operand fp insns have size in bit 20: 1 for 16 bit, 0 for 32 bit, |
17 | 40 | # like Neon FP insns. | |
18 | /** | 41 | %2op_fp_size 20:1 !function=neon_3same_fp_size |
19 | - * kvm_arm_vcpu_finalize | 42 | +# VCADD is an exception, where bit 20 is 0 for 16 bit and 1 for 32 bit |
20 | + * kvm_arm_vcpu_finalize: | 43 | +%2op_fp_size_rev 20:1 !function=plus_1 |
21 | * @cs: CPUState | 44 | |
22 | - * @feature: int | 45 | # 1imm format immediate |
23 | + * @feature: feature to finalize | 46 | %imm_28_16_0 28:1 16:3 0:4 |
24 | * | 47 | @@ -XXX,XX +XXX,XX @@ |
25 | * Finalizes the configuration of the specified VCPU feature by | 48 | @2op_fp .... .... .... .... .... .... .... .... &2op \ |
26 | * invoking the KVM_ARM_VCPU_FINALIZE ioctl. Features requiring | 49 | qd=%qd qn=%qn qm=%qm size=%2op_fp_size |
27 | @@ -XXX,XX +XXX,XX @@ void kvm_arm_register_device(MemoryRegion *mr, uint64_t devid, uint64_t group, | 50 | |
28 | int kvm_arm_init_cpreg_list(ARMCPU *cpu); | 51 | +@2op_fp_size_rev .... .... .... .... .... .... .... .... &2op \ |
29 | 52 | + qd=%qd qn=%qn qm=%qm size=%2op_fp_size_rev | |
30 | /** | 53 | + |
31 | - * kvm_arm_reg_syncs_via_cpreg_list | 54 | # Vector loads and stores |
32 | - * regidx: KVM register index | 55 | |
33 | + * kvm_arm_reg_syncs_via_cpreg_list: | 56 | # Widening loads and narrowing stores: |
34 | + * @regidx: KVM register index | 57 | @@ -XXX,XX +XXX,XX @@ VABD_fp 1111 1111 0 . 1 . ... 0 ... 0 1101 . 1 . 0 ... 0 @2op_fp |
35 | * | 58 | |
36 | * Return true if this KVM register should be synchronized via the | 59 | VMAXNM 1111 1111 0 . 0 . ... 0 ... 0 1111 . 1 . 1 ... 0 @2op_fp |
37 | * cpreg list of arbitrary system registers, false if it is synchronized | 60 | VMINNM 1111 1111 0 . 1 . ... 0 ... 0 1111 . 1 . 1 ... 0 @2op_fp |
38 | @@ -XXX,XX +XXX,XX @@ int kvm_arm_init_cpreg_list(ARMCPU *cpu); | 61 | + |
39 | bool kvm_arm_reg_syncs_via_cpreg_list(uint64_t regidx); | 62 | +VCADD90_fp 1111 1100 1 . 0 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev |
40 | 63 | +VCADD270_fp 1111 1101 1 . 0 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev | |
41 | /** | 64 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c |
42 | - * kvm_arm_cpreg_level | 65 | index XXXXXXX..XXXXXXX 100644 |
43 | - * regidx: KVM register index | 66 | --- a/target/arm/mve_helper.c |
44 | + * kvm_arm_cpreg_level: | 67 | +++ b/target/arm/mve_helper.c |
45 | + * @regidx: KVM register index | 68 | @@ -XXX,XX +XXX,XX @@ static inline float32 float32_abd(float32 a, float32 b, float_status *s) |
46 | * | 69 | DO_2OP_FP_ALL(vfabd, abd) |
47 | * Return the level of this coprocessor/system register. Return value is | 70 | DO_2OP_FP_ALL(vmaxnm, maxnum) |
48 | * either KVM_PUT_RUNTIME_STATE, KVM_PUT_RESET_STATE, or KVM_PUT_FULL_STATE. | 71 | DO_2OP_FP_ALL(vminnm, minnum) |
49 | @@ -XXX,XX +XXX,XX @@ void kvm_arm_init_serror_injection(CPUState *cs); | 72 | + |
50 | * @cpu: ARMCPU | 73 | +#define DO_VCADD_FP(OP, ESIZE, TYPE, FN0, FN1) \ |
51 | * | 74 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ |
52 | * Get VCPU related state from kvm. | 75 | + void *vd, void *vn, void *vm) \ |
53 | + * | 76 | + { \ |
54 | + * Returns: 0 if success else < 0 error code | 77 | + TYPE *d = vd, *n = vn, *m = vm; \ |
55 | */ | 78 | + TYPE r[16 / ESIZE]; \ |
56 | int kvm_get_vcpu_events(ARMCPU *cpu); | 79 | + uint16_t tm, mask = mve_element_mask(env); \ |
57 | 80 | + unsigned e; \ | |
58 | @@ -XXX,XX +XXX,XX @@ int kvm_get_vcpu_events(ARMCPU *cpu); | 81 | + float_status *fpst; \ |
59 | * @cpu: ARMCPU | 82 | + float_status scratch_fpst; \ |
60 | * | 83 | + /* Calculate all results first to avoid overwriting inputs */ \ |
61 | * Put VCPU related state to kvm. | 84 | + for (e = 0, tm = mask; e < 16 / ESIZE; e++, tm >>= ESIZE) { \ |
62 | + * | 85 | + if ((tm & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ |
63 | + * Returns: 0 if success else < 0 error code | 86 | + r[e] = 0; \ |
64 | */ | 87 | + continue; \ |
65 | int kvm_put_vcpu_events(ARMCPU *cpu); | 88 | + } \ |
66 | 89 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | |
67 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMHostCPUFeatures { | 90 | + &env->vfp.standard_fp_status; \ |
68 | 91 | + if (!(tm & 1)) { \ | |
69 | /** | 92 | + /* We need the result but without updating flags */ \ |
70 | * kvm_arm_get_host_cpu_features: | 93 | + scratch_fpst = *fpst; \ |
71 | - * @ahcc: ARMHostCPUClass to fill in | 94 | + fpst = &scratch_fpst; \ |
72 | + * @ahcf: ARMHostCPUClass to fill in | 95 | + } \ |
73 | * | 96 | + if (!(e & 1)) { \ |
74 | * Probe the capabilities of the host kernel's preferred CPU and fill | 97 | + r[e] = FN0(n[H##ESIZE(e)], m[H##ESIZE(e + 1)], fpst); \ |
75 | * in the ARMHostCPUClass struct accordingly. | 98 | + } else { \ |
76 | + * | 99 | + r[e] = FN1(n[H##ESIZE(e)], m[H##ESIZE(e - 1)], fpst); \ |
77 | + * Returns true on success and false otherwise. | 100 | + } \ |
78 | */ | 101 | + } \ |
79 | bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf); | 102 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ |
80 | 103 | + mergemask(&d[H##ESIZE(e)], r[e], mask); \ | |
81 | @@ -XXX,XX +XXX,XX @@ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu); | 104 | + } \ |
82 | bool kvm_arm_aarch32_supported(CPUState *cs); | 105 | + mve_advance_vpt(env); \ |
83 | 106 | + } | |
84 | /** | 107 | + |
85 | - * bool kvm_arm_pmu_supported: | 108 | +DO_VCADD_FP(vfcadd90h, 2, float16, float16_sub, float16_add) |
86 | + * kvm_arm_pmu_supported: | 109 | +DO_VCADD_FP(vfcadd90s, 4, float32, float32_sub, float32_add) |
87 | * @cs: CPUState | 110 | +DO_VCADD_FP(vfcadd270h, 2, float16, float16_add, float16_sub) |
88 | * | 111 | +DO_VCADD_FP(vfcadd270s, 4, float32, float32_add, float32_sub) |
89 | * Returns: true if the KVM VCPU can enable its PMU | 112 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
90 | @@ -XXX,XX +XXX,XX @@ bool kvm_arm_aarch32_supported(CPUState *cs); | 113 | index XXXXXXX..XXXXXXX 100644 |
91 | bool kvm_arm_pmu_supported(CPUState *cs); | 114 | --- a/target/arm/translate-mve.c |
92 | 115 | +++ b/target/arm/translate-mve.c | |
93 | /** | 116 | @@ -XXX,XX +XXX,XX @@ DO_2OP_FP(VMUL_fp, vfmul) |
94 | - * bool kvm_arm_sve_supported: | 117 | DO_2OP_FP(VABD_fp, vfabd) |
95 | + * kvm_arm_sve_supported: | 118 | DO_2OP_FP(VMAXNM, vmaxnm) |
96 | * @cs: CPUState | 119 | DO_2OP_FP(VMINNM, vminnm) |
97 | * | 120 | +DO_2OP_FP(VCADD90_fp, vfcadd90) |
98 | * Returns true if the KVM VCPU can enable SVE and false otherwise. | 121 | +DO_2OP_FP(VCADD270_fp, vfcadd270) |
99 | @@ -XXX,XX +XXX,XX @@ bool kvm_arm_pmu_supported(CPUState *cs); | 122 | |
100 | bool kvm_arm_sve_supported(CPUState *cs); | 123 | static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, |
101 | 124 | MVEGenTwoOpScalarFn fn) | |
102 | /** | 125 | @@ -XXX,XX +XXX,XX @@ static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, |
103 | - * kvm_arm_get_max_vm_ipa_size - Returns the number of bits in the | 126 | return true; |
104 | - * IPA address space supported by KVM | 127 | } |
105 | - * | 128 | |
106 | + * kvm_arm_get_max_vm_ipa_size: | 129 | -#define DO_2OP_SCALAR(INSN, FN) \ |
107 | * @ms: Machine state handle | 130 | +#define DO_2OP_SCALAR(INSN, FN) \ |
108 | + * | 131 | static bool trans_##INSN(DisasContext *s, arg_2scalar *a) \ |
109 | + * Returns the number of bits in the IPA address space supported by KVM | 132 | { \ |
110 | */ | 133 | static MVEGenTwoOpScalarFn * const fns[] = { \ |
111 | int kvm_arm_get_max_vm_ipa_size(MachineState *ms); | ||
112 | |||
113 | /** | ||
114 | - * kvm_arm_sync_mpstate_to_kvm | ||
115 | + * kvm_arm_sync_mpstate_to_kvm: | ||
116 | * @cpu: ARMCPU | ||
117 | * | ||
118 | * If supported set the KVM MP_STATE based on QEMU's model. | ||
119 | + * | ||
120 | + * Returns 0 on success and -1 on failure. | ||
121 | */ | ||
122 | int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu); | ||
123 | |||
124 | /** | ||
125 | - * kvm_arm_sync_mpstate_to_qemu | ||
126 | + * kvm_arm_sync_mpstate_to_qemu: | ||
127 | * @cpu: ARMCPU | ||
128 | * | ||
129 | * If supported get the MP_STATE from KVM and store in QEMU's model. | ||
130 | + * | ||
131 | + * Returns 0 on success and aborts on failure. | ||
132 | */ | ||
133 | int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu); | ||
134 | |||
135 | @@ -XXX,XX +XXX,XX @@ int kvm_arm_set_irq(int cpu, int irqtype, int irq, int level); | ||
136 | |||
137 | static inline void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu) | ||
138 | { | ||
139 | - /* This should never actually be called in the "not KVM" case, | ||
140 | + /* | ||
141 | + * This should never actually be called in the "not KVM" case, | ||
142 | * but set up the fields to indicate an error anyway. | ||
143 | */ | ||
144 | cpu->kvm_target = QEMU_KVM_ARM_TARGET_NONE; | ||
145 | @@ -XXX,XX +XXX,XX @@ bool kvm_arm_handle_debug(CPUState *cs, struct kvm_debug_exit_arch *debug_exit); | ||
146 | * | ||
147 | * Return: TRUE if any hardware breakpoints in use. | ||
148 | */ | ||
149 | - | ||
150 | bool kvm_arm_hw_debug_active(CPUState *cs); | ||
151 | |||
152 | /** | ||
153 | * kvm_arm_copy_hw_debug_data: | ||
154 | - * | ||
155 | * @ptr: kvm_guest_debug_arch structure | ||
156 | * | ||
157 | * Copy the architecture specific debug registers into the | ||
158 | * kvm_guest_debug ioctl structure. | ||
159 | */ | ||
160 | struct kvm_guest_debug_arch; | ||
161 | - | ||
162 | void kvm_arm_copy_hw_debug_data(struct kvm_guest_debug_arch *ptr); | ||
163 | |||
164 | /** | ||
165 | - * its_class_name | ||
166 | + * its_class_name: | ||
167 | * | ||
168 | * Return the ITS class name to use depending on whether KVM acceleration | ||
169 | * and KVM CAP_SIGNAL_MSI are supported | ||
170 | -- | 134 | -- |
171 | 2.20.1 | 135 | 2.20.1 |
172 | 136 | ||
173 | 137 | diff view generated by jsdifflib |
1 | From: Zenghui Yu <yuzenghui@huawei.com> | 1 | Implement the MVE VFMA and VFMS insns. |
---|---|---|---|
2 | 2 | ||
3 | If LPIs are disabled, KVM will just ignore the GICR_PENDBASER.PTZ bit when | 3 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
4 | restoring GICR_CTLR. Setting PTZ here makes littlt sense in "reduce GIC | ||
5 | initialization time". | ||
6 | |||
7 | And what's worse, PTZ is generally programmed by guest to indicate to the | ||
8 | Redistributor whether the LPI Pending table is zero when enabling LPIs. | ||
9 | If migration is triggered when the PTZ has just been cleared by guest (and | ||
10 | before enabling LPIs), we will see PTZ==1 on the destination side, which | ||
11 | is not as expected. Let's just drop this hackish userspace behavior. | ||
12 | |||
13 | Also take this chance to refine the comment a bit. | ||
14 | |||
15 | Fixes: 367b9f527bec ("hw/intc/arm_gicv3_kvm: Implement get/put functions") | ||
16 | Signed-off-by: Zenghui Yu <yuzenghui@huawei.com> | ||
17 | Message-id: 20200119133051.642-1-yuzenghui@huawei.com | ||
18 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 5 | --- |
21 | hw/intc/arm_gicv3_kvm.c | 11 ++++------- | 6 | target/arm/helper-mve.h | 6 ++++++ |
22 | 1 file changed, 4 insertions(+), 7 deletions(-) | 7 | target/arm/mve.decode | 3 +++ |
8 | target/arm/mve_helper.c | 37 +++++++++++++++++++++++++++++++++++++ | ||
9 | target/arm/translate-mve.c | 2 ++ | ||
10 | 4 files changed, 48 insertions(+) | ||
23 | 11 | ||
24 | diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c | 12 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
25 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/intc/arm_gicv3_kvm.c | 14 | --- a/target/arm/helper-mve.h |
27 | +++ b/hw/intc/arm_gicv3_kvm.c | 15 | +++ b/target/arm/helper-mve.h |
28 | @@ -XXX,XX +XXX,XX @@ static void kvm_arm_gicv3_put(GICv3State *s) | 16 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vfcadd90s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
29 | kvm_gicd_access(s, GICD_CTLR, ®, true); | 17 | DEF_HELPER_FLAGS_4(mve_vfcadd270h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
30 | 18 | DEF_HELPER_FLAGS_4(mve_vfcadd270s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | |
31 | if (redist_typer & GICR_TYPER_PLPIS) { | 19 | |
32 | - /* Set base addresses before LPIs are enabled by GICR_CTLR write */ | 20 | +DEF_HELPER_FLAGS_4(mve_vfmah, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
33 | + /* | 21 | +DEF_HELPER_FLAGS_4(mve_vfmas, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
34 | + * Restore base addresses before LPIs are potentially enabled by | 22 | + |
35 | + * GICR_CTLR write | 23 | +DEF_HELPER_FLAGS_4(mve_vfmsh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
36 | + */ | 24 | +DEF_HELPER_FLAGS_4(mve_vfmss, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
37 | for (ncpu = 0; ncpu < s->num_cpu; ncpu++) { | 25 | + |
38 | GICv3CPUState *c = &s->cpu[ncpu]; | 26 | DEF_HELPER_FLAGS_4(mve_vadd_scalarb, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
39 | 27 | DEF_HELPER_FLAGS_4(mve_vadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | |
40 | @@ -XXX,XX +XXX,XX @@ static void kvm_arm_gicv3_put(GICv3State *s) | 28 | DEF_HELPER_FLAGS_4(mve_vadd_scalarw, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
41 | kvm_gicr_access(s, GICR_PROPBASER + 4, ncpu, ®h, true); | 29 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode |
42 | 30 | index XXXXXXX..XXXXXXX 100644 | |
43 | reg64 = c->gicr_pendbaser; | 31 | --- a/target/arm/mve.decode |
44 | - if (!(c->gicr_ctlr & GICR_CTLR_ENABLE_LPIS)) { | 32 | +++ b/target/arm/mve.decode |
45 | - /* Setting PTZ is advised if LPIs are disabled, to reduce | 33 | @@ -XXX,XX +XXX,XX @@ VMINNM 1111 1111 0 . 1 . ... 0 ... 0 1111 . 1 . 1 ... 0 @2op_fp |
46 | - * GIC initialization time. | 34 | |
47 | - */ | 35 | VCADD90_fp 1111 1100 1 . 0 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev |
48 | - reg64 |= GICR_PENDBASER_PTZ; | 36 | VCADD270_fp 1111 1101 1 . 0 . ... 0 ... 0 1000 . 1 . 0 ... 0 @2op_fp_size_rev |
49 | - } | 37 | + |
50 | regl = (uint32_t)reg64; | 38 | +VFMA 1110 1111 0 . 0 . ... 0 ... 0 1100 . 1 . 1 ... 0 @2op_fp |
51 | kvm_gicr_access(s, GICR_PENDBASER, ncpu, ®l, true); | 39 | +VFMS 1110 1111 0 . 1 . ... 0 ... 0 1100 . 1 . 1 ... 0 @2op_fp |
52 | regh = (uint32_t)(reg64 >> 32); | 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) | ||
48 | + | ||
49 | +#define DO_VFMA(OP, ESIZE, TYPE, CHS) \ | ||
50 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ | ||
51 | + void *vd, void *vn, void *vm) \ | ||
52 | + { \ | ||
53 | + TYPE *d = vd, *n = vn, *m = vm; \ | ||
54 | + TYPE r; \ | ||
55 | + uint16_t mask = mve_element_mask(env); \ | ||
56 | + unsigned e; \ | ||
57 | + float_status *fpst; \ | ||
58 | + float_status scratch_fpst; \ | ||
59 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ | ||
60 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ | ||
61 | + continue; \ | ||
62 | + } \ | ||
63 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | ||
64 | + &env->vfp.standard_fp_status; \ | ||
65 | + if (!(mask & 1)) { \ | ||
66 | + /* We need the result but without updating flags */ \ | ||
67 | + scratch_fpst = *fpst; \ | ||
68 | + fpst = &scratch_fpst; \ | ||
69 | + } \ | ||
70 | + r = n[H##ESIZE(e)]; \ | ||
71 | + if (CHS) { \ | ||
72 | + r = TYPE##_chs(r); \ | ||
73 | + } \ | ||
74 | + r = TYPE##_muladd(r, m[H##ESIZE(e)], d[H##ESIZE(e)], \ | ||
75 | + 0, fpst); \ | ||
76 | + mergemask(&d[H##ESIZE(e)], r, mask); \ | ||
77 | + } \ | ||
78 | + mve_advance_vpt(env); \ | ||
79 | + } | ||
80 | + | ||
81 | +DO_VFMA(vfmah, 2, float16, false) | ||
82 | +DO_VFMA(vfmas, 4, float32, false) | ||
83 | +DO_VFMA(vfmsh, 2, float16, true) | ||
84 | +DO_VFMA(vfmss, 4, float32, true) | ||
85 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
86 | index XXXXXXX..XXXXXXX 100644 | ||
87 | --- a/target/arm/translate-mve.c | ||
88 | +++ b/target/arm/translate-mve.c | ||
89 | @@ -XXX,XX +XXX,XX @@ DO_2OP_FP(VMAXNM, vmaxnm) | ||
90 | DO_2OP_FP(VMINNM, vminnm) | ||
91 | DO_2OP_FP(VCADD90_fp, vfcadd90) | ||
92 | DO_2OP_FP(VCADD270_fp, vfcadd270) | ||
93 | +DO_2OP_FP(VFMA, vfma) | ||
94 | +DO_2OP_FP(VFMS, vfms) | ||
95 | |||
96 | static bool do_2op_scalar(DisasContext *s, arg_2scalar *a, | ||
97 | MVEGenTwoOpScalarFn fn) | ||
53 | -- | 98 | -- |
54 | 2.20.1 | 99 | 2.20.1 |
55 | 100 | ||
56 | 101 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | Implement the MVE VCMUL and VCMLA insns. |
---|---|---|---|
2 | 2 | ||
3 | Replace deprecated qdev_reset_all by resettable_cold_reset_fn for | ||
4 | the ipl registration in the main reset handlers. | ||
5 | |||
6 | This does not impact the behavior for the following reasons: | ||
7 | + at this point resettable just call the old reset methods of devices | ||
8 | and buses in the same order than qdev/qbus. | ||
9 | + resettable handlers registered with qemu_register_reset are | ||
10 | serialized; there is no interleaving. | ||
11 | + eventual explicit calls to legacy reset API (device_reset or | ||
12 | qdev/qbus_reset) inside this reset handler will not be masked out | ||
13 | by resettable mechanism; they do not go through resettable api. | ||
14 | |||
15 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
16 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
17 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
18 | Reviewed-by: Cornelia Huck <cohuck@redhat.com> | ||
19 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
20 | Message-id: 20200123132823.1117486-12-damien.hedde@greensocs.com | ||
21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
22 | --- | 5 | --- |
23 | hw/s390x/ipl.c | 10 +++++++++- | 6 | target/arm/helper-mve.h | 18 ++++++++ |
24 | 1 file changed, 9 insertions(+), 1 deletion(-) | 7 | target/arm/mve.decode | 35 ++++++++++++---- |
25 | 8 | target/arm/mve_helper.c | 86 ++++++++++++++++++++++++++++++++++++++ | |
26 | diff --git a/hw/s390x/ipl.c b/hw/s390x/ipl.c | 9 | target/arm/translate-mve.c | 8 ++++ |
27 | index XXXXXXX..XXXXXXX 100644 | 10 | 4 files changed, 139 insertions(+), 8 deletions(-) |
28 | --- a/hw/s390x/ipl.c | 11 | |
29 | +++ b/hw/s390x/ipl.c | 12 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
30 | @@ -XXX,XX +XXX,XX @@ static void s390_ipl_realize(DeviceState *dev, Error **errp) | 13 | index XXXXXXX..XXXXXXX 100644 |
31 | */ | 14 | --- a/target/arm/helper-mve.h |
32 | ipl->compat_start_addr = ipl->start_addr; | 15 | +++ b/target/arm/helper-mve.h |
33 | ipl->compat_bios_start_addr = ipl->bios_start_addr; | 16 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vfmas, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
34 | - qemu_register_reset(qdev_reset_all_fn, dev); | 17 | DEF_HELPER_FLAGS_4(mve_vfmsh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
35 | + /* | 18 | DEF_HELPER_FLAGS_4(mve_vfmss, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
36 | + * Because this Device is not on any bus in the qbus tree (it is | 19 | |
37 | + * not a sysbus device and it's not on some other bus like a PCI | 20 | +DEF_HELPER_FLAGS_4(mve_vcmul0h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
38 | + * bus) it will not be automatically reset by the 'reset the | 21 | +DEF_HELPER_FLAGS_4(mve_vcmul0s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
39 | + * sysbus' hook registered by vl.c like most devices. So we must | 22 | +DEF_HELPER_FLAGS_4(mve_vcmul90h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
40 | + * manually register a reset hook for it. | 23 | +DEF_HELPER_FLAGS_4(mve_vcmul90s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
41 | + * TODO: there should be a better way to do this. | 24 | +DEF_HELPER_FLAGS_4(mve_vcmul180h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
42 | + */ | 25 | +DEF_HELPER_FLAGS_4(mve_vcmul180s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
43 | + qemu_register_reset(resettable_cold_reset_fn, dev); | 26 | +DEF_HELPER_FLAGS_4(mve_vcmul270h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
44 | error: | 27 | +DEF_HELPER_FLAGS_4(mve_vcmul270s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
45 | error_propagate(errp, err); | 28 | + |
46 | } | 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) | ||
47 | -- | 205 | -- |
48 | 2.20.1 | 206 | 2.20.1 |
49 | 207 | ||
50 | 208 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 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 | The overhead for the OpenBMC firmware images using the a custom U-Boot | 5 | We defer the decode of the size in bit 28 to the individual insn |
4 | is around 2 seconds, which is fine, but with a U-Boot from mainline, | 6 | patterns rather than doing it in the format, because otherwise we |
5 | it takes an extra 50 seconds or so to reach Linux. A quick survey on | 7 | would have a single insn pattern that overlapped with two groups (eg |
6 | the number of reads performed on the flash memory region gives the | 8 | VMAXNMA with the VMULH_S and VMULH_U groups). Having two insn |
7 | following figures : | 9 | patterns per insn seems clearer than a complex multilevel nesting |
10 | of overlapping and non-overlapping groups. | ||
8 | 11 | ||
9 | OpenBMC U-Boot 922478 (~ 3.5 MBytes) | 12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
10 | Mainline U-Boot 20569977 (~ 80 MBytes) | ||
11 | |||
12 | QEMU must be trashing the TCG TBs and reloading text very often. Some | ||
13 | addresses are read more than 250.000 times. Until we find a solution | ||
14 | to improve boot time, execution from MMIO is not activated by default. | ||
15 | |||
16 | Setting this option also breaks migration compatibility. | ||
17 | |||
18 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
19 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
20 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
21 | Message-id: 20200114103433.30534-5-clg@kaod.org | ||
22 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
23 | --- | 14 | --- |
24 | include/hw/arm/aspeed.h | 2 ++ | 15 | target/arm/helper-mve.h | 6 ++++++ |
25 | hw/arm/aspeed.c | 44 ++++++++++++++++++++++++++++++++++++----- | 16 | target/arm/mve.decode | 11 +++++++++++ |
26 | 2 files changed, 41 insertions(+), 5 deletions(-) | 17 | target/arm/mve_helper.c | 23 +++++++++++++++++++++++ |
18 | target/arm/translate-mve.c | 2 ++ | ||
19 | 4 files changed, 42 insertions(+) | ||
27 | 20 | ||
28 | diff --git a/include/hw/arm/aspeed.h b/include/hw/arm/aspeed.h | 21 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
29 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/include/hw/arm/aspeed.h | 23 | --- a/target/arm/helper-mve.h |
31 | +++ b/include/hw/arm/aspeed.h | 24 | +++ b/target/arm/helper-mve.h |
32 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedBoardState AspeedBoardState; | 25 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vmaxnms, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
33 | 26 | DEF_HELPER_FLAGS_4(mve_vminnmh, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | |
34 | typedef struct AspeedMachine { | 27 | DEF_HELPER_FLAGS_4(mve_vminnms, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
35 | MachineState parent_obj; | 28 | |
29 | +DEF_HELPER_FLAGS_4(mve_vmaxnmah, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
30 | +DEF_HELPER_FLAGS_4(mve_vmaxnmas, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) | ||
36 | + | 31 | + |
37 | + bool mmio_exec; | 32 | +DEF_HELPER_FLAGS_4(mve_vminnmah, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
38 | } AspeedMachine; | 33 | +DEF_HELPER_FLAGS_4(mve_vminnmas, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
39 | 34 | + | |
40 | #define ASPEED_MACHINE_CLASS(klass) \ | 35 | DEF_HELPER_FLAGS_4(mve_vfcadd90h, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
41 | diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c | 36 | DEF_HELPER_FLAGS_4(mve_vfcadd90s, TCG_CALL_NO_WG, void, env, ptr, ptr, ptr) |
37 | |||
38 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode | ||
42 | index XXXXXXX..XXXXXXX 100644 | 39 | index XXXXXXX..XXXXXXX 100644 |
43 | --- a/hw/arm/aspeed.c | 40 | --- a/target/arm/mve.decode |
44 | +++ b/hw/arm/aspeed.c | 41 | +++ b/target/arm/mve.decode |
45 | @@ -XXX,XX +XXX,XX @@ static void aspeed_machine_init(MachineState *machine) | 42 | @@ -XXX,XX +XXX,XX @@ |
46 | * SoC and 128MB for the AST2500 SoC, which is twice as big as | 43 | @2op_fp_size_rev .... .... .... .... .... .... .... .... &2op \ |
47 | * needed by the flash modules of the Aspeed machines. | 44 | qd=%qd qn=%qn qm=%qm size=%2op_fp_size_rev |
48 | */ | 45 | |
49 | - memory_region_init_rom(boot_rom, OBJECT(bmc), "aspeed.boot_rom", | 46 | +# 2-operand, but Qd and Qn share a field. Size is in bit 28, but we |
50 | - fl->size, &error_abort); | 47 | +# don't decode it in this format |
51 | - memory_region_add_subregion(get_system_memory(), FIRMWARE_ADDR, | 48 | +@vmaxnma .... .... .... .... .... .... .... .... &2op \ |
52 | - boot_rom); | 49 | + qd=%qd qn=%qd qm=%qm |
53 | - write_boot_rom(drive0, FIRMWARE_ADDR, fl->size, &error_abort); | 50 | + |
54 | + if (ASPEED_MACHINE(machine)->mmio_exec) { | 51 | # Vector loads and stores |
55 | + memory_region_init_alias(boot_rom, OBJECT(bmc), "aspeed.boot_rom", | 52 | |
56 | + &fl->mmio, 0, fl->size); | 53 | # Widening loads and narrowing stores: |
57 | + memory_region_add_subregion(get_system_memory(), FIRMWARE_ADDR, | 54 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op |
58 | + boot_rom); | 55 | # The VSHLL T2 encoding is not a @2op pattern, but is here because it |
59 | + } else { | 56 | # overlaps what would be size=0b11 VMULH/VRMULH |
60 | + memory_region_init_rom(boot_rom, OBJECT(bmc), "aspeed.boot_rom", | 57 | { |
61 | + fl->size, &error_abort); | 58 | + VMAXNMA 111 0 1110 0 . 11 1111 ... 0 1110 1 0 . 0 ... 1 @vmaxnma size=2 |
62 | + memory_region_add_subregion(get_system_memory(), FIRMWARE_ADDR, | 59 | + |
63 | + boot_rom); | 60 | VSHLL_BS 111 0 1110 0 . 11 .. 01 ... 0 1110 0 0 . 0 ... 1 @2_shll_esize_b |
64 | + write_boot_rom(drive0, FIRMWARE_ADDR, fl->size, &error_abort); | 61 | VSHLL_BS 111 0 1110 0 . 11 .. 01 ... 0 1110 0 0 . 0 ... 1 @2_shll_esize_h |
65 | + } | 62 | |
66 | } | 63 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op |
67 | |||
68 | aspeed_board_binfo.ram_size = ram_size; | ||
69 | @@ -XXX,XX +XXX,XX @@ static void witherspoon_bmc_i2c_init(AspeedBoardState *bmc) | ||
70 | /* Bus 11: TODO ucd90160@64 */ | ||
71 | } | 64 | } |
72 | 65 | ||
73 | +static bool aspeed_get_mmio_exec(Object *obj, Error **errp) | 66 | { |
67 | + VMAXNMA 111 1 1110 0 . 11 1111 ... 0 1110 1 0 . 0 ... 1 @vmaxnma size=1 | ||
68 | + | ||
69 | VSHLL_BU 111 1 1110 0 . 11 .. 01 ... 0 1110 0 0 . 0 ... 1 @2_shll_esize_b | ||
70 | VSHLL_BU 111 1 1110 0 . 11 .. 01 ... 0 1110 0 0 . 0 ... 1 @2_shll_esize_h | ||
71 | |||
72 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op | ||
73 | } | ||
74 | |||
75 | { | ||
76 | + VMINNMA 111 0 1110 0 . 11 1111 ... 1 1110 1 0 . 0 ... 1 @vmaxnma size=2 | ||
77 | VSHLL_TS 111 0 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_b | ||
78 | VSHLL_TS 111 0 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_h | ||
79 | |||
80 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op | ||
81 | } | ||
82 | |||
83 | { | ||
84 | + VMINNMA 111 1 1110 0 . 11 1111 ... 1 1110 1 0 . 0 ... 1 @vmaxnma size=1 | ||
85 | VSHLL_TU 111 1 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_b | ||
86 | VSHLL_TU 111 1 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_h | ||
87 | |||
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_2OP_FP_ALL(vfabd, abd) | ||
93 | DO_2OP_FP_ALL(vmaxnm, maxnum) | ||
94 | DO_2OP_FP_ALL(vminnm, minnum) | ||
95 | |||
96 | +static inline float16 float16_maxnuma(float16 a, float16 b, float_status *s) | ||
74 | +{ | 97 | +{ |
75 | + return ASPEED_MACHINE(obj)->mmio_exec; | 98 | + return float16_maxnum(float16_abs(a), float16_abs(b), s); |
76 | +} | 99 | +} |
77 | + | 100 | + |
78 | +static void aspeed_set_mmio_exec(Object *obj, bool value, Error **errp) | 101 | +static inline float32 float32_maxnuma(float32 a, float32 b, float_status *s) |
79 | +{ | 102 | +{ |
80 | + ASPEED_MACHINE(obj)->mmio_exec = value; | 103 | + return float32_maxnum(float32_abs(a), float32_abs(b), s); |
81 | +} | 104 | +} |
82 | + | 105 | + |
83 | +static void aspeed_machine_instance_init(Object *obj) | 106 | +static inline float16 float16_minnuma(float16 a, float16 b, float_status *s) |
84 | +{ | 107 | +{ |
85 | + ASPEED_MACHINE(obj)->mmio_exec = false; | 108 | + return float16_minnum(float16_abs(a), float16_abs(b), s); |
86 | +} | 109 | +} |
87 | + | 110 | + |
88 | +static void aspeed_machine_class_props_init(ObjectClass *oc) | 111 | +static inline float32 float32_minnuma(float32 a, float32 b, float_status *s) |
89 | +{ | 112 | +{ |
90 | + object_class_property_add_bool(oc, "execute-in-place", | 113 | + return float32_minnum(float32_abs(a), float32_abs(b), s); |
91 | + aspeed_get_mmio_exec, | ||
92 | + aspeed_set_mmio_exec, &error_abort); | ||
93 | + object_class_property_set_description(oc, "execute-in-place", | ||
94 | + "boot directly from CE0 flash device", &error_abort); | ||
95 | +} | 114 | +} |
96 | + | 115 | + |
97 | static void aspeed_machine_class_init(ObjectClass *oc, void *data) | 116 | +DO_2OP_FP_ALL(vmaxnma, maxnuma) |
98 | { | 117 | +DO_2OP_FP_ALL(vminnma, minnuma) |
99 | MachineClass *mc = MACHINE_CLASS(oc); | ||
100 | @@ -XXX,XX +XXX,XX @@ static void aspeed_machine_class_init(ObjectClass *oc, void *data) | ||
101 | mc->no_floppy = 1; | ||
102 | mc->no_cdrom = 1; | ||
103 | mc->no_parallel = 1; | ||
104 | + | 118 | + |
105 | + aspeed_machine_class_props_init(oc); | 119 | #define DO_VCADD_FP(OP, ESIZE, TYPE, FN0, FN1) \ |
106 | } | 120 | void HELPER(glue(mve_, OP))(CPUARMState *env, \ |
107 | 121 | void *vd, void *vn, void *vm) \ | |
108 | static void aspeed_machine_palmetto_class_init(ObjectClass *oc, void *data) | 122 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
109 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo aspeed_machine_types[] = { | 123 | index XXXXXXX..XXXXXXX 100644 |
110 | .name = TYPE_ASPEED_MACHINE, | 124 | --- a/target/arm/translate-mve.c |
111 | .parent = TYPE_MACHINE, | 125 | +++ b/target/arm/translate-mve.c |
112 | .instance_size = sizeof(AspeedMachine), | 126 | @@ -XXX,XX +XXX,XX @@ DO_2OP_FP(VCMLA0, vcmla0) |
113 | + .instance_init = aspeed_machine_instance_init, | 127 | DO_2OP_FP(VCMLA90, vcmla90) |
114 | .class_size = sizeof(AspeedMachineClass), | 128 | DO_2OP_FP(VCMLA180, vcmla180) |
115 | .class_init = aspeed_machine_class_init, | 129 | DO_2OP_FP(VCMLA270, vcmla270) |
116 | .abstract = true, | 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) | ||
117 | -- | 135 | -- |
118 | 2.20.1 | 136 | 2.20.1 |
119 | 137 | ||
120 | 138 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Implement the MVE scalar floating point insns VADD, VSUB and VMUL. | ||
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/helper-mve.h | 9 +++++++++ | ||
7 | target/arm/mve.decode | 27 +++++++++++++++++++++------ | ||
8 | target/arm/mve_helper.c | 35 +++++++++++++++++++++++++++++++++++ | ||
9 | target/arm/translate-mve.c | 20 ++++++++++++++++++++ | ||
10 | 4 files changed, 85 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_vcmpgt_scalarw, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
17 | DEF_HELPER_FLAGS_3(mve_vcmple_scalarb, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
18 | DEF_HELPER_FLAGS_3(mve_vcmple_scalarh, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
19 | DEF_HELPER_FLAGS_3(mve_vcmple_scalarw, TCG_CALL_NO_WG, void, env, ptr, i32) | ||
20 | + | ||
21 | +DEF_HELPER_FLAGS_4(mve_vfadd_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
22 | +DEF_HELPER_FLAGS_4(mve_vfadd_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
23 | + | ||
24 | +DEF_HELPER_FLAGS_4(mve_vfsub_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
25 | +DEF_HELPER_FLAGS_4(mve_vfsub_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
26 | + | ||
27 | +DEF_HELPER_FLAGS_4(mve_vfmul_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
28 | +DEF_HELPER_FLAGS_4(mve_vfmul_scalars, 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 @@ | ||
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 | ||
54 | } | ||
55 | |||
56 | -VHADD_S_scalar 1110 1110 0 . .. ... 0 ... 0 1111 . 100 .... @2scalar | ||
57 | -VHADD_U_scalar 1111 1110 0 . .. ... 0 ... 0 1111 . 100 .... @2scalar | ||
58 | -VHSUB_S_scalar 1110 1110 0 . .. ... 0 ... 1 1111 . 100 .... @2scalar | ||
59 | -VHSUB_U_scalar 1111 1110 0 . .. ... 0 ... 1 1111 . 100 .... @2scalar | ||
60 | +{ | ||
61 | + VADD_fp_scalar 111 . 1110 0 . 11 ... 0 ... 0 1111 . 100 .... @2op_fp_scalar | ||
62 | + VHADD_S_scalar 1110 1110 0 . .. ... 0 ... 0 1111 . 100 .... @2scalar | ||
63 | + VHADD_U_scalar 1111 1110 0 . .. ... 0 ... 0 1111 . 100 .... @2scalar | ||
64 | +} | ||
65 | + | ||
66 | +{ | ||
67 | + VSUB_fp_scalar 111 . 1110 0 . 11 ... 0 ... 1 1111 . 100 .... @2op_fp_scalar | ||
68 | + VHSUB_S_scalar 1110 1110 0 . .. ... 0 ... 1 1111 . 100 .... @2scalar | ||
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) | ||
96 | + | ||
97 | +#define DO_2OP_FP_SCALAR(OP, ESIZE, TYPE, FN) \ | ||
98 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ | ||
99 | + void *vd, void *vn, uint32_t rm) \ | ||
100 | + { \ | ||
101 | + TYPE *d = vd, *n = vn; \ | ||
102 | + TYPE r, m = rm; \ | ||
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); \ | ||
122 | + } | ||
123 | + | ||
124 | +#define DO_2OP_FP_SCALAR_ALL(OP, FN) \ | ||
125 | + DO_2OP_FP_SCALAR(OP##h, 2, float16, float16_##FN) \ | ||
126 | + DO_2OP_FP_SCALAR(OP##s, 4, float32, float32_##FN) | ||
127 | + | ||
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]); | ||
137 | } | ||
138 | |||
139 | + | ||
140 | +#define DO_2OP_FP_SCALAR(INSN, FN) \ | ||
141 | + static bool trans_##INSN(DisasContext *s, arg_2scalar *a) \ | ||
142 | + { \ | ||
143 | + static MVEGenTwoOpScalarFn * const fns[] = { \ | ||
144 | + NULL, \ | ||
145 | + gen_helper_mve_##FN##h, \ | ||
146 | + gen_helper_mve_##FN##s, \ | ||
147 | + NULL, \ | ||
148 | + }; \ | ||
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) | ||
161 | { | ||
162 | -- | ||
163 | 2.20.1 | ||
164 | |||
165 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Implement the MVE fp-with-scalar VFMA and VFMAS insns. | ||
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/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(-) | ||
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_vfsub_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
17 | |||
18 | DEF_HELPER_FLAGS_4(mve_vfmul_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
19 | DEF_HELPER_FLAGS_4(mve_vfmul_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
20 | + | ||
21 | +DEF_HELPER_FLAGS_4(mve_vfma_scalarh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
22 | +DEF_HELPER_FLAGS_4(mve_vfma_scalars, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
23 | + | ||
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 | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/target/arm/mve.decode | ||
29 | +++ b/target/arm/mve.decode | ||
30 | @@ -XXX,XX +XXX,XX @@ VSUB_scalar 1110 1110 0 . .. ... 1 ... 1 1111 . 100 .... @2scalar | ||
31 | VQRDMULH_scalar 1111 1110 0 . .. ... 1 ... 0 1110 . 110 .... @2scalar | ||
32 | } | ||
33 | |||
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 | ||
37 | +{ | ||
38 | + VFMA_scalar 111 . 1110 0 . 11 ... 1 ... 0 1110 . 100 .... @2op_fp_scalar | ||
39 | + # The U bit (28) is don't-care because it does not affect the result | ||
40 | + VMLA 111 - 1110 0 . .. ... 1 ... 0 1110 . 100 .... @2scalar | ||
41 | +} | ||
42 | + | ||
43 | +{ | ||
44 | + VFMAS_scalar 111 . 1110 0 . 11 ... 1 ... 1 1110 . 100 .... @2op_fp_scalar | ||
45 | + # The U bit (28) is don't-care because it does not affect the result | ||
46 | + VMLAS 111 - 1110 0 . .. ... 1 ... 1 1110 . 100 .... @2scalar | ||
47 | +} | ||
48 | |||
49 | VQRDMLAH 1110 1110 0 . .. ... 0 ... 0 1110 . 100 .... @2scalar | ||
50 | VQRDMLASH 1110 1110 0 . .. ... 0 ... 1 1110 . 100 .... @2scalar | ||
51 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/arm/mve_helper.c | ||
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) | ||
59 | + | ||
60 | +#define DO_2OP_FP_ACC_SCALAR(OP, ESIZE, TYPE, FN) \ | ||
61 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ | ||
62 | + void *vd, void *vn, uint32_t rm) \ | ||
63 | + { \ | ||
64 | + TYPE *d = vd, *n = vn; \ | ||
65 | + TYPE r, m = rm; \ | ||
66 | + uint16_t mask = mve_element_mask(env); \ | ||
67 | + unsigned e; \ | ||
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) | ||
109 | -- | ||
110 | 2.20.1 | ||
111 | |||
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 |
New patch | |||
---|---|---|---|
1 | Implement the MVE VMAXNMV, VMINNMV, VMAXNMAV, VMINNMAV insns. These | ||
2 | calculate the maximum or minimum of floating point elements across a | ||
3 | vector, starting with a value in a general purpose register and | ||
4 | returning the result there. | ||
1 | 5 | ||
6 | The pseudocode silences a possible SNaN in the accumulating result | ||
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. | ||
15 | |||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
18 | --- | ||
19 | target/arm/helper-mve.h | 12 +++++++++++ | ||
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(-) | ||
24 | |||
25 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/target/arm/helper-mve.h | ||
28 | +++ b/target/arm/helper-mve.h | ||
29 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(mve_vminavb, TCG_CALL_NO_WG, i32, env, ptr, i32) | ||
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 | ||
85 | } | ||
86 | |||
87 | { | ||
88 | - VMAXV_U 1111 1110 1110 .. 10 .... 1111 0 0 . 0 ... 0 @vmaxv | ||
89 | - VMINV_U 1111 1110 1110 .. 10 .... 1111 1 0 . 0 ... 0 @vmaxv | ||
90 | + [ | ||
91 | + VMAXNMAV 1111 1110 1110 11 00 .... 1111 0 0 . 0 ... 0 @vmaxnmv size=1 | ||
92 | + VMINNMAV 1111 1110 1110 11 00 .... 1111 1 0 . 0 ... 0 @vmaxnmv size=1 | ||
93 | + VMAXNMV 1111 1110 1110 11 10 .... 1111 0 0 . 0 ... 0 @vmaxnmv size=1 | ||
94 | + VMINNMV 1111 1110 1110 11 10 .... 1111 1 0 . 0 ... 0 @vmaxnmv size=1 | ||
95 | + ] | ||
96 | + [ | ||
97 | + VMAXV_U 1111 1110 1110 .. 10 .... 1111 0 0 . 0 ... 0 @vmaxv | ||
98 | + VMINV_U 1111 1110 1110 .. 10 .... 1111 1 0 . 0 ... 0 @vmaxv | ||
99 | + ] | ||
100 | VMLADAV_U 1111 1110 1111 ... 0 ... . 1111 . 0 . 0 ... 0 @vmladav_nosz | ||
101 | VRMLALDAVH_U 1111 1110 1 ... ... 0 ... . 1111 . 0 . 0 ... 0 @vmlaldav_nosz | ||
102 | } | ||
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_2OP_FP_ACC_SCALAR(vfma_scalarh, 2, float16, float16_muladd) | ||
108 | DO_2OP_FP_ACC_SCALAR(vfma_scalars, 4, float32, float32_muladd) | ||
109 | DO_2OP_FP_ACC_SCALAR(vfmas_scalarh, 2, float16, DO_VFMAS_SCALARH) | ||
110 | DO_2OP_FP_ACC_SCALAR(vfmas_scalars, 4, float32, DO_VFMAS_SCALARS) | ||
111 | + | ||
112 | +/* Floating point max/min across vector. */ | ||
113 | +#define DO_FP_VMAXMINV(OP, ESIZE, TYPE, ABS, FN) \ | ||
114 | + uint32_t HELPER(glue(mve_, OP))(CPUARMState *env, void *vm, \ | ||
115 | + uint32_t ra_in) \ | ||
116 | + { \ | ||
117 | + uint16_t mask = mve_element_mask(env); \ | ||
118 | + unsigned e; \ | ||
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]); \ | ||
176 | + } | ||
177 | + | ||
178 | +DO_VMAXV_FP(VMAXNMV, vmaxnmv) | ||
179 | +DO_VMAXV_FP(VMINNMV, vminnmv) | ||
180 | +DO_VMAXV_FP(VMAXNMAV, vmaxnmav) | ||
181 | +DO_VMAXV_FP(VMINNMAV, vminnmav) | ||
182 | + | ||
183 | static bool do_vabav(DisasContext *s, arg_vabav *a, MVEGenVABAVFn *fn) | ||
184 | { | ||
185 | /* Absolute difference accumulated across vector */ | ||
186 | -- | ||
187 | 2.20.1 | ||
188 | |||
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: Damien Hedde <damien.hedde@greensocs.com> | 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 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Message-id: 20200123132823.1117486-10-damien.hedde@greensocs.com | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | --- | 8 | --- |
9 | docs/devel/index.rst | 1 + | 9 | target/arm/helper-mve.h | 5 ++++ |
10 | docs/devel/reset.rst | 289 +++++++++++++++++++++++++++++++++++++++++++ | 10 | target/arm/mve.decode | 10 ++++++++ |
11 | 2 files changed, 290 insertions(+) | 11 | target/arm/mve_helper.c | 38 ++++++++++++++++++++++++++++ |
12 | create mode 100644 docs/devel/reset.rst | 12 | target/arm/translate-mve.c | 52 ++++++++++++++++++++++++++++++++++++++ |
13 | 4 files changed, 105 insertions(+) | ||
13 | 14 | ||
14 | diff --git a/docs/devel/index.rst b/docs/devel/index.rst | 15 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/docs/devel/index.rst | 17 | --- a/target/arm/helper-mve.h |
17 | +++ b/docs/devel/index.rst | 18 | +++ b/target/arm/helper-mve.h |
18 | @@ -XXX,XX +XXX,XX @@ Contents: | 19 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(mve_vminab, TCG_CALL_NO_WG, void, env, ptr, ptr) |
19 | tcg | 20 | DEF_HELPER_FLAGS_3(mve_vminah, TCG_CALL_NO_WG, void, env, ptr, ptr) |
20 | tcg-plugins | 21 | DEF_HELPER_FLAGS_3(mve_vminaw, TCG_CALL_NO_WG, void, env, ptr, ptr) |
21 | bitops | 22 | |
22 | + reset | 23 | +DEF_HELPER_FLAGS_4(mve_vcvt_rm_sh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
23 | diff --git a/docs/devel/reset.rst b/docs/devel/reset.rst | 24 | +DEF_HELPER_FLAGS_4(mve_vcvt_rm_uh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
24 | new file mode 100644 | 25 | +DEF_HELPER_FLAGS_4(mve_vcvt_rm_ss, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
25 | index XXXXXXX..XXXXXXX | 26 | +DEF_HELPER_FLAGS_4(mve_vcvt_rm_us, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
26 | --- /dev/null | ||
27 | +++ b/docs/devel/reset.rst | ||
28 | @@ -XXX,XX +XXX,XX @@ | ||
29 | + | 27 | + |
30 | +======================================= | 28 | DEF_HELPER_FLAGS_3(mve_vmovnbb, TCG_CALL_NO_WG, void, env, ptr, ptr) |
31 | +Reset in QEMU: the Resettable interface | 29 | DEF_HELPER_FLAGS_3(mve_vmovnbh, TCG_CALL_NO_WG, void, env, ptr, ptr) |
32 | +======================================= | 30 | DEF_HELPER_FLAGS_3(mve_vmovntb, TCG_CALL_NO_WG, void, env, ptr, ptr) |
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 @@ VCVT_SF 1111 1111 1 . 11 .. 11 ... 0 011 00 1 . 0 ... 0 @1op | ||
36 | VCVT_UF 1111 1111 1 . 11 .. 11 ... 0 011 01 1 . 0 ... 0 @1op | ||
37 | VCVT_FS 1111 1111 1 . 11 .. 11 ... 0 011 10 1 . 0 ... 0 @1op | ||
38 | VCVT_FU 1111 1111 1 . 11 .. 11 ... 0 011 11 1 . 0 ... 0 @1op | ||
33 | + | 39 | + |
34 | +The reset of qemu objects is handled using the resettable interface declared | 40 | +# VCVT from floating point to integer with specified rounding mode |
35 | +in ``include/hw/resettable.h``. | 41 | +VCVTAS 1111 1111 1 . 11 .. 11 ... 000 00 0 1 . 0 ... 0 @1op |
42 | +VCVTAU 1111 1111 1 . 11 .. 11 ... 000 00 1 1 . 0 ... 0 @1op | ||
43 | +VCVTNS 1111 1111 1 . 11 .. 11 ... 000 01 0 1 . 0 ... 0 @1op | ||
44 | +VCVTNU 1111 1111 1 . 11 .. 11 ... 000 01 1 1 . 0 ... 0 @1op | ||
45 | +VCVTPS 1111 1111 1 . 11 .. 11 ... 000 10 0 1 . 0 ... 0 @1op | ||
46 | +VCVTPU 1111 1111 1 . 11 .. 11 ... 000 10 1 1 . 0 ... 0 @1op | ||
47 | +VCVTMS 1111 1111 1 . 11 .. 11 ... 000 11 0 1 . 0 ... 0 @1op | ||
48 | +VCVTMU 1111 1111 1 . 11 .. 11 ... 000 11 1 1 . 0 ... 0 @1op | ||
49 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/target/arm/mve_helper.c | ||
52 | +++ b/target/arm/mve_helper.c | ||
53 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_FIXED(vcvt_sf, 4, int32_t, helper_vfp_sltos) | ||
54 | DO_VCVT_FIXED(vcvt_uf, 4, uint32_t, helper_vfp_ultos) | ||
55 | DO_VCVT_FIXED(vcvt_fs, 4, int32_t, helper_vfp_tosls_round_to_zero) | ||
56 | DO_VCVT_FIXED(vcvt_fu, 4, uint32_t, helper_vfp_touls_round_to_zero) | ||
36 | + | 57 | + |
37 | +This interface allows objects to be grouped (on a tree basis); so that the | 58 | +/* VCVT with specified rmode */ |
38 | +whole group can be reset consistently. Each individual member object does not | 59 | +#define DO_VCVT_RMODE(OP, ESIZE, TYPE, FN) \ |
39 | +have to care about others; in particular, problems of order (which object is | 60 | + void HELPER(glue(mve_, OP))(CPUARMState *env, \ |
40 | +reset first) are addressed. | 61 | + void *vd, void *vm, uint32_t rmode) \ |
41 | + | 62 | + { \ |
42 | +As of now DeviceClass and BusClass implement this interface. | 63 | + TYPE *d = vd, *m = vm; \ |
43 | + | 64 | + TYPE r; \ |
44 | + | 65 | + uint16_t mask = mve_element_mask(env); \ |
45 | +Triggering reset | 66 | + unsigned e; \ |
46 | +---------------- | 67 | + float_status *fpst; \ |
47 | + | 68 | + float_status scratch_fpst; \ |
48 | +This section documents the APIs which "users" of a resettable object should use | 69 | + float_status *base_fpst = (ESIZE == 2) ? \ |
49 | +to control it. All resettable control functions must be called while holding | 70 | + &env->vfp.standard_fp_status_f16 : \ |
50 | +the iothread lock. | 71 | + &env->vfp.standard_fp_status; \ |
51 | + | 72 | + uint32_t prev_rmode = get_float_rounding_mode(base_fpst); \ |
52 | +You can apply a reset to an object using ``resettable_assert_reset()``. You need | 73 | + set_float_rounding_mode(rmode, base_fpst); \ |
53 | +to call ``resettable_release_reset()`` to release the object from reset. To | 74 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ |
54 | +instantly reset an object, without keeping it in reset state, just call | 75 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ |
55 | +``resettable_reset()``. These functions take two parameters: a pointer to the | 76 | + continue; \ |
56 | +object to reset and a reset type. | 77 | + } \ |
57 | + | 78 | + fpst = base_fpst; \ |
58 | +Several types of reset will be supported. For now only cold reset is defined; | 79 | + if (!(mask & 1)) { \ |
59 | +others may be added later. The Resettable interface handles reset types with an | 80 | + /* We need the result but without updating flags */ \ |
60 | +enum: | 81 | + scratch_fpst = *fpst; \ |
61 | + | 82 | + fpst = &scratch_fpst; \ |
62 | +``RESET_TYPE_COLD`` | 83 | + } \ |
63 | + Cold reset is supported by every resettable object. In QEMU, it means we reset | 84 | + r = FN(m[H##ESIZE(e)], 0, fpst); \ |
64 | + to the initial state corresponding to the start of QEMU; this might differ | 85 | + mergemask(&d[H##ESIZE(e)], r, mask); \ |
65 | + from what is a real hardware cold reset. It differs from other resets (like | 86 | + } \ |
66 | + warm or bus resets) which may keep certain parts untouched. | 87 | + set_float_rounding_mode(prev_rmode, base_fpst); \ |
67 | + | 88 | + mve_advance_vpt(env); \ |
68 | +Calling ``resettable_reset()`` is equivalent to calling | ||
69 | +``resettable_assert_reset()`` then ``resettable_release_reset()``. It is | ||
70 | +possible to interleave multiple calls to these three functions. There may | ||
71 | +be several reset sources/controllers of a given object. The interface handles | ||
72 | +everything and the different reset controllers do not need to know anything | ||
73 | +about each others. The object will leave reset state only when each other | ||
74 | +controllers end their reset operation. This point is handled internally by | ||
75 | +maintaining a count of in-progress resets; it is crucial to call | ||
76 | +``resettable_release_reset()`` one time and only one time per | ||
77 | +``resettable_assert_reset()`` call. | ||
78 | + | ||
79 | +For now migration of a device or bus in reset is not supported. Care must be | ||
80 | +taken not to delay ``resettable_release_reset()`` after its | ||
81 | +``resettable_assert_reset()`` counterpart. | ||
82 | + | ||
83 | +Note that, since resettable is an interface, the API takes a simple Object as | ||
84 | +parameter. Still, it is a programming error to call a resettable function on a | ||
85 | +non-resettable object and it will trigger a run time assert error. Since most | ||
86 | +calls to resettable interface are done through base class functions, such an | ||
87 | +error is not likely to happen. | ||
88 | + | ||
89 | +For Devices and Buses, the following helper functions exist: | ||
90 | + | ||
91 | +- ``device_cold_reset()`` | ||
92 | +- ``bus_cold_reset()`` | ||
93 | + | ||
94 | +These are simple wrappers around resettable_reset() function; they only cast the | ||
95 | +Device or Bus into an Object and pass the cold reset type. When possible | ||
96 | +prefer to use these functions instead of ``resettable_reset()``. | ||
97 | + | ||
98 | +Device and bus functions co-exist because there can be semantic differences | ||
99 | +between resetting a bus and resetting the controller bridge which owns it. | ||
100 | +For example, consider a SCSI controller. Resetting the controller puts all | ||
101 | +its registers back to what reset state was as well as reset everything on the | ||
102 | +SCSI bus, whereas resetting just the SCSI bus only resets everything that's on | ||
103 | +it but not the controller. | ||
104 | + | ||
105 | + | ||
106 | +Multi-phase mechanism | ||
107 | +--------------------- | ||
108 | + | ||
109 | +This section documents the internals of the resettable interface. | ||
110 | + | ||
111 | +The resettable interface uses a multi-phase system to relieve objects and | ||
112 | +machines from reset ordering problems. To address this, the reset operation | ||
113 | +of an object is split into three well defined phases. | ||
114 | + | ||
115 | +When resetting several objects (for example the whole machine at simulation | ||
116 | +startup), all first phases of all objects are executed, then all second phases | ||
117 | +and then all third phases. | ||
118 | + | ||
119 | +The three phases are: | ||
120 | + | ||
121 | +1. The **enter** phase is executed when the object enters reset. It resets only | ||
122 | + local state of the object; it must not do anything that has a side-effect | ||
123 | + on other objects, such as raising or lowering a qemu_irq line or reading or | ||
124 | + writing guest memory. | ||
125 | + | ||
126 | +2. The **hold** phase is executed for entry into reset, once every object in the | ||
127 | + group which is being reset has had its *enter* phase executed. At this point | ||
128 | + devices can do actions that affect other objects. | ||
129 | + | ||
130 | +3. The **exit** phase is executed when the object leaves the reset state. | ||
131 | + Actions affecting other objects are permitted. | ||
132 | + | ||
133 | +As said in previous section, the interface maintains a count of reset. This | ||
134 | +count is used to ensure phases are executed only when required. *enter* and | ||
135 | +*hold* phases are executed only when asserting reset for the first time | ||
136 | +(if an object is already in reset state when calling | ||
137 | +``resettable_assert_reset()`` or ``resettable_reset()``, they are not | ||
138 | +executed). | ||
139 | +The *exit* phase is executed only when the last reset operation ends. Therefore | ||
140 | +the object does not need to care how many of reset controllers it has and how | ||
141 | +many of them have started a reset. | ||
142 | + | ||
143 | + | ||
144 | +Handling reset in a resettable object | ||
145 | +------------------------------------- | ||
146 | + | ||
147 | +This section documents the APIs that an implementation of a resettable object | ||
148 | +must provide and what functions it has access to. It is intended for people | ||
149 | +who want to implement or convert a class which has the resettable interface; | ||
150 | +for example when specializing an existing device or bus. | ||
151 | + | ||
152 | +Methods to implement | ||
153 | +.................... | ||
154 | + | ||
155 | +Three methods should be defined or left empty. Each method corresponds to a | ||
156 | +phase of the reset; they are name ``phases.enter()``, ``phases.hold()`` and | ||
157 | +``phases.exit()``. They all take the object as parameter. The *enter* method | ||
158 | +also take the reset type as second parameter. | ||
159 | + | ||
160 | +When extending an existing class, these methods may need to be extended too. | ||
161 | +The ``resettable_class_set_parent_phases()`` class function may be used to | ||
162 | +backup parent class methods. | ||
163 | + | ||
164 | +Here follows an example to implement reset for a Device which sets an IO while | ||
165 | +in reset. | ||
166 | + | ||
167 | +:: | ||
168 | + | ||
169 | + static void mydev_reset_enter(Object *obj, ResetType type) | ||
170 | + { | ||
171 | + MyDevClass *myclass = MYDEV_GET_CLASS(obj); | ||
172 | + MyDevState *mydev = MYDEV(obj); | ||
173 | + /* call parent class enter phase */ | ||
174 | + if (myclass->parent_phases.enter) { | ||
175 | + myclass->parent_phases.enter(obj, type); | ||
176 | + } | ||
177 | + /* initialize local state only */ | ||
178 | + mydev->var = 0; | ||
179 | + } | 89 | + } |
180 | + | 90 | + |
181 | + static void mydev_reset_hold(Object *obj) | 91 | +DO_VCVT_RMODE(vcvt_rm_sh, 2, uint16_t, helper_vfp_toshh) |
182 | + { | 92 | +DO_VCVT_RMODE(vcvt_rm_uh, 2, uint16_t, helper_vfp_touhh) |
183 | + MyDevClass *myclass = MYDEV_GET_CLASS(obj); | 93 | +DO_VCVT_RMODE(vcvt_rm_ss, 4, uint32_t, helper_vfp_tosls) |
184 | + MyDevState *mydev = MYDEV(obj); | 94 | +DO_VCVT_RMODE(vcvt_rm_us, 4, uint32_t, helper_vfp_touls) |
185 | + /* call parent class hold phase */ | 95 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
186 | + if (myclass->parent_phases.hold) { | 96 | index XXXXXXX..XXXXXXX 100644 |
187 | + myclass->parent_phases.hold(obj); | 97 | --- a/target/arm/translate-mve.c |
188 | + } | 98 | +++ b/target/arm/translate-mve.c |
189 | + /* set an IO */ | 99 | @@ -XXX,XX +XXX,XX @@ typedef void MVEGenCmpFn(TCGv_ptr, TCGv_ptr, TCGv_ptr); |
190 | + qemu_set_irq(mydev->irq, 1); | 100 | typedef void MVEGenScalarCmpFn(TCGv_ptr, TCGv_ptr, TCGv_i32); |
101 | typedef void MVEGenVABAVFn(TCGv_i32, TCGv_ptr, TCGv_ptr, TCGv_ptr, TCGv_i32); | ||
102 | typedef void MVEGenDualAccOpFn(TCGv_i32, TCGv_ptr, TCGv_ptr, TCGv_ptr, TCGv_i32); | ||
103 | +typedef void MVEGenVCVTRmodeFn(TCGv_ptr, TCGv_ptr, TCGv_ptr, TCGv_i32); | ||
104 | |||
105 | /* Return the offset of a Qn register (same semantics as aa32_vfp_qreg()) */ | ||
106 | static inline long mve_qreg_offset(unsigned reg) | ||
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; | ||
191 | + } | 132 | + } |
192 | + | 133 | + |
193 | + static void mydev_reset_exit(Object *obj) | 134 | + if (!mve_eci_check(s) || !vfp_access_check(s)) { |
194 | + { | 135 | + return true; |
195 | + MyDevClass *myclass = MYDEV_GET_CLASS(obj); | ||
196 | + MyDevState *mydev = MYDEV(obj); | ||
197 | + /* call parent class exit phase */ | ||
198 | + if (myclass->parent_phases.exit) { | ||
199 | + myclass->parent_phases.exit(obj); | ||
200 | + } | ||
201 | + /* clear an IO */ | ||
202 | + qemu_set_irq(mydev->irq, 0); | ||
203 | + } | 136 | + } |
204 | + | 137 | + |
205 | + typedef struct MyDevClass { | 138 | + qd = mve_qreg_ptr(a->qd); |
206 | + MyParentClass parent_class; | 139 | + qm = mve_qreg_ptr(a->qm); |
207 | + /* to store eventual parent reset methods */ | 140 | + fn(cpu_env, qd, qm, tcg_constant_i32(arm_rmode_to_sf(rmode))); |
208 | + ResettablePhases parent_phases; | 141 | + tcg_temp_free_ptr(qd); |
209 | + } MyDevClass; | 142 | + tcg_temp_free_ptr(qm); |
143 | + mve_update_eci(s); | ||
144 | + return true; | ||
145 | +} | ||
210 | + | 146 | + |
211 | + static void mydev_class_init(ObjectClass *class, void *data) | 147 | +#define DO_VCVT_RMODE(INSN, RMODE, U) \ |
212 | + { | 148 | + static bool trans_##INSN(DisasContext *s, arg_1op *a) \ |
213 | + MyDevClass *myclass = MYDEV_CLASS(class); | 149 | + { \ |
214 | + ResettableClass *rc = RESETTABLE_CLASS(class); | 150 | + return do_vcvt_rmode(s, a, RMODE, U); \ |
215 | + resettable_class_set_parent_reset_phases(rc, | 151 | + } \ |
216 | + mydev_reset_enter, | ||
217 | + mydev_reset_hold, | ||
218 | + mydev_reset_exit, | ||
219 | + &myclass->parent_phases); | ||
220 | + } | ||
221 | + | 152 | + |
222 | +In the above example, we override all three phases. It is possible to override | 153 | +DO_VCVT_RMODE(VCVTAS, FPROUNDING_TIEAWAY, false) |
223 | +only some of them by passing NULL instead of a function pointer to | 154 | +DO_VCVT_RMODE(VCVTAU, FPROUNDING_TIEAWAY, true) |
224 | +``resettable_class_set_parent_reset_phases()``. For example, the following will | 155 | +DO_VCVT_RMODE(VCVTNS, FPROUNDING_TIEEVEN, false) |
225 | +only override the *enter* phase and leave *hold* and *exit* untouched:: | 156 | +DO_VCVT_RMODE(VCVTNU, FPROUNDING_TIEEVEN, true) |
157 | +DO_VCVT_RMODE(VCVTPS, FPROUNDING_POSINF, false) | ||
158 | +DO_VCVT_RMODE(VCVTPU, FPROUNDING_POSINF, true) | ||
159 | +DO_VCVT_RMODE(VCVTMS, FPROUNDING_NEGINF, false) | ||
160 | +DO_VCVT_RMODE(VCVTMU, FPROUNDING_NEGINF, true) | ||
226 | + | 161 | + |
227 | + resettable_class_set_parent_reset_phases(rc, mydev_reset_enter, | 162 | /* Narrowing moves: only size 0 and 1 are valid */ |
228 | + NULL, NULL, | 163 | #define DO_VMOVN(INSN, FN) \ |
229 | + &myclass->parent_phases); | 164 | static bool trans_##INSN(DisasContext *s, arg_1op *a) \ |
230 | + | ||
231 | +This is equivalent to providing a trivial implementation of the hold and exit | ||
232 | +phases which does nothing but call the parent class's implementation of the | ||
233 | +phase. | ||
234 | + | ||
235 | +Polling the reset state | ||
236 | +....................... | ||
237 | + | ||
238 | +Resettable interface provides the ``resettable_is_in_reset()`` function. | ||
239 | +This function returns true if the object parameter is currently under reset. | ||
240 | + | ||
241 | +An object is under reset from the beginning of the *init* phase to the end of | ||
242 | +the *exit* phase. During all three phases, the function will return that the | ||
243 | +object is in reset. | ||
244 | + | ||
245 | +This function may be used if the object behavior has to be adapted | ||
246 | +while in reset state. For example if a device has an irq input, | ||
247 | +it will probably need to ignore it while in reset; then it can for | ||
248 | +example check the reset state at the beginning of the irq callback. | ||
249 | + | ||
250 | +Note that until migration of the reset state is supported, an object | ||
251 | +should not be left in reset. So apart from being currently executing | ||
252 | +one of the reset phases, the only cases when this function will return | ||
253 | +true is if an external interaction (like changing an io) is made during | ||
254 | +*hold* or *exit* phase of another object in the same reset group. | ||
255 | + | ||
256 | +Helpers ``device_is_in_reset()`` and ``bus_is_in_reset()`` are also provided | ||
257 | +for devices and buses and should be preferred. | ||
258 | + | ||
259 | + | ||
260 | +Base class handling of reset | ||
261 | +---------------------------- | ||
262 | + | ||
263 | +This section documents parts of the reset mechanism that you only need to know | ||
264 | +about if you are extending it to work with a new base class other than | ||
265 | +DeviceClass or BusClass, or maintaining the existing code in those classes. Most | ||
266 | +people can ignore it. | ||
267 | + | ||
268 | +Methods to implement | ||
269 | +.................... | ||
270 | + | ||
271 | +There are two other methods that need to exist in a class implementing the | ||
272 | +interface: ``get_state()`` and ``child_foreach()``. | ||
273 | + | ||
274 | +``get_state()`` is simple. *resettable* is an interface and, as a consequence, | ||
275 | +does not have any class state structure. But in order to factorize the code, we | ||
276 | +need one. This method must return a pointer to ``ResettableState`` structure. | ||
277 | +The structure must be allocated by the base class; preferably it should be | ||
278 | +located inside the object instance structure. | ||
279 | + | ||
280 | +``child_foreach()`` is more complex. It should execute the given callback on | ||
281 | +every reset child of the given resettable object. All children must be | ||
282 | +resettable too. Additional parameters (a reset type and an opaque pointer) must | ||
283 | +be passed to the callback too. | ||
284 | + | ||
285 | +In ``DeviceClass`` and ``BusClass`` the ``ResettableState`` is located | ||
286 | +``DeviceState`` and ``BusState`` structure. ``child_foreach()`` is implemented | ||
287 | +to follow the bus hierarchy; for a bus, it calls the function on every child | ||
288 | +device; for a device, it calls the function on every bus child. When we reset | ||
289 | +the main system bus, we reset the whole machine bus tree. | ||
290 | + | ||
291 | +Changing a resettable parent | ||
292 | +............................ | ||
293 | + | ||
294 | +One thing which should be taken care of by the base class is handling reset | ||
295 | +hierarchy changes. | ||
296 | + | ||
297 | +The reset hierarchy is supposed to be static and built during machine creation. | ||
298 | +But there are actually some exceptions. To cope with this, the resettable API | ||
299 | +provides ``resettable_change_parent()``. This function allows to set, update or | ||
300 | +remove the parent of a resettable object after machine creation is done. As | ||
301 | +parameters, it takes the object being moved, the old parent if any and the new | ||
302 | +parent if any. | ||
303 | + | ||
304 | +This function can be used at any time when not in a reset operation. During | ||
305 | +a reset operation it must be used only in *hold* phase. Using it in *enter* or | ||
306 | +*exit* phase is an error. | ||
307 | +Also it should not be used during machine creation, although it is harmless to | ||
308 | +do so: the function is a no-op as long as old and new parent are NULL or not | ||
309 | +in reset. | ||
310 | + | ||
311 | +There is currently 2 cases where this function is used: | ||
312 | + | ||
313 | +1. *device hotplug*; it means a new device is introduced on a live bus. | ||
314 | + | ||
315 | +2. *hot bus change*; it means an existing live device is added, moved or | ||
316 | + removed in the bus hierarchy. At the moment, it occurs only in the raspi | ||
317 | + machines for changing the sdbus used by sd card. | ||
318 | -- | 165 | -- |
319 | 2.20.1 | 166 | 2.20.1 |
320 | 167 | ||
321 | 168 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | Implement the MVE VCVT instruction which converts between single |
---|---|---|---|
2 | and half precision floating point. | ||
2 | 3 | ||
3 | Adds trace events to reset procedure and when updating the parent | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | bus of a device. | 5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
6 | --- | ||
7 | target/arm/helper-mve.h | 5 +++ | ||
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(+) | ||
5 | 12 | ||
6 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | 13 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
9 | Reviewed-by: Cornelia Huck <cohuck@redhat.com> | ||
10 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Message-id: 20200123132823.1117486-3-damien.hedde@greensocs.com | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | --- | ||
14 | hw/core/qdev.c | 29 ++++++++++++++++++++++++++--- | ||
15 | hw/core/trace-events | 9 +++++++++ | ||
16 | 2 files changed, 35 insertions(+), 3 deletions(-) | ||
17 | |||
18 | diff --git a/hw/core/qdev.c b/hw/core/qdev.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/core/qdev.c | 15 | --- a/target/arm/helper-mve.h |
21 | +++ b/hw/core/qdev.c | 16 | +++ b/target/arm/helper-mve.h |
22 | @@ -XXX,XX +XXX,XX @@ | 17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vcvt_rm_uh, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
23 | #include "hw/boards.h" | 18 | DEF_HELPER_FLAGS_4(mve_vcvt_rm_ss, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
24 | #include "hw/sysbus.h" | 19 | DEF_HELPER_FLAGS_4(mve_vcvt_rm_us, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) |
25 | #include "migration/vmstate.h" | 20 | |
26 | +#include "trace.h" | 21 | +DEF_HELPER_FLAGS_3(mve_vcvtb_sh, TCG_CALL_NO_WG, void, env, ptr, ptr) |
27 | 22 | +DEF_HELPER_FLAGS_3(mve_vcvtt_sh, TCG_CALL_NO_WG, void, env, ptr, ptr) | |
28 | bool qdev_hotplug = false; | 23 | +DEF_HELPER_FLAGS_3(mve_vcvtb_hs, TCG_CALL_NO_WG, void, env, ptr, ptr) |
29 | static bool qdev_hot_added = false; | 24 | +DEF_HELPER_FLAGS_3(mve_vcvtt_hs, TCG_CALL_NO_WG, void, env, ptr, ptr) |
30 | @@ -XXX,XX +XXX,XX @@ void qdev_set_parent_bus(DeviceState *dev, BusState *bus) | 25 | + |
31 | bool replugging = dev->parent_bus != NULL; | 26 | DEF_HELPER_FLAGS_3(mve_vmovnbb, TCG_CALL_NO_WG, void, env, ptr, ptr) |
32 | 27 | DEF_HELPER_FLAGS_3(mve_vmovnbh, TCG_CALL_NO_WG, void, env, ptr, ptr) | |
33 | if (replugging) { | 28 | DEF_HELPER_FLAGS_3(mve_vmovntb, TCG_CALL_NO_WG, void, env, ptr, ptr) |
34 | - /* Keep a reference to the device while it's not plugged into | 29 | diff --git a/target/arm/mve.decode b/target/arm/mve.decode |
35 | + trace_qdev_update_parent_bus(dev, object_get_typename(OBJECT(dev)), | 30 | index XXXXXXX..XXXXXXX 100644 |
36 | + dev->parent_bus, object_get_typename(OBJECT(dev->parent_bus)), | 31 | --- a/target/arm/mve.decode |
37 | + OBJECT(bus), object_get_typename(OBJECT(bus))); | 32 | +++ b/target/arm/mve.decode |
38 | + /* | 33 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op |
39 | + * Keep a reference to the device while it's not plugged into | 34 | # The VSHLL T2 encoding is not a @2op pattern, but is here because it |
40 | * any bus, to avoid it potentially evaporating when it is | 35 | # overlaps what would be size=0b11 VMULH/VRMULH |
41 | * dereffed in bus_remove_child(). | 36 | { |
42 | */ | 37 | + VCVTB_SH 111 0 1110 0 . 11 1111 ... 0 1110 0 0 . 0 ... 1 @1op_nosz |
43 | @@ -XXX,XX +XXX,XX @@ HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev) | 38 | + |
44 | return hotplug_ctrl; | 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 | ||
45 | } | 43 | } |
46 | 44 | ||
47 | +static int qdev_prereset(DeviceState *dev, void *opaque) | 45 | { |
46 | + VCVTB_HS 111 1 1110 0 . 11 1111 ... 0 1110 0 0 . 0 ... 1 @1op_nosz | ||
47 | + | ||
48 | VMAXNMA 111 1 1110 0 . 11 1111 ... 0 1110 1 0 . 0 ... 1 @vmaxnma size=1 | ||
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 | ||
52 | } | ||
53 | |||
54 | { | ||
55 | + VCVTT_SH 111 0 1110 0 . 11 1111 ... 1 1110 0 0 . 0 ... 1 @1op_nosz | ||
56 | + | ||
57 | VMINNMA 111 0 1110 0 . 11 1111 ... 1 1110 1 0 . 0 ... 1 @vmaxnma size=2 | ||
58 | VSHLL_TS 111 0 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_b | ||
59 | VSHLL_TS 111 0 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_h | ||
60 | @@ -XXX,XX +XXX,XX @@ VMUL 1110 1111 0 . .. ... 0 ... 0 1001 . 1 . 1 ... 0 @2op | ||
61 | } | ||
62 | |||
63 | { | ||
64 | + VCVTT_HS 111 1 1110 0 . 11 1111 ... 1 1110 0 0 . 0 ... 1 @1op_nosz | ||
65 | + | ||
66 | VMINNMA 111 1 1110 0 . 11 1111 ... 1 1110 1 0 . 0 ... 1 @vmaxnma size=1 | ||
67 | VSHLL_TU 111 1 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_b | ||
68 | VSHLL_TU 111 1 1110 0 . 11 .. 01 ... 1 1110 0 0 . 0 ... 1 @2_shll_esize_h | ||
69 | diff --git a/target/arm/mve_helper.c b/target/arm/mve_helper.c | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/target/arm/mve_helper.c | ||
72 | +++ b/target/arm/mve_helper.c | ||
73 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_RMODE(vcvt_rm_sh, 2, uint16_t, helper_vfp_toshh) | ||
74 | DO_VCVT_RMODE(vcvt_rm_uh, 2, uint16_t, helper_vfp_touhh) | ||
75 | DO_VCVT_RMODE(vcvt_rm_ss, 4, uint32_t, helper_vfp_tosls) | ||
76 | DO_VCVT_RMODE(vcvt_rm_us, 4, uint32_t, helper_vfp_touls) | ||
77 | + | ||
78 | +/* | ||
79 | + * VCVT between halfprec and singleprec. As usual for halfprec | ||
80 | + * conversions, FZ16 is ignored and AHP is observed. | ||
81 | + */ | ||
82 | +static void do_vcvt_sh(CPUARMState *env, void *vd, void *vm, int top) | ||
48 | +{ | 83 | +{ |
49 | + trace_qdev_reset_tree(dev, object_get_typename(OBJECT(dev))); | 84 | + uint16_t *d = vd; |
50 | + return 0; | 85 | + uint32_t *m = vm; |
86 | + uint16_t r; | ||
87 | + uint16_t mask = mve_element_mask(env); | ||
88 | + bool ieee = !(env->vfp.xregs[ARM_VFP_FPSCR] & FPCR_AHP); | ||
89 | + unsigned e; | ||
90 | + float_status *fpst; | ||
91 | + float_status scratch_fpst; | ||
92 | + float_status *base_fpst = &env->vfp.standard_fp_status; | ||
93 | + bool old_fz = get_flush_to_zero(base_fpst); | ||
94 | + set_flush_to_zero(false, base_fpst); | ||
95 | + for (e = 0; e < 16 / 4; e++, mask >>= 4) { | ||
96 | + if ((mask & MAKE_64BIT_MASK(0, 4)) == 0) { | ||
97 | + continue; | ||
98 | + } | ||
99 | + fpst = base_fpst; | ||
100 | + if (!(mask & 1)) { | ||
101 | + /* We need the result but without updating flags */ | ||
102 | + scratch_fpst = *fpst; | ||
103 | + fpst = &scratch_fpst; | ||
104 | + } | ||
105 | + r = float32_to_float16(m[H4(e)], ieee, fpst); | ||
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); | ||
51 | +} | 110 | +} |
52 | + | 111 | + |
53 | +static int qbus_prereset(BusState *bus, void *opaque) | 112 | +static void do_vcvt_hs(CPUARMState *env, void *vd, void *vm, int top) |
54 | +{ | 113 | +{ |
55 | + trace_qbus_reset_tree(bus, object_get_typename(OBJECT(bus))); | 114 | + uint32_t *d = vd; |
56 | + return 0; | 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); | ||
57 | +} | 140 | +} |
58 | + | 141 | + |
59 | static int qdev_reset_one(DeviceState *dev, void *opaque) | 142 | +void HELPER(mve_vcvtb_sh)(CPUARMState *env, void *vd, void *vm) |
60 | { | 143 | +{ |
61 | device_legacy_reset(dev); | 144 | + do_vcvt_sh(env, vd, vm, 0); |
62 | @@ -XXX,XX +XXX,XX @@ static int qdev_reset_one(DeviceState *dev, void *opaque) | 145 | +} |
63 | static int qbus_reset_one(BusState *bus, void *opaque) | 146 | +void HELPER(mve_vcvtt_sh)(CPUARMState *env, void *vd, void *vm) |
64 | { | 147 | +{ |
65 | BusClass *bc = BUS_GET_CLASS(bus); | 148 | + do_vcvt_sh(env, vd, vm, 1); |
66 | + trace_qbus_reset(bus, object_get_typename(OBJECT(bus))); | 149 | +} |
67 | if (bc->reset) { | 150 | +void HELPER(mve_vcvtb_hs)(CPUARMState *env, void *vd, void *vm) |
68 | bc->reset(bus); | 151 | +{ |
69 | } | 152 | + do_vcvt_hs(env, vd, vm, 0); |
70 | @@ -XXX,XX +XXX,XX @@ static int qbus_reset_one(BusState *bus, void *opaque) | 153 | +} |
71 | 154 | +void HELPER(mve_vcvtt_hs)(CPUARMState *env, void *vd, void *vm) | |
72 | void qdev_reset_all(DeviceState *dev) | 155 | +{ |
73 | { | 156 | + do_vcvt_hs(env, vd, vm, 1); |
74 | - qdev_walk_children(dev, NULL, NULL, qdev_reset_one, qbus_reset_one, NULL); | 157 | +} |
75 | + trace_qdev_reset_all(dev, object_get_typename(OBJECT(dev))); | 158 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c |
76 | + qdev_walk_children(dev, qdev_prereset, qbus_prereset, | ||
77 | + qdev_reset_one, qbus_reset_one, NULL); | ||
78 | } | ||
79 | |||
80 | void qdev_reset_all_fn(void *opaque) | ||
81 | @@ -XXX,XX +XXX,XX @@ void qdev_reset_all_fn(void *opaque) | ||
82 | |||
83 | void qbus_reset_all(BusState *bus) | ||
84 | { | ||
85 | - qbus_walk_children(bus, NULL, NULL, qdev_reset_one, qbus_reset_one, NULL); | ||
86 | + trace_qbus_reset_all(bus, object_get_typename(OBJECT(bus))); | ||
87 | + qbus_walk_children(bus, qdev_prereset, qbus_prereset, | ||
88 | + qdev_reset_one, qbus_reset_one, NULL); | ||
89 | } | ||
90 | |||
91 | void qbus_reset_all_fn(void *opaque) | ||
92 | @@ -XXX,XX +XXX,XX @@ void device_legacy_reset(DeviceState *dev) | ||
93 | { | ||
94 | DeviceClass *klass = DEVICE_GET_CLASS(dev); | ||
95 | |||
96 | + trace_qdev_reset(dev, object_get_typename(OBJECT(dev))); | ||
97 | if (klass->reset) { | ||
98 | klass->reset(dev); | ||
99 | } | ||
100 | diff --git a/hw/core/trace-events b/hw/core/trace-events | ||
101 | index XXXXXXX..XXXXXXX 100644 | 159 | index XXXXXXX..XXXXXXX 100644 |
102 | --- a/hw/core/trace-events | 160 | --- a/target/arm/translate-mve.c |
103 | +++ b/hw/core/trace-events | 161 | +++ b/target/arm/translate-mve.c |
104 | @@ -XXX,XX +XXX,XX @@ | 162 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_RMODE(VCVTPU, FPROUNDING_POSINF, true) |
105 | # loader.c | 163 | DO_VCVT_RMODE(VCVTMS, FPROUNDING_NEGINF, false) |
106 | loader_write_rom(const char *name, uint64_t gpa, uint64_t size, bool isrom) "%s: @0x%"PRIx64" size=0x%"PRIx64" ROM=%d" | 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 | + } \ | ||
107 | + | 174 | + |
108 | +# qdev.c | 175 | +DO_VCVT_SH(VCVTB_SH, vcvtb_sh) |
109 | +qdev_reset(void *obj, const char *objtype) "obj=%p(%s)" | 176 | +DO_VCVT_SH(VCVTT_SH, vcvtt_sh) |
110 | +qdev_reset_all(void *obj, const char *objtype) "obj=%p(%s)" | 177 | +DO_VCVT_SH(VCVTB_HS, vcvtb_hs) |
111 | +qdev_reset_tree(void *obj, const char *objtype) "obj=%p(%s)" | 178 | +DO_VCVT_SH(VCVTT_HS, vcvtt_hs) |
112 | +qbus_reset(void *obj, const char *objtype) "obj=%p(%s)" | 179 | + |
113 | +qbus_reset_all(void *obj, const char *objtype) "obj=%p(%s)" | 180 | /* Narrowing moves: only size 0 and 1 are valid */ |
114 | +qbus_reset_tree(void *obj, const char *objtype) "obj=%p(%s)" | 181 | #define DO_VMOVN(INSN, FN) \ |
115 | +qdev_update_parent_bus(void *obj, const char *objtype, void *oldp, const char *oldptype, void *newp, const char *newptype) "obj=%p(%s) old_parent=%p(%s) new_parent=%p(%s)" | 182 | static bool trans_##INSN(DisasContext *s, arg_1op *a) \ |
116 | -- | 183 | -- |
117 | 2.20.1 | 184 | 2.20.1 |
118 | 185 | ||
119 | 186 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Implement the MVE VRINT insns, which round floating point inputs | ||
2 | to integer values, leaving them in floating point format. | ||
1 | 3 | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | --- | ||
7 | target/arm/helper-mve.h | 6 +++++ | ||
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(+) | ||
12 | |||
13 | diff --git a/target/arm/helper-mve.h b/target/arm/helper-mve.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/arm/helper-mve.h | ||
16 | +++ b/target/arm/helper-mve.h | ||
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(mve_vcvt_sf, TCG_CALL_NO_WG, void, env, ptr, ptr, i32) | ||
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); | ||
62 | } | ||
63 | + | ||
64 | +#define DO_1OP_FP(OP, ESIZE, TYPE, FN) \ | ||
65 | + void HELPER(glue(mve_, OP))(CPUARMState *env, void *vd, void *vm) \ | ||
66 | + { \ | ||
67 | + TYPE *d = vd, *m = vm; \ | ||
68 | + TYPE r; \ | ||
69 | + uint16_t mask = mve_element_mask(env); \ | ||
70 | + unsigned e; \ | ||
71 | + float_status *fpst; \ | ||
72 | + float_status scratch_fpst; \ | ||
73 | + for (e = 0; e < 16 / ESIZE; e++, mask >>= ESIZE) { \ | ||
74 | + if ((mask & MAKE_64BIT_MASK(0, ESIZE)) == 0) { \ | ||
75 | + continue; \ | ||
76 | + } \ | ||
77 | + fpst = (ESIZE == 2) ? &env->vfp.standard_fp_status_f16 : \ | ||
78 | + &env->vfp.standard_fp_status; \ | ||
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)], fpst); \ | ||
85 | + mergemask(&d[H##ESIZE(e)], r, mask); \ | ||
86 | + } \ | ||
87 | + mve_advance_vpt(env); \ | ||
88 | + } | ||
89 | + | ||
90 | +DO_1OP_FP(vrintx_h, 2, float16, float16_round_to_int) | ||
91 | +DO_1OP_FP(vrintx_s, 4, float32, float32_round_to_int) | ||
92 | diff --git a/target/arm/translate-mve.c b/target/arm/translate-mve.c | ||
93 | index XXXXXXX..XXXXXXX 100644 | ||
94 | --- a/target/arm/translate-mve.c | ||
95 | +++ b/target/arm/translate-mve.c | ||
96 | @@ -XXX,XX +XXX,XX @@ DO_VCVT_SH(VCVTT_SH, vcvtt_sh) | ||
97 | DO_VCVT_SH(VCVTB_HS, vcvtb_hs) | ||
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]); \ | ||
123 | + } | ||
124 | + | ||
125 | +DO_VRINT(VRINTN, FPROUNDING_TIEEVEN) | ||
126 | +DO_VRINT(VRINTA, FPROUNDING_TIEAWAY) | ||
127 | +DO_VRINT(VRINTZ, FPROUNDING_ZERO) | ||
128 | +DO_VRINT(VRINTM, FPROUNDING_NEGINF) | ||
129 | +DO_VRINT(VRINTP, FPROUNDING_POSINF) | ||
130 | + | ||
131 | +static bool trans_VRINTX(DisasContext *s, arg_1op *a) | ||
132 | +{ | ||
133 | + static MVEGenOneOpFn * const fns[] = { | ||
134 | + NULL, | ||
135 | + gen_helper_mve_vrintx_h, | ||
136 | + gen_helper_mve_vrintx_s, | ||
137 | + NULL, | ||
138 | + }; | ||
139 | + if (!dc_isar_feature(aa32_mve_fp, s)) { | ||
140 | + return false; | ||
141 | + } | ||
142 | + return do_1op(s, a, fns[a->size]); | ||
143 | +} | ||
144 | + | ||
145 | /* Narrowing moves: only size 0 and 1 are valid */ | ||
146 | #define DO_VMOVN(INSN, FN) \ | ||
147 | static bool trans_##INSN(DisasContext *s, arg_1op *a) \ | ||
148 | -- | ||
149 | 2.20.1 | ||
150 | |||
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: Andrew Jones <drjones@redhat.com> | 1 | From: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> |
---|---|---|---|
2 | 2 | ||
3 | kvm-no-adjvtime is a KVM specific CPU property and a first of its | 3 | Add a definition for the Fujitsu A64FX processor. |
4 | kind. To accommodate it we also add kvm_arm_add_vcpu_properties() | ||
5 | and a KVM specific CPU properties description to the CPU features | ||
6 | document. | ||
7 | 4 | ||
8 | Signed-off-by: Andrew Jones <drjones@redhat.com> | 5 | The A64FX processor does not implement the AArch32 Execution state, |
9 | Message-id: 20200120101023.16030-7-drjones@redhat.com | 6 | so there are no associated AArch32 Identification registers. |
10 | 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> | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 17 | --- |
13 | include/hw/arm/virt.h | 1 + | 18 | target/arm/cpu64.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++ |
14 | target/arm/kvm_arm.h | 11 ++++++++++ | 19 | 1 file changed, 48 insertions(+) |
15 | hw/arm/virt.c | 8 ++++++++ | ||
16 | target/arm/cpu.c | 2 ++ | ||
17 | target/arm/cpu64.c | 1 + | ||
18 | target/arm/kvm.c | 28 +++++++++++++++++++++++++ | ||
19 | target/arm/monitor.c | 1 + | ||
20 | tests/qtest/arm-cpu-features.c | 4 ++++ | ||
21 | docs/arm-cpu-features.rst | 37 +++++++++++++++++++++++++++++++++- | ||
22 | 9 files changed, 92 insertions(+), 1 deletion(-) | ||
23 | 20 | ||
24 | diff --git a/include/hw/arm/virt.h b/include/hw/arm/virt.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | ||
26 | --- a/include/hw/arm/virt.h | ||
27 | +++ b/include/hw/arm/virt.h | ||
28 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
29 | bool smbios_old_sys_ver; | ||
30 | bool no_highmem_ecam; | ||
31 | bool no_ged; /* Machines < 4.2 has no support for ACPI GED device */ | ||
32 | + bool kvm_no_adjvtime; | ||
33 | } VirtMachineClass; | ||
34 | |||
35 | typedef struct { | ||
36 | diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/arm/kvm_arm.h | ||
39 | +++ b/target/arm/kvm_arm.h | ||
40 | @@ -XXX,XX +XXX,XX @@ void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *map); | ||
41 | */ | ||
42 | void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu); | ||
43 | |||
44 | +/** | ||
45 | + * kvm_arm_add_vcpu_properties: | ||
46 | + * @obj: The CPU object to add the properties to | ||
47 | + * | ||
48 | + * Add all KVM specific CPU properties to the CPU object. These | ||
49 | + * are the CPU properties with "kvm-" prefixed names. | ||
50 | + */ | ||
51 | +void kvm_arm_add_vcpu_properties(Object *obj); | ||
52 | + | ||
53 | /** | ||
54 | * kvm_arm_aarch32_supported: | ||
55 | * @cs: CPUState | ||
56 | @@ -XXX,XX +XXX,XX @@ static inline void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu) | ||
57 | cpu->host_cpu_probe_failed = true; | ||
58 | } | ||
59 | |||
60 | +static inline void kvm_arm_add_vcpu_properties(Object *obj) {} | ||
61 | + | ||
62 | static inline bool kvm_arm_aarch32_supported(CPUState *cs) | ||
63 | { | ||
64 | return false; | ||
65 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/hw/arm/virt.c | ||
68 | +++ b/hw/arm/virt.c | ||
69 | @@ -XXX,XX +XXX,XX @@ static void machvirt_init(MachineState *machine) | ||
70 | } | ||
71 | } | ||
72 | |||
73 | + if (vmc->kvm_no_adjvtime && | ||
74 | + object_property_find(cpuobj, "kvm-no-adjvtime", NULL)) { | ||
75 | + object_property_set_bool(cpuobj, true, "kvm-no-adjvtime", NULL); | ||
76 | + } | ||
77 | + | ||
78 | if (vmc->no_pmu && object_property_find(cpuobj, "pmu", NULL)) { | ||
79 | object_property_set_bool(cpuobj, false, "pmu", NULL); | ||
80 | } | ||
81 | @@ -XXX,XX +XXX,XX @@ DEFINE_VIRT_MACHINE_AS_LATEST(5, 0) | ||
82 | |||
83 | static void virt_machine_4_2_options(MachineClass *mc) | ||
84 | { | ||
85 | + VirtMachineClass *vmc = VIRT_MACHINE_CLASS(OBJECT_CLASS(mc)); | ||
86 | + | ||
87 | virt_machine_5_0_options(mc); | ||
88 | compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len); | ||
89 | + vmc->kvm_no_adjvtime = true; | ||
90 | } | ||
91 | DEFINE_VIRT_MACHINE(4, 2) | ||
92 | |||
93 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
94 | index XXXXXXX..XXXXXXX 100644 | ||
95 | --- a/target/arm/cpu.c | ||
96 | +++ b/target/arm/cpu.c | ||
97 | @@ -XXX,XX +XXX,XX @@ static void arm_max_initfn(Object *obj) | ||
98 | |||
99 | if (kvm_enabled()) { | ||
100 | kvm_arm_set_cpu_features_from_host(cpu); | ||
101 | + kvm_arm_add_vcpu_properties(obj); | ||
102 | } else { | ||
103 | cortex_a15_initfn(obj); | ||
104 | |||
105 | @@ -XXX,XX +XXX,XX @@ static void arm_host_initfn(Object *obj) | ||
106 | if (arm_feature(&cpu->env, ARM_FEATURE_AARCH64)) { | ||
107 | aarch64_add_sve_properties(obj); | ||
108 | } | ||
109 | + kvm_arm_add_vcpu_properties(obj); | ||
110 | arm_cpu_post_init(obj); | ||
111 | } | ||
112 | |||
113 | 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 |
114 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
115 | --- a/target/arm/cpu64.c | 23 | --- a/target/arm/cpu64.c |
116 | +++ b/target/arm/cpu64.c | 24 | +++ b/target/arm/cpu64.c |
117 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) | 25 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) |
118 | 26 | cpu_max_set_sve_max_vq, NULL, NULL); | |
119 | if (kvm_enabled()) { | ||
120 | kvm_arm_set_cpu_features_from_host(cpu); | ||
121 | + kvm_arm_add_vcpu_properties(obj); | ||
122 | } else { | ||
123 | uint64_t t; | ||
124 | uint32_t u; | ||
125 | diff --git a/target/arm/kvm.c b/target/arm/kvm.c | ||
126 | index XXXXXXX..XXXXXXX 100644 | ||
127 | --- a/target/arm/kvm.c | ||
128 | +++ b/target/arm/kvm.c | ||
129 | @@ -XXX,XX +XXX,XX @@ | ||
130 | #include "qemu/timer.h" | ||
131 | #include "qemu/error-report.h" | ||
132 | #include "qemu/main-loop.h" | ||
133 | +#include "qom/object.h" | ||
134 | +#include "qapi/error.h" | ||
135 | #include "sysemu/sysemu.h" | ||
136 | #include "sysemu/kvm.h" | ||
137 | #include "sysemu/kvm_int.h" | ||
138 | @@ -XXX,XX +XXX,XX @@ void kvm_arm_set_cpu_features_from_host(ARMCPU *cpu) | ||
139 | env->features = arm_host_cpu_features.features; | ||
140 | } | 27 | } |
141 | 28 | ||
142 | +static bool kvm_no_adjvtime_get(Object *obj, Error **errp) | 29 | +static void aarch64_a64fx_initfn(Object *obj) |
143 | +{ | 30 | +{ |
144 | + return !ARM_CPU(obj)->kvm_adjvtime; | 31 | + ARMCPU *cpu = ARM_CPU(obj); |
32 | + | ||
33 | + cpu->dtb_compatible = "arm,a64fx"; | ||
34 | + set_feature(&cpu->env, ARM_FEATURE_V8); | ||
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 */ | ||
145 | +} | 74 | +} |
146 | + | 75 | + |
147 | +static void kvm_no_adjvtime_set(Object *obj, bool value, Error **errp) | 76 | static const ARMCPUInfo aarch64_cpus[] = { |
148 | +{ | 77 | { .name = "cortex-a57", .initfn = aarch64_a57_initfn }, |
149 | + ARM_CPU(obj)->kvm_adjvtime = !value; | 78 | { .name = "cortex-a53", .initfn = aarch64_a53_initfn }, |
150 | +} | 79 | { .name = "cortex-a72", .initfn = aarch64_a72_initfn }, |
151 | + | 80 | + { .name = "a64fx", .initfn = aarch64_a64fx_initfn }, |
152 | +/* KVM VCPU properties should be prefixed with "kvm-". */ | 81 | { .name = "max", .initfn = aarch64_max_initfn }, |
153 | +void kvm_arm_add_vcpu_properties(Object *obj) | ||
154 | +{ | ||
155 | + if (!kvm_enabled()) { | ||
156 | + return; | ||
157 | + } | ||
158 | + | ||
159 | + ARM_CPU(obj)->kvm_adjvtime = true; | ||
160 | + object_property_add_bool(obj, "kvm-no-adjvtime", kvm_no_adjvtime_get, | ||
161 | + kvm_no_adjvtime_set, &error_abort); | ||
162 | + object_property_set_description(obj, "kvm-no-adjvtime", | ||
163 | + "Set on to disable the adjustment of " | ||
164 | + "the virtual counter. VM stopped time " | ||
165 | + "will be counted.", &error_abort); | ||
166 | +} | ||
167 | + | ||
168 | bool kvm_arm_pmu_supported(CPUState *cpu) | ||
169 | { | ||
170 | return kvm_check_extension(cpu->kvm_state, KVM_CAP_ARM_PMU_V3); | ||
171 | diff --git a/target/arm/monitor.c b/target/arm/monitor.c | ||
172 | index XXXXXXX..XXXXXXX 100644 | ||
173 | --- a/target/arm/monitor.c | ||
174 | +++ b/target/arm/monitor.c | ||
175 | @@ -XXX,XX +XXX,XX @@ static const char *cpu_model_advertised_features[] = { | ||
176 | "sve128", "sve256", "sve384", "sve512", | ||
177 | "sve640", "sve768", "sve896", "sve1024", "sve1152", "sve1280", | ||
178 | "sve1408", "sve1536", "sve1664", "sve1792", "sve1920", "sve2048", | ||
179 | + "kvm-no-adjvtime", | ||
180 | NULL | ||
181 | }; | 82 | }; |
182 | |||
183 | diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c | ||
184 | index XXXXXXX..XXXXXXX 100644 | ||
185 | --- a/tests/qtest/arm-cpu-features.c | ||
186 | +++ b/tests/qtest/arm-cpu-features.c | ||
187 | @@ -XXX,XX +XXX,XX @@ static void test_query_cpu_model_expansion(const void *data) | ||
188 | assert_has_feature_enabled(qts, "cortex-a15", "pmu"); | ||
189 | assert_has_not_feature(qts, "cortex-a15", "aarch64"); | ||
190 | |||
191 | + assert_has_not_feature(qts, "max", "kvm-no-adjvtime"); | ||
192 | + | ||
193 | if (g_str_equal(qtest_get_arch(), "aarch64")) { | ||
194 | assert_has_feature_enabled(qts, "max", "aarch64"); | ||
195 | assert_has_feature_enabled(qts, "max", "sve"); | ||
196 | @@ -XXX,XX +XXX,XX @@ static void test_query_cpu_model_expansion_kvm(const void *data) | ||
197 | return; | ||
198 | } | ||
199 | |||
200 | + assert_has_feature_disabled(qts, "host", "kvm-no-adjvtime"); | ||
201 | + | ||
202 | if (g_str_equal(qtest_get_arch(), "aarch64")) { | ||
203 | bool kvm_supports_sve; | ||
204 | char max_name[8], name[8]; | ||
205 | diff --git a/docs/arm-cpu-features.rst b/docs/arm-cpu-features.rst | ||
206 | index XXXXXXX..XXXXXXX 100644 | ||
207 | --- a/docs/arm-cpu-features.rst | ||
208 | +++ b/docs/arm-cpu-features.rst | ||
209 | @@ -XXX,XX +XXX,XX @@ supporting the feature or only supporting the feature under certain | ||
210 | configurations. For example, the `aarch64` CPU feature, which, when | ||
211 | disabled, enables the optional AArch32 CPU feature, is only supported | ||
212 | when using the KVM accelerator and when running on a host CPU type that | ||
213 | -supports the feature. | ||
214 | +supports the feature. While `aarch64` currently only works with KVM, | ||
215 | +it could work with TCG. CPU features that are specific to KVM are | ||
216 | +prefixed with "kvm-" and are described in "KVM VCPU Features". | ||
217 | |||
218 | CPU Feature Probing | ||
219 | =================== | ||
220 | @@ -XXX,XX +XXX,XX @@ disabling many SVE vector lengths would be quite verbose, the `sve<N>` CPU | ||
221 | properties have special semantics (see "SVE CPU Property Parsing | ||
222 | Semantics"). | ||
223 | |||
224 | +KVM VCPU Features | ||
225 | +================= | ||
226 | + | ||
227 | +KVM VCPU features are CPU features that are specific to KVM, such as | ||
228 | +paravirt features or features that enable CPU virtualization extensions. | ||
229 | +The features' CPU properties are only available when KVM is enabled and | ||
230 | +are named with the prefix "kvm-". KVM VCPU features may be probed, | ||
231 | +enabled, and disabled in the same way as other CPU features. Below is | ||
232 | +the list of KVM VCPU features and their descriptions. | ||
233 | + | ||
234 | + kvm-no-adjvtime By default kvm-no-adjvtime is disabled. This | ||
235 | + means that by default the virtual time | ||
236 | + adjustment is enabled (vtime is *not not* | ||
237 | + adjusted). | ||
238 | + | ||
239 | + When virtual time adjustment is enabled each | ||
240 | + time the VM transitions back to running state | ||
241 | + the VCPU's virtual counter is updated to ensure | ||
242 | + stopped time is not counted. This avoids time | ||
243 | + jumps surprising guest OSes and applications, | ||
244 | + as long as they use the virtual counter for | ||
245 | + timekeeping. However it has the side effect of | ||
246 | + the virtual and physical counters diverging. | ||
247 | + All timekeeping based on the virtual counter | ||
248 | + will appear to lag behind any timekeeping that | ||
249 | + does not subtract VM stopped time. The guest | ||
250 | + may resynchronize its virtual counter with | ||
251 | + other time sources as needed. | ||
252 | + | ||
253 | + Enable kvm-no-adjvtime to disable virtual time | ||
254 | + adjustment, also restoring the legacy (pre-5.0) | ||
255 | + behavior. | ||
256 | + | ||
257 | SVE CPU Properties | ||
258 | ================== | ||
259 | 83 | ||
260 | -- | 84 | -- |
261 | 2.20.1 | 85 | 2.20.1 |
262 | 86 | ||
263 | 87 | diff view generated by jsdifflib |
1 | From: Andrew Jones <drjones@redhat.com> | 1 | From: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Andrew Jones <drjones@redhat.com> | 3 | Add -cpu a64fx to use A64FX processor when -machine virt option is |
4 | Message-id: 20200120101023.16030-3-drjones@redhat.com | 4 | specified. In addition, add a64fx to the Supported guest CPU types |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 5 | in the virt.rst document. |
6 | |||
7 | Signed-off-by: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> | ||
8 | Reviewed-by: Andrew Jones <drjones@redhat.com> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 10 | --- |
8 | hw/arm/virt.c | 1 + | 11 | docs/system/arm/virt.rst | 1 + |
9 | 1 file changed, 1 insertion(+) | 12 | hw/arm/virt.c | 1 + |
13 | 2 files changed, 2 insertions(+) | ||
10 | 14 | ||
15 | diff --git a/docs/system/arm/virt.rst b/docs/system/arm/virt.rst | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/docs/system/arm/virt.rst | ||
18 | +++ b/docs/system/arm/virt.rst | ||
19 | @@ -XXX,XX +XXX,XX @@ Supported guest CPU types: | ||
20 | - ``cortex-a53`` (64-bit) | ||
21 | - ``cortex-a57`` (64-bit) | ||
22 | - ``cortex-a72`` (64-bit) | ||
23 | +- ``a64fx`` (64-bit) | ||
24 | - ``host`` (with KVM only) | ||
25 | - ``max`` (same as ``host`` for KVM; best possible emulation with TCG) | ||
26 | |||
11 | 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 |
12 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/hw/arm/virt.c | 29 | --- a/hw/arm/virt.c |
14 | +++ b/hw/arm/virt.c | 30 | +++ b/hw/arm/virt.c |
15 | @@ -XXX,XX +XXX,XX @@ DEFINE_VIRT_MACHINE_AS_LATEST(5, 0) | 31 | @@ -XXX,XX +XXX,XX @@ static const char *valid_cpus[] = { |
16 | 32 | ARM_CPU_TYPE_NAME("cortex-a53"), | |
17 | static void virt_machine_4_2_options(MachineClass *mc) | 33 | ARM_CPU_TYPE_NAME("cortex-a57"), |
18 | { | 34 | ARM_CPU_TYPE_NAME("cortex-a72"), |
19 | + virt_machine_5_0_options(mc); | 35 | + ARM_CPU_TYPE_NAME("a64fx"), |
20 | compat_props_add(mc->compat_props, hw_compat_4_2, hw_compat_4_2_len); | 36 | ARM_CPU_TYPE_NAME("host"), |
21 | } | 37 | ARM_CPU_TYPE_NAME("max"), |
22 | DEFINE_VIRT_MACHINE(4, 2) | 38 | }; |
23 | -- | 39 | -- |
24 | 2.20.1 | 40 | 2.20.1 |
25 | 41 | ||
26 | 42 | diff view generated by jsdifflib |
1 | From: Andrew Jones <drjones@redhat.com> | 1 | From: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> |
---|---|---|---|
2 | 2 | ||
3 | If we know what the default value should be then we can test for | 3 | Add tests that the A64FX CPU model exposes the expected features. |
4 | that as well as the feature existence. | ||
5 | 4 | ||
6 | Signed-off-by: Andrew Jones <drjones@redhat.com> | 5 | Signed-off-by: Shuuichirou Ishii <ishii.shuuichir@fujitsu.com> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Reviewed-by: Andrew Jones <drjones@redhat.com> |
8 | Message-id: 20200120101023.16030-5-drjones@redhat.com | 7 | [PMM: added commit message body] |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 9 | --- |
11 | tests/qtest/arm-cpu-features.c | 37 +++++++++++++++++++++++++--------- | 10 | tests/qtest/arm-cpu-features.c | 13 +++++++++++++ |
12 | 1 file changed, 28 insertions(+), 9 deletions(-) | 11 | 1 file changed, 13 insertions(+) |
13 | 12 | ||
14 | diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c | 13 | diff --git a/tests/qtest/arm-cpu-features.c b/tests/qtest/arm-cpu-features.c |
15 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/tests/qtest/arm-cpu-features.c | 15 | --- a/tests/qtest/arm-cpu-features.c |
17 | +++ b/tests/qtest/arm-cpu-features.c | 16 | +++ b/tests/qtest/arm-cpu-features.c |
18 | @@ -XXX,XX +XXX,XX @@ static bool resp_get_feature(QDict *resp, const char *feature) | 17 | @@ -XXX,XX +XXX,XX @@ static void test_query_cpu_model_expansion(const void *data) |
19 | qobject_unref(_resp); \ | 18 | assert_has_feature_enabled(qts, "cortex-a57", "pmu"); |
20 | }) | 19 | assert_has_feature_enabled(qts, "cortex-a57", "aarch64"); |
21 | 20 | ||
22 | +#define assert_feature(qts, cpu_type, feature, expected_value) \ | 21 | + assert_has_feature_enabled(qts, "a64fx", "pmu"); |
23 | +({ \ | 22 | + assert_has_feature_enabled(qts, "a64fx", "aarch64"); |
24 | + QDict *_resp, *_props; \ | 23 | + /* |
25 | + \ | 24 | + * A64FX does not support any other vector lengths besides those |
26 | + _resp = do_query_no_props(qts, cpu_type); \ | 25 | + * that are enabled by default(128bit, 256bits, 512bit). |
27 | + g_assert(_resp); \ | 26 | + */ |
28 | + g_assert(resp_has_props(_resp)); \ | 27 | + assert_has_feature_enabled(qts, "a64fx", "sve"); |
29 | + _props = resp_get_props(_resp); \ | 28 | + assert_sve_vls(qts, "a64fx", 0xb, NULL); |
30 | + g_assert(qdict_get(_props, feature)); \ | 29 | + assert_error(qts, "a64fx", "cannot enable sve384", |
31 | + g_assert(qdict_get_bool(_props, feature) == (expected_value)); \ | 30 | + "{ 'sve384': true }"); |
32 | + qobject_unref(_resp); \ | 31 | + assert_error(qts, "a64fx", "cannot enable sve640", |
33 | +}) | 32 | + "{ 'sve640': true }"); |
34 | + | 33 | + |
35 | +#define assert_has_feature_enabled(qts, cpu_type, feature) \ | ||
36 | + assert_feature(qts, cpu_type, feature, true) | ||
37 | + | ||
38 | +#define assert_has_feature_disabled(qts, cpu_type, feature) \ | ||
39 | + assert_feature(qts, cpu_type, feature, false) | ||
40 | + | ||
41 | static void assert_type_full(QTestState *qts) | ||
42 | { | ||
43 | const char *error; | ||
44 | @@ -XXX,XX +XXX,XX @@ static void test_query_cpu_model_expansion(const void *data) | ||
45 | assert_error(qts, "host", "The CPU type 'host' requires KVM", NULL); | ||
46 | |||
47 | /* Test expected feature presence/absence for some cpu types */ | ||
48 | - assert_has_feature(qts, "max", "pmu"); | ||
49 | - assert_has_feature(qts, "cortex-a15", "pmu"); | ||
50 | + assert_has_feature_enabled(qts, "max", "pmu"); | ||
51 | + assert_has_feature_enabled(qts, "cortex-a15", "pmu"); | ||
52 | assert_has_not_feature(qts, "cortex-a15", "aarch64"); | ||
53 | |||
54 | if (g_str_equal(qtest_get_arch(), "aarch64")) { | ||
55 | - assert_has_feature(qts, "max", "aarch64"); | ||
56 | - assert_has_feature(qts, "max", "sve"); | ||
57 | - assert_has_feature(qts, "max", "sve128"); | ||
58 | - assert_has_feature(qts, "cortex-a57", "pmu"); | ||
59 | - assert_has_feature(qts, "cortex-a57", "aarch64"); | ||
60 | + assert_has_feature_enabled(qts, "max", "aarch64"); | ||
61 | + assert_has_feature_enabled(qts, "max", "sve"); | ||
62 | + assert_has_feature_enabled(qts, "max", "sve128"); | ||
63 | + assert_has_feature_enabled(qts, "cortex-a57", "pmu"); | ||
64 | + assert_has_feature_enabled(qts, "cortex-a57", "aarch64"); | ||
65 | |||
66 | sve_tests_default(qts, "max"); | 34 | sve_tests_default(qts, "max"); |
67 | 35 | pauth_tests_default(qts, "max"); | |
68 | @@ -XXX,XX +XXX,XX @@ static void test_query_cpu_model_expansion_kvm(const void *data) | 36 | |
69 | QDict *resp; | ||
70 | char *error; | ||
71 | |||
72 | - assert_has_feature(qts, "host", "aarch64"); | ||
73 | - assert_has_feature(qts, "host", "pmu"); | ||
74 | + assert_has_feature_enabled(qts, "host", "aarch64"); | ||
75 | + assert_has_feature_enabled(qts, "host", "pmu"); | ||
76 | |||
77 | assert_error(qts, "cortex-a15", | ||
78 | "We cannot guarantee the CPU type 'cortex-a15' works " | ||
79 | -- | 37 | -- |
80 | 2.20.1 | 38 | 2.20.1 |
81 | 39 | ||
82 | 40 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 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 | These buffers should be aligned on 16 bytes. | 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 | Ignore invalid RX and TX buffer addresses and log an error. All | 26 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h |
6 | incoming and outgoing traffic will be dropped because no valid RX or | 27 | index XXXXXXX..XXXXXXX 100644 |
7 | TX descriptors will be available. | 28 | --- a/include/hw/arm/armv7m.h |
8 | 29 | +++ b/include/hw/arm/armv7m.h | |
9 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | 30 | @@ -XXX,XX +XXX,XX @@ |
10 | Message-id: 20200114103433.30534-4-clg@kaod.org | 31 | |
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 32 | #include "hw/sysbus.h" |
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 33 | #include "hw/intc/armv7m_nvic.h" |
13 | --- | 34 | +#include "hw/misc/armv7m_ras.h" |
14 | hw/net/ftgmac100.c | 13 +++++++++++++ | 35 | #include "target/arm/idau.h" |
15 | 1 file changed, 13 insertions(+) | 36 | #include "qom/object.h" |
16 | 37 | ||
17 | diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c | 38 | @@ -XXX,XX +XXX,XX @@ struct ARMv7MState { |
18 | index XXXXXXX..XXXXXXX 100644 | 39 | NVICState nvic; |
19 | --- a/hw/net/ftgmac100.c | 40 | BitBandState bitband[ARMV7M_NUM_BITBANDS]; |
20 | +++ b/hw/net/ftgmac100.c | 41 | ARMCPU *cpu; |
21 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 42 | + ARMv7MRAS ras; |
22 | uint32_t des3; | 43 | |
23 | } FTGMAC100Desc; | 44 | /* MemoryRegion we pass to the CPU, with our devices layered on |
24 | 45 | * top of the ones the board provides in board_memory. | |
25 | +#define FTGMAC100_DESC_ALIGNMENT 16 | 46 | diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h |
26 | + | 47 | index XXXXXXX..XXXXXXX 100644 |
27 | /* | 48 | --- a/include/hw/intc/armv7m_nvic.h |
28 | * Specific RTL8211E MII Registers | 49 | +++ b/include/hw/intc/armv7m_nvic.h |
29 | */ | 50 | @@ -XXX,XX +XXX,XX @@ struct NVICState { |
30 | @@ -XXX,XX +XXX,XX @@ static void ftgmac100_write(void *opaque, hwaddr addr, | 51 | MemoryRegion sysreg_ns_mem; |
31 | s->itc = value; | 52 | MemoryRegion systickmem; |
32 | break; | 53 | MemoryRegion systick_ns_mem; |
33 | case FTGMAC100_RXR_BADR: /* Ring buffer address */ | 54 | - MemoryRegion ras_mem; |
34 | + if (!QEMU_IS_ALIGNED(value, FTGMAC100_DESC_ALIGNMENT)) { | 55 | MemoryRegion container; |
35 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad RX buffer alignment 0x%" | 56 | MemoryRegion defaultmem; |
36 | + HWADDR_PRIx "\n", __func__, value); | 57 | |
58 | diff --git a/include/hw/misc/armv7m_ras.h b/include/hw/misc/armv7m_ras.h | ||
59 | new file mode 100644 | ||
60 | index XXXXXXX..XXXXXXX | ||
61 | --- /dev/null | ||
62 | +++ b/include/hw/misc/armv7m_ras.h | ||
63 | @@ -XXX,XX +XXX,XX @@ | ||
64 | +/* | ||
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 | ||
86 | + | ||
87 | +#include "hw/sysbus.h" | ||
88 | + | ||
89 | +#define TYPE_ARMV7M_RAS "armv7m-ras" | ||
90 | +OBJECT_DECLARE_SIMPLE_TYPE(ARMv7MRAS, ARMV7M_RAS) | ||
91 | + | ||
92 | +struct ARMv7MRAS { | ||
93 | + /*< private >*/ | ||
94 | + SysBusDevice parent_obj; | ||
95 | + | ||
96 | + /*< public >*/ | ||
97 | + MemoryRegion iomem; | ||
98 | +}; | ||
99 | + | ||
100 | +#endif | ||
101 | diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c | ||
102 | index XXXXXXX..XXXXXXX 100644 | ||
103 | --- a/hw/arm/armv7m.c | ||
104 | +++ b/hw/arm/armv7m.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)) { | ||
37 | + return; | 115 | + return; |
38 | + } | 116 | + } |
39 | + | 117 | + memory_region_add_subregion_overlap(&s->container, 0xe0005000, |
40 | s->rx_ring = value; | 118 | + sysbus_mmio_get_region(sbd, 0), 1); |
41 | s->rx_descriptor = s->rx_ring; | 119 | + } |
42 | break; | 120 | + |
43 | @@ -XXX,XX +XXX,XX @@ static void ftgmac100_write(void *opaque, hwaddr addr, | 121 | for (i = 0; i < ARRAY_SIZE(s->bitband); i++) { |
44 | break; | 122 | if (s->enable_bitband) { |
45 | 123 | Object *obj = OBJECT(&s->bitband[i]); | |
46 | case FTGMAC100_NPTXR_BADR: /* Transmit buffer address */ | 124 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c |
47 | + if (!QEMU_IS_ALIGNED(value, FTGMAC100_DESC_ALIGNMENT)) { | 125 | index XXXXXXX..XXXXXXX 100644 |
48 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad TX buffer alignment 0x%" | 126 | --- a/hw/intc/armv7m_nvic.c |
49 | + HWADDR_PRIx "\n", __func__, value); | 127 | +++ b/hw/intc/armv7m_nvic.c |
50 | + return; | 128 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvic_systick_ops = { |
51 | + } | 129 | .endianness = DEVICE_NATIVE_ENDIAN, |
52 | s->tx_ring = value; | 130 | }; |
53 | s->tx_descriptor = s->tx_ring; | 131 | |
54 | break; | 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 | ||
199 | new file mode 100644 | ||
200 | index XXXXXXX..XXXXXXX | ||
201 | --- /dev/null | ||
202 | +++ b/hw/misc/armv7m_ras.c | ||
203 | @@ -XXX,XX +XXX,XX @@ | ||
204 | +/* | ||
205 | + * Arm M-profile RAS (Reliability, Availability and Serviceability) block | ||
206 | + * | ||
207 | + * Copyright (c) 2021 Linaro Limited | ||
208 | + * | ||
209 | + * This program is free software; you can redistribute it and/or modify | ||
210 | + * it under the terms of the GNU General Public License version 2 or | ||
211 | + * (at your option) any later version. | ||
212 | + */ | ||
213 | + | ||
214 | +#include "qemu/osdep.h" | ||
215 | +#include "hw/misc/armv7m_ras.h" | ||
216 | +#include "qemu/log.h" | ||
217 | + | ||
218 | +static MemTxResult ras_read(void *opaque, hwaddr addr, | ||
219 | + uint64_t *data, unsigned size, | ||
220 | + MemTxAttrs attrs) | ||
221 | +{ | ||
222 | + if (attrs.user) { | ||
223 | + return MEMTX_ERROR; | ||
224 | + } | ||
225 | + | ||
226 | + switch (addr) { | ||
227 | + case 0xe10: /* ERRIIDR */ | ||
228 | + /* architect field = Arm; product/variant/revision 0 */ | ||
229 | + *data = 0x43b; | ||
230 | + break; | ||
231 | + case 0xfc8: /* ERRDEVID */ | ||
232 | + /* Minimal RAS: we implement 0 error record indexes */ | ||
233 | + *data = 0; | ||
234 | + break; | ||
235 | + default: | ||
236 | + qemu_log_mask(LOG_UNIMP, "Read RAS register offset 0x%x\n", | ||
237 | + (uint32_t)addr); | ||
238 | + *data = 0; | ||
239 | + break; | ||
240 | + } | ||
241 | + return MEMTX_OK; | ||
242 | +} | ||
243 | + | ||
244 | +static MemTxResult ras_write(void *opaque, hwaddr addr, | ||
245 | + uint64_t value, unsigned size, | ||
246 | + MemTxAttrs attrs) | ||
247 | +{ | ||
248 | + if (attrs.user) { | ||
249 | + return MEMTX_ERROR; | ||
250 | + } | ||
251 | + | ||
252 | + switch (addr) { | ||
253 | + default: | ||
254 | + qemu_log_mask(LOG_UNIMP, "Write to RAS register offset 0x%x\n", | ||
255 | + (uint32_t)addr); | ||
256 | + break; | ||
257 | + } | ||
258 | + return MEMTX_OK; | ||
259 | +} | ||
260 | + | ||
261 | +static const MemoryRegionOps ras_ops = { | ||
262 | + .read_with_attrs = ras_read, | ||
263 | + .write_with_attrs = ras_write, | ||
264 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
265 | +}; | ||
266 | + | ||
267 | + | ||
268 | +static void armv7m_ras_init(Object *obj) | ||
269 | +{ | ||
270 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
271 | + ARMv7MRAS *s = ARMV7M_RAS(obj); | ||
272 | + | ||
273 | + memory_region_init_io(&s->iomem, obj, &ras_ops, | ||
274 | + s, "armv7m-ras", 0x1000); | ||
275 | + sysbus_init_mmio(sbd, &s->iomem); | ||
276 | +} | ||
277 | + | ||
278 | +static void armv7m_ras_class_init(ObjectClass *klass, void *data) | ||
279 | +{ | ||
280 | + /* This device has no state: no need for vmstate or reset */ | ||
281 | +} | ||
282 | + | ||
283 | +static const TypeInfo armv7m_ras_info = { | ||
284 | + .name = TYPE_ARMV7M_RAS, | ||
285 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
286 | + .instance_size = sizeof(ARMv7MRAS), | ||
287 | + .instance_init = armv7m_ras_init, | ||
288 | + .class_init = armv7m_ras_class_init, | ||
289 | +}; | ||
290 | + | ||
291 | +static void armv7m_ras_register_types(void) | ||
292 | +{ | ||
293 | + type_register_static(&armv7m_ras_info); | ||
294 | +} | ||
295 | + | ||
296 | +type_init(armv7m_ras_register_types); | ||
297 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
298 | index XXXXXXX..XXXXXXX 100644 | ||
299 | --- a/MAINTAINERS | ||
300 | +++ b/MAINTAINERS | ||
301 | @@ -XXX,XX +XXX,XX @@ F: hw/intc/gic_internal.h | ||
302 | F: hw/misc/a9scu.c | ||
303 | F: hw/misc/arm11scu.c | ||
304 | F: hw/misc/arm_l2x0.c | ||
305 | +F: hw/misc/armv7m_ras.c | ||
306 | F: hw/timer/a9gtimer* | ||
307 | F: hw/timer/arm* | ||
308 | F: include/hw/arm/arm*.h | ||
309 | @@ -XXX,XX +XXX,XX @@ F: include/hw/misc/arm11scu.h | ||
310 | F: include/hw/timer/a9gtimer.h | ||
311 | F: include/hw/timer/arm_mptimer.h | ||
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 | |||
55 | -- | 330 | -- |
56 | 2.20.1 | 331 | 2.20.1 |
57 | 332 | ||
58 | 333 | diff view generated by jsdifflib |
1 | From: Andrew Jones <drjones@redhat.com> | 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 | When a VM is stopped (such as when it's paused) guest virtual time | 3 | instead, as part of consolidating the "create the devices which are |
4 | should stop counting. Otherwise, when the VM is resumed it will | 4 | built into an M-profile CPU and map them into their architected |
5 | experience time jumps and its kernel may report soft lockups. Not | 5 | locations in the address space" work into one place. |
6 | counting virtual time while the VM is stopped has the side effect | 6 | |
7 | of making the guest's time appear to lag when compared with real | 7 | This involves temporarily creating a duplicate copy of the |
8 | time, and even with time derived from the physical counter. For | 8 | nvic_sysreg_ns_ops struct and its read/write functions (renamed as |
9 | this reason, this change, which is enabled by default, comes with | 9 | v7m_sysreg_ns_*), but we will delete the NVIC's copy of this code in |
10 | a KVM CPU feature allowing it to be disabled, restoring legacy | 10 | a subsequent patch. |
11 | behavior. | 11 | |
12 | |||
13 | This patch only provides the implementation of the virtual time | ||
14 | adjustment. A subsequent patch will provide the CPU property | ||
15 | allowing the change to be enabled and disabled. | ||
16 | |||
17 | Reported-by: Bijan Mottahedeh <bijan.mottahedeh@oracle.com> | ||
18 | Signed-off-by: Andrew Jones <drjones@redhat.com> | ||
19 | Message-id: 20200120101023.16030-6-drjones@redhat.com | ||
20 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
21 | 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 | ||
22 | --- | 16 | --- |
23 | target/arm/cpu.h | 7 ++++ | 17 | include/hw/arm/armv7m.h | 12 ++++ |
24 | target/arm/kvm_arm.h | 38 ++++++++++++++++++ | 18 | include/hw/intc/armv7m_nvic.h | 4 -- |
25 | target/arm/kvm.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ | 19 | hw/arm/armv7m.c | 125 ++++++++++++++++++++++++++++++++++ |
26 | target/arm/kvm32.c | 3 ++ | 20 | hw/intc/armv7m_nvic.c | 73 -------------------- |
27 | target/arm/kvm64.c | 3 ++ | 21 | 4 files changed, 137 insertions(+), 77 deletions(-) |
28 | target/arm/machine.c | 7 ++++ | 22 | |
29 | 6 files changed, 150 insertions(+) | 23 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h |
30 | |||
31 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | 24 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/target/arm/cpu.h | 25 | --- a/include/hw/arm/armv7m.h |
34 | +++ b/target/arm/cpu.h | 26 | +++ b/include/hw/arm/armv7m.h |
35 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { | 27 | @@ -XXX,XX +XXX,XX @@ struct ARMv7MState { |
36 | /* KVM init features for this CPU */ | 28 | BitBandState bitband[ARMV7M_NUM_BITBANDS]; |
37 | uint32_t kvm_init_features[7]; | 29 | ARMCPU *cpu; |
38 | 30 | ARMv7MRAS ras; | |
39 | + /* KVM CPU state */ | 31 | + SysTickState systick[M_REG_NUM_BANKS]; |
40 | + | 32 | |
41 | + /* KVM virtual time adjustment */ | 33 | /* MemoryRegion we pass to the CPU, with our devices layered on |
42 | + bool kvm_adjvtime; | 34 | * top of the ones the board provides in board_memory. |
43 | + bool kvm_vtime_dirty; | 35 | */ |
44 | + uint64_t kvm_vtime; | 36 | MemoryRegion container; |
45 | + | 37 | + /* |
46 | /* Uniprocessor system with MP extensions */ | 38 | + * MemoryRegion which passes the transaction to either the S or the |
47 | bool mp_is_up; | 39 | + * NS systick device depending on the transaction attributes |
48 | 40 | + */ | |
49 | diff --git a/target/arm/kvm_arm.h b/target/arm/kvm_arm.h | 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 | ||
50 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
51 | --- a/target/arm/kvm_arm.h | 53 | --- a/include/hw/intc/armv7m_nvic.h |
52 | +++ b/target/arm/kvm_arm.h | 54 | +++ b/include/hw/intc/armv7m_nvic.h |
53 | @@ -XXX,XX +XXX,XX @@ bool write_list_to_kvmstate(ARMCPU *cpu, int level); | 55 | @@ -XXX,XX +XXX,XX @@ struct NVICState { |
54 | */ | 56 | |
55 | bool write_kvmstate_to_list(ARMCPU *cpu); | 57 | MemoryRegion sysregmem; |
56 | 58 | MemoryRegion sysreg_ns_mem; | |
57 | +/** | 59 | - MemoryRegion systickmem; |
58 | + * kvm_arm_cpu_pre_save: | 60 | - MemoryRegion systick_ns_mem; |
59 | + * @cpu: ARMCPU | 61 | MemoryRegion container; |
60 | + * | 62 | MemoryRegion defaultmem; |
61 | + * Called after write_kvmstate_to_list() from cpu_pre_save() to update | 63 | |
62 | + * the cpreg list with KVM CPU state. | 64 | uint32_t num_irq; |
63 | + */ | 65 | qemu_irq excpout; |
64 | +void kvm_arm_cpu_pre_save(ARMCPU *cpu); | 66 | qemu_irq sysresetreq; |
65 | + | 67 | - |
66 | +/** | 68 | - SysTickState systick[M_REG_NUM_BANKS]; |
67 | + * kvm_arm_cpu_post_load: | 69 | }; |
68 | + * @cpu: ARMCPU | 70 | |
69 | + * | ||
70 | + * Called from cpu_post_load() to update KVM CPU state from the cpreg list. | ||
71 | + */ | ||
72 | +void kvm_arm_cpu_post_load(ARMCPU *cpu); | ||
73 | + | ||
74 | /** | ||
75 | * kvm_arm_reset_vcpu: | ||
76 | * @cpu: ARMCPU | ||
77 | @@ -XXX,XX +XXX,XX @@ int kvm_arm_sync_mpstate_to_kvm(ARMCPU *cpu); | ||
78 | */ | ||
79 | int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu); | ||
80 | |||
81 | +/** | ||
82 | + * kvm_arm_get_virtual_time: | ||
83 | + * @cs: CPUState | ||
84 | + * | ||
85 | + * Gets the VCPU's virtual counter and stores it in the KVM CPU state. | ||
86 | + */ | ||
87 | +void kvm_arm_get_virtual_time(CPUState *cs); | ||
88 | + | ||
89 | +/** | ||
90 | + * kvm_arm_put_virtual_time: | ||
91 | + * @cs: CPUState | ||
92 | + * | ||
93 | + * Sets the VCPU's virtual counter to the value stored in the KVM CPU state. | ||
94 | + */ | ||
95 | +void kvm_arm_put_virtual_time(CPUState *cs); | ||
96 | + | ||
97 | +void kvm_arm_vm_state_change(void *opaque, int running, RunState state); | ||
98 | + | ||
99 | int kvm_arm_vgic_probe(void); | ||
100 | |||
101 | void kvm_arm_pmu_set_irq(CPUState *cs, int irq); | ||
102 | @@ -XXX,XX +XXX,XX @@ static inline void kvm_arm_pmu_set_irq(CPUState *cs, int irq) {} | ||
103 | static inline void kvm_arm_pmu_init(CPUState *cs) {} | ||
104 | |||
105 | static inline void kvm_arm_sve_get_vls(CPUState *cs, unsigned long *map) {} | ||
106 | + | ||
107 | +static inline void kvm_arm_get_virtual_time(CPUState *cs) {} | ||
108 | +static inline void kvm_arm_put_virtual_time(CPUState *cs) {} | ||
109 | #endif | 71 | #endif |
110 | 72 | diff --git a/hw/arm/armv7m.c b/hw/arm/armv7m.c | |
111 | static inline const char *gic_class_name(void) | ||
112 | diff --git a/target/arm/kvm.c b/target/arm/kvm.c | ||
113 | index XXXXXXX..XXXXXXX 100644 | 73 | index XXXXXXX..XXXXXXX 100644 |
114 | --- a/target/arm/kvm.c | 74 | --- a/hw/arm/armv7m.c |
115 | +++ b/target/arm/kvm.c | 75 | +++ b/hw/arm/armv7m.c |
116 | @@ -XXX,XX +XXX,XX @@ static int compare_u64(const void *a, const void *b) | 76 | @@ -XXX,XX +XXX,XX @@ static const hwaddr bitband_output_addr[ARMV7M_NUM_BITBANDS] = { |
117 | return 0; | 77 | 0x22000000, 0x42000000 |
118 | } | 78 | }; |
119 | 79 | ||
120 | +/* | 80 | +static MemTxResult v7m_sysreg_ns_write(void *opaque, hwaddr addr, |
121 | + * cpreg_values are sorted in ascending order by KVM register ID | 81 | + uint64_t value, unsigned size, |
122 | + * (see kvm_arm_init_cpreg_list). This allows us to cheaply find | 82 | + MemTxAttrs attrs) |
123 | + * the storage for a KVM register by ID with a binary search. | ||
124 | + */ | ||
125 | +static uint64_t *kvm_arm_get_cpreg_ptr(ARMCPU *cpu, uint64_t regidx) | ||
126 | +{ | 83 | +{ |
127 | + uint64_t *res; | 84 | + MemoryRegion *mr = opaque; |
128 | + | 85 | + |
129 | + res = bsearch(®idx, cpu->cpreg_indexes, cpu->cpreg_array_len, | 86 | + if (attrs.secure) { |
130 | + sizeof(uint64_t), compare_u64); | 87 | + /* S accesses to the alias act like NS accesses to the real region */ |
131 | + assert(res); | 88 | + attrs.secure = 0; |
132 | + | 89 | + return memory_region_dispatch_write(mr, addr, value, |
133 | + return &cpu->cpreg_values[res - cpu->cpreg_indexes]; | 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 | + } | ||
134 | +} | 98 | +} |
135 | + | 99 | + |
136 | /* Initialize the ARMCPU cpreg list according to the kernel's | 100 | +static MemTxResult v7m_sysreg_ns_read(void *opaque, hwaddr addr, |
137 | * definition of what CPU registers it knows about (and throw away | 101 | + uint64_t *data, unsigned size, |
138 | * the previous TCG-created cpreg list). | 102 | + MemTxAttrs attrs) |
139 | @@ -XXX,XX +XXX,XX @@ bool write_list_to_kvmstate(ARMCPU *cpu, int level) | ||
140 | return ok; | ||
141 | } | ||
142 | |||
143 | +void kvm_arm_cpu_pre_save(ARMCPU *cpu) | ||
144 | +{ | 103 | +{ |
145 | + /* KVM virtual time adjustment */ | 104 | + MemoryRegion *mr = opaque; |
146 | + if (cpu->kvm_vtime_dirty) { | 105 | + |
147 | + *kvm_arm_get_cpreg_ptr(cpu, KVM_REG_ARM_TIMER_CNT) = cpu->kvm_vtime; | 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; | ||
148 | + } | 118 | + } |
149 | +} | 119 | +} |
150 | + | 120 | + |
151 | +void kvm_arm_cpu_post_load(ARMCPU *cpu) | 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) | ||
152 | +{ | 130 | +{ |
153 | + /* KVM virtual time adjustment */ | 131 | + ARMv7MState *s = opaque; |
154 | + if (cpu->kvm_adjvtime) { | 132 | + MemoryRegion *mr; |
155 | + cpu->kvm_vtime = *kvm_arm_get_cpreg_ptr(cpu, KVM_REG_ARM_TIMER_CNT); | 133 | + |
156 | + cpu->kvm_vtime_dirty = true; | 134 | + /* Direct the access to the correct systick */ |
157 | + } | 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); | ||
158 | +} | 138 | +} |
159 | + | 139 | + |
160 | void kvm_arm_reset_vcpu(ARMCPU *cpu) | 140 | +static MemTxResult v7m_systick_read(void *opaque, hwaddr addr, |
141 | + uint64_t *data, unsigned size, | ||
142 | + MemTxAttrs attrs) | ||
143 | +{ | ||
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); | ||
151 | +} | ||
152 | + | ||
153 | +static const MemoryRegionOps v7m_systick_ops = { | ||
154 | + .read_with_attrs = v7m_systick_read, | ||
155 | + .write_with_attrs = v7m_systick_write, | ||
156 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
157 | +}; | ||
158 | + | ||
159 | static void armv7m_instance_init(Object *obj) | ||
161 | { | 160 | { |
162 | int ret; | 161 | ARMv7MState *s = ARMV7M(obj); |
163 | @@ -XXX,XX +XXX,XX @@ int kvm_arm_sync_mpstate_to_qemu(ARMCPU *cpu) | 162 | @@ -XXX,XX +XXX,XX @@ static void armv7m_instance_init(Object *obj) |
164 | return 0; | 163 | object_property_add_alias(obj, "num-irq", |
165 | } | 164 | OBJECT(&s->nvic), "num-irq"); |
166 | 165 | ||
167 | +void kvm_arm_get_virtual_time(CPUState *cs) | 166 | + object_initialize_child(obj, "systick-reg-ns", &s->systick[M_REG_NS], |
168 | +{ | 167 | + TYPE_SYSTICK); |
169 | + ARMCPU *cpu = ARM_CPU(cs); | 168 | + /* |
170 | + struct kvm_one_reg reg = { | 169 | + * We can't initialize the secure systick here, as we don't know |
171 | + .id = KVM_REG_ARM_TIMER_CNT, | 170 | + * yet if we need it. |
172 | + .addr = (uintptr_t)&cpu->kvm_vtime, | 171 | + */ |
173 | + }; | 172 | + |
174 | + int ret; | 173 | for (i = 0; i < ARRAY_SIZE(s->bitband); i++) { |
175 | + | 174 | object_initialize_child(obj, "bitband[*]", &s->bitband[i], |
176 | + if (cpu->kvm_vtime_dirty) { | 175 | TYPE_BITBAND); |
176 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) | ||
177 | memory_region_add_subregion(&s->container, 0xe0000000, | ||
178 | sysbus_mmio_get_region(sbd, 0)); | ||
179 | |||
180 | + /* Create and map the systick devices */ | ||
181 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), errp)) { | ||
177 | + return; | 182 | + return; |
178 | + } | 183 | + } |
179 | + | 184 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), 0, |
180 | + ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, ®); | 185 | + qdev_get_gpio_in_named(DEVICE(&s->nvic), |
181 | + if (ret) { | 186 | + "systick-trigger", M_REG_NS)); |
182 | + error_report("Failed to get KVM_REG_ARM_TIMER_CNT"); | 187 | + |
183 | + abort(); | 188 | + if (arm_feature(&s->cpu->env, ARM_FEATURE_M_SECURITY)) { |
184 | + } | 189 | + /* |
185 | + | 190 | + * We couldn't init the secure systick device in instance_init |
186 | + cpu->kvm_vtime_dirty = true; | 191 | + * as we didn't know then if the CPU had the security extensions; |
187 | +} | 192 | + * so we have to do it here. |
188 | + | 193 | + */ |
189 | +void kvm_arm_put_virtual_time(CPUState *cs) | 194 | + object_initialize_child(OBJECT(dev), "systick-reg-s", |
190 | +{ | 195 | + &s->systick[M_REG_S], TYPE_SYSTICK); |
191 | + ARMCPU *cpu = ARM_CPU(cs); | 196 | + |
192 | + struct kvm_one_reg reg = { | 197 | + if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_S]), errp)) { |
193 | + .id = KVM_REG_ARM_TIMER_CNT, | 198 | + return; |
194 | + .addr = (uintptr_t)&cpu->kvm_vtime, | ||
195 | + }; | ||
196 | + int ret; | ||
197 | + | ||
198 | + if (!cpu->kvm_vtime_dirty) { | ||
199 | + return; | ||
200 | + } | ||
201 | + | ||
202 | + ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, ®); | ||
203 | + if (ret) { | ||
204 | + error_report("Failed to set KVM_REG_ARM_TIMER_CNT"); | ||
205 | + abort(); | ||
206 | + } | ||
207 | + | ||
208 | + cpu->kvm_vtime_dirty = false; | ||
209 | +} | ||
210 | + | ||
211 | int kvm_put_vcpu_events(ARMCPU *cpu) | ||
212 | { | ||
213 | CPUARMState *env = &cpu->env; | ||
214 | @@ -XXX,XX +XXX,XX @@ MemTxAttrs kvm_arch_post_run(CPUState *cs, struct kvm_run *run) | ||
215 | return MEMTXATTRS_UNSPECIFIED; | ||
216 | } | ||
217 | |||
218 | +void kvm_arm_vm_state_change(void *opaque, int running, RunState state) | ||
219 | +{ | ||
220 | + CPUState *cs = opaque; | ||
221 | + ARMCPU *cpu = ARM_CPU(cs); | ||
222 | + | ||
223 | + if (running) { | ||
224 | + if (cpu->kvm_adjvtime) { | ||
225 | + kvm_arm_put_virtual_time(cs); | ||
226 | + } | 199 | + } |
227 | + } else { | 200 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->systick[M_REG_S]), 0, |
228 | + if (cpu->kvm_adjvtime) { | 201 | + qdev_get_gpio_in_named(DEVICE(&s->nvic), |
229 | + kvm_arm_get_virtual_time(cs); | 202 | + "systick-trigger", M_REG_S)); |
230 | + } | 203 | + } |
231 | + } | 204 | + |
232 | +} | 205 | + memory_region_init_io(&s->systickmem, OBJECT(s), |
233 | 206 | + &v7m_systick_ops, s, | |
234 | int kvm_arch_handle_exit(CPUState *cs, struct kvm_run *run) | 207 | + "v7m_systick", 0xe0); |
235 | { | 208 | + |
236 | diff --git a/target/arm/kvm32.c b/target/arm/kvm32.c | 209 | + memory_region_add_subregion_overlap(&s->container, 0xe000e010, |
210 | + &s->systickmem, 1); | ||
211 | + if (arm_feature(&s->cpu->env, ARM_FEATURE_V8)) { | ||
212 | + memory_region_init_io(&s->systick_ns_mem, OBJECT(s), | ||
213 | + &v7m_sysreg_ns_ops, &s->systickmem, | ||
214 | + "v7m_systick_ns", 0xe0); | ||
215 | + memory_region_add_subregion_overlap(&s->container, 0xe002e010, | ||
216 | + &s->systick_ns_mem, 1); | ||
217 | + } | ||
218 | + | ||
219 | /* If the CPU has RAS support, create the RAS register block */ | ||
220 | if (cpu_isar_feature(aa32_ras, s->cpu)) { | ||
221 | object_initialize_child(OBJECT(dev), "armv7m-ras", | ||
222 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | ||
237 | index XXXXXXX..XXXXXXX 100644 | 223 | index XXXXXXX..XXXXXXX 100644 |
238 | --- a/target/arm/kvm32.c | 224 | --- a/hw/intc/armv7m_nvic.c |
239 | +++ b/target/arm/kvm32.c | 225 | +++ b/hw/intc/armv7m_nvic.c |
240 | @@ -XXX,XX +XXX,XX @@ | 226 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvic_sysreg_ns_ops = { |
241 | #include "qemu-common.h" | 227 | .endianness = DEVICE_NATIVE_ENDIAN, |
242 | #include "cpu.h" | 228 | }; |
243 | #include "qemu/timer.h" | 229 | |
244 | +#include "sysemu/runstate.h" | 230 | -static MemTxResult nvic_systick_write(void *opaque, hwaddr addr, |
245 | #include "sysemu/kvm.h" | 231 | - uint64_t value, unsigned size, |
246 | #include "kvm_arm.h" | 232 | - MemTxAttrs attrs) |
247 | #include "internals.h" | 233 | -{ |
248 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) | 234 | - NVICState *s = opaque; |
249 | return -EINVAL; | 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); | ||
250 | } | 316 | } |
251 | 317 | ||
252 | + qemu_add_vm_change_state_handler(kvm_arm_vm_state_change, cs); | 318 | sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->container); |
253 | + | 319 | @@ -XXX,XX +XXX,XX @@ static void armv7m_nvic_instance_init(Object *obj) |
254 | /* Determine init features for this CPU */ | 320 | NVICState *nvic = NVIC(obj); |
255 | memset(cpu->kvm_init_features, 0, sizeof(cpu->kvm_init_features)); | 321 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); |
256 | if (cpu->start_powered_off) { | 322 | |
257 | diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c | 323 | - object_initialize_child(obj, "systick-reg-ns", &nvic->systick[M_REG_NS], |
258 | index XXXXXXX..XXXXXXX 100644 | 324 | - TYPE_SYSTICK); |
259 | --- a/target/arm/kvm64.c | 325 | - /* We can't initialize the secure systick here, as we don't know |
260 | +++ b/target/arm/kvm64.c | 326 | - * yet if we need it. |
261 | @@ -XXX,XX +XXX,XX @@ | 327 | - */ |
262 | #include "qemu/host-utils.h" | 328 | - |
263 | #include "qemu/main-loop.h" | 329 | sysbus_init_irq(sbd, &nvic->excpout); |
264 | #include "exec/gdbstub.h" | 330 | qdev_init_gpio_out_named(dev, &nvic->sysresetreq, "SYSRESETREQ", 1); |
265 | +#include "sysemu/runstate.h" | 331 | qdev_init_gpio_in_named(dev, nvic_systick_trigger, "systick-trigger", |
266 | #include "sysemu/kvm.h" | ||
267 | #include "sysemu/kvm_int.h" | ||
268 | #include "kvm_arm.h" | ||
269 | @@ -XXX,XX +XXX,XX @@ int kvm_arch_init_vcpu(CPUState *cs) | ||
270 | return -EINVAL; | ||
271 | } | ||
272 | |||
273 | + qemu_add_vm_change_state_handler(kvm_arm_vm_state_change, cs); | ||
274 | + | ||
275 | /* Determine init features for this CPU */ | ||
276 | memset(cpu->kvm_init_features, 0, sizeof(cpu->kvm_init_features)); | ||
277 | if (cpu->start_powered_off) { | ||
278 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
279 | index XXXXXXX..XXXXXXX 100644 | ||
280 | --- a/target/arm/machine.c | ||
281 | +++ b/target/arm/machine.c | ||
282 | @@ -XXX,XX +XXX,XX @@ static int cpu_pre_save(void *opaque) | ||
283 | /* This should never fail */ | ||
284 | abort(); | ||
285 | } | ||
286 | + | ||
287 | + /* | ||
288 | + * kvm_arm_cpu_pre_save() must be called after | ||
289 | + * write_kvmstate_to_list() | ||
290 | + */ | ||
291 | + kvm_arm_cpu_pre_save(cpu); | ||
292 | } else { | ||
293 | if (!write_cpustate_to_list(cpu, false)) { | ||
294 | /* This should never fail. */ | ||
295 | @@ -XXX,XX +XXX,XX @@ static int cpu_post_load(void *opaque, int version_id) | ||
296 | * we're using it. | ||
297 | */ | ||
298 | write_list_to_cpustate(cpu); | ||
299 | + kvm_arm_cpu_post_load(cpu); | ||
300 | } else { | ||
301 | if (!write_list_to_cpustate(cpu)) { | ||
302 | return -1; | ||
303 | -- | 332 | -- |
304 | 2.20.1 | 333 | 2.20.1 |
305 | 334 | ||
306 | 335 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | Instead of having the NVIC device provide a single sysbus memory |
---|---|---|---|
2 | region covering the whole of the "System PPB" space, which implements | ||
3 | the default behaviour for unimplemented ranges and provides the NS | ||
4 | alias window to the sysregs as well as the main sysreg MR, move this | ||
5 | handling to the container armv7m device. The NVIC now provides a | ||
6 | single memory region which just implements the system registers. | ||
7 | This consolidates all the handling of "map various devices in the | ||
8 | PPB" into the armv7m container where it belongs. | ||
2 | 9 | ||
3 | This commit make use of the resettable API to reset the device being | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | hotplugged when it is realized. Also it ensures it is put in a reset | 11 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> |
5 | state coherent with the parent it is plugged into. | 12 | Reviewed-by: Luc Michel <luc@lmichel.fr> |
13 | Message-id: 20210812093356.1946-4-peter.maydell@linaro.org | ||
14 | --- | ||
15 | include/hw/arm/armv7m.h | 4 + | ||
16 | include/hw/intc/armv7m_nvic.h | 3 - | ||
17 | hw/arm/armv7m.c | 100 ++++++++++++++++++++++- | ||
18 | hw/intc/armv7m_nvic.c | 145 +--------------------------------- | ||
19 | 4 files changed, 107 insertions(+), 145 deletions(-) | ||
6 | 20 | ||
7 | Note that there is a difference in the reset. Instead of resetting | 21 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h |
8 | only the hotplugged device, we reset also its subtree (switch to | ||
9 | resettable API). This is not expected to be a problem because | ||
10 | sub-buses are just realized too. If a hotplugged device has any | ||
11 | sub-buses it is logical to reset them too at this point. | ||
12 | |||
13 | The recently added should_be_hidden and PCI's partially_hotplugged | ||
14 | mechanisms do not interfere with realize operation: | ||
15 | + In the should_be_hidden use case, device creation is | ||
16 | delayed. | ||
17 | + The partially_hotplugged mechanism prevents a device to be | ||
18 | unplugged and unrealized from qdev POV and unrealized. | ||
19 | |||
20 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
21 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
22 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
23 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
24 | Message-id: 20200123132823.1117486-8-damien.hedde@greensocs.com | ||
25 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
26 | --- | ||
27 | include/hw/resettable.h | 11 +++++++++++ | ||
28 | hw/core/qdev.c | 15 ++++++++++++++- | ||
29 | 2 files changed, 25 insertions(+), 1 deletion(-) | ||
30 | |||
31 | diff --git a/include/hw/resettable.h b/include/hw/resettable.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
33 | --- a/include/hw/resettable.h | 23 | --- a/include/hw/arm/armv7m.h |
34 | +++ b/include/hw/resettable.h | 24 | +++ b/include/hw/arm/armv7m.h |
35 | @@ -XXX,XX +XXX,XX @@ struct ResettableState { | 25 | @@ -XXX,XX +XXX,XX @@ struct ARMv7MState { |
36 | bool exit_phase_in_progress; | 26 | * NS systick device if appropriate. |
27 | */ | ||
28 | MemoryRegion systick_ns_mem; | ||
29 | + /* Ditto, for the sysregs region provided by the NVIC */ | ||
30 | + MemoryRegion sysreg_ns_mem; | ||
31 | + /* MR providing default PPB behaviour */ | ||
32 | + MemoryRegion defaultmem; | ||
33 | |||
34 | /* Properties */ | ||
35 | char *cpu_type; | ||
36 | diff --git a/include/hw/intc/armv7m_nvic.h b/include/hw/intc/armv7m_nvic.h | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/include/hw/intc/armv7m_nvic.h | ||
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, | ||
37 | }; | 64 | }; |
38 | 65 | ||
39 | +/** | 66 | +/* |
40 | + * resettable_state_clear: | 67 | + * Unassigned portions of the PPB space are RAZ/WI for privileged |
41 | + * Clear the state. It puts the state to the initial (zeroed) state required | 68 | + * accesses, and fault for non-privileged accesses. |
42 | + * to reuse an object. Typically used in realize step of base classes | ||
43 | + * implementing the interface. | ||
44 | + */ | 69 | + */ |
45 | +static inline void resettable_state_clear(ResettableState *state) | 70 | +static MemTxResult ppb_default_read(void *opaque, hwaddr addr, |
71 | + uint64_t *data, unsigned size, | ||
72 | + MemTxAttrs attrs) | ||
46 | +{ | 73 | +{ |
47 | + memset(state, 0, sizeof(ResettableState)); | 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; | ||
48 | +} | 81 | +} |
49 | + | 82 | + |
50 | /** | 83 | +static MemTxResult ppb_default_write(void *opaque, hwaddr addr, |
51 | * resettable_reset: | 84 | + uint64_t value, unsigned size, |
52 | * Trigger a reset on an object @obj of type @type. @obj must implement | 85 | + MemTxAttrs attrs) |
53 | diff --git a/hw/core/qdev.c b/hw/core/qdev.c | 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)) { | ||
181 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | ||
54 | index XXXXXXX..XXXXXXX 100644 | 182 | index XXXXXXX..XXXXXXX 100644 |
55 | --- a/hw/core/qdev.c | 183 | --- a/hw/intc/armv7m_nvic.c |
56 | +++ b/hw/core/qdev.c | 184 | +++ b/hw/intc/armv7m_nvic.c |
57 | @@ -XXX,XX +XXX,XX @@ static void device_set_realized(Object *obj, bool value, Error **errp) | 185 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps nvic_sysreg_ops = { |
58 | } | 186 | .endianness = DEVICE_NATIVE_ENDIAN, |
59 | } | 187 | }; |
60 | 188 | ||
61 | + /* | 189 | -static MemTxResult nvic_sysreg_ns_write(void *opaque, hwaddr addr, |
62 | + * Clear the reset state, in case the object was previously unrealized | 190 | - uint64_t value, unsigned size, |
63 | + * with a dirty state. | 191 | - MemTxAttrs attrs) |
64 | + */ | 192 | -{ |
65 | + resettable_state_clear(&dev->reset); | 193 | - MemoryRegion *mr = opaque; |
66 | + | 194 | - |
67 | QLIST_FOREACH(bus, &dev->child_bus, sibling) { | 195 | - if (attrs.secure) { |
68 | object_property_set_bool(OBJECT(bus), true, "realized", | 196 | - /* S accesses to the alias act like NS accesses to the real region */ |
69 | &local_err); | 197 | - attrs.secure = 0; |
70 | @@ -XXX,XX +XXX,XX @@ static void device_set_realized(Object *obj, bool value, Error **errp) | 198 | - return memory_region_dispatch_write(mr, addr, value, |
71 | } | 199 | - size_memop(size) | MO_TE, attrs); |
72 | } | 200 | - } else { |
73 | if (dev->hotplugged) { | 201 | - /* NS attrs are RAZ/WI for privileged, and BusFault for user */ |
74 | - device_legacy_reset(dev); | 202 | - if (attrs.user) { |
75 | + /* | 203 | - return MEMTX_ERROR; |
76 | + * Reset the device, as well as its subtree which, at this point, | 204 | - } |
77 | + * should be realized too. | 205 | - return MEMTX_OK; |
78 | + */ | 206 | - } |
79 | + resettable_assert_reset(OBJECT(dev), RESET_TYPE_COLD); | 207 | -} |
80 | + resettable_change_parent(OBJECT(dev), OBJECT(dev->parent_bus), | 208 | - |
81 | + NULL); | 209 | -static MemTxResult nvic_sysreg_ns_read(void *opaque, hwaddr addr, |
82 | + resettable_release_reset(OBJECT(dev), RESET_TYPE_COLD); | 210 | - uint64_t *data, unsigned size, |
83 | } | 211 | - MemTxAttrs attrs) |
84 | dev->pending_deleted_event = false; | 212 | -{ |
85 | 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); | ||
344 | } | ||
345 | |||
346 | static void armv7m_nvic_instance_init(Object *obj) | ||
86 | -- | 347 | -- |
87 | 2.20.1 | 348 | 2.20.1 |
88 | 349 | ||
89 | 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 |
New patch | |||
---|---|---|---|
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) | ||
1 | 5 | ||
6 | Our implementation currently hardwires the external reference clock | ||
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). | ||
11 | |||
12 | As the first step in converting this to use the Clock infrastructure, | ||
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. | ||
18 | |||
19 | This is a migration compat break for all M-profile boards, because of | ||
20 | the addition of the new clock objects to the vmstate struct. | ||
21 | |||
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 | ||
26 | --- | ||
27 | include/hw/timer/armv7m_systick.h | 7 +++++++ | ||
28 | hw/timer/armv7m_systick.c | 10 ++++++++-- | ||
29 | 2 files changed, 15 insertions(+), 2 deletions(-) | ||
30 | |||
31 | diff --git a/include/hw/timer/armv7m_systick.h b/include/hw/timer/armv7m_systick.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/include/hw/timer/armv7m_systick.h | ||
34 | +++ b/include/hw/timer/armv7m_systick.h | ||
35 | @@ -XXX,XX +XXX,XX @@ | ||
36 | #include "hw/sysbus.h" | ||
37 | #include "qom/object.h" | ||
38 | #include "hw/ptimer.h" | ||
39 | +#include "hw/clock.h" | ||
40 | |||
41 | #define TYPE_SYSTICK "armv7m_systick" | ||
42 | |||
43 | @@ -XXX,XX +XXX,XX @@ OBJECT_DECLARE_SIMPLE_TYPE(SysTickState, SYSTICK) | ||
44 | * + sysbus MMIO region 0 is the register interface (covering | ||
45 | * the registers which are mapped at address 0xE000E010) | ||
46 | * + sysbus IRQ 0 is the interrupt line to the NVIC | ||
47 | + * + Clock input "refclk" is the external reference clock | ||
48 | + * (used when SYST_CSR.CLKSOURCE == 0) | ||
49 | + * + Clock input "cpuclk" is the main CPU clock | ||
50 | + * (used when SYST_CSR.CLKSOURCE == 1) | ||
51 | */ | ||
52 | |||
53 | struct SysTickState { | ||
54 | @@ -XXX,XX +XXX,XX @@ struct SysTickState { | ||
55 | ptimer_state *ptimer; | ||
56 | MemoryRegion iomem; | ||
57 | qemu_irq irq; | ||
58 | + Clock *refclk; | ||
59 | + Clock *cpuclk; | ||
60 | }; | ||
61 | |||
62 | /* | ||
63 | diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/hw/timer/armv7m_systick.c | ||
66 | +++ b/hw/timer/armv7m_systick.c | ||
67 | @@ -XXX,XX +XXX,XX @@ | ||
68 | #include "migration/vmstate.h" | ||
69 | #include "hw/irq.h" | ||
70 | #include "hw/sysbus.h" | ||
71 | +#include "hw/qdev-clock.h" | ||
72 | #include "qemu/timer.h" | ||
73 | #include "qemu/log.h" | ||
74 | #include "qemu/module.h" | ||
75 | @@ -XXX,XX +XXX,XX @@ static void systick_instance_init(Object *obj) | ||
76 | memory_region_init_io(&s->iomem, obj, &systick_ops, s, "systick", 0xe0); | ||
77 | sysbus_init_mmio(sbd, &s->iomem); | ||
78 | sysbus_init_irq(sbd, &s->irq); | ||
79 | + | ||
80 | + s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", NULL, NULL, 0); | ||
81 | + s->cpuclk = qdev_init_clock_in(DEVICE(obj), "cpuclk", NULL, NULL, 0); | ||
82 | } | ||
83 | |||
84 | static void systick_realize(DeviceState *dev, Error **errp) | ||
85 | @@ -XXX,XX +XXX,XX @@ static void systick_realize(DeviceState *dev, Error **errp) | ||
86 | |||
87 | static const VMStateDescription vmstate_systick = { | ||
88 | .name = "armv7m_systick", | ||
89 | - .version_id = 2, | ||
90 | - .minimum_version_id = 2, | ||
91 | + .version_id = 3, | ||
92 | + .minimum_version_id = 3, | ||
93 | .fields = (VMStateField[]) { | ||
94 | + VMSTATE_CLOCK(refclk, SysTickState), | ||
95 | + VMSTATE_CLOCK(cpuclk, SysTickState), | ||
96 | VMSTATE_UINT32(control, SysTickState), | ||
97 | VMSTATE_INT64(tick, SysTickState), | ||
98 | VMSTATE_PTIMER(ptimer, SysTickState), | ||
99 | -- | ||
100 | 2.20.1 | ||
101 | |||
102 | diff view generated by jsdifflib |
1 | From: Andrew Jeffery <andrew@aj.id.au> | 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 | The AST2600 includes a second cut-down version of the SD/MMC controller | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | found in the AST2500, named the eMMC controller. It's cut down in the | 6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> |
5 | sense that it only supports one slot rather than two, but it brings the | 7 | Reviewed-by: Luc Michel <luc@lmichel.fr> |
6 | total number of slots supported by the AST2600 to three. | 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(+) | ||
7 | 13 | ||
8 | The existing code assumed that the SD controller always provided two | 14 | diff --git a/include/hw/arm/armv7m.h b/include/hw/arm/armv7m.h |
9 | slots. Rework the SDHCI object to expose the number of slots as a | ||
10 | property to be set by the SoC configuration. | ||
11 | |||
12 | Signed-off-by: Andrew Jeffery <andrew@aj.id.au> | ||
13 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
14 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | ||
15 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
16 | Message-id: 20200114103433.30534-2-clg@kaod.org | ||
17 | [PMM: fixed up to use device_class_set_props()] | ||
18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
19 | --- | ||
20 | include/hw/sd/aspeed_sdhci.h | 1 + | ||
21 | hw/arm/aspeed.c | 2 +- | ||
22 | hw/arm/aspeed_ast2600.c | 2 ++ | ||
23 | hw/arm/aspeed_soc.c | 2 ++ | ||
24 | hw/sd/aspeed_sdhci.c | 11 +++++++++-- | ||
25 | 5 files changed, 15 insertions(+), 3 deletions(-) | ||
26 | |||
27 | diff --git a/include/hw/sd/aspeed_sdhci.h b/include/hw/sd/aspeed_sdhci.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/include/hw/sd/aspeed_sdhci.h | 16 | --- a/include/hw/arm/armv7m.h |
30 | +++ b/include/hw/sd/aspeed_sdhci.h | 17 | +++ b/include/hw/arm/armv7m.h |
31 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSDHCIState { | 18 | @@ -XXX,XX +XXX,XX @@ |
32 | SysBusDevice parent; | 19 | #include "hw/misc/armv7m_ras.h" |
33 | 20 | #include "target/arm/idau.h" | |
34 | SDHCIState slots[ASPEED_SDHCI_NUM_SLOTS]; | 21 | #include "qom/object.h" |
35 | + uint8_t num_slots; | 22 | +#include "hw/clock.h" |
36 | 23 | ||
37 | MemoryRegion iomem; | 24 | #define TYPE_BITBAND "ARM-bitband-memory" |
38 | qemu_irq irq; | 25 | OBJECT_DECLARE_SIMPLE_TYPE(BitBandState, BITBAND) |
39 | diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c | 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 | ||
40 | index XXXXXXX..XXXXXXX 100644 | 46 | index XXXXXXX..XXXXXXX 100644 |
41 | --- a/hw/arm/aspeed.c | 47 | --- a/hw/arm/armv7m.c |
42 | +++ b/hw/arm/aspeed.c | 48 | +++ b/hw/arm/armv7m.c |
43 | @@ -XXX,XX +XXX,XX @@ static void aspeed_machine_init(MachineState *machine) | 49 | @@ -XXX,XX +XXX,XX @@ |
44 | amc->i2c_init(bmc); | 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); | ||
45 | } | 67 | } |
46 | |||
47 | - for (i = 0; i < ARRAY_SIZE(bmc->soc.sdhci.slots); i++) { | ||
48 | + for (i = 0; i < bmc->soc.sdhci.num_slots; i++) { | ||
49 | SDHCIState *sdhci = &bmc->soc.sdhci.slots[i]; | ||
50 | DriveInfo *dinfo = drive_get_next(IF_SD); | ||
51 | BlockBackend *blk; | ||
52 | diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/hw/arm/aspeed_ast2600.c | ||
55 | +++ b/hw/arm/aspeed_ast2600.c | ||
56 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_init(Object *obj) | ||
57 | sysbus_init_child_obj(obj, "sdc", OBJECT(&s->sdhci), sizeof(s->sdhci), | ||
58 | TYPE_ASPEED_SDHCI); | ||
59 | |||
60 | + object_property_set_int(OBJECT(&s->sdhci), 2, "num-slots", &error_abort); | ||
61 | + | 68 | + |
62 | /* Init sd card slot class here so that they're under the correct parent */ | 69 | + s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", NULL, NULL, 0); |
63 | for (i = 0; i < ASPEED_SDHCI_NUM_SLOTS; ++i) { | 70 | + s->cpuclk = qdev_init_clock_in(DEVICE(obj), "cpuclk", NULL, NULL, 0); |
64 | sysbus_init_child_obj(obj, "sdhci[*]", OBJECT(&s->sdhci.slots[i]), | 71 | } |
65 | diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c | 72 | |
66 | index XXXXXXX..XXXXXXX 100644 | 73 | static void armv7m_realize(DeviceState *dev, Error **errp) |
67 | --- a/hw/arm/aspeed_soc.c | 74 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) |
68 | +++ b/hw/arm/aspeed_soc.c | 75 | } |
69 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_init(Object *obj) | 76 | |
70 | sysbus_init_child_obj(obj, "sdc", OBJECT(&s->sdhci), sizeof(s->sdhci), | 77 | /* Create and map the systick devices */ |
71 | TYPE_ASPEED_SDHCI); | 78 | + qdev_connect_clock_in(DEVICE(&s->systick[M_REG_NS]), "refclk", s->refclk); |
72 | 79 | + qdev_connect_clock_in(DEVICE(&s->systick[M_REG_NS]), "cpuclk", s->cpuclk); | |
73 | + object_property_set_int(OBJECT(&s->sdhci), 2, "num-slots", &error_abort); | 80 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_NS]), errp)) { |
74 | + | 81 | return; |
75 | /* Init sd card slot class here so that they're under the correct parent */ | 82 | } |
76 | for (i = 0; i < ASPEED_SDHCI_NUM_SLOTS; ++i) { | 83 | @@ -XXX,XX +XXX,XX @@ static void armv7m_realize(DeviceState *dev, Error **errp) |
77 | sysbus_init_child_obj(obj, "sdhci[*]", OBJECT(&s->sdhci.slots[i]), | 84 | */ |
78 | diff --git a/hw/sd/aspeed_sdhci.c b/hw/sd/aspeed_sdhci.c | 85 | object_initialize_child(OBJECT(dev), "systick-reg-s", |
79 | index XXXXXXX..XXXXXXX 100644 | 86 | &s->systick[M_REG_S], TYPE_SYSTICK); |
80 | --- a/hw/sd/aspeed_sdhci.c | 87 | + qdev_connect_clock_in(DEVICE(&s->systick[M_REG_S]), "refclk", |
81 | +++ b/hw/sd/aspeed_sdhci.c | 88 | + s->refclk); |
82 | @@ -XXX,XX +XXX,XX @@ | 89 | + qdev_connect_clock_in(DEVICE(&s->systick[M_REG_S]), "cpuclk", |
83 | #include "qapi/error.h" | 90 | + s->cpuclk); |
84 | #include "hw/irq.h" | 91 | |
85 | #include "migration/vmstate.h" | 92 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->systick[M_REG_S]), errp)) { |
86 | +#include "hw/qdev-properties.h" | 93 | return; |
87 | 94 | @@ -XXX,XX +XXX,XX @@ static Property armv7m_properties[] = { | |
88 | #define ASPEED_SDHCI_INFO 0x00 | 95 | DEFINE_PROP_END_OF_LIST(), |
89 | #define ASPEED_SDHCI_INFO_RESET 0x00030000 | ||
90 | @@ -XXX,XX +XXX,XX @@ static void aspeed_sdhci_realize(DeviceState *dev, Error **errp) | ||
91 | |||
92 | /* Create input irqs for the slots */ | ||
93 | qdev_init_gpio_in_named_with_opaque(DEVICE(sbd), aspeed_sdhci_set_irq, | ||
94 | - sdhci, NULL, ASPEED_SDHCI_NUM_SLOTS); | ||
95 | + sdhci, NULL, sdhci->num_slots); | ||
96 | |||
97 | sysbus_init_irq(sbd, &sdhci->irq); | ||
98 | memory_region_init_io(&sdhci->iomem, OBJECT(sdhci), &aspeed_sdhci_ops, | ||
99 | sdhci, TYPE_ASPEED_SDHCI, 0x1000); | ||
100 | sysbus_init_mmio(sbd, &sdhci->iomem); | ||
101 | |||
102 | - for (int i = 0; i < ASPEED_SDHCI_NUM_SLOTS; ++i) { | ||
103 | + for (int i = 0; i < sdhci->num_slots; ++i) { | ||
104 | Object *sdhci_slot = OBJECT(&sdhci->slots[i]); | ||
105 | SysBusDevice *sbd_slot = SYS_BUS_DEVICE(&sdhci->slots[i]); | ||
106 | |||
107 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_aspeed_sdhci = { | ||
108 | }, | ||
109 | }; | 96 | }; |
110 | 97 | ||
111 | +static Property aspeed_sdhci_properties[] = { | 98 | +static const VMStateDescription vmstate_armv7m = { |
112 | + DEFINE_PROP_UINT8("num-slots", AspeedSDHCIState, num_slots, 0), | 99 | + .name = "armv7m", |
113 | + DEFINE_PROP_END_OF_LIST(), | 100 | + .version_id = 1, |
101 | + .minimum_version_id = 1, | ||
102 | + .fields = (VMStateField[]) { | ||
103 | + VMSTATE_CLOCK(refclk, SysTickState), | ||
104 | + VMSTATE_CLOCK(cpuclk, SysTickState), | ||
105 | + VMSTATE_END_OF_LIST() | ||
106 | + } | ||
114 | +}; | 107 | +}; |
115 | + | 108 | + |
116 | static void aspeed_sdhci_class_init(ObjectClass *classp, void *data) | 109 | static void armv7m_class_init(ObjectClass *klass, void *data) |
117 | { | 110 | { |
118 | DeviceClass *dc = DEVICE_CLASS(classp); | 111 | DeviceClass *dc = DEVICE_CLASS(klass); |
119 | @@ -XXX,XX +XXX,XX @@ static void aspeed_sdhci_class_init(ObjectClass *classp, void *data) | 112 | |
120 | dc->realize = aspeed_sdhci_realize; | 113 | dc->realize = armv7m_realize; |
121 | dc->reset = aspeed_sdhci_reset; | 114 | + dc->vmsd = &vmstate_armv7m; |
122 | dc->vmsd = &vmstate_aspeed_sdhci; | 115 | device_class_set_props(dc, armv7m_properties); |
123 | + device_class_set_props(dc, aspeed_sdhci_properties); | ||
124 | } | 116 | } |
125 | 117 | ||
126 | static TypeInfo aspeed_sdhci_info = { | ||
127 | -- | 118 | -- |
128 | 2.20.1 | 119 | 2.20.1 |
129 | 120 | ||
130 | 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: Damien Hedde <damien.hedde@greensocs.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 a function resettable_change_parent() to do the required | 3 | instance divided by 8 to produce a slower clock to feed to a |
4 | plumbing when changing the parent a of Resettable object. | 4 | particular device. |
5 | 5 | ||
6 | We need to make sure that the reset state of the object remains | 6 | Currently we provide no convenient mechanism for modelling this. You |
7 | coherent with the reset state of the new parent. | 7 | can implement it by having an input Clock and an output Clock, and |
8 | 8 | manually setting the period of the output clock in the period-changed | |
9 | We make the 2 following hypothesis: | 9 | callback of the input clock, but that's quite clunky. |
10 | + when an object is put in a parent under reset, the object goes in | 10 | |
11 | reset. | 11 | This patch adds support in the Clock objects themselves for setting a |
12 | + when an object is removed from a parent under reset, the object | 12 | multiplier or divider. The effect of setting this on a clock is that |
13 | leaves reset. | 13 | when the clock's period is changed, all the children of the clock are |
14 | 14 | set to period * multiplier / divider, rather than being set to the | |
15 | The added function avoids any glitch if both old and new parent are | 15 | same period as the parent clock. |
16 | already in reset. | 16 | |
17 | |||
18 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
19 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
20 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
21 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
22 | Message-id: 20200123132823.1117486-6-damien.hedde@greensocs.com | ||
23 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 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> | ||
20 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
21 | Reviewed-by: Luc Michel <luc@lmichel.fr> | ||
22 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> | ||
23 | Message-id: 20210812093356.1946-10-peter.maydell@linaro.org | ||
24 | --- | 24 | --- |
25 | include/hw/resettable.h | 16 +++++++++++ | 25 | docs/devel/clocks.rst | 23 +++++++++++++++++++++++ |
26 | hw/core/resettable.c | 62 +++++++++++++++++++++++++++++++++++++++-- | 26 | include/hw/clock.h | 29 +++++++++++++++++++++++++++++ |
27 | hw/core/clock-vmstate.c | 40 +++++++++++++++++++++++++++++++++++++++- | ||
28 | hw/core/clock.c | 31 +++++++++++++++++++++++++++---- | ||
27 | hw/core/trace-events | 1 + | 29 | hw/core/trace-events | 1 + |
28 | 3 files changed, 77 insertions(+), 2 deletions(-) | 30 | 5 files changed, 119 insertions(+), 5 deletions(-) |
29 | 31 | ||
30 | diff --git a/include/hw/resettable.h b/include/hw/resettable.h | 32 | diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst |
31 | index XXXXXXX..XXXXXXX 100644 | 33 | index XXXXXXX..XXXXXXX 100644 |
32 | --- a/include/hw/resettable.h | 34 | --- a/docs/devel/clocks.rst |
33 | +++ b/include/hw/resettable.h | 35 | +++ b/docs/devel/clocks.rst |
34 | @@ -XXX,XX +XXX,XX @@ void resettable_release_reset(Object *obj, ResetType type); | 36 | @@ -XXX,XX +XXX,XX @@ clocks get the new clock period value: *Clock 2*, *Clock 3* and *Clock 4*. |
37 | It is not possible to disconnect a clock or to change the clock connection | ||
38 | after it is connected. | ||
39 | |||
40 | +Clock multiplier and divider settings | ||
41 | +------------------------------------- | ||
42 | + | ||
43 | +By default, when clocks are connected together, the child | ||
44 | +clocks run with the same period as their source (parent) clock. | ||
45 | +The Clock API supports a built-in period multiplier/divider | ||
46 | +mechanism so you can configure a clock to make its children | ||
47 | +run at a different period from its own. If you call the | ||
48 | +``clock_set_mul_div()`` function you can specify the clock's | ||
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) | ||
35 | */ | 82 | */ |
36 | bool resettable_is_in_reset(Object *obj); | 83 | char *clock_display_freq(Clock *clk); |
37 | 84 | ||
38 | +/** | 85 | +/** |
39 | + * resettable_change_parent: | 86 | + * clock_set_mul_div: set multiplier/divider for child clocks |
40 | + * Indicate that the parent of Ressettable @obj is changing from @oldp to @newp. | 87 | + * @clk: clock |
41 | + * All 3 objects must implement resettable interface. @oldp or @newp may be | 88 | + * @multiplier: multiplier value |
42 | + * NULL. | 89 | + * @divider: divider value |
43 | + * | 90 | + * |
44 | + * This function will adapt the reset state of @obj so that it is coherent | 91 | + * By default, a Clock's children will all run with the same period |
45 | + * with the reset state of @newp. It may trigger @resettable_assert_reset() | 92 | + * as their parent. This function allows you to adjust the multiplier |
46 | + * or @resettable_release_reset(). It will do such things only if the reset | 93 | + * and divider used to derive the child clock frequency. |
47 | + * state of @newp and @oldp are different. | 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. | ||
48 | + * | 98 | + * |
49 | + * When using this function during reset, it must only be called during | 99 | + * Setting the multiplier to 0 will stop the child clocks. |
50 | + * a hold phase method. Calling this during enter or exit phase is an error. | 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. | ||
51 | + */ | 107 | + */ |
52 | +void resettable_change_parent(Object *obj, Object *newp, Object *oldp); | 108 | +void clock_set_mul_div(Clock *clk, uint32_t multiplier, uint32_t divider); |
53 | + | 109 | + |
54 | /** | 110 | #endif /* QEMU_HW_CLOCK_H */ |
55 | * resettable_class_set_parent_phases: | 111 | diff --git a/hw/core/clock-vmstate.c b/hw/core/clock-vmstate.c |
56 | * | 112 | index XXXXXXX..XXXXXXX 100644 |
57 | diff --git a/hw/core/resettable.c b/hw/core/resettable.c | 113 | --- a/hw/core/clock-vmstate.c |
58 | index XXXXXXX..XXXXXXX 100644 | 114 | +++ b/hw/core/clock-vmstate.c |
59 | --- a/hw/core/resettable.c | 115 | @@ -XXX,XX +XXX,XX @@ |
60 | +++ b/hw/core/resettable.c | 116 | #include "migration/vmstate.h" |
61 | @@ -XXX,XX +XXX,XX @@ static void resettable_phase_exit(Object *obj, void *opaque, ResetType type); | 117 | #include "hw/clock.h" |
62 | * enter_phase_in_progress: | 118 | |
63 | * True if we are currently in reset enter phase. | 119 | +static bool muldiv_needed(void *opaque) |
64 | * | 120 | +{ |
65 | - * Note: This flag is only used to guarantee (using asserts) that the reset | 121 | + Clock *clk = opaque; |
66 | - * API is used correctly. We can use a global variable because we rely on the | 122 | + |
67 | + * exit_phase_in_progress: | 123 | + return clk->multiplier != 1 || clk->divider != 1; |
68 | + * count the number of exit phase we are in. | 124 | +} |
69 | + * | 125 | + |
70 | + * Note: These flags are only used to guarantee (using asserts) that the reset | 126 | +static int clock_pre_load(void *opaque) |
71 | + * API is used correctly. We can use global variables because we rely on the | 127 | +{ |
72 | * iothread mutex to ensure only one reset operation is in a progress at a | 128 | + Clock *clk = opaque; |
73 | * given time. | 129 | + /* |
74 | */ | 130 | + * The initial out-of-reset settings of the Clock might have been |
75 | static bool enter_phase_in_progress; | 131 | + * configured by the device to be different from what we set |
76 | +static unsigned exit_phase_in_progress; | 132 | + * in clock_initfn(), so we must here set the default values to |
77 | 133 | + * be used if they are not in the inbound migration state. | |
78 | void resettable_reset(Object *obj, ResetType type) | 134 | + */ |
135 | + clk->multiplier = 1; | ||
136 | + clk->divider = 1; | ||
137 | + | ||
138 | + return 0; | ||
139 | +} | ||
140 | + | ||
141 | +const VMStateDescription vmstate_muldiv = { | ||
142 | + .name = "clock/muldiv", | ||
143 | + .version_id = 1, | ||
144 | + .minimum_version_id = 1, | ||
145 | + .needed = muldiv_needed, | ||
146 | + .fields = (VMStateField[]) { | ||
147 | + VMSTATE_UINT32(multiplier, Clock), | ||
148 | + VMSTATE_UINT32(divider, Clock), | ||
149 | + }, | ||
150 | +}; | ||
151 | + | ||
152 | const VMStateDescription vmstate_clock = { | ||
153 | .name = "clock", | ||
154 | .version_id = 0, | ||
155 | .minimum_version_id = 0, | ||
156 | + .pre_load = clock_pre_load, | ||
157 | .fields = (VMStateField[]) { | ||
158 | VMSTATE_UINT64(period, Clock), | ||
159 | VMSTATE_END_OF_LIST() | ||
160 | - } | ||
161 | + }, | ||
162 | + .subsections = (const VMStateDescription*[]) { | ||
163 | + &vmstate_muldiv, | ||
164 | + NULL | ||
165 | + }, | ||
166 | }; | ||
167 | diff --git a/hw/core/clock.c b/hw/core/clock.c | ||
168 | index XXXXXXX..XXXXXXX 100644 | ||
169 | --- a/hw/core/clock.c | ||
170 | +++ b/hw/core/clock.c | ||
171 | @@ -XXX,XX +XXX,XX @@ bool clock_set(Clock *clk, uint64_t period) | ||
172 | return true; | ||
173 | } | ||
174 | |||
175 | +static uint64_t clock_get_child_period(Clock *clk) | ||
176 | +{ | ||
177 | + /* | ||
178 | + * Return the period to be used for child clocks, which is the parent | ||
179 | + * clock period adjusted for for multiplier and divider effects. | ||
180 | + */ | ||
181 | + return muldiv64(clk->period, clk->multiplier, clk->divider); | ||
182 | +} | ||
183 | + | ||
184 | static void clock_call_callback(Clock *clk, ClockEvent event) | ||
79 | { | 185 | { |
80 | @@ -XXX,XX +XXX,XX @@ void resettable_release_reset(Object *obj, ResetType type) | 186 | /* |
81 | trace_resettable_reset_release_begin(obj, type); | 187 | @@ -XXX,XX +XXX,XX @@ static void clock_call_callback(Clock *clk, ClockEvent event) |
82 | assert(!enter_phase_in_progress); | 188 | static void clock_propagate_period(Clock *clk, bool call_callbacks) |
83 | 189 | { | |
84 | + exit_phase_in_progress += 1; | 190 | Clock *child; |
85 | resettable_phase_exit(obj, NULL, type); | 191 | + uint64_t child_period = clock_get_child_period(clk); |
86 | + exit_phase_in_progress -= 1; | 192 | |
87 | 193 | QLIST_FOREACH(child, &clk->children, sibling) { | |
88 | trace_resettable_reset_release_end(obj); | 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)); | ||
89 | } | 218 | } |
90 | @@ -XXX,XX +XXX,XX @@ static void resettable_phase_exit(Object *obj, void *opaque, ResetType type) | 219 | |
91 | trace_resettable_phase_exit_end(obj, obj_typename, s->count); | 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); | ||
92 | } | 238 | } |
93 | 239 | ||
94 | +/* | ||
95 | + * resettable_get_count: | ||
96 | + * Get the count of the Resettable object @obj. Return 0 if @obj is NULL. | ||
97 | + */ | ||
98 | +static unsigned resettable_get_count(Object *obj) | ||
99 | +{ | ||
100 | + if (obj) { | ||
101 | + ResettableClass *rc = RESETTABLE_GET_CLASS(obj); | ||
102 | + return rc->get_state(obj)->count; | ||
103 | + } | ||
104 | + return 0; | ||
105 | +} | ||
106 | + | ||
107 | +void resettable_change_parent(Object *obj, Object *newp, Object *oldp) | ||
108 | +{ | ||
109 | + ResettableClass *rc = RESETTABLE_GET_CLASS(obj); | ||
110 | + ResettableState *s = rc->get_state(obj); | ||
111 | + unsigned newp_count = resettable_get_count(newp); | ||
112 | + unsigned oldp_count = resettable_get_count(oldp); | ||
113 | + | ||
114 | + /* | ||
115 | + * Ensure we do not change parent when in enter or exit phase. | ||
116 | + * During these phases, the reset subtree being updated is partly in reset | ||
117 | + * and partly not in reset (it depends on the actual position in | ||
118 | + * resettable_child_foreach()s). We are not able to tell in which part is a | ||
119 | + * leaving or arriving device. Thus we cannot set the reset count of the | ||
120 | + * moving device to the proper value. | ||
121 | + */ | ||
122 | + assert(!enter_phase_in_progress && !exit_phase_in_progress); | ||
123 | + trace_resettable_change_parent(obj, oldp, oldp_count, newp, newp_count); | ||
124 | + | ||
125 | + /* | ||
126 | + * At most one of the two 'for' loops will be executed below | ||
127 | + * in order to cope with the difference between the two counts. | ||
128 | + */ | ||
129 | + /* if newp is more reset than oldp */ | ||
130 | + for (unsigned i = oldp_count; i < newp_count; i++) { | ||
131 | + resettable_assert_reset(obj, RESET_TYPE_COLD); | ||
132 | + } | ||
133 | + /* | ||
134 | + * if obj is leaving a bus under reset, we need to ensure | ||
135 | + * hold phase is not pending. | ||
136 | + */ | ||
137 | + if (oldp_count && s->hold_phase_pending) { | ||
138 | + resettable_phase_hold(obj, NULL, RESET_TYPE_COLD); | ||
139 | + } | ||
140 | + /* if oldp is more reset than newp */ | ||
141 | + for (unsigned i = newp_count; i < oldp_count; i++) { | ||
142 | + resettable_release_reset(obj, RESET_TYPE_COLD); | ||
143 | + } | ||
144 | +} | ||
145 | + | ||
146 | void resettable_class_set_parent_phases(ResettableClass *rc, | ||
147 | ResettableEnterPhase enter, | ||
148 | ResettableHoldPhase hold, | ||
149 | diff --git a/hw/core/trace-events b/hw/core/trace-events | 240 | diff --git a/hw/core/trace-events b/hw/core/trace-events |
150 | index XXXXXXX..XXXXXXX 100644 | 241 | index XXXXXXX..XXXXXXX 100644 |
151 | --- a/hw/core/trace-events | 242 | --- a/hw/core/trace-events |
152 | +++ b/hw/core/trace-events | 243 | +++ b/hw/core/trace-events |
153 | @@ -XXX,XX +XXX,XX @@ resettable_reset_assert_begin(void *obj, int cold) "obj=%p cold=%d" | 244 | @@ -XXX,XX +XXX,XX @@ clock_disconnect(const char *clk) "'%s'" |
154 | resettable_reset_assert_end(void *obj) "obj=%p" | 245 | clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', %"PRIu64"Hz->%"PRIu64"Hz" |
155 | resettable_reset_release_begin(void *obj, int cold) "obj=%p cold=%d" | 246 | clock_propagate(const char *clk) "'%s'" |
156 | resettable_reset_release_end(void *obj) "obj=%p" | 247 | clock_update(const char *clk, const char *src, uint64_t hz, int cb) "'%s', src='%s', val=%"PRIu64"Hz cb=%d" |
157 | +resettable_change_parent(void *obj, void *o, unsigned oc, void *n, unsigned nc) "obj=%p from=%p(%d) to=%p(%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" |
158 | resettable_phase_enter_begin(void *obj, const char *objtype, unsigned count, int type) "obj=%p(%s) count=%d type=%d" | ||
159 | resettable_phase_enter_exec(void *obj, const char *objtype, int type, int has_method) "obj=%p(%s) type=%d method=%d" | ||
160 | resettable_phase_enter_end(void *obj, const char *objtype, unsigned count) "obj=%p(%s) count=%d" | ||
161 | -- | 249 | -- |
162 | 2.20.1 | 250 | 2.20.1 |
163 | 251 | ||
164 | 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 |
New patch | |||
---|---|---|---|
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. | ||
1 | 4 | ||
5 | Because there is only one board using this SoC, we convert the SoC | ||
6 | and the board together, rather than splitting it into "add clock to | ||
7 | SoC; connect clock in board; add error check in SoC code that clock | ||
8 | is wired up". | ||
9 | |||
10 | When the systick device starts honouring its clock inputs, this will | ||
11 | fix an emulation inaccuracy in the stm32vldiscovery board where the | ||
12 | systick reference clock was running at 1MHz rather than 3MHz. | ||
13 | |||
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 | ||
19 | --- | ||
20 | include/hw/arm/stm32f100_soc.h | 4 ++++ | ||
21 | hw/arm/stm32f100_soc.c | 30 ++++++++++++++++++++++++++++++ | ||
22 | hw/arm/stm32vldiscovery.c | 12 +++++++----- | ||
23 | 3 files changed, 41 insertions(+), 5 deletions(-) | ||
24 | |||
25 | diff --git a/include/hw/arm/stm32f100_soc.h b/include/hw/arm/stm32f100_soc.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/include/hw/arm/stm32f100_soc.h | ||
28 | +++ b/include/hw/arm/stm32f100_soc.h | ||
29 | @@ -XXX,XX +XXX,XX @@ | ||
30 | #include "hw/ssi/stm32f2xx_spi.h" | ||
31 | #include "hw/arm/armv7m.h" | ||
32 | #include "qom/object.h" | ||
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; | ||
44 | }; | ||
45 | |||
46 | #endif | ||
47 | diff --git a/hw/arm/stm32f100_soc.c b/hw/arm/stm32f100_soc.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/hw/arm/stm32f100_soc.c | ||
50 | +++ b/hw/arm/stm32f100_soc.c | ||
51 | @@ -XXX,XX +XXX,XX @@ | ||
52 | #include "exec/address-spaces.h" | ||
53 | #include "hw/arm/stm32f100_soc.h" | ||
54 | #include "hw/qdev-properties.h" | ||
55 | +#include "hw/qdev-clock.h" | ||
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 | } | ||
63 | + | ||
64 | + s->sysclk = qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0); | ||
65 | + s->refclk = qdev_init_clock_in(DEVICE(s), "refclk", NULL, NULL, 0); | ||
66 | } | ||
67 | |||
68 | static void stm32f100_soc_realize(DeviceState *dev_soc, Error **errp) | ||
69 | @@ -XXX,XX +XXX,XX @@ static void stm32f100_soc_realize(DeviceState *dev_soc, Error **errp) | ||
70 | |||
71 | MemoryRegion *system_memory = get_system_memory(); | ||
72 | |||
73 | + /* | ||
74 | + * We use s->refclk internally and only define it with qdev_init_clock_in() | ||
75 | + * so it is correctly parented and not leaked on an init/deinit; it is not | ||
76 | + * intended as an externally exposed clock. | ||
77 | + */ | ||
78 | + if (clock_has_source(s->refclk)) { | ||
79 | + error_setg(errp, "refclk clock must not be wired up by the board code"); | ||
80 | + return; | ||
81 | + } | ||
82 | + | ||
83 | + if (!clock_has_source(s->sysclk)) { | ||
84 | + error_setg(errp, "sysclk clock must be wired up by the board code"); | ||
85 | + return; | ||
86 | + } | ||
87 | + | ||
88 | + /* | ||
89 | + * TODO: ideally we should model the SoC RCC and its ability to | ||
90 | + * change the sysclk frequency and define different sysclk sources. | ||
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 | ||
110 | index XXXXXXX..XXXXXXX 100644 | ||
111 | --- a/hw/arm/stm32vldiscovery.c | ||
112 | +++ b/hw/arm/stm32vldiscovery.c | ||
113 | @@ -XXX,XX +XXX,XX @@ | ||
114 | #include "qapi/error.h" | ||
115 | #include "hw/boards.h" | ||
116 | #include "hw/qdev-properties.h" | ||
117 | +#include "hw/qdev-clock.h" | ||
118 | #include "qemu/error-report.h" | ||
119 | #include "hw/arm/stm32f100_soc.h" | ||
120 | #include "hw/arm/boot.h" | ||
121 | @@ -XXX,XX +XXX,XX @@ | ||
122 | static void stm32vldiscovery_init(MachineState *machine) | ||
123 | { | ||
124 | DeviceState *dev; | ||
125 | + Clock *sysclk; | ||
126 | |||
127 | - /* | ||
128 | - * TODO: ideally we would model the SoC RCC and let it handle | ||
129 | - * system_clock_scale, including its ability to define different | ||
130 | - * possible SYSCLK sources. | ||
131 | - */ | ||
132 | system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; | ||
133 | |||
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), | ||
144 | -- | ||
145 | 2.20.1 | ||
146 | |||
147 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
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. | ||
1 | 4 | ||
5 | Because there is only one board using this SoC, we convert the SoC | ||
6 | and the board together, rather than splitting it into "add clock to | ||
7 | SoC; connect clock in board; add error check in SoC code that clock | ||
8 | is wired up". | ||
9 | |||
10 | When the systick device starts honouring its clock inputs, this will | ||
11 | fix an emulation inaccuracy in the netduino2 board where the systick | ||
12 | reference clock was running at 1MHz rather than 15MHz. | ||
13 | |||
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 | ||
19 | --- | ||
20 | include/hw/arm/stm32f205_soc.h | 4 ++++ | ||
21 | hw/arm/netduino2.c | 12 +++++++----- | ||
22 | hw/arm/stm32f205_soc.c | 30 ++++++++++++++++++++++++++++++ | ||
23 | 3 files changed, 41 insertions(+), 5 deletions(-) | ||
24 | |||
25 | diff --git a/include/hw/arm/stm32f205_soc.h b/include/hw/arm/stm32f205_soc.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | ||
27 | --- a/include/hw/arm/stm32f205_soc.h | ||
28 | +++ b/include/hw/arm/stm32f205_soc.h | ||
29 | @@ -XXX,XX +XXX,XX @@ | ||
30 | #include "hw/or-irq.h" | ||
31 | #include "hw/ssi/stm32f2xx_spi.h" | ||
32 | #include "hw/arm/armv7m.h" | ||
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; | ||
44 | }; | ||
45 | |||
46 | #endif | ||
47 | diff --git a/hw/arm/netduino2.c b/hw/arm/netduino2.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/hw/arm/netduino2.c | ||
50 | +++ b/hw/arm/netduino2.c | ||
51 | @@ -XXX,XX +XXX,XX @@ | ||
52 | #include "qapi/error.h" | ||
53 | #include "hw/boards.h" | ||
54 | #include "hw/qdev-properties.h" | ||
55 | +#include "hw/qdev-clock.h" | ||
56 | #include "qemu/error-report.h" | ||
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); | ||
75 | + | ||
76 | dev = qdev_new(TYPE_STM32F205_SOC); | ||
77 | qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m3")); | ||
78 | + qdev_connect_clock_in(dev, "sysclk", sysclk); | ||
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 | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/hw/arm/stm32f205_soc.c | ||
85 | +++ b/hw/arm/stm32f205_soc.c | ||
86 | @@ -XXX,XX +XXX,XX @@ | ||
87 | #include "exec/address-spaces.h" | ||
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); | ||
101 | } | ||
102 | |||
103 | static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp) | ||
104 | @@ -XXX,XX +XXX,XX @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp) | ||
105 | |||
106 | MemoryRegion *system_memory = get_system_memory(); | ||
107 | |||
108 | + /* | ||
109 | + * We use s->refclk internally and only define it with qdev_init_clock_in() | ||
110 | + * so it is correctly parented and not leaked on an init/deinit; it is not | ||
111 | + * intended as an externally exposed clock. | ||
112 | + */ | ||
113 | + if (clock_has_source(s->refclk)) { | ||
114 | + error_setg(errp, "refclk clock must not be wired up by the board code"); | ||
115 | + return; | ||
116 | + } | ||
117 | + | ||
118 | + if (!clock_has_source(s->sysclk)) { | ||
119 | + error_setg(errp, "sysclk clock must be wired up by the board code"); | ||
120 | + return; | ||
121 | + } | ||
122 | + | ||
123 | + /* | ||
124 | + * TODO: ideally we should model the SoC RCC and its ability to | ||
125 | + * change the sysclk frequency and define different sysclk sources. | ||
126 | + */ | ||
127 | + | ||
128 | + /* The refclk always runs at frequency HCLK / 8 */ | ||
129 | + clock_set_mul_div(s->refclk, 8, 1); | ||
130 | + clock_set_source(s->refclk, s->sysclk); | ||
131 | + | ||
132 | memory_region_init_rom(&s->flash, OBJECT(dev_soc), "STM32F205.flash", | ||
133 | FLASH_SIZE, &error_fatal); | ||
134 | memory_region_init_alias(&s->flash_alias, OBJECT(dev_soc), | ||
135 | @@ -XXX,XX +XXX,XX @@ static void stm32f205_soc_realize(DeviceState *dev_soc, Error **errp) | ||
136 | qdev_prop_set_uint32(armv7m, "num-irq", 96); | ||
137 | qdev_prop_set_string(armv7m, "cpu-type", s->cpu_type); | ||
138 | qdev_prop_set_bit(armv7m, "enable-bitband", true); | ||
139 | + qdev_connect_clock_in(armv7m, "cpuclk", s->sysclk); | ||
140 | + qdev_connect_clock_in(armv7m, "refclk", s->refclk); | ||
141 | object_property_set_link(OBJECT(&s->armv7m), "memory", | ||
142 | OBJECT(get_system_memory()), &error_abort); | ||
143 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->armv7m), errp)) { | ||
144 | -- | ||
145 | 2.20.1 | ||
146 | |||
147 | diff view generated by jsdifflib |
1 | From: Joel Stanley <joel@jms.id.au> | 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 | Following the pattern of the work recently done with the ASPEED GPIO | 5 | Because there is only one board using this SoC, we convert the SoC |
4 | model, this adds support for inspecting and modifying the PCA9552 LEDs | 6 | and the board together, rather than splitting it into "add clock to |
5 | from the monitor. | 7 | SoC; connect clock in board; add error check in SoC code that clock |
8 | is wired up". | ||
6 | 9 | ||
7 | (qemu) qom-set /machine/unattached/device[17] led0 on | 10 | When the systick device starts honouring its clock inputs, this will |
8 | (qemu) qom-set /machine/unattached/device[17] led0 off | 11 | fix an emulation inaccuracy in the netduinoplus2 board where the |
9 | (qemu) qom-set /machine/unattached/device[17] led0 pwm0 | 12 | systick reference clock was running at 1MHz rather than 21MHz. |
10 | (qemu) qom-set /machine/unattached/device[17] led0 pwm1 | ||
11 | 13 | ||
12 | Signed-off-by: Joel Stanley <joel@jms.id.au> | ||
13 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
14 | Message-id: 20200114103433.30534-6-clg@kaod.org | ||
15 | [clg: - removed the "qom-get" examples from the commit log | ||
16 | - merged memory leak fixes from Joel ] | ||
17 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
18 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
19 | 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 | ||
20 | --- | 19 | --- |
21 | hw/misc/pca9552.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++ | 20 | include/hw/arm/stm32f405_soc.h | 3 +++ |
22 | 1 file changed, 90 insertions(+) | 21 | hw/arm/netduinoplus2.c | 12 +++++++----- |
22 | hw/arm/stm32f405_soc.c | 30 ++++++++++++++++++++++++++++++ | ||
23 | 3 files changed, 40 insertions(+), 5 deletions(-) | ||
23 | 24 | ||
24 | diff --git a/hw/misc/pca9552.c b/hw/misc/pca9552.c | 25 | diff --git a/include/hw/arm/stm32f405_soc.h b/include/hw/arm/stm32f405_soc.h |
25 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/misc/pca9552.c | 27 | --- a/include/hw/arm/stm32f405_soc.h |
27 | +++ b/hw/misc/pca9552.c | 28 | +++ b/include/hw/arm/stm32f405_soc.h |
29 | @@ -XXX,XX +XXX,XX @@ struct STM32F405State { | ||
30 | MemoryRegion sram; | ||
31 | MemoryRegion flash; | ||
32 | MemoryRegion flash_alias; | ||
33 | + | ||
34 | + Clock *sysclk; | ||
35 | + Clock *refclk; | ||
36 | }; | ||
37 | |||
38 | #endif | ||
39 | diff --git a/hw/arm/netduinoplus2.c b/hw/arm/netduinoplus2.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/hw/arm/netduinoplus2.c | ||
42 | +++ b/hw/arm/netduinoplus2.c | ||
28 | @@ -XXX,XX +XXX,XX @@ | 43 | @@ -XXX,XX +XXX,XX @@ |
29 | #include "hw/misc/pca9552.h" | 44 | #include "qapi/error.h" |
30 | #include "hw/misc/pca9552_regs.h" | 45 | #include "hw/boards.h" |
31 | #include "migration/vmstate.h" | 46 | #include "hw/qdev-properties.h" |
32 | +#include "qapi/error.h" | 47 | +#include "hw/qdev-clock.h" |
33 | +#include "qapi/visitor.h" | 48 | #include "qemu/error-report.h" |
34 | 49 | #include "hw/arm/stm32f405_soc.h" | |
35 | #define PCA9552_LED_ON 0x0 | 50 | #include "hw/arm/boot.h" |
36 | #define PCA9552_LED_OFF 0x1 | 51 | @@ -XXX,XX +XXX,XX @@ |
37 | #define PCA9552_LED_PWM0 0x2 | 52 | static void netduinoplus2_init(MachineState *machine) |
38 | #define PCA9552_LED_PWM1 0x3 | 53 | { |
39 | 54 | DeviceState *dev; | |
40 | +static const char *led_state[] = {"on", "off", "pwm0", "pwm1"}; | 55 | + Clock *sysclk; |
56 | |||
57 | - /* | ||
58 | - * TODO: ideally we would model the SoC RCC and let it handle | ||
59 | - * system_clock_scale, including its ability to define different | ||
60 | - * possible SYSCLK sources. | ||
61 | - */ | ||
62 | system_clock_scale = NANOSECONDS_PER_SECOND / SYSCLK_FRQ; | ||
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); | ||
41 | + | 67 | + |
42 | static uint8_t pca9552_pin_get_config(PCA9552State *s, int pin) | 68 | dev = qdev_new(TYPE_STM32F405_SOC); |
43 | { | 69 | qdev_prop_set_string(dev, "cpu-type", ARM_CPU_TYPE_NAME("cortex-m4")); |
44 | uint8_t reg = PCA9552_LS0 + (pin / 4); | 70 | + qdev_connect_clock_in(dev, "sysclk", sysclk); |
45 | @@ -XXX,XX +XXX,XX @@ static int pca9552_event(I2CSlave *i2c, enum i2c_event event) | 71 | sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal); |
46 | return 0; | 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); | ||
90 | + | ||
91 | + s->sysclk = qdev_init_clock_in(DEVICE(s), "sysclk", NULL, NULL, 0); | ||
92 | + s->refclk = qdev_init_clock_in(DEVICE(s), "refclk", NULL, NULL, 0); | ||
47 | } | 93 | } |
48 | 94 | ||
49 | +static void pca9552_get_led(Object *obj, Visitor *v, const char *name, | 95 | static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp) |
50 | + void *opaque, Error **errp) | 96 | @@ -XXX,XX +XXX,XX @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp) |
51 | +{ | 97 | Error *err = NULL; |
52 | + PCA9552State *s = PCA9552(obj); | 98 | int i; |
53 | + int led, rc, reg; | 99 | |
54 | + uint8_t state; | ||
55 | + | ||
56 | + rc = sscanf(name, "led%2d", &led); | ||
57 | + if (rc != 1) { | ||
58 | + error_setg(errp, "%s: error reading %s", __func__, name); | ||
59 | + return; | ||
60 | + } | ||
61 | + if (led < 0 || led > s->nr_leds) { | ||
62 | + error_setg(errp, "%s invalid led %s", __func__, name); | ||
63 | + return; | ||
64 | + } | ||
65 | + /* | 100 | + /* |
66 | + * Get the LSx register as the qom interface should expose the device | 101 | + * We use s->refclk internally and only define it with qdev_init_clock_in() |
67 | + * state, not the modeled 'input line' behaviour which would come from | 102 | + * so it is correctly parented and not leaked on an init/deinit; it is not |
68 | + * reading the INPUTx reg | 103 | + * intended as an externally exposed clock. |
69 | + */ | 104 | + */ |
70 | + reg = PCA9552_LS0 + led / 4; | 105 | + if (clock_has_source(s->refclk)) { |
71 | + state = (pca9552_read(s, reg) >> (led % 8)) & 0x3; | 106 | + error_setg(errp, "refclk clock must not be wired up by the board code"); |
72 | + visit_type_str(v, name, (char **)&led_state[state], errp); | ||
73 | +} | ||
74 | + | ||
75 | +/* | ||
76 | + * Return an LED selector register value based on an existing one, with | ||
77 | + * the appropriate 2-bit state value set for the given LED number (0-3). | ||
78 | + */ | ||
79 | +static inline uint8_t pca955x_ledsel(uint8_t oldval, int led_num, int state) | ||
80 | +{ | ||
81 | + return (oldval & (~(0x3 << (led_num << 1)))) | | ||
82 | + ((state & 0x3) << (led_num << 1)); | ||
83 | +} | ||
84 | + | ||
85 | +static void pca9552_set_led(Object *obj, Visitor *v, const char *name, | ||
86 | + void *opaque, Error **errp) | ||
87 | +{ | ||
88 | + PCA9552State *s = PCA9552(obj); | ||
89 | + Error *local_err = NULL; | ||
90 | + int led, rc, reg, val; | ||
91 | + uint8_t state; | ||
92 | + char *state_str; | ||
93 | + | ||
94 | + visit_type_str(v, name, &state_str, &local_err); | ||
95 | + if (local_err) { | ||
96 | + error_propagate(errp, local_err); | ||
97 | + return; | ||
98 | + } | ||
99 | + rc = sscanf(name, "led%2d", &led); | ||
100 | + if (rc != 1) { | ||
101 | + error_setg(errp, "%s: error reading %s", __func__, name); | ||
102 | + return; | ||
103 | + } | ||
104 | + if (led < 0 || led > s->nr_leds) { | ||
105 | + error_setg(errp, "%s invalid led %s", __func__, name); | ||
106 | + return; | 107 | + return; |
107 | + } | 108 | + } |
108 | + | 109 | + |
109 | + for (state = 0; state < ARRAY_SIZE(led_state); state++) { | 110 | + if (!clock_has_source(s->sysclk)) { |
110 | + if (!strcmp(state_str, led_state[state])) { | 111 | + error_setg(errp, "sysclk clock must be wired up by the board code"); |
111 | + break; | ||
112 | + } | ||
113 | + } | ||
114 | + if (state >= ARRAY_SIZE(led_state)) { | ||
115 | + error_setg(errp, "%s invalid led state %s", __func__, state_str); | ||
116 | + return; | 112 | + return; |
117 | + } | 113 | + } |
118 | + | 114 | + |
119 | + reg = PCA9552_LS0 + led / 4; | 115 | + /* |
120 | + val = pca9552_read(s, reg); | 116 | + * TODO: ideally we should model the SoC RCC and its ability to |
121 | + val = pca955x_ledsel(val, led % 4, state); | 117 | + * change the sysclk frequency and define different sysclk sources. |
122 | + pca9552_write(s, reg, val); | 118 | + */ |
123 | +} | ||
124 | + | 119 | + |
125 | static const VMStateDescription pca9552_vmstate = { | 120 | + /* The refclk always runs at frequency HCLK / 8 */ |
126 | .name = "PCA9552", | 121 | + clock_set_mul_div(s->refclk, 8, 1); |
127 | .version_id = 0, | 122 | + clock_set_source(s->refclk, s->sysclk); |
128 | @@ -XXX,XX +XXX,XX @@ static void pca9552_reset(DeviceState *dev) | ||
129 | static void pca9552_initfn(Object *obj) | ||
130 | { | ||
131 | PCA9552State *s = PCA9552(obj); | ||
132 | + int led; | ||
133 | |||
134 | /* If support for the other PCA955X devices are implemented, these | ||
135 | * constant values might be part of class structure describing the | ||
136 | @@ -XXX,XX +XXX,XX @@ static void pca9552_initfn(Object *obj) | ||
137 | */ | ||
138 | s->max_reg = PCA9552_LS3; | ||
139 | s->nr_leds = 16; | ||
140 | + | 123 | + |
141 | + for (led = 0; led < s->nr_leds; led++) { | 124 | memory_region_init_rom(&s->flash, OBJECT(dev_soc), "STM32F405.flash", |
142 | + char *name; | 125 | FLASH_SIZE, &err); |
143 | + | 126 | if (err != NULL) { |
144 | + name = g_strdup_printf("led%d", led); | 127 | @@ -XXX,XX +XXX,XX @@ static void stm32f405_soc_realize(DeviceState *dev_soc, Error **errp) |
145 | + object_property_add(obj, name, "bool", pca9552_get_led, pca9552_set_led, | 128 | qdev_prop_set_uint32(armv7m, "num-irq", 96); |
146 | + NULL, NULL, NULL); | 129 | qdev_prop_set_string(armv7m, "cpu-type", s->cpu_type); |
147 | + g_free(name); | 130 | qdev_prop_set_bit(armv7m, "enable-bitband", true); |
148 | + } | 131 | + qdev_connect_clock_in(armv7m, "cpuclk", s->sysclk); |
149 | } | 132 | + qdev_connect_clock_in(armv7m, "refclk", s->refclk); |
150 | 133 | object_property_set_link(OBJECT(&s->armv7m), "memory", | |
151 | static void pca9552_class_init(ObjectClass *klass, void *data) | 134 | OBJECT(system_memory), &error_abort); |
135 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->armv7m), errp)) { | ||
152 | -- | 136 | -- |
153 | 2.20.1 | 137 | 2.20.1 |
154 | 138 | ||
155 | 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 | The guest can use the semihosting API to open a handle | 1 | Currently the stellaris_sys_init() function creates the |
---|---|---|---|
2 | corresponding to QEMU's own stdin, stdout, or stderr. | 2 | TYPE_STELLARIS_SYS object, sets its properties, realizes it, maps its |
3 | When the guest closes this handle, we should not | 3 | MMIO region and connects its IRQ. In order to support wiring the |
4 | close the underlying host stdin/stdout/stderr | 4 | sysclk up to the armv7m object, we need to split this function apart, |
5 | the way we would do if the handle corresponded to | 5 | because to connect the clock output of the STELLARIS_SYS object to |
6 | a host fd we'd opened on behalf of the guest in SYS_OPEN. | 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. | ||
9 | |||
10 | Remove the stellaris_sys_init() function, and instead put the | ||
11 | create/configure/realize parts before we create the armv7m object and | ||
12 | the mmio/irq connection parts afterwards. | ||
7 | 13 | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | 15 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> |
10 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 16 | Message-id: 20210812093356.1946-17-peter.maydell@linaro.org |
11 | Message-id: 20200124172954.28481-1-peter.maydell@linaro.org | ||
12 | --- | 17 | --- |
13 | target/arm/arm-semi.c | 9 +++++++++ | 18 | hw/arm/stellaris.c | 56 +++++++++++++++++++++------------------------- |
14 | 1 file changed, 9 insertions(+) | 19 | 1 file changed, 25 insertions(+), 31 deletions(-) |
15 | 20 | ||
16 | diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c | 21 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c |
17 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/arm-semi.c | 23 | --- a/hw/arm/stellaris.c |
19 | +++ b/target/arm/arm-semi.c | 24 | +++ b/hw/arm/stellaris.c |
20 | @@ -XXX,XX +XXX,XX @@ static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf) | 25 | @@ -XXX,XX +XXX,XX @@ static void stellaris_sys_instance_init(Object *obj) |
21 | { | 26 | s->sysclk = qdev_init_clock_out(DEVICE(s), "SYSCLK"); |
22 | CPUARMState *env = &cpu->env; | 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); | ||
23 | 70 | ||
24 | + /* | 71 | + /* |
25 | + * Only close the underlying host fd if it's one we opened on behalf | 72 | + * Create the system-registers object early, because we will |
26 | + * of the guest in SYS_OPEN. | 73 | + * need its sysclk output. |
27 | + */ | 74 | + */ |
28 | + if (gf->hostfd == STDIN_FILENO || | 75 | + ssys_dev = qdev_new(TYPE_STELLARIS_SYS); |
29 | + gf->hostfd == STDOUT_FILENO || | 76 | + /* Most devices come preprogrammed with a MAC address in the user data. */ |
30 | + gf->hostfd == STDERR_FILENO) { | 77 | + macaddr = nd_table[0].macaddr.a; |
31 | + return 0; | 78 | + qdev_prop_set_uint32(ssys_dev, "user0", |
32 | + } | 79 | + macaddr[0] | (macaddr[1] << 8) | (macaddr[2] << 16)); |
33 | return set_swi_errno(env, close(gf->hostfd)); | 80 | + qdev_prop_set_uint32(ssys_dev, "user1", |
34 | } | 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 | } | ||
107 | } | ||
108 | |||
109 | - ssys_dev = stellaris_sys_init(0x400fe000, qdev_get_gpio_in(nvic, 28), | ||
110 | - board, nd_table[0].macaddr.a); | ||
111 | - | ||
112 | - | ||
113 | if (board->dc1 & (1 << 3)) { /* watchdog present */ | ||
114 | dev = qdev_new(TYPE_LUMINARY_WATCHDOG); | ||
35 | 115 | ||
36 | -- | 116 | -- |
37 | 2.20.1 | 117 | 2.20.1 |
38 | 118 | ||
39 | 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 |
New patch | |||
---|---|---|---|
1 | In the realize method of the msf2-soc SoC object, we call g_new() to | ||
2 | create new MemoryRegion objects for the nvm, nvm_alias, and sram. | ||
3 | This is unnecessary; make these MemoryRegions member fields of the | ||
4 | device state struct instead. | ||
1 | 5 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
8 | Message-id: 20210812093356.1946-19-peter.maydell@linaro.org | ||
9 | --- | ||
10 | include/hw/arm/msf2-soc.h | 4 ++++ | ||
11 | hw/arm/msf2-soc.c | 17 +++++++---------- | ||
12 | 2 files changed, 11 insertions(+), 10 deletions(-) | ||
13 | |||
14 | diff --git a/include/hw/arm/msf2-soc.h b/include/hw/arm/msf2-soc.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/include/hw/arm/msf2-soc.h | ||
17 | +++ b/include/hw/arm/msf2-soc.h | ||
18 | @@ -XXX,XX +XXX,XX @@ struct MSF2State { | ||
19 | MSSTimerState timer; | ||
20 | MSSSpiState spi[MSF2_NUM_SPIS]; | ||
21 | MSF2EmacState emac; | ||
22 | + | ||
23 | + MemoryRegion nvm; | ||
24 | + MemoryRegion nvm_alias; | ||
25 | + MemoryRegion sram; | ||
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); | ||
68 | -- | ||
69 | 2.20.1 | ||
70 | |||
71 | diff view generated by jsdifflib |
1 | From: Andrew Jones <drjones@redhat.com> | 1 | Instead of passing the MSF2 SoC an integer property specifying the |
---|---|---|---|
2 | CPU clock rate, pass it a Clock instead. This lets us wire that | ||
3 | clock up to the armv7m object. | ||
2 | 4 | ||
3 | Add the missing GENERIC_TIMER feature to kvm64 cpus. | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Alexandre Iooss <erdnaxe@crans.org> | ||
7 | Message-id: 20210812093356.1946-20-peter.maydell@linaro.org | ||
8 | --- | ||
9 | include/hw/arm/msf2-soc.h | 3 ++- | ||
10 | hw/arm/msf2-soc.c | 28 +++++++++++++++++----------- | ||
11 | hw/arm/msf2-som.c | 7 ++++++- | ||
12 | 3 files changed, 25 insertions(+), 13 deletions(-) | ||
4 | 13 | ||
5 | We don't currently use these registers when KVM is enabled, but it's | 14 | diff --git a/include/hw/arm/msf2-soc.h b/include/hw/arm/msf2-soc.h |
6 | probably best we add the feature flag for consistency and potential | ||
7 | future use. There's also precedent, as we add the PMU feature flag to | ||
8 | KVM enabled guests, even though we don't use those registers either. | ||
9 | |||
10 | This change was originally posted as a hunk of a different, never | ||
11 | merged patch from Bijan Mottahedeh. | ||
12 | |||
13 | Signed-off-by: Andrew Jones <drjones@redhat.com> | ||
14 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
15 | Message-id: 20200120101023.16030-4-drjones@redhat.com | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
17 | --- | ||
18 | target/arm/kvm64.c | 1 + | ||
19 | 1 file changed, 1 insertion(+) | ||
20 | |||
21 | diff --git a/target/arm/kvm64.c b/target/arm/kvm64.c | ||
22 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/target/arm/kvm64.c | 16 | --- a/include/hw/arm/msf2-soc.h |
24 | +++ b/target/arm/kvm64.c | 17 | +++ b/include/hw/arm/msf2-soc.h |
25 | @@ -XXX,XX +XXX,XX @@ bool kvm_arm_get_host_cpu_features(ARMHostCPUFeatures *ahcf) | 18 | @@ -XXX,XX +XXX,XX @@ |
26 | set_feature(&features, ARM_FEATURE_NEON); | 19 | #include "hw/misc/msf2-sysreg.h" |
27 | set_feature(&features, ARM_FEATURE_AARCH64); | 20 | #include "hw/ssi/mss-spi.h" |
28 | set_feature(&features, ARM_FEATURE_PMU); | 21 | #include "hw/net/msf2-emac.h" |
29 | + set_feature(&features, ARM_FEATURE_GENERIC_TIMER); | 22 | +#include "hw/clock.h" |
30 | 23 | #include "qom/object.h" | |
31 | ahcf->features = features; | 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) | ||
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); | ||
53 | } | ||
54 | |||
55 | static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | ||
56 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | ||
57 | |||
58 | MemoryRegion *system_memory = get_system_memory(); | ||
59 | |||
60 | + if (!clock_has_source(s->m3clk)) { | ||
61 | + error_setg(errp, "m3clk must be wired up by the board code"); | ||
62 | + return; | ||
63 | + } | ||
64 | + | ||
65 | memory_region_init_rom(&s->nvm, OBJECT(dev_soc), "MSF2.eNVM", s->envm_size, | ||
66 | &error_fatal); | ||
67 | /* | ||
68 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | ||
69 | qdev_prop_set_uint32(armv7m, "num-irq", 81); | ||
70 | qdev_prop_set_string(armv7m, "cpu-type", s->cpu_type); | ||
71 | qdev_prop_set_bit(armv7m, "enable-bitband", true); | ||
72 | + qdev_connect_clock_in(armv7m, "cpuclk", s->m3clk); | ||
73 | object_property_set_link(OBJECT(&s->armv7m), "memory", | ||
74 | OBJECT(get_system_memory()), &error_abort); | ||
75 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->armv7m), errp)) { | ||
76 | return; | ||
77 | } | ||
78 | |||
79 | - if (!s->m3clk) { | ||
80 | - error_setg(errp, "Invalid m3clk value"); | ||
81 | - error_append_hint(errp, "m3clk can not be zero\n"); | ||
82 | - return; | ||
83 | - } | ||
84 | - | ||
85 | - system_clock_scale = NANOSECONDS_PER_SECOND / s->m3clk; | ||
86 | + system_clock_scale = clock_ticks_to_ns(s->m3clk, 1); | ||
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); | ||
32 | 146 | ||
33 | -- | 147 | -- |
34 | 2.20.1 | 148 | 2.20.1 |
35 | 149 | ||
36 | 150 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Wire up the refclk for the msf2 SoC. This SoC runs the refclk at a | ||
2 | frequency which is programmably either /4, /8, /16 or /32 of the main | ||
3 | CPU clock. We don't currently model the register which allows the | ||
4 | guest to set the divisor, so implement the refclk as a fixed /32 of | ||
5 | the CPU clock (which is the value of the divisor at reset). | ||
1 | 6 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> | ||
9 | Message-id: 20210812093356.1946-21-peter.maydell@linaro.org | ||
10 | --- | ||
11 | include/hw/arm/msf2-soc.h | 1 + | ||
12 | hw/arm/msf2-soc.c | 23 +++++++++++++++++++++++ | ||
13 | 2 files changed, 24 insertions(+) | ||
14 | |||
15 | diff --git a/include/hw/arm/msf2-soc.h b/include/hw/arm/msf2-soc.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/include/hw/arm/msf2-soc.h | ||
18 | +++ b/include/hw/arm/msf2-soc.h | ||
19 | @@ -XXX,XX +XXX,XX @@ struct MSF2State { | ||
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); | ||
36 | } | ||
37 | |||
38 | static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | ||
39 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | ||
40 | return; | ||
41 | } | ||
42 | |||
43 | + /* | ||
44 | + * We use s->refclk internally and only define it with qdev_init_clock_in() | ||
45 | + * so it is correctly parented and not leaked on an init/deinit; it is not | ||
46 | + * intended as an externally exposed clock. | ||
47 | + */ | ||
48 | + if (clock_has_source(s->refclk)) { | ||
49 | + error_setg(errp, "refclk must not be wired up by the board code"); | ||
50 | + return; | ||
51 | + } | ||
52 | + | ||
53 | + /* | ||
54 | + * TODO: ideally we should model the SoC SYSTICK_CR register at 0xe0042038, | ||
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)) { | ||
75 | -- | ||
76 | 2.20.1 | ||
77 | |||
78 | diff view generated by jsdifflib |
1 | From: Andrew Jeffery <andrew@aj.id.au> | 1 | Now that all users of the systick devices wire up the clock inputs, |
---|---|---|---|
2 | 2 | use those instead of the system_clock_scale and the hardwired 1MHz | |
3 | Initialise another SDHCI model instance for the AST2600's eMMC | 3 | value for the reference clock. |
4 | controller and use the SDHCI's num_slots value introduced previously to | 4 | |
5 | determine whether we should create an SD card instance for the new slot. | 5 | This will fix various board models where we were incorrectly |
6 | 6 | providing a 1MHz reference clock instead of some other value or | |
7 | Signed-off-by: Andrew Jeffery <andrew@aj.id.au> | 7 | instead of providing no reference clock at all. |
8 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | 8 | |
9 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
10 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
11 | Message-id: 20200114103433.30534-3-clg@kaod.org | ||
12 | [ clg : - removed ternary operator from sdhci_attach_drive() | ||
13 | - renamed SDHCI objects with a '-controller' prefix ] | ||
14 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 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 | ||
16 | --- | 12 | --- |
17 | include/hw/arm/aspeed_soc.h | 2 ++ | 13 | hw/timer/armv7m_systick.c | 112 ++++++++++++++++++++++++++++---------- |
18 | hw/arm/aspeed.c | 26 +++++++++++++++++--------- | 14 | 1 file changed, 84 insertions(+), 28 deletions(-) |
19 | hw/arm/aspeed_ast2600.c | 29 ++++++++++++++++++++++++++--- | 15 | |
20 | 3 files changed, 45 insertions(+), 12 deletions(-) | 16 | diff --git a/hw/timer/armv7m_systick.c b/hw/timer/armv7m_systick.c |
21 | |||
22 | diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/include/hw/arm/aspeed_soc.h | 18 | --- a/hw/timer/armv7m_systick.c |
25 | +++ b/include/hw/arm/aspeed_soc.h | 19 | +++ b/hw/timer/armv7m_systick.c |
26 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState { | 20 | @@ -XXX,XX +XXX,XX @@ |
27 | AspeedGPIOState gpio; | 21 | #include "qemu/timer.h" |
28 | AspeedGPIOState gpio_1_8v; | 22 | #include "qemu/log.h" |
29 | AspeedSDHCIState sdhci; | 23 | #include "qemu/module.h" |
30 | + AspeedSDHCIState emmc; | 24 | +#include "qapi/error.h" |
31 | } AspeedSoCState; | 25 | #include "trace.h" |
32 | 26 | ||
33 | #define TYPE_ASPEED_SOC "aspeed-soc" | 27 | -/* qemu timers run at 1GHz. We want something closer to 1MHz. */ |
34 | @@ -XXX,XX +XXX,XX @@ enum { | 28 | -#define SYSTICK_SCALE 1000ULL |
35 | ASPEED_MII4, | 29 | - |
36 | ASPEED_SDRAM, | 30 | #define SYSTICK_ENABLE (1 << 0) |
37 | ASPEED_XDMA, | 31 | #define SYSTICK_TICKINT (1 << 1) |
38 | + ASPEED_EMMC, | 32 | #define SYSTICK_CLKSOURCE (1 << 2) |
39 | }; | 33 | #define SYSTICK_COUNTFLAG (1 << 16) |
40 | 34 | ||
41 | #endif /* ASPEED_SOC_H */ | 35 | +#define SYSCALIB_NOREF (1U << 31) |
42 | diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c | 36 | +#define SYSCALIB_SKEW (1U << 30) |
43 | index XXXXXXX..XXXXXXX 100644 | 37 | +#define SYSCALIB_TENMS ((1U << 24) - 1) |
44 | --- a/hw/arm/aspeed.c | 38 | + |
45 | +++ b/hw/arm/aspeed.c | 39 | int system_clock_scale; |
46 | @@ -XXX,XX +XXX,XX @@ static void aspeed_board_init_flashes(AspeedSMCState *s, const char *flashtype, | 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); | ||
47 | } | 55 | } |
48 | } | 56 | } |
49 | 57 | ||
50 | +static void sdhci_attach_drive(SDHCIState *sdhci, DriveInfo *dinfo) | 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) | ||
51 | +{ | 151 | +{ |
52 | + DeviceState *card; | 152 | + SysTickState *s = SYSTICK(opaque); |
53 | + | 153 | + |
54 | + card = qdev_create(qdev_get_child_bus(DEVICE(sdhci), "sd-bus"), | 154 | + if (!(s->control & SYSTICK_CLKSOURCE)) { |
55 | + TYPE_SD_CARD); | 155 | + /* currently using refclk, we can ignore cpuclk changes */ |
56 | + if (dinfo) { | 156 | + } |
57 | + qdev_prop_set_drive(card, "drive", blk_by_legacy_dinfo(dinfo), | 157 | + |
58 | + &error_fatal); | 158 | + ptimer_transaction_begin(s->ptimer); |
59 | + } | 159 | + ptimer_set_period_from_clock(s->ptimer, s->cpuclk, 1); |
60 | + object_property_set_bool(OBJECT(card), true, "realized", &error_fatal); | 160 | + ptimer_transaction_commit(s->ptimer); |
61 | +} | 161 | +} |
62 | + | 162 | + |
63 | static void aspeed_machine_init(MachineState *machine) | 163 | +static void systick_refclk_update(void *opaque, ClockEvent event) |
64 | { | 164 | +{ |
65 | AspeedBoardState *bmc; | 165 | + SysTickState *s = SYSTICK(opaque); |
66 | @@ -XXX,XX +XXX,XX @@ static void aspeed_machine_init(MachineState *machine) | 166 | + |
67 | } | 167 | + if (s->control & SYSTICK_CLKSOURCE) { |
68 | 168 | + /* currently using cpuclk, we can ignore refclk changes */ | |
69 | for (i = 0; i < bmc->soc.sdhci.num_slots; i++) { | 169 | + } |
70 | - SDHCIState *sdhci = &bmc->soc.sdhci.slots[i]; | 170 | + |
71 | - DriveInfo *dinfo = drive_get_next(IF_SD); | 171 | + ptimer_transaction_begin(s->ptimer); |
72 | - BlockBackend *blk; | 172 | + ptimer_set_period_from_clock(s->ptimer, s->refclk, 1); |
73 | - DeviceState *card; | 173 | ptimer_transaction_commit(s->ptimer); |
74 | + sdhci_attach_drive(&bmc->soc.sdhci.slots[i], drive_get_next(IF_SD)); | 174 | } |
75 | + } | 175 | |
76 | 176 | @@ -XXX,XX +XXX,XX @@ static void systick_instance_init(Object *obj) | |
77 | - blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; | 177 | sysbus_init_mmio(sbd, &s->iomem); |
78 | - card = qdev_create(qdev_get_child_bus(DEVICE(sdhci), "sd-bus"), | 178 | sysbus_init_irq(sbd, &s->irq); |
79 | - TYPE_SD_CARD); | 179 | |
80 | - qdev_prop_set_drive(card, "drive", blk, &error_fatal); | 180 | - s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", NULL, NULL, 0); |
81 | - object_property_set_bool(OBJECT(card), true, "realized", &error_fatal); | 181 | - s->cpuclk = qdev_init_clock_in(DEVICE(obj), "cpuclk", NULL, NULL, 0); |
82 | + if (bmc->soc.emmc.num_slots) { | 182 | + s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", |
83 | + sdhci_attach_drive(&bmc->soc.emmc.slots[0], drive_get_next(IF_SD)); | 183 | + systick_refclk_update, s, ClockUpdate); |
84 | } | 184 | + s->cpuclk = qdev_init_clock_in(DEVICE(obj), "cpuclk", |
85 | 185 | + systick_cpuclk_update, s, ClockUpdate); | |
86 | arm_load_kernel(ARM_CPU(first_cpu), machine, &aspeed_board_binfo); | 186 | } |
87 | diff --git a/hw/arm/aspeed_ast2600.c b/hw/arm/aspeed_ast2600.c | 187 | |
88 | index XXXXXXX..XXXXXXX 100644 | 188 | static void systick_realize(DeviceState *dev, Error **errp) |
89 | --- a/hw/arm/aspeed_ast2600.c | 189 | @@ -XXX,XX +XXX,XX @@ static void systick_realize(DeviceState *dev, Error **errp) |
90 | +++ b/hw/arm/aspeed_ast2600.c | 190 | PTIMER_POLICY_NO_COUNTER_ROUND_DOWN | |
91 | @@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2600_memmap[] = { | 191 | PTIMER_POLICY_NO_IMMEDIATE_RELOAD | |
92 | [ASPEED_ADC] = 0x1E6E9000, | 192 | PTIMER_POLICY_TRIGGER_ONLY_ON_DECREMENT); |
93 | [ASPEED_VIDEO] = 0x1E700000, | 193 | + |
94 | [ASPEED_SDHCI] = 0x1E740000, | 194 | + if (!clock_has_source(s->cpuclk)) { |
95 | + [ASPEED_EMMC] = 0x1E750000, | 195 | + error_setg(errp, "systick: cpuclk must be connected"); |
96 | [ASPEED_GPIO] = 0x1E780000, | ||
97 | [ASPEED_GPIO_1_8V] = 0x1E780800, | ||
98 | [ASPEED_RTC] = 0x1E781000, | ||
99 | @@ -XXX,XX +XXX,XX @@ static const hwaddr aspeed_soc_ast2600_memmap[] = { | ||
100 | |||
101 | #define ASPEED_SOC_AST2600_MAX_IRQ 128 | ||
102 | |||
103 | +/* Shared Peripheral Interrupt values below are offset by -32 from datasheet */ | ||
104 | static const int aspeed_soc_ast2600_irqmap[] = { | ||
105 | [ASPEED_UART1] = 47, | ||
106 | [ASPEED_UART2] = 48, | ||
107 | @@ -XXX,XX +XXX,XX @@ static const int aspeed_soc_ast2600_irqmap[] = { | ||
108 | [ASPEED_ADC] = 78, | ||
109 | [ASPEED_XDMA] = 6, | ||
110 | [ASPEED_SDHCI] = 43, | ||
111 | + [ASPEED_EMMC] = 15, | ||
112 | [ASPEED_GPIO] = 40, | ||
113 | [ASPEED_GPIO_1_8V] = 11, | ||
114 | [ASPEED_RTC] = 13, | ||
115 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_init(Object *obj) | ||
116 | sysbus_init_child_obj(obj, "gpio_1_8v", OBJECT(&s->gpio_1_8v), | ||
117 | sizeof(s->gpio_1_8v), typename); | ||
118 | |||
119 | - sysbus_init_child_obj(obj, "sdc", OBJECT(&s->sdhci), sizeof(s->sdhci), | ||
120 | - TYPE_ASPEED_SDHCI); | ||
121 | + sysbus_init_child_obj(obj, "sd-controller", OBJECT(&s->sdhci), | ||
122 | + sizeof(s->sdhci), TYPE_ASPEED_SDHCI); | ||
123 | |||
124 | object_property_set_int(OBJECT(&s->sdhci), 2, "num-slots", &error_abort); | ||
125 | |||
126 | /* Init sd card slot class here so that they're under the correct parent */ | ||
127 | for (i = 0; i < ASPEED_SDHCI_NUM_SLOTS; ++i) { | ||
128 | - sysbus_init_child_obj(obj, "sdhci[*]", OBJECT(&s->sdhci.slots[i]), | ||
129 | + sysbus_init_child_obj(obj, "sd-controller.sdhci[*]", | ||
130 | + OBJECT(&s->sdhci.slots[i]), | ||
131 | sizeof(s->sdhci.slots[i]), TYPE_SYSBUS_SDHCI); | ||
132 | } | ||
133 | + | ||
134 | + sysbus_init_child_obj(obj, "emmc-controller", OBJECT(&s->emmc), | ||
135 | + sizeof(s->emmc), TYPE_ASPEED_SDHCI); | ||
136 | + | ||
137 | + object_property_set_int(OBJECT(&s->emmc), 1, "num-slots", &error_abort); | ||
138 | + | ||
139 | + sysbus_init_child_obj(obj, "emmc-controller.sdhci", | ||
140 | + OBJECT(&s->emmc.slots[0]), sizeof(s->emmc.slots[0]), | ||
141 | + TYPE_SYSBUS_SDHCI); | ||
142 | } | ||
143 | |||
144 | /* | ||
145 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp) | ||
146 | sc->memmap[ASPEED_SDHCI]); | ||
147 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->sdhci), 0, | ||
148 | aspeed_soc_get_irq(s, ASPEED_SDHCI)); | ||
149 | + | ||
150 | + /* eMMC */ | ||
151 | + object_property_set_bool(OBJECT(&s->emmc), true, "realized", &err); | ||
152 | + if (err) { | ||
153 | + error_propagate(errp, err); | ||
154 | + return; | 196 | + return; |
155 | + } | 197 | + } |
156 | + sysbus_mmio_map(SYS_BUS_DEVICE(&s->emmc), 0, sc->memmap[ASPEED_EMMC]); | 198 | + /* It's OK not to connect the refclk */ |
157 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->emmc), 0, | 199 | } |
158 | + aspeed_soc_get_irq(s, ASPEED_EMMC)); | 200 | |
159 | } | 201 | static const VMStateDescription vmstate_systick = { |
160 | |||
161 | static void aspeed_soc_ast2600_class_init(ObjectClass *oc, void *data) | ||
162 | -- | 202 | -- |
163 | 2.20.1 | 203 | 2.20.1 |
164 | 204 | ||
165 | 205 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | Fix the code style issues in the Stellaris general purpose timer | ||
2 | module code, so that when we move it to a different file in a | ||
3 | following patch checkpatch doesn't complain. | ||
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-23-peter.maydell@linaro.org | ||
8 | --- | ||
9 | hw/arm/stellaris.c | 13 ++++++++----- | ||
10 | 1 file changed, 8 insertions(+), 5 deletions(-) | ||
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 gptm_stop(gptm_state *s, int n) | ||
17 | static void gptm_reload(gptm_state *s, int n, int reset) | ||
18 | { | ||
19 | int64_t tick; | ||
20 | - if (reset) | ||
21 | + if (reset) { | ||
22 | tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
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; | ||
45 | -- | ||
46 | 2.20.1 | ||
47 | |||
48 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.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 | This commit defines an interface allowing multi-phase reset. This aims | 5 | Apart from the new file comment headers and the Kconfig and |
4 | to solve a problem of the actual single-phase reset (built in | 6 | meson.build changes, this is just code movement. |
5 | DeviceClass and BusClass): reset behavior is dependent on the order | ||
6 | in which reset handlers are called. In particular doing external | ||
7 | side-effect (like setting an qemu_irq) is problematic because receiving | ||
8 | object may not be reset yet. | ||
9 | 7 | ||
10 | The Resettable interface divides the reset in 3 well defined phases. | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | To reset an object tree, all 1st phases are executed then all 2nd then | 9 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> |
12 | all 3rd. See the comments in include/hw/resettable.h for a more complete | 10 | Message-id: 20210812093356.1946-24-peter.maydell@linaro.org |
13 | description. The interface defines 3 phases to let the future | 11 | --- |
14 | possibility of holding an object into reset for some time. | 12 | include/hw/timer/stellaris-gptm.h | 48 +++++ |
13 | hw/arm/stellaris.c | 321 +----------------------------- | ||
14 | hw/timer/stellaris-gptm.c | 314 +++++++++++++++++++++++++++++ | ||
15 | hw/arm/Kconfig | 1 + | ||
16 | hw/timer/Kconfig | 3 + | ||
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 | ||
15 | 21 | ||
16 | The qdev/qbus reset in DeviceClass and BusClass will be modified in | 22 | diff --git a/include/hw/timer/stellaris-gptm.h b/include/hw/timer/stellaris-gptm.h |
17 | following commits to use this interface. A mechanism is provided | ||
18 | to allow executing a transitional reset handler in place of the 2nd | ||
19 | phase which is executed in children-then-parent order inside a tree. | ||
20 | This will allow to transition devices and buses smoothly while | ||
21 | keeping the exact current qdev/qbus reset behavior for now. | ||
22 | |||
23 | Documentation will be added in a following commit. | ||
24 | |||
25 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
26 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
27 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
28 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
29 | Message-id: 20200123132823.1117486-4-damien.hedde@greensocs.com | ||
30 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
31 | --- | ||
32 | hw/core/Makefile.objs | 1 + | ||
33 | include/hw/resettable.h | 211 +++++++++++++++++++++++++++++++++++ | ||
34 | hw/core/resettable.c | 238 ++++++++++++++++++++++++++++++++++++++++ | ||
35 | hw/core/trace-events | 17 +++ | ||
36 | 4 files changed, 467 insertions(+) | ||
37 | create mode 100644 include/hw/resettable.h | ||
38 | create mode 100644 hw/core/resettable.c | ||
39 | |||
40 | diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs | ||
41 | index XXXXXXX..XXXXXXX 100644 | ||
42 | --- a/hw/core/Makefile.objs | ||
43 | +++ b/hw/core/Makefile.objs | ||
44 | @@ -XXX,XX +XXX,XX @@ | ||
45 | common-obj-y += qdev.o qdev-properties.o | ||
46 | common-obj-y += bus.o | ||
47 | common-obj-y += cpu.o | ||
48 | +common-obj-y += resettable.o | ||
49 | common-obj-y += hotplug.o | ||
50 | common-obj-y += vmstate-if.o | ||
51 | # irq.o needed for qdev GPIO handling: | ||
52 | diff --git a/include/hw/resettable.h b/include/hw/resettable.h | ||
53 | new file mode 100644 | 23 | new file mode 100644 |
54 | index XXXXXXX..XXXXXXX | 24 | index XXXXXXX..XXXXXXX |
55 | --- /dev/null | 25 | --- /dev/null |
56 | +++ b/include/hw/resettable.h | 26 | +++ b/include/hw/timer/stellaris-gptm.h |
57 | @@ -XXX,XX +XXX,XX @@ | 27 | @@ -XXX,XX +XXX,XX @@ |
58 | +/* | 28 | +/* |
59 | + * Resettable interface header. | 29 | + * Luminary Micro Stellaris General Purpose Timer Module |
60 | + * | 30 | + * |
61 | + * Copyright (c) 2019 GreenSocs SAS | 31 | + * Copyright (c) 2006 CodeSourcery. |
32 | + * Written by Paul Brook | ||
62 | + * | 33 | + * |
63 | + * Authors: | 34 | + * This code is licensed under the GPL. |
64 | + * Damien Hedde | ||
65 | + * | ||
66 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
67 | + * See the COPYING file in the top-level directory. | ||
68 | + */ | 35 | + */ |
69 | + | 36 | + |
70 | +#ifndef HW_RESETTABLE_H | 37 | +#ifndef HW_TIMER_STELLARIS_GPTM_H |
71 | +#define HW_RESETTABLE_H | 38 | +#define HW_TIMER_STELLARIS_GPTM_H |
72 | + | 39 | + |
73 | +#include "qom/object.h" | 40 | +#include "qom/object.h" |
74 | + | 41 | +#include "hw/sysbus.h" |
75 | +#define TYPE_RESETTABLE_INTERFACE "resettable" | 42 | +#include "hw/irq.h" |
76 | + | 43 | + |
77 | +#define RESETTABLE_CLASS(class) \ | 44 | +#define TYPE_STELLARIS_GPTM "stellaris-gptm" |
78 | + OBJECT_CLASS_CHECK(ResettableClass, (class), TYPE_RESETTABLE_INTERFACE) | 45 | +OBJECT_DECLARE_SIMPLE_TYPE(gptm_state, STELLARIS_GPTM) |
79 | + | 46 | + |
80 | +#define RESETTABLE_GET_CLASS(obj) \ | 47 | +/* |
81 | + OBJECT_GET_CLASS(ResettableClass, (obj), TYPE_RESETTABLE_INTERFACE) | 48 | + * QEMU interface: |
82 | + | 49 | + * + sysbus MMIO region 0: register bank |
83 | +typedef struct ResettableState ResettableState; | 50 | + * + sysbus IRQ 0: timer interrupt |
84 | + | 51 | + * + unnamed GPIO output 0: trigger output for the ADC |
85 | +/** | ||
86 | + * ResetType: | ||
87 | + * Types of reset. | ||
88 | + * | ||
89 | + * + Cold: reset resulting from a power cycle of the object. | ||
90 | + * | ||
91 | + * TODO: Support has to be added to handle more types. In particular, | ||
92 | + * ResettableState structure needs to be expanded. | ||
93 | + */ | 52 | + */ |
94 | +typedef enum ResetType { | 53 | +struct gptm_state { |
95 | + RESET_TYPE_COLD, | 54 | + SysBusDevice parent_obj; |
96 | +} ResetType; | 55 | + |
97 | + | 56 | + MemoryRegion iomem; |
98 | +/* | 57 | + uint32_t config; |
99 | + * ResettableClass: | 58 | + uint32_t mode[2]; |
100 | + * Interface for resettable objects. | 59 | + uint32_t control; |
101 | + * | 60 | + uint32_t state; |
102 | + * See docs/devel/reset.rst for more detailed information about how QEMU models | 61 | + uint32_t mask; |
103 | + * reset. This whole API must only be used when holding the iothread mutex. | 62 | + uint32_t load[2]; |
104 | + * | 63 | + uint32_t match[2]; |
105 | + * All objects which can be reset must implement this interface; | 64 | + uint32_t prescale[2]; |
106 | + * it is usually provided by a base class such as DeviceClass or BusClass. | 65 | + uint32_t match_prescale[2]; |
107 | + * Every Resettable object must maintain some state tracking the | 66 | + uint32_t rtc; |
108 | + * progress of a reset operation by providing a ResettableState structure. | 67 | + int64_t tick[2]; |
109 | + * The functions defined in this module take care of updating the | 68 | + struct gptm_state *opaque[2]; |
110 | + * state of the reset. | 69 | + QEMUTimer *timer[2]; |
111 | + * The base class implementation of the interface provides this | 70 | + /* The timers have an alternate output used to trigger the ADC. */ |
112 | + * state and implements the associated method: get_state. | 71 | + qemu_irq trigger; |
113 | + * | 72 | + qemu_irq irq; |
114 | + * Concrete object implementations (typically specific devices | ||
115 | + * such as a UART model) should provide the functions | ||
116 | + * for the phases.enter, phases.hold and phases.exit methods, which | ||
117 | + * they can set in their class init function, either directly or | ||
118 | + * by calling resettable_class_set_parent_phases(). | ||
119 | + * The phase methods are guaranteed to only only ever be called once | ||
120 | + * for any reset event, in the order 'enter', 'hold', 'exit'. | ||
121 | + * An object will always move quickly from 'enter' to 'hold' | ||
122 | + * but might remain in 'hold' for an arbitrary period of time | ||
123 | + * before eventually reset is deasserted and the 'exit' phase is called. | ||
124 | + * Object implementations should be prepared for functions handling | ||
125 | + * inbound connections from other devices (such as qemu_irq handler | ||
126 | + * functions) to be called at any point during reset after their | ||
127 | + * 'enter' method has been called. | ||
128 | + * | ||
129 | + * Users of a resettable object should not call these methods | ||
130 | + * directly, but instead use the function resettable_reset(). | ||
131 | + * | ||
132 | + * @phases.enter: This phase is called when the object enters reset. It | ||
133 | + * should reset local state of the object, but it must not do anything that | ||
134 | + * has a side-effect on other objects, such as raising or lowering a qemu_irq | ||
135 | + * line or reading or writing guest memory. It takes the reset's type as | ||
136 | + * argument. | ||
137 | + * | ||
138 | + * @phases.hold: This phase is called for entry into reset, once every object | ||
139 | + * in the system which is being reset has had its @phases.enter method called. | ||
140 | + * At this point devices can do actions that affect other objects. | ||
141 | + * | ||
142 | + * @phases.exit: This phase is called when the object leaves the reset state. | ||
143 | + * Actions affecting other objects are permitted. | ||
144 | + * | ||
145 | + * @get_state: Mandatory method which must return a pointer to a | ||
146 | + * ResettableState. | ||
147 | + * | ||
148 | + * @get_transitional_function: transitional method to handle Resettable objects | ||
149 | + * not yet fully moved to this interface. It will be removed as soon as it is | ||
150 | + * not needed anymore. This method is optional and may return a pointer to a | ||
151 | + * function to be used instead of the phases. If the method exists and returns | ||
152 | + * a non-NULL function pointer then that function is executed as a replacement | ||
153 | + * of the 'hold' phase method taking the object as argument. The two other phase | ||
154 | + * methods are not executed. | ||
155 | + * | ||
156 | + * @child_foreach: Executes a given callback on every Resettable child. Child | ||
157 | + * in this context means a child in the qbus tree, so the children of a qbus | ||
158 | + * are the devices on it, and the children of a device are all the buses it | ||
159 | + * owns. This is not the same as the QOM object hierarchy. The function takes | ||
160 | + * additional opaque and ResetType arguments which must be passed unmodified to | ||
161 | + * the callback. | ||
162 | + */ | ||
163 | +typedef void (*ResettableEnterPhase)(Object *obj, ResetType type); | ||
164 | +typedef void (*ResettableHoldPhase)(Object *obj); | ||
165 | +typedef void (*ResettableExitPhase)(Object *obj); | ||
166 | +typedef ResettableState * (*ResettableGetState)(Object *obj); | ||
167 | +typedef void (*ResettableTrFunction)(Object *obj); | ||
168 | +typedef ResettableTrFunction (*ResettableGetTrFunction)(Object *obj); | ||
169 | +typedef void (*ResettableChildCallback)(Object *, void *opaque, | ||
170 | + ResetType type); | ||
171 | +typedef void (*ResettableChildForeach)(Object *obj, | ||
172 | + ResettableChildCallback cb, | ||
173 | + void *opaque, ResetType type); | ||
174 | +typedef struct ResettablePhases { | ||
175 | + ResettableEnterPhase enter; | ||
176 | + ResettableHoldPhase hold; | ||
177 | + ResettableExitPhase exit; | ||
178 | +} ResettablePhases; | ||
179 | +typedef struct ResettableClass { | ||
180 | + InterfaceClass parent_class; | ||
181 | + | ||
182 | + /* Phase methods */ | ||
183 | + ResettablePhases phases; | ||
184 | + | ||
185 | + /* State access method */ | ||
186 | + ResettableGetState get_state; | ||
187 | + | ||
188 | + /* Transitional method for legacy reset compatibility */ | ||
189 | + ResettableGetTrFunction get_transitional_function; | ||
190 | + | ||
191 | + /* Hierarchy handling method */ | ||
192 | + ResettableChildForeach child_foreach; | ||
193 | +} ResettableClass; | ||
194 | + | ||
195 | +/** | ||
196 | + * ResettableState: | ||
197 | + * Structure holding reset related state. The fields should not be accessed | ||
198 | + * directly; the definition is here to allow further inclusion into other | ||
199 | + * objects. | ||
200 | + * | ||
201 | + * @count: Number of reset level the object is into. It is incremented when | ||
202 | + * the reset operation starts and decremented when it finishes. | ||
203 | + * @hold_phase_pending: flag which indicates that we need to invoke the 'hold' | ||
204 | + * phase handler for this object. | ||
205 | + * @exit_phase_in_progress: true if we are currently in the exit phase | ||
206 | + */ | ||
207 | +struct ResettableState { | ||
208 | + unsigned count; | ||
209 | + bool hold_phase_pending; | ||
210 | + bool exit_phase_in_progress; | ||
211 | +}; | 73 | +}; |
212 | + | 74 | + |
213 | +/** | ||
214 | + * resettable_reset: | ||
215 | + * Trigger a reset on an object @obj of type @type. @obj must implement | ||
216 | + * Resettable interface. | ||
217 | + * | ||
218 | + * Calling this function is equivalent to calling @resettable_assert_reset() | ||
219 | + * then @resettable_release_reset(). | ||
220 | + */ | ||
221 | +void resettable_reset(Object *obj, ResetType type); | ||
222 | + | ||
223 | +/** | ||
224 | + * resettable_assert_reset: | ||
225 | + * Put an object @obj into reset. @obj must implement Resettable interface. | ||
226 | + * | ||
227 | + * @resettable_release_reset() must eventually be called after this call. | ||
228 | + * There must be one call to @resettable_release_reset() per call of | ||
229 | + * @resettable_assert_reset(), with the same type argument. | ||
230 | + * | ||
231 | + * NOTE: Until support for migration is added, the @resettable_release_reset() | ||
232 | + * must not be delayed. It must occur just after @resettable_assert_reset() so | ||
233 | + * that migration cannot be triggered in between. Prefer using | ||
234 | + * @resettable_reset() for now. | ||
235 | + */ | ||
236 | +void resettable_assert_reset(Object *obj, ResetType type); | ||
237 | + | ||
238 | +/** | ||
239 | + * resettable_release_reset: | ||
240 | + * Release the object @obj from reset. @obj must implement Resettable interface. | ||
241 | + * | ||
242 | + * See @resettable_assert_reset() description for details. | ||
243 | + */ | ||
244 | +void resettable_release_reset(Object *obj, ResetType type); | ||
245 | + | ||
246 | +/** | ||
247 | + * resettable_is_in_reset: | ||
248 | + * Return true if @obj is under reset. | ||
249 | + * | ||
250 | + * @obj must implement Resettable interface. | ||
251 | + */ | ||
252 | +bool resettable_is_in_reset(Object *obj); | ||
253 | + | ||
254 | +/** | ||
255 | + * resettable_class_set_parent_phases: | ||
256 | + * | ||
257 | + * Save @rc current reset phases into @parent_phases and override @rc phases | ||
258 | + * by the given new methods (@enter, @hold and @exit). | ||
259 | + * Each phase is overridden only if the new one is not NULL allowing to | ||
260 | + * override a subset of phases. | ||
261 | + */ | ||
262 | +void resettable_class_set_parent_phases(ResettableClass *rc, | ||
263 | + ResettableEnterPhase enter, | ||
264 | + ResettableHoldPhase hold, | ||
265 | + ResettableExitPhase exit, | ||
266 | + ResettablePhases *parent_phases); | ||
267 | + | ||
268 | +#endif | 75 | +#endif |
269 | diff --git a/hw/core/resettable.c b/hw/core/resettable.c | 76 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c |
77 | index XXXXXXX..XXXXXXX 100644 | ||
78 | --- a/hw/arm/stellaris.c | ||
79 | +++ b/hw/arm/stellaris.c | ||
80 | @@ -XXX,XX +XXX,XX @@ | ||
81 | #include "hw/watchdog/cmsdk-apb-watchdog.h" | ||
82 | #include "migration/vmstate.h" | ||
83 | #include "hw/misc/unimp.h" | ||
84 | +#include "hw/timer/stellaris-gptm.h" | ||
85 | #include "hw/qdev-clock.h" | ||
86 | #include "qom/object.h" | ||
87 | |||
88 | @@ -XXX,XX +XXX,XX @@ typedef const struct { | ||
89 | uint32_t peripherals; | ||
90 | } stellaris_board_info; | ||
91 | |||
92 | -/* General purpose timer module. */ | ||
93 | - | ||
94 | -#define TYPE_STELLARIS_GPTM "stellaris-gptm" | ||
95 | -OBJECT_DECLARE_SIMPLE_TYPE(gptm_state, STELLARIS_GPTM) | ||
96 | - | ||
97 | -struct gptm_state { | ||
98 | - SysBusDevice parent_obj; | ||
99 | - | ||
100 | - MemoryRegion iomem; | ||
101 | - uint32_t config; | ||
102 | - uint32_t mode[2]; | ||
103 | - uint32_t control; | ||
104 | - uint32_t state; | ||
105 | - uint32_t mask; | ||
106 | - uint32_t load[2]; | ||
107 | - uint32_t match[2]; | ||
108 | - uint32_t prescale[2]; | ||
109 | - uint32_t match_prescale[2]; | ||
110 | - uint32_t rtc; | ||
111 | - int64_t tick[2]; | ||
112 | - struct gptm_state *opaque[2]; | ||
113 | - QEMUTimer *timer[2]; | ||
114 | - /* The timers have an alternate output used to trigger the ADC. */ | ||
115 | - qemu_irq trigger; | ||
116 | - qemu_irq irq; | ||
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 | ||
270 | new file mode 100644 | 430 | new file mode 100644 |
271 | index XXXXXXX..XXXXXXX | 431 | index XXXXXXX..XXXXXXX |
272 | --- /dev/null | 432 | --- /dev/null |
273 | +++ b/hw/core/resettable.c | 433 | +++ b/hw/timer/stellaris-gptm.c |
274 | @@ -XXX,XX +XXX,XX @@ | 434 | @@ -XXX,XX +XXX,XX @@ |
275 | +/* | 435 | +/* |
276 | + * Resettable interface. | 436 | + * Luminary Micro Stellaris General Purpose Timer Module |
277 | + * | 437 | + * |
278 | + * Copyright (c) 2019 GreenSocs SAS | 438 | + * Copyright (c) 2006 CodeSourcery. |
439 | + * Written by Paul Brook | ||
279 | + * | 440 | + * |
280 | + * Authors: | 441 | + * This code is licensed under the GPL. |
281 | + * Damien Hedde | ||
282 | + * | ||
283 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
284 | + * See the COPYING file in the top-level directory. | ||
285 | + */ | 442 | + */ |
286 | + | 443 | + |
287 | +#include "qemu/osdep.h" | 444 | +#include "qemu/osdep.h" |
288 | +#include "qemu/module.h" | 445 | +#include "qemu/log.h" |
289 | +#include "hw/resettable.h" | 446 | +#include "qemu/timer.h" |
290 | +#include "trace.h" | 447 | +#include "migration/vmstate.h" |
291 | + | 448 | +#include "hw/timer/stellaris-gptm.h" |
292 | +/** | 449 | +#include "hw/timer/armv7m_systick.h" /* Needed only for system_clock_scale */ |
293 | + * resettable_phase_enter/hold/exit: | 450 | + |
294 | + * Function executing a phase recursively in a resettable object and its | 451 | +static void gptm_update_irq(gptm_state *s) |
295 | + * children. | 452 | +{ |
296 | + */ | 453 | + int level; |
297 | +static void resettable_phase_enter(Object *obj, void *opaque, ResetType type); | 454 | + level = (s->state & s->mask) != 0; |
298 | +static void resettable_phase_hold(Object *obj, void *opaque, ResetType type); | 455 | + qemu_set_irq(s->irq, level); |
299 | +static void resettable_phase_exit(Object *obj, void *opaque, ResetType type); | 456 | +} |
300 | + | 457 | + |
301 | +/** | 458 | +static void gptm_stop(gptm_state *s, int n) |
302 | + * enter_phase_in_progress: | 459 | +{ |
303 | + * True if we are currently in reset enter phase. | 460 | + timer_del(s->timer[n]); |
304 | + * | 461 | +} |
305 | + * Note: This flag is only used to guarantee (using asserts) that the reset | 462 | + |
306 | + * API is used correctly. We can use a global variable because we rely on the | 463 | +static void gptm_reload(gptm_state *s, int n, int reset) |
307 | + * iothread mutex to ensure only one reset operation is in a progress at a | 464 | +{ |
308 | + * given time. | 465 | + int64_t tick; |
309 | + */ | 466 | + if (reset) { |
310 | +static bool enter_phase_in_progress; | 467 | + tick = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); |
311 | + | 468 | + } else { |
312 | +void resettable_reset(Object *obj, ResetType type) | 469 | + tick = s->tick[n]; |
313 | +{ | ||
314 | + trace_resettable_reset(obj, type); | ||
315 | + resettable_assert_reset(obj, type); | ||
316 | + resettable_release_reset(obj, type); | ||
317 | +} | ||
318 | + | ||
319 | +void resettable_assert_reset(Object *obj, ResetType type) | ||
320 | +{ | ||
321 | + /* TODO: change this assert when adding support for other reset types */ | ||
322 | + assert(type == RESET_TYPE_COLD); | ||
323 | + trace_resettable_reset_assert_begin(obj, type); | ||
324 | + assert(!enter_phase_in_progress); | ||
325 | + | ||
326 | + enter_phase_in_progress = true; | ||
327 | + resettable_phase_enter(obj, NULL, type); | ||
328 | + enter_phase_in_progress = false; | ||
329 | + | ||
330 | + resettable_phase_hold(obj, NULL, type); | ||
331 | + | ||
332 | + trace_resettable_reset_assert_end(obj); | ||
333 | +} | ||
334 | + | ||
335 | +void resettable_release_reset(Object *obj, ResetType type) | ||
336 | +{ | ||
337 | + /* TODO: change this assert when adding support for other reset types */ | ||
338 | + assert(type == RESET_TYPE_COLD); | ||
339 | + trace_resettable_reset_release_begin(obj, type); | ||
340 | + assert(!enter_phase_in_progress); | ||
341 | + | ||
342 | + resettable_phase_exit(obj, NULL, type); | ||
343 | + | ||
344 | + trace_resettable_reset_release_end(obj); | ||
345 | +} | ||
346 | + | ||
347 | +bool resettable_is_in_reset(Object *obj) | ||
348 | +{ | ||
349 | + ResettableClass *rc = RESETTABLE_GET_CLASS(obj); | ||
350 | + ResettableState *s = rc->get_state(obj); | ||
351 | + | ||
352 | + return s->count > 0; | ||
353 | +} | ||
354 | + | ||
355 | +/** | ||
356 | + * resettable_child_foreach: | ||
357 | + * helper to avoid checking the existence of the method. | ||
358 | + */ | ||
359 | +static void resettable_child_foreach(ResettableClass *rc, Object *obj, | ||
360 | + ResettableChildCallback cb, | ||
361 | + void *opaque, ResetType type) | ||
362 | +{ | ||
363 | + if (rc->child_foreach) { | ||
364 | + rc->child_foreach(obj, cb, opaque, type); | ||
365 | + } | 470 | + } |
366 | +} | 471 | + |
367 | + | 472 | + if (s->config == 0) { |
368 | +/** | 473 | + /* 32-bit CountDown. */ |
369 | + * resettable_get_tr_func: | 474 | + uint32_t count; |
370 | + * helper to fetch transitional reset callback if any. | 475 | + count = s->load[0] | (s->load[1] << 16); |
371 | + */ | 476 | + tick += (int64_t)count * system_clock_scale; |
372 | +static ResettableTrFunction resettable_get_tr_func(ResettableClass *rc, | 477 | + } else if (s->config == 1) { |
373 | + Object *obj) | 478 | + /* 32-bit RTC. 1Hz tick. */ |
374 | +{ | 479 | + tick += NANOSECONDS_PER_SECOND; |
375 | + ResettableTrFunction tr_func = NULL; | 480 | + } else if (s->mode[n] == 0xa) { |
376 | + if (rc->get_transitional_function) { | 481 | + /* PWM mode. Not implemented. */ |
377 | + tr_func = rc->get_transitional_function(obj); | 482 | + } else { |
483 | + qemu_log_mask(LOG_UNIMP, | ||
484 | + "GPTM: 16-bit timer mode unimplemented: 0x%x\n", | ||
485 | + s->mode[n]); | ||
486 | + return; | ||
378 | + } | 487 | + } |
379 | + return tr_func; | 488 | + s->tick[n] = tick; |
380 | +} | 489 | + timer_mod(s->timer[n], tick); |
381 | + | 490 | +} |
382 | +static void resettable_phase_enter(Object *obj, void *opaque, ResetType type) | 491 | + |
383 | +{ | 492 | +static void gptm_tick(void *opaque) |
384 | + ResettableClass *rc = RESETTABLE_GET_CLASS(obj); | 493 | +{ |
385 | + ResettableState *s = rc->get_state(obj); | 494 | + gptm_state **p = (gptm_state **)opaque; |
386 | + const char *obj_typename = object_get_typename(obj); | 495 | + gptm_state *s; |
387 | + bool action_needed = false; | 496 | + int n; |
388 | + | 497 | + |
389 | + /* exit phase has to finish properly before entering back in reset */ | 498 | + s = *p; |
390 | + assert(!s->exit_phase_in_progress); | 499 | + n = p - s->opaque; |
391 | + | 500 | + if (s->config == 0) { |
392 | + trace_resettable_phase_enter_begin(obj, obj_typename, s->count, type); | 501 | + s->state |= 1; |
393 | + | 502 | + if ((s->control & 0x20)) { |
394 | + /* Only take action if we really enter reset for the 1st time. */ | 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; | ||
596 | + | ||
395 | + /* | 597 | + /* |
396 | + * TODO: if adding more ResetType support, some additional checks | 598 | + * The timers should be disabled before changing the configuration. |
397 | + * are probably needed here. | 599 | + * We take advantage of this and defer everything until the timer |
600 | + * is enabled. | ||
398 | + */ | 601 | + */ |
399 | + if (s->count++ == 0) { | 602 | + switch (offset) { |
400 | + action_needed = true; | 603 | + case 0x00: /* CFG */ |
604 | + s->config = value; | ||
605 | + break; | ||
606 | + case 0x04: /* TAMR */ | ||
607 | + s->mode[0] = value; | ||
608 | + break; | ||
609 | + case 0x08: /* TBMR */ | ||
610 | + s->mode[1] = value; | ||
611 | + break; | ||
612 | + case 0x0c: /* CTL */ | ||
613 | + oldval = s->control; | ||
614 | + s->control = value; | ||
615 | + /* TODO: Implement pause. */ | ||
616 | + if ((oldval ^ value) & 1) { | ||
617 | + if (value & 1) { | ||
618 | + gptm_reload(s, 0, 1); | ||
619 | + } else { | ||
620 | + gptm_stop(s, 0); | ||
621 | + } | ||
622 | + } | ||
623 | + if (((oldval ^ value) & 0x100) && s->config >= 4) { | ||
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); | ||
401 | + } | 672 | + } |
402 | + /* | 673 | + gptm_update_irq(s); |
403 | + * We limit the count to an arbitrary "big" value. The value is big | 674 | +} |
404 | + * enough not to be triggered normally. | 675 | + |
405 | + * The assert will stop an infinite loop if there is a cycle in the | 676 | +static const MemoryRegionOps gptm_ops = { |
406 | + * reset tree. The loop goes through resettable_foreach_child below | 677 | + .read = gptm_read, |
407 | + * which at some point will call us again. | 678 | + .write = gptm_write, |
408 | + */ | 679 | + .endianness = DEVICE_NATIVE_ENDIAN, |
409 | + assert(s->count <= 50); | 680 | +}; |
410 | + | 681 | + |
411 | + /* | 682 | +static const VMStateDescription vmstate_stellaris_gptm = { |
412 | + * handle the children even if action_needed is at false so that | 683 | + .name = "stellaris_gptm", |
413 | + * child counts are incremented too | 684 | + .version_id = 1, |
414 | + */ | 685 | + .minimum_version_id = 1, |
415 | + resettable_child_foreach(rc, obj, resettable_phase_enter, NULL, type); | 686 | + .fields = (VMStateField[]) { |
416 | + | 687 | + VMSTATE_UINT32(config, gptm_state), |
417 | + /* execute enter phase for the object if needed */ | 688 | + VMSTATE_UINT32_ARRAY(mode, gptm_state, 2), |
418 | + if (action_needed) { | 689 | + VMSTATE_UINT32(control, gptm_state), |
419 | + trace_resettable_phase_enter_exec(obj, obj_typename, type, | 690 | + VMSTATE_UINT32(state, gptm_state), |
420 | + !!rc->phases.enter); | 691 | + VMSTATE_UINT32(mask, gptm_state), |
421 | + if (rc->phases.enter && !resettable_get_tr_func(rc, obj)) { | 692 | + VMSTATE_UNUSED(8), |
422 | + rc->phases.enter(obj, type); | 693 | + VMSTATE_UINT32_ARRAY(load, gptm_state, 2), |
423 | + } | 694 | + VMSTATE_UINT32_ARRAY(match, gptm_state, 2), |
424 | + s->hold_phase_pending = true; | 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), | ||
700 | + VMSTATE_END_OF_LIST() | ||
425 | + } | 701 | + } |
426 | + trace_resettable_phase_enter_end(obj, obj_typename, s->count); | ||
427 | +} | ||
428 | + | ||
429 | +static void resettable_phase_hold(Object *obj, void *opaque, ResetType type) | ||
430 | +{ | ||
431 | + ResettableClass *rc = RESETTABLE_GET_CLASS(obj); | ||
432 | + ResettableState *s = rc->get_state(obj); | ||
433 | + const char *obj_typename = object_get_typename(obj); | ||
434 | + | ||
435 | + /* exit phase has to finish properly before entering back in reset */ | ||
436 | + assert(!s->exit_phase_in_progress); | ||
437 | + | ||
438 | + trace_resettable_phase_hold_begin(obj, obj_typename, s->count, type); | ||
439 | + | ||
440 | + /* handle children first */ | ||
441 | + resettable_child_foreach(rc, obj, resettable_phase_hold, NULL, type); | ||
442 | + | ||
443 | + /* exec hold phase */ | ||
444 | + if (s->hold_phase_pending) { | ||
445 | + s->hold_phase_pending = false; | ||
446 | + ResettableTrFunction tr_func = resettable_get_tr_func(rc, obj); | ||
447 | + trace_resettable_phase_hold_exec(obj, obj_typename, !!rc->phases.hold); | ||
448 | + if (tr_func) { | ||
449 | + trace_resettable_transitional_function(obj, obj_typename); | ||
450 | + tr_func(obj); | ||
451 | + } else if (rc->phases.hold) { | ||
452 | + rc->phases.hold(obj); | ||
453 | + } | ||
454 | + } | ||
455 | + trace_resettable_phase_hold_end(obj, obj_typename, s->count); | ||
456 | +} | ||
457 | + | ||
458 | +static void resettable_phase_exit(Object *obj, void *opaque, ResetType type) | ||
459 | +{ | ||
460 | + ResettableClass *rc = RESETTABLE_GET_CLASS(obj); | ||
461 | + ResettableState *s = rc->get_state(obj); | ||
462 | + const char *obj_typename = object_get_typename(obj); | ||
463 | + | ||
464 | + assert(!s->exit_phase_in_progress); | ||
465 | + trace_resettable_phase_exit_begin(obj, obj_typename, s->count, type); | ||
466 | + | ||
467 | + /* exit_phase_in_progress ensures this phase is 'atomic' */ | ||
468 | + s->exit_phase_in_progress = true; | ||
469 | + resettable_child_foreach(rc, obj, resettable_phase_exit, NULL, type); | ||
470 | + | ||
471 | + assert(s->count > 0); | ||
472 | + if (s->count == 1) { | ||
473 | + trace_resettable_phase_exit_exec(obj, obj_typename, !!rc->phases.exit); | ||
474 | + if (rc->phases.exit && !resettable_get_tr_func(rc, obj)) { | ||
475 | + rc->phases.exit(obj); | ||
476 | + } | ||
477 | + s->count = 0; | ||
478 | + } | ||
479 | + s->exit_phase_in_progress = false; | ||
480 | + trace_resettable_phase_exit_end(obj, obj_typename, s->count); | ||
481 | +} | ||
482 | + | ||
483 | +void resettable_class_set_parent_phases(ResettableClass *rc, | ||
484 | + ResettableEnterPhase enter, | ||
485 | + ResettableHoldPhase hold, | ||
486 | + ResettableExitPhase exit, | ||
487 | + ResettablePhases *parent_phases) | ||
488 | +{ | ||
489 | + *parent_phases = rc->phases; | ||
490 | + if (enter) { | ||
491 | + rc->phases.enter = enter; | ||
492 | + } | ||
493 | + if (hold) { | ||
494 | + rc->phases.hold = hold; | ||
495 | + } | ||
496 | + if (exit) { | ||
497 | + rc->phases.exit = exit; | ||
498 | + } | ||
499 | +} | ||
500 | + | ||
501 | +static const TypeInfo resettable_interface_info = { | ||
502 | + .name = TYPE_RESETTABLE_INTERFACE, | ||
503 | + .parent = TYPE_INTERFACE, | ||
504 | + .class_size = sizeof(ResettableClass), | ||
505 | +}; | 702 | +}; |
506 | + | 703 | + |
507 | +static void reset_register_types(void) | 704 | +static void stellaris_gptm_init(Object *obj) |
508 | +{ | 705 | +{ |
509 | + type_register_static(&resettable_interface_info); | 706 | + DeviceState *dev = DEVICE(obj); |
510 | +} | 707 | + gptm_state *s = STELLARIS_GPTM(obj); |
511 | + | 708 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); |
512 | +type_init(reset_register_types) | 709 | + |
513 | diff --git a/hw/core/trace-events b/hw/core/trace-events | 710 | + sysbus_init_irq(sbd, &s->irq); |
711 | + qdev_init_gpio_out(dev, &s->trigger, 1); | ||
712 | + | ||
713 | + memory_region_init_io(&s->iomem, obj, &gptm_ops, s, | ||
714 | + "gptm", 0x1000); | ||
715 | + sysbus_init_mmio(sbd, &s->iomem); | ||
716 | + | ||
717 | + s->opaque[0] = s->opaque[1] = s; | ||
718 | +} | ||
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) | ||
728 | +{ | ||
729 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
730 | + | ||
731 | + dc->vmsd = &vmstate_stellaris_gptm; | ||
732 | + dc->realize = stellaris_gptm_realize; | ||
733 | +} | ||
734 | + | ||
735 | +static const TypeInfo stellaris_gptm_info = { | ||
736 | + .name = TYPE_STELLARIS_GPTM, | ||
737 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
738 | + .instance_size = sizeof(gptm_state), | ||
739 | + .instance_init = stellaris_gptm_init, | ||
740 | + .class_init = stellaris_gptm_class_init, | ||
741 | +}; | ||
742 | + | ||
743 | +static void stellaris_gptm_register_types(void) | ||
744 | +{ | ||
745 | + type_register_static(&stellaris_gptm_info); | ||
746 | +} | ||
747 | + | ||
748 | +type_init(stellaris_gptm_register_types) | ||
749 | diff --git a/hw/arm/Kconfig b/hw/arm/Kconfig | ||
514 | index XXXXXXX..XXXXXXX 100644 | 750 | index XXXXXXX..XXXXXXX 100644 |
515 | --- a/hw/core/trace-events | 751 | --- a/hw/arm/Kconfig |
516 | +++ b/hw/core/trace-events | 752 | +++ b/hw/arm/Kconfig |
517 | @@ -XXX,XX +XXX,XX @@ qbus_reset(void *obj, const char *objtype) "obj=%p(%s)" | 753 | @@ -XXX,XX +XXX,XX @@ config STELLARIS |
518 | qbus_reset_all(void *obj, const char *objtype) "obj=%p(%s)" | 754 | select SSI_SD |
519 | qbus_reset_tree(void *obj, const char *objtype) "obj=%p(%s)" | 755 | select STELLARIS_INPUT |
520 | qdev_update_parent_bus(void *obj, const char *objtype, void *oldp, const char *oldptype, void *newp, const char *newptype) "obj=%p(%s) old_parent=%p(%s) new_parent=%p(%s)" | 756 | select STELLARIS_ENET # ethernet |
521 | + | 757 | + select STELLARIS_GPTM # general purpose timer module |
522 | +# resettable.c | 758 | select UNIMP |
523 | +resettable_reset(void *obj, int cold) "obj=%p cold=%d" | 759 | |
524 | +resettable_reset_assert_begin(void *obj, int cold) "obj=%p cold=%d" | 760 | config STM32VLDISCOVERY |
525 | +resettable_reset_assert_end(void *obj) "obj=%p" | 761 | diff --git a/hw/timer/Kconfig b/hw/timer/Kconfig |
526 | +resettable_reset_release_begin(void *obj, int cold) "obj=%p cold=%d" | 762 | index XXXXXXX..XXXXXXX 100644 |
527 | +resettable_reset_release_end(void *obj) "obj=%p" | 763 | --- a/hw/timer/Kconfig |
528 | +resettable_phase_enter_begin(void *obj, const char *objtype, unsigned count, int type) "obj=%p(%s) count=%d type=%d" | 764 | +++ b/hw/timer/Kconfig |
529 | +resettable_phase_enter_exec(void *obj, const char *objtype, int type, int has_method) "obj=%p(%s) type=%d method=%d" | 765 | @@ -XXX,XX +XXX,XX @@ config SSE_COUNTER |
530 | +resettable_phase_enter_end(void *obj, const char *objtype, unsigned count) "obj=%p(%s) count=%d" | 766 | config SSE_TIMER |
531 | +resettable_phase_hold_begin(void *obj, const char *objtype, unsigned count, int type) "obj=%p(%s) count=%d type=%d" | 767 | bool |
532 | +resettable_phase_hold_exec(void *obj, const char *objtype, int has_method) "obj=%p(%s) method=%d" | 768 | |
533 | +resettable_phase_hold_end(void *obj, const char *objtype, unsigned count) "obj=%p(%s) count=%d" | 769 | +config STELLARIS_GPTM |
534 | +resettable_phase_exit_begin(void *obj, const char *objtype, unsigned count, int type) "obj=%p(%s) count=%d type=%d" | 770 | + bool |
535 | +resettable_phase_exit_exec(void *obj, const char *objtype, int has_method) "obj=%p(%s) method=%d" | 771 | + |
536 | +resettable_phase_exit_end(void *obj, const char *objtype, unsigned count) "obj=%p(%s) count=%d" | 772 | config AVR_TIMER16 |
537 | +resettable_transitional_function(void *obj, const char *objtype) "obj=%p(%s)" | 773 | bool |
774 | diff --git a/hw/timer/meson.build b/hw/timer/meson.build | ||
775 | index XXXXXXX..XXXXXXX 100644 | ||
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')) | ||
538 | -- | 786 | -- |
539 | 2.20.1 | 787 | 2.20.1 |
540 | 788 | ||
541 | 789 | diff view generated by jsdifflib |
1 | The num-lines property of the TYPE_OR_GATE device sets the number | 1 | The stellaris-gptm timer currently uses system_clock_scale for one of |
---|---|---|---|
2 | of input lines it has. An assert() in or_irq_realize() restricts | 2 | its timer modes where the timer runs at the CPU clock rate. Make it |
3 | this to the maximum supported by the implementation. However we | 3 | use a Clock input instead. |
4 | got the condition in the assert wrong: it should be using <=, | ||
5 | because num-lines == MAX_OR_LINES is permitted, and means that | ||
6 | all entries from 0 to MAX_OR_LINES-1 in the s->levels[] array | ||
7 | are used. | ||
8 | 4 | ||
9 | We didn't notice this previously because no user has so far | 5 | We don't try to make the timer handle changes in the clock frequency |
10 | needed that many input lines. | 6 | while the downcounter is running. This is not a change in behaviour |
7 | from the previous system_clock_scale implementation -- we will pick | ||
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. | ||
11 | 11 | ||
12 | Reported-by: Guenter Roeck <linux@roeck-us.net> | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 13 | Reviewed-by: Damien Hedde <damien.hedde@greensocs.com> |
15 | Reviewed-by: Guenter Roeck <linux@roeck-us.net> | 14 | Message-id: 20210812093356.1946-25-peter.maydell@linaro.org |
16 | Message-id: 20200120142235.10432-1-peter.maydell@linaro.org | ||
17 | --- | 15 | --- |
18 | hw/core/or-irq.c | 2 +- | 16 | include/hw/timer/stellaris-gptm.h | 3 +++ |
19 | 1 file changed, 1 insertion(+), 1 deletion(-) | 17 | hw/arm/stellaris.c | 12 +++++++++--- |
18 | hw/timer/stellaris-gptm.c | 26 ++++++++++++++++++++++---- | ||
19 | 3 files changed, 34 insertions(+), 7 deletions(-) | ||
20 | 20 | ||
21 | diff --git a/hw/core/or-irq.c b/hw/core/or-irq.c | 21 | diff --git a/include/hw/timer/stellaris-gptm.h b/include/hw/timer/stellaris-gptm.h |
22 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/core/or-irq.c | 23 | --- a/include/hw/timer/stellaris-gptm.h |
24 | +++ b/hw/core/or-irq.c | 24 | +++ b/include/hw/timer/stellaris-gptm.h |
25 | @@ -XXX,XX +XXX,XX @@ static void or_irq_realize(DeviceState *dev, Error **errp) | 25 | @@ -XXX,XX +XXX,XX @@ |
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 | |||
48 | #endif | ||
49 | diff --git a/hw/arm/stellaris.c b/hw/arm/stellaris.c | ||
50 | index XXXXXXX..XXXXXXX 100644 | ||
51 | --- a/hw/arm/stellaris.c | ||
52 | +++ b/hw/arm/stellaris.c | ||
53 | @@ -XXX,XX +XXX,XX @@ static void stellaris_init(MachineState *ms, stellaris_board_info *board) | ||
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) | ||
26 | { | 87 | { |
27 | qemu_or_irq *s = OR_IRQ(dev); | 88 | @@ -XXX,XX +XXX,XX @@ static void gptm_reload(gptm_state *s, int n, int reset) |
28 | 89 | /* 32-bit CountDown. */ | |
29 | - assert(s->num_lines < MAX_OR_LINES); | 90 | uint32_t count; |
30 | + assert(s->num_lines <= MAX_OR_LINES); | 91 | count = s->load[0] | (s->load[1] << 16); |
31 | 92 | - tick += (int64_t)count * system_clock_scale; | |
32 | qdev_init_gpio_in(dev, or_irq_handler, s->num_lines); | 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]); | ||
33 | } | 143 | } |
34 | -- | 144 | -- |
35 | 2.20.1 | 145 | 2.20.1 |
36 | 146 | ||
37 | 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 |