1 | First arm pullreq of the 5.1 cycle; mostly bugfixes and some | 1 | Two small bugfixes, plus most of RTH's refactoring of cpregs |
---|---|---|---|
2 | cleanup patches. The new clock modelling framework is the big | 2 | handling. |
3 | thing here. | ||
4 | 3 | ||
5 | -- PMM | 4 | -- PMM |
6 | 5 | ||
7 | The following changes since commit 648db19685b7030aa558a4ddbd3a8e53d8c9a062: | 6 | The following changes since commit 1fba9dc71a170b3a05b9d3272dd8ecfe7f26e215: |
8 | 7 | ||
9 | Merge remote-tracking branch 'remotes/armbru/tags/pull-misc-2020-04-29' into staging (2020-04-29 15:07:33 +0100) | 8 | Merge tag 'pull-request-2022-05-04' of https://gitlab.com/thuth/qemu into staging (2022-05-04 08:07:02 -0700) |
10 | 9 | ||
11 | are available in the Git repository at: | 10 | are available in the Git repository at: |
12 | 11 | ||
13 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200430 | 12 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20220505 |
14 | 13 | ||
15 | for you to fetch changes up to 1267437e593e85498f9105b3bdab796630d2e83f: | 14 | for you to fetch changes up to 99a50d1a67c602126fc2b3a4812d3000eba9bf34: |
16 | 15 | ||
17 | hw/arm: xlnx-zcu102: Disable unsupported FDT firmware nodes (2020-04-30 11:52:29 +0100) | 16 | target/arm: read access to performance counters from EL0 (2022-05-05 09:36:22 +0100) |
18 | 17 | ||
19 | ---------------------------------------------------------------- | 18 | ---------------------------------------------------------------- |
20 | target-arm queue: | 19 | target-arm queue: |
21 | * xlnx-zdma: Fix endianness handling of descriptor loading | 20 | * Enable read access to performance counters from EL0 |
22 | * nrf51: Fix last GPIO CNF address | 21 | * Enable SCTLR_EL1.BT0 for aarch64-linux-user |
23 | * gicv3: Use gicr_typer in arm_gicv3_icc_reset | 22 | * Refactoring of cpreg handling |
24 | * msf2: Add EMAC block to SmartFusion2 SoC | ||
25 | * New clock modelling framework | ||
26 | * hw/arm: versal: Setup the ADMA with 128bit bus-width | ||
27 | * Cadence: gem: fix wraparound in 64bit descriptors | ||
28 | * cadence_gem: clear RX control descriptor | ||
29 | * target/arm: Vectorize integer comparison vs zero | ||
30 | * hw/arm/virt: dt: add kaslr-seed property | ||
31 | * hw/arm: xlnx-zcu102: Disable unsupported FDT firmware nodes | ||
32 | 23 | ||
33 | ---------------------------------------------------------------- | 24 | ---------------------------------------------------------------- |
34 | Cameron Esfahani (1): | 25 | Alex Zuepke (1): |
35 | nrf51: Fix last GPIO CNF address | 26 | target/arm: read access to performance counters from EL0 |
36 | 27 | ||
37 | Damien Hedde (7): | 28 | Richard Henderson (22): |
38 | hw/core/clock-vmstate: define a vmstate entry for clock state | 29 | target/arm: Enable SCTLR_EL1.BT0 for aarch64-linux-user |
39 | qdev: add clock input&output support to devices. | 30 | target/arm: Split out cpregs.h |
40 | qdev-clock: introduce an init array to ease the device construction | 31 | target/arm: Reorg CPAccessResult and access_check_cp_reg |
41 | hw/misc/zynq_slcr: add clock generation for uarts | 32 | target/arm: Replace sentinels with ARRAY_SIZE in cpregs.h |
42 | hw/char/cadence_uart: add clock support | 33 | target/arm: Make some more cpreg data static const |
43 | hw/arm/xilinx_zynq: connect uart clocks to slcr | 34 | target/arm: Reorg ARMCPRegInfo type field bits |
44 | qdev-monitor: print the device's clock with info qtree | 35 | target/arm: Avoid bare abort() or assert(0) |
36 | target/arm: Change cpreg access permissions to enum | ||
37 | target/arm: Name CPState type | ||
38 | target/arm: Name CPSecureState type | ||
39 | target/arm: Drop always-true test in define_arm_vh_e2h_redirects_aliases | ||
40 | target/arm: Store cpregs key in the hash table directly | ||
41 | target/arm: Merge allocation of the cpreg and its name | ||
42 | target/arm: Hoist computation of key in add_cpreg_to_hashtable | ||
43 | target/arm: Consolidate cpreg updates in add_cpreg_to_hashtable | ||
44 | target/arm: Use bool for is64 and ns in add_cpreg_to_hashtable | ||
45 | target/arm: Hoist isbanked computation in add_cpreg_to_hashtable | ||
46 | target/arm: Perform override check early in add_cpreg_to_hashtable | ||
47 | target/arm: Reformat comments in add_cpreg_to_hashtable | ||
48 | target/arm: Remove HOST_BIG_ENDIAN ifdef in add_cpreg_to_hashtable | ||
49 | target/arm: Add isar predicates for FEAT_Debugv8p2 | ||
50 | target/arm: Add isar_feature_{aa64,any}_ras | ||
45 | 51 | ||
46 | Edgar E. Iglesias (7): | 52 | target/arm/cpregs.h | 453 ++++++++++++++++++++++++++++++++++++++ |
47 | dma/xlnx-zdma: Fix descriptor loading (MEM) wrt endianness | 53 | target/arm/cpu.h | 393 +++------------------------------ |
48 | dma/xlnx-zdma: Fix descriptor loading (REG) wrt endianness | 54 | hw/arm/pxa2xx.c | 2 +- |
49 | hw/arm: versal: Setup the ADMA with 128bit bus-width | 55 | hw/arm/pxa2xx_pic.c | 2 +- |
50 | device_tree: Allow name wildcards in qemu_fdt_node_path() | 56 | hw/intc/arm_gicv3_cpuif.c | 6 +- |
51 | device_tree: Constify compat in qemu_fdt_node_path() | 57 | hw/intc/arm_gicv3_kvm.c | 3 +- |
52 | hw/arm: xlnx-zcu102: Move arm_boot_info into XlnxZCU102 | 58 | target/arm/cpu.c | 25 +-- |
53 | hw/arm: xlnx-zcu102: Disable unsupported FDT firmware nodes | 59 | target/arm/cpu64.c | 2 +- |
54 | 60 | target/arm/cpu_tcg.c | 5 +- | |
55 | Jerome Forissier (2): | 61 | target/arm/gdbstub.c | 5 +- |
56 | hw/arm/virt: dt: move creation of /secure-chosen to create_fdt() | 62 | target/arm/helper.c | 358 +++++++++++++----------------- |
57 | hw/arm/virt: dt: add kaslr-seed property | 63 | target/arm/hvf/hvf.c | 2 +- |
58 | 64 | target/arm/kvm-stub.c | 4 +- | |
59 | Keqian Zhu (2): | 65 | target/arm/kvm.c | 4 +- |
60 | bugfix: Use gicr_typer in arm_gicv3_icc_reset | 66 | target/arm/machine.c | 4 +- |
61 | Typo: Correct the name of CPU hotplug memory region | 67 | target/arm/op_helper.c | 57 ++--- |
62 | 68 | target/arm/translate-a64.c | 14 +- | |
63 | Peter Maydell (2): | 69 | target/arm/translate-neon.c | 2 +- |
64 | hw/core/clock: introduce clock object | 70 | target/arm/translate.c | 13 +- |
65 | docs/clocks: add device's clock documentation | 71 | tests/tcg/aarch64/bti-3.c | 42 ++++ |
66 | 72 | tests/tcg/aarch64/Makefile.target | 6 +- | |
67 | Philippe Mathieu-Daudé (3): | 73 | 21 files changed, 738 insertions(+), 664 deletions(-) |
68 | target/arm: Restrict the Address Translate write operation to TCG accel | 74 | create mode 100644 target/arm/cpregs.h |
69 | target/arm/cpu: Use ARRAY_SIZE() to iterate over ARMCPUInfo[] | 75 | create mode 100644 tests/tcg/aarch64/bti-3.c |
70 | target/arm/cpu: Update coding style to make checkpatch.pl happy | ||
71 | |||
72 | Ramon Fried (2): | ||
73 | Cadence: gem: fix wraparound in 64bit descriptors | ||
74 | net: cadence_gem: clear RX control descriptor | ||
75 | |||
76 | Richard Henderson (1): | ||
77 | target/arm: Vectorize integer comparison vs zero | ||
78 | |||
79 | Subbaraya Sundeep (3): | ||
80 | hw/net: Add Smartfusion2 emac block | ||
81 | msf2: Add EMAC block to SmartFusion2 SoC | ||
82 | tests/boot_linux_console: Add ethernet test to SmartFusion2 | ||
83 | |||
84 | Thomas Huth (1): | ||
85 | target/arm: Make cpu_register() available for other files | ||
86 | |||
87 | hw/core/Makefile.objs | 2 + | ||
88 | hw/net/Makefile.objs | 1 + | ||
89 | tests/Makefile.include | 1 + | ||
90 | include/hw/arm/msf2-soc.h | 2 + | ||
91 | include/hw/char/cadence_uart.h | 1 + | ||
92 | include/hw/clock.h | 225 +++++++++++++ | ||
93 | include/hw/gpio/nrf51_gpio.h | 2 +- | ||
94 | include/hw/net/msf2-emac.h | 53 +++ | ||
95 | include/hw/qdev-clock.h | 159 +++++++++ | ||
96 | include/hw/qdev-core.h | 12 + | ||
97 | include/sysemu/device_tree.h | 5 +- | ||
98 | target/arm/cpu-qom.h | 9 +- | ||
99 | target/arm/helper.h | 27 +- | ||
100 | target/arm/translate.h | 5 + | ||
101 | device_tree.c | 4 +- | ||
102 | hw/acpi/cpu.c | 2 +- | ||
103 | hw/arm/msf2-soc.c | 26 +- | ||
104 | hw/arm/virt.c | 20 +- | ||
105 | hw/arm/xilinx_zynq.c | 57 +++- | ||
106 | hw/arm/xlnx-versal.c | 2 + | ||
107 | hw/arm/xlnx-zcu102.c | 39 ++- | ||
108 | hw/char/cadence_uart.c | 73 +++- | ||
109 | hw/core/clock-vmstate.c | 25 ++ | ||
110 | hw/core/clock.c | 130 ++++++++ | ||
111 | hw/core/qdev-clock.c | 185 +++++++++++ | ||
112 | hw/core/qdev.c | 12 + | ||
113 | hw/dma/xlnx-zdma.c | 25 +- | ||
114 | hw/intc/arm_gicv3_kvm.c | 4 +- | ||
115 | hw/misc/zynq_slcr.c | 172 +++++++++- | ||
116 | hw/net/cadence_gem.c | 16 +- | ||
117 | hw/net/msf2-emac.c | 589 +++++++++++++++++++++++++++++++++ | ||
118 | qdev-monitor.c | 9 + | ||
119 | target/arm/cpu.c | 25 +- | ||
120 | target/arm/cpu64.c | 16 +- | ||
121 | target/arm/helper.c | 17 + | ||
122 | target/arm/neon_helper.c | 24 -- | ||
123 | target/arm/translate-a64.c | 64 +--- | ||
124 | target/arm/translate.c | 256 ++++++++++++-- | ||
125 | target/arm/vec_helper.c | 25 ++ | ||
126 | MAINTAINERS | 2 + | ||
127 | docs/devel/clocks.rst | 391 ++++++++++++++++++++++ | ||
128 | docs/devel/index.rst | 1 + | ||
129 | hw/char/trace-events | 3 + | ||
130 | hw/core/trace-events | 7 + | ||
131 | tests/acceptance/boot_linux_console.py | 15 +- | ||
132 | 45 files changed, 2538 insertions(+), 202 deletions(-) | ||
133 | create mode 100644 include/hw/clock.h | ||
134 | create mode 100644 include/hw/net/msf2-emac.h | ||
135 | create mode 100644 include/hw/qdev-clock.h | ||
136 | create mode 100644 hw/core/clock-vmstate.c | ||
137 | create mode 100644 hw/core/clock.c | ||
138 | create mode 100644 hw/core/qdev-clock.c | ||
139 | create mode 100644 hw/net/msf2-emac.c | ||
140 | create mode 100644 docs/devel/clocks.rst | ||
141 | diff view generated by jsdifflib |
1 | From: Subbaraya Sundeep <sundeep.lkml@gmail.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Modelled Ethernet MAC of Smartfusion2 SoC. | 3 | This controls whether the PACI{A,B}SP instructions trap with BTYPE=3 |
4 | Micrel KSZ8051 PHY is present on Emcraft's | 4 | (indirect branch from register other than x16/x17). The linux kernel |
5 | SOM kit hence same PHY is emulated. | 5 | sets this in bti_enable(). |
6 | 6 | ||
7 | Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com> | 7 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/998 |
8 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Message-id: 1587048891-30493-2-git-send-email-sundeep.lkml@gmail.com | 10 | Message-id: 20220427042312.294300-1-richard.henderson@linaro.org |
11 | [PMM: remove stray change to makefile comment] | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 13 | --- |
13 | hw/net/Makefile.objs | 1 + | 14 | target/arm/cpu.c | 2 ++ |
14 | include/hw/net/msf2-emac.h | 53 ++++ | 15 | tests/tcg/aarch64/bti-3.c | 42 +++++++++++++++++++++++++++++++ |
15 | hw/net/msf2-emac.c | 589 +++++++++++++++++++++++++++++++++++++ | 16 | tests/tcg/aarch64/Makefile.target | 6 ++--- |
16 | MAINTAINERS | 2 + | 17 | 3 files changed, 47 insertions(+), 3 deletions(-) |
17 | 4 files changed, 645 insertions(+) | 18 | create mode 100644 tests/tcg/aarch64/bti-3.c |
18 | create mode 100644 include/hw/net/msf2-emac.h | ||
19 | create mode 100644 hw/net/msf2-emac.c | ||
20 | 19 | ||
21 | diff --git a/hw/net/Makefile.objs b/hw/net/Makefile.objs | 20 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
22 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/hw/net/Makefile.objs | 22 | --- a/target/arm/cpu.c |
24 | +++ b/hw/net/Makefile.objs | 23 | +++ b/target/arm/cpu.c |
25 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_ROCKER) += rocker/rocker.o rocker/rocker_fp.o \ | 24 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) |
26 | obj-$(call lnot,$(CONFIG_ROCKER)) += rocker/qmp-norocker.o | 25 | /* Enable all PAC keys. */ |
27 | 26 | env->cp15.sctlr_el[1] |= (SCTLR_EnIA | SCTLR_EnIB | | |
28 | common-obj-$(CONFIG_CAN_BUS) += can/ | 27 | SCTLR_EnDA | SCTLR_EnDB); |
29 | +common-obj-$(CONFIG_MSF2) += msf2-emac.o | 28 | + /* Trap on btype=3 for PACIxSP. */ |
30 | diff --git a/include/hw/net/msf2-emac.h b/include/hw/net/msf2-emac.h | 29 | + env->cp15.sctlr_el[1] |= SCTLR_BT0; |
30 | /* and to the FP/Neon instructions */ | ||
31 | env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 20, 2, 3); | ||
32 | /* and to the SVE instructions */ | ||
33 | diff --git a/tests/tcg/aarch64/bti-3.c b/tests/tcg/aarch64/bti-3.c | ||
31 | new file mode 100644 | 34 | new file mode 100644 |
32 | index XXXXXXX..XXXXXXX | 35 | index XXXXXXX..XXXXXXX |
33 | --- /dev/null | 36 | --- /dev/null |
34 | +++ b/include/hw/net/msf2-emac.h | 37 | +++ b/tests/tcg/aarch64/bti-3.c |
35 | @@ -XXX,XX +XXX,XX @@ | 38 | @@ -XXX,XX +XXX,XX @@ |
36 | +/* | 39 | +/* |
37 | + * QEMU model of the Smartfusion2 Ethernet MAC. | 40 | + * BTI vs PACIASP |
38 | + * | ||
39 | + * Copyright (c) 2020 Subbaraya Sundeep <sundeep.lkml@gmail.com>. | ||
40 | + * | ||
41 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
42 | + * of this software and associated documentation files (the "Software"), to deal | ||
43 | + * in the Software without restriction, including without limitation the rights | ||
44 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
45 | + * copies of the Software, and to permit persons to whom the Software is | ||
46 | + * furnished to do so, subject to the following conditions: | ||
47 | + * | ||
48 | + * The above copyright notice and this permission notice shall be included in | ||
49 | + * all copies or substantial portions of the Software. | ||
50 | + * | ||
51 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
52 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
53 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
54 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
55 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
56 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
57 | + * THE SOFTWARE. | ||
58 | + */ | 41 | + */ |
59 | + | 42 | + |
60 | +#include "hw/sysbus.h" | 43 | +#include "bti-crt.inc.c" |
61 | +#include "exec/memory.h" | ||
62 | +#include "net/net.h" | ||
63 | +#include "net/eth.h" | ||
64 | + | 44 | + |
65 | +#define TYPE_MSS_EMAC "msf2-emac" | 45 | +static void skip2_sigill(int sig, siginfo_t *info, ucontext_t *uc) |
66 | +#define MSS_EMAC(obj) \ | ||
67 | + OBJECT_CHECK(MSF2EmacState, (obj), TYPE_MSS_EMAC) | ||
68 | + | ||
69 | +#define R_MAX (0x1a0 / 4) | ||
70 | +#define PHY_MAX_REGS 32 | ||
71 | + | ||
72 | +typedef struct MSF2EmacState { | ||
73 | + SysBusDevice parent; | ||
74 | + | ||
75 | + MemoryRegion mmio; | ||
76 | + MemoryRegion *dma_mr; | ||
77 | + AddressSpace dma_as; | ||
78 | + | ||
79 | + qemu_irq irq; | ||
80 | + NICState *nic; | ||
81 | + NICConf conf; | ||
82 | + | ||
83 | + uint8_t mac_addr[ETH_ALEN]; | ||
84 | + uint32_t rx_desc; | ||
85 | + uint16_t phy_regs[PHY_MAX_REGS]; | ||
86 | + | ||
87 | + uint32_t regs[R_MAX]; | ||
88 | +} MSF2EmacState; | ||
89 | diff --git a/hw/net/msf2-emac.c b/hw/net/msf2-emac.c | ||
90 | new file mode 100644 | ||
91 | index XXXXXXX..XXXXXXX | ||
92 | --- /dev/null | ||
93 | +++ b/hw/net/msf2-emac.c | ||
94 | @@ -XXX,XX +XXX,XX @@ | ||
95 | +/* | ||
96 | + * QEMU model of the Smartfusion2 Ethernet MAC. | ||
97 | + * | ||
98 | + * Copyright (c) 2020 Subbaraya Sundeep <sundeep.lkml@gmail.com>. | ||
99 | + * | ||
100 | + * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
101 | + * of this software and associated documentation files (the "Software"), to deal | ||
102 | + * in the Software without restriction, including without limitation the rights | ||
103 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
104 | + * copies of the Software, and to permit persons to whom the Software is | ||
105 | + * furnished to do so, subject to the following conditions: | ||
106 | + * | ||
107 | + * The above copyright notice and this permission notice shall be included in | ||
108 | + * all copies or substantial portions of the Software. | ||
109 | + * | ||
110 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
111 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
112 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | ||
113 | + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
114 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
115 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
116 | + * THE SOFTWARE. | ||
117 | + * | ||
118 | + * Refer to section Ethernet MAC in the document: | ||
119 | + * UG0331: SmartFusion2 Microcontroller Subsystem User Guide | ||
120 | + * Datasheet URL: | ||
121 | + * https://www.microsemi.com/document-portal/cat_view/56661-internal-documents/ | ||
122 | + * 56758-soc?lang=en&limit=20&limitstart=220 | ||
123 | + */ | ||
124 | + | ||
125 | +#include "qemu/osdep.h" | ||
126 | +#include "qemu-common.h" | ||
127 | +#include "qemu/log.h" | ||
128 | +#include "qapi/error.h" | ||
129 | +#include "exec/address-spaces.h" | ||
130 | +#include "hw/registerfields.h" | ||
131 | +#include "hw/net/msf2-emac.h" | ||
132 | +#include "hw/net/mii.h" | ||
133 | +#include "hw/irq.h" | ||
134 | +#include "hw/qdev-properties.h" | ||
135 | +#include "migration/vmstate.h" | ||
136 | + | ||
137 | +REG32(CFG1, 0x0) | ||
138 | + FIELD(CFG1, RESET, 31, 1) | ||
139 | + FIELD(CFG1, RX_EN, 2, 1) | ||
140 | + FIELD(CFG1, TX_EN, 0, 1) | ||
141 | + FIELD(CFG1, LB_EN, 8, 1) | ||
142 | +REG32(CFG2, 0x4) | ||
143 | +REG32(IFG, 0x8) | ||
144 | +REG32(HALF_DUPLEX, 0xc) | ||
145 | +REG32(MAX_FRAME_LENGTH, 0x10) | ||
146 | +REG32(MII_CMD, 0x24) | ||
147 | + FIELD(MII_CMD, READ, 0, 1) | ||
148 | +REG32(MII_ADDR, 0x28) | ||
149 | + FIELD(MII_ADDR, REGADDR, 0, 5) | ||
150 | + FIELD(MII_ADDR, PHYADDR, 8, 5) | ||
151 | +REG32(MII_CTL, 0x2c) | ||
152 | +REG32(MII_STS, 0x30) | ||
153 | +REG32(STA1, 0x40) | ||
154 | +REG32(STA2, 0x44) | ||
155 | +REG32(FIFO_CFG0, 0x48) | ||
156 | +REG32(FIFO_CFG4, 0x58) | ||
157 | + FIELD(FIFO_CFG4, BCAST, 9, 1) | ||
158 | + FIELD(FIFO_CFG4, MCAST, 8, 1) | ||
159 | +REG32(FIFO_CFG5, 0x5C) | ||
160 | + FIELD(FIFO_CFG5, BCAST, 9, 1) | ||
161 | + FIELD(FIFO_CFG5, MCAST, 8, 1) | ||
162 | +REG32(DMA_TX_CTL, 0x180) | ||
163 | + FIELD(DMA_TX_CTL, EN, 0, 1) | ||
164 | +REG32(DMA_TX_DESC, 0x184) | ||
165 | +REG32(DMA_TX_STATUS, 0x188) | ||
166 | + FIELD(DMA_TX_STATUS, PKTCNT, 16, 8) | ||
167 | + FIELD(DMA_TX_STATUS, UNDERRUN, 1, 1) | ||
168 | + FIELD(DMA_TX_STATUS, PKT_SENT, 0, 1) | ||
169 | +REG32(DMA_RX_CTL, 0x18c) | ||
170 | + FIELD(DMA_RX_CTL, EN, 0, 1) | ||
171 | +REG32(DMA_RX_DESC, 0x190) | ||
172 | +REG32(DMA_RX_STATUS, 0x194) | ||
173 | + FIELD(DMA_RX_STATUS, PKTCNT, 16, 8) | ||
174 | + FIELD(DMA_RX_STATUS, OVERFLOW, 2, 1) | ||
175 | + FIELD(DMA_RX_STATUS, PKT_RCVD, 0, 1) | ||
176 | +REG32(DMA_IRQ_MASK, 0x198) | ||
177 | +REG32(DMA_IRQ, 0x19c) | ||
178 | + | ||
179 | +#define EMPTY_MASK (1 << 31) | ||
180 | +#define PKT_SIZE 0x7FF | ||
181 | +#define PHYADDR 0x1 | ||
182 | +#define MAX_PKT_SIZE 2048 | ||
183 | + | ||
184 | +typedef struct { | ||
185 | + uint32_t pktaddr; | ||
186 | + uint32_t pktsize; | ||
187 | + uint32_t next; | ||
188 | +} EmacDesc; | ||
189 | + | ||
190 | +static uint32_t emac_get_isr(MSF2EmacState *s) | ||
191 | +{ | 46 | +{ |
192 | + uint32_t ier = s->regs[R_DMA_IRQ_MASK]; | 47 | + uc->uc_mcontext.pc += 8; |
193 | + uint32_t tx = s->regs[R_DMA_TX_STATUS] & 0xF; | 48 | + uc->uc_mcontext.pstate = 1; |
194 | + uint32_t rx = s->regs[R_DMA_RX_STATUS] & 0xF; | ||
195 | + uint32_t isr = (rx << 4) | tx; | ||
196 | + | ||
197 | + s->regs[R_DMA_IRQ] = ier & isr; | ||
198 | + return s->regs[R_DMA_IRQ]; | ||
199 | +} | 49 | +} |
200 | + | 50 | + |
201 | +static void emac_update_irq(MSF2EmacState *s) | 51 | +#define BTYPE_1() \ |
52 | + asm("mov %0,#1; adr x16, 1f; br x16; 1: hint #25; mov %0,#0" \ | ||
53 | + : "=r"(skipped) : : "x16", "x30") | ||
54 | + | ||
55 | +#define BTYPE_2() \ | ||
56 | + asm("mov %0,#1; adr x16, 1f; blr x16; 1: hint #25; mov %0,#0" \ | ||
57 | + : "=r"(skipped) : : "x16", "x30") | ||
58 | + | ||
59 | +#define BTYPE_3() \ | ||
60 | + asm("mov %0,#1; adr x15, 1f; br x15; 1: hint #25; mov %0,#0" \ | ||
61 | + : "=r"(skipped) : : "x15", "x30") | ||
62 | + | ||
63 | +#define TEST(WHICH, EXPECT) \ | ||
64 | + do { WHICH(); fail += skipped ^ EXPECT; } while (0) | ||
65 | + | ||
66 | +int main() | ||
202 | +{ | 67 | +{ |
203 | + bool intr = emac_get_isr(s); | 68 | + int fail = 0; |
69 | + int skipped; | ||
204 | + | 70 | + |
205 | + qemu_set_irq(s->irq, intr); | 71 | + /* Signal-like with SA_SIGINFO. */ |
72 | + signal_info(SIGILL, skip2_sigill); | ||
73 | + | ||
74 | + /* With SCTLR_EL1.BT0 set, PACIASP is not compatible with type=3. */ | ||
75 | + TEST(BTYPE_1, 0); | ||
76 | + TEST(BTYPE_2, 0); | ||
77 | + TEST(BTYPE_3, 1); | ||
78 | + | ||
79 | + return fail; | ||
206 | +} | 80 | +} |
207 | + | 81 | diff --git a/tests/tcg/aarch64/Makefile.target b/tests/tcg/aarch64/Makefile.target |
208 | +static void emac_load_desc(MSF2EmacState *s, EmacDesc *d, hwaddr desc) | ||
209 | +{ | ||
210 | + address_space_read(&s->dma_as, desc, MEMTXATTRS_UNSPECIFIED, d, sizeof *d); | ||
211 | + /* Convert from LE into host endianness. */ | ||
212 | + d->pktaddr = le32_to_cpu(d->pktaddr); | ||
213 | + d->pktsize = le32_to_cpu(d->pktsize); | ||
214 | + d->next = le32_to_cpu(d->next); | ||
215 | +} | ||
216 | + | ||
217 | +static void emac_store_desc(MSF2EmacState *s, EmacDesc *d, hwaddr desc) | ||
218 | +{ | ||
219 | + /* Convert from host endianness into LE. */ | ||
220 | + d->pktaddr = cpu_to_le32(d->pktaddr); | ||
221 | + d->pktsize = cpu_to_le32(d->pktsize); | ||
222 | + d->next = cpu_to_le32(d->next); | ||
223 | + | ||
224 | + address_space_write(&s->dma_as, desc, MEMTXATTRS_UNSPECIFIED, d, sizeof *d); | ||
225 | +} | ||
226 | + | ||
227 | +static void msf2_dma_tx(MSF2EmacState *s) | ||
228 | +{ | ||
229 | + NetClientState *nc = qemu_get_queue(s->nic); | ||
230 | + hwaddr desc = s->regs[R_DMA_TX_DESC]; | ||
231 | + uint8_t buf[MAX_PKT_SIZE]; | ||
232 | + EmacDesc d; | ||
233 | + int size; | ||
234 | + uint8_t pktcnt; | ||
235 | + uint32_t status; | ||
236 | + | ||
237 | + if (!(s->regs[R_CFG1] & R_CFG1_TX_EN_MASK)) { | ||
238 | + return; | ||
239 | + } | ||
240 | + | ||
241 | + while (1) { | ||
242 | + emac_load_desc(s, &d, desc); | ||
243 | + if (d.pktsize & EMPTY_MASK) { | ||
244 | + break; | ||
245 | + } | ||
246 | + size = d.pktsize & PKT_SIZE; | ||
247 | + address_space_read(&s->dma_as, d.pktaddr, MEMTXATTRS_UNSPECIFIED, | ||
248 | + buf, size); | ||
249 | + /* | ||
250 | + * This is very basic way to send packets. Ideally there should be | ||
251 | + * a FIFO and packets should be sent out from FIFO only when | ||
252 | + * R_CFG1 bit 0 is set. | ||
253 | + */ | ||
254 | + if (s->regs[R_CFG1] & R_CFG1_LB_EN_MASK) { | ||
255 | + nc->info->receive(nc, buf, size); | ||
256 | + } else { | ||
257 | + qemu_send_packet(nc, buf, size); | ||
258 | + } | ||
259 | + d.pktsize |= EMPTY_MASK; | ||
260 | + emac_store_desc(s, &d, desc); | ||
261 | + /* update sent packets count */ | ||
262 | + status = s->regs[R_DMA_TX_STATUS]; | ||
263 | + pktcnt = FIELD_EX32(status, DMA_TX_STATUS, PKTCNT); | ||
264 | + pktcnt++; | ||
265 | + s->regs[R_DMA_TX_STATUS] = FIELD_DP32(status, DMA_TX_STATUS, | ||
266 | + PKTCNT, pktcnt); | ||
267 | + s->regs[R_DMA_TX_STATUS] |= R_DMA_TX_STATUS_PKT_SENT_MASK; | ||
268 | + desc = d.next; | ||
269 | + } | ||
270 | + s->regs[R_DMA_TX_STATUS] |= R_DMA_TX_STATUS_UNDERRUN_MASK; | ||
271 | + s->regs[R_DMA_TX_CTL] &= ~R_DMA_TX_CTL_EN_MASK; | ||
272 | +} | ||
273 | + | ||
274 | +static void msf2_phy_update_link(MSF2EmacState *s) | ||
275 | +{ | ||
276 | + /* Autonegotiation status mirrors link status. */ | ||
277 | + if (qemu_get_queue(s->nic)->link_down) { | ||
278 | + s->phy_regs[MII_BMSR] &= ~(MII_BMSR_AN_COMP | | ||
279 | + MII_BMSR_LINK_ST); | ||
280 | + } else { | ||
281 | + s->phy_regs[MII_BMSR] |= (MII_BMSR_AN_COMP | | ||
282 | + MII_BMSR_LINK_ST); | ||
283 | + } | ||
284 | +} | ||
285 | + | ||
286 | +static void msf2_phy_reset(MSF2EmacState *s) | ||
287 | +{ | ||
288 | + memset(&s->phy_regs[0], 0, sizeof(s->phy_regs)); | ||
289 | + s->phy_regs[MII_BMCR] = 0x1140; | ||
290 | + s->phy_regs[MII_BMSR] = 0x7968; | ||
291 | + s->phy_regs[MII_PHYID1] = 0x0022; | ||
292 | + s->phy_regs[MII_PHYID2] = 0x1550; | ||
293 | + s->phy_regs[MII_ANAR] = 0x01E1; | ||
294 | + s->phy_regs[MII_ANLPAR] = 0xCDE1; | ||
295 | + | ||
296 | + msf2_phy_update_link(s); | ||
297 | +} | ||
298 | + | ||
299 | +static void write_to_phy(MSF2EmacState *s) | ||
300 | +{ | ||
301 | + uint8_t reg_addr = s->regs[R_MII_ADDR] & R_MII_ADDR_REGADDR_MASK; | ||
302 | + uint8_t phy_addr = (s->regs[R_MII_ADDR] >> R_MII_ADDR_PHYADDR_SHIFT) & | ||
303 | + R_MII_ADDR_REGADDR_MASK; | ||
304 | + uint16_t data = s->regs[R_MII_CTL] & 0xFFFF; | ||
305 | + | ||
306 | + if (phy_addr != PHYADDR) { | ||
307 | + return; | ||
308 | + } | ||
309 | + | ||
310 | + switch (reg_addr) { | ||
311 | + case MII_BMCR: | ||
312 | + if (data & MII_BMCR_RESET) { | ||
313 | + /* Phy reset */ | ||
314 | + msf2_phy_reset(s); | ||
315 | + data &= ~MII_BMCR_RESET; | ||
316 | + } | ||
317 | + if (data & MII_BMCR_AUTOEN) { | ||
318 | + /* Complete autonegotiation immediately */ | ||
319 | + data &= ~MII_BMCR_AUTOEN; | ||
320 | + s->phy_regs[MII_BMSR] |= MII_BMSR_AN_COMP; | ||
321 | + } | ||
322 | + break; | ||
323 | + } | ||
324 | + | ||
325 | + s->phy_regs[reg_addr] = data; | ||
326 | +} | ||
327 | + | ||
328 | +static uint16_t read_from_phy(MSF2EmacState *s) | ||
329 | +{ | ||
330 | + uint8_t reg_addr = s->regs[R_MII_ADDR] & R_MII_ADDR_REGADDR_MASK; | ||
331 | + uint8_t phy_addr = (s->regs[R_MII_ADDR] >> R_MII_ADDR_PHYADDR_SHIFT) & | ||
332 | + R_MII_ADDR_REGADDR_MASK; | ||
333 | + | ||
334 | + if (phy_addr == PHYADDR) { | ||
335 | + return s->phy_regs[reg_addr]; | ||
336 | + } else { | ||
337 | + return 0xFFFF; | ||
338 | + } | ||
339 | +} | ||
340 | + | ||
341 | +static void msf2_emac_do_reset(MSF2EmacState *s) | ||
342 | +{ | ||
343 | + memset(&s->regs[0], 0, sizeof(s->regs)); | ||
344 | + s->regs[R_CFG1] = 0x80000000; | ||
345 | + s->regs[R_CFG2] = 0x00007000; | ||
346 | + s->regs[R_IFG] = 0x40605060; | ||
347 | + s->regs[R_HALF_DUPLEX] = 0x00A1F037; | ||
348 | + s->regs[R_MAX_FRAME_LENGTH] = 0x00000600; | ||
349 | + s->regs[R_FIFO_CFG5] = 0X3FFFF; | ||
350 | + | ||
351 | + msf2_phy_reset(s); | ||
352 | +} | ||
353 | + | ||
354 | +static uint64_t emac_read(void *opaque, hwaddr addr, unsigned int size) | ||
355 | +{ | ||
356 | + MSF2EmacState *s = opaque; | ||
357 | + uint32_t r = 0; | ||
358 | + | ||
359 | + addr >>= 2; | ||
360 | + | ||
361 | + switch (addr) { | ||
362 | + case R_DMA_IRQ: | ||
363 | + r = emac_get_isr(s); | ||
364 | + break; | ||
365 | + default: | ||
366 | + if (addr >= ARRAY_SIZE(s->regs)) { | ||
367 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
368 | + "%s: Bad offset 0x%" HWADDR_PRIx "\n", __func__, | ||
369 | + addr * 4); | ||
370 | + return r; | ||
371 | + } | ||
372 | + r = s->regs[addr]; | ||
373 | + break; | ||
374 | + } | ||
375 | + return r; | ||
376 | +} | ||
377 | + | ||
378 | +static void emac_write(void *opaque, hwaddr addr, uint64_t val64, | ||
379 | + unsigned int size) | ||
380 | +{ | ||
381 | + MSF2EmacState *s = opaque; | ||
382 | + uint32_t value = val64; | ||
383 | + uint32_t enreqbits; | ||
384 | + uint8_t pktcnt; | ||
385 | + | ||
386 | + addr >>= 2; | ||
387 | + switch (addr) { | ||
388 | + case R_DMA_TX_CTL: | ||
389 | + s->regs[addr] = value; | ||
390 | + if (value & R_DMA_TX_CTL_EN_MASK) { | ||
391 | + msf2_dma_tx(s); | ||
392 | + } | ||
393 | + break; | ||
394 | + case R_DMA_RX_CTL: | ||
395 | + s->regs[addr] = value; | ||
396 | + if (value & R_DMA_RX_CTL_EN_MASK) { | ||
397 | + s->rx_desc = s->regs[R_DMA_RX_DESC]; | ||
398 | + qemu_flush_queued_packets(qemu_get_queue(s->nic)); | ||
399 | + } | ||
400 | + break; | ||
401 | + case R_CFG1: | ||
402 | + s->regs[addr] = value; | ||
403 | + if (value & R_CFG1_RESET_MASK) { | ||
404 | + msf2_emac_do_reset(s); | ||
405 | + } | ||
406 | + break; | ||
407 | + case R_FIFO_CFG0: | ||
408 | + /* | ||
409 | + * For our implementation, turning on modules is instantaneous, | ||
410 | + * so the states requested via the *ENREQ bits appear in the | ||
411 | + * *ENRPLY bits immediately. Also the reset bits to reset PE-MCXMAC | ||
412 | + * module are not emulated here since it deals with start of frames, | ||
413 | + * inter-packet gap and control frames. | ||
414 | + */ | ||
415 | + enreqbits = extract32(value, 8, 5); | ||
416 | + s->regs[addr] = deposit32(value, 16, 5, enreqbits); | ||
417 | + break; | ||
418 | + case R_DMA_TX_DESC: | ||
419 | + if (value & 0x3) { | ||
420 | + qemu_log_mask(LOG_GUEST_ERROR, "Tx Descriptor address should be" | ||
421 | + " 32 bit aligned\n"); | ||
422 | + } | ||
423 | + /* Ignore [1:0] bits */ | ||
424 | + s->regs[addr] = value & ~3; | ||
425 | + break; | ||
426 | + case R_DMA_RX_DESC: | ||
427 | + if (value & 0x3) { | ||
428 | + qemu_log_mask(LOG_GUEST_ERROR, "Rx Descriptor address should be" | ||
429 | + " 32 bit aligned\n"); | ||
430 | + } | ||
431 | + /* Ignore [1:0] bits */ | ||
432 | + s->regs[addr] = value & ~3; | ||
433 | + break; | ||
434 | + case R_DMA_TX_STATUS: | ||
435 | + if (value & R_DMA_TX_STATUS_UNDERRUN_MASK) { | ||
436 | + s->regs[addr] &= ~R_DMA_TX_STATUS_UNDERRUN_MASK; | ||
437 | + } | ||
438 | + if (value & R_DMA_TX_STATUS_PKT_SENT_MASK) { | ||
439 | + pktcnt = FIELD_EX32(s->regs[addr], DMA_TX_STATUS, PKTCNT); | ||
440 | + pktcnt--; | ||
441 | + s->regs[addr] = FIELD_DP32(s->regs[addr], DMA_TX_STATUS, | ||
442 | + PKTCNT, pktcnt); | ||
443 | + if (pktcnt == 0) { | ||
444 | + s->regs[addr] &= ~R_DMA_TX_STATUS_PKT_SENT_MASK; | ||
445 | + } | ||
446 | + } | ||
447 | + break; | ||
448 | + case R_DMA_RX_STATUS: | ||
449 | + if (value & R_DMA_RX_STATUS_OVERFLOW_MASK) { | ||
450 | + s->regs[addr] &= ~R_DMA_RX_STATUS_OVERFLOW_MASK; | ||
451 | + } | ||
452 | + if (value & R_DMA_RX_STATUS_PKT_RCVD_MASK) { | ||
453 | + pktcnt = FIELD_EX32(s->regs[addr], DMA_RX_STATUS, PKTCNT); | ||
454 | + pktcnt--; | ||
455 | + s->regs[addr] = FIELD_DP32(s->regs[addr], DMA_RX_STATUS, | ||
456 | + PKTCNT, pktcnt); | ||
457 | + if (pktcnt == 0) { | ||
458 | + s->regs[addr] &= ~R_DMA_RX_STATUS_PKT_RCVD_MASK; | ||
459 | + } | ||
460 | + } | ||
461 | + break; | ||
462 | + case R_DMA_IRQ: | ||
463 | + break; | ||
464 | + case R_MII_CMD: | ||
465 | + if (value & R_MII_CMD_READ_MASK) { | ||
466 | + s->regs[R_MII_STS] = read_from_phy(s); | ||
467 | + } | ||
468 | + break; | ||
469 | + case R_MII_CTL: | ||
470 | + s->regs[addr] = value; | ||
471 | + write_to_phy(s); | ||
472 | + break; | ||
473 | + case R_STA1: | ||
474 | + s->regs[addr] = value; | ||
475 | + /* | ||
476 | + * R_STA1 [31:24] : octet 1 of mac address | ||
477 | + * R_STA1 [23:16] : octet 2 of mac address | ||
478 | + * R_STA1 [15:8] : octet 3 of mac address | ||
479 | + * R_STA1 [7:0] : octet 4 of mac address | ||
480 | + */ | ||
481 | + stl_be_p(s->mac_addr, value); | ||
482 | + break; | ||
483 | + case R_STA2: | ||
484 | + s->regs[addr] = value; | ||
485 | + /* | ||
486 | + * R_STA2 [31:24] : octet 5 of mac address | ||
487 | + * R_STA2 [23:16] : octet 6 of mac address | ||
488 | + */ | ||
489 | + stw_be_p(s->mac_addr + 4, value >> 16); | ||
490 | + break; | ||
491 | + default: | ||
492 | + if (addr >= ARRAY_SIZE(s->regs)) { | ||
493 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
494 | + "%s: Bad offset 0x%" HWADDR_PRIx "\n", __func__, | ||
495 | + addr * 4); | ||
496 | + return; | ||
497 | + } | ||
498 | + s->regs[addr] = value; | ||
499 | + break; | ||
500 | + } | ||
501 | + emac_update_irq(s); | ||
502 | +} | ||
503 | + | ||
504 | +static const MemoryRegionOps emac_ops = { | ||
505 | + .read = emac_read, | ||
506 | + .write = emac_write, | ||
507 | + .endianness = DEVICE_NATIVE_ENDIAN, | ||
508 | + .impl = { | ||
509 | + .min_access_size = 4, | ||
510 | + .max_access_size = 4 | ||
511 | + } | ||
512 | +}; | ||
513 | + | ||
514 | +static bool emac_can_rx(NetClientState *nc) | ||
515 | +{ | ||
516 | + MSF2EmacState *s = qemu_get_nic_opaque(nc); | ||
517 | + | ||
518 | + return (s->regs[R_CFG1] & R_CFG1_RX_EN_MASK) && | ||
519 | + (s->regs[R_DMA_RX_CTL] & R_DMA_RX_CTL_EN_MASK); | ||
520 | +} | ||
521 | + | ||
522 | +static bool addr_filter_ok(MSF2EmacState *s, const uint8_t *buf) | ||
523 | +{ | ||
524 | + /* The broadcast MAC address: FF:FF:FF:FF:FF:FF */ | ||
525 | + const uint8_t broadcast_addr[] = { 0xFF, 0xFF, 0xFF, 0xFF, | ||
526 | + 0xFF, 0xFF }; | ||
527 | + bool bcast_en = true; | ||
528 | + bool mcast_en = true; | ||
529 | + | ||
530 | + if (s->regs[R_FIFO_CFG5] & R_FIFO_CFG5_BCAST_MASK) { | ||
531 | + bcast_en = true; /* Broadcast dont care for drop circuitry */ | ||
532 | + } else if (s->regs[R_FIFO_CFG4] & R_FIFO_CFG4_BCAST_MASK) { | ||
533 | + bcast_en = false; | ||
534 | + } | ||
535 | + | ||
536 | + if (s->regs[R_FIFO_CFG5] & R_FIFO_CFG5_MCAST_MASK) { | ||
537 | + mcast_en = true; /* Multicast dont care for drop circuitry */ | ||
538 | + } else if (s->regs[R_FIFO_CFG4] & R_FIFO_CFG4_MCAST_MASK) { | ||
539 | + mcast_en = false; | ||
540 | + } | ||
541 | + | ||
542 | + if (!memcmp(buf, broadcast_addr, sizeof(broadcast_addr))) { | ||
543 | + return bcast_en; | ||
544 | + } | ||
545 | + | ||
546 | + if (buf[0] & 1) { | ||
547 | + return mcast_en; | ||
548 | + } | ||
549 | + | ||
550 | + return !memcmp(buf, s->mac_addr, sizeof(s->mac_addr)); | ||
551 | +} | ||
552 | + | ||
553 | +static ssize_t emac_rx(NetClientState *nc, const uint8_t *buf, size_t size) | ||
554 | +{ | ||
555 | + MSF2EmacState *s = qemu_get_nic_opaque(nc); | ||
556 | + EmacDesc d; | ||
557 | + uint8_t pktcnt; | ||
558 | + uint32_t status; | ||
559 | + | ||
560 | + if (size > (s->regs[R_MAX_FRAME_LENGTH] & 0xFFFF)) { | ||
561 | + return size; | ||
562 | + } | ||
563 | + if (!addr_filter_ok(s, buf)) { | ||
564 | + return size; | ||
565 | + } | ||
566 | + | ||
567 | + emac_load_desc(s, &d, s->rx_desc); | ||
568 | + | ||
569 | + if (d.pktsize & EMPTY_MASK) { | ||
570 | + address_space_write(&s->dma_as, d.pktaddr, MEMTXATTRS_UNSPECIFIED, | ||
571 | + buf, size & PKT_SIZE); | ||
572 | + d.pktsize = size & PKT_SIZE; | ||
573 | + emac_store_desc(s, &d, s->rx_desc); | ||
574 | + /* update received packets count */ | ||
575 | + status = s->regs[R_DMA_RX_STATUS]; | ||
576 | + pktcnt = FIELD_EX32(status, DMA_RX_STATUS, PKTCNT); | ||
577 | + pktcnt++; | ||
578 | + s->regs[R_DMA_RX_STATUS] = FIELD_DP32(status, DMA_RX_STATUS, | ||
579 | + PKTCNT, pktcnt); | ||
580 | + s->regs[R_DMA_RX_STATUS] |= R_DMA_RX_STATUS_PKT_RCVD_MASK; | ||
581 | + s->rx_desc = d.next; | ||
582 | + } else { | ||
583 | + s->regs[R_DMA_RX_CTL] &= ~R_DMA_RX_CTL_EN_MASK; | ||
584 | + s->regs[R_DMA_RX_STATUS] |= R_DMA_RX_STATUS_OVERFLOW_MASK; | ||
585 | + } | ||
586 | + emac_update_irq(s); | ||
587 | + return size; | ||
588 | +} | ||
589 | + | ||
590 | +static void msf2_emac_reset(DeviceState *dev) | ||
591 | +{ | ||
592 | + MSF2EmacState *s = MSS_EMAC(dev); | ||
593 | + | ||
594 | + msf2_emac_do_reset(s); | ||
595 | +} | ||
596 | + | ||
597 | +static void emac_set_link(NetClientState *nc) | ||
598 | +{ | ||
599 | + MSF2EmacState *s = qemu_get_nic_opaque(nc); | ||
600 | + | ||
601 | + msf2_phy_update_link(s); | ||
602 | +} | ||
603 | + | ||
604 | +static NetClientInfo net_msf2_emac_info = { | ||
605 | + .type = NET_CLIENT_DRIVER_NIC, | ||
606 | + .size = sizeof(NICState), | ||
607 | + .can_receive = emac_can_rx, | ||
608 | + .receive = emac_rx, | ||
609 | + .link_status_changed = emac_set_link, | ||
610 | +}; | ||
611 | + | ||
612 | +static void msf2_emac_realize(DeviceState *dev, Error **errp) | ||
613 | +{ | ||
614 | + MSF2EmacState *s = MSS_EMAC(dev); | ||
615 | + | ||
616 | + if (!s->dma_mr) { | ||
617 | + error_setg(errp, "MSS_EMAC 'ahb-bus' link not set"); | ||
618 | + return; | ||
619 | + } | ||
620 | + | ||
621 | + address_space_init(&s->dma_as, s->dma_mr, "emac-ahb"); | ||
622 | + | ||
623 | + qemu_macaddr_default_if_unset(&s->conf.macaddr); | ||
624 | + s->nic = qemu_new_nic(&net_msf2_emac_info, &s->conf, | ||
625 | + object_get_typename(OBJECT(dev)), dev->id, s); | ||
626 | + qemu_format_nic_info_str(qemu_get_queue(s->nic), s->conf.macaddr.a); | ||
627 | +} | ||
628 | + | ||
629 | +static void msf2_emac_init(Object *obj) | ||
630 | +{ | ||
631 | + MSF2EmacState *s = MSS_EMAC(obj); | ||
632 | + | ||
633 | + sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); | ||
634 | + | ||
635 | + memory_region_init_io(&s->mmio, obj, &emac_ops, s, | ||
636 | + "msf2-emac", R_MAX * 4); | ||
637 | + sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); | ||
638 | +} | ||
639 | + | ||
640 | +static Property msf2_emac_properties[] = { | ||
641 | + DEFINE_PROP_LINK("ahb-bus", MSF2EmacState, dma_mr, | ||
642 | + TYPE_MEMORY_REGION, MemoryRegion *), | ||
643 | + DEFINE_NIC_PROPERTIES(MSF2EmacState, conf), | ||
644 | + DEFINE_PROP_END_OF_LIST(), | ||
645 | +}; | ||
646 | + | ||
647 | +static const VMStateDescription vmstate_msf2_emac = { | ||
648 | + .name = TYPE_MSS_EMAC, | ||
649 | + .version_id = 1, | ||
650 | + .minimum_version_id = 1, | ||
651 | + .fields = (VMStateField[]) { | ||
652 | + VMSTATE_UINT8_ARRAY(mac_addr, MSF2EmacState, ETH_ALEN), | ||
653 | + VMSTATE_UINT32(rx_desc, MSF2EmacState), | ||
654 | + VMSTATE_UINT16_ARRAY(phy_regs, MSF2EmacState, PHY_MAX_REGS), | ||
655 | + VMSTATE_UINT32_ARRAY(regs, MSF2EmacState, R_MAX), | ||
656 | + VMSTATE_END_OF_LIST() | ||
657 | + } | ||
658 | +}; | ||
659 | + | ||
660 | +static void msf2_emac_class_init(ObjectClass *klass, void *data) | ||
661 | +{ | ||
662 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
663 | + | ||
664 | + dc->realize = msf2_emac_realize; | ||
665 | + dc->reset = msf2_emac_reset; | ||
666 | + dc->vmsd = &vmstate_msf2_emac; | ||
667 | + device_class_set_props(dc, msf2_emac_properties); | ||
668 | +} | ||
669 | + | ||
670 | +static const TypeInfo msf2_emac_info = { | ||
671 | + .name = TYPE_MSS_EMAC, | ||
672 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
673 | + .instance_size = sizeof(MSF2EmacState), | ||
674 | + .instance_init = msf2_emac_init, | ||
675 | + .class_init = msf2_emac_class_init, | ||
676 | +}; | ||
677 | + | ||
678 | +static void msf2_emac_register_types(void) | ||
679 | +{ | ||
680 | + type_register_static(&msf2_emac_info); | ||
681 | +} | ||
682 | + | ||
683 | +type_init(msf2_emac_register_types) | ||
684 | diff --git a/MAINTAINERS b/MAINTAINERS | ||
685 | index XXXXXXX..XXXXXXX 100644 | 82 | index XXXXXXX..XXXXXXX 100644 |
686 | --- a/MAINTAINERS | 83 | --- a/tests/tcg/aarch64/Makefile.target |
687 | +++ b/MAINTAINERS | 84 | +++ b/tests/tcg/aarch64/Makefile.target |
688 | @@ -XXX,XX +XXX,XX @@ F: include/hw/arm/msf2-soc.h | 85 | @@ -XXX,XX +XXX,XX @@ endif |
689 | F: include/hw/misc/msf2-sysreg.h | 86 | # BTI Tests |
690 | F: include/hw/timer/mss-timer.h | 87 | # bti-1 tests the elf notes, so we require special compiler support. |
691 | F: include/hw/ssi/mss-spi.h | 88 | ifneq ($(CROSS_CC_HAS_ARMV8_BTI),) |
692 | +F: hw/net/msf2-emac.c | 89 | -AARCH64_TESTS += bti-1 |
693 | +F: include/hw/net/msf2-emac.h | 90 | -bti-1: CFLAGS += -mbranch-protection=standard |
694 | 91 | -bti-1: LDFLAGS += -nostdlib | |
695 | Emcraft M2S-FG484 | 92 | +AARCH64_TESTS += bti-1 bti-3 |
696 | M: Subbaraya Sundeep <sundeep.lkml@gmail.com> | 93 | +bti-1 bti-3: CFLAGS += -mbranch-protection=standard |
94 | +bti-1 bti-3: LDFLAGS += -nostdlib | ||
95 | endif | ||
96 | # bti-2 tests PROT_BTI, so no special compiler support required. | ||
97 | AARCH64_TESTS += bti-2 | ||
697 | -- | 98 | -- |
698 | 2.20.1 | 99 | 2.25.1 |
699 | |||
700 | diff view generated by jsdifflib |
1 | This object may be used to represent a clock inside a clock tree. | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | A clock may be connected to another clock so that it receives update, | 3 | Move ARMCPRegInfo and all related declarations to a new |
4 | through a callback, whenever the source/parent clock is updated. | 4 | internal header, out of the public cpu.h. |
5 | 5 | ||
6 | Although only the root clock of a clock tree controls the values | 6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
7 | (represented as periods) of all clocks in tree, each clock holds | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | a local state containing the current value so that it can be fetched | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | independently. It will allows us to fullfill migration requirements | 9 | Message-id: 20220501055028.646596-2-richard.henderson@linaro.org |
10 | by migrating each clock independently of others. | ||
11 | |||
12 | This is based on the original work of Frederic Konrad. | ||
13 | |||
14 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
15 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
17 | Message-id: 20200406135251.157596-2-damien.hedde@greensocs.com | ||
18 | [PMM: Use uint64_t rather than unsigned long long in trace events; | ||
19 | the dtrace backend can't handle the latter] | ||
20 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
21 | --- | 11 | --- |
22 | hw/core/Makefile.objs | 1 + | 12 | target/arm/cpregs.h | 413 +++++++++++++++++++++++++++++++++++++ |
23 | include/hw/clock.h | 216 ++++++++++++++++++++++++++++++++++++++++++ | 13 | target/arm/cpu.h | 368 --------------------------------- |
24 | hw/core/clock.c | 130 +++++++++++++++++++++++++ | 14 | hw/arm/pxa2xx.c | 1 + |
25 | hw/core/trace-events | 7 ++ | 15 | hw/arm/pxa2xx_pic.c | 1 + |
26 | 4 files changed, 354 insertions(+) | 16 | hw/intc/arm_gicv3_cpuif.c | 1 + |
27 | create mode 100644 include/hw/clock.h | 17 | hw/intc/arm_gicv3_kvm.c | 2 + |
28 | create mode 100644 hw/core/clock.c | 18 | target/arm/cpu.c | 1 + |
19 | target/arm/cpu64.c | 1 + | ||
20 | target/arm/cpu_tcg.c | 1 + | ||
21 | target/arm/gdbstub.c | 3 +- | ||
22 | target/arm/helper.c | 1 + | ||
23 | target/arm/op_helper.c | 1 + | ||
24 | target/arm/translate-a64.c | 4 +- | ||
25 | target/arm/translate.c | 3 +- | ||
26 | 14 files changed, 427 insertions(+), 374 deletions(-) | ||
27 | create mode 100644 target/arm/cpregs.h | ||
29 | 28 | ||
30 | diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs | 29 | diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h |
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/hw/core/Makefile.objs | ||
33 | +++ b/hw/core/Makefile.objs | ||
34 | @@ -XXX,XX +XXX,XX @@ common-obj-y += hotplug.o | ||
35 | common-obj-y += vmstate-if.o | ||
36 | # irq.o needed for qdev GPIO handling: | ||
37 | common-obj-y += irq.o | ||
38 | +common-obj-y += clock.o | ||
39 | |||
40 | common-obj-$(CONFIG_SOFTMMU) += reset.o | ||
41 | common-obj-$(CONFIG_SOFTMMU) += qdev-fw.o | ||
42 | diff --git a/include/hw/clock.h b/include/hw/clock.h | ||
43 | new file mode 100644 | 30 | new file mode 100644 |
44 | index XXXXXXX..XXXXXXX | 31 | index XXXXXXX..XXXXXXX |
45 | --- /dev/null | 32 | --- /dev/null |
46 | +++ b/include/hw/clock.h | 33 | +++ b/target/arm/cpregs.h |
47 | @@ -XXX,XX +XXX,XX @@ | 34 | @@ -XXX,XX +XXX,XX @@ |
48 | +/* | 35 | +/* |
49 | + * Hardware Clocks | 36 | + * QEMU ARM CP Register access and descriptions |
50 | + * | 37 | + * |
51 | + * Copyright GreenSocs 2016-2020 | 38 | + * Copyright (c) 2022 Linaro Ltd |
52 | + * | 39 | + * |
53 | + * Authors: | 40 | + * This program is free software; you can redistribute it and/or |
54 | + * Frederic Konrad | 41 | + * modify it under the terms of the GNU General Public License |
55 | + * Damien Hedde | 42 | + * as published by the Free Software Foundation; either version 2 |
43 | + * of the License, or (at your option) any later version. | ||
56 | + * | 44 | + * |
57 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 45 | + * This program is distributed in the hope that it will be useful, |
58 | + * See the COPYING file in the top-level directory. | 46 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
59 | + */ | 47 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
60 | + | 48 | + * GNU General Public License for more details. |
61 | +#ifndef QEMU_HW_CLOCK_H | 49 | + * |
62 | +#define QEMU_HW_CLOCK_H | 50 | + * You should have received a copy of the GNU General Public License |
63 | + | 51 | + * along with this program; if not, see |
64 | +#include "qom/object.h" | 52 | + * <http://www.gnu.org/licenses/gpl-2.0.html> |
65 | +#include "qemu/queue.h" | 53 | + */ |
66 | + | 54 | + |
67 | +#define TYPE_CLOCK "clock" | 55 | +#ifndef TARGET_ARM_CPREGS_H |
68 | +#define CLOCK(obj) OBJECT_CHECK(Clock, (obj), TYPE_CLOCK) | 56 | +#define TARGET_ARM_CPREGS_H |
69 | + | 57 | + |
70 | +typedef void ClockCallback(void *opaque); | 58 | +/* |
71 | + | 59 | + * ARMCPRegInfo type field bits. If the SPECIAL bit is set this is a |
72 | +/* | 60 | + * special-behaviour cp reg and bits [11..8] indicate what behaviour |
73 | + * clock store a value representing the clock's period in 2^-32ns unit. | 61 | + * it has. Otherwise it is a simple cp reg, where CONST indicates that |
74 | + * It can represent: | 62 | + * TCG can assume the value to be constant (ie load at translate time) |
75 | + * + periods from 2^-32ns up to 4seconds | 63 | + * and 64BIT indicates a 64 bit wide coprocessor register. SUPPRESS_TB_END |
76 | + * + frequency from ~0.25Hz 2e10Ghz | 64 | + * indicates that the TB should not be ended after a write to this register |
77 | + * Resolution of frequency representation decreases with frequency: | 65 | + * (the default is that the TB ends after cp writes). OVERRIDE permits |
78 | + * + at 100MHz, resolution is ~2mHz | 66 | + * a register definition to override a previous definition for the |
79 | + * + at 1Ghz, resolution is ~0.2Hz | 67 | + * same (cp, is64, crn, crm, opc1, opc2) tuple: either the new or the |
80 | + * + at 10Ghz, resolution is ~20Hz | 68 | + * old must have the OVERRIDE bit set. |
81 | + */ | 69 | + * ALIAS indicates that this register is an alias view of some underlying |
82 | +#define CLOCK_SECOND (1000000000llu << 32) | 70 | + * state which is also visible via another register, and that the other |
83 | + | 71 | + * register is handling migration and reset; registers marked ALIAS will not be |
84 | +/* | 72 | + * migrated but may have their state set by syncing of register state from KVM. |
85 | + * macro helpers to convert to hertz / nanosecond | 73 | + * NO_RAW indicates that this register has no underlying state and does not |
86 | + */ | 74 | + * support raw access for state saving/loading; it will not be used for either |
87 | +#define CLOCK_PERIOD_FROM_NS(ns) ((ns) * (CLOCK_SECOND / 1000000000llu)) | 75 | + * migration or KVM state synchronization. (Typically this is for "registers" |
88 | +#define CLOCK_PERIOD_TO_NS(per) ((per) / (CLOCK_SECOND / 1000000000llu)) | 76 | + * which are actually used as instructions for cache maintenance and so on.) |
89 | +#define CLOCK_PERIOD_FROM_HZ(hz) (((hz) != 0) ? CLOCK_SECOND / (hz) : 0u) | 77 | + * IO indicates that this register does I/O and therefore its accesses |
90 | +#define CLOCK_PERIOD_TO_HZ(per) (((per) != 0) ? CLOCK_SECOND / (per) : 0u) | 78 | + * need to be marked with gen_io_start() and also end the TB. In particular, |
91 | + | 79 | + * registers which implement clocks or timers require this. |
92 | +/** | 80 | + * RAISES_EXC is for when the read or write hook might raise an exception; |
93 | + * Clock: | 81 | + * the generated code will synchronize the CPU state before calling the hook |
94 | + * @parent_obj: parent class | 82 | + * so that it is safe for the hook to call raise_exception(). |
95 | + * @period: unsigned integer representing the period of the clock | 83 | + * NEWEL is for writes to registers that might change the exception |
96 | + * @canonical_path: clock path string cache (used for trace purpose) | 84 | + * level - typically on older ARM chips. For those cases we need to |
97 | + * @callback: called when clock changes | 85 | + * re-read the new el when recomputing the translation flags. |
98 | + * @callback_opaque: argument for @callback | 86 | + */ |
99 | + * @source: source (or parent in clock tree) of the clock | 87 | +#define ARM_CP_SPECIAL 0x0001 |
100 | + * @children: list of clocks connected to this one (it is their source) | 88 | +#define ARM_CP_CONST 0x0002 |
101 | + * @sibling: structure used to form a clock list | 89 | +#define ARM_CP_64BIT 0x0004 |
102 | + */ | 90 | +#define ARM_CP_SUPPRESS_TB_END 0x0008 |
103 | + | 91 | +#define ARM_CP_OVERRIDE 0x0010 |
104 | +typedef struct Clock Clock; | 92 | +#define ARM_CP_ALIAS 0x0020 |
105 | + | 93 | +#define ARM_CP_IO 0x0040 |
106 | +struct Clock { | 94 | +#define ARM_CP_NO_RAW 0x0080 |
107 | + /*< private >*/ | 95 | +#define ARM_CP_NOP (ARM_CP_SPECIAL | 0x0100) |
108 | + Object parent_obj; | 96 | +#define ARM_CP_WFI (ARM_CP_SPECIAL | 0x0200) |
109 | + | 97 | +#define ARM_CP_NZCV (ARM_CP_SPECIAL | 0x0300) |
110 | + /* all fields are private and should not be modified directly */ | 98 | +#define ARM_CP_CURRENTEL (ARM_CP_SPECIAL | 0x0400) |
111 | + | 99 | +#define ARM_CP_DC_ZVA (ARM_CP_SPECIAL | 0x0500) |
112 | + /* fields */ | 100 | +#define ARM_CP_DC_GVA (ARM_CP_SPECIAL | 0x0600) |
113 | + uint64_t period; | 101 | +#define ARM_CP_DC_GZVA (ARM_CP_SPECIAL | 0x0700) |
114 | + char *canonical_path; | 102 | +#define ARM_LAST_SPECIAL ARM_CP_DC_GZVA |
115 | + ClockCallback *callback; | 103 | +#define ARM_CP_FPU 0x1000 |
116 | + void *callback_opaque; | 104 | +#define ARM_CP_SVE 0x2000 |
117 | + | 105 | +#define ARM_CP_NO_GDB 0x4000 |
118 | + /* Clocks are organized in a clock tree */ | 106 | +#define ARM_CP_RAISES_EXC 0x8000 |
119 | + Clock *source; | 107 | +#define ARM_CP_NEWEL 0x10000 |
120 | + QLIST_HEAD(, Clock) children; | 108 | +/* Used only as a terminator for ARMCPRegInfo lists */ |
121 | + QLIST_ENTRY(Clock) sibling; | 109 | +#define ARM_CP_SENTINEL 0xfffff |
110 | +/* Mask of only the flag bits in a type field */ | ||
111 | +#define ARM_CP_FLAG_MASK 0x1f0ff | ||
112 | + | ||
113 | +/* | ||
114 | + * Valid values for ARMCPRegInfo state field, indicating which of | ||
115 | + * the AArch32 and AArch64 execution states this register is visible in. | ||
116 | + * If the reginfo doesn't explicitly specify then it is AArch32 only. | ||
117 | + * If the reginfo is declared to be visible in both states then a second | ||
118 | + * reginfo is synthesised for the AArch32 view of the AArch64 register, | ||
119 | + * such that the AArch32 view is the lower 32 bits of the AArch64 one. | ||
120 | + * Note that we rely on the values of these enums as we iterate through | ||
121 | + * the various states in some places. | ||
122 | + */ | ||
123 | +enum { | ||
124 | + ARM_CP_STATE_AA32 = 0, | ||
125 | + ARM_CP_STATE_AA64 = 1, | ||
126 | + ARM_CP_STATE_BOTH = 2, | ||
122 | +}; | 127 | +}; |
123 | + | 128 | + |
124 | +/** | 129 | +/* |
125 | + * clock_setup_canonical_path: | 130 | + * ARM CP register secure state flags. These flags identify security state |
126 | + * @clk: clock | 131 | + * attributes for a given CP register entry. |
132 | + * The existence of both or neither secure and non-secure flags indicates that | ||
133 | + * the register has both a secure and non-secure hash entry. A single one of | ||
134 | + * these flags causes the register to only be hashed for the specified | ||
135 | + * security state. | ||
136 | + * Although definitions may have any combination of the S/NS bits, each | ||
137 | + * registered entry will only have one to identify whether the entry is secure | ||
138 | + * or non-secure. | ||
139 | + */ | ||
140 | +enum { | ||
141 | + ARM_CP_SECSTATE_S = (1 << 0), /* bit[0]: Secure state register */ | ||
142 | + ARM_CP_SECSTATE_NS = (1 << 1), /* bit[1]: Non-secure state register */ | ||
143 | +}; | ||
144 | + | ||
145 | +/* | ||
146 | + * Return true if cptype is a valid type field. This is used to try to | ||
147 | + * catch errors where the sentinel has been accidentally left off the end | ||
148 | + * of a list of registers. | ||
149 | + */ | ||
150 | +static inline bool cptype_valid(int cptype) | ||
151 | +{ | ||
152 | + return ((cptype & ~ARM_CP_FLAG_MASK) == 0) | ||
153 | + || ((cptype & ARM_CP_SPECIAL) && | ||
154 | + ((cptype & ~ARM_CP_FLAG_MASK) <= ARM_LAST_SPECIAL)); | ||
155 | +} | ||
156 | + | ||
157 | +/* | ||
158 | + * Access rights: | ||
159 | + * We define bits for Read and Write access for what rev C of the v7-AR ARM ARM | ||
160 | + * defines as PL0 (user), PL1 (fiq/irq/svc/abt/und/sys, ie privileged), and | ||
161 | + * PL2 (hyp). The other level which has Read and Write bits is Secure PL1 | ||
162 | + * (ie any of the privileged modes in Secure state, or Monitor mode). | ||
163 | + * If a register is accessible in one privilege level it's always accessible | ||
164 | + * in higher privilege levels too. Since "Secure PL1" also follows this rule | ||
165 | + * (ie anything visible in PL2 is visible in S-PL1, some things are only | ||
166 | + * visible in S-PL1) but "Secure PL1" is a bit of a mouthful, we bend the | ||
167 | + * terminology a little and call this PL3. | ||
168 | + * In AArch64 things are somewhat simpler as the PLx bits line up exactly | ||
169 | + * with the ELx exception levels. | ||
127 | + * | 170 | + * |
128 | + * compute the canonical path of the clock (used by log messages) | 171 | + * If access permissions for a register are more complex than can be |
129 | + */ | 172 | + * described with these bits, then use a laxer set of restrictions, and |
130 | +void clock_setup_canonical_path(Clock *clk); | 173 | + * do the more restrictive/complex check inside a helper function. |
131 | + | 174 | + */ |
132 | +/** | 175 | +#define PL3_R 0x80 |
133 | + * clock_set_callback: | 176 | +#define PL3_W 0x40 |
134 | + * @clk: the clock to register the callback into | 177 | +#define PL2_R (0x20 | PL3_R) |
135 | + * @cb: the callback function | 178 | +#define PL2_W (0x10 | PL3_W) |
136 | + * @opaque: the argument to the callback | 179 | +#define PL1_R (0x08 | PL2_R) |
137 | + * | 180 | +#define PL1_W (0x04 | PL2_W) |
138 | + * Register a callback called on every clock update. | 181 | +#define PL0_R (0x02 | PL1_R) |
139 | + */ | 182 | +#define PL0_W (0x01 | PL1_W) |
140 | +void clock_set_callback(Clock *clk, ClockCallback *cb, void *opaque); | 183 | + |
141 | + | 184 | +/* |
142 | +/** | 185 | + * For user-mode some registers are accessible to EL0 via a kernel |
143 | + * clock_clear_callback: | 186 | + * trap-and-emulate ABI. In this case we define the read permissions |
144 | + * @clk: the clock to delete the callback from | 187 | + * as actually being PL0_R. However some bits of any given register |
145 | + * | 188 | + * may still be masked. |
146 | + * Unregister the callback registered with clock_set_callback. | 189 | + */ |
147 | + */ | 190 | +#ifdef CONFIG_USER_ONLY |
148 | +void clock_clear_callback(Clock *clk); | 191 | +#define PL0U_R PL0_R |
149 | + | 192 | +#else |
150 | +/** | 193 | +#define PL0U_R PL1_R |
151 | + * clock_set_source: | 194 | +#endif |
152 | + * @clk: the clock. | 195 | + |
153 | + * @src: the source clock | 196 | +#define PL3_RW (PL3_R | PL3_W) |
154 | + * | 197 | +#define PL2_RW (PL2_R | PL2_W) |
155 | + * Setup @src as the clock source of @clk. The current @src period | 198 | +#define PL1_RW (PL1_R | PL1_W) |
156 | + * value is also copied to @clk and its subtree but no callback is | 199 | +#define PL0_RW (PL0_R | PL0_W) |
157 | + * called. | 200 | + |
158 | + * Further @src update will be propagated to @clk and its subtree. | 201 | +typedef enum CPAccessResult { |
159 | + */ | 202 | + /* Access is permitted */ |
160 | +void clock_set_source(Clock *clk, Clock *src); | 203 | + CP_ACCESS_OK = 0, |
161 | + | 204 | + /* |
162 | +/** | 205 | + * Access fails due to a configurable trap or enable which would |
163 | + * clock_set: | 206 | + * result in a categorized exception syndrome giving information about |
164 | + * @clk: the clock to initialize. | 207 | + * the failing instruction (ie syndrome category 0x3, 0x4, 0x5, 0x6, |
165 | + * @value: the clock's value, 0 means unclocked | 208 | + * 0xc or 0x18). The exception is taken to the usual target EL (EL1 or |
166 | + * | 209 | + * PL1 if in EL0, otherwise to the current EL). |
167 | + * Set the local cached period value of @clk to @value. | 210 | + */ |
168 | + */ | 211 | + CP_ACCESS_TRAP = 1, |
169 | +void clock_set(Clock *clk, uint64_t value); | 212 | + /* |
170 | + | 213 | + * Access fails and results in an exception syndrome 0x0 ("uncategorized"). |
171 | +static inline void clock_set_hz(Clock *clk, unsigned hz) | 214 | + * Note that this is not a catch-all case -- the set of cases which may |
215 | + * result in this failure is specifically defined by the architecture. | ||
216 | + */ | ||
217 | + CP_ACCESS_TRAP_UNCATEGORIZED = 2, | ||
218 | + /* As CP_ACCESS_TRAP, but for traps directly to EL2 or EL3 */ | ||
219 | + CP_ACCESS_TRAP_EL2 = 3, | ||
220 | + CP_ACCESS_TRAP_EL3 = 4, | ||
221 | + /* As CP_ACCESS_UNCATEGORIZED, but for traps directly to EL2 or EL3 */ | ||
222 | + CP_ACCESS_TRAP_UNCATEGORIZED_EL2 = 5, | ||
223 | + CP_ACCESS_TRAP_UNCATEGORIZED_EL3 = 6, | ||
224 | +} CPAccessResult; | ||
225 | + | ||
226 | +typedef struct ARMCPRegInfo ARMCPRegInfo; | ||
227 | + | ||
228 | +/* | ||
229 | + * Access functions for coprocessor registers. These cannot fail and | ||
230 | + * may not raise exceptions. | ||
231 | + */ | ||
232 | +typedef uint64_t CPReadFn(CPUARMState *env, const ARMCPRegInfo *opaque); | ||
233 | +typedef void CPWriteFn(CPUARMState *env, const ARMCPRegInfo *opaque, | ||
234 | + uint64_t value); | ||
235 | +/* Access permission check functions for coprocessor registers. */ | ||
236 | +typedef CPAccessResult CPAccessFn(CPUARMState *env, | ||
237 | + const ARMCPRegInfo *opaque, | ||
238 | + bool isread); | ||
239 | +/* Hook function for register reset */ | ||
240 | +typedef void CPResetFn(CPUARMState *env, const ARMCPRegInfo *opaque); | ||
241 | + | ||
242 | +#define CP_ANY 0xff | ||
243 | + | ||
244 | +/* Definition of an ARM coprocessor register */ | ||
245 | +struct ARMCPRegInfo { | ||
246 | + /* Name of register (useful mainly for debugging, need not be unique) */ | ||
247 | + const char *name; | ||
248 | + /* | ||
249 | + * Location of register: coprocessor number and (crn,crm,opc1,opc2) | ||
250 | + * tuple. Any of crm, opc1 and opc2 may be CP_ANY to indicate a | ||
251 | + * 'wildcard' field -- any value of that field in the MRC/MCR insn | ||
252 | + * will be decoded to this register. The register read and write | ||
253 | + * callbacks will be passed an ARMCPRegInfo with the crn/crm/opc1/opc2 | ||
254 | + * used by the program, so it is possible to register a wildcard and | ||
255 | + * then behave differently on read/write if necessary. | ||
256 | + * For 64 bit registers, only crm and opc1 are relevant; crn and opc2 | ||
257 | + * must both be zero. | ||
258 | + * For AArch64-visible registers, opc0 is also used. | ||
259 | + * Since there are no "coprocessors" in AArch64, cp is purely used as a | ||
260 | + * way to distinguish (for KVM's benefit) guest-visible system registers | ||
261 | + * from demuxed ones provided to preserve the "no side effects on | ||
262 | + * KVM register read/write from QEMU" semantics. cp==0x13 is guest | ||
263 | + * visible (to match KVM's encoding); cp==0 will be converted to | ||
264 | + * cp==0x13 when the ARMCPRegInfo is registered, for convenience. | ||
265 | + */ | ||
266 | + uint8_t cp; | ||
267 | + uint8_t crn; | ||
268 | + uint8_t crm; | ||
269 | + uint8_t opc0; | ||
270 | + uint8_t opc1; | ||
271 | + uint8_t opc2; | ||
272 | + /* Execution state in which this register is visible: ARM_CP_STATE_* */ | ||
273 | + int state; | ||
274 | + /* Register type: ARM_CP_* bits/values */ | ||
275 | + int type; | ||
276 | + /* Access rights: PL*_[RW] */ | ||
277 | + int access; | ||
278 | + /* Security state: ARM_CP_SECSTATE_* bits/values */ | ||
279 | + int secure; | ||
280 | + /* | ||
281 | + * The opaque pointer passed to define_arm_cp_regs_with_opaque() when | ||
282 | + * this register was defined: can be used to hand data through to the | ||
283 | + * register read/write functions, since they are passed the ARMCPRegInfo*. | ||
284 | + */ | ||
285 | + void *opaque; | ||
286 | + /* | ||
287 | + * Value of this register, if it is ARM_CP_CONST. Otherwise, if | ||
288 | + * fieldoffset is non-zero, the reset value of the register. | ||
289 | + */ | ||
290 | + uint64_t resetvalue; | ||
291 | + /* | ||
292 | + * Offset of the field in CPUARMState for this register. | ||
293 | + * This is not needed if either: | ||
294 | + * 1. type is ARM_CP_CONST or one of the ARM_CP_SPECIALs | ||
295 | + * 2. both readfn and writefn are specified | ||
296 | + */ | ||
297 | + ptrdiff_t fieldoffset; /* offsetof(CPUARMState, field) */ | ||
298 | + | ||
299 | + /* | ||
300 | + * Offsets of the secure and non-secure fields in CPUARMState for the | ||
301 | + * register if it is banked. These fields are only used during the static | ||
302 | + * registration of a register. During hashing the bank associated | ||
303 | + * with a given security state is copied to fieldoffset which is used from | ||
304 | + * there on out. | ||
305 | + * | ||
306 | + * It is expected that register definitions use either fieldoffset or | ||
307 | + * bank_fieldoffsets in the definition but not both. It is also expected | ||
308 | + * that both bank offsets are set when defining a banked register. This | ||
309 | + * use indicates that a register is banked. | ||
310 | + */ | ||
311 | + ptrdiff_t bank_fieldoffsets[2]; | ||
312 | + | ||
313 | + /* | ||
314 | + * Function for making any access checks for this register in addition to | ||
315 | + * those specified by the 'access' permissions bits. If NULL, no extra | ||
316 | + * checks required. The access check is performed at runtime, not at | ||
317 | + * translate time. | ||
318 | + */ | ||
319 | + CPAccessFn *accessfn; | ||
320 | + /* | ||
321 | + * Function for handling reads of this register. If NULL, then reads | ||
322 | + * will be done by loading from the offset into CPUARMState specified | ||
323 | + * by fieldoffset. | ||
324 | + */ | ||
325 | + CPReadFn *readfn; | ||
326 | + /* | ||
327 | + * Function for handling writes of this register. If NULL, then writes | ||
328 | + * will be done by writing to the offset into CPUARMState specified | ||
329 | + * by fieldoffset. | ||
330 | + */ | ||
331 | + CPWriteFn *writefn; | ||
332 | + /* | ||
333 | + * Function for doing a "raw" read; used when we need to copy | ||
334 | + * coprocessor state to the kernel for KVM or out for | ||
335 | + * migration. This only needs to be provided if there is also a | ||
336 | + * readfn and it has side effects (for instance clear-on-read bits). | ||
337 | + */ | ||
338 | + CPReadFn *raw_readfn; | ||
339 | + /* | ||
340 | + * Function for doing a "raw" write; used when we need to copy KVM | ||
341 | + * kernel coprocessor state into userspace, or for inbound | ||
342 | + * migration. This only needs to be provided if there is also a | ||
343 | + * writefn and it masks out "unwritable" bits or has write-one-to-clear | ||
344 | + * or similar behaviour. | ||
345 | + */ | ||
346 | + CPWriteFn *raw_writefn; | ||
347 | + /* | ||
348 | + * Function for resetting the register. If NULL, then reset will be done | ||
349 | + * by writing resetvalue to the field specified in fieldoffset. If | ||
350 | + * fieldoffset is 0 then no reset will be done. | ||
351 | + */ | ||
352 | + CPResetFn *resetfn; | ||
353 | + | ||
354 | + /* | ||
355 | + * "Original" writefn and readfn. | ||
356 | + * For ARMv8.1-VHE register aliases, we overwrite the read/write | ||
357 | + * accessor functions of various EL1/EL0 to perform the runtime | ||
358 | + * check for which sysreg should actually be modified, and then | ||
359 | + * forwards the operation. Before overwriting the accessors, | ||
360 | + * the original function is copied here, so that accesses that | ||
361 | + * really do go to the EL1/EL0 version proceed normally. | ||
362 | + * (The corresponding EL2 register is linked via opaque.) | ||
363 | + */ | ||
364 | + CPReadFn *orig_readfn; | ||
365 | + CPWriteFn *orig_writefn; | ||
366 | +}; | ||
367 | + | ||
368 | +/* | ||
369 | + * Macros which are lvalues for the field in CPUARMState for the | ||
370 | + * ARMCPRegInfo *ri. | ||
371 | + */ | ||
372 | +#define CPREG_FIELD32(env, ri) \ | ||
373 | + (*(uint32_t *)((char *)(env) + (ri)->fieldoffset)) | ||
374 | +#define CPREG_FIELD64(env, ri) \ | ||
375 | + (*(uint64_t *)((char *)(env) + (ri)->fieldoffset)) | ||
376 | + | ||
377 | +#define REGINFO_SENTINEL { .type = ARM_CP_SENTINEL } | ||
378 | + | ||
379 | +void define_arm_cp_regs_with_opaque(ARMCPU *cpu, | ||
380 | + const ARMCPRegInfo *regs, void *opaque); | ||
381 | +void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, | ||
382 | + const ARMCPRegInfo *regs, void *opaque); | ||
383 | +static inline void define_arm_cp_regs(ARMCPU *cpu, const ARMCPRegInfo *regs) | ||
172 | +{ | 384 | +{ |
173 | + clock_set(clk, CLOCK_PERIOD_FROM_HZ(hz)); | 385 | + define_arm_cp_regs_with_opaque(cpu, regs, 0); |
174 | +} | 386 | +} |
175 | + | 387 | +static inline void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *regs) |
176 | +static inline void clock_set_ns(Clock *clk, unsigned ns) | ||
177 | +{ | 388 | +{ |
178 | + clock_set(clk, CLOCK_PERIOD_FROM_NS(ns)); | 389 | + define_one_arm_cp_reg_with_opaque(cpu, regs, 0); |
179 | +} | 390 | +} |
180 | + | 391 | +const ARMCPRegInfo *get_arm_cp_reginfo(GHashTable *cpregs, uint32_t encoded_cp); |
181 | +/** | 392 | + |
182 | + * clock_propagate: | 393 | +/* |
183 | + * @clk: the clock | 394 | + * Definition of an ARM co-processor register as viewed from |
184 | + * | 395 | + * userspace. This is used for presenting sanitised versions of |
185 | + * Propagate the clock period that has been previously configured using | 396 | + * registers to userspace when emulating the Linux AArch64 CPU |
186 | + * @clock_set(). This will update recursively all connected clocks. | 397 | + * ID/feature ABI (advertised as HWCAP_CPUID). |
187 | + * It is an error to call this function on a clock which has a source. | 398 | + */ |
188 | + * Note: this function must not be called during device inititialization | 399 | +typedef struct ARMCPRegUserSpaceInfo { |
189 | + * or migration. | 400 | + /* Name of register */ |
190 | + */ | 401 | + const char *name; |
191 | +void clock_propagate(Clock *clk); | 402 | + |
192 | + | 403 | + /* Is the name actually a glob pattern */ |
193 | +/** | 404 | + bool is_glob; |
194 | + * clock_update: | 405 | + |
195 | + * @clk: the clock to update. | 406 | + /* Only some bits are exported to user space */ |
196 | + * @value: the new clock's value, 0 means unclocked | 407 | + uint64_t exported_bits; |
197 | + * | 408 | + |
198 | + * Update the @clk to the new @value. All connected clocks will be informed | 409 | + /* Fixed bits are applied after the mask */ |
199 | + * of this update. This is equivalent to call @clock_set() then | 410 | + uint64_t fixed_bits; |
200 | + * @clock_propagate(). | 411 | +} ARMCPRegUserSpaceInfo; |
201 | + */ | 412 | + |
202 | +static inline void clock_update(Clock *clk, uint64_t value) | 413 | +#define REGUSERINFO_SENTINEL { .name = NULL } |
414 | + | ||
415 | +void modify_arm_cp_regs(ARMCPRegInfo *regs, const ARMCPRegUserSpaceInfo *mods); | ||
416 | + | ||
417 | +/* CPWriteFn that can be used to implement writes-ignored behaviour */ | ||
418 | +void arm_cp_write_ignore(CPUARMState *env, const ARMCPRegInfo *ri, | ||
419 | + uint64_t value); | ||
420 | +/* CPReadFn that can be used for read-as-zero behaviour */ | ||
421 | +uint64_t arm_cp_read_zero(CPUARMState *env, const ARMCPRegInfo *ri); | ||
422 | + | ||
423 | +/* | ||
424 | + * CPResetFn that does nothing, for use if no reset is required even | ||
425 | + * if fieldoffset is non zero. | ||
426 | + */ | ||
427 | +void arm_cp_reset_ignore(CPUARMState *env, const ARMCPRegInfo *opaque); | ||
428 | + | ||
429 | +/* | ||
430 | + * Return true if this reginfo struct's field in the cpu state struct | ||
431 | + * is 64 bits wide. | ||
432 | + */ | ||
433 | +static inline bool cpreg_field_is_64bit(const ARMCPRegInfo *ri) | ||
203 | +{ | 434 | +{ |
204 | + clock_set(clk, value); | 435 | + return (ri->state == ARM_CP_STATE_AA64) || (ri->type & ARM_CP_64BIT); |
205 | + clock_propagate(clk); | ||
206 | +} | 436 | +} |
207 | + | 437 | + |
208 | +static inline void clock_update_hz(Clock *clk, unsigned hz) | 438 | +static inline bool cp_access_ok(int current_el, |
439 | + const ARMCPRegInfo *ri, int isread) | ||
209 | +{ | 440 | +{ |
210 | + clock_update(clk, CLOCK_PERIOD_FROM_HZ(hz)); | 441 | + return (ri->access >> ((current_el * 2) + isread)) & 1; |
211 | +} | 442 | +} |
212 | + | 443 | + |
213 | +static inline void clock_update_ns(Clock *clk, unsigned ns) | 444 | +/* Raw read of a coprocessor register (as needed for migration, etc) */ |
214 | +{ | 445 | +uint64_t read_raw_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri); |
215 | + clock_update(clk, CLOCK_PERIOD_FROM_NS(ns)); | 446 | + |
216 | +} | 447 | +#endif /* TARGET_ARM_CPREGS_H */ |
217 | + | 448 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
218 | +/** | 449 | index XXXXXXX..XXXXXXX 100644 |
219 | + * clock_get: | 450 | --- a/target/arm/cpu.h |
220 | + * @clk: the clk to fetch the clock | 451 | +++ b/target/arm/cpu.h |
221 | + * | 452 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t cpreg_to_kvm_id(uint32_t cpregid) |
222 | + * @return: the current period. | 453 | return kvmid; |
223 | + */ | 454 | } |
224 | +static inline uint64_t clock_get(const Clock *clk) | 455 | |
225 | +{ | 456 | -/* ARMCPRegInfo type field bits. If the SPECIAL bit is set this is a |
226 | + return clk->period; | 457 | - * special-behaviour cp reg and bits [11..8] indicate what behaviour |
227 | +} | 458 | - * it has. Otherwise it is a simple cp reg, where CONST indicates that |
228 | + | 459 | - * TCG can assume the value to be constant (ie load at translate time) |
229 | +static inline unsigned clock_get_hz(Clock *clk) | 460 | - * and 64BIT indicates a 64 bit wide coprocessor register. SUPPRESS_TB_END |
230 | +{ | 461 | - * indicates that the TB should not be ended after a write to this register |
231 | + return CLOCK_PERIOD_TO_HZ(clock_get(clk)); | 462 | - * (the default is that the TB ends after cp writes). OVERRIDE permits |
232 | +} | 463 | - * a register definition to override a previous definition for the |
233 | + | 464 | - * same (cp, is64, crn, crm, opc1, opc2) tuple: either the new or the |
234 | +static inline unsigned clock_get_ns(Clock *clk) | 465 | - * old must have the OVERRIDE bit set. |
235 | +{ | 466 | - * ALIAS indicates that this register is an alias view of some underlying |
236 | + return CLOCK_PERIOD_TO_NS(clock_get(clk)); | 467 | - * state which is also visible via another register, and that the other |
237 | +} | 468 | - * register is handling migration and reset; registers marked ALIAS will not be |
238 | + | 469 | - * migrated but may have their state set by syncing of register state from KVM. |
239 | +/** | 470 | - * NO_RAW indicates that this register has no underlying state and does not |
240 | + * clock_is_enabled: | 471 | - * support raw access for state saving/loading; it will not be used for either |
241 | + * @clk: a clock | 472 | - * migration or KVM state synchronization. (Typically this is for "registers" |
242 | + * | 473 | - * which are actually used as instructions for cache maintenance and so on.) |
243 | + * @return: true if the clock is running. | 474 | - * IO indicates that this register does I/O and therefore its accesses |
244 | + */ | 475 | - * need to be marked with gen_io_start() and also end the TB. In particular, |
245 | +static inline bool clock_is_enabled(const Clock *clk) | 476 | - * registers which implement clocks or timers require this. |
246 | +{ | 477 | - * RAISES_EXC is for when the read or write hook might raise an exception; |
247 | + return clock_get(clk) != 0; | 478 | - * the generated code will synchronize the CPU state before calling the hook |
248 | +} | 479 | - * so that it is safe for the hook to call raise_exception(). |
249 | + | 480 | - * NEWEL is for writes to registers that might change the exception |
250 | +static inline void clock_init(Clock *clk, uint64_t value) | 481 | - * level - typically on older ARM chips. For those cases we need to |
251 | +{ | 482 | - * re-read the new el when recomputing the translation flags. |
252 | + clock_set(clk, value); | 483 | - */ |
253 | +} | 484 | -#define ARM_CP_SPECIAL 0x0001 |
254 | +static inline void clock_init_hz(Clock *clk, uint64_t value) | 485 | -#define ARM_CP_CONST 0x0002 |
255 | +{ | 486 | -#define ARM_CP_64BIT 0x0004 |
256 | + clock_set_hz(clk, value); | 487 | -#define ARM_CP_SUPPRESS_TB_END 0x0008 |
257 | +} | 488 | -#define ARM_CP_OVERRIDE 0x0010 |
258 | +static inline void clock_init_ns(Clock *clk, uint64_t value) | 489 | -#define ARM_CP_ALIAS 0x0020 |
259 | +{ | 490 | -#define ARM_CP_IO 0x0040 |
260 | + clock_set_ns(clk, value); | 491 | -#define ARM_CP_NO_RAW 0x0080 |
261 | +} | 492 | -#define ARM_CP_NOP (ARM_CP_SPECIAL | 0x0100) |
262 | + | 493 | -#define ARM_CP_WFI (ARM_CP_SPECIAL | 0x0200) |
263 | +#endif /* QEMU_HW_CLOCK_H */ | 494 | -#define ARM_CP_NZCV (ARM_CP_SPECIAL | 0x0300) |
264 | diff --git a/hw/core/clock.c b/hw/core/clock.c | 495 | -#define ARM_CP_CURRENTEL (ARM_CP_SPECIAL | 0x0400) |
265 | new file mode 100644 | 496 | -#define ARM_CP_DC_ZVA (ARM_CP_SPECIAL | 0x0500) |
266 | index XXXXXXX..XXXXXXX | 497 | -#define ARM_CP_DC_GVA (ARM_CP_SPECIAL | 0x0600) |
267 | --- /dev/null | 498 | -#define ARM_CP_DC_GZVA (ARM_CP_SPECIAL | 0x0700) |
268 | +++ b/hw/core/clock.c | 499 | -#define ARM_LAST_SPECIAL ARM_CP_DC_GZVA |
269 | @@ -XXX,XX +XXX,XX @@ | 500 | -#define ARM_CP_FPU 0x1000 |
270 | +/* | 501 | -#define ARM_CP_SVE 0x2000 |
271 | + * Hardware Clocks | 502 | -#define ARM_CP_NO_GDB 0x4000 |
272 | + * | 503 | -#define ARM_CP_RAISES_EXC 0x8000 |
273 | + * Copyright GreenSocs 2016-2020 | 504 | -#define ARM_CP_NEWEL 0x10000 |
274 | + * | 505 | -/* Used only as a terminator for ARMCPRegInfo lists */ |
275 | + * Authors: | 506 | -#define ARM_CP_SENTINEL 0xfffff |
276 | + * Frederic Konrad | 507 | -/* Mask of only the flag bits in a type field */ |
277 | + * Damien Hedde | 508 | -#define ARM_CP_FLAG_MASK 0x1f0ff |
278 | + * | 509 | - |
279 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | 510 | -/* Valid values for ARMCPRegInfo state field, indicating which of |
280 | + * See the COPYING file in the top-level directory. | 511 | - * the AArch32 and AArch64 execution states this register is visible in. |
281 | + */ | 512 | - * If the reginfo doesn't explicitly specify then it is AArch32 only. |
282 | + | 513 | - * If the reginfo is declared to be visible in both states then a second |
283 | +#include "qemu/osdep.h" | 514 | - * reginfo is synthesised for the AArch32 view of the AArch64 register, |
284 | +#include "hw/clock.h" | 515 | - * such that the AArch32 view is the lower 32 bits of the AArch64 one. |
285 | +#include "trace.h" | 516 | - * Note that we rely on the values of these enums as we iterate through |
286 | + | 517 | - * the various states in some places. |
287 | +#define CLOCK_PATH(_clk) (_clk->canonical_path) | 518 | - */ |
288 | + | 519 | -enum { |
289 | +void clock_setup_canonical_path(Clock *clk) | 520 | - ARM_CP_STATE_AA32 = 0, |
290 | +{ | 521 | - ARM_CP_STATE_AA64 = 1, |
291 | + g_free(clk->canonical_path); | 522 | - ARM_CP_STATE_BOTH = 2, |
292 | + clk->canonical_path = object_get_canonical_path(OBJECT(clk)); | 523 | -}; |
293 | +} | 524 | - |
294 | + | 525 | -/* ARM CP register secure state flags. These flags identify security state |
295 | +void clock_set_callback(Clock *clk, ClockCallback *cb, void *opaque) | 526 | - * attributes for a given CP register entry. |
296 | +{ | 527 | - * The existence of both or neither secure and non-secure flags indicates that |
297 | + clk->callback = cb; | 528 | - * the register has both a secure and non-secure hash entry. A single one of |
298 | + clk->callback_opaque = opaque; | 529 | - * these flags causes the register to only be hashed for the specified |
299 | +} | 530 | - * security state. |
300 | + | 531 | - * Although definitions may have any combination of the S/NS bits, each |
301 | +void clock_clear_callback(Clock *clk) | 532 | - * registered entry will only have one to identify whether the entry is secure |
302 | +{ | 533 | - * or non-secure. |
303 | + clock_set_callback(clk, NULL, NULL); | 534 | - */ |
304 | +} | 535 | -enum { |
305 | + | 536 | - ARM_CP_SECSTATE_S = (1 << 0), /* bit[0]: Secure state register */ |
306 | +void clock_set(Clock *clk, uint64_t period) | 537 | - ARM_CP_SECSTATE_NS = (1 << 1), /* bit[1]: Non-secure state register */ |
307 | +{ | 538 | -}; |
308 | + trace_clock_set(CLOCK_PATH(clk), CLOCK_PERIOD_TO_NS(clk->period), | 539 | - |
309 | + CLOCK_PERIOD_TO_NS(period)); | 540 | -/* Return true if cptype is a valid type field. This is used to try to |
310 | + clk->period = period; | 541 | - * catch errors where the sentinel has been accidentally left off the end |
311 | +} | 542 | - * of a list of registers. |
312 | + | 543 | - */ |
313 | +static void clock_propagate_period(Clock *clk, bool call_callbacks) | 544 | -static inline bool cptype_valid(int cptype) |
314 | +{ | 545 | -{ |
315 | + Clock *child; | 546 | - return ((cptype & ~ARM_CP_FLAG_MASK) == 0) |
316 | + | 547 | - || ((cptype & ARM_CP_SPECIAL) && |
317 | + QLIST_FOREACH(child, &clk->children, sibling) { | 548 | - ((cptype & ~ARM_CP_FLAG_MASK) <= ARM_LAST_SPECIAL)); |
318 | + if (child->period != clk->period) { | 549 | -} |
319 | + child->period = clk->period; | 550 | - |
320 | + trace_clock_update(CLOCK_PATH(child), CLOCK_PATH(clk), | 551 | -/* Access rights: |
321 | + CLOCK_PERIOD_TO_NS(clk->period), | 552 | - * We define bits for Read and Write access for what rev C of the v7-AR ARM ARM |
322 | + call_callbacks); | 553 | - * defines as PL0 (user), PL1 (fiq/irq/svc/abt/und/sys, ie privileged), and |
323 | + if (call_callbacks && child->callback) { | 554 | - * PL2 (hyp). The other level which has Read and Write bits is Secure PL1 |
324 | + child->callback(child->callback_opaque); | 555 | - * (ie any of the privileged modes in Secure state, or Monitor mode). |
325 | + } | 556 | - * If a register is accessible in one privilege level it's always accessible |
326 | + clock_propagate_period(child, call_callbacks); | 557 | - * in higher privilege levels too. Since "Secure PL1" also follows this rule |
327 | + } | 558 | - * (ie anything visible in PL2 is visible in S-PL1, some things are only |
328 | + } | 559 | - * visible in S-PL1) but "Secure PL1" is a bit of a mouthful, we bend the |
329 | +} | 560 | - * terminology a little and call this PL3. |
330 | + | 561 | - * In AArch64 things are somewhat simpler as the PLx bits line up exactly |
331 | +void clock_propagate(Clock *clk) | 562 | - * with the ELx exception levels. |
332 | +{ | 563 | - * |
333 | + assert(clk->source == NULL); | 564 | - * If access permissions for a register are more complex than can be |
334 | + trace_clock_propagate(CLOCK_PATH(clk)); | 565 | - * described with these bits, then use a laxer set of restrictions, and |
335 | + clock_propagate_period(clk, true); | 566 | - * do the more restrictive/complex check inside a helper function. |
336 | +} | 567 | - */ |
337 | + | 568 | -#define PL3_R 0x80 |
338 | +void clock_set_source(Clock *clk, Clock *src) | 569 | -#define PL3_W 0x40 |
339 | +{ | 570 | -#define PL2_R (0x20 | PL3_R) |
340 | + /* changing clock source is not supported */ | 571 | -#define PL2_W (0x10 | PL3_W) |
341 | + assert(!clk->source); | 572 | -#define PL1_R (0x08 | PL2_R) |
342 | + | 573 | -#define PL1_W (0x04 | PL2_W) |
343 | + trace_clock_set_source(CLOCK_PATH(clk), CLOCK_PATH(src)); | 574 | -#define PL0_R (0x02 | PL1_R) |
344 | + | 575 | -#define PL0_W (0x01 | PL1_W) |
345 | + clk->period = src->period; | 576 | - |
346 | + QLIST_INSERT_HEAD(&src->children, clk, sibling); | 577 | -/* |
347 | + clk->source = src; | 578 | - * For user-mode some registers are accessible to EL0 via a kernel |
348 | + clock_propagate_period(clk, false); | 579 | - * trap-and-emulate ABI. In this case we define the read permissions |
349 | +} | 580 | - * as actually being PL0_R. However some bits of any given register |
350 | + | 581 | - * may still be masked. |
351 | +static void clock_disconnect(Clock *clk) | 582 | - */ |
352 | +{ | 583 | -#ifdef CONFIG_USER_ONLY |
353 | + if (clk->source == NULL) { | 584 | -#define PL0U_R PL0_R |
354 | + return; | 585 | -#else |
355 | + } | 586 | -#define PL0U_R PL1_R |
356 | + | 587 | -#endif |
357 | + trace_clock_disconnect(CLOCK_PATH(clk)); | 588 | - |
358 | + | 589 | -#define PL3_RW (PL3_R | PL3_W) |
359 | + clk->source = NULL; | 590 | -#define PL2_RW (PL2_R | PL2_W) |
360 | + QLIST_REMOVE(clk, sibling); | 591 | -#define PL1_RW (PL1_R | PL1_W) |
361 | +} | 592 | -#define PL0_RW (PL0_R | PL0_W) |
362 | + | 593 | - |
363 | +static void clock_initfn(Object *obj) | 594 | /* Return the highest implemented Exception Level */ |
364 | +{ | 595 | static inline int arm_highest_el(CPUARMState *env) |
365 | + Clock *clk = CLOCK(obj); | 596 | { |
366 | + | 597 | @@ -XXX,XX +XXX,XX @@ static inline int arm_current_el(CPUARMState *env) |
367 | + QLIST_INIT(&clk->children); | 598 | } |
368 | +} | 599 | } |
369 | + | 600 | |
370 | +static void clock_finalizefn(Object *obj) | 601 | -typedef struct ARMCPRegInfo ARMCPRegInfo; |
371 | +{ | 602 | - |
372 | + Clock *clk = CLOCK(obj); | 603 | -typedef enum CPAccessResult { |
373 | + Clock *child, *next; | 604 | - /* Access is permitted */ |
374 | + | 605 | - CP_ACCESS_OK = 0, |
375 | + /* clear our list of children */ | 606 | - /* Access fails due to a configurable trap or enable which would |
376 | + QLIST_FOREACH_SAFE(child, &clk->children, sibling, next) { | 607 | - * result in a categorized exception syndrome giving information about |
377 | + clock_disconnect(child); | 608 | - * the failing instruction (ie syndrome category 0x3, 0x4, 0x5, 0x6, |
378 | + } | 609 | - * 0xc or 0x18). The exception is taken to the usual target EL (EL1 or |
379 | + | 610 | - * PL1 if in EL0, otherwise to the current EL). |
380 | + /* remove us from source's children list */ | 611 | - */ |
381 | + clock_disconnect(clk); | 612 | - CP_ACCESS_TRAP = 1, |
382 | + | 613 | - /* Access fails and results in an exception syndrome 0x0 ("uncategorized"). |
383 | + g_free(clk->canonical_path); | 614 | - * Note that this is not a catch-all case -- the set of cases which may |
384 | +} | 615 | - * result in this failure is specifically defined by the architecture. |
385 | + | 616 | - */ |
386 | +static const TypeInfo clock_info = { | 617 | - CP_ACCESS_TRAP_UNCATEGORIZED = 2, |
387 | + .name = TYPE_CLOCK, | 618 | - /* As CP_ACCESS_TRAP, but for traps directly to EL2 or EL3 */ |
388 | + .parent = TYPE_OBJECT, | 619 | - CP_ACCESS_TRAP_EL2 = 3, |
389 | + .instance_size = sizeof(Clock), | 620 | - CP_ACCESS_TRAP_EL3 = 4, |
390 | + .instance_init = clock_initfn, | 621 | - /* As CP_ACCESS_UNCATEGORIZED, but for traps directly to EL2 or EL3 */ |
391 | + .instance_finalize = clock_finalizefn, | 622 | - CP_ACCESS_TRAP_UNCATEGORIZED_EL2 = 5, |
392 | +}; | 623 | - CP_ACCESS_TRAP_UNCATEGORIZED_EL3 = 6, |
393 | + | 624 | -} CPAccessResult; |
394 | +static void clock_register_types(void) | 625 | - |
395 | +{ | 626 | -/* Access functions for coprocessor registers. These cannot fail and |
396 | + type_register_static(&clock_info); | 627 | - * may not raise exceptions. |
397 | +} | 628 | - */ |
398 | + | 629 | -typedef uint64_t CPReadFn(CPUARMState *env, const ARMCPRegInfo *opaque); |
399 | +type_init(clock_register_types) | 630 | -typedef void CPWriteFn(CPUARMState *env, const ARMCPRegInfo *opaque, |
400 | diff --git a/hw/core/trace-events b/hw/core/trace-events | 631 | - uint64_t value); |
401 | index XXXXXXX..XXXXXXX 100644 | 632 | -/* Access permission check functions for coprocessor registers. */ |
402 | --- a/hw/core/trace-events | 633 | -typedef CPAccessResult CPAccessFn(CPUARMState *env, |
403 | +++ b/hw/core/trace-events | 634 | - const ARMCPRegInfo *opaque, |
404 | @@ -XXX,XX +XXX,XX @@ resettable_phase_exit_begin(void *obj, const char *objtype, unsigned count, int | 635 | - bool isread); |
405 | resettable_phase_exit_exec(void *obj, const char *objtype, int has_method) "obj=%p(%s) method=%d" | 636 | -/* Hook function for register reset */ |
406 | resettable_phase_exit_end(void *obj, const char *objtype, unsigned count) "obj=%p(%s) count=%d" | 637 | -typedef void CPResetFn(CPUARMState *env, const ARMCPRegInfo *opaque); |
407 | resettable_transitional_function(void *obj, const char *objtype) "obj=%p(%s)" | 638 | - |
408 | + | 639 | -#define CP_ANY 0xff |
409 | +# clock.c | 640 | - |
410 | +clock_set_source(const char *clk, const char *src) "'%s', src='%s'" | 641 | -/* Definition of an ARM coprocessor register */ |
411 | +clock_disconnect(const char *clk) "'%s'" | 642 | -struct ARMCPRegInfo { |
412 | +clock_set(const char *clk, uint64_t old, uint64_t new) "'%s', ns=%"PRIu64"->%"PRIu64 | 643 | - /* Name of register (useful mainly for debugging, need not be unique) */ |
413 | +clock_propagate(const char *clk) "'%s'" | 644 | - const char *name; |
414 | +clock_update(const char *clk, const char *src, uint64_t val, int cb) "'%s', src='%s', ns=%"PRIu64", cb=%d" | 645 | - /* Location of register: coprocessor number and (crn,crm,opc1,opc2) |
646 | - * tuple. Any of crm, opc1 and opc2 may be CP_ANY to indicate a | ||
647 | - * 'wildcard' field -- any value of that field in the MRC/MCR insn | ||
648 | - * will be decoded to this register. The register read and write | ||
649 | - * callbacks will be passed an ARMCPRegInfo with the crn/crm/opc1/opc2 | ||
650 | - * used by the program, so it is possible to register a wildcard and | ||
651 | - * then behave differently on read/write if necessary. | ||
652 | - * For 64 bit registers, only crm and opc1 are relevant; crn and opc2 | ||
653 | - * must both be zero. | ||
654 | - * For AArch64-visible registers, opc0 is also used. | ||
655 | - * Since there are no "coprocessors" in AArch64, cp is purely used as a | ||
656 | - * way to distinguish (for KVM's benefit) guest-visible system registers | ||
657 | - * from demuxed ones provided to preserve the "no side effects on | ||
658 | - * KVM register read/write from QEMU" semantics. cp==0x13 is guest | ||
659 | - * visible (to match KVM's encoding); cp==0 will be converted to | ||
660 | - * cp==0x13 when the ARMCPRegInfo is registered, for convenience. | ||
661 | - */ | ||
662 | - uint8_t cp; | ||
663 | - uint8_t crn; | ||
664 | - uint8_t crm; | ||
665 | - uint8_t opc0; | ||
666 | - uint8_t opc1; | ||
667 | - uint8_t opc2; | ||
668 | - /* Execution state in which this register is visible: ARM_CP_STATE_* */ | ||
669 | - int state; | ||
670 | - /* Register type: ARM_CP_* bits/values */ | ||
671 | - int type; | ||
672 | - /* Access rights: PL*_[RW] */ | ||
673 | - int access; | ||
674 | - /* Security state: ARM_CP_SECSTATE_* bits/values */ | ||
675 | - int secure; | ||
676 | - /* The opaque pointer passed to define_arm_cp_regs_with_opaque() when | ||
677 | - * this register was defined: can be used to hand data through to the | ||
678 | - * register read/write functions, since they are passed the ARMCPRegInfo*. | ||
679 | - */ | ||
680 | - void *opaque; | ||
681 | - /* Value of this register, if it is ARM_CP_CONST. Otherwise, if | ||
682 | - * fieldoffset is non-zero, the reset value of the register. | ||
683 | - */ | ||
684 | - uint64_t resetvalue; | ||
685 | - /* Offset of the field in CPUARMState for this register. | ||
686 | - * | ||
687 | - * This is not needed if either: | ||
688 | - * 1. type is ARM_CP_CONST or one of the ARM_CP_SPECIALs | ||
689 | - * 2. both readfn and writefn are specified | ||
690 | - */ | ||
691 | - ptrdiff_t fieldoffset; /* offsetof(CPUARMState, field) */ | ||
692 | - | ||
693 | - /* Offsets of the secure and non-secure fields in CPUARMState for the | ||
694 | - * register if it is banked. These fields are only used during the static | ||
695 | - * registration of a register. During hashing the bank associated | ||
696 | - * with a given security state is copied to fieldoffset which is used from | ||
697 | - * there on out. | ||
698 | - * | ||
699 | - * It is expected that register definitions use either fieldoffset or | ||
700 | - * bank_fieldoffsets in the definition but not both. It is also expected | ||
701 | - * that both bank offsets are set when defining a banked register. This | ||
702 | - * use indicates that a register is banked. | ||
703 | - */ | ||
704 | - ptrdiff_t bank_fieldoffsets[2]; | ||
705 | - | ||
706 | - /* Function for making any access checks for this register in addition to | ||
707 | - * those specified by the 'access' permissions bits. If NULL, no extra | ||
708 | - * checks required. The access check is performed at runtime, not at | ||
709 | - * translate time. | ||
710 | - */ | ||
711 | - CPAccessFn *accessfn; | ||
712 | - /* Function for handling reads of this register. If NULL, then reads | ||
713 | - * will be done by loading from the offset into CPUARMState specified | ||
714 | - * by fieldoffset. | ||
715 | - */ | ||
716 | - CPReadFn *readfn; | ||
717 | - /* Function for handling writes of this register. If NULL, then writes | ||
718 | - * will be done by writing to the offset into CPUARMState specified | ||
719 | - * by fieldoffset. | ||
720 | - */ | ||
721 | - CPWriteFn *writefn; | ||
722 | - /* Function for doing a "raw" read; used when we need to copy | ||
723 | - * coprocessor state to the kernel for KVM or out for | ||
724 | - * migration. This only needs to be provided if there is also a | ||
725 | - * readfn and it has side effects (for instance clear-on-read bits). | ||
726 | - */ | ||
727 | - CPReadFn *raw_readfn; | ||
728 | - /* Function for doing a "raw" write; used when we need to copy KVM | ||
729 | - * kernel coprocessor state into userspace, or for inbound | ||
730 | - * migration. This only needs to be provided if there is also a | ||
731 | - * writefn and it masks out "unwritable" bits or has write-one-to-clear | ||
732 | - * or similar behaviour. | ||
733 | - */ | ||
734 | - CPWriteFn *raw_writefn; | ||
735 | - /* Function for resetting the register. If NULL, then reset will be done | ||
736 | - * by writing resetvalue to the field specified in fieldoffset. If | ||
737 | - * fieldoffset is 0 then no reset will be done. | ||
738 | - */ | ||
739 | - CPResetFn *resetfn; | ||
740 | - | ||
741 | - /* | ||
742 | - * "Original" writefn and readfn. | ||
743 | - * For ARMv8.1-VHE register aliases, we overwrite the read/write | ||
744 | - * accessor functions of various EL1/EL0 to perform the runtime | ||
745 | - * check for which sysreg should actually be modified, and then | ||
746 | - * forwards the operation. Before overwriting the accessors, | ||
747 | - * the original function is copied here, so that accesses that | ||
748 | - * really do go to the EL1/EL0 version proceed normally. | ||
749 | - * (The corresponding EL2 register is linked via opaque.) | ||
750 | - */ | ||
751 | - CPReadFn *orig_readfn; | ||
752 | - CPWriteFn *orig_writefn; | ||
753 | -}; | ||
754 | - | ||
755 | -/* Macros which are lvalues for the field in CPUARMState for the | ||
756 | - * ARMCPRegInfo *ri. | ||
757 | - */ | ||
758 | -#define CPREG_FIELD32(env, ri) \ | ||
759 | - (*(uint32_t *)((char *)(env) + (ri)->fieldoffset)) | ||
760 | -#define CPREG_FIELD64(env, ri) \ | ||
761 | - (*(uint64_t *)((char *)(env) + (ri)->fieldoffset)) | ||
762 | - | ||
763 | -#define REGINFO_SENTINEL { .type = ARM_CP_SENTINEL } | ||
764 | - | ||
765 | -void define_arm_cp_regs_with_opaque(ARMCPU *cpu, | ||
766 | - const ARMCPRegInfo *regs, void *opaque); | ||
767 | -void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, | ||
768 | - const ARMCPRegInfo *regs, void *opaque); | ||
769 | -static inline void define_arm_cp_regs(ARMCPU *cpu, const ARMCPRegInfo *regs) | ||
770 | -{ | ||
771 | - define_arm_cp_regs_with_opaque(cpu, regs, 0); | ||
772 | -} | ||
773 | -static inline void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *regs) | ||
774 | -{ | ||
775 | - define_one_arm_cp_reg_with_opaque(cpu, regs, 0); | ||
776 | -} | ||
777 | -const ARMCPRegInfo *get_arm_cp_reginfo(GHashTable *cpregs, uint32_t encoded_cp); | ||
778 | - | ||
779 | -/* | ||
780 | - * Definition of an ARM co-processor register as viewed from | ||
781 | - * userspace. This is used for presenting sanitised versions of | ||
782 | - * registers to userspace when emulating the Linux AArch64 CPU | ||
783 | - * ID/feature ABI (advertised as HWCAP_CPUID). | ||
784 | - */ | ||
785 | -typedef struct ARMCPRegUserSpaceInfo { | ||
786 | - /* Name of register */ | ||
787 | - const char *name; | ||
788 | - | ||
789 | - /* Is the name actually a glob pattern */ | ||
790 | - bool is_glob; | ||
791 | - | ||
792 | - /* Only some bits are exported to user space */ | ||
793 | - uint64_t exported_bits; | ||
794 | - | ||
795 | - /* Fixed bits are applied after the mask */ | ||
796 | - uint64_t fixed_bits; | ||
797 | -} ARMCPRegUserSpaceInfo; | ||
798 | - | ||
799 | -#define REGUSERINFO_SENTINEL { .name = NULL } | ||
800 | - | ||
801 | -void modify_arm_cp_regs(ARMCPRegInfo *regs, const ARMCPRegUserSpaceInfo *mods); | ||
802 | - | ||
803 | -/* CPWriteFn that can be used to implement writes-ignored behaviour */ | ||
804 | -void arm_cp_write_ignore(CPUARMState *env, const ARMCPRegInfo *ri, | ||
805 | - uint64_t value); | ||
806 | -/* CPReadFn that can be used for read-as-zero behaviour */ | ||
807 | -uint64_t arm_cp_read_zero(CPUARMState *env, const ARMCPRegInfo *ri); | ||
808 | - | ||
809 | -/* CPResetFn that does nothing, for use if no reset is required even | ||
810 | - * if fieldoffset is non zero. | ||
811 | - */ | ||
812 | -void arm_cp_reset_ignore(CPUARMState *env, const ARMCPRegInfo *opaque); | ||
813 | - | ||
814 | -/* Return true if this reginfo struct's field in the cpu state struct | ||
815 | - * is 64 bits wide. | ||
816 | - */ | ||
817 | -static inline bool cpreg_field_is_64bit(const ARMCPRegInfo *ri) | ||
818 | -{ | ||
819 | - return (ri->state == ARM_CP_STATE_AA64) || (ri->type & ARM_CP_64BIT); | ||
820 | -} | ||
821 | - | ||
822 | -static inline bool cp_access_ok(int current_el, | ||
823 | - const ARMCPRegInfo *ri, int isread) | ||
824 | -{ | ||
825 | - return (ri->access >> ((current_el * 2) + isread)) & 1; | ||
826 | -} | ||
827 | - | ||
828 | -/* Raw read of a coprocessor register (as needed for migration, etc) */ | ||
829 | -uint64_t read_raw_cp_reg(CPUARMState *env, const ARMCPRegInfo *ri); | ||
830 | - | ||
831 | /** | ||
832 | * write_list_to_cpustate | ||
833 | * @cpu: ARMCPU | ||
834 | diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c | ||
835 | index XXXXXXX..XXXXXXX 100644 | ||
836 | --- a/hw/arm/pxa2xx.c | ||
837 | +++ b/hw/arm/pxa2xx.c | ||
838 | @@ -XXX,XX +XXX,XX @@ | ||
839 | #include "qemu/cutils.h" | ||
840 | #include "qemu/log.h" | ||
841 | #include "qom/object.h" | ||
842 | +#include "target/arm/cpregs.h" | ||
843 | |||
844 | static struct { | ||
845 | hwaddr io_base; | ||
846 | diff --git a/hw/arm/pxa2xx_pic.c b/hw/arm/pxa2xx_pic.c | ||
847 | index XXXXXXX..XXXXXXX 100644 | ||
848 | --- a/hw/arm/pxa2xx_pic.c | ||
849 | +++ b/hw/arm/pxa2xx_pic.c | ||
850 | @@ -XXX,XX +XXX,XX @@ | ||
851 | #include "hw/sysbus.h" | ||
852 | #include "migration/vmstate.h" | ||
853 | #include "qom/object.h" | ||
854 | +#include "target/arm/cpregs.h" | ||
855 | |||
856 | #define ICIP 0x00 /* Interrupt Controller IRQ Pending register */ | ||
857 | #define ICMR 0x04 /* Interrupt Controller Mask register */ | ||
858 | diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c | ||
859 | index XXXXXXX..XXXXXXX 100644 | ||
860 | --- a/hw/intc/arm_gicv3_cpuif.c | ||
861 | +++ b/hw/intc/arm_gicv3_cpuif.c | ||
862 | @@ -XXX,XX +XXX,XX @@ | ||
863 | #include "gicv3_internal.h" | ||
864 | #include "hw/irq.h" | ||
865 | #include "cpu.h" | ||
866 | +#include "target/arm/cpregs.h" | ||
867 | |||
868 | /* | ||
869 | * Special case return value from hppvi_index(); must be larger than | ||
870 | diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c | ||
871 | index XXXXXXX..XXXXXXX 100644 | ||
872 | --- a/hw/intc/arm_gicv3_kvm.c | ||
873 | +++ b/hw/intc/arm_gicv3_kvm.c | ||
874 | @@ -XXX,XX +XXX,XX @@ | ||
875 | #include "vgic_common.h" | ||
876 | #include "migration/blocker.h" | ||
877 | #include "qom/object.h" | ||
878 | +#include "target/arm/cpregs.h" | ||
879 | + | ||
880 | |||
881 | #ifdef DEBUG_GICV3_KVM | ||
882 | #define DPRINTF(fmt, ...) \ | ||
883 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
884 | index XXXXXXX..XXXXXXX 100644 | ||
885 | --- a/target/arm/cpu.c | ||
886 | +++ b/target/arm/cpu.c | ||
887 | @@ -XXX,XX +XXX,XX @@ | ||
888 | #include "kvm_arm.h" | ||
889 | #include "disas/capstone.h" | ||
890 | #include "fpu/softfloat.h" | ||
891 | +#include "cpregs.h" | ||
892 | |||
893 | static void arm_cpu_set_pc(CPUState *cs, vaddr value) | ||
894 | { | ||
895 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | ||
896 | index XXXXXXX..XXXXXXX 100644 | ||
897 | --- a/target/arm/cpu64.c | ||
898 | +++ b/target/arm/cpu64.c | ||
899 | @@ -XXX,XX +XXX,XX @@ | ||
900 | #include "hvf_arm.h" | ||
901 | #include "qapi/visitor.h" | ||
902 | #include "hw/qdev-properties.h" | ||
903 | +#include "cpregs.h" | ||
904 | |||
905 | |||
906 | #ifndef CONFIG_USER_ONLY | ||
907 | diff --git a/target/arm/cpu_tcg.c b/target/arm/cpu_tcg.c | ||
908 | index XXXXXXX..XXXXXXX 100644 | ||
909 | --- a/target/arm/cpu_tcg.c | ||
910 | +++ b/target/arm/cpu_tcg.c | ||
911 | @@ -XXX,XX +XXX,XX @@ | ||
912 | #if !defined(CONFIG_USER_ONLY) | ||
913 | #include "hw/boards.h" | ||
914 | #endif | ||
915 | +#include "cpregs.h" | ||
916 | |||
917 | /* CPU models. These are not needed for the AArch64 linux-user build. */ | ||
918 | #if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64) | ||
919 | diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c | ||
920 | index XXXXXXX..XXXXXXX 100644 | ||
921 | --- a/target/arm/gdbstub.c | ||
922 | +++ b/target/arm/gdbstub.c | ||
923 | @@ -XXX,XX +XXX,XX @@ | ||
924 | */ | ||
925 | #include "qemu/osdep.h" | ||
926 | #include "cpu.h" | ||
927 | -#include "internals.h" | ||
928 | #include "exec/gdbstub.h" | ||
929 | +#include "internals.h" | ||
930 | +#include "cpregs.h" | ||
931 | |||
932 | typedef struct RegisterSysregXmlParam { | ||
933 | CPUState *cs; | ||
934 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
935 | index XXXXXXX..XXXXXXX 100644 | ||
936 | --- a/target/arm/helper.c | ||
937 | +++ b/target/arm/helper.c | ||
938 | @@ -XXX,XX +XXX,XX @@ | ||
939 | #include "exec/cpu_ldst.h" | ||
940 | #include "semihosting/common-semi.h" | ||
941 | #endif | ||
942 | +#include "cpregs.h" | ||
943 | |||
944 | #define ARM_CPU_FREQ 1000000000 /* FIXME: 1 GHz, should be configurable */ | ||
945 | #define PMCR_NUM_COUNTERS 4 /* QEMU IMPDEF choice */ | ||
946 | diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c | ||
947 | index XXXXXXX..XXXXXXX 100644 | ||
948 | --- a/target/arm/op_helper.c | ||
949 | +++ b/target/arm/op_helper.c | ||
950 | @@ -XXX,XX +XXX,XX @@ | ||
951 | #include "internals.h" | ||
952 | #include "exec/exec-all.h" | ||
953 | #include "exec/cpu_ldst.h" | ||
954 | +#include "cpregs.h" | ||
955 | |||
956 | #define SIGNBIT (uint32_t)0x80000000 | ||
957 | #define SIGNBIT64 ((uint64_t)1 << 63) | ||
958 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
959 | index XXXXXXX..XXXXXXX 100644 | ||
960 | --- a/target/arm/translate-a64.c | ||
961 | +++ b/target/arm/translate-a64.c | ||
962 | @@ -XXX,XX +XXX,XX @@ | ||
963 | #include "translate.h" | ||
964 | #include "internals.h" | ||
965 | #include "qemu/host-utils.h" | ||
966 | - | ||
967 | #include "semihosting/semihost.h" | ||
968 | #include "exec/gen-icount.h" | ||
969 | - | ||
970 | #include "exec/helper-proto.h" | ||
971 | #include "exec/helper-gen.h" | ||
972 | #include "exec/log.h" | ||
973 | - | ||
974 | +#include "cpregs.h" | ||
975 | #include "translate-a64.h" | ||
976 | #include "qemu/atomic128.h" | ||
977 | |||
978 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
979 | index XXXXXXX..XXXXXXX 100644 | ||
980 | --- a/target/arm/translate.c | ||
981 | +++ b/target/arm/translate.c | ||
982 | @@ -XXX,XX +XXX,XX @@ | ||
983 | #include "qemu/bitops.h" | ||
984 | #include "arm_ldst.h" | ||
985 | #include "semihosting/semihost.h" | ||
986 | - | ||
987 | #include "exec/helper-proto.h" | ||
988 | #include "exec/helper-gen.h" | ||
989 | - | ||
990 | #include "exec/log.h" | ||
991 | +#include "cpregs.h" | ||
992 | |||
993 | |||
994 | #define ENABLE_ARCH_4T arm_dc_feature(s, ARM_FEATURE_V4T) | ||
415 | -- | 995 | -- |
416 | 2.20.1 | 996 | 2.25.1 |
417 | 997 | ||
418 | 998 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add some clocks to zynq_slcr | 3 | Rearrange the values of the enumerators of CPAccessResult |
4 | + the main input clock (ps_clk) | 4 | so that we may directly extract the target el. For the two |
5 | + the reference clock outputs for each uart (uart0 & 1) | 5 | special cases in access_check_cp_reg, use CPAccessResult. |
6 | 6 | ||
7 | This commit also transitional the slcr to multi-phase reset as it is | 7 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
8 | required to initialize the clocks correctly. | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | 9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | |
10 | The clock frequencies are computed using the internal pll & uart configuration | 10 | Message-id: 20220501055028.646596-3-richard.henderson@linaro.org |
11 | registers and the input ps_clk frequency. | ||
12 | |||
13 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
14 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
15 | Acked-by: Alistair Francis <alistair.francis@wdc.com> | ||
16 | Message-id: 20200406135251.157596-7-damien.hedde@greensocs.com | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | --- | 12 | --- |
19 | hw/misc/zynq_slcr.c | 172 ++++++++++++++++++++++++++++++++++++++++++-- | 13 | target/arm/cpregs.h | 26 ++++++++++++-------- |
20 | 1 file changed, 168 insertions(+), 4 deletions(-) | 14 | target/arm/op_helper.c | 56 +++++++++++++++++++++--------------------- |
15 | 2 files changed, 44 insertions(+), 38 deletions(-) | ||
21 | 16 | ||
22 | diff --git a/hw/misc/zynq_slcr.c b/hw/misc/zynq_slcr.c | 17 | diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h |
23 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
24 | --- a/hw/misc/zynq_slcr.c | 19 | --- a/target/arm/cpregs.h |
25 | +++ b/hw/misc/zynq_slcr.c | 20 | +++ b/target/arm/cpregs.h |
26 | @@ -XXX,XX +XXX,XX @@ | 21 | @@ -XXX,XX +XXX,XX @@ static inline bool cptype_valid(int cptype) |
27 | #include "qemu/log.h" | 22 | typedef enum CPAccessResult { |
28 | #include "qemu/module.h" | 23 | /* Access is permitted */ |
29 | #include "hw/registerfields.h" | 24 | CP_ACCESS_OK = 0, |
30 | +#include "hw/qdev-clock.h" | ||
31 | |||
32 | #ifndef ZYNQ_SLCR_ERR_DEBUG | ||
33 | #define ZYNQ_SLCR_ERR_DEBUG 0 | ||
34 | @@ -XXX,XX +XXX,XX @@ REG32(LOCKSTA, 0x00c) | ||
35 | REG32(ARM_PLL_CTRL, 0x100) | ||
36 | REG32(DDR_PLL_CTRL, 0x104) | ||
37 | REG32(IO_PLL_CTRL, 0x108) | ||
38 | +/* fields for [ARM|DDR|IO]_PLL_CTRL registers */ | ||
39 | + FIELD(xxx_PLL_CTRL, PLL_RESET, 0, 1) | ||
40 | + FIELD(xxx_PLL_CTRL, PLL_PWRDWN, 1, 1) | ||
41 | + FIELD(xxx_PLL_CTRL, PLL_BYPASS_QUAL, 3, 1) | ||
42 | + FIELD(xxx_PLL_CTRL, PLL_BYPASS_FORCE, 4, 1) | ||
43 | + FIELD(xxx_PLL_CTRL, PLL_FPDIV, 12, 7) | ||
44 | REG32(PLL_STATUS, 0x10c) | ||
45 | REG32(ARM_PLL_CFG, 0x110) | ||
46 | REG32(DDR_PLL_CFG, 0x114) | ||
47 | @@ -XXX,XX +XXX,XX @@ REG32(SMC_CLK_CTRL, 0x148) | ||
48 | REG32(LQSPI_CLK_CTRL, 0x14c) | ||
49 | REG32(SDIO_CLK_CTRL, 0x150) | ||
50 | REG32(UART_CLK_CTRL, 0x154) | ||
51 | + FIELD(UART_CLK_CTRL, CLKACT0, 0, 1) | ||
52 | + FIELD(UART_CLK_CTRL, CLKACT1, 1, 1) | ||
53 | + FIELD(UART_CLK_CTRL, SRCSEL, 4, 2) | ||
54 | + FIELD(UART_CLK_CTRL, DIVISOR, 8, 6) | ||
55 | REG32(SPI_CLK_CTRL, 0x158) | ||
56 | REG32(CAN_CLK_CTRL, 0x15c) | ||
57 | REG32(CAN_MIOCLK_CTRL, 0x160) | ||
58 | @@ -XXX,XX +XXX,XX @@ typedef struct ZynqSLCRState { | ||
59 | MemoryRegion iomem; | ||
60 | |||
61 | uint32_t regs[ZYNQ_SLCR_NUM_REGS]; | ||
62 | + | 25 | + |
63 | + Clock *ps_clk; | 26 | + /* |
64 | + Clock *uart0_ref_clk; | 27 | + * Combined with one of the following, the low 2 bits indicate the |
65 | + Clock *uart1_ref_clk; | 28 | + * target exception level. If 0, the exception is taken to the usual |
66 | } ZynqSLCRState; | 29 | + * target EL (EL1 or PL1 if in EL0, otherwise to the current EL). |
67 | 30 | + */ | |
68 | -static void zynq_slcr_reset(DeviceState *d) | 31 | + CP_ACCESS_EL_MASK = 3, |
69 | +/* | 32 | + |
70 | + * return the output frequency of ARM/DDR/IO pll | 33 | /* |
71 | + * using input frequency and PLL_CTRL register | 34 | * Access fails due to a configurable trap or enable which would |
72 | + */ | 35 | * result in a categorized exception syndrome giving information about |
73 | +static uint64_t zynq_slcr_compute_pll(uint64_t input, uint32_t ctrl_reg) | 36 | * the failing instruction (ie syndrome category 0x3, 0x4, 0x5, 0x6, |
37 | - * 0xc or 0x18). The exception is taken to the usual target EL (EL1 or | ||
38 | - * PL1 if in EL0, otherwise to the current EL). | ||
39 | + * 0xc or 0x18). | ||
40 | */ | ||
41 | - CP_ACCESS_TRAP = 1, | ||
42 | + CP_ACCESS_TRAP = (1 << 2), | ||
43 | + CP_ACCESS_TRAP_EL2 = CP_ACCESS_TRAP | 2, | ||
44 | + CP_ACCESS_TRAP_EL3 = CP_ACCESS_TRAP | 3, | ||
45 | + | ||
46 | /* | ||
47 | * Access fails and results in an exception syndrome 0x0 ("uncategorized"). | ||
48 | * Note that this is not a catch-all case -- the set of cases which may | ||
49 | * result in this failure is specifically defined by the architecture. | ||
50 | */ | ||
51 | - CP_ACCESS_TRAP_UNCATEGORIZED = 2, | ||
52 | - /* As CP_ACCESS_TRAP, but for traps directly to EL2 or EL3 */ | ||
53 | - CP_ACCESS_TRAP_EL2 = 3, | ||
54 | - CP_ACCESS_TRAP_EL3 = 4, | ||
55 | - /* As CP_ACCESS_UNCATEGORIZED, but for traps directly to EL2 or EL3 */ | ||
56 | - CP_ACCESS_TRAP_UNCATEGORIZED_EL2 = 5, | ||
57 | - CP_ACCESS_TRAP_UNCATEGORIZED_EL3 = 6, | ||
58 | + CP_ACCESS_TRAP_UNCATEGORIZED = (2 << 2), | ||
59 | + CP_ACCESS_TRAP_UNCATEGORIZED_EL2 = CP_ACCESS_TRAP_UNCATEGORIZED | 2, | ||
60 | + CP_ACCESS_TRAP_UNCATEGORIZED_EL3 = CP_ACCESS_TRAP_UNCATEGORIZED | 3, | ||
61 | } CPAccessResult; | ||
62 | |||
63 | typedef struct ARMCPRegInfo ARMCPRegInfo; | ||
64 | diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c | ||
65 | index XXXXXXX..XXXXXXX 100644 | ||
66 | --- a/target/arm/op_helper.c | ||
67 | +++ b/target/arm/op_helper.c | ||
68 | @@ -XXX,XX +XXX,XX @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome, | ||
69 | uint32_t isread) | ||
74 | { | 70 | { |
75 | - ZynqSLCRState *s = ZYNQ_SLCR(d); | 71 | const ARMCPRegInfo *ri = rip; |
76 | + uint32_t mult = ((ctrl_reg & R_xxx_PLL_CTRL_PLL_FPDIV_MASK) >> | 72 | + CPAccessResult res = CP_ACCESS_OK; |
77 | + R_xxx_PLL_CTRL_PLL_FPDIV_SHIFT); | 73 | int target_el; |
78 | + | 74 | |
79 | + /* first, check if pll is bypassed */ | 75 | if (arm_feature(env, ARM_FEATURE_XSCALE) && ri->cp < 14 |
80 | + if (ctrl_reg & R_xxx_PLL_CTRL_PLL_BYPASS_FORCE_MASK) { | 76 | && extract32(env->cp15.c15_cpar, ri->cp, 1) == 0) { |
81 | + return input; | 77 | - raise_exception(env, EXCP_UDEF, syndrome, exception_target_el(env)); |
78 | + res = CP_ACCESS_TRAP; | ||
79 | + goto fail; | ||
80 | } | ||
81 | |||
82 | /* | ||
83 | @@ -XXX,XX +XXX,XX @@ void HELPER(access_check_cp_reg)(CPUARMState *env, void *rip, uint32_t syndrome, | ||
84 | mask &= ~((1 << 4) | (1 << 14)); | ||
85 | |||
86 | if (env->cp15.hstr_el2 & mask) { | ||
87 | - target_el = 2; | ||
88 | - goto exept; | ||
89 | + res = CP_ACCESS_TRAP_EL2; | ||
90 | + goto fail; | ||
91 | } | ||
92 | } | ||
93 | |||
94 | - if (!ri->accessfn) { | ||
95 | + if (ri->accessfn) { | ||
96 | + res = ri->accessfn(env, ri, isread); | ||
97 | + } | ||
98 | + if (likely(res == CP_ACCESS_OK)) { | ||
99 | return; | ||
100 | } | ||
101 | |||
102 | - switch (ri->accessfn(env, ri, isread)) { | ||
103 | - case CP_ACCESS_OK: | ||
104 | - return; | ||
105 | + fail: | ||
106 | + switch (res & ~CP_ACCESS_EL_MASK) { | ||
107 | case CP_ACCESS_TRAP: | ||
108 | - target_el = exception_target_el(env); | ||
109 | - break; | ||
110 | - case CP_ACCESS_TRAP_EL2: | ||
111 | - /* Requesting a trap to EL2 when we're in EL3 is | ||
112 | - * a bug in the access function. | ||
113 | - */ | ||
114 | - assert(arm_current_el(env) != 3); | ||
115 | - target_el = 2; | ||
116 | - break; | ||
117 | - case CP_ACCESS_TRAP_EL3: | ||
118 | - target_el = 3; | ||
119 | break; | ||
120 | case CP_ACCESS_TRAP_UNCATEGORIZED: | ||
121 | - target_el = exception_target_el(env); | ||
122 | - syndrome = syn_uncategorized(); | ||
123 | - break; | ||
124 | - case CP_ACCESS_TRAP_UNCATEGORIZED_EL2: | ||
125 | - target_el = 2; | ||
126 | - syndrome = syn_uncategorized(); | ||
127 | - break; | ||
128 | - case CP_ACCESS_TRAP_UNCATEGORIZED_EL3: | ||
129 | - target_el = 3; | ||
130 | syndrome = syn_uncategorized(); | ||
131 | break; | ||
132 | default: | ||
133 | g_assert_not_reached(); | ||
134 | } | ||
135 | |||
136 | -exept: | ||
137 | + target_el = res & CP_ACCESS_EL_MASK; | ||
138 | + switch (target_el) { | ||
139 | + case 0: | ||
140 | + target_el = exception_target_el(env); | ||
141 | + break; | ||
142 | + case 2: | ||
143 | + assert(arm_current_el(env) != 3); | ||
144 | + assert(arm_is_el2_enabled(env)); | ||
145 | + break; | ||
146 | + case 3: | ||
147 | + assert(arm_feature(env, ARM_FEATURE_EL3)); | ||
148 | + break; | ||
149 | + default: | ||
150 | + /* No "direct" traps to EL1 */ | ||
151 | + g_assert_not_reached(); | ||
82 | + } | 152 | + } |
83 | + | 153 | + |
84 | + /* is pll disabled ? */ | 154 | raise_exception(env, EXCP_UDEF, syndrome, target_el); |
85 | + if (ctrl_reg & (R_xxx_PLL_CTRL_PLL_RESET_MASK | | ||
86 | + R_xxx_PLL_CTRL_PLL_PWRDWN_MASK)) { | ||
87 | + return 0; | ||
88 | + } | ||
89 | + | ||
90 | + /* frequency multiplier -> period division */ | ||
91 | + return input / mult; | ||
92 | +} | ||
93 | + | ||
94 | +/* | ||
95 | + * return the output period of a clock given: | ||
96 | + * + the periods in an array corresponding to input mux selector | ||
97 | + * + the register xxx_CLK_CTRL value | ||
98 | + * + enable bit index in ctrl register | ||
99 | + * | ||
100 | + * This function makes the assumption that the ctrl_reg value is organized as | ||
101 | + * follows: | ||
102 | + * + bits[13:8] clock frequency divisor | ||
103 | + * + bits[5:4] clock mux selector (index in array) | ||
104 | + * + bits[index] clock enable | ||
105 | + */ | ||
106 | +static uint64_t zynq_slcr_compute_clock(const uint64_t periods[], | ||
107 | + uint32_t ctrl_reg, | ||
108 | + unsigned index) | ||
109 | +{ | ||
110 | + uint32_t srcsel = extract32(ctrl_reg, 4, 2); /* bits [5:4] */ | ||
111 | + uint32_t divisor = extract32(ctrl_reg, 8, 6); /* bits [13:8] */ | ||
112 | + | ||
113 | + /* first, check if clock is disabled */ | ||
114 | + if (((ctrl_reg >> index) & 1u) == 0) { | ||
115 | + return 0; | ||
116 | + } | ||
117 | + | ||
118 | + /* | ||
119 | + * according to the Zynq technical ref. manual UG585 v1.12.2 in | ||
120 | + * Clocks chapter, section 25.10.1 page 705: | ||
121 | + * "The 6-bit divider provides a divide range of 1 to 63" | ||
122 | + * We follow here what is implemented in linux kernel and consider | ||
123 | + * the 0 value as a bypass (no division). | ||
124 | + */ | ||
125 | + /* frequency divisor -> period multiplication */ | ||
126 | + return periods[srcsel] * (divisor ? divisor : 1u); | ||
127 | +} | ||
128 | + | ||
129 | +/* | ||
130 | + * macro helper around zynq_slcr_compute_clock to avoid repeating | ||
131 | + * the register name. | ||
132 | + */ | ||
133 | +#define ZYNQ_COMPUTE_CLK(state, plls, reg, enable_field) \ | ||
134 | + zynq_slcr_compute_clock((plls), (state)->regs[reg], \ | ||
135 | + reg ## _ ## enable_field ## _SHIFT) | ||
136 | + | ||
137 | +/** | ||
138 | + * Compute and set the ouputs clocks periods. | ||
139 | + * But do not propagate them further. Connected clocks | ||
140 | + * will not receive any updates (See zynq_slcr_compute_clocks()) | ||
141 | + */ | ||
142 | +static void zynq_slcr_compute_clocks(ZynqSLCRState *s) | ||
143 | +{ | ||
144 | + uint64_t ps_clk = clock_get(s->ps_clk); | ||
145 | + | ||
146 | + /* consider outputs clocks are disabled while in reset */ | ||
147 | + if (device_is_in_reset(DEVICE(s))) { | ||
148 | + ps_clk = 0; | ||
149 | + } | ||
150 | + | ||
151 | + uint64_t io_pll = zynq_slcr_compute_pll(ps_clk, s->regs[R_IO_PLL_CTRL]); | ||
152 | + uint64_t arm_pll = zynq_slcr_compute_pll(ps_clk, s->regs[R_ARM_PLL_CTRL]); | ||
153 | + uint64_t ddr_pll = zynq_slcr_compute_pll(ps_clk, s->regs[R_DDR_PLL_CTRL]); | ||
154 | + | ||
155 | + uint64_t uart_mux[4] = {io_pll, io_pll, arm_pll, ddr_pll}; | ||
156 | + | ||
157 | + /* compute uartX reference clocks */ | ||
158 | + clock_set(s->uart0_ref_clk, | ||
159 | + ZYNQ_COMPUTE_CLK(s, uart_mux, R_UART_CLK_CTRL, CLKACT0)); | ||
160 | + clock_set(s->uart1_ref_clk, | ||
161 | + ZYNQ_COMPUTE_CLK(s, uart_mux, R_UART_CLK_CTRL, CLKACT1)); | ||
162 | +} | ||
163 | + | ||
164 | +/** | ||
165 | + * Propagate the outputs clocks. | ||
166 | + * zynq_slcr_compute_clocks() should have been called before | ||
167 | + * to configure them. | ||
168 | + */ | ||
169 | +static void zynq_slcr_propagate_clocks(ZynqSLCRState *s) | ||
170 | +{ | ||
171 | + clock_propagate(s->uart0_ref_clk); | ||
172 | + clock_propagate(s->uart1_ref_clk); | ||
173 | +} | ||
174 | + | ||
175 | +static void zynq_slcr_ps_clk_callback(void *opaque) | ||
176 | +{ | ||
177 | + ZynqSLCRState *s = (ZynqSLCRState *) opaque; | ||
178 | + zynq_slcr_compute_clocks(s); | ||
179 | + zynq_slcr_propagate_clocks(s); | ||
180 | +} | ||
181 | + | ||
182 | +static void zynq_slcr_reset_init(Object *obj, ResetType type) | ||
183 | +{ | ||
184 | + ZynqSLCRState *s = ZYNQ_SLCR(obj); | ||
185 | int i; | ||
186 | |||
187 | DB_PRINT("RESET\n"); | ||
188 | @@ -XXX,XX +XXX,XX @@ static void zynq_slcr_reset(DeviceState *d) | ||
189 | s->regs[R_DDRIOB + 12] = 0x00000021; | ||
190 | } | 155 | } |
191 | 156 | ||
192 | +static void zynq_slcr_reset_hold(Object *obj) | ||
193 | +{ | ||
194 | + ZynqSLCRState *s = ZYNQ_SLCR(obj); | ||
195 | + | ||
196 | + /* will disable all output clocks */ | ||
197 | + zynq_slcr_compute_clocks(s); | ||
198 | + zynq_slcr_propagate_clocks(s); | ||
199 | +} | ||
200 | + | ||
201 | +static void zynq_slcr_reset_exit(Object *obj) | ||
202 | +{ | ||
203 | + ZynqSLCRState *s = ZYNQ_SLCR(obj); | ||
204 | + | ||
205 | + /* will compute output clocks according to ps_clk and registers */ | ||
206 | + zynq_slcr_compute_clocks(s); | ||
207 | + zynq_slcr_propagate_clocks(s); | ||
208 | +} | ||
209 | |||
210 | static bool zynq_slcr_check_offset(hwaddr offset, bool rnw) | ||
211 | { | ||
212 | @@ -XXX,XX +XXX,XX @@ static void zynq_slcr_write(void *opaque, hwaddr offset, | ||
213 | qemu_system_reset_request(SHUTDOWN_CAUSE_GUEST_RESET); | ||
214 | } | ||
215 | break; | ||
216 | + case R_IO_PLL_CTRL: | ||
217 | + case R_ARM_PLL_CTRL: | ||
218 | + case R_DDR_PLL_CTRL: | ||
219 | + case R_UART_CLK_CTRL: | ||
220 | + zynq_slcr_compute_clocks(s); | ||
221 | + zynq_slcr_propagate_clocks(s); | ||
222 | + break; | ||
223 | } | ||
224 | } | ||
225 | |||
226 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps slcr_ops = { | ||
227 | .endianness = DEVICE_NATIVE_ENDIAN, | ||
228 | }; | ||
229 | |||
230 | +static const ClockPortInitArray zynq_slcr_clocks = { | ||
231 | + QDEV_CLOCK_IN(ZynqSLCRState, ps_clk, zynq_slcr_ps_clk_callback), | ||
232 | + QDEV_CLOCK_OUT(ZynqSLCRState, uart0_ref_clk), | ||
233 | + QDEV_CLOCK_OUT(ZynqSLCRState, uart1_ref_clk), | ||
234 | + QDEV_CLOCK_END | ||
235 | +}; | ||
236 | + | ||
237 | static void zynq_slcr_init(Object *obj) | ||
238 | { | ||
239 | ZynqSLCRState *s = ZYNQ_SLCR(obj); | ||
240 | @@ -XXX,XX +XXX,XX @@ static void zynq_slcr_init(Object *obj) | ||
241 | memory_region_init_io(&s->iomem, obj, &slcr_ops, s, "slcr", | ||
242 | ZYNQ_SLCR_MMIO_SIZE); | ||
243 | sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->iomem); | ||
244 | + | ||
245 | + qdev_init_clocks(DEVICE(obj), zynq_slcr_clocks); | ||
246 | } | ||
247 | |||
248 | static const VMStateDescription vmstate_zynq_slcr = { | ||
249 | .name = "zynq_slcr", | ||
250 | - .version_id = 2, | ||
251 | + .version_id = 3, | ||
252 | .minimum_version_id = 2, | ||
253 | .fields = (VMStateField[]) { | ||
254 | VMSTATE_UINT32_ARRAY(regs, ZynqSLCRState, ZYNQ_SLCR_NUM_REGS), | ||
255 | + VMSTATE_CLOCK_V(ps_clk, ZynqSLCRState, 3), | ||
256 | VMSTATE_END_OF_LIST() | ||
257 | } | ||
258 | }; | ||
259 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_zynq_slcr = { | ||
260 | static void zynq_slcr_class_init(ObjectClass *klass, void *data) | ||
261 | { | ||
262 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
263 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | ||
264 | |||
265 | dc->vmsd = &vmstate_zynq_slcr; | ||
266 | - dc->reset = zynq_slcr_reset; | ||
267 | + rc->phases.enter = zynq_slcr_reset_init; | ||
268 | + rc->phases.hold = zynq_slcr_reset_hold; | ||
269 | + rc->phases.exit = zynq_slcr_reset_exit; | ||
270 | } | ||
271 | |||
272 | static const TypeInfo zynq_slcr_info = { | ||
273 | -- | 157 | -- |
274 | 2.20.1 | 158 | 2.25.1 |
275 | 159 | ||
276 | 160 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | 3 | Remove a possible source of error by removing REGINFO_SENTINEL |
4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 4 | and using ARRAY_SIZE (convinently hidden inside a macro) to |
5 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 5 | find the end of the set of regs being registered or modified. |
6 | Message-id: 20200423073358.27155-4-philmd@redhat.com | 6 | |
7 | The space saved by not having the extra array element reduces | ||
8 | the executable's .data.rel.ro section by about 9k. | ||
9 | |||
10 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Message-id: 20220501055028.646596-4-richard.henderson@linaro.org | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 15 | --- |
9 | target/arm/cpu.c | 8 +++----- | 16 | target/arm/cpregs.h | 53 +++++++++--------- |
10 | target/arm/cpu64.c | 8 +++----- | 17 | hw/arm/pxa2xx.c | 1 - |
11 | 2 files changed, 6 insertions(+), 10 deletions(-) | 18 | hw/arm/pxa2xx_pic.c | 1 - |
19 | hw/intc/arm_gicv3_cpuif.c | 5 -- | ||
20 | hw/intc/arm_gicv3_kvm.c | 1 - | ||
21 | target/arm/cpu64.c | 1 - | ||
22 | target/arm/cpu_tcg.c | 4 -- | ||
23 | target/arm/helper.c | 111 ++++++++------------------------------ | ||
24 | 8 files changed, 48 insertions(+), 129 deletions(-) | ||
12 | 25 | ||
13 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 26 | diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h |
14 | index XXXXXXX..XXXXXXX 100644 | 27 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/cpu.c | 28 | --- a/target/arm/cpregs.h |
16 | +++ b/target/arm/cpu.c | 29 | +++ b/target/arm/cpregs.h |
17 | @@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo arm_cpus[] = { | 30 | @@ -XXX,XX +XXX,XX @@ |
18 | { .name = "any", .initfn = arm_max_initfn }, | 31 | #define ARM_CP_NO_GDB 0x4000 |
19 | #endif | 32 | #define ARM_CP_RAISES_EXC 0x8000 |
20 | #endif | 33 | #define ARM_CP_NEWEL 0x10000 |
21 | - { .name = NULL } | 34 | -/* Used only as a terminator for ARMCPRegInfo lists */ |
22 | }; | 35 | -#define ARM_CP_SENTINEL 0xfffff |
23 | 36 | /* Mask of only the flag bits in a type field */ | |
24 | static Property arm_cpu_properties[] = { | 37 | #define ARM_CP_FLAG_MASK 0x1f0ff |
25 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo idau_interface_type_info = { | 38 | |
26 | 39 | @@ -XXX,XX +XXX,XX @@ enum { | |
27 | static void arm_cpu_register_types(void) | 40 | ARM_CP_SECSTATE_NS = (1 << 1), /* bit[1]: Non-secure state register */ |
41 | }; | ||
42 | |||
43 | -/* | ||
44 | - * Return true if cptype is a valid type field. This is used to try to | ||
45 | - * catch errors where the sentinel has been accidentally left off the end | ||
46 | - * of a list of registers. | ||
47 | - */ | ||
48 | -static inline bool cptype_valid(int cptype) | ||
49 | -{ | ||
50 | - return ((cptype & ~ARM_CP_FLAG_MASK) == 0) | ||
51 | - || ((cptype & ARM_CP_SPECIAL) && | ||
52 | - ((cptype & ~ARM_CP_FLAG_MASK) <= ARM_LAST_SPECIAL)); | ||
53 | -} | ||
54 | - | ||
55 | /* | ||
56 | * Access rights: | ||
57 | * We define bits for Read and Write access for what rev C of the v7-AR ARM ARM | ||
58 | @@ -XXX,XX +XXX,XX @@ struct ARMCPRegInfo { | ||
59 | #define CPREG_FIELD64(env, ri) \ | ||
60 | (*(uint64_t *)((char *)(env) + (ri)->fieldoffset)) | ||
61 | |||
62 | -#define REGINFO_SENTINEL { .type = ARM_CP_SENTINEL } | ||
63 | +void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, const ARMCPRegInfo *reg, | ||
64 | + void *opaque); | ||
65 | |||
66 | -void define_arm_cp_regs_with_opaque(ARMCPU *cpu, | ||
67 | - const ARMCPRegInfo *regs, void *opaque); | ||
68 | -void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, | ||
69 | - const ARMCPRegInfo *regs, void *opaque); | ||
70 | -static inline void define_arm_cp_regs(ARMCPU *cpu, const ARMCPRegInfo *regs) | ||
71 | -{ | ||
72 | - define_arm_cp_regs_with_opaque(cpu, regs, 0); | ||
73 | -} | ||
74 | static inline void define_one_arm_cp_reg(ARMCPU *cpu, const ARMCPRegInfo *regs) | ||
28 | { | 75 | { |
29 | - const ARMCPUInfo *info = arm_cpus; | 76 | - define_one_arm_cp_reg_with_opaque(cpu, regs, 0); |
30 | + size_t i; | 77 | + define_one_arm_cp_reg_with_opaque(cpu, regs, NULL); |
31 | 78 | } | |
32 | type_register_static(&arm_cpu_type_info); | 79 | + |
33 | type_register_static(&idau_interface_type_info); | 80 | +void define_arm_cp_regs_with_opaque_len(ARMCPU *cpu, const ARMCPRegInfo *regs, |
34 | 81 | + void *opaque, size_t len); | |
35 | - while (info->name) { | 82 | + |
36 | - arm_cpu_register(info); | 83 | +#define define_arm_cp_regs_with_opaque(CPU, REGS, OPAQUE) \ |
37 | - info++; | 84 | + do { \ |
38 | + for (i = 0; i < ARRAY_SIZE(arm_cpus); ++i) { | 85 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(REGS) == 0); \ |
39 | + arm_cpu_register(&arm_cpus[i]); | 86 | + define_arm_cp_regs_with_opaque_len(CPU, REGS, OPAQUE, \ |
40 | } | 87 | + ARRAY_SIZE(REGS)); \ |
41 | 88 | + } while (0) | |
42 | #ifdef CONFIG_KVM | 89 | + |
90 | +#define define_arm_cp_regs(CPU, REGS) \ | ||
91 | + define_arm_cp_regs_with_opaque(CPU, REGS, NULL) | ||
92 | + | ||
93 | const ARMCPRegInfo *get_arm_cp_reginfo(GHashTable *cpregs, uint32_t encoded_cp); | ||
94 | |||
95 | /* | ||
96 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMCPRegUserSpaceInfo { | ||
97 | uint64_t fixed_bits; | ||
98 | } ARMCPRegUserSpaceInfo; | ||
99 | |||
100 | -#define REGUSERINFO_SENTINEL { .name = NULL } | ||
101 | +void modify_arm_cp_regs_with_len(ARMCPRegInfo *regs, size_t regs_len, | ||
102 | + const ARMCPRegUserSpaceInfo *mods, | ||
103 | + size_t mods_len); | ||
104 | |||
105 | -void modify_arm_cp_regs(ARMCPRegInfo *regs, const ARMCPRegUserSpaceInfo *mods); | ||
106 | +#define modify_arm_cp_regs(REGS, MODS) \ | ||
107 | + do { \ | ||
108 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(REGS) == 0); \ | ||
109 | + QEMU_BUILD_BUG_ON(ARRAY_SIZE(MODS) == 0); \ | ||
110 | + modify_arm_cp_regs_with_len(REGS, ARRAY_SIZE(REGS), \ | ||
111 | + MODS, ARRAY_SIZE(MODS)); \ | ||
112 | + } while (0) | ||
113 | |||
114 | /* CPWriteFn that can be used to implement writes-ignored behaviour */ | ||
115 | void arm_cp_write_ignore(CPUARMState *env, const ARMCPRegInfo *ri, | ||
116 | diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c | ||
117 | index XXXXXXX..XXXXXXX 100644 | ||
118 | --- a/hw/arm/pxa2xx.c | ||
119 | +++ b/hw/arm/pxa2xx.c | ||
120 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo pxa_cp_reginfo[] = { | ||
121 | { .name = "PWRMODE", .cp = 14, .crn = 7, .crm = 0, .opc1 = 0, .opc2 = 0, | ||
122 | .access = PL1_RW, .type = ARM_CP_IO, | ||
123 | .readfn = arm_cp_read_zero, .writefn = pxa2xx_pwrmode_write }, | ||
124 | - REGINFO_SENTINEL | ||
125 | }; | ||
126 | |||
127 | static void pxa2xx_setup_cp14(PXA2xxState *s) | ||
128 | diff --git a/hw/arm/pxa2xx_pic.c b/hw/arm/pxa2xx_pic.c | ||
129 | index XXXXXXX..XXXXXXX 100644 | ||
130 | --- a/hw/arm/pxa2xx_pic.c | ||
131 | +++ b/hw/arm/pxa2xx_pic.c | ||
132 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo pxa_pic_cp_reginfo[] = { | ||
133 | REGINFO_FOR_PIC_CP("ICLR2", 8), | ||
134 | REGINFO_FOR_PIC_CP("ICFP2", 9), | ||
135 | REGINFO_FOR_PIC_CP("ICPR2", 0xa), | ||
136 | - REGINFO_SENTINEL | ||
137 | }; | ||
138 | |||
139 | static const MemoryRegionOps pxa2xx_pic_ops = { | ||
140 | diff --git a/hw/intc/arm_gicv3_cpuif.c b/hw/intc/arm_gicv3_cpuif.c | ||
141 | index XXXXXXX..XXXXXXX 100644 | ||
142 | --- a/hw/intc/arm_gicv3_cpuif.c | ||
143 | +++ b/hw/intc/arm_gicv3_cpuif.c | ||
144 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = { | ||
145 | .readfn = icc_igrpen1_el3_read, | ||
146 | .writefn = icc_igrpen1_el3_write, | ||
147 | }, | ||
148 | - REGINFO_SENTINEL | ||
149 | }; | ||
150 | |||
151 | static uint64_t ich_ap_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
152 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo gicv3_cpuif_hcr_reginfo[] = { | ||
153 | .readfn = ich_vmcr_read, | ||
154 | .writefn = ich_vmcr_write, | ||
155 | }, | ||
156 | - REGINFO_SENTINEL | ||
157 | }; | ||
158 | |||
159 | static const ARMCPRegInfo gicv3_cpuif_ich_apxr1_reginfo[] = { | ||
160 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo gicv3_cpuif_ich_apxr1_reginfo[] = { | ||
161 | .readfn = ich_ap_read, | ||
162 | .writefn = ich_ap_write, | ||
163 | }, | ||
164 | - REGINFO_SENTINEL | ||
165 | }; | ||
166 | |||
167 | static const ARMCPRegInfo gicv3_cpuif_ich_apxr23_reginfo[] = { | ||
168 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo gicv3_cpuif_ich_apxr23_reginfo[] = { | ||
169 | .readfn = ich_ap_read, | ||
170 | .writefn = ich_ap_write, | ||
171 | }, | ||
172 | - REGINFO_SENTINEL | ||
173 | }; | ||
174 | |||
175 | static void gicv3_cpuif_el_change_hook(ARMCPU *cpu, void *opaque) | ||
176 | @@ -XXX,XX +XXX,XX @@ void gicv3_init_cpuif(GICv3State *s) | ||
177 | .readfn = ich_lr_read, | ||
178 | .writefn = ich_lr_write, | ||
179 | }, | ||
180 | - REGINFO_SENTINEL | ||
181 | }; | ||
182 | define_arm_cp_regs(cpu, lr_regset); | ||
183 | } | ||
184 | diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c | ||
185 | index XXXXXXX..XXXXXXX 100644 | ||
186 | --- a/hw/intc/arm_gicv3_kvm.c | ||
187 | +++ b/hw/intc/arm_gicv3_kvm.c | ||
188 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo gicv3_cpuif_reginfo[] = { | ||
189 | */ | ||
190 | .resetfn = arm_gicv3_icc_reset, | ||
191 | }, | ||
192 | - REGINFO_SENTINEL | ||
193 | }; | ||
194 | |||
195 | /** | ||
43 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | 196 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c |
44 | index XXXXXXX..XXXXXXX 100644 | 197 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/target/arm/cpu64.c | 198 | --- a/target/arm/cpu64.c |
46 | +++ b/target/arm/cpu64.c | 199 | +++ b/target/arm/cpu64.c |
47 | @@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo aarch64_cpus[] = { | 200 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cortex_a72_a57_a53_cp_reginfo[] = { |
48 | { .name = "cortex-a53", .initfn = aarch64_a53_initfn }, | 201 | { .name = "L2MERRSR", |
49 | { .name = "cortex-a72", .initfn = aarch64_a72_initfn }, | 202 | .cp = 15, .opc1 = 3, .crm = 15, |
50 | { .name = "max", .initfn = aarch64_max_initfn }, | 203 | .access = PL1_RW, .type = ARM_CP_CONST | ARM_CP_64BIT, .resetvalue = 0 }, |
51 | - { .name = NULL } | 204 | - REGINFO_SENTINEL |
52 | }; | 205 | }; |
53 | 206 | ||
54 | static bool aarch64_cpu_get_aarch64(Object *obj, Error **errp) | 207 | static void aarch64_a57_initfn(Object *obj) |
55 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo aarch64_cpu_type_info = { | 208 | diff --git a/target/arm/cpu_tcg.c b/target/arm/cpu_tcg.c |
56 | 209 | index XXXXXXX..XXXXXXX 100644 | |
57 | static void aarch64_cpu_register_types(void) | 210 | --- a/target/arm/cpu_tcg.c |
58 | { | 211 | +++ b/target/arm/cpu_tcg.c |
59 | - const ARMCPUInfo *info = aarch64_cpus; | 212 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cortexa8_cp_reginfo[] = { |
60 | + size_t i; | 213 | .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
61 | 214 | { .name = "L2AUXCR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 2, | |
62 | type_register_static(&aarch64_cpu_type_info); | 215 | .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, |
63 | 216 | - REGINFO_SENTINEL | |
64 | - while (info->name) { | 217 | }; |
65 | - aarch64_cpu_register(info); | 218 | |
66 | - info++; | 219 | static void cortex_a8_initfn(Object *obj) |
67 | + for (i = 0; i < ARRAY_SIZE(aarch64_cpus); ++i) { | 220 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cortexa9_cp_reginfo[] = { |
68 | + aarch64_cpu_register(&aarch64_cpus[i]); | 221 | .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST }, |
222 | { .name = "TLB_ATTR", .cp = 15, .crn = 15, .crm = 7, .opc1 = 5, .opc2 = 2, | ||
223 | .access = PL1_RW, .resetvalue = 0, .type = ARM_CP_CONST }, | ||
224 | - REGINFO_SENTINEL | ||
225 | }; | ||
226 | |||
227 | static void cortex_a9_initfn(Object *obj) | ||
228 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cortexa15_cp_reginfo[] = { | ||
229 | #endif | ||
230 | { .name = "L2ECTLR", .cp = 15, .crn = 9, .crm = 0, .opc1 = 1, .opc2 = 3, | ||
231 | .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, | ||
232 | - REGINFO_SENTINEL | ||
233 | }; | ||
234 | |||
235 | static void cortex_a7_initfn(Object *obj) | ||
236 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cortexr5_cp_reginfo[] = { | ||
237 | .access = PL1_RW, .type = ARM_CP_CONST }, | ||
238 | { .name = "DCACHE_INVAL", .cp = 15, .opc1 = 0, .crn = 15, .crm = 5, | ||
239 | .opc2 = 0, .access = PL1_W, .type = ARM_CP_NOP }, | ||
240 | - REGINFO_SENTINEL | ||
241 | }; | ||
242 | |||
243 | static void cortex_r5_initfn(Object *obj) | ||
244 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
245 | index XXXXXXX..XXXXXXX 100644 | ||
246 | --- a/target/arm/helper.c | ||
247 | +++ b/target/arm/helper.c | ||
248 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cp_reginfo[] = { | ||
249 | .secure = ARM_CP_SECSTATE_S, | ||
250 | .fieldoffset = offsetof(CPUARMState, cp15.contextidr_s), | ||
251 | .resetvalue = 0, .writefn = contextidr_write, .raw_writefn = raw_write, }, | ||
252 | - REGINFO_SENTINEL | ||
253 | }; | ||
254 | |||
255 | static const ARMCPRegInfo not_v8_cp_reginfo[] = { | ||
256 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo not_v8_cp_reginfo[] = { | ||
257 | { .name = "CACHEMAINT", .cp = 15, .crn = 7, .crm = CP_ANY, | ||
258 | .opc1 = 0, .opc2 = CP_ANY, .access = PL1_W, | ||
259 | .type = ARM_CP_NOP | ARM_CP_OVERRIDE }, | ||
260 | - REGINFO_SENTINEL | ||
261 | }; | ||
262 | |||
263 | static const ARMCPRegInfo not_v6_cp_reginfo[] = { | ||
264 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo not_v6_cp_reginfo[] = { | ||
265 | */ | ||
266 | { .name = "WFI_v5", .cp = 15, .crn = 7, .crm = 8, .opc1 = 0, .opc2 = 2, | ||
267 | .access = PL1_W, .type = ARM_CP_WFI }, | ||
268 | - REGINFO_SENTINEL | ||
269 | }; | ||
270 | |||
271 | static const ARMCPRegInfo not_v7_cp_reginfo[] = { | ||
272 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo not_v7_cp_reginfo[] = { | ||
273 | .opc1 = 0, .opc2 = 0, .access = PL1_RW, .type = ARM_CP_NOP }, | ||
274 | { .name = "NMRR", .cp = 15, .crn = 10, .crm = 2, | ||
275 | .opc1 = 0, .opc2 = 1, .access = PL1_RW, .type = ARM_CP_NOP }, | ||
276 | - REGINFO_SENTINEL | ||
277 | }; | ||
278 | |||
279 | static void cpacr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
280 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6_cp_reginfo[] = { | ||
281 | .crn = 1, .crm = 0, .opc1 = 0, .opc2 = 2, .accessfn = cpacr_access, | ||
282 | .access = PL1_RW, .fieldoffset = offsetof(CPUARMState, cp15.cpacr_el1), | ||
283 | .resetfn = cpacr_reset, .writefn = cpacr_write, .readfn = cpacr_read }, | ||
284 | - REGINFO_SENTINEL | ||
285 | }; | ||
286 | |||
287 | typedef struct pm_event { | ||
288 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = { | ||
289 | { .name = "TLBIMVAA", .cp = 15, .opc1 = 0, .crn = 8, .crm = 7, .opc2 = 3, | ||
290 | .type = ARM_CP_NO_RAW, .access = PL1_W, .accessfn = access_ttlb, | ||
291 | .writefn = tlbimvaa_write }, | ||
292 | - REGINFO_SENTINEL | ||
293 | }; | ||
294 | |||
295 | static const ARMCPRegInfo v7mp_cp_reginfo[] = { | ||
296 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7mp_cp_reginfo[] = { | ||
297 | { .name = "TLBIMVAAIS", .cp = 15, .opc1 = 0, .crn = 8, .crm = 3, .opc2 = 3, | ||
298 | .type = ARM_CP_NO_RAW, .access = PL1_W, .accessfn = access_ttlb, | ||
299 | .writefn = tlbimvaa_is_write }, | ||
300 | - REGINFO_SENTINEL | ||
301 | }; | ||
302 | |||
303 | static const ARMCPRegInfo pmovsset_cp_reginfo[] = { | ||
304 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo pmovsset_cp_reginfo[] = { | ||
305 | .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr), | ||
306 | .writefn = pmovsset_write, | ||
307 | .raw_writefn = raw_write }, | ||
308 | - REGINFO_SENTINEL | ||
309 | }; | ||
310 | |||
311 | static void teecr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
312 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo t2ee_cp_reginfo[] = { | ||
313 | { .name = "TEEHBR", .cp = 14, .crn = 1, .crm = 0, .opc1 = 6, .opc2 = 0, | ||
314 | .access = PL0_RW, .fieldoffset = offsetof(CPUARMState, teehbr), | ||
315 | .accessfn = teehbr_access, .resetvalue = 0 }, | ||
316 | - REGINFO_SENTINEL | ||
317 | }; | ||
318 | |||
319 | static const ARMCPRegInfo v6k_cp_reginfo[] = { | ||
320 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6k_cp_reginfo[] = { | ||
321 | .bank_fieldoffsets = { offsetoflow32(CPUARMState, cp15.tpidrprw_s), | ||
322 | offsetoflow32(CPUARMState, cp15.tpidrprw_ns) }, | ||
323 | .resetvalue = 0 }, | ||
324 | - REGINFO_SENTINEL | ||
325 | }; | ||
326 | |||
327 | #ifndef CONFIG_USER_ONLY | ||
328 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = { | ||
329 | .fieldoffset = offsetof(CPUARMState, cp15.c14_timer[GTIMER_SEC].cval), | ||
330 | .writefn = gt_sec_cval_write, .raw_writefn = raw_write, | ||
331 | }, | ||
332 | - REGINFO_SENTINEL | ||
333 | }; | ||
334 | |||
335 | static CPAccessResult e2h_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
336 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo generic_timer_cp_reginfo[] = { | ||
337 | .access = PL0_R, .type = ARM_CP_NO_RAW | ARM_CP_IO, | ||
338 | .readfn = gt_virt_cnt_read, | ||
339 | }, | ||
340 | - REGINFO_SENTINEL | ||
341 | }; | ||
342 | |||
343 | #endif | ||
344 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo vapa_cp_reginfo[] = { | ||
345 | .access = PL1_W, .accessfn = ats_access, | ||
346 | .writefn = ats_write, .type = ARM_CP_NO_RAW | ARM_CP_RAISES_EXC }, | ||
347 | #endif | ||
348 | - REGINFO_SENTINEL | ||
349 | }; | ||
350 | |||
351 | /* Return basic MPU access permission bits. */ | ||
352 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo pmsav7_cp_reginfo[] = { | ||
353 | .fieldoffset = offsetof(CPUARMState, pmsav7.rnr[M_REG_NS]), | ||
354 | .writefn = pmsav7_rgnr_write, | ||
355 | .resetfn = arm_cp_reset_ignore }, | ||
356 | - REGINFO_SENTINEL | ||
357 | }; | ||
358 | |||
359 | static const ARMCPRegInfo pmsav5_cp_reginfo[] = { | ||
360 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo pmsav5_cp_reginfo[] = { | ||
361 | { .name = "946_PRBS7", .cp = 15, .crn = 6, .crm = 7, .opc1 = 0, | ||
362 | .opc2 = CP_ANY, .access = PL1_RW, .resetvalue = 0, | ||
363 | .fieldoffset = offsetof(CPUARMState, cp15.c6_region[7]) }, | ||
364 | - REGINFO_SENTINEL | ||
365 | }; | ||
366 | |||
367 | static void vmsa_ttbcr_raw_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
368 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo vmsa_pmsa_cp_reginfo[] = { | ||
369 | .access = PL1_RW, .accessfn = access_tvm_trvm, | ||
370 | .fieldoffset = offsetof(CPUARMState, cp15.far_el[1]), | ||
371 | .resetvalue = 0, }, | ||
372 | - REGINFO_SENTINEL | ||
373 | }; | ||
374 | |||
375 | static const ARMCPRegInfo vmsa_cp_reginfo[] = { | ||
376 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = { | ||
377 | /* No offsetoflow32 -- pass the entire TCR to writefn/raw_writefn. */ | ||
378 | .bank_fieldoffsets = { offsetof(CPUARMState, cp15.tcr_el[3]), | ||
379 | offsetof(CPUARMState, cp15.tcr_el[1])} }, | ||
380 | - REGINFO_SENTINEL | ||
381 | }; | ||
382 | |||
383 | /* Note that unlike TTBCR, writing to TTBCR2 does not require flushing | ||
384 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo omap_cp_reginfo[] = { | ||
385 | { .name = "C9", .cp = 15, .crn = 9, | ||
386 | .crm = CP_ANY, .opc1 = CP_ANY, .opc2 = CP_ANY, .access = PL1_RW, | ||
387 | .type = ARM_CP_CONST | ARM_CP_OVERRIDE, .resetvalue = 0 }, | ||
388 | - REGINFO_SENTINEL | ||
389 | }; | ||
390 | |||
391 | static void xscale_cpar_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
392 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo xscale_cp_reginfo[] = { | ||
393 | { .name = "XSCALE_UNLOCK_DCACHE", | ||
394 | .cp = 15, .opc1 = 0, .crn = 9, .crm = 2, .opc2 = 1, | ||
395 | .access = PL1_W, .type = ARM_CP_NOP }, | ||
396 | - REGINFO_SENTINEL | ||
397 | }; | ||
398 | |||
399 | static const ARMCPRegInfo dummy_c15_cp_reginfo[] = { | ||
400 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo dummy_c15_cp_reginfo[] = { | ||
401 | .access = PL1_RW, | ||
402 | .type = ARM_CP_CONST | ARM_CP_NO_RAW | ARM_CP_OVERRIDE, | ||
403 | .resetvalue = 0 }, | ||
404 | - REGINFO_SENTINEL | ||
405 | }; | ||
406 | |||
407 | static const ARMCPRegInfo cache_dirty_status_cp_reginfo[] = { | ||
408 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cache_dirty_status_cp_reginfo[] = { | ||
409 | { .name = "CDSR", .cp = 15, .crn = 7, .crm = 10, .opc1 = 0, .opc2 = 6, | ||
410 | .access = PL1_R, .type = ARM_CP_CONST | ARM_CP_NO_RAW, | ||
411 | .resetvalue = 0 }, | ||
412 | - REGINFO_SENTINEL | ||
413 | }; | ||
414 | |||
415 | static const ARMCPRegInfo cache_block_ops_cp_reginfo[] = { | ||
416 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cache_block_ops_cp_reginfo[] = { | ||
417 | .access = PL0_W, .type = ARM_CP_NOP|ARM_CP_64BIT }, | ||
418 | { .name = "CIDCR", .cp = 15, .crm = 14, .opc1 = 0, | ||
419 | .access = PL1_W, .type = ARM_CP_NOP|ARM_CP_64BIT }, | ||
420 | - REGINFO_SENTINEL | ||
421 | }; | ||
422 | |||
423 | static const ARMCPRegInfo cache_test_clean_cp_reginfo[] = { | ||
424 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo cache_test_clean_cp_reginfo[] = { | ||
425 | { .name = "TCI_DCACHE", .cp = 15, .crn = 7, .crm = 14, .opc1 = 0, .opc2 = 3, | ||
426 | .access = PL0_R, .type = ARM_CP_CONST | ARM_CP_NO_RAW, | ||
427 | .resetvalue = (1 << 30) }, | ||
428 | - REGINFO_SENTINEL | ||
429 | }; | ||
430 | |||
431 | static const ARMCPRegInfo strongarm_cp_reginfo[] = { | ||
432 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo strongarm_cp_reginfo[] = { | ||
433 | .crm = CP_ANY, .opc1 = CP_ANY, .opc2 = CP_ANY, | ||
434 | .access = PL1_RW, .resetvalue = 0, | ||
435 | .type = ARM_CP_CONST | ARM_CP_OVERRIDE | ARM_CP_NO_RAW }, | ||
436 | - REGINFO_SENTINEL | ||
437 | }; | ||
438 | |||
439 | static uint64_t midr_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
440 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo lpae_cp_reginfo[] = { | ||
441 | .bank_fieldoffsets = { offsetof(CPUARMState, cp15.ttbr1_s), | ||
442 | offsetof(CPUARMState, cp15.ttbr1_ns) }, | ||
443 | .writefn = vmsa_ttbr_write, }, | ||
444 | - REGINFO_SENTINEL | ||
445 | }; | ||
446 | |||
447 | static uint64_t aa64_fpcr_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
448 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v8_cp_reginfo[] = { | ||
449 | .access = PL1_RW, .accessfn = access_trap_aa32s_el1, | ||
450 | .writefn = sdcr_write, | ||
451 | .fieldoffset = offsetoflow32(CPUARMState, cp15.mdcr_el3) }, | ||
452 | - REGINFO_SENTINEL | ||
453 | }; | ||
454 | |||
455 | /* Used to describe the behaviour of EL2 regs when EL2 does not exist. */ | ||
456 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el3_no_el2_cp_reginfo[] = { | ||
457 | .type = ARM_CP_CONST, | ||
458 | .cp = 15, .opc1 = 4, .crn = 6, .crm = 0, .opc2 = 2, | ||
459 | .access = PL2_RW, .resetvalue = 0 }, | ||
460 | - REGINFO_SENTINEL | ||
461 | }; | ||
462 | |||
463 | /* Ditto, but for registers which exist in ARMv8 but not v7 */ | ||
464 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el3_no_el2_v8_cp_reginfo[] = { | ||
465 | .cp = 15, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 4, | ||
466 | .access = PL2_RW, | ||
467 | .type = ARM_CP_CONST, .resetvalue = 0 }, | ||
468 | - REGINFO_SENTINEL | ||
469 | }; | ||
470 | |||
471 | static void do_hcr_write(CPUARMState *env, uint64_t value, uint64_t valid_mask) | ||
472 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = { | ||
473 | .cp = 15, .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 1, .opc2 = 3, | ||
474 | .access = PL2_RW, | ||
475 | .fieldoffset = offsetof(CPUARMState, cp15.hstr_el2) }, | ||
476 | - REGINFO_SENTINEL | ||
477 | }; | ||
478 | |||
479 | static const ARMCPRegInfo el2_v8_cp_reginfo[] = { | ||
480 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_v8_cp_reginfo[] = { | ||
481 | .access = PL2_RW, | ||
482 | .fieldoffset = offsetofhigh32(CPUARMState, cp15.hcr_el2), | ||
483 | .writefn = hcr_writehigh }, | ||
484 | - REGINFO_SENTINEL | ||
485 | }; | ||
486 | |||
487 | static CPAccessResult sel2_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
488 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_sec_cp_reginfo[] = { | ||
489 | .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 6, .opc2 = 2, | ||
490 | .access = PL2_RW, .accessfn = sel2_access, | ||
491 | .fieldoffset = offsetof(CPUARMState, cp15.vstcr_el2) }, | ||
492 | - REGINFO_SENTINEL | ||
493 | }; | ||
494 | |||
495 | static CPAccessResult nsacr_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
496 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el3_cp_reginfo[] = { | ||
497 | .opc0 = 1, .opc1 = 6, .crn = 8, .crm = 7, .opc2 = 5, | ||
498 | .access = PL3_W, .type = ARM_CP_NO_RAW, | ||
499 | .writefn = tlbi_aa64_vae3_write }, | ||
500 | - REGINFO_SENTINEL | ||
501 | }; | ||
502 | |||
503 | #ifndef CONFIG_USER_ONLY | ||
504 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo debug_cp_reginfo[] = { | ||
505 | .cp = 14, .opc0 = 2, .opc1 = 0, .crn = 0, .crm = 2, .opc2 = 0, | ||
506 | .access = PL1_RW, .accessfn = access_tda, | ||
507 | .type = ARM_CP_NOP }, | ||
508 | - REGINFO_SENTINEL | ||
509 | }; | ||
510 | |||
511 | static const ARMCPRegInfo debug_lpae_cp_reginfo[] = { | ||
512 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo debug_lpae_cp_reginfo[] = { | ||
513 | .access = PL0_R, .type = ARM_CP_CONST|ARM_CP_64BIT, .resetvalue = 0 }, | ||
514 | { .name = "DBGDSAR", .cp = 14, .crm = 2, .opc1 = 0, | ||
515 | .access = PL0_R, .type = ARM_CP_CONST|ARM_CP_64BIT, .resetvalue = 0 }, | ||
516 | - REGINFO_SENTINEL | ||
517 | }; | ||
518 | |||
519 | /* Return the exception level to which exceptions should be taken | ||
520 | @@ -XXX,XX +XXX,XX @@ static void define_debug_regs(ARMCPU *cpu) | ||
521 | .fieldoffset = offsetof(CPUARMState, cp15.dbgbcr[i]), | ||
522 | .writefn = dbgbcr_write, .raw_writefn = raw_write | ||
523 | }, | ||
524 | - REGINFO_SENTINEL | ||
525 | }; | ||
526 | define_arm_cp_regs(cpu, dbgregs); | ||
527 | } | ||
528 | @@ -XXX,XX +XXX,XX @@ static void define_debug_regs(ARMCPU *cpu) | ||
529 | .fieldoffset = offsetof(CPUARMState, cp15.dbgwcr[i]), | ||
530 | .writefn = dbgwcr_write, .raw_writefn = raw_write | ||
531 | }, | ||
532 | - REGINFO_SENTINEL | ||
533 | }; | ||
534 | define_arm_cp_regs(cpu, dbgregs); | ||
535 | } | ||
536 | @@ -XXX,XX +XXX,XX @@ static void define_pmu_regs(ARMCPU *cpu) | ||
537 | .type = ARM_CP_IO, | ||
538 | .readfn = pmevtyper_readfn, .writefn = pmevtyper_writefn, | ||
539 | .raw_writefn = pmevtyper_rawwrite }, | ||
540 | - REGINFO_SENTINEL | ||
541 | }; | ||
542 | define_arm_cp_regs(cpu, pmev_regs); | ||
543 | g_free(pmevcntr_name); | ||
544 | @@ -XXX,XX +XXX,XX @@ static void define_pmu_regs(ARMCPU *cpu) | ||
545 | .cp = 15, .opc1 = 0, .crn = 9, .crm = 14, .opc2 = 5, | ||
546 | .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST, | ||
547 | .resetvalue = extract64(cpu->pmceid1, 32, 32) }, | ||
548 | - REGINFO_SENTINEL | ||
549 | }; | ||
550 | define_arm_cp_regs(cpu, v81_pmu_regs); | ||
551 | } | ||
552 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo lor_reginfo[] = { | ||
553 | .opc0 = 3, .opc1 = 0, .crn = 10, .crm = 4, .opc2 = 7, | ||
554 | .access = PL1_R, .accessfn = access_lor_ns, | ||
555 | .type = ARM_CP_CONST, .resetvalue = 0 }, | ||
556 | - REGINFO_SENTINEL | ||
557 | }; | ||
558 | |||
559 | #ifdef TARGET_AARCH64 | ||
560 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo pauth_reginfo[] = { | ||
561 | .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 3, | ||
562 | .access = PL1_RW, .accessfn = access_pauth, | ||
563 | .fieldoffset = offsetof(CPUARMState, keys.apib.hi) }, | ||
564 | - REGINFO_SENTINEL | ||
565 | }; | ||
566 | |||
567 | static const ARMCPRegInfo tlbirange_reginfo[] = { | ||
568 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo tlbirange_reginfo[] = { | ||
569 | .opc0 = 1, .opc1 = 6, .crn = 8, .crm = 6, .opc2 = 5, | ||
570 | .access = PL3_W, .type = ARM_CP_NO_RAW, | ||
571 | .writefn = tlbi_aa64_rvae3_write }, | ||
572 | - REGINFO_SENTINEL | ||
573 | }; | ||
574 | |||
575 | static const ARMCPRegInfo tlbios_reginfo[] = { | ||
576 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo tlbios_reginfo[] = { | ||
577 | .opc0 = 1, .opc1 = 6, .crn = 8, .crm = 1, .opc2 = 5, | ||
578 | .access = PL3_W, .type = ARM_CP_NO_RAW, | ||
579 | .writefn = tlbi_aa64_vae3is_write }, | ||
580 | - REGINFO_SENTINEL | ||
581 | }; | ||
582 | |||
583 | static uint64_t rndr_readfn(CPUARMState *env, const ARMCPRegInfo *ri) | ||
584 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo rndr_reginfo[] = { | ||
585 | .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END | ARM_CP_IO, | ||
586 | .opc0 = 3, .opc1 = 3, .crn = 2, .crm = 4, .opc2 = 1, | ||
587 | .access = PL0_R, .readfn = rndr_readfn }, | ||
588 | - REGINFO_SENTINEL | ||
589 | }; | ||
590 | |||
591 | #ifndef CONFIG_USER_ONLY | ||
592 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo dcpop_reg[] = { | ||
593 | .opc0 = 1, .opc1 = 3, .crn = 7, .crm = 12, .opc2 = 1, | ||
594 | .access = PL0_W, .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END, | ||
595 | .accessfn = aa64_cacheop_poc_access, .writefn = dccvap_writefn }, | ||
596 | - REGINFO_SENTINEL | ||
597 | }; | ||
598 | |||
599 | static const ARMCPRegInfo dcpodp_reg[] = { | ||
600 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo dcpodp_reg[] = { | ||
601 | .opc0 = 1, .opc1 = 3, .crn = 7, .crm = 13, .opc2 = 1, | ||
602 | .access = PL0_W, .type = ARM_CP_NO_RAW | ARM_CP_SUPPRESS_TB_END, | ||
603 | .accessfn = aa64_cacheop_poc_access, .writefn = dccvap_writefn }, | ||
604 | - REGINFO_SENTINEL | ||
605 | }; | ||
606 | #endif /*CONFIG_USER_ONLY*/ | ||
607 | |||
608 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo mte_reginfo[] = { | ||
609 | { .name = "DC_CIGDSW", .state = ARM_CP_STATE_AA64, | ||
610 | .opc0 = 1, .opc1 = 0, .crn = 7, .crm = 14, .opc2 = 6, | ||
611 | .type = ARM_CP_NOP, .access = PL1_W, .accessfn = access_tsw }, | ||
612 | - REGINFO_SENTINEL | ||
613 | }; | ||
614 | |||
615 | static const ARMCPRegInfo mte_tco_ro_reginfo[] = { | ||
616 | { .name = "TCO", .state = ARM_CP_STATE_AA64, | ||
617 | .opc0 = 3, .opc1 = 3, .crn = 4, .crm = 2, .opc2 = 7, | ||
618 | .type = ARM_CP_CONST, .access = PL0_RW, }, | ||
619 | - REGINFO_SENTINEL | ||
620 | }; | ||
621 | |||
622 | static const ARMCPRegInfo mte_el0_cacheop_reginfo[] = { | ||
623 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo mte_el0_cacheop_reginfo[] = { | ||
624 | .accessfn = aa64_zva_access, | ||
625 | #endif | ||
626 | }, | ||
627 | - REGINFO_SENTINEL | ||
628 | }; | ||
629 | |||
630 | #endif | ||
631 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo predinv_reginfo[] = { | ||
632 | { .name = "CPPRCTX", .state = ARM_CP_STATE_AA32, | ||
633 | .cp = 15, .opc1 = 0, .crn = 7, .crm = 3, .opc2 = 7, | ||
634 | .type = ARM_CP_NOP, .access = PL0_W, .accessfn = access_predinv }, | ||
635 | - REGINFO_SENTINEL | ||
636 | }; | ||
637 | |||
638 | static uint64_t ccsidr2_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
639 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo ccsidr2_reginfo[] = { | ||
640 | .access = PL1_R, | ||
641 | .accessfn = access_aa64_tid2, | ||
642 | .readfn = ccsidr2_read, .type = ARM_CP_NO_RAW }, | ||
643 | - REGINFO_SENTINEL | ||
644 | }; | ||
645 | |||
646 | static CPAccessResult access_aa64_tid3(CPUARMState *env, const ARMCPRegInfo *ri, | ||
647 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo jazelle_regs[] = { | ||
648 | .cp = 14, .crn = 2, .crm = 0, .opc1 = 7, .opc2 = 0, | ||
649 | .accessfn = access_joscr_jmcr, | ||
650 | .access = PL1_RW, .type = ARM_CP_CONST, .resetvalue = 0 }, | ||
651 | - REGINFO_SENTINEL | ||
652 | }; | ||
653 | |||
654 | static const ARMCPRegInfo vhe_reginfo[] = { | ||
655 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo vhe_reginfo[] = { | ||
656 | .access = PL2_RW, .accessfn = e2h_access, | ||
657 | .writefn = gt_virt_cval_write, .raw_writefn = raw_write }, | ||
658 | #endif | ||
659 | - REGINFO_SENTINEL | ||
660 | }; | ||
661 | |||
662 | #ifndef CONFIG_USER_ONLY | ||
663 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo ats1e1_reginfo[] = { | ||
664 | .opc0 = 1, .opc1 = 0, .crn = 7, .crm = 9, .opc2 = 1, | ||
665 | .access = PL1_W, .type = ARM_CP_NO_RAW | ARM_CP_RAISES_EXC, | ||
666 | .writefn = ats_write64 }, | ||
667 | - REGINFO_SENTINEL | ||
668 | }; | ||
669 | |||
670 | static const ARMCPRegInfo ats1cp_reginfo[] = { | ||
671 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo ats1cp_reginfo[] = { | ||
672 | .cp = 15, .opc1 = 0, .crn = 7, .crm = 9, .opc2 = 1, | ||
673 | .access = PL1_W, .type = ARM_CP_NO_RAW | ARM_CP_RAISES_EXC, | ||
674 | .writefn = ats_write }, | ||
675 | - REGINFO_SENTINEL | ||
676 | }; | ||
677 | #endif | ||
678 | |||
679 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo actlr2_hactlr2_reginfo[] = { | ||
680 | .cp = 15, .opc1 = 4, .crn = 1, .crm = 0, .opc2 = 3, | ||
681 | .access = PL2_RW, .type = ARM_CP_CONST, | ||
682 | .resetvalue = 0 }, | ||
683 | - REGINFO_SENTINEL | ||
684 | }; | ||
685 | |||
686 | void register_cp_regs_for_features(ARMCPU *cpu) | ||
687 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
688 | .access = PL1_R, .type = ARM_CP_CONST, | ||
689 | .accessfn = access_aa32_tid3, | ||
690 | .resetvalue = cpu->isar.id_isar6 }, | ||
691 | - REGINFO_SENTINEL | ||
692 | }; | ||
693 | define_arm_cp_regs(cpu, v6_idregs); | ||
694 | define_arm_cp_regs(cpu, v6_cp_reginfo); | ||
695 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
696 | .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 7, | ||
697 | .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST, | ||
698 | .resetvalue = cpu->pmceid1 }, | ||
699 | - REGINFO_SENTINEL | ||
700 | }; | ||
701 | #ifdef CONFIG_USER_ONLY | ||
702 | ARMCPRegUserSpaceInfo v8_user_idregs[] = { | ||
703 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
704 | .exported_bits = 0x000000f0ffffffff }, | ||
705 | { .name = "ID_AA64ISAR*_EL1_RESERVED", | ||
706 | .is_glob = true }, | ||
707 | - REGUSERINFO_SENTINEL | ||
708 | }; | ||
709 | modify_arm_cp_regs(v8_idregs, v8_user_idregs); | ||
710 | #endif | ||
711 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
712 | .access = PL2_RW, | ||
713 | .resetvalue = vmpidr_def, | ||
714 | .fieldoffset = offsetof(CPUARMState, cp15.vmpidr_el2) }, | ||
715 | - REGINFO_SENTINEL | ||
716 | }; | ||
717 | define_arm_cp_regs(cpu, vpidr_regs); | ||
718 | define_arm_cp_regs(cpu, el2_cp_reginfo); | ||
719 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
720 | .access = PL2_RW, .accessfn = access_el3_aa32ns, | ||
721 | .type = ARM_CP_NO_RAW, | ||
722 | .writefn = arm_cp_write_ignore, .readfn = mpidr_read }, | ||
723 | - REGINFO_SENTINEL | ||
724 | }; | ||
725 | define_arm_cp_regs(cpu, vpidr_regs); | ||
726 | define_arm_cp_regs(cpu, el3_no_el2_cp_reginfo); | ||
727 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
728 | .raw_writefn = raw_write, .writefn = sctlr_write, | ||
729 | .fieldoffset = offsetof(CPUARMState, cp15.sctlr_el[3]), | ||
730 | .resetvalue = cpu->reset_sctlr }, | ||
731 | - REGINFO_SENTINEL | ||
732 | }; | ||
733 | |||
734 | define_arm_cp_regs(cpu, el3_regs); | ||
735 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
736 | { .name = "DUMMY", | ||
737 | .cp = 15, .crn = 0, .crm = 7, .opc1 = 0, .opc2 = CP_ANY, | ||
738 | .access = PL1_R, .type = ARM_CP_CONST, .resetvalue = 0 }, | ||
739 | - REGINFO_SENTINEL | ||
740 | }; | ||
741 | ARMCPRegInfo id_v8_midr_cp_reginfo[] = { | ||
742 | { .name = "MIDR_EL1", .state = ARM_CP_STATE_BOTH, | ||
743 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
744 | .access = PL1_R, | ||
745 | .accessfn = access_aa64_tid1, | ||
746 | .type = ARM_CP_CONST, .resetvalue = cpu->revidr }, | ||
747 | - REGINFO_SENTINEL | ||
748 | }; | ||
749 | ARMCPRegInfo id_cp_reginfo[] = { | ||
750 | /* These are common to v8 and pre-v8 */ | ||
751 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
752 | .access = PL1_R, | ||
753 | .accessfn = access_aa32_tid1, | ||
754 | .type = ARM_CP_CONST, .resetvalue = 0 }, | ||
755 | - REGINFO_SENTINEL | ||
756 | }; | ||
757 | /* TLBTR is specific to VMSA */ | ||
758 | ARMCPRegInfo id_tlbtr_reginfo = { | ||
759 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
760 | { .name = "MIDR_EL1", | ||
761 | .exported_bits = 0x00000000ffffffff }, | ||
762 | { .name = "REVIDR_EL1" }, | ||
763 | - REGUSERINFO_SENTINEL | ||
764 | }; | ||
765 | modify_arm_cp_regs(id_v8_midr_cp_reginfo, id_v8_user_midr_cp_reginfo); | ||
766 | #endif | ||
767 | if (arm_feature(env, ARM_FEATURE_OMAPCP) || | ||
768 | arm_feature(env, ARM_FEATURE_STRONGARM)) { | ||
769 | - ARMCPRegInfo *r; | ||
770 | + size_t i; | ||
771 | /* Register the blanket "writes ignored" value first to cover the | ||
772 | * whole space. Then update the specific ID registers to allow write | ||
773 | * access, so that they ignore writes rather than causing them to | ||
774 | * UNDEF. | ||
775 | */ | ||
776 | define_one_arm_cp_reg(cpu, &crn0_wi_reginfo); | ||
777 | - for (r = id_pre_v8_midr_cp_reginfo; | ||
778 | - r->type != ARM_CP_SENTINEL; r++) { | ||
779 | - r->access = PL1_RW; | ||
780 | + for (i = 0; i < ARRAY_SIZE(id_pre_v8_midr_cp_reginfo); ++i) { | ||
781 | + id_pre_v8_midr_cp_reginfo[i].access = PL1_RW; | ||
782 | } | ||
783 | - for (r = id_cp_reginfo; r->type != ARM_CP_SENTINEL; r++) { | ||
784 | - r->access = PL1_RW; | ||
785 | + for (i = 0; i < ARRAY_SIZE(id_cp_reginfo); ++i) { | ||
786 | + id_cp_reginfo[i].access = PL1_RW; | ||
787 | } | ||
788 | id_mpuir_reginfo.access = PL1_RW; | ||
789 | id_tlbtr_reginfo.access = PL1_RW; | ||
790 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
791 | { .name = "MPIDR_EL1", .state = ARM_CP_STATE_BOTH, | ||
792 | .opc0 = 3, .crn = 0, .crm = 0, .opc1 = 0, .opc2 = 5, | ||
793 | .access = PL1_R, .readfn = mpidr_read, .type = ARM_CP_NO_RAW }, | ||
794 | - REGINFO_SENTINEL | ||
795 | }; | ||
796 | #ifdef CONFIG_USER_ONLY | ||
797 | ARMCPRegUserSpaceInfo mpidr_user_cp_reginfo[] = { | ||
798 | { .name = "MPIDR_EL1", | ||
799 | .fixed_bits = 0x0000000080000000 }, | ||
800 | - REGUSERINFO_SENTINEL | ||
801 | }; | ||
802 | modify_arm_cp_regs(mpidr_cp_reginfo, mpidr_user_cp_reginfo); | ||
803 | #endif | ||
804 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
805 | .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 0, .opc2 = 1, | ||
806 | .access = PL3_RW, .type = ARM_CP_CONST, | ||
807 | .resetvalue = 0 }, | ||
808 | - REGINFO_SENTINEL | ||
809 | }; | ||
810 | define_arm_cp_regs(cpu, auxcr_reginfo); | ||
811 | if (cpu_isar_feature(aa32_ac2, cpu)) { | ||
812 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
813 | .type = ARM_CP_CONST, | ||
814 | .opc0 = 3, .opc1 = 1, .crn = 15, .crm = 3, .opc2 = 0, | ||
815 | .access = PL1_R, .resetvalue = cpu->reset_cbar }, | ||
816 | - REGINFO_SENTINEL | ||
817 | }; | ||
818 | /* We don't implement a r/w 64 bit CBAR currently */ | ||
819 | assert(arm_feature(env, ARM_FEATURE_CBAR_RO)); | ||
820 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
821 | .bank_fieldoffsets = { offsetof(CPUARMState, cp15.vbar_s), | ||
822 | offsetof(CPUARMState, cp15.vbar_ns) }, | ||
823 | .resetvalue = 0 }, | ||
824 | - REGINFO_SENTINEL | ||
825 | }; | ||
826 | define_arm_cp_regs(cpu, vbar_cp_reginfo); | ||
827 | } | ||
828 | @@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, | ||
829 | r->writefn); | ||
830 | } | ||
831 | } | ||
832 | - /* Bad type field probably means missing sentinel at end of reg list */ | ||
833 | - assert(cptype_valid(r->type)); | ||
834 | + | ||
835 | for (crm = crmmin; crm <= crmmax; crm++) { | ||
836 | for (opc1 = opc1min; opc1 <= opc1max; opc1++) { | ||
837 | for (opc2 = opc2min; opc2 <= opc2max; opc2++) { | ||
838 | @@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, | ||
69 | } | 839 | } |
70 | } | 840 | } |
71 | 841 | ||
842 | -void define_arm_cp_regs_with_opaque(ARMCPU *cpu, | ||
843 | - const ARMCPRegInfo *regs, void *opaque) | ||
844 | +/* Define a whole list of registers */ | ||
845 | +void define_arm_cp_regs_with_opaque_len(ARMCPU *cpu, const ARMCPRegInfo *regs, | ||
846 | + void *opaque, size_t len) | ||
847 | { | ||
848 | - /* Define a whole list of registers */ | ||
849 | - const ARMCPRegInfo *r; | ||
850 | - for (r = regs; r->type != ARM_CP_SENTINEL; r++) { | ||
851 | - define_one_arm_cp_reg_with_opaque(cpu, r, opaque); | ||
852 | + size_t i; | ||
853 | + for (i = 0; i < len; ++i) { | ||
854 | + define_one_arm_cp_reg_with_opaque(cpu, regs + i, opaque); | ||
855 | } | ||
856 | } | ||
857 | |||
858 | @@ -XXX,XX +XXX,XX @@ void define_arm_cp_regs_with_opaque(ARMCPU *cpu, | ||
859 | * user-space cannot alter any values and dynamic values pertaining to | ||
860 | * execution state are hidden from user space view anyway. | ||
861 | */ | ||
862 | -void modify_arm_cp_regs(ARMCPRegInfo *regs, const ARMCPRegUserSpaceInfo *mods) | ||
863 | +void modify_arm_cp_regs_with_len(ARMCPRegInfo *regs, size_t regs_len, | ||
864 | + const ARMCPRegUserSpaceInfo *mods, | ||
865 | + size_t mods_len) | ||
866 | { | ||
867 | - const ARMCPRegUserSpaceInfo *m; | ||
868 | - ARMCPRegInfo *r; | ||
869 | - | ||
870 | - for (m = mods; m->name; m++) { | ||
871 | + for (size_t mi = 0; mi < mods_len; ++mi) { | ||
872 | + const ARMCPRegUserSpaceInfo *m = mods + mi; | ||
873 | GPatternSpec *pat = NULL; | ||
874 | + | ||
875 | if (m->is_glob) { | ||
876 | pat = g_pattern_spec_new(m->name); | ||
877 | } | ||
878 | - for (r = regs; r->type != ARM_CP_SENTINEL; r++) { | ||
879 | + for (size_t ri = 0; ri < regs_len; ++ri) { | ||
880 | + ARMCPRegInfo *r = regs + ri; | ||
881 | + | ||
882 | if (pat && g_pattern_match_string(pat, r->name)) { | ||
883 | r->type = ARM_CP_CONST; | ||
884 | r->access = PL0U_R; | ||
72 | -- | 885 | -- |
73 | 2.20.1 | 886 | 2.25.1 |
74 | 887 | ||
75 | 888 | diff view generated by jsdifflib |
1 | From: Jerome Forissier <jerome@forissier.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Generate random seeds to be used by the non-secure and/or secure OSes | 3 | These particular data structures are not modified at runtime. |
4 | for ASLR. The seeds are 64-bit random values exported via the DT | ||
5 | properties /chosen/kaslr-seed [1] and /secure-chosen/kaslr-seed, the | ||
6 | latter being used by OP-TEE [2]. | ||
7 | 4 | ||
8 | [1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=e5bc0c37c97e1 | 5 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
9 | [2] https://github.com/OP-TEE/optee_os/commit/ef262691fe0e | ||
10 | |||
11 | Signed-off-by: Jerome Forissier <jerome@forissier.org> | ||
12 | Message-id: 20200420121807.8204-3-jerome@forissier.org | ||
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20220501055028.646596-5-richard.henderson@linaro.org | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | --- | 10 | --- |
16 | hw/arm/virt.c | 15 +++++++++++++++ | 11 | target/arm/helper.c | 16 ++++++++-------- |
17 | 1 file changed, 15 insertions(+) | 12 | 1 file changed, 8 insertions(+), 8 deletions(-) |
18 | 13 | ||
19 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | 14 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
20 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/arm/virt.c | 16 | --- a/target/arm/helper.c |
22 | +++ b/hw/arm/virt.c | 17 | +++ b/target/arm/helper.c |
23 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) |
24 | #include "hw/acpi/generic_event_device.h" | 19 | .resetvalue = cpu->pmceid1 }, |
25 | #include "hw/virtio/virtio-iommu.h" | 20 | }; |
26 | #include "hw/char/pl011.h" | 21 | #ifdef CONFIG_USER_ONLY |
27 | +#include "qemu/guest-random.h" | 22 | - ARMCPRegUserSpaceInfo v8_user_idregs[] = { |
28 | 23 | + static const ARMCPRegUserSpaceInfo v8_user_idregs[] = { | |
29 | #define DEFINE_VIRT_MACHINE_LATEST(major, minor, latest) \ | 24 | { .name = "ID_AA64PFR0_EL1", |
30 | static void virt_##major##_##minor##_class_init(ObjectClass *oc, \ | 25 | .exported_bits = 0x000f000f00ff0000, |
31 | @@ -XXX,XX +XXX,XX @@ static bool cpu_type_valid(const char *cpu) | 26 | .fixed_bits = 0x0000000000000011 }, |
32 | return false; | 27 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) |
33 | } | 28 | */ |
34 | 29 | if (arm_feature(env, ARM_FEATURE_EL3)) { | |
35 | +static void create_kaslr_seed(VirtMachineState *vms, const char *node) | 30 | if (arm_feature(env, ARM_FEATURE_AARCH64)) { |
36 | +{ | 31 | - ARMCPRegInfo nsacr = { |
37 | + Error *err = NULL; | 32 | + static const ARMCPRegInfo nsacr = { |
38 | + uint64_t seed; | 33 | .name = "NSACR", .type = ARM_CP_CONST, |
39 | + | 34 | .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 2, |
40 | + if (qemu_guest_getrandom(&seed, sizeof(seed), &err)) { | 35 | .access = PL1_RW, .accessfn = nsacr_access, |
41 | + error_free(err); | 36 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) |
42 | + return; | 37 | }; |
43 | + } | 38 | define_one_arm_cp_reg(cpu, &nsacr); |
44 | + qemu_fdt_setprop_u64(vms->fdt, node, "kaslr-seed", seed); | 39 | } else { |
45 | +} | 40 | - ARMCPRegInfo nsacr = { |
46 | + | 41 | + static const ARMCPRegInfo nsacr = { |
47 | static void create_fdt(VirtMachineState *vms) | 42 | .name = "NSACR", |
48 | { | 43 | .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 2, |
49 | MachineState *ms = MACHINE(vms); | 44 | .access = PL3_RW | PL1_R, |
50 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(VirtMachineState *vms) | 45 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) |
51 | 46 | } | |
52 | /* /chosen must exist for load_dtb to fill in necessary properties later */ | 47 | } else { |
53 | qemu_fdt_add_subnode(fdt, "/chosen"); | 48 | if (arm_feature(env, ARM_FEATURE_V8)) { |
54 | + create_kaslr_seed(vms, "/chosen"); | 49 | - ARMCPRegInfo nsacr = { |
55 | 50 | + static const ARMCPRegInfo nsacr = { | |
56 | if (vms->secure) { | 51 | .name = "NSACR", .type = ARM_CP_CONST, |
57 | qemu_fdt_add_subnode(fdt, "/secure-chosen"); | 52 | .cp = 15, .opc1 = 0, .crn = 1, .crm = 1, .opc2 = 2, |
58 | + create_kaslr_seed(vms, "/secure-chosen"); | 53 | .access = PL1_R, |
54 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
55 | .access = PL1_R, .type = ARM_CP_CONST, | ||
56 | .resetvalue = cpu->pmsav7_dregion << 8 | ||
57 | }; | ||
58 | - ARMCPRegInfo crn0_wi_reginfo = { | ||
59 | + static const ARMCPRegInfo crn0_wi_reginfo = { | ||
60 | .name = "CRN0_WI", .cp = 15, .crn = 0, .crm = CP_ANY, | ||
61 | .opc1 = CP_ANY, .opc2 = CP_ANY, .access = PL1_W, | ||
62 | .type = ARM_CP_NOP | ARM_CP_OVERRIDE | ||
63 | }; | ||
64 | #ifdef CONFIG_USER_ONLY | ||
65 | - ARMCPRegUserSpaceInfo id_v8_user_midr_cp_reginfo[] = { | ||
66 | + static const ARMCPRegUserSpaceInfo id_v8_user_midr_cp_reginfo[] = { | ||
67 | { .name = "MIDR_EL1", | ||
68 | .exported_bits = 0x00000000ffffffff }, | ||
69 | { .name = "REVIDR_EL1" }, | ||
70 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
71 | .access = PL1_R, .readfn = mpidr_read, .type = ARM_CP_NO_RAW }, | ||
72 | }; | ||
73 | #ifdef CONFIG_USER_ONLY | ||
74 | - ARMCPRegUserSpaceInfo mpidr_user_cp_reginfo[] = { | ||
75 | + static const ARMCPRegUserSpaceInfo mpidr_user_cp_reginfo[] = { | ||
76 | { .name = "MPIDR_EL1", | ||
77 | .fixed_bits = 0x0000000080000000 }, | ||
78 | }; | ||
79 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
59 | } | 80 | } |
60 | 81 | ||
61 | /* Clock node, for the benefit of the UART. The kernel device tree | 82 | if (arm_feature(env, ARM_FEATURE_VBAR)) { |
83 | - ARMCPRegInfo vbar_cp_reginfo[] = { | ||
84 | + static const ARMCPRegInfo vbar_cp_reginfo[] = { | ||
85 | { .name = "VBAR", .state = ARM_CP_STATE_BOTH, | ||
86 | .opc0 = 3, .crn = 12, .crm = 0, .opc1 = 0, .opc2 = 0, | ||
87 | .access = PL1_RW, .writefn = vbar_write, | ||
62 | -- | 88 | -- |
63 | 2.20.1 | 89 | 2.25.1 |
64 | 90 | ||
65 | 91 | diff view generated by jsdifflib |
1 | From: Subbaraya Sundeep <sundeep.lkml@gmail.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | With SmartFusion2 Ethernet MAC model in | 3 | Instead of defining ARM_CP_FLAG_MASK to remove flags, |
4 | place this patch adds the same to SoC. | 4 | define ARM_CP_SPECIAL_MASK to isolate special cases. |
5 | 5 | Sort the specials to the low bits. Use an enum. | |
6 | Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com> | 6 | |
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Split the large comment block so as to document each |
8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | value separately. |
9 | Message-id: 1587048891-30493-3-git-send-email-sundeep.lkml@gmail.com | 9 | |
10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Message-id: 20220501055028.646596-6-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 14 | --- |
12 | include/hw/arm/msf2-soc.h | 2 ++ | 15 | target/arm/cpregs.h | 130 +++++++++++++++++++++++-------------- |
13 | hw/arm/msf2-soc.c | 26 ++++++++++++++++++++++++-- | 16 | target/arm/cpu.c | 4 +- |
14 | 2 files changed, 26 insertions(+), 2 deletions(-) | 17 | target/arm/helper.c | 4 +- |
15 | 18 | target/arm/translate-a64.c | 6 +- | |
16 | diff --git a/include/hw/arm/msf2-soc.h b/include/hw/arm/msf2-soc.h | 19 | target/arm/translate.c | 6 +- |
17 | index XXXXXXX..XXXXXXX 100644 | 20 | 5 files changed, 92 insertions(+), 58 deletions(-) |
18 | --- a/include/hw/arm/msf2-soc.h | 21 | |
19 | +++ b/include/hw/arm/msf2-soc.h | 22 | diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h |
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/target/arm/cpregs.h | ||
25 | +++ b/target/arm/cpregs.h | ||
20 | @@ -XXX,XX +XXX,XX @@ | 26 | @@ -XXX,XX +XXX,XX @@ |
21 | #include "hw/timer/mss-timer.h" | 27 | #define TARGET_ARM_CPREGS_H |
22 | #include "hw/misc/msf2-sysreg.h" | 28 | |
23 | #include "hw/ssi/mss-spi.h" | ||
24 | +#include "hw/net/msf2-emac.h" | ||
25 | |||
26 | #define TYPE_MSF2_SOC "msf2-soc" | ||
27 | #define MSF2_SOC(obj) OBJECT_CHECK(MSF2State, (obj), TYPE_MSF2_SOC) | ||
28 | @@ -XXX,XX +XXX,XX @@ typedef struct MSF2State { | ||
29 | MSF2SysregState sysreg; | ||
30 | MSSTimerState timer; | ||
31 | MSSSpiState spi[MSF2_NUM_SPIS]; | ||
32 | + MSF2EmacState emac; | ||
33 | } MSF2State; | ||
34 | |||
35 | #endif | ||
36 | diff --git a/hw/arm/msf2-soc.c b/hw/arm/msf2-soc.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/hw/arm/msf2-soc.c | ||
39 | +++ b/hw/arm/msf2-soc.c | ||
40 | @@ -XXX,XX +XXX,XX @@ | ||
41 | /* | 29 | /* |
42 | * SmartFusion2 SoC emulation. | 30 | - * ARMCPRegInfo type field bits. If the SPECIAL bit is set this is a |
43 | * | 31 | - * special-behaviour cp reg and bits [11..8] indicate what behaviour |
44 | - * Copyright (c) 2017 Subbaraya Sundeep <sundeep.lkml@gmail.com> | 32 | - * it has. Otherwise it is a simple cp reg, where CONST indicates that |
45 | + * Copyright (c) 2017-2020 Subbaraya Sundeep <sundeep.lkml@gmail.com> | 33 | - * TCG can assume the value to be constant (ie load at translate time) |
46 | * | 34 | - * and 64BIT indicates a 64 bit wide coprocessor register. SUPPRESS_TB_END |
47 | * Permission is hereby granted, free of charge, to any person obtaining a copy | 35 | - * indicates that the TB should not be ended after a write to this register |
48 | * of this software and associated documentation files (the "Software"), to deal | 36 | - * (the default is that the TB ends after cp writes). OVERRIDE permits |
49 | @@ -XXX,XX +XXX,XX @@ | 37 | - * a register definition to override a previous definition for the |
50 | 38 | - * same (cp, is64, crn, crm, opc1, opc2) tuple: either the new or the | |
51 | #define MSF2_TIMER_BASE 0x40004000 | 39 | - * old must have the OVERRIDE bit set. |
52 | #define MSF2_SYSREG_BASE 0x40038000 | 40 | - * ALIAS indicates that this register is an alias view of some underlying |
53 | +#define MSF2_EMAC_BASE 0x40041000 | 41 | - * state which is also visible via another register, and that the other |
54 | 42 | - * register is handling migration and reset; registers marked ALIAS will not be | |
55 | #define ENVM_BASE_ADDRESS 0x60000000 | 43 | - * migrated but may have their state set by syncing of register state from KVM. |
56 | 44 | - * NO_RAW indicates that this register has no underlying state and does not | |
57 | #define SRAM_BASE_ADDRESS 0x20000000 | 45 | - * support raw access for state saving/loading; it will not be used for either |
58 | 46 | - * migration or KVM state synchronization. (Typically this is for "registers" | |
59 | +#define MSF2_EMAC_IRQ 12 | 47 | - * which are actually used as instructions for cache maintenance and so on.) |
48 | - * IO indicates that this register does I/O and therefore its accesses | ||
49 | - * need to be marked with gen_io_start() and also end the TB. In particular, | ||
50 | - * registers which implement clocks or timers require this. | ||
51 | - * RAISES_EXC is for when the read or write hook might raise an exception; | ||
52 | - * the generated code will synchronize the CPU state before calling the hook | ||
53 | - * so that it is safe for the hook to call raise_exception(). | ||
54 | - * NEWEL is for writes to registers that might change the exception | ||
55 | - * level - typically on older ARM chips. For those cases we need to | ||
56 | - * re-read the new el when recomputing the translation flags. | ||
57 | + * ARMCPRegInfo type field bits: | ||
58 | */ | ||
59 | -#define ARM_CP_SPECIAL 0x0001 | ||
60 | -#define ARM_CP_CONST 0x0002 | ||
61 | -#define ARM_CP_64BIT 0x0004 | ||
62 | -#define ARM_CP_SUPPRESS_TB_END 0x0008 | ||
63 | -#define ARM_CP_OVERRIDE 0x0010 | ||
64 | -#define ARM_CP_ALIAS 0x0020 | ||
65 | -#define ARM_CP_IO 0x0040 | ||
66 | -#define ARM_CP_NO_RAW 0x0080 | ||
67 | -#define ARM_CP_NOP (ARM_CP_SPECIAL | 0x0100) | ||
68 | -#define ARM_CP_WFI (ARM_CP_SPECIAL | 0x0200) | ||
69 | -#define ARM_CP_NZCV (ARM_CP_SPECIAL | 0x0300) | ||
70 | -#define ARM_CP_CURRENTEL (ARM_CP_SPECIAL | 0x0400) | ||
71 | -#define ARM_CP_DC_ZVA (ARM_CP_SPECIAL | 0x0500) | ||
72 | -#define ARM_CP_DC_GVA (ARM_CP_SPECIAL | 0x0600) | ||
73 | -#define ARM_CP_DC_GZVA (ARM_CP_SPECIAL | 0x0700) | ||
74 | -#define ARM_LAST_SPECIAL ARM_CP_DC_GZVA | ||
75 | -#define ARM_CP_FPU 0x1000 | ||
76 | -#define ARM_CP_SVE 0x2000 | ||
77 | -#define ARM_CP_NO_GDB 0x4000 | ||
78 | -#define ARM_CP_RAISES_EXC 0x8000 | ||
79 | -#define ARM_CP_NEWEL 0x10000 | ||
80 | -/* Mask of only the flag bits in a type field */ | ||
81 | -#define ARM_CP_FLAG_MASK 0x1f0ff | ||
82 | +enum { | ||
83 | + /* | ||
84 | + * Register must be handled specially during translation. | ||
85 | + * The method is one of the values below: | ||
86 | + */ | ||
87 | + ARM_CP_SPECIAL_MASK = 0x000f, | ||
88 | + /* Special: no change to PE state: writes ignored, reads ignored. */ | ||
89 | + ARM_CP_NOP = 0x0001, | ||
90 | + /* Special: sysreg is WFI, for v5 and v6. */ | ||
91 | + ARM_CP_WFI = 0x0002, | ||
92 | + /* Special: sysreg is NZCV. */ | ||
93 | + ARM_CP_NZCV = 0x0003, | ||
94 | + /* Special: sysreg is CURRENTEL. */ | ||
95 | + ARM_CP_CURRENTEL = 0x0004, | ||
96 | + /* Special: sysreg is DC ZVA or similar. */ | ||
97 | + ARM_CP_DC_ZVA = 0x0005, | ||
98 | + ARM_CP_DC_GVA = 0x0006, | ||
99 | + ARM_CP_DC_GZVA = 0x0007, | ||
60 | + | 100 | + |
61 | #define MSF2_ENVM_MAX_SIZE (512 * KiB) | 101 | + /* Flag: reads produce resetvalue; writes ignored. */ |
102 | + ARM_CP_CONST = 1 << 4, | ||
103 | + /* Flag: For ARM_CP_STATE_AA32, sysreg is 64-bit. */ | ||
104 | + ARM_CP_64BIT = 1 << 5, | ||
105 | + /* | ||
106 | + * Flag: TB should not be ended after a write to this register | ||
107 | + * (the default is that the TB ends after cp writes). | ||
108 | + */ | ||
109 | + ARM_CP_SUPPRESS_TB_END = 1 << 6, | ||
110 | + /* | ||
111 | + * Flag: Permit a register definition to override a previous definition | ||
112 | + * for the same (cp, is64, crn, crm, opc1, opc2) tuple: either the new | ||
113 | + * or the old must have the ARM_CP_OVERRIDE bit set. | ||
114 | + */ | ||
115 | + ARM_CP_OVERRIDE = 1 << 7, | ||
116 | + /* | ||
117 | + * Flag: Register is an alias view of some underlying state which is also | ||
118 | + * visible via another register, and that the other register is handling | ||
119 | + * migration and reset; registers marked ARM_CP_ALIAS will not be migrated | ||
120 | + * but may have their state set by syncing of register state from KVM. | ||
121 | + */ | ||
122 | + ARM_CP_ALIAS = 1 << 8, | ||
123 | + /* | ||
124 | + * Flag: Register does I/O and therefore its accesses need to be marked | ||
125 | + * with gen_io_start() and also end the TB. In particular, registers which | ||
126 | + * implement clocks or timers require this. | ||
127 | + */ | ||
128 | + ARM_CP_IO = 1 << 9, | ||
129 | + /* | ||
130 | + * Flag: Register has no underlying state and does not support raw access | ||
131 | + * for state saving/loading; it will not be used for either migration or | ||
132 | + * KVM state synchronization. Typically this is for "registers" which are | ||
133 | + * actually used as instructions for cache maintenance and so on. | ||
134 | + */ | ||
135 | + ARM_CP_NO_RAW = 1 << 10, | ||
136 | + /* | ||
137 | + * Flag: The read or write hook might raise an exception; the generated | ||
138 | + * code will synchronize the CPU state before calling the hook so that it | ||
139 | + * is safe for the hook to call raise_exception(). | ||
140 | + */ | ||
141 | + ARM_CP_RAISES_EXC = 1 << 11, | ||
142 | + /* | ||
143 | + * Flag: Writes to the sysreg might change the exception level - typically | ||
144 | + * on older ARM chips. For those cases we need to re-read the new el when | ||
145 | + * recomputing the translation flags. | ||
146 | + */ | ||
147 | + ARM_CP_NEWEL = 1 << 12, | ||
148 | + /* | ||
149 | + * Flag: Access check for this sysreg is identical to accessing FPU state | ||
150 | + * from an instruction: use translation fp_access_check(). | ||
151 | + */ | ||
152 | + ARM_CP_FPU = 1 << 13, | ||
153 | + /* | ||
154 | + * Flag: Access check for this sysreg is identical to accessing SVE state | ||
155 | + * from an instruction: use translation sve_access_check(). | ||
156 | + */ | ||
157 | + ARM_CP_SVE = 1 << 14, | ||
158 | + /* Flag: Do not expose in gdb sysreg xml. */ | ||
159 | + ARM_CP_NO_GDB = 1 << 15, | ||
160 | +}; | ||
62 | 161 | ||
63 | /* | 162 | /* |
64 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_initfn(Object *obj) | 163 | * Valid values for ARMCPRegInfo state field, indicating which of |
65 | sysbus_init_child_obj(obj, "spi[*]", &s->spi[i], sizeof(s->spi[i]), | 164 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
66 | TYPE_MSS_SPI); | 165 | index XXXXXXX..XXXXXXX 100644 |
67 | } | 166 | --- a/target/arm/cpu.c |
68 | + | 167 | +++ b/target/arm/cpu.c |
69 | + sysbus_init_child_obj(obj, "emac", &s->emac, sizeof(s->emac), | 168 | @@ -XXX,XX +XXX,XX @@ static void cp_reg_reset(gpointer key, gpointer value, gpointer opaque) |
70 | + TYPE_MSS_EMAC); | 169 | ARMCPRegInfo *ri = value; |
71 | + if (nd_table[0].used) { | 170 | ARMCPU *cpu = opaque; |
72 | + qemu_check_nic_model(&nd_table[0], TYPE_MSS_EMAC); | 171 | |
73 | + qdev_set_nic_properties(DEVICE(&s->emac), &nd_table[0]); | 172 | - if (ri->type & (ARM_CP_SPECIAL | ARM_CP_ALIAS)) { |
74 | + } | 173 | + if (ri->type & (ARM_CP_SPECIAL_MASK | ARM_CP_ALIAS)) { |
75 | } | 174 | return; |
76 | 175 | } | |
77 | static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | 176 | |
78 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | 177 | @@ -XXX,XX +XXX,XX @@ static void cp_reg_check_reset(gpointer key, gpointer value, gpointer opaque) |
79 | g_free(bus_name); | 178 | ARMCPU *cpu = opaque; |
80 | } | 179 | uint64_t oldvalue, newvalue; |
81 | 180 | ||
82 | + dev = DEVICE(&s->emac); | 181 | - if (ri->type & (ARM_CP_SPECIAL | ARM_CP_ALIAS | ARM_CP_NO_RAW)) { |
83 | + object_property_set_link(OBJECT(&s->emac), OBJECT(get_system_memory()), | 182 | + if (ri->type & (ARM_CP_SPECIAL_MASK | ARM_CP_ALIAS | ARM_CP_NO_RAW)) { |
84 | + "ahb-bus", &error_abort); | 183 | return; |
85 | + object_property_set_bool(OBJECT(&s->emac), true, "realized", &err); | 184 | } |
86 | + if (err != NULL) { | 185 | |
87 | + error_propagate(errp, err); | 186 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
88 | + return; | 187 | index XXXXXXX..XXXXXXX 100644 |
89 | + } | 188 | --- a/target/arm/helper.c |
90 | + busdev = SYS_BUS_DEVICE(dev); | 189 | +++ b/target/arm/helper.c |
91 | + sysbus_mmio_map(busdev, 0, MSF2_EMAC_BASE); | 190 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
92 | + sysbus_connect_irq(busdev, 0, | 191 | * multiple times. Special registers (ie NOP/WFI) are |
93 | + qdev_get_gpio_in(armv7m, MSF2_EMAC_IRQ)); | 192 | * never migratable and not even raw-accessible. |
94 | + | 193 | */ |
95 | /* Below devices are not modelled yet. */ | 194 | - if ((r->type & ARM_CP_SPECIAL)) { |
96 | create_unimplemented_device("i2c_0", 0x40002000, 0x1000); | 195 | + if (r->type & ARM_CP_SPECIAL_MASK) { |
97 | create_unimplemented_device("dma", 0x40003000, 0x1000); | 196 | r2->type |= ARM_CP_NO_RAW; |
98 | @@ -XXX,XX +XXX,XX @@ static void m2sxxx_soc_realize(DeviceState *dev_soc, Error **errp) | 197 | } |
99 | create_unimplemented_device("can", 0x40015000, 0x1000); | 198 | if (((r->crm == CP_ANY) && crm != 0) || |
100 | create_unimplemented_device("rtc", 0x40017000, 0x1000); | 199 | @@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, |
101 | create_unimplemented_device("apb_config", 0x40020000, 0x10000); | 200 | /* Check that the register definition has enough info to handle |
102 | - create_unimplemented_device("emac", 0x40041000, 0x1000); | 201 | * reads and writes if they are permitted. |
103 | create_unimplemented_device("usb", 0x40043000, 0x1000); | 202 | */ |
104 | } | 203 | - if (!(r->type & (ARM_CP_SPECIAL|ARM_CP_CONST))) { |
105 | 204 | + if (!(r->type & (ARM_CP_SPECIAL_MASK | ARM_CP_CONST))) { | |
205 | if (r->access & PL3_R) { | ||
206 | assert((r->fieldoffset || | ||
207 | (r->bank_fieldoffsets[0] && r->bank_fieldoffsets[1])) || | ||
208 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
209 | index XXXXXXX..XXXXXXX 100644 | ||
210 | --- a/target/arm/translate-a64.c | ||
211 | +++ b/target/arm/translate-a64.c | ||
212 | @@ -XXX,XX +XXX,XX @@ static void handle_sys(DisasContext *s, uint32_t insn, bool isread, | ||
213 | } | ||
214 | |||
215 | /* Handle special cases first */ | ||
216 | - switch (ri->type & ~(ARM_CP_FLAG_MASK & ~ARM_CP_SPECIAL)) { | ||
217 | + switch (ri->type & ARM_CP_SPECIAL_MASK) { | ||
218 | + case 0: | ||
219 | + break; | ||
220 | case ARM_CP_NOP: | ||
221 | return; | ||
222 | case ARM_CP_NZCV: | ||
223 | @@ -XXX,XX +XXX,XX @@ static void handle_sys(DisasContext *s, uint32_t insn, bool isread, | ||
224 | } | ||
225 | return; | ||
226 | default: | ||
227 | - break; | ||
228 | + g_assert_not_reached(); | ||
229 | } | ||
230 | if ((ri->type & ARM_CP_FPU) && !fp_access_check(s)) { | ||
231 | return; | ||
232 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
233 | index XXXXXXX..XXXXXXX 100644 | ||
234 | --- a/target/arm/translate.c | ||
235 | +++ b/target/arm/translate.c | ||
236 | @@ -XXX,XX +XXX,XX @@ static void do_coproc_insn(DisasContext *s, int cpnum, int is64, | ||
237 | } | ||
238 | |||
239 | /* Handle special cases first */ | ||
240 | - switch (ri->type & ~(ARM_CP_FLAG_MASK & ~ARM_CP_SPECIAL)) { | ||
241 | + switch (ri->type & ARM_CP_SPECIAL_MASK) { | ||
242 | + case 0: | ||
243 | + break; | ||
244 | case ARM_CP_NOP: | ||
245 | return; | ||
246 | case ARM_CP_WFI: | ||
247 | @@ -XXX,XX +XXX,XX @@ static void do_coproc_insn(DisasContext *s, int cpnum, int is64, | ||
248 | s->base.is_jmp = DISAS_WFI; | ||
249 | return; | ||
250 | default: | ||
251 | - break; | ||
252 | + g_assert_not_reached(); | ||
253 | } | ||
254 | |||
255 | if ((tb_cflags(s->base.tb) & CF_USE_ICOUNT) && (ri->type & ARM_CP_IO)) { | ||
106 | -- | 256 | -- |
107 | 2.20.1 | 257 | 2.25.1 |
108 | |||
109 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | These instructions are often used in glibc's string routines. | 3 | Standardize on g_assert_not_reached() for "should not happen". |
4 | They were the final uses of the 32-bit at a time neon helpers. | 4 | Retain abort() when preceeded by fprintf or error_report. |
5 | 5 | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20200418162808.4680-1-richard.henderson@linaro.org | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Message-id: 20220501055028.646596-7-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 10 | --- |
11 | target/arm/helper.h | 27 ++-- | 11 | target/arm/helper.c | 7 +++---- |
12 | target/arm/translate.h | 5 + | 12 | target/arm/hvf/hvf.c | 2 +- |
13 | target/arm/neon_helper.c | 24 ---- | 13 | target/arm/kvm-stub.c | 4 ++-- |
14 | target/arm/translate-a64.c | 64 +++------- | 14 | target/arm/kvm.c | 4 ++-- |
15 | target/arm/translate.c | 256 +++++++++++++++++++++++++++++++------ | 15 | target/arm/machine.c | 4 ++-- |
16 | target/arm/vec_helper.c | 25 ++++ | 16 | target/arm/translate-a64.c | 4 ++-- |
17 | 6 files changed, 278 insertions(+), 123 deletions(-) | 17 | target/arm/translate-neon.c | 2 +- |
18 | target/arm/translate.c | 4 ++-- | ||
19 | 8 files changed, 15 insertions(+), 16 deletions(-) | ||
18 | 20 | ||
19 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 21 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
20 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/helper.h | 23 | --- a/target/arm/helper.c |
22 | +++ b/target/arm/helper.h | 24 | +++ b/target/arm/helper.c |
23 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(neon_hsub_u16, i32, i32, i32) | 25 | @@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, |
24 | DEF_HELPER_2(neon_hsub_s32, s32, s32, s32) | 26 | break; |
25 | DEF_HELPER_2(neon_hsub_u32, i32, i32, i32) | 27 | default: |
26 | 28 | /* broken reginfo with out-of-range opc1 */ | |
27 | -DEF_HELPER_2(neon_cgt_u8, i32, i32, i32) | 29 | - assert(false); |
28 | -DEF_HELPER_2(neon_cgt_s8, i32, i32, i32) | 30 | - break; |
29 | -DEF_HELPER_2(neon_cgt_u16, i32, i32, i32) | 31 | + g_assert_not_reached(); |
30 | -DEF_HELPER_2(neon_cgt_s16, i32, i32, i32) | 32 | } |
31 | -DEF_HELPER_2(neon_cgt_u32, i32, i32, i32) | 33 | /* assert our permissions are not too lax (stricter is fine) */ |
32 | -DEF_HELPER_2(neon_cgt_s32, i32, i32, i32) | 34 | assert((r->access & ~mask) == 0); |
33 | -DEF_HELPER_2(neon_cge_u8, i32, i32, i32) | 35 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_v5(CPUARMState *env, uint32_t address, |
34 | -DEF_HELPER_2(neon_cge_s8, i32, i32, i32) | 36 | break; |
35 | -DEF_HELPER_2(neon_cge_u16, i32, i32, i32) | 37 | default: |
36 | -DEF_HELPER_2(neon_cge_s16, i32, i32, i32) | 38 | /* Never happens, but compiler isn't smart enough to tell. */ |
37 | -DEF_HELPER_2(neon_cge_u32, i32, i32, i32) | 39 | - abort(); |
38 | -DEF_HELPER_2(neon_cge_s32, i32, i32, i32) | 40 | + g_assert_not_reached(); |
39 | - | 41 | } |
40 | DEF_HELPER_2(neon_pmin_u8, i32, i32, i32) | 42 | } |
41 | DEF_HELPER_2(neon_pmin_s8, i32, i32, i32) | 43 | *prot = ap_to_rw_prot(env, mmu_idx, ap, domain_prot); |
42 | DEF_HELPER_2(neon_pmin_u16, i32, i32, i32) | 44 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_v6(CPUARMState *env, uint32_t address, |
43 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(neon_mul_u16, i32, i32, i32) | 45 | break; |
44 | DEF_HELPER_2(neon_tst_u8, i32, i32, i32) | 46 | default: |
45 | DEF_HELPER_2(neon_tst_u16, i32, i32, i32) | 47 | /* Never happens, but compiler isn't smart enough to tell. */ |
46 | DEF_HELPER_2(neon_tst_u32, i32, i32, i32) | 48 | - abort(); |
47 | -DEF_HELPER_2(neon_ceq_u8, i32, i32, i32) | 49 | + g_assert_not_reached(); |
48 | -DEF_HELPER_2(neon_ceq_u16, i32, i32, i32) | 50 | } |
49 | -DEF_HELPER_2(neon_ceq_u32, i32, i32, i32) | 51 | } |
50 | 52 | if (domain_prot == 3) { | |
51 | DEF_HELPER_1(neon_clz_u8, i32, i32) | 53 | diff --git a/target/arm/hvf/hvf.c b/target/arm/hvf/hvf.c |
52 | DEF_HELPER_1(neon_clz_u16, i32, i32) | ||
53 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(frint64_s, TCG_CALL_NO_RWG, f32, f32, ptr) | ||
54 | DEF_HELPER_FLAGS_2(frint32_d, TCG_CALL_NO_RWG, f64, f64, ptr) | ||
55 | DEF_HELPER_FLAGS_2(frint64_d, TCG_CALL_NO_RWG, f64, f64, ptr) | ||
56 | |||
57 | +DEF_HELPER_FLAGS_3(gvec_ceq0_b, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
58 | +DEF_HELPER_FLAGS_3(gvec_ceq0_h, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
59 | +DEF_HELPER_FLAGS_3(gvec_clt0_b, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
60 | +DEF_HELPER_FLAGS_3(gvec_clt0_h, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
61 | +DEF_HELPER_FLAGS_3(gvec_cle0_b, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
62 | +DEF_HELPER_FLAGS_3(gvec_cle0_h, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
63 | +DEF_HELPER_FLAGS_3(gvec_cgt0_b, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
64 | +DEF_HELPER_FLAGS_3(gvec_cgt0_h, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
65 | +DEF_HELPER_FLAGS_3(gvec_cge0_b, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
66 | +DEF_HELPER_FLAGS_3(gvec_cge0_h, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
67 | + | ||
68 | DEF_HELPER_FLAGS_4(gvec_sshl_b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
69 | DEF_HELPER_FLAGS_4(gvec_sshl_h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
70 | DEF_HELPER_FLAGS_4(gvec_ushl_b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
71 | diff --git a/target/arm/translate.h b/target/arm/translate.h | ||
72 | index XXXXXXX..XXXXXXX 100644 | 54 | index XXXXXXX..XXXXXXX 100644 |
73 | --- a/target/arm/translate.h | 55 | --- a/target/arm/hvf/hvf.c |
74 | +++ b/target/arm/translate.h | 56 | +++ b/target/arm/hvf/hvf.c |
75 | @@ -XXX,XX +XXX,XX @@ static inline void gen_swstep_exception(DisasContext *s, int isv, int ex) | 57 | @@ -XXX,XX +XXX,XX @@ int hvf_vcpu_exec(CPUState *cpu) |
76 | uint64_t vfp_expand_imm(int size, uint8_t imm8); | 58 | /* we got kicked, no exit to process */ |
77 | 59 | return 0; | |
78 | /* Vector operations shared between ARM and AArch64. */ | 60 | default: |
79 | +extern const GVecGen2 ceq0_op[4]; | 61 | - assert(0); |
80 | +extern const GVecGen2 clt0_op[4]; | 62 | + g_assert_not_reached(); |
81 | +extern const GVecGen2 cgt0_op[4]; | 63 | } |
82 | +extern const GVecGen2 cle0_op[4]; | 64 | |
83 | +extern const GVecGen2 cge0_op[4]; | 65 | hvf_sync_vtimer(cpu); |
84 | extern const GVecGen3 mla_op[4]; | 66 | diff --git a/target/arm/kvm-stub.c b/target/arm/kvm-stub.c |
85 | extern const GVecGen3 mls_op[4]; | ||
86 | extern const GVecGen3 cmtst_op[4]; | ||
87 | diff --git a/target/arm/neon_helper.c b/target/arm/neon_helper.c | ||
88 | index XXXXXXX..XXXXXXX 100644 | 67 | index XXXXXXX..XXXXXXX 100644 |
89 | --- a/target/arm/neon_helper.c | 68 | --- a/target/arm/kvm-stub.c |
90 | +++ b/target/arm/neon_helper.c | 69 | +++ b/target/arm/kvm-stub.c |
91 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(neon_hsub_u32)(uint32_t src1, uint32_t src2) | 70 | @@ -XXX,XX +XXX,XX @@ |
92 | return dest; | 71 | |
72 | bool write_kvmstate_to_list(ARMCPU *cpu) | ||
73 | { | ||
74 | - abort(); | ||
75 | + g_assert_not_reached(); | ||
93 | } | 76 | } |
94 | 77 | ||
95 | -#define NEON_FN(dest, src1, src2) dest = (src1 > src2) ? ~0 : 0 | 78 | bool write_list_to_kvmstate(ARMCPU *cpu, int level) |
96 | -NEON_VOP(cgt_s8, neon_s8, 4) | ||
97 | -NEON_VOP(cgt_u8, neon_u8, 4) | ||
98 | -NEON_VOP(cgt_s16, neon_s16, 2) | ||
99 | -NEON_VOP(cgt_u16, neon_u16, 2) | ||
100 | -NEON_VOP(cgt_s32, neon_s32, 1) | ||
101 | -NEON_VOP(cgt_u32, neon_u32, 1) | ||
102 | -#undef NEON_FN | ||
103 | - | ||
104 | -#define NEON_FN(dest, src1, src2) dest = (src1 >= src2) ? ~0 : 0 | ||
105 | -NEON_VOP(cge_s8, neon_s8, 4) | ||
106 | -NEON_VOP(cge_u8, neon_u8, 4) | ||
107 | -NEON_VOP(cge_s16, neon_s16, 2) | ||
108 | -NEON_VOP(cge_u16, neon_u16, 2) | ||
109 | -NEON_VOP(cge_s32, neon_s32, 1) | ||
110 | -NEON_VOP(cge_u32, neon_u32, 1) | ||
111 | -#undef NEON_FN | ||
112 | - | ||
113 | #define NEON_FN(dest, src1, src2) dest = (src1 < src2) ? src1 : src2 | ||
114 | NEON_POP(pmin_s8, neon_s8, 4) | ||
115 | NEON_POP(pmin_u8, neon_u8, 4) | ||
116 | @@ -XXX,XX +XXX,XX @@ NEON_VOP(tst_u16, neon_u16, 2) | ||
117 | NEON_VOP(tst_u32, neon_u32, 1) | ||
118 | #undef NEON_FN | ||
119 | |||
120 | -#define NEON_FN(dest, src1, src2) dest = (src1 == src2) ? -1 : 0 | ||
121 | -NEON_VOP(ceq_u8, neon_u8, 4) | ||
122 | -NEON_VOP(ceq_u16, neon_u16, 2) | ||
123 | -NEON_VOP(ceq_u32, neon_u32, 1) | ||
124 | -#undef NEON_FN | ||
125 | - | ||
126 | /* Count Leading Sign/Zero Bits. */ | ||
127 | static inline int do_clz8(uint8_t x) | ||
128 | { | 79 | { |
80 | - abort(); | ||
81 | + g_assert_not_reached(); | ||
82 | } | ||
83 | diff --git a/target/arm/kvm.c b/target/arm/kvm.c | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/target/arm/kvm.c | ||
86 | +++ b/target/arm/kvm.c | ||
87 | @@ -XXX,XX +XXX,XX @@ bool write_kvmstate_to_list(ARMCPU *cpu) | ||
88 | ret = kvm_vcpu_ioctl(cs, KVM_GET_ONE_REG, &r); | ||
89 | break; | ||
90 | default: | ||
91 | - abort(); | ||
92 | + g_assert_not_reached(); | ||
93 | } | ||
94 | if (ret) { | ||
95 | ok = false; | ||
96 | @@ -XXX,XX +XXX,XX @@ bool write_list_to_kvmstate(ARMCPU *cpu, int level) | ||
97 | r.addr = (uintptr_t)(cpu->cpreg_values + i); | ||
98 | break; | ||
99 | default: | ||
100 | - abort(); | ||
101 | + g_assert_not_reached(); | ||
102 | } | ||
103 | ret = kvm_vcpu_ioctl(cs, KVM_SET_ONE_REG, &r); | ||
104 | if (ret) { | ||
105 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
106 | index XXXXXXX..XXXXXXX 100644 | ||
107 | --- a/target/arm/machine.c | ||
108 | +++ b/target/arm/machine.c | ||
109 | @@ -XXX,XX +XXX,XX @@ static int cpu_pre_save(void *opaque) | ||
110 | if (kvm_enabled()) { | ||
111 | if (!write_kvmstate_to_list(cpu)) { | ||
112 | /* This should never fail */ | ||
113 | - abort(); | ||
114 | + g_assert_not_reached(); | ||
115 | } | ||
116 | |||
117 | /* | ||
118 | @@ -XXX,XX +XXX,XX @@ static int cpu_pre_save(void *opaque) | ||
119 | } else { | ||
120 | if (!write_cpustate_to_list(cpu, false)) { | ||
121 | /* This should never fail. */ | ||
122 | - abort(); | ||
123 | + g_assert_not_reached(); | ||
124 | } | ||
125 | } | ||
126 | |||
129 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 127 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
130 | index XXXXXXX..XXXXXXX 100644 | 128 | index XXXXXXX..XXXXXXX 100644 |
131 | --- a/target/arm/translate-a64.c | 129 | --- a/target/arm/translate-a64.c |
132 | +++ b/target/arm/translate-a64.c | 130 | +++ b/target/arm/translate-a64.c |
133 | @@ -XXX,XX +XXX,XX @@ static void gen_gvec_fn4(DisasContext *s, bool is_q, int rd, int rn, int rm, | 131 | @@ -XXX,XX +XXX,XX @@ static void handle_fp_1src_half(DisasContext *s, int opcode, int rd, int rn) |
134 | is_q ? 16 : 8, vec_full_reg_size(s)); | 132 | gen_helper_advsimd_rinth(tcg_res, tcg_op, fpst); |
133 | break; | ||
134 | default: | ||
135 | - abort(); | ||
136 | + g_assert_not_reached(); | ||
137 | } | ||
138 | |||
139 | write_fp_sreg(s, rd, tcg_res); | ||
140 | @@ -XXX,XX +XXX,XX @@ static void handle_fp_fcvt(DisasContext *s, int opcode, | ||
141 | break; | ||
142 | } | ||
143 | default: | ||
144 | - abort(); | ||
145 | + g_assert_not_reached(); | ||
146 | } | ||
135 | } | 147 | } |
136 | 148 | ||
137 | +/* Expand a 2-operand AdvSIMD vector operation using an op descriptor. */ | 149 | diff --git a/target/arm/translate-neon.c b/target/arm/translate-neon.c |
138 | +static void gen_gvec_op2(DisasContext *s, bool is_q, int rd, | 150 | index XXXXXXX..XXXXXXX 100644 |
139 | + int rn, const GVecGen2 *gvec_op) | 151 | --- a/target/arm/translate-neon.c |
140 | +{ | 152 | +++ b/target/arm/translate-neon.c |
141 | + tcg_gen_gvec_2(vec_full_reg_offset(s, rd), vec_full_reg_offset(s, rn), | 153 | @@ -XXX,XX +XXX,XX @@ static bool trans_VLDST_single(DisasContext *s, arg_VLDST_single *a) |
142 | + is_q ? 16 : 8, vec_full_reg_size(s), gvec_op); | ||
143 | +} | ||
144 | + | ||
145 | /* Expand a 2-operand + immediate AdvSIMD vector operation using | ||
146 | * an op descriptor. | ||
147 | */ | ||
148 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn) | ||
149 | return; | ||
150 | } | 154 | } |
151 | break; | 155 | break; |
152 | + case 0x8: /* CMGT, CMGE */ | 156 | default: |
153 | + gen_gvec_op2(s, is_q, rd, rn, u ? &cge0_op[size] : &cgt0_op[size]); | 157 | - abort(); |
154 | + return; | 158 | + g_assert_not_reached(); |
155 | + case 0x9: /* CMEQ, CMLE */ | 159 | } |
156 | + gen_gvec_op2(s, is_q, rd, rn, u ? &cle0_op[size] : &ceq0_op[size]); | 160 | if ((vd + a->stride * (nregs - 1)) > 31) { |
157 | + return; | 161 | /* |
158 | + case 0xa: /* CMLT */ | ||
159 | + gen_gvec_op2(s, is_q, rd, rn, &clt0_op[size]); | ||
160 | + return; | ||
161 | case 0xb: | ||
162 | if (u) { /* ABS, NEG */ | ||
163 | gen_gvec_fn2(s, is_q, rd, rn, tcg_gen_gvec_neg, size); | ||
164 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn) | ||
165 | for (pass = 0; pass < (is_q ? 4 : 2); pass++) { | ||
166 | TCGv_i32 tcg_op = tcg_temp_new_i32(); | ||
167 | TCGv_i32 tcg_res = tcg_temp_new_i32(); | ||
168 | - TCGCond cond; | ||
169 | |||
170 | read_vec_element_i32(s, tcg_op, rn, pass, MO_32); | ||
171 | |||
172 | if (size == 2) { | ||
173 | /* Special cases for 32 bit elements */ | ||
174 | switch (opcode) { | ||
175 | - case 0xa: /* CMLT */ | ||
176 | - /* 32 bit integer comparison against zero, result is | ||
177 | - * test ? (2^32 - 1) : 0. We implement via setcond(test) | ||
178 | - * and inverting. | ||
179 | - */ | ||
180 | - cond = TCG_COND_LT; | ||
181 | - do_cmop: | ||
182 | - tcg_gen_setcondi_i32(cond, tcg_res, tcg_op, 0); | ||
183 | - tcg_gen_neg_i32(tcg_res, tcg_res); | ||
184 | - break; | ||
185 | - case 0x8: /* CMGT, CMGE */ | ||
186 | - cond = u ? TCG_COND_GE : TCG_COND_GT; | ||
187 | - goto do_cmop; | ||
188 | - case 0x9: /* CMEQ, CMLE */ | ||
189 | - cond = u ? TCG_COND_LE : TCG_COND_EQ; | ||
190 | - goto do_cmop; | ||
191 | case 0x4: /* CLS */ | ||
192 | if (u) { | ||
193 | tcg_gen_clzi_i32(tcg_res, tcg_op, 32); | ||
194 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn) | ||
195 | genfn(tcg_res, cpu_env, tcg_op); | ||
196 | break; | ||
197 | } | ||
198 | - case 0x8: /* CMGT, CMGE */ | ||
199 | - case 0x9: /* CMEQ, CMLE */ | ||
200 | - case 0xa: /* CMLT */ | ||
201 | - { | ||
202 | - static NeonGenTwoOpFn * const fns[3][2] = { | ||
203 | - { gen_helper_neon_cgt_s8, gen_helper_neon_cgt_s16 }, | ||
204 | - { gen_helper_neon_cge_s8, gen_helper_neon_cge_s16 }, | ||
205 | - { gen_helper_neon_ceq_u8, gen_helper_neon_ceq_u16 }, | ||
206 | - }; | ||
207 | - NeonGenTwoOpFn *genfn; | ||
208 | - int comp; | ||
209 | - bool reverse; | ||
210 | - TCGv_i32 tcg_zero = tcg_const_i32(0); | ||
211 | - | ||
212 | - /* comp = index into [CMGT, CMGE, CMEQ, CMLE, CMLT] */ | ||
213 | - comp = (opcode - 0x8) * 2 + u; | ||
214 | - /* ...but LE, LT are implemented as reverse GE, GT */ | ||
215 | - reverse = (comp > 2); | ||
216 | - if (reverse) { | ||
217 | - comp = 4 - comp; | ||
218 | - } | ||
219 | - genfn = fns[comp][size]; | ||
220 | - if (reverse) { | ||
221 | - genfn(tcg_res, tcg_zero, tcg_op); | ||
222 | - } else { | ||
223 | - genfn(tcg_res, tcg_op, tcg_zero); | ||
224 | - } | ||
225 | - tcg_temp_free_i32(tcg_zero); | ||
226 | - break; | ||
227 | - } | ||
228 | case 0x4: /* CLS, CLZ */ | ||
229 | if (u) { | ||
230 | if (size == 0) { | ||
231 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 162 | diff --git a/target/arm/translate.c b/target/arm/translate.c |
232 | index XXXXXXX..XXXXXXX 100644 | 163 | index XXXXXXX..XXXXXXX 100644 |
233 | --- a/target/arm/translate.c | 164 | --- a/target/arm/translate.c |
234 | +++ b/target/arm/translate.c | 165 | +++ b/target/arm/translate.c |
235 | @@ -XXX,XX +XXX,XX @@ static int do_v81_helper(DisasContext *s, gen_helper_gvec_3_ptr *fn, | 166 | @@ -XXX,XX +XXX,XX @@ static void gen_srs(DisasContext *s, |
236 | return 1; | 167 | offset = 4; |
237 | } | 168 | break; |
238 | 169 | default: | |
239 | +static void gen_ceq0_i32(TCGv_i32 d, TCGv_i32 a) | 170 | - abort(); |
240 | +{ | 171 | + g_assert_not_reached(); |
241 | + tcg_gen_setcondi_i32(TCG_COND_EQ, d, a, 0); | ||
242 | + tcg_gen_neg_i32(d, d); | ||
243 | +} | ||
244 | + | ||
245 | +static void gen_ceq0_i64(TCGv_i64 d, TCGv_i64 a) | ||
246 | +{ | ||
247 | + tcg_gen_setcondi_i64(TCG_COND_EQ, d, a, 0); | ||
248 | + tcg_gen_neg_i64(d, d); | ||
249 | +} | ||
250 | + | ||
251 | +static void gen_ceq0_vec(unsigned vece, TCGv_vec d, TCGv_vec a) | ||
252 | +{ | ||
253 | + TCGv_vec zero = tcg_const_zeros_vec_matching(d); | ||
254 | + tcg_gen_cmp_vec(TCG_COND_EQ, vece, d, a, zero); | ||
255 | + tcg_temp_free_vec(zero); | ||
256 | +} | ||
257 | + | ||
258 | +static const TCGOpcode vecop_list_cmp[] = { | ||
259 | + INDEX_op_cmp_vec, 0 | ||
260 | +}; | ||
261 | + | ||
262 | +const GVecGen2 ceq0_op[4] = { | ||
263 | + { .fno = gen_helper_gvec_ceq0_b, | ||
264 | + .fniv = gen_ceq0_vec, | ||
265 | + .opt_opc = vecop_list_cmp, | ||
266 | + .vece = MO_8 }, | ||
267 | + { .fno = gen_helper_gvec_ceq0_h, | ||
268 | + .fniv = gen_ceq0_vec, | ||
269 | + .opt_opc = vecop_list_cmp, | ||
270 | + .vece = MO_16 }, | ||
271 | + { .fni4 = gen_ceq0_i32, | ||
272 | + .fniv = gen_ceq0_vec, | ||
273 | + .opt_opc = vecop_list_cmp, | ||
274 | + .vece = MO_32 }, | ||
275 | + { .fni8 = gen_ceq0_i64, | ||
276 | + .fniv = gen_ceq0_vec, | ||
277 | + .opt_opc = vecop_list_cmp, | ||
278 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
279 | + .vece = MO_64 }, | ||
280 | +}; | ||
281 | + | ||
282 | +static void gen_cle0_i32(TCGv_i32 d, TCGv_i32 a) | ||
283 | +{ | ||
284 | + tcg_gen_setcondi_i32(TCG_COND_LE, d, a, 0); | ||
285 | + tcg_gen_neg_i32(d, d); | ||
286 | +} | ||
287 | + | ||
288 | +static void gen_cle0_i64(TCGv_i64 d, TCGv_i64 a) | ||
289 | +{ | ||
290 | + tcg_gen_setcondi_i64(TCG_COND_LE, d, a, 0); | ||
291 | + tcg_gen_neg_i64(d, d); | ||
292 | +} | ||
293 | + | ||
294 | +static void gen_cle0_vec(unsigned vece, TCGv_vec d, TCGv_vec a) | ||
295 | +{ | ||
296 | + TCGv_vec zero = tcg_const_zeros_vec_matching(d); | ||
297 | + tcg_gen_cmp_vec(TCG_COND_LE, vece, d, a, zero); | ||
298 | + tcg_temp_free_vec(zero); | ||
299 | +} | ||
300 | + | ||
301 | +const GVecGen2 cle0_op[4] = { | ||
302 | + { .fno = gen_helper_gvec_cle0_b, | ||
303 | + .fniv = gen_cle0_vec, | ||
304 | + .opt_opc = vecop_list_cmp, | ||
305 | + .vece = MO_8 }, | ||
306 | + { .fno = gen_helper_gvec_cle0_h, | ||
307 | + .fniv = gen_cle0_vec, | ||
308 | + .opt_opc = vecop_list_cmp, | ||
309 | + .vece = MO_16 }, | ||
310 | + { .fni4 = gen_cle0_i32, | ||
311 | + .fniv = gen_cle0_vec, | ||
312 | + .opt_opc = vecop_list_cmp, | ||
313 | + .vece = MO_32 }, | ||
314 | + { .fni8 = gen_cle0_i64, | ||
315 | + .fniv = gen_cle0_vec, | ||
316 | + .opt_opc = vecop_list_cmp, | ||
317 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
318 | + .vece = MO_64 }, | ||
319 | +}; | ||
320 | + | ||
321 | +static void gen_cge0_i32(TCGv_i32 d, TCGv_i32 a) | ||
322 | +{ | ||
323 | + tcg_gen_setcondi_i32(TCG_COND_GE, d, a, 0); | ||
324 | + tcg_gen_neg_i32(d, d); | ||
325 | +} | ||
326 | + | ||
327 | +static void gen_cge0_i64(TCGv_i64 d, TCGv_i64 a) | ||
328 | +{ | ||
329 | + tcg_gen_setcondi_i64(TCG_COND_GE, d, a, 0); | ||
330 | + tcg_gen_neg_i64(d, d); | ||
331 | +} | ||
332 | + | ||
333 | +static void gen_cge0_vec(unsigned vece, TCGv_vec d, TCGv_vec a) | ||
334 | +{ | ||
335 | + TCGv_vec zero = tcg_const_zeros_vec_matching(d); | ||
336 | + tcg_gen_cmp_vec(TCG_COND_GE, vece, d, a, zero); | ||
337 | + tcg_temp_free_vec(zero); | ||
338 | +} | ||
339 | + | ||
340 | +const GVecGen2 cge0_op[4] = { | ||
341 | + { .fno = gen_helper_gvec_cge0_b, | ||
342 | + .fniv = gen_cge0_vec, | ||
343 | + .opt_opc = vecop_list_cmp, | ||
344 | + .vece = MO_8 }, | ||
345 | + { .fno = gen_helper_gvec_cge0_h, | ||
346 | + .fniv = gen_cge0_vec, | ||
347 | + .opt_opc = vecop_list_cmp, | ||
348 | + .vece = MO_16 }, | ||
349 | + { .fni4 = gen_cge0_i32, | ||
350 | + .fniv = gen_cge0_vec, | ||
351 | + .opt_opc = vecop_list_cmp, | ||
352 | + .vece = MO_32 }, | ||
353 | + { .fni8 = gen_cge0_i64, | ||
354 | + .fniv = gen_cge0_vec, | ||
355 | + .opt_opc = vecop_list_cmp, | ||
356 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
357 | + .vece = MO_64 }, | ||
358 | +}; | ||
359 | + | ||
360 | +static void gen_clt0_i32(TCGv_i32 d, TCGv_i32 a) | ||
361 | +{ | ||
362 | + tcg_gen_setcondi_i32(TCG_COND_LT, d, a, 0); | ||
363 | + tcg_gen_neg_i32(d, d); | ||
364 | +} | ||
365 | + | ||
366 | +static void gen_clt0_i64(TCGv_i64 d, TCGv_i64 a) | ||
367 | +{ | ||
368 | + tcg_gen_setcondi_i64(TCG_COND_LT, d, a, 0); | ||
369 | + tcg_gen_neg_i64(d, d); | ||
370 | +} | ||
371 | + | ||
372 | +static void gen_clt0_vec(unsigned vece, TCGv_vec d, TCGv_vec a) | ||
373 | +{ | ||
374 | + TCGv_vec zero = tcg_const_zeros_vec_matching(d); | ||
375 | + tcg_gen_cmp_vec(TCG_COND_LT, vece, d, a, zero); | ||
376 | + tcg_temp_free_vec(zero); | ||
377 | +} | ||
378 | + | ||
379 | +const GVecGen2 clt0_op[4] = { | ||
380 | + { .fno = gen_helper_gvec_clt0_b, | ||
381 | + .fniv = gen_clt0_vec, | ||
382 | + .opt_opc = vecop_list_cmp, | ||
383 | + .vece = MO_8 }, | ||
384 | + { .fno = gen_helper_gvec_clt0_h, | ||
385 | + .fniv = gen_clt0_vec, | ||
386 | + .opt_opc = vecop_list_cmp, | ||
387 | + .vece = MO_16 }, | ||
388 | + { .fni4 = gen_clt0_i32, | ||
389 | + .fniv = gen_clt0_vec, | ||
390 | + .opt_opc = vecop_list_cmp, | ||
391 | + .vece = MO_32 }, | ||
392 | + { .fni8 = gen_clt0_i64, | ||
393 | + .fniv = gen_clt0_vec, | ||
394 | + .opt_opc = vecop_list_cmp, | ||
395 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
396 | + .vece = MO_64 }, | ||
397 | +}; | ||
398 | + | ||
399 | +static void gen_cgt0_i32(TCGv_i32 d, TCGv_i32 a) | ||
400 | +{ | ||
401 | + tcg_gen_setcondi_i32(TCG_COND_GT, d, a, 0); | ||
402 | + tcg_gen_neg_i32(d, d); | ||
403 | +} | ||
404 | + | ||
405 | +static void gen_cgt0_i64(TCGv_i64 d, TCGv_i64 a) | ||
406 | +{ | ||
407 | + tcg_gen_setcondi_i64(TCG_COND_GT, d, a, 0); | ||
408 | + tcg_gen_neg_i64(d, d); | ||
409 | +} | ||
410 | + | ||
411 | +static void gen_cgt0_vec(unsigned vece, TCGv_vec d, TCGv_vec a) | ||
412 | +{ | ||
413 | + TCGv_vec zero = tcg_const_zeros_vec_matching(d); | ||
414 | + tcg_gen_cmp_vec(TCG_COND_GT, vece, d, a, zero); | ||
415 | + tcg_temp_free_vec(zero); | ||
416 | +} | ||
417 | + | ||
418 | +const GVecGen2 cgt0_op[4] = { | ||
419 | + { .fno = gen_helper_gvec_cgt0_b, | ||
420 | + .fniv = gen_cgt0_vec, | ||
421 | + .opt_opc = vecop_list_cmp, | ||
422 | + .vece = MO_8 }, | ||
423 | + { .fno = gen_helper_gvec_cgt0_h, | ||
424 | + .fniv = gen_cgt0_vec, | ||
425 | + .opt_opc = vecop_list_cmp, | ||
426 | + .vece = MO_16 }, | ||
427 | + { .fni4 = gen_cgt0_i32, | ||
428 | + .fniv = gen_cgt0_vec, | ||
429 | + .opt_opc = vecop_list_cmp, | ||
430 | + .vece = MO_32 }, | ||
431 | + { .fni8 = gen_cgt0_i64, | ||
432 | + .fniv = gen_cgt0_vec, | ||
433 | + .opt_opc = vecop_list_cmp, | ||
434 | + .prefer_i64 = TCG_TARGET_REG_BITS == 64, | ||
435 | + .vece = MO_64 }, | ||
436 | +}; | ||
437 | + | ||
438 | static void gen_ssra8_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
439 | { | ||
440 | tcg_gen_vec_sar8i_i64(a, a, shift); | ||
441 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
442 | tcg_gen_gvec_abs(size, rd_ofs, rm_ofs, vec_size, vec_size); | ||
443 | break; | ||
444 | |||
445 | + case NEON_2RM_VCEQ0: | ||
446 | + tcg_gen_gvec_2(rd_ofs, rm_ofs, vec_size, | ||
447 | + vec_size, &ceq0_op[size]); | ||
448 | + break; | ||
449 | + case NEON_2RM_VCGT0: | ||
450 | + tcg_gen_gvec_2(rd_ofs, rm_ofs, vec_size, | ||
451 | + vec_size, &cgt0_op[size]); | ||
452 | + break; | ||
453 | + case NEON_2RM_VCLE0: | ||
454 | + tcg_gen_gvec_2(rd_ofs, rm_ofs, vec_size, | ||
455 | + vec_size, &cle0_op[size]); | ||
456 | + break; | ||
457 | + case NEON_2RM_VCGE0: | ||
458 | + tcg_gen_gvec_2(rd_ofs, rm_ofs, vec_size, | ||
459 | + vec_size, &cge0_op[size]); | ||
460 | + break; | ||
461 | + case NEON_2RM_VCLT0: | ||
462 | + tcg_gen_gvec_2(rd_ofs, rm_ofs, vec_size, | ||
463 | + vec_size, &clt0_op[size]); | ||
464 | + break; | ||
465 | + | ||
466 | default: | ||
467 | elementwise: | ||
468 | for (pass = 0; pass < (q ? 4 : 2); pass++) { | ||
469 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
470 | default: abort(); | ||
471 | } | ||
472 | break; | ||
473 | - case NEON_2RM_VCGT0: case NEON_2RM_VCLE0: | ||
474 | - tmp2 = tcg_const_i32(0); | ||
475 | - switch(size) { | ||
476 | - case 0: gen_helper_neon_cgt_s8(tmp, tmp, tmp2); break; | ||
477 | - case 1: gen_helper_neon_cgt_s16(tmp, tmp, tmp2); break; | ||
478 | - case 2: gen_helper_neon_cgt_s32(tmp, tmp, tmp2); break; | ||
479 | - default: abort(); | ||
480 | - } | ||
481 | - tcg_temp_free_i32(tmp2); | ||
482 | - if (op == NEON_2RM_VCLE0) { | ||
483 | - tcg_gen_not_i32(tmp, tmp); | ||
484 | - } | ||
485 | - break; | ||
486 | - case NEON_2RM_VCGE0: case NEON_2RM_VCLT0: | ||
487 | - tmp2 = tcg_const_i32(0); | ||
488 | - switch(size) { | ||
489 | - case 0: gen_helper_neon_cge_s8(tmp, tmp, tmp2); break; | ||
490 | - case 1: gen_helper_neon_cge_s16(tmp, tmp, tmp2); break; | ||
491 | - case 2: gen_helper_neon_cge_s32(tmp, tmp, tmp2); break; | ||
492 | - default: abort(); | ||
493 | - } | ||
494 | - tcg_temp_free_i32(tmp2); | ||
495 | - if (op == NEON_2RM_VCLT0) { | ||
496 | - tcg_gen_not_i32(tmp, tmp); | ||
497 | - } | ||
498 | - break; | ||
499 | - case NEON_2RM_VCEQ0: | ||
500 | - tmp2 = tcg_const_i32(0); | ||
501 | - switch(size) { | ||
502 | - case 0: gen_helper_neon_ceq_u8(tmp, tmp, tmp2); break; | ||
503 | - case 1: gen_helper_neon_ceq_u16(tmp, tmp, tmp2); break; | ||
504 | - case 2: gen_helper_neon_ceq_u32(tmp, tmp, tmp2); break; | ||
505 | - default: abort(); | ||
506 | - } | ||
507 | - tcg_temp_free_i32(tmp2); | ||
508 | - break; | ||
509 | case NEON_2RM_VCGT0_F: | ||
510 | { | ||
511 | TCGv_ptr fpstatus = get_fpstatus_ptr(1); | ||
512 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | ||
513 | index XXXXXXX..XXXXXXX 100644 | ||
514 | --- a/target/arm/vec_helper.c | ||
515 | +++ b/target/arm/vec_helper.c | ||
516 | @@ -XXX,XX +XXX,XX @@ void HELPER(sve2_pmull_h)(void *vd, void *vn, void *vm, uint32_t desc) | ||
517 | } | 172 | } |
518 | } | 173 | tcg_gen_addi_i32(addr, addr, offset); |
519 | #endif | 174 | tmp = load_reg(s, 14); |
520 | + | 175 | @@ -XXX,XX +XXX,XX @@ static void gen_srs(DisasContext *s, |
521 | +#define DO_CMP0(NAME, TYPE, OP) \ | 176 | offset = 0; |
522 | +void HELPER(NAME)(void *vd, void *vn, uint32_t desc) \ | 177 | break; |
523 | +{ \ | 178 | default: |
524 | + intptr_t i, opr_sz = simd_oprsz(desc); \ | 179 | - abort(); |
525 | + for (i = 0; i < opr_sz; i += sizeof(TYPE)) { \ | 180 | + g_assert_not_reached(); |
526 | + TYPE nn = *(TYPE *)(vn + i); \ | 181 | } |
527 | + *(TYPE *)(vd + i) = -(nn OP 0); \ | 182 | tcg_gen_addi_i32(addr, addr, offset); |
528 | + } \ | 183 | gen_helper_set_r13_banked(cpu_env, tcg_constant_i32(mode), addr); |
529 | + clear_tail(vd, opr_sz, simd_maxsz(desc)); \ | ||
530 | +} | ||
531 | + | ||
532 | +DO_CMP0(gvec_ceq0_b, int8_t, ==) | ||
533 | +DO_CMP0(gvec_clt0_b, int8_t, <) | ||
534 | +DO_CMP0(gvec_cle0_b, int8_t, <=) | ||
535 | +DO_CMP0(gvec_cgt0_b, int8_t, >) | ||
536 | +DO_CMP0(gvec_cge0_b, int8_t, >=) | ||
537 | + | ||
538 | +DO_CMP0(gvec_ceq0_h, int16_t, ==) | ||
539 | +DO_CMP0(gvec_clt0_h, int16_t, <) | ||
540 | +DO_CMP0(gvec_cle0_h, int16_t, <=) | ||
541 | +DO_CMP0(gvec_cgt0_h, int16_t, >) | ||
542 | +DO_CMP0(gvec_cge0_h, int16_t, >=) | ||
543 | + | ||
544 | +#undef DO_CMP0 | ||
545 | -- | 184 | -- |
546 | 2.20.1 | 185 | 2.25.1 |
547 | |||
548 | diff view generated by jsdifflib |
1 | From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Disable unsupported FDT firmware nodes if a user passes us | 3 | Create a typedef as well, and use it in ARMCPRegInfo. |
4 | a DTB with nodes enabled that the machine cannot support | 4 | This won't be perfect for debugging, but it'll nicely |
5 | due to lack of EL3 or EL2 support. | 5 | display the most common cases. |
6 | 6 | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Message-id: 20200423121114.4274-5-edgar.iglesias@gmail.com | 9 | Message-id: 20220501055028.646596-8-richard.henderson@linaro.org |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 11 | --- |
12 | hw/arm/xlnx-zcu102.c | 30 ++++++++++++++++++++++++++++++ | 12 | target/arm/cpregs.h | 44 +++++++++++++++++++++++--------------------- |
13 | 1 file changed, 30 insertions(+) | 13 | target/arm/helper.c | 2 +- |
14 | 2 files changed, 24 insertions(+), 22 deletions(-) | ||
14 | 15 | ||
15 | diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c | 16 | diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h |
16 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/arm/xlnx-zcu102.c | 18 | --- a/target/arm/cpregs.h |
18 | +++ b/hw/arm/xlnx-zcu102.c | 19 | +++ b/target/arm/cpregs.h |
19 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ enum { |
20 | #include "qemu/error-report.h" | 21 | * described with these bits, then use a laxer set of restrictions, and |
21 | #include "qemu/log.h" | 22 | * do the more restrictive/complex check inside a helper function. |
22 | #include "sysemu/qtest.h" | 23 | */ |
23 | +#include "sysemu/device_tree.h" | 24 | -#define PL3_R 0x80 |
24 | 25 | -#define PL3_W 0x40 | |
25 | typedef struct XlnxZCU102 { | 26 | -#define PL2_R (0x20 | PL3_R) |
26 | MachineState parent_obj; | 27 | -#define PL2_W (0x10 | PL3_W) |
27 | @@ -XXX,XX +XXX,XX @@ static void zcu102_set_virt(Object *obj, bool value, Error **errp) | 28 | -#define PL1_R (0x08 | PL2_R) |
28 | s->virt = value; | 29 | -#define PL1_W (0x04 | PL2_W) |
29 | } | 30 | -#define PL0_R (0x02 | PL1_R) |
30 | 31 | -#define PL0_W (0x01 | PL1_W) | |
31 | +static void zcu102_modify_dtb(const struct arm_boot_info *binfo, void *fdt) | 32 | +typedef enum { |
32 | +{ | 33 | + PL3_R = 0x80, |
33 | + XlnxZCU102 *s = container_of(binfo, XlnxZCU102, binfo); | 34 | + PL3_W = 0x40, |
34 | + bool method_is_hvc; | 35 | + PL2_R = 0x20 | PL3_R, |
35 | + char **node_path; | 36 | + PL2_W = 0x10 | PL3_W, |
36 | + const char *r; | 37 | + PL1_R = 0x08 | PL2_R, |
37 | + int prop_len; | 38 | + PL1_W = 0x04 | PL2_W, |
38 | + int i; | 39 | + PL0_R = 0x02 | PL1_R, |
39 | + | 40 | + PL0_W = 0x01 | PL1_W, |
40 | + /* If EL3 is enabled, we keep all firmware nodes active. */ | 41 | |
41 | + if (!s->secure) { | 42 | -/* |
42 | + node_path = qemu_fdt_node_path(fdt, NULL, "xlnx,zynqmp-firmware", | 43 | - * For user-mode some registers are accessible to EL0 via a kernel |
43 | + &error_fatal); | 44 | - * trap-and-emulate ABI. In this case we define the read permissions |
44 | + | 45 | - * as actually being PL0_R. However some bits of any given register |
45 | + for (i = 0; node_path && node_path[i]; i++) { | 46 | - * may still be masked. |
46 | + r = qemu_fdt_getprop(fdt, node_path[i], "method", &prop_len, NULL); | 47 | - */ |
47 | + method_is_hvc = r && !strcmp("hvc", r); | 48 | + /* |
48 | + | 49 | + * For user-mode some registers are accessible to EL0 via a kernel |
49 | + /* Allow HVC based firmware if EL2 is enabled. */ | 50 | + * trap-and-emulate ABI. In this case we define the read permissions |
50 | + if (method_is_hvc && s->virt) { | 51 | + * as actually being PL0_R. However some bits of any given register |
51 | + continue; | 52 | + * may still be masked. |
52 | + } | 53 | + */ |
53 | + qemu_fdt_setprop_string(fdt, node_path[i], "status", "disabled"); | 54 | #ifdef CONFIG_USER_ONLY |
54 | + } | 55 | -#define PL0U_R PL0_R |
55 | + g_strfreev(node_path); | 56 | + PL0U_R = PL0_R, |
56 | + } | 57 | #else |
57 | +} | 58 | -#define PL0U_R PL1_R |
58 | + | 59 | + PL0U_R = PL1_R, |
59 | static void xlnx_zcu102_init(MachineState *machine) | 60 | #endif |
60 | { | 61 | |
61 | XlnxZCU102 *s = ZCU102_MACHINE(machine); | 62 | -#define PL3_RW (PL3_R | PL3_W) |
62 | @@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_init(MachineState *machine) | 63 | -#define PL2_RW (PL2_R | PL2_W) |
63 | 64 | -#define PL1_RW (PL1_R | PL1_W) | |
64 | s->binfo.ram_size = ram_size; | 65 | -#define PL0_RW (PL0_R | PL0_W) |
65 | s->binfo.loader_start = 0; | 66 | + PL3_RW = PL3_R | PL3_W, |
66 | + s->binfo.modify_dtb = zcu102_modify_dtb; | 67 | + PL2_RW = PL2_R | PL2_W, |
67 | arm_load_kernel(s->soc.boot_cpu_ptr, machine, &s->binfo); | 68 | + PL1_RW = PL1_R | PL1_W, |
68 | } | 69 | + PL0_RW = PL0_R | PL0_W, |
69 | 70 | +} CPAccessRights; | |
71 | |||
72 | typedef enum CPAccessResult { | ||
73 | /* Access is permitted */ | ||
74 | @@ -XXX,XX +XXX,XX @@ struct ARMCPRegInfo { | ||
75 | /* Register type: ARM_CP_* bits/values */ | ||
76 | int type; | ||
77 | /* Access rights: PL*_[RW] */ | ||
78 | - int access; | ||
79 | + CPAccessRights access; | ||
80 | /* Security state: ARM_CP_SECSTATE_* bits/values */ | ||
81 | int secure; | ||
82 | /* | ||
83 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/target/arm/helper.c | ||
86 | +++ b/target/arm/helper.c | ||
87 | @@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, | ||
88 | * to encompass the generic architectural permission check. | ||
89 | */ | ||
90 | if (r->state != ARM_CP_STATE_AA32) { | ||
91 | - int mask = 0; | ||
92 | + CPAccessRights mask; | ||
93 | switch (r->opc1) { | ||
94 | case 0: | ||
95 | /* min_EL EL1, but some accessible to EL0 via kernel ABI */ | ||
70 | -- | 96 | -- |
71 | 2.20.1 | 97 | 2.25.1 |
72 | |||
73 | diff view generated by jsdifflib |
1 | From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Make compat in qemu_fdt_node_path() const char *. | 3 | Give this enum a name and use in ARMCPRegInfo, |
4 | add_cpreg_to_hashtable and define_one_arm_cp_reg_with_opaque. | ||
4 | 5 | ||
5 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 6 | Reviewed-by: Alex Bennée <alex.bennee@linaro.org> |
6 | Message-id: 20200423121114.4274-3-edgar.iglesias@gmail.com | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20220501055028.646596-9-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 11 | --- |
10 | include/sysemu/device_tree.h | 2 +- | 12 | target/arm/cpregs.h | 6 +++--- |
11 | device_tree.c | 2 +- | 13 | target/arm/helper.c | 6 ++++-- |
12 | 2 files changed, 2 insertions(+), 2 deletions(-) | 14 | 2 files changed, 7 insertions(+), 5 deletions(-) |
13 | 15 | ||
14 | diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h | 16 | diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/include/sysemu/device_tree.h | 18 | --- a/target/arm/cpregs.h |
17 | +++ b/include/sysemu/device_tree.h | 19 | +++ b/target/arm/cpregs.h |
18 | @@ -XXX,XX +XXX,XX @@ void *load_device_tree_from_sysfs(void); | 20 | @@ -XXX,XX +XXX,XX @@ enum { |
19 | * @name may be NULL to wildcard names and only match compatibility | 21 | * Note that we rely on the values of these enums as we iterate through |
20 | * strings. | 22 | * the various states in some places. |
21 | */ | 23 | */ |
22 | -char **qemu_fdt_node_path(void *fdt, const char *name, char *compat, | 24 | -enum { |
23 | +char **qemu_fdt_node_path(void *fdt, const char *name, const char *compat, | 25 | +typedef enum { |
24 | Error **errp); | 26 | ARM_CP_STATE_AA32 = 0, |
25 | 27 | ARM_CP_STATE_AA64 = 1, | |
26 | /** | 28 | ARM_CP_STATE_BOTH = 2, |
27 | diff --git a/device_tree.c b/device_tree.c | 29 | -}; |
30 | +} CPState; | ||
31 | |||
32 | /* | ||
33 | * ARM CP register secure state flags. These flags identify security state | ||
34 | @@ -XXX,XX +XXX,XX @@ struct ARMCPRegInfo { | ||
35 | uint8_t opc1; | ||
36 | uint8_t opc2; | ||
37 | /* Execution state in which this register is visible: ARM_CP_STATE_* */ | ||
38 | - int state; | ||
39 | + CPState state; | ||
40 | /* Register type: ARM_CP_* bits/values */ | ||
41 | int type; | ||
42 | /* Access rights: PL*_[RW] */ | ||
43 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | 44 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/device_tree.c | 45 | --- a/target/arm/helper.c |
30 | +++ b/device_tree.c | 46 | +++ b/target/arm/helper.c |
31 | @@ -XXX,XX +XXX,XX @@ char **qemu_fdt_node_unit_path(void *fdt, const char *name, Error **errp) | 47 | @@ -XXX,XX +XXX,XX @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) |
32 | return path_array; | ||
33 | } | 48 | } |
34 | 49 | ||
35 | -char **qemu_fdt_node_path(void *fdt, const char *name, char *compat, | 50 | static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
36 | +char **qemu_fdt_node_path(void *fdt, const char *name, const char *compat, | 51 | - void *opaque, int state, int secstate, |
37 | Error **errp) | 52 | + void *opaque, CPState state, int secstate, |
53 | int crm, int opc1, int opc2, | ||
54 | const char *name) | ||
38 | { | 55 | { |
39 | int offset, len, ret; | 56 | @@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, |
57 | * bits; the ARM_CP_64BIT* flag applies only to the AArch32 view of | ||
58 | * the register, if any. | ||
59 | */ | ||
60 | - int crm, opc1, opc2, state; | ||
61 | + int crm, opc1, opc2; | ||
62 | int crmmin = (r->crm == CP_ANY) ? 0 : r->crm; | ||
63 | int crmmax = (r->crm == CP_ANY) ? 15 : r->crm; | ||
64 | int opc1min = (r->opc1 == CP_ANY) ? 0 : r->opc1; | ||
65 | int opc1max = (r->opc1 == CP_ANY) ? 7 : r->opc1; | ||
66 | int opc2min = (r->opc2 == CP_ANY) ? 0 : r->opc2; | ||
67 | int opc2max = (r->opc2 == CP_ANY) ? 7 : r->opc2; | ||
68 | + CPState state; | ||
69 | + | ||
70 | /* 64 bit registers have only CRm and Opc1 fields */ | ||
71 | assert(!((r->type & ARM_CP_64BIT) && (r->opc2 || r->crn))); | ||
72 | /* op0 only exists in the AArch64 encodings */ | ||
40 | -- | 73 | -- |
41 | 2.20.1 | 74 | 2.25.1 |
42 | 75 | ||
43 | 76 | diff view generated by jsdifflib |
1 | From: Ramon Fried <rfried.dev@gmail.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The RX ring descriptors control field is used for setting | 3 | Give this enum a name and use in ARMCPRegInfo and add_cpreg_to_hashtable. |
4 | SOF and EOF (start of frame and end of frame). | 4 | Add the enumerator ARM_CP_SECSTATE_BOTH to clarify how 0 |
5 | The SOF and EOF weren't cleared from the previous descriptors, | 5 | is handled in define_one_arm_cp_reg_with_opaque. |
6 | causing inconsistencies in ring buffer. | ||
7 | Fix that by clearing the control field of every descriptors we're | ||
8 | processing. | ||
9 | 6 | ||
10 | Signed-off-by: Ramon Fried <rfried.dev@gmail.com> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
12 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 9 | Message-id: 20220501055028.646596-10-richard.henderson@linaro.org |
13 | Message-id: 20200418085145.489726-1-rfried.dev@gmail.com | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | --- | 11 | --- |
16 | hw/net/cadence_gem.c | 7 +++++++ | 12 | target/arm/cpregs.h | 7 ++++--- |
17 | 1 file changed, 7 insertions(+) | 13 | target/arm/helper.c | 7 +++++-- |
14 | 2 files changed, 9 insertions(+), 5 deletions(-) | ||
18 | 15 | ||
19 | diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c | 16 | diff --git a/target/arm/cpregs.h b/target/arm/cpregs.h |
20 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/net/cadence_gem.c | 18 | --- a/target/arm/cpregs.h |
22 | +++ b/hw/net/cadence_gem.c | 19 | +++ b/target/arm/cpregs.h |
23 | @@ -XXX,XX +XXX,XX @@ static inline void rx_desc_set_sof(uint32_t *desc) | 20 | @@ -XXX,XX +XXX,XX @@ typedef enum { |
24 | desc[1] |= DESC_1_RX_SOF; | 21 | * registered entry will only have one to identify whether the entry is secure |
22 | * or non-secure. | ||
23 | */ | ||
24 | -enum { | ||
25 | +typedef enum { | ||
26 | + ARM_CP_SECSTATE_BOTH = 0, /* define one cpreg for each secstate */ | ||
27 | ARM_CP_SECSTATE_S = (1 << 0), /* bit[0]: Secure state register */ | ||
28 | ARM_CP_SECSTATE_NS = (1 << 1), /* bit[1]: Non-secure state register */ | ||
29 | -}; | ||
30 | +} CPSecureState; | ||
31 | |||
32 | /* | ||
33 | * Access rights: | ||
34 | @@ -XXX,XX +XXX,XX @@ struct ARMCPRegInfo { | ||
35 | /* Access rights: PL*_[RW] */ | ||
36 | CPAccessRights access; | ||
37 | /* Security state: ARM_CP_SECSTATE_* bits/values */ | ||
38 | - int secure; | ||
39 | + CPSecureState secure; | ||
40 | /* | ||
41 | * The opaque pointer passed to define_arm_cp_regs_with_opaque() when | ||
42 | * this register was defined: can be used to hand data through to the | ||
43 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/target/arm/helper.c | ||
46 | +++ b/target/arm/helper.c | ||
47 | @@ -XXX,XX +XXX,XX @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) | ||
25 | } | 48 | } |
26 | 49 | ||
27 | +static inline void rx_desc_clear_control(uint32_t *desc) | 50 | static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
28 | +{ | 51 | - void *opaque, CPState state, int secstate, |
29 | + desc[1] = 0; | 52 | + void *opaque, CPState state, |
30 | +} | 53 | + CPSecureState secstate, |
31 | + | 54 | int crm, int opc1, int opc2, |
32 | static inline void rx_desc_set_eof(uint32_t *desc) | 55 | const char *name) |
33 | { | 56 | { |
34 | desc[1] |= DESC_1_RX_EOF; | 57 | @@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, |
35 | @@ -XXX,XX +XXX,XX @@ static ssize_t gem_receive(NetClientState *nc, const uint8_t *buf, size_t size) | 58 | r->secure, crm, opc1, opc2, |
36 | rxbuf_ptr += MIN(bytes_to_copy, rxbufsize); | 59 | r->name); |
37 | bytes_to_copy -= MIN(bytes_to_copy, rxbufsize); | 60 | break; |
38 | 61 | - default: | |
39 | + rx_desc_clear_control(s->rx_desc[q]); | 62 | + case ARM_CP_SECSTATE_BOTH: |
40 | + | 63 | name = g_strdup_printf("%s_S", r->name); |
41 | /* Update the descriptor. */ | 64 | add_cpreg_to_hashtable(cpu, r, opaque, state, |
42 | if (first_desc) { | 65 | ARM_CP_SECSTATE_S, |
43 | rx_desc_set_sof(s->rx_desc[q]); | 66 | @@ -XXX,XX +XXX,XX @@ void define_one_arm_cp_reg_with_opaque(ARMCPU *cpu, |
67 | ARM_CP_SECSTATE_NS, | ||
68 | crm, opc1, opc2, r->name); | ||
69 | break; | ||
70 | + default: | ||
71 | + g_assert_not_reached(); | ||
72 | } | ||
73 | } else { | ||
74 | /* AArch64 registers get mapped to non-secure instance | ||
44 | -- | 75 | -- |
45 | 2.20.1 | 76 | 2.25.1 |
46 | |||
47 | diff view generated by jsdifflib |
1 | From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Move arm_boot_info into XlnxZCU102. | 3 | The new_key field is always non-zero -- drop the if. |
4 | 4 | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Message-id: 20200423121114.4274-4-edgar.iglesias@gmail.com | 7 | Message-id: 20220501055028.646596-11-richard.henderson@linaro.org |
8 | [PMM: reinstated dropped PL3_RW mask] | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 10 | --- |
10 | hw/arm/xlnx-zcu102.c | 9 +++++---- | 11 | target/arm/helper.c | 23 +++++++++++------------ |
11 | 1 file changed, 5 insertions(+), 4 deletions(-) | 12 | 1 file changed, 11 insertions(+), 12 deletions(-) |
12 | 13 | ||
13 | diff --git a/hw/arm/xlnx-zcu102.c b/hw/arm/xlnx-zcu102.c | 14 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/arm/xlnx-zcu102.c | 16 | --- a/target/arm/helper.c |
16 | +++ b/hw/arm/xlnx-zcu102.c | 17 | +++ b/target/arm/helper.c |
17 | @@ -XXX,XX +XXX,XX @@ typedef struct XlnxZCU102 { | 18 | @@ -XXX,XX +XXX,XX @@ static void define_arm_vh_e2h_redirects_aliases(ARMCPU *cpu) |
18 | 19 | ||
19 | bool secure; | 20 | for (i = 0; i < ARRAY_SIZE(aliases); i++) { |
20 | bool virt; | 21 | const struct E2HAlias *a = &aliases[i]; |
21 | + | 22 | - ARMCPRegInfo *src_reg, *dst_reg; |
22 | + struct arm_boot_info binfo; | 23 | + ARMCPRegInfo *src_reg, *dst_reg, *new_reg; |
23 | } XlnxZCU102; | 24 | + uint32_t *new_key; |
24 | 25 | + bool ok; | |
25 | #define TYPE_ZCU102_MACHINE MACHINE_TYPE_NAME("xlnx-zcu102") | 26 | |
26 | #define ZCU102_MACHINE(obj) \ | 27 | if (a->feature && !a->feature(&cpu->isar)) { |
27 | OBJECT_CHECK(XlnxZCU102, (obj), TYPE_ZCU102_MACHINE) | 28 | continue; |
28 | 29 | @@ -XXX,XX +XXX,XX @@ static void define_arm_vh_e2h_redirects_aliases(ARMCPU *cpu) | |
29 | -static struct arm_boot_info xlnx_zcu102_binfo; | 30 | g_assert(src_reg->opaque == NULL); |
30 | 31 | ||
31 | static bool zcu102_get_secure(Object *obj, Error **errp) | 32 | /* Create alias before redirection so we dup the right data. */ |
32 | { | 33 | - if (a->new_key) { |
33 | @@ -XXX,XX +XXX,XX @@ static void xlnx_zcu102_init(MachineState *machine) | 34 | - ARMCPRegInfo *new_reg = g_memdup(src_reg, sizeof(ARMCPRegInfo)); |
34 | 35 | - uint32_t *new_key = g_memdup(&a->new_key, sizeof(uint32_t)); | |
35 | /* TODO create and connect IDE devices for ide_drive_get() */ | 36 | - bool ok; |
36 | 37 | + new_reg = g_memdup(src_reg, sizeof(ARMCPRegInfo)); | |
37 | - xlnx_zcu102_binfo.ram_size = ram_size; | 38 | + new_key = g_memdup(&a->new_key, sizeof(uint32_t)); |
38 | - xlnx_zcu102_binfo.loader_start = 0; | 39 | |
39 | - arm_load_kernel(s->soc.boot_cpu_ptr, machine, &xlnx_zcu102_binfo); | 40 | - new_reg->name = a->new_name; |
40 | + s->binfo.ram_size = ram_size; | 41 | - new_reg->type |= ARM_CP_ALIAS; |
41 | + s->binfo.loader_start = 0; | 42 | - /* Remove PL1/PL0 access, leaving PL2/PL3 R/W in place. */ |
42 | + arm_load_kernel(s->soc.boot_cpu_ptr, machine, &s->binfo); | 43 | - new_reg->access &= PL2_RW | PL3_RW; |
43 | } | 44 | + new_reg->name = a->new_name; |
44 | 45 | + new_reg->type |= ARM_CP_ALIAS; | |
45 | static void xlnx_zcu102_machine_instance_init(Object *obj) | 46 | + /* Remove PL1/PL0 access, leaving PL2/PL3 R/W in place. */ |
47 | + new_reg->access &= PL2_RW | PL3_RW; | ||
48 | |||
49 | - ok = g_hash_table_insert(cpu->cp_regs, new_key, new_reg); | ||
50 | - g_assert(ok); | ||
51 | - } | ||
52 | + ok = g_hash_table_insert(cpu->cp_regs, new_key, new_reg); | ||
53 | + g_assert(ok); | ||
54 | |||
55 | src_reg->opaque = dst_reg; | ||
56 | src_reg->orig_readfn = src_reg->readfn ?: raw_read; | ||
46 | -- | 57 | -- |
47 | 2.20.1 | 58 | 2.25.1 |
48 | |||
49 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Make cpu_register() (renamed to arm_cpu_register()) available | 3 | Cast the uint32_t key into a gpointer directly, which |
4 | from internals.h so we can register CPUs also from other files | 4 | allows us to avoid allocating storage for each key. |
5 | in the future. | ||
6 | 5 | ||
7 | Signed-off-by: Thomas Huth <thuth@redhat.com> | 6 | Use g_hash_table_lookup when we already have a gpointer |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 7 | (e.g. for callbacks like count_cpreg), or when using |
9 | Reviewed-by: Eric Auger <eric.auger@redhat.com> | 8 | get_arm_cp_reginfo would require casting away const. |
10 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 9 | |
11 | Message-id: 20200423073358.27155-3-philmd@redhat.com | 10 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
12 | Message-ID: <20190921150420.30743-2-thuth@redhat.com> | 11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
13 | [PMD: Only take cpu_register() from Thomas's patch] | 12 | Message-id: 20220501055028.646596-12-richard.henderson@linaro.org |
14 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | --- | 14 | --- |
17 | target/arm/cpu-qom.h | 9 ++++++++- | 15 | target/arm/cpu.c | 4 ++-- |
18 | target/arm/cpu.c | 10 ++-------- | 16 | target/arm/gdbstub.c | 2 +- |
19 | target/arm/cpu64.c | 8 +------- | 17 | target/arm/helper.c | 41 ++++++++++++++++++----------------------- |
20 | 3 files changed, 11 insertions(+), 16 deletions(-) | 18 | 3 files changed, 21 insertions(+), 26 deletions(-) |
21 | 19 | ||
22 | diff --git a/target/arm/cpu-qom.h b/target/arm/cpu-qom.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/target/arm/cpu-qom.h | ||
25 | +++ b/target/arm/cpu-qom.h | ||
26 | @@ -XXX,XX +XXX,XX @@ struct arm_boot_info; | ||
27 | |||
28 | #define TYPE_ARM_MAX_CPU "max-" TYPE_ARM_CPU | ||
29 | |||
30 | -typedef struct ARMCPUInfo ARMCPUInfo; | ||
31 | +typedef struct ARMCPUInfo { | ||
32 | + const char *name; | ||
33 | + void (*initfn)(Object *obj); | ||
34 | + void (*class_init)(ObjectClass *oc, void *data); | ||
35 | +} ARMCPUInfo; | ||
36 | + | ||
37 | +void arm_cpu_register(const ARMCPUInfo *info); | ||
38 | +void aarch64_cpu_register(const ARMCPUInfo *info); | ||
39 | |||
40 | /** | ||
41 | * ARMCPUClass: | ||
42 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 20 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
43 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/target/arm/cpu.c | 22 | --- a/target/arm/cpu.c |
45 | +++ b/target/arm/cpu.c | 23 | +++ b/target/arm/cpu.c |
46 | @@ -XXX,XX +XXX,XX @@ static void arm_max_initfn(Object *obj) | 24 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_initfn(Object *obj) |
47 | 25 | ARMCPU *cpu = ARM_CPU(obj); | |
48 | #endif /* !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64) */ | 26 | |
49 | 27 | cpu_set_cpustate_pointers(cpu); | |
50 | -struct ARMCPUInfo { | 28 | - cpu->cp_regs = g_hash_table_new_full(g_int_hash, g_int_equal, |
51 | - const char *name; | 29 | - g_free, cpreg_hashtable_data_destroy); |
52 | - void (*initfn)(Object *obj); | 30 | + cpu->cp_regs = g_hash_table_new_full(g_direct_hash, g_direct_equal, |
53 | - void (*class_init)(ObjectClass *oc, void *data); | 31 | + NULL, cpreg_hashtable_data_destroy); |
54 | -}; | 32 | |
33 | QLIST_INIT(&cpu->pre_el_change_hooks); | ||
34 | QLIST_INIT(&cpu->el_change_hooks); | ||
35 | diff --git a/target/arm/gdbstub.c b/target/arm/gdbstub.c | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/target/arm/gdbstub.c | ||
38 | +++ b/target/arm/gdbstub.c | ||
39 | @@ -XXX,XX +XXX,XX @@ static void arm_gen_one_xml_sysreg_tag(GString *s, DynamicGDBXMLInfo *dyn_xml, | ||
40 | static void arm_register_sysreg_for_xml(gpointer key, gpointer value, | ||
41 | gpointer p) | ||
42 | { | ||
43 | - uint32_t ri_key = *(uint32_t *)key; | ||
44 | + uint32_t ri_key = (uintptr_t)key; | ||
45 | ARMCPRegInfo *ri = value; | ||
46 | RegisterSysregXmlParam *param = (RegisterSysregXmlParam *)p; | ||
47 | GString *s = param->s; | ||
48 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
49 | index XXXXXXX..XXXXXXX 100644 | ||
50 | --- a/target/arm/helper.c | ||
51 | +++ b/target/arm/helper.c | ||
52 | @@ -XXX,XX +XXX,XX @@ bool write_list_to_cpustate(ARMCPU *cpu) | ||
53 | static void add_cpreg_to_list(gpointer key, gpointer opaque) | ||
54 | { | ||
55 | ARMCPU *cpu = opaque; | ||
56 | - uint64_t regidx; | ||
57 | - const ARMCPRegInfo *ri; | ||
55 | - | 58 | - |
56 | static const ARMCPUInfo arm_cpus[] = { | 59 | - regidx = *(uint32_t *)key; |
57 | #if !defined(CONFIG_USER_ONLY) || !defined(TARGET_AARCH64) | 60 | - ri = get_arm_cp_reginfo(cpu->cp_regs, regidx); |
58 | { .name = "arm926", .initfn = arm926_initfn }, | 61 | + uint32_t regidx = (uintptr_t)key; |
59 | @@ -XXX,XX +XXX,XX @@ static void cpu_register_class_init(ObjectClass *oc, void *data) | 62 | + const ARMCPRegInfo *ri = get_arm_cp_reginfo(cpu->cp_regs, regidx); |
60 | acc->info = data; | 63 | |
64 | if (!(ri->type & (ARM_CP_NO_RAW|ARM_CP_ALIAS))) { | ||
65 | cpu->cpreg_indexes[cpu->cpreg_array_len] = cpreg_to_kvm_id(regidx); | ||
66 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_list(gpointer key, gpointer opaque) | ||
67 | static void count_cpreg(gpointer key, gpointer opaque) | ||
68 | { | ||
69 | ARMCPU *cpu = opaque; | ||
70 | - uint64_t regidx; | ||
71 | const ARMCPRegInfo *ri; | ||
72 | |||
73 | - regidx = *(uint32_t *)key; | ||
74 | - ri = get_arm_cp_reginfo(cpu->cp_regs, regidx); | ||
75 | + ri = g_hash_table_lookup(cpu->cp_regs, key); | ||
76 | |||
77 | if (!(ri->type & (ARM_CP_NO_RAW|ARM_CP_ALIAS))) { | ||
78 | cpu->cpreg_array_len++; | ||
79 | @@ -XXX,XX +XXX,XX @@ static void count_cpreg(gpointer key, gpointer opaque) | ||
80 | |||
81 | static gint cpreg_key_compare(gconstpointer a, gconstpointer b) | ||
82 | { | ||
83 | - uint64_t aidx = cpreg_to_kvm_id(*(uint32_t *)a); | ||
84 | - uint64_t bidx = cpreg_to_kvm_id(*(uint32_t *)b); | ||
85 | + uint64_t aidx = cpreg_to_kvm_id((uintptr_t)a); | ||
86 | + uint64_t bidx = cpreg_to_kvm_id((uintptr_t)b); | ||
87 | |||
88 | if (aidx > bidx) { | ||
89 | return 1; | ||
90 | @@ -XXX,XX +XXX,XX @@ static void define_arm_vh_e2h_redirects_aliases(ARMCPU *cpu) | ||
91 | for (i = 0; i < ARRAY_SIZE(aliases); i++) { | ||
92 | const struct E2HAlias *a = &aliases[i]; | ||
93 | ARMCPRegInfo *src_reg, *dst_reg, *new_reg; | ||
94 | - uint32_t *new_key; | ||
95 | bool ok; | ||
96 | |||
97 | if (a->feature && !a->feature(&cpu->isar)) { | ||
98 | continue; | ||
99 | } | ||
100 | |||
101 | - src_reg = g_hash_table_lookup(cpu->cp_regs, &a->src_key); | ||
102 | - dst_reg = g_hash_table_lookup(cpu->cp_regs, &a->dst_key); | ||
103 | + src_reg = g_hash_table_lookup(cpu->cp_regs, | ||
104 | + (gpointer)(uintptr_t)a->src_key); | ||
105 | + dst_reg = g_hash_table_lookup(cpu->cp_regs, | ||
106 | + (gpointer)(uintptr_t)a->dst_key); | ||
107 | g_assert(src_reg != NULL); | ||
108 | g_assert(dst_reg != NULL); | ||
109 | |||
110 | @@ -XXX,XX +XXX,XX @@ static void define_arm_vh_e2h_redirects_aliases(ARMCPU *cpu) | ||
111 | |||
112 | /* Create alias before redirection so we dup the right data. */ | ||
113 | new_reg = g_memdup(src_reg, sizeof(ARMCPRegInfo)); | ||
114 | - new_key = g_memdup(&a->new_key, sizeof(uint32_t)); | ||
115 | |||
116 | new_reg->name = a->new_name; | ||
117 | new_reg->type |= ARM_CP_ALIAS; | ||
118 | /* Remove PL1/PL0 access, leaving PL2/PL3 R/W in place. */ | ||
119 | new_reg->access &= PL2_RW | PL3_RW; | ||
120 | |||
121 | - ok = g_hash_table_insert(cpu->cp_regs, new_key, new_reg); | ||
122 | + ok = g_hash_table_insert(cpu->cp_regs, | ||
123 | + (gpointer)(uintptr_t)a->new_key, new_reg); | ||
124 | g_assert(ok); | ||
125 | |||
126 | src_reg->opaque = dst_reg; | ||
127 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
128 | /* Private utility function for define_one_arm_cp_reg_with_opaque(): | ||
129 | * add a single reginfo struct to the hash table. | ||
130 | */ | ||
131 | - uint32_t *key = g_new(uint32_t, 1); | ||
132 | + uint32_t key; | ||
133 | ARMCPRegInfo *r2 = g_memdup(r, sizeof(ARMCPRegInfo)); | ||
134 | int is64 = (r->type & ARM_CP_64BIT) ? 1 : 0; | ||
135 | int ns = (secstate & ARM_CP_SECSTATE_NS) ? 1 : 0; | ||
136 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
137 | if (r->cp == 0 || r->state == ARM_CP_STATE_BOTH) { | ||
138 | r2->cp = CP_REG_ARM64_SYSREG_CP; | ||
139 | } | ||
140 | - *key = ENCODE_AA64_CP_REG(r2->cp, r2->crn, crm, | ||
141 | - r2->opc0, opc1, opc2); | ||
142 | + key = ENCODE_AA64_CP_REG(r2->cp, r2->crn, crm, | ||
143 | + r2->opc0, opc1, opc2); | ||
144 | } else { | ||
145 | - *key = ENCODE_CP_REG(r2->cp, is64, ns, r2->crn, crm, opc1, opc2); | ||
146 | + key = ENCODE_CP_REG(r2->cp, is64, ns, r2->crn, crm, opc1, opc2); | ||
147 | } | ||
148 | if (opaque) { | ||
149 | r2->opaque = opaque; | ||
150 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
151 | * requested. | ||
152 | */ | ||
153 | if (!(r->type & ARM_CP_OVERRIDE)) { | ||
154 | - ARMCPRegInfo *oldreg; | ||
155 | - oldreg = g_hash_table_lookup(cpu->cp_regs, key); | ||
156 | + const ARMCPRegInfo *oldreg = get_arm_cp_reginfo(cpu->cp_regs, key); | ||
157 | if (oldreg && !(oldreg->type & ARM_CP_OVERRIDE)) { | ||
158 | fprintf(stderr, "Register redefined: cp=%d %d bit " | ||
159 | "crn=%d crm=%d opc1=%d opc2=%d, " | ||
160 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
161 | g_assert_not_reached(); | ||
162 | } | ||
163 | } | ||
164 | - g_hash_table_insert(cpu->cp_regs, key, r2); | ||
165 | + g_hash_table_insert(cpu->cp_regs, (gpointer)(uintptr_t)key, r2); | ||
61 | } | 166 | } |
62 | 167 | ||
63 | -static void cpu_register(const ARMCPUInfo *info) | 168 | |
64 | +void arm_cpu_register(const ARMCPUInfo *info) | 169 | @@ -XXX,XX +XXX,XX @@ void modify_arm_cp_regs_with_len(ARMCPRegInfo *regs, size_t regs_len, |
170 | |||
171 | const ARMCPRegInfo *get_arm_cp_reginfo(GHashTable *cpregs, uint32_t encoded_cp) | ||
65 | { | 172 | { |
66 | TypeInfo type_info = { | 173 | - return g_hash_table_lookup(cpregs, &encoded_cp); |
67 | .parent = TYPE_ARM_CPU, | 174 | + return g_hash_table_lookup(cpregs, (gpointer)(uintptr_t)encoded_cp); |
68 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_register_types(void) | ||
69 | type_register_static(&idau_interface_type_info); | ||
70 | |||
71 | while (info->name) { | ||
72 | - cpu_register(info); | ||
73 | + arm_cpu_register(info); | ||
74 | info++; | ||
75 | } | ||
76 | |||
77 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | ||
78 | index XXXXXXX..XXXXXXX 100644 | ||
79 | --- a/target/arm/cpu64.c | ||
80 | +++ b/target/arm/cpu64.c | ||
81 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) | ||
82 | cpu_max_set_sve_max_vq, NULL, NULL, &error_fatal); | ||
83 | } | 175 | } |
84 | 176 | ||
85 | -struct ARMCPUInfo { | 177 | void arm_cp_write_ignore(CPUARMState *env, const ARMCPRegInfo *ri, |
86 | - const char *name; | ||
87 | - void (*initfn)(Object *obj); | ||
88 | - void (*class_init)(ObjectClass *oc, void *data); | ||
89 | -}; | ||
90 | - | ||
91 | static const ARMCPUInfo aarch64_cpus[] = { | ||
92 | { .name = "cortex-a57", .initfn = aarch64_a57_initfn }, | ||
93 | { .name = "cortex-a53", .initfn = aarch64_a53_initfn }, | ||
94 | @@ -XXX,XX +XXX,XX @@ static void cpu_register_class_init(ObjectClass *oc, void *data) | ||
95 | acc->info = data; | ||
96 | } | ||
97 | |||
98 | -static void aarch64_cpu_register(const ARMCPUInfo *info) | ||
99 | +void aarch64_cpu_register(const ARMCPUInfo *info) | ||
100 | { | ||
101 | TypeInfo type_info = { | ||
102 | .parent = TYPE_AARCH64_CPU, | ||
103 | -- | 178 | -- |
104 | 2.20.1 | 179 | 2.25.1 |
105 | |||
106 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | We will move this code in the next commit. Clean it up | 3 | Simplify freeing cp_regs hash table entries by using a single |
4 | first to avoid checkpatch.pl errors. | 4 | allocation for the entire value. |
5 | 5 | ||
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 6 | This fixes a theoretical bug if we were to ever free the entire |
7 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | 7 | hash table, because we've been installing string literal constants |
8 | Message-id: 20200423073358.27155-5-philmd@redhat.com | 8 | into the cpreg structure in define_arm_vh_e2h_redirects_aliases. |
9 | However, at present we only free entries created for AArch32 | ||
10 | wildcard cpregs which get overwritten by more specific cpregs, | ||
11 | so this bug is never exposed. | ||
12 | |||
13 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Message-id: 20220501055028.646596-13-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 17 | --- |
11 | target/arm/cpu.c | 9 ++++++--- | 18 | target/arm/cpu.c | 16 +--------------- |
12 | 1 file changed, 6 insertions(+), 3 deletions(-) | 19 | target/arm/helper.c | 10 ++++++++-- |
20 | 2 files changed, 9 insertions(+), 17 deletions(-) | ||
13 | 21 | ||
14 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | 22 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
15 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/cpu.c | 24 | --- a/target/arm/cpu.c |
17 | +++ b/target/arm/cpu.c | 25 | +++ b/target/arm/cpu.c |
18 | @@ -XXX,XX +XXX,XX @@ static bool arm_v7m_cpu_exec_interrupt(CPUState *cs, int interrupt_request) | 26 | @@ -XXX,XX +XXX,XX @@ uint64_t arm_cpu_mp_affinity(int idx, uint8_t clustersz) |
19 | CPUARMState *env = &cpu->env; | 27 | return (Aff1 << ARM_AFF1_SHIFT) | Aff0; |
20 | bool ret = false; | 28 | } |
21 | 29 | ||
22 | - /* ARMv7-M interrupt masking works differently than -A or -R. | 30 | -static void cpreg_hashtable_data_destroy(gpointer data) |
23 | + /* | 31 | -{ |
24 | + * ARMv7-M interrupt masking works differently than -A or -R. | 32 | - /* |
25 | * There is no FIQ/IRQ distinction. Instead of I and F bits | 33 | - * Destroy function for cpu->cp_regs hashtable data entries. |
26 | * masking FIQ and IRQ interrupts, an exception is taken only | 34 | - * We must free the name string because it was g_strdup()ed in |
27 | * if it is higher priority than the current execution priority | 35 | - * add_cpreg_to_hashtable(). It's OK to cast away the 'const' |
28 | @@ -XXX,XX +XXX,XX @@ static void arm1026_initfn(Object *obj) | 36 | - * from r->name because we know we definitely allocated it. |
29 | static void arm1136_r2_initfn(Object *obj) | 37 | - */ |
38 | - ARMCPRegInfo *r = data; | ||
39 | - | ||
40 | - g_free((void *)r->name); | ||
41 | - g_free(r); | ||
42 | -} | ||
43 | - | ||
44 | static void arm_cpu_initfn(Object *obj) | ||
30 | { | 45 | { |
31 | ARMCPU *cpu = ARM_CPU(obj); | 46 | ARMCPU *cpu = ARM_CPU(obj); |
32 | - /* What qemu calls "arm1136_r2" is actually the 1136 r0p2, ie an | 47 | |
33 | + /* | 48 | cpu_set_cpustate_pointers(cpu); |
34 | + * What qemu calls "arm1136_r2" is actually the 1136 r0p2, ie an | 49 | cpu->cp_regs = g_hash_table_new_full(g_direct_hash, g_direct_equal, |
35 | * older core than plain "arm1136". In particular this does not | 50 | - NULL, cpreg_hashtable_data_destroy); |
36 | * have the v6K features. | 51 | + NULL, g_free); |
37 | * These ID register values are correct for 1136 but may be wrong | 52 | |
38 | @@ -XXX,XX +XXX,XX @@ static const ARMCPUInfo arm_cpus[] = { | 53 | QLIST_INIT(&cpu->pre_el_change_hooks); |
39 | { .name = "arm926", .initfn = arm926_initfn }, | 54 | QLIST_INIT(&cpu->el_change_hooks); |
40 | { .name = "arm946", .initfn = arm946_initfn }, | 55 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
41 | { .name = "arm1026", .initfn = arm1026_initfn }, | 56 | index XXXXXXX..XXXXXXX 100644 |
42 | - /* What QEMU calls "arm1136-r2" is actually the 1136 r0p2, i.e. an | 57 | --- a/target/arm/helper.c |
43 | + /* | 58 | +++ b/target/arm/helper.c |
44 | + * What QEMU calls "arm1136-r2" is actually the 1136 r0p2, i.e. an | 59 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
45 | * older core than plain "arm1136". In particular this does not | 60 | * add a single reginfo struct to the hash table. |
46 | * have the v6K features. | 61 | */ |
62 | uint32_t key; | ||
63 | - ARMCPRegInfo *r2 = g_memdup(r, sizeof(ARMCPRegInfo)); | ||
64 | + ARMCPRegInfo *r2; | ||
65 | int is64 = (r->type & ARM_CP_64BIT) ? 1 : 0; | ||
66 | int ns = (secstate & ARM_CP_SECSTATE_NS) ? 1 : 0; | ||
67 | + size_t name_len; | ||
68 | + | ||
69 | + /* Combine cpreg and name into one allocation. */ | ||
70 | + name_len = strlen(name) + 1; | ||
71 | + r2 = g_malloc(sizeof(*r2) + name_len); | ||
72 | + *r2 = *r; | ||
73 | + r2->name = memcpy(r2 + 1, name, name_len); | ||
74 | |||
75 | - r2->name = g_strdup(name); | ||
76 | /* Reset the secure state to the specific incoming state. This is | ||
77 | * necessary as the register may have been defined with both states. | ||
47 | */ | 78 | */ |
48 | -- | 79 | -- |
49 | 2.20.1 | 80 | 2.25.1 |
50 | |||
51 | diff view generated by jsdifflib |
1 | From: Jerome Forissier <jerome@forissier.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The /secure-chosen node is currently used only by create_uart(), but | 3 | Move the computation of key to the top of the function. |
4 | this will change. Therefore move the creation of this node to | 4 | Hoist the resolution of cp as well, as an input to the |
5 | create_fdt(). | 5 | computation of key. |
6 | 6 | ||
7 | Signed-off-by: Jerome Forissier <jerome@forissier.org> | 7 | This will be required by a subsequent patch. |
8 | Message-id: 20200420121807.8204-2-jerome@forissier.org | 8 | |
9 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Message-id: 20220501055028.646596-14-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 13 | --- |
12 | hw/arm/virt.c | 5 ++++- | 14 | target/arm/helper.c | 49 +++++++++++++++++++++++++-------------------- |
13 | 1 file changed, 4 insertions(+), 1 deletion(-) | 15 | 1 file changed, 27 insertions(+), 22 deletions(-) |
14 | 16 | ||
15 | diff --git a/hw/arm/virt.c b/hw/arm/virt.c | 17 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
16 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/arm/virt.c | 19 | --- a/target/arm/helper.c |
18 | +++ b/hw/arm/virt.c | 20 | +++ b/target/arm/helper.c |
19 | @@ -XXX,XX +XXX,XX @@ static void create_fdt(VirtMachineState *vms) | 21 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
20 | /* /chosen must exist for load_dtb to fill in necessary properties later */ | 22 | ARMCPRegInfo *r2; |
21 | qemu_fdt_add_subnode(fdt, "/chosen"); | 23 | int is64 = (r->type & ARM_CP_64BIT) ? 1 : 0; |
22 | 24 | int ns = (secstate & ARM_CP_SECSTATE_NS) ? 1 : 0; | |
23 | + if (vms->secure) { | 25 | + int cp = r->cp; |
24 | + qemu_fdt_add_subnode(fdt, "/secure-chosen"); | 26 | size_t name_len; |
27 | |||
28 | + switch (state) { | ||
29 | + case ARM_CP_STATE_AA32: | ||
30 | + /* We assume it is a cp15 register if the .cp field is left unset. */ | ||
31 | + if (cp == 0 && r->state == ARM_CP_STATE_BOTH) { | ||
32 | + cp = 15; | ||
33 | + } | ||
34 | + key = ENCODE_CP_REG(cp, is64, ns, r->crn, crm, opc1, opc2); | ||
35 | + break; | ||
36 | + case ARM_CP_STATE_AA64: | ||
37 | + /* | ||
38 | + * To allow abbreviation of ARMCPRegInfo definitions, we treat | ||
39 | + * cp == 0 as equivalent to the value for "standard guest-visible | ||
40 | + * sysreg". STATE_BOTH definitions are also always "standard sysreg" | ||
41 | + * in their AArch64 view (the .cp value may be non-zero for the | ||
42 | + * benefit of the AArch32 view). | ||
43 | + */ | ||
44 | + if (cp == 0 || r->state == ARM_CP_STATE_BOTH) { | ||
45 | + cp = CP_REG_ARM64_SYSREG_CP; | ||
46 | + } | ||
47 | + key = ENCODE_AA64_CP_REG(cp, r->crn, crm, r->opc0, opc1, opc2); | ||
48 | + break; | ||
49 | + default: | ||
50 | + g_assert_not_reached(); | ||
25 | + } | 51 | + } |
26 | + | 52 | + |
27 | /* Clock node, for the benefit of the UART. The kernel device tree | 53 | /* Combine cpreg and name into one allocation. */ |
28 | * binding documentation claims the PL011 node clock properties are | 54 | name_len = strlen(name) + 1; |
29 | * optional but in practice if you omit them the kernel refuses to | 55 | r2 = g_malloc(sizeof(*r2) + name_len); |
30 | @@ -XXX,XX +XXX,XX @@ static void create_uart(const VirtMachineState *vms, int uart, | 56 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
31 | qemu_fdt_setprop_string(vms->fdt, nodename, "status", "disabled"); | 57 | } |
32 | qemu_fdt_setprop_string(vms->fdt, nodename, "secure-status", "okay"); | 58 | |
33 | 59 | if (r->state == ARM_CP_STATE_BOTH) { | |
34 | - qemu_fdt_add_subnode(vms->fdt, "/secure-chosen"); | 60 | - /* We assume it is a cp15 register if the .cp field is left unset. |
35 | qemu_fdt_setprop_string(vms->fdt, "/secure-chosen", "stdout-path", | 61 | - */ |
36 | nodename); | 62 | - if (r2->cp == 0) { |
63 | - r2->cp = 15; | ||
64 | - } | ||
65 | - | ||
66 | #if HOST_BIG_ENDIAN | ||
67 | if (r2->fieldoffset) { | ||
68 | r2->fieldoffset += sizeof(uint32_t); | ||
69 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
70 | #endif | ||
71 | } | ||
37 | } | 72 | } |
73 | - if (state == ARM_CP_STATE_AA64) { | ||
74 | - /* To allow abbreviation of ARMCPRegInfo | ||
75 | - * definitions, we treat cp == 0 as equivalent to | ||
76 | - * the value for "standard guest-visible sysreg". | ||
77 | - * STATE_BOTH definitions are also always "standard | ||
78 | - * sysreg" in their AArch64 view (the .cp value may | ||
79 | - * be non-zero for the benefit of the AArch32 view). | ||
80 | - */ | ||
81 | - if (r->cp == 0 || r->state == ARM_CP_STATE_BOTH) { | ||
82 | - r2->cp = CP_REG_ARM64_SYSREG_CP; | ||
83 | - } | ||
84 | - key = ENCODE_AA64_CP_REG(r2->cp, r2->crn, crm, | ||
85 | - r2->opc0, opc1, opc2); | ||
86 | - } else { | ||
87 | - key = ENCODE_CP_REG(r2->cp, is64, ns, r2->crn, crm, opc1, opc2); | ||
88 | - } | ||
89 | if (opaque) { | ||
90 | r2->opaque = opaque; | ||
91 | } | ||
92 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
93 | /* Make sure reginfo passed to helpers for wildcarded regs | ||
94 | * has the correct crm/opc1/opc2 for this reg, not CP_ANY: | ||
95 | */ | ||
96 | + r2->cp = cp; | ||
97 | r2->crm = crm; | ||
98 | r2->opc1 = opc1; | ||
99 | r2->opc2 = opc2; | ||
38 | -- | 100 | -- |
39 | 2.20.1 | 101 | 2.25.1 |
40 | |||
41 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | This prints the clocks attached to a DeviceState when using | 3 | Put most of the value writeback to the same place, |
4 | "info qtree" monitor command. For every clock, it displays the | 4 | and improve the comment that goes with them. |
5 | direction, the name and if the clock is forwarded. For input clock, | ||
6 | it displays also the frequency. | ||
7 | 5 | ||
8 | This is based on the original work of Frederic Konrad. | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
9 | |||
10 | Here follows a sample of `info qtree` output on xilinx_zynq machine | ||
11 | after linux boot with only one uart clocked: | ||
12 | > bus: main-system-bus | ||
13 | > type System | ||
14 | > [...] | ||
15 | > dev: cadence_uart, id "" | ||
16 | > gpio-out "sysbus-irq" 1 | ||
17 | > clock-in "refclk" freq_hz=0.000000e+00 | ||
18 | > chardev = "" | ||
19 | > mmio 00000000e0001000/0000000000001000 | ||
20 | > dev: cadence_uart, id "" | ||
21 | > gpio-out "sysbus-irq" 1 | ||
22 | > clock-in "refclk" freq_hz=1.375661e+07 | ||
23 | > chardev = "serial0" | ||
24 | > mmio 00000000e0000000/0000000000001000 | ||
25 | > [...] | ||
26 | > dev: xilinx,zynq_slcr, id "" | ||
27 | > clock-out "uart1_ref_clk" freq_hz=0.000000e+00 | ||
28 | > clock-out "uart0_ref_clk" freq_hz=1.375661e+07 | ||
29 | > clock-in "ps_clk" freq_hz=3.333333e+07 | ||
30 | > mmio 00000000f8000000/0000000000001000 | ||
31 | |||
32 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
33 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
34 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
35 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | Message-id: 20220501055028.646596-15-richard.henderson@linaro.org |
36 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
37 | Message-id: 20200406135251.157596-10-damien.hedde@greensocs.com | ||
38 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
39 | --- | 10 | --- |
40 | qdev-monitor.c | 9 +++++++++ | 11 | target/arm/helper.c | 28 ++++++++++++---------------- |
41 | 1 file changed, 9 insertions(+) | 12 | 1 file changed, 12 insertions(+), 16 deletions(-) |
42 | 13 | ||
43 | diff --git a/qdev-monitor.c b/qdev-monitor.c | 14 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
44 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
45 | --- a/qdev-monitor.c | 16 | --- a/target/arm/helper.c |
46 | +++ b/qdev-monitor.c | 17 | +++ b/target/arm/helper.c |
47 | @@ -XXX,XX +XXX,XX @@ | 18 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
48 | #include "migration/misc.h" | 19 | *r2 = *r; |
49 | #include "migration/migration.h" | 20 | r2->name = memcpy(r2 + 1, name, name_len); |
50 | #include "qemu/cutils.h" | 21 | |
51 | +#include "hw/clock.h" | 22 | - /* Reset the secure state to the specific incoming state. This is |
52 | 23 | - * necessary as the register may have been defined with both states. | |
53 | /* | 24 | + /* |
54 | * Aliases were a bad idea from the start. Let's keep them | 25 | + * Update fields to match the instantiation, overwiting wildcards |
55 | @@ -XXX,XX +XXX,XX @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) | 26 | + * such as CP_ANY, ARM_CP_STATE_BOTH, or ARM_CP_SECSTATE_BOTH. |
56 | ObjectClass *class; | 27 | */ |
57 | BusState *child; | 28 | + r2->cp = cp; |
58 | NamedGPIOList *ngl; | 29 | + r2->crm = crm; |
59 | + NamedClockList *ncl; | 30 | + r2->opc1 = opc1; |
60 | 31 | + r2->opc2 = opc2; | |
61 | qdev_printf("dev: %s, id \"%s\"\n", object_get_typename(OBJECT(dev)), | 32 | + r2->state = state; |
62 | dev->id ? dev->id : ""); | 33 | r2->secure = secstate; |
63 | @@ -XXX,XX +XXX,XX @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) | 34 | + if (opaque) { |
64 | ngl->num_out); | 35 | + r2->opaque = opaque; |
36 | + } | ||
37 | |||
38 | if (r->bank_fieldoffsets[0] && r->bank_fieldoffsets[1]) { | ||
39 | /* Register is banked (using both entries in array). | ||
40 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
41 | #endif | ||
65 | } | 42 | } |
66 | } | 43 | } |
67 | + QLIST_FOREACH(ncl, &dev->clocks, node) { | 44 | - if (opaque) { |
68 | + qdev_printf("clock-%s%s \"%s\" freq_hz=%e\n", | 45 | - r2->opaque = opaque; |
69 | + ncl->output ? "out" : "in", | 46 | - } |
70 | + ncl->alias ? " (alias)" : "", | 47 | - /* reginfo passed to helpers is correct for the actual access, |
71 | + ncl->name, | 48 | - * and is never ARM_CP_STATE_BOTH: |
72 | + CLOCK_PERIOD_TO_HZ(1.0 * clock_get(ncl->clock))); | 49 | - */ |
73 | + } | 50 | - r2->state = state; |
74 | class = object_get_class(OBJECT(dev)); | 51 | - /* Make sure reginfo passed to helpers for wildcarded regs |
75 | do { | 52 | - * has the correct crm/opc1/opc2 for this reg, not CP_ANY: |
76 | qdev_print_props(mon, dev, DEVICE_CLASS(class)->props_, indent); | 53 | - */ |
54 | - r2->cp = cp; | ||
55 | - r2->crm = crm; | ||
56 | - r2->opc1 = opc1; | ||
57 | - r2->opc2 = opc2; | ||
58 | + | ||
59 | /* By convention, for wildcarded registers only the first | ||
60 | * entry is used for migration; the others are marked as | ||
61 | * ALIAS so we don't try to transfer the register | ||
77 | -- | 62 | -- |
78 | 2.20.1 | 63 | 2.25.1 |
79 | |||
80 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Under KVM these registers are written by the hardware. | 3 | Bool is a more appropriate type for these variables. |
4 | Restrict the writefn handlers to TCG to avoid when building | ||
5 | without TCG: | ||
6 | 4 | ||
7 | LINK aarch64-softmmu/qemu-system-aarch64 | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | target/arm/helper.o: In function `do_ats_write': | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | target/arm/helper.c:3524: undefined reference to `raise_exception' | 7 | Message-id: 20220501055028.646596-16-richard.henderson@linaro.org |
10 | |||
11 | Suggested-by: Richard Henderson <richard.henderson@linaro.org> | ||
12 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
13 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
14 | Message-id: 20200423073358.27155-2-philmd@redhat.com | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
16 | --- | 9 | --- |
17 | target/arm/helper.c | 17 +++++++++++++++++ | 10 | target/arm/helper.c | 4 ++-- |
18 | 1 file changed, 17 insertions(+) | 11 | 1 file changed, 2 insertions(+), 2 deletions(-) |
19 | 12 | ||
20 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 13 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
21 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
22 | --- a/target/arm/helper.c | 15 | --- a/target/arm/helper.c |
23 | +++ b/target/arm/helper.c | 16 | +++ b/target/arm/helper.c |
24 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult ats_access(CPUARMState *env, const ARMCPRegInfo *ri, | 17 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
25 | return CP_ACCESS_OK; | 18 | */ |
26 | } | 19 | uint32_t key; |
27 | 20 | ARMCPRegInfo *r2; | |
28 | +#ifdef CONFIG_TCG | 21 | - int is64 = (r->type & ARM_CP_64BIT) ? 1 : 0; |
29 | static uint64_t do_ats_write(CPUARMState *env, uint64_t value, | 22 | - int ns = (secstate & ARM_CP_SECSTATE_NS) ? 1 : 0; |
30 | MMUAccessType access_type, ARMMMUIdx mmu_idx) | 23 | + bool is64 = r->type & ARM_CP_64BIT; |
31 | { | 24 | + bool ns = secstate & ARM_CP_SECSTATE_NS; |
32 | @@ -XXX,XX +XXX,XX @@ static uint64_t do_ats_write(CPUARMState *env, uint64_t value, | 25 | int cp = r->cp; |
33 | } | 26 | size_t name_len; |
34 | return par64; | ||
35 | } | ||
36 | +#endif /* CONFIG_TCG */ | ||
37 | |||
38 | static void ats_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) | ||
39 | { | ||
40 | +#ifdef CONFIG_TCG | ||
41 | MMUAccessType access_type = ri->opc2 & 1 ? MMU_DATA_STORE : MMU_DATA_LOAD; | ||
42 | uint64_t par64; | ||
43 | ARMMMUIdx mmu_idx; | ||
44 | @@ -XXX,XX +XXX,XX @@ static void ats_write(CPUARMState *env, const ARMCPRegInfo *ri, uint64_t value) | ||
45 | par64 = do_ats_write(env, value, access_type, mmu_idx); | ||
46 | |||
47 | A32_BANKED_CURRENT_REG_SET(env, par, par64); | ||
48 | +#else | ||
49 | + /* Handled by hardware accelerator. */ | ||
50 | + g_assert_not_reached(); | ||
51 | +#endif /* CONFIG_TCG */ | ||
52 | } | ||
53 | |||
54 | static void ats1h_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
55 | uint64_t value) | ||
56 | { | ||
57 | +#ifdef CONFIG_TCG | ||
58 | MMUAccessType access_type = ri->opc2 & 1 ? MMU_DATA_STORE : MMU_DATA_LOAD; | ||
59 | uint64_t par64; | ||
60 | |||
61 | par64 = do_ats_write(env, value, access_type, ARMMMUIdx_E2); | ||
62 | |||
63 | A32_BANKED_CURRENT_REG_SET(env, par, par64); | ||
64 | +#else | ||
65 | + /* Handled by hardware accelerator. */ | ||
66 | + g_assert_not_reached(); | ||
67 | +#endif /* CONFIG_TCG */ | ||
68 | } | ||
69 | |||
70 | static CPAccessResult at_s1e2_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
71 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult at_s1e2_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
72 | static void ats_write64(CPUARMState *env, const ARMCPRegInfo *ri, | ||
73 | uint64_t value) | ||
74 | { | ||
75 | +#ifdef CONFIG_TCG | ||
76 | MMUAccessType access_type = ri->opc2 & 1 ? MMU_DATA_STORE : MMU_DATA_LOAD; | ||
77 | ARMMMUIdx mmu_idx; | ||
78 | int secure = arm_is_secure_below_el3(env); | ||
79 | @@ -XXX,XX +XXX,XX @@ static void ats_write64(CPUARMState *env, const ARMCPRegInfo *ri, | ||
80 | } | ||
81 | |||
82 | env->cp15.par_el[1] = do_ats_write(env, value, access_type, mmu_idx); | ||
83 | +#else | ||
84 | + /* Handled by hardware accelerator. */ | ||
85 | + g_assert_not_reached(); | ||
86 | +#endif /* CONFIG_TCG */ | ||
87 | } | ||
88 | #endif | ||
89 | 27 | ||
90 | -- | 28 | -- |
91 | 2.20.1 | 29 | 2.25.1 |
92 | |||
93 | diff view generated by jsdifflib |
1 | From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Fix descriptor loading from registers wrt host endianness. | 3 | Computing isbanked only once makes the code |
4 | a bit easier to read. | ||
4 | 5 | ||
5 | Reported-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com> | 8 | Message-id: 20220501055028.646596-17-richard.henderson@linaro.org |
8 | Message-id: 20200404122718.25111-3-edgar.iglesias@gmail.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 10 | --- |
11 | hw/dma/xlnx-zdma.c | 14 ++++++++++---- | 11 | target/arm/helper.c | 6 ++++-- |
12 | 1 file changed, 10 insertions(+), 4 deletions(-) | 12 | 1 file changed, 4 insertions(+), 2 deletions(-) |
13 | 13 | ||
14 | diff --git a/hw/dma/xlnx-zdma.c b/hw/dma/xlnx-zdma.c | 14 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
15 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/dma/xlnx-zdma.c | 16 | --- a/target/arm/helper.c |
17 | +++ b/hw/dma/xlnx-zdma.c | 17 | +++ b/target/arm/helper.c |
18 | @@ -XXX,XX +XXX,XX @@ static void zdma_put_regaddr64(XlnxZDMA *s, unsigned int basereg, uint64_t addr) | 18 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
19 | s->regs[basereg + 1] = addr >> 32; | 19 | bool is64 = r->type & ARM_CP_64BIT; |
20 | } | 20 | bool ns = secstate & ARM_CP_SECSTATE_NS; |
21 | 21 | int cp = r->cp; | |
22 | +static void zdma_load_descriptor_reg(XlnxZDMA *s, unsigned int reg, | 22 | + bool isbanked; |
23 | + XlnxZDMADescr *descr) | 23 | size_t name_len; |
24 | +{ | 24 | |
25 | + descr->addr = zdma_get_regaddr64(s, reg); | 25 | switch (state) { |
26 | + descr->size = s->regs[reg + 2]; | 26 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
27 | + descr->attr = s->regs[reg + 3]; | 27 | r2->opaque = opaque; |
28 | +} | ||
29 | + | ||
30 | static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr, | ||
31 | XlnxZDMADescr *descr) | ||
32 | { | ||
33 | @@ -XXX,XX +XXX,XX @@ static void zdma_load_src_descriptor(XlnxZDMA *s) | ||
34 | unsigned int ptype = ARRAY_FIELD_EX32(s->regs, ZDMA_CH_CTRL0, POINT_TYPE); | ||
35 | |||
36 | if (ptype == PT_REG) { | ||
37 | - memcpy(&s->dsc_src, &s->regs[R_ZDMA_CH_SRC_DSCR_WORD0], | ||
38 | - sizeof(s->dsc_src)); | ||
39 | + zdma_load_descriptor_reg(s, R_ZDMA_CH_SRC_DSCR_WORD0, &s->dsc_src); | ||
40 | return; | ||
41 | } | 28 | } |
42 | 29 | ||
43 | @@ -XXX,XX +XXX,XX @@ static void zdma_load_dst_descriptor(XlnxZDMA *s) | 30 | - if (r->bank_fieldoffsets[0] && r->bank_fieldoffsets[1]) { |
44 | bool dst_type; | 31 | + isbanked = r->bank_fieldoffsets[0] && r->bank_fieldoffsets[1]; |
45 | 32 | + if (isbanked) { | |
46 | if (ptype == PT_REG) { | 33 | /* Register is banked (using both entries in array). |
47 | - memcpy(&s->dsc_dst, &s->regs[R_ZDMA_CH_DST_DSCR_WORD0], | 34 | * Overwriting fieldoffset as the array is only used to define |
48 | - sizeof(s->dsc_dst)); | 35 | * banked registers but later only fieldoffset is used. |
49 | + zdma_load_descriptor_reg(s, R_ZDMA_CH_DST_DSCR_WORD0, &s->dsc_dst); | 36 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
50 | return; | ||
51 | } | 37 | } |
52 | 38 | ||
39 | if (state == ARM_CP_STATE_AA32) { | ||
40 | - if (r->bank_fieldoffsets[0] && r->bank_fieldoffsets[1]) { | ||
41 | + if (isbanked) { | ||
42 | /* If the register is banked then we don't need to migrate or | ||
43 | * reset the 32-bit instance in certain cases: | ||
44 | * | ||
53 | -- | 45 | -- |
54 | 2.20.1 | 46 | 2.25.1 |
55 | |||
56 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add functions to easily handle clocks with devices. | 3 | Perform the override check early, so that it is still done |
4 | Clock inputs and outputs should be used to handle clock propagation | 4 | even when we decide to discard an unreachable cpreg. |
5 | between devices. | ||
6 | The API is very similar the GPIO API. | ||
7 | 5 | ||
8 | This is based on the original work of Frederic Konrad. | 6 | Use assert not printf+abort. |
9 | 7 | ||
10 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
11 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
12 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 10 | Message-id: 20220501055028.646596-18-richard.henderson@linaro.org |
13 | Message-id: 20200406135251.157596-4-damien.hedde@greensocs.com | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | --- | 12 | --- |
16 | hw/core/Makefile.objs | 2 +- | 13 | target/arm/helper.c | 22 ++++++++-------------- |
17 | tests/Makefile.include | 1 + | 14 | 1 file changed, 8 insertions(+), 14 deletions(-) |
18 | include/hw/qdev-clock.h | 104 +++++++++++++++++++++++++ | ||
19 | include/hw/qdev-core.h | 12 +++ | ||
20 | hw/core/qdev-clock.c | 168 ++++++++++++++++++++++++++++++++++++++++ | ||
21 | hw/core/qdev.c | 12 +++ | ||
22 | 6 files changed, 298 insertions(+), 1 deletion(-) | ||
23 | create mode 100644 include/hw/qdev-clock.h | ||
24 | create mode 100644 hw/core/qdev-clock.c | ||
25 | 15 | ||
26 | diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs | 16 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
27 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/hw/core/Makefile.objs | 18 | --- a/target/arm/helper.c |
29 | +++ b/hw/core/Makefile.objs | 19 | +++ b/target/arm/helper.c |
30 | @@ -XXX,XX +XXX,XX @@ common-obj-y += hotplug.o | 20 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
31 | common-obj-y += vmstate-if.o | 21 | g_assert_not_reached(); |
32 | # irq.o needed for qdev GPIO handling: | 22 | } |
33 | common-obj-y += irq.o | 23 | |
34 | -common-obj-y += clock.o | 24 | + /* Overriding of an existing definition must be explicitly requested. */ |
35 | +common-obj-y += clock.o qdev-clock.o | 25 | + if (!(r->type & ARM_CP_OVERRIDE)) { |
36 | 26 | + const ARMCPRegInfo *oldreg = get_arm_cp_reginfo(cpu->cp_regs, key); | |
37 | common-obj-$(CONFIG_SOFTMMU) += reset.o | 27 | + if (oldreg) { |
38 | common-obj-$(CONFIG_SOFTMMU) += qdev-fw.o | 28 | + assert(oldreg->type & ARM_CP_OVERRIDE); |
39 | diff --git a/tests/Makefile.include b/tests/Makefile.include | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/tests/Makefile.include | ||
42 | +++ b/tests/Makefile.include | ||
43 | @@ -XXX,XX +XXX,XX @@ tests/test-qdev-global-props$(EXESUF): tests/test-qdev-global-props.o \ | ||
44 | hw/core/fw-path-provider.o \ | ||
45 | hw/core/reset.o \ | ||
46 | hw/core/vmstate-if.o \ | ||
47 | + hw/core/clock.o hw/core/qdev-clock.o \ | ||
48 | $(test-qapi-obj-y) | ||
49 | tests/test-vmstate$(EXESUF): tests/test-vmstate.o \ | ||
50 | migration/vmstate.o migration/vmstate-types.o migration/qemu-file.o \ | ||
51 | diff --git a/include/hw/qdev-clock.h b/include/hw/qdev-clock.h | ||
52 | new file mode 100644 | ||
53 | index XXXXXXX..XXXXXXX | ||
54 | --- /dev/null | ||
55 | +++ b/include/hw/qdev-clock.h | ||
56 | @@ -XXX,XX +XXX,XX @@ | ||
57 | +/* | ||
58 | + * Device's clock input and output | ||
59 | + * | ||
60 | + * Copyright GreenSocs 2016-2020 | ||
61 | + * | ||
62 | + * Authors: | ||
63 | + * Frederic Konrad | ||
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 | + */ | ||
69 | + | ||
70 | +#ifndef QDEV_CLOCK_H | ||
71 | +#define QDEV_CLOCK_H | ||
72 | + | ||
73 | +#include "hw/clock.h" | ||
74 | + | ||
75 | +/** | ||
76 | + * qdev_init_clock_in: | ||
77 | + * @dev: the device to add an input clock to | ||
78 | + * @name: the name of the clock (can't be NULL). | ||
79 | + * @callback: optional callback to be called on update or NULL. | ||
80 | + * @opaque: argument for the callback | ||
81 | + * @returns: a pointer to the newly added clock | ||
82 | + * | ||
83 | + * Add an input clock to device @dev as a clock named @name. | ||
84 | + * This adds a child<> property. | ||
85 | + * The callback will be called with @opaque as opaque parameter. | ||
86 | + */ | ||
87 | +Clock *qdev_init_clock_in(DeviceState *dev, const char *name, | ||
88 | + ClockCallback *callback, void *opaque); | ||
89 | + | ||
90 | +/** | ||
91 | + * qdev_init_clock_out: | ||
92 | + * @dev: the device to add an output clock to | ||
93 | + * @name: the name of the clock (can't be NULL). | ||
94 | + * @returns: a pointer to the newly added clock | ||
95 | + * | ||
96 | + * Add an output clock to device @dev as a clock named @name. | ||
97 | + * This adds a child<> property. | ||
98 | + */ | ||
99 | +Clock *qdev_init_clock_out(DeviceState *dev, const char *name); | ||
100 | + | ||
101 | +/** | ||
102 | + * qdev_get_clock_in: | ||
103 | + * @dev: the device which has the clock | ||
104 | + * @name: the name of the clock (can't be NULL). | ||
105 | + * @returns: a pointer to the clock | ||
106 | + * | ||
107 | + * Get the input clock @name from @dev or NULL if does not exist. | ||
108 | + */ | ||
109 | +Clock *qdev_get_clock_in(DeviceState *dev, const char *name); | ||
110 | + | ||
111 | +/** | ||
112 | + * qdev_get_clock_out: | ||
113 | + * @dev: the device which has the clock | ||
114 | + * @name: the name of the clock (can't be NULL). | ||
115 | + * @returns: a pointer to the clock | ||
116 | + * | ||
117 | + * Get the output clock @name from @dev or NULL if does not exist. | ||
118 | + */ | ||
119 | +Clock *qdev_get_clock_out(DeviceState *dev, const char *name); | ||
120 | + | ||
121 | +/** | ||
122 | + * qdev_connect_clock_in: | ||
123 | + * @dev: a device | ||
124 | + * @name: the name of an input clock in @dev | ||
125 | + * @source: the source clock (an output clock of another device for example) | ||
126 | + * | ||
127 | + * Set the source clock of input clock @name of device @dev to @source. | ||
128 | + * @source period update will be propagated to @name clock. | ||
129 | + */ | ||
130 | +static inline void qdev_connect_clock_in(DeviceState *dev, const char *name, | ||
131 | + Clock *source) | ||
132 | +{ | ||
133 | + clock_set_source(qdev_get_clock_in(dev, name), source); | ||
134 | +} | ||
135 | + | ||
136 | +/** | ||
137 | + * qdev_alias_clock: | ||
138 | + * @dev: the device which has the clock | ||
139 | + * @name: the name of the clock in @dev (can't be NULL) | ||
140 | + * @alias_dev: the device to add the clock | ||
141 | + * @alias_name: the name of the clock in @container | ||
142 | + * @returns: a pointer to the clock | ||
143 | + * | ||
144 | + * Add a clock @alias_name in @alias_dev which is an alias of the clock @name | ||
145 | + * in @dev. The direction _in_ or _out_ will the same as the original. | ||
146 | + * An alias clock must not be modified or used by @alias_dev and should | ||
147 | + * typically be only only for device composition purpose. | ||
148 | + */ | ||
149 | +Clock *qdev_alias_clock(DeviceState *dev, const char *name, | ||
150 | + DeviceState *alias_dev, const char *alias_name); | ||
151 | + | ||
152 | +/** | ||
153 | + * qdev_finalize_clocklist: | ||
154 | + * @dev: the device being finalized | ||
155 | + * | ||
156 | + * Clear the clocklist from @dev. Only used internally in qdev. | ||
157 | + */ | ||
158 | +void qdev_finalize_clocklist(DeviceState *dev); | ||
159 | + | ||
160 | +#endif /* QDEV_CLOCK_H */ | ||
161 | diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h | ||
162 | index XXXXXXX..XXXXXXX 100644 | ||
163 | --- a/include/hw/qdev-core.h | ||
164 | +++ b/include/hw/qdev-core.h | ||
165 | @@ -XXX,XX +XXX,XX @@ struct NamedGPIOList { | ||
166 | QLIST_ENTRY(NamedGPIOList) node; | ||
167 | }; | ||
168 | |||
169 | +typedef struct Clock Clock; | ||
170 | +typedef struct NamedClockList NamedClockList; | ||
171 | + | ||
172 | +struct NamedClockList { | ||
173 | + char *name; | ||
174 | + Clock *clock; | ||
175 | + bool output; | ||
176 | + bool alias; | ||
177 | + QLIST_ENTRY(NamedClockList) node; | ||
178 | +}; | ||
179 | + | ||
180 | /** | ||
181 | * DeviceState: | ||
182 | * @realized: Indicates whether the device has been fully constructed. | ||
183 | @@ -XXX,XX +XXX,XX @@ struct DeviceState { | ||
184 | bool allow_unplug_during_migration; | ||
185 | BusState *parent_bus; | ||
186 | QLIST_HEAD(, NamedGPIOList) gpios; | ||
187 | + QLIST_HEAD(, NamedClockList) clocks; | ||
188 | QLIST_HEAD(, BusState) child_bus; | ||
189 | int num_child_bus; | ||
190 | int instance_id_alias; | ||
191 | diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c | ||
192 | new file mode 100644 | ||
193 | index XXXXXXX..XXXXXXX | ||
194 | --- /dev/null | ||
195 | +++ b/hw/core/qdev-clock.c | ||
196 | @@ -XXX,XX +XXX,XX @@ | ||
197 | +/* | ||
198 | + * Device's clock input and output | ||
199 | + * | ||
200 | + * Copyright GreenSocs 2016-2020 | ||
201 | + * | ||
202 | + * Authors: | ||
203 | + * Frederic Konrad | ||
204 | + * Damien Hedde | ||
205 | + * | ||
206 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
207 | + * See the COPYING file in the top-level directory. | ||
208 | + */ | ||
209 | + | ||
210 | +#include "qemu/osdep.h" | ||
211 | +#include "hw/qdev-clock.h" | ||
212 | +#include "hw/qdev-core.h" | ||
213 | +#include "qapi/error.h" | ||
214 | + | ||
215 | +/* | ||
216 | + * qdev_init_clocklist: | ||
217 | + * Add a new clock in a device | ||
218 | + */ | ||
219 | +static NamedClockList *qdev_init_clocklist(DeviceState *dev, const char *name, | ||
220 | + bool output, Clock *clk) | ||
221 | +{ | ||
222 | + NamedClockList *ncl; | ||
223 | + | ||
224 | + /* | ||
225 | + * Clock must be added before realize() so that we can compute the | ||
226 | + * clock's canonical path during device_realize(). | ||
227 | + */ | ||
228 | + assert(!dev->realized); | ||
229 | + | ||
230 | + /* | ||
231 | + * The ncl structure is freed by qdev_finalize_clocklist() which will | ||
232 | + * be called during @dev's device_finalize(). | ||
233 | + */ | ||
234 | + ncl = g_new0(NamedClockList, 1); | ||
235 | + ncl->name = g_strdup(name); | ||
236 | + ncl->output = output; | ||
237 | + ncl->alias = (clk != NULL); | ||
238 | + | ||
239 | + /* | ||
240 | + * Trying to create a clock whose name clashes with some other | ||
241 | + * clock or property is a bug in the caller and we will abort(). | ||
242 | + */ | ||
243 | + if (clk == NULL) { | ||
244 | + clk = CLOCK(object_new(TYPE_CLOCK)); | ||
245 | + object_property_add_child(OBJECT(dev), name, OBJECT(clk), &error_abort); | ||
246 | + if (output) { | ||
247 | + /* | ||
248 | + * Remove object_new()'s initial reference. | ||
249 | + * Note that for inputs, the reference created by object_new() | ||
250 | + * will be deleted in qdev_finalize_clocklist(). | ||
251 | + */ | ||
252 | + object_unref(OBJECT(clk)); | ||
253 | + } | ||
254 | + } else { | ||
255 | + object_property_add_link(OBJECT(dev), name, | ||
256 | + object_get_typename(OBJECT(clk)), | ||
257 | + (Object **) &ncl->clock, | ||
258 | + NULL, OBJ_PROP_LINK_STRONG, &error_abort); | ||
259 | + } | ||
260 | + | ||
261 | + ncl->clock = clk; | ||
262 | + | ||
263 | + QLIST_INSERT_HEAD(&dev->clocks, ncl, node); | ||
264 | + return ncl; | ||
265 | +} | ||
266 | + | ||
267 | +void qdev_finalize_clocklist(DeviceState *dev) | ||
268 | +{ | ||
269 | + /* called by @dev's device_finalize() */ | ||
270 | + NamedClockList *ncl, *ncl_next; | ||
271 | + | ||
272 | + QLIST_FOREACH_SAFE(ncl, &dev->clocks, node, ncl_next) { | ||
273 | + QLIST_REMOVE(ncl, node); | ||
274 | + if (!ncl->output && !ncl->alias) { | ||
275 | + /* | ||
276 | + * We kept a reference on the input clock to ensure it lives up to | ||
277 | + * this point so we can safely remove the callback. | ||
278 | + * It avoids having a callback to a deleted object if ncl->clock | ||
279 | + * is still referenced somewhere else (eg: by a clock output). | ||
280 | + */ | ||
281 | + clock_clear_callback(ncl->clock); | ||
282 | + object_unref(OBJECT(ncl->clock)); | ||
283 | + } | ||
284 | + g_free(ncl->name); | ||
285 | + g_free(ncl); | ||
286 | + } | ||
287 | +} | ||
288 | + | ||
289 | +Clock *qdev_init_clock_out(DeviceState *dev, const char *name) | ||
290 | +{ | ||
291 | + NamedClockList *ncl; | ||
292 | + | ||
293 | + assert(name); | ||
294 | + | ||
295 | + ncl = qdev_init_clocklist(dev, name, true, NULL); | ||
296 | + | ||
297 | + return ncl->clock; | ||
298 | +} | ||
299 | + | ||
300 | +Clock *qdev_init_clock_in(DeviceState *dev, const char *name, | ||
301 | + ClockCallback *callback, void *opaque) | ||
302 | +{ | ||
303 | + NamedClockList *ncl; | ||
304 | + | ||
305 | + assert(name); | ||
306 | + | ||
307 | + ncl = qdev_init_clocklist(dev, name, false, NULL); | ||
308 | + | ||
309 | + if (callback) { | ||
310 | + clock_set_callback(ncl->clock, callback, opaque); | ||
311 | + } | ||
312 | + return ncl->clock; | ||
313 | +} | ||
314 | + | ||
315 | +static NamedClockList *qdev_get_clocklist(DeviceState *dev, const char *name) | ||
316 | +{ | ||
317 | + NamedClockList *ncl; | ||
318 | + | ||
319 | + QLIST_FOREACH(ncl, &dev->clocks, node) { | ||
320 | + if (strcmp(name, ncl->name) == 0) { | ||
321 | + return ncl; | ||
322 | + } | 29 | + } |
323 | + } | 30 | + } |
324 | + | 31 | + |
325 | + return NULL; | 32 | /* Combine cpreg and name into one allocation. */ |
326 | +} | 33 | name_len = strlen(name) + 1; |
327 | + | 34 | r2 = g_malloc(sizeof(*r2) + name_len); |
328 | +Clock *qdev_get_clock_in(DeviceState *dev, const char *name) | 35 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
329 | +{ | 36 | assert(!raw_accessors_invalid(r2)); |
330 | + NamedClockList *ncl; | 37 | } |
331 | + | 38 | |
332 | + assert(name); | 39 | - /* Overriding of an existing definition must be explicitly |
333 | + | 40 | - * requested. |
334 | + ncl = qdev_get_clocklist(dev, name); | 41 | - */ |
335 | + assert(!ncl->output); | 42 | - if (!(r->type & ARM_CP_OVERRIDE)) { |
336 | + | 43 | - const ARMCPRegInfo *oldreg = get_arm_cp_reginfo(cpu->cp_regs, key); |
337 | + return ncl->clock; | 44 | - if (oldreg && !(oldreg->type & ARM_CP_OVERRIDE)) { |
338 | +} | 45 | - fprintf(stderr, "Register redefined: cp=%d %d bit " |
339 | + | 46 | - "crn=%d crm=%d opc1=%d opc2=%d, " |
340 | +Clock *qdev_get_clock_out(DeviceState *dev, const char *name) | 47 | - "was %s, now %s\n", r2->cp, 32 + 32 * is64, |
341 | +{ | 48 | - r2->crn, r2->crm, r2->opc1, r2->opc2, |
342 | + NamedClockList *ncl; | 49 | - oldreg->name, r2->name); |
343 | + | 50 | - g_assert_not_reached(); |
344 | + assert(name); | 51 | - } |
345 | + | 52 | - } |
346 | + ncl = qdev_get_clocklist(dev, name); | 53 | g_hash_table_insert(cpu->cp_regs, (gpointer)(uintptr_t)key, r2); |
347 | + assert(ncl->output); | ||
348 | + | ||
349 | + return ncl->clock; | ||
350 | +} | ||
351 | + | ||
352 | +Clock *qdev_alias_clock(DeviceState *dev, const char *name, | ||
353 | + DeviceState *alias_dev, const char *alias_name) | ||
354 | +{ | ||
355 | + NamedClockList *ncl; | ||
356 | + | ||
357 | + assert(name && alias_name); | ||
358 | + | ||
359 | + ncl = qdev_get_clocklist(dev, name); | ||
360 | + | ||
361 | + qdev_init_clocklist(alias_dev, alias_name, ncl->output, ncl->clock); | ||
362 | + | ||
363 | + return ncl->clock; | ||
364 | +} | ||
365 | diff --git a/hw/core/qdev.c b/hw/core/qdev.c | ||
366 | index XXXXXXX..XXXXXXX 100644 | ||
367 | --- a/hw/core/qdev.c | ||
368 | +++ b/hw/core/qdev.c | ||
369 | @@ -XXX,XX +XXX,XX @@ | ||
370 | #include "hw/qdev-properties.h" | ||
371 | #include "hw/boards.h" | ||
372 | #include "hw/sysbus.h" | ||
373 | +#include "hw/qdev-clock.h" | ||
374 | #include "migration/vmstate.h" | ||
375 | #include "trace.h" | ||
376 | |||
377 | @@ -XXX,XX +XXX,XX @@ static void device_set_realized(Object *obj, bool value, Error **errp) | ||
378 | DeviceClass *dc = DEVICE_GET_CLASS(dev); | ||
379 | HotplugHandler *hotplug_ctrl; | ||
380 | BusState *bus; | ||
381 | + NamedClockList *ncl; | ||
382 | Error *local_err = NULL; | ||
383 | bool unattached_parent = false; | ||
384 | static int unattached_count; | ||
385 | @@ -XXX,XX +XXX,XX @@ static void device_set_realized(Object *obj, bool value, Error **errp) | ||
386 | */ | ||
387 | g_free(dev->canonical_path); | ||
388 | dev->canonical_path = object_get_canonical_path(OBJECT(dev)); | ||
389 | + QLIST_FOREACH(ncl, &dev->clocks, node) { | ||
390 | + if (ncl->alias) { | ||
391 | + continue; | ||
392 | + } else { | ||
393 | + clock_setup_canonical_path(ncl->clock); | ||
394 | + } | ||
395 | + } | ||
396 | |||
397 | if (qdev_get_vmsd(dev)) { | ||
398 | if (vmstate_register_with_alias_id(VMSTATE_IF(dev), | ||
399 | @@ -XXX,XX +XXX,XX @@ static void device_initfn(Object *obj) | ||
400 | dev->allow_unplug_during_migration = false; | ||
401 | |||
402 | QLIST_INIT(&dev->gpios); | ||
403 | + QLIST_INIT(&dev->clocks); | ||
404 | } | 54 | } |
405 | 55 | ||
406 | static void device_post_init(Object *obj) | ||
407 | @@ -XXX,XX +XXX,XX @@ static void device_finalize(Object *obj) | ||
408 | */ | ||
409 | } | ||
410 | |||
411 | + qdev_finalize_clocklist(dev); | ||
412 | + | ||
413 | /* Only send event if the device had been completely realized */ | ||
414 | if (dev->pending_deleted_event) { | ||
415 | g_assert(dev->canonical_path); | ||
416 | -- | 56 | -- |
417 | 2.20.1 | 57 | 2.25.1 |
418 | |||
419 | diff view generated by jsdifflib |
1 | From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Fix descriptor loading from memory wrt host endianness. | 3 | Put the block comments into the current coding style. |
4 | 4 | ||
5 | Reported-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Francisco Iglesias <frasse.iglesias@gmail.com> | 7 | Message-id: 20220501055028.646596-19-richard.henderson@linaro.org |
8 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
9 | Message-id: 20200404122718.25111-2-edgar.iglesias@gmail.com | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 9 | --- |
12 | hw/dma/xlnx-zdma.c | 11 +++++++---- | 10 | target/arm/helper.c | 24 +++++++++++++++--------- |
13 | 1 file changed, 7 insertions(+), 4 deletions(-) | 11 | 1 file changed, 15 insertions(+), 9 deletions(-) |
14 | 12 | ||
15 | diff --git a/hw/dma/xlnx-zdma.c b/hw/dma/xlnx-zdma.c | 13 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
16 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/dma/xlnx-zdma.c | 15 | --- a/target/arm/helper.c |
18 | +++ b/hw/dma/xlnx-zdma.c | 16 | +++ b/target/arm/helper.c |
19 | @@ -XXX,XX +XXX,XX @@ static void zdma_put_regaddr64(XlnxZDMA *s, unsigned int basereg, uint64_t addr) | 17 | @@ -XXX,XX +XXX,XX @@ CpuDefinitionInfoList *qmp_query_cpu_definitions(Error **errp) |
20 | s->regs[basereg + 1] = addr >> 32; | 18 | return cpu_list; |
21 | } | 19 | } |
22 | 20 | ||
23 | -static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr, void *buf) | 21 | +/* |
24 | +static bool zdma_load_descriptor(XlnxZDMA *s, uint64_t addr, | 22 | + * Private utility function for define_one_arm_cp_reg_with_opaque(): |
25 | + XlnxZDMADescr *descr) | 23 | + * add a single reginfo struct to the hash table. |
24 | + */ | ||
25 | static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
26 | void *opaque, CPState state, | ||
27 | CPSecureState secstate, | ||
28 | int crm, int opc1, int opc2, | ||
29 | const char *name) | ||
26 | { | 30 | { |
27 | /* ZDMA descriptors must be aligned to their own size. */ | 31 | - /* Private utility function for define_one_arm_cp_reg_with_opaque(): |
28 | if (addr % sizeof(XlnxZDMADescr)) { | 32 | - * add a single reginfo struct to the hash table. |
29 | qemu_log_mask(LOG_GUEST_ERROR, | 33 | - */ |
30 | "zdma: unaligned descriptor at %" PRIx64, | 34 | uint32_t key; |
31 | addr); | 35 | ARMCPRegInfo *r2; |
32 | - memset(buf, 0x0, sizeof(XlnxZDMADescr)); | 36 | bool is64 = r->type & ARM_CP_64BIT; |
33 | + memset(descr, 0x0, sizeof(XlnxZDMADescr)); | 37 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
34 | s->error = true; | 38 | |
35 | return false; | 39 | isbanked = r->bank_fieldoffsets[0] && r->bank_fieldoffsets[1]; |
40 | if (isbanked) { | ||
41 | - /* Register is banked (using both entries in array). | ||
42 | + /* | ||
43 | + * Register is banked (using both entries in array). | ||
44 | * Overwriting fieldoffset as the array is only used to define | ||
45 | * banked registers but later only fieldoffset is used. | ||
46 | */ | ||
47 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
48 | |||
49 | if (state == ARM_CP_STATE_AA32) { | ||
50 | if (isbanked) { | ||
51 | - /* If the register is banked then we don't need to migrate or | ||
52 | + /* | ||
53 | + * If the register is banked then we don't need to migrate or | ||
54 | * reset the 32-bit instance in certain cases: | ||
55 | * | ||
56 | * 1) If the register has both 32-bit and 64-bit instances then we | ||
57 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
58 | r2->type |= ARM_CP_ALIAS; | ||
59 | } | ||
60 | } else if ((secstate != r->secure) && !ns) { | ||
61 | - /* The register is not banked so we only want to allow migration of | ||
62 | - * the non-secure instance. | ||
63 | + /* | ||
64 | + * The register is not banked so we only want to allow migration | ||
65 | + * of the non-secure instance. | ||
66 | */ | ||
67 | r2->type |= ARM_CP_ALIAS; | ||
68 | } | ||
69 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | ||
70 | } | ||
36 | } | 71 | } |
37 | 72 | ||
38 | - address_space_read(s->dma_as, addr, s->attr, buf, sizeof(XlnxZDMADescr)); | 73 | - /* By convention, for wildcarded registers only the first |
39 | + descr->addr = address_space_ldq_le(s->dma_as, addr, s->attr, NULL); | 74 | + /* |
40 | + descr->size = address_space_ldl_le(s->dma_as, addr + 8, s->attr, NULL); | 75 | + * By convention, for wildcarded registers only the first |
41 | + descr->attr = address_space_ldl_le(s->dma_as, addr + 12, s->attr, NULL); | 76 | * entry is used for migration; the others are marked as |
42 | return true; | 77 | * ALIAS so we don't try to transfer the register |
43 | } | 78 | * multiple times. Special registers (ie NOP/WFI) are |
44 | 79 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, | |
45 | @@ -XXX,XX +XXX,XX @@ static void zdma_update_descr_addr(XlnxZDMA *s, bool type, | 80 | r2->type |= ARM_CP_ALIAS | ARM_CP_NO_GDB; |
46 | } else { | ||
47 | addr = zdma_get_regaddr64(s, basereg); | ||
48 | addr += sizeof(s->dsc_dst); | ||
49 | - address_space_read(s->dma_as, addr, s->attr, (void *) &next, 8); | ||
50 | + next = address_space_ldq_le(s->dma_as, addr, s->attr, NULL); | ||
51 | } | 81 | } |
52 | 82 | ||
53 | zdma_put_regaddr64(s, basereg, next); | 83 | - /* Check that raw accesses are either forbidden or handled. Note that |
84 | + /* | ||
85 | + * Check that raw accesses are either forbidden or handled. Note that | ||
86 | * we can't assert this earlier because the setup of fieldoffset for | ||
87 | * banked registers has to be done first. | ||
88 | */ | ||
54 | -- | 89 | -- |
55 | 2.20.1 | 90 | 2.25.1 |
56 | |||
57 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Cameron Esfahani <dirty@apple.com> | ||
2 | 1 | ||
3 | NRF51_GPIO_REG_CNF_END doesn't actually refer to the start of the last | ||
4 | valid CNF register: it's referring to the last byte of the last valid | ||
5 | CNF register. | ||
6 | |||
7 | This hasn't been a problem up to now, as current implementation in | ||
8 | memory.c turns an unaligned 4-byte read from 0x77f to a single byte read | ||
9 | and the qtest only looks at the least-significant byte of the register. | ||
10 | |||
11 | But when running with patches which fix unaligned accesses in memory.c, | ||
12 | the qtest breaks. | ||
13 | |||
14 | Considering NRF51 doesn't support unaligned accesses, the simplest fix | ||
15 | is to actually set NRF51_GPIO_REG_CNF_END to the start of the last valid | ||
16 | CNF register: 0x77c. | ||
17 | |||
18 | Now, qtests work with or without the unaligned access patches. | ||
19 | |||
20 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | ||
21 | Tested-by: Cédric Le Goater <clg@kaod.org> | ||
22 | Reviewed-by: Joel Stanley <joel@jms.id.au> | ||
23 | Signed-off-by: Cameron Esfahani <dirty@apple.com> | ||
24 | Message-id: 51b427f06838622da783d38ba56e3630d6d85c60.1586925392.git.dirty@apple.com | ||
25 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
26 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
27 | --- | ||
28 | include/hw/gpio/nrf51_gpio.h | 2 +- | ||
29 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
30 | |||
31 | diff --git a/include/hw/gpio/nrf51_gpio.h b/include/hw/gpio/nrf51_gpio.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/include/hw/gpio/nrf51_gpio.h | ||
34 | +++ b/include/hw/gpio/nrf51_gpio.h | ||
35 | @@ -XXX,XX +XXX,XX @@ | ||
36 | #define NRF51_GPIO_REG_DIRSET 0x518 | ||
37 | #define NRF51_GPIO_REG_DIRCLR 0x51C | ||
38 | #define NRF51_GPIO_REG_CNF_START 0x700 | ||
39 | -#define NRF51_GPIO_REG_CNF_END 0x77F | ||
40 | +#define NRF51_GPIO_REG_CNF_END 0x77C | ||
41 | |||
42 | #define NRF51_GPIO_PULLDOWN 1 | ||
43 | #define NRF51_GPIO_PULLUP 3 | ||
44 | -- | ||
45 | 2.20.1 | ||
46 | |||
47 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Keqian Zhu <zhukeqian1@huawei.com> | ||
2 | 1 | ||
3 | The KVM_VGIC_ATTR macro expect the second parameter as gicr_typer, | ||
4 | of which high 32bit is constructed by mp_affinity. For most case, | ||
5 | the high 32bit of mp_affinity is zero, so it will always access the | ||
6 | ICC_CTLR_EL1 of CPU0. | ||
7 | |||
8 | Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> | ||
9 | Message-id: 20200413091552.62748-2-zhukeqian1@huawei.com | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | hw/intc/arm_gicv3_kvm.c | 4 +--- | ||
14 | 1 file changed, 1 insertion(+), 3 deletions(-) | ||
15 | |||
16 | diff --git a/hw/intc/arm_gicv3_kvm.c b/hw/intc/arm_gicv3_kvm.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/hw/intc/arm_gicv3_kvm.c | ||
19 | +++ b/hw/intc/arm_gicv3_kvm.c | ||
20 | @@ -XXX,XX +XXX,XX @@ static void kvm_arm_gicv3_get(GICv3State *s) | ||
21 | |||
22 | static void arm_gicv3_icc_reset(CPUARMState *env, const ARMCPRegInfo *ri) | ||
23 | { | ||
24 | - ARMCPU *cpu; | ||
25 | GICv3State *s; | ||
26 | GICv3CPUState *c; | ||
27 | |||
28 | c = (GICv3CPUState *)env->gicv3state; | ||
29 | s = c->gic; | ||
30 | - cpu = ARM_CPU(c->cpu); | ||
31 | |||
32 | c->icc_pmr_el1 = 0; | ||
33 | c->icc_bpr[GICV3_G0] = GIC_MIN_BPR; | ||
34 | @@ -XXX,XX +XXX,XX @@ static void arm_gicv3_icc_reset(CPUARMState *env, const ARMCPRegInfo *ri) | ||
35 | |||
36 | /* Initialize to actual HW supported configuration */ | ||
37 | kvm_device_access(s->dev_fd, KVM_DEV_ARM_VGIC_GRP_CPU_SYSREGS, | ||
38 | - KVM_VGIC_ATTR(ICC_CTLR_EL1, cpu->mp_affinity), | ||
39 | + KVM_VGIC_ATTR(ICC_CTLR_EL1, c->gicr_typer), | ||
40 | &c->icc_ctlr_el1[GICV3_NS], false, &error_abort); | ||
41 | |||
42 | c->icc_ctlr_el1[GICV3_S] = c->icc_ctlr_el1[GICV3_NS]; | ||
43 | -- | ||
44 | 2.20.1 | ||
45 | |||
46 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Keqian Zhu <zhukeqian1@huawei.com> | ||
2 | 1 | ||
3 | Replace "acpi-mem-hotplug" with "acpi-cpu-hotplug" | ||
4 | |||
5 | Signed-off-by: Keqian Zhu <zhukeqian1@huawei.com> | ||
6 | Message-id: 20200413091552.62748-4-zhukeqian1@huawei.com | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | hw/acpi/cpu.c | 2 +- | ||
11 | 1 file changed, 1 insertion(+), 1 deletion(-) | ||
12 | |||
13 | diff --git a/hw/acpi/cpu.c b/hw/acpi/cpu.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/hw/acpi/cpu.c | ||
16 | +++ b/hw/acpi/cpu.c | ||
17 | @@ -XXX,XX +XXX,XX @@ void cpu_hotplug_hw_init(MemoryRegion *as, Object *owner, | ||
18 | state->devs[i].arch_id = id_list->cpus[i].arch_id; | ||
19 | } | ||
20 | memory_region_init_io(&state->ctrl_reg, owner, &cpu_hotplug_ops, state, | ||
21 | - "acpi-mem-hotplug", ACPI_CPU_HOTPLUG_REG_LEN); | ||
22 | + "acpi-cpu-hotplug", ACPI_CPU_HOTPLUG_REG_LEN); | ||
23 | memory_region_add_subregion(as, base_addr, &state->ctrl_reg); | ||
24 | } | ||
25 | |||
26 | -- | ||
27 | 2.20.1 | ||
28 | |||
29 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Subbaraya Sundeep <sundeep.lkml@gmail.com> | ||
2 | 1 | ||
3 | In addition to simple serial test this patch uses ping | ||
4 | to test the ethernet block modelled in SmartFusion2 SoC. | ||
5 | |||
6 | Signed-off-by: Subbaraya Sundeep <sundeep.lkml@gmail.com> | ||
7 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Tested-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Message-id: 1587048891-30493-4-git-send-email-sundeep.lkml@gmail.com | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | tests/acceptance/boot_linux_console.py | 15 ++++++++++----- | ||
13 | 1 file changed, 10 insertions(+), 5 deletions(-) | ||
14 | |||
15 | diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/tests/acceptance/boot_linux_console.py | ||
18 | +++ b/tests/acceptance/boot_linux_console.py | ||
19 | @@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test): | ||
20 | """ | ||
21 | uboot_url = ('https://raw.githubusercontent.com/' | ||
22 | 'Subbaraya-Sundeep/qemu-test-binaries/' | ||
23 | - 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/u-boot') | ||
24 | - uboot_hash = 'abba5d9c24cdd2d49cdc2a8aa92976cf20737eff' | ||
25 | + 'fe371d32e50ca682391e1e70ab98c2942aeffb01/u-boot') | ||
26 | + uboot_hash = 'cbb8cbab970f594bf6523b9855be209c08374ae2' | ||
27 | uboot_path = self.fetch_asset(uboot_url, asset_hash=uboot_hash) | ||
28 | spi_url = ('https://raw.githubusercontent.com/' | ||
29 | 'Subbaraya-Sundeep/qemu-test-binaries/' | ||
30 | - 'fa030bd77a014a0b8e360d3b7011df89283a2f0b/spi.bin') | ||
31 | - spi_hash = '85f698329d38de63aea6e884a86fbde70890a78a' | ||
32 | + 'fe371d32e50ca682391e1e70ab98c2942aeffb01/spi.bin') | ||
33 | + spi_hash = '65523a1835949b6f4553be96dec1b6a38fb05501' | ||
34 | spi_path = self.fetch_asset(spi_url, asset_hash=spi_hash) | ||
35 | |||
36 | self.vm.set_console() | ||
37 | @@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(Test): | ||
38 | '-drive', 'file=' + spi_path + ',if=mtd,format=raw', | ||
39 | '-no-reboot') | ||
40 | self.vm.launch() | ||
41 | - self.wait_for_console_pattern('init started: BusyBox') | ||
42 | + self.wait_for_console_pattern('Enter \'help\' for a list') | ||
43 | + | ||
44 | + exec_command_and_wait_for_pattern(self, 'ifconfig eth0 10.0.2.15', | ||
45 | + 'eth0: link becomes ready') | ||
46 | + exec_command_and_wait_for_pattern(self, 'ping -c 3 10.0.2.2', | ||
47 | + '3 packets transmitted, 3 packets received, 0% packet loss') | ||
48 | |||
49 | def do_test_arm_raspi2(self, uart_id): | ||
50 | """ | ||
51 | -- | ||
52 | 2.20.1 | ||
53 | |||
54 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Damien Hedde <damien.hedde@greensocs.com> | ||
2 | 1 | ||
3 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
5 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
8 | Message-id: 20200406135251.157596-3-damien.hedde@greensocs.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/core/Makefile.objs | 1 + | ||
12 | include/hw/clock.h | 9 +++++++++ | ||
13 | hw/core/clock-vmstate.c | 25 +++++++++++++++++++++++++ | ||
14 | 3 files changed, 35 insertions(+) | ||
15 | create mode 100644 hw/core/clock-vmstate.c | ||
16 | |||
17 | diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/hw/core/Makefile.objs | ||
20 | +++ b/hw/core/Makefile.objs | ||
21 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_SOFTMMU) += null-machine.o | ||
22 | common-obj-$(CONFIG_SOFTMMU) += loader.o | ||
23 | common-obj-$(CONFIG_SOFTMMU) += machine-hmp-cmds.o | ||
24 | common-obj-$(CONFIG_SOFTMMU) += numa.o | ||
25 | +common-obj-$(CONFIG_SOFTMMU) += clock-vmstate.o | ||
26 | obj-$(CONFIG_SOFTMMU) += machine-qmp-cmds.o | ||
27 | |||
28 | common-obj-$(CONFIG_EMPTY_SLOT) += empty_slot.o | ||
29 | diff --git a/include/hw/clock.h b/include/hw/clock.h | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/include/hw/clock.h | ||
32 | +++ b/include/hw/clock.h | ||
33 | @@ -XXX,XX +XXX,XX @@ struct Clock { | ||
34 | QLIST_ENTRY(Clock) sibling; | ||
35 | }; | ||
36 | |||
37 | +/* | ||
38 | + * vmstate description entry to be added in device vmsd. | ||
39 | + */ | ||
40 | +extern const VMStateDescription vmstate_clock; | ||
41 | +#define VMSTATE_CLOCK(field, state) \ | ||
42 | + VMSTATE_CLOCK_V(field, state, 0) | ||
43 | +#define VMSTATE_CLOCK_V(field, state, version) \ | ||
44 | + VMSTATE_STRUCT_POINTER_V(field, state, version, vmstate_clock, Clock) | ||
45 | + | ||
46 | /** | ||
47 | * clock_setup_canonical_path: | ||
48 | * @clk: clock | ||
49 | diff --git a/hw/core/clock-vmstate.c b/hw/core/clock-vmstate.c | ||
50 | new file mode 100644 | ||
51 | index XXXXXXX..XXXXXXX | ||
52 | --- /dev/null | ||
53 | +++ b/hw/core/clock-vmstate.c | ||
54 | @@ -XXX,XX +XXX,XX @@ | ||
55 | +/* | ||
56 | + * Clock migration structure | ||
57 | + * | ||
58 | + * Copyright GreenSocs 2019-2020 | ||
59 | + * | ||
60 | + * Authors: | ||
61 | + * Damien Hedde | ||
62 | + * | ||
63 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
64 | + * See the COPYING file in the top-level directory. | ||
65 | + */ | ||
66 | + | ||
67 | +#include "qemu/osdep.h" | ||
68 | +#include "migration/vmstate.h" | ||
69 | +#include "hw/clock.h" | ||
70 | + | ||
71 | +const VMStateDescription vmstate_clock = { | ||
72 | + .name = "clock", | ||
73 | + .version_id = 0, | ||
74 | + .minimum_version_id = 0, | ||
75 | + .fields = (VMStateField[]) { | ||
76 | + VMSTATE_UINT64(period, Clock), | ||
77 | + VMSTATE_END_OF_LIST() | ||
78 | + } | ||
79 | +}; | ||
80 | -- | ||
81 | 2.20.1 | ||
82 | |||
83 | diff view generated by jsdifflib |
1 | From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Setup the ADMA with 128bit bus-width. This matters when | 3 | Since e03b56863d2bc, our host endian indicator is unconditionally |
4 | FIXED BURST mode is used. | 4 | set, which means that we can use a normal C condition. |
5 | 5 | ||
6 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Luc Michel <luc.michel@greensocs.com> | 8 | Message-id: 20220501055028.646596-20-richard.henderson@linaro.org |
9 | Message-id: 20200417153800.27399-2-edgar.iglesias@gmail.com | 9 | [PMM: quote correct git hash in commit message] |
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 11 | --- |
12 | hw/arm/xlnx-versal.c | 2 ++ | 12 | target/arm/helper.c | 9 +++------ |
13 | 1 file changed, 2 insertions(+) | 13 | 1 file changed, 3 insertions(+), 6 deletions(-) |
14 | 14 | ||
15 | diff --git a/hw/arm/xlnx-versal.c b/hw/arm/xlnx-versal.c | 15 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/arm/xlnx-versal.c | 17 | --- a/target/arm/helper.c |
18 | +++ b/hw/arm/xlnx-versal.c | 18 | +++ b/target/arm/helper.c |
19 | @@ -XXX,XX +XXX,XX @@ static void versal_create_admas(Versal *s, qemu_irq *pic) | 19 | @@ -XXX,XX +XXX,XX @@ static void add_cpreg_to_hashtable(ARMCPU *cpu, const ARMCPRegInfo *r, |
20 | 20 | r2->type |= ARM_CP_ALIAS; | |
21 | dev = qdev_create(NULL, "xlnx.zdma"); | 21 | } |
22 | s->lpd.iou.adma[i] = SYS_BUS_DEVICE(dev); | 22 | |
23 | + object_property_set_int(OBJECT(s->lpd.iou.adma[i]), 128, "bus-width", | 23 | - if (r->state == ARM_CP_STATE_BOTH) { |
24 | + &error_abort); | 24 | -#if HOST_BIG_ENDIAN |
25 | object_property_add_child(OBJECT(s), name, OBJECT(dev), &error_fatal); | 25 | - if (r2->fieldoffset) { |
26 | qdev_init_nofail(dev); | 26 | - r2->fieldoffset += sizeof(uint32_t); |
27 | - } | ||
28 | -#endif | ||
29 | + if (HOST_BIG_ENDIAN && | ||
30 | + r->state == ARM_CP_STATE_BOTH && r2->fieldoffset) { | ||
31 | + r2->fieldoffset += sizeof(uint32_t); | ||
32 | } | ||
33 | } | ||
27 | 34 | ||
28 | -- | 35 | -- |
29 | 2.20.1 | 36 | 2.25.1 |
30 | |||
31 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Switch the cadence uart to multi-phase reset and add the | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
4 | reference clock input. | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
5 | 5 | Message-id: 20220501055028.646596-24-richard.henderson@linaro.org | |
6 | The input clock frequency is added to the migration structure. | ||
7 | |||
8 | The reference clock controls the baudrate generation. If it disabled, | ||
9 | any input characters and events are ignored. | ||
10 | |||
11 | If this clock remains unconnected, the uart behaves as before | ||
12 | (it default to a 50MHz ref clock). | ||
13 | |||
14 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
15 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | Message-id: 20200406135251.157596-8-damien.hedde@greensocs.com | ||
18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
19 | --- | 7 | --- |
20 | include/hw/char/cadence_uart.h | 1 + | 8 | target/arm/cpu.h | 15 +++++++++++++++ |
21 | hw/char/cadence_uart.c | 73 +++++++++++++++++++++++++++++----- | 9 | 1 file changed, 15 insertions(+) |
22 | hw/char/trace-events | 3 ++ | ||
23 | 3 files changed, 67 insertions(+), 10 deletions(-) | ||
24 | 10 | ||
25 | diff --git a/include/hw/char/cadence_uart.h b/include/hw/char/cadence_uart.h | 11 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
26 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/include/hw/char/cadence_uart.h | 13 | --- a/target/arm/cpu.h |
28 | +++ b/include/hw/char/cadence_uart.h | 14 | +++ b/target/arm/cpu.h |
29 | @@ -XXX,XX +XXX,XX @@ typedef struct { | 15 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa32_ssbs(const ARMISARegisters *id) |
30 | CharBackend chr; | 16 | return FIELD_EX32(id->id_pfr2, ID_PFR2, SSBS) != 0; |
31 | qemu_irq irq; | ||
32 | QEMUTimer *fifo_trigger_handle; | ||
33 | + Clock *refclk; | ||
34 | } CadenceUARTState; | ||
35 | |||
36 | static inline DeviceState *cadence_uart_create(hwaddr addr, | ||
37 | diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/hw/char/cadence_uart.c | ||
40 | +++ b/hw/char/cadence_uart.c | ||
41 | @@ -XXX,XX +XXX,XX @@ | ||
42 | #include "qemu/module.h" | ||
43 | #include "hw/char/cadence_uart.h" | ||
44 | #include "hw/irq.h" | ||
45 | +#include "hw/qdev-clock.h" | ||
46 | +#include "trace.h" | ||
47 | |||
48 | #ifdef CADENCE_UART_ERR_DEBUG | ||
49 | #define DB_PRINT(...) do { \ | ||
50 | @@ -XXX,XX +XXX,XX @@ | ||
51 | #define LOCAL_LOOPBACK (0x2 << UART_MR_CHMODE_SH) | ||
52 | #define REMOTE_LOOPBACK (0x3 << UART_MR_CHMODE_SH) | ||
53 | |||
54 | -#define UART_INPUT_CLK 50000000 | ||
55 | +#define UART_DEFAULT_REF_CLK (50 * 1000 * 1000) | ||
56 | |||
57 | #define R_CR (0x00/4) | ||
58 | #define R_MR (0x04/4) | ||
59 | @@ -XXX,XX +XXX,XX @@ static void uart_send_breaks(CadenceUARTState *s) | ||
60 | static void uart_parameters_setup(CadenceUARTState *s) | ||
61 | { | ||
62 | QEMUSerialSetParams ssp; | ||
63 | - unsigned int baud_rate, packet_size; | ||
64 | + unsigned int baud_rate, packet_size, input_clk; | ||
65 | + input_clk = clock_get_hz(s->refclk); | ||
66 | |||
67 | - baud_rate = (s->r[R_MR] & UART_MR_CLKS) ? | ||
68 | - UART_INPUT_CLK / 8 : UART_INPUT_CLK; | ||
69 | + baud_rate = (s->r[R_MR] & UART_MR_CLKS) ? input_clk / 8 : input_clk; | ||
70 | + baud_rate /= (s->r[R_BRGR] * (s->r[R_BDIV] + 1)); | ||
71 | + trace_cadence_uart_baudrate(baud_rate); | ||
72 | + | ||
73 | + ssp.speed = baud_rate; | ||
74 | |||
75 | - ssp.speed = baud_rate / (s->r[R_BRGR] * (s->r[R_BDIV] + 1)); | ||
76 | packet_size = 1; | ||
77 | |||
78 | switch (s->r[R_MR] & UART_MR_PAR) { | ||
79 | @@ -XXX,XX +XXX,XX @@ static void uart_parameters_setup(CadenceUARTState *s) | ||
80 | } | ||
81 | |||
82 | packet_size += ssp.data_bits + ssp.stop_bits; | ||
83 | + if (ssp.speed == 0) { | ||
84 | + /* | ||
85 | + * Avoid division-by-zero below. | ||
86 | + * TODO: find something better | ||
87 | + */ | ||
88 | + ssp.speed = 1; | ||
89 | + } | ||
90 | s->char_tx_time = (NANOSECONDS_PER_SECOND / ssp.speed) * packet_size; | ||
91 | qemu_chr_fe_ioctl(&s->chr, CHR_IOCTL_SERIAL_SET_PARAMS, &ssp); | ||
92 | } | 17 | } |
93 | @@ -XXX,XX +XXX,XX @@ static void uart_receive(void *opaque, const uint8_t *buf, int size) | 18 | |
94 | CadenceUARTState *s = opaque; | 19 | +static inline bool isar_feature_aa32_debugv8p2(const ARMISARegisters *id) |
95 | uint32_t ch_mode = s->r[R_MR] & UART_MR_CHMODE; | 20 | +{ |
96 | 21 | + return FIELD_EX32(id->id_dfr0, ID_DFR0, COPDBG) >= 8; | |
97 | + /* ignore characters when unclocked or in reset */ | ||
98 | + if (!clock_is_enabled(s->refclk) || device_is_in_reset(DEVICE(s))) { | ||
99 | + return; | ||
100 | + } | ||
101 | + | ||
102 | if (ch_mode == NORMAL_MODE || ch_mode == ECHO_MODE) { | ||
103 | uart_write_rx_fifo(opaque, buf, size); | ||
104 | } | ||
105 | @@ -XXX,XX +XXX,XX @@ static void uart_event(void *opaque, QEMUChrEvent event) | ||
106 | CadenceUARTState *s = opaque; | ||
107 | uint8_t buf = '\0'; | ||
108 | |||
109 | + /* ignore characters when unclocked or in reset */ | ||
110 | + if (!clock_is_enabled(s->refclk) || device_is_in_reset(DEVICE(s))) { | ||
111 | + return; | ||
112 | + } | ||
113 | + | ||
114 | if (event == CHR_EVENT_BREAK) { | ||
115 | uart_write_rx_fifo(opaque, &buf, 1); | ||
116 | } | ||
117 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps uart_ops = { | ||
118 | .endianness = DEVICE_NATIVE_ENDIAN, | ||
119 | }; | ||
120 | |||
121 | -static void cadence_uart_reset(DeviceState *dev) | ||
122 | +static void cadence_uart_reset_init(Object *obj, ResetType type) | ||
123 | { | ||
124 | - CadenceUARTState *s = CADENCE_UART(dev); | ||
125 | + CadenceUARTState *s = CADENCE_UART(obj); | ||
126 | |||
127 | s->r[R_CR] = 0x00000128; | ||
128 | s->r[R_IMR] = 0; | ||
129 | @@ -XXX,XX +XXX,XX @@ static void cadence_uart_reset(DeviceState *dev) | ||
130 | s->r[R_BRGR] = 0x0000028B; | ||
131 | s->r[R_BDIV] = 0x0000000F; | ||
132 | s->r[R_TTRIG] = 0x00000020; | ||
133 | +} | 22 | +} |
134 | + | 23 | + |
135 | +static void cadence_uart_reset_hold(Object *obj) | 24 | /* |
25 | * 64-bit feature tests via id registers. | ||
26 | */ | ||
27 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_ssbs(const ARMISARegisters *id) | ||
28 | return FIELD_EX64(id->id_aa64pfr1, ID_AA64PFR1, SSBS) != 0; | ||
29 | } | ||
30 | |||
31 | +static inline bool isar_feature_aa64_debugv8p2(const ARMISARegisters *id) | ||
136 | +{ | 32 | +{ |
137 | + CadenceUARTState *s = CADENCE_UART(obj); | 33 | + return FIELD_EX64(id->id_aa64dfr0, ID_AA64DFR0, DEBUGVER) >= 8; |
138 | |||
139 | uart_rx_reset(s); | ||
140 | uart_tx_reset(s); | ||
141 | @@ -XXX,XX +XXX,XX @@ static void cadence_uart_realize(DeviceState *dev, Error **errp) | ||
142 | uart_event, NULL, s, NULL, true); | ||
143 | } | ||
144 | |||
145 | +static void cadence_uart_refclk_update(void *opaque) | ||
146 | +{ | ||
147 | + CadenceUARTState *s = opaque; | ||
148 | + | ||
149 | + /* recompute uart's speed on clock change */ | ||
150 | + uart_parameters_setup(s); | ||
151 | +} | 34 | +} |
152 | + | 35 | + |
153 | static void cadence_uart_init(Object *obj) | 36 | static inline bool isar_feature_aa64_sve2(const ARMISARegisters *id) |
154 | { | 37 | { |
155 | SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | 38 | return FIELD_EX64(id->id_aa64zfr0, ID_AA64ZFR0, SVEVER) != 0; |
156 | @@ -XXX,XX +XXX,XX @@ static void cadence_uart_init(Object *obj) | 39 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_any_tts2uxn(const ARMISARegisters *id) |
157 | sysbus_init_mmio(sbd, &s->iomem); | 40 | return isar_feature_aa64_tts2uxn(id) || isar_feature_aa32_tts2uxn(id); |
158 | sysbus_init_irq(sbd, &s->irq); | ||
159 | |||
160 | + s->refclk = qdev_init_clock_in(DEVICE(obj), "refclk", | ||
161 | + cadence_uart_refclk_update, s); | ||
162 | + /* initialize the frequency in case the clock remains unconnected */ | ||
163 | + clock_set_hz(s->refclk, UART_DEFAULT_REF_CLK); | ||
164 | + | ||
165 | s->char_tx_time = (NANOSECONDS_PER_SECOND / 9600) * 10; | ||
166 | } | 41 | } |
167 | 42 | ||
168 | +static int cadence_uart_pre_load(void *opaque) | 43 | +static inline bool isar_feature_any_debugv8p2(const ARMISARegisters *id) |
169 | +{ | 44 | +{ |
170 | + CadenceUARTState *s = opaque; | 45 | + return isar_feature_aa64_debugv8p2(id) || isar_feature_aa32_debugv8p2(id); |
171 | + | ||
172 | + /* the frequency will be overriden if the refclk field is present */ | ||
173 | + clock_set_hz(s->refclk, UART_DEFAULT_REF_CLK); | ||
174 | + return 0; | ||
175 | +} | 46 | +} |
176 | + | 47 | + |
177 | static int cadence_uart_post_load(void *opaque, int version_id) | 48 | /* |
178 | { | 49 | * Forward to the above feature tests given an ARMCPU pointer. |
179 | CadenceUARTState *s = opaque; | 50 | */ |
180 | @@ -XXX,XX +XXX,XX @@ static int cadence_uart_post_load(void *opaque, int version_id) | ||
181 | |||
182 | static const VMStateDescription vmstate_cadence_uart = { | ||
183 | .name = "cadence_uart", | ||
184 | - .version_id = 2, | ||
185 | + .version_id = 3, | ||
186 | .minimum_version_id = 2, | ||
187 | + .pre_load = cadence_uart_pre_load, | ||
188 | .post_load = cadence_uart_post_load, | ||
189 | .fields = (VMStateField[]) { | ||
190 | VMSTATE_UINT32_ARRAY(r, CadenceUARTState, CADENCE_UART_R_MAX), | ||
191 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_cadence_uart = { | ||
192 | VMSTATE_UINT32(tx_count, CadenceUARTState), | ||
193 | VMSTATE_UINT32(rx_wpos, CadenceUARTState), | ||
194 | VMSTATE_TIMER_PTR(fifo_trigger_handle, CadenceUARTState), | ||
195 | + VMSTATE_CLOCK_V(refclk, CadenceUARTState, 3), | ||
196 | VMSTATE_END_OF_LIST() | ||
197 | - } | ||
198 | + }, | ||
199 | }; | ||
200 | |||
201 | static Property cadence_uart_properties[] = { | ||
202 | @@ -XXX,XX +XXX,XX @@ static Property cadence_uart_properties[] = { | ||
203 | static void cadence_uart_class_init(ObjectClass *klass, void *data) | ||
204 | { | ||
205 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
206 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | ||
207 | |||
208 | dc->realize = cadence_uart_realize; | ||
209 | dc->vmsd = &vmstate_cadence_uart; | ||
210 | - dc->reset = cadence_uart_reset; | ||
211 | + rc->phases.enter = cadence_uart_reset_init; | ||
212 | + rc->phases.hold = cadence_uart_reset_hold; | ||
213 | device_class_set_props(dc, cadence_uart_properties); | ||
214 | } | ||
215 | |||
216 | diff --git a/hw/char/trace-events b/hw/char/trace-events | ||
217 | index XXXXXXX..XXXXXXX 100644 | ||
218 | --- a/hw/char/trace-events | ||
219 | +++ b/hw/char/trace-events | ||
220 | @@ -XXX,XX +XXX,XX @@ exynos_uart_wo_read(uint32_t channel, const char *name, uint32_t reg) "UART%d: T | ||
221 | exynos_uart_rxsize(uint32_t channel, uint32_t size) "UART%d: Rx FIFO size: %d" | ||
222 | exynos_uart_channel_error(uint32_t channel) "Wrong UART channel number: %d" | ||
223 | exynos_uart_rx_timeout(uint32_t channel, uint32_t stat, uint32_t intsp) "UART%d: Rx timeout stat=0x%x intsp=0x%x" | ||
224 | + | ||
225 | +# hw/char/cadence_uart.c | ||
226 | +cadence_uart_baudrate(unsigned baudrate) "baudrate %u" | ||
227 | -- | 51 | -- |
228 | 2.20.1 | 52 | 2.25.1 |
229 | |||
230 | diff view generated by jsdifflib |
1 | From: Damien Hedde <damien.hedde@greensocs.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Introduce a function and macro helpers to setup several clocks | 3 | Add the aa64 predicate for detecting RAS support from id registers. |
4 | in a device from a static array description. | 4 | We already have the aa32 version from the M-profile work. |
5 | Add the 'any' predicate for testing both aa64 and aa32. | ||
5 | 6 | ||
6 | An element of the array describes the clock (name and direction) as | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | well as the related callback and an optional offset to store the | 8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | created object pointer in the device state structure. | 9 | Message-id: 20220501055028.646596-34-richard.henderson@linaro.org |
9 | |||
10 | The array must be terminated by a special element QDEV_CLOCK_END. | ||
11 | |||
12 | This is based on the original work of Frederic Konrad. | ||
13 | |||
14 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
15 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
16 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
17 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
18 | Message-id: 20200406135251.157596-5-damien.hedde@greensocs.com | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | --- | 11 | --- |
21 | include/hw/qdev-clock.h | 55 +++++++++++++++++++++++++++++++++++++++++ | 12 | target/arm/cpu.h | 10 ++++++++++ |
22 | hw/core/qdev-clock.c | 17 +++++++++++++ | 13 | 1 file changed, 10 insertions(+) |
23 | 2 files changed, 72 insertions(+) | ||
24 | 14 | ||
25 | diff --git a/include/hw/qdev-clock.h b/include/hw/qdev-clock.h | 15 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
26 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/include/hw/qdev-clock.h | 17 | --- a/target/arm/cpu.h |
28 | +++ b/include/hw/qdev-clock.h | 18 | +++ b/target/arm/cpu.h |
29 | @@ -XXX,XX +XXX,XX @@ Clock *qdev_alias_clock(DeviceState *dev, const char *name, | 19 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_aa32_el1(const ARMISARegisters *id) |
30 | */ | 20 | return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, EL1) >= 2; |
31 | void qdev_finalize_clocklist(DeviceState *dev); | 21 | } |
32 | 22 | ||
33 | +/** | 23 | +static inline bool isar_feature_aa64_ras(const ARMISARegisters *id) |
34 | + * ClockPortInitElem: | 24 | +{ |
35 | + * @name: name of the clock (can't be NULL) | 25 | + return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, RAS) != 0; |
36 | + * @output: indicates whether the clock is input or output | ||
37 | + * @callback: for inputs, optional callback to be called on clock's update | ||
38 | + * with device as opaque | ||
39 | + * @offset: optional offset to store the ClockIn or ClockOut pointer in device | ||
40 | + * state structure (0 means unused) | ||
41 | + */ | ||
42 | +struct ClockPortInitElem { | ||
43 | + const char *name; | ||
44 | + bool is_output; | ||
45 | + ClockCallback *callback; | ||
46 | + size_t offset; | ||
47 | +}; | ||
48 | + | ||
49 | +#define clock_offset_value(devstate, field) \ | ||
50 | + (offsetof(devstate, field) + \ | ||
51 | + type_check(Clock *, typeof_field(devstate, field))) | ||
52 | + | ||
53 | +#define QDEV_CLOCK(out_not_in, devstate, field, cb) { \ | ||
54 | + .name = (stringify(field)), \ | ||
55 | + .is_output = out_not_in, \ | ||
56 | + .callback = cb, \ | ||
57 | + .offset = clock_offset_value(devstate, field), \ | ||
58 | +} | 26 | +} |
59 | + | 27 | + |
60 | +/** | 28 | static inline bool isar_feature_aa64_sve(const ARMISARegisters *id) |
61 | + * QDEV_CLOCK_(IN|OUT): | 29 | { |
62 | + * @devstate: structure type. @dev argument of qdev_init_clocks below must be | 30 | return FIELD_EX64(id->id_aa64pfr0, ID_AA64PFR0, SVE) != 0; |
63 | + * a pointer to that same type. | 31 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_any_debugv8p2(const ARMISARegisters *id) |
64 | + * @field: a field in @_devstate (must be Clock*) | 32 | return isar_feature_aa64_debugv8p2(id) || isar_feature_aa32_debugv8p2(id); |
65 | + * @callback: (for input only) callback (or NULL) to be called with the device | ||
66 | + * state as argument | ||
67 | + * | ||
68 | + * The name of the clock will be derived from @field | ||
69 | + */ | ||
70 | +#define QDEV_CLOCK_IN(devstate, field, callback) \ | ||
71 | + QDEV_CLOCK(false, devstate, field, callback) | ||
72 | + | ||
73 | +#define QDEV_CLOCK_OUT(devstate, field) \ | ||
74 | + QDEV_CLOCK(true, devstate, field, NULL) | ||
75 | + | ||
76 | +#define QDEV_CLOCK_END { .name = NULL } | ||
77 | + | ||
78 | +typedef struct ClockPortInitElem ClockPortInitArray[]; | ||
79 | + | ||
80 | +/** | ||
81 | + * qdev_init_clocks: | ||
82 | + * @dev: the device to add clocks to | ||
83 | + * @clocks: a QDEV_CLOCK_END-terminated array which contains the | ||
84 | + * clocks information. | ||
85 | + */ | ||
86 | +void qdev_init_clocks(DeviceState *dev, const ClockPortInitArray clocks); | ||
87 | + | ||
88 | #endif /* QDEV_CLOCK_H */ | ||
89 | diff --git a/hw/core/qdev-clock.c b/hw/core/qdev-clock.c | ||
90 | index XXXXXXX..XXXXXXX 100644 | ||
91 | --- a/hw/core/qdev-clock.c | ||
92 | +++ b/hw/core/qdev-clock.c | ||
93 | @@ -XXX,XX +XXX,XX @@ Clock *qdev_init_clock_in(DeviceState *dev, const char *name, | ||
94 | return ncl->clock; | ||
95 | } | 33 | } |
96 | 34 | ||
97 | +void qdev_init_clocks(DeviceState *dev, const ClockPortInitArray clocks) | 35 | +static inline bool isar_feature_any_ras(const ARMISARegisters *id) |
98 | +{ | 36 | +{ |
99 | + const struct ClockPortInitElem *elem; | 37 | + return isar_feature_aa64_ras(id) || isar_feature_aa32_ras(id); |
100 | + | ||
101 | + for (elem = &clocks[0]; elem->name != NULL; elem++) { | ||
102 | + Clock **clkp; | ||
103 | + /* offset cannot be inside the DeviceState part */ | ||
104 | + assert(elem->offset > sizeof(DeviceState)); | ||
105 | + clkp = (Clock **)(((void *) dev) + elem->offset); | ||
106 | + if (elem->is_output) { | ||
107 | + *clkp = qdev_init_clock_out(dev, elem->name); | ||
108 | + } else { | ||
109 | + *clkp = qdev_init_clock_in(dev, elem->name, elem->callback, dev); | ||
110 | + } | ||
111 | + } | ||
112 | +} | 38 | +} |
113 | + | 39 | + |
114 | static NamedClockList *qdev_get_clocklist(DeviceState *dev, const char *name) | 40 | /* |
115 | { | 41 | * Forward to the above feature tests given an ARMCPU pointer. |
116 | NamedClockList *ncl; | 42 | */ |
117 | -- | 43 | -- |
118 | 2.20.1 | 44 | 2.25.1 |
119 | |||
120 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Add the documentation about the clock inputs and outputs in devices. | ||
2 | 1 | ||
3 | This is based on the original work of Frederic Konrad. | ||
4 | |||
5 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
7 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
8 | Message-id: 20200406135251.157596-6-damien.hedde@greensocs.com | ||
9 | [PMM: Editing pass for minor grammar, style and Sphinx | ||
10 | formatting fixes] | ||
11 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | --- | ||
14 | docs/devel/clocks.rst | 391 ++++++++++++++++++++++++++++++++++++++++++ | ||
15 | docs/devel/index.rst | 1 + | ||
16 | 2 files changed, 392 insertions(+) | ||
17 | create mode 100644 docs/devel/clocks.rst | ||
18 | |||
19 | diff --git a/docs/devel/clocks.rst b/docs/devel/clocks.rst | ||
20 | new file mode 100644 | ||
21 | index XXXXXXX..XXXXXXX | ||
22 | --- /dev/null | ||
23 | +++ b/docs/devel/clocks.rst | ||
24 | @@ -XXX,XX +XXX,XX @@ | ||
25 | +Modelling a clock tree in QEMU | ||
26 | +============================== | ||
27 | + | ||
28 | +What are clocks? | ||
29 | +---------------- | ||
30 | + | ||
31 | +Clocks are QOM objects developed for the purpose of modelling the | ||
32 | +distribution of clocks in QEMU. | ||
33 | + | ||
34 | +They allow us to model the clock distribution of a platform and detect | ||
35 | +configuration errors in the clock tree such as badly configured PLL, clock | ||
36 | +source selection or disabled clock. | ||
37 | + | ||
38 | +The object is *Clock* and its QOM name is ``clock`` (in C code, the macro | ||
39 | +``TYPE_CLOCK``). | ||
40 | + | ||
41 | +Clocks are typically used with devices where they are used to model inputs | ||
42 | +and outputs. They are created in a similar way to GPIOs. Inputs and outputs | ||
43 | +of different devices can be connected together. | ||
44 | + | ||
45 | +In these cases a Clock object is a child of a Device object, but this | ||
46 | +is not a requirement. Clocks can be independent of devices. For | ||
47 | +example it is possible to create a clock outside of any device to | ||
48 | +model the main clock source of a machine. | ||
49 | + | ||
50 | +Here is an example of clocks:: | ||
51 | + | ||
52 | + +---------+ +----------------------+ +--------------+ | ||
53 | + | Clock 1 | | Device B | | Device C | | ||
54 | + | | | +-------+ +-------+ | | +-------+ | | ||
55 | + | |>>-+-->>|Clock 2| |Clock 3|>>--->>|Clock 6| | | ||
56 | + +---------+ | | | (in) | | (out) | | | | (in) | | | ||
57 | + | | +-------+ +-------+ | | +-------+ | | ||
58 | + | | +-------+ | +--------------+ | ||
59 | + | | |Clock 4|>> | ||
60 | + | | | (out) | | +--------------+ | ||
61 | + | | +-------+ | | Device D | | ||
62 | + | | +-------+ | | +-------+ | | ||
63 | + | | |Clock 5|>>--->>|Clock 7| | | ||
64 | + | | | (out) | | | | (in) | | | ||
65 | + | | +-------+ | | +-------+ | | ||
66 | + | +----------------------+ | | | ||
67 | + | | +-------+ | | ||
68 | + +----------------------------->>|Clock 8| | | ||
69 | + | | (in) | | | ||
70 | + | +-------+ | | ||
71 | + +--------------+ | ||
72 | + | ||
73 | +Clocks are defined in the ``include/hw/clock.h`` header and device | ||
74 | +related functions are defined in the ``include/hw/qdev-clock.h`` | ||
75 | +header. | ||
76 | + | ||
77 | +The clock state | ||
78 | +--------------- | ||
79 | + | ||
80 | +The state of a clock is its period; it is stored as an integer | ||
81 | +representing it in units of 2 :sup:`-32` ns. The special value of 0 is used to | ||
82 | +represent the clock being inactive or gated. The clocks do not model | ||
83 | +the signal itself (pin toggling) or other properties such as the duty | ||
84 | +cycle. | ||
85 | + | ||
86 | +All clocks contain this state: outputs as well as inputs. This allows | ||
87 | +the current period of a clock to be fetched at any time. When a clock | ||
88 | +is updated, the value is immediately propagated to all connected | ||
89 | +clocks in the tree. | ||
90 | + | ||
91 | +To ease interaction with clocks, helpers with a unit suffix are defined for | ||
92 | +every clock state setter or getter. The suffixes are: | ||
93 | + | ||
94 | +- ``_ns`` for handling periods in nanoseconds | ||
95 | +- ``_hz`` for handling frequencies in hertz | ||
96 | + | ||
97 | +The 0 period value is converted to 0 in hertz and vice versa. 0 always means | ||
98 | +that the clock is disabled. | ||
99 | + | ||
100 | +Adding a new clock | ||
101 | +------------------ | ||
102 | + | ||
103 | +Adding clocks to a device must be done during the init method of the Device | ||
104 | +instance. | ||
105 | + | ||
106 | +To add an input clock to a device, the function ``qdev_init_clock_in()`` | ||
107 | +must be used. It takes the name, a callback and an opaque parameter | ||
108 | +for the callback (this will be explained in a following section). | ||
109 | +Output is simpler; only the name is required. Typically:: | ||
110 | + | ||
111 | + qdev_init_clock_in(DEVICE(dev), "clk_in", clk_in_callback, dev); | ||
112 | + qdev_init_clock_out(DEVICE(dev), "clk_out"); | ||
113 | + | ||
114 | +Both functions return the created Clock pointer, which should be saved in the | ||
115 | +device's state structure for further use. | ||
116 | + | ||
117 | +These objects will be automatically deleted by the QOM reference mechanism. | ||
118 | + | ||
119 | +Note that it is possible to create a static array describing clock inputs and | ||
120 | +outputs. The function ``qdev_init_clocks()`` must be called with the array as | ||
121 | +parameter to initialize the clocks: it has the same behaviour as calling the | ||
122 | +``qdev_init_clock_in/out()`` for each clock in the array. To ease the array | ||
123 | +construction, some macros are defined in ``include/hw/qdev-clock.h``. | ||
124 | +As an example, the following creates 2 clocks to a device: one input and one | ||
125 | +output. | ||
126 | + | ||
127 | +.. code-block:: c | ||
128 | + | ||
129 | + /* device structure containing pointers to the clock objects */ | ||
130 | + typedef struct MyDeviceState { | ||
131 | + DeviceState parent_obj; | ||
132 | + Clock *clk_in; | ||
133 | + Clock *clk_out; | ||
134 | + } MyDeviceState; | ||
135 | + | ||
136 | + /* | ||
137 | + * callback for the input clock (see "Callback on input clock | ||
138 | + * change" section below for more information). | ||
139 | + */ | ||
140 | + static void clk_in_callback(void *opaque); | ||
141 | + | ||
142 | + /* | ||
143 | + * static array describing clocks: | ||
144 | + * + a clock input named "clk_in", whose pointer is stored in | ||
145 | + * the clk_in field of a MyDeviceState structure with callback | ||
146 | + * clk_in_callback. | ||
147 | + * + a clock output named "clk_out" whose pointer is stored in | ||
148 | + * the clk_out field of a MyDeviceState structure. | ||
149 | + */ | ||
150 | + static const ClockPortInitArray mydev_clocks = { | ||
151 | + QDEV_CLOCK_IN(MyDeviceState, clk_in, clk_in_callback), | ||
152 | + QDEV_CLOCK_OUT(MyDeviceState, clk_out), | ||
153 | + QDEV_CLOCK_END | ||
154 | + }; | ||
155 | + | ||
156 | + /* device initialization function */ | ||
157 | + static void mydev_init(Object *obj) | ||
158 | + { | ||
159 | + /* cast to MyDeviceState */ | ||
160 | + MyDeviceState *mydev = MYDEVICE(obj); | ||
161 | + /* create and fill the pointer fields in the MyDeviceState */ | ||
162 | + qdev_init_clocks(mydev, mydev_clocks); | ||
163 | + [...] | ||
164 | + } | ||
165 | + | ||
166 | +An alternative way to create a clock is to simply call | ||
167 | +``object_new(TYPE_CLOCK)``. In that case the clock will neither be an | ||
168 | +input nor an output of a device. After the whole QOM hierarchy of the | ||
169 | +clock has been set ``clock_setup_canonical_path()`` should be called. | ||
170 | + | ||
171 | +At creation, the period of the clock is 0: the clock is disabled. You can | ||
172 | +change it using ``clock_set_ns()`` or ``clock_set_hz()``. | ||
173 | + | ||
174 | +Note that if you are creating a clock with a fixed period which will never | ||
175 | +change (for example the main clock source of a board), then you'll have | ||
176 | +nothing else to do. This value will be propagated to other clocks when | ||
177 | +connecting the clocks together and devices will fetch the right value during | ||
178 | +the first reset. | ||
179 | + | ||
180 | +Retrieving clocks from a device | ||
181 | +------------------------------- | ||
182 | + | ||
183 | +``qdev_get_clock_in()`` and ``dev_get_clock_out()`` are available to | ||
184 | +get the clock inputs or outputs of a device. For example: | ||
185 | + | ||
186 | +.. code-block:: c | ||
187 | + | ||
188 | + Clock *clk = qdev_get_clock_in(DEVICE(mydev), "clk_in"); | ||
189 | + | ||
190 | +or: | ||
191 | + | ||
192 | +.. code-block:: c | ||
193 | + | ||
194 | + Clock *clk = qdev_get_clock_out(DEVICE(mydev), "clk_out"); | ||
195 | + | ||
196 | +Connecting two clocks together | ||
197 | +------------------------------ | ||
198 | + | ||
199 | +To connect two clocks together, use the ``clock_set_source()`` function. | ||
200 | +Given two clocks ``clk1``, and ``clk2``, ``clock_set_source(clk2, clk1);`` | ||
201 | +configures ``clk2`` to follow the ``clk1`` period changes. Every time ``clk1`` | ||
202 | +is updated, ``clk2`` will be updated too. | ||
203 | + | ||
204 | +When connecting clock between devices, prefer using the | ||
205 | +``qdev_connect_clock_in()`` function to set the source of an input | ||
206 | +device clock. For example, to connect the input clock ``clk2`` of | ||
207 | +``devB`` to the output clock ``clk1`` of ``devA``, do: | ||
208 | + | ||
209 | +.. code-block:: c | ||
210 | + | ||
211 | + qdev_connect_clock_in(devB, "clk2", qdev_get_clock_out(devA, "clk1")) | ||
212 | + | ||
213 | +We used ``qdev_get_clock_out()`` above, but any clock can drive an | ||
214 | +input clock, even another input clock. The following diagram shows | ||
215 | +some examples of connections. Note also that a clock can drive several | ||
216 | +other clocks. | ||
217 | + | ||
218 | +:: | ||
219 | + | ||
220 | + +------------+ +--------------------------------------------------+ | ||
221 | + | Device A | | Device B | | ||
222 | + | | | +---------------------+ | | ||
223 | + | | | | Device C | | | ||
224 | + | +-------+ | | +-------+ | +-------+ +-------+ | +-------+ | | ||
225 | + | |Clock 1|>>-->>|Clock 2|>>+-->>|Clock 3| |Clock 5|>>>>|Clock 6|>> | ||
226 | + | | (out) | | | | (in) | | | | (in) | | (out) | | | (out) | | | ||
227 | + | +-------+ | | +-------+ | | +-------+ +-------+ | +-------+ | | ||
228 | + +------------+ | | +---------------------+ | | ||
229 | + | | | | ||
230 | + | | +--------------+ | | ||
231 | + | | | Device D | | | ||
232 | + | | | +-------+ | | | ||
233 | + | +-->>|Clock 4| | | | ||
234 | + | | | (in) | | | | ||
235 | + | | +-------+ | | | ||
236 | + | +--------------+ | | ||
237 | + +--------------------------------------------------+ | ||
238 | + | ||
239 | +In the above example, when *Clock 1* is updated by *Device A*, three | ||
240 | +clocks get the new clock period value: *Clock 2*, *Clock 3* and *Clock 4*. | ||
241 | + | ||
242 | +It is not possible to disconnect a clock or to change the clock connection | ||
243 | +after it is connected. | ||
244 | + | ||
245 | +Unconnected input clocks | ||
246 | +------------------------ | ||
247 | + | ||
248 | +A newly created input clock is disabled (period of 0). This means the | ||
249 | +clock will be considered as disabled until the period is updated. If | ||
250 | +the clock remains unconnected it will always keep its initial value | ||
251 | +of 0. If this is not the desired behaviour, ``clock_set()``, | ||
252 | +``clock_set_ns()`` or ``clock_set_hz()`` should be called on the Clock | ||
253 | +object during device instance init. For example: | ||
254 | + | ||
255 | +.. code-block:: c | ||
256 | + | ||
257 | + clk = qdev_init_clock_in(DEVICE(dev), "clk-in", clk_in_callback, | ||
258 | + dev); | ||
259 | + /* set initial value to 10ns / 100MHz */ | ||
260 | + clock_set_ns(clk, 10); | ||
261 | + | ||
262 | +Fetching clock frequency/period | ||
263 | +------------------------------- | ||
264 | + | ||
265 | +To get the current state of a clock, use the functions ``clock_get()``, | ||
266 | +``clock_get_ns()`` or ``clock_get_hz()``. | ||
267 | + | ||
268 | +It is also possible to register a callback on clock frequency changes. | ||
269 | +Here is an example: | ||
270 | + | ||
271 | +.. code-block:: c | ||
272 | + | ||
273 | + void clock_callback(void *opaque) { | ||
274 | + MyDeviceState *s = (MyDeviceState *) opaque; | ||
275 | + /* | ||
276 | + * 'opaque' is the argument passed to qdev_init_clock_in(); | ||
277 | + * usually this will be the device state pointer. | ||
278 | + */ | ||
279 | + | ||
280 | + /* do something with the new period */ | ||
281 | + fprintf(stdout, "device new period is %" PRIu64 "ns\n", | ||
282 | + clock_get_ns(dev->my_clk_input)); | ||
283 | + } | ||
284 | + | ||
285 | +Changing a clock period | ||
286 | +----------------------- | ||
287 | + | ||
288 | +A device can change its outputs using the ``clock_update()``, | ||
289 | +``clock_update_ns()`` or ``clock_update_hz()`` function. It will trigger | ||
290 | +updates on every connected input. | ||
291 | + | ||
292 | +For example, let's say that we have an output clock *clkout* and we | ||
293 | +have a pointer to it in the device state because we did the following | ||
294 | +in init phase: | ||
295 | + | ||
296 | +.. code-block:: c | ||
297 | + | ||
298 | + dev->clkout = qdev_init_clock_out(DEVICE(dev), "clkout"); | ||
299 | + | ||
300 | +Then at any time (apart from the cases listed below), it is possible to | ||
301 | +change the clock value by doing: | ||
302 | + | ||
303 | +.. code-block:: c | ||
304 | + | ||
305 | + clock_update_hz(dev->clkout, 1000 * 1000 * 1000); /* 1GHz */ | ||
306 | + | ||
307 | +Because updating a clock may trigger any side effects through | ||
308 | +connected clocks and their callbacks, this operation must be done | ||
309 | +while holding the qemu io lock. | ||
310 | + | ||
311 | +For the same reason, one can update clocks only when it is allowed to have | ||
312 | +side effects on other objects. In consequence, it is forbidden: | ||
313 | + | ||
314 | +* during migration, | ||
315 | +* and in the enter phase of reset. | ||
316 | + | ||
317 | +Note that calling ``clock_update[_ns|_hz]()`` is equivalent to calling | ||
318 | +``clock_set[_ns|_hz]()`` (with the same arguments) then | ||
319 | +``clock_propagate()`` on the clock. Thus, setting the clock value can | ||
320 | +be separated from triggering the side-effects. This is often required | ||
321 | +to factorize code to handle reset and migration in devices. | ||
322 | + | ||
323 | +Aliasing clocks | ||
324 | +--------------- | ||
325 | + | ||
326 | +Sometimes, one needs to forward, or inherit, a clock from another | ||
327 | +device. Typically, when doing device composition, a device might | ||
328 | +expose a sub-device's clock without interfering with it. The function | ||
329 | +``qdev_alias_clock()`` can be used to achieve this behaviour. Note | ||
330 | +that it is possible to expose the clock under a different name. | ||
331 | +``qdev_alias_clock()`` works for both input and output clocks. | ||
332 | + | ||
333 | +For example, if device B is a child of device A, | ||
334 | +``device_a_instance_init()`` may do something like this: | ||
335 | + | ||
336 | +.. code-block:: c | ||
337 | + | ||
338 | + void device_a_instance_init(Object *obj) | ||
339 | + { | ||
340 | + AState *A = DEVICE_A(obj); | ||
341 | + BState *B; | ||
342 | + /* create object B as child of A */ | ||
343 | + [...] | ||
344 | + qdev_alias_clock(B, "clk", A, "b_clk"); | ||
345 | + /* | ||
346 | + * Now A has a clock "b_clk" which is an alias to | ||
347 | + * the clock "clk" of its child B. | ||
348 | + */ | ||
349 | + } | ||
350 | + | ||
351 | +This function does not return any clock object. The new clock has the | ||
352 | +same direction (input or output) as the original one. This function | ||
353 | +only adds a link to the existing clock. In the above example, object B | ||
354 | +remains the only object allowed to use the clock and device A must not | ||
355 | +try to change the clock period or set a callback to the clock. This | ||
356 | +diagram describes the example with an input clock:: | ||
357 | + | ||
358 | + +--------------------------+ | ||
359 | + | Device A | | ||
360 | + | +--------------+ | | ||
361 | + | | Device B | | | ||
362 | + | | +-------+ | | | ||
363 | + >>"b_clk">>>| "clk" | | | | ||
364 | + | (in) | | (in) | | | | ||
365 | + | | +-------+ | | | ||
366 | + | +--------------+ | | ||
367 | + +--------------------------+ | ||
368 | + | ||
369 | +Migration | ||
370 | +--------- | ||
371 | + | ||
372 | +Clock state is not migrated automatically. Every device must handle its | ||
373 | +clock migration. Alias clocks must not be migrated. | ||
374 | + | ||
375 | +To ensure clock states are restored correctly during migration, there | ||
376 | +are two solutions. | ||
377 | + | ||
378 | +Clock states can be migrated by adding an entry into the device | ||
379 | +vmstate description. You should use the ``VMSTATE_CLOCK`` macro for this. | ||
380 | +This is typically used to migrate an input clock state. For example: | ||
381 | + | ||
382 | +.. code-block:: c | ||
383 | + | ||
384 | + MyDeviceState { | ||
385 | + DeviceState parent_obj; | ||
386 | + [...] /* some fields */ | ||
387 | + Clock *clk; | ||
388 | + }; | ||
389 | + | ||
390 | + VMStateDescription my_device_vmstate = { | ||
391 | + .name = "my_device", | ||
392 | + .fields = (VMStateField[]) { | ||
393 | + [...], /* other migrated fields */ | ||
394 | + VMSTATE_CLOCK(clk, MyDeviceState), | ||
395 | + VMSTATE_END_OF_LIST() | ||
396 | + } | ||
397 | + }; | ||
398 | + | ||
399 | +The second solution is to restore the clock state using information already | ||
400 | +at our disposal. This can be used to restore output clock states using the | ||
401 | +device state. The functions ``clock_set[_ns|_hz]()`` can be used during the | ||
402 | +``post_load()`` migration callback. | ||
403 | + | ||
404 | +When adding clock support to an existing device, if you care about | ||
405 | +migration compatibility you will need to be careful, as simply adding | ||
406 | +a ``VMSTATE_CLOCK()`` line will break compatibility. Instead, you can | ||
407 | +put the ``VMSTATE_CLOCK()`` line into a vmstate subsection with a | ||
408 | +suitable ``needed`` function, and use ``clock_set()`` in a | ||
409 | +``pre_load()`` function to set the default value that will be used if | ||
410 | +the source virtual machine in the migration does not send the clock | ||
411 | +state. | ||
412 | + | ||
413 | +Care should be taken not to use ``clock_update[_ns|_hz]()`` or | ||
414 | +``clock_propagate()`` during the whole migration procedure because it | ||
415 | +will trigger side effects to other devices in an unknown state. | ||
416 | diff --git a/docs/devel/index.rst b/docs/devel/index.rst | ||
417 | index XXXXXXX..XXXXXXX 100644 | ||
418 | --- a/docs/devel/index.rst | ||
419 | +++ b/docs/devel/index.rst | ||
420 | @@ -XXX,XX +XXX,XX @@ Contents: | ||
421 | bitops | ||
422 | reset | ||
423 | s390-dasd-ipl | ||
424 | + clocks | ||
425 | -- | ||
426 | 2.20.1 | ||
427 | |||
428 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Damien Hedde <damien.hedde@greensocs.com> | ||
2 | 1 | ||
3 | Add the connection between the slcr's output clocks and the uarts inputs. | ||
4 | |||
5 | Also add the main board clock 'ps_clk', which is hard-coded to 33.33MHz | ||
6 | (the default frequency). This clock is used to feed the slcr's input | ||
7 | clock. | ||
8 | |||
9 | Signed-off-by: Damien Hedde <damien.hedde@greensocs.com> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
11 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
12 | Message-id: 20200406135251.157596-9-damien.hedde@greensocs.com | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | --- | ||
15 | hw/arm/xilinx_zynq.c | 57 +++++++++++++++++++++++++++++++++++++------- | ||
16 | 1 file changed, 49 insertions(+), 8 deletions(-) | ||
17 | |||
18 | diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/hw/arm/xilinx_zynq.c | ||
21 | +++ b/hw/arm/xilinx_zynq.c | ||
22 | @@ -XXX,XX +XXX,XX @@ | ||
23 | #include "hw/char/cadence_uart.h" | ||
24 | #include "hw/net/cadence_gem.h" | ||
25 | #include "hw/cpu/a9mpcore.h" | ||
26 | +#include "hw/qdev-clock.h" | ||
27 | +#include "sysemu/reset.h" | ||
28 | + | ||
29 | +#define TYPE_ZYNQ_MACHINE MACHINE_TYPE_NAME("xilinx-zynq-a9") | ||
30 | +#define ZYNQ_MACHINE(obj) \ | ||
31 | + OBJECT_CHECK(ZynqMachineState, (obj), TYPE_ZYNQ_MACHINE) | ||
32 | + | ||
33 | +/* board base frequency: 33.333333 MHz */ | ||
34 | +#define PS_CLK_FREQUENCY (100 * 1000 * 1000 / 3) | ||
35 | |||
36 | #define NUM_SPI_FLASHES 4 | ||
37 | #define NUM_QSPI_FLASHES 2 | ||
38 | @@ -XXX,XX +XXX,XX @@ static const int dma_irqs[8] = { | ||
39 | 0xe3401000 + ARMV7_IMM16(extract32((val), 16, 16)), /* movt r1 ... */ \ | ||
40 | 0xe5801000 + (addr) | ||
41 | |||
42 | +typedef struct ZynqMachineState { | ||
43 | + MachineState parent; | ||
44 | + Clock *ps_clk; | ||
45 | +} ZynqMachineState; | ||
46 | + | ||
47 | static void zynq_write_board_setup(ARMCPU *cpu, | ||
48 | const struct arm_boot_info *info) | ||
49 | { | ||
50 | @@ -XXX,XX +XXX,XX @@ static inline void zynq_init_spi_flashes(uint32_t base_addr, qemu_irq irq, | ||
51 | |||
52 | static void zynq_init(MachineState *machine) | ||
53 | { | ||
54 | + ZynqMachineState *zynq_machine = ZYNQ_MACHINE(machine); | ||
55 | ARMCPU *cpu; | ||
56 | MemoryRegion *address_space_mem = get_system_memory(); | ||
57 | MemoryRegion *ocm_ram = g_new(MemoryRegion, 1); | ||
58 | - DeviceState *dev; | ||
59 | + DeviceState *dev, *slcr; | ||
60 | SysBusDevice *busdev; | ||
61 | qemu_irq pic[64]; | ||
62 | int n; | ||
63 | @@ -XXX,XX +XXX,XX @@ static void zynq_init(MachineState *machine) | ||
64 | 1, 0x0066, 0x0022, 0x0000, 0x0000, 0x0555, 0x2aa, | ||
65 | 0); | ||
66 | |||
67 | - dev = qdev_create(NULL, "xilinx,zynq_slcr"); | ||
68 | - qdev_init_nofail(dev); | ||
69 | - sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, 0xF8000000); | ||
70 | + /* Create slcr, keep a pointer to connect clocks */ | ||
71 | + slcr = qdev_create(NULL, "xilinx,zynq_slcr"); | ||
72 | + qdev_init_nofail(slcr); | ||
73 | + sysbus_mmio_map(SYS_BUS_DEVICE(slcr), 0, 0xF8000000); | ||
74 | + | ||
75 | + /* Create the main clock source, and feed slcr with it */ | ||
76 | + zynq_machine->ps_clk = CLOCK(object_new(TYPE_CLOCK)); | ||
77 | + object_property_add_child(OBJECT(zynq_machine), "ps_clk", | ||
78 | + OBJECT(zynq_machine->ps_clk), &error_abort); | ||
79 | + object_unref(OBJECT(zynq_machine->ps_clk)); | ||
80 | + clock_set_hz(zynq_machine->ps_clk, PS_CLK_FREQUENCY); | ||
81 | + qdev_connect_clock_in(slcr, "ps_clk", zynq_machine->ps_clk); | ||
82 | |||
83 | dev = qdev_create(NULL, TYPE_A9MPCORE_PRIV); | ||
84 | qdev_prop_set_uint32(dev, "num-cpu", 1); | ||
85 | @@ -XXX,XX +XXX,XX @@ static void zynq_init(MachineState *machine) | ||
86 | sysbus_create_simple(TYPE_CHIPIDEA, 0xE0002000, pic[53 - IRQ_OFFSET]); | ||
87 | sysbus_create_simple(TYPE_CHIPIDEA, 0xE0003000, pic[76 - IRQ_OFFSET]); | ||
88 | |||
89 | - cadence_uart_create(0xE0000000, pic[59 - IRQ_OFFSET], serial_hd(0)); | ||
90 | - cadence_uart_create(0xE0001000, pic[82 - IRQ_OFFSET], serial_hd(1)); | ||
91 | + dev = cadence_uart_create(0xE0000000, pic[59 - IRQ_OFFSET], serial_hd(0)); | ||
92 | + qdev_connect_clock_in(dev, "refclk", | ||
93 | + qdev_get_clock_out(slcr, "uart0_ref_clk")); | ||
94 | + dev = cadence_uart_create(0xE0001000, pic[82 - IRQ_OFFSET], serial_hd(1)); | ||
95 | + qdev_connect_clock_in(dev, "refclk", | ||
96 | + qdev_get_clock_out(slcr, "uart1_ref_clk")); | ||
97 | |||
98 | sysbus_create_varargs("cadence_ttc", 0xF8001000, | ||
99 | pic[42-IRQ_OFFSET], pic[43-IRQ_OFFSET], pic[44-IRQ_OFFSET], NULL); | ||
100 | @@ -XXX,XX +XXX,XX @@ static void zynq_init(MachineState *machine) | ||
101 | arm_load_kernel(ARM_CPU(first_cpu), machine, &zynq_binfo); | ||
102 | } | ||
103 | |||
104 | -static void zynq_machine_init(MachineClass *mc) | ||
105 | +static void zynq_machine_class_init(ObjectClass *oc, void *data) | ||
106 | { | ||
107 | + MachineClass *mc = MACHINE_CLASS(oc); | ||
108 | mc->desc = "Xilinx Zynq Platform Baseboard for Cortex-A9"; | ||
109 | mc->init = zynq_init; | ||
110 | mc->max_cpus = 1; | ||
111 | @@ -XXX,XX +XXX,XX @@ static void zynq_machine_init(MachineClass *mc) | ||
112 | mc->default_ram_id = "zynq.ext_ram"; | ||
113 | } | ||
114 | |||
115 | -DEFINE_MACHINE("xilinx-zynq-a9", zynq_machine_init) | ||
116 | +static const TypeInfo zynq_machine_type = { | ||
117 | + .name = TYPE_ZYNQ_MACHINE, | ||
118 | + .parent = TYPE_MACHINE, | ||
119 | + .class_init = zynq_machine_class_init, | ||
120 | + .instance_size = sizeof(ZynqMachineState), | ||
121 | +}; | ||
122 | + | ||
123 | +static void zynq_machine_register_types(void) | ||
124 | +{ | ||
125 | + type_register_static(&zynq_machine_type); | ||
126 | +} | ||
127 | + | ||
128 | +type_init(zynq_machine_register_types) | ||
129 | -- | ||
130 | 2.20.1 | ||
131 | |||
132 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Ramon Fried <rfried.dev@gmail.com> | ||
2 | 1 | ||
3 | Wraparound of TX descriptor cyclic buffer only updated | ||
4 | the low 32 bits of the descriptor. | ||
5 | Fix that by checking if we're working with 64bit descriptors. | ||
6 | |||
7 | Signed-off-by: Ramon Fried <rfried.dev@gmail.com> | ||
8 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
9 | Message-id: 20200417171736.441607-1-rfried.dev@gmail.com | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | hw/net/cadence_gem.c | 9 ++++++++- | ||
13 | 1 file changed, 8 insertions(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/hw/net/cadence_gem.c b/hw/net/cadence_gem.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/net/cadence_gem.c | ||
18 | +++ b/hw/net/cadence_gem.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static void gem_transmit(CadenceGEMState *s) | ||
20 | /* read next descriptor */ | ||
21 | if (tx_desc_get_wrap(desc)) { | ||
22 | tx_desc_set_last(desc); | ||
23 | - packet_desc_addr = s->regs[GEM_TXQBASE]; | ||
24 | + | ||
25 | + if (s->regs[GEM_DMACFG] & GEM_DMACFG_ADDR_64B) { | ||
26 | + packet_desc_addr = s->regs[GEM_TBQPH]; | ||
27 | + packet_desc_addr <<= 32; | ||
28 | + } else { | ||
29 | + packet_desc_addr = 0; | ||
30 | + } | ||
31 | + packet_desc_addr |= s->regs[GEM_TXQBASE]; | ||
32 | } else { | ||
33 | packet_desc_addr += 4 * gem_get_desc_len(s, false); | ||
34 | } | ||
35 | -- | ||
36 | 2.20.1 | ||
37 | |||
38 | diff view generated by jsdifflib |
1 | From: "Edgar E. Iglesias" <edgar.iglesias@xilinx.com> | 1 | From: Alex Zuepke <alex.zuepke@tum.de> |
---|---|---|---|
2 | 2 | ||
3 | Allow name wildcards in qemu_fdt_node_path(). This is useful | 3 | The ARMv8 manual defines that PMUSERENR_EL0.ER enables read-access |
4 | to find all nodes with a given compatibility string. | 4 | to both PMXEVCNTR_EL0 and PMEVCNTR<n>_EL0 registers, however, |
5 | we only use it for PMXEVCNTR_EL0. Extend to PMEVCNTR<n>_EL0 as well. | ||
5 | 6 | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Signed-off-by: Alex Zuepke <alex.zuepke@tum.de> |
7 | Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | 8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20200423121114.4274-2-edgar.iglesias@gmail.com | 9 | Message-id: 20220428132717.84190-1-alex.zuepke@tum.de |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 11 | --- |
11 | include/sysemu/device_tree.h | 3 +++ | 12 | target/arm/helper.c | 4 ++-- |
12 | device_tree.c | 2 +- | 13 | 1 file changed, 2 insertions(+), 2 deletions(-) |
13 | 2 files changed, 4 insertions(+), 1 deletion(-) | ||
14 | 14 | ||
15 | diff --git a/include/sysemu/device_tree.h b/include/sysemu/device_tree.h | 15 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
16 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/include/sysemu/device_tree.h | 17 | --- a/target/arm/helper.c |
18 | +++ b/include/sysemu/device_tree.h | 18 | +++ b/target/arm/helper.c |
19 | @@ -XXX,XX +XXX,XX @@ void *load_device_tree_from_sysfs(void); | 19 | @@ -XXX,XX +XXX,XX @@ static void define_pmu_regs(ARMCPU *cpu) |
20 | * NULL. If there is no error but no matching node was found, the | 20 | .crm = 8 | (3 & (i >> 3)), .opc1 = 0, .opc2 = i & 7, |
21 | * returned array contains a single element equal to NULL. If an error | 21 | .access = PL0_RW, .type = ARM_CP_IO | ARM_CP_ALIAS, |
22 | * was encountered when parsing the blob, the function returns NULL | 22 | .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, |
23 | + * | 23 | - .accessfn = pmreg_access }, |
24 | + * @name may be NULL to wildcard names and only match compatibility | 24 | + .accessfn = pmreg_access_xevcntr }, |
25 | + * strings. | 25 | { .name = pmevcntr_el0_name, .state = ARM_CP_STATE_AA64, |
26 | */ | 26 | .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 8 | (3 & (i >> 3)), |
27 | char **qemu_fdt_node_path(void *fdt, const char *name, char *compat, | 27 | - .opc2 = i & 7, .access = PL0_RW, .accessfn = pmreg_access, |
28 | Error **errp); | 28 | + .opc2 = i & 7, .access = PL0_RW, .accessfn = pmreg_access_xevcntr, |
29 | diff --git a/device_tree.c b/device_tree.c | 29 | .type = ARM_CP_IO, |
30 | index XXXXXXX..XXXXXXX 100644 | 30 | .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, |
31 | --- a/device_tree.c | 31 | .raw_readfn = pmevcntr_rawread, |
32 | +++ b/device_tree.c | ||
33 | @@ -XXX,XX +XXX,XX @@ char **qemu_fdt_node_path(void *fdt, const char *name, char *compat, | ||
34 | offset = len; | ||
35 | break; | ||
36 | } | ||
37 | - if (!strcmp(iter_name, name)) { | ||
38 | + if (!name || !strcmp(iter_name, name)) { | ||
39 | char *path; | ||
40 | |||
41 | path = g_malloc(path_len); | ||
42 | -- | 32 | -- |
43 | 2.20.1 | 33 | 2.25.1 |
44 | |||
45 | diff view generated by jsdifflib |