1 | Arm queue; some of the simpler stuff, things other have reviewed (thanks!), etc. | 1 | A largish pull request: the big things are Richard's PAuth work |
---|---|---|---|
2 | and Aaron's PMU emulation improvements. | ||
2 | 3 | ||
4 | thanks | ||
3 | -- PMM | 5 | -- PMM |
4 | 6 | ||
5 | The following changes since commit 5d2f557b47dfbf8f23277a5bdd8473d4607c681a: | ||
6 | 7 | ||
7 | Merge remote-tracking branch 'remotes/kraxel/tags/vga-20200605-pull-request' into staging (2020-06-05 13:53:05 +0100) | 8 | The following changes since commit 681d61362d3f766a00806b89d6581869041f73cb: |
9 | |||
10 | Merge remote-tracking branch 'remotes/jnsnow/tags/bitmaps-pull-request' into staging (2019-01-17 12:48:42 +0000) | ||
8 | 11 | ||
9 | are available in the Git repository at: | 12 | are available in the Git repository at: |
10 | 13 | ||
11 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20200605 | 14 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20190118 |
12 | 15 | ||
13 | for you to fetch changes up to 2c35a39eda0b16c2ed85c94cec204bf5efb97812: | 16 | for you to fetch changes up to 2a0ed2804e2c77a1c4e255f05ab739618e05c85d: |
14 | 17 | ||
15 | target/arm: Convert Neon one-register-and-immediate insns to decodetree (2020-06-05 17:23:10 +0100) | 18 | tests/libqtest: Introduce qtest_init_with_serial() (2019-01-18 14:17:38 +0000) |
16 | 19 | ||
17 | ---------------------------------------------------------------- | 20 | ---------------------------------------------------------------- |
18 | target-arm queue: | 21 | target-arm queue: |
19 | hw/ssi/imx_spi: Handle tx burst lengths other than 8 correctly | 22 | * hw/char/stm32f2xx_usart: Do not update data register when device is disabled |
20 | hw/input/pxa2xx_keypad: Replace hw_error() by qemu_log_mask() | 23 | * hw/arm/virt-acpi-build: Set COHACC override flag in IORT SMMUv3 node |
21 | hw/arm/pxa2xx: Replace printf() call by qemu_log_mask() | 24 | * target/arm: Allow Aarch32 exception return to switch from Mon->Hyp |
22 | target/arm: Convert crypto insns to gvec | 25 | * ftgmac100: implement the new MDIO interface on Aspeed SoC |
23 | hw/adc/stm32f2xx_adc: Correct memory region size and access size | 26 | * implement the ARMv8.3-PAuth extension |
24 | tests/acceptance: Add a boot test for the xlnx-versal-virt machine | 27 | * improve emulation of the ARM PMU |
25 | docs/system: Document Aspeed boards | ||
26 | raspi: Add model of the USB controller | ||
27 | target/arm: Convert 2-reg-and-shift and 1-reg-imm Neon insns to decodetree | ||
28 | 28 | ||
29 | ---------------------------------------------------------------- | 29 | ---------------------------------------------------------------- |
30 | Aaron Lindsay (13): | ||
31 | migration: Add post_save function to VMStateDescription | ||
32 | target/arm: Reorganize PMCCNTR accesses | ||
33 | target/arm: Swap PMU values before/after migrations | ||
34 | target/arm: Filter cycle counter based on PMCCFILTR_EL0 | ||
35 | target/arm: Allow AArch32 access for PMCCFILTR | ||
36 | target/arm: Implement PMOVSSET | ||
37 | target/arm: Define FIELDs for ID_DFR0 | ||
38 | target/arm: Make PMCEID[01]_EL0 64 bit registers, add PMCEID[23] | ||
39 | target/arm: Add array for supported PMU events, generate PMCEID[01]_EL0 | ||
40 | target/arm: Finish implementation of PM[X]EVCNTR and PM[X]EVTYPER | ||
41 | target/arm: PMU: Add instruction and cycle events | ||
42 | target/arm: PMU: Set PMCR.N to 4 | ||
43 | target/arm: Implement PMSWINC | ||
44 | |||
45 | Alexander Graf (1): | ||
46 | target/arm: Allow Aarch32 exception return to switch from Mon->Hyp | ||
47 | |||
30 | Cédric Le Goater (1): | 48 | Cédric Le Goater (1): |
31 | docs/system: Document Aspeed boards | 49 | ftgmac100: implement the new MDIO interface on Aspeed SoC |
32 | 50 | ||
33 | Eden Mikitas (2): | 51 | Eric Auger (1): |
34 | hw/ssi/imx_spi: changed while statement to prevent underflow | 52 | hw/arm/virt-acpi-build: Set COHACC override flag in IORT SMMUv3 node |
35 | hw/ssi/imx_spi: Removed unnecessary cast of rx data received from slave | ||
36 | 53 | ||
37 | Paul Zimmerman (7): | 54 | Julia Suvorova (1): |
38 | raspi: add BCM2835 SOC MPHI emulation | 55 | tests/libqtest: Introduce qtest_init_with_serial() |
39 | dwc-hsotg (dwc2) USB host controller register definitions | ||
40 | dwc-hsotg (dwc2) USB host controller state definitions | ||
41 | dwc-hsotg (dwc2) USB host controller emulation | ||
42 | usb: add short-packet handling to usb-storage driver | ||
43 | wire in the dwc-hsotg (dwc2) USB host controller emulation | ||
44 | raspi2 acceptance test: add test for dwc-hsotg (dwc2) USB host | ||
45 | 56 | ||
46 | Peter Maydell (9): | 57 | Philippe Mathieu-Daudé (1): |
47 | target/arm: Convert Neon VSHL and VSLI 2-reg-shift insn to decodetree | 58 | hw/char/stm32f2xx_usart: Do not update data register when device is disabled |
48 | target/arm: Convert Neon VSHR 2-reg-shift insns to decodetree | ||
49 | target/arm: Convert Neon VSRA, VSRI, VRSHR, VRSRA 2-reg-shift insns to decodetree | ||
50 | target/arm: Convert VQSHLU, VQSHL 2-reg-shift insns to decodetree | ||
51 | target/arm: Convert Neon narrowing shifts with op==8 to decodetree | ||
52 | target/arm: Convert Neon narrowing shifts with op==9 to decodetree | ||
53 | target/arm: Convert Neon VSHLL, VMOVL to decodetree | ||
54 | target/arm: Convert VCVT fixed-point ops to decodetree | ||
55 | target/arm: Convert Neon one-register-and-immediate insns to decodetree | ||
56 | 59 | ||
57 | Philippe Mathieu-Daudé (3): | 60 | Richard Henderson (31): |
58 | hw/input/pxa2xx_keypad: Replace hw_error() by qemu_log_mask() | 61 | target/arm: Add state for the ARMv8.3-PAuth extension |
59 | hw/arm/pxa2xx: Replace printf() call by qemu_log_mask() | 62 | target/arm: Add SCTLR bits through ARMv8.5 |
60 | hw/adc/stm32f2xx_adc: Correct memory region size and access size | 63 | target/arm: Add PAuth active bit to tbflags |
64 | target/arm: Introduce raise_exception_ra | ||
65 | target/arm: Add PAuth helpers | ||
66 | target/arm: Decode PAuth within system hint space | ||
67 | target/arm: Rearrange decode in disas_data_proc_1src | ||
68 | target/arm: Decode PAuth within disas_data_proc_1src | ||
69 | target/arm: Decode PAuth within disas_data_proc_2src | ||
70 | target/arm: Move helper_exception_return to helper-a64.c | ||
71 | target/arm: Add new_pc argument to helper_exception_return | ||
72 | target/arm: Rearrange decode in disas_uncond_b_reg | ||
73 | target/arm: Decode PAuth within disas_uncond_b_reg | ||
74 | target/arm: Decode Load/store register (pac) | ||
75 | target/arm: Move cpu_mmu_index out of line | ||
76 | target/arm: Introduce arm_mmu_idx | ||
77 | target/arm: Introduce arm_stage1_mmu_idx | ||
78 | target/arm: Create ARMVAParameters and helpers | ||
79 | target/arm: Merge TBFLAG_AA_TB{0, 1} to TBII | ||
80 | target/arm: Export aa64_va_parameters to internals.h | ||
81 | target/arm: Add aa64_va_parameters_both | ||
82 | target/arm: Decode TBID from TCR | ||
83 | target/arm: Reuse aa64_va_parameters for setting tbflags | ||
84 | target/arm: Implement pauth_strip | ||
85 | target/arm: Implement pauth_auth | ||
86 | target/arm: Implement pauth_addpac | ||
87 | target/arm: Implement pauth_computepac | ||
88 | target/arm: Add PAuth system registers | ||
89 | target/arm: Enable PAuth for -cpu max | ||
90 | target/arm: Enable PAuth for user-only | ||
91 | target/arm: Tidy TBI handling in gen_a64_set_pc | ||
61 | 92 | ||
62 | Richard Henderson (6): | 93 | target/arm/Makefile.objs | 1 + |
63 | target/arm: Convert aes and sm4 to gvec helpers | 94 | include/hw/acpi/acpi-defs.h | 2 + |
64 | target/arm: Convert rax1 to gvec helpers | 95 | include/migration/vmstate.h | 1 + |
65 | target/arm: Convert sha512 and sm3 to gvec helpers | 96 | target/arm/cpu.h | 244 +++++---- |
66 | target/arm: Convert sha1 and sha256 to gvec helpers | 97 | target/arm/helper-a64.h | 14 + |
67 | target/arm: Split helper_crypto_sha1_3reg | 98 | target/arm/helper.h | 1 - |
68 | target/arm: Split helper_crypto_sm3tt | 99 | target/arm/internals.h | 77 +++ |
100 | target/arm/translate.h | 5 +- | ||
101 | tests/libqtest.h | 11 + | ||
102 | hw/arm/virt-acpi-build.c | 1 + | ||
103 | hw/char/stm32f2xx_usart.c | 3 +- | ||
104 | hw/net/ftgmac100.c | 80 ++- | ||
105 | migration/vmstate.c | 13 +- | ||
106 | target/arm/cpu.c | 19 +- | ||
107 | target/arm/cpu64.c | 68 ++- | ||
108 | target/arm/helper-a64.c | 155 ++++++ | ||
109 | target/arm/helper.c | 1222 +++++++++++++++++++++++++++++++++---------- | ||
110 | target/arm/machine.c | 24 + | ||
111 | target/arm/op_helper.c | 174 +----- | ||
112 | target/arm/pauth_helper.c | 497 ++++++++++++++++++ | ||
113 | target/arm/translate-a64.c | 537 ++++++++++++++++--- | ||
114 | tests/libqtest.c | 26 + | ||
115 | docs/devel/migration.rst | 9 +- | ||
116 | 23 files changed, 2552 insertions(+), 632 deletions(-) | ||
117 | create mode 100644 target/arm/pauth_helper.c | ||
69 | 118 | ||
70 | Thomas Huth (1): | ||
71 | tests/acceptance: Add a boot test for the xlnx-versal-virt machine | ||
72 | |||
73 | docs/system/arm/aspeed.rst | 85 ++ | ||
74 | docs/system/target-arm.rst | 1 + | ||
75 | hw/usb/hcd-dwc2.h | 190 +++++ | ||
76 | include/hw/arm/bcm2835_peripherals.h | 5 +- | ||
77 | include/hw/misc/bcm2835_mphi.h | 44 + | ||
78 | include/hw/usb/dwc2-regs.h | 899 ++++++++++++++++++++ | ||
79 | target/arm/helper.h | 45 +- | ||
80 | target/arm/translate-a64.h | 3 + | ||
81 | target/arm/vec_internal.h | 33 + | ||
82 | target/arm/neon-dp.decode | 214 ++++- | ||
83 | hw/adc/stm32f2xx_adc.c | 4 +- | ||
84 | hw/arm/bcm2835_peripherals.c | 38 +- | ||
85 | hw/arm/pxa2xx.c | 66 +- | ||
86 | hw/input/pxa2xx_keypad.c | 10 +- | ||
87 | hw/misc/bcm2835_mphi.c | 191 +++++ | ||
88 | hw/ssi/imx_spi.c | 4 +- | ||
89 | hw/usb/dev-storage.c | 15 +- | ||
90 | hw/usb/hcd-dwc2.c | 1417 ++++++++++++++++++++++++++++++++ | ||
91 | target/arm/crypto_helper.c | 267 ++++-- | ||
92 | target/arm/translate-a64.c | 198 ++--- | ||
93 | target/arm/translate-neon.inc.c | 796 ++++++++++++++---- | ||
94 | target/arm/translate.c | 539 +----------- | ||
95 | target/arm/vec_helper.c | 12 +- | ||
96 | hw/misc/Makefile.objs | 1 + | ||
97 | hw/usb/Kconfig | 5 + | ||
98 | hw/usb/Makefile.objs | 1 + | ||
99 | hw/usb/trace-events | 50 ++ | ||
100 | tests/acceptance/boot_linux_console.py | 35 +- | ||
101 | 28 files changed, 4258 insertions(+), 910 deletions(-) | ||
102 | create mode 100644 docs/system/arm/aspeed.rst | ||
103 | create mode 100644 hw/usb/hcd-dwc2.h | ||
104 | create mode 100644 include/hw/misc/bcm2835_mphi.h | ||
105 | create mode 100644 include/hw/usb/dwc2-regs.h | ||
106 | create mode 100644 target/arm/vec_internal.h | ||
107 | create mode 100644 hw/misc/bcm2835_mphi.c | ||
108 | create mode 100644 hw/usb/hcd-dwc2.c | ||
109 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
1 | 2 | ||
3 | When the device is disabled, the internal circuitry keeps the data | ||
4 | register loaded and doesn't update it. | ||
5 | |||
6 | Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
8 | Message-id: 20190104182057.8778-1-philmd@redhat.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/char/stm32f2xx_usart.c | 3 +-- | ||
12 | 1 file changed, 1 insertion(+), 2 deletions(-) | ||
13 | |||
14 | diff --git a/hw/char/stm32f2xx_usart.c b/hw/char/stm32f2xx_usart.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/char/stm32f2xx_usart.c | ||
17 | +++ b/hw/char/stm32f2xx_usart.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static void stm32f2xx_usart_receive(void *opaque, const uint8_t *buf, int size) | ||
19 | { | ||
20 | STM32F2XXUsartState *s = opaque; | ||
21 | |||
22 | - s->usart_dr = *buf; | ||
23 | - | ||
24 | if (!(s->usart_cr1 & USART_CR1_UE && s->usart_cr1 & USART_CR1_RE)) { | ||
25 | /* USART not enabled - drop the chars */ | ||
26 | DB_PRINT("Dropping the chars\n"); | ||
27 | return; | ||
28 | } | ||
29 | |||
30 | + s->usart_dr = *buf; | ||
31 | s->usart_sr |= USART_SR_RXNE; | ||
32 | |||
33 | if (s->usart_cr1 & USART_CR1_RXNEIE) { | ||
34 | -- | ||
35 | 2.20.1 | ||
36 | |||
37 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Eric Auger <eric.auger@redhat.com> | ||
1 | 2 | ||
3 | Let's report IO-coherent access is supported for translation | ||
4 | table walks, descriptor fetches and queues by setting the COHACC | ||
5 | override flag. Without that, we observe wrong command opcodes. | ||
6 | The DT description also advertises the dma coherency. | ||
7 | |||
8 | Fixes a703b4f6c1ee ("hw/arm/virt-acpi-build: Add smmuv3 node in IORT table") | ||
9 | |||
10 | Signed-off-by: Eric Auger <eric.auger@redhat.com> | ||
11 | Reported-by: Shameerali Kolothum Thodi <shameerali.kolothum.thodi@huawei.com> | ||
12 | Tested-by: Shameer Kolothum <shameerali.kolothum.thodi@huawei.com> | ||
13 | Reviewed-by: Andrew Jones <drjones@redhat.com> | ||
14 | Message-id: 20190107101041.765-1-eric.auger@redhat.com | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | --- | ||
17 | include/hw/acpi/acpi-defs.h | 2 ++ | ||
18 | hw/arm/virt-acpi-build.c | 1 + | ||
19 | 2 files changed, 3 insertions(+) | ||
20 | |||
21 | diff --git a/include/hw/acpi/acpi-defs.h b/include/hw/acpi/acpi-defs.h | ||
22 | index XXXXXXX..XXXXXXX 100644 | ||
23 | --- a/include/hw/acpi/acpi-defs.h | ||
24 | +++ b/include/hw/acpi/acpi-defs.h | ||
25 | @@ -XXX,XX +XXX,XX @@ struct AcpiIortItsGroup { | ||
26 | } QEMU_PACKED; | ||
27 | typedef struct AcpiIortItsGroup AcpiIortItsGroup; | ||
28 | |||
29 | +#define ACPI_IORT_SMMU_V3_COHACC_OVERRIDE 1 | ||
30 | + | ||
31 | struct AcpiIortSmmu3 { | ||
32 | ACPI_IORT_NODE_HEADER_DEF | ||
33 | uint64_t base_address; | ||
34 | diff --git a/hw/arm/virt-acpi-build.c b/hw/arm/virt-acpi-build.c | ||
35 | index XXXXXXX..XXXXXXX 100644 | ||
36 | --- a/hw/arm/virt-acpi-build.c | ||
37 | +++ b/hw/arm/virt-acpi-build.c | ||
38 | @@ -XXX,XX +XXX,XX @@ build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) | ||
39 | smmu->mapping_count = cpu_to_le32(1); | ||
40 | smmu->mapping_offset = cpu_to_le32(sizeof(*smmu)); | ||
41 | smmu->base_address = cpu_to_le64(vms->memmap[VIRT_SMMU].base); | ||
42 | + smmu->flags = cpu_to_le32(ACPI_IORT_SMMU_V3_COHACC_OVERRIDE); | ||
43 | smmu->event_gsiv = cpu_to_le32(irq); | ||
44 | smmu->pri_gsiv = cpu_to_le32(irq + 1); | ||
45 | smmu->gerr_gsiv = cpu_to_le32(irq + 2); | ||
46 | -- | ||
47 | 2.20.1 | ||
48 | |||
49 | diff view generated by jsdifflib |
1 | From: Eden Mikitas <e.mikitas@gmail.com> | 1 | From: Alexander Graf <agraf@suse.de> |
---|---|---|---|
2 | 2 | ||
3 | When inserting the value retrieved (rx) from the spi slave, rx is pushed to | 3 | In U-boot, we switch from S-SVC -> Mon -> Hyp mode when we want to |
4 | rx_fifo after being cast to uint8_t. rx_fifo is a fifo32, and the rx | 4 | enter Hyp mode. The change into Hyp mode is done by doing an |
5 | register the driver uses is also 32 bit. This zeroes the 24 most | 5 | exception return from Mon. This doesn't work with current QEMU. |
6 | significant bits of rx. This proved problematic with devices that expect to | ||
7 | use the whole 32 bits of the rx register. | ||
8 | 6 | ||
9 | Signed-off-by: Eden Mikitas <e.mikitas@gmail.com> | 7 | The problem is that in bad_mode_switch() we refuse to allow |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 8 | the change of mode. |
9 | |||
10 | Note that bad_mode_switch() is used to do validation for two situations: | ||
11 | |||
12 | (1) changes to mode by instructions writing to CPSR.M | ||
13 | (ie not exception take/return) -- this corresponds to the | ||
14 | Armv8 Arm ARM pseudocode Arch32.WriteModeByInstr | ||
15 | (2) changes to mode by exception return | ||
16 | |||
17 | Attempting to enter or leave Hyp mode via case (1) is forbidden in | ||
18 | v8 and UNPREDICTABLE in v7, and QEMU is correct to disallow it | ||
19 | there. However, we're already doing that check at the top of the | ||
20 | bad_mode_switch() function, so if that passes then we should allow | ||
21 | the case (2) exception return mode changes to switch into Hyp mode. | ||
22 | |||
23 | We want to test whether we're trying to return to the nonexistent | ||
24 | "secure Hyp" mode, so we need to look at arm_is_secure_below_el3() | ||
25 | rather than arm_is_secure(), since the latter is always true if | ||
26 | we're in Mon (EL3). | ||
27 | |||
28 | Signed-off-by: Alexander Graf <agraf@suse.de> | ||
29 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
30 | Message-id: 20190109152430.32359-1-agraf@suse.de | ||
31 | [PMM: rewrote commit message] | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 32 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 33 | --- |
13 | hw/ssi/imx_spi.c | 2 +- | 34 | target/arm/helper.c | 2 +- |
14 | 1 file changed, 1 insertion(+), 1 deletion(-) | 35 | 1 file changed, 1 insertion(+), 1 deletion(-) |
15 | 36 | ||
16 | diff --git a/hw/ssi/imx_spi.c b/hw/ssi/imx_spi.c | 37 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
17 | index XXXXXXX..XXXXXXX 100644 | 38 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/ssi/imx_spi.c | 39 | --- a/target/arm/helper.c |
19 | +++ b/hw/ssi/imx_spi.c | 40 | +++ b/target/arm/helper.c |
20 | @@ -XXX,XX +XXX,XX @@ static void imx_spi_flush_txfifo(IMXSPIState *s) | 41 | @@ -XXX,XX +XXX,XX @@ static int bad_mode_switch(CPUARMState *env, int mode, CPSRWriteType write_type) |
21 | if (fifo32_is_full(&s->rx_fifo)) { | 42 | return 0; |
22 | s->regs[ECSPI_STATREG] |= ECSPI_STATREG_RO; | 43 | case ARM_CPU_MODE_HYP: |
23 | } else { | 44 | return !arm_feature(env, ARM_FEATURE_EL2) |
24 | - fifo32_push(&s->rx_fifo, (uint8_t)rx); | 45 | - || arm_current_el(env) < 2 || arm_is_secure(env); |
25 | + fifo32_push(&s->rx_fifo, rx); | 46 | + || arm_current_el(env) < 2 || arm_is_secure_below_el3(env); |
26 | } | 47 | case ARM_CPU_MODE_MON: |
27 | 48 | return arm_current_el(env) < 3; | |
28 | if (s->burst_length <= 0) { | 49 | default: |
29 | -- | 50 | -- |
30 | 2.20.1 | 51 | 2.20.1 |
31 | 52 | ||
32 | 53 | diff view generated by jsdifflib |
1 | Convert the VSHLL and VMOVL insns from the 2-reg-shift group | 1 | From: Cédric Le Goater <clg@kaod.org> |
---|---|---|---|
2 | to decodetree. Since the loop always has two passes, we unroll | ||
3 | it to avoid the awkward reassignment of one TCGv to another. | ||
4 | 2 | ||
3 | The PHY behind the MAC of an Aspeed SoC can be controlled using two | ||
4 | different MDC/MDIO interfaces. The same registers PHYCR (MAC60) and | ||
5 | PHYDATA (MAC64) are involved but they have a different layout. | ||
6 | |||
7 | BIT31 of the Feature Register (MAC40) controls which MDC/MDIO | ||
8 | interface is active. | ||
9 | |||
10 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | ||
11 | Reviewed-by: Andrew Jeffery <andrew@aj.id.au> | ||
12 | Reviewed-by: Joel Stanley <joel@jms.id.au> | ||
13 | Message-id: 20190111125759.31577-1-clg@kaod.org | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20200522145520.6778-8-peter.maydell@linaro.org | ||
8 | --- | 15 | --- |
9 | target/arm/neon-dp.decode | 16 +++++++ | 16 | hw/net/ftgmac100.c | 80 +++++++++++++++++++++++++++++++++++++++------- |
10 | target/arm/translate-neon.inc.c | 81 +++++++++++++++++++++++++++++++++ | 17 | 1 file changed, 68 insertions(+), 12 deletions(-) |
11 | target/arm/translate.c | 46 +------------------ | ||
12 | 3 files changed, 99 insertions(+), 44 deletions(-) | ||
13 | 18 | ||
14 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | 19 | diff --git a/hw/net/ftgmac100.c b/hw/net/ftgmac100.c |
15 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/neon-dp.decode | 21 | --- a/hw/net/ftgmac100.c |
17 | +++ b/target/arm/neon-dp.decode | 22 | +++ b/hw/net/ftgmac100.c |
18 | @@ -XXX,XX +XXX,XX @@ VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp | 23 | @@ -XXX,XX +XXX,XX @@ |
19 | &2reg_shift vm=%vm_dp vd=%vd_dp size=1 q=0 \ | 24 | #define FTGMAC100_PHYDATA_MIIWDATA(x) ((x) & 0xffff) |
20 | shift=%neon_rshift_i3 | 25 | #define FTGMAC100_PHYDATA_MIIRDATA(x) (((x) >> 16) & 0xffff) |
21 | 26 | ||
22 | +# Long left shifts: again Q is part of opcode decode | 27 | +/* |
23 | +@2reg_shll_s .... ... . . . 1 shift:5 .... .... 0 . . . .... \ | 28 | + * PHY control register - New MDC/MDIO interface |
24 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=2 q=0 | 29 | + */ |
25 | +@2reg_shll_h .... ... . . . 01 shift:4 .... .... 0 . . . .... \ | 30 | +#define FTGMAC100_PHYCR_NEW_DATA(x) (((x) >> 16) & 0xffff) |
26 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=1 q=0 | 31 | +#define FTGMAC100_PHYCR_NEW_FIRE (1 << 15) |
27 | +@2reg_shll_b .... ... . . . 001 shift:3 .... .... 0 . . . .... \ | 32 | +#define FTGMAC100_PHYCR_NEW_ST_22 (1 << 12) |
28 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=0 q=0 | 33 | +#define FTGMAC100_PHYCR_NEW_OP(x) (((x) >> 10) & 3) |
34 | +#define FTGMAC100_PHYCR_NEW_OP_WRITE 0x1 | ||
35 | +#define FTGMAC100_PHYCR_NEW_OP_READ 0x2 | ||
36 | +#define FTGMAC100_PHYCR_NEW_DEV(x) (((x) >> 5) & 0x1f) | ||
37 | +#define FTGMAC100_PHYCR_NEW_REG(x) ((x) & 0x1f) | ||
29 | + | 38 | + |
30 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_d | 39 | /* |
31 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_s | 40 | * Feature Register |
32 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_h | 41 | */ |
33 | @@ -XXX,XX +XXX,XX @@ VQSHRN_U16_2sh 1111 001 1 1 . ...... .... 1001 . 0 . 1 .... @2reg_shrn_h | 42 | @@ -XXX,XX +XXX,XX @@ static void phy_reset(FTGMAC100State *s) |
34 | VQRSHRN_U64_2sh 1111 001 1 1 . ...... .... 1001 . 1 . 1 .... @2reg_shrn_d | 43 | s->phy_int = 0; |
35 | VQRSHRN_U32_2sh 1111 001 1 1 . ...... .... 1001 . 1 . 1 .... @2reg_shrn_s | 44 | } |
36 | VQRSHRN_U16_2sh 1111 001 1 1 . ...... .... 1001 . 1 . 1 .... @2reg_shrn_h | 45 | |
46 | -static uint32_t do_phy_read(FTGMAC100State *s, int reg) | ||
47 | +static uint16_t do_phy_read(FTGMAC100State *s, uint8_t reg) | ||
48 | { | ||
49 | - uint32_t val; | ||
50 | + uint16_t val; | ||
51 | |||
52 | switch (reg) { | ||
53 | case MII_BMCR: /* Basic Control */ | ||
54 | @@ -XXX,XX +XXX,XX @@ static uint32_t do_phy_read(FTGMAC100State *s, int reg) | ||
55 | MII_BMCR_FD | MII_BMCR_CTST) | ||
56 | #define MII_ANAR_MASK 0x2d7f | ||
57 | |||
58 | -static void do_phy_write(FTGMAC100State *s, int reg, uint32_t val) | ||
59 | +static void do_phy_write(FTGMAC100State *s, uint8_t reg, uint16_t val) | ||
60 | { | ||
61 | switch (reg) { | ||
62 | case MII_BMCR: /* Basic Control */ | ||
63 | @@ -XXX,XX +XXX,XX @@ static void do_phy_write(FTGMAC100State *s, int reg, uint32_t val) | ||
64 | } | ||
65 | } | ||
66 | |||
67 | +static void do_phy_new_ctl(FTGMAC100State *s) | ||
68 | +{ | ||
69 | + uint8_t reg; | ||
70 | + uint16_t data; | ||
37 | + | 71 | + |
38 | +VSHLL_S_2sh 1111 001 0 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_s | 72 | + if (!(s->phycr & FTGMAC100_PHYCR_NEW_ST_22)) { |
39 | +VSHLL_S_2sh 1111 001 0 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_h | 73 | + qemu_log_mask(LOG_UNIMP, "%s: unsupported ST code\n", __func__); |
40 | +VSHLL_S_2sh 1111 001 0 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_b | 74 | + return; |
41 | + | ||
42 | +VSHLL_U_2sh 1111 001 1 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_s | ||
43 | +VSHLL_U_2sh 1111 001 1 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_h | ||
44 | +VSHLL_U_2sh 1111 001 1 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_b | ||
45 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/target/arm/translate-neon.inc.c | ||
48 | +++ b/target/arm/translate-neon.inc.c | ||
49 | @@ -XXX,XX +XXX,XX @@ DO_2SN_32(VQSHRN_U16, gen_helper_neon_shl_u16, gen_helper_neon_narrow_sat_u8) | ||
50 | DO_2SN_64(VQRSHRN_U64, gen_helper_neon_rshl_u64, gen_helper_neon_narrow_sat_u32) | ||
51 | DO_2SN_32(VQRSHRN_U32, gen_helper_neon_rshl_u32, gen_helper_neon_narrow_sat_u16) | ||
52 | DO_2SN_32(VQRSHRN_U16, gen_helper_neon_rshl_u16, gen_helper_neon_narrow_sat_u8) | ||
53 | + | ||
54 | +static bool do_vshll_2sh(DisasContext *s, arg_2reg_shift *a, | ||
55 | + NeonGenWidenFn *widenfn, bool u) | ||
56 | +{ | ||
57 | + TCGv_i64 tmp; | ||
58 | + TCGv_i32 rm0, rm1; | ||
59 | + uint64_t widen_mask = 0; | ||
60 | + | ||
61 | + if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | ||
62 | + return false; | ||
63 | + } | 75 | + } |
64 | + | 76 | + |
65 | + /* UNDEF accesses to D16-D31 if they don't exist. */ | 77 | + /* Nothing to do */ |
66 | + if (!dc_isar_feature(aa32_simd_r32, s) && | 78 | + if (!(s->phycr & FTGMAC100_PHYCR_NEW_FIRE)) { |
67 | + ((a->vd | a->vm) & 0x10)) { | 79 | + return; |
68 | + return false; | ||
69 | + } | 80 | + } |
70 | + | 81 | + |
71 | + if (a->vd & 1) { | 82 | + reg = FTGMAC100_PHYCR_NEW_REG(s->phycr); |
72 | + return false; | 83 | + data = FTGMAC100_PHYCR_NEW_DATA(s->phycr); |
84 | + | ||
85 | + switch (FTGMAC100_PHYCR_NEW_OP(s->phycr)) { | ||
86 | + case FTGMAC100_PHYCR_NEW_OP_WRITE: | ||
87 | + do_phy_write(s, reg, data); | ||
88 | + break; | ||
89 | + case FTGMAC100_PHYCR_NEW_OP_READ: | ||
90 | + s->phydata = do_phy_read(s, reg) & 0xffff; | ||
91 | + break; | ||
92 | + default: | ||
93 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: invalid OP code %08x\n", | ||
94 | + __func__, s->phycr); | ||
73 | + } | 95 | + } |
74 | + | 96 | + |
75 | + if (!vfp_access_check(s)) { | 97 | + s->phycr &= ~FTGMAC100_PHYCR_NEW_FIRE; |
76 | + return true; | ||
77 | + } | ||
78 | + | ||
79 | + /* | ||
80 | + * This is a widen-and-shift operation. The shift is always less | ||
81 | + * than the width of the source type, so after widening the input | ||
82 | + * vector we can simply shift the whole 64-bit widened register, | ||
83 | + * and then clear the potential overflow bits resulting from left | ||
84 | + * bits of the narrow input appearing as right bits of the left | ||
85 | + * neighbour narrow input. Calculate a mask of bits to clear. | ||
86 | + */ | ||
87 | + if ((a->shift != 0) && (a->size < 2 || u)) { | ||
88 | + int esize = 8 << a->size; | ||
89 | + widen_mask = MAKE_64BIT_MASK(0, esize); | ||
90 | + widen_mask >>= esize - a->shift; | ||
91 | + widen_mask = dup_const(a->size + 1, widen_mask); | ||
92 | + } | ||
93 | + | ||
94 | + rm0 = neon_load_reg(a->vm, 0); | ||
95 | + rm1 = neon_load_reg(a->vm, 1); | ||
96 | + tmp = tcg_temp_new_i64(); | ||
97 | + | ||
98 | + widenfn(tmp, rm0); | ||
99 | + if (a->shift != 0) { | ||
100 | + tcg_gen_shli_i64(tmp, tmp, a->shift); | ||
101 | + tcg_gen_andi_i64(tmp, tmp, ~widen_mask); | ||
102 | + } | ||
103 | + neon_store_reg64(tmp, a->vd); | ||
104 | + | ||
105 | + widenfn(tmp, rm1); | ||
106 | + if (a->shift != 0) { | ||
107 | + tcg_gen_shli_i64(tmp, tmp, a->shift); | ||
108 | + tcg_gen_andi_i64(tmp, tmp, ~widen_mask); | ||
109 | + } | ||
110 | + neon_store_reg64(tmp, a->vd + 1); | ||
111 | + tcg_temp_free_i64(tmp); | ||
112 | + return true; | ||
113 | +} | 98 | +} |
114 | + | 99 | + |
115 | +static bool trans_VSHLL_S_2sh(DisasContext *s, arg_2reg_shift *a) | 100 | +static void do_phy_ctl(FTGMAC100State *s) |
116 | +{ | 101 | +{ |
117 | + NeonGenWidenFn *widenfn[] = { | 102 | + uint8_t reg = FTGMAC100_PHYCR_REG(s->phycr); |
118 | + gen_helper_neon_widen_s8, | 103 | + |
119 | + gen_helper_neon_widen_s16, | 104 | + if (s->phycr & FTGMAC100_PHYCR_MIIWR) { |
120 | + tcg_gen_ext_i32_i64, | 105 | + do_phy_write(s, reg, s->phydata & 0xffff); |
121 | + }; | 106 | + s->phycr &= ~FTGMAC100_PHYCR_MIIWR; |
122 | + return do_vshll_2sh(s, a, widenfn[a->size], false); | 107 | + } else if (s->phycr & FTGMAC100_PHYCR_MIIRD) { |
108 | + s->phydata = do_phy_read(s, reg) << 16; | ||
109 | + s->phycr &= ~FTGMAC100_PHYCR_MIIRD; | ||
110 | + } else { | ||
111 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: no OP code %08x\n", | ||
112 | + __func__, s->phycr); | ||
113 | + } | ||
123 | +} | 114 | +} |
124 | + | 115 | + |
125 | +static bool trans_VSHLL_U_2sh(DisasContext *s, arg_2reg_shift *a) | 116 | static int ftgmac100_read_bd(FTGMAC100Desc *bd, dma_addr_t addr) |
126 | +{ | 117 | { |
127 | + NeonGenWidenFn *widenfn[] = { | 118 | if (dma_memory_read(&address_space_memory, addr, bd, sizeof(*bd))) { |
128 | + gen_helper_neon_widen_u8, | 119 | @@ -XXX,XX +XXX,XX @@ static void ftgmac100_write(void *opaque, hwaddr addr, |
129 | + gen_helper_neon_widen_u16, | 120 | uint64_t value, unsigned size) |
130 | + tcg_gen_extu_i32_i64, | 121 | { |
131 | + }; | 122 | FTGMAC100State *s = FTGMAC100(opaque); |
132 | + return do_vshll_2sh(s, a, widenfn[a->size], true); | 123 | - int reg; |
133 | +} | 124 | |
134 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 125 | switch (addr & 0xff) { |
135 | index XXXXXXX..XXXXXXX 100644 | 126 | case FTGMAC100_ISR: /* Interrupt status */ |
136 | --- a/target/arm/translate.c | 127 | @@ -XXX,XX +XXX,XX @@ static void ftgmac100_write(void *opaque, hwaddr addr, |
137 | +++ b/target/arm/translate.c | 128 | break; |
138 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 129 | |
139 | case 7: /* VQSHL */ | 130 | case FTGMAC100_PHYCR: /* PHY Device control */ |
140 | case 8: /* VSHRN, VRSHRN, VQSHRUN, VQRSHRUN */ | 131 | - reg = FTGMAC100_PHYCR_REG(value); |
141 | case 9: /* VQSHRN, VQRSHRN */ | 132 | s->phycr = value; |
142 | + case 10: /* VSHLL, including VMOVL */ | 133 | - if (value & FTGMAC100_PHYCR_MIIWR) { |
143 | return 1; /* handled by decodetree */ | 134 | - do_phy_write(s, reg, s->phydata & 0xffff); |
144 | default: | 135 | - s->phycr &= ~FTGMAC100_PHYCR_MIIWR; |
145 | break; | 136 | + if (s->revr & FTGMAC100_REVR_NEW_MDIO_INTERFACE) { |
146 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 137 | + do_phy_new_ctl(s); |
147 | size--; | 138 | } else { |
148 | } | 139 | - s->phydata = do_phy_read(s, reg) << 16; |
149 | shift = (insn >> 16) & ((1 << (3 + size)) - 1); | 140 | - s->phycr &= ~FTGMAC100_PHYCR_MIIRD; |
150 | - if (op == 10) { | 141 | + do_phy_ctl(s); |
151 | - /* VSHLL, VMOVL */ | 142 | } |
152 | - if (q || (rd & 1)) { | 143 | break; |
153 | - return 1; | 144 | case FTGMAC100_PHYDATA: |
154 | - } | 145 | @@ -XXX,XX +XXX,XX @@ static void ftgmac100_write(void *opaque, hwaddr addr, |
155 | - tmp = neon_load_reg(rm, 0); | 146 | s->dblac = value; |
156 | - tmp2 = neon_load_reg(rm, 1); | 147 | break; |
157 | - for (pass = 0; pass < 2; pass++) { | 148 | case FTGMAC100_REVR: /* Feature Register */ |
158 | - if (pass == 1) | 149 | - /* TODO: Only Old MDIO interface is supported */ |
159 | - tmp = tmp2; | 150 | - s->revr = value & ~FTGMAC100_REVR_NEW_MDIO_INTERFACE; |
160 | - | 151 | + s->revr = value; |
161 | - gen_neon_widen(cpu_V0, tmp, size, u); | 152 | break; |
162 | - | 153 | case FTGMAC100_FEAR1: /* Feature Register 1 */ |
163 | - if (shift != 0) { | 154 | s->fear1 = value; |
164 | - /* The shift is less than the width of the source | ||
165 | - type, so we can just shift the whole register. */ | ||
166 | - tcg_gen_shli_i64(cpu_V0, cpu_V0, shift); | ||
167 | - /* Widen the result of shift: we need to clear | ||
168 | - * the potential overflow bits resulting from | ||
169 | - * left bits of the narrow input appearing as | ||
170 | - * right bits of left the neighbour narrow | ||
171 | - * input. */ | ||
172 | - if (size < 2 || !u) { | ||
173 | - uint64_t imm64; | ||
174 | - if (size == 0) { | ||
175 | - imm = (0xffu >> (8 - shift)); | ||
176 | - imm |= imm << 16; | ||
177 | - } else if (size == 1) { | ||
178 | - imm = 0xffff >> (16 - shift); | ||
179 | - } else { | ||
180 | - /* size == 2 */ | ||
181 | - imm = 0xffffffff >> (32 - shift); | ||
182 | - } | ||
183 | - if (size < 2) { | ||
184 | - imm64 = imm | (((uint64_t)imm) << 32); | ||
185 | - } else { | ||
186 | - imm64 = imm; | ||
187 | - } | ||
188 | - tcg_gen_andi_i64(cpu_V0, cpu_V0, ~imm64); | ||
189 | - } | ||
190 | - } | ||
191 | - neon_store_reg64(cpu_V0, rd + pass); | ||
192 | - } | ||
193 | - } else if (op >= 14) { | ||
194 | + if (op >= 14) { | ||
195 | /* VCVT fixed-point. */ | ||
196 | TCGv_ptr fpst; | ||
197 | TCGv_i32 shiftv; | ||
198 | -- | 155 | -- |
199 | 2.20.1 | 156 | 2.20.1 |
200 | 157 | ||
201 | 158 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | Add storage space for the 5 encryption keys. | ||
4 | |||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20190108223129.5570-2-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | target/arm/cpu.h | 30 +++++++++++++++++++++++++++++- | ||
11 | 1 file changed, 29 insertions(+), 1 deletion(-) | ||
12 | |||
13 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/arm/cpu.h | ||
16 | +++ b/target/arm/cpu.h | ||
17 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMVectorReg { | ||
18 | uint64_t d[2 * ARM_MAX_VQ] QEMU_ALIGNED(16); | ||
19 | } ARMVectorReg; | ||
20 | |||
21 | -/* In AArch32 mode, predicate registers do not exist at all. */ | ||
22 | #ifdef TARGET_AARCH64 | ||
23 | +/* In AArch32 mode, predicate registers do not exist at all. */ | ||
24 | typedef struct ARMPredicateReg { | ||
25 | uint64_t p[2 * ARM_MAX_VQ / 8] QEMU_ALIGNED(16); | ||
26 | } ARMPredicateReg; | ||
27 | + | ||
28 | +/* In AArch32 mode, PAC keys do not exist at all. */ | ||
29 | +typedef struct ARMPACKey { | ||
30 | + uint64_t lo, hi; | ||
31 | +} ARMPACKey; | ||
32 | #endif | ||
33 | |||
34 | |||
35 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | ||
36 | uint32_t cregs[16]; | ||
37 | } iwmmxt; | ||
38 | |||
39 | +#ifdef TARGET_AARCH64 | ||
40 | + ARMPACKey apia_key; | ||
41 | + ARMPACKey apib_key; | ||
42 | + ARMPACKey apda_key; | ||
43 | + ARMPACKey apdb_key; | ||
44 | + ARMPACKey apga_key; | ||
45 | +#endif | ||
46 | + | ||
47 | #if defined(CONFIG_USER_ONLY) | ||
48 | /* For usermode syscall translation. */ | ||
49 | int eabi; | ||
50 | @@ -XXX,XX +XXX,XX @@ static inline bool isar_feature_aa64_fcma(const ARMISARegisters *id) | ||
51 | return FIELD_EX64(id->id_aa64isar1, ID_AA64ISAR1, FCMA) != 0; | ||
52 | } | ||
53 | |||
54 | +static inline bool isar_feature_aa64_pauth(const ARMISARegisters *id) | ||
55 | +{ | ||
56 | + /* | ||
57 | + * Note that while QEMU will only implement the architected algorithm | ||
58 | + * QARMA, and thus APA+GPA, the host cpu for kvm may use implementation | ||
59 | + * defined algorithms, and thus API+GPI, and this predicate controls | ||
60 | + * migration of the 128-bit keys. | ||
61 | + */ | ||
62 | + return (id->id_aa64isar1 & | ||
63 | + (FIELD_DP64(0, ID_AA64ISAR1, APA, -1) | | ||
64 | + FIELD_DP64(0, ID_AA64ISAR1, API, -1) | | ||
65 | + FIELD_DP64(0, ID_AA64ISAR1, GPA, -1) | | ||
66 | + FIELD_DP64(0, ID_AA64ISAR1, GPI, -1))) != 0; | ||
67 | +} | ||
68 | + | ||
69 | static inline bool isar_feature_aa64_fp16(const ARMISARegisters *id) | ||
70 | { | ||
71 | /* We always set the AdvSIMD and FP fields identically wrt FP16. */ | ||
72 | -- | ||
73 | 2.20.1 | ||
74 | |||
75 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | Post v8.4 bits taken from SysReg_v85_xml-00bet8. | ||
4 | |||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20190108223129.5570-3-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | target/arm/cpu.h | 45 +++++++++++++++++++++++++++++++++------------ | ||
11 | 1 file changed, 33 insertions(+), 12 deletions(-) | ||
12 | |||
13 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/arm/cpu.h | ||
16 | +++ b/target/arm/cpu.h | ||
17 | @@ -XXX,XX +XXX,XX @@ void pmccntr_sync(CPUARMState *env); | ||
18 | #define SCTLR_A (1U << 1) | ||
19 | #define SCTLR_C (1U << 2) | ||
20 | #define SCTLR_W (1U << 3) /* up to v6; RAO in v7 */ | ||
21 | -#define SCTLR_SA (1U << 3) | ||
22 | +#define SCTLR_nTLSMD_32 (1U << 3) /* v8.2-LSMAOC, AArch32 only */ | ||
23 | +#define SCTLR_SA (1U << 3) /* AArch64 only */ | ||
24 | #define SCTLR_P (1U << 4) /* up to v5; RAO in v6 and v7 */ | ||
25 | +#define SCTLR_LSMAOE_32 (1U << 4) /* v8.2-LSMAOC, AArch32 only */ | ||
26 | #define SCTLR_SA0 (1U << 4) /* v8 onward, AArch64 only */ | ||
27 | #define SCTLR_D (1U << 5) /* up to v5; RAO in v6 */ | ||
28 | #define SCTLR_CP15BEN (1U << 5) /* v7 onward */ | ||
29 | #define SCTLR_L (1U << 6) /* up to v5; RAO in v6 and v7; RAZ in v8 */ | ||
30 | +#define SCTLR_nAA (1U << 6) /* when v8.4-LSE is implemented */ | ||
31 | #define SCTLR_B (1U << 7) /* up to v6; RAZ in v7 */ | ||
32 | #define SCTLR_ITD (1U << 7) /* v8 onward */ | ||
33 | #define SCTLR_S (1U << 8) /* up to v6; RAZ in v7 */ | ||
34 | @@ -XXX,XX +XXX,XX @@ void pmccntr_sync(CPUARMState *env); | ||
35 | #define SCTLR_R (1U << 9) /* up to v6; RAZ in v7 */ | ||
36 | #define SCTLR_UMA (1U << 9) /* v8 onward, AArch64 only */ | ||
37 | #define SCTLR_F (1U << 10) /* up to v6 */ | ||
38 | -#define SCTLR_SW (1U << 10) /* v7 onward */ | ||
39 | -#define SCTLR_Z (1U << 11) | ||
40 | +#define SCTLR_SW (1U << 10) /* v7, RES0 in v8 */ | ||
41 | +#define SCTLR_Z (1U << 11) /* in v7, RES1 in v8 */ | ||
42 | +#define SCTLR_EOS (1U << 11) /* v8.5-ExS */ | ||
43 | #define SCTLR_I (1U << 12) | ||
44 | -#define SCTLR_V (1U << 13) | ||
45 | +#define SCTLR_V (1U << 13) /* AArch32 only */ | ||
46 | +#define SCTLR_EnDB (1U << 13) /* v8.3, AArch64 only */ | ||
47 | #define SCTLR_RR (1U << 14) /* up to v7 */ | ||
48 | #define SCTLR_DZE (1U << 14) /* v8 onward, AArch64 only */ | ||
49 | #define SCTLR_L4 (1U << 15) /* up to v6; RAZ in v7 */ | ||
50 | #define SCTLR_UCT (1U << 15) /* v8 onward, AArch64 only */ | ||
51 | #define SCTLR_DT (1U << 16) /* up to ??, RAO in v6 and v7 */ | ||
52 | #define SCTLR_nTWI (1U << 16) /* v8 onward */ | ||
53 | -#define SCTLR_HA (1U << 17) | ||
54 | +#define SCTLR_HA (1U << 17) /* up to v7, RES0 in v8 */ | ||
55 | #define SCTLR_BR (1U << 17) /* PMSA only */ | ||
56 | #define SCTLR_IT (1U << 18) /* up to ??, RAO in v6 and v7 */ | ||
57 | #define SCTLR_nTWE (1U << 18) /* v8 onward */ | ||
58 | #define SCTLR_WXN (1U << 19) | ||
59 | #define SCTLR_ST (1U << 20) /* up to ??, RAZ in v6 */ | ||
60 | -#define SCTLR_UWXN (1U << 20) /* v7 onward */ | ||
61 | -#define SCTLR_FI (1U << 21) | ||
62 | -#define SCTLR_U (1U << 22) | ||
63 | +#define SCTLR_UWXN (1U << 20) /* v7 onward, AArch32 only */ | ||
64 | +#define SCTLR_FI (1U << 21) /* up to v7, v8 RES0 */ | ||
65 | +#define SCTLR_IESB (1U << 21) /* v8.2-IESB, AArch64 only */ | ||
66 | +#define SCTLR_U (1U << 22) /* up to v6, RAO in v7 */ | ||
67 | +#define SCTLR_EIS (1U << 22) /* v8.5-ExS */ | ||
68 | #define SCTLR_XP (1U << 23) /* up to v6; v7 onward RAO */ | ||
69 | +#define SCTLR_SPAN (1U << 23) /* v8.1-PAN */ | ||
70 | #define SCTLR_VE (1U << 24) /* up to v7 */ | ||
71 | #define SCTLR_E0E (1U << 24) /* v8 onward, AArch64 only */ | ||
72 | #define SCTLR_EE (1U << 25) | ||
73 | #define SCTLR_L2 (1U << 26) /* up to v6, RAZ in v7 */ | ||
74 | #define SCTLR_UCI (1U << 26) /* v8 onward, AArch64 only */ | ||
75 | -#define SCTLR_NMFI (1U << 27) | ||
76 | -#define SCTLR_TRE (1U << 28) | ||
77 | -#define SCTLR_AFE (1U << 29) | ||
78 | -#define SCTLR_TE (1U << 30) | ||
79 | +#define SCTLR_NMFI (1U << 27) /* up to v7, RAZ in v7VE and v8 */ | ||
80 | +#define SCTLR_EnDA (1U << 27) /* v8.3, AArch64 only */ | ||
81 | +#define SCTLR_TRE (1U << 28) /* AArch32 only */ | ||
82 | +#define SCTLR_nTLSMD_64 (1U << 28) /* v8.2-LSMAOC, AArch64 only */ | ||
83 | +#define SCTLR_AFE (1U << 29) /* AArch32 only */ | ||
84 | +#define SCTLR_LSMAOE_64 (1U << 29) /* v8.2-LSMAOC, AArch64 only */ | ||
85 | +#define SCTLR_TE (1U << 30) /* AArch32 only */ | ||
86 | +#define SCTLR_EnIB (1U << 30) /* v8.3, AArch64 only */ | ||
87 | +#define SCTLR_EnIA (1U << 31) /* v8.3, AArch64 only */ | ||
88 | +#define SCTLR_BT0 (1ULL << 35) /* v8.5-BTI */ | ||
89 | +#define SCTLR_BT1 (1ULL << 36) /* v8.5-BTI */ | ||
90 | +#define SCTLR_ITFSB (1ULL << 37) /* v8.5-MemTag */ | ||
91 | +#define SCTLR_TCF0 (3ULL << 38) /* v8.5-MemTag */ | ||
92 | +#define SCTLR_TCF (3ULL << 40) /* v8.5-MemTag */ | ||
93 | +#define SCTLR_ATA0 (1ULL << 42) /* v8.5-MemTag */ | ||
94 | +#define SCTLR_ATA (1ULL << 43) /* v8.5-MemTag */ | ||
95 | +#define SCTLR_DSSBS (1ULL << 44) /* v8.5 */ | ||
96 | |||
97 | #define CPTR_TCPAC (1U << 31) | ||
98 | #define CPTR_TTA (1U << 20) | ||
99 | -- | ||
100 | 2.20.1 | ||
101 | |||
102 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | There are 5 bits of state that could be added, but to save | ||
4 | space within tbflags, add only a single enable bit. | ||
5 | Helpers will determine the rest of the state at runtime. | ||
6 | |||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20190108223129.5570-4-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | target/arm/cpu.h | 1 + | ||
13 | target/arm/translate.h | 2 ++ | ||
14 | target/arm/helper.c | 19 +++++++++++++++++++ | ||
15 | target/arm/translate-a64.c | 1 + | ||
16 | 4 files changed, 23 insertions(+) | ||
17 | |||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/arm/cpu.h | ||
21 | +++ b/target/arm/cpu.h | ||
22 | @@ -XXX,XX +XXX,XX @@ FIELD(TBFLAG_A64, TBI0, 0, 1) | ||
23 | FIELD(TBFLAG_A64, TBI1, 1, 1) | ||
24 | FIELD(TBFLAG_A64, SVEEXC_EL, 2, 2) | ||
25 | FIELD(TBFLAG_A64, ZCR_LEN, 4, 4) | ||
26 | +FIELD(TBFLAG_A64, PAUTH_ACTIVE, 8, 1) | ||
27 | |||
28 | static inline bool bswap_code(bool sctlr_b) | ||
29 | { | ||
30 | diff --git a/target/arm/translate.h b/target/arm/translate.h | ||
31 | index XXXXXXX..XXXXXXX 100644 | ||
32 | --- a/target/arm/translate.h | ||
33 | +++ b/target/arm/translate.h | ||
34 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | ||
35 | bool is_ldex; | ||
36 | /* True if a single-step exception will be taken to the current EL */ | ||
37 | bool ss_same_el; | ||
38 | + /* True if v8.3-PAuth is active. */ | ||
39 | + bool pauth_active; | ||
40 | /* Bottom two bits of XScale c15_cpar coprocessor access control reg */ | ||
41 | int c15_cpar; | ||
42 | /* TCG op of the current insn_start. */ | ||
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 @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
48 | flags = FIELD_DP32(flags, TBFLAG_A64, SVEEXC_EL, sve_el); | ||
49 | flags = FIELD_DP32(flags, TBFLAG_A64, ZCR_LEN, zcr_len); | ||
50 | } | ||
51 | + | ||
52 | + if (cpu_isar_feature(aa64_pauth, cpu)) { | ||
53 | + /* | ||
54 | + * In order to save space in flags, we record only whether | ||
55 | + * pauth is "inactive", meaning all insns are implemented as | ||
56 | + * a nop, or "active" when some action must be performed. | ||
57 | + * The decision of which action to take is left to a helper. | ||
58 | + */ | ||
59 | + uint64_t sctlr; | ||
60 | + if (current_el == 0) { | ||
61 | + /* FIXME: ARMv8.1-VHE S2 translation regime. */ | ||
62 | + sctlr = env->cp15.sctlr_el[1]; | ||
63 | + } else { | ||
64 | + sctlr = env->cp15.sctlr_el[current_el]; | ||
65 | + } | ||
66 | + if (sctlr & (SCTLR_EnIA | SCTLR_EnIB | SCTLR_EnDA | SCTLR_EnDB)) { | ||
67 | + flags = FIELD_DP32(flags, TBFLAG_A64, PAUTH_ACTIVE, 1); | ||
68 | + } | ||
69 | + } | ||
70 | } else { | ||
71 | *pc = env->regs[15]; | ||
72 | flags = FIELD_DP32(flags, TBFLAG_A32, THUMB, env->thumb); | ||
73 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
74 | index XXXXXXX..XXXXXXX 100644 | ||
75 | --- a/target/arm/translate-a64.c | ||
76 | +++ b/target/arm/translate-a64.c | ||
77 | @@ -XXX,XX +XXX,XX @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, | ||
78 | dc->fp_excp_el = FIELD_EX32(tb_flags, TBFLAG_ANY, FPEXC_EL); | ||
79 | dc->sve_excp_el = FIELD_EX32(tb_flags, TBFLAG_A64, SVEEXC_EL); | ||
80 | dc->sve_len = (FIELD_EX32(tb_flags, TBFLAG_A64, ZCR_LEN) + 1) * 16; | ||
81 | + dc->pauth_active = FIELD_EX32(tb_flags, TBFLAG_A64, PAUTH_ACTIVE); | ||
82 | dc->vec_len = 0; | ||
83 | dc->vec_stride = 0; | ||
84 | dc->cp_regs = arm_cpu->cp_regs; | ||
85 | -- | ||
86 | 2.20.1 | ||
87 | |||
88 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | This path uses cpu_loop_exit_restore to unwind current processor state. | ||
4 | |||
5 | Suggested-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Message-id: 20190108223129.5570-5-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | target/arm/internals.h | 7 +++++++ | ||
12 | target/arm/op_helper.c | 19 +++++++++++++++++-- | ||
13 | 2 files changed, 24 insertions(+), 2 deletions(-) | ||
14 | |||
15 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/arm/internals.h | ||
18 | +++ b/target/arm/internals.h | ||
19 | @@ -XXX,XX +XXX,XX @@ FIELD(V7M_EXCRET, RES1, 7, 25) /* including the must-be-1 prefix */ | ||
20 | void QEMU_NORETURN raise_exception(CPUARMState *env, uint32_t excp, | ||
21 | uint32_t syndrome, uint32_t target_el); | ||
22 | |||
23 | +/* | ||
24 | + * Similarly, but also use unwinding to restore cpu state. | ||
25 | + */ | ||
26 | +void QEMU_NORETURN raise_exception_ra(CPUARMState *env, uint32_t excp, | ||
27 | + uint32_t syndrome, uint32_t target_el, | ||
28 | + uintptr_t ra); | ||
29 | + | ||
30 | /* | ||
31 | * For AArch64, map a given EL to an index in the banked_spsr array. | ||
32 | * Note that this mapping and the AArch32 mapping defined in bank_number() | ||
33 | diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/target/arm/op_helper.c | ||
36 | +++ b/target/arm/op_helper.c | ||
37 | @@ -XXX,XX +XXX,XX @@ | ||
38 | #define SIGNBIT (uint32_t)0x80000000 | ||
39 | #define SIGNBIT64 ((uint64_t)1 << 63) | ||
40 | |||
41 | -void raise_exception(CPUARMState *env, uint32_t excp, | ||
42 | - uint32_t syndrome, uint32_t target_el) | ||
43 | +static CPUState *do_raise_exception(CPUARMState *env, uint32_t excp, | ||
44 | + uint32_t syndrome, uint32_t target_el) | ||
45 | { | ||
46 | CPUState *cs = CPU(arm_env_get_cpu(env)); | ||
47 | |||
48 | @@ -XXX,XX +XXX,XX @@ void raise_exception(CPUARMState *env, uint32_t excp, | ||
49 | cs->exception_index = excp; | ||
50 | env->exception.syndrome = syndrome; | ||
51 | env->exception.target_el = target_el; | ||
52 | + | ||
53 | + return cs; | ||
54 | +} | ||
55 | + | ||
56 | +void raise_exception(CPUARMState *env, uint32_t excp, | ||
57 | + uint32_t syndrome, uint32_t target_el) | ||
58 | +{ | ||
59 | + CPUState *cs = do_raise_exception(env, excp, syndrome, target_el); | ||
60 | cpu_loop_exit(cs); | ||
61 | } | ||
62 | |||
63 | +void raise_exception_ra(CPUARMState *env, uint32_t excp, uint32_t syndrome, | ||
64 | + uint32_t target_el, uintptr_t ra) | ||
65 | +{ | ||
66 | + CPUState *cs = do_raise_exception(env, excp, syndrome, target_el); | ||
67 | + cpu_loop_exit_restore(cs, ra); | ||
68 | +} | ||
69 | + | ||
70 | static int exception_target_el(CPUARMState *env) | ||
71 | { | ||
72 | int target_el = MAX(1, arm_current_el(env)); | ||
73 | -- | ||
74 | 2.20.1 | ||
75 | |||
76 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | With this conversion, we will be able to use the same helpers | 3 | The cryptographic internals are stubbed out for now, |
4 | with sve. In particular, pass 3 vector parameters for the | 4 | but the enable and trap bits are checked. |
5 | 3-operand operations; for advsimd the destination register | ||
6 | is also an input. | ||
7 | |||
8 | This also fixes a bug in which we failed to clear the high bits | ||
9 | of the SVE register after an AdvSIMD operation. | ||
10 | 5 | ||
11 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
12 | Message-id: 20200514212831.31248-2-richard.henderson@linaro.org | ||
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Message-id: 20190108223129.5570-6-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 | target/arm/helper.h | 6 ++-- | 11 | target/arm/Makefile.objs | 1 + |
17 | target/arm/vec_internal.h | 33 +++++++++++++++++ | 12 | target/arm/helper-a64.h | 12 +++ |
18 | target/arm/crypto_helper.c | 72 +++++++++++++++++++++++++++----------- | 13 | target/arm/internals.h | 6 ++ |
19 | target/arm/translate-a64.c | 55 ++++++++++++++++++----------- | 14 | target/arm/pauth_helper.c | 186 ++++++++++++++++++++++++++++++++++++++ |
20 | target/arm/translate.c | 27 +++++++------- | 15 | 4 files changed, 205 insertions(+) |
21 | target/arm/vec_helper.c | 12 +------ | 16 | create mode 100644 target/arm/pauth_helper.c |
22 | 6 files changed, 138 insertions(+), 67 deletions(-) | 17 | |
23 | create mode 100644 target/arm/vec_internal.h | 18 | diff --git a/target/arm/Makefile.objs b/target/arm/Makefile.objs |
24 | |||
25 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
26 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
27 | --- a/target/arm/helper.h | 20 | --- a/target/arm/Makefile.objs |
28 | +++ b/target/arm/helper.h | 21 | +++ b/target/arm/Makefile.objs |
29 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(neon_qzip8, TCG_CALL_NO_RWG, void, ptr, ptr) | 22 | @@ -XXX,XX +XXX,XX @@ obj-y += translate.o op_helper.o helper.o cpu.o |
30 | DEF_HELPER_FLAGS_2(neon_qzip16, TCG_CALL_NO_RWG, void, ptr, ptr) | 23 | obj-y += neon_helper.o iwmmxt_helper.o vec_helper.o |
31 | DEF_HELPER_FLAGS_2(neon_qzip32, TCG_CALL_NO_RWG, void, ptr, ptr) | 24 | obj-y += gdbstub.o |
32 | 25 | obj-$(TARGET_AARCH64) += cpu64.o translate-a64.o helper-a64.o gdbstub64.o | |
33 | -DEF_HELPER_FLAGS_3(crypto_aese, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | 26 | +obj-$(TARGET_AARCH64) += pauth_helper.o |
34 | +DEF_HELPER_FLAGS_4(crypto_aese, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 27 | obj-y += crypto_helper.o |
35 | DEF_HELPER_FLAGS_3(crypto_aesmc, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | 28 | obj-$(CONFIG_SOFTMMU) += arm-powerctl.o |
36 | 29 | ||
37 | DEF_HELPER_FLAGS_4(crypto_sha1_3reg, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 30 | diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h |
38 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) | 31 | index XXXXXXX..XXXXXXX 100644 |
39 | DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 32 | --- a/target/arm/helper-a64.h |
40 | DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 33 | +++ b/target/arm/helper-a64.h |
41 | 34 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(advsimd_rinth, f16, f16, ptr) | |
42 | -DEF_HELPER_FLAGS_2(crypto_sm4e, TCG_CALL_NO_RWG, void, ptr, ptr) | 35 | DEF_HELPER_2(advsimd_f16tosinth, i32, f16, ptr) |
43 | -DEF_HELPER_FLAGS_3(crypto_sm4ekey, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 36 | DEF_HELPER_2(advsimd_f16touinth, i32, f16, ptr) |
44 | +DEF_HELPER_FLAGS_4(crypto_sm4e, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 37 | DEF_HELPER_2(sqrt_f16, f16, f16, ptr) |
45 | +DEF_HELPER_FLAGS_4(crypto_sm4ekey, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 38 | + |
46 | 39 | +DEF_HELPER_FLAGS_3(pacia, TCG_CALL_NO_WG, i64, env, i64, i64) | |
47 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 40 | +DEF_HELPER_FLAGS_3(pacib, TCG_CALL_NO_WG, i64, env, i64, i64) |
48 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | 41 | +DEF_HELPER_FLAGS_3(pacda, TCG_CALL_NO_WG, i64, env, i64, i64) |
49 | diff --git a/target/arm/vec_internal.h b/target/arm/vec_internal.h | 42 | +DEF_HELPER_FLAGS_3(pacdb, TCG_CALL_NO_WG, i64, env, i64, i64) |
43 | +DEF_HELPER_FLAGS_3(pacga, TCG_CALL_NO_WG, i64, env, i64, i64) | ||
44 | +DEF_HELPER_FLAGS_3(autia, TCG_CALL_NO_WG, i64, env, i64, i64) | ||
45 | +DEF_HELPER_FLAGS_3(autib, TCG_CALL_NO_WG, i64, env, i64, i64) | ||
46 | +DEF_HELPER_FLAGS_3(autda, TCG_CALL_NO_WG, i64, env, i64, i64) | ||
47 | +DEF_HELPER_FLAGS_3(autdb, TCG_CALL_NO_WG, i64, env, i64, i64) | ||
48 | +DEF_HELPER_FLAGS_2(xpaci, TCG_CALL_NO_RWG_SE, i64, env, i64) | ||
49 | +DEF_HELPER_FLAGS_2(xpacd, TCG_CALL_NO_RWG_SE, i64, env, i64) | ||
50 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
51 | index XXXXXXX..XXXXXXX 100644 | ||
52 | --- a/target/arm/internals.h | ||
53 | +++ b/target/arm/internals.h | ||
54 | @@ -XXX,XX +XXX,XX @@ enum arm_exception_class { | ||
55 | EC_CP14DTTRAP = 0x06, | ||
56 | EC_ADVSIMDFPACCESSTRAP = 0x07, | ||
57 | EC_FPIDTRAP = 0x08, | ||
58 | + EC_PACTRAP = 0x09, | ||
59 | EC_CP14RRTTRAP = 0x0c, | ||
60 | EC_ILLEGALSTATE = 0x0e, | ||
61 | EC_AA32_SVC = 0x11, | ||
62 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t syn_sve_access_trap(void) | ||
63 | return EC_SVEACCESSTRAP << ARM_EL_EC_SHIFT; | ||
64 | } | ||
65 | |||
66 | +static inline uint32_t syn_pactrap(void) | ||
67 | +{ | ||
68 | + return EC_PACTRAP << ARM_EL_EC_SHIFT; | ||
69 | +} | ||
70 | + | ||
71 | static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int fsc) | ||
72 | { | ||
73 | return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
74 | diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c | ||
50 | new file mode 100644 | 75 | new file mode 100644 |
51 | index XXXXXXX..XXXXXXX | 76 | index XXXXXXX..XXXXXXX |
52 | --- /dev/null | 77 | --- /dev/null |
53 | +++ b/target/arm/vec_internal.h | 78 | +++ b/target/arm/pauth_helper.c |
54 | @@ -XXX,XX +XXX,XX @@ | 79 | @@ -XXX,XX +XXX,XX @@ |
55 | +/* | 80 | +/* |
56 | + * ARM AdvSIMD / SVE Vector Helpers | 81 | + * ARM v8.3-PAuth Operations |
57 | + * | 82 | + * |
58 | + * Copyright (c) 2020 Linaro | 83 | + * Copyright (c) 2019 Linaro, Ltd. |
59 | + * | 84 | + * |
60 | + * This library is free software; you can redistribute it and/or | 85 | + * This library is free software; you can redistribute it and/or |
61 | + * modify it under the terms of the GNU Lesser General Public | 86 | + * modify it under the terms of the GNU Lesser General Public |
62 | + * License as published by the Free Software Foundation; either | 87 | + * License as published by the Free Software Foundation; either |
63 | + * version 2 of the License, or (at your option) any later version. | 88 | + * version 2 of the License, or (at your option) any later version. |
... | ... | ||
69 | + * | 94 | + * |
70 | + * You should have received a copy of the GNU Lesser General Public | 95 | + * You should have received a copy of the GNU Lesser General Public |
71 | + * License along with this library; if not, see <http://www.gnu.org/licenses/>. | 96 | + * License along with this library; if not, see <http://www.gnu.org/licenses/>. |
72 | + */ | 97 | + */ |
73 | + | 98 | + |
74 | +#ifndef TARGET_ARM_VEC_INTERNALS_H | 99 | +#include "qemu/osdep.h" |
75 | +#define TARGET_ARM_VEC_INTERNALS_H | 100 | +#include "cpu.h" |
76 | + | 101 | +#include "internals.h" |
77 | +static inline void clear_tail(void *vd, uintptr_t opr_sz, uintptr_t max_sz) | 102 | +#include "exec/exec-all.h" |
78 | +{ | 103 | +#include "exec/cpu_ldst.h" |
79 | + uint64_t *d = vd + opr_sz; | 104 | +#include "exec/helper-proto.h" |
80 | + uintptr_t i; | ||
81 | + | ||
82 | + for (i = opr_sz; i < max_sz; i += 8) { | ||
83 | + *d++ = 0; | ||
84 | + } | ||
85 | +} | ||
86 | + | ||
87 | +#endif /* TARGET_ARM_VEC_INTERNALS_H */ | ||
88 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
89 | index XXXXXXX..XXXXXXX 100644 | ||
90 | --- a/target/arm/crypto_helper.c | ||
91 | +++ b/target/arm/crypto_helper.c | ||
92 | @@ -XXX,XX +XXX,XX @@ | ||
93 | |||
94 | #include "cpu.h" | ||
95 | #include "exec/helper-proto.h" | ||
96 | +#include "tcg/tcg-gvec-desc.h" | 105 | +#include "tcg/tcg-gvec-desc.h" |
97 | #include "crypto/aes.h" | 106 | + |
98 | +#include "vec_internal.h" | 107 | + |
99 | 108 | +static uint64_t pauth_computepac(uint64_t data, uint64_t modifier, | |
100 | union CRYPTO_STATE { | 109 | + ARMPACKey key) |
101 | uint8_t bytes[16]; | 110 | +{ |
102 | @@ -XXX,XX +XXX,XX @@ union CRYPTO_STATE { | 111 | + g_assert_not_reached(); /* FIXME */ |
103 | #define CR_ST_WORD(state, i) (state.words[i]) | 112 | +} |
104 | #endif | 113 | + |
105 | 114 | +static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, | |
106 | -void HELPER(crypto_aese)(void *vd, void *vm, uint32_t decrypt) | 115 | + ARMPACKey *key, bool data) |
107 | +static void do_crypto_aese(uint64_t *rd, uint64_t *rn, | 116 | +{ |
108 | + uint64_t *rm, bool decrypt) | 117 | + g_assert_not_reached(); /* FIXME */ |
109 | { | 118 | +} |
110 | static uint8_t const * const sbox[2] = { AES_sbox, AES_isbox }; | 119 | + |
111 | static uint8_t const * const shift[2] = { AES_shifts, AES_ishifts }; | 120 | +static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifier, |
112 | - uint64_t *rd = vd; | 121 | + ARMPACKey *key, bool data, int keynumber) |
113 | - uint64_t *rm = vm; | 122 | +{ |
114 | union CRYPTO_STATE rk = { .l = { rm[0], rm[1] } }; | 123 | + g_assert_not_reached(); /* FIXME */ |
115 | - union CRYPTO_STATE st = { .l = { rd[0], rd[1] } }; | 124 | +} |
116 | + union CRYPTO_STATE st = { .l = { rn[0], rn[1] } }; | 125 | + |
117 | int i; | 126 | +static uint64_t pauth_strip(CPUARMState *env, uint64_t ptr, bool data) |
118 | 127 | +{ | |
119 | - assert(decrypt < 2); | 128 | + g_assert_not_reached(); /* FIXME */ |
120 | - | 129 | +} |
121 | /* xor state vector with round key */ | 130 | + |
122 | rk.l[0] ^= st.l[0]; | 131 | +static void QEMU_NORETURN pauth_trap(CPUARMState *env, int target_el, |
123 | rk.l[1] ^= st.l[1]; | 132 | + uintptr_t ra) |
124 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_aese)(void *vd, void *vm, uint32_t decrypt) | 133 | +{ |
125 | rd[1] = st.l[1]; | 134 | + raise_exception_ra(env, EXCP_UDEF, syn_pactrap(), target_el, ra); |
126 | } | 135 | +} |
127 | 136 | + | |
128 | -void HELPER(crypto_aesmc)(void *vd, void *vm, uint32_t decrypt) | 137 | +static void pauth_check_trap(CPUARMState *env, int el, uintptr_t ra) |
129 | +void HELPER(crypto_aese)(void *vd, void *vn, void *vm, uint32_t desc) | 138 | +{ |
130 | +{ | 139 | + if (el < 2 && arm_feature(env, ARM_FEATURE_EL2)) { |
131 | + intptr_t i, opr_sz = simd_oprsz(desc); | 140 | + uint64_t hcr = arm_hcr_el2_eff(env); |
132 | + bool decrypt = simd_data(desc); | 141 | + bool trap = !(hcr & HCR_API); |
133 | + | 142 | + /* FIXME: ARMv8.1-VHE: trap only applies to EL1&0 regime. */ |
134 | + for (i = 0; i < opr_sz; i += 16) { | 143 | + /* FIXME: ARMv8.3-NV: HCR_NV trap takes precedence for ERETA[AB]. */ |
135 | + do_crypto_aese(vd + i, vn + i, vm + i, decrypt); | 144 | + if (trap) { |
136 | + } | 145 | + pauth_trap(env, 2, ra); |
137 | + clear_tail(vd, opr_sz, simd_maxsz(desc)); | 146 | + } |
138 | +} | 147 | + } |
139 | + | 148 | + if (el < 3 && arm_feature(env, ARM_FEATURE_EL3)) { |
140 | +static void do_crypto_aesmc(uint64_t *rd, uint64_t *rm, bool decrypt) | 149 | + if (!(env->cp15.scr_el3 & SCR_API)) { |
141 | { | 150 | + pauth_trap(env, 3, ra); |
142 | static uint32_t const mc[][256] = { { | 151 | + } |
143 | /* MixColumns lookup table */ | 152 | + } |
144 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_aesmc)(void *vd, void *vm, uint32_t decrypt) | 153 | +} |
145 | 0xbe805d9f, 0xb58d5491, 0xa89a4f83, 0xa397468d, | 154 | + |
146 | } }; | 155 | +static bool pauth_key_enabled(CPUARMState *env, int el, uint32_t bit) |
147 | 156 | +{ | |
148 | - uint64_t *rd = vd; | 157 | + uint32_t sctlr; |
149 | - uint64_t *rm = vm; | 158 | + if (el == 0) { |
150 | union CRYPTO_STATE st = { .l = { rm[0], rm[1] } }; | 159 | + /* FIXME: ARMv8.1-VHE S2 translation regime. */ |
151 | int i; | 160 | + sctlr = env->cp15.sctlr_el[1]; |
152 | |||
153 | - assert(decrypt < 2); | ||
154 | - | ||
155 | for (i = 0; i < 16; i += 4) { | ||
156 | CR_ST_WORD(st, i >> 2) = | ||
157 | mc[decrypt][CR_ST_BYTE(st, i)] ^ | ||
158 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_aesmc)(void *vd, void *vm, uint32_t decrypt) | ||
159 | rd[1] = st.l[1]; | ||
160 | } | ||
161 | |||
162 | +void HELPER(crypto_aesmc)(void *vd, void *vm, uint32_t desc) | ||
163 | +{ | ||
164 | + intptr_t i, opr_sz = simd_oprsz(desc); | ||
165 | + bool decrypt = simd_data(desc); | ||
166 | + | ||
167 | + for (i = 0; i < opr_sz; i += 16) { | ||
168 | + do_crypto_aesmc(vd + i, vm + i, decrypt); | ||
169 | + } | ||
170 | + clear_tail(vd, opr_sz, simd_maxsz(desc)); | ||
171 | +} | ||
172 | + | ||
173 | /* | ||
174 | * SHA-1 logical functions | ||
175 | */ | ||
176 | @@ -XXX,XX +XXX,XX @@ static uint8_t const sm4_sbox[] = { | ||
177 | 0x79, 0xee, 0x5f, 0x3e, 0xd7, 0xcb, 0x39, 0x48, | ||
178 | }; | ||
179 | |||
180 | -void HELPER(crypto_sm4e)(void *vd, void *vn) | ||
181 | +static void do_crypto_sm4e(uint64_t *rd, uint64_t *rn, uint64_t *rm) | ||
182 | { | ||
183 | - uint64_t *rd = vd; | ||
184 | - uint64_t *rn = vn; | ||
185 | - union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
186 | - union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
187 | + union CRYPTO_STATE d = { .l = { rn[0], rn[1] } }; | ||
188 | + union CRYPTO_STATE n = { .l = { rm[0], rm[1] } }; | ||
189 | uint32_t t, i; | ||
190 | |||
191 | for (i = 0; i < 4; i++) { | ||
192 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm4e)(void *vd, void *vn) | ||
193 | rd[1] = d.l[1]; | ||
194 | } | ||
195 | |||
196 | -void HELPER(crypto_sm4ekey)(void *vd, void *vn, void* vm) | ||
197 | +void HELPER(crypto_sm4e)(void *vd, void *vn, void *vm, uint32_t desc) | ||
198 | +{ | ||
199 | + intptr_t i, opr_sz = simd_oprsz(desc); | ||
200 | + | ||
201 | + for (i = 0; i < opr_sz; i += 16) { | ||
202 | + do_crypto_sm4e(vd + i, vn + i, vm + i); | ||
203 | + } | ||
204 | + clear_tail(vd, opr_sz, simd_maxsz(desc)); | ||
205 | +} | ||
206 | + | ||
207 | +static void do_crypto_sm4ekey(uint64_t *rd, uint64_t *rn, uint64_t *rm) | ||
208 | { | ||
209 | - uint64_t *rd = vd; | ||
210 | - uint64_t *rn = vn; | ||
211 | - uint64_t *rm = vm; | ||
212 | union CRYPTO_STATE d; | ||
213 | union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
214 | union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
215 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm4ekey)(void *vd, void *vn, void* vm) | ||
216 | rd[0] = d.l[0]; | ||
217 | rd[1] = d.l[1]; | ||
218 | } | ||
219 | + | ||
220 | +void HELPER(crypto_sm4ekey)(void *vd, void *vn, void* vm, uint32_t desc) | ||
221 | +{ | ||
222 | + intptr_t i, opr_sz = simd_oprsz(desc); | ||
223 | + | ||
224 | + for (i = 0; i < opr_sz; i += 16) { | ||
225 | + do_crypto_sm4ekey(vd + i, vn + i, vm + i); | ||
226 | + } | ||
227 | + clear_tail(vd, opr_sz, simd_maxsz(desc)); | ||
228 | +} | ||
229 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
230 | index XXXXXXX..XXXXXXX 100644 | ||
231 | --- a/target/arm/translate-a64.c | ||
232 | +++ b/target/arm/translate-a64.c | ||
233 | @@ -XXX,XX +XXX,XX @@ static void gen_gvec_fn4(DisasContext *s, bool is_q, int rd, int rn, int rm, | ||
234 | is_q ? 16 : 8, vec_full_reg_size(s)); | ||
235 | } | ||
236 | |||
237 | +/* Expand a 2-operand operation using an out-of-line helper. */ | ||
238 | +static void gen_gvec_op2_ool(DisasContext *s, bool is_q, int rd, | ||
239 | + int rn, int data, gen_helper_gvec_2 *fn) | ||
240 | +{ | ||
241 | + tcg_gen_gvec_2_ool(vec_full_reg_offset(s, rd), | ||
242 | + vec_full_reg_offset(s, rn), | ||
243 | + is_q ? 16 : 8, vec_full_reg_size(s), data, fn); | ||
244 | +} | ||
245 | + | ||
246 | /* Expand a 3-operand operation using an out-of-line helper. */ | ||
247 | static void gen_gvec_op3_ool(DisasContext *s, bool is_q, int rd, | ||
248 | int rn, int rm, int data, gen_helper_gvec_3 *fn) | ||
249 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn) | ||
250 | int rn = extract32(insn, 5, 5); | ||
251 | int rd = extract32(insn, 0, 5); | ||
252 | int decrypt; | ||
253 | - TCGv_ptr tcg_rd_ptr, tcg_rn_ptr; | ||
254 | - TCGv_i32 tcg_decrypt; | ||
255 | - CryptoThreeOpIntFn *genfn; | ||
256 | + gen_helper_gvec_2 *genfn2 = NULL; | ||
257 | + gen_helper_gvec_3 *genfn3 = NULL; | ||
258 | |||
259 | if (!dc_isar_feature(aa64_aes, s) || size != 0) { | ||
260 | unallocated_encoding(s); | ||
261 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn) | ||
262 | switch (opcode) { | ||
263 | case 0x4: /* AESE */ | ||
264 | decrypt = 0; | ||
265 | - genfn = gen_helper_crypto_aese; | ||
266 | + genfn3 = gen_helper_crypto_aese; | ||
267 | break; | ||
268 | case 0x6: /* AESMC */ | ||
269 | decrypt = 0; | ||
270 | - genfn = gen_helper_crypto_aesmc; | ||
271 | + genfn2 = gen_helper_crypto_aesmc; | ||
272 | break; | ||
273 | case 0x5: /* AESD */ | ||
274 | decrypt = 1; | ||
275 | - genfn = gen_helper_crypto_aese; | ||
276 | + genfn3 = gen_helper_crypto_aese; | ||
277 | break; | ||
278 | case 0x7: /* AESIMC */ | ||
279 | decrypt = 1; | ||
280 | - genfn = gen_helper_crypto_aesmc; | ||
281 | + genfn2 = gen_helper_crypto_aesmc; | ||
282 | break; | ||
283 | default: | ||
284 | unallocated_encoding(s); | ||
285 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_aes(DisasContext *s, uint32_t insn) | ||
286 | if (!fp_access_check(s)) { | ||
287 | return; | ||
288 | } | ||
289 | - | ||
290 | - tcg_rd_ptr = vec_full_reg_ptr(s, rd); | ||
291 | - tcg_rn_ptr = vec_full_reg_ptr(s, rn); | ||
292 | - tcg_decrypt = tcg_const_i32(decrypt); | ||
293 | - | ||
294 | - genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_decrypt); | ||
295 | - | ||
296 | - tcg_temp_free_ptr(tcg_rd_ptr); | ||
297 | - tcg_temp_free_ptr(tcg_rn_ptr); | ||
298 | - tcg_temp_free_i32(tcg_decrypt); | ||
299 | + if (genfn2) { | ||
300 | + gen_gvec_op2_ool(s, true, rd, rn, decrypt, genfn2); | ||
301 | + } else { | 161 | + } else { |
302 | + gen_gvec_op3_ool(s, true, rd, rd, rn, decrypt, genfn3); | 162 | + sctlr = env->cp15.sctlr_el[el]; |
303 | + } | 163 | + } |
304 | } | 164 | + return (sctlr & bit) != 0; |
305 | 165 | +} | |
306 | /* Crypto three-reg SHA | 166 | + |
307 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 167 | +uint64_t HELPER(pacia)(CPUARMState *env, uint64_t x, uint64_t y) |
308 | int rn = extract32(insn, 5, 5); | 168 | +{ |
309 | int rd = extract32(insn, 0, 5); | 169 | + int el = arm_current_el(env); |
310 | bool feature; | 170 | + if (!pauth_key_enabled(env, el, SCTLR_EnIA)) { |
311 | - CryptoThreeOpFn *genfn; | 171 | + return x; |
312 | + CryptoThreeOpFn *genfn = NULL; | 172 | + } |
313 | + gen_helper_gvec_3 *oolfn = NULL; | 173 | + pauth_check_trap(env, el, GETPC()); |
314 | 174 | + return pauth_addpac(env, x, y, &env->apia_key, false); | |
315 | if (o == 0) { | 175 | +} |
316 | switch (opcode) { | 176 | + |
317 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 177 | +uint64_t HELPER(pacib)(CPUARMState *env, uint64_t x, uint64_t y) |
318 | break; | 178 | +{ |
319 | case 2: /* SM4EKEY */ | 179 | + int el = arm_current_el(env); |
320 | feature = dc_isar_feature(aa64_sm4, s); | 180 | + if (!pauth_key_enabled(env, el, SCTLR_EnIB)) { |
321 | - genfn = gen_helper_crypto_sm4ekey; | 181 | + return x; |
322 | + oolfn = gen_helper_crypto_sm4ekey; | 182 | + } |
323 | break; | 183 | + pauth_check_trap(env, el, GETPC()); |
324 | default: | 184 | + return pauth_addpac(env, x, y, &env->apib_key, false); |
325 | unallocated_encoding(s); | 185 | +} |
326 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 186 | + |
327 | return; | 187 | +uint64_t HELPER(pacda)(CPUARMState *env, uint64_t x, uint64_t y) |
328 | } | 188 | +{ |
329 | 189 | + int el = arm_current_el(env); | |
330 | + if (oolfn) { | 190 | + if (!pauth_key_enabled(env, el, SCTLR_EnDA)) { |
331 | + gen_gvec_op3_ool(s, true, rd, rn, rm, 0, oolfn); | 191 | + return x; |
332 | + return; | 192 | + } |
333 | + } | 193 | + pauth_check_trap(env, el, GETPC()); |
334 | + | 194 | + return pauth_addpac(env, x, y, &env->apda_key, true); |
335 | if (genfn) { | 195 | +} |
336 | TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | 196 | + |
337 | 197 | +uint64_t HELPER(pacdb)(CPUARMState *env, uint64_t x, uint64_t y) | |
338 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | 198 | +{ |
339 | TCGv_ptr tcg_rd_ptr, tcg_rn_ptr; | 199 | + int el = arm_current_el(env); |
340 | bool feature; | 200 | + if (!pauth_key_enabled(env, el, SCTLR_EnDB)) { |
341 | CryptoTwoOpFn *genfn; | 201 | + return x; |
342 | + gen_helper_gvec_3 *oolfn = NULL; | 202 | + } |
343 | 203 | + pauth_check_trap(env, el, GETPC()); | |
344 | switch (opcode) { | 204 | + return pauth_addpac(env, x, y, &env->apdb_key, true); |
345 | case 0: /* SHA512SU0 */ | 205 | +} |
346 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | 206 | + |
347 | break; | 207 | +uint64_t HELPER(pacga)(CPUARMState *env, uint64_t x, uint64_t y) |
348 | case 1: /* SM4E */ | 208 | +{ |
349 | feature = dc_isar_feature(aa64_sm4, s); | 209 | + uint64_t pac; |
350 | - genfn = gen_helper_crypto_sm4e; | 210 | + |
351 | + oolfn = gen_helper_crypto_sm4e; | 211 | + pauth_check_trap(env, arm_current_el(env), GETPC()); |
352 | break; | 212 | + pac = pauth_computepac(x, y, env->apga_key); |
353 | default: | 213 | + |
354 | unallocated_encoding(s); | 214 | + return pac & 0xffffffff00000000ull; |
355 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | 215 | +} |
356 | return; | 216 | + |
357 | } | 217 | +uint64_t HELPER(autia)(CPUARMState *env, uint64_t x, uint64_t y) |
358 | 218 | +{ | |
359 | + if (oolfn) { | 219 | + int el = arm_current_el(env); |
360 | + gen_gvec_op3_ool(s, true, rd, rd, rn, 0, oolfn); | 220 | + if (!pauth_key_enabled(env, el, SCTLR_EnIA)) { |
361 | + return; | 221 | + return x; |
362 | + } | 222 | + } |
363 | + | 223 | + pauth_check_trap(env, el, GETPC()); |
364 | tcg_rd_ptr = vec_full_reg_ptr(s, rd); | 224 | + return pauth_auth(env, x, y, &env->apia_key, false, 0); |
365 | tcg_rn_ptr = vec_full_reg_ptr(s, rn); | 225 | +} |
366 | 226 | + | |
367 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 227 | +uint64_t HELPER(autib)(CPUARMState *env, uint64_t x, uint64_t y) |
368 | index XXXXXXX..XXXXXXX 100644 | 228 | +{ |
369 | --- a/target/arm/translate.c | 229 | + int el = arm_current_el(env); |
370 | +++ b/target/arm/translate.c | 230 | + if (!pauth_key_enabled(env, el, SCTLR_EnIB)) { |
371 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 231 | + return x; |
372 | if (!dc_isar_feature(aa32_aes, s) || ((rm | rd) & 1)) { | 232 | + } |
373 | return 1; | 233 | + pauth_check_trap(env, el, GETPC()); |
374 | } | 234 | + return pauth_auth(env, x, y, &env->apib_key, false, 1); |
375 | - ptr1 = vfp_reg_ptr(true, rd); | 235 | +} |
376 | - ptr2 = vfp_reg_ptr(true, rm); | 236 | + |
377 | - | 237 | +uint64_t HELPER(autda)(CPUARMState *env, uint64_t x, uint64_t y) |
378 | - /* Bit 6 is the lowest opcode bit; it distinguishes between | 238 | +{ |
379 | - * encryption (AESE/AESMC) and decryption (AESD/AESIMC) | 239 | + int el = arm_current_el(env); |
380 | - */ | 240 | + if (!pauth_key_enabled(env, el, SCTLR_EnDA)) { |
381 | - tmp3 = tcg_const_i32(extract32(insn, 6, 1)); | 241 | + return x; |
382 | - | 242 | + } |
383 | + /* | 243 | + pauth_check_trap(env, el, GETPC()); |
384 | + * Bit 6 is the lowest opcode bit; it distinguishes | 244 | + return pauth_auth(env, x, y, &env->apda_key, true, 0); |
385 | + * between encryption (AESE/AESMC) and decryption | 245 | +} |
386 | + * (AESD/AESIMC). | 246 | + |
387 | + */ | 247 | +uint64_t HELPER(autdb)(CPUARMState *env, uint64_t x, uint64_t y) |
388 | if (op == NEON_2RM_AESE) { | 248 | +{ |
389 | - gen_helper_crypto_aese(ptr1, ptr2, tmp3); | 249 | + int el = arm_current_el(env); |
390 | + tcg_gen_gvec_3_ool(vfp_reg_offset(true, rd), | 250 | + if (!pauth_key_enabled(env, el, SCTLR_EnDB)) { |
391 | + vfp_reg_offset(true, rd), | 251 | + return x; |
392 | + vfp_reg_offset(true, rm), | 252 | + } |
393 | + 16, 16, extract32(insn, 6, 1), | 253 | + pauth_check_trap(env, el, GETPC()); |
394 | + gen_helper_crypto_aese); | 254 | + return pauth_auth(env, x, y, &env->apdb_key, true, 1); |
395 | } else { | 255 | +} |
396 | - gen_helper_crypto_aesmc(ptr1, ptr2, tmp3); | 256 | + |
397 | + tcg_gen_gvec_2_ool(vfp_reg_offset(true, rd), | 257 | +uint64_t HELPER(xpaci)(CPUARMState *env, uint64_t a) |
398 | + vfp_reg_offset(true, rm), | 258 | +{ |
399 | + 16, 16, extract32(insn, 6, 1), | 259 | + return pauth_strip(env, a, false); |
400 | + gen_helper_crypto_aesmc); | 260 | +} |
401 | } | 261 | + |
402 | - tcg_temp_free_ptr(ptr1); | 262 | +uint64_t HELPER(xpacd)(CPUARMState *env, uint64_t a) |
403 | - tcg_temp_free_ptr(ptr2); | 263 | +{ |
404 | - tcg_temp_free_i32(tmp3); | 264 | + return pauth_strip(env, a, true); |
405 | break; | 265 | +} |
406 | case NEON_2RM_SHA1H: | ||
407 | if (!dc_isar_feature(aa32_sha1, s) || ((rm | rd) & 1)) { | ||
408 | diff --git a/target/arm/vec_helper.c b/target/arm/vec_helper.c | ||
409 | index XXXXXXX..XXXXXXX 100644 | ||
410 | --- a/target/arm/vec_helper.c | ||
411 | +++ b/target/arm/vec_helper.c | ||
412 | @@ -XXX,XX +XXX,XX @@ | ||
413 | #include "exec/helper-proto.h" | ||
414 | #include "tcg/tcg-gvec-desc.h" | ||
415 | #include "fpu/softfloat.h" | ||
416 | - | ||
417 | +#include "vec_internal.h" | ||
418 | |||
419 | /* Note that vector data is stored in host-endian 64-bit chunks, | ||
420 | so addressing units smaller than that needs a host-endian fixup. */ | ||
421 | @@ -XXX,XX +XXX,XX @@ | ||
422 | #define H4(x) (x) | ||
423 | #endif | ||
424 | |||
425 | -static void clear_tail(void *vd, uintptr_t opr_sz, uintptr_t max_sz) | ||
426 | -{ | ||
427 | - uint64_t *d = vd + opr_sz; | ||
428 | - uintptr_t i; | ||
429 | - | ||
430 | - for (i = opr_sz; i < max_sz; i += 8) { | ||
431 | - *d++ = 0; | ||
432 | - } | ||
433 | -} | ||
434 | - | ||
435 | /* Signed saturating rounding doubling multiply-accumulate high half, 16-bit */ | ||
436 | static int16_t inl_qrdmlah_s16(int16_t src1, int16_t src2, | ||
437 | int16_t src3, uint32_t *sat) | ||
438 | -- | 266 | -- |
439 | 2.20.1 | 267 | 2.20.1 |
440 | 268 | ||
441 | 269 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | With this conversion, we will be able to use the same helpers | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
4 | with sve. This also fixes a bug in which we failed to clear | ||
5 | the high bits of the SVE register after an AdvSIMD operation. | ||
6 | |||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20200514212831.31248-3-richard.henderson@linaro.org | 5 | Message-id: 20190108223129.5570-7-richard.henderson@linaro.org |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 7 | --- |
12 | target/arm/helper.h | 2 ++ | 8 | target/arm/translate-a64.c | 93 +++++++++++++++++++++++++++++++++----- |
13 | target/arm/translate-a64.h | 3 ++ | 9 | 1 file changed, 81 insertions(+), 12 deletions(-) |
14 | target/arm/crypto_helper.c | 11 +++++++ | ||
15 | target/arm/translate-a64.c | 59 ++++++++++++++++++++------------------ | ||
16 | 4 files changed, 47 insertions(+), 28 deletions(-) | ||
17 | 10 | ||
18 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/arm/helper.h | ||
21 | +++ b/target/arm/helper.h | ||
22 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
23 | DEF_HELPER_FLAGS_4(crypto_sm4e, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
24 | DEF_HELPER_FLAGS_4(crypto_sm4ekey, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
25 | |||
26 | +DEF_HELPER_FLAGS_4(crypto_rax1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
27 | + | ||
28 | DEF_HELPER_FLAGS_3(crc32, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | ||
29 | DEF_HELPER_FLAGS_3(crc32c, TCG_CALL_NO_RWG_SE, i32, i32, i32, i32) | ||
30 | |||
31 | diff --git a/target/arm/translate-a64.h b/target/arm/translate-a64.h | ||
32 | index XXXXXXX..XXXXXXX 100644 | ||
33 | --- a/target/arm/translate-a64.h | ||
34 | +++ b/target/arm/translate-a64.h | ||
35 | @@ -XXX,XX +XXX,XX @@ static inline int vec_full_reg_size(DisasContext *s) | ||
36 | |||
37 | bool disas_sve(DisasContext *, uint32_t); | ||
38 | |||
39 | +void gen_gvec_rax1(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs, | ||
40 | + uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz); | ||
41 | + | ||
42 | #endif /* TARGET_ARM_TRANSLATE_A64_H */ | ||
43 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
44 | index XXXXXXX..XXXXXXX 100644 | ||
45 | --- a/target/arm/crypto_helper.c | ||
46 | +++ b/target/arm/crypto_helper.c | ||
47 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm4ekey)(void *vd, void *vn, void* vm, uint32_t desc) | ||
48 | } | ||
49 | clear_tail(vd, opr_sz, simd_maxsz(desc)); | ||
50 | } | ||
51 | + | ||
52 | +void HELPER(crypto_rax1)(void *vd, void *vn, void *vm, uint32_t desc) | ||
53 | +{ | ||
54 | + intptr_t i, opr_sz = simd_oprsz(desc); | ||
55 | + uint64_t *d = vd, *n = vn, *m = vm; | ||
56 | + | ||
57 | + for (i = 0; i < opr_sz / 8; ++i) { | ||
58 | + d[i] = n[i] ^ rol64(m[i], 1); | ||
59 | + } | ||
60 | + clear_tail(vd, opr_sz, simd_maxsz(desc)); | ||
61 | +} | ||
62 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 11 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
63 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
64 | --- a/target/arm/translate-a64.c | 13 | --- a/target/arm/translate-a64.c |
65 | +++ b/target/arm/translate-a64.c | 14 | +++ b/target/arm/translate-a64.c |
66 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn) | 15 | @@ -XXX,XX +XXX,XX @@ static void handle_hint(DisasContext *s, uint32_t insn, |
67 | tcg_temp_free_ptr(tcg_rn_ptr); | 16 | } |
68 | } | 17 | |
69 | 18 | switch (selector) { | |
70 | +static void gen_rax1_i64(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m) | 19 | - case 0: /* NOP */ |
71 | +{ | ||
72 | + tcg_gen_rotli_i64(d, m, 1); | ||
73 | + tcg_gen_xor_i64(d, d, n); | ||
74 | +} | ||
75 | + | ||
76 | +static void gen_rax1_vec(unsigned vece, TCGv_vec d, TCGv_vec n, TCGv_vec m) | ||
77 | +{ | ||
78 | + tcg_gen_rotli_vec(vece, d, m, 1); | ||
79 | + tcg_gen_xor_vec(vece, d, d, n); | ||
80 | +} | ||
81 | + | ||
82 | +void gen_gvec_rax1(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs, | ||
83 | + uint32_t rm_ofs, uint32_t opr_sz, uint32_t max_sz) | ||
84 | +{ | ||
85 | + static const TCGOpcode vecop_list[] = { INDEX_op_rotli_vec, 0 }; | ||
86 | + static const GVecGen3 op = { | ||
87 | + .fni8 = gen_rax1_i64, | ||
88 | + .fniv = gen_rax1_vec, | ||
89 | + .opt_opc = vecop_list, | ||
90 | + .fno = gen_helper_crypto_rax1, | ||
91 | + .vece = MO_64, | ||
92 | + }; | ||
93 | + tcg_gen_gvec_3(rd_ofs, rn_ofs, rm_ofs, opr_sz, max_sz, &op); | ||
94 | +} | ||
95 | + | ||
96 | /* Crypto three-reg SHA512 | ||
97 | * 31 21 20 16 15 14 13 12 11 10 9 5 4 0 | ||
98 | * +-----------------------+------+---+---+-----+--------+------+------+ | ||
99 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
100 | bool feature; | ||
101 | CryptoThreeOpFn *genfn = NULL; | ||
102 | gen_helper_gvec_3 *oolfn = NULL; | ||
103 | + GVecGen3Fn *gvecfn = NULL; | ||
104 | |||
105 | if (o == 0) { | ||
106 | switch (opcode) { | ||
107 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
108 | break; | ||
109 | case 3: /* RAX1 */ | ||
110 | feature = dc_isar_feature(aa64_sha3, s); | ||
111 | - genfn = NULL; | ||
112 | + gvecfn = gen_gvec_rax1; | ||
113 | break; | ||
114 | default: | ||
115 | g_assert_not_reached(); | ||
116 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
117 | |||
118 | if (oolfn) { | ||
119 | gen_gvec_op3_ool(s, true, rd, rn, rm, 0, oolfn); | ||
120 | - return; | 20 | - return; |
121 | - } | 21 | - case 3: /* WFI */ |
122 | - | 22 | + case 0b00000: /* NOP */ |
123 | - if (genfn) { | 23 | + break; |
124 | + } else if (gvecfn) { | 24 | + case 0b00011: /* WFI */ |
125 | + gen_gvec_fn3(s, true, rd, rn, rm, gvecfn, MO_64); | 25 | s->base.is_jmp = DISAS_WFI; |
126 | + } else { | 26 | - return; |
127 | TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | 27 | + break; |
128 | 28 | + case 0b00001: /* YIELD */ | |
129 | tcg_rd_ptr = vec_full_reg_ptr(s, rd); | 29 | /* When running in MTTCG we don't generate jumps to the yield and |
130 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 30 | * WFE helpers as it won't affect the scheduling of other vCPUs. |
131 | tcg_temp_free_ptr(tcg_rd_ptr); | 31 | * If we wanted to more completely model WFE/SEV so we don't busy |
132 | tcg_temp_free_ptr(tcg_rn_ptr); | 32 | * spin unnecessarily we would need to do something more involved. |
133 | tcg_temp_free_ptr(tcg_rm_ptr); | 33 | */ |
134 | - } else { | 34 | - case 1: /* YIELD */ |
135 | - TCGv_i64 tcg_op1, tcg_op2, tcg_res[2]; | 35 | if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) { |
136 | - int pass; | 36 | s->base.is_jmp = DISAS_YIELD; |
137 | - | 37 | } |
138 | - tcg_op1 = tcg_temp_new_i64(); | 38 | - return; |
139 | - tcg_op2 = tcg_temp_new_i64(); | 39 | - case 2: /* WFE */ |
140 | - tcg_res[0] = tcg_temp_new_i64(); | 40 | + break; |
141 | - tcg_res[1] = tcg_temp_new_i64(); | 41 | + case 0b00010: /* WFE */ |
142 | - | 42 | if (!(tb_cflags(s->base.tb) & CF_PARALLEL)) { |
143 | - for (pass = 0; pass < 2; pass++) { | 43 | s->base.is_jmp = DISAS_WFE; |
144 | - read_vec_element(s, tcg_op1, rn, pass, MO_64); | 44 | } |
145 | - read_vec_element(s, tcg_op2, rm, pass, MO_64); | 45 | - return; |
146 | - | 46 | - case 4: /* SEV */ |
147 | - tcg_gen_rotli_i64(tcg_res[pass], tcg_op2, 1); | 47 | - case 5: /* SEVL */ |
148 | - tcg_gen_xor_i64(tcg_res[pass], tcg_res[pass], tcg_op1); | 48 | + break; |
149 | - } | 49 | + case 0b00100: /* SEV */ |
150 | - write_vec_element(s, tcg_res[0], rd, 0, MO_64); | 50 | + case 0b00101: /* SEVL */ |
151 | - write_vec_element(s, tcg_res[1], rd, 1, MO_64); | 51 | /* we treat all as NOP at least for now */ |
152 | - | 52 | - return; |
153 | - tcg_temp_free_i64(tcg_op1); | 53 | + break; |
154 | - tcg_temp_free_i64(tcg_op2); | 54 | + case 0b00111: /* XPACLRI */ |
155 | - tcg_temp_free_i64(tcg_res[0]); | 55 | + if (s->pauth_active) { |
156 | - tcg_temp_free_i64(tcg_res[1]); | 56 | + gen_helper_xpaci(cpu_X[30], cpu_env, cpu_X[30]); |
57 | + } | ||
58 | + break; | ||
59 | + case 0b01000: /* PACIA1716 */ | ||
60 | + if (s->pauth_active) { | ||
61 | + gen_helper_pacia(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]); | ||
62 | + } | ||
63 | + break; | ||
64 | + case 0b01010: /* PACIB1716 */ | ||
65 | + if (s->pauth_active) { | ||
66 | + gen_helper_pacib(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]); | ||
67 | + } | ||
68 | + break; | ||
69 | + case 0b01100: /* AUTIA1716 */ | ||
70 | + if (s->pauth_active) { | ||
71 | + gen_helper_autia(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]); | ||
72 | + } | ||
73 | + break; | ||
74 | + case 0b01110: /* AUTIB1716 */ | ||
75 | + if (s->pauth_active) { | ||
76 | + gen_helper_autib(cpu_X[17], cpu_env, cpu_X[17], cpu_X[16]); | ||
77 | + } | ||
78 | + break; | ||
79 | + case 0b11000: /* PACIAZ */ | ||
80 | + if (s->pauth_active) { | ||
81 | + gen_helper_pacia(cpu_X[30], cpu_env, cpu_X[30], | ||
82 | + new_tmp_a64_zero(s)); | ||
83 | + } | ||
84 | + break; | ||
85 | + case 0b11001: /* PACIASP */ | ||
86 | + if (s->pauth_active) { | ||
87 | + gen_helper_pacia(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]); | ||
88 | + } | ||
89 | + break; | ||
90 | + case 0b11010: /* PACIBZ */ | ||
91 | + if (s->pauth_active) { | ||
92 | + gen_helper_pacib(cpu_X[30], cpu_env, cpu_X[30], | ||
93 | + new_tmp_a64_zero(s)); | ||
94 | + } | ||
95 | + break; | ||
96 | + case 0b11011: /* PACIBSP */ | ||
97 | + if (s->pauth_active) { | ||
98 | + gen_helper_pacib(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]); | ||
99 | + } | ||
100 | + break; | ||
101 | + case 0b11100: /* AUTIAZ */ | ||
102 | + if (s->pauth_active) { | ||
103 | + gen_helper_autia(cpu_X[30], cpu_env, cpu_X[30], | ||
104 | + new_tmp_a64_zero(s)); | ||
105 | + } | ||
106 | + break; | ||
107 | + case 0b11101: /* AUTIASP */ | ||
108 | + if (s->pauth_active) { | ||
109 | + gen_helper_autia(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]); | ||
110 | + } | ||
111 | + break; | ||
112 | + case 0b11110: /* AUTIBZ */ | ||
113 | + if (s->pauth_active) { | ||
114 | + gen_helper_autib(cpu_X[30], cpu_env, cpu_X[30], | ||
115 | + new_tmp_a64_zero(s)); | ||
116 | + } | ||
117 | + break; | ||
118 | + case 0b11111: /* AUTIBSP */ | ||
119 | + if (s->pauth_active) { | ||
120 | + gen_helper_autib(cpu_X[30], cpu_env, cpu_X[30], cpu_X[31]); | ||
121 | + } | ||
122 | + break; | ||
123 | default: | ||
124 | /* default specified as NOP equivalent */ | ||
125 | - return; | ||
126 | + break; | ||
157 | } | 127 | } |
158 | } | 128 | } |
159 | 129 | ||
160 | -- | 130 | -- |
161 | 2.20.1 | 131 | 2.20.1 |
162 | 132 | ||
163 | 133 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Rather than passing an opcode to a helper, fully decode the | 3 | Now properly signals unallocated for REV64 with SF=0. |
4 | operation at translate time. Use clear_tail_16 to zap the | 4 | Allows for the opcode2 field to be decoded shortly. |
5 | balance of the SVE register with the AdvSIMD write. | ||
6 | 5 | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20200514212831.31248-7-richard.henderson@linaro.org | 8 | Message-id: 20190108223129.5570-8-richard.henderson@linaro.org |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 10 | --- |
12 | target/arm/helper.h | 5 ++++- | 11 | target/arm/translate-a64.c | 31 ++++++++++++++++++++++--------- |
13 | target/arm/crypto_helper.c | 24 ++++++++++++++++++------ | 12 | 1 file changed, 22 insertions(+), 9 deletions(-) |
14 | target/arm/translate-a64.c | 21 +++++---------------- | ||
15 | 3 files changed, 27 insertions(+), 23 deletions(-) | ||
16 | 13 | ||
17 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
18 | index XXXXXXX..XXXXXXX 100644 | ||
19 | --- a/target/arm/helper.h | ||
20 | +++ b/target/arm/helper.h | ||
21 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
22 | DEF_HELPER_FLAGS_4(crypto_sha512su1, TCG_CALL_NO_RWG, | ||
23 | void, ptr, ptr, ptr, i32) | ||
24 | |||
25 | -DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) | ||
26 | +DEF_HELPER_FLAGS_4(crypto_sm3tt1a, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
27 | +DEF_HELPER_FLAGS_4(crypto_sm3tt1b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
28 | +DEF_HELPER_FLAGS_4(crypto_sm3tt2a, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
29 | +DEF_HELPER_FLAGS_4(crypto_sm3tt2b, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
30 | DEF_HELPER_FLAGS_4(crypto_sm3partw1, TCG_CALL_NO_RWG, | ||
31 | void, ptr, ptr, ptr, i32) | ||
32 | DEF_HELPER_FLAGS_4(crypto_sm3partw2, TCG_CALL_NO_RWG, | ||
33 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
34 | index XXXXXXX..XXXXXXX 100644 | ||
35 | --- a/target/arm/crypto_helper.c | ||
36 | +++ b/target/arm/crypto_helper.c | ||
37 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm, uint32_t desc) | ||
38 | clear_tail_16(vd, desc); | ||
39 | } | ||
40 | |||
41 | -void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, | ||
42 | - uint32_t opcode) | ||
43 | +static inline void QEMU_ALWAYS_INLINE | ||
44 | +crypto_sm3tt(uint64_t *rd, uint64_t *rn, uint64_t *rm, | ||
45 | + uint32_t desc, uint32_t opcode) | ||
46 | { | ||
47 | - uint64_t *rd = vd; | ||
48 | - uint64_t *rn = vn; | ||
49 | - uint64_t *rm = vm; | ||
50 | union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
51 | union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
52 | union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
53 | + uint32_t imm2 = simd_data(desc); | ||
54 | uint32_t t; | ||
55 | |||
56 | assert(imm2 < 4); | ||
57 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, | ||
58 | /* SM3TT2B */ | ||
59 | t = cho(CR_ST_WORD(d, 3), CR_ST_WORD(d, 2), CR_ST_WORD(d, 1)); | ||
60 | } else { | ||
61 | - g_assert_not_reached(); | ||
62 | + qemu_build_not_reached(); | ||
63 | } | ||
64 | |||
65 | t += CR_ST_WORD(d, 0) + CR_ST_WORD(m, imm2); | ||
66 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, | ||
67 | |||
68 | rd[0] = d.l[0]; | ||
69 | rd[1] = d.l[1]; | ||
70 | + | ||
71 | + clear_tail_16(rd, desc); | ||
72 | } | ||
73 | |||
74 | +#define DO_SM3TT(NAME, OPCODE) \ | ||
75 | + void HELPER(NAME)(void *vd, void *vn, void *vm, uint32_t desc) \ | ||
76 | + { crypto_sm3tt(vd, vn, vm, desc, OPCODE); } | ||
77 | + | ||
78 | +DO_SM3TT(crypto_sm3tt1a, 0) | ||
79 | +DO_SM3TT(crypto_sm3tt1b, 1) | ||
80 | +DO_SM3TT(crypto_sm3tt2a, 2) | ||
81 | +DO_SM3TT(crypto_sm3tt2b, 3) | ||
82 | + | ||
83 | +#undef DO_SM3TT | ||
84 | + | ||
85 | static uint8_t const sm4_sbox[] = { | ||
86 | 0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7, | ||
87 | 0x16, 0xb6, 0x14, 0xc2, 0x28, 0xfb, 0x2c, 0x05, | ||
88 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 14 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
89 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
90 | --- a/target/arm/translate-a64.c | 16 | --- a/target/arm/translate-a64.c |
91 | +++ b/target/arm/translate-a64.c | 17 | +++ b/target/arm/translate-a64.c |
92 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_xar(DisasContext *s, uint32_t insn) | 18 | @@ -XXX,XX +XXX,XX @@ static void handle_rev16(DisasContext *s, unsigned int sf, |
93 | */ | 19 | */ |
94 | static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn) | 20 | static void disas_data_proc_1src(DisasContext *s, uint32_t insn) |
95 | { | 21 | { |
96 | + static gen_helper_gvec_3 * const fns[4] = { | 22 | - unsigned int sf, opcode, rn, rd; |
97 | + gen_helper_crypto_sm3tt1a, gen_helper_crypto_sm3tt1b, | 23 | + unsigned int sf, opcode, opcode2, rn, rd; |
98 | + gen_helper_crypto_sm3tt2a, gen_helper_crypto_sm3tt2b, | 24 | |
99 | + }; | 25 | - if (extract32(insn, 29, 1) || extract32(insn, 16, 5)) { |
100 | int opcode = extract32(insn, 10, 2); | 26 | + if (extract32(insn, 29, 1)) { |
101 | int imm2 = extract32(insn, 12, 2); | ||
102 | int rm = extract32(insn, 16, 5); | ||
103 | int rn = extract32(insn, 5, 5); | ||
104 | int rd = extract32(insn, 0, 5); | ||
105 | - TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | ||
106 | - TCGv_i32 tcg_imm2, tcg_opcode; | ||
107 | |||
108 | if (!dc_isar_feature(aa64_sm3, s)) { | ||
109 | unallocated_encoding(s); | 27 | unallocated_encoding(s); |
110 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_imm2(DisasContext *s, uint32_t insn) | ||
111 | return; | 28 | return; |
112 | } | 29 | } |
113 | 30 | ||
114 | - tcg_rd_ptr = vec_full_reg_ptr(s, rd); | 31 | sf = extract32(insn, 31, 1); |
115 | - tcg_rn_ptr = vec_full_reg_ptr(s, rn); | 32 | opcode = extract32(insn, 10, 6); |
116 | - tcg_rm_ptr = vec_full_reg_ptr(s, rm); | 33 | + opcode2 = extract32(insn, 16, 5); |
117 | - tcg_imm2 = tcg_const_i32(imm2); | 34 | rn = extract32(insn, 5, 5); |
118 | - tcg_opcode = tcg_const_i32(opcode); | 35 | rd = extract32(insn, 0, 5); |
119 | - | 36 | |
120 | - gen_helper_crypto_sm3tt(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr, tcg_imm2, | 37 | - switch (opcode) { |
121 | - tcg_opcode); | 38 | - case 0: /* RBIT */ |
122 | - | 39 | +#define MAP(SF, O2, O1) ((SF) | (O1 << 1) | (O2 << 7)) |
123 | - tcg_temp_free_ptr(tcg_rd_ptr); | 40 | + |
124 | - tcg_temp_free_ptr(tcg_rn_ptr); | 41 | + switch (MAP(sf, opcode2, opcode)) { |
125 | - tcg_temp_free_ptr(tcg_rm_ptr); | 42 | + case MAP(0, 0x00, 0x00): /* RBIT */ |
126 | - tcg_temp_free_i32(tcg_imm2); | 43 | + case MAP(1, 0x00, 0x00): |
127 | - tcg_temp_free_i32(tcg_opcode); | 44 | handle_rbit(s, sf, rn, rd); |
128 | + gen_gvec_op3_ool(s, true, rd, rn, rm, imm2, fns[opcode]); | 45 | break; |
46 | - case 1: /* REV16 */ | ||
47 | + case MAP(0, 0x00, 0x01): /* REV16 */ | ||
48 | + case MAP(1, 0x00, 0x01): | ||
49 | handle_rev16(s, sf, rn, rd); | ||
50 | break; | ||
51 | - case 2: /* REV32 */ | ||
52 | + case MAP(0, 0x00, 0x02): /* REV/REV32 */ | ||
53 | + case MAP(1, 0x00, 0x02): | ||
54 | handle_rev32(s, sf, rn, rd); | ||
55 | break; | ||
56 | - case 3: /* REV64 */ | ||
57 | + case MAP(1, 0x00, 0x03): /* REV64 */ | ||
58 | handle_rev64(s, sf, rn, rd); | ||
59 | break; | ||
60 | - case 4: /* CLZ */ | ||
61 | + case MAP(0, 0x00, 0x04): /* CLZ */ | ||
62 | + case MAP(1, 0x00, 0x04): | ||
63 | handle_clz(s, sf, rn, rd); | ||
64 | break; | ||
65 | - case 5: /* CLS */ | ||
66 | + case MAP(0, 0x00, 0x05): /* CLS */ | ||
67 | + case MAP(1, 0x00, 0x05): | ||
68 | handle_cls(s, sf, rn, rd); | ||
69 | break; | ||
70 | + default: | ||
71 | + unallocated_encoding(s); | ||
72 | + break; | ||
73 | } | ||
74 | + | ||
75 | +#undef MAP | ||
129 | } | 76 | } |
130 | 77 | ||
131 | /* C3.6 Data processing - SIMD, inc Crypto | 78 | static void handle_div(DisasContext *s, bool is_signed, unsigned int sf, |
132 | -- | 79 | -- |
133 | 2.20.1 | 80 | 2.20.1 |
134 | 81 | ||
135 | 82 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20190108223129.5570-9-richard.henderson@linaro.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | target/arm/translate-a64.c | 146 +++++++++++++++++++++++++++++++++++++ | ||
9 | 1 file changed, 146 insertions(+) | ||
10 | |||
11 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/target/arm/translate-a64.c | ||
14 | +++ b/target/arm/translate-a64.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static void handle_rev16(DisasContext *s, unsigned int sf, | ||
16 | static void disas_data_proc_1src(DisasContext *s, uint32_t insn) | ||
17 | { | ||
18 | unsigned int sf, opcode, opcode2, rn, rd; | ||
19 | + TCGv_i64 tcg_rd; | ||
20 | |||
21 | if (extract32(insn, 29, 1)) { | ||
22 | unallocated_encoding(s); | ||
23 | @@ -XXX,XX +XXX,XX @@ static void disas_data_proc_1src(DisasContext *s, uint32_t insn) | ||
24 | case MAP(1, 0x00, 0x05): | ||
25 | handle_cls(s, sf, rn, rd); | ||
26 | break; | ||
27 | + case MAP(1, 0x01, 0x00): /* PACIA */ | ||
28 | + if (s->pauth_active) { | ||
29 | + tcg_rd = cpu_reg(s, rd); | ||
30 | + gen_helper_pacia(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn)); | ||
31 | + } else if (!dc_isar_feature(aa64_pauth, s)) { | ||
32 | + goto do_unallocated; | ||
33 | + } | ||
34 | + break; | ||
35 | + case MAP(1, 0x01, 0x01): /* PACIB */ | ||
36 | + if (s->pauth_active) { | ||
37 | + tcg_rd = cpu_reg(s, rd); | ||
38 | + gen_helper_pacib(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn)); | ||
39 | + } else if (!dc_isar_feature(aa64_pauth, s)) { | ||
40 | + goto do_unallocated; | ||
41 | + } | ||
42 | + break; | ||
43 | + case MAP(1, 0x01, 0x02): /* PACDA */ | ||
44 | + if (s->pauth_active) { | ||
45 | + tcg_rd = cpu_reg(s, rd); | ||
46 | + gen_helper_pacda(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn)); | ||
47 | + } else if (!dc_isar_feature(aa64_pauth, s)) { | ||
48 | + goto do_unallocated; | ||
49 | + } | ||
50 | + break; | ||
51 | + case MAP(1, 0x01, 0x03): /* PACDB */ | ||
52 | + if (s->pauth_active) { | ||
53 | + tcg_rd = cpu_reg(s, rd); | ||
54 | + gen_helper_pacdb(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn)); | ||
55 | + } else if (!dc_isar_feature(aa64_pauth, s)) { | ||
56 | + goto do_unallocated; | ||
57 | + } | ||
58 | + break; | ||
59 | + case MAP(1, 0x01, 0x04): /* AUTIA */ | ||
60 | + if (s->pauth_active) { | ||
61 | + tcg_rd = cpu_reg(s, rd); | ||
62 | + gen_helper_autia(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn)); | ||
63 | + } else if (!dc_isar_feature(aa64_pauth, s)) { | ||
64 | + goto do_unallocated; | ||
65 | + } | ||
66 | + break; | ||
67 | + case MAP(1, 0x01, 0x05): /* AUTIB */ | ||
68 | + if (s->pauth_active) { | ||
69 | + tcg_rd = cpu_reg(s, rd); | ||
70 | + gen_helper_autib(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn)); | ||
71 | + } else if (!dc_isar_feature(aa64_pauth, s)) { | ||
72 | + goto do_unallocated; | ||
73 | + } | ||
74 | + break; | ||
75 | + case MAP(1, 0x01, 0x06): /* AUTDA */ | ||
76 | + if (s->pauth_active) { | ||
77 | + tcg_rd = cpu_reg(s, rd); | ||
78 | + gen_helper_autda(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn)); | ||
79 | + } else if (!dc_isar_feature(aa64_pauth, s)) { | ||
80 | + goto do_unallocated; | ||
81 | + } | ||
82 | + break; | ||
83 | + case MAP(1, 0x01, 0x07): /* AUTDB */ | ||
84 | + if (s->pauth_active) { | ||
85 | + tcg_rd = cpu_reg(s, rd); | ||
86 | + gen_helper_autdb(tcg_rd, cpu_env, tcg_rd, cpu_reg_sp(s, rn)); | ||
87 | + } else if (!dc_isar_feature(aa64_pauth, s)) { | ||
88 | + goto do_unallocated; | ||
89 | + } | ||
90 | + break; | ||
91 | + case MAP(1, 0x01, 0x08): /* PACIZA */ | ||
92 | + if (!dc_isar_feature(aa64_pauth, s) || rn != 31) { | ||
93 | + goto do_unallocated; | ||
94 | + } else if (s->pauth_active) { | ||
95 | + tcg_rd = cpu_reg(s, rd); | ||
96 | + gen_helper_pacia(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s)); | ||
97 | + } | ||
98 | + break; | ||
99 | + case MAP(1, 0x01, 0x09): /* PACIZB */ | ||
100 | + if (!dc_isar_feature(aa64_pauth, s) || rn != 31) { | ||
101 | + goto do_unallocated; | ||
102 | + } else if (s->pauth_active) { | ||
103 | + tcg_rd = cpu_reg(s, rd); | ||
104 | + gen_helper_pacib(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s)); | ||
105 | + } | ||
106 | + break; | ||
107 | + case MAP(1, 0x01, 0x0a): /* PACDZA */ | ||
108 | + if (!dc_isar_feature(aa64_pauth, s) || rn != 31) { | ||
109 | + goto do_unallocated; | ||
110 | + } else if (s->pauth_active) { | ||
111 | + tcg_rd = cpu_reg(s, rd); | ||
112 | + gen_helper_pacda(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s)); | ||
113 | + } | ||
114 | + break; | ||
115 | + case MAP(1, 0x01, 0x0b): /* PACDZB */ | ||
116 | + if (!dc_isar_feature(aa64_pauth, s) || rn != 31) { | ||
117 | + goto do_unallocated; | ||
118 | + } else if (s->pauth_active) { | ||
119 | + tcg_rd = cpu_reg(s, rd); | ||
120 | + gen_helper_pacdb(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s)); | ||
121 | + } | ||
122 | + break; | ||
123 | + case MAP(1, 0x01, 0x0c): /* AUTIZA */ | ||
124 | + if (!dc_isar_feature(aa64_pauth, s) || rn != 31) { | ||
125 | + goto do_unallocated; | ||
126 | + } else if (s->pauth_active) { | ||
127 | + tcg_rd = cpu_reg(s, rd); | ||
128 | + gen_helper_autia(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s)); | ||
129 | + } | ||
130 | + break; | ||
131 | + case MAP(1, 0x01, 0x0d): /* AUTIZB */ | ||
132 | + if (!dc_isar_feature(aa64_pauth, s) || rn != 31) { | ||
133 | + goto do_unallocated; | ||
134 | + } else if (s->pauth_active) { | ||
135 | + tcg_rd = cpu_reg(s, rd); | ||
136 | + gen_helper_autib(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s)); | ||
137 | + } | ||
138 | + break; | ||
139 | + case MAP(1, 0x01, 0x0e): /* AUTDZA */ | ||
140 | + if (!dc_isar_feature(aa64_pauth, s) || rn != 31) { | ||
141 | + goto do_unallocated; | ||
142 | + } else if (s->pauth_active) { | ||
143 | + tcg_rd = cpu_reg(s, rd); | ||
144 | + gen_helper_autda(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s)); | ||
145 | + } | ||
146 | + break; | ||
147 | + case MAP(1, 0x01, 0x0f): /* AUTDZB */ | ||
148 | + if (!dc_isar_feature(aa64_pauth, s) || rn != 31) { | ||
149 | + goto do_unallocated; | ||
150 | + } else if (s->pauth_active) { | ||
151 | + tcg_rd = cpu_reg(s, rd); | ||
152 | + gen_helper_autdb(tcg_rd, cpu_env, tcg_rd, new_tmp_a64_zero(s)); | ||
153 | + } | ||
154 | + break; | ||
155 | + case MAP(1, 0x01, 0x10): /* XPACI */ | ||
156 | + if (!dc_isar_feature(aa64_pauth, s) || rn != 31) { | ||
157 | + goto do_unallocated; | ||
158 | + } else if (s->pauth_active) { | ||
159 | + tcg_rd = cpu_reg(s, rd); | ||
160 | + gen_helper_xpaci(tcg_rd, cpu_env, tcg_rd); | ||
161 | + } | ||
162 | + break; | ||
163 | + case MAP(1, 0x01, 0x11): /* XPACD */ | ||
164 | + if (!dc_isar_feature(aa64_pauth, s) || rn != 31) { | ||
165 | + goto do_unallocated; | ||
166 | + } else if (s->pauth_active) { | ||
167 | + tcg_rd = cpu_reg(s, rd); | ||
168 | + gen_helper_xpacd(tcg_rd, cpu_env, tcg_rd); | ||
169 | + } | ||
170 | + break; | ||
171 | default: | ||
172 | + do_unallocated: | ||
173 | unallocated_encoding(s); | ||
174 | break; | ||
175 | } | ||
176 | -- | ||
177 | 2.20.1 | ||
178 | |||
179 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Replace printf() calls by qemu_log_mask(), which is disabled | ||
4 | by default. This avoid flooding the terminal when fuzzing the | ||
5 | device. | ||
6 | |||
7 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
8 | Message-id: 20200525114123.21317-3-f4bug@amsat.org | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20190108223129.5570-10-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 7 | --- |
12 | hw/arm/pxa2xx.c | 66 ++++++++++++++++++++++++++++++++++++------------- | 8 | target/arm/translate-a64.c | 8 ++++++++ |
13 | 1 file changed, 49 insertions(+), 17 deletions(-) | 9 | 1 file changed, 8 insertions(+) |
14 | 10 | ||
15 | diff --git a/hw/arm/pxa2xx.c b/hw/arm/pxa2xx.c | 11 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
16 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/arm/pxa2xx.c | 13 | --- a/target/arm/translate-a64.c |
18 | +++ b/hw/arm/pxa2xx.c | 14 | +++ b/target/arm/translate-a64.c |
19 | @@ -XXX,XX +XXX,XX @@ | 15 | @@ -XXX,XX +XXX,XX @@ static void disas_data_proc_2src(DisasContext *s, uint32_t insn) |
20 | #include "sysemu/blockdev.h" | 16 | case 11: /* RORV */ |
21 | #include "sysemu/qtest.h" | 17 | handle_shift_reg(s, A64_SHIFT_TYPE_ROR, sf, rm, rn, rd); |
22 | #include "qemu/cutils.h" | 18 | break; |
23 | +#include "qemu/log.h" | 19 | + case 12: /* PACGA */ |
24 | 20 | + if (sf == 0 || !dc_isar_feature(aa64_pauth, s)) { | |
25 | static struct { | 21 | + goto do_unallocated; |
26 | hwaddr io_base; | 22 | + } |
27 | @@ -XXX,XX +XXX,XX @@ static uint64_t pxa2xx_pm_read(void *opaque, hwaddr addr, | 23 | + gen_helper_pacga(cpu_reg(s, rd), cpu_env, |
28 | return s->pm_regs[addr >> 2]; | 24 | + cpu_reg(s, rn), cpu_reg_sp(s, rm)); |
29 | default: | 25 | + break; |
30 | fail: | 26 | case 16: |
31 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | 27 | case 17: |
32 | + qemu_log_mask(LOG_GUEST_ERROR, | 28 | case 18: |
33 | + "%s: Bad read offset 0x%"HWADDR_PRIx"\n", | 29 | @@ -XXX,XX +XXX,XX @@ static void disas_data_proc_2src(DisasContext *s, uint32_t insn) |
34 | + __func__, addr); | ||
35 | break; | 30 | break; |
36 | } | 31 | } |
37 | return 0; | 32 | default: |
38 | @@ -XXX,XX +XXX,XX @@ static void pxa2xx_pm_write(void *opaque, hwaddr addr, | 33 | + do_unallocated: |
39 | s->pm_regs[addr >> 2] = value; | 34 | unallocated_encoding(s); |
40 | break; | ||
41 | } | ||
42 | - | ||
43 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
44 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
45 | + "%s: Bad write offset 0x%"HWADDR_PRIx"\n", | ||
46 | + __func__, addr); | ||
47 | break; | 35 | break; |
48 | } | 36 | } |
49 | } | ||
50 | @@ -XXX,XX +XXX,XX @@ static uint64_t pxa2xx_cm_read(void *opaque, hwaddr addr, | ||
51 | return s->cm_regs[CCCR >> 2] | (3 << 28); | ||
52 | |||
53 | default: | ||
54 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
55 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
56 | + "%s: Bad read offset 0x%"HWADDR_PRIx"\n", | ||
57 | + __func__, addr); | ||
58 | break; | ||
59 | } | ||
60 | return 0; | ||
61 | @@ -XXX,XX +XXX,XX @@ static void pxa2xx_cm_write(void *opaque, hwaddr addr, | ||
62 | break; | ||
63 | |||
64 | default: | ||
65 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
66 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
67 | + "%s: Bad write offset 0x%"HWADDR_PRIx"\n", | ||
68 | + __func__, addr); | ||
69 | break; | ||
70 | } | ||
71 | } | ||
72 | @@ -XXX,XX +XXX,XX @@ static uint64_t pxa2xx_mm_read(void *opaque, hwaddr addr, | ||
73 | return s->mm_regs[addr >> 2]; | ||
74 | /* fall through */ | ||
75 | default: | ||
76 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
77 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
78 | + "%s: Bad read offset 0x%"HWADDR_PRIx"\n", | ||
79 | + __func__, addr); | ||
80 | break; | ||
81 | } | ||
82 | return 0; | ||
83 | @@ -XXX,XX +XXX,XX @@ static void pxa2xx_mm_write(void *opaque, hwaddr addr, | ||
84 | } | ||
85 | |||
86 | default: | ||
87 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
88 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
89 | + "%s: Bad write offset 0x%"HWADDR_PRIx"\n", | ||
90 | + __func__, addr); | ||
91 | break; | ||
92 | } | ||
93 | } | ||
94 | @@ -XXX,XX +XXX,XX @@ static uint64_t pxa2xx_ssp_read(void *opaque, hwaddr addr, | ||
95 | case SSACD: | ||
96 | return s->ssacd; | ||
97 | default: | ||
98 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
99 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
100 | + "%s: Bad read offset 0x%"HWADDR_PRIx"\n", | ||
101 | + __func__, addr); | ||
102 | break; | ||
103 | } | ||
104 | return 0; | ||
105 | @@ -XXX,XX +XXX,XX @@ static void pxa2xx_ssp_write(void *opaque, hwaddr addr, | ||
106 | break; | ||
107 | |||
108 | default: | ||
109 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
110 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
111 | + "%s: Bad write offset 0x%"HWADDR_PRIx"\n", | ||
112 | + __func__, addr); | ||
113 | break; | ||
114 | } | ||
115 | } | ||
116 | @@ -XXX,XX +XXX,XX @@ static uint64_t pxa2xx_rtc_read(void *opaque, hwaddr addr, | ||
117 | else | ||
118 | return s->last_swcr; | ||
119 | default: | ||
120 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
121 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
122 | + "%s: Bad read offset 0x%"HWADDR_PRIx"\n", | ||
123 | + __func__, addr); | ||
124 | break; | ||
125 | } | ||
126 | return 0; | ||
127 | @@ -XXX,XX +XXX,XX @@ static void pxa2xx_rtc_write(void *opaque, hwaddr addr, | ||
128 | break; | ||
129 | |||
130 | default: | ||
131 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
132 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
133 | + "%s: Bad write offset 0x%"HWADDR_PRIx"\n", | ||
134 | + __func__, addr); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | @@ -XXX,XX +XXX,XX @@ static uint64_t pxa2xx_i2c_read(void *opaque, hwaddr addr, | ||
139 | s->ibmr = 0; | ||
140 | return s->ibmr; | ||
141 | default: | ||
142 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
143 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
144 | + "%s: Bad read offset 0x%"HWADDR_PRIx"\n", | ||
145 | + __func__, addr); | ||
146 | break; | ||
147 | } | ||
148 | return 0; | ||
149 | @@ -XXX,XX +XXX,XX @@ static void pxa2xx_i2c_write(void *opaque, hwaddr addr, | ||
150 | break; | ||
151 | |||
152 | default: | ||
153 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
154 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
155 | + "%s: Bad write offset 0x%"HWADDR_PRIx"\n", | ||
156 | + __func__, addr); | ||
157 | } | ||
158 | } | ||
159 | |||
160 | @@ -XXX,XX +XXX,XX @@ static uint64_t pxa2xx_i2s_read(void *opaque, hwaddr addr, | ||
161 | } | ||
162 | return 0; | ||
163 | default: | ||
164 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
165 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
166 | + "%s: Bad read offset 0x%"HWADDR_PRIx"\n", | ||
167 | + __func__, addr); | ||
168 | break; | ||
169 | } | ||
170 | return 0; | ||
171 | @@ -XXX,XX +XXX,XX @@ static void pxa2xx_i2s_write(void *opaque, hwaddr addr, | ||
172 | } | ||
173 | break; | ||
174 | default: | ||
175 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
176 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
177 | + "%s: Bad write offset 0x%"HWADDR_PRIx"\n", | ||
178 | + __func__, addr); | ||
179 | } | ||
180 | } | ||
181 | |||
182 | @@ -XXX,XX +XXX,XX @@ static uint64_t pxa2xx_fir_read(void *opaque, hwaddr addr, | ||
183 | case ICFOR: | ||
184 | return s->rx_len; | ||
185 | default: | ||
186 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
187 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
188 | + "%s: Bad read offset 0x%"HWADDR_PRIx"\n", | ||
189 | + __func__, addr); | ||
190 | break; | ||
191 | } | ||
192 | return 0; | ||
193 | @@ -XXX,XX +XXX,XX @@ static void pxa2xx_fir_write(void *opaque, hwaddr addr, | ||
194 | case ICFOR: | ||
195 | break; | ||
196 | default: | ||
197 | - printf("%s: Bad register " REG_FMT "\n", __func__, addr); | ||
198 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
199 | + "%s: Bad write offset 0x%"HWADDR_PRIx"\n", | ||
200 | + __func__, addr); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | -- | 37 | -- |
205 | 2.20.1 | 38 | 2.20.1 |
206 | 39 | ||
207 | 40 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Do not yet convert the helpers to loop over opr_sz, but the | 3 | This function is only used by AArch64. Code movement only. |
4 | descriptor allows the vector tail to be cleared. Which fixes | 4 | |
5 | an existing bug vs SVE. | 5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | |||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20200514212831.31248-4-richard.henderson@linaro.org | 7 | Message-id: 20190108223129.5570-11-richard.henderson@linaro.org |
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 9 | --- |
12 | target/arm/helper.h | 15 +++++++----- | 10 | target/arm/helper-a64.h | 2 + |
13 | target/arm/crypto_helper.c | 37 +++++++++++++++++++++++----- | 11 | target/arm/helper.h | 1 - |
14 | target/arm/translate-a64.c | 50 ++++++++++++-------------------------- | 12 | target/arm/helper-a64.c | 155 ++++++++++++++++++++++++++++++++++++++++ |
15 | 3 files changed, 55 insertions(+), 47 deletions(-) | 13 | target/arm/op_helper.c | 155 ---------------------------------------- |
16 | 14 | 4 files changed, 157 insertions(+), 156 deletions(-) | |
15 | |||
16 | diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/target/arm/helper-a64.h | ||
19 | +++ b/target/arm/helper-a64.h | ||
20 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(advsimd_f16tosinth, i32, f16, ptr) | ||
21 | DEF_HELPER_2(advsimd_f16touinth, i32, f16, ptr) | ||
22 | DEF_HELPER_2(sqrt_f16, f16, f16, ptr) | ||
23 | |||
24 | +DEF_HELPER_1(exception_return, void, env) | ||
25 | + | ||
26 | DEF_HELPER_FLAGS_3(pacia, TCG_CALL_NO_WG, i64, env, i64, i64) | ||
27 | DEF_HELPER_FLAGS_3(pacib, TCG_CALL_NO_WG, i64, env, i64, i64) | ||
28 | DEF_HELPER_FLAGS_3(pacda, TCG_CALL_NO_WG, i64, env, i64, i64) | ||
17 | diff --git a/target/arm/helper.h b/target/arm/helper.h | 29 | diff --git a/target/arm/helper.h b/target/arm/helper.h |
18 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/arm/helper.h | 31 | --- a/target/arm/helper.h |
20 | +++ b/target/arm/helper.h | 32 | +++ b/target/arm/helper.h |
21 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_3(crypto_sha256h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 33 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(get_cp_reg64, i64, env, ptr) |
22 | DEF_HELPER_FLAGS_2(crypto_sha256su0, TCG_CALL_NO_RWG, void, ptr, ptr) | 34 | |
23 | DEF_HELPER_FLAGS_3(crypto_sha256su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 35 | DEF_HELPER_3(msr_i_pstate, void, env, i32, i32) |
24 | 36 | DEF_HELPER_1(clear_pstate_ss, void, env) | |
25 | -DEF_HELPER_FLAGS_3(crypto_sha512h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 37 | -DEF_HELPER_1(exception_return, void, env) |
26 | -DEF_HELPER_FLAGS_3(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 38 | |
27 | -DEF_HELPER_FLAGS_2(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr) | 39 | DEF_HELPER_2(get_r13_banked, i32, env, i32) |
28 | -DEF_HELPER_FLAGS_3(crypto_sha512su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | 40 | DEF_HELPER_3(set_r13_banked, void, env, i32, i32) |
29 | +DEF_HELPER_FLAGS_4(crypto_sha512h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | 41 | diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c |
30 | +DEF_HELPER_FLAGS_4(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
31 | +DEF_HELPER_FLAGS_3(crypto_sha512su0, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
32 | +DEF_HELPER_FLAGS_4(crypto_sha512su1, TCG_CALL_NO_RWG, | ||
33 | + void, ptr, ptr, ptr, i32) | ||
34 | |||
35 | DEF_HELPER_FLAGS_5(crypto_sm3tt, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32, i32) | ||
36 | -DEF_HELPER_FLAGS_3(crypto_sm3partw1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
37 | -DEF_HELPER_FLAGS_3(crypto_sm3partw2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
38 | +DEF_HELPER_FLAGS_4(crypto_sm3partw1, TCG_CALL_NO_RWG, | ||
39 | + void, ptr, ptr, ptr, i32) | ||
40 | +DEF_HELPER_FLAGS_4(crypto_sm3partw2, TCG_CALL_NO_RWG, | ||
41 | + void, ptr, ptr, ptr, i32) | ||
42 | |||
43 | DEF_HELPER_FLAGS_4(crypto_sm4e, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
44 | DEF_HELPER_FLAGS_4(crypto_sm4ekey, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
45 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
46 | index XXXXXXX..XXXXXXX 100644 | 42 | index XXXXXXX..XXXXXXX 100644 |
47 | --- a/target/arm/crypto_helper.c | 43 | --- a/target/arm/helper-a64.c |
48 | +++ b/target/arm/crypto_helper.c | 44 | +++ b/target/arm/helper-a64.c |
49 | @@ -XXX,XX +XXX,XX @@ union CRYPTO_STATE { | 45 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(advsimd_f16touinth)(uint32_t a, void *fpstp) |
50 | #define CR_ST_WORD(state, i) (state.words[i]) | 46 | return float16_to_uint16(a, fpst); |
51 | #endif | 47 | } |
52 | 48 | ||
53 | +/* | 49 | +static int el_from_spsr(uint32_t spsr) |
54 | + * The caller has not been converted to full gvec, and so only | ||
55 | + * modifies the low 16 bytes of the vector register. | ||
56 | + */ | ||
57 | +static void clear_tail_16(void *vd, uint32_t desc) | ||
58 | +{ | 50 | +{ |
59 | + int opr_sz = simd_oprsz(desc); | 51 | + /* Return the exception level that this SPSR is requesting a return to, |
60 | + int max_sz = simd_maxsz(desc); | 52 | + * or -1 if it is invalid (an illegal return) |
61 | + | 53 | + */ |
62 | + assert(opr_sz == 16); | 54 | + if (spsr & PSTATE_nRW) { |
63 | + clear_tail(vd, opr_sz, max_sz); | 55 | + switch (spsr & CPSR_M) { |
56 | + case ARM_CPU_MODE_USR: | ||
57 | + return 0; | ||
58 | + case ARM_CPU_MODE_HYP: | ||
59 | + return 2; | ||
60 | + case ARM_CPU_MODE_FIQ: | ||
61 | + case ARM_CPU_MODE_IRQ: | ||
62 | + case ARM_CPU_MODE_SVC: | ||
63 | + case ARM_CPU_MODE_ABT: | ||
64 | + case ARM_CPU_MODE_UND: | ||
65 | + case ARM_CPU_MODE_SYS: | ||
66 | + return 1; | ||
67 | + case ARM_CPU_MODE_MON: | ||
68 | + /* Returning to Mon from AArch64 is never possible, | ||
69 | + * so this is an illegal return. | ||
70 | + */ | ||
71 | + default: | ||
72 | + return -1; | ||
73 | + } | ||
74 | + } else { | ||
75 | + if (extract32(spsr, 1, 1)) { | ||
76 | + /* Return with reserved M[1] bit set */ | ||
77 | + return -1; | ||
78 | + } | ||
79 | + if (extract32(spsr, 0, 4) == 1) { | ||
80 | + /* return to EL0 with M[0] bit set */ | ||
81 | + return -1; | ||
82 | + } | ||
83 | + return extract32(spsr, 2, 2); | ||
84 | + } | ||
64 | +} | 85 | +} |
65 | + | 86 | + |
66 | static void do_crypto_aese(uint64_t *rd, uint64_t *rn, | 87 | +void HELPER(exception_return)(CPUARMState *env) |
67 | uint64_t *rm, bool decrypt) | 88 | +{ |
68 | { | 89 | + int cur_el = arm_current_el(env); |
69 | @@ -XXX,XX +XXX,XX @@ static uint64_t s1_512(uint64_t x) | 90 | + unsigned int spsr_idx = aarch64_banked_spsr_index(cur_el); |
70 | return ror64(x, 19) ^ ror64(x, 61) ^ (x >> 6); | 91 | + uint32_t spsr = env->banked_spsr[spsr_idx]; |
71 | } | 92 | + int new_el; |
72 | 93 | + bool return_to_aa64 = (spsr & PSTATE_nRW) == 0; | |
73 | -void HELPER(crypto_sha512h)(void *vd, void *vn, void *vm) | 94 | + |
74 | +void HELPER(crypto_sha512h)(void *vd, void *vn, void *vm, uint32_t desc) | 95 | + aarch64_save_sp(env, cur_el); |
75 | { | 96 | + |
76 | uint64_t *rd = vd; | 97 | + arm_clear_exclusive(env); |
77 | uint64_t *rn = vn; | 98 | + |
78 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha512h)(void *vd, void *vn, void *vm) | 99 | + /* We must squash the PSTATE.SS bit to zero unless both of the |
79 | 100 | + * following hold: | |
80 | rd[0] = d0; | 101 | + * 1. debug exceptions are currently disabled |
81 | rd[1] = d1; | 102 | + * 2. singlestep will be active in the EL we return to |
82 | + | 103 | + * We check 1 here and 2 after we've done the pstate/cpsr write() to |
83 | + clear_tail_16(vd, desc); | 104 | + * transition to the EL we're going to. |
84 | } | 105 | + */ |
85 | 106 | + if (arm_generate_debug_exceptions(env)) { | |
86 | -void HELPER(crypto_sha512h2)(void *vd, void *vn, void *vm) | 107 | + spsr &= ~PSTATE_SS; |
87 | +void HELPER(crypto_sha512h2)(void *vd, void *vn, void *vm, uint32_t desc) | 108 | + } |
88 | { | 109 | + |
89 | uint64_t *rd = vd; | 110 | + new_el = el_from_spsr(spsr); |
90 | uint64_t *rn = vn; | 111 | + if (new_el == -1) { |
91 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha512h2)(void *vd, void *vn, void *vm) | 112 | + goto illegal_return; |
92 | 113 | + } | |
93 | rd[0] = d0; | 114 | + if (new_el > cur_el |
94 | rd[1] = d1; | 115 | + || (new_el == 2 && !arm_feature(env, ARM_FEATURE_EL2))) { |
95 | + | 116 | + /* Disallow return to an EL which is unimplemented or higher |
96 | + clear_tail_16(vd, desc); | 117 | + * than the current one. |
97 | } | 118 | + */ |
98 | 119 | + goto illegal_return; | |
99 | -void HELPER(crypto_sha512su0)(void *vd, void *vn) | 120 | + } |
100 | +void HELPER(crypto_sha512su0)(void *vd, void *vn, uint32_t desc) | 121 | + |
101 | { | 122 | + if (new_el != 0 && arm_el_is_aa64(env, new_el) != return_to_aa64) { |
102 | uint64_t *rd = vd; | 123 | + /* Return to an EL which is configured for a different register width */ |
103 | uint64_t *rn = vn; | 124 | + goto illegal_return; |
104 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha512su0)(void *vd, void *vn) | 125 | + } |
105 | 126 | + | |
106 | rd[0] = d0; | 127 | + if (new_el == 2 && arm_is_secure_below_el3(env)) { |
107 | rd[1] = d1; | 128 | + /* Return to the non-existent secure-EL2 */ |
108 | + | 129 | + goto illegal_return; |
109 | + clear_tail_16(vd, desc); | 130 | + } |
110 | } | 131 | + |
111 | 132 | + if (new_el == 1 && (arm_hcr_el2_eff(env) & HCR_TGE)) { | |
112 | -void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm) | 133 | + goto illegal_return; |
113 | +void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm, uint32_t desc) | 134 | + } |
114 | { | 135 | + |
115 | uint64_t *rd = vd; | 136 | + qemu_mutex_lock_iothread(); |
116 | uint64_t *rn = vn; | 137 | + arm_call_pre_el_change_hook(arm_env_get_cpu(env)); |
117 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha512su1)(void *vd, void *vn, void *vm) | 138 | + qemu_mutex_unlock_iothread(); |
118 | 139 | + | |
119 | rd[0] += s1_512(rn[0]) + rm[0]; | 140 | + if (!return_to_aa64) { |
120 | rd[1] += s1_512(rn[1]) + rm[1]; | 141 | + env->aarch64 = 0; |
121 | + | 142 | + /* We do a raw CPSR write because aarch64_sync_64_to_32() |
122 | + clear_tail_16(vd, desc); | 143 | + * will sort the register banks out for us, and we've already |
123 | } | 144 | + * caught all the bad-mode cases in el_from_spsr(). |
124 | 145 | + */ | |
125 | -void HELPER(crypto_sm3partw1)(void *vd, void *vn, void *vm) | 146 | + cpsr_write(env, spsr, ~0, CPSRWriteRaw); |
126 | +void HELPER(crypto_sm3partw1)(void *vd, void *vn, void *vm, uint32_t desc) | 147 | + if (!arm_singlestep_active(env)) { |
127 | { | 148 | + env->uncached_cpsr &= ~PSTATE_SS; |
128 | uint64_t *rd = vd; | 149 | + } |
129 | uint64_t *rn = vn; | 150 | + aarch64_sync_64_to_32(env); |
130 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm3partw1)(void *vd, void *vn, void *vm) | 151 | + |
131 | 152 | + if (spsr & CPSR_T) { | |
132 | rd[0] = d.l[0]; | 153 | + env->regs[15] = env->elr_el[cur_el] & ~0x1; |
133 | rd[1] = d.l[1]; | 154 | + } else { |
134 | + | 155 | + env->regs[15] = env->elr_el[cur_el] & ~0x3; |
135 | + clear_tail_16(vd, desc); | 156 | + } |
136 | } | 157 | + qemu_log_mask(CPU_LOG_INT, "Exception return from AArch64 EL%d to " |
137 | 158 | + "AArch32 EL%d PC 0x%" PRIx32 "\n", | |
138 | -void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm) | 159 | + cur_el, new_el, env->regs[15]); |
139 | +void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm, uint32_t desc) | 160 | + } else { |
140 | { | 161 | + env->aarch64 = 1; |
141 | uint64_t *rd = vd; | 162 | + pstate_write(env, spsr); |
142 | uint64_t *rn = vn; | 163 | + if (!arm_singlestep_active(env)) { |
143 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sm3partw2)(void *vd, void *vn, void *vm) | 164 | + env->pstate &= ~PSTATE_SS; |
144 | 165 | + } | |
145 | rd[0] = d.l[0]; | 166 | + aarch64_restore_sp(env, new_el); |
146 | rd[1] = d.l[1]; | 167 | + env->pc = env->elr_el[cur_el]; |
147 | + | 168 | + qemu_log_mask(CPU_LOG_INT, "Exception return from AArch64 EL%d to " |
148 | + clear_tail_16(vd, desc); | 169 | + "AArch64 EL%d PC 0x%" PRIx64 "\n", |
149 | } | 170 | + cur_el, new_el, env->pc); |
150 | 171 | + } | |
151 | void HELPER(crypto_sm3tt)(void *vd, void *vn, void *vm, uint32_t imm2, | 172 | + /* |
152 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 173 | + * Note that cur_el can never be 0. If new_el is 0, then |
174 | + * el0_a64 is return_to_aa64, else el0_a64 is ignored. | ||
175 | + */ | ||
176 | + aarch64_sve_change_el(env, cur_el, new_el, return_to_aa64); | ||
177 | + | ||
178 | + qemu_mutex_lock_iothread(); | ||
179 | + arm_call_el_change_hook(arm_env_get_cpu(env)); | ||
180 | + qemu_mutex_unlock_iothread(); | ||
181 | + | ||
182 | + return; | ||
183 | + | ||
184 | +illegal_return: | ||
185 | + /* Illegal return events of various kinds have architecturally | ||
186 | + * mandated behaviour: | ||
187 | + * restore NZCV and DAIF from SPSR_ELx | ||
188 | + * set PSTATE.IL | ||
189 | + * restore PC from ELR_ELx | ||
190 | + * no change to exception level, execution state or stack pointer | ||
191 | + */ | ||
192 | + env->pstate |= PSTATE_IL; | ||
193 | + env->pc = env->elr_el[cur_el]; | ||
194 | + spsr &= PSTATE_NZCV | PSTATE_DAIF; | ||
195 | + spsr |= pstate_read(env) & ~(PSTATE_NZCV | PSTATE_DAIF); | ||
196 | + pstate_write(env, spsr); | ||
197 | + if (!arm_singlestep_active(env)) { | ||
198 | + env->pstate &= ~PSTATE_SS; | ||
199 | + } | ||
200 | + qemu_log_mask(LOG_GUEST_ERROR, "Illegal exception return at EL%d: " | ||
201 | + "resuming execution at 0x%" PRIx64 "\n", cur_el, env->pc); | ||
202 | +} | ||
203 | + | ||
204 | /* | ||
205 | * Square Root and Reciprocal square root | ||
206 | */ | ||
207 | diff --git a/target/arm/op_helper.c b/target/arm/op_helper.c | ||
153 | index XXXXXXX..XXXXXXX 100644 | 208 | index XXXXXXX..XXXXXXX 100644 |
154 | --- a/target/arm/translate-a64.c | 209 | --- a/target/arm/op_helper.c |
155 | +++ b/target/arm/translate-a64.c | 210 | +++ b/target/arm/op_helper.c |
156 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | 211 | @@ -XXX,XX +XXX,XX @@ void HELPER(pre_smc)(CPUARMState *env, uint32_t syndrome) |
157 | int rn = extract32(insn, 5, 5); | ||
158 | int rd = extract32(insn, 0, 5); | ||
159 | bool feature; | ||
160 | - CryptoThreeOpFn *genfn = NULL; | ||
161 | gen_helper_gvec_3 *oolfn = NULL; | ||
162 | GVecGen3Fn *gvecfn = NULL; | ||
163 | |||
164 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
165 | switch (opcode) { | ||
166 | case 0: /* SHA512H */ | ||
167 | feature = dc_isar_feature(aa64_sha512, s); | ||
168 | - genfn = gen_helper_crypto_sha512h; | ||
169 | + oolfn = gen_helper_crypto_sha512h; | ||
170 | break; | ||
171 | case 1: /* SHA512H2 */ | ||
172 | feature = dc_isar_feature(aa64_sha512, s); | ||
173 | - genfn = gen_helper_crypto_sha512h2; | ||
174 | + oolfn = gen_helper_crypto_sha512h2; | ||
175 | break; | ||
176 | case 2: /* SHA512SU1 */ | ||
177 | feature = dc_isar_feature(aa64_sha512, s); | ||
178 | - genfn = gen_helper_crypto_sha512su1; | ||
179 | + oolfn = gen_helper_crypto_sha512su1; | ||
180 | break; | ||
181 | case 3: /* RAX1 */ | ||
182 | feature = dc_isar_feature(aa64_sha3, s); | ||
183 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
184 | switch (opcode) { | ||
185 | case 0: /* SM3PARTW1 */ | ||
186 | feature = dc_isar_feature(aa64_sm3, s); | ||
187 | - genfn = gen_helper_crypto_sm3partw1; | ||
188 | + oolfn = gen_helper_crypto_sm3partw1; | ||
189 | break; | ||
190 | case 1: /* SM3PARTW2 */ | ||
191 | feature = dc_isar_feature(aa64_sm3, s); | ||
192 | - genfn = gen_helper_crypto_sm3partw2; | ||
193 | + oolfn = gen_helper_crypto_sm3partw2; | ||
194 | break; | ||
195 | case 2: /* SM4EKEY */ | ||
196 | feature = dc_isar_feature(aa64_sm4, s); | ||
197 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha512(DisasContext *s, uint32_t insn) | ||
198 | |||
199 | if (oolfn) { | ||
200 | gen_gvec_op3_ool(s, true, rd, rn, rm, 0, oolfn); | ||
201 | - } else if (gvecfn) { | ||
202 | - gen_gvec_fn3(s, true, rd, rn, rm, gvecfn, MO_64); | ||
203 | } else { | ||
204 | - TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | ||
205 | - | ||
206 | - tcg_rd_ptr = vec_full_reg_ptr(s, rd); | ||
207 | - tcg_rn_ptr = vec_full_reg_ptr(s, rn); | ||
208 | - tcg_rm_ptr = vec_full_reg_ptr(s, rm); | ||
209 | - | ||
210 | - genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr); | ||
211 | - | ||
212 | - tcg_temp_free_ptr(tcg_rd_ptr); | ||
213 | - tcg_temp_free_ptr(tcg_rn_ptr); | ||
214 | - tcg_temp_free_ptr(tcg_rm_ptr); | ||
215 | + gen_gvec_fn3(s, true, rd, rn, rm, gvecfn, MO_64); | ||
216 | } | 212 | } |
217 | } | 213 | } |
218 | 214 | ||
219 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | 215 | -static int el_from_spsr(uint32_t spsr) |
220 | int opcode = extract32(insn, 10, 2); | 216 | -{ |
221 | int rn = extract32(insn, 5, 5); | 217 | - /* Return the exception level that this SPSR is requesting a return to, |
222 | int rd = extract32(insn, 0, 5); | 218 | - * or -1 if it is invalid (an illegal return) |
223 | - TCGv_ptr tcg_rd_ptr, tcg_rn_ptr; | 219 | - */ |
224 | bool feature; | 220 | - if (spsr & PSTATE_nRW) { |
225 | - CryptoTwoOpFn *genfn; | 221 | - switch (spsr & CPSR_M) { |
226 | - gen_helper_gvec_3 *oolfn = NULL; | 222 | - case ARM_CPU_MODE_USR: |
227 | 223 | - return 0; | |
228 | switch (opcode) { | 224 | - case ARM_CPU_MODE_HYP: |
229 | case 0: /* SHA512SU0 */ | 225 | - return 2; |
230 | feature = dc_isar_feature(aa64_sha512, s); | 226 | - case ARM_CPU_MODE_FIQ: |
231 | - genfn = gen_helper_crypto_sha512su0; | 227 | - case ARM_CPU_MODE_IRQ: |
232 | break; | 228 | - case ARM_CPU_MODE_SVC: |
233 | case 1: /* SM4E */ | 229 | - case ARM_CPU_MODE_ABT: |
234 | feature = dc_isar_feature(aa64_sm4, s); | 230 | - case ARM_CPU_MODE_UND: |
235 | - oolfn = gen_helper_crypto_sm4e; | 231 | - case ARM_CPU_MODE_SYS: |
236 | break; | 232 | - return 1; |
237 | default: | 233 | - case ARM_CPU_MODE_MON: |
238 | unallocated_encoding(s); | 234 | - /* Returning to Mon from AArch64 is never possible, |
239 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha512(DisasContext *s, uint32_t insn) | 235 | - * so this is an illegal return. |
240 | return; | 236 | - */ |
241 | } | 237 | - default: |
242 | 238 | - return -1; | |
243 | - if (oolfn) { | 239 | - } |
244 | - gen_gvec_op3_ool(s, true, rd, rd, rn, 0, oolfn); | 240 | - } else { |
245 | - return; | 241 | - if (extract32(spsr, 1, 1)) { |
246 | + switch (opcode) { | 242 | - /* Return with reserved M[1] bit set */ |
247 | + case 0: /* SHA512SU0 */ | 243 | - return -1; |
248 | + gen_gvec_op2_ool(s, true, rd, rn, 0, gen_helper_crypto_sha512su0); | 244 | - } |
249 | + break; | 245 | - if (extract32(spsr, 0, 4) == 1) { |
250 | + case 1: /* SM4E */ | 246 | - /* return to EL0 with M[0] bit set */ |
251 | + gen_gvec_op3_ool(s, true, rd, rd, rn, 0, gen_helper_crypto_sm4e); | 247 | - return -1; |
252 | + break; | 248 | - } |
253 | + default: | 249 | - return extract32(spsr, 2, 2); |
254 | + g_assert_not_reached(); | 250 | - } |
255 | } | 251 | -} |
256 | - | 252 | - |
257 | - tcg_rd_ptr = vec_full_reg_ptr(s, rd); | 253 | -void HELPER(exception_return)(CPUARMState *env) |
258 | - tcg_rn_ptr = vec_full_reg_ptr(s, rn); | 254 | -{ |
259 | - | 255 | - int cur_el = arm_current_el(env); |
260 | - genfn(tcg_rd_ptr, tcg_rn_ptr); | 256 | - unsigned int spsr_idx = aarch64_banked_spsr_index(cur_el); |
261 | - | 257 | - uint32_t spsr = env->banked_spsr[spsr_idx]; |
262 | - tcg_temp_free_ptr(tcg_rd_ptr); | 258 | - int new_el; |
263 | - tcg_temp_free_ptr(tcg_rn_ptr); | 259 | - bool return_to_aa64 = (spsr & PSTATE_nRW) == 0; |
264 | } | 260 | - |
265 | 261 | - aarch64_save_sp(env, cur_el); | |
266 | /* Crypto four-register | 262 | - |
263 | - arm_clear_exclusive(env); | ||
264 | - | ||
265 | - /* We must squash the PSTATE.SS bit to zero unless both of the | ||
266 | - * following hold: | ||
267 | - * 1. debug exceptions are currently disabled | ||
268 | - * 2. singlestep will be active in the EL we return to | ||
269 | - * We check 1 here and 2 after we've done the pstate/cpsr write() to | ||
270 | - * transition to the EL we're going to. | ||
271 | - */ | ||
272 | - if (arm_generate_debug_exceptions(env)) { | ||
273 | - spsr &= ~PSTATE_SS; | ||
274 | - } | ||
275 | - | ||
276 | - new_el = el_from_spsr(spsr); | ||
277 | - if (new_el == -1) { | ||
278 | - goto illegal_return; | ||
279 | - } | ||
280 | - if (new_el > cur_el | ||
281 | - || (new_el == 2 && !arm_feature(env, ARM_FEATURE_EL2))) { | ||
282 | - /* Disallow return to an EL which is unimplemented or higher | ||
283 | - * than the current one. | ||
284 | - */ | ||
285 | - goto illegal_return; | ||
286 | - } | ||
287 | - | ||
288 | - if (new_el != 0 && arm_el_is_aa64(env, new_el) != return_to_aa64) { | ||
289 | - /* Return to an EL which is configured for a different register width */ | ||
290 | - goto illegal_return; | ||
291 | - } | ||
292 | - | ||
293 | - if (new_el == 2 && arm_is_secure_below_el3(env)) { | ||
294 | - /* Return to the non-existent secure-EL2 */ | ||
295 | - goto illegal_return; | ||
296 | - } | ||
297 | - | ||
298 | - if (new_el == 1 && (arm_hcr_el2_eff(env) & HCR_TGE)) { | ||
299 | - goto illegal_return; | ||
300 | - } | ||
301 | - | ||
302 | - qemu_mutex_lock_iothread(); | ||
303 | - arm_call_pre_el_change_hook(arm_env_get_cpu(env)); | ||
304 | - qemu_mutex_unlock_iothread(); | ||
305 | - | ||
306 | - if (!return_to_aa64) { | ||
307 | - env->aarch64 = 0; | ||
308 | - /* We do a raw CPSR write because aarch64_sync_64_to_32() | ||
309 | - * will sort the register banks out for us, and we've already | ||
310 | - * caught all the bad-mode cases in el_from_spsr(). | ||
311 | - */ | ||
312 | - cpsr_write(env, spsr, ~0, CPSRWriteRaw); | ||
313 | - if (!arm_singlestep_active(env)) { | ||
314 | - env->uncached_cpsr &= ~PSTATE_SS; | ||
315 | - } | ||
316 | - aarch64_sync_64_to_32(env); | ||
317 | - | ||
318 | - if (spsr & CPSR_T) { | ||
319 | - env->regs[15] = env->elr_el[cur_el] & ~0x1; | ||
320 | - } else { | ||
321 | - env->regs[15] = env->elr_el[cur_el] & ~0x3; | ||
322 | - } | ||
323 | - qemu_log_mask(CPU_LOG_INT, "Exception return from AArch64 EL%d to " | ||
324 | - "AArch32 EL%d PC 0x%" PRIx32 "\n", | ||
325 | - cur_el, new_el, env->regs[15]); | ||
326 | - } else { | ||
327 | - env->aarch64 = 1; | ||
328 | - pstate_write(env, spsr); | ||
329 | - if (!arm_singlestep_active(env)) { | ||
330 | - env->pstate &= ~PSTATE_SS; | ||
331 | - } | ||
332 | - aarch64_restore_sp(env, new_el); | ||
333 | - env->pc = env->elr_el[cur_el]; | ||
334 | - qemu_log_mask(CPU_LOG_INT, "Exception return from AArch64 EL%d to " | ||
335 | - "AArch64 EL%d PC 0x%" PRIx64 "\n", | ||
336 | - cur_el, new_el, env->pc); | ||
337 | - } | ||
338 | - /* | ||
339 | - * Note that cur_el can never be 0. If new_el is 0, then | ||
340 | - * el0_a64 is return_to_aa64, else el0_a64 is ignored. | ||
341 | - */ | ||
342 | - aarch64_sve_change_el(env, cur_el, new_el, return_to_aa64); | ||
343 | - | ||
344 | - qemu_mutex_lock_iothread(); | ||
345 | - arm_call_el_change_hook(arm_env_get_cpu(env)); | ||
346 | - qemu_mutex_unlock_iothread(); | ||
347 | - | ||
348 | - return; | ||
349 | - | ||
350 | -illegal_return: | ||
351 | - /* Illegal return events of various kinds have architecturally | ||
352 | - * mandated behaviour: | ||
353 | - * restore NZCV and DAIF from SPSR_ELx | ||
354 | - * set PSTATE.IL | ||
355 | - * restore PC from ELR_ELx | ||
356 | - * no change to exception level, execution state or stack pointer | ||
357 | - */ | ||
358 | - env->pstate |= PSTATE_IL; | ||
359 | - env->pc = env->elr_el[cur_el]; | ||
360 | - spsr &= PSTATE_NZCV | PSTATE_DAIF; | ||
361 | - spsr |= pstate_read(env) & ~(PSTATE_NZCV | PSTATE_DAIF); | ||
362 | - pstate_write(env, spsr); | ||
363 | - if (!arm_singlestep_active(env)) { | ||
364 | - env->pstate &= ~PSTATE_SS; | ||
365 | - } | ||
366 | - qemu_log_mask(LOG_GUEST_ERROR, "Illegal exception return at EL%d: " | ||
367 | - "resuming execution at 0x%" PRIx64 "\n", cur_el, env->pc); | ||
368 | -} | ||
369 | - | ||
370 | /* Return true if the linked breakpoint entry lbn passes its checks */ | ||
371 | static bool linked_bp_matches(ARMCPU *cpu, int lbn) | ||
372 | { | ||
267 | -- | 373 | -- |
268 | 2.20.1 | 374 | 2.20.1 |
269 | 375 | ||
270 | 376 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20190108223129.5570-12-richard.henderson@linaro.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | target/arm/helper-a64.h | 2 +- | ||
9 | target/arm/helper-a64.c | 10 +++++----- | ||
10 | target/arm/translate-a64.c | 7 ++++++- | ||
11 | 3 files changed, 12 insertions(+), 7 deletions(-) | ||
12 | |||
13 | diff --git a/target/arm/helper-a64.h b/target/arm/helper-a64.h | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/arm/helper-a64.h | ||
16 | +++ b/target/arm/helper-a64.h | ||
17 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_2(advsimd_f16tosinth, i32, f16, ptr) | ||
18 | DEF_HELPER_2(advsimd_f16touinth, i32, f16, ptr) | ||
19 | DEF_HELPER_2(sqrt_f16, f16, f16, ptr) | ||
20 | |||
21 | -DEF_HELPER_1(exception_return, void, env) | ||
22 | +DEF_HELPER_2(exception_return, void, env, i64) | ||
23 | |||
24 | DEF_HELPER_FLAGS_3(pacia, TCG_CALL_NO_WG, i64, env, i64, i64) | ||
25 | DEF_HELPER_FLAGS_3(pacib, TCG_CALL_NO_WG, i64, env, i64, i64) | ||
26 | diff --git a/target/arm/helper-a64.c b/target/arm/helper-a64.c | ||
27 | index XXXXXXX..XXXXXXX 100644 | ||
28 | --- a/target/arm/helper-a64.c | ||
29 | +++ b/target/arm/helper-a64.c | ||
30 | @@ -XXX,XX +XXX,XX @@ static int el_from_spsr(uint32_t spsr) | ||
31 | } | ||
32 | } | ||
33 | |||
34 | -void HELPER(exception_return)(CPUARMState *env) | ||
35 | +void HELPER(exception_return)(CPUARMState *env, uint64_t new_pc) | ||
36 | { | ||
37 | int cur_el = arm_current_el(env); | ||
38 | unsigned int spsr_idx = aarch64_banked_spsr_index(cur_el); | ||
39 | @@ -XXX,XX +XXX,XX @@ void HELPER(exception_return)(CPUARMState *env) | ||
40 | aarch64_sync_64_to_32(env); | ||
41 | |||
42 | if (spsr & CPSR_T) { | ||
43 | - env->regs[15] = env->elr_el[cur_el] & ~0x1; | ||
44 | + env->regs[15] = new_pc & ~0x1; | ||
45 | } else { | ||
46 | - env->regs[15] = env->elr_el[cur_el] & ~0x3; | ||
47 | + env->regs[15] = new_pc & ~0x3; | ||
48 | } | ||
49 | qemu_log_mask(CPU_LOG_INT, "Exception return from AArch64 EL%d to " | ||
50 | "AArch32 EL%d PC 0x%" PRIx32 "\n", | ||
51 | @@ -XXX,XX +XXX,XX @@ void HELPER(exception_return)(CPUARMState *env) | ||
52 | env->pstate &= ~PSTATE_SS; | ||
53 | } | ||
54 | aarch64_restore_sp(env, new_el); | ||
55 | - env->pc = env->elr_el[cur_el]; | ||
56 | + env->pc = new_pc; | ||
57 | qemu_log_mask(CPU_LOG_INT, "Exception return from AArch64 EL%d to " | ||
58 | "AArch64 EL%d PC 0x%" PRIx64 "\n", | ||
59 | cur_el, new_el, env->pc); | ||
60 | @@ -XXX,XX +XXX,XX @@ illegal_return: | ||
61 | * no change to exception level, execution state or stack pointer | ||
62 | */ | ||
63 | env->pstate |= PSTATE_IL; | ||
64 | - env->pc = env->elr_el[cur_el]; | ||
65 | + env->pc = new_pc; | ||
66 | spsr &= PSTATE_NZCV | PSTATE_DAIF; | ||
67 | spsr |= pstate_read(env) & ~(PSTATE_NZCV | PSTATE_DAIF); | ||
68 | pstate_write(env, spsr); | ||
69 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/target/arm/translate-a64.c | ||
72 | +++ b/target/arm/translate-a64.c | ||
73 | @@ -XXX,XX +XXX,XX @@ static void disas_exc(DisasContext *s, uint32_t insn) | ||
74 | static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) | ||
75 | { | ||
76 | unsigned int opc, op2, op3, rn, op4; | ||
77 | + TCGv_i64 dst; | ||
78 | |||
79 | opc = extract32(insn, 21, 4); | ||
80 | op2 = extract32(insn, 16, 5); | ||
81 | @@ -XXX,XX +XXX,XX @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) | ||
82 | if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) { | ||
83 | gen_io_start(); | ||
84 | } | ||
85 | - gen_helper_exception_return(cpu_env); | ||
86 | + dst = tcg_temp_new_i64(); | ||
87 | + tcg_gen_ld_i64(dst, cpu_env, | ||
88 | + offsetof(CPUARMState, elr_el[s->current_el])); | ||
89 | + gen_helper_exception_return(cpu_env, dst); | ||
90 | + tcg_temp_free_i64(dst); | ||
91 | if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) { | ||
92 | gen_io_end(); | ||
93 | } | ||
94 | -- | ||
95 | 2.20.1 | ||
96 | |||
97 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Rather than passing an opcode to a helper, fully decode the | 3 | This will enable PAuth decode in a subsequent patch. |
4 | operation at translate time. Use clear_tail_16 to zap the | ||
5 | balance of the SVE register with the AdvSIMD write. | ||
6 | 4 | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20200514212831.31248-6-richard.henderson@linaro.org | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Message-id: 20190108223129.5570-13-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 9 | --- |
12 | target/arm/helper.h | 5 +- | 10 | target/arm/translate-a64.c | 47 +++++++++++++++++++++++++++++--------- |
13 | target/arm/neon-dp.decode | 6 +- | 11 | 1 file changed, 36 insertions(+), 11 deletions(-) |
14 | target/arm/crypto_helper.c | 99 +++++++++++++++++++++------------ | ||
15 | target/arm/translate-a64.c | 29 ++++------ | ||
16 | target/arm/translate-neon.inc.c | 46 ++++----------- | ||
17 | 5 files changed, 93 insertions(+), 92 deletions(-) | ||
18 | 12 | ||
19 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/target/arm/helper.h | ||
22 | +++ b/target/arm/helper.h | ||
23 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_2(neon_qzip32, TCG_CALL_NO_RWG, void, ptr, ptr) | ||
24 | DEF_HELPER_FLAGS_4(crypto_aese, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
25 | DEF_HELPER_FLAGS_3(crypto_aesmc, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
26 | |||
27 | -DEF_HELPER_FLAGS_4(crypto_sha1_3reg, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
28 | +DEF_HELPER_FLAGS_4(crypto_sha1su0, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
29 | +DEF_HELPER_FLAGS_4(crypto_sha1c, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
30 | +DEF_HELPER_FLAGS_4(crypto_sha1p, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
31 | +DEF_HELPER_FLAGS_4(crypto_sha1m, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
32 | DEF_HELPER_FLAGS_3(crypto_sha1h, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
33 | DEF_HELPER_FLAGS_3(crypto_sha1su1, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
34 | |||
35 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/target/arm/neon-dp.decode | ||
38 | +++ b/target/arm/neon-dp.decode | ||
39 | @@ -XXX,XX +XXX,XX @@ VQRDMLAH_3s 1111 001 1 0 . .. .... .... 1011 ... 1 .... @3same | ||
40 | @3same_crypto .... .... .... .... .... .... .... .... \ | ||
41 | &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp size=0 q=1 | ||
42 | |||
43 | -SHA1_3s 1111 001 0 0 . optype:2 .... .... 1100 . 1 . 0 .... \ | ||
44 | - vm=%vm_dp vn=%vn_dp vd=%vd_dp | ||
45 | +SHA1C_3s 1111 001 0 0 . 00 .... .... 1100 . 1 . 0 .... @3same_crypto | ||
46 | +SHA1P_3s 1111 001 0 0 . 01 .... .... 1100 . 1 . 0 .... @3same_crypto | ||
47 | +SHA1M_3s 1111 001 0 0 . 10 .... .... 1100 . 1 . 0 .... @3same_crypto | ||
48 | +SHA1SU0_3s 1111 001 0 0 . 11 .... .... 1100 . 1 . 0 .... @3same_crypto | ||
49 | SHA256H_3s 1111 001 1 0 . 00 .... .... 1100 . 1 . 0 .... @3same_crypto | ||
50 | SHA256H2_3s 1111 001 1 0 . 01 .... .... 1100 . 1 . 0 .... @3same_crypto | ||
51 | SHA256SU1_3s 1111 001 1 0 . 10 .... .... 1100 . 1 . 0 .... @3same_crypto | ||
52 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
53 | index XXXXXXX..XXXXXXX 100644 | ||
54 | --- a/target/arm/crypto_helper.c | ||
55 | +++ b/target/arm/crypto_helper.c | ||
56 | @@ -XXX,XX +XXX,XX @@ union CRYPTO_STATE { | ||
57 | }; | ||
58 | |||
59 | #ifdef HOST_WORDS_BIGENDIAN | ||
60 | -#define CR_ST_BYTE(state, i) (state.bytes[(15 - (i)) ^ 8]) | ||
61 | -#define CR_ST_WORD(state, i) (state.words[(3 - (i)) ^ 2]) | ||
62 | +#define CR_ST_BYTE(state, i) ((state).bytes[(15 - (i)) ^ 8]) | ||
63 | +#define CR_ST_WORD(state, i) ((state).words[(3 - (i)) ^ 2]) | ||
64 | #else | ||
65 | -#define CR_ST_BYTE(state, i) (state.bytes[i]) | ||
66 | -#define CR_ST_WORD(state, i) (state.words[i]) | ||
67 | +#define CR_ST_BYTE(state, i) ((state).bytes[i]) | ||
68 | +#define CR_ST_WORD(state, i) ((state).words[i]) | ||
69 | #endif | ||
70 | |||
71 | /* | ||
72 | @@ -XXX,XX +XXX,XX @@ static uint32_t maj(uint32_t x, uint32_t y, uint32_t z) | ||
73 | return (x & y) | ((x | y) & z); | ||
74 | } | ||
75 | |||
76 | -void HELPER(crypto_sha1_3reg)(void *vd, void *vn, void *vm, uint32_t op) | ||
77 | +void HELPER(crypto_sha1su0)(void *vd, void *vn, void *vm, uint32_t desc) | ||
78 | +{ | ||
79 | + uint64_t *d = vd, *n = vn, *m = vm; | ||
80 | + uint64_t d0, d1; | ||
81 | + | ||
82 | + d0 = d[1] ^ d[0] ^ m[0]; | ||
83 | + d1 = n[0] ^ d[1] ^ m[1]; | ||
84 | + d[0] = d0; | ||
85 | + d[1] = d1; | ||
86 | + | ||
87 | + clear_tail_16(vd, desc); | ||
88 | +} | ||
89 | + | ||
90 | +static inline void crypto_sha1_3reg(uint64_t *rd, uint64_t *rn, | ||
91 | + uint64_t *rm, uint32_t desc, | ||
92 | + uint32_t (*fn)(union CRYPTO_STATE *d)) | ||
93 | { | ||
94 | - uint64_t *rd = vd; | ||
95 | - uint64_t *rn = vn; | ||
96 | - uint64_t *rm = vm; | ||
97 | union CRYPTO_STATE d = { .l = { rd[0], rd[1] } }; | ||
98 | union CRYPTO_STATE n = { .l = { rn[0], rn[1] } }; | ||
99 | union CRYPTO_STATE m = { .l = { rm[0], rm[1] } }; | ||
100 | + int i; | ||
101 | |||
102 | - if (op == 3) { /* sha1su0 */ | ||
103 | - d.l[0] ^= d.l[1] ^ m.l[0]; | ||
104 | - d.l[1] ^= n.l[0] ^ m.l[1]; | ||
105 | - } else { | ||
106 | - int i; | ||
107 | + for (i = 0; i < 4; i++) { | ||
108 | + uint32_t t = fn(&d); | ||
109 | |||
110 | - for (i = 0; i < 4; i++) { | ||
111 | - uint32_t t; | ||
112 | + t += rol32(CR_ST_WORD(d, 0), 5) + CR_ST_WORD(n, 0) | ||
113 | + + CR_ST_WORD(m, i); | ||
114 | |||
115 | - switch (op) { | ||
116 | - case 0: /* sha1c */ | ||
117 | - t = cho(CR_ST_WORD(d, 1), CR_ST_WORD(d, 2), CR_ST_WORD(d, 3)); | ||
118 | - break; | ||
119 | - case 1: /* sha1p */ | ||
120 | - t = par(CR_ST_WORD(d, 1), CR_ST_WORD(d, 2), CR_ST_WORD(d, 3)); | ||
121 | - break; | ||
122 | - case 2: /* sha1m */ | ||
123 | - t = maj(CR_ST_WORD(d, 1), CR_ST_WORD(d, 2), CR_ST_WORD(d, 3)); | ||
124 | - break; | ||
125 | - default: | ||
126 | - g_assert_not_reached(); | ||
127 | - } | ||
128 | - t += rol32(CR_ST_WORD(d, 0), 5) + CR_ST_WORD(n, 0) | ||
129 | - + CR_ST_WORD(m, i); | ||
130 | - | ||
131 | - CR_ST_WORD(n, 0) = CR_ST_WORD(d, 3); | ||
132 | - CR_ST_WORD(d, 3) = CR_ST_WORD(d, 2); | ||
133 | - CR_ST_WORD(d, 2) = ror32(CR_ST_WORD(d, 1), 2); | ||
134 | - CR_ST_WORD(d, 1) = CR_ST_WORD(d, 0); | ||
135 | - CR_ST_WORD(d, 0) = t; | ||
136 | - } | ||
137 | + CR_ST_WORD(n, 0) = CR_ST_WORD(d, 3); | ||
138 | + CR_ST_WORD(d, 3) = CR_ST_WORD(d, 2); | ||
139 | + CR_ST_WORD(d, 2) = ror32(CR_ST_WORD(d, 1), 2); | ||
140 | + CR_ST_WORD(d, 1) = CR_ST_WORD(d, 0); | ||
141 | + CR_ST_WORD(d, 0) = t; | ||
142 | } | ||
143 | rd[0] = d.l[0]; | ||
144 | rd[1] = d.l[1]; | ||
145 | + | ||
146 | + clear_tail_16(rd, desc); | ||
147 | +} | ||
148 | + | ||
149 | +static uint32_t do_sha1c(union CRYPTO_STATE *d) | ||
150 | +{ | ||
151 | + return cho(CR_ST_WORD(*d, 1), CR_ST_WORD(*d, 2), CR_ST_WORD(*d, 3)); | ||
152 | +} | ||
153 | + | ||
154 | +void HELPER(crypto_sha1c)(void *vd, void *vn, void *vm, uint32_t desc) | ||
155 | +{ | ||
156 | + crypto_sha1_3reg(vd, vn, vm, desc, do_sha1c); | ||
157 | +} | ||
158 | + | ||
159 | +static uint32_t do_sha1p(union CRYPTO_STATE *d) | ||
160 | +{ | ||
161 | + return par(CR_ST_WORD(*d, 1), CR_ST_WORD(*d, 2), CR_ST_WORD(*d, 3)); | ||
162 | +} | ||
163 | + | ||
164 | +void HELPER(crypto_sha1p)(void *vd, void *vn, void *vm, uint32_t desc) | ||
165 | +{ | ||
166 | + crypto_sha1_3reg(vd, vn, vm, desc, do_sha1p); | ||
167 | +} | ||
168 | + | ||
169 | +static uint32_t do_sha1m(union CRYPTO_STATE *d) | ||
170 | +{ | ||
171 | + return maj(CR_ST_WORD(*d, 1), CR_ST_WORD(*d, 2), CR_ST_WORD(*d, 3)); | ||
172 | +} | ||
173 | + | ||
174 | +void HELPER(crypto_sha1m)(void *vd, void *vn, void *vm, uint32_t desc) | ||
175 | +{ | ||
176 | + crypto_sha1_3reg(vd, vn, vm, desc, do_sha1m); | ||
177 | } | ||
178 | |||
179 | void HELPER(crypto_sha1h)(void *vd, void *vm, uint32_t desc) | ||
180 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 13 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
181 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
182 | --- a/target/arm/translate-a64.c | 15 | --- a/target/arm/translate-a64.c |
183 | +++ b/target/arm/translate-a64.c | 16 | +++ b/target/arm/translate-a64.c |
184 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn) | 17 | @@ -XXX,XX +XXX,XX @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) |
185 | 18 | rn = extract32(insn, 5, 5); | |
186 | switch (opcode) { | 19 | op4 = extract32(insn, 0, 5); |
187 | case 0: /* SHA1C */ | 20 | |
188 | + genfn = gen_helper_crypto_sha1c; | 21 | - if (op4 != 0x0 || op3 != 0x0 || op2 != 0x1f) { |
189 | + feature = dc_isar_feature(aa64_sha1, s); | 22 | - unallocated_encoding(s); |
190 | + break; | 23 | - return; |
191 | case 1: /* SHA1P */ | 24 | + if (op2 != 0x1f) { |
192 | + genfn = gen_helper_crypto_sha1p; | 25 | + goto do_unallocated; |
193 | + feature = dc_isar_feature(aa64_sha1, s); | 26 | } |
194 | + break; | 27 | |
195 | case 2: /* SHA1M */ | 28 | switch (opc) { |
196 | + genfn = gen_helper_crypto_sha1m; | 29 | case 0: /* BR */ |
197 | + feature = dc_isar_feature(aa64_sha1, s); | 30 | case 1: /* BLR */ |
198 | + break; | 31 | case 2: /* RET */ |
199 | case 3: /* SHA1SU0 */ | 32 | - gen_a64_set_pc(s, cpu_reg(s, rn)); |
200 | - genfn = NULL; | 33 | + switch (op3) { |
201 | + genfn = gen_helper_crypto_sha1su0; | 34 | + case 0: |
202 | feature = dc_isar_feature(aa64_sha1, s); | 35 | + if (op4 != 0) { |
36 | + goto do_unallocated; | ||
37 | + } | ||
38 | + dst = cpu_reg(s, rn); | ||
39 | + break; | ||
40 | + | ||
41 | + default: | ||
42 | + goto do_unallocated; | ||
43 | + } | ||
44 | + | ||
45 | + gen_a64_set_pc(s, dst); | ||
46 | /* BLR also needs to load return address */ | ||
47 | if (opc == 1) { | ||
48 | tcg_gen_movi_i64(cpu_reg(s, 30), s->pc); | ||
49 | } | ||
203 | break; | 50 | break; |
204 | case 4: /* SHA256H */ | 51 | + |
205 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn) | 52 | case 4: /* ERET */ |
206 | if (!fp_access_check(s)) { | 53 | if (s->current_el == 0) { |
54 | - unallocated_encoding(s); | ||
55 | - return; | ||
56 | + goto do_unallocated; | ||
57 | + } | ||
58 | + switch (op3) { | ||
59 | + case 0: | ||
60 | + if (op4 != 0) { | ||
61 | + goto do_unallocated; | ||
62 | + } | ||
63 | + dst = tcg_temp_new_i64(); | ||
64 | + tcg_gen_ld_i64(dst, cpu_env, | ||
65 | + offsetof(CPUARMState, elr_el[s->current_el])); | ||
66 | + break; | ||
67 | + | ||
68 | + default: | ||
69 | + goto do_unallocated; | ||
70 | } | ||
71 | if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) { | ||
72 | gen_io_start(); | ||
73 | } | ||
74 | - dst = tcg_temp_new_i64(); | ||
75 | - tcg_gen_ld_i64(dst, cpu_env, | ||
76 | - offsetof(CPUARMState, elr_el[s->current_el])); | ||
77 | + | ||
78 | gen_helper_exception_return(cpu_env, dst); | ||
79 | tcg_temp_free_i64(dst); | ||
80 | if (tb_cflags(s->base.tb) & CF_USE_ICOUNT) { | ||
81 | @@ -XXX,XX +XXX,XX @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) | ||
82 | /* Must exit loop to check un-masked IRQs */ | ||
83 | s->base.is_jmp = DISAS_EXIT; | ||
84 | return; | ||
85 | + | ||
86 | case 5: /* DRPS */ | ||
87 | - if (rn != 0x1f) { | ||
88 | - unallocated_encoding(s); | ||
89 | + if (op3 != 0 || op4 != 0 || rn != 0x1f) { | ||
90 | + goto do_unallocated; | ||
91 | } else { | ||
92 | unsupported_encoding(s, insn); | ||
93 | } | ||
94 | return; | ||
95 | + | ||
96 | default: | ||
97 | + do_unallocated: | ||
98 | unallocated_encoding(s); | ||
207 | return; | 99 | return; |
208 | } | 100 | } |
209 | - | ||
210 | - if (genfn) { | ||
211 | - gen_gvec_op3_ool(s, true, rd, rn, rm, 0, genfn); | ||
212 | - } else { | ||
213 | - TCGv_i32 tcg_opcode = tcg_const_i32(opcode); | ||
214 | - TCGv_ptr tcg_rd_ptr = vec_full_reg_ptr(s, rd); | ||
215 | - TCGv_ptr tcg_rn_ptr = vec_full_reg_ptr(s, rn); | ||
216 | - TCGv_ptr tcg_rm_ptr = vec_full_reg_ptr(s, rm); | ||
217 | - | ||
218 | - gen_helper_crypto_sha1_3reg(tcg_rd_ptr, tcg_rn_ptr, | ||
219 | - tcg_rm_ptr, tcg_opcode); | ||
220 | - | ||
221 | - tcg_temp_free_i32(tcg_opcode); | ||
222 | - tcg_temp_free_ptr(tcg_rd_ptr); | ||
223 | - tcg_temp_free_ptr(tcg_rn_ptr); | ||
224 | - tcg_temp_free_ptr(tcg_rm_ptr); | ||
225 | - } | ||
226 | + gen_gvec_op3_ool(s, true, rd, rn, rm, 0, genfn); | ||
227 | } | ||
228 | |||
229 | /* Crypto two-reg SHA | ||
230 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | ||
231 | index XXXXXXX..XXXXXXX 100644 | ||
232 | --- a/target/arm/translate-neon.inc.c | ||
233 | +++ b/target/arm/translate-neon.inc.c | ||
234 | @@ -XXX,XX +XXX,XX @@ static bool trans_VMUL_p_3s(DisasContext *s, arg_3same *a) | ||
235 | DO_VQRDMLAH(VQRDMLAH, gen_gvec_sqrdmlah_qc) | ||
236 | DO_VQRDMLAH(VQRDMLSH, gen_gvec_sqrdmlsh_qc) | ||
237 | |||
238 | -static bool trans_SHA1_3s(DisasContext *s, arg_SHA1_3s *a) | ||
239 | -{ | ||
240 | - TCGv_ptr ptr1, ptr2, ptr3; | ||
241 | - TCGv_i32 tmp; | ||
242 | - | ||
243 | - if (!arm_dc_feature(s, ARM_FEATURE_NEON) || | ||
244 | - !dc_isar_feature(aa32_sha1, s)) { | ||
245 | - return false; | ||
246 | +#define DO_SHA1(NAME, FUNC) \ | ||
247 | + WRAP_OOL_FN(gen_##NAME##_3s, FUNC) \ | ||
248 | + static bool trans_##NAME##_3s(DisasContext *s, arg_3same *a) \ | ||
249 | + { \ | ||
250 | + if (!dc_isar_feature(aa32_sha1, s)) { \ | ||
251 | + return false; \ | ||
252 | + } \ | ||
253 | + return do_3same(s, a, gen_##NAME##_3s); \ | ||
254 | } | ||
255 | |||
256 | - /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
257 | - if (!dc_isar_feature(aa32_simd_r32, s) && | ||
258 | - ((a->vd | a->vn | a->vm) & 0x10)) { | ||
259 | - return false; | ||
260 | - } | ||
261 | - | ||
262 | - if ((a->vn | a->vm | a->vd) & 1) { | ||
263 | - return false; | ||
264 | - } | ||
265 | - | ||
266 | - if (!vfp_access_check(s)) { | ||
267 | - return true; | ||
268 | - } | ||
269 | - | ||
270 | - ptr1 = vfp_reg_ptr(true, a->vd); | ||
271 | - ptr2 = vfp_reg_ptr(true, a->vn); | ||
272 | - ptr3 = vfp_reg_ptr(true, a->vm); | ||
273 | - tmp = tcg_const_i32(a->optype); | ||
274 | - gen_helper_crypto_sha1_3reg(ptr1, ptr2, ptr3, tmp); | ||
275 | - tcg_temp_free_i32(tmp); | ||
276 | - tcg_temp_free_ptr(ptr1); | ||
277 | - tcg_temp_free_ptr(ptr2); | ||
278 | - tcg_temp_free_ptr(ptr3); | ||
279 | - | ||
280 | - return true; | ||
281 | -} | ||
282 | +DO_SHA1(SHA1C, gen_helper_crypto_sha1c) | ||
283 | +DO_SHA1(SHA1P, gen_helper_crypto_sha1p) | ||
284 | +DO_SHA1(SHA1M, gen_helper_crypto_sha1m) | ||
285 | +DO_SHA1(SHA1SU0, gen_helper_crypto_sha1su0) | ||
286 | |||
287 | #define DO_SHA2(NAME, FUNC) \ | ||
288 | WRAP_OOL_FN(gen_##NAME##_3s, FUNC) \ | ||
289 | -- | 101 | -- |
290 | 2.20.1 | 102 | 2.20.1 |
291 | 103 | ||
292 | 104 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20190108223129.5570-14-richard.henderson@linaro.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | target/arm/translate-a64.c | 82 +++++++++++++++++++++++++++++++++++++- | ||
9 | 1 file changed, 81 insertions(+), 1 deletion(-) | ||
10 | |||
11 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/target/arm/translate-a64.c | ||
14 | +++ b/target/arm/translate-a64.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) | ||
16 | { | ||
17 | unsigned int opc, op2, op3, rn, op4; | ||
18 | TCGv_i64 dst; | ||
19 | + TCGv_i64 modifier; | ||
20 | |||
21 | opc = extract32(insn, 21, 4); | ||
22 | op2 = extract32(insn, 16, 5); | ||
23 | @@ -XXX,XX +XXX,XX @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) | ||
24 | case 2: /* RET */ | ||
25 | switch (op3) { | ||
26 | case 0: | ||
27 | + /* BR, BLR, RET */ | ||
28 | if (op4 != 0) { | ||
29 | goto do_unallocated; | ||
30 | } | ||
31 | dst = cpu_reg(s, rn); | ||
32 | break; | ||
33 | |||
34 | + case 2: | ||
35 | + case 3: | ||
36 | + if (!dc_isar_feature(aa64_pauth, s)) { | ||
37 | + goto do_unallocated; | ||
38 | + } | ||
39 | + if (opc == 2) { | ||
40 | + /* RETAA, RETAB */ | ||
41 | + if (rn != 0x1f || op4 != 0x1f) { | ||
42 | + goto do_unallocated; | ||
43 | + } | ||
44 | + rn = 30; | ||
45 | + modifier = cpu_X[31]; | ||
46 | + } else { | ||
47 | + /* BRAAZ, BRABZ, BLRAAZ, BLRABZ */ | ||
48 | + if (op4 != 0x1f) { | ||
49 | + goto do_unallocated; | ||
50 | + } | ||
51 | + modifier = new_tmp_a64_zero(s); | ||
52 | + } | ||
53 | + if (s->pauth_active) { | ||
54 | + dst = new_tmp_a64(s); | ||
55 | + if (op3 == 2) { | ||
56 | + gen_helper_autia(dst, cpu_env, cpu_reg(s, rn), modifier); | ||
57 | + } else { | ||
58 | + gen_helper_autib(dst, cpu_env, cpu_reg(s, rn), modifier); | ||
59 | + } | ||
60 | + } else { | ||
61 | + dst = cpu_reg(s, rn); | ||
62 | + } | ||
63 | + break; | ||
64 | + | ||
65 | default: | ||
66 | goto do_unallocated; | ||
67 | } | ||
68 | @@ -XXX,XX +XXX,XX @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) | ||
69 | } | ||
70 | break; | ||
71 | |||
72 | + case 8: /* BRAA */ | ||
73 | + case 9: /* BLRAA */ | ||
74 | + if (!dc_isar_feature(aa64_pauth, s)) { | ||
75 | + goto do_unallocated; | ||
76 | + } | ||
77 | + if (op3 != 2 || op3 != 3) { | ||
78 | + goto do_unallocated; | ||
79 | + } | ||
80 | + if (s->pauth_active) { | ||
81 | + dst = new_tmp_a64(s); | ||
82 | + modifier = cpu_reg_sp(s, op4); | ||
83 | + if (op3 == 2) { | ||
84 | + gen_helper_autia(dst, cpu_env, cpu_reg(s, rn), modifier); | ||
85 | + } else { | ||
86 | + gen_helper_autib(dst, cpu_env, cpu_reg(s, rn), modifier); | ||
87 | + } | ||
88 | + } else { | ||
89 | + dst = cpu_reg(s, rn); | ||
90 | + } | ||
91 | + gen_a64_set_pc(s, dst); | ||
92 | + /* BLRAA also needs to load return address */ | ||
93 | + if (opc == 9) { | ||
94 | + tcg_gen_movi_i64(cpu_reg(s, 30), s->pc); | ||
95 | + } | ||
96 | + break; | ||
97 | + | ||
98 | case 4: /* ERET */ | ||
99 | if (s->current_el == 0) { | ||
100 | goto do_unallocated; | ||
101 | } | ||
102 | switch (op3) { | ||
103 | - case 0: | ||
104 | + case 0: /* ERET */ | ||
105 | if (op4 != 0) { | ||
106 | goto do_unallocated; | ||
107 | } | ||
108 | @@ -XXX,XX +XXX,XX @@ static void disas_uncond_b_reg(DisasContext *s, uint32_t insn) | ||
109 | offsetof(CPUARMState, elr_el[s->current_el])); | ||
110 | break; | ||
111 | |||
112 | + case 2: /* ERETAA */ | ||
113 | + case 3: /* ERETAB */ | ||
114 | + if (!dc_isar_feature(aa64_pauth, s)) { | ||
115 | + goto do_unallocated; | ||
116 | + } | ||
117 | + if (rn != 0x1f || op4 != 0x1f) { | ||
118 | + goto do_unallocated; | ||
119 | + } | ||
120 | + dst = tcg_temp_new_i64(); | ||
121 | + tcg_gen_ld_i64(dst, cpu_env, | ||
122 | + offsetof(CPUARMState, elr_el[s->current_el])); | ||
123 | + if (s->pauth_active) { | ||
124 | + modifier = cpu_X[31]; | ||
125 | + if (op3 == 2) { | ||
126 | + gen_helper_autia(dst, cpu_env, dst, modifier); | ||
127 | + } else { | ||
128 | + gen_helper_autib(dst, cpu_env, dst, modifier); | ||
129 | + } | ||
130 | + } | ||
131 | + break; | ||
132 | + | ||
133 | default: | ||
134 | goto do_unallocated; | ||
135 | } | ||
136 | -- | ||
137 | 2.20.1 | ||
138 | |||
139 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Do not yet convert the helpers to loop over opr_sz, but the | 3 | Not that there are any stores involved, but why argue with ARM's |
4 | descriptor allows the vector tail to be cleared. Which fixes | 4 | naming convention. |
5 | an existing bug vs SVE. | ||
6 | 5 | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20200514212831.31248-5-richard.henderson@linaro.org | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Message-id: 20190108223129.5570-15-richard.henderson@linaro.org | ||
9 | [fixed trivial comment nit] | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
11 | --- | 11 | --- |
12 | target/arm/helper.h | 12 ++-- | 12 | target/arm/translate-a64.c | 61 ++++++++++++++++++++++++++++++++++++++ |
13 | target/arm/neon-dp.decode | 12 ++-- | 13 | 1 file changed, 61 insertions(+) |
14 | target/arm/crypto_helper.c | 24 +++++-- | ||
15 | target/arm/translate-a64.c | 34 ++++----- | ||
16 | target/arm/translate-neon.inc.c | 124 +++++--------------------------- | ||
17 | target/arm/translate.c | 24 ++----- | ||
18 | 6 files changed, 67 insertions(+), 163 deletions(-) | ||
19 | 14 | ||
20 | diff --git a/target/arm/helper.h b/target/arm/helper.h | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/target/arm/helper.h | ||
23 | +++ b/target/arm/helper.h | ||
24 | @@ -XXX,XX +XXX,XX @@ DEF_HELPER_FLAGS_4(crypto_aese, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
25 | DEF_HELPER_FLAGS_3(crypto_aesmc, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
26 | |||
27 | DEF_HELPER_FLAGS_4(crypto_sha1_3reg, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
28 | -DEF_HELPER_FLAGS_2(crypto_sha1h, TCG_CALL_NO_RWG, void, ptr, ptr) | ||
29 | -DEF_HELPER_FLAGS_2(crypto_sha1su1, TCG_CALL_NO_RWG, void, ptr, ptr) | ||
30 | +DEF_HELPER_FLAGS_3(crypto_sha1h, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
31 | +DEF_HELPER_FLAGS_3(crypto_sha1su1, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
32 | |||
33 | -DEF_HELPER_FLAGS_3(crypto_sha256h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
34 | -DEF_HELPER_FLAGS_3(crypto_sha256h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
35 | -DEF_HELPER_FLAGS_2(crypto_sha256su0, TCG_CALL_NO_RWG, void, ptr, ptr) | ||
36 | -DEF_HELPER_FLAGS_3(crypto_sha256su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr) | ||
37 | +DEF_HELPER_FLAGS_4(crypto_sha256h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
38 | +DEF_HELPER_FLAGS_4(crypto_sha256h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
39 | +DEF_HELPER_FLAGS_3(crypto_sha256su0, TCG_CALL_NO_RWG, void, ptr, ptr, i32) | ||
40 | +DEF_HELPER_FLAGS_4(crypto_sha256su1, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
41 | |||
42 | DEF_HELPER_FLAGS_4(crypto_sha512h, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
43 | DEF_HELPER_FLAGS_4(crypto_sha512h2, TCG_CALL_NO_RWG, void, ptr, ptr, ptr, i32) | ||
44 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/arm/neon-dp.decode | ||
47 | +++ b/target/arm/neon-dp.decode | ||
48 | @@ -XXX,XX +XXX,XX @@ VPADD_3s 1111 001 0 0 . .. .... .... 1011 . . . 1 .... @3same_q0 | ||
49 | |||
50 | VQRDMLAH_3s 1111 001 1 0 . .. .... .... 1011 ... 1 .... @3same | ||
51 | |||
52 | +@3same_crypto .... .... .... .... .... .... .... .... \ | ||
53 | + &3same vm=%vm_dp vn=%vn_dp vd=%vd_dp size=0 q=1 | ||
54 | + | ||
55 | SHA1_3s 1111 001 0 0 . optype:2 .... .... 1100 . 1 . 0 .... \ | ||
56 | vm=%vm_dp vn=%vn_dp vd=%vd_dp | ||
57 | -SHA256H_3s 1111 001 1 0 . 00 .... .... 1100 . 1 . 0 .... \ | ||
58 | - vm=%vm_dp vn=%vn_dp vd=%vd_dp | ||
59 | -SHA256H2_3s 1111 001 1 0 . 01 .... .... 1100 . 1 . 0 .... \ | ||
60 | - vm=%vm_dp vn=%vn_dp vd=%vd_dp | ||
61 | -SHA256SU1_3s 1111 001 1 0 . 10 .... .... 1100 . 1 . 0 .... \ | ||
62 | - vm=%vm_dp vn=%vn_dp vd=%vd_dp | ||
63 | +SHA256H_3s 1111 001 1 0 . 00 .... .... 1100 . 1 . 0 .... @3same_crypto | ||
64 | +SHA256H2_3s 1111 001 1 0 . 01 .... .... 1100 . 1 . 0 .... @3same_crypto | ||
65 | +SHA256SU1_3s 1111 001 1 0 . 10 .... .... 1100 . 1 . 0 .... @3same_crypto | ||
66 | |||
67 | VFMA_fp_3s 1111 001 0 0 . 0 . .... .... 1100 ... 1 .... @3same_fp | ||
68 | VFMS_fp_3s 1111 001 0 0 . 1 . .... .... 1100 ... 1 .... @3same_fp | ||
69 | diff --git a/target/arm/crypto_helper.c b/target/arm/crypto_helper.c | ||
70 | index XXXXXXX..XXXXXXX 100644 | ||
71 | --- a/target/arm/crypto_helper.c | ||
72 | +++ b/target/arm/crypto_helper.c | ||
73 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha1_3reg)(void *vd, void *vn, void *vm, uint32_t op) | ||
74 | rd[1] = d.l[1]; | ||
75 | } | ||
76 | |||
77 | -void HELPER(crypto_sha1h)(void *vd, void *vm) | ||
78 | +void HELPER(crypto_sha1h)(void *vd, void *vm, uint32_t desc) | ||
79 | { | ||
80 | uint64_t *rd = vd; | ||
81 | uint64_t *rm = vm; | ||
82 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha1h)(void *vd, void *vm) | ||
83 | |||
84 | rd[0] = m.l[0]; | ||
85 | rd[1] = m.l[1]; | ||
86 | + | ||
87 | + clear_tail_16(vd, desc); | ||
88 | } | ||
89 | |||
90 | -void HELPER(crypto_sha1su1)(void *vd, void *vm) | ||
91 | +void HELPER(crypto_sha1su1)(void *vd, void *vm, uint32_t desc) | ||
92 | { | ||
93 | uint64_t *rd = vd; | ||
94 | uint64_t *rm = vm; | ||
95 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha1su1)(void *vd, void *vm) | ||
96 | |||
97 | rd[0] = d.l[0]; | ||
98 | rd[1] = d.l[1]; | ||
99 | + | ||
100 | + clear_tail_16(vd, desc); | ||
101 | } | ||
102 | |||
103 | /* | ||
104 | @@ -XXX,XX +XXX,XX @@ static uint32_t s1(uint32_t x) | ||
105 | return ror32(x, 17) ^ ror32(x, 19) ^ (x >> 10); | ||
106 | } | ||
107 | |||
108 | -void HELPER(crypto_sha256h)(void *vd, void *vn, void *vm) | ||
109 | +void HELPER(crypto_sha256h)(void *vd, void *vn, void *vm, uint32_t desc) | ||
110 | { | ||
111 | uint64_t *rd = vd; | ||
112 | uint64_t *rn = vn; | ||
113 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha256h)(void *vd, void *vn, void *vm) | ||
114 | |||
115 | rd[0] = d.l[0]; | ||
116 | rd[1] = d.l[1]; | ||
117 | + | ||
118 | + clear_tail_16(vd, desc); | ||
119 | } | ||
120 | |||
121 | -void HELPER(crypto_sha256h2)(void *vd, void *vn, void *vm) | ||
122 | +void HELPER(crypto_sha256h2)(void *vd, void *vn, void *vm, uint32_t desc) | ||
123 | { | ||
124 | uint64_t *rd = vd; | ||
125 | uint64_t *rn = vn; | ||
126 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha256h2)(void *vd, void *vn, void *vm) | ||
127 | |||
128 | rd[0] = d.l[0]; | ||
129 | rd[1] = d.l[1]; | ||
130 | + | ||
131 | + clear_tail_16(vd, desc); | ||
132 | } | ||
133 | |||
134 | -void HELPER(crypto_sha256su0)(void *vd, void *vm) | ||
135 | +void HELPER(crypto_sha256su0)(void *vd, void *vm, uint32_t desc) | ||
136 | { | ||
137 | uint64_t *rd = vd; | ||
138 | uint64_t *rm = vm; | ||
139 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha256su0)(void *vd, void *vm) | ||
140 | |||
141 | rd[0] = d.l[0]; | ||
142 | rd[1] = d.l[1]; | ||
143 | + | ||
144 | + clear_tail_16(vd, desc); | ||
145 | } | ||
146 | |||
147 | -void HELPER(crypto_sha256su1)(void *vd, void *vn, void *vm) | ||
148 | +void HELPER(crypto_sha256su1)(void *vd, void *vn, void *vm, uint32_t desc) | ||
149 | { | ||
150 | uint64_t *rd = vd; | ||
151 | uint64_t *rn = vn; | ||
152 | @@ -XXX,XX +XXX,XX @@ void HELPER(crypto_sha256su1)(void *vd, void *vn, void *vm) | ||
153 | |||
154 | rd[0] = d.l[0]; | ||
155 | rd[1] = d.l[1]; | ||
156 | + | ||
157 | + clear_tail_16(vd, desc); | ||
158 | } | ||
159 | |||
160 | /* | ||
161 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 15 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
162 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
163 | --- a/target/arm/translate-a64.c | 17 | --- a/target/arm/translate-a64.c |
164 | +++ b/target/arm/translate-a64.c | 18 | +++ b/target/arm/translate-a64.c |
165 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn) | 19 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_atomic(DisasContext *s, uint32_t insn, |
166 | int rm = extract32(insn, 16, 5); | 20 | s->be_data | size | MO_ALIGN); |
167 | int rn = extract32(insn, 5, 5); | ||
168 | int rd = extract32(insn, 0, 5); | ||
169 | - CryptoThreeOpFn *genfn; | ||
170 | - TCGv_ptr tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr; | ||
171 | + gen_helper_gvec_3 *genfn; | ||
172 | bool feature; | ||
173 | |||
174 | if (size != 0) { | ||
175 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_three_reg_sha(DisasContext *s, uint32_t insn) | ||
176 | return; | ||
177 | } | ||
178 | |||
179 | - tcg_rd_ptr = vec_full_reg_ptr(s, rd); | ||
180 | - tcg_rn_ptr = vec_full_reg_ptr(s, rn); | ||
181 | - tcg_rm_ptr = vec_full_reg_ptr(s, rm); | ||
182 | - | ||
183 | if (genfn) { | ||
184 | - genfn(tcg_rd_ptr, tcg_rn_ptr, tcg_rm_ptr); | ||
185 | + gen_gvec_op3_ool(s, true, rd, rn, rm, 0, genfn); | ||
186 | } else { | ||
187 | TCGv_i32 tcg_opcode = tcg_const_i32(opcode); | ||
188 | + TCGv_ptr tcg_rd_ptr = vec_full_reg_ptr(s, rd); | ||
189 | + TCGv_ptr tcg_rn_ptr = vec_full_reg_ptr(s, rn); | ||
190 | + TCGv_ptr tcg_rm_ptr = vec_full_reg_ptr(s, rm); | ||
191 | |||
192 | gen_helper_crypto_sha1_3reg(tcg_rd_ptr, tcg_rn_ptr, | ||
193 | tcg_rm_ptr, tcg_opcode); | ||
194 | - tcg_temp_free_i32(tcg_opcode); | ||
195 | - } | ||
196 | |||
197 | - tcg_temp_free_ptr(tcg_rd_ptr); | ||
198 | - tcg_temp_free_ptr(tcg_rn_ptr); | ||
199 | - tcg_temp_free_ptr(tcg_rm_ptr); | ||
200 | + tcg_temp_free_i32(tcg_opcode); | ||
201 | + tcg_temp_free_ptr(tcg_rd_ptr); | ||
202 | + tcg_temp_free_ptr(tcg_rn_ptr); | ||
203 | + tcg_temp_free_ptr(tcg_rm_ptr); | ||
204 | + } | ||
205 | } | 21 | } |
206 | 22 | ||
207 | /* Crypto two-reg SHA | 23 | +/* |
208 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn) | 24 | + * PAC memory operations |
209 | int opcode = extract32(insn, 12, 5); | 25 | + * |
210 | int rn = extract32(insn, 5, 5); | 26 | + * 31 30 27 26 24 22 21 12 11 10 5 0 |
211 | int rd = extract32(insn, 0, 5); | 27 | + * +------+-------+---+-----+-----+---+--------+---+---+----+-----+ |
212 | - CryptoTwoOpFn *genfn; | 28 | + * | size | 1 1 1 | V | 0 0 | M S | 1 | imm9 | W | 1 | Rn | Rt | |
213 | + gen_helper_gvec_2 *genfn; | 29 | + * +------+-------+---+-----+-----+---+--------+---+---+----+-----+ |
214 | bool feature; | 30 | + * |
215 | - TCGv_ptr tcg_rd_ptr, tcg_rn_ptr; | 31 | + * Rt: the result register |
216 | 32 | + * Rn: base address or SP | |
217 | if (size != 0) { | 33 | + * V: vector flag (always 0 as of v8.3) |
218 | unallocated_encoding(s); | 34 | + * M: clear for key DA, set for key DB |
219 | @@ -XXX,XX +XXX,XX @@ static void disas_crypto_two_reg_sha(DisasContext *s, uint32_t insn) | 35 | + * W: pre-indexing flag |
220 | if (!fp_access_check(s)) { | 36 | + * S: sign for imm9. |
221 | return; | 37 | + */ |
222 | } | 38 | +static void disas_ldst_pac(DisasContext *s, uint32_t insn, |
223 | - | 39 | + int size, int rt, bool is_vector) |
224 | - tcg_rd_ptr = vec_full_reg_ptr(s, rd); | 40 | +{ |
225 | - tcg_rn_ptr = vec_full_reg_ptr(s, rn); | 41 | + int rn = extract32(insn, 5, 5); |
226 | - | 42 | + bool is_wback = extract32(insn, 11, 1); |
227 | - genfn(tcg_rd_ptr, tcg_rn_ptr); | 43 | + bool use_key_a = !extract32(insn, 23, 1); |
228 | - | 44 | + int offset; |
229 | - tcg_temp_free_ptr(tcg_rd_ptr); | 45 | + TCGv_i64 tcg_addr, tcg_rt; |
230 | - tcg_temp_free_ptr(tcg_rn_ptr); | 46 | + |
231 | + gen_gvec_op2_ool(s, true, rd, rn, 0, genfn); | 47 | + if (size != 3 || is_vector || !dc_isar_feature(aa64_pauth, s)) { |
232 | } | 48 | + unallocated_encoding(s); |
233 | 49 | + return; | |
234 | static void gen_rax1_i64(TCGv_i64 d, TCGv_i64 n, TCGv_i64 m) | ||
235 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | ||
236 | index XXXXXXX..XXXXXXX 100644 | ||
237 | --- a/target/arm/translate-neon.inc.c | ||
238 | +++ b/target/arm/translate-neon.inc.c | ||
239 | @@ -XXX,XX +XXX,XX @@ DO_3SAME_CMP(VCGE_S, TCG_COND_GE) | ||
240 | DO_3SAME_CMP(VCGE_U, TCG_COND_GEU) | ||
241 | DO_3SAME_CMP(VCEQ, TCG_COND_EQ) | ||
242 | |||
243 | -static void gen_VMUL_p_3s(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs, | ||
244 | - uint32_t rm_ofs, uint32_t oprsz, uint32_t maxsz) | ||
245 | -{ | ||
246 | - tcg_gen_gvec_3_ool(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, | ||
247 | - 0, gen_helper_gvec_pmul_b); | ||
248 | -} | ||
249 | +#define WRAP_OOL_FN(WRAPNAME, FUNC) \ | ||
250 | + static void WRAPNAME(unsigned vece, uint32_t rd_ofs, uint32_t rn_ofs, \ | ||
251 | + uint32_t rm_ofs, uint32_t oprsz, uint32_t maxsz) \ | ||
252 | + { \ | ||
253 | + tcg_gen_gvec_3_ool(rd_ofs, rn_ofs, rm_ofs, oprsz, maxsz, 0, FUNC); \ | ||
254 | + } | 50 | + } |
255 | + | 51 | + |
256 | +WRAP_OOL_FN(gen_VMUL_p_3s, gen_helper_gvec_pmul_b) | 52 | + if (rn == 31) { |
257 | 53 | + gen_check_sp_alignment(s); | |
258 | static bool trans_VMUL_p_3s(DisasContext *s, arg_3same *a) | 54 | + } |
55 | + tcg_addr = read_cpu_reg_sp(s, rn, 1); | ||
56 | + | ||
57 | + if (s->pauth_active) { | ||
58 | + if (use_key_a) { | ||
59 | + gen_helper_autda(tcg_addr, cpu_env, tcg_addr, cpu_X[31]); | ||
60 | + } else { | ||
61 | + gen_helper_autdb(tcg_addr, cpu_env, tcg_addr, cpu_X[31]); | ||
62 | + } | ||
63 | + } | ||
64 | + | ||
65 | + /* Form the 10-bit signed, scaled offset. */ | ||
66 | + offset = (extract32(insn, 22, 1) << 9) | extract32(insn, 12, 9); | ||
67 | + offset = sextract32(offset << size, 0, 10 + size); | ||
68 | + tcg_gen_addi_i64(tcg_addr, tcg_addr, offset); | ||
69 | + | ||
70 | + tcg_rt = cpu_reg(s, rt); | ||
71 | + | ||
72 | + do_gpr_ld(s, tcg_rt, tcg_addr, size, /* is_signed */ false, | ||
73 | + /* extend */ false, /* iss_valid */ !is_wback, | ||
74 | + /* iss_srt */ rt, /* iss_sf */ true, /* iss_ar */ false); | ||
75 | + | ||
76 | + if (is_wback) { | ||
77 | + tcg_gen_mov_i64(cpu_reg_sp(s, rn), tcg_addr); | ||
78 | + } | ||
79 | +} | ||
80 | + | ||
81 | /* Load/store register (all forms) */ | ||
82 | static void disas_ldst_reg(DisasContext *s, uint32_t insn) | ||
259 | { | 83 | { |
260 | @@ -XXX,XX +XXX,XX @@ static bool trans_SHA1_3s(DisasContext *s, arg_SHA1_3s *a) | 84 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_reg(DisasContext *s, uint32_t insn) |
261 | return true; | 85 | case 2: |
262 | } | 86 | disas_ldst_reg_roffset(s, insn, opc, size, rt, is_vector); |
263 | 87 | return; | |
264 | -static bool trans_SHA256H_3s(DisasContext *s, arg_SHA256H_3s *a) | 88 | + default: |
265 | -{ | 89 | + disas_ldst_pac(s, insn, size, rt, is_vector); |
266 | - TCGv_ptr ptr1, ptr2, ptr3; | 90 | + return; |
267 | - | 91 | } |
268 | - if (!arm_dc_feature(s, ARM_FEATURE_NEON) || | 92 | break; |
269 | - !dc_isar_feature(aa32_sha2, s)) { | 93 | case 1: |
270 | - return false; | ||
271 | +#define DO_SHA2(NAME, FUNC) \ | ||
272 | + WRAP_OOL_FN(gen_##NAME##_3s, FUNC) \ | ||
273 | + static bool trans_##NAME##_3s(DisasContext *s, arg_3same *a) \ | ||
274 | + { \ | ||
275 | + if (!dc_isar_feature(aa32_sha2, s)) { \ | ||
276 | + return false; \ | ||
277 | + } \ | ||
278 | + return do_3same(s, a, gen_##NAME##_3s); \ | ||
279 | } | ||
280 | |||
281 | - /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
282 | - if (!dc_isar_feature(aa32_simd_r32, s) && | ||
283 | - ((a->vd | a->vn | a->vm) & 0x10)) { | ||
284 | - return false; | ||
285 | - } | ||
286 | - | ||
287 | - if ((a->vn | a->vm | a->vd) & 1) { | ||
288 | - return false; | ||
289 | - } | ||
290 | - | ||
291 | - if (!vfp_access_check(s)) { | ||
292 | - return true; | ||
293 | - } | ||
294 | - | ||
295 | - ptr1 = vfp_reg_ptr(true, a->vd); | ||
296 | - ptr2 = vfp_reg_ptr(true, a->vn); | ||
297 | - ptr3 = vfp_reg_ptr(true, a->vm); | ||
298 | - gen_helper_crypto_sha256h(ptr1, ptr2, ptr3); | ||
299 | - tcg_temp_free_ptr(ptr1); | ||
300 | - tcg_temp_free_ptr(ptr2); | ||
301 | - tcg_temp_free_ptr(ptr3); | ||
302 | - | ||
303 | - return true; | ||
304 | -} | ||
305 | - | ||
306 | -static bool trans_SHA256H2_3s(DisasContext *s, arg_SHA256H2_3s *a) | ||
307 | -{ | ||
308 | - TCGv_ptr ptr1, ptr2, ptr3; | ||
309 | - | ||
310 | - if (!arm_dc_feature(s, ARM_FEATURE_NEON) || | ||
311 | - !dc_isar_feature(aa32_sha2, s)) { | ||
312 | - return false; | ||
313 | - } | ||
314 | - | ||
315 | - /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
316 | - if (!dc_isar_feature(aa32_simd_r32, s) && | ||
317 | - ((a->vd | a->vn | a->vm) & 0x10)) { | ||
318 | - return false; | ||
319 | - } | ||
320 | - | ||
321 | - if ((a->vn | a->vm | a->vd) & 1) { | ||
322 | - return false; | ||
323 | - } | ||
324 | - | ||
325 | - if (!vfp_access_check(s)) { | ||
326 | - return true; | ||
327 | - } | ||
328 | - | ||
329 | - ptr1 = vfp_reg_ptr(true, a->vd); | ||
330 | - ptr2 = vfp_reg_ptr(true, a->vn); | ||
331 | - ptr3 = vfp_reg_ptr(true, a->vm); | ||
332 | - gen_helper_crypto_sha256h2(ptr1, ptr2, ptr3); | ||
333 | - tcg_temp_free_ptr(ptr1); | ||
334 | - tcg_temp_free_ptr(ptr2); | ||
335 | - tcg_temp_free_ptr(ptr3); | ||
336 | - | ||
337 | - return true; | ||
338 | -} | ||
339 | - | ||
340 | -static bool trans_SHA256SU1_3s(DisasContext *s, arg_SHA256SU1_3s *a) | ||
341 | -{ | ||
342 | - TCGv_ptr ptr1, ptr2, ptr3; | ||
343 | - | ||
344 | - if (!arm_dc_feature(s, ARM_FEATURE_NEON) || | ||
345 | - !dc_isar_feature(aa32_sha2, s)) { | ||
346 | - return false; | ||
347 | - } | ||
348 | - | ||
349 | - /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
350 | - if (!dc_isar_feature(aa32_simd_r32, s) && | ||
351 | - ((a->vd | a->vn | a->vm) & 0x10)) { | ||
352 | - return false; | ||
353 | - } | ||
354 | - | ||
355 | - if ((a->vn | a->vm | a->vd) & 1) { | ||
356 | - return false; | ||
357 | - } | ||
358 | - | ||
359 | - if (!vfp_access_check(s)) { | ||
360 | - return true; | ||
361 | - } | ||
362 | - | ||
363 | - ptr1 = vfp_reg_ptr(true, a->vd); | ||
364 | - ptr2 = vfp_reg_ptr(true, a->vn); | ||
365 | - ptr3 = vfp_reg_ptr(true, a->vm); | ||
366 | - gen_helper_crypto_sha256su1(ptr1, ptr2, ptr3); | ||
367 | - tcg_temp_free_ptr(ptr1); | ||
368 | - tcg_temp_free_ptr(ptr2); | ||
369 | - tcg_temp_free_ptr(ptr3); | ||
370 | - | ||
371 | - return true; | ||
372 | -} | ||
373 | +DO_SHA2(SHA256H, gen_helper_crypto_sha256h) | ||
374 | +DO_SHA2(SHA256H2, gen_helper_crypto_sha256h2) | ||
375 | +DO_SHA2(SHA256SU1, gen_helper_crypto_sha256su1) | ||
376 | |||
377 | #define DO_3SAME_64(INSN, FUNC) \ | ||
378 | static void gen_##INSN##_3s(unsigned vece, uint32_t rd_ofs, \ | ||
379 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
380 | index XXXXXXX..XXXXXXX 100644 | ||
381 | --- a/target/arm/translate.c | ||
382 | +++ b/target/arm/translate.c | ||
383 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
384 | int vec_size; | ||
385 | uint32_t imm; | ||
386 | TCGv_i32 tmp, tmp2, tmp3, tmp4, tmp5; | ||
387 | - TCGv_ptr ptr1, ptr2; | ||
388 | + TCGv_ptr ptr1; | ||
389 | TCGv_i64 tmp64; | ||
390 | |||
391 | if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | ||
392 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
393 | if (!dc_isar_feature(aa32_sha1, s) || ((rm | rd) & 1)) { | ||
394 | return 1; | ||
395 | } | ||
396 | - ptr1 = vfp_reg_ptr(true, rd); | ||
397 | - ptr2 = vfp_reg_ptr(true, rm); | ||
398 | - | ||
399 | - gen_helper_crypto_sha1h(ptr1, ptr2); | ||
400 | - | ||
401 | - tcg_temp_free_ptr(ptr1); | ||
402 | - tcg_temp_free_ptr(ptr2); | ||
403 | + tcg_gen_gvec_2_ool(rd_ofs, rm_ofs, 16, 16, 0, | ||
404 | + gen_helper_crypto_sha1h); | ||
405 | break; | ||
406 | case NEON_2RM_SHA1SU1: | ||
407 | if ((rm | rd) & 1) { | ||
408 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
409 | } else if (!dc_isar_feature(aa32_sha1, s)) { | ||
410 | return 1; | ||
411 | } | ||
412 | - ptr1 = vfp_reg_ptr(true, rd); | ||
413 | - ptr2 = vfp_reg_ptr(true, rm); | ||
414 | - if (q) { | ||
415 | - gen_helper_crypto_sha256su0(ptr1, ptr2); | ||
416 | - } else { | ||
417 | - gen_helper_crypto_sha1su1(ptr1, ptr2); | ||
418 | - } | ||
419 | - tcg_temp_free_ptr(ptr1); | ||
420 | - tcg_temp_free_ptr(ptr2); | ||
421 | + tcg_gen_gvec_2_ool(rd_ofs, rm_ofs, 16, 16, 0, | ||
422 | + q ? gen_helper_crypto_sha256su0 | ||
423 | + : gen_helper_crypto_sha1su1); | ||
424 | break; | ||
425 | - | ||
426 | case NEON_2RM_VMVN: | ||
427 | tcg_gen_gvec_not(0, rd_ofs, rm_ofs, vec_size, vec_size); | ||
428 | break; | ||
429 | -- | 94 | -- |
430 | 2.20.1 | 95 | 2.20.1 |
431 | 96 | ||
432 | 97 | diff view generated by jsdifflib |
1 | Convert the VCVT fixed-point conversion operations in the | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | Neon 2-regs-and-shift group to decodetree. | ||
3 | 2 | ||
3 | This function is, or will shortly become, too big to inline. | ||
4 | |||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20190108223129.5570-16-richard.henderson@linaro.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200522145520.6778-9-peter.maydell@linaro.org | ||
7 | --- | 9 | --- |
8 | target/arm/neon-dp.decode | 11 +++++ | 10 | target/arm/cpu.h | 48 +++++---------------------------------------- |
9 | target/arm/translate-neon.inc.c | 49 +++++++++++++++++++++ | 11 | target/arm/helper.c | 44 +++++++++++++++++++++++++++++++++++++++++ |
10 | target/arm/translate.c | 75 +-------------------------------- | 12 | 2 files changed, 49 insertions(+), 43 deletions(-) |
11 | 3 files changed, 62 insertions(+), 73 deletions(-) | ||
12 | 13 | ||
13 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | 14 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/neon-dp.decode | 16 | --- a/target/arm/cpu.h |
16 | +++ b/target/arm/neon-dp.decode | 17 | +++ b/target/arm/cpu.h |
17 | @@ -XXX,XX +XXX,XX @@ VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp | 18 | @@ -XXX,XX +XXX,XX @@ static inline int arm_mmu_idx_to_el(ARMMMUIdx mmu_idx) |
18 | @2reg_shll_b .... ... . . . 001 shift:3 .... .... 0 . . . .... \ | 19 | } |
19 | &2reg_shift vm=%vm_dp vd=%vd_dp size=0 q=0 | 20 | |
20 | 21 | /* Return the MMU index for a v7M CPU in the specified security and | |
21 | +# We use size=0 for fp32 and size=1 for fp16 to match the 3-same encodings. | 22 | - * privilege state |
22 | +@2reg_vcvt .... ... . . . 1 ..... .... .... . q:1 . . .... \ | 23 | + * privilege state. |
23 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=0 shift=%neon_rshift_i5 | 24 | */ |
25 | -static inline ARMMMUIdx arm_v7m_mmu_idx_for_secstate_and_priv(CPUARMState *env, | ||
26 | - bool secstate, | ||
27 | - bool priv) | ||
28 | -{ | ||
29 | - ARMMMUIdx mmu_idx = ARM_MMU_IDX_M; | ||
30 | - | ||
31 | - if (priv) { | ||
32 | - mmu_idx |= ARM_MMU_IDX_M_PRIV; | ||
33 | - } | ||
34 | - | ||
35 | - if (armv7m_nvic_neg_prio_requested(env->nvic, secstate)) { | ||
36 | - mmu_idx |= ARM_MMU_IDX_M_NEGPRI; | ||
37 | - } | ||
38 | - | ||
39 | - if (secstate) { | ||
40 | - mmu_idx |= ARM_MMU_IDX_M_S; | ||
41 | - } | ||
42 | - | ||
43 | - return mmu_idx; | ||
44 | -} | ||
45 | +ARMMMUIdx arm_v7m_mmu_idx_for_secstate_and_priv(CPUARMState *env, | ||
46 | + bool secstate, bool priv); | ||
47 | |||
48 | /* Return the MMU index for a v7M CPU in the specified security state */ | ||
49 | -static inline ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, | ||
50 | - bool secstate) | ||
51 | -{ | ||
52 | - bool priv = arm_current_el(env) != 0; | ||
53 | - | ||
54 | - return arm_v7m_mmu_idx_for_secstate_and_priv(env, secstate, priv); | ||
55 | -} | ||
56 | +ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, bool secstate); | ||
57 | |||
58 | /* Determine the current mmu_idx to use for normal loads/stores */ | ||
59 | -static inline int cpu_mmu_index(CPUARMState *env, bool ifetch) | ||
60 | -{ | ||
61 | - int el = arm_current_el(env); | ||
62 | - | ||
63 | - if (arm_feature(env, ARM_FEATURE_M)) { | ||
64 | - ARMMMUIdx mmu_idx = arm_v7m_mmu_idx_for_secstate(env, env->v7m.secure); | ||
65 | - | ||
66 | - return arm_to_core_mmu_idx(mmu_idx); | ||
67 | - } | ||
68 | - | ||
69 | - if (el < 2 && arm_is_secure_below_el3(env)) { | ||
70 | - return arm_to_core_mmu_idx(ARMMMUIdx_S1SE0 + el); | ||
71 | - } | ||
72 | - return el; | ||
73 | -} | ||
74 | +int cpu_mmu_index(CPUARMState *env, bool ifetch); | ||
75 | |||
76 | /* Indexes used when registering address spaces with cpu_address_space_init */ | ||
77 | typedef enum ARMASIdx { | ||
78 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/target/arm/helper.c | ||
81 | +++ b/target/arm/helper.c | ||
82 | @@ -XXX,XX +XXX,XX @@ int fp_exception_el(CPUARMState *env, int cur_el) | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | +ARMMMUIdx arm_v7m_mmu_idx_for_secstate_and_priv(CPUARMState *env, | ||
87 | + bool secstate, bool priv) | ||
88 | +{ | ||
89 | + ARMMMUIdx mmu_idx = ARM_MMU_IDX_M; | ||
24 | + | 90 | + |
25 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_d | 91 | + if (priv) { |
26 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_s | 92 | + mmu_idx |= ARM_MMU_IDX_M_PRIV; |
27 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_h | ||
28 | @@ -XXX,XX +XXX,XX @@ VSHLL_S_2sh 1111 001 0 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_b | ||
29 | VSHLL_U_2sh 1111 001 1 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_s | ||
30 | VSHLL_U_2sh 1111 001 1 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_h | ||
31 | VSHLL_U_2sh 1111 001 1 1 . ...... .... 1010 . 0 . 1 .... @2reg_shll_b | ||
32 | + | ||
33 | +# VCVT fixed<->float conversions | ||
34 | +# TODO: FP16 fixed<->float conversions are opc==0b1100 and 0b1101 | ||
35 | +VCVT_SF_2sh 1111 001 0 1 . ...... .... 1110 0 . . 1 .... @2reg_vcvt | ||
36 | +VCVT_UF_2sh 1111 001 1 1 . ...... .... 1110 0 . . 1 .... @2reg_vcvt | ||
37 | +VCVT_FS_2sh 1111 001 0 1 . ...... .... 1111 0 . . 1 .... @2reg_vcvt | ||
38 | +VCVT_FU_2sh 1111 001 1 1 . ...... .... 1111 0 . . 1 .... @2reg_vcvt | ||
39 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/target/arm/translate-neon.inc.c | ||
42 | +++ b/target/arm/translate-neon.inc.c | ||
43 | @@ -XXX,XX +XXX,XX @@ static bool trans_VSHLL_U_2sh(DisasContext *s, arg_2reg_shift *a) | ||
44 | }; | ||
45 | return do_vshll_2sh(s, a, widenfn[a->size], true); | ||
46 | } | ||
47 | + | ||
48 | +static bool do_fp_2sh(DisasContext *s, arg_2reg_shift *a, | ||
49 | + NeonGenTwoSingleOPFn *fn) | ||
50 | +{ | ||
51 | + /* FP operations in 2-reg-and-shift group */ | ||
52 | + TCGv_i32 tmp, shiftv; | ||
53 | + TCGv_ptr fpstatus; | ||
54 | + int pass; | ||
55 | + | ||
56 | + if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | ||
57 | + return false; | ||
58 | + } | 93 | + } |
59 | + | 94 | + |
60 | + /* UNDEF accesses to D16-D31 if they don't exist. */ | 95 | + if (armv7m_nvic_neg_prio_requested(env->nvic, secstate)) { |
61 | + if (!dc_isar_feature(aa32_simd_r32, s) && | 96 | + mmu_idx |= ARM_MMU_IDX_M_NEGPRI; |
62 | + ((a->vd | a->vm) & 0x10)) { | ||
63 | + return false; | ||
64 | + } | 97 | + } |
65 | + | 98 | + |
66 | + if ((a->vm | a->vd) & a->q) { | 99 | + if (secstate) { |
67 | + return false; | 100 | + mmu_idx |= ARM_MMU_IDX_M_S; |
68 | + } | 101 | + } |
69 | + | 102 | + |
70 | + if (!vfp_access_check(s)) { | 103 | + return mmu_idx; |
71 | + return true; | 104 | +} |
105 | + | ||
106 | +/* Return the MMU index for a v7M CPU in the specified security state */ | ||
107 | +ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, bool secstate) | ||
108 | +{ | ||
109 | + bool priv = arm_current_el(env) != 0; | ||
110 | + | ||
111 | + return arm_v7m_mmu_idx_for_secstate_and_priv(env, secstate, priv); | ||
112 | +} | ||
113 | + | ||
114 | +int cpu_mmu_index(CPUARMState *env, bool ifetch) | ||
115 | +{ | ||
116 | + int el = arm_current_el(env); | ||
117 | + | ||
118 | + if (arm_feature(env, ARM_FEATURE_M)) { | ||
119 | + ARMMMUIdx mmu_idx = arm_v7m_mmu_idx_for_secstate(env, env->v7m.secure); | ||
120 | + | ||
121 | + return arm_to_core_mmu_idx(mmu_idx); | ||
72 | + } | 122 | + } |
73 | + | 123 | + |
74 | + fpstatus = get_fpstatus_ptr(1); | 124 | + if (el < 2 && arm_is_secure_below_el3(env)) { |
75 | + shiftv = tcg_const_i32(a->shift); | 125 | + return arm_to_core_mmu_idx(ARMMMUIdx_S1SE0 + el); |
76 | + for (pass = 0; pass < (a->q ? 4 : 2); pass++) { | ||
77 | + tmp = neon_load_reg(a->vm, pass); | ||
78 | + fn(tmp, tmp, shiftv, fpstatus); | ||
79 | + neon_store_reg(a->vd, pass, tmp); | ||
80 | + } | 126 | + } |
81 | + tcg_temp_free_ptr(fpstatus); | 127 | + return el; |
82 | + tcg_temp_free_i32(shiftv); | ||
83 | + return true; | ||
84 | +} | 128 | +} |
85 | + | 129 | + |
86 | +#define DO_FP_2SH(INSN, FUNC) \ | 130 | void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, |
87 | + static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \ | 131 | target_ulong *cs_base, uint32_t *pflags) |
88 | + { \ | 132 | { |
89 | + return do_fp_2sh(s, a, FUNC); \ | ||
90 | + } | ||
91 | + | ||
92 | +DO_FP_2SH(VCVT_SF, gen_helper_vfp_sltos) | ||
93 | +DO_FP_2SH(VCVT_UF, gen_helper_vfp_ultos) | ||
94 | +DO_FP_2SH(VCVT_FS, gen_helper_vfp_tosls_round_to_zero) | ||
95 | +DO_FP_2SH(VCVT_FU, gen_helper_vfp_touls_round_to_zero) | ||
96 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/target/arm/translate.c | ||
99 | +++ b/target/arm/translate.c | ||
100 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
101 | int q; | ||
102 | int rd, rn, rm, rd_ofs, rn_ofs, rm_ofs; | ||
103 | int size; | ||
104 | - int shift; | ||
105 | int pass; | ||
106 | int u; | ||
107 | int vec_size; | ||
108 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
109 | return 1; | ||
110 | } else if (insn & (1 << 4)) { | ||
111 | if ((insn & 0x00380080) != 0) { | ||
112 | - /* Two registers and shift. */ | ||
113 | - op = (insn >> 8) & 0xf; | ||
114 | - | ||
115 | - switch (op) { | ||
116 | - case 0: /* VSHR */ | ||
117 | - case 1: /* VSRA */ | ||
118 | - case 2: /* VRSHR */ | ||
119 | - case 3: /* VRSRA */ | ||
120 | - case 4: /* VSRI */ | ||
121 | - case 5: /* VSHL, VSLI */ | ||
122 | - case 6: /* VQSHLU */ | ||
123 | - case 7: /* VQSHL */ | ||
124 | - case 8: /* VSHRN, VRSHRN, VQSHRUN, VQRSHRUN */ | ||
125 | - case 9: /* VQSHRN, VQRSHRN */ | ||
126 | - case 10: /* VSHLL, including VMOVL */ | ||
127 | - return 1; /* handled by decodetree */ | ||
128 | - default: | ||
129 | - break; | ||
130 | - } | ||
131 | - | ||
132 | - if (insn & (1 << 7)) { | ||
133 | - /* 64-bit shift. */ | ||
134 | - if (op > 7) { | ||
135 | - return 1; | ||
136 | - } | ||
137 | - size = 3; | ||
138 | - } else { | ||
139 | - size = 2; | ||
140 | - while ((insn & (1 << (size + 19))) == 0) | ||
141 | - size--; | ||
142 | - } | ||
143 | - shift = (insn >> 16) & ((1 << (3 + size)) - 1); | ||
144 | - if (op >= 14) { | ||
145 | - /* VCVT fixed-point. */ | ||
146 | - TCGv_ptr fpst; | ||
147 | - TCGv_i32 shiftv; | ||
148 | - VFPGenFixPointFn *fn; | ||
149 | - | ||
150 | - if (!(insn & (1 << 21)) || (q && ((rd | rm) & 1))) { | ||
151 | - return 1; | ||
152 | - } | ||
153 | - | ||
154 | - if (!(op & 1)) { | ||
155 | - if (u) { | ||
156 | - fn = gen_helper_vfp_ultos; | ||
157 | - } else { | ||
158 | - fn = gen_helper_vfp_sltos; | ||
159 | - } | ||
160 | - } else { | ||
161 | - if (u) { | ||
162 | - fn = gen_helper_vfp_touls_round_to_zero; | ||
163 | - } else { | ||
164 | - fn = gen_helper_vfp_tosls_round_to_zero; | ||
165 | - } | ||
166 | - } | ||
167 | - | ||
168 | - /* We have already masked out the must-be-1 top bit of imm6, | ||
169 | - * hence this 32-shift where the ARM ARM has 64-imm6. | ||
170 | - */ | ||
171 | - shift = 32 - shift; | ||
172 | - fpst = get_fpstatus_ptr(1); | ||
173 | - shiftv = tcg_const_i32(shift); | ||
174 | - for (pass = 0; pass < (q ? 4 : 2); pass++) { | ||
175 | - TCGv_i32 tmpf = neon_load_reg(rm, pass); | ||
176 | - fn(tmpf, tmpf, shiftv, fpst); | ||
177 | - neon_store_reg(rd, pass, tmpf); | ||
178 | - } | ||
179 | - tcg_temp_free_ptr(fpst); | ||
180 | - tcg_temp_free_i32(shiftv); | ||
181 | - } else { | ||
182 | - return 1; | ||
183 | - } | ||
184 | + /* Two registers and shift: handled by decodetree */ | ||
185 | + return 1; | ||
186 | } else { /* (insn & 0x00380080) == 0 */ | ||
187 | int invert, reg_ofs, vec_size; | ||
188 | |||
189 | -- | 133 | -- |
190 | 2.20.1 | 134 | 2.20.1 |
191 | 135 | ||
192 | 136 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | The pattern | ||
4 | |||
5 | ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
6 | |||
7 | is computing the full ARMMMUIdx, stripping off the ARM bits, | ||
8 | and then putting them back. | ||
9 | |||
10 | Avoid the extra two steps with the appropriate helper function. | ||
11 | |||
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
13 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 20190108223129.5570-17-richard.henderson@linaro.org | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | --- | ||
17 | target/arm/cpu.h | 9 ++++++++- | ||
18 | target/arm/internals.h | 8 ++++++++ | ||
19 | target/arm/helper.c | 27 ++++++++++++++++----------- | ||
20 | 3 files changed, 32 insertions(+), 12 deletions(-) | ||
21 | |||
22 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
23 | index XXXXXXX..XXXXXXX 100644 | ||
24 | --- a/target/arm/cpu.h | ||
25 | +++ b/target/arm/cpu.h | ||
26 | @@ -XXX,XX +XXX,XX @@ ARMMMUIdx arm_v7m_mmu_idx_for_secstate_and_priv(CPUARMState *env, | ||
27 | /* Return the MMU index for a v7M CPU in the specified security state */ | ||
28 | ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, bool secstate); | ||
29 | |||
30 | -/* Determine the current mmu_idx to use for normal loads/stores */ | ||
31 | +/** | ||
32 | + * cpu_mmu_index: | ||
33 | + * @env: The cpu environment | ||
34 | + * @ifetch: True for code access, false for data access. | ||
35 | + * | ||
36 | + * Return the core mmu index for the current translation regime. | ||
37 | + * This function is used by generic TCG code paths. | ||
38 | + */ | ||
39 | int cpu_mmu_index(CPUARMState *env, bool ifetch); | ||
40 | |||
41 | /* Indexes used when registering address spaces with cpu_address_space_init */ | ||
42 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/target/arm/internals.h | ||
45 | +++ b/target/arm/internals.h | ||
46 | @@ -XXX,XX +XXX,XX @@ void arm_cpu_update_virq(ARMCPU *cpu); | ||
47 | */ | ||
48 | void arm_cpu_update_vfiq(ARMCPU *cpu); | ||
49 | |||
50 | +/** | ||
51 | + * arm_mmu_idx: | ||
52 | + * @env: The cpu environment | ||
53 | + * | ||
54 | + * Return the full ARMMMUIdx for the current translation regime. | ||
55 | + */ | ||
56 | +ARMMMUIdx arm_mmu_idx(CPUARMState *env); | ||
57 | + | ||
58 | #endif | ||
59 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
60 | index XXXXXXX..XXXXXXX 100644 | ||
61 | --- a/target/arm/helper.c | ||
62 | +++ b/target/arm/helper.c | ||
63 | @@ -XXX,XX +XXX,XX @@ static bool v7m_push_callee_stack(ARMCPU *cpu, uint32_t lr, bool dotailchain, | ||
64 | limit = env->v7m.msplim[M_REG_S]; | ||
65 | } | ||
66 | } else { | ||
67 | - mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
68 | + mmu_idx = arm_mmu_idx(env); | ||
69 | frame_sp_p = &env->regs[13]; | ||
70 | limit = v7m_sp_limit(env); | ||
71 | } | ||
72 | @@ -XXX,XX +XXX,XX @@ static bool v7m_push_stack(ARMCPU *cpu) | ||
73 | CPUARMState *env = &cpu->env; | ||
74 | uint32_t xpsr = xpsr_read(env); | ||
75 | uint32_t frameptr = env->regs[13]; | ||
76 | - ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
77 | + ARMMMUIdx mmu_idx = arm_mmu_idx(env); | ||
78 | |||
79 | /* Align stack pointer if the guest wants that */ | ||
80 | if ((frameptr & 4) && | ||
81 | @@ -XXX,XX +XXX,XX @@ hwaddr arm_cpu_get_phys_page_attrs_debug(CPUState *cs, vaddr addr, | ||
82 | int prot; | ||
83 | bool ret; | ||
84 | ARMMMUFaultInfo fi = {}; | ||
85 | - ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
86 | + ARMMMUIdx mmu_idx = arm_mmu_idx(env); | ||
87 | |||
88 | *attrs = (MemTxAttrs) {}; | ||
89 | |||
90 | @@ -XXX,XX +XXX,XX @@ ARMMMUIdx arm_v7m_mmu_idx_for_secstate(CPUARMState *env, bool secstate) | ||
91 | return arm_v7m_mmu_idx_for_secstate_and_priv(env, secstate, priv); | ||
92 | } | ||
93 | |||
94 | -int cpu_mmu_index(CPUARMState *env, bool ifetch) | ||
95 | +ARMMMUIdx arm_mmu_idx(CPUARMState *env) | ||
96 | { | ||
97 | - int el = arm_current_el(env); | ||
98 | + int el; | ||
99 | |||
100 | if (arm_feature(env, ARM_FEATURE_M)) { | ||
101 | - ARMMMUIdx mmu_idx = arm_v7m_mmu_idx_for_secstate(env, env->v7m.secure); | ||
102 | - | ||
103 | - return arm_to_core_mmu_idx(mmu_idx); | ||
104 | + return arm_v7m_mmu_idx_for_secstate(env, env->v7m.secure); | ||
105 | } | ||
106 | |||
107 | + el = arm_current_el(env); | ||
108 | if (el < 2 && arm_is_secure_below_el3(env)) { | ||
109 | - return arm_to_core_mmu_idx(ARMMMUIdx_S1SE0 + el); | ||
110 | + return ARMMMUIdx_S1SE0 + el; | ||
111 | + } else { | ||
112 | + return ARMMMUIdx_S12NSE0 + el; | ||
113 | } | ||
114 | - return el; | ||
115 | +} | ||
116 | + | ||
117 | +int cpu_mmu_index(CPUARMState *env, bool ifetch) | ||
118 | +{ | ||
119 | + return arm_to_core_mmu_idx(arm_mmu_idx(env)); | ||
120 | } | ||
121 | |||
122 | void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
123 | target_ulong *cs_base, uint32_t *pflags) | ||
124 | { | ||
125 | - ARMMMUIdx mmu_idx = core_to_arm_mmu_idx(env, cpu_mmu_index(env, false)); | ||
126 | + ARMMMUIdx mmu_idx = arm_mmu_idx(env); | ||
127 | int current_el = arm_current_el(env); | ||
128 | int fp_el = fp_exception_el(env, current_el); | ||
129 | uint32_t flags = 0; | ||
130 | -- | ||
131 | 2.20.1 | ||
132 | |||
133 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | While we could expose stage_1_mmu_idx, the combination is | ||
4 | probably going to be more useful. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20190108223129.5570-18-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | target/arm/internals.h | 15 +++++++++++++++ | ||
12 | target/arm/helper.c | 7 +++++++ | ||
13 | 2 files changed, 22 insertions(+) | ||
14 | |||
15 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/arm/internals.h | ||
18 | +++ b/target/arm/internals.h | ||
19 | @@ -XXX,XX +XXX,XX @@ void arm_cpu_update_vfiq(ARMCPU *cpu); | ||
20 | */ | ||
21 | ARMMMUIdx arm_mmu_idx(CPUARMState *env); | ||
22 | |||
23 | +/** | ||
24 | + * arm_stage1_mmu_idx: | ||
25 | + * @env: The cpu environment | ||
26 | + * | ||
27 | + * Return the ARMMMUIdx for the stage1 traversal for the current regime. | ||
28 | + */ | ||
29 | +#ifdef CONFIG_USER_ONLY | ||
30 | +static inline ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env) | ||
31 | +{ | ||
32 | + return ARMMMUIdx_S1NSE0; | ||
33 | +} | ||
34 | +#else | ||
35 | +ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env); | ||
36 | +#endif | ||
37 | + | ||
38 | #endif | ||
39 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
40 | index XXXXXXX..XXXXXXX 100644 | ||
41 | --- a/target/arm/helper.c | ||
42 | +++ b/target/arm/helper.c | ||
43 | @@ -XXX,XX +XXX,XX @@ int cpu_mmu_index(CPUARMState *env, bool ifetch) | ||
44 | return arm_to_core_mmu_idx(arm_mmu_idx(env)); | ||
45 | } | ||
46 | |||
47 | +#ifndef CONFIG_USER_ONLY | ||
48 | +ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env) | ||
49 | +{ | ||
50 | + return stage_1_mmu_idx(arm_mmu_idx(env)); | ||
51 | +} | ||
52 | +#endif | ||
53 | + | ||
54 | void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
55 | target_ulong *cs_base, uint32_t *pflags) | ||
56 | { | ||
57 | -- | ||
58 | 2.20.1 | ||
59 | |||
60 | diff view generated by jsdifflib |
1 | Convert the remaining Neon narrowing shifts to decodetree: | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | * VQSHRN | 2 | |
3 | * VQRSHRN | 3 | Split out functions to extract the virtual address parameters. |
4 | 4 | Let the functions choose T0 or T1 address space half, if present. | |
5 | Extract (most of) the control bits that vary between EL or Tx. | ||
6 | |||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Message-id: 20190108223129.5570-19-richard.henderson@linaro.org | ||
10 | [PMM: fixed minor checkpatch comment nits] | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20200522145520.6778-7-peter.maydell@linaro.org | ||
8 | --- | 12 | --- |
9 | target/arm/neon-dp.decode | 20 ++++++ | 13 | target/arm/internals.h | 14 +++ |
10 | target/arm/translate-neon.inc.c | 15 +++++ | 14 | target/arm/helper.c | 278 ++++++++++++++++++++++------------------- |
11 | target/arm/translate.c | 110 +------------------------------- | 15 | 2 files changed, 164 insertions(+), 128 deletions(-) |
12 | 3 files changed, 37 insertions(+), 108 deletions(-) | 16 | |
13 | 17 | diff --git a/target/arm/internals.h b/target/arm/internals.h | |
14 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | ||
15 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/neon-dp.decode | 19 | --- a/target/arm/internals.h |
17 | +++ b/target/arm/neon-dp.decode | 20 | +++ b/target/arm/internals.h |
18 | @@ -XXX,XX +XXX,XX @@ VQSHRUN_16_2sh 1111 001 1 1 . ...... .... 1000 . 0 . 1 .... @2reg_shrn_h | 21 | @@ -XXX,XX +XXX,XX @@ static inline ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env) |
19 | VQRSHRUN_64_2sh 1111 001 1 1 . ...... .... 1000 . 1 . 1 .... @2reg_shrn_d | 22 | ARMMMUIdx arm_stage1_mmu_idx(CPUARMState *env); |
20 | VQRSHRUN_32_2sh 1111 001 1 1 . ...... .... 1000 . 1 . 1 .... @2reg_shrn_s | 23 | #endif |
21 | VQRSHRUN_16_2sh 1111 001 1 1 . ...... .... 1000 . 1 . 1 .... @2reg_shrn_h | 24 | |
22 | + | 25 | +/* |
23 | +# VQSHRN with signed input | 26 | + * Parameters of a given virtual address, as extracted from the |
24 | +VQSHRN_S64_2sh 1111 001 0 1 . ...... .... 1001 . 0 . 1 .... @2reg_shrn_d | 27 | + * translation control register (TCR) for a given regime. |
25 | +VQSHRN_S32_2sh 1111 001 0 1 . ...... .... 1001 . 0 . 1 .... @2reg_shrn_s | 28 | + */ |
26 | +VQSHRN_S16_2sh 1111 001 0 1 . ...... .... 1001 . 0 . 1 .... @2reg_shrn_h | 29 | +typedef struct ARMVAParameters { |
27 | + | 30 | + unsigned tsz : 8; |
28 | +# VQRSHRN with signed input | 31 | + unsigned select : 1; |
29 | +VQRSHRN_S64_2sh 1111 001 0 1 . ...... .... 1001 . 1 . 1 .... @2reg_shrn_d | 32 | + bool tbi : 1; |
30 | +VQRSHRN_S32_2sh 1111 001 0 1 . ...... .... 1001 . 1 . 1 .... @2reg_shrn_s | 33 | + bool epd : 1; |
31 | +VQRSHRN_S16_2sh 1111 001 0 1 . ...... .... 1001 . 1 . 1 .... @2reg_shrn_h | 34 | + bool hpd : 1; |
32 | + | 35 | + bool using16k : 1; |
33 | +# VQSHRN with unsigned input | 36 | + bool using64k : 1; |
34 | +VQSHRN_U64_2sh 1111 001 1 1 . ...... .... 1001 . 0 . 1 .... @2reg_shrn_d | 37 | +} ARMVAParameters; |
35 | +VQSHRN_U32_2sh 1111 001 1 1 . ...... .... 1001 . 0 . 1 .... @2reg_shrn_s | 38 | + |
36 | +VQSHRN_U16_2sh 1111 001 1 1 . ...... .... 1001 . 0 . 1 .... @2reg_shrn_h | 39 | #endif |
37 | + | 40 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
38 | +# VQRSHRN with unsigned input | ||
39 | +VQRSHRN_U64_2sh 1111 001 1 1 . ...... .... 1001 . 1 . 1 .... @2reg_shrn_d | ||
40 | +VQRSHRN_U32_2sh 1111 001 1 1 . ...... .... 1001 . 1 . 1 .... @2reg_shrn_s | ||
41 | +VQRSHRN_U16_2sh 1111 001 1 1 . ...... .... 1001 . 1 . 1 .... @2reg_shrn_h | ||
42 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | 41 | index XXXXXXX..XXXXXXX 100644 |
44 | --- a/target/arm/translate-neon.inc.c | 42 | --- a/target/arm/helper.c |
45 | +++ b/target/arm/translate-neon.inc.c | 43 | +++ b/target/arm/helper.c |
46 | @@ -XXX,XX +XXX,XX @@ DO_2SN_32(VQSHRUN_16, gen_helper_neon_shl_s16, gen_helper_neon_unarrow_sat8) | 44 | @@ -XXX,XX +XXX,XX @@ static uint8_t convert_stage2_attrs(CPUARMState *env, uint8_t s2attrs) |
47 | DO_2SN_64(VQRSHRUN_64, gen_helper_neon_rshl_s64, gen_helper_neon_unarrow_sat32) | 45 | return (hiattr << 6) | (hihint << 4) | (loattr << 2) | lohint; |
48 | DO_2SN_32(VQRSHRUN_32, gen_helper_neon_rshl_s32, gen_helper_neon_unarrow_sat16) | ||
49 | DO_2SN_32(VQRSHRUN_16, gen_helper_neon_rshl_s16, gen_helper_neon_unarrow_sat8) | ||
50 | +DO_2SN_64(VQSHRN_S64, gen_sshl_i64, gen_helper_neon_narrow_sat_s32) | ||
51 | +DO_2SN_32(VQSHRN_S32, gen_sshl_i32, gen_helper_neon_narrow_sat_s16) | ||
52 | +DO_2SN_32(VQSHRN_S16, gen_helper_neon_shl_s16, gen_helper_neon_narrow_sat_s8) | ||
53 | + | ||
54 | +DO_2SN_64(VQRSHRN_S64, gen_helper_neon_rshl_s64, gen_helper_neon_narrow_sat_s32) | ||
55 | +DO_2SN_32(VQRSHRN_S32, gen_helper_neon_rshl_s32, gen_helper_neon_narrow_sat_s16) | ||
56 | +DO_2SN_32(VQRSHRN_S16, gen_helper_neon_rshl_s16, gen_helper_neon_narrow_sat_s8) | ||
57 | + | ||
58 | +DO_2SN_64(VQSHRN_U64, gen_ushl_i64, gen_helper_neon_narrow_sat_u32) | ||
59 | +DO_2SN_32(VQSHRN_U32, gen_ushl_i32, gen_helper_neon_narrow_sat_u16) | ||
60 | +DO_2SN_32(VQSHRN_U16, gen_helper_neon_shl_u16, gen_helper_neon_narrow_sat_u8) | ||
61 | + | ||
62 | +DO_2SN_64(VQRSHRN_U64, gen_helper_neon_rshl_u64, gen_helper_neon_narrow_sat_u32) | ||
63 | +DO_2SN_32(VQRSHRN_U32, gen_helper_neon_rshl_u32, gen_helper_neon_narrow_sat_u16) | ||
64 | +DO_2SN_32(VQRSHRN_U16, gen_helper_neon_rshl_u16, gen_helper_neon_narrow_sat_u8) | ||
65 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
66 | index XXXXXXX..XXXXXXX 100644 | ||
67 | --- a/target/arm/translate.c | ||
68 | +++ b/target/arm/translate.c | ||
69 | @@ -XXX,XX +XXX,XX @@ static inline void gen_neon_unarrow_sats(int size, TCGv_i32 dest, TCGv_i64 src) | ||
70 | } | ||
71 | } | 46 | } |
72 | 47 | ||
73 | -static inline void gen_neon_shift_narrow(int size, TCGv_i32 var, TCGv_i32 shift, | 48 | +static ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, |
74 | - int q, int u) | 49 | + ARMMMUIdx mmu_idx, bool data) |
75 | -{ | 50 | +{ |
76 | - if (q) { | 51 | + uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; |
77 | - if (u) { | 52 | + uint32_t el = regime_el(env, mmu_idx); |
78 | - switch (size) { | 53 | + bool tbi, epd, hpd, using16k, using64k; |
79 | - case 1: gen_helper_neon_rshl_u16(var, var, shift); break; | 54 | + int select, tsz; |
80 | - case 2: gen_helper_neon_rshl_u32(var, var, shift); break; | 55 | + |
81 | - default: abort(); | 56 | + /* |
57 | + * Bit 55 is always between the two regions, and is canonical for | ||
58 | + * determining if address tagging is enabled. | ||
59 | + */ | ||
60 | + select = extract64(va, 55, 1); | ||
61 | + | ||
62 | + if (el > 1) { | ||
63 | + tsz = extract32(tcr, 0, 6); | ||
64 | + using64k = extract32(tcr, 14, 1); | ||
65 | + using16k = extract32(tcr, 15, 1); | ||
66 | + if (mmu_idx == ARMMMUIdx_S2NS) { | ||
67 | + /* VTCR_EL2 */ | ||
68 | + tbi = hpd = false; | ||
69 | + } else { | ||
70 | + tbi = extract32(tcr, 20, 1); | ||
71 | + hpd = extract32(tcr, 24, 1); | ||
72 | + } | ||
73 | + epd = false; | ||
74 | + } else if (!select) { | ||
75 | + tsz = extract32(tcr, 0, 6); | ||
76 | + epd = extract32(tcr, 7, 1); | ||
77 | + using64k = extract32(tcr, 14, 1); | ||
78 | + using16k = extract32(tcr, 15, 1); | ||
79 | + tbi = extract64(tcr, 37, 1); | ||
80 | + hpd = extract64(tcr, 41, 1); | ||
81 | + } else { | ||
82 | + int tg = extract32(tcr, 30, 2); | ||
83 | + using16k = tg == 1; | ||
84 | + using64k = tg == 3; | ||
85 | + tsz = extract32(tcr, 16, 6); | ||
86 | + epd = extract32(tcr, 23, 1); | ||
87 | + tbi = extract64(tcr, 38, 1); | ||
88 | + hpd = extract64(tcr, 42, 1); | ||
89 | + } | ||
90 | + tsz = MIN(tsz, 39); /* TODO: ARMv8.4-TTST */ | ||
91 | + tsz = MAX(tsz, 16); /* TODO: ARMv8.2-LVA */ | ||
92 | + | ||
93 | + return (ARMVAParameters) { | ||
94 | + .tsz = tsz, | ||
95 | + .select = select, | ||
96 | + .tbi = tbi, | ||
97 | + .epd = epd, | ||
98 | + .hpd = hpd, | ||
99 | + .using16k = using16k, | ||
100 | + .using64k = using64k, | ||
101 | + }; | ||
102 | +} | ||
103 | + | ||
104 | +static ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, | ||
105 | + ARMMMUIdx mmu_idx) | ||
106 | +{ | ||
107 | + uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; | ||
108 | + uint32_t el = regime_el(env, mmu_idx); | ||
109 | + int select, tsz; | ||
110 | + bool epd, hpd; | ||
111 | + | ||
112 | + if (mmu_idx == ARMMMUIdx_S2NS) { | ||
113 | + /* VTCR */ | ||
114 | + bool sext = extract32(tcr, 4, 1); | ||
115 | + bool sign = extract32(tcr, 3, 1); | ||
116 | + | ||
117 | + /* | ||
118 | + * If the sign-extend bit is not the same as t0sz[3], the result | ||
119 | + * is unpredictable. Flag this as a guest error. | ||
120 | + */ | ||
121 | + if (sign != sext) { | ||
122 | + qemu_log_mask(LOG_GUEST_ERROR, | ||
123 | + "AArch32: VTCR.S / VTCR.T0SZ[3] mismatch\n"); | ||
124 | + } | ||
125 | + tsz = sextract32(tcr, 0, 4) + 8; | ||
126 | + select = 0; | ||
127 | + hpd = false; | ||
128 | + epd = false; | ||
129 | + } else if (el == 2) { | ||
130 | + /* HTCR */ | ||
131 | + tsz = extract32(tcr, 0, 3); | ||
132 | + select = 0; | ||
133 | + hpd = extract64(tcr, 24, 1); | ||
134 | + epd = false; | ||
135 | + } else { | ||
136 | + int t0sz = extract32(tcr, 0, 3); | ||
137 | + int t1sz = extract32(tcr, 16, 3); | ||
138 | + | ||
139 | + if (t1sz == 0) { | ||
140 | + select = va > (0xffffffffu >> t0sz); | ||
141 | + } else { | ||
142 | + /* Note that we will detect errors later. */ | ||
143 | + select = va >= ~(0xffffffffu >> t1sz); | ||
144 | + } | ||
145 | + if (!select) { | ||
146 | + tsz = t0sz; | ||
147 | + epd = extract32(tcr, 7, 1); | ||
148 | + hpd = extract64(tcr, 41, 1); | ||
149 | + } else { | ||
150 | + tsz = t1sz; | ||
151 | + epd = extract32(tcr, 23, 1); | ||
152 | + hpd = extract64(tcr, 42, 1); | ||
153 | + } | ||
154 | + /* For aarch32, hpd0 is not enabled without t2e as well. */ | ||
155 | + hpd &= extract32(tcr, 6, 1); | ||
156 | + } | ||
157 | + | ||
158 | + return (ARMVAParameters) { | ||
159 | + .tsz = tsz, | ||
160 | + .select = select, | ||
161 | + .epd = epd, | ||
162 | + .hpd = hpd, | ||
163 | + }; | ||
164 | +} | ||
165 | + | ||
166 | static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, | ||
167 | MMUAccessType access_type, ARMMMUIdx mmu_idx, | ||
168 | hwaddr *phys_ptr, MemTxAttrs *txattrs, int *prot, | ||
169 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, | ||
170 | /* Read an LPAE long-descriptor translation table. */ | ||
171 | ARMFaultType fault_type = ARMFault_Translation; | ||
172 | uint32_t level; | ||
173 | - uint32_t epd = 0; | ||
174 | - int32_t t0sz, t1sz; | ||
175 | - uint32_t tg; | ||
176 | + ARMVAParameters param; | ||
177 | uint64_t ttbr; | ||
178 | - int ttbr_select; | ||
179 | hwaddr descaddr, indexmask, indexmask_grainsize; | ||
180 | uint32_t tableattrs; | ||
181 | - target_ulong page_size; | ||
182 | + target_ulong page_size, top_bits; | ||
183 | uint32_t attrs; | ||
184 | - int32_t stride = 9; | ||
185 | - int32_t addrsize; | ||
186 | - int inputsize; | ||
187 | - int32_t tbi = 0; | ||
188 | + int32_t stride; | ||
189 | + int addrsize, inputsize; | ||
190 | TCR *tcr = regime_tcr(env, mmu_idx); | ||
191 | int ap, ns, xn, pxn; | ||
192 | uint32_t el = regime_el(env, mmu_idx); | ||
193 | - bool ttbr1_valid = true; | ||
194 | + bool ttbr1_valid; | ||
195 | uint64_t descaddrmask; | ||
196 | bool aarch64 = arm_el_is_aa64(env, el); | ||
197 | - bool hpd = false; | ||
198 | |||
199 | /* TODO: | ||
200 | * This code does not handle the different format TCR for VTCR_EL2. | ||
201 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, | ||
202 | * support for those page table walks. | ||
203 | */ | ||
204 | if (aarch64) { | ||
205 | + param = aa64_va_parameters(env, address, mmu_idx, | ||
206 | + access_type != MMU_INST_FETCH); | ||
207 | level = 0; | ||
208 | - addrsize = 64; | ||
209 | - if (el > 1) { | ||
210 | - if (mmu_idx != ARMMMUIdx_S2NS) { | ||
211 | - tbi = extract64(tcr->raw_tcr, 20, 1); | ||
82 | - } | 212 | - } |
83 | - } else { | 213 | - } else { |
84 | - switch (size) { | 214 | - if (extract64(address, 55, 1)) { |
85 | - case 1: gen_helper_neon_rshl_s16(var, var, shift); break; | 215 | - tbi = extract64(tcr->raw_tcr, 38, 1); |
86 | - case 2: gen_helper_neon_rshl_s32(var, var, shift); break; | 216 | - } else { |
87 | - default: abort(); | 217 | - tbi = extract64(tcr->raw_tcr, 37, 1); |
88 | - } | 218 | - } |
89 | - } | 219 | - } |
220 | - tbi *= 8; | ||
221 | - | ||
222 | /* If we are in 64-bit EL2 or EL3 then there is no TTBR1, so mark it | ||
223 | * invalid. | ||
224 | */ | ||
225 | - if (el > 1) { | ||
226 | - ttbr1_valid = false; | ||
227 | - } | ||
228 | + ttbr1_valid = (el < 2); | ||
229 | + addrsize = 64 - 8 * param.tbi; | ||
230 | + inputsize = 64 - param.tsz; | ||
231 | } else { | ||
232 | + param = aa32_va_parameters(env, address, mmu_idx); | ||
233 | level = 1; | ||
234 | - addrsize = 32; | ||
235 | /* There is no TTBR1 for EL2 */ | ||
236 | - if (el == 2) { | ||
237 | - ttbr1_valid = false; | ||
238 | - } | ||
239 | + ttbr1_valid = (el != 2); | ||
240 | + addrsize = (mmu_idx == ARMMMUIdx_S2NS ? 40 : 32); | ||
241 | + inputsize = addrsize - param.tsz; | ||
242 | } | ||
243 | |||
244 | - /* Determine whether this address is in the region controlled by | ||
245 | - * TTBR0 or TTBR1 (or if it is in neither region and should fault). | ||
246 | - * This is a Non-secure PL0/1 stage 1 translation, so controlled by | ||
247 | - * TTBCR/TTBR0/TTBR1 in accordance with ARM ARM DDI0406C table B-32: | ||
248 | + /* | ||
249 | + * We determined the region when collecting the parameters, but we | ||
250 | + * have not yet validated that the address is valid for the region. | ||
251 | + * Extract the top bits and verify that they all match select. | ||
252 | */ | ||
253 | - if (aarch64) { | ||
254 | - /* AArch64 translation. */ | ||
255 | - t0sz = extract32(tcr->raw_tcr, 0, 6); | ||
256 | - t0sz = MIN(t0sz, 39); | ||
257 | - t0sz = MAX(t0sz, 16); | ||
258 | - } else if (mmu_idx != ARMMMUIdx_S2NS) { | ||
259 | - /* AArch32 stage 1 translation. */ | ||
260 | - t0sz = extract32(tcr->raw_tcr, 0, 3); | ||
90 | - } else { | 261 | - } else { |
91 | - if (u) { | 262 | - /* AArch32 stage 2 translation. */ |
92 | - switch (size) { | 263 | - bool sext = extract32(tcr->raw_tcr, 4, 1); |
93 | - case 1: gen_helper_neon_shl_u16(var, var, shift); break; | 264 | - bool sign = extract32(tcr->raw_tcr, 3, 1); |
94 | - case 2: gen_ushl_i32(var, var, shift); break; | 265 | - /* Address size is 40-bit for a stage 2 translation, |
95 | - default: abort(); | 266 | - * and t0sz can be negative (from -8 to 7), |
96 | - } | 267 | - * so we need to adjust it to use the TTBR selecting logic below. |
268 | - */ | ||
269 | - addrsize = 40; | ||
270 | - t0sz = sextract32(tcr->raw_tcr, 0, 4) + 8; | ||
271 | - | ||
272 | - /* If the sign-extend bit is not the same as t0sz[3], the result | ||
273 | - * is unpredictable. Flag this as a guest error. */ | ||
274 | - if (sign != sext) { | ||
275 | - qemu_log_mask(LOG_GUEST_ERROR, | ||
276 | - "AArch32: VTCR.S / VTCR.T0SZ[3] mismatch\n"); | ||
277 | - } | ||
278 | - } | ||
279 | - t1sz = extract32(tcr->raw_tcr, 16, 6); | ||
280 | - if (aarch64) { | ||
281 | - t1sz = MIN(t1sz, 39); | ||
282 | - t1sz = MAX(t1sz, 16); | ||
283 | - } | ||
284 | - if (t0sz && !extract64(address, addrsize - t0sz, t0sz - tbi)) { | ||
285 | - /* there is a ttbr0 region and we are in it (high bits all zero) */ | ||
286 | - ttbr_select = 0; | ||
287 | - } else if (ttbr1_valid && t1sz && | ||
288 | - !extract64(~address, addrsize - t1sz, t1sz - tbi)) { | ||
289 | - /* there is a ttbr1 region and we are in it (high bits all one) */ | ||
290 | - ttbr_select = 1; | ||
291 | - } else if (!t0sz) { | ||
292 | - /* ttbr0 region is "everything not in the ttbr1 region" */ | ||
293 | - ttbr_select = 0; | ||
294 | - } else if (!t1sz && ttbr1_valid) { | ||
295 | - /* ttbr1 region is "everything not in the ttbr0 region" */ | ||
296 | - ttbr_select = 1; | ||
297 | - } else { | ||
298 | - /* in the gap between the two regions, this is a Translation fault */ | ||
299 | + top_bits = sextract64(address, inputsize, addrsize - inputsize); | ||
300 | + if (-top_bits != param.select || (param.select && !ttbr1_valid)) { | ||
301 | + /* In the gap between the two regions, this is a Translation fault */ | ||
302 | fault_type = ARMFault_Translation; | ||
303 | goto do_fault; | ||
304 | } | ||
305 | |||
306 | + if (param.using64k) { | ||
307 | + stride = 13; | ||
308 | + } else if (param.using16k) { | ||
309 | + stride = 11; | ||
310 | + } else { | ||
311 | + stride = 9; | ||
312 | + } | ||
313 | + | ||
314 | /* Note that QEMU ignores shareability and cacheability attributes, | ||
315 | * so we don't need to do anything with the SH, ORGN, IRGN fields | ||
316 | * in the TTBCR. Similarly, TTBCR:A1 selects whether we get the | ||
317 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, | ||
318 | * implement any ASID-like capability so we can ignore it (instead | ||
319 | * we will always flush the TLB any time the ASID is changed). | ||
320 | */ | ||
321 | - if (ttbr_select == 0) { | ||
322 | - ttbr = regime_ttbr(env, mmu_idx, 0); | ||
323 | - if (el < 2) { | ||
324 | - epd = extract32(tcr->raw_tcr, 7, 1); | ||
325 | - } | ||
326 | - inputsize = addrsize - t0sz; | ||
327 | - | ||
328 | - tg = extract32(tcr->raw_tcr, 14, 2); | ||
329 | - if (tg == 1) { /* 64KB pages */ | ||
330 | - stride = 13; | ||
331 | - } | ||
332 | - if (tg == 2) { /* 16KB pages */ | ||
333 | - stride = 11; | ||
334 | - } | ||
335 | - if (aarch64 && el > 1) { | ||
336 | - hpd = extract64(tcr->raw_tcr, 24, 1); | ||
97 | - } else { | 337 | - } else { |
98 | - switch (size) { | 338 | - hpd = extract64(tcr->raw_tcr, 41, 1); |
99 | - case 1: gen_helper_neon_shl_s16(var, var, shift); break; | 339 | - } |
100 | - case 2: gen_sshl_i32(var, var, shift); break; | 340 | - if (!aarch64) { |
101 | - default: abort(); | 341 | - /* For aarch32, hpd0 is not enabled without t2e as well. */ |
102 | - } | 342 | - hpd &= extract64(tcr->raw_tcr, 6, 1); |
343 | - } | ||
344 | - } else { | ||
345 | - /* We should only be here if TTBR1 is valid */ | ||
346 | - assert(ttbr1_valid); | ||
347 | - | ||
348 | - ttbr = regime_ttbr(env, mmu_idx, 1); | ||
349 | - epd = extract32(tcr->raw_tcr, 23, 1); | ||
350 | - inputsize = addrsize - t1sz; | ||
351 | - | ||
352 | - tg = extract32(tcr->raw_tcr, 30, 2); | ||
353 | - if (tg == 3) { /* 64KB pages */ | ||
354 | - stride = 13; | ||
355 | - } | ||
356 | - if (tg == 1) { /* 16KB pages */ | ||
357 | - stride = 11; | ||
358 | - } | ||
359 | - hpd = extract64(tcr->raw_tcr, 42, 1); | ||
360 | - if (!aarch64) { | ||
361 | - /* For aarch32, hpd1 is not enabled without t2e as well. */ | ||
362 | - hpd &= extract64(tcr->raw_tcr, 6, 1); | ||
103 | - } | 363 | - } |
104 | - } | 364 | - } |
105 | -} | 365 | + ttbr = regime_ttbr(env, mmu_idx, param.select); |
106 | - | 366 | |
107 | static inline void gen_neon_widen(TCGv_i64 dest, TCGv_i32 src, int size, int u) | 367 | /* Here we should have set up all the parameters for the translation: |
108 | { | 368 | * inputsize, ttbr, epd, stride, tbi |
109 | if (u) { | 369 | */ |
110 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 370 | |
111 | case 6: /* VQSHLU */ | 371 | - if (epd) { |
112 | case 7: /* VQSHL */ | 372 | + if (param.epd) { |
113 | case 8: /* VSHRN, VRSHRN, VQSHRUN, VQRSHRUN */ | 373 | /* Translation table walk disabled => Translation fault on TLB miss |
114 | + case 9: /* VQSHRN, VQRSHRN */ | 374 | * Note: This is always 0 on 64-bit EL2 and EL3. |
115 | return 1; /* handled by decodetree */ | 375 | */ |
116 | default: | 376 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, target_ulong address, |
117 | break; | 377 | } |
118 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 378 | /* Merge in attributes from table descriptors */ |
119 | size--; | 379 | attrs |= nstable << 3; /* NS */ |
120 | } | 380 | - if (hpd) { |
121 | shift = (insn >> 16) & ((1 << (3 + size)) - 1); | 381 | + if (param.hpd) { |
122 | - if (op < 10) { | 382 | /* HPD disables all the table attributes except NSTable. */ |
123 | - /* Shift by immediate and narrow: | 383 | break; |
124 | - VSHRN, VRSHRN, VQSHRN, VQRSHRN. */ | 384 | } |
125 | - int input_unsigned = (op == 8) ? !u : u; | ||
126 | - if (rm & 1) { | ||
127 | - return 1; | ||
128 | - } | ||
129 | - shift = shift - (1 << (size + 3)); | ||
130 | - size++; | ||
131 | - if (size == 3) { | ||
132 | - tmp64 = tcg_const_i64(shift); | ||
133 | - neon_load_reg64(cpu_V0, rm); | ||
134 | - neon_load_reg64(cpu_V1, rm + 1); | ||
135 | - for (pass = 0; pass < 2; pass++) { | ||
136 | - TCGv_i64 in; | ||
137 | - if (pass == 0) { | ||
138 | - in = cpu_V0; | ||
139 | - } else { | ||
140 | - in = cpu_V1; | ||
141 | - } | ||
142 | - if (q) { | ||
143 | - if (input_unsigned) { | ||
144 | - gen_helper_neon_rshl_u64(cpu_V0, in, tmp64); | ||
145 | - } else { | ||
146 | - gen_helper_neon_rshl_s64(cpu_V0, in, tmp64); | ||
147 | - } | ||
148 | - } else { | ||
149 | - if (input_unsigned) { | ||
150 | - gen_ushl_i64(cpu_V0, in, tmp64); | ||
151 | - } else { | ||
152 | - gen_sshl_i64(cpu_V0, in, tmp64); | ||
153 | - } | ||
154 | - } | ||
155 | - tmp = tcg_temp_new_i32(); | ||
156 | - gen_neon_narrow_op(op == 8, u, size - 1, tmp, cpu_V0); | ||
157 | - neon_store_reg(rd, pass, tmp); | ||
158 | - } /* for pass */ | ||
159 | - tcg_temp_free_i64(tmp64); | ||
160 | - } else { | ||
161 | - if (size == 1) { | ||
162 | - imm = (uint16_t)shift; | ||
163 | - imm |= imm << 16; | ||
164 | - } else { | ||
165 | - /* size == 2 */ | ||
166 | - imm = (uint32_t)shift; | ||
167 | - } | ||
168 | - tmp2 = tcg_const_i32(imm); | ||
169 | - tmp4 = neon_load_reg(rm + 1, 0); | ||
170 | - tmp5 = neon_load_reg(rm + 1, 1); | ||
171 | - for (pass = 0; pass < 2; pass++) { | ||
172 | - if (pass == 0) { | ||
173 | - tmp = neon_load_reg(rm, 0); | ||
174 | - } else { | ||
175 | - tmp = tmp4; | ||
176 | - } | ||
177 | - gen_neon_shift_narrow(size, tmp, tmp2, q, | ||
178 | - input_unsigned); | ||
179 | - if (pass == 0) { | ||
180 | - tmp3 = neon_load_reg(rm, 1); | ||
181 | - } else { | ||
182 | - tmp3 = tmp5; | ||
183 | - } | ||
184 | - gen_neon_shift_narrow(size, tmp3, tmp2, q, | ||
185 | - input_unsigned); | ||
186 | - tcg_gen_concat_i32_i64(cpu_V0, tmp, tmp3); | ||
187 | - tcg_temp_free_i32(tmp); | ||
188 | - tcg_temp_free_i32(tmp3); | ||
189 | - tmp = tcg_temp_new_i32(); | ||
190 | - gen_neon_narrow_op(op == 8, u, size - 1, tmp, cpu_V0); | ||
191 | - neon_store_reg(rd, pass, tmp); | ||
192 | - } /* for pass */ | ||
193 | - tcg_temp_free_i32(tmp2); | ||
194 | - } | ||
195 | - } else if (op == 10) { | ||
196 | + if (op == 10) { | ||
197 | /* VSHLL, VMOVL */ | ||
198 | if (q || (rd & 1)) { | ||
199 | return 1; | ||
200 | -- | 385 | -- |
201 | 2.20.1 | 386 | 2.20.1 |
202 | 387 | ||
203 | 388 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | We will shortly want to talk about TBI as it relates to data. | ||
4 | Passing around a pair of variables is less convenient than a | ||
5 | single variable. | ||
6 | |||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Message-id: 20190108223129.5570-20-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | target/arm/cpu.h | 3 +-- | ||
13 | target/arm/translate.h | 3 +-- | ||
14 | target/arm/helper.c | 5 ++--- | ||
15 | target/arm/translate-a64.c | 13 +++++++------ | ||
16 | 4 files changed, 11 insertions(+), 13 deletions(-) | ||
17 | |||
18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | ||
20 | --- a/target/arm/cpu.h | ||
21 | +++ b/target/arm/cpu.h | ||
22 | @@ -XXX,XX +XXX,XX @@ FIELD(TBFLAG_A32, HANDLER, 21, 1) | ||
23 | FIELD(TBFLAG_A32, STACKCHECK, 22, 1) | ||
24 | |||
25 | /* Bit usage when in AArch64 state */ | ||
26 | -FIELD(TBFLAG_A64, TBI0, 0, 1) | ||
27 | -FIELD(TBFLAG_A64, TBI1, 1, 1) | ||
28 | +FIELD(TBFLAG_A64, TBII, 0, 2) | ||
29 | FIELD(TBFLAG_A64, SVEEXC_EL, 2, 2) | ||
30 | FIELD(TBFLAG_A64, ZCR_LEN, 4, 4) | ||
31 | FIELD(TBFLAG_A64, PAUTH_ACTIVE, 8, 1) | ||
32 | diff --git a/target/arm/translate.h b/target/arm/translate.h | ||
33 | index XXXXXXX..XXXXXXX 100644 | ||
34 | --- a/target/arm/translate.h | ||
35 | +++ b/target/arm/translate.h | ||
36 | @@ -XXX,XX +XXX,XX @@ typedef struct DisasContext { | ||
37 | int user; | ||
38 | #endif | ||
39 | ARMMMUIdx mmu_idx; /* MMU index to use for normal loads/stores */ | ||
40 | - bool tbi0; /* TBI0 for EL0/1 or TBI for EL2/3 */ | ||
41 | - bool tbi1; /* TBI1 for EL0/1, not used for EL2/3 */ | ||
42 | + uint8_t tbii; /* TBI1|TBI0 for EL0/1 or TBI for EL2/3 */ | ||
43 | bool ns; /* Use non-secure CPREG bank on access */ | ||
44 | int fp_excp_el; /* FP exception EL or 0 if enabled */ | ||
45 | int sve_excp_el; /* SVE exception EL or 0 if enabled */ | ||
46 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | ||
48 | --- a/target/arm/helper.c | ||
49 | +++ b/target/arm/helper.c | ||
50 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
51 | *pc = env->pc; | ||
52 | flags = FIELD_DP32(flags, TBFLAG_ANY, AARCH64_STATE, 1); | ||
53 | /* Get control bits for tagged addresses */ | ||
54 | - flags = FIELD_DP32(flags, TBFLAG_A64, TBI0, | ||
55 | + flags = FIELD_DP32(flags, TBFLAG_A64, TBII, | ||
56 | + (arm_regime_tbi1(env, mmu_idx) << 1) | | ||
57 | arm_regime_tbi0(env, mmu_idx)); | ||
58 | - flags = FIELD_DP32(flags, TBFLAG_A64, TBI1, | ||
59 | - arm_regime_tbi1(env, mmu_idx)); | ||
60 | |||
61 | if (cpu_isar_feature(aa64_sve, cpu)) { | ||
62 | int sve_el = sve_exception_el(env, current_el); | ||
63 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
64 | index XXXXXXX..XXXXXXX 100644 | ||
65 | --- a/target/arm/translate-a64.c | ||
66 | +++ b/target/arm/translate-a64.c | ||
67 | @@ -XXX,XX +XXX,XX @@ void gen_a64_set_pc_im(uint64_t val) | ||
68 | */ | ||
69 | static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src) | ||
70 | { | ||
71 | + /* Note that TBII is TBI1:TBI0. */ | ||
72 | + int tbi = s->tbii; | ||
73 | |||
74 | if (s->current_el <= 1) { | ||
75 | /* Test if NEITHER or BOTH TBI values are set. If so, no need to | ||
76 | * examine bit 55 of address, can just generate code. | ||
77 | * If mixed, then test via generated code | ||
78 | */ | ||
79 | - if (s->tbi0 && s->tbi1) { | ||
80 | + if (tbi == 3) { | ||
81 | TCGv_i64 tmp_reg = tcg_temp_new_i64(); | ||
82 | /* Both bits set, sign extension from bit 55 into [63:56] will | ||
83 | * cover both cases | ||
84 | @@ -XXX,XX +XXX,XX @@ static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src) | ||
85 | tcg_gen_shli_i64(tmp_reg, src, 8); | ||
86 | tcg_gen_sari_i64(cpu_pc, tmp_reg, 8); | ||
87 | tcg_temp_free_i64(tmp_reg); | ||
88 | - } else if (!s->tbi0 && !s->tbi1) { | ||
89 | + } else if (tbi == 0) { | ||
90 | /* Neither bit set, just load it as-is */ | ||
91 | tcg_gen_mov_i64(cpu_pc, src); | ||
92 | } else { | ||
93 | @@ -XXX,XX +XXX,XX @@ static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src) | ||
94 | |||
95 | tcg_gen_andi_i64(tcg_bit55, src, (1ull << 55)); | ||
96 | |||
97 | - if (s->tbi0) { | ||
98 | + if (tbi == 1) { | ||
99 | /* tbi0==1, tbi1==0, so 0-fill upper byte if bit 55 = 0 */ | ||
100 | tcg_gen_andi_i64(tcg_tmpval, src, | ||
101 | 0x00FFFFFFFFFFFFFFull); | ||
102 | @@ -XXX,XX +XXX,XX @@ static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src) | ||
103 | tcg_temp_free_i64(tcg_tmpval); | ||
104 | } | ||
105 | } else { /* EL > 1 */ | ||
106 | - if (s->tbi0) { | ||
107 | + if (tbi != 0) { | ||
108 | /* Force tag byte to all zero */ | ||
109 | tcg_gen_andi_i64(cpu_pc, src, 0x00FFFFFFFFFFFFFFull); | ||
110 | } else { | ||
111 | @@ -XXX,XX +XXX,XX @@ static void aarch64_tr_init_disas_context(DisasContextBase *dcbase, | ||
112 | dc->condexec_cond = 0; | ||
113 | core_mmu_idx = FIELD_EX32(tb_flags, TBFLAG_ANY, MMUIDX); | ||
114 | dc->mmu_idx = core_to_arm_mmu_idx(env, core_mmu_idx); | ||
115 | - dc->tbi0 = FIELD_EX32(tb_flags, TBFLAG_A64, TBI0); | ||
116 | - dc->tbi1 = FIELD_EX32(tb_flags, TBFLAG_A64, TBI1); | ||
117 | + dc->tbii = FIELD_EX32(tb_flags, TBFLAG_A64, TBII); | ||
118 | dc->current_el = arm_mmu_idx_to_el(dc->mmu_idx); | ||
119 | #if !defined(CONFIG_USER_ONLY) | ||
120 | dc->user = (dc->current_el == 0); | ||
121 | -- | ||
122 | 2.20.1 | ||
123 | |||
124 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | We need to reuse this from helper-a64.c. Provide a stub | ||
4 | definition for CONFIG_USER_ONLY. This matches the stub | ||
5 | definitions that we removed for arm_regime_tbi{0,1} before. | ||
6 | |||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20190108223129.5570-21-richard.henderson@linaro.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | target/arm/internals.h | 17 +++++++++++++++++ | ||
13 | target/arm/helper.c | 4 ++-- | ||
14 | 2 files changed, 19 insertions(+), 2 deletions(-) | ||
15 | |||
16 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
17 | index XXXXXXX..XXXXXXX 100644 | ||
18 | --- a/target/arm/internals.h | ||
19 | +++ b/target/arm/internals.h | ||
20 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMVAParameters { | ||
21 | bool using64k : 1; | ||
22 | } ARMVAParameters; | ||
23 | |||
24 | +#ifdef CONFIG_USER_ONLY | ||
25 | +static inline ARMVAParameters aa64_va_parameters(CPUARMState *env, | ||
26 | + uint64_t va, | ||
27 | + ARMMMUIdx mmu_idx, bool data) | ||
28 | +{ | ||
29 | + return (ARMVAParameters) { | ||
30 | + /* 48-bit address space */ | ||
31 | + .tsz = 16, | ||
32 | + /* We can't handle tagged addresses properly in user-only mode */ | ||
33 | + .tbi = false, | ||
34 | + }; | ||
35 | +} | ||
36 | +#else | ||
37 | +ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, | ||
38 | + ARMMMUIdx mmu_idx, bool data); | ||
39 | +#endif | ||
40 | + | ||
41 | #endif | ||
42 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/target/arm/helper.c | ||
45 | +++ b/target/arm/helper.c | ||
46 | @@ -XXX,XX +XXX,XX @@ static uint8_t convert_stage2_attrs(CPUARMState *env, uint8_t s2attrs) | ||
47 | return (hiattr << 6) | (hihint << 4) | (loattr << 2) | lohint; | ||
48 | } | ||
49 | |||
50 | -static ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, | ||
51 | - ARMMMUIdx mmu_idx, bool data) | ||
52 | +ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, | ||
53 | + ARMMMUIdx mmu_idx, bool data) | ||
54 | { | ||
55 | uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; | ||
56 | uint32_t el = regime_el(env, mmu_idx); | ||
57 | -- | ||
58 | 2.20.1 | ||
59 | |||
60 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | We will want to check TBI for I and D simultaneously. | ||
4 | |||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Message-id: 20190108223129.5570-22-richard.henderson@linaro.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | target/arm/internals.h | 15 ++++++++++++--- | ||
11 | target/arm/helper.c | 10 ++++++++-- | ||
12 | 2 files changed, 20 insertions(+), 5 deletions(-) | ||
13 | |||
14 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/target/arm/internals.h | ||
17 | +++ b/target/arm/internals.h | ||
18 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMVAParameters { | ||
19 | } ARMVAParameters; | ||
20 | |||
21 | #ifdef CONFIG_USER_ONLY | ||
22 | -static inline ARMVAParameters aa64_va_parameters(CPUARMState *env, | ||
23 | - uint64_t va, | ||
24 | - ARMMMUIdx mmu_idx, bool data) | ||
25 | +static inline ARMVAParameters aa64_va_parameters_both(CPUARMState *env, | ||
26 | + uint64_t va, | ||
27 | + ARMMMUIdx mmu_idx) | ||
28 | { | ||
29 | return (ARMVAParameters) { | ||
30 | /* 48-bit address space */ | ||
31 | @@ -XXX,XX +XXX,XX @@ static inline ARMVAParameters aa64_va_parameters(CPUARMState *env, | ||
32 | .tbi = false, | ||
33 | }; | ||
34 | } | ||
35 | + | ||
36 | +static inline ARMVAParameters aa64_va_parameters(CPUARMState *env, | ||
37 | + uint64_t va, | ||
38 | + ARMMMUIdx mmu_idx, bool data) | ||
39 | +{ | ||
40 | + return aa64_va_parameters_both(env, va, mmu_idx); | ||
41 | +} | ||
42 | #else | ||
43 | +ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, | ||
44 | + ARMMMUIdx mmu_idx); | ||
45 | ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, | ||
46 | ARMMMUIdx mmu_idx, bool data); | ||
47 | #endif | ||
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 @@ static uint8_t convert_stage2_attrs(CPUARMState *env, uint8_t s2attrs) | ||
53 | return (hiattr << 6) | (hihint << 4) | (loattr << 2) | lohint; | ||
54 | } | ||
55 | |||
56 | -ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, | ||
57 | - ARMMMUIdx mmu_idx, bool data) | ||
58 | +ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, | ||
59 | + ARMMMUIdx mmu_idx) | ||
60 | { | ||
61 | uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; | ||
62 | uint32_t el = regime_el(env, mmu_idx); | ||
63 | @@ -XXX,XX +XXX,XX @@ ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, | ||
64 | }; | ||
65 | } | ||
66 | |||
67 | +ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, | ||
68 | + ARMMMUIdx mmu_idx, bool data) | ||
69 | +{ | ||
70 | + return aa64_va_parameters_both(env, va, mmu_idx); | ||
71 | +} | ||
72 | + | ||
73 | static ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, | ||
74 | ARMMMUIdx mmu_idx) | ||
75 | { | ||
76 | -- | ||
77 | 2.20.1 | ||
78 | |||
79 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | Use TBID in aa64_va_parameters depending on the data parameter. | ||
4 | This automatically updates all existing users of the function. | ||
5 | |||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Message-id: 20190108223129.5570-23-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | target/arm/internals.h | 1 + | ||
12 | target/arm/helper.c | 14 +++++++++++--- | ||
13 | 2 files changed, 12 insertions(+), 3 deletions(-) | ||
14 | |||
15 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/arm/internals.h | ||
18 | +++ b/target/arm/internals.h | ||
19 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMVAParameters { | ||
20 | unsigned tsz : 8; | ||
21 | unsigned select : 1; | ||
22 | bool tbi : 1; | ||
23 | + bool tbid : 1; | ||
24 | bool epd : 1; | ||
25 | bool hpd : 1; | ||
26 | bool using16k : 1; | ||
27 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/target/arm/helper.c | ||
30 | +++ b/target/arm/helper.c | ||
31 | @@ -XXX,XX +XXX,XX @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, | ||
32 | { | ||
33 | uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; | ||
34 | uint32_t el = regime_el(env, mmu_idx); | ||
35 | - bool tbi, epd, hpd, using16k, using64k; | ||
36 | + bool tbi, tbid, epd, hpd, using16k, using64k; | ||
37 | int select, tsz; | ||
38 | |||
39 | /* | ||
40 | @@ -XXX,XX +XXX,XX @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, | ||
41 | using16k = extract32(tcr, 15, 1); | ||
42 | if (mmu_idx == ARMMMUIdx_S2NS) { | ||
43 | /* VTCR_EL2 */ | ||
44 | - tbi = hpd = false; | ||
45 | + tbi = tbid = hpd = false; | ||
46 | } else { | ||
47 | tbi = extract32(tcr, 20, 1); | ||
48 | hpd = extract32(tcr, 24, 1); | ||
49 | + tbid = extract32(tcr, 29, 1); | ||
50 | } | ||
51 | epd = false; | ||
52 | } else if (!select) { | ||
53 | @@ -XXX,XX +XXX,XX @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, | ||
54 | using16k = extract32(tcr, 15, 1); | ||
55 | tbi = extract64(tcr, 37, 1); | ||
56 | hpd = extract64(tcr, 41, 1); | ||
57 | + tbid = extract64(tcr, 51, 1); | ||
58 | } else { | ||
59 | int tg = extract32(tcr, 30, 2); | ||
60 | using16k = tg == 1; | ||
61 | @@ -XXX,XX +XXX,XX @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, | ||
62 | epd = extract32(tcr, 23, 1); | ||
63 | tbi = extract64(tcr, 38, 1); | ||
64 | hpd = extract64(tcr, 42, 1); | ||
65 | + tbid = extract64(tcr, 52, 1); | ||
66 | } | ||
67 | tsz = MIN(tsz, 39); /* TODO: ARMv8.4-TTST */ | ||
68 | tsz = MAX(tsz, 16); /* TODO: ARMv8.2-LVA */ | ||
69 | @@ -XXX,XX +XXX,XX @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, | ||
70 | .tsz = tsz, | ||
71 | .select = select, | ||
72 | .tbi = tbi, | ||
73 | + .tbid = tbid, | ||
74 | .epd = epd, | ||
75 | .hpd = hpd, | ||
76 | .using16k = using16k, | ||
77 | @@ -XXX,XX +XXX,XX @@ ARMVAParameters aa64_va_parameters_both(CPUARMState *env, uint64_t va, | ||
78 | ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, | ||
79 | ARMMMUIdx mmu_idx, bool data) | ||
80 | { | ||
81 | - return aa64_va_parameters_both(env, va, mmu_idx); | ||
82 | + ARMVAParameters ret = aa64_va_parameters_both(env, va, mmu_idx); | ||
83 | + | ||
84 | + /* Present TBI as a composite with TBID. */ | ||
85 | + ret.tbi &= (data || !ret.tbid); | ||
86 | + return ret; | ||
87 | } | ||
88 | |||
89 | static ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, | ||
90 | -- | ||
91 | 2.20.1 | ||
92 | |||
93 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | The arm_regime_tbi{0,1} functions are replacable with the new function | ||
4 | by giving the lowest and highest address. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20190108223129.5570-24-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | target/arm/cpu.h | 35 ----------------------- | ||
12 | target/arm/helper.c | 70 ++++++++++++++++----------------------------- | ||
13 | 2 files changed, 24 insertions(+), 81 deletions(-) | ||
14 | |||
15 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/arm/cpu.h | ||
18 | +++ b/target/arm/cpu.h | ||
19 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_cpu_bswap_data(CPUARMState *env) | ||
20 | } | ||
21 | #endif | ||
22 | |||
23 | -#ifndef CONFIG_USER_ONLY | ||
24 | -/** | ||
25 | - * arm_regime_tbi0: | ||
26 | - * @env: CPUARMState | ||
27 | - * @mmu_idx: MMU index indicating required translation regime | ||
28 | - * | ||
29 | - * Extracts the TBI0 value from the appropriate TCR for the current EL | ||
30 | - * | ||
31 | - * Returns: the TBI0 value. | ||
32 | - */ | ||
33 | -uint32_t arm_regime_tbi0(CPUARMState *env, ARMMMUIdx mmu_idx); | ||
34 | - | ||
35 | -/** | ||
36 | - * arm_regime_tbi1: | ||
37 | - * @env: CPUARMState | ||
38 | - * @mmu_idx: MMU index indicating required translation regime | ||
39 | - * | ||
40 | - * Extracts the TBI1 value from the appropriate TCR for the current EL | ||
41 | - * | ||
42 | - * Returns: the TBI1 value. | ||
43 | - */ | ||
44 | -uint32_t arm_regime_tbi1(CPUARMState *env, ARMMMUIdx mmu_idx); | ||
45 | -#else | ||
46 | -/* We can't handle tagged addresses properly in user-only mode */ | ||
47 | -static inline uint32_t arm_regime_tbi0(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
48 | -{ | ||
49 | - return 0; | ||
50 | -} | ||
51 | - | ||
52 | -static inline uint32_t arm_regime_tbi1(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
53 | -{ | ||
54 | - return 0; | ||
55 | -} | ||
56 | -#endif | ||
57 | - | ||
58 | void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
59 | target_ulong *cs_base, uint32_t *flags); | ||
60 | |||
61 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
62 | index XXXXXXX..XXXXXXX 100644 | ||
63 | --- a/target/arm/helper.c | ||
64 | +++ b/target/arm/helper.c | ||
65 | @@ -XXX,XX +XXX,XX @@ static inline ARMMMUIdx stage_1_mmu_idx(ARMMMUIdx mmu_idx) | ||
66 | return mmu_idx; | ||
67 | } | ||
68 | |||
69 | -/* Returns TBI0 value for current regime el */ | ||
70 | -uint32_t arm_regime_tbi0(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
71 | -{ | ||
72 | - TCR *tcr; | ||
73 | - uint32_t el; | ||
74 | - | ||
75 | - /* For EL0 and EL1, TBI is controlled by stage 1's TCR, so convert | ||
76 | - * a stage 1+2 mmu index into the appropriate stage 1 mmu index. | ||
77 | - */ | ||
78 | - mmu_idx = stage_1_mmu_idx(mmu_idx); | ||
79 | - | ||
80 | - tcr = regime_tcr(env, mmu_idx); | ||
81 | - el = regime_el(env, mmu_idx); | ||
82 | - | ||
83 | - if (el > 1) { | ||
84 | - return extract64(tcr->raw_tcr, 20, 1); | ||
85 | - } else { | ||
86 | - return extract64(tcr->raw_tcr, 37, 1); | ||
87 | - } | ||
88 | -} | ||
89 | - | ||
90 | -/* Returns TBI1 value for current regime el */ | ||
91 | -uint32_t arm_regime_tbi1(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
92 | -{ | ||
93 | - TCR *tcr; | ||
94 | - uint32_t el; | ||
95 | - | ||
96 | - /* For EL0 and EL1, TBI is controlled by stage 1's TCR, so convert | ||
97 | - * a stage 1+2 mmu index into the appropriate stage 1 mmu index. | ||
98 | - */ | ||
99 | - mmu_idx = stage_1_mmu_idx(mmu_idx); | ||
100 | - | ||
101 | - tcr = regime_tcr(env, mmu_idx); | ||
102 | - el = regime_el(env, mmu_idx); | ||
103 | - | ||
104 | - if (el > 1) { | ||
105 | - return 0; | ||
106 | - } else { | ||
107 | - return extract64(tcr->raw_tcr, 38, 1); | ||
108 | - } | ||
109 | -} | ||
110 | - | ||
111 | /* Return the TTBR associated with this translation regime */ | ||
112 | static inline uint64_t regime_ttbr(CPUARMState *env, ARMMMUIdx mmu_idx, | ||
113 | int ttbrn) | ||
114 | @@ -XXX,XX +XXX,XX @@ void cpu_get_tb_cpu_state(CPUARMState *env, target_ulong *pc, | ||
115 | |||
116 | *pc = env->pc; | ||
117 | flags = FIELD_DP32(flags, TBFLAG_ANY, AARCH64_STATE, 1); | ||
118 | - /* Get control bits for tagged addresses */ | ||
119 | - flags = FIELD_DP32(flags, TBFLAG_A64, TBII, | ||
120 | - (arm_regime_tbi1(env, mmu_idx) << 1) | | ||
121 | - arm_regime_tbi0(env, mmu_idx)); | ||
122 | + | ||
123 | +#ifndef CONFIG_USER_ONLY | ||
124 | + /* | ||
125 | + * Get control bits for tagged addresses. Note that the | ||
126 | + * translator only uses this for instruction addresses. | ||
127 | + */ | ||
128 | + { | ||
129 | + ARMMMUIdx stage1 = stage_1_mmu_idx(mmu_idx); | ||
130 | + ARMVAParameters p0 = aa64_va_parameters_both(env, 0, stage1); | ||
131 | + int tbii, tbid; | ||
132 | + | ||
133 | + /* FIXME: ARMv8.1-VHE S2 translation regime. */ | ||
134 | + if (regime_el(env, stage1) < 2) { | ||
135 | + ARMVAParameters p1 = aa64_va_parameters_both(env, -1, stage1); | ||
136 | + tbid = (p1.tbi << 1) | p0.tbi; | ||
137 | + tbii = tbid & ~((p1.tbid << 1) | p0.tbid); | ||
138 | + } else { | ||
139 | + tbid = p0.tbi; | ||
140 | + tbii = tbid & !p0.tbid; | ||
141 | + } | ||
142 | + | ||
143 | + flags = FIELD_DP32(flags, TBFLAG_A64, TBII, tbii); | ||
144 | + } | ||
145 | +#endif | ||
146 | |||
147 | if (cpu_isar_feature(aa64_sve, cpu)) { | ||
148 | int sve_el = sve_exception_el(env, current_el); | ||
149 | -- | ||
150 | 2.20.1 | ||
151 | |||
152 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | Stripping out the authentication data does not require any crypto, | ||
4 | it merely requires the virtual address parameters. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20190108223129.5570-25-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | target/arm/pauth_helper.c | 14 +++++++++++++- | ||
12 | 1 file changed, 13 insertions(+), 1 deletion(-) | ||
13 | |||
14 | diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/target/arm/pauth_helper.c | ||
17 | +++ b/target/arm/pauth_helper.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, | ||
19 | g_assert_not_reached(); /* FIXME */ | ||
20 | } | ||
21 | |||
22 | +static uint64_t pauth_original_ptr(uint64_t ptr, ARMVAParameters param) | ||
23 | +{ | ||
24 | + uint64_t extfield = -param.select; | ||
25 | + int bot_pac_bit = 64 - param.tsz; | ||
26 | + int top_pac_bit = 64 - 8 * param.tbi; | ||
27 | + | ||
28 | + return deposit64(ptr, bot_pac_bit, top_pac_bit - bot_pac_bit, extfield); | ||
29 | +} | ||
30 | + | ||
31 | static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifier, | ||
32 | ARMPACKey *key, bool data, int keynumber) | ||
33 | { | ||
34 | @@ -XXX,XX +XXX,XX @@ static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifier, | ||
35 | |||
36 | static uint64_t pauth_strip(CPUARMState *env, uint64_t ptr, bool data) | ||
37 | { | ||
38 | - g_assert_not_reached(); /* FIXME */ | ||
39 | + ARMMMUIdx mmu_idx = arm_stage1_mmu_idx(env); | ||
40 | + ARMVAParameters param = aa64_va_parameters(env, ptr, mmu_idx, data); | ||
41 | + | ||
42 | + return pauth_original_ptr(ptr, param); | ||
43 | } | ||
44 | |||
45 | static void QEMU_NORETURN pauth_trap(CPUARMState *env, int target_el, | ||
46 | -- | ||
47 | 2.20.1 | ||
48 | |||
49 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | This is not really functional yet, because the crypto is not yet | ||
4 | implemented. This, however follows the Auth pseudo function. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20190108223129.5570-26-richard.henderson@linaro.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | target/arm/pauth_helper.c | 21 ++++++++++++++++++++- | ||
12 | 1 file changed, 20 insertions(+), 1 deletion(-) | ||
13 | |||
14 | diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/target/arm/pauth_helper.c | ||
17 | +++ b/target/arm/pauth_helper.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static uint64_t pauth_original_ptr(uint64_t ptr, ARMVAParameters param) | ||
19 | static uint64_t pauth_auth(CPUARMState *env, uint64_t ptr, uint64_t modifier, | ||
20 | ARMPACKey *key, bool data, int keynumber) | ||
21 | { | ||
22 | - g_assert_not_reached(); /* FIXME */ | ||
23 | + ARMMMUIdx mmu_idx = arm_stage1_mmu_idx(env); | ||
24 | + ARMVAParameters param = aa64_va_parameters(env, ptr, mmu_idx, data); | ||
25 | + int bot_bit, top_bit; | ||
26 | + uint64_t pac, orig_ptr, test; | ||
27 | + | ||
28 | + orig_ptr = pauth_original_ptr(ptr, param); | ||
29 | + pac = pauth_computepac(orig_ptr, modifier, *key); | ||
30 | + bot_bit = 64 - param.tsz; | ||
31 | + top_bit = 64 - 8 * param.tbi; | ||
32 | + | ||
33 | + test = (pac ^ ptr) & ~MAKE_64BIT_MASK(55, 1); | ||
34 | + if (unlikely(extract64(test, bot_bit, top_bit - bot_bit))) { | ||
35 | + int error_code = (keynumber << 1) | (keynumber ^ 1); | ||
36 | + if (param.tbi) { | ||
37 | + return deposit64(ptr, 53, 2, error_code); | ||
38 | + } else { | ||
39 | + return deposit64(ptr, 61, 2, error_code); | ||
40 | + } | ||
41 | + } | ||
42 | + return orig_ptr; | ||
43 | } | ||
44 | |||
45 | static uint64_t pauth_strip(CPUARMState *env, uint64_t ptr, bool data) | ||
46 | -- | ||
47 | 2.20.1 | ||
48 | |||
49 | diff view generated by jsdifflib |
1 | Convert the VQSHLU and QVSHL 2-reg-shift insns to decodetree. | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | These are the last of the simple shift-by-immediate insns. | ||
3 | 2 | ||
3 | This is not really functional yet, because the crypto is not yet | ||
4 | implemented. This, however follows the AddPAC pseudo function. | ||
5 | |||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20190108223129.5570-27-richard.henderson@linaro.org | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200522145520.6778-5-peter.maydell@linaro.org | ||
7 | --- | 10 | --- |
8 | target/arm/neon-dp.decode | 15 +++++ | 11 | target/arm/pauth_helper.c | 42 ++++++++++++++++++++++++++++++++++++++- |
9 | target/arm/translate-neon.inc.c | 108 +++++++++++++++++++++++++++++++ | 12 | 1 file changed, 41 insertions(+), 1 deletion(-) |
10 | target/arm/translate.c | 110 +------------------------------- | ||
11 | 3 files changed, 126 insertions(+), 107 deletions(-) | ||
12 | 13 | ||
13 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | 14 | diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/neon-dp.decode | 16 | --- a/target/arm/pauth_helper.c |
16 | +++ b/target/arm/neon-dp.decode | 17 | +++ b/target/arm/pauth_helper.c |
17 | @@ -XXX,XX +XXX,XX @@ VSLI_2sh 1111 001 1 1 . ...... .... 0101 . . . 1 .... @2reg_shl_d | 18 | @@ -XXX,XX +XXX,XX @@ static uint64_t pauth_computepac(uint64_t data, uint64_t modifier, |
18 | VSLI_2sh 1111 001 1 1 . ...... .... 0101 . . . 1 .... @2reg_shl_s | 19 | static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, |
19 | VSLI_2sh 1111 001 1 1 . ...... .... 0101 . . . 1 .... @2reg_shl_h | 20 | ARMPACKey *key, bool data) |
20 | VSLI_2sh 1111 001 1 1 . ...... .... 0101 . . . 1 .... @2reg_shl_b | 21 | { |
22 | - g_assert_not_reached(); /* FIXME */ | ||
23 | + ARMMMUIdx mmu_idx = arm_stage1_mmu_idx(env); | ||
24 | + ARMVAParameters param = aa64_va_parameters(env, ptr, mmu_idx, data); | ||
25 | + uint64_t pac, ext_ptr, ext, test; | ||
26 | + int bot_bit, top_bit; | ||
21 | + | 27 | + |
22 | +VQSHLU_64_2sh 1111 001 1 1 . ...... .... 0110 . . . 1 .... @2reg_shl_d | 28 | + /* If tagged pointers are in use, use ptr<55>, otherwise ptr<63>. */ |
23 | +VQSHLU_2sh 1111 001 1 1 . ...... .... 0110 . . . 1 .... @2reg_shl_s | 29 | + if (param.tbi) { |
24 | +VQSHLU_2sh 1111 001 1 1 . ...... .... 0110 . . . 1 .... @2reg_shl_h | 30 | + ext = sextract64(ptr, 55, 1); |
25 | +VQSHLU_2sh 1111 001 1 1 . ...... .... 0110 . . . 1 .... @2reg_shl_b | 31 | + } else { |
26 | + | 32 | + ext = sextract64(ptr, 63, 1); |
27 | +VQSHL_S_64_2sh 1111 001 0 1 . ...... .... 0111 . . . 1 .... @2reg_shl_d | ||
28 | +VQSHL_S_2sh 1111 001 0 1 . ...... .... 0111 . . . 1 .... @2reg_shl_s | ||
29 | +VQSHL_S_2sh 1111 001 0 1 . ...... .... 0111 . . . 1 .... @2reg_shl_h | ||
30 | +VQSHL_S_2sh 1111 001 0 1 . ...... .... 0111 . . . 1 .... @2reg_shl_b | ||
31 | + | ||
32 | +VQSHL_U_64_2sh 1111 001 1 1 . ...... .... 0111 . . . 1 .... @2reg_shl_d | ||
33 | +VQSHL_U_2sh 1111 001 1 1 . ...... .... 0111 . . . 1 .... @2reg_shl_s | ||
34 | +VQSHL_U_2sh 1111 001 1 1 . ...... .... 0111 . . . 1 .... @2reg_shl_h | ||
35 | +VQSHL_U_2sh 1111 001 1 1 . ...... .... 0111 . . . 1 .... @2reg_shl_b | ||
36 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/target/arm/translate-neon.inc.c | ||
39 | +++ b/target/arm/translate-neon.inc.c | ||
40 | @@ -XXX,XX +XXX,XX @@ static bool trans_VSHR_U_2sh(DisasContext *s, arg_2reg_shift *a) | ||
41 | return do_vector_2sh(s, a, tcg_gen_gvec_shri); | ||
42 | } | ||
43 | } | ||
44 | + | ||
45 | +static bool do_2shift_env_64(DisasContext *s, arg_2reg_shift *a, | ||
46 | + NeonGenTwo64OpEnvFn *fn) | ||
47 | +{ | ||
48 | + /* | ||
49 | + * 2-reg-and-shift operations, size == 3 case, where the | ||
50 | + * function needs to be passed cpu_env. | ||
51 | + */ | ||
52 | + TCGv_i64 constimm; | ||
53 | + int pass; | ||
54 | + | ||
55 | + if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | ||
56 | + return false; | ||
57 | + } | 33 | + } |
58 | + | 34 | + |
59 | + /* UNDEF accesses to D16-D31 if they don't exist. */ | 35 | + /* Build a pointer with known good extension bits. */ |
60 | + if (!dc_isar_feature(aa32_simd_r32, s) && | 36 | + top_bit = 64 - 8 * param.tbi; |
61 | + ((a->vd | a->vm) & 0x10)) { | 37 | + bot_bit = 64 - param.tsz; |
62 | + return false; | 38 | + ext_ptr = deposit64(ptr, bot_bit, top_bit - bot_bit, ext); |
63 | + } | ||
64 | + | 39 | + |
65 | + if ((a->vm | a->vd) & a->q) { | 40 | + pac = pauth_computepac(ext_ptr, modifier, *key); |
66 | + return false; | ||
67 | + } | ||
68 | + | 41 | + |
69 | + if (!vfp_access_check(s)) { | 42 | + /* |
70 | + return true; | 43 | + * Check if the ptr has good extension bits and corrupt the |
44 | + * pointer authentication code if not. | ||
45 | + */ | ||
46 | + test = sextract64(ptr, bot_bit, top_bit - bot_bit); | ||
47 | + if (test != 0 && test != -1) { | ||
48 | + pac ^= MAKE_64BIT_MASK(top_bit - 1, 1); | ||
71 | + } | 49 | + } |
72 | + | 50 | + |
73 | + /* | 51 | + /* |
74 | + * To avoid excessive duplication of ops we implement shift | 52 | + * Preserve the determination between upper and lower at bit 55, |
75 | + * by immediate using the variable shift operations. | 53 | + * and insert pointer authentication code. |
76 | + */ | 54 | + */ |
77 | + constimm = tcg_const_i64(dup_const(a->size, a->shift)); | 55 | + if (param.tbi) { |
78 | + | 56 | + ptr &= ~MAKE_64BIT_MASK(bot_bit, 55 - bot_bit + 1); |
79 | + for (pass = 0; pass < a->q + 1; pass++) { | 57 | + pac &= MAKE_64BIT_MASK(bot_bit, 54 - bot_bit + 1); |
80 | + TCGv_i64 tmp = tcg_temp_new_i64(); | 58 | + } else { |
81 | + | 59 | + ptr &= MAKE_64BIT_MASK(0, bot_bit); |
82 | + neon_load_reg64(tmp, a->vm + pass); | 60 | + pac &= ~(MAKE_64BIT_MASK(55, 1) | MAKE_64BIT_MASK(0, bot_bit)); |
83 | + fn(tmp, cpu_env, tmp, constimm); | ||
84 | + neon_store_reg64(tmp, a->vd + pass); | ||
85 | + } | 61 | + } |
86 | + tcg_temp_free_i64(constimm); | 62 | + ext &= MAKE_64BIT_MASK(55, 1); |
87 | + return true; | 63 | + return pac | ext | ptr; |
88 | +} | ||
89 | + | ||
90 | +static bool do_2shift_env_32(DisasContext *s, arg_2reg_shift *a, | ||
91 | + NeonGenTwoOpEnvFn *fn) | ||
92 | +{ | ||
93 | + /* | ||
94 | + * 2-reg-and-shift operations, size < 3 case, where the | ||
95 | + * helper needs to be passed cpu_env. | ||
96 | + */ | ||
97 | + TCGv_i32 constimm; | ||
98 | + int pass; | ||
99 | + | ||
100 | + if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | ||
101 | + return false; | ||
102 | + } | ||
103 | + | ||
104 | + /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
105 | + if (!dc_isar_feature(aa32_simd_r32, s) && | ||
106 | + ((a->vd | a->vm) & 0x10)) { | ||
107 | + return false; | ||
108 | + } | ||
109 | + | ||
110 | + if ((a->vm | a->vd) & a->q) { | ||
111 | + return false; | ||
112 | + } | ||
113 | + | ||
114 | + if (!vfp_access_check(s)) { | ||
115 | + return true; | ||
116 | + } | ||
117 | + | ||
118 | + /* | ||
119 | + * To avoid excessive duplication of ops we implement shift | ||
120 | + * by immediate using the variable shift operations. | ||
121 | + */ | ||
122 | + constimm = tcg_const_i32(dup_const(a->size, a->shift)); | ||
123 | + | ||
124 | + for (pass = 0; pass < (a->q ? 4 : 2); pass++) { | ||
125 | + TCGv_i32 tmp = neon_load_reg(a->vm, pass); | ||
126 | + fn(tmp, cpu_env, tmp, constimm); | ||
127 | + neon_store_reg(a->vd, pass, tmp); | ||
128 | + } | ||
129 | + tcg_temp_free_i32(constimm); | ||
130 | + return true; | ||
131 | +} | ||
132 | + | ||
133 | +#define DO_2SHIFT_ENV(INSN, FUNC) \ | ||
134 | + static bool trans_##INSN##_64_2sh(DisasContext *s, arg_2reg_shift *a) \ | ||
135 | + { \ | ||
136 | + return do_2shift_env_64(s, a, gen_helper_neon_##FUNC##64); \ | ||
137 | + } \ | ||
138 | + static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \ | ||
139 | + { \ | ||
140 | + static NeonGenTwoOpEnvFn * const fns[] = { \ | ||
141 | + gen_helper_neon_##FUNC##8, \ | ||
142 | + gen_helper_neon_##FUNC##16, \ | ||
143 | + gen_helper_neon_##FUNC##32, \ | ||
144 | + }; \ | ||
145 | + assert(a->size < ARRAY_SIZE(fns)); \ | ||
146 | + return do_2shift_env_32(s, a, fns[a->size]); \ | ||
147 | + } | ||
148 | + | ||
149 | +DO_2SHIFT_ENV(VQSHLU, qshlu_s) | ||
150 | +DO_2SHIFT_ENV(VQSHL_U, qshl_u) | ||
151 | +DO_2SHIFT_ENV(VQSHL_S, qshl_s) | ||
152 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
153 | index XXXXXXX..XXXXXXX 100644 | ||
154 | --- a/target/arm/translate.c | ||
155 | +++ b/target/arm/translate.c | ||
156 | @@ -XXX,XX +XXX,XX @@ static inline void gen_neon_rsb(int size, TCGv_i32 t0, TCGv_i32 t1) | ||
157 | } | ||
158 | } | 64 | } |
159 | 65 | ||
160 | -#define GEN_NEON_INTEGER_OP_ENV(name) do { \ | 66 | static uint64_t pauth_original_ptr(uint64_t ptr, ARMVAParameters param) |
161 | - switch ((size << 1) | u) { \ | ||
162 | - case 0: \ | ||
163 | - gen_helper_neon_##name##_s8(tmp, cpu_env, tmp, tmp2); \ | ||
164 | - break; \ | ||
165 | - case 1: \ | ||
166 | - gen_helper_neon_##name##_u8(tmp, cpu_env, tmp, tmp2); \ | ||
167 | - break; \ | ||
168 | - case 2: \ | ||
169 | - gen_helper_neon_##name##_s16(tmp, cpu_env, tmp, tmp2); \ | ||
170 | - break; \ | ||
171 | - case 3: \ | ||
172 | - gen_helper_neon_##name##_u16(tmp, cpu_env, tmp, tmp2); \ | ||
173 | - break; \ | ||
174 | - case 4: \ | ||
175 | - gen_helper_neon_##name##_s32(tmp, cpu_env, tmp, tmp2); \ | ||
176 | - break; \ | ||
177 | - case 5: \ | ||
178 | - gen_helper_neon_##name##_u32(tmp, cpu_env, tmp, tmp2); \ | ||
179 | - break; \ | ||
180 | - default: return 1; \ | ||
181 | - }} while (0) | ||
182 | - | ||
183 | static TCGv_i32 neon_load_scratch(int scratch) | ||
184 | { | ||
185 | TCGv_i32 tmp = tcg_temp_new_i32(); | ||
186 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
187 | int size; | ||
188 | int shift; | ||
189 | int pass; | ||
190 | - int count; | ||
191 | int u; | ||
192 | int vec_size; | ||
193 | uint32_t imm; | ||
194 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
195 | case 3: /* VRSRA */ | ||
196 | case 4: /* VSRI */ | ||
197 | case 5: /* VSHL, VSLI */ | ||
198 | + case 6: /* VQSHLU */ | ||
199 | + case 7: /* VQSHL */ | ||
200 | return 1; /* handled by decodetree */ | ||
201 | default: | ||
202 | break; | ||
203 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
204 | size--; | ||
205 | } | ||
206 | shift = (insn >> 16) & ((1 << (3 + size)) - 1); | ||
207 | - if (op < 8) { | ||
208 | - /* Shift by immediate: | ||
209 | - VSHR, VSRA, VRSHR, VRSRA, VSRI, VSHL, VQSHL, VQSHLU. */ | ||
210 | - if (q && ((rd | rm) & 1)) { | ||
211 | - return 1; | ||
212 | - } | ||
213 | - if (!u && (op == 4 || op == 6)) { | ||
214 | - return 1; | ||
215 | - } | ||
216 | - /* Right shifts are encoded as N - shift, where N is the | ||
217 | - element size in bits. */ | ||
218 | - if (op <= 4) { | ||
219 | - shift = shift - (1 << (size + 3)); | ||
220 | - } | ||
221 | - | ||
222 | - if (size == 3) { | ||
223 | - count = q + 1; | ||
224 | - } else { | ||
225 | - count = q ? 4: 2; | ||
226 | - } | ||
227 | - | ||
228 | - /* To avoid excessive duplication of ops we implement shift | ||
229 | - * by immediate using the variable shift operations. | ||
230 | - */ | ||
231 | - imm = dup_const(size, shift); | ||
232 | - | ||
233 | - for (pass = 0; pass < count; pass++) { | ||
234 | - if (size == 3) { | ||
235 | - neon_load_reg64(cpu_V0, rm + pass); | ||
236 | - tcg_gen_movi_i64(cpu_V1, imm); | ||
237 | - switch (op) { | ||
238 | - case 6: /* VQSHLU */ | ||
239 | - gen_helper_neon_qshlu_s64(cpu_V0, cpu_env, | ||
240 | - cpu_V0, cpu_V1); | ||
241 | - break; | ||
242 | - case 7: /* VQSHL */ | ||
243 | - if (u) { | ||
244 | - gen_helper_neon_qshl_u64(cpu_V0, cpu_env, | ||
245 | - cpu_V0, cpu_V1); | ||
246 | - } else { | ||
247 | - gen_helper_neon_qshl_s64(cpu_V0, cpu_env, | ||
248 | - cpu_V0, cpu_V1); | ||
249 | - } | ||
250 | - break; | ||
251 | - default: | ||
252 | - g_assert_not_reached(); | ||
253 | - } | ||
254 | - neon_store_reg64(cpu_V0, rd + pass); | ||
255 | - } else { /* size < 3 */ | ||
256 | - /* Operands in T0 and T1. */ | ||
257 | - tmp = neon_load_reg(rm, pass); | ||
258 | - tmp2 = tcg_temp_new_i32(); | ||
259 | - tcg_gen_movi_i32(tmp2, imm); | ||
260 | - switch (op) { | ||
261 | - case 6: /* VQSHLU */ | ||
262 | - switch (size) { | ||
263 | - case 0: | ||
264 | - gen_helper_neon_qshlu_s8(tmp, cpu_env, | ||
265 | - tmp, tmp2); | ||
266 | - break; | ||
267 | - case 1: | ||
268 | - gen_helper_neon_qshlu_s16(tmp, cpu_env, | ||
269 | - tmp, tmp2); | ||
270 | - break; | ||
271 | - case 2: | ||
272 | - gen_helper_neon_qshlu_s32(tmp, cpu_env, | ||
273 | - tmp, tmp2); | ||
274 | - break; | ||
275 | - default: | ||
276 | - abort(); | ||
277 | - } | ||
278 | - break; | ||
279 | - case 7: /* VQSHL */ | ||
280 | - GEN_NEON_INTEGER_OP_ENV(qshl); | ||
281 | - break; | ||
282 | - default: | ||
283 | - g_assert_not_reached(); | ||
284 | - } | ||
285 | - tcg_temp_free_i32(tmp2); | ||
286 | - neon_store_reg(rd, pass, tmp); | ||
287 | - } | ||
288 | - } /* for pass */ | ||
289 | - } else if (op < 10) { | ||
290 | + if (op < 10) { | ||
291 | /* Shift by immediate and narrow: | ||
292 | VSHRN, VRSHRN, VQSHRN, VQRSHRN. */ | ||
293 | int input_unsigned = (op == 8) ? !u : u; | ||
294 | -- | 67 | -- |
295 | 2.20.1 | 68 | 2.20.1 |
296 | 69 | ||
297 | 70 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | 1 | From: Richard Henderson <richard.henderson@linaro.org> | |
2 | |||
3 | This is the main crypto routine, an implementation of QARMA. | ||
4 | This matches, as much as possible, ARM pseudocode. | ||
5 | |||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Message-id: 20190108223129.5570-28-richard.henderson@linaro.org | ||
9 | [PMM: fixed minor checkpatch nits] | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | --- | ||
12 | target/arm/pauth_helper.c | 242 +++++++++++++++++++++++++++++++++++++- | ||
13 | 1 file changed, 241 insertions(+), 1 deletion(-) | ||
14 | |||
15 | diff --git a/target/arm/pauth_helper.c b/target/arm/pauth_helper.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/target/arm/pauth_helper.c | ||
18 | +++ b/target/arm/pauth_helper.c | ||
19 | @@ -XXX,XX +XXX,XX @@ | ||
20 | #include "tcg/tcg-gvec-desc.h" | ||
21 | |||
22 | |||
23 | +static uint64_t pac_cell_shuffle(uint64_t i) | ||
24 | +{ | ||
25 | + uint64_t o = 0; | ||
26 | + | ||
27 | + o |= extract64(i, 52, 4); | ||
28 | + o |= extract64(i, 24, 4) << 4; | ||
29 | + o |= extract64(i, 44, 4) << 8; | ||
30 | + o |= extract64(i, 0, 4) << 12; | ||
31 | + | ||
32 | + o |= extract64(i, 28, 4) << 16; | ||
33 | + o |= extract64(i, 48, 4) << 20; | ||
34 | + o |= extract64(i, 4, 4) << 24; | ||
35 | + o |= extract64(i, 40, 4) << 28; | ||
36 | + | ||
37 | + o |= extract64(i, 32, 4) << 32; | ||
38 | + o |= extract64(i, 12, 4) << 36; | ||
39 | + o |= extract64(i, 56, 4) << 40; | ||
40 | + o |= extract64(i, 20, 4) << 44; | ||
41 | + | ||
42 | + o |= extract64(i, 8, 4) << 48; | ||
43 | + o |= extract64(i, 36, 4) << 52; | ||
44 | + o |= extract64(i, 16, 4) << 56; | ||
45 | + o |= extract64(i, 60, 4) << 60; | ||
46 | + | ||
47 | + return o; | ||
48 | +} | ||
49 | + | ||
50 | +static uint64_t pac_cell_inv_shuffle(uint64_t i) | ||
51 | +{ | ||
52 | + uint64_t o = 0; | ||
53 | + | ||
54 | + o |= extract64(i, 12, 4); | ||
55 | + o |= extract64(i, 24, 4) << 4; | ||
56 | + o |= extract64(i, 48, 4) << 8; | ||
57 | + o |= extract64(i, 36, 4) << 12; | ||
58 | + | ||
59 | + o |= extract64(i, 56, 4) << 16; | ||
60 | + o |= extract64(i, 44, 4) << 20; | ||
61 | + o |= extract64(i, 4, 4) << 24; | ||
62 | + o |= extract64(i, 16, 4) << 28; | ||
63 | + | ||
64 | + o |= i & MAKE_64BIT_MASK(32, 4); | ||
65 | + o |= extract64(i, 52, 4) << 36; | ||
66 | + o |= extract64(i, 28, 4) << 40; | ||
67 | + o |= extract64(i, 8, 4) << 44; | ||
68 | + | ||
69 | + o |= extract64(i, 20, 4) << 48; | ||
70 | + o |= extract64(i, 0, 4) << 52; | ||
71 | + o |= extract64(i, 40, 4) << 56; | ||
72 | + o |= i & MAKE_64BIT_MASK(60, 4); | ||
73 | + | ||
74 | + return o; | ||
75 | +} | ||
76 | + | ||
77 | +static uint64_t pac_sub(uint64_t i) | ||
78 | +{ | ||
79 | + static const uint8_t sub[16] = { | ||
80 | + 0xb, 0x6, 0x8, 0xf, 0xc, 0x0, 0x9, 0xe, | ||
81 | + 0x3, 0x7, 0x4, 0x5, 0xd, 0x2, 0x1, 0xa, | ||
82 | + }; | ||
83 | + uint64_t o = 0; | ||
84 | + int b; | ||
85 | + | ||
86 | + for (b = 0; b < 64; b += 16) { | ||
87 | + o |= (uint64_t)sub[(i >> b) & 0xf] << b; | ||
88 | + } | ||
89 | + return o; | ||
90 | +} | ||
91 | + | ||
92 | +static uint64_t pac_inv_sub(uint64_t i) | ||
93 | +{ | ||
94 | + static const uint8_t inv_sub[16] = { | ||
95 | + 0x5, 0xe, 0xd, 0x8, 0xa, 0xb, 0x1, 0x9, | ||
96 | + 0x2, 0x6, 0xf, 0x0, 0x4, 0xc, 0x7, 0x3, | ||
97 | + }; | ||
98 | + uint64_t o = 0; | ||
99 | + int b; | ||
100 | + | ||
101 | + for (b = 0; b < 64; b += 16) { | ||
102 | + o |= (uint64_t)inv_sub[(i >> b) & 0xf] << b; | ||
103 | + } | ||
104 | + return o; | ||
105 | +} | ||
106 | + | ||
107 | +static int rot_cell(int cell, int n) | ||
108 | +{ | ||
109 | + /* 4-bit rotate left by n. */ | ||
110 | + cell |= cell << 4; | ||
111 | + return extract32(cell, 4 - n, 4); | ||
112 | +} | ||
113 | + | ||
114 | +static uint64_t pac_mult(uint64_t i) | ||
115 | +{ | ||
116 | + uint64_t o = 0; | ||
117 | + int b; | ||
118 | + | ||
119 | + for (b = 0; b < 4 * 4; b += 4) { | ||
120 | + int i0, i4, i8, ic, t0, t1, t2, t3; | ||
121 | + | ||
122 | + i0 = extract64(i, b, 4); | ||
123 | + i4 = extract64(i, b + 4 * 4, 4); | ||
124 | + i8 = extract64(i, b + 8 * 4, 4); | ||
125 | + ic = extract64(i, b + 12 * 4, 4); | ||
126 | + | ||
127 | + t0 = rot_cell(i8, 1) ^ rot_cell(i4, 2) ^ rot_cell(i0, 1); | ||
128 | + t1 = rot_cell(ic, 1) ^ rot_cell(i4, 1) ^ rot_cell(i0, 2); | ||
129 | + t2 = rot_cell(ic, 2) ^ rot_cell(i8, 1) ^ rot_cell(i0, 1); | ||
130 | + t3 = rot_cell(ic, 1) ^ rot_cell(i8, 2) ^ rot_cell(i4, 1); | ||
131 | + | ||
132 | + o |= (uint64_t)t3 << b; | ||
133 | + o |= (uint64_t)t2 << (b + 4 * 4); | ||
134 | + o |= (uint64_t)t1 << (b + 8 * 4); | ||
135 | + o |= (uint64_t)t0 << (b + 12 * 4); | ||
136 | + } | ||
137 | + return o; | ||
138 | +} | ||
139 | + | ||
140 | +static uint64_t tweak_cell_rot(uint64_t cell) | ||
141 | +{ | ||
142 | + return (cell >> 1) | (((cell ^ (cell >> 1)) & 1) << 3); | ||
143 | +} | ||
144 | + | ||
145 | +static uint64_t tweak_shuffle(uint64_t i) | ||
146 | +{ | ||
147 | + uint64_t o = 0; | ||
148 | + | ||
149 | + o |= extract64(i, 16, 4) << 0; | ||
150 | + o |= extract64(i, 20, 4) << 4; | ||
151 | + o |= tweak_cell_rot(extract64(i, 24, 4)) << 8; | ||
152 | + o |= extract64(i, 28, 4) << 12; | ||
153 | + | ||
154 | + o |= tweak_cell_rot(extract64(i, 44, 4)) << 16; | ||
155 | + o |= extract64(i, 8, 4) << 20; | ||
156 | + o |= extract64(i, 12, 4) << 24; | ||
157 | + o |= tweak_cell_rot(extract64(i, 32, 4)) << 28; | ||
158 | + | ||
159 | + o |= extract64(i, 48, 4) << 32; | ||
160 | + o |= extract64(i, 52, 4) << 36; | ||
161 | + o |= extract64(i, 56, 4) << 40; | ||
162 | + o |= tweak_cell_rot(extract64(i, 60, 4)) << 44; | ||
163 | + | ||
164 | + o |= tweak_cell_rot(extract64(i, 0, 4)) << 48; | ||
165 | + o |= extract64(i, 4, 4) << 52; | ||
166 | + o |= tweak_cell_rot(extract64(i, 40, 4)) << 56; | ||
167 | + o |= tweak_cell_rot(extract64(i, 36, 4)) << 60; | ||
168 | + | ||
169 | + return o; | ||
170 | +} | ||
171 | + | ||
172 | +static uint64_t tweak_cell_inv_rot(uint64_t cell) | ||
173 | +{ | ||
174 | + return ((cell << 1) & 0xf) | ((cell & 1) ^ (cell >> 3)); | ||
175 | +} | ||
176 | + | ||
177 | +static uint64_t tweak_inv_shuffle(uint64_t i) | ||
178 | +{ | ||
179 | + uint64_t o = 0; | ||
180 | + | ||
181 | + o |= tweak_cell_inv_rot(extract64(i, 48, 4)); | ||
182 | + o |= extract64(i, 52, 4) << 4; | ||
183 | + o |= extract64(i, 20, 4) << 8; | ||
184 | + o |= extract64(i, 24, 4) << 12; | ||
185 | + | ||
186 | + o |= extract64(i, 0, 4) << 16; | ||
187 | + o |= extract64(i, 4, 4) << 20; | ||
188 | + o |= tweak_cell_inv_rot(extract64(i, 8, 4)) << 24; | ||
189 | + o |= extract64(i, 12, 4) << 28; | ||
190 | + | ||
191 | + o |= tweak_cell_inv_rot(extract64(i, 28, 4)) << 32; | ||
192 | + o |= tweak_cell_inv_rot(extract64(i, 60, 4)) << 36; | ||
193 | + o |= tweak_cell_inv_rot(extract64(i, 56, 4)) << 40; | ||
194 | + o |= tweak_cell_inv_rot(extract64(i, 16, 4)) << 44; | ||
195 | + | ||
196 | + o |= extract64(i, 32, 4) << 48; | ||
197 | + o |= extract64(i, 36, 4) << 52; | ||
198 | + o |= extract64(i, 40, 4) << 56; | ||
199 | + o |= tweak_cell_inv_rot(extract64(i, 44, 4)) << 60; | ||
200 | + | ||
201 | + return o; | ||
202 | +} | ||
203 | + | ||
204 | static uint64_t pauth_computepac(uint64_t data, uint64_t modifier, | ||
205 | ARMPACKey key) | ||
206 | { | ||
207 | - g_assert_not_reached(); /* FIXME */ | ||
208 | + static const uint64_t RC[5] = { | ||
209 | + 0x0000000000000000ull, | ||
210 | + 0x13198A2E03707344ull, | ||
211 | + 0xA4093822299F31D0ull, | ||
212 | + 0x082EFA98EC4E6C89ull, | ||
213 | + 0x452821E638D01377ull, | ||
214 | + }; | ||
215 | + const uint64_t alpha = 0xC0AC29B7C97C50DDull; | ||
216 | + /* | ||
217 | + * Note that in the ARM pseudocode, key0 contains bits <127:64> | ||
218 | + * and key1 contains bits <63:0> of the 128-bit key. | ||
219 | + */ | ||
220 | + uint64_t key0 = key.hi, key1 = key.lo; | ||
221 | + uint64_t workingval, runningmod, roundkey, modk0; | ||
222 | + int i; | ||
223 | + | ||
224 | + modk0 = (key0 << 63) | ((key0 >> 1) ^ (key0 >> 63)); | ||
225 | + runningmod = modifier; | ||
226 | + workingval = data ^ key0; | ||
227 | + | ||
228 | + for (i = 0; i <= 4; ++i) { | ||
229 | + roundkey = key1 ^ runningmod; | ||
230 | + workingval ^= roundkey; | ||
231 | + workingval ^= RC[i]; | ||
232 | + if (i > 0) { | ||
233 | + workingval = pac_cell_shuffle(workingval); | ||
234 | + workingval = pac_mult(workingval); | ||
235 | + } | ||
236 | + workingval = pac_sub(workingval); | ||
237 | + runningmod = tweak_shuffle(runningmod); | ||
238 | + } | ||
239 | + roundkey = modk0 ^ runningmod; | ||
240 | + workingval ^= roundkey; | ||
241 | + workingval = pac_cell_shuffle(workingval); | ||
242 | + workingval = pac_mult(workingval); | ||
243 | + workingval = pac_sub(workingval); | ||
244 | + workingval = pac_cell_shuffle(workingval); | ||
245 | + workingval = pac_mult(workingval); | ||
246 | + workingval ^= key1; | ||
247 | + workingval = pac_cell_inv_shuffle(workingval); | ||
248 | + workingval = pac_inv_sub(workingval); | ||
249 | + workingval = pac_mult(workingval); | ||
250 | + workingval = pac_cell_inv_shuffle(workingval); | ||
251 | + workingval ^= key0; | ||
252 | + workingval ^= runningmod; | ||
253 | + for (i = 0; i <= 4; ++i) { | ||
254 | + workingval = pac_inv_sub(workingval); | ||
255 | + if (i < 4) { | ||
256 | + workingval = pac_mult(workingval); | ||
257 | + workingval = pac_cell_inv_shuffle(workingval); | ||
258 | + } | ||
259 | + runningmod = tweak_inv_shuffle(runningmod); | ||
260 | + roundkey = key1 ^ runningmod; | ||
261 | + workingval ^= RC[4 - i]; | ||
262 | + workingval ^= roundkey; | ||
263 | + workingval ^= alpha; | ||
264 | + } | ||
265 | + workingval ^= modk0; | ||
266 | + | ||
267 | + return workingval; | ||
268 | } | ||
269 | |||
270 | static uint64_t pauth_addpac(CPUARMState *env, uint64_t ptr, uint64_t modifier, | ||
271 | -- | ||
272 | 2.20.1 | ||
273 | |||
274 | diff view generated by jsdifflib |
New patch | |||
---|---|---|---|
1 | From: Richard Henderson <richard.henderson@linaro.org> | ||
1 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20190108223129.5570-29-richard.henderson@linaro.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | target/arm/helper.c | 70 +++++++++++++++++++++++++++++++++++++++++++++ | ||
9 | 1 file changed, 70 insertions(+) | ||
10 | |||
11 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/target/arm/helper.c | ||
14 | +++ b/target/arm/helper.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult access_lor_other(CPUARMState *env, | ||
16 | return access_lor_ns(env); | ||
17 | } | ||
18 | |||
19 | +#ifdef TARGET_AARCH64 | ||
20 | +static CPAccessResult access_pauth(CPUARMState *env, const ARMCPRegInfo *ri, | ||
21 | + bool isread) | ||
22 | +{ | ||
23 | + int el = arm_current_el(env); | ||
24 | + | ||
25 | + if (el < 2 && | ||
26 | + arm_feature(env, ARM_FEATURE_EL2) && | ||
27 | + !(arm_hcr_el2_eff(env) & HCR_APK)) { | ||
28 | + return CP_ACCESS_TRAP_EL2; | ||
29 | + } | ||
30 | + if (el < 3 && | ||
31 | + arm_feature(env, ARM_FEATURE_EL3) && | ||
32 | + !(env->cp15.scr_el3 & SCR_APK)) { | ||
33 | + return CP_ACCESS_TRAP_EL3; | ||
34 | + } | ||
35 | + return CP_ACCESS_OK; | ||
36 | +} | ||
37 | + | ||
38 | +static const ARMCPRegInfo pauth_reginfo[] = { | ||
39 | + { .name = "APDAKEYLO_EL1", .state = ARM_CP_STATE_AA64, | ||
40 | + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 0, | ||
41 | + .access = PL1_RW, .accessfn = access_pauth, | ||
42 | + .fieldoffset = offsetof(CPUARMState, apda_key.lo) }, | ||
43 | + { .name = "APDAKEYHI_EL1", .state = ARM_CP_STATE_AA64, | ||
44 | + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 1, | ||
45 | + .access = PL1_RW, .accessfn = access_pauth, | ||
46 | + .fieldoffset = offsetof(CPUARMState, apda_key.hi) }, | ||
47 | + { .name = "APDBKEYLO_EL1", .state = ARM_CP_STATE_AA64, | ||
48 | + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 2, | ||
49 | + .access = PL1_RW, .accessfn = access_pauth, | ||
50 | + .fieldoffset = offsetof(CPUARMState, apdb_key.lo) }, | ||
51 | + { .name = "APDBKEYHI_EL1", .state = ARM_CP_STATE_AA64, | ||
52 | + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 2, .opc2 = 3, | ||
53 | + .access = PL1_RW, .accessfn = access_pauth, | ||
54 | + .fieldoffset = offsetof(CPUARMState, apdb_key.hi) }, | ||
55 | + { .name = "APGAKEYLO_EL1", .state = ARM_CP_STATE_AA64, | ||
56 | + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 3, .opc2 = 0, | ||
57 | + .access = PL1_RW, .accessfn = access_pauth, | ||
58 | + .fieldoffset = offsetof(CPUARMState, apga_key.lo) }, | ||
59 | + { .name = "APGAKEYHI_EL1", .state = ARM_CP_STATE_AA64, | ||
60 | + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 3, .opc2 = 1, | ||
61 | + .access = PL1_RW, .accessfn = access_pauth, | ||
62 | + .fieldoffset = offsetof(CPUARMState, apga_key.hi) }, | ||
63 | + { .name = "APIAKEYLO_EL1", .state = ARM_CP_STATE_AA64, | ||
64 | + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 0, | ||
65 | + .access = PL1_RW, .accessfn = access_pauth, | ||
66 | + .fieldoffset = offsetof(CPUARMState, apia_key.lo) }, | ||
67 | + { .name = "APIAKEYHI_EL1", .state = ARM_CP_STATE_AA64, | ||
68 | + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 1, | ||
69 | + .access = PL1_RW, .accessfn = access_pauth, | ||
70 | + .fieldoffset = offsetof(CPUARMState, apia_key.hi) }, | ||
71 | + { .name = "APIBKEYLO_EL1", .state = ARM_CP_STATE_AA64, | ||
72 | + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 2, | ||
73 | + .access = PL1_RW, .accessfn = access_pauth, | ||
74 | + .fieldoffset = offsetof(CPUARMState, apib_key.lo) }, | ||
75 | + { .name = "APIBKEYHI_EL1", .state = ARM_CP_STATE_AA64, | ||
76 | + .opc0 = 3, .opc1 = 0, .crn = 2, .crm = 1, .opc2 = 3, | ||
77 | + .access = PL1_RW, .accessfn = access_pauth, | ||
78 | + .fieldoffset = offsetof(CPUARMState, apib_key.hi) }, | ||
79 | + REGINFO_SENTINEL | ||
80 | +}; | ||
81 | +#endif | ||
82 | + | ||
83 | void register_cp_regs_for_features(ARMCPU *cpu) | ||
84 | { | ||
85 | /* Register all the coprocessor registers based on feature bits */ | ||
86 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
87 | define_one_arm_cp_reg(cpu, &zcr_el3_reginfo); | ||
88 | } | ||
89 | } | ||
90 | + | ||
91 | +#ifdef TARGET_AARCH64 | ||
92 | + if (cpu_isar_feature(aa64_pauth, cpu)) { | ||
93 | + define_arm_cp_regs(cpu, pauth_reginfo); | ||
94 | + } | ||
95 | +#endif | ||
96 | } | ||
97 | |||
98 | void arm_cpu_register_gdb_regs_for_features(ARMCPU *cpu) | ||
99 | -- | ||
100 | 2.20.1 | ||
101 | |||
102 | diff view generated by jsdifflib |
1 | Convert the VSRA, VSRI, VRSHR, VRSRA 2-reg-shift insns to decodetree. | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | (These are the last instructions in the group that are vectorized; | ||
3 | the rest all require looping over each element.) | ||
4 | 2 | ||
3 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
4 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
5 | Message-id: 20190108223129.5570-30-richard.henderson@linaro.org | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20200522145520.6778-4-peter.maydell@linaro.org | ||
8 | --- | 7 | --- |
9 | target/arm/neon-dp.decode | 35 ++++++++++++++++++++++ | 8 | target/arm/cpu64.c | 4 ++++ |
10 | target/arm/translate-neon.inc.c | 7 +++++ | 9 | 1 file changed, 4 insertions(+) |
11 | target/arm/translate.c | 52 +++------------------------------ | ||
12 | 3 files changed, 46 insertions(+), 48 deletions(-) | ||
13 | 10 | ||
14 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | 11 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c |
15 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/target/arm/neon-dp.decode | 13 | --- a/target/arm/cpu64.c |
17 | +++ b/target/arm/neon-dp.decode | 14 | +++ b/target/arm/cpu64.c |
18 | @@ -XXX,XX +XXX,XX @@ VSHR_U_2sh 1111 001 1 1 . ...... .... 0000 . . . 1 .... @2reg_shr_s | 15 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) |
19 | VSHR_U_2sh 1111 001 1 1 . ...... .... 0000 . . . 1 .... @2reg_shr_h | 16 | |
20 | VSHR_U_2sh 1111 001 1 1 . ...... .... 0000 . . . 1 .... @2reg_shr_b | 17 | t = cpu->isar.id_aa64isar1; |
21 | 18 | t = FIELD_DP64(t, ID_AA64ISAR1, FCMA, 1); | |
22 | +VSRA_S_2sh 1111 001 0 1 . ...... .... 0001 . . . 1 .... @2reg_shr_d | 19 | + t = FIELD_DP64(t, ID_AA64ISAR1, APA, 1); /* PAuth, architected only */ |
23 | +VSRA_S_2sh 1111 001 0 1 . ...... .... 0001 . . . 1 .... @2reg_shr_s | 20 | + t = FIELD_DP64(t, ID_AA64ISAR1, API, 0); |
24 | +VSRA_S_2sh 1111 001 0 1 . ...... .... 0001 . . . 1 .... @2reg_shr_h | 21 | + t = FIELD_DP64(t, ID_AA64ISAR1, GPA, 1); |
25 | +VSRA_S_2sh 1111 001 0 1 . ...... .... 0001 . . . 1 .... @2reg_shr_b | 22 | + t = FIELD_DP64(t, ID_AA64ISAR1, GPI, 0); |
26 | + | 23 | cpu->isar.id_aa64isar1 = t; |
27 | +VSRA_U_2sh 1111 001 1 1 . ...... .... 0001 . . . 1 .... @2reg_shr_d | 24 | |
28 | +VSRA_U_2sh 1111 001 1 1 . ...... .... 0001 . . . 1 .... @2reg_shr_s | 25 | t = cpu->isar.id_aa64pfr0; |
29 | +VSRA_U_2sh 1111 001 1 1 . ...... .... 0001 . . . 1 .... @2reg_shr_h | ||
30 | +VSRA_U_2sh 1111 001 1 1 . ...... .... 0001 . . . 1 .... @2reg_shr_b | ||
31 | + | ||
32 | +VRSHR_S_2sh 1111 001 0 1 . ...... .... 0010 . . . 1 .... @2reg_shr_d | ||
33 | +VRSHR_S_2sh 1111 001 0 1 . ...... .... 0010 . . . 1 .... @2reg_shr_s | ||
34 | +VRSHR_S_2sh 1111 001 0 1 . ...... .... 0010 . . . 1 .... @2reg_shr_h | ||
35 | +VRSHR_S_2sh 1111 001 0 1 . ...... .... 0010 . . . 1 .... @2reg_shr_b | ||
36 | + | ||
37 | +VRSHR_U_2sh 1111 001 1 1 . ...... .... 0010 . . . 1 .... @2reg_shr_d | ||
38 | +VRSHR_U_2sh 1111 001 1 1 . ...... .... 0010 . . . 1 .... @2reg_shr_s | ||
39 | +VRSHR_U_2sh 1111 001 1 1 . ...... .... 0010 . . . 1 .... @2reg_shr_h | ||
40 | +VRSHR_U_2sh 1111 001 1 1 . ...... .... 0010 . . . 1 .... @2reg_shr_b | ||
41 | + | ||
42 | +VRSRA_S_2sh 1111 001 0 1 . ...... .... 0011 . . . 1 .... @2reg_shr_d | ||
43 | +VRSRA_S_2sh 1111 001 0 1 . ...... .... 0011 . . . 1 .... @2reg_shr_s | ||
44 | +VRSRA_S_2sh 1111 001 0 1 . ...... .... 0011 . . . 1 .... @2reg_shr_h | ||
45 | +VRSRA_S_2sh 1111 001 0 1 . ...... .... 0011 . . . 1 .... @2reg_shr_b | ||
46 | + | ||
47 | +VRSRA_U_2sh 1111 001 1 1 . ...... .... 0011 . . . 1 .... @2reg_shr_d | ||
48 | +VRSRA_U_2sh 1111 001 1 1 . ...... .... 0011 . . . 1 .... @2reg_shr_s | ||
49 | +VRSRA_U_2sh 1111 001 1 1 . ...... .... 0011 . . . 1 .... @2reg_shr_h | ||
50 | +VRSRA_U_2sh 1111 001 1 1 . ...... .... 0011 . . . 1 .... @2reg_shr_b | ||
51 | + | ||
52 | +VSRI_2sh 1111 001 1 1 . ...... .... 0100 . . . 1 .... @2reg_shr_d | ||
53 | +VSRI_2sh 1111 001 1 1 . ...... .... 0100 . . . 1 .... @2reg_shr_s | ||
54 | +VSRI_2sh 1111 001 1 1 . ...... .... 0100 . . . 1 .... @2reg_shr_h | ||
55 | +VSRI_2sh 1111 001 1 1 . ...... .... 0100 . . . 1 .... @2reg_shr_b | ||
56 | + | ||
57 | VSHL_2sh 1111 001 0 1 . ...... .... 0101 . . . 1 .... @2reg_shl_d | ||
58 | VSHL_2sh 1111 001 0 1 . ...... .... 0101 . . . 1 .... @2reg_shl_s | ||
59 | VSHL_2sh 1111 001 0 1 . ...... .... 0101 . . . 1 .... @2reg_shl_h | ||
60 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | ||
61 | index XXXXXXX..XXXXXXX 100644 | ||
62 | --- a/target/arm/translate-neon.inc.c | ||
63 | +++ b/target/arm/translate-neon.inc.c | ||
64 | @@ -XXX,XX +XXX,XX @@ static bool do_vector_2sh(DisasContext *s, arg_2reg_shift *a, GVecGen2iFn *fn) | ||
65 | |||
66 | DO_2SH(VSHL, tcg_gen_gvec_shli) | ||
67 | DO_2SH(VSLI, gen_gvec_sli) | ||
68 | +DO_2SH(VSRI, gen_gvec_sri) | ||
69 | +DO_2SH(VSRA_S, gen_gvec_ssra) | ||
70 | +DO_2SH(VSRA_U, gen_gvec_usra) | ||
71 | +DO_2SH(VRSHR_S, gen_gvec_srshr) | ||
72 | +DO_2SH(VRSHR_U, gen_gvec_urshr) | ||
73 | +DO_2SH(VRSRA_S, gen_gvec_srsra) | ||
74 | +DO_2SH(VRSRA_U, gen_gvec_ursra) | ||
75 | |||
76 | static bool trans_VSHR_S_2sh(DisasContext *s, arg_2reg_shift *a) | ||
77 | { | ||
78 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
79 | index XXXXXXX..XXXXXXX 100644 | ||
80 | --- a/target/arm/translate.c | ||
81 | +++ b/target/arm/translate.c | ||
82 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
83 | |||
84 | switch (op) { | ||
85 | case 0: /* VSHR */ | ||
86 | + case 1: /* VSRA */ | ||
87 | + case 2: /* VRSHR */ | ||
88 | + case 3: /* VRSRA */ | ||
89 | + case 4: /* VSRI */ | ||
90 | case 5: /* VSHL, VSLI */ | ||
91 | return 1; /* handled by decodetree */ | ||
92 | default: | ||
93 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
94 | shift = shift - (1 << (size + 3)); | ||
95 | } | ||
96 | |||
97 | - switch (op) { | ||
98 | - case 1: /* VSRA */ | ||
99 | - /* Right shift comes here negative. */ | ||
100 | - shift = -shift; | ||
101 | - if (u) { | ||
102 | - gen_gvec_usra(size, rd_ofs, rm_ofs, shift, | ||
103 | - vec_size, vec_size); | ||
104 | - } else { | ||
105 | - gen_gvec_ssra(size, rd_ofs, rm_ofs, shift, | ||
106 | - vec_size, vec_size); | ||
107 | - } | ||
108 | - return 0; | ||
109 | - | ||
110 | - case 2: /* VRSHR */ | ||
111 | - /* Right shift comes here negative. */ | ||
112 | - shift = -shift; | ||
113 | - if (u) { | ||
114 | - gen_gvec_urshr(size, rd_ofs, rm_ofs, shift, | ||
115 | - vec_size, vec_size); | ||
116 | - } else { | ||
117 | - gen_gvec_srshr(size, rd_ofs, rm_ofs, shift, | ||
118 | - vec_size, vec_size); | ||
119 | - } | ||
120 | - return 0; | ||
121 | - | ||
122 | - case 3: /* VRSRA */ | ||
123 | - /* Right shift comes here negative. */ | ||
124 | - shift = -shift; | ||
125 | - if (u) { | ||
126 | - gen_gvec_ursra(size, rd_ofs, rm_ofs, shift, | ||
127 | - vec_size, vec_size); | ||
128 | - } else { | ||
129 | - gen_gvec_srsra(size, rd_ofs, rm_ofs, shift, | ||
130 | - vec_size, vec_size); | ||
131 | - } | ||
132 | - return 0; | ||
133 | - | ||
134 | - case 4: /* VSRI */ | ||
135 | - if (!u) { | ||
136 | - return 1; | ||
137 | - } | ||
138 | - /* Right shift comes here negative. */ | ||
139 | - shift = -shift; | ||
140 | - gen_gvec_sri(size, rd_ofs, rm_ofs, shift, | ||
141 | - vec_size, vec_size); | ||
142 | - return 0; | ||
143 | - } | ||
144 | - | ||
145 | if (size == 3) { | ||
146 | count = q + 1; | ||
147 | } else { | ||
148 | -- | 26 | -- |
149 | 2.20.1 | 27 | 2.20.1 |
150 | 28 | ||
151 | 29 | diff view generated by jsdifflib |
1 | From: Paul Zimmerman <pauldzim@gmail.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Add a check for functional dwc-hsotg (dwc2) USB host emulation to | 3 | Add 4 attributes that controls the EL1 enable bits, as we may not |
4 | the Raspi 2 acceptance test | 4 | always want to turn on pointer authentication with -cpu max. |
5 | However, by default they are enabled. | ||
5 | 6 | ||
6 | Signed-off-by: Paul Zimmerman <pauldzim@gmail.com> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Reviewed-by: Philippe Mathieu-Daude <f4bug@amsat.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Message-id: 20200520235349.21215-8-pauldzim@gmail.com | 9 | Message-id: 20190108223129.5570-31-richard.henderson@linaro.org |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 11 | --- |
11 | tests/acceptance/boot_linux_console.py | 9 +++++++-- | 12 | target/arm/cpu.c | 3 +++ |
12 | 1 file changed, 7 insertions(+), 2 deletions(-) | 13 | target/arm/cpu64.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++ |
14 | 2 files changed, 63 insertions(+) | ||
13 | 15 | ||
14 | diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py | 16 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c |
15 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/tests/acceptance/boot_linux_console.py | 18 | --- a/target/arm/cpu.c |
17 | +++ b/tests/acceptance/boot_linux_console.py | 19 | +++ b/target/arm/cpu.c |
18 | @@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(LinuxKernelTest): | 20 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(CPUState *s) |
19 | 21 | env->pstate = PSTATE_MODE_EL0t; | |
20 | self.vm.set_console() | 22 | /* Userspace expects access to DC ZVA, CTL_EL0 and the cache ops */ |
21 | kernel_command_line = (self.KERNEL_COMMON_COMMAND_LINE + | 23 | env->cp15.sctlr_el[1] |= SCTLR_UCT | SCTLR_UCI | SCTLR_DZE; |
22 | - serial_kernel_cmdline[uart_id]) | 24 | + /* Enable all PAC instructions */ |
23 | + serial_kernel_cmdline[uart_id] + | 25 | + env->cp15.hcr_el2 |= HCR_API; |
24 | + ' root=/dev/mmcblk0p2 rootwait ' + | 26 | + env->cp15.scr_el3 |= SCR_API; |
25 | + 'dwc_otg.fiq_fsm_enable=0') | 27 | /* and to the FP/Neon instructions */ |
26 | self.vm.add_args('-kernel', kernel_path, | 28 | env->cp15.cpacr_el1 = deposit64(env->cp15.cpacr_el1, 20, 2, 3); |
27 | '-dtb', dtb_path, | 29 | /* and to the SVE instructions */ |
28 | - '-append', kernel_command_line) | 30 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c |
29 | + '-append', kernel_command_line, | 31 | index XXXXXXX..XXXXXXX 100644 |
30 | + '-device', 'usb-kbd') | 32 | --- a/target/arm/cpu64.c |
31 | self.vm.launch() | 33 | +++ b/target/arm/cpu64.c |
32 | console_pattern = 'Kernel command line: %s' % kernel_command_line | 34 | @@ -XXX,XX +XXX,XX @@ static void cpu_max_set_sve_vq(Object *obj, Visitor *v, const char *name, |
33 | self.wait_for_console_pattern(console_pattern) | 35 | error_propagate(errp, err); |
34 | + console_pattern = 'Product: QEMU USB Keyboard' | 36 | } |
35 | + self.wait_for_console_pattern(console_pattern) | 37 | |
36 | 38 | +#ifdef CONFIG_USER_ONLY | |
37 | def test_arm_raspi2_uart0(self): | 39 | +static void cpu_max_get_packey(Object *obj, Visitor *v, const char *name, |
38 | """ | 40 | + void *opaque, Error **errp) |
41 | +{ | ||
42 | + ARMCPU *cpu = ARM_CPU(obj); | ||
43 | + const uint64_t *bit = opaque; | ||
44 | + bool enabled = (cpu->env.cp15.sctlr_el[1] & *bit) != 0; | ||
45 | + | ||
46 | + visit_type_bool(v, name, &enabled, errp); | ||
47 | +} | ||
48 | + | ||
49 | +static void cpu_max_set_packey(Object *obj, Visitor *v, const char *name, | ||
50 | + void *opaque, Error **errp) | ||
51 | +{ | ||
52 | + ARMCPU *cpu = ARM_CPU(obj); | ||
53 | + Error *err = NULL; | ||
54 | + const uint64_t *bit = opaque; | ||
55 | + bool enabled; | ||
56 | + | ||
57 | + visit_type_bool(v, name, &enabled, errp); | ||
58 | + | ||
59 | + if (!err) { | ||
60 | + if (enabled) { | ||
61 | + cpu->env.cp15.sctlr_el[1] |= *bit; | ||
62 | + } else { | ||
63 | + cpu->env.cp15.sctlr_el[1] &= ~*bit; | ||
64 | + } | ||
65 | + } | ||
66 | + error_propagate(errp, err); | ||
67 | +} | ||
68 | +#endif | ||
69 | + | ||
70 | /* -cpu max: if KVM is enabled, like -cpu host (best possible with this host); | ||
71 | * otherwise, a CPU with as many features enabled as our emulation supports. | ||
72 | * The version of '-cpu max' for qemu-system-arm is defined in cpu.c; | ||
73 | @@ -XXX,XX +XXX,XX @@ static void aarch64_max_initfn(Object *obj) | ||
74 | */ | ||
75 | cpu->ctr = 0x80038003; /* 32 byte I and D cacheline size, VIPT icache */ | ||
76 | cpu->dcz_blocksize = 7; /* 512 bytes */ | ||
77 | + | ||
78 | + /* | ||
79 | + * Note that Linux will enable enable all of the keys at once. | ||
80 | + * But doing it this way will allow experimentation beyond that. | ||
81 | + */ | ||
82 | + { | ||
83 | + static const uint64_t apia_bit = SCTLR_EnIA; | ||
84 | + static const uint64_t apib_bit = SCTLR_EnIB; | ||
85 | + static const uint64_t apda_bit = SCTLR_EnDA; | ||
86 | + static const uint64_t apdb_bit = SCTLR_EnDB; | ||
87 | + | ||
88 | + object_property_add(obj, "apia", "bool", cpu_max_get_packey, | ||
89 | + cpu_max_set_packey, NULL, | ||
90 | + (void *)&apia_bit, &error_fatal); | ||
91 | + object_property_add(obj, "apib", "bool", cpu_max_get_packey, | ||
92 | + cpu_max_set_packey, NULL, | ||
93 | + (void *)&apib_bit, &error_fatal); | ||
94 | + object_property_add(obj, "apda", "bool", cpu_max_get_packey, | ||
95 | + cpu_max_set_packey, NULL, | ||
96 | + (void *)&apda_bit, &error_fatal); | ||
97 | + object_property_add(obj, "apdb", "bool", cpu_max_get_packey, | ||
98 | + cpu_max_set_packey, NULL, | ||
99 | + (void *)&apdb_bit, &error_fatal); | ||
100 | + | ||
101 | + /* Enable all PAC keys by default. */ | ||
102 | + cpu->env.cp15.sctlr_el[1] |= SCTLR_EnIA | SCTLR_EnIB; | ||
103 | + cpu->env.cp15.sctlr_el[1] |= SCTLR_EnDA | SCTLR_EnDB; | ||
104 | + } | ||
105 | #endif | ||
106 | |||
107 | cpu->sve_max_vq = ARM_MAX_VQ; | ||
39 | -- | 108 | -- |
40 | 2.20.1 | 109 | 2.20.1 |
41 | 110 | ||
42 | 111 | diff view generated by jsdifflib |
1 | From: Paul Zimmerman <pauldzim@gmail.com> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Wire the dwc-hsotg (dwc2) emulation into Qemu | 3 | We can perform this with fewer operations. |
4 | 4 | ||
5 | Signed-off-by: Paul Zimmerman <pauldzim@gmail.com> | 5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Philippe Mathieu-Daude <f4bug@amsat.org> | 6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20200520235349.21215-7-pauldzim@gmail.com | 7 | Message-id: 20190108223129.5570-32-richard.henderson@linaro.org |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 9 | --- |
10 | include/hw/arm/bcm2835_peripherals.h | 3 ++- | 10 | target/arm/translate-a64.c | 62 +++++++++++++------------------------- |
11 | hw/arm/bcm2835_peripherals.c | 21 ++++++++++++++++++++- | 11 | 1 file changed, 21 insertions(+), 41 deletions(-) |
12 | 2 files changed, 22 insertions(+), 2 deletions(-) | ||
13 | 12 | ||
14 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h | 13 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
15 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/include/hw/arm/bcm2835_peripherals.h | 15 | --- a/target/arm/translate-a64.c |
17 | +++ b/include/hw/arm/bcm2835_peripherals.h | 16 | +++ b/target/arm/translate-a64.c |
18 | @@ -XXX,XX +XXX,XX @@ | 17 | @@ -XXX,XX +XXX,XX @@ void gen_a64_set_pc_im(uint64_t val) |
19 | #include "hw/sd/bcm2835_sdhost.h" | 18 | /* Load the PC from a generic TCG variable. |
20 | #include "hw/gpio/bcm2835_gpio.h" | 19 | * |
21 | #include "hw/timer/bcm2835_systmr.h" | 20 | * If address tagging is enabled via the TCR TBI bits, then loading |
22 | +#include "hw/usb/hcd-dwc2.h" | 21 | - * an address into the PC will clear out any tag in the it: |
23 | #include "hw/misc/unimp.h" | 22 | + * an address into the PC will clear out any tag in it: |
24 | 23 | * + for EL2 and EL3 there is only one TBI bit, and if it is set | |
25 | #define TYPE_BCM2835_PERIPHERALS "bcm2835-peripherals" | 24 | * then the address is zero-extended, clearing bits [63:56] |
26 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM2835PeripheralState { | 25 | * + for EL0 and EL1, TBI0 controls addresses with bit 55 == 0 |
27 | UnimplementedDeviceState ave0; | 26 | @@ -XXX,XX +XXX,XX @@ static void gen_a64_set_pc(DisasContext *s, TCGv_i64 src) |
28 | UnimplementedDeviceState bscsl; | 27 | int tbi = s->tbii; |
29 | UnimplementedDeviceState smi; | 28 | |
30 | - UnimplementedDeviceState dwc2; | 29 | if (s->current_el <= 1) { |
31 | + DWC2State dwc2; | 30 | - /* Test if NEITHER or BOTH TBI values are set. If so, no need to |
32 | UnimplementedDeviceState sdramc; | 31 | - * examine bit 55 of address, can just generate code. |
33 | } BCM2835PeripheralState; | 32 | - * If mixed, then test via generated code |
34 | 33 | - */ | |
35 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | 34 | - if (tbi == 3) { |
36 | index XXXXXXX..XXXXXXX 100644 | 35 | - TCGv_i64 tmp_reg = tcg_temp_new_i64(); |
37 | --- a/hw/arm/bcm2835_peripherals.c | 36 | - /* Both bits set, sign extension from bit 55 into [63:56] will |
38 | +++ b/hw/arm/bcm2835_peripherals.c | 37 | - * cover both cases |
39 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj) | 38 | - */ |
40 | /* Mphi */ | 39 | - tcg_gen_shli_i64(tmp_reg, src, 8); |
41 | sysbus_init_child_obj(obj, "mphi", &s->mphi, sizeof(s->mphi), | 40 | - tcg_gen_sari_i64(cpu_pc, tmp_reg, 8); |
42 | TYPE_BCM2835_MPHI); | 41 | - tcg_temp_free_i64(tmp_reg); |
42 | - } else if (tbi == 0) { | ||
43 | - /* Neither bit set, just load it as-is */ | ||
44 | - tcg_gen_mov_i64(cpu_pc, src); | ||
45 | - } else { | ||
46 | - TCGv_i64 tcg_tmpval = tcg_temp_new_i64(); | ||
47 | - TCGv_i64 tcg_bit55 = tcg_temp_new_i64(); | ||
48 | - TCGv_i64 tcg_zero = tcg_const_i64(0); | ||
49 | + if (tbi != 0) { | ||
50 | + /* Sign-extend from bit 55. */ | ||
51 | + tcg_gen_sextract_i64(cpu_pc, src, 0, 56); | ||
52 | |||
53 | - tcg_gen_andi_i64(tcg_bit55, src, (1ull << 55)); | ||
54 | + if (tbi != 3) { | ||
55 | + TCGv_i64 tcg_zero = tcg_const_i64(0); | ||
56 | |||
57 | - if (tbi == 1) { | ||
58 | - /* tbi0==1, tbi1==0, so 0-fill upper byte if bit 55 = 0 */ | ||
59 | - tcg_gen_andi_i64(tcg_tmpval, src, | ||
60 | - 0x00FFFFFFFFFFFFFFull); | ||
61 | - tcg_gen_movcond_i64(TCG_COND_EQ, cpu_pc, tcg_bit55, tcg_zero, | ||
62 | - tcg_tmpval, src); | ||
63 | - } else { | ||
64 | - /* tbi0==0, tbi1==1, so 1-fill upper byte if bit 55 = 1 */ | ||
65 | - tcg_gen_ori_i64(tcg_tmpval, src, | ||
66 | - 0xFF00000000000000ull); | ||
67 | - tcg_gen_movcond_i64(TCG_COND_NE, cpu_pc, tcg_bit55, tcg_zero, | ||
68 | - tcg_tmpval, src); | ||
69 | + /* | ||
70 | + * The two TBI bits differ. | ||
71 | + * If tbi0, then !tbi1: only use the extension if positive. | ||
72 | + * if !tbi0, then tbi1: only use the extension if negative. | ||
73 | + */ | ||
74 | + tcg_gen_movcond_i64(tbi == 1 ? TCG_COND_GE : TCG_COND_LT, | ||
75 | + cpu_pc, cpu_pc, tcg_zero, cpu_pc, src); | ||
76 | + tcg_temp_free_i64(tcg_zero); | ||
77 | } | ||
78 | - tcg_temp_free_i64(tcg_zero); | ||
79 | - tcg_temp_free_i64(tcg_bit55); | ||
80 | - tcg_temp_free_i64(tcg_tmpval); | ||
81 | + return; | ||
82 | } | ||
83 | - } else { /* EL > 1 */ | ||
84 | + } else { | ||
85 | if (tbi != 0) { | ||
86 | /* Force tag byte to all zero */ | ||
87 | - tcg_gen_andi_i64(cpu_pc, src, 0x00FFFFFFFFFFFFFFull); | ||
88 | - } else { | ||
89 | - /* Load unmodified address */ | ||
90 | - tcg_gen_mov_i64(cpu_pc, src); | ||
91 | + tcg_gen_extract_i64(cpu_pc, src, 0, 56); | ||
92 | + return; | ||
93 | } | ||
94 | } | ||
43 | + | 95 | + |
44 | + /* DWC2 */ | 96 | + /* Load unmodified address */ |
45 | + sysbus_init_child_obj(obj, "dwc2", &s->dwc2, sizeof(s->dwc2), | 97 | + tcg_gen_mov_i64(cpu_pc, src); |
46 | + TYPE_DWC2_USB); | ||
47 | + | ||
48 | + object_property_add_const_link(OBJECT(&s->dwc2), "dma-mr", | ||
49 | + OBJECT(&s->gpu_bus_mr)); | ||
50 | } | 98 | } |
51 | 99 | ||
52 | static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | 100 | typedef struct DisasCompare64 { |
53 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
54 | qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ, | ||
55 | INTERRUPT_HOSTPORT)); | ||
56 | |||
57 | + /* DWC2 */ | ||
58 | + object_property_set_bool(OBJECT(&s->dwc2), true, "realized", &err); | ||
59 | + if (err) { | ||
60 | + error_propagate(errp, err); | ||
61 | + return; | ||
62 | + } | ||
63 | + | ||
64 | + memory_region_add_subregion(&s->peri_mr, USB_OTG_OFFSET, | ||
65 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dwc2), 0)); | ||
66 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->dwc2), 0, | ||
67 | + qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ, | ||
68 | + INTERRUPT_USB)); | ||
69 | + | ||
70 | create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); | ||
71 | create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x1000); | ||
72 | create_unimp(s, &s->a2w, "bcm2835-a2w", A2W_OFFSET, 0x1000); | ||
73 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
74 | create_unimp(s, &s->otp, "bcm2835-otp", OTP_OFFSET, 0x80); | ||
75 | create_unimp(s, &s->dbus, "bcm2835-dbus", DBUS_OFFSET, 0x8000); | ||
76 | create_unimp(s, &s->ave0, "bcm2835-ave0", AVE0_OFFSET, 0x8000); | ||
77 | - create_unimp(s, &s->dwc2, "dwc-usb2", USB_OTG_OFFSET, 0x1000); | ||
78 | create_unimp(s, &s->sdramc, "bcm2835-sdramc", SDRAMC_OFFSET, 0x100); | ||
79 | } | ||
80 | |||
81 | -- | 101 | -- |
82 | 2.20.1 | 102 | 2.20.1 |
83 | 103 | ||
84 | 104 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | hw_error() calls exit(). This a bit overkill when we can log | 3 | In some cases it may be helpful to modify state before saving it for |
4 | the accesses as unimplemented or guest error. | 4 | migration, and then modify the state back after it has been saved. The |
5 | existing pre_save function provides half of this functionality. This | ||
6 | patch adds a post_save function to provide the second half. | ||
5 | 7 | ||
6 | When fuzzing the devices, we don't want the whole process to | 8 | Signed-off-by: Aaron Lindsay <aclindsa@gmail.com> |
7 | exit. Replace some hw_error() calls by qemu_log_mask() | ||
8 | (missed in commit 5a0001ec7e). | ||
9 | |||
10 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Message-id: 20200525114123.21317-2-f4bug@amsat.org | ||
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com> | ||
11 | Message-id: 20181211151945.29137-2-aaron@os.amperecomputing.com | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 13 | --- |
15 | hw/input/pxa2xx_keypad.c | 10 +++++++--- | 14 | include/migration/vmstate.h | 1 + |
16 | 1 file changed, 7 insertions(+), 3 deletions(-) | 15 | migration/vmstate.c | 13 ++++++++++++- |
16 | docs/devel/migration.rst | 9 +++++++-- | ||
17 | 3 files changed, 20 insertions(+), 3 deletions(-) | ||
17 | 18 | ||
18 | diff --git a/hw/input/pxa2xx_keypad.c b/hw/input/pxa2xx_keypad.c | 19 | diff --git a/include/migration/vmstate.h b/include/migration/vmstate.h |
19 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/input/pxa2xx_keypad.c | 21 | --- a/include/migration/vmstate.h |
21 | +++ b/hw/input/pxa2xx_keypad.c | 22 | +++ b/include/migration/vmstate.h |
22 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ struct VMStateDescription { |
23 | */ | 24 | int (*pre_load)(void *opaque); |
24 | 25 | int (*post_load)(void *opaque, int version_id); | |
25 | #include "qemu/osdep.h" | 26 | int (*pre_save)(void *opaque); |
26 | -#include "hw/hw.h" | 27 | + int (*post_save)(void *opaque); |
27 | +#include "qemu/log.h" | 28 | bool (*needed)(void *opaque); |
28 | #include "hw/irq.h" | 29 | const VMStateField *fields; |
29 | #include "migration/vmstate.h" | 30 | const VMStateDescription **subsections; |
30 | #include "hw/arm/pxa.h" | 31 | diff --git a/migration/vmstate.c b/migration/vmstate.c |
31 | @@ -XXX,XX +XXX,XX @@ static uint64_t pxa2xx_keypad_read(void *opaque, hwaddr offset, | 32 | index XXXXXXX..XXXXXXX 100644 |
32 | return s->kpkdi; | 33 | --- a/migration/vmstate.c |
33 | break; | 34 | +++ b/migration/vmstate.c |
34 | default: | 35 | @@ -XXX,XX +XXX,XX @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, |
35 | - hw_error("%s: Bad offset " REG_FMT "\n", __func__, offset); | 36 | if (ret) { |
36 | + qemu_log_mask(LOG_GUEST_ERROR, | 37 | error_report("Save of field %s/%s failed", |
37 | + "%s: Bad read offset 0x%"HWADDR_PRIx"\n", | 38 | vmsd->name, field->name); |
38 | + __func__, offset); | 39 | + if (vmsd->post_save) { |
40 | + vmsd->post_save(opaque); | ||
41 | + } | ||
42 | return ret; | ||
43 | } | ||
44 | |||
45 | @@ -XXX,XX +XXX,XX @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, | ||
46 | json_end_array(vmdesc); | ||
39 | } | 47 | } |
40 | 48 | ||
41 | return 0; | 49 | - return vmstate_subsection_save(f, vmsd, opaque, vmdesc); |
42 | @@ -XXX,XX +XXX,XX @@ static void pxa2xx_keypad_write(void *opaque, hwaddr offset, | 50 | + ret = vmstate_subsection_save(f, vmsd, opaque, vmdesc); |
43 | break; | 51 | + |
44 | 52 | + if (vmsd->post_save) { | |
45 | default: | 53 | + int ps_ret = vmsd->post_save(opaque); |
46 | - hw_error("%s: Bad offset " REG_FMT "\n", __func__, offset); | 54 | + if (!ret) { |
47 | + qemu_log_mask(LOG_GUEST_ERROR, | 55 | + ret = ps_ret; |
48 | + "%s: Bad write offset 0x%"HWADDR_PRIx"\n", | 56 | + } |
49 | + __func__, offset); | 57 | + } |
50 | } | 58 | + return ret; |
51 | } | 59 | } |
52 | 60 | ||
61 | static const VMStateDescription * | ||
62 | diff --git a/docs/devel/migration.rst b/docs/devel/migration.rst | ||
63 | index XXXXXXX..XXXXXXX 100644 | ||
64 | --- a/docs/devel/migration.rst | ||
65 | +++ b/docs/devel/migration.rst | ||
66 | @@ -XXX,XX +XXX,XX @@ The functions to do that are inside a vmstate definition, and are called: | ||
67 | |||
68 | This function is called before we save the state of one device. | ||
69 | |||
70 | -Example: You can look at hpet.c, that uses the three function to | ||
71 | -massage the state that is transferred. | ||
72 | +- ``int (*post_save)(void *opaque);`` | ||
73 | + | ||
74 | + This function is called after we save the state of one device | ||
75 | + (even upon failure, unless the call to pre_save returned an error). | ||
76 | + | ||
77 | +Example: You can look at hpet.c, that uses the first three functions | ||
78 | +to massage the state that is transferred. | ||
79 | |||
80 | The ``VMSTATE_WITH_TMP`` macro may be useful when the migration | ||
81 | data doesn't match the stored device data well; it allows an | ||
53 | -- | 82 | -- |
54 | 2.20.1 | 83 | 2.20.1 |
55 | 84 | ||
56 | 85 | diff view generated by jsdifflib |
1 | From: Paul Zimmerman <pauldzim@gmail.com> | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | The dwc-hsotg (dwc2) USB host depends on a short packet to | 3 | pmccntr_read and pmccntr_write contained duplicate code that was already |
4 | indicate the end of an IN transfer. The usb-storage driver | 4 | being handled by pmccntr_sync. Consolidate the duplicated code into two |
5 | currently doesn't provide this, so fix it. | 5 | functions: pmccntr_op_start and pmccntr_op_finish. Add a companion to |
6 | 6 | c15_ccnt in CPUARMState so that we can simultaneously save both the | |
7 | I have tested this change rather extensively using a PC | 7 | architectural register value and the last underlying cycle count - this |
8 | emulation with xhci, ehci, and uhci controllers, and have | 8 | ensures time isn't lost and will also allow us to access the 'old' |
9 | not observed any regressions. | 9 | architectural register value in order to detect overflows in later |
10 | 10 | patches. | |
11 | Signed-off-by: Paul Zimmerman <pauldzim@gmail.com> | 11 | |
12 | Message-id: 20200520235349.21215-6-pauldzim@gmail.com | 12 | Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org> |
13 | Signed-off-by: Aaron Lindsay <aclindsa@gmail.com> | ||
14 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
15 | Message-id: 20181211151945.29137-3-aaron@os.amperecomputing.com | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 17 | --- |
15 | hw/usb/dev-storage.c | 15 ++++++++++++++- | 18 | target/arm/cpu.h | 37 +++++++++++--- |
16 | 1 file changed, 14 insertions(+), 1 deletion(-) | 19 | target/arm/helper.c | 118 ++++++++++++++++++++++++++------------------ |
17 | 20 | 2 files changed, 100 insertions(+), 55 deletions(-) | |
18 | diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c | 21 | |
22 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | ||
19 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
20 | --- a/hw/usb/dev-storage.c | 24 | --- a/target/arm/cpu.h |
21 | +++ b/hw/usb/dev-storage.c | 25 | +++ b/target/arm/cpu.h |
22 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_copy_data(MSDState *s, USBPacket *p) | 26 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { |
23 | usb_packet_copy(p, scsi_req_get_buf(s->req) + s->scsi_off, len); | 27 | uint64_t oslsr_el1; /* OS Lock Status */ |
24 | s->scsi_len -= len; | 28 | uint64_t mdcr_el2; |
25 | s->scsi_off += len; | 29 | uint64_t mdcr_el3; |
26 | + if (len > s->data_len) { | 30 | - /* If the counter is enabled, this stores the last time the counter |
27 | + len = s->data_len; | 31 | - * was reset. Otherwise it stores the counter value |
32 | + /* Stores the architectural value of the counter *the last time it was | ||
33 | + * updated* by pmccntr_op_start. Accesses should always be surrounded | ||
34 | + * by pmccntr_op_start/pmccntr_op_finish to guarantee the latest | ||
35 | + * architecturally-correct value is being read/set. | ||
36 | */ | ||
37 | uint64_t c15_ccnt; | ||
38 | + /* Stores the delta between the architectural value and the underlying | ||
39 | + * cycle count during normal operation. It is used to update c15_ccnt | ||
40 | + * to be the correct architectural value before accesses. During | ||
41 | + * accesses, c15_ccnt_delta contains the underlying count being used | ||
42 | + * for the access, after which it reverts to the delta value in | ||
43 | + * pmccntr_op_finish. | ||
44 | + */ | ||
45 | + uint64_t c15_ccnt_delta; | ||
46 | uint64_t pmccfiltr_el0; /* Performance Monitor Filter Register */ | ||
47 | uint64_t vpidr_el2; /* Virtualization Processor ID Register */ | ||
48 | uint64_t vmpidr_el2; /* Virtualization Multiprocessor ID Register */ | ||
49 | @@ -XXX,XX +XXX,XX @@ int cpu_arm_signal_handler(int host_signum, void *pinfo, | ||
50 | void *puc); | ||
51 | |||
52 | /** | ||
53 | - * pmccntr_sync | ||
54 | + * pmccntr_op_start/finish | ||
55 | * @env: CPUARMState | ||
56 | * | ||
57 | - * Synchronises the counter in the PMCCNTR. This must always be called twice, | ||
58 | - * once before any action that might affect the timer and again afterwards. | ||
59 | - * The function is used to swap the state of the register if required. | ||
60 | - * This only happens when not in user mode (!CONFIG_USER_ONLY) | ||
61 | + * Convert the counter in the PMCCNTR between its delta form (the typical mode | ||
62 | + * when it's enabled) and the guest-visible value. These two calls must always | ||
63 | + * surround any action which might affect the counter. | ||
64 | */ | ||
65 | -void pmccntr_sync(CPUARMState *env); | ||
66 | +void pmccntr_op_start(CPUARMState *env); | ||
67 | +void pmccntr_op_finish(CPUARMState *env); | ||
68 | + | ||
69 | +/** | ||
70 | + * pmu_op_start/finish | ||
71 | + * @env: CPUARMState | ||
72 | + * | ||
73 | + * Convert all PMU counters between their delta form (the typical mode when | ||
74 | + * they are enabled) and the guest-visible values. These two calls must | ||
75 | + * surround any action which might affect the counters. | ||
76 | + */ | ||
77 | +void pmu_op_start(CPUARMState *env); | ||
78 | +void pmu_op_finish(CPUARMState *env); | ||
79 | |||
80 | /* SCTLR bit meanings. Several bits have been reused in newer | ||
81 | * versions of the architecture; in that case we define constants | ||
82 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/target/arm/helper.c | ||
85 | +++ b/target/arm/helper.c | ||
86 | @@ -XXX,XX +XXX,XX @@ static inline bool arm_ccnt_enabled(CPUARMState *env) | ||
87 | |||
88 | return true; | ||
89 | } | ||
90 | - | ||
91 | -void pmccntr_sync(CPUARMState *env) | ||
92 | +/* | ||
93 | + * Ensure c15_ccnt is the guest-visible count so that operations such as | ||
94 | + * enabling/disabling the counter or filtering, modifying the count itself, | ||
95 | + * etc. can be done logically. This is essentially a no-op if the counter is | ||
96 | + * not enabled at the time of the call. | ||
97 | + */ | ||
98 | +void pmccntr_op_start(CPUARMState *env) | ||
99 | { | ||
100 | - uint64_t temp_ticks; | ||
101 | - | ||
102 | - temp_ticks = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), | ||
103 | + uint64_t cycles = 0; | ||
104 | + cycles = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), | ||
105 | ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); | ||
106 | |||
107 | - if (env->cp15.c9_pmcr & PMCRD) { | ||
108 | - /* Increment once every 64 processor clock cycles */ | ||
109 | - temp_ticks /= 64; | ||
110 | - } | ||
111 | - | ||
112 | if (arm_ccnt_enabled(env)) { | ||
113 | - env->cp15.c15_ccnt = temp_ticks - env->cp15.c15_ccnt; | ||
114 | + uint64_t eff_cycles = cycles; | ||
115 | + if (env->cp15.c9_pmcr & PMCRD) { | ||
116 | + /* Increment once every 64 processor clock cycles */ | ||
117 | + eff_cycles /= 64; | ||
118 | + } | ||
119 | + | ||
120 | + env->cp15.c15_ccnt = eff_cycles - env->cp15.c15_ccnt_delta; | ||
121 | } | ||
122 | + env->cp15.c15_ccnt_delta = cycles; | ||
123 | +} | ||
124 | + | ||
125 | +/* | ||
126 | + * If PMCCNTR is enabled, recalculate the delta between the clock and the | ||
127 | + * guest-visible count. A call to pmccntr_op_finish should follow every call to | ||
128 | + * pmccntr_op_start. | ||
129 | + */ | ||
130 | +void pmccntr_op_finish(CPUARMState *env) | ||
131 | +{ | ||
132 | + if (arm_ccnt_enabled(env)) { | ||
133 | + uint64_t prev_cycles = env->cp15.c15_ccnt_delta; | ||
134 | + | ||
135 | + if (env->cp15.c9_pmcr & PMCRD) { | ||
136 | + /* Increment once every 64 processor clock cycles */ | ||
137 | + prev_cycles /= 64; | ||
138 | + } | ||
139 | + | ||
140 | + env->cp15.c15_ccnt_delta = prev_cycles - env->cp15.c15_ccnt; | ||
28 | + } | 141 | + } |
29 | s->data_len -= len; | 142 | +} |
30 | if (s->scsi_len == 0 || s->data_len == 0) { | 143 | + |
31 | scsi_req_continue(s->req); | 144 | +void pmu_op_start(CPUARMState *env) |
32 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_command_complete(SCSIRequest *req, uint32_t status, size_t r | 145 | +{ |
33 | if (s->data_len) { | 146 | + pmccntr_op_start(env); |
34 | int len = (p->iov.size - p->actual_length); | 147 | +} |
35 | usb_packet_skip(p, len); | 148 | + |
36 | + if (len > s->data_len) { | 149 | +void pmu_op_finish(CPUARMState *env) |
37 | + len = s->data_len; | 150 | +{ |
38 | + } | 151 | + pmccntr_op_finish(env); |
39 | s->data_len -= len; | 152 | } |
40 | } | 153 | |
41 | if (s->data_len == 0) { | 154 | static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, |
42 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p) | 155 | uint64_t value) |
43 | int len = p->iov.size - p->actual_length; | 156 | { |
44 | if (len) { | 157 | - pmccntr_sync(env); |
45 | usb_packet_skip(p, len); | 158 | + pmu_op_start(env); |
46 | + if (len > s->data_len) { | 159 | |
47 | + len = s->data_len; | 160 | if (value & PMCRC) { |
48 | + } | 161 | /* The counter has been reset */ |
49 | s->data_len -= len; | 162 | @@ -XXX,XX +XXX,XX @@ static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, |
50 | if (s->data_len == 0) { | 163 | env->cp15.c9_pmcr &= ~0x39; |
51 | s->mode = USB_MSDM_CSW; | 164 | env->cp15.c9_pmcr |= (value & 0x39); |
52 | @@ -XXX,XX +XXX,XX @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p) | 165 | |
53 | int len = p->iov.size - p->actual_length; | 166 | - pmccntr_sync(env); |
54 | if (len) { | 167 | + pmu_op_finish(env); |
55 | usb_packet_skip(p, len); | 168 | } |
56 | + if (len > s->data_len) { | 169 | |
57 | + len = s->data_len; | 170 | static uint64_t pmccntr_read(CPUARMState *env, const ARMCPRegInfo *ri) |
58 | + } | 171 | { |
59 | s->data_len -= len; | 172 | - uint64_t total_ticks; |
60 | if (s->data_len == 0) { | 173 | - |
61 | s->mode = USB_MSDM_CSW; | 174 | - if (!arm_ccnt_enabled(env)) { |
62 | } | 175 | - /* Counter is disabled, do not change value */ |
63 | } | 176 | - return env->cp15.c15_ccnt; |
64 | } | 177 | - } |
65 | - if (p->actual_length < p->iov.size) { | 178 | - |
66 | + if (p->actual_length < p->iov.size && (p->short_not_ok || | 179 | - total_ticks = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), |
67 | + s->scsi_len >= p->ep->max_packet_size)) { | 180 | - ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); |
68 | DPRINTF("Deferring packet %p [wait data-in]\n", p); | 181 | - |
69 | s->packet = p; | 182 | - if (env->cp15.c9_pmcr & PMCRD) { |
70 | p->status = USB_RET_ASYNC; | 183 | - /* Increment once every 64 processor clock cycles */ |
184 | - total_ticks /= 64; | ||
185 | - } | ||
186 | - return total_ticks - env->cp15.c15_ccnt; | ||
187 | + uint64_t ret; | ||
188 | + pmccntr_op_start(env); | ||
189 | + ret = env->cp15.c15_ccnt; | ||
190 | + pmccntr_op_finish(env); | ||
191 | + return ret; | ||
192 | } | ||
193 | |||
194 | static void pmselr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
195 | @@ -XXX,XX +XXX,XX @@ static void pmselr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
196 | static void pmccntr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
197 | uint64_t value) | ||
198 | { | ||
199 | - uint64_t total_ticks; | ||
200 | - | ||
201 | - if (!arm_ccnt_enabled(env)) { | ||
202 | - /* Counter is disabled, set the absolute value */ | ||
203 | - env->cp15.c15_ccnt = value; | ||
204 | - return; | ||
205 | - } | ||
206 | - | ||
207 | - total_ticks = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), | ||
208 | - ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); | ||
209 | - | ||
210 | - if (env->cp15.c9_pmcr & PMCRD) { | ||
211 | - /* Increment once every 64 processor clock cycles */ | ||
212 | - total_ticks /= 64; | ||
213 | - } | ||
214 | - env->cp15.c15_ccnt = total_ticks - value; | ||
215 | + pmccntr_op_start(env); | ||
216 | + env->cp15.c15_ccnt = value; | ||
217 | + pmccntr_op_finish(env); | ||
218 | } | ||
219 | |||
220 | static void pmccntr_write32(CPUARMState *env, const ARMCPRegInfo *ri, | ||
221 | @@ -XXX,XX +XXX,XX @@ static void pmccntr_write32(CPUARMState *env, const ARMCPRegInfo *ri, | ||
222 | |||
223 | #else /* CONFIG_USER_ONLY */ | ||
224 | |||
225 | -void pmccntr_sync(CPUARMState *env) | ||
226 | +void pmccntr_op_start(CPUARMState *env) | ||
227 | +{ | ||
228 | +} | ||
229 | + | ||
230 | +void pmccntr_op_finish(CPUARMState *env) | ||
231 | +{ | ||
232 | +} | ||
233 | + | ||
234 | +void pmu_op_start(CPUARMState *env) | ||
235 | +{ | ||
236 | +} | ||
237 | + | ||
238 | +void pmu_op_finish(CPUARMState *env) | ||
239 | { | ||
240 | } | ||
241 | |||
242 | @@ -XXX,XX +XXX,XX @@ void pmccntr_sync(CPUARMState *env) | ||
243 | static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
244 | uint64_t value) | ||
245 | { | ||
246 | - pmccntr_sync(env); | ||
247 | + pmccntr_op_start(env); | ||
248 | env->cp15.pmccfiltr_el0 = value & 0xfc000000; | ||
249 | - pmccntr_sync(env); | ||
250 | + pmccntr_op_finish(env); | ||
251 | } | ||
252 | |||
253 | static void pmcntenset_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
71 | -- | 254 | -- |
72 | 2.20.1 | 255 | 2.20.1 |
73 | 256 | ||
74 | 257 | diff view generated by jsdifflib |
1 | From: Paul Zimmerman <pauldzim@gmail.com> | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | Add the dwc-hsotg (dwc2) USB host controller emulation code. | 3 | Because of the PMU's design, many register accesses have side effects |
4 | Based on hw/usb/hcd-ehci.c and hw/usb/hcd-ohci.c. | 4 | which are inter-related, meaning that the normal method of saving CP |
5 | registers can result in inconsistent state. These side-effects are | ||
6 | largely handled in pmu_op_start/finish functions which can be called | ||
7 | before and after the state is saved/restored. By doing this and adding | ||
8 | raw read/write functions for the affected registers, we avoid | ||
9 | migration-related inconsistencies. | ||
5 | 10 | ||
6 | Note that to use this with the dwc-otg driver in the Raspbian | 11 | Signed-off-by: Aaron Lindsay <aclindsa@gmail.com> |
7 | kernel, you must pass the option "dwc_otg.fiq_fsm_enable=0" on | 12 | Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com> |
8 | the kernel command line. | ||
9 | |||
10 | Emulation of slave mode and of descriptor-DMA mode has not been | ||
11 | implemented yet. These modes are seldom used. | ||
12 | |||
13 | I have used some on-line sources of information while developing | ||
14 | this emulation, including: | ||
15 | |||
16 | http://www.capital-micro.com/PDF/CME-M7_Family_User_Guide_EN.pdf | ||
17 | which has a pretty complete description of the controller starting | ||
18 | on page 370. | ||
19 | |||
20 | https://sourceforge.net/p/wive-ng/wive-ng-mt/ci/master/tree/docs/DataSheets/RT3050_5x_V2.0_081408_0902.pdf | ||
21 | which has a description of the controller registers starting on | ||
22 | page 130. | ||
23 | |||
24 | Thanks to Felippe Mathieu-Daude for providing a cleaner method | ||
25 | of implementing the memory regions for the controller registers. | ||
26 | |||
27 | Signed-off-by: Paul Zimmerman <pauldzim@gmail.com> | ||
28 | Message-id: 20200520235349.21215-5-pauldzim@gmail.com | ||
29 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
14 | Message-id: 20181211151945.29137-4-aaron@os.amperecomputing.com | ||
30 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
31 | --- | 16 | --- |
32 | hw/usb/hcd-dwc2.c | 1417 ++++++++++++++++++++++++++++++++++++++++++ | 17 | target/arm/helper.c | 6 ++++-- |
33 | hw/usb/Kconfig | 5 + | 18 | target/arm/machine.c | 24 ++++++++++++++++++++++++ |
34 | hw/usb/Makefile.objs | 1 + | 19 | 2 files changed, 28 insertions(+), 2 deletions(-) |
35 | hw/usb/trace-events | 50 ++ | ||
36 | 4 files changed, 1473 insertions(+) | ||
37 | create mode 100644 hw/usb/hcd-dwc2.c | ||
38 | 20 | ||
39 | diff --git a/hw/usb/hcd-dwc2.c b/hw/usb/hcd-dwc2.c | 21 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
40 | new file mode 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
41 | index XXXXXXX..XXXXXXX | 23 | --- a/target/arm/helper.c |
42 | --- /dev/null | 24 | +++ b/target/arm/helper.c |
43 | +++ b/hw/usb/hcd-dwc2.c | 25 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = { |
44 | @@ -XXX,XX +XXX,XX @@ | 26 | .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 13, .opc2 = 0, |
45 | +/* | 27 | .access = PL0_RW, .accessfn = pmreg_access_ccntr, |
46 | + * dwc-hsotg (dwc2) USB host controller emulation | 28 | .type = ARM_CP_IO, |
47 | + * | 29 | - .readfn = pmccntr_read, .writefn = pmccntr_write, }, |
48 | + * Based on hw/usb/hcd-ehci.c and hw/usb/hcd-ohci.c | 30 | + .fieldoffset = offsetof(CPUARMState, cp15.c15_ccnt), |
49 | + * | 31 | + .readfn = pmccntr_read, .writefn = pmccntr_write, |
50 | + * Note that to use this emulation with the dwc-otg driver in the | 32 | + .raw_readfn = raw_read, .raw_writefn = raw_write, }, |
51 | + * Raspbian kernel, you must pass the option "dwc_otg.fiq_fsm_enable=0" | 33 | #endif |
52 | + * on the kernel command line. | 34 | { .name = "PMCCFILTR_EL0", .state = ARM_CP_STATE_AA64, |
53 | + * | 35 | .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 15, .opc2 = 7, |
54 | + * Some useful documentation used to develop this emulation can be | 36 | - .writefn = pmccfiltr_write, |
55 | + * found online (as of April 2020) at: | 37 | + .writefn = pmccfiltr_write, .raw_writefn = raw_write, |
56 | + * | 38 | .access = PL0_RW, .accessfn = pmreg_access, |
57 | + * http://www.capital-micro.com/PDF/CME-M7_Family_User_Guide_EN.pdf | 39 | .type = ARM_CP_IO, |
58 | + * which has a pretty complete description of the controller starting | 40 | .fieldoffset = offsetof(CPUARMState, cp15.pmccfiltr_el0), |
59 | + * on page 370. | 41 | diff --git a/target/arm/machine.c b/target/arm/machine.c |
60 | + * | 42 | index XXXXXXX..XXXXXXX 100644 |
61 | + * https://sourceforge.net/p/wive-ng/wive-ng-mt/ci/master/tree/docs/DataSheets/RT3050_5x_V2.0_081408_0902.pdf | 43 | --- a/target/arm/machine.c |
62 | + * which has a description of the controller registers starting on | 44 | +++ b/target/arm/machine.c |
63 | + * page 130. | 45 | @@ -XXX,XX +XXX,XX @@ static int cpu_pre_save(void *opaque) |
64 | + * | 46 | { |
65 | + * Copyright (c) 2020 Paul Zimmerman <pauldzim@gmail.com> | 47 | ARMCPU *cpu = opaque; |
66 | + * | 48 | |
67 | + * This program is free software; you can redistribute it and/or modify | 49 | + if (!kvm_enabled()) { |
68 | + * it under the terms of the GNU General Public License as published by | 50 | + pmu_op_start(&cpu->env); |
69 | + * the Free Software Foundation; either version 2 of the License, or | ||
70 | + * (at your option) any later version. | ||
71 | + * | ||
72 | + * This program is distributed in the hope that it will be useful, | ||
73 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
74 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
75 | + * GNU General Public License for more details. | ||
76 | + */ | ||
77 | + | ||
78 | +#include "qemu/osdep.h" | ||
79 | +#include "qemu/units.h" | ||
80 | +#include "qapi/error.h" | ||
81 | +#include "hw/usb/dwc2-regs.h" | ||
82 | +#include "hw/usb/hcd-dwc2.h" | ||
83 | +#include "migration/vmstate.h" | ||
84 | +#include "trace.h" | ||
85 | +#include "qemu/log.h" | ||
86 | +#include "qemu/error-report.h" | ||
87 | +#include "qemu/main-loop.h" | ||
88 | +#include "hw/qdev-properties.h" | ||
89 | + | ||
90 | +#define USB_HZ_FS 12000000 | ||
91 | +#define USB_HZ_HS 96000000 | ||
92 | +#define USB_FRMINTVL 12000 | ||
93 | + | ||
94 | +/* nifty macros from Arnon's EHCI version */ | ||
95 | +#define get_field(data, field) \ | ||
96 | + (((data) & field##_MASK) >> field##_SHIFT) | ||
97 | + | ||
98 | +#define set_field(data, newval, field) do { \ | ||
99 | + uint32_t val = *(data); \ | ||
100 | + val &= ~field##_MASK; \ | ||
101 | + val |= ((newval) << field##_SHIFT) & field##_MASK; \ | ||
102 | + *(data) = val; \ | ||
103 | +} while (0) | ||
104 | + | ||
105 | +#define get_bit(data, bitmask) \ | ||
106 | + (!!((data) & (bitmask))) | ||
107 | + | ||
108 | +/* update irq line */ | ||
109 | +static inline void dwc2_update_irq(DWC2State *s) | ||
110 | +{ | ||
111 | + static int oldlevel; | ||
112 | + int level = 0; | ||
113 | + | ||
114 | + if ((s->gintsts & s->gintmsk) && (s->gahbcfg & GAHBCFG_GLBL_INTR_EN)) { | ||
115 | + level = 1; | ||
116 | + } | ||
117 | + if (level != oldlevel) { | ||
118 | + oldlevel = level; | ||
119 | + trace_usb_dwc2_update_irq(level); | ||
120 | + qemu_set_irq(s->irq, level); | ||
121 | + } | ||
122 | +} | ||
123 | + | ||
124 | +/* flag interrupt condition */ | ||
125 | +static inline void dwc2_raise_global_irq(DWC2State *s, uint32_t intr) | ||
126 | +{ | ||
127 | + if (!(s->gintsts & intr)) { | ||
128 | + s->gintsts |= intr; | ||
129 | + trace_usb_dwc2_raise_global_irq(intr); | ||
130 | + dwc2_update_irq(s); | ||
131 | + } | ||
132 | +} | ||
133 | + | ||
134 | +static inline void dwc2_lower_global_irq(DWC2State *s, uint32_t intr) | ||
135 | +{ | ||
136 | + if (s->gintsts & intr) { | ||
137 | + s->gintsts &= ~intr; | ||
138 | + trace_usb_dwc2_lower_global_irq(intr); | ||
139 | + dwc2_update_irq(s); | ||
140 | + } | ||
141 | +} | ||
142 | + | ||
143 | +static inline void dwc2_raise_host_irq(DWC2State *s, uint32_t host_intr) | ||
144 | +{ | ||
145 | + if (!(s->haint & host_intr)) { | ||
146 | + s->haint |= host_intr; | ||
147 | + s->haint &= 0xffff; | ||
148 | + trace_usb_dwc2_raise_host_irq(host_intr); | ||
149 | + if (s->haint & s->haintmsk) { | ||
150 | + dwc2_raise_global_irq(s, GINTSTS_HCHINT); | ||
151 | + } | ||
152 | + } | ||
153 | +} | ||
154 | + | ||
155 | +static inline void dwc2_lower_host_irq(DWC2State *s, uint32_t host_intr) | ||
156 | +{ | ||
157 | + if (s->haint & host_intr) { | ||
158 | + s->haint &= ~host_intr; | ||
159 | + trace_usb_dwc2_lower_host_irq(host_intr); | ||
160 | + if (!(s->haint & s->haintmsk)) { | ||
161 | + dwc2_lower_global_irq(s, GINTSTS_HCHINT); | ||
162 | + } | ||
163 | + } | ||
164 | +} | ||
165 | + | ||
166 | +static inline void dwc2_update_hc_irq(DWC2State *s, int index) | ||
167 | +{ | ||
168 | + uint32_t host_intr = 1 << (index >> 3); | ||
169 | + | ||
170 | + if (s->hreg1[index + 2] & s->hreg1[index + 3]) { | ||
171 | + dwc2_raise_host_irq(s, host_intr); | ||
172 | + } else { | ||
173 | + dwc2_lower_host_irq(s, host_intr); | ||
174 | + } | ||
175 | +} | ||
176 | + | ||
177 | +/* set a timer for EOF */ | ||
178 | +static void dwc2_eof_timer(DWC2State *s) | ||
179 | +{ | ||
180 | + timer_mod(s->eof_timer, s->sof_time + s->usb_frame_time); | ||
181 | +} | ||
182 | + | ||
183 | +/* Set a timer for EOF and generate SOF event */ | ||
184 | +static void dwc2_sof(DWC2State *s) | ||
185 | +{ | ||
186 | + s->sof_time += s->usb_frame_time; | ||
187 | + trace_usb_dwc2_sof(s->sof_time); | ||
188 | + dwc2_eof_timer(s); | ||
189 | + dwc2_raise_global_irq(s, GINTSTS_SOF); | ||
190 | +} | ||
191 | + | ||
192 | +/* Do frame processing on frame boundary */ | ||
193 | +static void dwc2_frame_boundary(void *opaque) | ||
194 | +{ | ||
195 | + DWC2State *s = opaque; | ||
196 | + int64_t now; | ||
197 | + uint16_t frcnt; | ||
198 | + | ||
199 | + now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
200 | + | ||
201 | + /* Frame boundary, so do EOF stuff here */ | ||
202 | + | ||
203 | + /* Increment frame number */ | ||
204 | + frcnt = (uint16_t)((now - s->sof_time) / s->fi); | ||
205 | + s->frame_number = (s->frame_number + frcnt) & 0xffff; | ||
206 | + s->hfnum = s->frame_number & HFNUM_MAX_FRNUM; | ||
207 | + | ||
208 | + /* Do SOF stuff here */ | ||
209 | + dwc2_sof(s); | ||
210 | +} | ||
211 | + | ||
212 | +/* Start sending SOF tokens on the USB bus */ | ||
213 | +static void dwc2_bus_start(DWC2State *s) | ||
214 | +{ | ||
215 | + trace_usb_dwc2_bus_start(); | ||
216 | + s->sof_time = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
217 | + dwc2_eof_timer(s); | ||
218 | +} | ||
219 | + | ||
220 | +/* Stop sending SOF tokens on the USB bus */ | ||
221 | +static void dwc2_bus_stop(DWC2State *s) | ||
222 | +{ | ||
223 | + trace_usb_dwc2_bus_stop(); | ||
224 | + timer_del(s->eof_timer); | ||
225 | +} | ||
226 | + | ||
227 | +static USBDevice *dwc2_find_device(DWC2State *s, uint8_t addr) | ||
228 | +{ | ||
229 | + USBDevice *dev; | ||
230 | + | ||
231 | + trace_usb_dwc2_find_device(addr); | ||
232 | + | ||
233 | + if (!(s->hprt0 & HPRT0_ENA)) { | ||
234 | + trace_usb_dwc2_port_disabled(0); | ||
235 | + } else { | ||
236 | + dev = usb_find_device(&s->uport, addr); | ||
237 | + if (dev != NULL) { | ||
238 | + trace_usb_dwc2_device_found(0); | ||
239 | + return dev; | ||
240 | + } | ||
241 | + } | 51 | + } |
242 | + | 52 | + |
243 | + trace_usb_dwc2_device_not_found(); | 53 | if (kvm_enabled()) { |
244 | + return NULL; | 54 | if (!write_kvmstate_to_list(cpu)) { |
245 | +} | 55 | /* This should never fail */ |
56 | @@ -XXX,XX +XXX,XX @@ static int cpu_pre_save(void *opaque) | ||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | +static int cpu_post_save(void *opaque) | ||
61 | +{ | ||
62 | + ARMCPU *cpu = opaque; | ||
246 | + | 63 | + |
247 | +static const char *pstatus[] = { | 64 | + if (!kvm_enabled()) { |
248 | + "USB_RET_SUCCESS", "USB_RET_NODEV", "USB_RET_NAK", "USB_RET_STALL", | 65 | + pmu_op_finish(&cpu->env); |
249 | + "USB_RET_BABBLE", "USB_RET_IOERROR", "USB_RET_ASYNC", | ||
250 | + "USB_RET_ADD_TO_QUEUE", "USB_RET_REMOVE_FROM_QUEUE" | ||
251 | +}; | ||
252 | + | ||
253 | +static uint32_t pintr[] = { | ||
254 | + HCINTMSK_XFERCOMPL, HCINTMSK_XACTERR, HCINTMSK_NAK, HCINTMSK_STALL, | ||
255 | + HCINTMSK_BBLERR, HCINTMSK_XACTERR, HCINTMSK_XACTERR, HCINTMSK_XACTERR, | ||
256 | + HCINTMSK_XACTERR | ||
257 | +}; | ||
258 | + | ||
259 | +static const char *types[] = { | ||
260 | + "Ctrl", "Isoc", "Bulk", "Intr" | ||
261 | +}; | ||
262 | + | ||
263 | +static const char *dirs[] = { | ||
264 | + "Out", "In" | ||
265 | +}; | ||
266 | + | ||
267 | +static void dwc2_handle_packet(DWC2State *s, uint32_t devadr, USBDevice *dev, | ||
268 | + USBEndpoint *ep, uint32_t index, bool send) | ||
269 | +{ | ||
270 | + DWC2Packet *p; | ||
271 | + uint32_t hcchar = s->hreg1[index]; | ||
272 | + uint32_t hctsiz = s->hreg1[index + 4]; | ||
273 | + uint32_t hcdma = s->hreg1[index + 5]; | ||
274 | + uint32_t chan, epnum, epdir, eptype, mps, pid, pcnt, len, tlen, intr = 0; | ||
275 | + uint32_t tpcnt, stsidx, actual = 0; | ||
276 | + bool do_intr = false, done = false; | ||
277 | + | ||
278 | + epnum = get_field(hcchar, HCCHAR_EPNUM); | ||
279 | + epdir = get_bit(hcchar, HCCHAR_EPDIR); | ||
280 | + eptype = get_field(hcchar, HCCHAR_EPTYPE); | ||
281 | + mps = get_field(hcchar, HCCHAR_MPS); | ||
282 | + pid = get_field(hctsiz, TSIZ_SC_MC_PID); | ||
283 | + pcnt = get_field(hctsiz, TSIZ_PKTCNT); | ||
284 | + len = get_field(hctsiz, TSIZ_XFERSIZE); | ||
285 | + assert(len <= DWC2_MAX_XFER_SIZE); | ||
286 | + chan = index >> 3; | ||
287 | + p = &s->packet[chan]; | ||
288 | + | ||
289 | + trace_usb_dwc2_handle_packet(chan, dev, &p->packet, epnum, types[eptype], | ||
290 | + dirs[epdir], mps, len, pcnt); | ||
291 | + | ||
292 | + if (eptype == USB_ENDPOINT_XFER_CONTROL && pid == TSIZ_SC_MC_PID_SETUP) { | ||
293 | + pid = USB_TOKEN_SETUP; | ||
294 | + } else { | ||
295 | + pid = epdir ? USB_TOKEN_IN : USB_TOKEN_OUT; | ||
296 | + } | 66 | + } |
297 | + | 67 | + |
298 | + if (send) { | ||
299 | + tlen = len; | ||
300 | + if (p->small) { | ||
301 | + if (tlen > mps) { | ||
302 | + tlen = mps; | ||
303 | + } | ||
304 | + } | ||
305 | + | ||
306 | + if (pid != USB_TOKEN_IN) { | ||
307 | + trace_usb_dwc2_memory_read(hcdma, tlen); | ||
308 | + if (dma_memory_read(&s->dma_as, hcdma, | ||
309 | + s->usb_buf[chan], tlen) != MEMTX_OK) { | ||
310 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: dma_memory_read failed\n", | ||
311 | + __func__); | ||
312 | + } | ||
313 | + } | ||
314 | + | ||
315 | + usb_packet_init(&p->packet); | ||
316 | + usb_packet_setup(&p->packet, pid, ep, 0, hcdma, | ||
317 | + pid != USB_TOKEN_IN, true); | ||
318 | + usb_packet_addbuf(&p->packet, s->usb_buf[chan], tlen); | ||
319 | + p->async = DWC2_ASYNC_NONE; | ||
320 | + usb_handle_packet(dev, &p->packet); | ||
321 | + } else { | ||
322 | + tlen = p->len; | ||
323 | + } | ||
324 | + | ||
325 | + stsidx = -p->packet.status; | ||
326 | + assert(stsidx < sizeof(pstatus) / sizeof(*pstatus)); | ||
327 | + actual = p->packet.actual_length; | ||
328 | + trace_usb_dwc2_packet_status(pstatus[stsidx], actual); | ||
329 | + | ||
330 | +babble: | ||
331 | + if (p->packet.status != USB_RET_SUCCESS && | ||
332 | + p->packet.status != USB_RET_NAK && | ||
333 | + p->packet.status != USB_RET_STALL && | ||
334 | + p->packet.status != USB_RET_ASYNC) { | ||
335 | + trace_usb_dwc2_packet_error(pstatus[stsidx]); | ||
336 | + } | ||
337 | + | ||
338 | + if (p->packet.status == USB_RET_ASYNC) { | ||
339 | + trace_usb_dwc2_async_packet(&p->packet, chan, dev, epnum, | ||
340 | + dirs[epdir], tlen); | ||
341 | + usb_device_flush_ep_queue(dev, ep); | ||
342 | + assert(p->async != DWC2_ASYNC_INFLIGHT); | ||
343 | + p->devadr = devadr; | ||
344 | + p->epnum = epnum; | ||
345 | + p->epdir = epdir; | ||
346 | + p->mps = mps; | ||
347 | + p->pid = pid; | ||
348 | + p->index = index; | ||
349 | + p->pcnt = pcnt; | ||
350 | + p->len = tlen; | ||
351 | + p->async = DWC2_ASYNC_INFLIGHT; | ||
352 | + p->needs_service = false; | ||
353 | + return; | ||
354 | + } | ||
355 | + | ||
356 | + if (p->packet.status == USB_RET_SUCCESS) { | ||
357 | + if (actual > tlen) { | ||
358 | + p->packet.status = USB_RET_BABBLE; | ||
359 | + goto babble; | ||
360 | + } | ||
361 | + | ||
362 | + if (pid == USB_TOKEN_IN) { | ||
363 | + trace_usb_dwc2_memory_write(hcdma, actual); | ||
364 | + if (dma_memory_write(&s->dma_as, hcdma, s->usb_buf[chan], | ||
365 | + actual) != MEMTX_OK) { | ||
366 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: dma_memory_write failed\n", | ||
367 | + __func__); | ||
368 | + } | ||
369 | + } | ||
370 | + | ||
371 | + tpcnt = actual / mps; | ||
372 | + if (actual % mps) { | ||
373 | + tpcnt++; | ||
374 | + if (pid == USB_TOKEN_IN) { | ||
375 | + done = true; | ||
376 | + } | ||
377 | + } | ||
378 | + | ||
379 | + pcnt -= tpcnt < pcnt ? tpcnt : pcnt; | ||
380 | + set_field(&hctsiz, pcnt, TSIZ_PKTCNT); | ||
381 | + len -= actual < len ? actual : len; | ||
382 | + set_field(&hctsiz, len, TSIZ_XFERSIZE); | ||
383 | + s->hreg1[index + 4] = hctsiz; | ||
384 | + hcdma += actual; | ||
385 | + s->hreg1[index + 5] = hcdma; | ||
386 | + | ||
387 | + if (!pcnt || len == 0 || actual == 0) { | ||
388 | + done = true; | ||
389 | + } | ||
390 | + } else { | ||
391 | + intr |= pintr[stsidx]; | ||
392 | + if (p->packet.status == USB_RET_NAK && | ||
393 | + (eptype == USB_ENDPOINT_XFER_CONTROL || | ||
394 | + eptype == USB_ENDPOINT_XFER_BULK)) { | ||
395 | + /* | ||
396 | + * for ctrl/bulk, automatically retry on NAK, | ||
397 | + * but send the interrupt anyway | ||
398 | + */ | ||
399 | + intr &= ~HCINTMSK_RESERVED14_31; | ||
400 | + s->hreg1[index + 2] |= intr; | ||
401 | + do_intr = true; | ||
402 | + } else { | ||
403 | + intr |= HCINTMSK_CHHLTD; | ||
404 | + done = true; | ||
405 | + } | ||
406 | + } | ||
407 | + | ||
408 | + usb_packet_cleanup(&p->packet); | ||
409 | + | ||
410 | + if (done) { | ||
411 | + hcchar &= ~HCCHAR_CHENA; | ||
412 | + s->hreg1[index] = hcchar; | ||
413 | + if (!(intr & HCINTMSK_CHHLTD)) { | ||
414 | + intr |= HCINTMSK_CHHLTD | HCINTMSK_XFERCOMPL; | ||
415 | + } | ||
416 | + intr &= ~HCINTMSK_RESERVED14_31; | ||
417 | + s->hreg1[index + 2] |= intr; | ||
418 | + p->needs_service = false; | ||
419 | + trace_usb_dwc2_packet_done(pstatus[stsidx], actual, len, pcnt); | ||
420 | + dwc2_update_hc_irq(s, index); | ||
421 | + return; | ||
422 | + } | ||
423 | + | ||
424 | + p->devadr = devadr; | ||
425 | + p->epnum = epnum; | ||
426 | + p->epdir = epdir; | ||
427 | + p->mps = mps; | ||
428 | + p->pid = pid; | ||
429 | + p->index = index; | ||
430 | + p->pcnt = pcnt; | ||
431 | + p->len = len; | ||
432 | + p->needs_service = true; | ||
433 | + trace_usb_dwc2_packet_next(pstatus[stsidx], len, pcnt); | ||
434 | + if (do_intr) { | ||
435 | + dwc2_update_hc_irq(s, index); | ||
436 | + } | ||
437 | +} | ||
438 | + | ||
439 | +/* Attach or detach a device on root hub */ | ||
440 | + | ||
441 | +static const char *speeds[] = { | ||
442 | + "low", "full", "high" | ||
443 | +}; | ||
444 | + | ||
445 | +static void dwc2_attach(USBPort *port) | ||
446 | +{ | ||
447 | + DWC2State *s = port->opaque; | ||
448 | + int hispd = 0; | ||
449 | + | ||
450 | + trace_usb_dwc2_attach(port); | ||
451 | + assert(port->index == 0); | ||
452 | + | ||
453 | + if (!port->dev || !port->dev->attached) { | ||
454 | + return; | ||
455 | + } | ||
456 | + | ||
457 | + assert(port->dev->speed <= USB_SPEED_HIGH); | ||
458 | + trace_usb_dwc2_attach_speed(speeds[port->dev->speed]); | ||
459 | + s->hprt0 &= ~HPRT0_SPD_MASK; | ||
460 | + | ||
461 | + switch (port->dev->speed) { | ||
462 | + case USB_SPEED_LOW: | ||
463 | + s->hprt0 |= HPRT0_SPD_LOW_SPEED << HPRT0_SPD_SHIFT; | ||
464 | + break; | ||
465 | + case USB_SPEED_FULL: | ||
466 | + s->hprt0 |= HPRT0_SPD_FULL_SPEED << HPRT0_SPD_SHIFT; | ||
467 | + break; | ||
468 | + case USB_SPEED_HIGH: | ||
469 | + s->hprt0 |= HPRT0_SPD_HIGH_SPEED << HPRT0_SPD_SHIFT; | ||
470 | + hispd = 1; | ||
471 | + break; | ||
472 | + } | ||
473 | + | ||
474 | + if (hispd) { | ||
475 | + s->usb_frame_time = NANOSECONDS_PER_SECOND / 8000; /* 125000 */ | ||
476 | + if (NANOSECONDS_PER_SECOND >= USB_HZ_HS) { | ||
477 | + s->usb_bit_time = NANOSECONDS_PER_SECOND / USB_HZ_HS; /* 10.4 */ | ||
478 | + } else { | ||
479 | + s->usb_bit_time = 1; | ||
480 | + } | ||
481 | + } else { | ||
482 | + s->usb_frame_time = NANOSECONDS_PER_SECOND / 1000; /* 1000000 */ | ||
483 | + if (NANOSECONDS_PER_SECOND >= USB_HZ_FS) { | ||
484 | + s->usb_bit_time = NANOSECONDS_PER_SECOND / USB_HZ_FS; /* 83.3 */ | ||
485 | + } else { | ||
486 | + s->usb_bit_time = 1; | ||
487 | + } | ||
488 | + } | ||
489 | + | ||
490 | + s->fi = USB_FRMINTVL - 1; | ||
491 | + s->hprt0 |= HPRT0_CONNDET | HPRT0_CONNSTS; | ||
492 | + | ||
493 | + dwc2_bus_start(s); | ||
494 | + dwc2_raise_global_irq(s, GINTSTS_PRTINT); | ||
495 | +} | ||
496 | + | ||
497 | +static void dwc2_detach(USBPort *port) | ||
498 | +{ | ||
499 | + DWC2State *s = port->opaque; | ||
500 | + | ||
501 | + trace_usb_dwc2_detach(port); | ||
502 | + assert(port->index == 0); | ||
503 | + | ||
504 | + dwc2_bus_stop(s); | ||
505 | + | ||
506 | + s->hprt0 &= ~(HPRT0_SPD_MASK | HPRT0_SUSP | HPRT0_ENA | HPRT0_CONNSTS); | ||
507 | + s->hprt0 |= HPRT0_CONNDET | HPRT0_ENACHG; | ||
508 | + | ||
509 | + dwc2_raise_global_irq(s, GINTSTS_PRTINT); | ||
510 | +} | ||
511 | + | ||
512 | +static void dwc2_child_detach(USBPort *port, USBDevice *child) | ||
513 | +{ | ||
514 | + trace_usb_dwc2_child_detach(port, child); | ||
515 | + assert(port->index == 0); | ||
516 | +} | ||
517 | + | ||
518 | +static void dwc2_wakeup(USBPort *port) | ||
519 | +{ | ||
520 | + DWC2State *s = port->opaque; | ||
521 | + | ||
522 | + trace_usb_dwc2_wakeup(port); | ||
523 | + assert(port->index == 0); | ||
524 | + | ||
525 | + if (s->hprt0 & HPRT0_SUSP) { | ||
526 | + s->hprt0 |= HPRT0_RES; | ||
527 | + dwc2_raise_global_irq(s, GINTSTS_PRTINT); | ||
528 | + } | ||
529 | + | ||
530 | + qemu_bh_schedule(s->async_bh); | ||
531 | +} | ||
532 | + | ||
533 | +static void dwc2_async_packet_complete(USBPort *port, USBPacket *packet) | ||
534 | +{ | ||
535 | + DWC2State *s = port->opaque; | ||
536 | + DWC2Packet *p; | ||
537 | + USBDevice *dev; | ||
538 | + USBEndpoint *ep; | ||
539 | + | ||
540 | + assert(port->index == 0); | ||
541 | + p = container_of(packet, DWC2Packet, packet); | ||
542 | + dev = dwc2_find_device(s, p->devadr); | ||
543 | + ep = usb_ep_get(dev, p->pid, p->epnum); | ||
544 | + trace_usb_dwc2_async_packet_complete(port, packet, p->index >> 3, dev, | ||
545 | + p->epnum, dirs[p->epdir], p->len); | ||
546 | + assert(p->async == DWC2_ASYNC_INFLIGHT); | ||
547 | + | ||
548 | + if (packet->status == USB_RET_REMOVE_FROM_QUEUE) { | ||
549 | + usb_cancel_packet(packet); | ||
550 | + usb_packet_cleanup(packet); | ||
551 | + return; | ||
552 | + } | ||
553 | + | ||
554 | + dwc2_handle_packet(s, p->devadr, dev, ep, p->index, false); | ||
555 | + | ||
556 | + p->async = DWC2_ASYNC_FINISHED; | ||
557 | + qemu_bh_schedule(s->async_bh); | ||
558 | +} | ||
559 | + | ||
560 | +static USBPortOps dwc2_port_ops = { | ||
561 | + .attach = dwc2_attach, | ||
562 | + .detach = dwc2_detach, | ||
563 | + .child_detach = dwc2_child_detach, | ||
564 | + .wakeup = dwc2_wakeup, | ||
565 | + .complete = dwc2_async_packet_complete, | ||
566 | +}; | ||
567 | + | ||
568 | +static uint32_t dwc2_get_frame_remaining(DWC2State *s) | ||
569 | +{ | ||
570 | + uint32_t fr = 0; | ||
571 | + int64_t tks; | ||
572 | + | ||
573 | + tks = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) - s->sof_time; | ||
574 | + if (tks < 0) { | ||
575 | + tks = 0; | ||
576 | + } | ||
577 | + | ||
578 | + /* avoid muldiv if possible */ | ||
579 | + if (tks >= s->usb_frame_time) { | ||
580 | + goto out; | ||
581 | + } | ||
582 | + if (tks < s->usb_bit_time) { | ||
583 | + fr = s->fi; | ||
584 | + goto out; | ||
585 | + } | ||
586 | + | ||
587 | + /* tks = number of ns since SOF, divided by 83 (fs) or 10 (hs) */ | ||
588 | + tks = tks / s->usb_bit_time; | ||
589 | + if (tks >= (int64_t)s->fi) { | ||
590 | + goto out; | ||
591 | + } | ||
592 | + | ||
593 | + /* remaining = frame interval minus tks */ | ||
594 | + fr = (uint32_t)((int64_t)s->fi - tks); | ||
595 | + | ||
596 | +out: | ||
597 | + return fr; | ||
598 | +} | ||
599 | + | ||
600 | +static void dwc2_work_bh(void *opaque) | ||
601 | +{ | ||
602 | + DWC2State *s = opaque; | ||
603 | + DWC2Packet *p; | ||
604 | + USBDevice *dev; | ||
605 | + USBEndpoint *ep; | ||
606 | + int64_t t_now, expire_time; | ||
607 | + int chan; | ||
608 | + bool found = false; | ||
609 | + | ||
610 | + trace_usb_dwc2_work_bh(); | ||
611 | + if (s->working) { | ||
612 | + return; | ||
613 | + } | ||
614 | + s->working = true; | ||
615 | + | ||
616 | + t_now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL); | ||
617 | + chan = s->next_chan; | ||
618 | + | ||
619 | + do { | ||
620 | + p = &s->packet[chan]; | ||
621 | + if (p->needs_service) { | ||
622 | + dev = dwc2_find_device(s, p->devadr); | ||
623 | + ep = usb_ep_get(dev, p->pid, p->epnum); | ||
624 | + trace_usb_dwc2_work_bh_service(s->next_chan, chan, dev, p->epnum); | ||
625 | + dwc2_handle_packet(s, p->devadr, dev, ep, p->index, true); | ||
626 | + found = true; | ||
627 | + } | ||
628 | + if (++chan == DWC2_NB_CHAN) { | ||
629 | + chan = 0; | ||
630 | + } | ||
631 | + if (found) { | ||
632 | + s->next_chan = chan; | ||
633 | + trace_usb_dwc2_work_bh_next(chan); | ||
634 | + } | ||
635 | + } while (chan != s->next_chan); | ||
636 | + | ||
637 | + if (found) { | ||
638 | + expire_time = t_now + NANOSECONDS_PER_SECOND / 4000; | ||
639 | + timer_mod(s->frame_timer, expire_time); | ||
640 | + } | ||
641 | + s->working = false; | ||
642 | +} | ||
643 | + | ||
644 | +static void dwc2_enable_chan(DWC2State *s, uint32_t index) | ||
645 | +{ | ||
646 | + USBDevice *dev; | ||
647 | + USBEndpoint *ep; | ||
648 | + uint32_t hcchar; | ||
649 | + uint32_t hctsiz; | ||
650 | + uint32_t devadr, epnum, epdir, eptype, pid, len; | ||
651 | + DWC2Packet *p; | ||
652 | + | ||
653 | + assert((index >> 3) < DWC2_NB_CHAN); | ||
654 | + p = &s->packet[index >> 3]; | ||
655 | + hcchar = s->hreg1[index]; | ||
656 | + hctsiz = s->hreg1[index + 4]; | ||
657 | + devadr = get_field(hcchar, HCCHAR_DEVADDR); | ||
658 | + epnum = get_field(hcchar, HCCHAR_EPNUM); | ||
659 | + epdir = get_bit(hcchar, HCCHAR_EPDIR); | ||
660 | + eptype = get_field(hcchar, HCCHAR_EPTYPE); | ||
661 | + pid = get_field(hctsiz, TSIZ_SC_MC_PID); | ||
662 | + len = get_field(hctsiz, TSIZ_XFERSIZE); | ||
663 | + | ||
664 | + dev = dwc2_find_device(s, devadr); | ||
665 | + | ||
666 | + trace_usb_dwc2_enable_chan(index >> 3, dev, &p->packet, epnum); | ||
667 | + if (dev == NULL) { | ||
668 | + return; | ||
669 | + } | ||
670 | + | ||
671 | + if (eptype == USB_ENDPOINT_XFER_CONTROL && pid == TSIZ_SC_MC_PID_SETUP) { | ||
672 | + pid = USB_TOKEN_SETUP; | ||
673 | + } else { | ||
674 | + pid = epdir ? USB_TOKEN_IN : USB_TOKEN_OUT; | ||
675 | + } | ||
676 | + | ||
677 | + ep = usb_ep_get(dev, pid, epnum); | ||
678 | + | ||
679 | + /* | ||
680 | + * Hack: Networking doesn't like us delivering large transfers, it kind | ||
681 | + * of works but the latency is horrible. So if the transfer is <= the mtu | ||
682 | + * size, we take that as a hint that this might be a network transfer, | ||
683 | + * and do the transfer packet-by-packet. | ||
684 | + */ | ||
685 | + if (len > 1536) { | ||
686 | + p->small = false; | ||
687 | + } else { | ||
688 | + p->small = true; | ||
689 | + } | ||
690 | + | ||
691 | + dwc2_handle_packet(s, devadr, dev, ep, index, true); | ||
692 | + qemu_bh_schedule(s->async_bh); | ||
693 | +} | ||
694 | + | ||
695 | +static const char *glbregnm[] = { | ||
696 | + "GOTGCTL ", "GOTGINT ", "GAHBCFG ", "GUSBCFG ", "GRSTCTL ", | ||
697 | + "GINTSTS ", "GINTMSK ", "GRXSTSR ", "GRXSTSP ", "GRXFSIZ ", | ||
698 | + "GNPTXFSIZ", "GNPTXSTS ", "GI2CCTL ", "GPVNDCTL ", "GGPIO ", | ||
699 | + "GUID ", "GSNPSID ", "GHWCFG1 ", "GHWCFG2 ", "GHWCFG3 ", | ||
700 | + "GHWCFG4 ", "GLPMCFG ", "GPWRDN ", "GDFIFOCFG", "GADPCTL ", | ||
701 | + "GREFCLK ", "GINTMSK2 ", "GINTSTS2 " | ||
702 | +}; | ||
703 | + | ||
704 | +static uint64_t dwc2_glbreg_read(void *ptr, hwaddr addr, int index, | ||
705 | + unsigned size) | ||
706 | +{ | ||
707 | + DWC2State *s = ptr; | ||
708 | + uint32_t val; | ||
709 | + | ||
710 | + assert(addr <= GINTSTS2); | ||
711 | + val = s->glbreg[index]; | ||
712 | + | ||
713 | + switch (addr) { | ||
714 | + case GRSTCTL: | ||
715 | + /* clear any self-clearing bits that were set */ | ||
716 | + val &= ~(GRSTCTL_TXFFLSH | GRSTCTL_RXFFLSH | GRSTCTL_IN_TKNQ_FLSH | | ||
717 | + GRSTCTL_FRMCNTRRST | GRSTCTL_HSFTRST | GRSTCTL_CSFTRST); | ||
718 | + s->glbreg[index] = val; | ||
719 | + break; | ||
720 | + default: | ||
721 | + break; | ||
722 | + } | ||
723 | + | ||
724 | + trace_usb_dwc2_glbreg_read(addr, glbregnm[index], val); | ||
725 | + return val; | ||
726 | +} | ||
727 | + | ||
728 | +static void dwc2_glbreg_write(void *ptr, hwaddr addr, int index, uint64_t val, | ||
729 | + unsigned size) | ||
730 | +{ | ||
731 | + DWC2State *s = ptr; | ||
732 | + uint64_t orig = val; | ||
733 | + uint32_t *mmio; | ||
734 | + uint32_t old; | ||
735 | + int iflg = 0; | ||
736 | + | ||
737 | + assert(addr <= GINTSTS2); | ||
738 | + mmio = &s->glbreg[index]; | ||
739 | + old = *mmio; | ||
740 | + | ||
741 | + switch (addr) { | ||
742 | + case GOTGCTL: | ||
743 | + /* don't allow setting of read-only bits */ | ||
744 | + val &= ~(GOTGCTL_MULT_VALID_BC_MASK | GOTGCTL_BSESVLD | | ||
745 | + GOTGCTL_ASESVLD | GOTGCTL_DBNC_SHORT | GOTGCTL_CONID_B | | ||
746 | + GOTGCTL_HSTNEGSCS | GOTGCTL_SESREQSCS); | ||
747 | + /* don't allow clearing of read-only bits */ | ||
748 | + val |= old & (GOTGCTL_MULT_VALID_BC_MASK | GOTGCTL_BSESVLD | | ||
749 | + GOTGCTL_ASESVLD | GOTGCTL_DBNC_SHORT | GOTGCTL_CONID_B | | ||
750 | + GOTGCTL_HSTNEGSCS | GOTGCTL_SESREQSCS); | ||
751 | + break; | ||
752 | + case GAHBCFG: | ||
753 | + if ((val & GAHBCFG_GLBL_INTR_EN) && !(old & GAHBCFG_GLBL_INTR_EN)) { | ||
754 | + iflg = 1; | ||
755 | + } | ||
756 | + break; | ||
757 | + case GRSTCTL: | ||
758 | + val |= GRSTCTL_AHBIDLE; | ||
759 | + val &= ~GRSTCTL_DMAREQ; | ||
760 | + if (!(old & GRSTCTL_TXFFLSH) && (val & GRSTCTL_TXFFLSH)) { | ||
761 | + /* TODO - TX fifo flush */ | ||
762 | + qemu_log_mask(LOG_UNIMP, "Tx FIFO flush not implemented\n"); | ||
763 | + } | ||
764 | + if (!(old & GRSTCTL_RXFFLSH) && (val & GRSTCTL_RXFFLSH)) { | ||
765 | + /* TODO - RX fifo flush */ | ||
766 | + qemu_log_mask(LOG_UNIMP, "Rx FIFO flush not implemented\n"); | ||
767 | + } | ||
768 | + if (!(old & GRSTCTL_IN_TKNQ_FLSH) && (val & GRSTCTL_IN_TKNQ_FLSH)) { | ||
769 | + /* TODO - device IN token queue flush */ | ||
770 | + qemu_log_mask(LOG_UNIMP, "Token queue flush not implemented\n"); | ||
771 | + } | ||
772 | + if (!(old & GRSTCTL_FRMCNTRRST) && (val & GRSTCTL_FRMCNTRRST)) { | ||
773 | + /* TODO - host frame counter reset */ | ||
774 | + qemu_log_mask(LOG_UNIMP, "Frame counter reset not implemented\n"); | ||
775 | + } | ||
776 | + if (!(old & GRSTCTL_HSFTRST) && (val & GRSTCTL_HSFTRST)) { | ||
777 | + /* TODO - host soft reset */ | ||
778 | + qemu_log_mask(LOG_UNIMP, "Host soft reset not implemented\n"); | ||
779 | + } | ||
780 | + if (!(old & GRSTCTL_CSFTRST) && (val & GRSTCTL_CSFTRST)) { | ||
781 | + /* TODO - core soft reset */ | ||
782 | + qemu_log_mask(LOG_UNIMP, "Core soft reset not implemented\n"); | ||
783 | + } | ||
784 | + /* don't allow clearing of self-clearing bits */ | ||
785 | + val |= old & (GRSTCTL_TXFFLSH | GRSTCTL_RXFFLSH | | ||
786 | + GRSTCTL_IN_TKNQ_FLSH | GRSTCTL_FRMCNTRRST | | ||
787 | + GRSTCTL_HSFTRST | GRSTCTL_CSFTRST); | ||
788 | + break; | ||
789 | + case GINTSTS: | ||
790 | + /* clear the write-1-to-clear bits */ | ||
791 | + val |= ~old; | ||
792 | + val = ~val; | ||
793 | + /* don't allow clearing of read-only bits */ | ||
794 | + val |= old & (GINTSTS_PTXFEMP | GINTSTS_HCHINT | GINTSTS_PRTINT | | ||
795 | + GINTSTS_OEPINT | GINTSTS_IEPINT | GINTSTS_GOUTNAKEFF | | ||
796 | + GINTSTS_GINNAKEFF | GINTSTS_NPTXFEMP | GINTSTS_RXFLVL | | ||
797 | + GINTSTS_OTGINT | GINTSTS_CURMODE_HOST); | ||
798 | + iflg = 1; | ||
799 | + break; | ||
800 | + case GINTMSK: | ||
801 | + iflg = 1; | ||
802 | + break; | ||
803 | + default: | ||
804 | + break; | ||
805 | + } | ||
806 | + | ||
807 | + trace_usb_dwc2_glbreg_write(addr, glbregnm[index], orig, old, val); | ||
808 | + *mmio = val; | ||
809 | + | ||
810 | + if (iflg) { | ||
811 | + dwc2_update_irq(s); | ||
812 | + } | ||
813 | +} | ||
814 | + | ||
815 | +static uint64_t dwc2_fszreg_read(void *ptr, hwaddr addr, int index, | ||
816 | + unsigned size) | ||
817 | +{ | ||
818 | + DWC2State *s = ptr; | ||
819 | + uint32_t val; | ||
820 | + | ||
821 | + assert(addr == HPTXFSIZ); | ||
822 | + val = s->fszreg[index]; | ||
823 | + | ||
824 | + trace_usb_dwc2_fszreg_read(addr, val); | ||
825 | + return val; | ||
826 | +} | ||
827 | + | ||
828 | +static void dwc2_fszreg_write(void *ptr, hwaddr addr, int index, uint64_t val, | ||
829 | + unsigned size) | ||
830 | +{ | ||
831 | + DWC2State *s = ptr; | ||
832 | + uint64_t orig = val; | ||
833 | + uint32_t *mmio; | ||
834 | + uint32_t old; | ||
835 | + | ||
836 | + assert(addr == HPTXFSIZ); | ||
837 | + mmio = &s->fszreg[index]; | ||
838 | + old = *mmio; | ||
839 | + | ||
840 | + trace_usb_dwc2_fszreg_write(addr, orig, old, val); | ||
841 | + *mmio = val; | ||
842 | +} | ||
843 | + | ||
844 | +static const char *hreg0nm[] = { | ||
845 | + "HCFG ", "HFIR ", "HFNUM ", "<rsvd> ", "HPTXSTS ", | ||
846 | + "HAINT ", "HAINTMSK ", "HFLBADDR ", "<rsvd> ", "<rsvd> ", | ||
847 | + "<rsvd> ", "<rsvd> ", "<rsvd> ", "<rsvd> ", "<rsvd> ", | ||
848 | + "<rsvd> ", "HPRT0 " | ||
849 | +}; | ||
850 | + | ||
851 | +static uint64_t dwc2_hreg0_read(void *ptr, hwaddr addr, int index, | ||
852 | + unsigned size) | ||
853 | +{ | ||
854 | + DWC2State *s = ptr; | ||
855 | + uint32_t val; | ||
856 | + | ||
857 | + assert(addr >= HCFG && addr <= HPRT0); | ||
858 | + val = s->hreg0[index]; | ||
859 | + | ||
860 | + switch (addr) { | ||
861 | + case HFNUM: | ||
862 | + val = (dwc2_get_frame_remaining(s) << HFNUM_FRREM_SHIFT) | | ||
863 | + (s->hfnum << HFNUM_FRNUM_SHIFT); | ||
864 | + break; | ||
865 | + default: | ||
866 | + break; | ||
867 | + } | ||
868 | + | ||
869 | + trace_usb_dwc2_hreg0_read(addr, hreg0nm[index], val); | ||
870 | + return val; | ||
871 | +} | ||
872 | + | ||
873 | +static void dwc2_hreg0_write(void *ptr, hwaddr addr, int index, uint64_t val, | ||
874 | + unsigned size) | ||
875 | +{ | ||
876 | + DWC2State *s = ptr; | ||
877 | + USBDevice *dev = s->uport.dev; | ||
878 | + uint64_t orig = val; | ||
879 | + uint32_t *mmio; | ||
880 | + uint32_t tval, told, old; | ||
881 | + int prst = 0; | ||
882 | + int iflg = 0; | ||
883 | + | ||
884 | + assert(addr >= HCFG && addr <= HPRT0); | ||
885 | + mmio = &s->hreg0[index]; | ||
886 | + old = *mmio; | ||
887 | + | ||
888 | + switch (addr) { | ||
889 | + case HFIR: | ||
890 | + break; | ||
891 | + case HFNUM: | ||
892 | + case HPTXSTS: | ||
893 | + case HAINT: | ||
894 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: write to read-only register\n", | ||
895 | + __func__); | ||
896 | + return; | ||
897 | + case HAINTMSK: | ||
898 | + val &= 0xffff; | ||
899 | + break; | ||
900 | + case HPRT0: | ||
901 | + /* don't allow clearing of read-only bits */ | ||
902 | + val |= old & (HPRT0_SPD_MASK | HPRT0_LNSTS_MASK | HPRT0_OVRCURRACT | | ||
903 | + HPRT0_CONNSTS); | ||
904 | + /* don't allow clearing of self-clearing bits */ | ||
905 | + val |= old & (HPRT0_SUSP | HPRT0_RES); | ||
906 | + /* don't allow setting of self-setting bits */ | ||
907 | + if (!(old & HPRT0_ENA) && (val & HPRT0_ENA)) { | ||
908 | + val &= ~HPRT0_ENA; | ||
909 | + } | ||
910 | + /* clear the write-1-to-clear bits */ | ||
911 | + tval = val & (HPRT0_OVRCURRCHG | HPRT0_ENACHG | HPRT0_ENA | | ||
912 | + HPRT0_CONNDET); | ||
913 | + told = old & (HPRT0_OVRCURRCHG | HPRT0_ENACHG | HPRT0_ENA | | ||
914 | + HPRT0_CONNDET); | ||
915 | + tval |= ~told; | ||
916 | + tval = ~tval; | ||
917 | + tval &= (HPRT0_OVRCURRCHG | HPRT0_ENACHG | HPRT0_ENA | | ||
918 | + HPRT0_CONNDET); | ||
919 | + val &= ~(HPRT0_OVRCURRCHG | HPRT0_ENACHG | HPRT0_ENA | | ||
920 | + HPRT0_CONNDET); | ||
921 | + val |= tval; | ||
922 | + if (!(val & HPRT0_RST) && (old & HPRT0_RST)) { | ||
923 | + if (dev && dev->attached) { | ||
924 | + val |= HPRT0_ENA | HPRT0_ENACHG; | ||
925 | + prst = 1; | ||
926 | + } | ||
927 | + } | ||
928 | + if (val & (HPRT0_OVRCURRCHG | HPRT0_ENACHG | HPRT0_CONNDET)) { | ||
929 | + iflg = 1; | ||
930 | + } else { | ||
931 | + iflg = -1; | ||
932 | + } | ||
933 | + break; | ||
934 | + default: | ||
935 | + break; | ||
936 | + } | ||
937 | + | ||
938 | + if (prst) { | ||
939 | + trace_usb_dwc2_hreg0_write(addr, hreg0nm[index], orig, old, | ||
940 | + val & ~HPRT0_CONNDET); | ||
941 | + trace_usb_dwc2_hreg0_action("call usb_port_reset"); | ||
942 | + usb_port_reset(&s->uport); | ||
943 | + val &= ~HPRT0_CONNDET; | ||
944 | + } else { | ||
945 | + trace_usb_dwc2_hreg0_write(addr, hreg0nm[index], orig, old, val); | ||
946 | + } | ||
947 | + | ||
948 | + *mmio = val; | ||
949 | + | ||
950 | + if (iflg > 0) { | ||
951 | + trace_usb_dwc2_hreg0_action("enable PRTINT"); | ||
952 | + dwc2_raise_global_irq(s, GINTSTS_PRTINT); | ||
953 | + } else if (iflg < 0) { | ||
954 | + trace_usb_dwc2_hreg0_action("disable PRTINT"); | ||
955 | + dwc2_lower_global_irq(s, GINTSTS_PRTINT); | ||
956 | + } | ||
957 | +} | ||
958 | + | ||
959 | +static const char *hreg1nm[] = { | ||
960 | + "HCCHAR ", "HCSPLT ", "HCINT ", "HCINTMSK", "HCTSIZ ", "HCDMA ", | ||
961 | + "<rsvd> ", "HCDMAB " | ||
962 | +}; | ||
963 | + | ||
964 | +static uint64_t dwc2_hreg1_read(void *ptr, hwaddr addr, int index, | ||
965 | + unsigned size) | ||
966 | +{ | ||
967 | + DWC2State *s = ptr; | ||
968 | + uint32_t val; | ||
969 | + | ||
970 | + assert(addr >= HCCHAR(0) && addr <= HCDMAB(DWC2_NB_CHAN - 1)); | ||
971 | + val = s->hreg1[index]; | ||
972 | + | ||
973 | + trace_usb_dwc2_hreg1_read(addr, hreg1nm[index & 7], addr >> 5, val); | ||
974 | + return val; | ||
975 | +} | ||
976 | + | ||
977 | +static void dwc2_hreg1_write(void *ptr, hwaddr addr, int index, uint64_t val, | ||
978 | + unsigned size) | ||
979 | +{ | ||
980 | + DWC2State *s = ptr; | ||
981 | + uint64_t orig = val; | ||
982 | + uint32_t *mmio; | ||
983 | + uint32_t old; | ||
984 | + int iflg = 0; | ||
985 | + int enflg = 0; | ||
986 | + int disflg = 0; | ||
987 | + | ||
988 | + assert(addr >= HCCHAR(0) && addr <= HCDMAB(DWC2_NB_CHAN - 1)); | ||
989 | + mmio = &s->hreg1[index]; | ||
990 | + old = *mmio; | ||
991 | + | ||
992 | + switch (HSOTG_REG(0x500) + (addr & 0x1c)) { | ||
993 | + case HCCHAR(0): | ||
994 | + if ((val & HCCHAR_CHDIS) && !(old & HCCHAR_CHDIS)) { | ||
995 | + val &= ~(HCCHAR_CHENA | HCCHAR_CHDIS); | ||
996 | + disflg = 1; | ||
997 | + } else { | ||
998 | + val |= old & HCCHAR_CHDIS; | ||
999 | + if ((val & HCCHAR_CHENA) && !(old & HCCHAR_CHENA)) { | ||
1000 | + val &= ~HCCHAR_CHDIS; | ||
1001 | + enflg = 1; | ||
1002 | + } else { | ||
1003 | + val |= old & HCCHAR_CHENA; | ||
1004 | + } | ||
1005 | + } | ||
1006 | + break; | ||
1007 | + case HCINT(0): | ||
1008 | + /* clear the write-1-to-clear bits */ | ||
1009 | + val |= ~old; | ||
1010 | + val = ~val; | ||
1011 | + val &= ~HCINTMSK_RESERVED14_31; | ||
1012 | + iflg = 1; | ||
1013 | + break; | ||
1014 | + case HCINTMSK(0): | ||
1015 | + val &= ~HCINTMSK_RESERVED14_31; | ||
1016 | + iflg = 1; | ||
1017 | + break; | ||
1018 | + case HCDMAB(0): | ||
1019 | + qemu_log_mask(LOG_GUEST_ERROR, "%s: write to read-only register\n", | ||
1020 | + __func__); | ||
1021 | + return; | ||
1022 | + default: | ||
1023 | + break; | ||
1024 | + } | ||
1025 | + | ||
1026 | + trace_usb_dwc2_hreg1_write(addr, hreg1nm[index & 7], index >> 3, orig, | ||
1027 | + old, val); | ||
1028 | + *mmio = val; | ||
1029 | + | ||
1030 | + if (disflg) { | ||
1031 | + /* set ChHltd in HCINT */ | ||
1032 | + s->hreg1[(index & ~7) + 2] |= HCINTMSK_CHHLTD; | ||
1033 | + iflg = 1; | ||
1034 | + } | ||
1035 | + | ||
1036 | + if (enflg) { | ||
1037 | + dwc2_enable_chan(s, index & ~7); | ||
1038 | + } | ||
1039 | + | ||
1040 | + if (iflg) { | ||
1041 | + dwc2_update_hc_irq(s, index & ~7); | ||
1042 | + } | ||
1043 | +} | ||
1044 | + | ||
1045 | +static const char *pcgregnm[] = { | ||
1046 | + "PCGCTL ", "PCGCCTL1 " | ||
1047 | +}; | ||
1048 | + | ||
1049 | +static uint64_t dwc2_pcgreg_read(void *ptr, hwaddr addr, int index, | ||
1050 | + unsigned size) | ||
1051 | +{ | ||
1052 | + DWC2State *s = ptr; | ||
1053 | + uint32_t val; | ||
1054 | + | ||
1055 | + assert(addr >= PCGCTL && addr <= PCGCCTL1); | ||
1056 | + val = s->pcgreg[index]; | ||
1057 | + | ||
1058 | + trace_usb_dwc2_pcgreg_read(addr, pcgregnm[index], val); | ||
1059 | + return val; | ||
1060 | +} | ||
1061 | + | ||
1062 | +static void dwc2_pcgreg_write(void *ptr, hwaddr addr, int index, | ||
1063 | + uint64_t val, unsigned size) | ||
1064 | +{ | ||
1065 | + DWC2State *s = ptr; | ||
1066 | + uint64_t orig = val; | ||
1067 | + uint32_t *mmio; | ||
1068 | + uint32_t old; | ||
1069 | + | ||
1070 | + assert(addr >= PCGCTL && addr <= PCGCCTL1); | ||
1071 | + mmio = &s->pcgreg[index]; | ||
1072 | + old = *mmio; | ||
1073 | + | ||
1074 | + trace_usb_dwc2_pcgreg_write(addr, pcgregnm[index], orig, old, val); | ||
1075 | + *mmio = val; | ||
1076 | +} | ||
1077 | + | ||
1078 | +static uint64_t dwc2_hsotg_read(void *ptr, hwaddr addr, unsigned size) | ||
1079 | +{ | ||
1080 | + uint64_t val; | ||
1081 | + | ||
1082 | + switch (addr) { | ||
1083 | + case HSOTG_REG(0x000) ... HSOTG_REG(0x0fc): | ||
1084 | + val = dwc2_glbreg_read(ptr, addr, (addr - HSOTG_REG(0x000)) >> 2, size); | ||
1085 | + break; | ||
1086 | + case HSOTG_REG(0x100): | ||
1087 | + val = dwc2_fszreg_read(ptr, addr, (addr - HSOTG_REG(0x100)) >> 2, size); | ||
1088 | + break; | ||
1089 | + case HSOTG_REG(0x104) ... HSOTG_REG(0x3fc): | ||
1090 | + /* Gadget-mode registers, just return 0 for now */ | ||
1091 | + val = 0; | ||
1092 | + break; | ||
1093 | + case HSOTG_REG(0x400) ... HSOTG_REG(0x4fc): | ||
1094 | + val = dwc2_hreg0_read(ptr, addr, (addr - HSOTG_REG(0x400)) >> 2, size); | ||
1095 | + break; | ||
1096 | + case HSOTG_REG(0x500) ... HSOTG_REG(0x7fc): | ||
1097 | + val = dwc2_hreg1_read(ptr, addr, (addr - HSOTG_REG(0x500)) >> 2, size); | ||
1098 | + break; | ||
1099 | + case HSOTG_REG(0x800) ... HSOTG_REG(0xdfc): | ||
1100 | + /* Gadget-mode registers, just return 0 for now */ | ||
1101 | + val = 0; | ||
1102 | + break; | ||
1103 | + case HSOTG_REG(0xe00) ... HSOTG_REG(0xffc): | ||
1104 | + val = dwc2_pcgreg_read(ptr, addr, (addr - HSOTG_REG(0xe00)) >> 2, size); | ||
1105 | + break; | ||
1106 | + default: | ||
1107 | + g_assert_not_reached(); | ||
1108 | + } | ||
1109 | + | ||
1110 | + return val; | ||
1111 | +} | ||
1112 | + | ||
1113 | +static void dwc2_hsotg_write(void *ptr, hwaddr addr, uint64_t val, | ||
1114 | + unsigned size) | ||
1115 | +{ | ||
1116 | + switch (addr) { | ||
1117 | + case HSOTG_REG(0x000) ... HSOTG_REG(0x0fc): | ||
1118 | + dwc2_glbreg_write(ptr, addr, (addr - HSOTG_REG(0x000)) >> 2, val, size); | ||
1119 | + break; | ||
1120 | + case HSOTG_REG(0x100): | ||
1121 | + dwc2_fszreg_write(ptr, addr, (addr - HSOTG_REG(0x100)) >> 2, val, size); | ||
1122 | + break; | ||
1123 | + case HSOTG_REG(0x104) ... HSOTG_REG(0x3fc): | ||
1124 | + /* Gadget-mode registers, do nothing for now */ | ||
1125 | + break; | ||
1126 | + case HSOTG_REG(0x400) ... HSOTG_REG(0x4fc): | ||
1127 | + dwc2_hreg0_write(ptr, addr, (addr - HSOTG_REG(0x400)) >> 2, val, size); | ||
1128 | + break; | ||
1129 | + case HSOTG_REG(0x500) ... HSOTG_REG(0x7fc): | ||
1130 | + dwc2_hreg1_write(ptr, addr, (addr - HSOTG_REG(0x500)) >> 2, val, size); | ||
1131 | + break; | ||
1132 | + case HSOTG_REG(0x800) ... HSOTG_REG(0xdfc): | ||
1133 | + /* Gadget-mode registers, do nothing for now */ | ||
1134 | + break; | ||
1135 | + case HSOTG_REG(0xe00) ... HSOTG_REG(0xffc): | ||
1136 | + dwc2_pcgreg_write(ptr, addr, (addr - HSOTG_REG(0xe00)) >> 2, val, size); | ||
1137 | + break; | ||
1138 | + default: | ||
1139 | + g_assert_not_reached(); | ||
1140 | + } | ||
1141 | +} | ||
1142 | + | ||
1143 | +static const MemoryRegionOps dwc2_mmio_hsotg_ops = { | ||
1144 | + .read = dwc2_hsotg_read, | ||
1145 | + .write = dwc2_hsotg_write, | ||
1146 | + .impl.min_access_size = 4, | ||
1147 | + .impl.max_access_size = 4, | ||
1148 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
1149 | +}; | ||
1150 | + | ||
1151 | +static uint64_t dwc2_hreg2_read(void *ptr, hwaddr addr, unsigned size) | ||
1152 | +{ | ||
1153 | + /* TODO - implement FIFOs to support slave mode */ | ||
1154 | + trace_usb_dwc2_hreg2_read(addr, addr >> 12, 0); | ||
1155 | + qemu_log_mask(LOG_UNIMP, "FIFO read not implemented\n"); | ||
1156 | + return 0; | 68 | + return 0; |
1157 | +} | 69 | +} |
1158 | + | 70 | + |
1159 | +static void dwc2_hreg2_write(void *ptr, hwaddr addr, uint64_t val, | 71 | static int cpu_pre_load(void *opaque) |
1160 | + unsigned size) | 72 | { |
1161 | +{ | 73 | ARMCPU *cpu = opaque; |
1162 | + uint64_t orig = val; | 74 | @@ -XXX,XX +XXX,XX @@ static int cpu_pre_load(void *opaque) |
1163 | + | 75 | */ |
1164 | + /* TODO - implement FIFOs to support slave mode */ | 76 | env->irq_line_state = UINT32_MAX; |
1165 | + trace_usb_dwc2_hreg2_write(addr, addr >> 12, orig, 0, val); | 77 | |
1166 | + qemu_log_mask(LOG_UNIMP, "FIFO write not implemented\n"); | 78 | + if (!kvm_enabled()) { |
1167 | +} | 79 | + pmu_op_start(&cpu->env); |
1168 | + | ||
1169 | +static const MemoryRegionOps dwc2_mmio_hreg2_ops = { | ||
1170 | + .read = dwc2_hreg2_read, | ||
1171 | + .write = dwc2_hreg2_write, | ||
1172 | + .impl.min_access_size = 4, | ||
1173 | + .impl.max_access_size = 4, | ||
1174 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
1175 | +}; | ||
1176 | + | ||
1177 | +static void dwc2_wakeup_endpoint(USBBus *bus, USBEndpoint *ep, | ||
1178 | + unsigned int stream) | ||
1179 | +{ | ||
1180 | + DWC2State *s = container_of(bus, DWC2State, bus); | ||
1181 | + | ||
1182 | + trace_usb_dwc2_wakeup_endpoint(ep, stream); | ||
1183 | + | ||
1184 | + /* TODO - do something here? */ | ||
1185 | + qemu_bh_schedule(s->async_bh); | ||
1186 | +} | ||
1187 | + | ||
1188 | +static USBBusOps dwc2_bus_ops = { | ||
1189 | + .wakeup_endpoint = dwc2_wakeup_endpoint, | ||
1190 | +}; | ||
1191 | + | ||
1192 | +static void dwc2_work_timer(void *opaque) | ||
1193 | +{ | ||
1194 | + DWC2State *s = opaque; | ||
1195 | + | ||
1196 | + trace_usb_dwc2_work_timer(); | ||
1197 | + qemu_bh_schedule(s->async_bh); | ||
1198 | +} | ||
1199 | + | ||
1200 | +static void dwc2_reset_enter(Object *obj, ResetType type) | ||
1201 | +{ | ||
1202 | + DWC2Class *c = DWC2_GET_CLASS(obj); | ||
1203 | + DWC2State *s = DWC2_USB(obj); | ||
1204 | + int i; | ||
1205 | + | ||
1206 | + trace_usb_dwc2_reset_enter(); | ||
1207 | + | ||
1208 | + if (c->parent_phases.enter) { | ||
1209 | + c->parent_phases.enter(obj, type); | ||
1210 | + } | 80 | + } |
1211 | + | 81 | + |
1212 | + timer_del(s->frame_timer); | 82 | return 0; |
1213 | + qemu_bh_cancel(s->async_bh); | 83 | } |
1214 | + | 84 | |
1215 | + if (s->uport.dev && s->uport.dev->attached) { | 85 | @@ -XXX,XX +XXX,XX @@ static int cpu_post_load(void *opaque, int version_id) |
1216 | + usb_detach(&s->uport); | 86 | hw_breakpoint_update_all(cpu); |
87 | hw_watchpoint_update_all(cpu); | ||
88 | |||
89 | + if (!kvm_enabled()) { | ||
90 | + pmu_op_finish(&cpu->env); | ||
1217 | + } | 91 | + } |
1218 | + | 92 | + |
1219 | + dwc2_bus_stop(s); | 93 | return 0; |
1220 | + | 94 | } |
1221 | + s->gotgctl = GOTGCTL_BSESVLD | GOTGCTL_ASESVLD | GOTGCTL_CONID_B; | 95 | |
1222 | + s->gotgint = 0; | 96 | @@ -XXX,XX +XXX,XX @@ const VMStateDescription vmstate_arm_cpu = { |
1223 | + s->gahbcfg = 0; | 97 | .version_id = 22, |
1224 | + s->gusbcfg = 5 << GUSBCFG_USBTRDTIM_SHIFT; | 98 | .minimum_version_id = 22, |
1225 | + s->grstctl = GRSTCTL_AHBIDLE; | 99 | .pre_save = cpu_pre_save, |
1226 | + s->gintsts = GINTSTS_CONIDSTSCHNG | GINTSTS_PTXFEMP | GINTSTS_NPTXFEMP | | 100 | + .post_save = cpu_post_save, |
1227 | + GINTSTS_CURMODE_HOST; | 101 | .pre_load = cpu_pre_load, |
1228 | + s->gintmsk = 0; | 102 | .post_load = cpu_post_load, |
1229 | + s->grxstsr = 0; | 103 | .fields = (VMStateField[]) { |
1230 | + s->grxstsp = 0; | ||
1231 | + s->grxfsiz = 1024; | ||
1232 | + s->gnptxfsiz = 1024 << FIFOSIZE_DEPTH_SHIFT; | ||
1233 | + s->gnptxsts = (4 << FIFOSIZE_DEPTH_SHIFT) | 1024; | ||
1234 | + s->gi2cctl = GI2CCTL_I2CDATSE0 | GI2CCTL_ACK; | ||
1235 | + s->gpvndctl = 0; | ||
1236 | + s->ggpio = 0; | ||
1237 | + s->guid = 0; | ||
1238 | + s->gsnpsid = 0x4f54294a; | ||
1239 | + s->ghwcfg1 = 0; | ||
1240 | + s->ghwcfg2 = (8 << GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT) | | ||
1241 | + (4 << GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT) | | ||
1242 | + (4 << GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT) | | ||
1243 | + GHWCFG2_DYNAMIC_FIFO | | ||
1244 | + GHWCFG2_PERIO_EP_SUPPORTED | | ||
1245 | + ((DWC2_NB_CHAN - 1) << GHWCFG2_NUM_HOST_CHAN_SHIFT) | | ||
1246 | + (GHWCFG2_INT_DMA_ARCH << GHWCFG2_ARCHITECTURE_SHIFT) | | ||
1247 | + (GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST << GHWCFG2_OP_MODE_SHIFT); | ||
1248 | + s->ghwcfg3 = (4096 << GHWCFG3_DFIFO_DEPTH_SHIFT) | | ||
1249 | + (4 << GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT) | | ||
1250 | + (4 << GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT); | ||
1251 | + s->ghwcfg4 = 0; | ||
1252 | + s->glpmcfg = 0; | ||
1253 | + s->gpwrdn = GPWRDN_PWRDNRSTN; | ||
1254 | + s->gdfifocfg = 0; | ||
1255 | + s->gadpctl = 0; | ||
1256 | + s->grefclk = 0; | ||
1257 | + s->gintmsk2 = 0; | ||
1258 | + s->gintsts2 = 0; | ||
1259 | + | ||
1260 | + s->hptxfsiz = 500 << FIFOSIZE_DEPTH_SHIFT; | ||
1261 | + | ||
1262 | + s->hcfg = 2 << HCFG_RESVALID_SHIFT; | ||
1263 | + s->hfir = 60000; | ||
1264 | + s->hfnum = 0x3fff; | ||
1265 | + s->hptxsts = (16 << TXSTS_QSPCAVAIL_SHIFT) | 32768; | ||
1266 | + s->haint = 0; | ||
1267 | + s->haintmsk = 0; | ||
1268 | + s->hprt0 = 0; | ||
1269 | + | ||
1270 | + memset(s->hreg1, 0, sizeof(s->hreg1)); | ||
1271 | + memset(s->pcgreg, 0, sizeof(s->pcgreg)); | ||
1272 | + | ||
1273 | + s->sof_time = 0; | ||
1274 | + s->frame_number = 0; | ||
1275 | + s->fi = USB_FRMINTVL - 1; | ||
1276 | + s->next_chan = 0; | ||
1277 | + s->working = false; | ||
1278 | + | ||
1279 | + for (i = 0; i < DWC2_NB_CHAN; i++) { | ||
1280 | + s->packet[i].needs_service = false; | ||
1281 | + } | ||
1282 | +} | ||
1283 | + | ||
1284 | +static void dwc2_reset_hold(Object *obj) | ||
1285 | +{ | ||
1286 | + DWC2Class *c = DWC2_GET_CLASS(obj); | ||
1287 | + DWC2State *s = DWC2_USB(obj); | ||
1288 | + | ||
1289 | + trace_usb_dwc2_reset_hold(); | ||
1290 | + | ||
1291 | + if (c->parent_phases.hold) { | ||
1292 | + c->parent_phases.hold(obj); | ||
1293 | + } | ||
1294 | + | ||
1295 | + dwc2_update_irq(s); | ||
1296 | +} | ||
1297 | + | ||
1298 | +static void dwc2_reset_exit(Object *obj) | ||
1299 | +{ | ||
1300 | + DWC2Class *c = DWC2_GET_CLASS(obj); | ||
1301 | + DWC2State *s = DWC2_USB(obj); | ||
1302 | + | ||
1303 | + trace_usb_dwc2_reset_exit(); | ||
1304 | + | ||
1305 | + if (c->parent_phases.exit) { | ||
1306 | + c->parent_phases.exit(obj); | ||
1307 | + } | ||
1308 | + | ||
1309 | + s->hprt0 = HPRT0_PWR; | ||
1310 | + if (s->uport.dev && s->uport.dev->attached) { | ||
1311 | + usb_attach(&s->uport); | ||
1312 | + usb_device_reset(s->uport.dev); | ||
1313 | + } | ||
1314 | +} | ||
1315 | + | ||
1316 | +static void dwc2_realize(DeviceState *dev, Error **errp) | ||
1317 | +{ | ||
1318 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
1319 | + DWC2State *s = DWC2_USB(dev); | ||
1320 | + Object *obj; | ||
1321 | + Error *err = NULL; | ||
1322 | + | ||
1323 | + obj = object_property_get_link(OBJECT(dev), "dma-mr", &err); | ||
1324 | + if (err) { | ||
1325 | + error_setg(errp, "dwc2: required dma-mr link not found: %s", | ||
1326 | + error_get_pretty(err)); | ||
1327 | + return; | ||
1328 | + } | ||
1329 | + assert(obj != NULL); | ||
1330 | + | ||
1331 | + s->dma_mr = MEMORY_REGION(obj); | ||
1332 | + address_space_init(&s->dma_as, s->dma_mr, "dwc2"); | ||
1333 | + | ||
1334 | + usb_bus_new(&s->bus, sizeof(s->bus), &dwc2_bus_ops, dev); | ||
1335 | + usb_register_port(&s->bus, &s->uport, s, 0, &dwc2_port_ops, | ||
1336 | + USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL | | ||
1337 | + (s->usb_version == 2 ? USB_SPEED_MASK_HIGH : 0)); | ||
1338 | + s->uport.dev = 0; | ||
1339 | + | ||
1340 | + s->usb_frame_time = NANOSECONDS_PER_SECOND / 1000; /* 1000000 */ | ||
1341 | + if (NANOSECONDS_PER_SECOND >= USB_HZ_FS) { | ||
1342 | + s->usb_bit_time = NANOSECONDS_PER_SECOND / USB_HZ_FS; /* 83.3 */ | ||
1343 | + } else { | ||
1344 | + s->usb_bit_time = 1; | ||
1345 | + } | ||
1346 | + | ||
1347 | + s->fi = USB_FRMINTVL - 1; | ||
1348 | + s->eof_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, dwc2_frame_boundary, s); | ||
1349 | + s->frame_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, dwc2_work_timer, s); | ||
1350 | + s->async_bh = qemu_bh_new(dwc2_work_bh, s); | ||
1351 | + | ||
1352 | + sysbus_init_irq(sbd, &s->irq); | ||
1353 | +} | ||
1354 | + | ||
1355 | +static void dwc2_init(Object *obj) | ||
1356 | +{ | ||
1357 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
1358 | + DWC2State *s = DWC2_USB(obj); | ||
1359 | + | ||
1360 | + memory_region_init(&s->container, obj, "dwc2", DWC2_MMIO_SIZE); | ||
1361 | + sysbus_init_mmio(sbd, &s->container); | ||
1362 | + | ||
1363 | + memory_region_init_io(&s->hsotg, obj, &dwc2_mmio_hsotg_ops, s, | ||
1364 | + "dwc2-io", 4 * KiB); | ||
1365 | + memory_region_add_subregion(&s->container, 0x0000, &s->hsotg); | ||
1366 | + | ||
1367 | + memory_region_init_io(&s->fifos, obj, &dwc2_mmio_hreg2_ops, s, | ||
1368 | + "dwc2-fifo", 64 * KiB); | ||
1369 | + memory_region_add_subregion(&s->container, 0x1000, &s->fifos); | ||
1370 | +} | ||
1371 | + | ||
1372 | +static const VMStateDescription vmstate_dwc2_state_packet = { | ||
1373 | + .name = "dwc2/packet", | ||
1374 | + .version_id = 1, | ||
1375 | + .minimum_version_id = 1, | ||
1376 | + .fields = (VMStateField[]) { | ||
1377 | + VMSTATE_UINT32(devadr, DWC2Packet), | ||
1378 | + VMSTATE_UINT32(epnum, DWC2Packet), | ||
1379 | + VMSTATE_UINT32(epdir, DWC2Packet), | ||
1380 | + VMSTATE_UINT32(mps, DWC2Packet), | ||
1381 | + VMSTATE_UINT32(pid, DWC2Packet), | ||
1382 | + VMSTATE_UINT32(index, DWC2Packet), | ||
1383 | + VMSTATE_UINT32(pcnt, DWC2Packet), | ||
1384 | + VMSTATE_UINT32(len, DWC2Packet), | ||
1385 | + VMSTATE_INT32(async, DWC2Packet), | ||
1386 | + VMSTATE_BOOL(small, DWC2Packet), | ||
1387 | + VMSTATE_BOOL(needs_service, DWC2Packet), | ||
1388 | + VMSTATE_END_OF_LIST() | ||
1389 | + }, | ||
1390 | +}; | ||
1391 | + | ||
1392 | +const VMStateDescription vmstate_dwc2_state = { | ||
1393 | + .name = "dwc2", | ||
1394 | + .version_id = 1, | ||
1395 | + .minimum_version_id = 1, | ||
1396 | + .fields = (VMStateField[]) { | ||
1397 | + VMSTATE_UINT32_ARRAY(glbreg, DWC2State, | ||
1398 | + DWC2_GLBREG_SIZE / sizeof(uint32_t)), | ||
1399 | + VMSTATE_UINT32_ARRAY(fszreg, DWC2State, | ||
1400 | + DWC2_FSZREG_SIZE / sizeof(uint32_t)), | ||
1401 | + VMSTATE_UINT32_ARRAY(hreg0, DWC2State, | ||
1402 | + DWC2_HREG0_SIZE / sizeof(uint32_t)), | ||
1403 | + VMSTATE_UINT32_ARRAY(hreg1, DWC2State, | ||
1404 | + DWC2_HREG1_SIZE / sizeof(uint32_t)), | ||
1405 | + VMSTATE_UINT32_ARRAY(pcgreg, DWC2State, | ||
1406 | + DWC2_PCGREG_SIZE / sizeof(uint32_t)), | ||
1407 | + | ||
1408 | + VMSTATE_TIMER_PTR(eof_timer, DWC2State), | ||
1409 | + VMSTATE_TIMER_PTR(frame_timer, DWC2State), | ||
1410 | + VMSTATE_INT64(sof_time, DWC2State), | ||
1411 | + VMSTATE_INT64(usb_frame_time, DWC2State), | ||
1412 | + VMSTATE_INT64(usb_bit_time, DWC2State), | ||
1413 | + VMSTATE_UINT32(usb_version, DWC2State), | ||
1414 | + VMSTATE_UINT16(frame_number, DWC2State), | ||
1415 | + VMSTATE_UINT16(fi, DWC2State), | ||
1416 | + VMSTATE_UINT16(next_chan, DWC2State), | ||
1417 | + VMSTATE_BOOL(working, DWC2State), | ||
1418 | + | ||
1419 | + VMSTATE_STRUCT_ARRAY(packet, DWC2State, DWC2_NB_CHAN, 1, | ||
1420 | + vmstate_dwc2_state_packet, DWC2Packet), | ||
1421 | + VMSTATE_UINT8_2DARRAY(usb_buf, DWC2State, DWC2_NB_CHAN, | ||
1422 | + DWC2_MAX_XFER_SIZE), | ||
1423 | + | ||
1424 | + VMSTATE_END_OF_LIST() | ||
1425 | + } | ||
1426 | +}; | ||
1427 | + | ||
1428 | +static Property dwc2_usb_properties[] = { | ||
1429 | + DEFINE_PROP_UINT32("usb_version", DWC2State, usb_version, 2), | ||
1430 | + DEFINE_PROP_END_OF_LIST(), | ||
1431 | +}; | ||
1432 | + | ||
1433 | +static void dwc2_class_init(ObjectClass *klass, void *data) | ||
1434 | +{ | ||
1435 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
1436 | + DWC2Class *c = DWC2_CLASS(klass); | ||
1437 | + ResettableClass *rc = RESETTABLE_CLASS(klass); | ||
1438 | + | ||
1439 | + dc->realize = dwc2_realize; | ||
1440 | + dc->vmsd = &vmstate_dwc2_state; | ||
1441 | + set_bit(DEVICE_CATEGORY_USB, dc->categories); | ||
1442 | + device_class_set_props(dc, dwc2_usb_properties); | ||
1443 | + resettable_class_set_parent_phases(rc, dwc2_reset_enter, dwc2_reset_hold, | ||
1444 | + dwc2_reset_exit, &c->parent_phases); | ||
1445 | +} | ||
1446 | + | ||
1447 | +static const TypeInfo dwc2_usb_type_info = { | ||
1448 | + .name = TYPE_DWC2_USB, | ||
1449 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
1450 | + .instance_size = sizeof(DWC2State), | ||
1451 | + .instance_init = dwc2_init, | ||
1452 | + .class_size = sizeof(DWC2Class), | ||
1453 | + .class_init = dwc2_class_init, | ||
1454 | +}; | ||
1455 | + | ||
1456 | +static void dwc2_usb_register_types(void) | ||
1457 | +{ | ||
1458 | + type_register_static(&dwc2_usb_type_info); | ||
1459 | +} | ||
1460 | + | ||
1461 | +type_init(dwc2_usb_register_types) | ||
1462 | diff --git a/hw/usb/Kconfig b/hw/usb/Kconfig | ||
1463 | index XXXXXXX..XXXXXXX 100644 | ||
1464 | --- a/hw/usb/Kconfig | ||
1465 | +++ b/hw/usb/Kconfig | ||
1466 | @@ -XXX,XX +XXX,XX @@ config USB_MUSB | ||
1467 | bool | ||
1468 | select USB | ||
1469 | |||
1470 | +config USB_DWC2 | ||
1471 | + bool | ||
1472 | + default y | ||
1473 | + select USB | ||
1474 | + | ||
1475 | config TUSB6010 | ||
1476 | bool | ||
1477 | select USB_MUSB | ||
1478 | diff --git a/hw/usb/Makefile.objs b/hw/usb/Makefile.objs | ||
1479 | index XXXXXXX..XXXXXXX 100644 | ||
1480 | --- a/hw/usb/Makefile.objs | ||
1481 | +++ b/hw/usb/Makefile.objs | ||
1482 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_USB_EHCI_SYSBUS) += hcd-ehci-sysbus.o | ||
1483 | common-obj-$(CONFIG_USB_XHCI) += hcd-xhci.o | ||
1484 | common-obj-$(CONFIG_USB_XHCI_NEC) += hcd-xhci-nec.o | ||
1485 | common-obj-$(CONFIG_USB_MUSB) += hcd-musb.o | ||
1486 | +common-obj-$(CONFIG_USB_DWC2) += hcd-dwc2.o | ||
1487 | |||
1488 | common-obj-$(CONFIG_TUSB6010) += tusb6010.o | ||
1489 | common-obj-$(CONFIG_IMX) += chipidea.o | ||
1490 | diff --git a/hw/usb/trace-events b/hw/usb/trace-events | ||
1491 | index XXXXXXX..XXXXXXX 100644 | ||
1492 | --- a/hw/usb/trace-events | ||
1493 | +++ b/hw/usb/trace-events | ||
1494 | @@ -XXX,XX +XXX,XX @@ usb_xhci_xfer_error(void *xfer, uint32_t ret) "%p: ret %d" | ||
1495 | usb_xhci_unimplemented(const char *item, int nr) "%s (0x%x)" | ||
1496 | usb_xhci_enforced_limit(const char *item) "%s" | ||
1497 | |||
1498 | +# hcd-dwc2.c | ||
1499 | +usb_dwc2_update_irq(uint32_t level) "level=%d" | ||
1500 | +usb_dwc2_raise_global_irq(uint32_t intr) "0x%08x" | ||
1501 | +usb_dwc2_lower_global_irq(uint32_t intr) "0x%08x" | ||
1502 | +usb_dwc2_raise_host_irq(uint32_t intr) "0x%04x" | ||
1503 | +usb_dwc2_lower_host_irq(uint32_t intr) "0x%04x" | ||
1504 | +usb_dwc2_sof(int64_t next) "next SOF %" PRId64 | ||
1505 | +usb_dwc2_bus_start(void) "start SOFs" | ||
1506 | +usb_dwc2_bus_stop(void) "stop SOFs" | ||
1507 | +usb_dwc2_find_device(uint8_t addr) "%d" | ||
1508 | +usb_dwc2_port_disabled(uint32_t pnum) "port %d disabled" | ||
1509 | +usb_dwc2_device_found(uint32_t pnum) "device found on port %d" | ||
1510 | +usb_dwc2_device_not_found(void) "device not found" | ||
1511 | +usb_dwc2_handle_packet(uint32_t chan, void *dev, void *pkt, uint32_t ep, const char *type, const char *dir, uint32_t mps, uint32_t len, uint32_t pcnt) "ch %d dev %p pkt %p ep %d type %s dir %s mps %d len %d pcnt %d" | ||
1512 | +usb_dwc2_memory_read(uint32_t addr, uint32_t len) "addr %d len %d" | ||
1513 | +usb_dwc2_packet_status(const char *status, uint32_t len) "status %s len %d" | ||
1514 | +usb_dwc2_packet_error(const char *status) "ERROR %s" | ||
1515 | +usb_dwc2_async_packet(void *pkt, uint32_t chan, void *dev, uint32_t ep, const char *dir, uint32_t len) "pkt %p ch %d dev %p ep %d %s len %d" | ||
1516 | +usb_dwc2_memory_write(uint32_t addr, uint32_t len) "addr %d len %d" | ||
1517 | +usb_dwc2_packet_done(const char *status, uint32_t actual, uint32_t len, uint32_t pcnt) "status %s actual %d len %d pcnt %d" | ||
1518 | +usb_dwc2_packet_next(const char *status, uint32_t len, uint32_t pcnt) "status %s len %d pcnt %d" | ||
1519 | +usb_dwc2_attach(void *port) "port %p" | ||
1520 | +usb_dwc2_attach_speed(const char *speed) "%s-speed device attached" | ||
1521 | +usb_dwc2_detach(void *port) "port %p" | ||
1522 | +usb_dwc2_child_detach(void *port, void *child) "port %p child %p" | ||
1523 | +usb_dwc2_wakeup(void *port) "port %p" | ||
1524 | +usb_dwc2_async_packet_complete(void *port, void *pkt, uint32_t chan, void *dev, uint32_t ep, const char *dir, uint32_t len) "port %p packet %p ch %d dev %p ep %d %s len %d" | ||
1525 | +usb_dwc2_work_bh(void) "" | ||
1526 | +usb_dwc2_work_bh_service(uint32_t first, uint32_t current, void *dev, uint32_t ep) "first %d servicing %d dev %p ep %d" | ||
1527 | +usb_dwc2_work_bh_next(uint32_t chan) "next %d" | ||
1528 | +usb_dwc2_enable_chan(uint32_t chan, void *dev, void *pkt, uint32_t ep) "ch %d dev %p pkt %p ep %d" | ||
1529 | +usb_dwc2_glbreg_read(uint64_t addr, const char *reg, uint32_t val) " 0x%04" PRIx64 " %s val 0x%08x" | ||
1530 | +usb_dwc2_glbreg_write(uint64_t addr, const char *reg, uint64_t val, uint32_t old, uint64_t result) "0x%04" PRIx64 " %s val 0x%08" PRIx64 " old 0x%08x result 0x%08" PRIx64 | ||
1531 | +usb_dwc2_fszreg_read(uint64_t addr, uint32_t val) " 0x%04" PRIx64 " HPTXFSIZ val 0x%08x" | ||
1532 | +usb_dwc2_fszreg_write(uint64_t addr, uint64_t val, uint32_t old, uint64_t result) "0x%04" PRIx64 " HPTXFSIZ val 0x%08" PRIx64 " old 0x%08x result 0x%08" PRIx64 | ||
1533 | +usb_dwc2_hreg0_read(uint64_t addr, const char *reg, uint32_t val) " 0x%04" PRIx64 " %s val 0x%08x" | ||
1534 | +usb_dwc2_hreg0_write(uint64_t addr, const char *reg, uint64_t val, uint32_t old, uint64_t result) " 0x%04" PRIx64 " %s val 0x%08" PRIx64 " old 0x%08x result 0x%08" PRIx64 | ||
1535 | +usb_dwc2_hreg1_read(uint64_t addr, const char *reg, uint64_t chan, uint32_t val) " 0x%04" PRIx64 " %s%" PRId64 " val 0x%08x" | ||
1536 | +usb_dwc2_hreg1_write(uint64_t addr, const char *reg, uint64_t chan, uint64_t val, uint32_t old, uint64_t result) " 0x%04" PRIx64 " %s%" PRId64 " val 0x%08" PRIx64 " old 0x%08x result 0x%08" PRIx64 | ||
1537 | +usb_dwc2_pcgreg_read(uint64_t addr, const char *reg, uint32_t val) " 0x%04" PRIx64 " %s val 0x%08x" | ||
1538 | +usb_dwc2_pcgreg_write(uint64_t addr, const char *reg, uint64_t val, uint32_t old, uint64_t result) "0x%04" PRIx64 " %s val 0x%08" PRIx64 " old 0x%08x result 0x%08" PRIx64 | ||
1539 | +usb_dwc2_hreg2_read(uint64_t addr, uint64_t fifo, uint32_t val) " 0x%04" PRIx64 " FIFO%" PRId64 " val 0x%08x" | ||
1540 | +usb_dwc2_hreg2_write(uint64_t addr, uint64_t fifo, uint64_t val, uint32_t old, uint64_t result) " 0x%04" PRIx64 " FIFO%" PRId64 " val 0x%08" PRIx64 " old 0x%08x result 0x%08" PRIx64 | ||
1541 | +usb_dwc2_hreg0_action(const char *s) "%s" | ||
1542 | +usb_dwc2_wakeup_endpoint(void *ep, uint32_t stream) "endp %p stream %d" | ||
1543 | +usb_dwc2_work_timer(void) "" | ||
1544 | +usb_dwc2_reset_enter(void) "=== RESET enter ===" | ||
1545 | +usb_dwc2_reset_hold(void) "=== RESET hold ===" | ||
1546 | +usb_dwc2_reset_exit(void) "=== RESET exit ===" | ||
1547 | + | ||
1548 | # desc.c | ||
1549 | usb_desc_device(int addr, int len, int ret) "dev %d query device, len %d, ret %d" | ||
1550 | usb_desc_device_qualifier(int addr, int len, int ret) "dev %d query device qualifier, len %d, ret %d" | ||
1551 | -- | 104 | -- |
1552 | 2.20.1 | 105 | 2.20.1 |
1553 | 106 | ||
1554 | 107 | diff view generated by jsdifflib |
1 | Convert the VSHL and VSLI insns from the Neon 2-registers-and-a-shift | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | group to decodetree. | 2 | |
3 | 3 | Rename arm_ccnt_enabled to pmu_counter_enabled, and add logic to only | |
4 | return 'true' if the specified counter is enabled and neither prohibited | ||
5 | or filtered. | ||
6 | |||
7 | Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org> | ||
8 | Signed-off-by: Aaron Lindsay <aclindsa@gmail.com> | ||
9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-id: 20181211151945.29137-5-aaron@os.amperecomputing.com | ||
4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20200522145520.6778-2-peter.maydell@linaro.org | ||
7 | --- | 13 | --- |
8 | target/arm/neon-dp.decode | 25 ++++++++++++++++++++++ | 14 | target/arm/cpu.h | 10 ++++- |
9 | target/arm/translate-neon.inc.c | 38 +++++++++++++++++++++++++++++++++ | 15 | target/arm/cpu.c | 3 ++ |
10 | target/arm/translate.c | 18 +++++++--------- | 16 | target/arm/helper.c | 96 +++++++++++++++++++++++++++++++++++++++++---- |
11 | 3 files changed, 71 insertions(+), 10 deletions(-) | 17 | 3 files changed, 101 insertions(+), 8 deletions(-) |
12 | 18 | ||
13 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | 19 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
14 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/neon-dp.decode | 21 | --- a/target/arm/cpu.h |
16 | +++ b/target/arm/neon-dp.decode | 22 | +++ b/target/arm/cpu.h |
17 | @@ -XXX,XX +XXX,XX @@ VRECPS_fp_3s 1111 001 0 0 . 0 . .... .... 1111 ... 1 .... @3same_fp | 23 | @@ -XXX,XX +XXX,XX @@ void pmccntr_op_finish(CPUARMState *env); |
18 | VRSQRTS_fp_3s 1111 001 0 0 . 1 . .... .... 1111 ... 1 .... @3same_fp | 24 | void pmu_op_start(CPUARMState *env); |
19 | VMAXNM_fp_3s 1111 001 1 0 . 0 . .... .... 1111 ... 1 .... @3same_fp | 25 | void pmu_op_finish(CPUARMState *env); |
20 | VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp | 26 | |
21 | + | 27 | +/** |
22 | +###################################################################### | 28 | + * Functions to register as EL change hooks for PMU mode filtering |
23 | +# 2-reg-and-shift grouping: | 29 | + */ |
24 | +# 1111 001 U 1 D immH:3 immL:3 Vd:4 opc:4 L Q M 1 Vm:4 | 30 | +void pmu_pre_el_change(ARMCPU *cpu, void *ignored); |
25 | +###################################################################### | 31 | +void pmu_post_el_change(ARMCPU *cpu, void *ignored); |
26 | +&2reg_shift vm vd q shift size | 32 | + |
27 | + | 33 | /* SCTLR bit meanings. Several bits have been reused in newer |
28 | +@2reg_shl_d .... ... . . . shift:6 .... .... 1 q:1 . . .... \ | 34 | * versions of the architecture; in that case we define constants |
29 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=3 | 35 | * for both old and new bit meanings. Code which tests against those |
30 | +@2reg_shl_s .... ... . . . 1 shift:5 .... .... 0 q:1 . . .... \ | 36 | @@ -XXX,XX +XXX,XX @@ void pmu_op_finish(CPUARMState *env); |
31 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=2 | 37 | |
32 | +@2reg_shl_h .... ... . . . 01 shift:4 .... .... 0 q:1 . . .... \ | 38 | #define MDCR_EPMAD (1U << 21) |
33 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=1 | 39 | #define MDCR_EDAD (1U << 20) |
34 | +@2reg_shl_b .... ... . . . 001 shift:3 .... .... 0 q:1 . . .... \ | 40 | -#define MDCR_SPME (1U << 17) |
35 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=0 | 41 | +#define MDCR_SPME (1U << 17) /* MDCR_EL3 */ |
36 | + | 42 | +#define MDCR_HPMD (1U << 17) /* MDCR_EL2 */ |
37 | +VSHL_2sh 1111 001 0 1 . ...... .... 0101 . . . 1 .... @2reg_shl_d | 43 | #define MDCR_SDD (1U << 16) |
38 | +VSHL_2sh 1111 001 0 1 . ...... .... 0101 . . . 1 .... @2reg_shl_s | 44 | #define MDCR_SPD (3U << 14) |
39 | +VSHL_2sh 1111 001 0 1 . ...... .... 0101 . . . 1 .... @2reg_shl_h | 45 | #define MDCR_TDRA (1U << 11) |
40 | +VSHL_2sh 1111 001 0 1 . ...... .... 0101 . . . 1 .... @2reg_shl_b | 46 | @@ -XXX,XX +XXX,XX @@ void pmu_op_finish(CPUARMState *env); |
41 | + | 47 | #define MDCR_HPME (1U << 7) |
42 | +VSLI_2sh 1111 001 1 1 . ...... .... 0101 . . . 1 .... @2reg_shl_d | 48 | #define MDCR_TPM (1U << 6) |
43 | +VSLI_2sh 1111 001 1 1 . ...... .... 0101 . . . 1 .... @2reg_shl_s | 49 | #define MDCR_TPMCR (1U << 5) |
44 | +VSLI_2sh 1111 001 1 1 . ...... .... 0101 . . . 1 .... @2reg_shl_h | 50 | +#define MDCR_HPMN (0x1fU) |
45 | +VSLI_2sh 1111 001 1 1 . ...... .... 0101 . . . 1 .... @2reg_shl_b | 51 | |
46 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | 52 | /* Not all of the MDCR_EL3 bits are present in the 32-bit SDCR */ |
53 | #define SDCR_VALID_MASK (MDCR_EPMAD | MDCR_EDAD | MDCR_SPME | MDCR_SPD) | ||
54 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
47 | index XXXXXXX..XXXXXXX 100644 | 55 | index XXXXXXX..XXXXXXX 100644 |
48 | --- a/target/arm/translate-neon.inc.c | 56 | --- a/target/arm/cpu.c |
49 | +++ b/target/arm/translate-neon.inc.c | 57 | +++ b/target/arm/cpu.c |
50 | @@ -XXX,XX +XXX,XX @@ static bool do_3same_fp_pair(DisasContext *s, arg_3same *a, VFPGen3OpSPFn *fn) | 58 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) |
51 | DO_3S_FP_PAIR(VPADD, gen_helper_vfp_adds) | 59 | if (!cpu->has_pmu) { |
52 | DO_3S_FP_PAIR(VPMAX, gen_helper_vfp_maxs) | 60 | unset_feature(env, ARM_FEATURE_PMU); |
53 | DO_3S_FP_PAIR(VPMIN, gen_helper_vfp_mins) | 61 | cpu->id_aa64dfr0 &= ~0xf00; |
54 | + | 62 | + } else if (!kvm_enabled()) { |
55 | +static bool do_vector_2sh(DisasContext *s, arg_2reg_shift *a, GVecGen2iFn *fn) | 63 | + arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0); |
56 | +{ | 64 | + arm_register_el_change_hook(cpu, &pmu_post_el_change, 0); |
57 | + /* Handle a 2-reg-shift insn which can be vectorized. */ | 65 | } |
58 | + int vec_size = a->q ? 16 : 8; | 66 | |
59 | + int rd_ofs = neon_reg_offset(a->vd, 0); | 67 | if (!arm_feature(env, ARM_FEATURE_EL2)) { |
60 | + int rm_ofs = neon_reg_offset(a->vm, 0); | 68 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
61 | + | 69 | index XXXXXXX..XXXXXXX 100644 |
62 | + if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | 70 | --- a/target/arm/helper.c |
63 | + return false; | 71 | +++ b/target/arm/helper.c |
72 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6_cp_reginfo[] = { | ||
73 | /* Definitions for the PMU registers */ | ||
74 | #define PMCRN_MASK 0xf800 | ||
75 | #define PMCRN_SHIFT 11 | ||
76 | +#define PMCRDP 0x10 | ||
77 | #define PMCRD 0x8 | ||
78 | #define PMCRC 0x4 | ||
79 | #define PMCRE 0x1 | ||
80 | |||
81 | +#define PMXEVTYPER_P 0x80000000 | ||
82 | +#define PMXEVTYPER_U 0x40000000 | ||
83 | +#define PMXEVTYPER_NSK 0x20000000 | ||
84 | +#define PMXEVTYPER_NSU 0x10000000 | ||
85 | +#define PMXEVTYPER_NSH 0x08000000 | ||
86 | +#define PMXEVTYPER_M 0x04000000 | ||
87 | +#define PMXEVTYPER_MT 0x02000000 | ||
88 | +#define PMXEVTYPER_EVTCOUNT 0x0000ffff | ||
89 | +#define PMXEVTYPER_MASK (PMXEVTYPER_P | PMXEVTYPER_U | PMXEVTYPER_NSK | \ | ||
90 | + PMXEVTYPER_NSU | PMXEVTYPER_NSH | \ | ||
91 | + PMXEVTYPER_M | PMXEVTYPER_MT | \ | ||
92 | + PMXEVTYPER_EVTCOUNT) | ||
93 | + | ||
94 | static inline uint32_t pmu_num_counters(CPUARMState *env) | ||
95 | { | ||
96 | return (env->cp15.c9_pmcr & PMCRN_MASK) >> PMCRN_SHIFT; | ||
97 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult pmreg_access_ccntr(CPUARMState *env, | ||
98 | return pmreg_access(env, ri, isread); | ||
99 | } | ||
100 | |||
101 | -static inline bool arm_ccnt_enabled(CPUARMState *env) | ||
102 | +/* Returns true if the counter (pass 31 for PMCCNTR) should count events using | ||
103 | + * the current EL, security state, and register configuration. | ||
104 | + */ | ||
105 | +static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter) | ||
106 | { | ||
107 | - /* This does not support checking PMCCFILTR_EL0 register */ | ||
108 | + uint64_t filter; | ||
109 | + bool e, p, u, nsk, nsu, nsh, m; | ||
110 | + bool enabled, prohibited, filtered; | ||
111 | + bool secure = arm_is_secure(env); | ||
112 | + int el = arm_current_el(env); | ||
113 | + uint8_t hpmn = env->cp15.mdcr_el2 & MDCR_HPMN; | ||
114 | |||
115 | - if (!(env->cp15.c9_pmcr & PMCRE) || !(env->cp15.c9_pmcnten & (1 << 31))) { | ||
116 | - return false; | ||
117 | + if (!arm_feature(env, ARM_FEATURE_EL2) || | ||
118 | + (counter < hpmn || counter == 31)) { | ||
119 | + e = env->cp15.c9_pmcr & PMCRE; | ||
120 | + } else { | ||
121 | + e = env->cp15.mdcr_el2 & MDCR_HPME; | ||
64 | + } | 122 | + } |
65 | + | 123 | + enabled = e && (env->cp15.c9_pmcnten & (1 << counter)); |
66 | + /* UNDEF accesses to D16-D31 if they don't exist. */ | 124 | + |
67 | + if (!dc_isar_feature(aa32_simd_r32, s) && | 125 | + if (!secure) { |
68 | + ((a->vd | a->vm) & 0x10)) { | 126 | + if (el == 2 && (counter < hpmn || counter == 31)) { |
69 | + return false; | 127 | + prohibited = env->cp15.mdcr_el2 & MDCR_HPMD; |
128 | + } else { | ||
129 | + prohibited = false; | ||
130 | + } | ||
131 | + } else { | ||
132 | + prohibited = arm_feature(env, ARM_FEATURE_EL3) && | ||
133 | + (env->cp15.mdcr_el3 & MDCR_SPME); | ||
134 | } | ||
135 | |||
136 | - return true; | ||
137 | + if (prohibited && counter == 31) { | ||
138 | + prohibited = env->cp15.c9_pmcr & PMCRDP; | ||
70 | + } | 139 | + } |
71 | + | 140 | + |
72 | + if ((a->vm | a->vd) & a->q) { | 141 | + /* TODO Remove assert, set filter to correct PMEVTYPER */ |
73 | + return false; | 142 | + assert(counter == 31); |
143 | + filter = env->cp15.pmccfiltr_el0; | ||
144 | + | ||
145 | + p = filter & PMXEVTYPER_P; | ||
146 | + u = filter & PMXEVTYPER_U; | ||
147 | + nsk = arm_feature(env, ARM_FEATURE_EL3) && (filter & PMXEVTYPER_NSK); | ||
148 | + nsu = arm_feature(env, ARM_FEATURE_EL3) && (filter & PMXEVTYPER_NSU); | ||
149 | + nsh = arm_feature(env, ARM_FEATURE_EL2) && (filter & PMXEVTYPER_NSH); | ||
150 | + m = arm_el_is_aa64(env, 1) && | ||
151 | + arm_feature(env, ARM_FEATURE_EL3) && (filter & PMXEVTYPER_M); | ||
152 | + | ||
153 | + if (el == 0) { | ||
154 | + filtered = secure ? u : u != nsu; | ||
155 | + } else if (el == 1) { | ||
156 | + filtered = secure ? p : p != nsk; | ||
157 | + } else if (el == 2) { | ||
158 | + filtered = !nsh; | ||
159 | + } else { /* EL3 */ | ||
160 | + filtered = m != p; | ||
74 | + } | 161 | + } |
75 | + | 162 | + |
76 | + if (!vfp_access_check(s)) { | 163 | + return enabled && !prohibited && !filtered; |
77 | + return true; | 164 | } |
78 | + } | 165 | + |
79 | + | 166 | /* |
80 | + fn(a->size, rd_ofs, rm_ofs, a->shift, vec_size, vec_size); | 167 | * Ensure c15_ccnt is the guest-visible count so that operations such as |
81 | + return true; | 168 | * enabling/disabling the counter or filtering, modifying the count itself, |
82 | +} | 169 | @@ -XXX,XX +XXX,XX @@ void pmccntr_op_start(CPUARMState *env) |
83 | + | 170 | cycles = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), |
84 | +#define DO_2SH(INSN, FUNC) \ | 171 | ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); |
85 | + static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \ | 172 | |
86 | + { \ | 173 | - if (arm_ccnt_enabled(env)) { |
87 | + return do_vector_2sh(s, a, FUNC); \ | 174 | + if (pmu_counter_enabled(env, 31)) { |
88 | + } \ | 175 | uint64_t eff_cycles = cycles; |
89 | + | 176 | if (env->cp15.c9_pmcr & PMCRD) { |
90 | +DO_2SH(VSHL, tcg_gen_gvec_shli) | 177 | /* Increment once every 64 processor clock cycles */ |
91 | +DO_2SH(VSLI, gen_gvec_sli) | 178 | @@ -XXX,XX +XXX,XX @@ void pmccntr_op_start(CPUARMState *env) |
92 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 179 | */ |
93 | index XXXXXXX..XXXXXXX 100644 | 180 | void pmccntr_op_finish(CPUARMState *env) |
94 | --- a/target/arm/translate.c | 181 | { |
95 | +++ b/target/arm/translate.c | 182 | - if (arm_ccnt_enabled(env)) { |
96 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 183 | + if (pmu_counter_enabled(env, 31)) { |
97 | if ((insn & 0x00380080) != 0) { | 184 | uint64_t prev_cycles = env->cp15.c15_ccnt_delta; |
98 | /* Two registers and shift. */ | 185 | |
99 | op = (insn >> 8) & 0xf; | 186 | if (env->cp15.c9_pmcr & PMCRD) { |
100 | + | 187 | @@ -XXX,XX +XXX,XX @@ void pmu_op_finish(CPUARMState *env) |
101 | + switch (op) { | 188 | pmccntr_op_finish(env); |
102 | + case 5: /* VSHL, VSLI */ | 189 | } |
103 | + return 1; /* handled by decodetree */ | 190 | |
104 | + default: | 191 | +void pmu_pre_el_change(ARMCPU *cpu, void *ignored) |
105 | + break; | 192 | +{ |
106 | + } | 193 | + pmu_op_start(&cpu->env); |
107 | + | 194 | +} |
108 | if (insn & (1 << 7)) { | 195 | + |
109 | /* 64-bit shift. */ | 196 | +void pmu_post_el_change(ARMCPU *cpu, void *ignored) |
110 | if (op > 7) { | 197 | +{ |
111 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 198 | + pmu_op_finish(&cpu->env); |
112 | gen_gvec_sri(size, rd_ofs, rm_ofs, shift, | 199 | +} |
113 | vec_size, vec_size); | 200 | + |
114 | return 0; | 201 | static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, |
115 | - | 202 | uint64_t value) |
116 | - case 5: /* VSHL, VSLI */ | 203 | { |
117 | - if (u) { /* VSLI */ | 204 | @@ -XXX,XX +XXX,XX @@ void pmu_op_finish(CPUARMState *env) |
118 | - gen_gvec_sli(size, rd_ofs, rm_ofs, shift, | 205 | { |
119 | - vec_size, vec_size); | 206 | } |
120 | - } else { /* VSHL */ | 207 | |
121 | - tcg_gen_gvec_shli(size, rd_ofs, rm_ofs, shift, | 208 | +void pmu_pre_el_change(ARMCPU *cpu, void *ignored) |
122 | - vec_size, vec_size); | 209 | +{ |
123 | - } | 210 | +} |
124 | - return 0; | 211 | + |
125 | } | 212 | +void pmu_post_el_change(ARMCPU *cpu, void *ignored) |
126 | 213 | +{ | |
127 | if (size == 3) { | 214 | +} |
215 | + | ||
216 | #endif | ||
217 | |||
218 | static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
128 | -- | 219 | -- |
129 | 2.20.1 | 220 | 2.20.1 |
130 | 221 | ||
131 | 222 | diff view generated by jsdifflib |
1 | Convert the VSHR 2-reg-shift insns to decodetree. | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | Note that unlike the legacy decoder, we present the right shift | 3 | Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org> |
4 | amount to the trans_ function as a positive integer. | 4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20181211151945.29137-6-aaron@os.amperecomputing.com | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | --- | ||
9 | target/arm/helper.c | 27 ++++++++++++++++++++++++++- | ||
10 | 1 file changed, 26 insertions(+), 1 deletion(-) | ||
5 | 11 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20200522145520.6778-3-peter.maydell@linaro.org | ||
9 | --- | ||
10 | target/arm/neon-dp.decode | 25 ++++++++++++++++++++ | ||
11 | target/arm/translate-neon.inc.c | 41 +++++++++++++++++++++++++++++++++ | ||
12 | target/arm/translate.c | 21 +---------------- | ||
13 | 3 files changed, 67 insertions(+), 20 deletions(-) | ||
14 | |||
15 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | ||
16 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/neon-dp.decode | 14 | --- a/target/arm/helper.c |
18 | +++ b/target/arm/neon-dp.decode | 15 | +++ b/target/arm/helper.c |
19 | @@ -XXX,XX +XXX,XX @@ VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp | 16 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6_cp_reginfo[] = { |
20 | ###################################################################### | 17 | PMXEVTYPER_M | PMXEVTYPER_MT | \ |
21 | &2reg_shift vm vd q shift size | 18 | PMXEVTYPER_EVTCOUNT) |
22 | 19 | ||
23 | +# Right shifts are encoded as N - shift, where N is the element size in bits. | 20 | +#define PMCCFILTR 0xf8000000 |
24 | +%neon_rshift_i6 16:6 !function=rsub_64 | 21 | +#define PMCCFILTR_M PMXEVTYPER_M |
25 | +%neon_rshift_i5 16:5 !function=rsub_32 | 22 | +#define PMCCFILTR_EL0 (PMCCFILTR | PMCCFILTR_M) |
26 | +%neon_rshift_i4 16:4 !function=rsub_16 | ||
27 | +%neon_rshift_i3 16:3 !function=rsub_8 | ||
28 | + | 23 | + |
29 | +@2reg_shr_d .... ... . . . ...... .... .... 1 q:1 . . .... \ | 24 | static inline uint32_t pmu_num_counters(CPUARMState *env) |
30 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=3 shift=%neon_rshift_i6 | 25 | { |
31 | +@2reg_shr_s .... ... . . . 1 ..... .... .... 0 q:1 . . .... \ | 26 | return (env->cp15.c9_pmcr & PMCRN_MASK) >> PMCRN_SHIFT; |
32 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=2 shift=%neon_rshift_i5 | 27 | @@ -XXX,XX +XXX,XX @@ static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri, |
33 | +@2reg_shr_h .... ... . . . 01 .... .... .... 0 q:1 . . .... \ | 28 | uint64_t value) |
34 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=1 shift=%neon_rshift_i4 | 29 | { |
35 | +@2reg_shr_b .... ... . . . 001 ... .... .... 0 q:1 . . .... \ | 30 | pmccntr_op_start(env); |
36 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=0 shift=%neon_rshift_i3 | 31 | - env->cp15.pmccfiltr_el0 = value & 0xfc000000; |
37 | + | 32 | + env->cp15.pmccfiltr_el0 = value & PMCCFILTR_EL0; |
38 | @2reg_shl_d .... ... . . . shift:6 .... .... 1 q:1 . . .... \ | 33 | pmccntr_op_finish(env); |
39 | &2reg_shift vm=%vm_dp vd=%vd_dp size=3 | ||
40 | @2reg_shl_s .... ... . . . 1 shift:5 .... .... 0 q:1 . . .... \ | ||
41 | @@ -XXX,XX +XXX,XX @@ VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp | ||
42 | @2reg_shl_b .... ... . . . 001 shift:3 .... .... 0 q:1 . . .... \ | ||
43 | &2reg_shift vm=%vm_dp vd=%vd_dp size=0 | ||
44 | |||
45 | +VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_d | ||
46 | +VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_s | ||
47 | +VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_h | ||
48 | +VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_b | ||
49 | + | ||
50 | +VSHR_U_2sh 1111 001 1 1 . ...... .... 0000 . . . 1 .... @2reg_shr_d | ||
51 | +VSHR_U_2sh 1111 001 1 1 . ...... .... 0000 . . . 1 .... @2reg_shr_s | ||
52 | +VSHR_U_2sh 1111 001 1 1 . ...... .... 0000 . . . 1 .... @2reg_shr_h | ||
53 | +VSHR_U_2sh 1111 001 1 1 . ...... .... 0000 . . . 1 .... @2reg_shr_b | ||
54 | + | ||
55 | VSHL_2sh 1111 001 0 1 . ...... .... 0101 . . . 1 .... @2reg_shl_d | ||
56 | VSHL_2sh 1111 001 0 1 . ...... .... 0101 . . . 1 .... @2reg_shl_s | ||
57 | VSHL_2sh 1111 001 0 1 . ...... .... 0101 . . . 1 .... @2reg_shl_h | ||
58 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/target/arm/translate-neon.inc.c | ||
61 | +++ b/target/arm/translate-neon.inc.c | ||
62 | @@ -XXX,XX +XXX,XX @@ static inline int plus1(DisasContext *s, int x) | ||
63 | return x + 1; | ||
64 | } | 34 | } |
65 | 35 | ||
66 | +static inline int rsub_64(DisasContext *s, int x) | 36 | +static void pmccfiltr_write_a32(CPUARMState *env, const ARMCPRegInfo *ri, |
37 | + uint64_t value) | ||
67 | +{ | 38 | +{ |
68 | + return 64 - x; | 39 | + pmccntr_op_start(env); |
40 | + /* M is not accessible from AArch32 */ | ||
41 | + env->cp15.pmccfiltr_el0 = (env->cp15.pmccfiltr_el0 & PMCCFILTR_M) | | ||
42 | + (value & PMCCFILTR); | ||
43 | + pmccntr_op_finish(env); | ||
69 | +} | 44 | +} |
70 | + | 45 | + |
71 | +static inline int rsub_32(DisasContext *s, int x) | 46 | +static uint64_t pmccfiltr_read_a32(CPUARMState *env, const ARMCPRegInfo *ri) |
72 | +{ | 47 | +{ |
73 | + return 32 - x; | 48 | + /* M is not visible in AArch32 */ |
74 | +} | 49 | + return env->cp15.pmccfiltr_el0 & PMCCFILTR; |
75 | +static inline int rsub_16(DisasContext *s, int x) | ||
76 | +{ | ||
77 | + return 16 - x; | ||
78 | +} | ||
79 | +static inline int rsub_8(DisasContext *s, int x) | ||
80 | +{ | ||
81 | + return 8 - x; | ||
82 | +} | 50 | +} |
83 | + | 51 | + |
84 | /* Include the generated Neon decoder */ | 52 | static void pmcntenset_write(CPUARMState *env, const ARMCPRegInfo *ri, |
85 | #include "decode-neon-dp.inc.c" | 53 | uint64_t value) |
86 | #include "decode-neon-ls.inc.c" | 54 | { |
87 | @@ -XXX,XX +XXX,XX @@ static bool do_vector_2sh(DisasContext *s, arg_2reg_shift *a, GVecGen2iFn *fn) | 55 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = { |
88 | 56 | .readfn = pmccntr_read, .writefn = pmccntr_write, | |
89 | DO_2SH(VSHL, tcg_gen_gvec_shli) | 57 | .raw_readfn = raw_read, .raw_writefn = raw_write, }, |
90 | DO_2SH(VSLI, gen_gvec_sli) | 58 | #endif |
91 | + | 59 | + { .name = "PMCCFILTR", .cp = 15, .opc1 = 0, .crn = 14, .crm = 15, .opc2 = 7, |
92 | +static bool trans_VSHR_S_2sh(DisasContext *s, arg_2reg_shift *a) | 60 | + .writefn = pmccfiltr_write_a32, .readfn = pmccfiltr_read_a32, |
93 | +{ | 61 | + .access = PL0_RW, .accessfn = pmreg_access, |
94 | + /* Signed shift out of range results in all-sign-bits */ | 62 | + .type = ARM_CP_ALIAS | ARM_CP_IO, |
95 | + a->shift = MIN(a->shift, (8 << a->size) - 1); | 63 | + .resetvalue = 0, }, |
96 | + return do_vector_2sh(s, a, tcg_gen_gvec_sari); | 64 | { .name = "PMCCFILTR_EL0", .state = ARM_CP_STATE_AA64, |
97 | +} | 65 | .opc0 = 3, .opc1 = 3, .crn = 14, .crm = 15, .opc2 = 7, |
98 | + | 66 | .writefn = pmccfiltr_write, .raw_writefn = raw_write, |
99 | +static void gen_zero_rd_2sh(unsigned vece, uint32_t rd_ofs, uint32_t rm_ofs, | ||
100 | + int64_t shift, uint32_t oprsz, uint32_t maxsz) | ||
101 | +{ | ||
102 | + tcg_gen_gvec_dup_imm(vece, rd_ofs, oprsz, maxsz, 0); | ||
103 | +} | ||
104 | + | ||
105 | +static bool trans_VSHR_U_2sh(DisasContext *s, arg_2reg_shift *a) | ||
106 | +{ | ||
107 | + /* Shift out of range is architecturally valid and results in zero. */ | ||
108 | + if (a->shift >= (8 << a->size)) { | ||
109 | + return do_vector_2sh(s, a, gen_zero_rd_2sh); | ||
110 | + } else { | ||
111 | + return do_vector_2sh(s, a, tcg_gen_gvec_shri); | ||
112 | + } | ||
113 | +} | ||
114 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
115 | index XXXXXXX..XXXXXXX 100644 | ||
116 | --- a/target/arm/translate.c | ||
117 | +++ b/target/arm/translate.c | ||
118 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
119 | op = (insn >> 8) & 0xf; | ||
120 | |||
121 | switch (op) { | ||
122 | + case 0: /* VSHR */ | ||
123 | case 5: /* VSHL, VSLI */ | ||
124 | return 1; /* handled by decodetree */ | ||
125 | default: | ||
126 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
127 | } | ||
128 | |||
129 | switch (op) { | ||
130 | - case 0: /* VSHR */ | ||
131 | - /* Right shift comes here negative. */ | ||
132 | - shift = -shift; | ||
133 | - /* Shifts larger than the element size are architecturally | ||
134 | - * valid. Unsigned results in all zeros; signed results | ||
135 | - * in all sign bits. | ||
136 | - */ | ||
137 | - if (!u) { | ||
138 | - tcg_gen_gvec_sari(size, rd_ofs, rm_ofs, | ||
139 | - MIN(shift, (8 << size) - 1), | ||
140 | - vec_size, vec_size); | ||
141 | - } else if (shift >= 8 << size) { | ||
142 | - tcg_gen_gvec_dup_imm(MO_8, rd_ofs, vec_size, | ||
143 | - vec_size, 0); | ||
144 | - } else { | ||
145 | - tcg_gen_gvec_shri(size, rd_ofs, rm_ofs, shift, | ||
146 | - vec_size, vec_size); | ||
147 | - } | ||
148 | - return 0; | ||
149 | - | ||
150 | case 1: /* VSRA */ | ||
151 | /* Right shift comes here negative. */ | ||
152 | shift = -shift; | ||
153 | -- | 67 | -- |
154 | 2.20.1 | 68 | 2.20.1 |
155 | 69 | ||
156 | 70 | diff view generated by jsdifflib |
1 | From: Paul Zimmerman <pauldzim@gmail.com> | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | Add the dwc-hsotg (dwc2) USB host controller state definitions. | 3 | Add an array for PMOVSSET so we only define it for v7ve+ platforms |
4 | Mostly based on hw/usb/hcd-ehci.h. | ||
5 | 4 | ||
6 | Signed-off-by: Paul Zimmerman <pauldzim@gmail.com> | 5 | Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org> |
7 | Message-id: 20200520235349.21215-4-pauldzim@gmail.com | 6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Message-id: 20181211151945.29137-7-aaron@os.amperecomputing.com |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 9 | --- |
11 | hw/usb/hcd-dwc2.h | 190 ++++++++++++++++++++++++++++++++++++++++++++++ | 10 | target/arm/helper.c | 28 ++++++++++++++++++++++++++++ |
12 | 1 file changed, 190 insertions(+) | 11 | 1 file changed, 28 insertions(+) |
13 | create mode 100644 hw/usb/hcd-dwc2.h | ||
14 | 12 | ||
15 | diff --git a/hw/usb/hcd-dwc2.h b/hw/usb/hcd-dwc2.h | 13 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
16 | new file mode 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
17 | index XXXXXXX..XXXXXXX | 15 | --- a/target/arm/helper.c |
18 | --- /dev/null | 16 | +++ b/target/arm/helper.c |
19 | +++ b/hw/usb/hcd-dwc2.h | 17 | @@ -XXX,XX +XXX,XX @@ static void pmovsr_write(CPUARMState *env, const ARMCPRegInfo *ri, |
20 | @@ -XXX,XX +XXX,XX @@ | 18 | env->cp15.c9_pmovsr &= ~value; |
21 | +/* | 19 | } |
22 | + * dwc-hsotg (dwc2) USB host controller state definitions | 20 | |
23 | + * | 21 | +static void pmovsset_write(CPUARMState *env, const ARMCPRegInfo *ri, |
24 | + * Based on hw/usb/hcd-ehci.h | 22 | + uint64_t value) |
25 | + * | 23 | +{ |
26 | + * Copyright (c) 2020 Paul Zimmerman <pauldzim@gmail.com> | 24 | + value &= pmu_counter_mask(env); |
27 | + * | 25 | + env->cp15.c9_pmovsr |= value; |
28 | + * This program is free software; you can redistribute it and/or modify | 26 | +} |
29 | + * it under the terms of the GNU General Public License as published by | ||
30 | + * the Free Software Foundation; either version 2 of the License, or | ||
31 | + * (at your option) any later version. | ||
32 | + * | ||
33 | + * This program is distributed in the hope that it will be useful, | ||
34 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
35 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
36 | + * GNU General Public License for more details. | ||
37 | + */ | ||
38 | + | 27 | + |
39 | +#ifndef HW_USB_DWC2_H | 28 | static void pmxevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri, |
40 | +#define HW_USB_DWC2_H | 29 | uint64_t value) |
41 | + | 30 | { |
42 | +#include "qemu/timer.h" | 31 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7mp_cp_reginfo[] = { |
43 | +#include "hw/irq.h" | 32 | REGINFO_SENTINEL |
44 | +#include "hw/sysbus.h" | 33 | }; |
45 | +#include "hw/usb.h" | 34 | |
46 | +#include "sysemu/dma.h" | 35 | +static const ARMCPRegInfo pmovsset_cp_reginfo[] = { |
47 | + | 36 | + /* PMOVSSET is not implemented in v7 before v7ve */ |
48 | +#define DWC2_MMIO_SIZE 0x11000 | 37 | + { .name = "PMOVSSET", .cp = 15, .opc1 = 0, .crn = 9, .crm = 14, .opc2 = 3, |
49 | + | 38 | + .access = PL0_RW, .accessfn = pmreg_access, |
50 | +#define DWC2_NB_CHAN 8 /* Number of host channels */ | 39 | + .type = ARM_CP_ALIAS, |
51 | +#define DWC2_MAX_XFER_SIZE 65536 /* Max transfer size expected in HCTSIZ */ | 40 | + .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmovsr), |
52 | + | 41 | + .writefn = pmovsset_write, |
53 | +typedef struct DWC2Packet DWC2Packet; | 42 | + .raw_writefn = raw_write }, |
54 | +typedef struct DWC2State DWC2State; | 43 | + { .name = "PMOVSSET_EL0", .state = ARM_CP_STATE_AA64, |
55 | +typedef struct DWC2Class DWC2Class; | 44 | + .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 14, .opc2 = 3, |
56 | + | 45 | + .access = PL0_RW, .accessfn = pmreg_access, |
57 | +enum async_state { | 46 | + .type = ARM_CP_ALIAS, |
58 | + DWC2_ASYNC_NONE = 0, | 47 | + .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr), |
59 | + DWC2_ASYNC_INITIALIZED, | 48 | + .writefn = pmovsset_write, |
60 | + DWC2_ASYNC_INFLIGHT, | 49 | + .raw_writefn = raw_write }, |
61 | + DWC2_ASYNC_FINISHED, | 50 | + REGINFO_SENTINEL |
62 | +}; | 51 | +}; |
63 | + | 52 | + |
64 | +struct DWC2Packet { | 53 | static void teecr_write(CPUARMState *env, const ARMCPRegInfo *ri, |
65 | + USBPacket packet; | 54 | uint64_t value) |
66 | + uint32_t devadr; | 55 | { |
67 | + uint32_t epnum; | 56 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) |
68 | + uint32_t epdir; | 57 | !arm_feature(env, ARM_FEATURE_PMSA)) { |
69 | + uint32_t mps; | 58 | define_arm_cp_regs(cpu, v7mp_cp_reginfo); |
70 | + uint32_t pid; | 59 | } |
71 | + uint32_t index; | 60 | + if (arm_feature(env, ARM_FEATURE_V7VE)) { |
72 | + uint32_t pcnt; | 61 | + define_arm_cp_regs(cpu, pmovsset_cp_reginfo); |
73 | + uint32_t len; | 62 | + } |
74 | + int32_t async; | 63 | if (arm_feature(env, ARM_FEATURE_V7)) { |
75 | + bool small; | 64 | /* v7 performance monitor control register: same implementor |
76 | + bool needs_service; | 65 | * field as main ID register, and we implement only the cycle |
77 | +}; | ||
78 | + | ||
79 | +struct DWC2State { | ||
80 | + /*< private >*/ | ||
81 | + SysBusDevice parent_obj; | ||
82 | + | ||
83 | + /*< public >*/ | ||
84 | + USBBus bus; | ||
85 | + qemu_irq irq; | ||
86 | + MemoryRegion *dma_mr; | ||
87 | + AddressSpace dma_as; | ||
88 | + MemoryRegion container; | ||
89 | + MemoryRegion hsotg; | ||
90 | + MemoryRegion fifos; | ||
91 | + | ||
92 | + union { | ||
93 | +#define DWC2_GLBREG_SIZE 0x70 | ||
94 | + uint32_t glbreg[DWC2_GLBREG_SIZE / sizeof(uint32_t)]; | ||
95 | + struct { | ||
96 | + uint32_t gotgctl; /* 00 */ | ||
97 | + uint32_t gotgint; /* 04 */ | ||
98 | + uint32_t gahbcfg; /* 08 */ | ||
99 | + uint32_t gusbcfg; /* 0c */ | ||
100 | + uint32_t grstctl; /* 10 */ | ||
101 | + uint32_t gintsts; /* 14 */ | ||
102 | + uint32_t gintmsk; /* 18 */ | ||
103 | + uint32_t grxstsr; /* 1c */ | ||
104 | + uint32_t grxstsp; /* 20 */ | ||
105 | + uint32_t grxfsiz; /* 24 */ | ||
106 | + uint32_t gnptxfsiz; /* 28 */ | ||
107 | + uint32_t gnptxsts; /* 2c */ | ||
108 | + uint32_t gi2cctl; /* 30 */ | ||
109 | + uint32_t gpvndctl; /* 34 */ | ||
110 | + uint32_t ggpio; /* 38 */ | ||
111 | + uint32_t guid; /* 3c */ | ||
112 | + uint32_t gsnpsid; /* 40 */ | ||
113 | + uint32_t ghwcfg1; /* 44 */ | ||
114 | + uint32_t ghwcfg2; /* 48 */ | ||
115 | + uint32_t ghwcfg3; /* 4c */ | ||
116 | + uint32_t ghwcfg4; /* 50 */ | ||
117 | + uint32_t glpmcfg; /* 54 */ | ||
118 | + uint32_t gpwrdn; /* 58 */ | ||
119 | + uint32_t gdfifocfg; /* 5c */ | ||
120 | + uint32_t gadpctl; /* 60 */ | ||
121 | + uint32_t grefclk; /* 64 */ | ||
122 | + uint32_t gintmsk2; /* 68 */ | ||
123 | + uint32_t gintsts2; /* 6c */ | ||
124 | + }; | ||
125 | + }; | ||
126 | + | ||
127 | + union { | ||
128 | +#define DWC2_FSZREG_SIZE 0x04 | ||
129 | + uint32_t fszreg[DWC2_FSZREG_SIZE / sizeof(uint32_t)]; | ||
130 | + struct { | ||
131 | + uint32_t hptxfsiz; /* 100 */ | ||
132 | + }; | ||
133 | + }; | ||
134 | + | ||
135 | + union { | ||
136 | +#define DWC2_HREG0_SIZE 0x44 | ||
137 | + uint32_t hreg0[DWC2_HREG0_SIZE / sizeof(uint32_t)]; | ||
138 | + struct { | ||
139 | + uint32_t hcfg; /* 400 */ | ||
140 | + uint32_t hfir; /* 404 */ | ||
141 | + uint32_t hfnum; /* 408 */ | ||
142 | + uint32_t rsvd0; /* 40c */ | ||
143 | + uint32_t hptxsts; /* 410 */ | ||
144 | + uint32_t haint; /* 414 */ | ||
145 | + uint32_t haintmsk; /* 418 */ | ||
146 | + uint32_t hflbaddr; /* 41c */ | ||
147 | + uint32_t rsvd1[8]; /* 420-43c */ | ||
148 | + uint32_t hprt0; /* 440 */ | ||
149 | + }; | ||
150 | + }; | ||
151 | + | ||
152 | +#define DWC2_HREG1_SIZE (0x20 * DWC2_NB_CHAN) | ||
153 | + uint32_t hreg1[DWC2_HREG1_SIZE / sizeof(uint32_t)]; | ||
154 | + | ||
155 | +#define hcchar(_ch) hreg1[((_ch) << 3) + 0] /* 500, 520, ... */ | ||
156 | +#define hcsplt(_ch) hreg1[((_ch) << 3) + 1] /* 504, 524, ... */ | ||
157 | +#define hcint(_ch) hreg1[((_ch) << 3) + 2] /* 508, 528, ... */ | ||
158 | +#define hcintmsk(_ch) hreg1[((_ch) << 3) + 3] /* 50c, 52c, ... */ | ||
159 | +#define hctsiz(_ch) hreg1[((_ch) << 3) + 4] /* 510, 530, ... */ | ||
160 | +#define hcdma(_ch) hreg1[((_ch) << 3) + 5] /* 514, 534, ... */ | ||
161 | +#define hcdmab(_ch) hreg1[((_ch) << 3) + 7] /* 51c, 53c, ... */ | ||
162 | + | ||
163 | + union { | ||
164 | +#define DWC2_PCGREG_SIZE 0x08 | ||
165 | + uint32_t pcgreg[DWC2_PCGREG_SIZE / sizeof(uint32_t)]; | ||
166 | + struct { | ||
167 | + uint32_t pcgctl; /* e00 */ | ||
168 | + uint32_t pcgcctl1; /* e04 */ | ||
169 | + }; | ||
170 | + }; | ||
171 | + | ||
172 | + /* TODO - implement FIFO registers for slave mode */ | ||
173 | +#define DWC2_HFIFO_SIZE (0x1000 * DWC2_NB_CHAN) | ||
174 | + | ||
175 | + /* | ||
176 | + * Internal state | ||
177 | + */ | ||
178 | + QEMUTimer *eof_timer; | ||
179 | + QEMUTimer *frame_timer; | ||
180 | + QEMUBH *async_bh; | ||
181 | + int64_t sof_time; | ||
182 | + int64_t usb_frame_time; | ||
183 | + int64_t usb_bit_time; | ||
184 | + uint32_t usb_version; | ||
185 | + uint16_t frame_number; | ||
186 | + uint16_t fi; | ||
187 | + uint16_t next_chan; | ||
188 | + bool working; | ||
189 | + USBPort uport; | ||
190 | + DWC2Packet packet[DWC2_NB_CHAN]; /* one packet per chan */ | ||
191 | + uint8_t usb_buf[DWC2_NB_CHAN][DWC2_MAX_XFER_SIZE]; /* one buffer per chan */ | ||
192 | +}; | ||
193 | + | ||
194 | +struct DWC2Class { | ||
195 | + /*< private >*/ | ||
196 | + SysBusDeviceClass parent_class; | ||
197 | + ResettablePhases parent_phases; | ||
198 | + | ||
199 | + /*< public >*/ | ||
200 | +}; | ||
201 | + | ||
202 | +#define TYPE_DWC2_USB "dwc2-usb" | ||
203 | +#define DWC2_USB(obj) \ | ||
204 | + OBJECT_CHECK(DWC2State, (obj), TYPE_DWC2_USB) | ||
205 | +#define DWC2_CLASS(klass) \ | ||
206 | + OBJECT_CLASS_CHECK(DWC2Class, (klass), TYPE_DWC2_USB) | ||
207 | +#define DWC2_GET_CLASS(obj) \ | ||
208 | + OBJECT_GET_CLASS(DWC2Class, (obj), TYPE_DWC2_USB) | ||
209 | + | ||
210 | +#endif | ||
211 | -- | 66 | -- |
212 | 2.20.1 | 67 | 2.20.1 |
213 | 68 | ||
214 | 69 | diff view generated by jsdifflib |
1 | From: Paul Zimmerman <pauldzim@gmail.com> | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | Import the dwc-hsotg (dwc2) register definitions file from the | 3 | This is immediately necessary for the PMUv3 implementation to check |
4 | Linux kernel. This is a copy of drivers/usb/dwc2/hw.h from the | 4 | ID_DFR0.PerfMon to enable/disable specific features, but defines the |
5 | mainline Linux kernel, the only changes being to the header, and | 5 | full complement of fields for possible future use elsewhere. |
6 | two instances of 'u32' changed to 'uint32_t' to allow it to | ||
7 | compile. Checkpatch throws a boatload of errors due to the tab | ||
8 | indentation, but I would rather import it as-is than reformat it. | ||
9 | 6 | ||
10 | Signed-off-by: Paul Zimmerman <pauldzim@gmail.com> | 7 | Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com> |
11 | Message-id: 20200520235349.21215-3-pauldzim@gmail.com | ||
12 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Message-id: 20181211151945.29137-8-aaron@os.amperecomputing.com | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
14 | --- | 11 | --- |
15 | include/hw/usb/dwc2-regs.h | 899 +++++++++++++++++++++++++++++++++++++ | 12 | target/arm/cpu.h | 9 +++++++++ |
16 | 1 file changed, 899 insertions(+) | 13 | 1 file changed, 9 insertions(+) |
17 | create mode 100644 include/hw/usb/dwc2-regs.h | ||
18 | 14 | ||
19 | diff --git a/include/hw/usb/dwc2-regs.h b/include/hw/usb/dwc2-regs.h | 15 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
20 | new file mode 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
21 | index XXXXXXX..XXXXXXX | 17 | --- a/target/arm/cpu.h |
22 | --- /dev/null | 18 | +++ b/target/arm/cpu.h |
23 | +++ b/include/hw/usb/dwc2-regs.h | 19 | @@ -XXX,XX +XXX,XX @@ FIELD(ID_AA64MMFR1, PAN, 20, 4) |
24 | @@ -XXX,XX +XXX,XX @@ | 20 | FIELD(ID_AA64MMFR1, SPECSEI, 24, 4) |
25 | +/* SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) */ | 21 | FIELD(ID_AA64MMFR1, XNX, 28, 4) |
26 | +/* | 22 | |
27 | + * Imported from the Linux kernel file drivers/usb/dwc2/hw.h, commit | 23 | +FIELD(ID_DFR0, COPDBG, 0, 4) |
28 | + * a89bae709b3492b478480a2c9734e7e9393b279c ("usb: dwc2: Move | 24 | +FIELD(ID_DFR0, COPSDBG, 4, 4) |
29 | + * UTMI_PHY_DATA defines closer") | 25 | +FIELD(ID_DFR0, MMAPDBG, 8, 4) |
30 | + * | 26 | +FIELD(ID_DFR0, COPTRC, 12, 4) |
31 | + * hw.h - DesignWare HS OTG Controller hardware definitions | 27 | +FIELD(ID_DFR0, MMAPTRC, 16, 4) |
32 | + * | 28 | +FIELD(ID_DFR0, MPROFDBG, 20, 4) |
33 | + * Copyright 2004-2013 Synopsys, Inc. | 29 | +FIELD(ID_DFR0, PERFMON, 24, 4) |
34 | + * | 30 | +FIELD(ID_DFR0, TRACEFILT, 28, 4) |
35 | + * Redistribution and use in source and binary forms, with or without | ||
36 | + * modification, are permitted provided that the following conditions | ||
37 | + * are met: | ||
38 | + * 1. Redistributions of source code must retain the above copyright | ||
39 | + * notice, this list of conditions, and the following disclaimer, | ||
40 | + * without modification. | ||
41 | + * 2. Redistributions in binary form must reproduce the above copyright | ||
42 | + * notice, this list of conditions and the following disclaimer in the | ||
43 | + * documentation and/or other materials provided with the distribution. | ||
44 | + * 3. The names of the above-listed copyright holders may not be used | ||
45 | + * to endorse or promote products derived from this software without | ||
46 | + * specific prior written permission. | ||
47 | + * | ||
48 | + * ALTERNATIVELY, this software may be distributed under the terms of the | ||
49 | + * GNU General Public License ("GPL") as published by the Free Software | ||
50 | + * Foundation; either version 2 of the License, or (at your option) any | ||
51 | + * later version. | ||
52 | + * | ||
53 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
54 | + * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
55 | + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
56 | + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
57 | + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
58 | + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
59 | + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
60 | + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
61 | + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
62 | + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
63 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
64 | + */ | ||
65 | + | 31 | + |
66 | +#ifndef __DWC2_HW_H__ | 32 | QEMU_BUILD_BUG_ON(ARRAY_SIZE(((ARMCPU *)0)->ccsidr) <= R_V7M_CSSELR_INDEX_MASK); |
67 | +#define __DWC2_HW_H__ | 33 | |
68 | + | 34 | /* If adding a feature bit which corresponds to a Linux ELF |
69 | +#define HSOTG_REG(x) (x) | ||
70 | + | ||
71 | +#define GOTGCTL HSOTG_REG(0x000) | ||
72 | +#define GOTGCTL_CHIRPEN BIT(27) | ||
73 | +#define GOTGCTL_MULT_VALID_BC_MASK (0x1f << 22) | ||
74 | +#define GOTGCTL_MULT_VALID_BC_SHIFT 22 | ||
75 | +#define GOTGCTL_OTGVER BIT(20) | ||
76 | +#define GOTGCTL_BSESVLD BIT(19) | ||
77 | +#define GOTGCTL_ASESVLD BIT(18) | ||
78 | +#define GOTGCTL_DBNC_SHORT BIT(17) | ||
79 | +#define GOTGCTL_CONID_B BIT(16) | ||
80 | +#define GOTGCTL_DBNCE_FLTR_BYPASS BIT(15) | ||
81 | +#define GOTGCTL_DEVHNPEN BIT(11) | ||
82 | +#define GOTGCTL_HSTSETHNPEN BIT(10) | ||
83 | +#define GOTGCTL_HNPREQ BIT(9) | ||
84 | +#define GOTGCTL_HSTNEGSCS BIT(8) | ||
85 | +#define GOTGCTL_SESREQ BIT(1) | ||
86 | +#define GOTGCTL_SESREQSCS BIT(0) | ||
87 | + | ||
88 | +#define GOTGINT HSOTG_REG(0x004) | ||
89 | +#define GOTGINT_DBNCE_DONE BIT(19) | ||
90 | +#define GOTGINT_A_DEV_TOUT_CHG BIT(18) | ||
91 | +#define GOTGINT_HST_NEG_DET BIT(17) | ||
92 | +#define GOTGINT_HST_NEG_SUC_STS_CHNG BIT(9) | ||
93 | +#define GOTGINT_SES_REQ_SUC_STS_CHNG BIT(8) | ||
94 | +#define GOTGINT_SES_END_DET BIT(2) | ||
95 | + | ||
96 | +#define GAHBCFG HSOTG_REG(0x008) | ||
97 | +#define GAHBCFG_AHB_SINGLE BIT(23) | ||
98 | +#define GAHBCFG_NOTI_ALL_DMA_WRIT BIT(22) | ||
99 | +#define GAHBCFG_REM_MEM_SUPP BIT(21) | ||
100 | +#define GAHBCFG_P_TXF_EMP_LVL BIT(8) | ||
101 | +#define GAHBCFG_NP_TXF_EMP_LVL BIT(7) | ||
102 | +#define GAHBCFG_DMA_EN BIT(5) | ||
103 | +#define GAHBCFG_HBSTLEN_MASK (0xf << 1) | ||
104 | +#define GAHBCFG_HBSTLEN_SHIFT 1 | ||
105 | +#define GAHBCFG_HBSTLEN_SINGLE 0 | ||
106 | +#define GAHBCFG_HBSTLEN_INCR 1 | ||
107 | +#define GAHBCFG_HBSTLEN_INCR4 3 | ||
108 | +#define GAHBCFG_HBSTLEN_INCR8 5 | ||
109 | +#define GAHBCFG_HBSTLEN_INCR16 7 | ||
110 | +#define GAHBCFG_GLBL_INTR_EN BIT(0) | ||
111 | +#define GAHBCFG_CTRL_MASK (GAHBCFG_P_TXF_EMP_LVL | \ | ||
112 | + GAHBCFG_NP_TXF_EMP_LVL | \ | ||
113 | + GAHBCFG_DMA_EN | \ | ||
114 | + GAHBCFG_GLBL_INTR_EN) | ||
115 | + | ||
116 | +#define GUSBCFG HSOTG_REG(0x00C) | ||
117 | +#define GUSBCFG_FORCEDEVMODE BIT(30) | ||
118 | +#define GUSBCFG_FORCEHOSTMODE BIT(29) | ||
119 | +#define GUSBCFG_TXENDDELAY BIT(28) | ||
120 | +#define GUSBCFG_ICTRAFFICPULLREMOVE BIT(27) | ||
121 | +#define GUSBCFG_ICUSBCAP BIT(26) | ||
122 | +#define GUSBCFG_ULPI_INT_PROT_DIS BIT(25) | ||
123 | +#define GUSBCFG_INDICATORPASSTHROUGH BIT(24) | ||
124 | +#define GUSBCFG_INDICATORCOMPLEMENT BIT(23) | ||
125 | +#define GUSBCFG_TERMSELDLPULSE BIT(22) | ||
126 | +#define GUSBCFG_ULPI_INT_VBUS_IND BIT(21) | ||
127 | +#define GUSBCFG_ULPI_EXT_VBUS_DRV BIT(20) | ||
128 | +#define GUSBCFG_ULPI_CLK_SUSP_M BIT(19) | ||
129 | +#define GUSBCFG_ULPI_AUTO_RES BIT(18) | ||
130 | +#define GUSBCFG_ULPI_FS_LS BIT(17) | ||
131 | +#define GUSBCFG_OTG_UTMI_FS_SEL BIT(16) | ||
132 | +#define GUSBCFG_PHY_LP_CLK_SEL BIT(15) | ||
133 | +#define GUSBCFG_USBTRDTIM_MASK (0xf << 10) | ||
134 | +#define GUSBCFG_USBTRDTIM_SHIFT 10 | ||
135 | +#define GUSBCFG_HNPCAP BIT(9) | ||
136 | +#define GUSBCFG_SRPCAP BIT(8) | ||
137 | +#define GUSBCFG_DDRSEL BIT(7) | ||
138 | +#define GUSBCFG_PHYSEL BIT(6) | ||
139 | +#define GUSBCFG_FSINTF BIT(5) | ||
140 | +#define GUSBCFG_ULPI_UTMI_SEL BIT(4) | ||
141 | +#define GUSBCFG_PHYIF16 BIT(3) | ||
142 | +#define GUSBCFG_PHYIF8 (0 << 3) | ||
143 | +#define GUSBCFG_TOUTCAL_MASK (0x7 << 0) | ||
144 | +#define GUSBCFG_TOUTCAL_SHIFT 0 | ||
145 | +#define GUSBCFG_TOUTCAL_LIMIT 0x7 | ||
146 | +#define GUSBCFG_TOUTCAL(_x) ((_x) << 0) | ||
147 | + | ||
148 | +#define GRSTCTL HSOTG_REG(0x010) | ||
149 | +#define GRSTCTL_AHBIDLE BIT(31) | ||
150 | +#define GRSTCTL_DMAREQ BIT(30) | ||
151 | +#define GRSTCTL_TXFNUM_MASK (0x1f << 6) | ||
152 | +#define GRSTCTL_TXFNUM_SHIFT 6 | ||
153 | +#define GRSTCTL_TXFNUM_LIMIT 0x1f | ||
154 | +#define GRSTCTL_TXFNUM(_x) ((_x) << 6) | ||
155 | +#define GRSTCTL_TXFFLSH BIT(5) | ||
156 | +#define GRSTCTL_RXFFLSH BIT(4) | ||
157 | +#define GRSTCTL_IN_TKNQ_FLSH BIT(3) | ||
158 | +#define GRSTCTL_FRMCNTRRST BIT(2) | ||
159 | +#define GRSTCTL_HSFTRST BIT(1) | ||
160 | +#define GRSTCTL_CSFTRST BIT(0) | ||
161 | + | ||
162 | +#define GINTSTS HSOTG_REG(0x014) | ||
163 | +#define GINTMSK HSOTG_REG(0x018) | ||
164 | +#define GINTSTS_WKUPINT BIT(31) | ||
165 | +#define GINTSTS_SESSREQINT BIT(30) | ||
166 | +#define GINTSTS_DISCONNINT BIT(29) | ||
167 | +#define GINTSTS_CONIDSTSCHNG BIT(28) | ||
168 | +#define GINTSTS_LPMTRANRCVD BIT(27) | ||
169 | +#define GINTSTS_PTXFEMP BIT(26) | ||
170 | +#define GINTSTS_HCHINT BIT(25) | ||
171 | +#define GINTSTS_PRTINT BIT(24) | ||
172 | +#define GINTSTS_RESETDET BIT(23) | ||
173 | +#define GINTSTS_FET_SUSP BIT(22) | ||
174 | +#define GINTSTS_INCOMPL_IP BIT(21) | ||
175 | +#define GINTSTS_INCOMPL_SOOUT BIT(21) | ||
176 | +#define GINTSTS_INCOMPL_SOIN BIT(20) | ||
177 | +#define GINTSTS_OEPINT BIT(19) | ||
178 | +#define GINTSTS_IEPINT BIT(18) | ||
179 | +#define GINTSTS_EPMIS BIT(17) | ||
180 | +#define GINTSTS_RESTOREDONE BIT(16) | ||
181 | +#define GINTSTS_EOPF BIT(15) | ||
182 | +#define GINTSTS_ISOUTDROP BIT(14) | ||
183 | +#define GINTSTS_ENUMDONE BIT(13) | ||
184 | +#define GINTSTS_USBRST BIT(12) | ||
185 | +#define GINTSTS_USBSUSP BIT(11) | ||
186 | +#define GINTSTS_ERLYSUSP BIT(10) | ||
187 | +#define GINTSTS_I2CINT BIT(9) | ||
188 | +#define GINTSTS_ULPI_CK_INT BIT(8) | ||
189 | +#define GINTSTS_GOUTNAKEFF BIT(7) | ||
190 | +#define GINTSTS_GINNAKEFF BIT(6) | ||
191 | +#define GINTSTS_NPTXFEMP BIT(5) | ||
192 | +#define GINTSTS_RXFLVL BIT(4) | ||
193 | +#define GINTSTS_SOF BIT(3) | ||
194 | +#define GINTSTS_OTGINT BIT(2) | ||
195 | +#define GINTSTS_MODEMIS BIT(1) | ||
196 | +#define GINTSTS_CURMODE_HOST BIT(0) | ||
197 | + | ||
198 | +#define GRXSTSR HSOTG_REG(0x01C) | ||
199 | +#define GRXSTSP HSOTG_REG(0x020) | ||
200 | +#define GRXSTS_FN_MASK (0x7f << 25) | ||
201 | +#define GRXSTS_FN_SHIFT 25 | ||
202 | +#define GRXSTS_PKTSTS_MASK (0xf << 17) | ||
203 | +#define GRXSTS_PKTSTS_SHIFT 17 | ||
204 | +#define GRXSTS_PKTSTS_GLOBALOUTNAK 1 | ||
205 | +#define GRXSTS_PKTSTS_OUTRX 2 | ||
206 | +#define GRXSTS_PKTSTS_HCHIN 2 | ||
207 | +#define GRXSTS_PKTSTS_OUTDONE 3 | ||
208 | +#define GRXSTS_PKTSTS_HCHIN_XFER_COMP 3 | ||
209 | +#define GRXSTS_PKTSTS_SETUPDONE 4 | ||
210 | +#define GRXSTS_PKTSTS_DATATOGGLEERR 5 | ||
211 | +#define GRXSTS_PKTSTS_SETUPRX 6 | ||
212 | +#define GRXSTS_PKTSTS_HCHHALTED 7 | ||
213 | +#define GRXSTS_HCHNUM_MASK (0xf << 0) | ||
214 | +#define GRXSTS_HCHNUM_SHIFT 0 | ||
215 | +#define GRXSTS_DPID_MASK (0x3 << 15) | ||
216 | +#define GRXSTS_DPID_SHIFT 15 | ||
217 | +#define GRXSTS_BYTECNT_MASK (0x7ff << 4) | ||
218 | +#define GRXSTS_BYTECNT_SHIFT 4 | ||
219 | +#define GRXSTS_EPNUM_MASK (0xf << 0) | ||
220 | +#define GRXSTS_EPNUM_SHIFT 0 | ||
221 | + | ||
222 | +#define GRXFSIZ HSOTG_REG(0x024) | ||
223 | +#define GRXFSIZ_DEPTH_MASK (0xffff << 0) | ||
224 | +#define GRXFSIZ_DEPTH_SHIFT 0 | ||
225 | + | ||
226 | +#define GNPTXFSIZ HSOTG_REG(0x028) | ||
227 | +/* Use FIFOSIZE_* constants to access this register */ | ||
228 | + | ||
229 | +#define GNPTXSTS HSOTG_REG(0x02C) | ||
230 | +#define GNPTXSTS_NP_TXQ_TOP_MASK (0x7f << 24) | ||
231 | +#define GNPTXSTS_NP_TXQ_TOP_SHIFT 24 | ||
232 | +#define GNPTXSTS_NP_TXQ_SPC_AVAIL_MASK (0xff << 16) | ||
233 | +#define GNPTXSTS_NP_TXQ_SPC_AVAIL_SHIFT 16 | ||
234 | +#define GNPTXSTS_NP_TXQ_SPC_AVAIL_GET(_v) (((_v) >> 16) & 0xff) | ||
235 | +#define GNPTXSTS_NP_TXF_SPC_AVAIL_MASK (0xffff << 0) | ||
236 | +#define GNPTXSTS_NP_TXF_SPC_AVAIL_SHIFT 0 | ||
237 | +#define GNPTXSTS_NP_TXF_SPC_AVAIL_GET(_v) (((_v) >> 0) & 0xffff) | ||
238 | + | ||
239 | +#define GI2CCTL HSOTG_REG(0x0030) | ||
240 | +#define GI2CCTL_BSYDNE BIT(31) | ||
241 | +#define GI2CCTL_RW BIT(30) | ||
242 | +#define GI2CCTL_I2CDATSE0 BIT(28) | ||
243 | +#define GI2CCTL_I2CDEVADDR_MASK (0x3 << 26) | ||
244 | +#define GI2CCTL_I2CDEVADDR_SHIFT 26 | ||
245 | +#define GI2CCTL_I2CSUSPCTL BIT(25) | ||
246 | +#define GI2CCTL_ACK BIT(24) | ||
247 | +#define GI2CCTL_I2CEN BIT(23) | ||
248 | +#define GI2CCTL_ADDR_MASK (0x7f << 16) | ||
249 | +#define GI2CCTL_ADDR_SHIFT 16 | ||
250 | +#define GI2CCTL_REGADDR_MASK (0xff << 8) | ||
251 | +#define GI2CCTL_REGADDR_SHIFT 8 | ||
252 | +#define GI2CCTL_RWDATA_MASK (0xff << 0) | ||
253 | +#define GI2CCTL_RWDATA_SHIFT 0 | ||
254 | + | ||
255 | +#define GPVNDCTL HSOTG_REG(0x0034) | ||
256 | +#define GGPIO HSOTG_REG(0x0038) | ||
257 | +#define GGPIO_STM32_OTG_GCCFG_PWRDWN BIT(16) | ||
258 | + | ||
259 | +#define GUID HSOTG_REG(0x003c) | ||
260 | +#define GSNPSID HSOTG_REG(0x0040) | ||
261 | +#define GHWCFG1 HSOTG_REG(0x0044) | ||
262 | +#define GSNPSID_ID_MASK GENMASK(31, 16) | ||
263 | + | ||
264 | +#define GHWCFG2 HSOTG_REG(0x0048) | ||
265 | +#define GHWCFG2_OTG_ENABLE_IC_USB BIT(31) | ||
266 | +#define GHWCFG2_DEV_TOKEN_Q_DEPTH_MASK (0x1f << 26) | ||
267 | +#define GHWCFG2_DEV_TOKEN_Q_DEPTH_SHIFT 26 | ||
268 | +#define GHWCFG2_HOST_PERIO_TX_Q_DEPTH_MASK (0x3 << 24) | ||
269 | +#define GHWCFG2_HOST_PERIO_TX_Q_DEPTH_SHIFT 24 | ||
270 | +#define GHWCFG2_NONPERIO_TX_Q_DEPTH_MASK (0x3 << 22) | ||
271 | +#define GHWCFG2_NONPERIO_TX_Q_DEPTH_SHIFT 22 | ||
272 | +#define GHWCFG2_MULTI_PROC_INT BIT(20) | ||
273 | +#define GHWCFG2_DYNAMIC_FIFO BIT(19) | ||
274 | +#define GHWCFG2_PERIO_EP_SUPPORTED BIT(18) | ||
275 | +#define GHWCFG2_NUM_HOST_CHAN_MASK (0xf << 14) | ||
276 | +#define GHWCFG2_NUM_HOST_CHAN_SHIFT 14 | ||
277 | +#define GHWCFG2_NUM_DEV_EP_MASK (0xf << 10) | ||
278 | +#define GHWCFG2_NUM_DEV_EP_SHIFT 10 | ||
279 | +#define GHWCFG2_FS_PHY_TYPE_MASK (0x3 << 8) | ||
280 | +#define GHWCFG2_FS_PHY_TYPE_SHIFT 8 | ||
281 | +#define GHWCFG2_FS_PHY_TYPE_NOT_SUPPORTED 0 | ||
282 | +#define GHWCFG2_FS_PHY_TYPE_DEDICATED 1 | ||
283 | +#define GHWCFG2_FS_PHY_TYPE_SHARED_UTMI 2 | ||
284 | +#define GHWCFG2_FS_PHY_TYPE_SHARED_ULPI 3 | ||
285 | +#define GHWCFG2_HS_PHY_TYPE_MASK (0x3 << 6) | ||
286 | +#define GHWCFG2_HS_PHY_TYPE_SHIFT 6 | ||
287 | +#define GHWCFG2_HS_PHY_TYPE_NOT_SUPPORTED 0 | ||
288 | +#define GHWCFG2_HS_PHY_TYPE_UTMI 1 | ||
289 | +#define GHWCFG2_HS_PHY_TYPE_ULPI 2 | ||
290 | +#define GHWCFG2_HS_PHY_TYPE_UTMI_ULPI 3 | ||
291 | +#define GHWCFG2_POINT2POINT BIT(5) | ||
292 | +#define GHWCFG2_ARCHITECTURE_MASK (0x3 << 3) | ||
293 | +#define GHWCFG2_ARCHITECTURE_SHIFT 3 | ||
294 | +#define GHWCFG2_SLAVE_ONLY_ARCH 0 | ||
295 | +#define GHWCFG2_EXT_DMA_ARCH 1 | ||
296 | +#define GHWCFG2_INT_DMA_ARCH 2 | ||
297 | +#define GHWCFG2_OP_MODE_MASK (0x7 << 0) | ||
298 | +#define GHWCFG2_OP_MODE_SHIFT 0 | ||
299 | +#define GHWCFG2_OP_MODE_HNP_SRP_CAPABLE 0 | ||
300 | +#define GHWCFG2_OP_MODE_SRP_ONLY_CAPABLE 1 | ||
301 | +#define GHWCFG2_OP_MODE_NO_HNP_SRP_CAPABLE 2 | ||
302 | +#define GHWCFG2_OP_MODE_SRP_CAPABLE_DEVICE 3 | ||
303 | +#define GHWCFG2_OP_MODE_NO_SRP_CAPABLE_DEVICE 4 | ||
304 | +#define GHWCFG2_OP_MODE_SRP_CAPABLE_HOST 5 | ||
305 | +#define GHWCFG2_OP_MODE_NO_SRP_CAPABLE_HOST 6 | ||
306 | +#define GHWCFG2_OP_MODE_UNDEFINED 7 | ||
307 | + | ||
308 | +#define GHWCFG3 HSOTG_REG(0x004c) | ||
309 | +#define GHWCFG3_DFIFO_DEPTH_MASK (0xffff << 16) | ||
310 | +#define GHWCFG3_DFIFO_DEPTH_SHIFT 16 | ||
311 | +#define GHWCFG3_OTG_LPM_EN BIT(15) | ||
312 | +#define GHWCFG3_BC_SUPPORT BIT(14) | ||
313 | +#define GHWCFG3_OTG_ENABLE_HSIC BIT(13) | ||
314 | +#define GHWCFG3_ADP_SUPP BIT(12) | ||
315 | +#define GHWCFG3_SYNCH_RESET_TYPE BIT(11) | ||
316 | +#define GHWCFG3_OPTIONAL_FEATURES BIT(10) | ||
317 | +#define GHWCFG3_VENDOR_CTRL_IF BIT(9) | ||
318 | +#define GHWCFG3_I2C BIT(8) | ||
319 | +#define GHWCFG3_OTG_FUNC BIT(7) | ||
320 | +#define GHWCFG3_PACKET_SIZE_CNTR_WIDTH_MASK (0x7 << 4) | ||
321 | +#define GHWCFG3_PACKET_SIZE_CNTR_WIDTH_SHIFT 4 | ||
322 | +#define GHWCFG3_XFER_SIZE_CNTR_WIDTH_MASK (0xf << 0) | ||
323 | +#define GHWCFG3_XFER_SIZE_CNTR_WIDTH_SHIFT 0 | ||
324 | + | ||
325 | +#define GHWCFG4 HSOTG_REG(0x0050) | ||
326 | +#define GHWCFG4_DESC_DMA_DYN BIT(31) | ||
327 | +#define GHWCFG4_DESC_DMA BIT(30) | ||
328 | +#define GHWCFG4_NUM_IN_EPS_MASK (0xf << 26) | ||
329 | +#define GHWCFG4_NUM_IN_EPS_SHIFT 26 | ||
330 | +#define GHWCFG4_DED_FIFO_EN BIT(25) | ||
331 | +#define GHWCFG4_DED_FIFO_SHIFT 25 | ||
332 | +#define GHWCFG4_SESSION_END_FILT_EN BIT(24) | ||
333 | +#define GHWCFG4_B_VALID_FILT_EN BIT(23) | ||
334 | +#define GHWCFG4_A_VALID_FILT_EN BIT(22) | ||
335 | +#define GHWCFG4_VBUS_VALID_FILT_EN BIT(21) | ||
336 | +#define GHWCFG4_IDDIG_FILT_EN BIT(20) | ||
337 | +#define GHWCFG4_NUM_DEV_MODE_CTRL_EP_MASK (0xf << 16) | ||
338 | +#define GHWCFG4_NUM_DEV_MODE_CTRL_EP_SHIFT 16 | ||
339 | +#define GHWCFG4_UTMI_PHY_DATA_WIDTH_MASK (0x3 << 14) | ||
340 | +#define GHWCFG4_UTMI_PHY_DATA_WIDTH_SHIFT 14 | ||
341 | +#define GHWCFG4_UTMI_PHY_DATA_WIDTH_8 0 | ||
342 | +#define GHWCFG4_UTMI_PHY_DATA_WIDTH_16 1 | ||
343 | +#define GHWCFG4_UTMI_PHY_DATA_WIDTH_8_OR_16 2 | ||
344 | +#define GHWCFG4_ACG_SUPPORTED BIT(12) | ||
345 | +#define GHWCFG4_IPG_ISOC_SUPPORTED BIT(11) | ||
346 | +#define GHWCFG4_SERVICE_INTERVAL_SUPPORTED BIT(10) | ||
347 | +#define GHWCFG4_XHIBER BIT(7) | ||
348 | +#define GHWCFG4_HIBER BIT(6) | ||
349 | +#define GHWCFG4_MIN_AHB_FREQ BIT(5) | ||
350 | +#define GHWCFG4_POWER_OPTIMIZ BIT(4) | ||
351 | +#define GHWCFG4_NUM_DEV_PERIO_IN_EP_MASK (0xf << 0) | ||
352 | +#define GHWCFG4_NUM_DEV_PERIO_IN_EP_SHIFT 0 | ||
353 | + | ||
354 | +#define GLPMCFG HSOTG_REG(0x0054) | ||
355 | +#define GLPMCFG_INVSELHSIC BIT(31) | ||
356 | +#define GLPMCFG_HSICCON BIT(30) | ||
357 | +#define GLPMCFG_RSTRSLPSTS BIT(29) | ||
358 | +#define GLPMCFG_ENBESL BIT(28) | ||
359 | +#define GLPMCFG_LPM_RETRYCNT_STS_MASK (0x7 << 25) | ||
360 | +#define GLPMCFG_LPM_RETRYCNT_STS_SHIFT 25 | ||
361 | +#define GLPMCFG_SNDLPM BIT(24) | ||
362 | +#define GLPMCFG_RETRY_CNT_MASK (0x7 << 21) | ||
363 | +#define GLPMCFG_RETRY_CNT_SHIFT 21 | ||
364 | +#define GLPMCFG_LPM_REJECT_CTRL_CONTROL BIT(21) | ||
365 | +#define GLPMCFG_LPM_ACCEPT_CTRL_ISOC BIT(22) | ||
366 | +#define GLPMCFG_LPM_CHNL_INDX_MASK (0xf << 17) | ||
367 | +#define GLPMCFG_LPM_CHNL_INDX_SHIFT 17 | ||
368 | +#define GLPMCFG_L1RESUMEOK BIT(16) | ||
369 | +#define GLPMCFG_SLPSTS BIT(15) | ||
370 | +#define GLPMCFG_COREL1RES_MASK (0x3 << 13) | ||
371 | +#define GLPMCFG_COREL1RES_SHIFT 13 | ||
372 | +#define GLPMCFG_HIRD_THRES_MASK (0x1f << 8) | ||
373 | +#define GLPMCFG_HIRD_THRES_SHIFT 8 | ||
374 | +#define GLPMCFG_HIRD_THRES_EN (0x10 << 8) | ||
375 | +#define GLPMCFG_ENBLSLPM BIT(7) | ||
376 | +#define GLPMCFG_BREMOTEWAKE BIT(6) | ||
377 | +#define GLPMCFG_HIRD_MASK (0xf << 2) | ||
378 | +#define GLPMCFG_HIRD_SHIFT 2 | ||
379 | +#define GLPMCFG_APPL1RES BIT(1) | ||
380 | +#define GLPMCFG_LPMCAP BIT(0) | ||
381 | + | ||
382 | +#define GPWRDN HSOTG_REG(0x0058) | ||
383 | +#define GPWRDN_MULT_VAL_ID_BC_MASK (0x1f << 24) | ||
384 | +#define GPWRDN_MULT_VAL_ID_BC_SHIFT 24 | ||
385 | +#define GPWRDN_ADP_INT BIT(23) | ||
386 | +#define GPWRDN_BSESSVLD BIT(22) | ||
387 | +#define GPWRDN_IDSTS BIT(21) | ||
388 | +#define GPWRDN_LINESTATE_MASK (0x3 << 19) | ||
389 | +#define GPWRDN_LINESTATE_SHIFT 19 | ||
390 | +#define GPWRDN_STS_CHGINT_MSK BIT(18) | ||
391 | +#define GPWRDN_STS_CHGINT BIT(17) | ||
392 | +#define GPWRDN_SRP_DET_MSK BIT(16) | ||
393 | +#define GPWRDN_SRP_DET BIT(15) | ||
394 | +#define GPWRDN_CONNECT_DET_MSK BIT(14) | ||
395 | +#define GPWRDN_CONNECT_DET BIT(13) | ||
396 | +#define GPWRDN_DISCONN_DET_MSK BIT(12) | ||
397 | +#define GPWRDN_DISCONN_DET BIT(11) | ||
398 | +#define GPWRDN_RST_DET_MSK BIT(10) | ||
399 | +#define GPWRDN_RST_DET BIT(9) | ||
400 | +#define GPWRDN_LNSTSCHG_MSK BIT(8) | ||
401 | +#define GPWRDN_LNSTSCHG BIT(7) | ||
402 | +#define GPWRDN_DIS_VBUS BIT(6) | ||
403 | +#define GPWRDN_PWRDNSWTCH BIT(5) | ||
404 | +#define GPWRDN_PWRDNRSTN BIT(4) | ||
405 | +#define GPWRDN_PWRDNCLMP BIT(3) | ||
406 | +#define GPWRDN_RESTORE BIT(2) | ||
407 | +#define GPWRDN_PMUACTV BIT(1) | ||
408 | +#define GPWRDN_PMUINTSEL BIT(0) | ||
409 | + | ||
410 | +#define GDFIFOCFG HSOTG_REG(0x005c) | ||
411 | +#define GDFIFOCFG_EPINFOBASE_MASK (0xffff << 16) | ||
412 | +#define GDFIFOCFG_EPINFOBASE_SHIFT 16 | ||
413 | +#define GDFIFOCFG_GDFIFOCFG_MASK (0xffff << 0) | ||
414 | +#define GDFIFOCFG_GDFIFOCFG_SHIFT 0 | ||
415 | + | ||
416 | +#define ADPCTL HSOTG_REG(0x0060) | ||
417 | +#define ADPCTL_AR_MASK (0x3 << 27) | ||
418 | +#define ADPCTL_AR_SHIFT 27 | ||
419 | +#define ADPCTL_ADP_TMOUT_INT_MSK BIT(26) | ||
420 | +#define ADPCTL_ADP_SNS_INT_MSK BIT(25) | ||
421 | +#define ADPCTL_ADP_PRB_INT_MSK BIT(24) | ||
422 | +#define ADPCTL_ADP_TMOUT_INT BIT(23) | ||
423 | +#define ADPCTL_ADP_SNS_INT BIT(22) | ||
424 | +#define ADPCTL_ADP_PRB_INT BIT(21) | ||
425 | +#define ADPCTL_ADPENA BIT(20) | ||
426 | +#define ADPCTL_ADPRES BIT(19) | ||
427 | +#define ADPCTL_ENASNS BIT(18) | ||
428 | +#define ADPCTL_ENAPRB BIT(17) | ||
429 | +#define ADPCTL_RTIM_MASK (0x7ff << 6) | ||
430 | +#define ADPCTL_RTIM_SHIFT 6 | ||
431 | +#define ADPCTL_PRB_PER_MASK (0x3 << 4) | ||
432 | +#define ADPCTL_PRB_PER_SHIFT 4 | ||
433 | +#define ADPCTL_PRB_DELTA_MASK (0x3 << 2) | ||
434 | +#define ADPCTL_PRB_DELTA_SHIFT 2 | ||
435 | +#define ADPCTL_PRB_DSCHRG_MASK (0x3 << 0) | ||
436 | +#define ADPCTL_PRB_DSCHRG_SHIFT 0 | ||
437 | + | ||
438 | +#define GREFCLK HSOTG_REG(0x0064) | ||
439 | +#define GREFCLK_REFCLKPER_MASK (0x1ffff << 15) | ||
440 | +#define GREFCLK_REFCLKPER_SHIFT 15 | ||
441 | +#define GREFCLK_REF_CLK_MODE BIT(14) | ||
442 | +#define GREFCLK_SOF_CNT_WKUP_ALERT_MASK (0x3ff) | ||
443 | +#define GREFCLK_SOF_CNT_WKUP_ALERT_SHIFT 0 | ||
444 | + | ||
445 | +#define GINTMSK2 HSOTG_REG(0x0068) | ||
446 | +#define GINTMSK2_WKUP_ALERT_INT_MSK BIT(0) | ||
447 | + | ||
448 | +#define GINTSTS2 HSOTG_REG(0x006c) | ||
449 | +#define GINTSTS2_WKUP_ALERT_INT BIT(0) | ||
450 | + | ||
451 | +#define HPTXFSIZ HSOTG_REG(0x100) | ||
452 | +/* Use FIFOSIZE_* constants to access this register */ | ||
453 | + | ||
454 | +#define DPTXFSIZN(_a) HSOTG_REG(0x104 + (((_a) - 1) * 4)) | ||
455 | +/* Use FIFOSIZE_* constants to access this register */ | ||
456 | + | ||
457 | +/* These apply to the GNPTXFSIZ, HPTXFSIZ and DPTXFSIZN registers */ | ||
458 | +#define FIFOSIZE_DEPTH_MASK (0xffff << 16) | ||
459 | +#define FIFOSIZE_DEPTH_SHIFT 16 | ||
460 | +#define FIFOSIZE_STARTADDR_MASK (0xffff << 0) | ||
461 | +#define FIFOSIZE_STARTADDR_SHIFT 0 | ||
462 | +#define FIFOSIZE_DEPTH_GET(_x) (((_x) >> 16) & 0xffff) | ||
463 | + | ||
464 | +/* Device mode registers */ | ||
465 | + | ||
466 | +#define DCFG HSOTG_REG(0x800) | ||
467 | +#define DCFG_DESCDMA_EN BIT(23) | ||
468 | +#define DCFG_EPMISCNT_MASK (0x1f << 18) | ||
469 | +#define DCFG_EPMISCNT_SHIFT 18 | ||
470 | +#define DCFG_EPMISCNT_LIMIT 0x1f | ||
471 | +#define DCFG_EPMISCNT(_x) ((_x) << 18) | ||
472 | +#define DCFG_IPG_ISOC_SUPPORDED BIT(17) | ||
473 | +#define DCFG_PERFRINT_MASK (0x3 << 11) | ||
474 | +#define DCFG_PERFRINT_SHIFT 11 | ||
475 | +#define DCFG_PERFRINT_LIMIT 0x3 | ||
476 | +#define DCFG_PERFRINT(_x) ((_x) << 11) | ||
477 | +#define DCFG_DEVADDR_MASK (0x7f << 4) | ||
478 | +#define DCFG_DEVADDR_SHIFT 4 | ||
479 | +#define DCFG_DEVADDR_LIMIT 0x7f | ||
480 | +#define DCFG_DEVADDR(_x) ((_x) << 4) | ||
481 | +#define DCFG_NZ_STS_OUT_HSHK BIT(2) | ||
482 | +#define DCFG_DEVSPD_MASK (0x3 << 0) | ||
483 | +#define DCFG_DEVSPD_SHIFT 0 | ||
484 | +#define DCFG_DEVSPD_HS 0 | ||
485 | +#define DCFG_DEVSPD_FS 1 | ||
486 | +#define DCFG_DEVSPD_LS 2 | ||
487 | +#define DCFG_DEVSPD_FS48 3 | ||
488 | + | ||
489 | +#define DCTL HSOTG_REG(0x804) | ||
490 | +#define DCTL_SERVICE_INTERVAL_SUPPORTED BIT(19) | ||
491 | +#define DCTL_PWRONPRGDONE BIT(11) | ||
492 | +#define DCTL_CGOUTNAK BIT(10) | ||
493 | +#define DCTL_SGOUTNAK BIT(9) | ||
494 | +#define DCTL_CGNPINNAK BIT(8) | ||
495 | +#define DCTL_SGNPINNAK BIT(7) | ||
496 | +#define DCTL_TSTCTL_MASK (0x7 << 4) | ||
497 | +#define DCTL_TSTCTL_SHIFT 4 | ||
498 | +#define DCTL_GOUTNAKSTS BIT(3) | ||
499 | +#define DCTL_GNPINNAKSTS BIT(2) | ||
500 | +#define DCTL_SFTDISCON BIT(1) | ||
501 | +#define DCTL_RMTWKUPSIG BIT(0) | ||
502 | + | ||
503 | +#define DSTS HSOTG_REG(0x808) | ||
504 | +#define DSTS_SOFFN_MASK (0x3fff << 8) | ||
505 | +#define DSTS_SOFFN_SHIFT 8 | ||
506 | +#define DSTS_SOFFN_LIMIT 0x3fff | ||
507 | +#define DSTS_SOFFN(_x) ((_x) << 8) | ||
508 | +#define DSTS_ERRATICERR BIT(3) | ||
509 | +#define DSTS_ENUMSPD_MASK (0x3 << 1) | ||
510 | +#define DSTS_ENUMSPD_SHIFT 1 | ||
511 | +#define DSTS_ENUMSPD_HS 0 | ||
512 | +#define DSTS_ENUMSPD_FS 1 | ||
513 | +#define DSTS_ENUMSPD_LS 2 | ||
514 | +#define DSTS_ENUMSPD_FS48 3 | ||
515 | +#define DSTS_SUSPSTS BIT(0) | ||
516 | + | ||
517 | +#define DIEPMSK HSOTG_REG(0x810) | ||
518 | +#define DIEPMSK_NAKMSK BIT(13) | ||
519 | +#define DIEPMSK_BNAININTRMSK BIT(9) | ||
520 | +#define DIEPMSK_TXFIFOUNDRNMSK BIT(8) | ||
521 | +#define DIEPMSK_TXFIFOEMPTY BIT(7) | ||
522 | +#define DIEPMSK_INEPNAKEFFMSK BIT(6) | ||
523 | +#define DIEPMSK_INTKNEPMISMSK BIT(5) | ||
524 | +#define DIEPMSK_INTKNTXFEMPMSK BIT(4) | ||
525 | +#define DIEPMSK_TIMEOUTMSK BIT(3) | ||
526 | +#define DIEPMSK_AHBERRMSK BIT(2) | ||
527 | +#define DIEPMSK_EPDISBLDMSK BIT(1) | ||
528 | +#define DIEPMSK_XFERCOMPLMSK BIT(0) | ||
529 | + | ||
530 | +#define DOEPMSK HSOTG_REG(0x814) | ||
531 | +#define DOEPMSK_BNAMSK BIT(9) | ||
532 | +#define DOEPMSK_BACK2BACKSETUP BIT(6) | ||
533 | +#define DOEPMSK_STSPHSERCVDMSK BIT(5) | ||
534 | +#define DOEPMSK_OUTTKNEPDISMSK BIT(4) | ||
535 | +#define DOEPMSK_SETUPMSK BIT(3) | ||
536 | +#define DOEPMSK_AHBERRMSK BIT(2) | ||
537 | +#define DOEPMSK_EPDISBLDMSK BIT(1) | ||
538 | +#define DOEPMSK_XFERCOMPLMSK BIT(0) | ||
539 | + | ||
540 | +#define DAINT HSOTG_REG(0x818) | ||
541 | +#define DAINTMSK HSOTG_REG(0x81C) | ||
542 | +#define DAINT_OUTEP_SHIFT 16 | ||
543 | +#define DAINT_OUTEP(_x) (1 << ((_x) + 16)) | ||
544 | +#define DAINT_INEP(_x) (1 << (_x)) | ||
545 | + | ||
546 | +#define DTKNQR1 HSOTG_REG(0x820) | ||
547 | +#define DTKNQR2 HSOTG_REG(0x824) | ||
548 | +#define DTKNQR3 HSOTG_REG(0x830) | ||
549 | +#define DTKNQR4 HSOTG_REG(0x834) | ||
550 | +#define DIEPEMPMSK HSOTG_REG(0x834) | ||
551 | + | ||
552 | +#define DVBUSDIS HSOTG_REG(0x828) | ||
553 | +#define DVBUSPULSE HSOTG_REG(0x82C) | ||
554 | + | ||
555 | +#define DIEPCTL0 HSOTG_REG(0x900) | ||
556 | +#define DIEPCTL(_a) HSOTG_REG(0x900 + ((_a) * 0x20)) | ||
557 | + | ||
558 | +#define DOEPCTL0 HSOTG_REG(0xB00) | ||
559 | +#define DOEPCTL(_a) HSOTG_REG(0xB00 + ((_a) * 0x20)) | ||
560 | + | ||
561 | +/* EP0 specialness: | ||
562 | + * bits[29..28] - reserved (no SetD0PID, SetD1PID) | ||
563 | + * bits[25..22] - should always be zero, this isn't a periodic endpoint | ||
564 | + * bits[10..0] - MPS setting different for EP0 | ||
565 | + */ | ||
566 | +#define D0EPCTL_MPS_MASK (0x3 << 0) | ||
567 | +#define D0EPCTL_MPS_SHIFT 0 | ||
568 | +#define D0EPCTL_MPS_64 0 | ||
569 | +#define D0EPCTL_MPS_32 1 | ||
570 | +#define D0EPCTL_MPS_16 2 | ||
571 | +#define D0EPCTL_MPS_8 3 | ||
572 | + | ||
573 | +#define DXEPCTL_EPENA BIT(31) | ||
574 | +#define DXEPCTL_EPDIS BIT(30) | ||
575 | +#define DXEPCTL_SETD1PID BIT(29) | ||
576 | +#define DXEPCTL_SETODDFR BIT(29) | ||
577 | +#define DXEPCTL_SETD0PID BIT(28) | ||
578 | +#define DXEPCTL_SETEVENFR BIT(28) | ||
579 | +#define DXEPCTL_SNAK BIT(27) | ||
580 | +#define DXEPCTL_CNAK BIT(26) | ||
581 | +#define DXEPCTL_TXFNUM_MASK (0xf << 22) | ||
582 | +#define DXEPCTL_TXFNUM_SHIFT 22 | ||
583 | +#define DXEPCTL_TXFNUM_LIMIT 0xf | ||
584 | +#define DXEPCTL_TXFNUM(_x) ((_x) << 22) | ||
585 | +#define DXEPCTL_STALL BIT(21) | ||
586 | +#define DXEPCTL_SNP BIT(20) | ||
587 | +#define DXEPCTL_EPTYPE_MASK (0x3 << 18) | ||
588 | +#define DXEPCTL_EPTYPE_CONTROL (0x0 << 18) | ||
589 | +#define DXEPCTL_EPTYPE_ISO (0x1 << 18) | ||
590 | +#define DXEPCTL_EPTYPE_BULK (0x2 << 18) | ||
591 | +#define DXEPCTL_EPTYPE_INTERRUPT (0x3 << 18) | ||
592 | + | ||
593 | +#define DXEPCTL_NAKSTS BIT(17) | ||
594 | +#define DXEPCTL_DPID BIT(16) | ||
595 | +#define DXEPCTL_EOFRNUM BIT(16) | ||
596 | +#define DXEPCTL_USBACTEP BIT(15) | ||
597 | +#define DXEPCTL_NEXTEP_MASK (0xf << 11) | ||
598 | +#define DXEPCTL_NEXTEP_SHIFT 11 | ||
599 | +#define DXEPCTL_NEXTEP_LIMIT 0xf | ||
600 | +#define DXEPCTL_NEXTEP(_x) ((_x) << 11) | ||
601 | +#define DXEPCTL_MPS_MASK (0x7ff << 0) | ||
602 | +#define DXEPCTL_MPS_SHIFT 0 | ||
603 | +#define DXEPCTL_MPS_LIMIT 0x7ff | ||
604 | +#define DXEPCTL_MPS(_x) ((_x) << 0) | ||
605 | + | ||
606 | +#define DIEPINT(_a) HSOTG_REG(0x908 + ((_a) * 0x20)) | ||
607 | +#define DOEPINT(_a) HSOTG_REG(0xB08 + ((_a) * 0x20)) | ||
608 | +#define DXEPINT_SETUP_RCVD BIT(15) | ||
609 | +#define DXEPINT_NYETINTRPT BIT(14) | ||
610 | +#define DXEPINT_NAKINTRPT BIT(13) | ||
611 | +#define DXEPINT_BBLEERRINTRPT BIT(12) | ||
612 | +#define DXEPINT_PKTDRPSTS BIT(11) | ||
613 | +#define DXEPINT_BNAINTR BIT(9) | ||
614 | +#define DXEPINT_TXFIFOUNDRN BIT(8) | ||
615 | +#define DXEPINT_OUTPKTERR BIT(8) | ||
616 | +#define DXEPINT_TXFEMP BIT(7) | ||
617 | +#define DXEPINT_INEPNAKEFF BIT(6) | ||
618 | +#define DXEPINT_BACK2BACKSETUP BIT(6) | ||
619 | +#define DXEPINT_INTKNEPMIS BIT(5) | ||
620 | +#define DXEPINT_STSPHSERCVD BIT(5) | ||
621 | +#define DXEPINT_INTKNTXFEMP BIT(4) | ||
622 | +#define DXEPINT_OUTTKNEPDIS BIT(4) | ||
623 | +#define DXEPINT_TIMEOUT BIT(3) | ||
624 | +#define DXEPINT_SETUP BIT(3) | ||
625 | +#define DXEPINT_AHBERR BIT(2) | ||
626 | +#define DXEPINT_EPDISBLD BIT(1) | ||
627 | +#define DXEPINT_XFERCOMPL BIT(0) | ||
628 | + | ||
629 | +#define DIEPTSIZ0 HSOTG_REG(0x910) | ||
630 | +#define DIEPTSIZ0_PKTCNT_MASK (0x3 << 19) | ||
631 | +#define DIEPTSIZ0_PKTCNT_SHIFT 19 | ||
632 | +#define DIEPTSIZ0_PKTCNT_LIMIT 0x3 | ||
633 | +#define DIEPTSIZ0_PKTCNT(_x) ((_x) << 19) | ||
634 | +#define DIEPTSIZ0_XFERSIZE_MASK (0x7f << 0) | ||
635 | +#define DIEPTSIZ0_XFERSIZE_SHIFT 0 | ||
636 | +#define DIEPTSIZ0_XFERSIZE_LIMIT 0x7f | ||
637 | +#define DIEPTSIZ0_XFERSIZE(_x) ((_x) << 0) | ||
638 | + | ||
639 | +#define DOEPTSIZ0 HSOTG_REG(0xB10) | ||
640 | +#define DOEPTSIZ0_SUPCNT_MASK (0x3 << 29) | ||
641 | +#define DOEPTSIZ0_SUPCNT_SHIFT 29 | ||
642 | +#define DOEPTSIZ0_SUPCNT_LIMIT 0x3 | ||
643 | +#define DOEPTSIZ0_SUPCNT(_x) ((_x) << 29) | ||
644 | +#define DOEPTSIZ0_PKTCNT BIT(19) | ||
645 | +#define DOEPTSIZ0_XFERSIZE_MASK (0x7f << 0) | ||
646 | +#define DOEPTSIZ0_XFERSIZE_SHIFT 0 | ||
647 | + | ||
648 | +#define DIEPTSIZ(_a) HSOTG_REG(0x910 + ((_a) * 0x20)) | ||
649 | +#define DOEPTSIZ(_a) HSOTG_REG(0xB10 + ((_a) * 0x20)) | ||
650 | +#define DXEPTSIZ_MC_MASK (0x3 << 29) | ||
651 | +#define DXEPTSIZ_MC_SHIFT 29 | ||
652 | +#define DXEPTSIZ_MC_LIMIT 0x3 | ||
653 | +#define DXEPTSIZ_MC(_x) ((_x) << 29) | ||
654 | +#define DXEPTSIZ_PKTCNT_MASK (0x3ff << 19) | ||
655 | +#define DXEPTSIZ_PKTCNT_SHIFT 19 | ||
656 | +#define DXEPTSIZ_PKTCNT_LIMIT 0x3ff | ||
657 | +#define DXEPTSIZ_PKTCNT_GET(_v) (((_v) >> 19) & 0x3ff) | ||
658 | +#define DXEPTSIZ_PKTCNT(_x) ((_x) << 19) | ||
659 | +#define DXEPTSIZ_XFERSIZE_MASK (0x7ffff << 0) | ||
660 | +#define DXEPTSIZ_XFERSIZE_SHIFT 0 | ||
661 | +#define DXEPTSIZ_XFERSIZE_LIMIT 0x7ffff | ||
662 | +#define DXEPTSIZ_XFERSIZE_GET(_v) (((_v) >> 0) & 0x7ffff) | ||
663 | +#define DXEPTSIZ_XFERSIZE(_x) ((_x) << 0) | ||
664 | + | ||
665 | +#define DIEPDMA(_a) HSOTG_REG(0x914 + ((_a) * 0x20)) | ||
666 | +#define DOEPDMA(_a) HSOTG_REG(0xB14 + ((_a) * 0x20)) | ||
667 | + | ||
668 | +#define DTXFSTS(_a) HSOTG_REG(0x918 + ((_a) * 0x20)) | ||
669 | + | ||
670 | +#define PCGCTL HSOTG_REG(0x0e00) | ||
671 | +#define PCGCTL_IF_DEV_MODE BIT(31) | ||
672 | +#define PCGCTL_P2HD_PRT_SPD_MASK (0x3 << 29) | ||
673 | +#define PCGCTL_P2HD_PRT_SPD_SHIFT 29 | ||
674 | +#define PCGCTL_P2HD_DEV_ENUM_SPD_MASK (0x3 << 27) | ||
675 | +#define PCGCTL_P2HD_DEV_ENUM_SPD_SHIFT 27 | ||
676 | +#define PCGCTL_MAC_DEV_ADDR_MASK (0x7f << 20) | ||
677 | +#define PCGCTL_MAC_DEV_ADDR_SHIFT 20 | ||
678 | +#define PCGCTL_MAX_TERMSEL BIT(19) | ||
679 | +#define PCGCTL_MAX_XCVRSELECT_MASK (0x3 << 17) | ||
680 | +#define PCGCTL_MAX_XCVRSELECT_SHIFT 17 | ||
681 | +#define PCGCTL_PORT_POWER BIT(16) | ||
682 | +#define PCGCTL_PRT_CLK_SEL_MASK (0x3 << 14) | ||
683 | +#define PCGCTL_PRT_CLK_SEL_SHIFT 14 | ||
684 | +#define PCGCTL_ESS_REG_RESTORED BIT(13) | ||
685 | +#define PCGCTL_EXTND_HIBER_SWITCH BIT(12) | ||
686 | +#define PCGCTL_EXTND_HIBER_PWRCLMP BIT(11) | ||
687 | +#define PCGCTL_ENBL_EXTND_HIBER BIT(10) | ||
688 | +#define PCGCTL_RESTOREMODE BIT(9) | ||
689 | +#define PCGCTL_RESETAFTSUSP BIT(8) | ||
690 | +#define PCGCTL_DEEP_SLEEP BIT(7) | ||
691 | +#define PCGCTL_PHY_IN_SLEEP BIT(6) | ||
692 | +#define PCGCTL_ENBL_SLEEP_GATING BIT(5) | ||
693 | +#define PCGCTL_RSTPDWNMODULE BIT(3) | ||
694 | +#define PCGCTL_PWRCLMP BIT(2) | ||
695 | +#define PCGCTL_GATEHCLK BIT(1) | ||
696 | +#define PCGCTL_STOPPCLK BIT(0) | ||
697 | + | ||
698 | +#define PCGCCTL1 HSOTG_REG(0xe04) | ||
699 | +#define PCGCCTL1_TIMER (0x3 << 1) | ||
700 | +#define PCGCCTL1_GATEEN BIT(0) | ||
701 | + | ||
702 | +#define EPFIFO(_a) HSOTG_REG(0x1000 + ((_a) * 0x1000)) | ||
703 | + | ||
704 | +/* Host Mode Registers */ | ||
705 | + | ||
706 | +#define HCFG HSOTG_REG(0x0400) | ||
707 | +#define HCFG_MODECHTIMEN BIT(31) | ||
708 | +#define HCFG_PERSCHEDENA BIT(26) | ||
709 | +#define HCFG_FRLISTEN_MASK (0x3 << 24) | ||
710 | +#define HCFG_FRLISTEN_SHIFT 24 | ||
711 | +#define HCFG_FRLISTEN_8 (0 << 24) | ||
712 | +#define FRLISTEN_8_SIZE 8 | ||
713 | +#define HCFG_FRLISTEN_16 BIT(24) | ||
714 | +#define FRLISTEN_16_SIZE 16 | ||
715 | +#define HCFG_FRLISTEN_32 (2 << 24) | ||
716 | +#define FRLISTEN_32_SIZE 32 | ||
717 | +#define HCFG_FRLISTEN_64 (3 << 24) | ||
718 | +#define FRLISTEN_64_SIZE 64 | ||
719 | +#define HCFG_DESCDMA BIT(23) | ||
720 | +#define HCFG_RESVALID_MASK (0xff << 8) | ||
721 | +#define HCFG_RESVALID_SHIFT 8 | ||
722 | +#define HCFG_ENA32KHZ BIT(7) | ||
723 | +#define HCFG_FSLSSUPP BIT(2) | ||
724 | +#define HCFG_FSLSPCLKSEL_MASK (0x3 << 0) | ||
725 | +#define HCFG_FSLSPCLKSEL_SHIFT 0 | ||
726 | +#define HCFG_FSLSPCLKSEL_30_60_MHZ 0 | ||
727 | +#define HCFG_FSLSPCLKSEL_48_MHZ 1 | ||
728 | +#define HCFG_FSLSPCLKSEL_6_MHZ 2 | ||
729 | + | ||
730 | +#define HFIR HSOTG_REG(0x0404) | ||
731 | +#define HFIR_FRINT_MASK (0xffff << 0) | ||
732 | +#define HFIR_FRINT_SHIFT 0 | ||
733 | +#define HFIR_RLDCTRL BIT(16) | ||
734 | + | ||
735 | +#define HFNUM HSOTG_REG(0x0408) | ||
736 | +#define HFNUM_FRREM_MASK (0xffff << 16) | ||
737 | +#define HFNUM_FRREM_SHIFT 16 | ||
738 | +#define HFNUM_FRNUM_MASK (0xffff << 0) | ||
739 | +#define HFNUM_FRNUM_SHIFT 0 | ||
740 | +#define HFNUM_MAX_FRNUM 0x3fff | ||
741 | + | ||
742 | +#define HPTXSTS HSOTG_REG(0x0410) | ||
743 | +#define TXSTS_QTOP_ODD BIT(31) | ||
744 | +#define TXSTS_QTOP_CHNEP_MASK (0xf << 27) | ||
745 | +#define TXSTS_QTOP_CHNEP_SHIFT 27 | ||
746 | +#define TXSTS_QTOP_TOKEN_MASK (0x3 << 25) | ||
747 | +#define TXSTS_QTOP_TOKEN_SHIFT 25 | ||
748 | +#define TXSTS_QTOP_TERMINATE BIT(24) | ||
749 | +#define TXSTS_QSPCAVAIL_MASK (0xff << 16) | ||
750 | +#define TXSTS_QSPCAVAIL_SHIFT 16 | ||
751 | +#define TXSTS_FSPCAVAIL_MASK (0xffff << 0) | ||
752 | +#define TXSTS_FSPCAVAIL_SHIFT 0 | ||
753 | + | ||
754 | +#define HAINT HSOTG_REG(0x0414) | ||
755 | +#define HAINTMSK HSOTG_REG(0x0418) | ||
756 | +#define HFLBADDR HSOTG_REG(0x041c) | ||
757 | + | ||
758 | +#define HPRT0 HSOTG_REG(0x0440) | ||
759 | +#define HPRT0_SPD_MASK (0x3 << 17) | ||
760 | +#define HPRT0_SPD_SHIFT 17 | ||
761 | +#define HPRT0_SPD_HIGH_SPEED 0 | ||
762 | +#define HPRT0_SPD_FULL_SPEED 1 | ||
763 | +#define HPRT0_SPD_LOW_SPEED 2 | ||
764 | +#define HPRT0_TSTCTL_MASK (0xf << 13) | ||
765 | +#define HPRT0_TSTCTL_SHIFT 13 | ||
766 | +#define HPRT0_PWR BIT(12) | ||
767 | +#define HPRT0_LNSTS_MASK (0x3 << 10) | ||
768 | +#define HPRT0_LNSTS_SHIFT 10 | ||
769 | +#define HPRT0_RST BIT(8) | ||
770 | +#define HPRT0_SUSP BIT(7) | ||
771 | +#define HPRT0_RES BIT(6) | ||
772 | +#define HPRT0_OVRCURRCHG BIT(5) | ||
773 | +#define HPRT0_OVRCURRACT BIT(4) | ||
774 | +#define HPRT0_ENACHG BIT(3) | ||
775 | +#define HPRT0_ENA BIT(2) | ||
776 | +#define HPRT0_CONNDET BIT(1) | ||
777 | +#define HPRT0_CONNSTS BIT(0) | ||
778 | + | ||
779 | +#define HCCHAR(_ch) HSOTG_REG(0x0500 + 0x20 * (_ch)) | ||
780 | +#define HCCHAR_CHENA BIT(31) | ||
781 | +#define HCCHAR_CHDIS BIT(30) | ||
782 | +#define HCCHAR_ODDFRM BIT(29) | ||
783 | +#define HCCHAR_DEVADDR_MASK (0x7f << 22) | ||
784 | +#define HCCHAR_DEVADDR_SHIFT 22 | ||
785 | +#define HCCHAR_MULTICNT_MASK (0x3 << 20) | ||
786 | +#define HCCHAR_MULTICNT_SHIFT 20 | ||
787 | +#define HCCHAR_EPTYPE_MASK (0x3 << 18) | ||
788 | +#define HCCHAR_EPTYPE_SHIFT 18 | ||
789 | +#define HCCHAR_LSPDDEV BIT(17) | ||
790 | +#define HCCHAR_EPDIR BIT(15) | ||
791 | +#define HCCHAR_EPNUM_MASK (0xf << 11) | ||
792 | +#define HCCHAR_EPNUM_SHIFT 11 | ||
793 | +#define HCCHAR_MPS_MASK (0x7ff << 0) | ||
794 | +#define HCCHAR_MPS_SHIFT 0 | ||
795 | + | ||
796 | +#define HCSPLT(_ch) HSOTG_REG(0x0504 + 0x20 * (_ch)) | ||
797 | +#define HCSPLT_SPLTENA BIT(31) | ||
798 | +#define HCSPLT_COMPSPLT BIT(16) | ||
799 | +#define HCSPLT_XACTPOS_MASK (0x3 << 14) | ||
800 | +#define HCSPLT_XACTPOS_SHIFT 14 | ||
801 | +#define HCSPLT_XACTPOS_MID 0 | ||
802 | +#define HCSPLT_XACTPOS_END 1 | ||
803 | +#define HCSPLT_XACTPOS_BEGIN 2 | ||
804 | +#define HCSPLT_XACTPOS_ALL 3 | ||
805 | +#define HCSPLT_HUBADDR_MASK (0x7f << 7) | ||
806 | +#define HCSPLT_HUBADDR_SHIFT 7 | ||
807 | +#define HCSPLT_PRTADDR_MASK (0x7f << 0) | ||
808 | +#define HCSPLT_PRTADDR_SHIFT 0 | ||
809 | + | ||
810 | +#define HCINT(_ch) HSOTG_REG(0x0508 + 0x20 * (_ch)) | ||
811 | +#define HCINTMSK(_ch) HSOTG_REG(0x050c + 0x20 * (_ch)) | ||
812 | +#define HCINTMSK_RESERVED14_31 (0x3ffff << 14) | ||
813 | +#define HCINTMSK_FRM_LIST_ROLL BIT(13) | ||
814 | +#define HCINTMSK_XCS_XACT BIT(12) | ||
815 | +#define HCINTMSK_BNA BIT(11) | ||
816 | +#define HCINTMSK_DATATGLERR BIT(10) | ||
817 | +#define HCINTMSK_FRMOVRUN BIT(9) | ||
818 | +#define HCINTMSK_BBLERR BIT(8) | ||
819 | +#define HCINTMSK_XACTERR BIT(7) | ||
820 | +#define HCINTMSK_NYET BIT(6) | ||
821 | +#define HCINTMSK_ACK BIT(5) | ||
822 | +#define HCINTMSK_NAK BIT(4) | ||
823 | +#define HCINTMSK_STALL BIT(3) | ||
824 | +#define HCINTMSK_AHBERR BIT(2) | ||
825 | +#define HCINTMSK_CHHLTD BIT(1) | ||
826 | +#define HCINTMSK_XFERCOMPL BIT(0) | ||
827 | + | ||
828 | +#define HCTSIZ(_ch) HSOTG_REG(0x0510 + 0x20 * (_ch)) | ||
829 | +#define TSIZ_DOPNG BIT(31) | ||
830 | +#define TSIZ_SC_MC_PID_MASK (0x3 << 29) | ||
831 | +#define TSIZ_SC_MC_PID_SHIFT 29 | ||
832 | +#define TSIZ_SC_MC_PID_DATA0 0 | ||
833 | +#define TSIZ_SC_MC_PID_DATA2 1 | ||
834 | +#define TSIZ_SC_MC_PID_DATA1 2 | ||
835 | +#define TSIZ_SC_MC_PID_MDATA 3 | ||
836 | +#define TSIZ_SC_MC_PID_SETUP 3 | ||
837 | +#define TSIZ_PKTCNT_MASK (0x3ff << 19) | ||
838 | +#define TSIZ_PKTCNT_SHIFT 19 | ||
839 | +#define TSIZ_NTD_MASK (0xff << 8) | ||
840 | +#define TSIZ_NTD_SHIFT 8 | ||
841 | +#define TSIZ_SCHINFO_MASK (0xff << 0) | ||
842 | +#define TSIZ_SCHINFO_SHIFT 0 | ||
843 | +#define TSIZ_XFERSIZE_MASK (0x7ffff << 0) | ||
844 | +#define TSIZ_XFERSIZE_SHIFT 0 | ||
845 | + | ||
846 | +#define HCDMA(_ch) HSOTG_REG(0x0514 + 0x20 * (_ch)) | ||
847 | + | ||
848 | +#define HCDMAB(_ch) HSOTG_REG(0x051c + 0x20 * (_ch)) | ||
849 | + | ||
850 | +#define HCFIFO(_ch) HSOTG_REG(0x1000 + 0x1000 * (_ch)) | ||
851 | + | ||
852 | +/** | ||
853 | + * struct dwc2_dma_desc - DMA descriptor structure, | ||
854 | + * used for both host and gadget modes | ||
855 | + * | ||
856 | + * @status: DMA descriptor status quadlet | ||
857 | + * @buf: DMA descriptor data buffer pointer | ||
858 | + * | ||
859 | + * DMA Descriptor structure contains two quadlets: | ||
860 | + * Status quadlet and Data buffer pointer. | ||
861 | + */ | ||
862 | +struct dwc2_dma_desc { | ||
863 | + uint32_t status; | ||
864 | + uint32_t buf; | ||
865 | +} __packed; | ||
866 | + | ||
867 | +/* Host Mode DMA descriptor status quadlet */ | ||
868 | + | ||
869 | +#define HOST_DMA_A BIT(31) | ||
870 | +#define HOST_DMA_STS_MASK (0x3 << 28) | ||
871 | +#define HOST_DMA_STS_SHIFT 28 | ||
872 | +#define HOST_DMA_STS_PKTERR BIT(28) | ||
873 | +#define HOST_DMA_EOL BIT(26) | ||
874 | +#define HOST_DMA_IOC BIT(25) | ||
875 | +#define HOST_DMA_SUP BIT(24) | ||
876 | +#define HOST_DMA_ALT_QTD BIT(23) | ||
877 | +#define HOST_DMA_QTD_OFFSET_MASK (0x3f << 17) | ||
878 | +#define HOST_DMA_QTD_OFFSET_SHIFT 17 | ||
879 | +#define HOST_DMA_ISOC_NBYTES_MASK (0xfff << 0) | ||
880 | +#define HOST_DMA_ISOC_NBYTES_SHIFT 0 | ||
881 | +#define HOST_DMA_NBYTES_MASK (0x1ffff << 0) | ||
882 | +#define HOST_DMA_NBYTES_SHIFT 0 | ||
883 | +#define HOST_DMA_NBYTES_LIMIT 131071 | ||
884 | + | ||
885 | +/* Device Mode DMA descriptor status quadlet */ | ||
886 | + | ||
887 | +#define DEV_DMA_BUFF_STS_MASK (0x3 << 30) | ||
888 | +#define DEV_DMA_BUFF_STS_SHIFT 30 | ||
889 | +#define DEV_DMA_BUFF_STS_HREADY 0 | ||
890 | +#define DEV_DMA_BUFF_STS_DMABUSY 1 | ||
891 | +#define DEV_DMA_BUFF_STS_DMADONE 2 | ||
892 | +#define DEV_DMA_BUFF_STS_HBUSY 3 | ||
893 | +#define DEV_DMA_STS_MASK (0x3 << 28) | ||
894 | +#define DEV_DMA_STS_SHIFT 28 | ||
895 | +#define DEV_DMA_STS_SUCC 0 | ||
896 | +#define DEV_DMA_STS_BUFF_FLUSH 1 | ||
897 | +#define DEV_DMA_STS_BUFF_ERR 3 | ||
898 | +#define DEV_DMA_L BIT(27) | ||
899 | +#define DEV_DMA_SHORT BIT(26) | ||
900 | +#define DEV_DMA_IOC BIT(25) | ||
901 | +#define DEV_DMA_SR BIT(24) | ||
902 | +#define DEV_DMA_MTRF BIT(23) | ||
903 | +#define DEV_DMA_ISOC_PID_MASK (0x3 << 23) | ||
904 | +#define DEV_DMA_ISOC_PID_SHIFT 23 | ||
905 | +#define DEV_DMA_ISOC_PID_DATA0 0 | ||
906 | +#define DEV_DMA_ISOC_PID_DATA2 1 | ||
907 | +#define DEV_DMA_ISOC_PID_DATA1 2 | ||
908 | +#define DEV_DMA_ISOC_PID_MDATA 3 | ||
909 | +#define DEV_DMA_ISOC_FRNUM_MASK (0x7ff << 12) | ||
910 | +#define DEV_DMA_ISOC_FRNUM_SHIFT 12 | ||
911 | +#define DEV_DMA_ISOC_TX_NBYTES_MASK (0xfff << 0) | ||
912 | +#define DEV_DMA_ISOC_TX_NBYTES_LIMIT 0xfff | ||
913 | +#define DEV_DMA_ISOC_RX_NBYTES_MASK (0x7ff << 0) | ||
914 | +#define DEV_DMA_ISOC_RX_NBYTES_LIMIT 0x7ff | ||
915 | +#define DEV_DMA_ISOC_NBYTES_SHIFT 0 | ||
916 | +#define DEV_DMA_NBYTES_MASK (0xffff << 0) | ||
917 | +#define DEV_DMA_NBYTES_SHIFT 0 | ||
918 | +#define DEV_DMA_NBYTES_LIMIT 0xffff | ||
919 | + | ||
920 | +#define MAX_DMA_DESC_NUM_GENERIC 64 | ||
921 | +#define MAX_DMA_DESC_NUM_HS_ISOC 256 | ||
922 | + | ||
923 | +#endif /* __DWC2_HW_H__ */ | ||
924 | -- | 35 | -- |
925 | 2.20.1 | 36 | 2.20.1 |
926 | 37 | ||
927 | 38 | diff view generated by jsdifflib |
1 | From: Cédric Le Goater <clg@kaod.org> | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Cédric Le Goater <clg@kaod.org> | 3 | Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com> |
4 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 4 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Message-id: 20200602135050.593692-1-clg@kaod.org | 5 | Message-id: 20181211151945.29137-9-aaron@os.amperecomputing.com |
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 7 | --- |
8 | docs/system/arm/aspeed.rst | 85 ++++++++++++++++++++++++++++++++++++++ | 8 | target/arm/cpu.h | 4 ++-- |
9 | docs/system/target-arm.rst | 1 + | 9 | target/arm/helper.c | 19 +++++++++++++++++-- |
10 | 2 files changed, 86 insertions(+) | 10 | 2 files changed, 19 insertions(+), 4 deletions(-) |
11 | create mode 100644 docs/system/arm/aspeed.rst | ||
12 | 11 | ||
13 | diff --git a/docs/system/arm/aspeed.rst b/docs/system/arm/aspeed.rst | 12 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
14 | new file mode 100644 | ||
15 | index XXXXXXX..XXXXXXX | ||
16 | --- /dev/null | ||
17 | +++ b/docs/system/arm/aspeed.rst | ||
18 | @@ -XXX,XX +XXX,XX @@ | ||
19 | +Aspeed family boards (``*-bmc``, ``ast2500-evb``, ``ast2600-evb``) | ||
20 | +================================================================== | ||
21 | + | ||
22 | +The QEMU Aspeed machines model BMCs of various OpenPOWER systems and | ||
23 | +Aspeed evaluation boards. They are based on different releases of the | ||
24 | +Aspeed SoC : the AST2400 integrating an ARM926EJ-S CPU (400MHz), the | ||
25 | +AST2500 with an ARM1176JZS CPU (800MHz) and more recently the AST2600 | ||
26 | +with dual cores ARM Cortex A7 CPUs (1.2GHz). | ||
27 | + | ||
28 | +The SoC comes with RAM, Gigabit ethernet, USB, SD/MMC, USB, SPI, I2C, | ||
29 | +etc. | ||
30 | + | ||
31 | +AST2400 SoC based machines : | ||
32 | + | ||
33 | +- ``palmetto-bmc`` OpenPOWER Palmetto POWER8 BMC | ||
34 | + | ||
35 | +AST2500 SoC based machines : | ||
36 | + | ||
37 | +- ``ast2500-evb`` Aspeed AST2500 Evaluation board | ||
38 | +- ``romulus-bmc`` OpenPOWER Romulus POWER9 BMC | ||
39 | +- ``witherspoon-bmc`` OpenPOWER Witherspoon POWER9 BMC | ||
40 | +- ``sonorapass-bmc`` OCP SonoraPass BMC | ||
41 | +- ``swift-bmc`` OpenPOWER Swift BMC POWER9 | ||
42 | + | ||
43 | +AST2600 SoC based machines : | ||
44 | + | ||
45 | +- ``ast2600-evb`` Aspeed AST2600 Evaluation board (Cortex A7) | ||
46 | +- ``tacoma-bmc`` OpenPOWER Witherspoon POWER9 AST2600 BMC | ||
47 | + | ||
48 | +Supported devices | ||
49 | +----------------- | ||
50 | + | ||
51 | + * SMP (for the AST2600 Cortex-A7) | ||
52 | + * Interrupt Controller (VIC) | ||
53 | + * Timer Controller | ||
54 | + * RTC Controller | ||
55 | + * I2C Controller | ||
56 | + * System Control Unit (SCU) | ||
57 | + * SRAM mapping | ||
58 | + * X-DMA Controller (basic interface) | ||
59 | + * Static Memory Controller (SMC or FMC) - Only SPI Flash support | ||
60 | + * SPI Memory Controller | ||
61 | + * USB 2.0 Controller | ||
62 | + * SD/MMC storage controllers | ||
63 | + * SDRAM controller (dummy interface for basic settings and training) | ||
64 | + * Watchdog Controller | ||
65 | + * GPIO Controller (Master only) | ||
66 | + * UART | ||
67 | + * Ethernet controllers | ||
68 | + | ||
69 | + | ||
70 | +Missing devices | ||
71 | +--------------- | ||
72 | + | ||
73 | + * Coprocessor support | ||
74 | + * ADC (out of tree implementation) | ||
75 | + * PWM and Fan Controller | ||
76 | + * LPC Bus Controller | ||
77 | + * Slave GPIO Controller | ||
78 | + * Super I/O Controller | ||
79 | + * Hash/Crypto Engine | ||
80 | + * PCI-Express 1 Controller | ||
81 | + * Graphic Display Controller | ||
82 | + * PECI Controller | ||
83 | + * MCTP Controller | ||
84 | + * Mailbox Controller | ||
85 | + * Virtual UART | ||
86 | + * eSPI Controller | ||
87 | + * I3C Controller | ||
88 | + | ||
89 | +Boot options | ||
90 | +------------ | ||
91 | + | ||
92 | +The Aspeed machines can be started using the -kernel option to load a | ||
93 | +Linux kernel or from a firmare image which can be downloaded from the | ||
94 | +OpenPOWER jenkins : | ||
95 | + | ||
96 | + https://openpower.xyz/ | ||
97 | + | ||
98 | +The image should be attached as an MTD drive. Run : | ||
99 | + | ||
100 | +.. code-block:: bash | ||
101 | + | ||
102 | + $ qemu-system-arm -M romulus-bmc -nic user \ | ||
103 | + -drive file=flash-romulus,format=raw,if=mtd -nographic | ||
104 | diff --git a/docs/system/target-arm.rst b/docs/system/target-arm.rst | ||
105 | index XXXXXXX..XXXXXXX 100644 | 13 | index XXXXXXX..XXXXXXX 100644 |
106 | --- a/docs/system/target-arm.rst | 14 | --- a/target/arm/cpu.h |
107 | +++ b/docs/system/target-arm.rst | 15 | +++ b/target/arm/cpu.h |
108 | @@ -XXX,XX +XXX,XX @@ undocumented; you can get a complete list by running | 16 | @@ -XXX,XX +XXX,XX @@ struct ARMCPU { |
109 | arm/realview | 17 | uint32_t id_pfr0; |
110 | arm/versatile | 18 | uint32_t id_pfr1; |
111 | arm/vexpress | 19 | uint32_t id_dfr0; |
112 | + arm/aspeed | 20 | - uint32_t pmceid0; |
113 | arm/musicpal | 21 | - uint32_t pmceid1; |
114 | arm/nseries | 22 | + uint64_t pmceid0; |
115 | arm/orangepi | 23 | + uint64_t pmceid1; |
24 | uint32_t id_afr0; | ||
25 | uint32_t id_mmfr0; | ||
26 | uint32_t id_mmfr1; | ||
27 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/target/arm/helper.c | ||
30 | +++ b/target/arm/helper.c | ||
31 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
32 | } else { | ||
33 | define_arm_cp_regs(cpu, not_v7_cp_reginfo); | ||
34 | } | ||
35 | + if (FIELD_EX32(cpu->id_dfr0, ID_DFR0, PERFMON) >= 4 && | ||
36 | + FIELD_EX32(cpu->id_dfr0, ID_DFR0, PERFMON) != 0xf) { | ||
37 | + ARMCPRegInfo v81_pmu_regs[] = { | ||
38 | + { .name = "PMCEID2", .state = ARM_CP_STATE_AA32, | ||
39 | + .cp = 15, .opc1 = 0, .crn = 9, .crm = 14, .opc2 = 4, | ||
40 | + .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST, | ||
41 | + .resetvalue = extract64(cpu->pmceid0, 32, 32) }, | ||
42 | + { .name = "PMCEID3", .state = ARM_CP_STATE_AA32, | ||
43 | + .cp = 15, .opc1 = 0, .crn = 9, .crm = 14, .opc2 = 5, | ||
44 | + .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST, | ||
45 | + .resetvalue = extract64(cpu->pmceid1, 32, 32) }, | ||
46 | + REGINFO_SENTINEL | ||
47 | + }; | ||
48 | + define_arm_cp_regs(cpu, v81_pmu_regs); | ||
49 | + } | ||
50 | if (arm_feature(env, ARM_FEATURE_V8)) { | ||
51 | /* AArch64 ID registers, which all have impdef reset values. | ||
52 | * Note that within the ID register ranges the unused slots | ||
53 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
54 | { .name = "PMCEID0", .state = ARM_CP_STATE_AA32, | ||
55 | .cp = 15, .opc1 = 0, .crn = 9, .crm = 12, .opc2 = 6, | ||
56 | .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST, | ||
57 | - .resetvalue = cpu->pmceid0 }, | ||
58 | + .resetvalue = extract64(cpu->pmceid0, 0, 32) }, | ||
59 | { .name = "PMCEID0_EL0", .state = ARM_CP_STATE_AA64, | ||
60 | .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 6, | ||
61 | .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST, | ||
62 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
63 | { .name = "PMCEID1", .state = ARM_CP_STATE_AA32, | ||
64 | .cp = 15, .opc1 = 0, .crn = 9, .crm = 12, .opc2 = 7, | ||
65 | .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST, | ||
66 | - .resetvalue = cpu->pmceid1 }, | ||
67 | + .resetvalue = extract64(cpu->pmceid1, 0, 32) }, | ||
68 | { .name = "PMCEID1_EL0", .state = ARM_CP_STATE_AA64, | ||
69 | .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 7, | ||
70 | .access = PL0_R, .accessfn = pmreg_access, .type = ARM_CP_CONST, | ||
116 | -- | 71 | -- |
117 | 2.20.1 | 72 | 2.20.1 |
118 | 73 | ||
119 | 74 | diff view generated by jsdifflib |
1 | From: Paul Zimmerman <pauldzim@gmail.com> | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | Add BCM2835 SOC MPHI (Message-based Parallel Host Interface) | 3 | This commit doesn't add any supported events, but provides the framework |
4 | emulation. It is very basic, only providing the FIQ interrupt | 4 | for adding them. We store the pm_event structs in a simple array, and |
5 | needed to allow the dwc-otg USB host controller driver in the | 5 | provide the mapping from the event numbers to array indexes in the |
6 | Raspbian kernel to function. | 6 | supported_event_map array. Because the value of PMCEID[01] depends upon |
7 | which events are supported at runtime, generate it dynamically. | ||
7 | 8 | ||
8 | Signed-off-by: Paul Zimmerman <pauldzim@gmail.com> | 9 | Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org> |
9 | Acked-by: Philippe Mathieu-Daude <f4bug@amsat.org> | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
11 | Message-id: 20200520235349.21215-2-pauldzim@gmail.com | 11 | Message-id: 20181211151945.29137-10-aaron@os.amperecomputing.com |
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | --- | 13 | --- |
14 | include/hw/arm/bcm2835_peripherals.h | 2 + | 14 | target/arm/cpu.h | 10 ++++++++ |
15 | include/hw/misc/bcm2835_mphi.h | 44 ++++++ | 15 | target/arm/cpu.c | 19 +++++++++------ |
16 | hw/arm/bcm2835_peripherals.c | 17 +++ | 16 | target/arm/cpu64.c | 4 ---- |
17 | hw/misc/bcm2835_mphi.c | 191 +++++++++++++++++++++++++++ | 17 | target/arm/helper.c | 57 +++++++++++++++++++++++++++++++++++++++++++++ |
18 | hw/misc/Makefile.objs | 1 + | 18 | 4 files changed, 79 insertions(+), 11 deletions(-) |
19 | 5 files changed, 255 insertions(+) | ||
20 | create mode 100644 include/hw/misc/bcm2835_mphi.h | ||
21 | create mode 100644 hw/misc/bcm2835_mphi.c | ||
22 | 19 | ||
23 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h | 20 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
24 | index XXXXXXX..XXXXXXX 100644 | 21 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/include/hw/arm/bcm2835_peripherals.h | 22 | --- a/target/arm/cpu.h |
26 | +++ b/include/hw/arm/bcm2835_peripherals.h | 23 | +++ b/target/arm/cpu.h |
27 | @@ -XXX,XX +XXX,XX @@ | 24 | @@ -XXX,XX +XXX,XX @@ void pmu_op_finish(CPUARMState *env); |
28 | #include "hw/misc/bcm2835_property.h" | 25 | void pmu_pre_el_change(ARMCPU *cpu, void *ignored); |
29 | #include "hw/misc/bcm2835_rng.h" | 26 | void pmu_post_el_change(ARMCPU *cpu, void *ignored); |
30 | #include "hw/misc/bcm2835_mbox.h" | 27 | |
31 | +#include "hw/misc/bcm2835_mphi.h" | ||
32 | #include "hw/misc/bcm2835_thermal.h" | ||
33 | #include "hw/sd/sdhci.h" | ||
34 | #include "hw/sd/bcm2835_sdhost.h" | ||
35 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM2835PeripheralState { | ||
36 | qemu_irq irq, fiq; | ||
37 | |||
38 | BCM2835SystemTimerState systmr; | ||
39 | + BCM2835MphiState mphi; | ||
40 | UnimplementedDeviceState armtmr; | ||
41 | UnimplementedDeviceState cprman; | ||
42 | UnimplementedDeviceState a2w; | ||
43 | diff --git a/include/hw/misc/bcm2835_mphi.h b/include/hw/misc/bcm2835_mphi.h | ||
44 | new file mode 100644 | ||
45 | index XXXXXXX..XXXXXXX | ||
46 | --- /dev/null | ||
47 | +++ b/include/hw/misc/bcm2835_mphi.h | ||
48 | @@ -XXX,XX +XXX,XX @@ | ||
49 | +/* | 28 | +/* |
50 | + * BCM2835 SOC MPHI state definitions | 29 | + * get_pmceid |
30 | + * @env: CPUARMState | ||
31 | + * @which: which PMCEID register to return (0 or 1) | ||
51 | + * | 32 | + * |
52 | + * Copyright (c) 2020 Paul Zimmerman <pauldzim@gmail.com> | 33 | + * Return the PMCEID[01]_EL0 register values corresponding to the counters |
53 | + * | 34 | + * which are supported given the current configuration |
54 | + * This program is free software; you can redistribute it and/or modify | ||
55 | + * it under the terms of the GNU General Public License as published by | ||
56 | + * the Free Software Foundation; either version 2 of the License, or | ||
57 | + * (at your option) any later version. | ||
58 | + * | ||
59 | + * This program is distributed in the hope that it will be useful, | ||
60 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
61 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
62 | + * GNU General Public License for more details. | ||
63 | + */ | 35 | + */ |
36 | +uint64_t get_pmceid(CPUARMState *env, unsigned which); | ||
64 | + | 37 | + |
65 | +#ifndef HW_MISC_BCM2835_MPHI_H | 38 | /* SCTLR bit meanings. Several bits have been reused in newer |
66 | +#define HW_MISC_BCM2835_MPHI_H | 39 | * versions of the architecture; in that case we define constants |
40 | * for both old and new bit meanings. Code which tests against those | ||
41 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/target/arm/cpu.c | ||
44 | +++ b/target/arm/cpu.c | ||
45 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp) | ||
46 | |||
47 | if (!cpu->has_pmu) { | ||
48 | unset_feature(env, ARM_FEATURE_PMU); | ||
49 | + } | ||
50 | + if (arm_feature(env, ARM_FEATURE_PMU)) { | ||
51 | + cpu->pmceid0 = get_pmceid(&cpu->env, 0); | ||
52 | + cpu->pmceid1 = get_pmceid(&cpu->env, 1); | ||
67 | + | 53 | + |
68 | +#include "hw/irq.h" | 54 | + if (!kvm_enabled()) { |
69 | +#include "hw/sysbus.h" | 55 | + arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0); |
56 | + arm_register_el_change_hook(cpu, &pmu_post_el_change, 0); | ||
57 | + } | ||
58 | + } else { | ||
59 | cpu->id_aa64dfr0 &= ~0xf00; | ||
60 | - } else if (!kvm_enabled()) { | ||
61 | - arm_register_pre_el_change_hook(cpu, &pmu_pre_el_change, 0); | ||
62 | - arm_register_el_change_hook(cpu, &pmu_post_el_change, 0); | ||
63 | + cpu->pmceid0 = 0; | ||
64 | + cpu->pmceid1 = 0; | ||
65 | } | ||
66 | |||
67 | if (!arm_feature(env, ARM_FEATURE_EL2)) { | ||
68 | @@ -XXX,XX +XXX,XX @@ static void cortex_a7_initfn(Object *obj) | ||
69 | cpu->id_pfr0 = 0x00001131; | ||
70 | cpu->id_pfr1 = 0x00011011; | ||
71 | cpu->id_dfr0 = 0x02010555; | ||
72 | - cpu->pmceid0 = 0x00000000; | ||
73 | - cpu->pmceid1 = 0x00000000; | ||
74 | cpu->id_afr0 = 0x00000000; | ||
75 | cpu->id_mmfr0 = 0x10101105; | ||
76 | cpu->id_mmfr1 = 0x40000000; | ||
77 | @@ -XXX,XX +XXX,XX @@ static void cortex_a15_initfn(Object *obj) | ||
78 | cpu->id_pfr0 = 0x00001131; | ||
79 | cpu->id_pfr1 = 0x00011011; | ||
80 | cpu->id_dfr0 = 0x02010555; | ||
81 | - cpu->pmceid0 = 0x0000000; | ||
82 | - cpu->pmceid1 = 0x00000000; | ||
83 | cpu->id_afr0 = 0x00000000; | ||
84 | cpu->id_mmfr0 = 0x10201105; | ||
85 | cpu->id_mmfr1 = 0x20000000; | ||
86 | diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c | ||
87 | index XXXXXXX..XXXXXXX 100644 | ||
88 | --- a/target/arm/cpu64.c | ||
89 | +++ b/target/arm/cpu64.c | ||
90 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a57_initfn(Object *obj) | ||
91 | cpu->isar.id_isar6 = 0; | ||
92 | cpu->isar.id_aa64pfr0 = 0x00002222; | ||
93 | cpu->id_aa64dfr0 = 0x10305106; | ||
94 | - cpu->pmceid0 = 0x00000000; | ||
95 | - cpu->pmceid1 = 0x00000000; | ||
96 | cpu->isar.id_aa64isar0 = 0x00011120; | ||
97 | cpu->isar.id_aa64mmfr0 = 0x00001124; | ||
98 | cpu->dbgdidr = 0x3516d000; | ||
99 | @@ -XXX,XX +XXX,XX @@ static void aarch64_a72_initfn(Object *obj) | ||
100 | cpu->isar.id_isar5 = 0x00011121; | ||
101 | cpu->isar.id_aa64pfr0 = 0x00002222; | ||
102 | cpu->id_aa64dfr0 = 0x10305106; | ||
103 | - cpu->pmceid0 = 0x00000000; | ||
104 | - cpu->pmceid1 = 0x00000000; | ||
105 | cpu->isar.id_aa64isar0 = 0x00011120; | ||
106 | cpu->isar.id_aa64mmfr0 = 0x00001124; | ||
107 | cpu->dbgdidr = 0x3516d000; | ||
108 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
109 | index XXXXXXX..XXXXXXX 100644 | ||
110 | --- a/target/arm/helper.c | ||
111 | +++ b/target/arm/helper.c | ||
112 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t pmu_counter_mask(CPUARMState *env) | ||
113 | return (1 << 31) | ((1 << pmu_num_counters(env)) - 1); | ||
114 | } | ||
115 | |||
116 | +typedef struct pm_event { | ||
117 | + uint16_t number; /* PMEVTYPER.evtCount is 16 bits wide */ | ||
118 | + /* If the event is supported on this CPU (used to generate PMCEID[01]) */ | ||
119 | + bool (*supported)(CPUARMState *); | ||
120 | + /* | ||
121 | + * Retrieve the current count of the underlying event. The programmed | ||
122 | + * counters hold a difference from the return value from this function | ||
123 | + */ | ||
124 | + uint64_t (*get_count)(CPUARMState *); | ||
125 | +} pm_event; | ||
70 | + | 126 | + |
71 | +#define MPHI_MMIO_SIZE 0x1000 | 127 | +static const pm_event pm_events[] = { |
72 | + | ||
73 | +typedef struct BCM2835MphiState BCM2835MphiState; | ||
74 | + | ||
75 | +struct BCM2835MphiState { | ||
76 | + SysBusDevice parent_obj; | ||
77 | + qemu_irq irq; | ||
78 | + MemoryRegion iomem; | ||
79 | + | ||
80 | + uint32_t outdda; | ||
81 | + uint32_t outddb; | ||
82 | + uint32_t ctrl; | ||
83 | + uint32_t intstat; | ||
84 | + uint32_t swirq; | ||
85 | +}; | 128 | +}; |
86 | + | 129 | + |
87 | +#define TYPE_BCM2835_MPHI "bcm2835-mphi" | 130 | +/* |
131 | + * Note: Before increasing MAX_EVENT_ID beyond 0x3f into the 0x40xx range of | ||
132 | + * events (i.e. the statistical profiling extension), this implementation | ||
133 | + * should first be updated to something sparse instead of the current | ||
134 | + * supported_event_map[] array. | ||
135 | + */ | ||
136 | +#define MAX_EVENT_ID 0x0 | ||
137 | +#define UNSUPPORTED_EVENT UINT16_MAX | ||
138 | +static uint16_t supported_event_map[MAX_EVENT_ID + 1]; | ||
88 | + | 139 | + |
89 | +#define BCM2835_MPHI(obj) \ | 140 | +/* |
90 | + OBJECT_CHECK(BCM2835MphiState, (obj), TYPE_BCM2835_MPHI) | 141 | + * Called upon initialization to build PMCEID0_EL0 or PMCEID1_EL0 (indicated by |
142 | + * 'which'). We also use it to build a map of ARM event numbers to indices in | ||
143 | + * our pm_events array. | ||
144 | + * | ||
145 | + * Note: Events in the 0x40XX range are not currently supported. | ||
146 | + */ | ||
147 | +uint64_t get_pmceid(CPUARMState *env, unsigned which) | ||
148 | +{ | ||
149 | + uint64_t pmceid = 0; | ||
150 | + unsigned int i; | ||
91 | + | 151 | + |
92 | +#endif | 152 | + assert(which <= 1); |
93 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | ||
94 | index XXXXXXX..XXXXXXX 100644 | ||
95 | --- a/hw/arm/bcm2835_peripherals.c | ||
96 | +++ b/hw/arm/bcm2835_peripherals.c | ||
97 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj) | ||
98 | OBJECT(&s->sdhci.sdbus)); | ||
99 | object_property_add_const_link(OBJECT(&s->gpio), "sdbus-sdhost", | ||
100 | OBJECT(&s->sdhost.sdbus)); | ||
101 | + | 153 | + |
102 | + /* Mphi */ | 154 | + for (i = 0; i < ARRAY_SIZE(supported_event_map); i++) { |
103 | + sysbus_init_child_obj(obj, "mphi", &s->mphi, sizeof(s->mphi), | 155 | + supported_event_map[i] = UNSUPPORTED_EVENT; |
104 | + TYPE_BCM2835_MPHI); | ||
105 | } | ||
106 | |||
107 | static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
108 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
109 | |||
110 | object_property_add_alias(OBJECT(s), "sd-bus", OBJECT(&s->gpio), "sd-bus"); | ||
111 | |||
112 | + /* Mphi */ | ||
113 | + object_property_set_bool(OBJECT(&s->mphi), true, "realized", &err); | ||
114 | + if (err) { | ||
115 | + error_propagate(errp, err); | ||
116 | + return; | ||
117 | + } | 156 | + } |
118 | + | 157 | + |
119 | + memory_region_add_subregion(&s->peri_mr, MPHI_OFFSET, | 158 | + for (i = 0; i < ARRAY_SIZE(pm_events); i++) { |
120 | + sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->mphi), 0)); | 159 | + const pm_event *cnt = &pm_events[i]; |
121 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->mphi), 0, | 160 | + assert(cnt->number <= MAX_EVENT_ID); |
122 | + qdev_get_gpio_in_named(DEVICE(&s->ic), BCM2835_IC_GPU_IRQ, | 161 | + /* We do not currently support events in the 0x40xx range */ |
123 | + INTERRUPT_HOSTPORT)); | 162 | + assert(cnt->number <= 0x3f); |
124 | + | 163 | + |
125 | create_unimp(s, &s->armtmr, "bcm2835-sp804", ARMCTRL_TIMER0_1_OFFSET, 0x40); | 164 | + if ((cnt->number & 0x20) == (which << 6) && |
126 | create_unimp(s, &s->cprman, "bcm2835-cprman", CPRMAN_OFFSET, 0x1000); | 165 | + cnt->supported(env)) { |
127 | create_unimp(s, &s->a2w, "bcm2835-a2w", A2W_OFFSET, 0x1000); | 166 | + pmceid |= (1 << (cnt->number & 0x1f)); |
128 | diff --git a/hw/misc/bcm2835_mphi.c b/hw/misc/bcm2835_mphi.c | 167 | + supported_event_map[cnt->number] = i; |
129 | new file mode 100644 | 168 | + } |
130 | index XXXXXXX..XXXXXXX | 169 | + } |
131 | --- /dev/null | 170 | + return pmceid; |
132 | +++ b/hw/misc/bcm2835_mphi.c | ||
133 | @@ -XXX,XX +XXX,XX @@ | ||
134 | +/* | ||
135 | + * BCM2835 SOC MPHI emulation | ||
136 | + * | ||
137 | + * Very basic emulation, only providing the FIQ interrupt needed to | ||
138 | + * allow the dwc-otg USB host controller driver in the Raspbian kernel | ||
139 | + * to function. | ||
140 | + * | ||
141 | + * Copyright (c) 2020 Paul Zimmerman <pauldzim@gmail.com> | ||
142 | + * | ||
143 | + * This program is free software; you can redistribute it and/or modify | ||
144 | + * it under the terms of the GNU General Public License as published by | ||
145 | + * the Free Software Foundation; either version 2 of the License, or | ||
146 | + * (at your option) any later version. | ||
147 | + * | ||
148 | + * This program is distributed in the hope that it will be useful, | ||
149 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
150 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
151 | + * GNU General Public License for more details. | ||
152 | + */ | ||
153 | + | ||
154 | +#include "qemu/osdep.h" | ||
155 | +#include "qapi/error.h" | ||
156 | +#include "hw/misc/bcm2835_mphi.h" | ||
157 | +#include "migration/vmstate.h" | ||
158 | +#include "qemu/error-report.h" | ||
159 | +#include "qemu/log.h" | ||
160 | +#include "qemu/main-loop.h" | ||
161 | + | ||
162 | +static inline void mphi_raise_irq(BCM2835MphiState *s) | ||
163 | +{ | ||
164 | + qemu_set_irq(s->irq, 1); | ||
165 | +} | 171 | +} |
166 | + | 172 | + |
167 | +static inline void mphi_lower_irq(BCM2835MphiState *s) | 173 | static CPAccessResult pmreg_access(CPUARMState *env, const ARMCPRegInfo *ri, |
168 | +{ | 174 | bool isread) |
169 | + qemu_set_irq(s->irq, 0); | 175 | { |
170 | +} | ||
171 | + | ||
172 | +static uint64_t mphi_reg_read(void *ptr, hwaddr addr, unsigned size) | ||
173 | +{ | ||
174 | + BCM2835MphiState *s = ptr; | ||
175 | + uint32_t val = 0; | ||
176 | + | ||
177 | + switch (addr) { | ||
178 | + case 0x28: /* outdda */ | ||
179 | + val = s->outdda; | ||
180 | + break; | ||
181 | + case 0x2c: /* outddb */ | ||
182 | + val = s->outddb; | ||
183 | + break; | ||
184 | + case 0x4c: /* ctrl */ | ||
185 | + val = s->ctrl; | ||
186 | + val |= 1 << 17; | ||
187 | + break; | ||
188 | + case 0x50: /* intstat */ | ||
189 | + val = s->intstat; | ||
190 | + break; | ||
191 | + case 0x1f0: /* swirq_set */ | ||
192 | + val = s->swirq; | ||
193 | + break; | ||
194 | + case 0x1f4: /* swirq_clr */ | ||
195 | + val = s->swirq; | ||
196 | + break; | ||
197 | + default: | ||
198 | + qemu_log_mask(LOG_UNIMP, "read from unknown register"); | ||
199 | + break; | ||
200 | + } | ||
201 | + | ||
202 | + return val; | ||
203 | +} | ||
204 | + | ||
205 | +static void mphi_reg_write(void *ptr, hwaddr addr, uint64_t val, unsigned size) | ||
206 | +{ | ||
207 | + BCM2835MphiState *s = ptr; | ||
208 | + int do_irq = 0; | ||
209 | + | ||
210 | + switch (addr) { | ||
211 | + case 0x28: /* outdda */ | ||
212 | + s->outdda = val; | ||
213 | + break; | ||
214 | + case 0x2c: /* outddb */ | ||
215 | + s->outddb = val; | ||
216 | + if (val & (1 << 29)) { | ||
217 | + do_irq = 1; | ||
218 | + } | ||
219 | + break; | ||
220 | + case 0x4c: /* ctrl */ | ||
221 | + s->ctrl = val; | ||
222 | + if (val & (1 << 16)) { | ||
223 | + do_irq = -1; | ||
224 | + } | ||
225 | + break; | ||
226 | + case 0x50: /* intstat */ | ||
227 | + s->intstat = val; | ||
228 | + if (val & ((1 << 16) | (1 << 29))) { | ||
229 | + do_irq = -1; | ||
230 | + } | ||
231 | + break; | ||
232 | + case 0x1f0: /* swirq_set */ | ||
233 | + s->swirq |= val; | ||
234 | + do_irq = 1; | ||
235 | + break; | ||
236 | + case 0x1f4: /* swirq_clr */ | ||
237 | + s->swirq &= ~val; | ||
238 | + do_irq = -1; | ||
239 | + break; | ||
240 | + default: | ||
241 | + qemu_log_mask(LOG_UNIMP, "write to unknown register"); | ||
242 | + return; | ||
243 | + } | ||
244 | + | ||
245 | + if (do_irq > 0) { | ||
246 | + mphi_raise_irq(s); | ||
247 | + } else if (do_irq < 0) { | ||
248 | + mphi_lower_irq(s); | ||
249 | + } | ||
250 | +} | ||
251 | + | ||
252 | +static const MemoryRegionOps mphi_mmio_ops = { | ||
253 | + .read = mphi_reg_read, | ||
254 | + .write = mphi_reg_write, | ||
255 | + .impl.min_access_size = 4, | ||
256 | + .impl.max_access_size = 4, | ||
257 | + .endianness = DEVICE_LITTLE_ENDIAN, | ||
258 | +}; | ||
259 | + | ||
260 | +static void mphi_reset(DeviceState *dev) | ||
261 | +{ | ||
262 | + BCM2835MphiState *s = BCM2835_MPHI(dev); | ||
263 | + | ||
264 | + s->outdda = 0; | ||
265 | + s->outddb = 0; | ||
266 | + s->ctrl = 0; | ||
267 | + s->intstat = 0; | ||
268 | + s->swirq = 0; | ||
269 | +} | ||
270 | + | ||
271 | +static void mphi_realize(DeviceState *dev, Error **errp) | ||
272 | +{ | ||
273 | + SysBusDevice *sbd = SYS_BUS_DEVICE(dev); | ||
274 | + BCM2835MphiState *s = BCM2835_MPHI(dev); | ||
275 | + | ||
276 | + sysbus_init_irq(sbd, &s->irq); | ||
277 | +} | ||
278 | + | ||
279 | +static void mphi_init(Object *obj) | ||
280 | +{ | ||
281 | + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); | ||
282 | + BCM2835MphiState *s = BCM2835_MPHI(obj); | ||
283 | + | ||
284 | + memory_region_init_io(&s->iomem, obj, &mphi_mmio_ops, s, "mphi", MPHI_MMIO_SIZE); | ||
285 | + sysbus_init_mmio(sbd, &s->iomem); | ||
286 | +} | ||
287 | + | ||
288 | +const VMStateDescription vmstate_mphi_state = { | ||
289 | + .name = "mphi", | ||
290 | + .version_id = 1, | ||
291 | + .minimum_version_id = 1, | ||
292 | + .fields = (VMStateField[]) { | ||
293 | + VMSTATE_UINT32(outdda, BCM2835MphiState), | ||
294 | + VMSTATE_UINT32(outddb, BCM2835MphiState), | ||
295 | + VMSTATE_UINT32(ctrl, BCM2835MphiState), | ||
296 | + VMSTATE_UINT32(intstat, BCM2835MphiState), | ||
297 | + VMSTATE_UINT32(swirq, BCM2835MphiState), | ||
298 | + VMSTATE_END_OF_LIST() | ||
299 | + } | ||
300 | +}; | ||
301 | + | ||
302 | +static void mphi_class_init(ObjectClass *klass, void *data) | ||
303 | +{ | ||
304 | + DeviceClass *dc = DEVICE_CLASS(klass); | ||
305 | + | ||
306 | + dc->realize = mphi_realize; | ||
307 | + dc->reset = mphi_reset; | ||
308 | + dc->vmsd = &vmstate_mphi_state; | ||
309 | +} | ||
310 | + | ||
311 | +static const TypeInfo bcm2835_mphi_type_info = { | ||
312 | + .name = TYPE_BCM2835_MPHI, | ||
313 | + .parent = TYPE_SYS_BUS_DEVICE, | ||
314 | + .instance_size = sizeof(BCM2835MphiState), | ||
315 | + .instance_init = mphi_init, | ||
316 | + .class_init = mphi_class_init, | ||
317 | +}; | ||
318 | + | ||
319 | +static void bcm2835_mphi_register_types(void) | ||
320 | +{ | ||
321 | + type_register_static(&bcm2835_mphi_type_info); | ||
322 | +} | ||
323 | + | ||
324 | +type_init(bcm2835_mphi_register_types) | ||
325 | diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs | ||
326 | index XXXXXXX..XXXXXXX 100644 | ||
327 | --- a/hw/misc/Makefile.objs | ||
328 | +++ b/hw/misc/Makefile.objs | ||
329 | @@ -XXX,XX +XXX,XX @@ common-obj-$(CONFIG_OMAP) += omap_l4.o | ||
330 | common-obj-$(CONFIG_OMAP) += omap_sdrc.o | ||
331 | common-obj-$(CONFIG_OMAP) += omap_tap.o | ||
332 | common-obj-$(CONFIG_RASPI) += bcm2835_mbox.o | ||
333 | +common-obj-$(CONFIG_RASPI) += bcm2835_mphi.o | ||
334 | common-obj-$(CONFIG_RASPI) += bcm2835_property.o | ||
335 | common-obj-$(CONFIG_RASPI) += bcm2835_rng.o | ||
336 | common-obj-$(CONFIG_RASPI) += bcm2835_thermal.o | ||
337 | -- | 176 | -- |
338 | 2.20.1 | 177 | 2.20.1 |
339 | 178 | ||
340 | 179 | diff view generated by jsdifflib |
1 | From: Thomas Huth <thuth@redhat.com> | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | As described by Edgar here: | 3 | Add arrays to hold the registers, the definitions themselves, access |
4 | functions, and logic to reset counters when PMCR.P is set. Update | ||
5 | filtering code to support counters other than PMCCNTR. Support migration | ||
6 | with raw read/write functions. | ||
4 | 7 | ||
5 | https://www.mail-archive.com/qemu-devel@nongnu.org/msg605124.html | 8 | Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org> |
6 | 9 | Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com> | |
7 | we can use the Ubuntu kernel for testing the xlnx-versal-virt machine. | 10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
8 | So let's add a boot test for this now. | 11 | Message-id: 20181211151945.29137-11-aaron@os.amperecomputing.com |
9 | |||
10 | Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
11 | Tested-by: Philippe Mathieu-Daudé <philmd@redhat.com> | ||
12 | Signed-off-by: Thomas Huth <thuth@redhat.com> | ||
13 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
14 | Reviewed-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com> | ||
15 | Message-id: 20200525141237.15243-1-thuth@redhat.com | ||
16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
17 | --- | 13 | --- |
18 | tests/acceptance/boot_linux_console.py | 26 ++++++++++++++++++++++++++ | 14 | target/arm/cpu.h | 3 + |
19 | 1 file changed, 26 insertions(+) | 15 | target/arm/helper.c | 296 +++++++++++++++++++++++++++++++++++++++++--- |
16 | 2 files changed, 282 insertions(+), 17 deletions(-) | ||
20 | 17 | ||
21 | diff --git a/tests/acceptance/boot_linux_console.py b/tests/acceptance/boot_linux_console.py | 18 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
22 | index XXXXXXX..XXXXXXX 100644 | 19 | index XXXXXXX..XXXXXXX 100644 |
23 | --- a/tests/acceptance/boot_linux_console.py | 20 | --- a/target/arm/cpu.h |
24 | +++ b/tests/acceptance/boot_linux_console.py | 21 | +++ b/target/arm/cpu.h |
25 | @@ -XXX,XX +XXX,XX @@ class BootLinuxConsole(LinuxKernelTest): | 22 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { |
26 | console_pattern = 'Kernel command line: %s' % kernel_command_line | 23 | * pmccntr_op_finish. |
27 | self.wait_for_console_pattern(console_pattern) | 24 | */ |
28 | 25 | uint64_t c15_ccnt_delta; | |
29 | + def test_aarch64_xlnx_versal_virt(self): | 26 | + uint64_t c14_pmevcntr[31]; |
30 | + """ | 27 | + uint64_t c14_pmevcntr_delta[31]; |
31 | + :avocado: tags=arch:aarch64 | 28 | + uint64_t c14_pmevtyper[31]; |
32 | + :avocado: tags=machine:xlnx-versal-virt | 29 | uint64_t pmccfiltr_el0; /* Performance Monitor Filter Register */ |
33 | + :avocado: tags=device:pl011 | 30 | uint64_t vpidr_el2; /* Virtualization Processor ID Register */ |
34 | + :avocado: tags=device:arm_gicv3 | 31 | uint64_t vmpidr_el2; /* Virtualization Multiprocessor ID Register */ |
35 | + """ | 32 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
36 | + kernel_url = ('http://ports.ubuntu.com/ubuntu-ports/dists/' | 33 | index XXXXXXX..XXXXXXX 100644 |
37 | + 'bionic-updates/main/installer-arm64/current/images/' | 34 | --- a/target/arm/helper.c |
38 | + 'netboot/ubuntu-installer/arm64/linux') | 35 | +++ b/target/arm/helper.c |
39 | + kernel_hash = '5bfc54cf7ed8157d93f6e5b0241e727b6dc22c50' | 36 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v6_cp_reginfo[] = { |
40 | + kernel_path = self.fetch_asset(kernel_url, asset_hash=kernel_hash) | 37 | #define PMCRDP 0x10 |
41 | + | 38 | #define PMCRD 0x8 |
42 | + initrd_url = ('http://ports.ubuntu.com/ubuntu-ports/dists/' | 39 | #define PMCRC 0x4 |
43 | + 'bionic-updates/main/installer-arm64/current/images/' | 40 | +#define PMCRP 0x2 |
44 | + 'netboot/ubuntu-installer/arm64/initrd.gz') | 41 | #define PMCRE 0x1 |
45 | + initrd_hash = 'd385d3e88d53e2004c5d43cbe668b458a094f772' | 42 | |
46 | + initrd_path = self.fetch_asset(initrd_url, asset_hash=initrd_hash) | 43 | #define PMXEVTYPER_P 0x80000000 |
47 | + | 44 | @@ -XXX,XX +XXX,XX @@ uint64_t get_pmceid(CPUARMState *env, unsigned which) |
48 | + self.vm.set_console() | 45 | return pmceid; |
49 | + self.vm.add_args('-m', '2G', | 46 | } |
50 | + '-kernel', kernel_path, | 47 | |
51 | + '-initrd', initrd_path) | 48 | +/* |
52 | + self.vm.launch() | 49 | + * Check at runtime whether a PMU event is supported for the current machine |
53 | + self.wait_for_console_pattern('Checked W+X mappings: passed') | 50 | + */ |
54 | + | 51 | +static bool event_supported(uint16_t number) |
55 | def test_arm_virt(self): | 52 | +{ |
56 | """ | 53 | + if (number > MAX_EVENT_ID) { |
57 | :avocado: tags=arch:arm | 54 | + return false; |
55 | + } | ||
56 | + return supported_event_map[number] != UNSUPPORTED_EVENT; | ||
57 | +} | ||
58 | + | ||
59 | static CPAccessResult pmreg_access(CPUARMState *env, const ARMCPRegInfo *ri, | ||
60 | bool isread) | ||
61 | { | ||
62 | @@ -XXX,XX +XXX,XX @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter) | ||
63 | prohibited = env->cp15.c9_pmcr & PMCRDP; | ||
64 | } | ||
65 | |||
66 | - /* TODO Remove assert, set filter to correct PMEVTYPER */ | ||
67 | - assert(counter == 31); | ||
68 | - filter = env->cp15.pmccfiltr_el0; | ||
69 | + if (counter == 31) { | ||
70 | + filter = env->cp15.pmccfiltr_el0; | ||
71 | + } else { | ||
72 | + filter = env->cp15.c14_pmevtyper[counter]; | ||
73 | + } | ||
74 | |||
75 | p = filter & PMXEVTYPER_P; | ||
76 | u = filter & PMXEVTYPER_U; | ||
77 | @@ -XXX,XX +XXX,XX @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter) | ||
78 | filtered = m != p; | ||
79 | } | ||
80 | |||
81 | + if (counter != 31) { | ||
82 | + /* | ||
83 | + * If not checking PMCCNTR, ensure the counter is setup to an event we | ||
84 | + * support | ||
85 | + */ | ||
86 | + uint16_t event = filter & PMXEVTYPER_EVTCOUNT; | ||
87 | + if (!event_supported(event)) { | ||
88 | + return false; | ||
89 | + } | ||
90 | + } | ||
91 | + | ||
92 | return enabled && !prohibited && !filtered; | ||
93 | } | ||
94 | |||
95 | @@ -XXX,XX +XXX,XX @@ void pmccntr_op_finish(CPUARMState *env) | ||
96 | } | ||
97 | } | ||
98 | |||
99 | +static void pmevcntr_op_start(CPUARMState *env, uint8_t counter) | ||
100 | +{ | ||
101 | + | ||
102 | + uint16_t event = env->cp15.c14_pmevtyper[counter] & PMXEVTYPER_EVTCOUNT; | ||
103 | + uint64_t count = 0; | ||
104 | + if (event_supported(event)) { | ||
105 | + uint16_t event_idx = supported_event_map[event]; | ||
106 | + count = pm_events[event_idx].get_count(env); | ||
107 | + } | ||
108 | + | ||
109 | + if (pmu_counter_enabled(env, counter)) { | ||
110 | + env->cp15.c14_pmevcntr[counter] = | ||
111 | + count - env->cp15.c14_pmevcntr_delta[counter]; | ||
112 | + } | ||
113 | + env->cp15.c14_pmevcntr_delta[counter] = count; | ||
114 | +} | ||
115 | + | ||
116 | +static void pmevcntr_op_finish(CPUARMState *env, uint8_t counter) | ||
117 | +{ | ||
118 | + if (pmu_counter_enabled(env, counter)) { | ||
119 | + env->cp15.c14_pmevcntr_delta[counter] -= | ||
120 | + env->cp15.c14_pmevcntr[counter]; | ||
121 | + } | ||
122 | +} | ||
123 | + | ||
124 | void pmu_op_start(CPUARMState *env) | ||
125 | { | ||
126 | + unsigned int i; | ||
127 | pmccntr_op_start(env); | ||
128 | + for (i = 0; i < pmu_num_counters(env); i++) { | ||
129 | + pmevcntr_op_start(env, i); | ||
130 | + } | ||
131 | } | ||
132 | |||
133 | void pmu_op_finish(CPUARMState *env) | ||
134 | { | ||
135 | + unsigned int i; | ||
136 | pmccntr_op_finish(env); | ||
137 | + for (i = 0; i < pmu_num_counters(env); i++) { | ||
138 | + pmevcntr_op_finish(env, i); | ||
139 | + } | ||
140 | } | ||
141 | |||
142 | void pmu_pre_el_change(ARMCPU *cpu, void *ignored) | ||
143 | @@ -XXX,XX +XXX,XX @@ static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
144 | env->cp15.c15_ccnt = 0; | ||
145 | } | ||
146 | |||
147 | + if (value & PMCRP) { | ||
148 | + unsigned int i; | ||
149 | + for (i = 0; i < pmu_num_counters(env); i++) { | ||
150 | + env->cp15.c14_pmevcntr[i] = 0; | ||
151 | + } | ||
152 | + } | ||
153 | + | ||
154 | /* only the DP, X, D and E bits are writable */ | ||
155 | env->cp15.c9_pmcr &= ~0x39; | ||
156 | env->cp15.c9_pmcr |= (value & 0x39); | ||
157 | @@ -XXX,XX +XXX,XX @@ void pmccntr_op_finish(CPUARMState *env) | ||
158 | { | ||
159 | } | ||
160 | |||
161 | +void pmevcntr_op_start(CPUARMState *env, uint8_t i) | ||
162 | +{ | ||
163 | +} | ||
164 | + | ||
165 | +void pmevcntr_op_finish(CPUARMState *env, uint8_t i) | ||
166 | +{ | ||
167 | +} | ||
168 | + | ||
169 | void pmu_op_start(CPUARMState *env) | ||
170 | { | ||
171 | } | ||
172 | @@ -XXX,XX +XXX,XX @@ static void pmovsset_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
173 | env->cp15.c9_pmovsr |= value; | ||
174 | } | ||
175 | |||
176 | -static void pmxevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
177 | - uint64_t value) | ||
178 | +static void pmevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
179 | + uint64_t value, const uint8_t counter) | ||
180 | { | ||
181 | + if (counter == 31) { | ||
182 | + pmccfiltr_write(env, ri, value); | ||
183 | + } else if (counter < pmu_num_counters(env)) { | ||
184 | + pmevcntr_op_start(env, counter); | ||
185 | + | ||
186 | + /* | ||
187 | + * If this counter's event type is changing, store the current | ||
188 | + * underlying count for the new type in c14_pmevcntr_delta[counter] so | ||
189 | + * pmevcntr_op_finish has the correct baseline when it converts back to | ||
190 | + * a delta. | ||
191 | + */ | ||
192 | + uint16_t old_event = env->cp15.c14_pmevtyper[counter] & | ||
193 | + PMXEVTYPER_EVTCOUNT; | ||
194 | + uint16_t new_event = value & PMXEVTYPER_EVTCOUNT; | ||
195 | + if (old_event != new_event) { | ||
196 | + uint64_t count = 0; | ||
197 | + if (event_supported(new_event)) { | ||
198 | + uint16_t event_idx = supported_event_map[new_event]; | ||
199 | + count = pm_events[event_idx].get_count(env); | ||
200 | + } | ||
201 | + env->cp15.c14_pmevcntr_delta[counter] = count; | ||
202 | + } | ||
203 | + | ||
204 | + env->cp15.c14_pmevtyper[counter] = value & PMXEVTYPER_MASK; | ||
205 | + pmevcntr_op_finish(env, counter); | ||
206 | + } | ||
207 | /* Attempts to access PMXEVTYPER are CONSTRAINED UNPREDICTABLE when | ||
208 | * PMSELR value is equal to or greater than the number of implemented | ||
209 | * counters, but not equal to 0x1f. We opt to behave as a RAZ/WI. | ||
210 | */ | ||
211 | - if (env->cp15.c9_pmselr == 0x1f) { | ||
212 | - pmccfiltr_write(env, ri, value); | ||
213 | +} | ||
214 | + | ||
215 | +static uint64_t pmevtyper_read(CPUARMState *env, const ARMCPRegInfo *ri, | ||
216 | + const uint8_t counter) | ||
217 | +{ | ||
218 | + if (counter == 31) { | ||
219 | + return env->cp15.pmccfiltr_el0; | ||
220 | + } else if (counter < pmu_num_counters(env)) { | ||
221 | + return env->cp15.c14_pmevtyper[counter]; | ||
222 | + } else { | ||
223 | + /* | ||
224 | + * We opt to behave as a RAZ/WI when attempts to access PMXEVTYPER | ||
225 | + * are CONSTRAINED UNPREDICTABLE. See comments in pmevtyper_write(). | ||
226 | + */ | ||
227 | + return 0; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | +static void pmevtyper_writefn(CPUARMState *env, const ARMCPRegInfo *ri, | ||
232 | + uint64_t value) | ||
233 | +{ | ||
234 | + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); | ||
235 | + pmevtyper_write(env, ri, value, counter); | ||
236 | +} | ||
237 | + | ||
238 | +static void pmevtyper_rawwrite(CPUARMState *env, const ARMCPRegInfo *ri, | ||
239 | + uint64_t value) | ||
240 | +{ | ||
241 | + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); | ||
242 | + env->cp15.c14_pmevtyper[counter] = value; | ||
243 | + | ||
244 | + /* | ||
245 | + * pmevtyper_rawwrite is called between a pair of pmu_op_start and | ||
246 | + * pmu_op_finish calls when loading saved state for a migration. Because | ||
247 | + * we're potentially updating the type of event here, the value written to | ||
248 | + * c14_pmevcntr_delta by the preceeding pmu_op_start call may be for a | ||
249 | + * different counter type. Therefore, we need to set this value to the | ||
250 | + * current count for the counter type we're writing so that pmu_op_finish | ||
251 | + * has the correct count for its calculation. | ||
252 | + */ | ||
253 | + uint16_t event = value & PMXEVTYPER_EVTCOUNT; | ||
254 | + if (event_supported(event)) { | ||
255 | + uint16_t event_idx = supported_event_map[event]; | ||
256 | + env->cp15.c14_pmevcntr_delta[counter] = | ||
257 | + pm_events[event_idx].get_count(env); | ||
258 | + } | ||
259 | +} | ||
260 | + | ||
261 | +static uint64_t pmevtyper_readfn(CPUARMState *env, const ARMCPRegInfo *ri) | ||
262 | +{ | ||
263 | + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); | ||
264 | + return pmevtyper_read(env, ri, counter); | ||
265 | +} | ||
266 | + | ||
267 | +static void pmxevtyper_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
268 | + uint64_t value) | ||
269 | +{ | ||
270 | + pmevtyper_write(env, ri, value, env->cp15.c9_pmselr & 31); | ||
271 | +} | ||
272 | + | ||
273 | static uint64_t pmxevtyper_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
274 | { | ||
275 | - /* We opt to behave as a RAZ/WI when attempts to access PMXEVTYPER | ||
276 | - * are CONSTRAINED UNPREDICTABLE. See comments in pmxevtyper_write(). | ||
277 | + return pmevtyper_read(env, ri, env->cp15.c9_pmselr & 31); | ||
278 | +} | ||
279 | + | ||
280 | +static void pmevcntr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
281 | + uint64_t value, uint8_t counter) | ||
282 | +{ | ||
283 | + if (counter < pmu_num_counters(env)) { | ||
284 | + pmevcntr_op_start(env, counter); | ||
285 | + env->cp15.c14_pmevcntr[counter] = value; | ||
286 | + pmevcntr_op_finish(env, counter); | ||
287 | + } | ||
288 | + /* | ||
289 | + * We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR | ||
290 | + * are CONSTRAINED UNPREDICTABLE. | ||
291 | */ | ||
292 | - if (env->cp15.c9_pmselr == 0x1f) { | ||
293 | - return env->cp15.pmccfiltr_el0; | ||
294 | +} | ||
295 | + | ||
296 | +static uint64_t pmevcntr_read(CPUARMState *env, const ARMCPRegInfo *ri, | ||
297 | + uint8_t counter) | ||
298 | +{ | ||
299 | + if (counter < pmu_num_counters(env)) { | ||
300 | + uint64_t ret; | ||
301 | + pmevcntr_op_start(env, counter); | ||
302 | + ret = env->cp15.c14_pmevcntr[counter]; | ||
303 | + pmevcntr_op_finish(env, counter); | ||
304 | + return ret; | ||
305 | } else { | ||
306 | + /* We opt to behave as a RAZ/WI when attempts to access PM[X]EVCNTR | ||
307 | + * are CONSTRAINED UNPREDICTABLE. */ | ||
308 | return 0; | ||
309 | } | ||
310 | } | ||
311 | |||
312 | +static void pmevcntr_writefn(CPUARMState *env, const ARMCPRegInfo *ri, | ||
313 | + uint64_t value) | ||
314 | +{ | ||
315 | + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); | ||
316 | + pmevcntr_write(env, ri, value, counter); | ||
317 | +} | ||
318 | + | ||
319 | +static uint64_t pmevcntr_readfn(CPUARMState *env, const ARMCPRegInfo *ri) | ||
320 | +{ | ||
321 | + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); | ||
322 | + return pmevcntr_read(env, ri, counter); | ||
323 | +} | ||
324 | + | ||
325 | +static void pmevcntr_rawwrite(CPUARMState *env, const ARMCPRegInfo *ri, | ||
326 | + uint64_t value) | ||
327 | +{ | ||
328 | + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); | ||
329 | + assert(counter < pmu_num_counters(env)); | ||
330 | + env->cp15.c14_pmevcntr[counter] = value; | ||
331 | + pmevcntr_write(env, ri, value, counter); | ||
332 | +} | ||
333 | + | ||
334 | +static uint64_t pmevcntr_rawread(CPUARMState *env, const ARMCPRegInfo *ri) | ||
335 | +{ | ||
336 | + uint8_t counter = ((ri->crm & 3) << 3) | (ri->opc2 & 7); | ||
337 | + assert(counter < pmu_num_counters(env)); | ||
338 | + return env->cp15.c14_pmevcntr[counter]; | ||
339 | +} | ||
340 | + | ||
341 | +static void pmxevcntr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
342 | + uint64_t value) | ||
343 | +{ | ||
344 | + pmevcntr_write(env, ri, value, env->cp15.c9_pmselr & 31); | ||
345 | +} | ||
346 | + | ||
347 | +static uint64_t pmxevcntr_read(CPUARMState *env, const ARMCPRegInfo *ri) | ||
348 | +{ | ||
349 | + return pmevcntr_read(env, ri, env->cp15.c9_pmselr & 31); | ||
350 | +} | ||
351 | + | ||
352 | static void pmuserenr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
353 | uint64_t value) | ||
354 | { | ||
355 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = { | ||
356 | .fieldoffset = offsetof(CPUARMState, cp15.pmccfiltr_el0), | ||
357 | .resetvalue = 0, }, | ||
358 | { .name = "PMXEVTYPER", .cp = 15, .crn = 9, .crm = 13, .opc1 = 0, .opc2 = 1, | ||
359 | - .access = PL0_RW, .type = ARM_CP_NO_RAW, .accessfn = pmreg_access, | ||
360 | + .access = PL0_RW, .type = ARM_CP_NO_RAW | ARM_CP_IO, | ||
361 | + .accessfn = pmreg_access, | ||
362 | .writefn = pmxevtyper_write, .readfn = pmxevtyper_read }, | ||
363 | { .name = "PMXEVTYPER_EL0", .state = ARM_CP_STATE_AA64, | ||
364 | .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 13, .opc2 = 1, | ||
365 | - .access = PL0_RW, .type = ARM_CP_NO_RAW, .accessfn = pmreg_access, | ||
366 | + .access = PL0_RW, .type = ARM_CP_NO_RAW | ARM_CP_IO, | ||
367 | + .accessfn = pmreg_access, | ||
368 | .writefn = pmxevtyper_write, .readfn = pmxevtyper_read }, | ||
369 | - /* Unimplemented, RAZ/WI. */ | ||
370 | { .name = "PMXEVCNTR", .cp = 15, .crn = 9, .crm = 13, .opc1 = 0, .opc2 = 2, | ||
371 | - .access = PL0_RW, .type = ARM_CP_CONST, .resetvalue = 0, | ||
372 | - .accessfn = pmreg_access_xevcntr }, | ||
373 | + .access = PL0_RW, .type = ARM_CP_NO_RAW | ARM_CP_IO, | ||
374 | + .accessfn = pmreg_access_xevcntr, | ||
375 | + .writefn = pmxevcntr_write, .readfn = pmxevcntr_read }, | ||
376 | + { .name = "PMXEVCNTR_EL0", .state = ARM_CP_STATE_AA64, | ||
377 | + .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 13, .opc2 = 2, | ||
378 | + .access = PL0_RW, .type = ARM_CP_NO_RAW | ARM_CP_IO, | ||
379 | + .accessfn = pmreg_access_xevcntr, | ||
380 | + .writefn = pmxevcntr_write, .readfn = pmxevcntr_read }, | ||
381 | { .name = "PMUSERENR", .cp = 15, .crn = 9, .crm = 14, .opc1 = 0, .opc2 = 0, | ||
382 | .access = PL0_R | PL1_RW, .accessfn = access_tpm, | ||
383 | .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmuserenr), | ||
384 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = { | ||
385 | #endif | ||
386 | /* The only field of MDCR_EL2 that has a defined architectural reset value | ||
387 | * is MDCR_EL2.HPMN which should reset to the value of PMCR_EL0.N; but we | ||
388 | - * don't impelment any PMU event counters, so using zero as a reset | ||
389 | + * don't implement any PMU event counters, so using zero as a reset | ||
390 | * value for MDCR_EL2 is okay | ||
391 | */ | ||
392 | { .name = "MDCR_EL2", .state = ARM_CP_STATE_BOTH, | ||
393 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
394 | * field as main ID register, and we implement only the cycle | ||
395 | * count register. | ||
396 | */ | ||
397 | + unsigned int i, pmcrn = 0; | ||
398 | #ifndef CONFIG_USER_ONLY | ||
399 | ARMCPRegInfo pmcr = { | ||
400 | .name = "PMCR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 0, | ||
401 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
402 | }; | ||
403 | define_one_arm_cp_reg(cpu, &pmcr); | ||
404 | define_one_arm_cp_reg(cpu, &pmcr64); | ||
405 | + for (i = 0; i < pmcrn; i++) { | ||
406 | + char *pmevcntr_name = g_strdup_printf("PMEVCNTR%d", i); | ||
407 | + char *pmevcntr_el0_name = g_strdup_printf("PMEVCNTR%d_EL0", i); | ||
408 | + char *pmevtyper_name = g_strdup_printf("PMEVTYPER%d", i); | ||
409 | + char *pmevtyper_el0_name = g_strdup_printf("PMEVTYPER%d_EL0", i); | ||
410 | + ARMCPRegInfo pmev_regs[] = { | ||
411 | + { .name = pmevcntr_name, .cp = 15, .crn = 15, | ||
412 | + .crm = 8 | (3 & (i >> 3)), .opc1 = 0, .opc2 = i & 7, | ||
413 | + .access = PL0_RW, .type = ARM_CP_IO | ARM_CP_ALIAS, | ||
414 | + .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, | ||
415 | + .accessfn = pmreg_access }, | ||
416 | + { .name = pmevcntr_el0_name, .state = ARM_CP_STATE_AA64, | ||
417 | + .opc0 = 3, .opc1 = 3, .crn = 15, .crm = 8 | (3 & (i >> 3)), | ||
418 | + .opc2 = i & 7, .access = PL0_RW, .accessfn = pmreg_access, | ||
419 | + .type = ARM_CP_IO, | ||
420 | + .readfn = pmevcntr_readfn, .writefn = pmevcntr_writefn, | ||
421 | + .raw_readfn = pmevcntr_rawread, | ||
422 | + .raw_writefn = pmevcntr_rawwrite }, | ||
423 | + { .name = pmevtyper_name, .cp = 15, .crn = 15, | ||
424 | + .crm = 12 | (3 & (i >> 3)), .opc1 = 0, .opc2 = i & 7, | ||
425 | + .access = PL0_RW, .type = ARM_CP_IO | ARM_CP_ALIAS, | ||
426 | + .readfn = pmevtyper_readfn, .writefn = pmevtyper_writefn, | ||
427 | + .accessfn = pmreg_access }, | ||
428 | + { .name = pmevtyper_el0_name, .state = ARM_CP_STATE_AA64, | ||
429 | + .opc0 = 3, .opc1 = 3, .crn = 15, .crm = 12 | (3 & (i >> 3)), | ||
430 | + .opc2 = i & 7, .access = PL0_RW, .accessfn = pmreg_access, | ||
431 | + .type = ARM_CP_IO, | ||
432 | + .readfn = pmevtyper_readfn, .writefn = pmevtyper_writefn, | ||
433 | + .raw_writefn = pmevtyper_rawwrite }, | ||
434 | + REGINFO_SENTINEL | ||
435 | + }; | ||
436 | + define_arm_cp_regs(cpu, pmev_regs); | ||
437 | + g_free(pmevcntr_name); | ||
438 | + g_free(pmevcntr_el0_name); | ||
439 | + g_free(pmevtyper_name); | ||
440 | + g_free(pmevtyper_el0_name); | ||
441 | + } | ||
442 | #endif | ||
443 | ARMCPRegInfo clidr = { | ||
444 | .name = "CLIDR", .state = ARM_CP_STATE_BOTH, | ||
58 | -- | 445 | -- |
59 | 2.20.1 | 446 | 2.20.1 |
60 | 447 | ||
61 | 448 | diff view generated by jsdifflib |
1 | Convert the Neon narrowing shifts where op==8 to decodetree: | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | * VSHRN | ||
3 | * VRSHRN | ||
4 | * VQSHRUN | ||
5 | * VQRSHRUN | ||
6 | 2 | ||
3 | The instruction event is only enabled when icount is used, cycles are | ||
4 | always supported. Always defining get_cycle_count (but altering its | ||
5 | behavior depending on CONFIG_USER_ONLY) allows us to remove some | ||
6 | CONFIG_USER_ONLY #defines throughout the rest of the code. | ||
7 | |||
8 | Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org> | ||
9 | Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com> | ||
10 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
11 | Message-id: 20181211151945.29137-12-aaron@os.amperecomputing.com | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20200522145520.6778-6-peter.maydell@linaro.org | ||
10 | --- | 13 | --- |
11 | target/arm/neon-dp.decode | 27 ++++++ | 14 | target/arm/helper.c | 90 ++++++++++++++++++++++----------------------- |
12 | target/arm/translate-neon.inc.c | 167 ++++++++++++++++++++++++++++++++ | 15 | 1 file changed, 44 insertions(+), 46 deletions(-) |
13 | target/arm/translate.c | 1 + | ||
14 | 3 files changed, 195 insertions(+) | ||
15 | 16 | ||
16 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | 17 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
17 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/neon-dp.decode | 19 | --- a/target/arm/helper.c |
19 | +++ b/target/arm/neon-dp.decode | 20 | +++ b/target/arm/helper.c |
20 | @@ -XXX,XX +XXX,XX @@ VMINNM_fp_3s 1111 001 1 0 . 1 . .... .... 1111 ... 1 .... @3same_fp | 21 | @@ -XXX,XX +XXX,XX @@ |
21 | @2reg_shl_b .... ... . . . 001 shift:3 .... .... 0 q:1 . . .... \ | 22 | #include "arm_ldst.h" |
22 | &2reg_shift vm=%vm_dp vd=%vd_dp size=0 | 23 | #include <zlib.h> /* For crc32 */ |
23 | 24 | #include "exec/semihost.h" | |
24 | +# Narrowing right shifts: here the Q bit is part of the opcode decode | 25 | +#include "sysemu/cpus.h" |
25 | +@2reg_shrn_d .... ... . . . 1 ..... .... .... 0 . . . .... \ | 26 | #include "sysemu/kvm.h" |
26 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=3 q=0 \ | 27 | #include "fpu/softfloat.h" |
27 | + shift=%neon_rshift_i5 | 28 | #include "qemu/range.h" |
28 | +@2reg_shrn_s .... ... . . . 01 .... .... .... 0 . . . .... \ | 29 | @@ -XXX,XX +XXX,XX @@ typedef struct pm_event { |
29 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=2 q=0 \ | 30 | uint64_t (*get_count)(CPUARMState *); |
30 | + shift=%neon_rshift_i4 | 31 | } pm_event; |
31 | +@2reg_shrn_h .... ... . . . 001 ... .... .... 0 . . . .... \ | 32 | |
32 | + &2reg_shift vm=%vm_dp vd=%vd_dp size=1 q=0 \ | 33 | +static bool event_always_supported(CPUARMState *env) |
33 | + shift=%neon_rshift_i3 | ||
34 | + | ||
35 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_d | ||
36 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_s | ||
37 | VSHR_S_2sh 1111 001 0 1 . ...... .... 0000 . . . 1 .... @2reg_shr_h | ||
38 | @@ -XXX,XX +XXX,XX @@ VQSHL_U_64_2sh 1111 001 1 1 . ...... .... 0111 . . . 1 .... @2reg_shl_d | ||
39 | VQSHL_U_2sh 1111 001 1 1 . ...... .... 0111 . . . 1 .... @2reg_shl_s | ||
40 | VQSHL_U_2sh 1111 001 1 1 . ...... .... 0111 . . . 1 .... @2reg_shl_h | ||
41 | VQSHL_U_2sh 1111 001 1 1 . ...... .... 0111 . . . 1 .... @2reg_shl_b | ||
42 | + | ||
43 | +VSHRN_64_2sh 1111 001 0 1 . ...... .... 1000 . 0 . 1 .... @2reg_shrn_d | ||
44 | +VSHRN_32_2sh 1111 001 0 1 . ...... .... 1000 . 0 . 1 .... @2reg_shrn_s | ||
45 | +VSHRN_16_2sh 1111 001 0 1 . ...... .... 1000 . 0 . 1 .... @2reg_shrn_h | ||
46 | + | ||
47 | +VRSHRN_64_2sh 1111 001 0 1 . ...... .... 1000 . 1 . 1 .... @2reg_shrn_d | ||
48 | +VRSHRN_32_2sh 1111 001 0 1 . ...... .... 1000 . 1 . 1 .... @2reg_shrn_s | ||
49 | +VRSHRN_16_2sh 1111 001 0 1 . ...... .... 1000 . 1 . 1 .... @2reg_shrn_h | ||
50 | + | ||
51 | +VQSHRUN_64_2sh 1111 001 1 1 . ...... .... 1000 . 0 . 1 .... @2reg_shrn_d | ||
52 | +VQSHRUN_32_2sh 1111 001 1 1 . ...... .... 1000 . 0 . 1 .... @2reg_shrn_s | ||
53 | +VQSHRUN_16_2sh 1111 001 1 1 . ...... .... 1000 . 0 . 1 .... @2reg_shrn_h | ||
54 | + | ||
55 | +VQRSHRUN_64_2sh 1111 001 1 1 . ...... .... 1000 . 1 . 1 .... @2reg_shrn_d | ||
56 | +VQRSHRUN_32_2sh 1111 001 1 1 . ...... .... 1000 . 1 . 1 .... @2reg_shrn_s | ||
57 | +VQRSHRUN_16_2sh 1111 001 1 1 . ...... .... 1000 . 1 . 1 .... @2reg_shrn_h | ||
58 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | ||
59 | index XXXXXXX..XXXXXXX 100644 | ||
60 | --- a/target/arm/translate-neon.inc.c | ||
61 | +++ b/target/arm/translate-neon.inc.c | ||
62 | @@ -XXX,XX +XXX,XX @@ static bool do_2shift_env_32(DisasContext *s, arg_2reg_shift *a, | ||
63 | DO_2SHIFT_ENV(VQSHLU, qshlu_s) | ||
64 | DO_2SHIFT_ENV(VQSHL_U, qshl_u) | ||
65 | DO_2SHIFT_ENV(VQSHL_S, qshl_s) | ||
66 | + | ||
67 | +static bool do_2shift_narrow_64(DisasContext *s, arg_2reg_shift *a, | ||
68 | + NeonGenTwo64OpFn *shiftfn, | ||
69 | + NeonGenNarrowEnvFn *narrowfn) | ||
70 | +{ | 34 | +{ |
71 | + /* 2-reg-and-shift narrowing-shift operations, size == 3 case */ | ||
72 | + TCGv_i64 constimm, rm1, rm2; | ||
73 | + TCGv_i32 rd; | ||
74 | + | ||
75 | + if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | ||
76 | + return false; | ||
77 | + } | ||
78 | + | ||
79 | + /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
80 | + if (!dc_isar_feature(aa32_simd_r32, s) && | ||
81 | + ((a->vd | a->vm) & 0x10)) { | ||
82 | + return false; | ||
83 | + } | ||
84 | + | ||
85 | + if (a->vm & 1) { | ||
86 | + return false; | ||
87 | + } | ||
88 | + | ||
89 | + if (!vfp_access_check(s)) { | ||
90 | + return true; | ||
91 | + } | ||
92 | + | ||
93 | + /* | ||
94 | + * This is always a right shift, and the shiftfn is always a | ||
95 | + * left-shift helper, which thus needs the negated shift count. | ||
96 | + */ | ||
97 | + constimm = tcg_const_i64(-a->shift); | ||
98 | + rm1 = tcg_temp_new_i64(); | ||
99 | + rm2 = tcg_temp_new_i64(); | ||
100 | + | ||
101 | + /* Load both inputs first to avoid potential overwrite if rm == rd */ | ||
102 | + neon_load_reg64(rm1, a->vm); | ||
103 | + neon_load_reg64(rm2, a->vm + 1); | ||
104 | + | ||
105 | + shiftfn(rm1, rm1, constimm); | ||
106 | + rd = tcg_temp_new_i32(); | ||
107 | + narrowfn(rd, cpu_env, rm1); | ||
108 | + neon_store_reg(a->vd, 0, rd); | ||
109 | + | ||
110 | + shiftfn(rm2, rm2, constimm); | ||
111 | + rd = tcg_temp_new_i32(); | ||
112 | + narrowfn(rd, cpu_env, rm2); | ||
113 | + neon_store_reg(a->vd, 1, rd); | ||
114 | + | ||
115 | + tcg_temp_free_i64(rm1); | ||
116 | + tcg_temp_free_i64(rm2); | ||
117 | + tcg_temp_free_i64(constimm); | ||
118 | + | ||
119 | + return true; | 35 | + return true; |
120 | +} | 36 | +} |
121 | + | 37 | + |
122 | +static bool do_2shift_narrow_32(DisasContext *s, arg_2reg_shift *a, | 38 | +/* |
123 | + NeonGenTwoOpFn *shiftfn, | 39 | + * Return the underlying cycle count for the PMU cycle counters. If we're in |
124 | + NeonGenNarrowEnvFn *narrowfn) | 40 | + * usermode, simply return 0. |
41 | + */ | ||
42 | +static uint64_t cycles_get_count(CPUARMState *env) | ||
125 | +{ | 43 | +{ |
126 | + /* 2-reg-and-shift narrowing-shift operations, size < 3 case */ | 44 | +#ifndef CONFIG_USER_ONLY |
127 | + TCGv_i32 constimm, rm1, rm2, rm3, rm4; | 45 | + return muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), |
128 | + TCGv_i64 rtmp; | 46 | + ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); |
129 | + uint32_t imm; | 47 | +#else |
130 | + | 48 | + return cpu_get_host_ticks(); |
131 | + if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | 49 | +#endif |
132 | + return false; | ||
133 | + } | ||
134 | + | ||
135 | + /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
136 | + if (!dc_isar_feature(aa32_simd_r32, s) && | ||
137 | + ((a->vd | a->vm) & 0x10)) { | ||
138 | + return false; | ||
139 | + } | ||
140 | + | ||
141 | + if (a->vm & 1) { | ||
142 | + return false; | ||
143 | + } | ||
144 | + | ||
145 | + if (!vfp_access_check(s)) { | ||
146 | + return true; | ||
147 | + } | ||
148 | + | ||
149 | + /* | ||
150 | + * This is always a right shift, and the shiftfn is always a | ||
151 | + * left-shift helper, which thus needs the negated shift count | ||
152 | + * duplicated into each lane of the immediate value. | ||
153 | + */ | ||
154 | + if (a->size == 1) { | ||
155 | + imm = (uint16_t)(-a->shift); | ||
156 | + imm |= imm << 16; | ||
157 | + } else { | ||
158 | + /* size == 2 */ | ||
159 | + imm = -a->shift; | ||
160 | + } | ||
161 | + constimm = tcg_const_i32(imm); | ||
162 | + | ||
163 | + /* Load all inputs first to avoid potential overwrite */ | ||
164 | + rm1 = neon_load_reg(a->vm, 0); | ||
165 | + rm2 = neon_load_reg(a->vm, 1); | ||
166 | + rm3 = neon_load_reg(a->vm + 1, 0); | ||
167 | + rm4 = neon_load_reg(a->vm + 1, 1); | ||
168 | + rtmp = tcg_temp_new_i64(); | ||
169 | + | ||
170 | + shiftfn(rm1, rm1, constimm); | ||
171 | + shiftfn(rm2, rm2, constimm); | ||
172 | + | ||
173 | + tcg_gen_concat_i32_i64(rtmp, rm1, rm2); | ||
174 | + tcg_temp_free_i32(rm2); | ||
175 | + | ||
176 | + narrowfn(rm1, cpu_env, rtmp); | ||
177 | + neon_store_reg(a->vd, 0, rm1); | ||
178 | + | ||
179 | + shiftfn(rm3, rm3, constimm); | ||
180 | + shiftfn(rm4, rm4, constimm); | ||
181 | + tcg_temp_free_i32(constimm); | ||
182 | + | ||
183 | + tcg_gen_concat_i32_i64(rtmp, rm3, rm4); | ||
184 | + tcg_temp_free_i32(rm4); | ||
185 | + | ||
186 | + narrowfn(rm3, cpu_env, rtmp); | ||
187 | + tcg_temp_free_i64(rtmp); | ||
188 | + neon_store_reg(a->vd, 1, rm3); | ||
189 | + return true; | ||
190 | +} | 50 | +} |
191 | + | 51 | + |
192 | +#define DO_2SN_64(INSN, FUNC, NARROWFUNC) \ | 52 | +#ifndef CONFIG_USER_ONLY |
193 | + static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \ | 53 | +static bool instructions_supported(CPUARMState *env) |
194 | + { \ | ||
195 | + return do_2shift_narrow_64(s, a, FUNC, NARROWFUNC); \ | ||
196 | + } | ||
197 | +#define DO_2SN_32(INSN, FUNC, NARROWFUNC) \ | ||
198 | + static bool trans_##INSN##_2sh(DisasContext *s, arg_2reg_shift *a) \ | ||
199 | + { \ | ||
200 | + return do_2shift_narrow_32(s, a, FUNC, NARROWFUNC); \ | ||
201 | + } | ||
202 | + | ||
203 | +static void gen_neon_narrow_u32(TCGv_i32 dest, TCGv_ptr env, TCGv_i64 src) | ||
204 | +{ | 54 | +{ |
205 | + tcg_gen_extrl_i64_i32(dest, src); | 55 | + return use_icount == 1 /* Precise instruction counting */; |
206 | +} | 56 | +} |
207 | + | 57 | + |
208 | +static void gen_neon_narrow_u16(TCGv_i32 dest, TCGv_ptr env, TCGv_i64 src) | 58 | +static uint64_t instructions_get_count(CPUARMState *env) |
209 | +{ | 59 | +{ |
210 | + gen_helper_neon_narrow_u16(dest, src); | 60 | + return (uint64_t)cpu_get_icount_raw(); |
211 | +} | 61 | +} |
62 | +#endif | ||
212 | + | 63 | + |
213 | +static void gen_neon_narrow_u8(TCGv_i32 dest, TCGv_ptr env, TCGv_i64 src) | 64 | static const pm_event pm_events[] = { |
214 | +{ | 65 | +#ifndef CONFIG_USER_ONLY |
215 | + gen_helper_neon_narrow_u8(dest, src); | 66 | + { .number = 0x008, /* INST_RETIRED, Instruction architecturally executed */ |
216 | +} | 67 | + .supported = instructions_supported, |
217 | + | 68 | + .get_count = instructions_get_count, |
218 | +DO_2SN_64(VSHRN_64, gen_ushl_i64, gen_neon_narrow_u32) | 69 | + }, |
219 | +DO_2SN_32(VSHRN_32, gen_ushl_i32, gen_neon_narrow_u16) | 70 | + { .number = 0x011, /* CPU_CYCLES, Cycle */ |
220 | +DO_2SN_32(VSHRN_16, gen_helper_neon_shl_u16, gen_neon_narrow_u8) | 71 | + .supported = event_always_supported, |
221 | + | 72 | + .get_count = cycles_get_count, |
222 | +DO_2SN_64(VRSHRN_64, gen_helper_neon_rshl_u64, gen_neon_narrow_u32) | 73 | + } |
223 | +DO_2SN_32(VRSHRN_32, gen_helper_neon_rshl_u32, gen_neon_narrow_u16) | 74 | +#endif |
224 | +DO_2SN_32(VRSHRN_16, gen_helper_neon_rshl_u16, gen_neon_narrow_u8) | 75 | }; |
225 | + | 76 | |
226 | +DO_2SN_64(VQSHRUN_64, gen_sshl_i64, gen_helper_neon_unarrow_sat32) | 77 | /* |
227 | +DO_2SN_32(VQSHRUN_32, gen_sshl_i32, gen_helper_neon_unarrow_sat16) | 78 | @@ -XXX,XX +XXX,XX @@ static const pm_event pm_events[] = { |
228 | +DO_2SN_32(VQSHRUN_16, gen_helper_neon_shl_s16, gen_helper_neon_unarrow_sat8) | 79 | * should first be updated to something sparse instead of the current |
229 | + | 80 | * supported_event_map[] array. |
230 | +DO_2SN_64(VQRSHRUN_64, gen_helper_neon_rshl_s64, gen_helper_neon_unarrow_sat32) | 81 | */ |
231 | +DO_2SN_32(VQRSHRUN_32, gen_helper_neon_rshl_s32, gen_helper_neon_unarrow_sat16) | 82 | -#define MAX_EVENT_ID 0x0 |
232 | +DO_2SN_32(VQRSHRUN_16, gen_helper_neon_rshl_s16, gen_helper_neon_unarrow_sat8) | 83 | +#define MAX_EVENT_ID 0x11 |
233 | diff --git a/target/arm/translate.c b/target/arm/translate.c | 84 | #define UNSUPPORTED_EVENT UINT16_MAX |
234 | index XXXXXXX..XXXXXXX 100644 | 85 | static uint16_t supported_event_map[MAX_EVENT_ID + 1]; |
235 | --- a/target/arm/translate.c | 86 | |
236 | +++ b/target/arm/translate.c | 87 | @@ -XXX,XX +XXX,XX @@ static CPAccessResult pmreg_access_swinc(CPUARMState *env, |
237 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | 88 | return pmreg_access(env, ri, isread); |
238 | case 5: /* VSHL, VSLI */ | 89 | } |
239 | case 6: /* VQSHLU */ | 90 | |
240 | case 7: /* VQSHL */ | 91 | -#ifndef CONFIG_USER_ONLY |
241 | + case 8: /* VSHRN, VRSHRN, VQSHRUN, VQRSHRUN */ | 92 | - |
242 | return 1; /* handled by decodetree */ | 93 | static CPAccessResult pmreg_access_selr(CPUARMState *env, |
243 | default: | 94 | const ARMCPRegInfo *ri, |
244 | break; | 95 | bool isread) |
96 | @@ -XXX,XX +XXX,XX @@ static bool pmu_counter_enabled(CPUARMState *env, uint8_t counter) | ||
97 | */ | ||
98 | void pmccntr_op_start(CPUARMState *env) | ||
99 | { | ||
100 | - uint64_t cycles = 0; | ||
101 | - cycles = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL), | ||
102 | - ARM_CPU_FREQ, NANOSECONDS_PER_SECOND); | ||
103 | + uint64_t cycles = cycles_get_count(env); | ||
104 | |||
105 | if (pmu_counter_enabled(env, 31)) { | ||
106 | uint64_t eff_cycles = cycles; | ||
107 | @@ -XXX,XX +XXX,XX @@ static void pmccntr_write32(CPUARMState *env, const ARMCPRegInfo *ri, | ||
108 | pmccntr_write(env, ri, deposit64(cur_val, 0, 32, value)); | ||
109 | } | ||
110 | |||
111 | -#else /* CONFIG_USER_ONLY */ | ||
112 | - | ||
113 | -void pmccntr_op_start(CPUARMState *env) | ||
114 | -{ | ||
115 | -} | ||
116 | - | ||
117 | -void pmccntr_op_finish(CPUARMState *env) | ||
118 | -{ | ||
119 | -} | ||
120 | - | ||
121 | -void pmevcntr_op_start(CPUARMState *env, uint8_t i) | ||
122 | -{ | ||
123 | -} | ||
124 | - | ||
125 | -void pmevcntr_op_finish(CPUARMState *env, uint8_t i) | ||
126 | -{ | ||
127 | -} | ||
128 | - | ||
129 | -void pmu_op_start(CPUARMState *env) | ||
130 | -{ | ||
131 | -} | ||
132 | - | ||
133 | -void pmu_op_finish(CPUARMState *env) | ||
134 | -{ | ||
135 | -} | ||
136 | - | ||
137 | -void pmu_pre_el_change(ARMCPU *cpu, void *ignored) | ||
138 | -{ | ||
139 | -} | ||
140 | - | ||
141 | -void pmu_post_el_change(ARMCPU *cpu, void *ignored) | ||
142 | -{ | ||
143 | -} | ||
144 | - | ||
145 | -#endif | ||
146 | - | ||
147 | static void pmccfiltr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
148 | uint64_t value) | ||
149 | { | ||
150 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = { | ||
151 | /* Unimplemented so WI. */ | ||
152 | { .name = "PMSWINC", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 4, | ||
153 | .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NOP }, | ||
154 | -#ifndef CONFIG_USER_ONLY | ||
155 | { .name = "PMSELR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 5, | ||
156 | .access = PL0_RW, .type = ARM_CP_ALIAS, | ||
157 | .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmselr), | ||
158 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = { | ||
159 | .fieldoffset = offsetof(CPUARMState, cp15.c15_ccnt), | ||
160 | .readfn = pmccntr_read, .writefn = pmccntr_write, | ||
161 | .raw_readfn = raw_read, .raw_writefn = raw_write, }, | ||
162 | -#endif | ||
163 | { .name = "PMCCFILTR", .cp = 15, .opc1 = 0, .crn = 14, .crm = 15, .opc2 = 7, | ||
164 | .writefn = pmccfiltr_write_a32, .readfn = pmccfiltr_read_a32, | ||
165 | .access = PL0_RW, .accessfn = pmreg_access, | ||
166 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
167 | * count register. | ||
168 | */ | ||
169 | unsigned int i, pmcrn = 0; | ||
170 | -#ifndef CONFIG_USER_ONLY | ||
171 | ARMCPRegInfo pmcr = { | ||
172 | .name = "PMCR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 0, | ||
173 | .access = PL0_RW, | ||
174 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
175 | g_free(pmevtyper_name); | ||
176 | g_free(pmevtyper_el0_name); | ||
177 | } | ||
178 | -#endif | ||
179 | ARMCPRegInfo clidr = { | ||
180 | .name = "CLIDR", .state = ARM_CP_STATE_BOTH, | ||
181 | .opc0 = 3, .crn = 0, .crm = 0, .opc1 = 1, .opc2 = 1, | ||
245 | -- | 182 | -- |
246 | 2.20.1 | 183 | 2.20.1 |
247 | 184 | ||
248 | 185 | diff view generated by jsdifflib |
1 | From: Eden Mikitas <e.mikitas@gmail.com> | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | The while statement in question only checked if tx_burst is not 0. | 3 | This both advertises that we support four counters and enables them |
4 | tx_burst is a signed int, which is assigned the value put by the | 4 | because the pmu_num_counters() reads this value from PMCR. |
5 | guest driver in ECSPI_CONREG. The burst length can be anywhere | ||
6 | between 1 and 4096, and since tx_burst is always decremented by 8 | ||
7 | it could possibly underflow, causing an infinite loop. | ||
8 | 5 | ||
9 | Signed-off-by: Eden Mikitas <e.mikitas@gmail.com> | 6 | Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org> |
10 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | 7 | Signed-off-by: Aaron Lindsay <aaron@os.amperecomputing.com> |
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Message-id: 20181211151945.29137-13-aaron@os.amperecomputing.com | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
12 | --- | 11 | --- |
13 | hw/ssi/imx_spi.c | 2 +- | 12 | target/arm/helper.c | 10 +++++----- |
14 | 1 file changed, 1 insertion(+), 1 deletion(-) | 13 | 1 file changed, 5 insertions(+), 5 deletions(-) |
15 | 14 | ||
16 | diff --git a/hw/ssi/imx_spi.c b/hw/ssi/imx_spi.c | 15 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
17 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/ssi/imx_spi.c | 17 | --- a/target/arm/helper.c |
19 | +++ b/hw/ssi/imx_spi.c | 18 | +++ b/target/arm/helper.c |
20 | @@ -XXX,XX +XXX,XX @@ static void imx_spi_flush_txfifo(IMXSPIState *s) | 19 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = { |
21 | 20 | .access = PL1_W, .type = ARM_CP_NOP }, | |
22 | rx = 0; | 21 | /* Performance monitors are implementation defined in v7, |
23 | 22 | * but with an ARM recommended set of registers, which we | |
24 | - while (tx_burst) { | 23 | - * follow (although we don't actually implement any counters) |
25 | + while (tx_burst > 0) { | 24 | + * follow. |
26 | uint8_t byte = tx & 0xff; | 25 | * |
27 | 26 | * Performance registers fall into three categories: | |
28 | DPRINTF("writing 0x%02x\n", (uint32_t)byte); | 27 | * (a) always UNDEF in PL0, RW in PL1 (PMINTENSET, PMINTENCLR) |
28 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
29 | } | ||
30 | if (arm_feature(env, ARM_FEATURE_V7)) { | ||
31 | /* v7 performance monitor control register: same implementor | ||
32 | - * field as main ID register, and we implement only the cycle | ||
33 | - * count register. | ||
34 | + * field as main ID register, and we implement four counters in | ||
35 | + * addition to the cycle count register. | ||
36 | */ | ||
37 | - unsigned int i, pmcrn = 0; | ||
38 | + unsigned int i, pmcrn = 4; | ||
39 | ARMCPRegInfo pmcr = { | ||
40 | .name = "PMCR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 0, | ||
41 | .access = PL0_RW, | ||
42 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
43 | .access = PL0_RW, .accessfn = pmreg_access, | ||
44 | .type = ARM_CP_IO, | ||
45 | .fieldoffset = offsetof(CPUARMState, cp15.c9_pmcr), | ||
46 | - .resetvalue = cpu->midr & 0xff000000, | ||
47 | + .resetvalue = (cpu->midr & 0xff000000) | (pmcrn << PMCRN_SHIFT), | ||
48 | .writefn = pmcr_write, .raw_writefn = raw_write, | ||
49 | }; | ||
50 | define_one_arm_cp_reg(cpu, &pmcr); | ||
29 | -- | 51 | -- |
30 | 2.20.1 | 52 | 2.20.1 |
31 | 53 | ||
32 | 54 | diff view generated by jsdifflib |
1 | Convert the insns in the one-register-and-immediate group to decodetree. | 1 | From: Aaron Lindsay <aaron@os.amperecomputing.com> |
---|---|---|---|
2 | 2 | ||
3 | In the new decode, our asimd_imm_const() function returns a 64-bit value | 3 | Signed-off-by: Aaron Lindsay <alindsay@codeaurora.org> |
4 | rather than a 32-bit one, which means we don't need to treat cmode=14 op=1 | 4 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
5 | as a special case in the decoder (it is the only encoding where the two | 5 | Message-id: 20181211151945.29137-14-aaron@os.amperecomputing.com |
6 | halves of the 64-bit value are different). | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | ||
8 | target/arm/helper.c | 39 +++++++++++++++++++++++++++++++++++++-- | ||
9 | 1 file changed, 37 insertions(+), 2 deletions(-) | ||
7 | 10 | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20200522145520.6778-10-peter.maydell@linaro.org | ||
11 | --- | ||
12 | target/arm/neon-dp.decode | 22 ++++++ | ||
13 | target/arm/translate-neon.inc.c | 118 ++++++++++++++++++++++++++++++++ | ||
14 | target/arm/translate.c | 101 +-------------------------- | ||
15 | 3 files changed, 142 insertions(+), 99 deletions(-) | ||
16 | |||
17 | diff --git a/target/arm/neon-dp.decode b/target/arm/neon-dp.decode | ||
18 | index XXXXXXX..XXXXXXX 100644 | 12 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/arm/neon-dp.decode | 13 | --- a/target/arm/helper.c |
20 | +++ b/target/arm/neon-dp.decode | 14 | +++ b/target/arm/helper.c |
21 | @@ -XXX,XX +XXX,XX @@ VCVT_SF_2sh 1111 001 0 1 . ...... .... 1110 0 . . 1 .... @2reg_vcvt | 15 | @@ -XXX,XX +XXX,XX @@ static bool event_always_supported(CPUARMState *env) |
22 | VCVT_UF_2sh 1111 001 1 1 . ...... .... 1110 0 . . 1 .... @2reg_vcvt | 16 | return true; |
23 | VCVT_FS_2sh 1111 001 0 1 . ...... .... 1111 0 . . 1 .... @2reg_vcvt | 17 | } |
24 | VCVT_FU_2sh 1111 001 1 1 . ...... .... 1111 0 . . 1 .... @2reg_vcvt | 18 | |
25 | + | 19 | +static uint64_t swinc_get_count(CPUARMState *env) |
26 | +###################################################################### | ||
27 | +# 1-reg-and-modified-immediate grouping: | ||
28 | +# 1111 001 i 1 D 000 imm:3 Vd:4 cmode:4 0 Q op 1 Vm:4 | ||
29 | +###################################################################### | ||
30 | + | ||
31 | +&1reg_imm vd q imm cmode op | ||
32 | + | ||
33 | +%asimd_imm_value 24:1 16:3 0:4 | ||
34 | + | ||
35 | +@1reg_imm .... ... . . . ... ... .... .... . q:1 . . .... \ | ||
36 | + &1reg_imm imm=%asimd_imm_value vd=%vd_dp | ||
37 | + | ||
38 | +# The cmode/op bits here decode VORR/VBIC/VMOV/VMNV, but | ||
39 | +# not in a way we can conveniently represent in decodetree without | ||
40 | +# a lot of repetition: | ||
41 | +# VORR: op=0, (cmode & 1) && cmode < 12 | ||
42 | +# VBIC: op=1, (cmode & 1) && cmode < 12 | ||
43 | +# VMOV: everything else | ||
44 | +# So we have a single decode line and check the cmode/op in the | ||
45 | +# trans function. | ||
46 | +Vimm_1r 1111 001 . 1 . 000 ... .... cmode:4 0 . op:1 1 .... @1reg_imm | ||
47 | diff --git a/target/arm/translate-neon.inc.c b/target/arm/translate-neon.inc.c | ||
48 | index XXXXXXX..XXXXXXX 100644 | ||
49 | --- a/target/arm/translate-neon.inc.c | ||
50 | +++ b/target/arm/translate-neon.inc.c | ||
51 | @@ -XXX,XX +XXX,XX @@ DO_FP_2SH(VCVT_SF, gen_helper_vfp_sltos) | ||
52 | DO_FP_2SH(VCVT_UF, gen_helper_vfp_ultos) | ||
53 | DO_FP_2SH(VCVT_FS, gen_helper_vfp_tosls_round_to_zero) | ||
54 | DO_FP_2SH(VCVT_FU, gen_helper_vfp_touls_round_to_zero) | ||
55 | + | ||
56 | +static uint64_t asimd_imm_const(uint32_t imm, int cmode, int op) | ||
57 | +{ | 20 | +{ |
58 | + /* | 21 | + /* |
59 | + * Expand the encoded constant. | 22 | + * SW_INCR events are written directly to the pmevcntr's by writes to |
60 | + * Note that cmode = 2,3,4,5,6,7,10,11,12,13 imm=0 is UNPREDICTABLE. | 23 | + * PMSWINC, so there is no underlying count maintained by the PMU itself |
61 | + * We choose to not special-case this and will behave as if a | ||
62 | + * valid constant encoding of 0 had been given. | ||
63 | + * cmode = 15 op = 1 must UNDEF; we assume decode has handled that. | ||
64 | + */ | 24 | + */ |
65 | + switch (cmode) { | 25 | + return 0; |
66 | + case 0: case 1: | ||
67 | + /* no-op */ | ||
68 | + break; | ||
69 | + case 2: case 3: | ||
70 | + imm <<= 8; | ||
71 | + break; | ||
72 | + case 4: case 5: | ||
73 | + imm <<= 16; | ||
74 | + break; | ||
75 | + case 6: case 7: | ||
76 | + imm <<= 24; | ||
77 | + break; | ||
78 | + case 8: case 9: | ||
79 | + imm |= imm << 16; | ||
80 | + break; | ||
81 | + case 10: case 11: | ||
82 | + imm = (imm << 8) | (imm << 24); | ||
83 | + break; | ||
84 | + case 12: | ||
85 | + imm = (imm << 8) | 0xff; | ||
86 | + break; | ||
87 | + case 13: | ||
88 | + imm = (imm << 16) | 0xffff; | ||
89 | + break; | ||
90 | + case 14: | ||
91 | + if (op) { | ||
92 | + /* | ||
93 | + * This is the only case where the top and bottom 32 bits | ||
94 | + * of the encoded constant differ. | ||
95 | + */ | ||
96 | + uint64_t imm64 = 0; | ||
97 | + int n; | ||
98 | + | ||
99 | + for (n = 0; n < 8; n++) { | ||
100 | + if (imm & (1 << n)) { | ||
101 | + imm64 |= (0xffULL << (n * 8)); | ||
102 | + } | ||
103 | + } | ||
104 | + return imm64; | ||
105 | + } | ||
106 | + imm |= (imm << 8) | (imm << 16) | (imm << 24); | ||
107 | + break; | ||
108 | + case 15: | ||
109 | + imm = ((imm & 0x80) << 24) | ((imm & 0x3f) << 19) | ||
110 | + | ((imm & 0x40) ? (0x1f << 25) : (1 << 30)); | ||
111 | + break; | ||
112 | + } | ||
113 | + if (op) { | ||
114 | + imm = ~imm; | ||
115 | + } | ||
116 | + return dup_const(MO_32, imm); | ||
117 | +} | 26 | +} |
118 | + | 27 | + |
119 | +static bool do_1reg_imm(DisasContext *s, arg_1reg_imm *a, | 28 | /* |
120 | + GVecGen2iFn *fn) | 29 | * Return the underlying cycle count for the PMU cycle counters. If we're in |
30 | * usermode, simply return 0. | ||
31 | @@ -XXX,XX +XXX,XX @@ static uint64_t instructions_get_count(CPUARMState *env) | ||
32 | #endif | ||
33 | |||
34 | static const pm_event pm_events[] = { | ||
35 | + { .number = 0x000, /* SW_INCR */ | ||
36 | + .supported = event_always_supported, | ||
37 | + .get_count = swinc_get_count, | ||
38 | + }, | ||
39 | #ifndef CONFIG_USER_ONLY | ||
40 | { .number = 0x008, /* INST_RETIRED, Instruction architecturally executed */ | ||
41 | .supported = instructions_supported, | ||
42 | @@ -XXX,XX +XXX,XX @@ static void pmcr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
43 | pmu_op_finish(env); | ||
44 | } | ||
45 | |||
46 | +static void pmswinc_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
47 | + uint64_t value) | ||
121 | +{ | 48 | +{ |
122 | + uint64_t imm; | 49 | + unsigned int i; |
123 | + int reg_ofs, vec_size; | 50 | + for (i = 0; i < pmu_num_counters(env); i++) { |
124 | + | 51 | + /* Increment a counter's count iff: */ |
125 | + if (!arm_dc_feature(s, ARM_FEATURE_NEON)) { | 52 | + if ((value & (1 << i)) && /* counter's bit is set */ |
126 | + return false; | 53 | + /* counter is enabled and not filtered */ |
54 | + pmu_counter_enabled(env, i) && | ||
55 | + /* counter is SW_INCR */ | ||
56 | + (env->cp15.c14_pmevtyper[i] & PMXEVTYPER_EVTCOUNT) == 0x0) { | ||
57 | + pmevcntr_op_start(env, i); | ||
58 | + env->cp15.c14_pmevcntr[i]++; | ||
59 | + pmevcntr_op_finish(env, i); | ||
60 | + } | ||
127 | + } | 61 | + } |
128 | + | ||
129 | + /* UNDEF accesses to D16-D31 if they don't exist. */ | ||
130 | + if (!dc_isar_feature(aa32_simd_r32, s) && (a->vd & 0x10)) { | ||
131 | + return false; | ||
132 | + } | ||
133 | + | ||
134 | + if (a->vd & a->q) { | ||
135 | + return false; | ||
136 | + } | ||
137 | + | ||
138 | + if (!vfp_access_check(s)) { | ||
139 | + return true; | ||
140 | + } | ||
141 | + | ||
142 | + reg_ofs = neon_reg_offset(a->vd, 0); | ||
143 | + vec_size = a->q ? 16 : 8; | ||
144 | + imm = asimd_imm_const(a->imm, a->cmode, a->op); | ||
145 | + | ||
146 | + fn(MO_64, reg_ofs, reg_ofs, imm, vec_size, vec_size); | ||
147 | + return true; | ||
148 | +} | 62 | +} |
149 | + | 63 | + |
150 | +static void gen_VMOV_1r(unsigned vece, uint32_t dofs, uint32_t aofs, | 64 | static uint64_t pmccntr_read(CPUARMState *env, const ARMCPRegInfo *ri) |
151 | + int64_t c, uint32_t oprsz, uint32_t maxsz) | 65 | { |
152 | +{ | 66 | uint64_t ret; |
153 | + tcg_gen_gvec_dup_imm(MO_64, dofs, oprsz, maxsz, c); | 67 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v7_cp_reginfo[] = { |
154 | +} | 68 | .fieldoffset = offsetof(CPUARMState, cp15.c9_pmovsr), |
155 | + | 69 | .writefn = pmovsr_write, |
156 | +static bool trans_Vimm_1r(DisasContext *s, arg_1reg_imm *a) | 70 | .raw_writefn = raw_write }, |
157 | +{ | 71 | - /* Unimplemented so WI. */ |
158 | + /* Handle decode of cmode/op here between VORR/VBIC/VMOV */ | 72 | { .name = "PMSWINC", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 4, |
159 | + GVecGen2iFn *fn; | 73 | - .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NOP }, |
160 | + | 74 | + .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NO_RAW, |
161 | + if ((a->cmode & 1) && a->cmode < 12) { | 75 | + .writefn = pmswinc_write }, |
162 | + /* for op=1, the imm will be inverted, so BIC becomes AND. */ | 76 | + { .name = "PMSWINC_EL0", .state = ARM_CP_STATE_AA64, |
163 | + fn = a->op ? tcg_gen_gvec_andi : tcg_gen_gvec_ori; | 77 | + .opc0 = 3, .opc1 = 3, .crn = 9, .crm = 12, .opc2 = 4, |
164 | + } else { | 78 | + .access = PL0_W, .accessfn = pmreg_access_swinc, .type = ARM_CP_NO_RAW, |
165 | + /* There is one unallocated cmode/op combination in this space */ | 79 | + .writefn = pmswinc_write }, |
166 | + if (a->cmode == 15 && a->op == 1) { | 80 | { .name = "PMSELR", .cp = 15, .crn = 9, .crm = 12, .opc1 = 0, .opc2 = 5, |
167 | + return false; | 81 | .access = PL0_RW, .type = ARM_CP_ALIAS, |
168 | + } | 82 | .fieldoffset = offsetoflow32(CPUARMState, cp15.c9_pmselr), |
169 | + fn = gen_VMOV_1r; | ||
170 | + } | ||
171 | + return do_1reg_imm(s, a, fn); | ||
172 | +} | ||
173 | diff --git a/target/arm/translate.c b/target/arm/translate.c | ||
174 | index XXXXXXX..XXXXXXX 100644 | ||
175 | --- a/target/arm/translate.c | ||
176 | +++ b/target/arm/translate.c | ||
177 | @@ -XXX,XX +XXX,XX @@ static int disas_neon_data_insn(DisasContext *s, uint32_t insn) | ||
178 | /* Three register same length: handled by decodetree */ | ||
179 | return 1; | ||
180 | } else if (insn & (1 << 4)) { | ||
181 | - if ((insn & 0x00380080) != 0) { | ||
182 | - /* Two registers and shift: handled by decodetree */ | ||
183 | - return 1; | ||
184 | - } else { /* (insn & 0x00380080) == 0 */ | ||
185 | - int invert, reg_ofs, vec_size; | ||
186 | - | ||
187 | - if (q && (rd & 1)) { | ||
188 | - return 1; | ||
189 | - } | ||
190 | - | ||
191 | - op = (insn >> 8) & 0xf; | ||
192 | - /* One register and immediate. */ | ||
193 | - imm = (u << 7) | ((insn >> 12) & 0x70) | (insn & 0xf); | ||
194 | - invert = (insn & (1 << 5)) != 0; | ||
195 | - /* Note that op = 2,3,4,5,6,7,10,11,12,13 imm=0 is UNPREDICTABLE. | ||
196 | - * We choose to not special-case this and will behave as if a | ||
197 | - * valid constant encoding of 0 had been given. | ||
198 | - */ | ||
199 | - switch (op) { | ||
200 | - case 0: case 1: | ||
201 | - /* no-op */ | ||
202 | - break; | ||
203 | - case 2: case 3: | ||
204 | - imm <<= 8; | ||
205 | - break; | ||
206 | - case 4: case 5: | ||
207 | - imm <<= 16; | ||
208 | - break; | ||
209 | - case 6: case 7: | ||
210 | - imm <<= 24; | ||
211 | - break; | ||
212 | - case 8: case 9: | ||
213 | - imm |= imm << 16; | ||
214 | - break; | ||
215 | - case 10: case 11: | ||
216 | - imm = (imm << 8) | (imm << 24); | ||
217 | - break; | ||
218 | - case 12: | ||
219 | - imm = (imm << 8) | 0xff; | ||
220 | - break; | ||
221 | - case 13: | ||
222 | - imm = (imm << 16) | 0xffff; | ||
223 | - break; | ||
224 | - case 14: | ||
225 | - imm |= (imm << 8) | (imm << 16) | (imm << 24); | ||
226 | - if (invert) { | ||
227 | - imm = ~imm; | ||
228 | - } | ||
229 | - break; | ||
230 | - case 15: | ||
231 | - if (invert) { | ||
232 | - return 1; | ||
233 | - } | ||
234 | - imm = ((imm & 0x80) << 24) | ((imm & 0x3f) << 19) | ||
235 | - | ((imm & 0x40) ? (0x1f << 25) : (1 << 30)); | ||
236 | - break; | ||
237 | - } | ||
238 | - if (invert) { | ||
239 | - imm = ~imm; | ||
240 | - } | ||
241 | - | ||
242 | - reg_ofs = neon_reg_offset(rd, 0); | ||
243 | - vec_size = q ? 16 : 8; | ||
244 | - | ||
245 | - if (op & 1 && op < 12) { | ||
246 | - if (invert) { | ||
247 | - /* The immediate value has already been inverted, | ||
248 | - * so BIC becomes AND. | ||
249 | - */ | ||
250 | - tcg_gen_gvec_andi(MO_32, reg_ofs, reg_ofs, imm, | ||
251 | - vec_size, vec_size); | ||
252 | - } else { | ||
253 | - tcg_gen_gvec_ori(MO_32, reg_ofs, reg_ofs, imm, | ||
254 | - vec_size, vec_size); | ||
255 | - } | ||
256 | - } else { | ||
257 | - /* VMOV, VMVN. */ | ||
258 | - if (op == 14 && invert) { | ||
259 | - TCGv_i64 t64 = tcg_temp_new_i64(); | ||
260 | - | ||
261 | - for (pass = 0; pass <= q; ++pass) { | ||
262 | - uint64_t val = 0; | ||
263 | - int n; | ||
264 | - | ||
265 | - for (n = 0; n < 8; n++) { | ||
266 | - if (imm & (1 << (n + pass * 8))) { | ||
267 | - val |= 0xffull << (n * 8); | ||
268 | - } | ||
269 | - } | ||
270 | - tcg_gen_movi_i64(t64, val); | ||
271 | - neon_store_reg64(t64, rd + pass); | ||
272 | - } | ||
273 | - tcg_temp_free_i64(t64); | ||
274 | - } else { | ||
275 | - tcg_gen_gvec_dup_imm(MO_32, reg_ofs, vec_size, | ||
276 | - vec_size, imm); | ||
277 | - } | ||
278 | - } | ||
279 | - } | ||
280 | + /* Two registers and shift or reg and imm: handled by decodetree */ | ||
281 | + return 1; | ||
282 | } else { /* (insn & 0x00800010 == 0x00800000) */ | ||
283 | if (size != 3) { | ||
284 | op = (insn >> 8) & 0xf; | ||
285 | -- | 83 | -- |
286 | 2.20.1 | 84 | 2.20.1 |
287 | 85 | ||
288 | 86 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Julia Suvorova <jusual@mail.ru> |
---|---|---|---|
2 | 2 | ||
3 | The ADC region size is 256B, split as: | 3 | Run qtest with a socket that connects QEMU chardev and test code. |
4 | - [0x00 - 0x4f] defined | ||
5 | - [0x50 - 0xff] reserved | ||
6 | 4 | ||
7 | All registers are 32-bit (thus when the datasheet mentions the | 5 | Signed-off-by: Julia Suvorova <jusual@mail.ru> |
8 | last defined register is 0x4c, it means its address range is | 6 | Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> |
9 | 0x4c .. 0x4f. | 7 | Message-id: 20190117161640.5496-2-jusual@mail.ru |
10 | |||
11 | This model implementation is also 32-bit. Set MemoryRegionOps | ||
12 | 'impl' fields. | ||
13 | |||
14 | See: | ||
15 | 'RM0033 Reference manual Rev 8', Table 10.13.18 "ADC register map". | ||
16 | |||
17 | Reported-by: Seth Kintigh <skintigh@gmail.com> | ||
18 | Reviewed-by: Alistair Francis <alistair.francis@wdc.com> | ||
19 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
20 | Message-id: 20200603055915.17678-1-f4bug@amsat.org | ||
21 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
22 | --- | 9 | --- |
23 | hw/adc/stm32f2xx_adc.c | 4 +++- | 10 | tests/libqtest.h | 11 +++++++++++ |
24 | 1 file changed, 3 insertions(+), 1 deletion(-) | 11 | tests/libqtest.c | 26 ++++++++++++++++++++++++++ |
12 | 2 files changed, 37 insertions(+) | ||
25 | 13 | ||
26 | diff --git a/hw/adc/stm32f2xx_adc.c b/hw/adc/stm32f2xx_adc.c | 14 | diff --git a/tests/libqtest.h b/tests/libqtest.h |
27 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
28 | --- a/hw/adc/stm32f2xx_adc.c | 16 | --- a/tests/libqtest.h |
29 | +++ b/hw/adc/stm32f2xx_adc.c | 17 | +++ b/tests/libqtest.h |
30 | @@ -XXX,XX +XXX,XX @@ static const MemoryRegionOps stm32f2xx_adc_ops = { | 18 | @@ -XXX,XX +XXX,XX @@ QTestState *qtest_init(const char *extra_args); |
31 | .read = stm32f2xx_adc_read, | 19 | */ |
32 | .write = stm32f2xx_adc_write, | 20 | QTestState *qtest_init_without_qmp_handshake(const char *extra_args); |
33 | .endianness = DEVICE_NATIVE_ENDIAN, | 21 | |
34 | + .impl.min_access_size = 4, | 22 | +/** |
35 | + .impl.max_access_size = 4, | 23 | + * qtest_init_with_serial: |
36 | }; | 24 | + * @extra_args: other arguments to pass to QEMU. CAUTION: these |
37 | 25 | + * arguments are subject to word splitting and shell evaluation. | |
38 | static const VMStateDescription vmstate_stm32f2xx_adc = { | 26 | + * @sock_fd: pointer to store the socket file descriptor for |
39 | @@ -XXX,XX +XXX,XX @@ static void stm32f2xx_adc_init(Object *obj) | 27 | + * connection with serial. |
40 | sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq); | 28 | + * |
41 | 29 | + * Returns: #QTestState instance. | |
42 | memory_region_init_io(&s->mmio, obj, &stm32f2xx_adc_ops, s, | 30 | + */ |
43 | - TYPE_STM32F2XX_ADC, 0xFF); | 31 | +QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd); |
44 | + TYPE_STM32F2XX_ADC, 0x100); | 32 | + |
45 | sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio); | 33 | /** |
34 | * qtest_quit: | ||
35 | * @s: #QTestState instance to operate on. | ||
36 | diff --git a/tests/libqtest.c b/tests/libqtest.c | ||
37 | index XXXXXXX..XXXXXXX 100644 | ||
38 | --- a/tests/libqtest.c | ||
39 | +++ b/tests/libqtest.c | ||
40 | @@ -XXX,XX +XXX,XX @@ QTestState *qtest_initf(const char *fmt, ...) | ||
41 | return s; | ||
46 | } | 42 | } |
47 | 43 | ||
44 | +QTestState *qtest_init_with_serial(const char *extra_args, int *sock_fd) | ||
45 | +{ | ||
46 | + int sock_fd_init; | ||
47 | + char *sock_path, sock_dir[] = "/tmp/qtest-serial-XXXXXX"; | ||
48 | + QTestState *qts; | ||
49 | + | ||
50 | + g_assert(mkdtemp(sock_dir)); | ||
51 | + sock_path = g_strdup_printf("%s/sock", sock_dir); | ||
52 | + | ||
53 | + sock_fd_init = init_socket(sock_path); | ||
54 | + | ||
55 | + qts = qtest_initf("-chardev socket,id=s0,path=%s,nowait " | ||
56 | + "-serial chardev:s0 %s", | ||
57 | + sock_path, extra_args); | ||
58 | + | ||
59 | + *sock_fd = socket_accept(sock_fd_init); | ||
60 | + | ||
61 | + unlink(sock_path); | ||
62 | + g_free(sock_path); | ||
63 | + rmdir(sock_dir); | ||
64 | + | ||
65 | + g_assert(*sock_fd >= 0); | ||
66 | + | ||
67 | + return qts; | ||
68 | +} | ||
69 | + | ||
70 | void qtest_quit(QTestState *s) | ||
71 | { | ||
72 | g_hook_destroy_link(&abrt_hooks, g_hook_find_data(&abrt_hooks, TRUE, s)); | ||
48 | -- | 73 | -- |
49 | 2.20.1 | 74 | 2.20.1 |
50 | 75 | ||
51 | 76 | diff view generated by jsdifflib |