1 | Changes v1->v2: it turns out that the raspi3 support exposes a | 1 | Some arm patches before softfreeze. These are all bug fixes. |
---|---|---|---|
2 | preexisting bug in our register definitions for VMPIDR/VMIDR: | ||
3 | https://lists.gnu.org/archive/html/qemu-devel/2018-02/msg04181.html | ||
4 | 2 | ||
5 | So I've dropped the final "enable raspi3 board" patch for the | ||
6 | moment. When that VMIDR/VMPIDR patch gets reviewed we can | ||
7 | put the raspi3 patch in with it. | ||
8 | |||
9 | |||
10 | thanks | ||
11 | -- PMM | 3 | -- PMM |
12 | 4 | ||
13 | The following changes since commit f003d07337a6d4d02c43429b26a4270459afb51a: | 5 | The following changes since commit 0ebf76aae58324b8f7bf6af798696687f5f4c2a9: |
14 | 6 | ||
15 | Merge remote-tracking branch 'remotes/stefanha/tags/block-pull-request' into staging (2018-02-15 15:45:33 +0000) | 7 | Merge tag 'nvme-next-pull-request' of git://git.infradead.org/qemu-nvme into staging (2022-07-15 15:38:13 +0100) |
16 | 8 | ||
17 | are available in the Git repository at: | 9 | are available in the Git repository at: |
18 | 10 | ||
19 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180215-1 | 11 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20220718 |
20 | 12 | ||
21 | for you to fetch changes up to bade58166f4466546600d824a2695a00269d10eb: | 13 | for you to fetch changes up to 004c8a8bc569c8b18fca6fc90ffe3223daaf17b7: |
22 | 14 | ||
23 | raspi: Raspberry Pi 3 support (2018-02-15 18:33:46 +0000) | 15 | Align Raspberry Pi DMA interrupts with Linux DTS (2022-07-18 13:25:13 +0100) |
24 | 16 | ||
25 | ---------------------------------------------------------------- | 17 | ---------------------------------------------------------------- |
26 | target-arm queue: | 18 | target-arm queue: |
27 | * aspeed: code cleanup to use unimplemented_device | 19 | * hw/intc/armv7m_nvic: ICPRn must not unpend an IRQ that is being held high |
28 | * preparatory work for 'raspi3' RaspberryPi 3 machine model | 20 | * target/arm: Fill in VL for tbflags when SME enabled and SVE disabled |
29 | * more SVE prep work | 21 | * target/arm: Fix aarch64_sve_change_el for SME |
30 | * v8M: add minor missing registers | 22 | * linux-user/aarch64: Do not clear PROT_MTE on mprotect |
31 | * v7M: fix bug where we weren't migrating v7m.other_sp | 23 | * target/arm: Honour VTCR_EL2 bits in Secure EL2 |
32 | * v7M: fix bugs in handling of interrupt registers for | 24 | * hw/adc: Fix CONV bit in NPCM7XX ADC CON register |
33 | external interrupts beyond 32 | 25 | * hw/adc: Make adci[*] R/W in NPCM7XX ADC |
26 | * target/arm: Don't set syndrome ISS for loads and stores with writeback | ||
27 | * Align Raspberry Pi DMA interrupts with Linux DTS | ||
34 | 28 | ||
35 | ---------------------------------------------------------------- | 29 | ---------------------------------------------------------------- |
36 | Pekka Enberg (2): | 30 | Andrey Makarov (1): |
37 | bcm2836: Make CPU type configurable | 31 | Align Raspberry Pi DMA interrupts with Linux DTS |
38 | raspi: Raspberry Pi 3 support | ||
39 | 32 | ||
40 | Peter Maydell (11): | 33 | Hao Wu (2): |
41 | hw/intc/armv7m_nvic: Don't hardcode M profile ID registers in NVIC | 34 | hw/adc: Fix CONV bit in NPCM7XX ADC CON register |
42 | hw/intc/armv7m_nvic: Fix ICSR PENDNMISET/CLR handling | 35 | hw/adc: Make adci[*] R/W in NPCM7XX ADC |
43 | hw/intc/armv7m_nvic: Implement M profile cache maintenance ops | ||
44 | hw/intc/armv7m_nvic: Implement v8M CPPWR register | ||
45 | hw/intc/armv7m_nvic: Implement cache ID registers | ||
46 | hw/intc/armv7m_nvic: Implement SCR | ||
47 | target/arm: Implement writing to CONTROL_NS for v8M | ||
48 | hw/intc/armv7m_nvic: Fix byte-to-interrupt number conversions | ||
49 | target/arm: Add AIRCR to vmstate struct | ||
50 | target/arm: Migrate v7m.other_sp | ||
51 | target/arm: Implement v8M MSPLIM and PSPLIM registers | ||
52 | 36 | ||
53 | Philippe Mathieu-Daudé (2): | 37 | Peter Maydell (9): |
54 | hw/arm/aspeed: directly map the serial device to the system address space | 38 | hw/intc/armv7m_nvic: ICPRn must not unpend an IRQ that is being held high |
55 | hw/arm/aspeed: simplify using the 'unimplemented device' for aspeed_soc.io | 39 | target/arm: Define and use new regime_tcr_value() function |
40 | target/arm: Calculate mask/base_mask in get_level1_table_address() | ||
41 | target/arm: Fold regime_tcr() and regime_tcr_value() together | ||
42 | target/arm: Fix big-endian host handling of VTCR | ||
43 | target/arm: Store VTCR_EL2, VSTCR_EL2 registers as uint64_t | ||
44 | target/arm: Store TCR_EL* registers as uint64_t | ||
45 | target/arm: Honour VTCR_EL2 bits in Secure EL2 | ||
46 | target/arm: Don't set syndrome ISS for loads and stores with writeback | ||
56 | 47 | ||
57 | Richard Henderson (5): | 48 | Richard Henderson (3): |
58 | target/arm: Remove ARM_CP_64BIT from ZCR_EL registers | 49 | target/arm: Fill in VL for tbflags when SME enabled and SVE disabled |
59 | target/arm: Enforce FP access to FPCR/FPSR | 50 | target/arm: Fix aarch64_sve_change_el for SME |
60 | target/arm: Suppress TB end for FPCR/FPSR | 51 | linux-user/aarch64: Do not clear PROT_MTE on mprotect |
61 | target/arm: Enforce access to ZCR_EL at translation | ||
62 | target/arm: Handle SVE registers when using clear_vec_high | ||
63 | 52 | ||
64 | include/hw/arm/aspeed_soc.h | 1 - | 53 | include/hw/arm/bcm2835_peripherals.h | 2 + |
65 | include/hw/arm/bcm2836.h | 1 + | 54 | target/arm/cpu.h | 38 ++++++++--- |
66 | target/arm/cpu.h | 71 ++++++++++++----- | 55 | target/arm/internals.h | 34 +++++++--- |
67 | target/arm/internals.h | 6 ++ | 56 | accel/tcg/translate-all.c | 13 +++- |
68 | hw/arm/aspeed_soc.c | 35 ++------- | 57 | hw/adc/npcm7xx_adc.c | 4 +- |
69 | hw/arm/bcm2836.c | 17 +++-- | 58 | hw/arm/bcm2835_peripherals.c | 26 ++++++- |
70 | hw/arm/raspi.c | 34 ++++++--- | 59 | hw/intc/armv7m_nvic.c | 9 ++- |
71 | hw/intc/armv7m_nvic.c | 98 ++++++++++++++++++------ | 60 | target/arm/cpu.c | 2 +- |
72 | target/arm/cpu.c | 28 +++++++ | 61 | target/arm/debug_helper.c | 2 +- |
73 | target/arm/helper.c | 84 +++++++++++++++----- | 62 | target/arm/helper.c | 128 ++++++++++++++++------------------- |
74 | target/arm/machine.c | 84 ++++++++++++++++++++ | 63 | target/arm/ptw.c | 38 ++++++----- |
75 | target/arm/translate-a64.c | 181 ++++++++++++++++++++------------------------ | 64 | target/arm/tlb_helper.c | 2 +- |
76 | 12 files changed, 429 insertions(+), 211 deletions(-) | 65 | target/arm/translate-a64.c | 4 +- |
77 | 66 | tests/qtest/bcm2835-dma-test.c | 118 ++++++++++++++++++++++++++++++++ | |
67 | tests/qtest/npcm7xx_adc-test.c | 2 +- | ||
68 | tests/qtest/meson.build | 3 +- | ||
69 | 16 files changed, 306 insertions(+), 119 deletions(-) | ||
70 | create mode 100644 tests/qtest/bcm2835-dma-test.c | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | (qemu) info mtree | ||
4 | address-space: cpu-memory-0 | ||
5 | 0000000000000000-ffffffffffffffff (prio 0, i/o): system | ||
6 | 0000000000000000-0000000007ffffff (prio 0, rom): aspeed.boot_rom | ||
7 | 000000001e600000-000000001e7fffff (prio -1, i/o): aspeed_soc.io | ||
8 | - 000000001e784000-000000001e78401f (prio 0, i/o): serial | ||
9 | 000000001e620000-000000001e6200ff (prio 0, i/o): aspeed.smc.ast2500-fmc | ||
10 | 000000001e630000-000000001e6300ff (prio 0, i/o): aspeed.smc.ast2500-spi1 | ||
11 | [...] | ||
12 | 000000001e720000-000000001e728fff (prio 0, ram): aspeed.sram | ||
13 | 000000001e782000-000000001e782fff (prio 0, i/o): aspeed.timer | ||
14 | + 000000001e784000-000000001e78401f (prio 0, i/o): serial | ||
15 | 000000001e785000-000000001e78501f (prio 0, i/o): aspeed.wdt | ||
16 | 000000001e785020-000000001e78503f (prio 0, i/o): aspeed.wdt | ||
17 | |||
18 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
19 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | ||
20 | Reviewed-by: Andrew Jeffery <andrew@aj.id.au> | ||
21 | Message-id: 20180209085755.30414-2-f4bug@amsat.org | ||
22 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
23 | --- | ||
24 | hw/arm/aspeed_soc.c | 3 ++- | ||
25 | 1 file changed, 2 insertions(+), 1 deletion(-) | ||
26 | |||
27 | diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c | ||
28 | index XXXXXXX..XXXXXXX 100644 | ||
29 | --- a/hw/arm/aspeed_soc.c | ||
30 | +++ b/hw/arm/aspeed_soc.c | ||
31 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) | ||
32 | /* UART - attach an 8250 to the IO space as our UART5 */ | ||
33 | if (serial_hds[0]) { | ||
34 | qemu_irq uart5 = qdev_get_gpio_in(DEVICE(&s->vic), uart_irqs[4]); | ||
35 | - serial_mm_init(&s->iomem, ASPEED_SOC_UART_5_BASE, 2, | ||
36 | + serial_mm_init(get_system_memory(), | ||
37 | + ASPEED_SOC_IOMEM_BASE + ASPEED_SOC_UART_5_BASE, 2, | ||
38 | uart5, 38400, serial_hds[0], DEVICE_LITTLE_ENDIAN); | ||
39 | } | ||
40 | |||
41 | -- | ||
42 | 2.16.1 | ||
43 | |||
44 | diff view generated by jsdifflib |
1 | In many of the NVIC registers relating to interrupts, we | 1 | In the M-profile Arm ARM, rule R_CVJS defines when an interrupt should |
---|---|---|---|
2 | have to convert from a byte offset within a register set | 2 | be set to the Pending state: |
3 | into the number of the first interrupt which is affected. | 3 | A) when the input line is high and the interrupt is not Active |
4 | We were getting this wrong for: | 4 | B) when the input line transitions from low to high and the interrupt |
5 | * reads of NVIC_ISPR<n>, NVIC_ISER<n>, NVIC_ICPR<n>, NVIC_ICER<n>, | 5 | is Active |
6 | NVIC_IABR<n> -- in all these cases we were missing the "* 8" | 6 | (Note that the first of these is an ongoing condition, and the |
7 | needed to convert from the byte offset to the interrupt number | 7 | second is a point-in-time event.) |
8 | (since all these registers use one bit per interrupt) | ||
9 | * writes of NVIC_IPR<n> had the opposite problem of a spurious | ||
10 | "* 8" (since these registers use one byte per interrupt) | ||
11 | 8 | ||
9 | This can be rephrased as: | ||
10 | 1 when the line goes from low to high, set Pending | ||
11 | 2 when Active goes from 1 to 0, if line is high then set Pending | ||
12 | 3 ignore attempts to clear Pending when the line is high | ||
13 | and Active is 0 | ||
14 | |||
15 | where 1 covers both B and one of the "transition into condition A" | ||
16 | cases, 2 deals with the other "transition into condition A" | ||
17 | possibility, and 3 is "don't drop Pending if we're already in | ||
18 | condition A". Transitions out of condition A don't affect Pending | ||
19 | state. | ||
20 | |||
21 | We handle case 1 in set_irq_level(). For an interrupt (as opposed | ||
22 | to other kinds of exception) the only place where we clear Active | ||
23 | is in armv7m_nvic_complete_irq(), where we handle case 2 by | ||
24 | checking for whether we need to re-pend the exception. For case 3, | ||
25 | the only places where we clear Pending state on an interrupt are in | ||
26 | armv7m_nvic_acknowledge_irq() (where we are setting Active so it | ||
27 | doesn't count) and for writes to NVIC_ICPRn. | ||
28 | |||
29 | It is the "write to NVIC_ICPRn" case that we missed: we must ignore | ||
30 | this if the input line is high and the interrupt is not Active. | ||
31 | (This required behaviour is differently and perhaps more clearly | ||
32 | stated in the v7M Arm ARM, which has pseudocode in section B3.4.1 | ||
33 | that implies it.) | ||
34 | |||
35 | Reported-by: Igor Kotrasiński <i.kotrasinsk@samsung.com> | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 36 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 37 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> |
14 | Message-id: 20180209165810.6668-9-peter.maydell@linaro.org | 38 | Message-id: 20220628154724.3297442-1-peter.maydell@linaro.org |
15 | --- | 39 | --- |
16 | hw/intc/armv7m_nvic.c | 8 ++++---- | 40 | hw/intc/armv7m_nvic.c | 9 ++++++++- |
17 | 1 file changed, 4 insertions(+), 4 deletions(-) | 41 | 1 file changed, 8 insertions(+), 1 deletion(-) |
18 | 42 | ||
19 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | 43 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c |
20 | index XXXXXXX..XXXXXXX 100644 | 44 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/intc/armv7m_nvic.c | 45 | --- a/hw/intc/armv7m_nvic.c |
22 | +++ b/hw/intc/armv7m_nvic.c | 46 | +++ b/hw/intc/armv7m_nvic.c |
23 | @@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr, | 47 | @@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr, |
24 | /* fall through */ | 48 | startvec = 8 * (offset - 0x280) + NVIC_FIRST_IRQ; /* vector # */ |
25 | case 0x180 ... 0x1bf: /* NVIC Clear enable */ | ||
26 | val = 0; | ||
27 | - startvec = offset - 0x180 + NVIC_FIRST_IRQ; /* vector # */ | ||
28 | + startvec = 8 * (offset - 0x180) + NVIC_FIRST_IRQ; /* vector # */ | ||
29 | 49 | ||
30 | for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { | 50 | for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { |
31 | if (s->vectors[startvec + i].enabled && | 51 | + /* |
32 | @@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr, | 52 | + * Note that if the input line is still held high and the interrupt |
33 | /* fall through */ | 53 | + * is not active then rule R_CVJS requires that the Pending state |
34 | case 0x280 ... 0x2bf: /* NVIC Clear pend */ | 54 | + * remains set; in that case we mustn't let it be cleared. |
35 | val = 0; | 55 | + */ |
36 | - startvec = offset - 0x280 + NVIC_FIRST_IRQ; /* vector # */ | 56 | if (value & (1 << i) && |
37 | + startvec = 8 * (offset - 0x280) + NVIC_FIRST_IRQ; /* vector # */ | 57 | - (attrs.secure || s->itns[startvec + i])) { |
38 | for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { | 58 | + (attrs.secure || s->itns[startvec + i]) && |
39 | if (s->vectors[startvec + i].pending && | 59 | + !(setval == 0 && s->vectors[startvec + i].level && |
40 | (attrs.secure || s->itns[startvec + i])) { | 60 | + !s->vectors[startvec + i].active)) { |
41 | @@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_read(void *opaque, hwaddr addr, | 61 | s->vectors[startvec + i].pending = setval; |
42 | break; | 62 | } |
43 | case 0x300 ... 0x33f: /* NVIC Active */ | 63 | } |
44 | val = 0; | ||
45 | - startvec = offset - 0x300 + NVIC_FIRST_IRQ; /* vector # */ | ||
46 | + startvec = 8 * (offset - 0x300) + NVIC_FIRST_IRQ; /* vector # */ | ||
47 | |||
48 | for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { | ||
49 | if (s->vectors[startvec + i].active && | ||
50 | @@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr, | ||
51 | case 0x300 ... 0x33f: /* NVIC Active */ | ||
52 | return MEMTX_OK; /* R/O */ | ||
53 | case 0x400 ... 0x5ef: /* NVIC Priority */ | ||
54 | - startvec = 8 * (offset - 0x400) + NVIC_FIRST_IRQ; /* vector # */ | ||
55 | + startvec = (offset - 0x400) + NVIC_FIRST_IRQ; /* vector # */ | ||
56 | |||
57 | for (i = 0; i < size && startvec + i < s->num_irq; i++) { | ||
58 | if (attrs.secure || s->itns[startvec + i]) { | ||
59 | -- | 64 | -- |
60 | 2.16.1 | 65 | 2.25.1 |
61 | 66 | ||
62 | 67 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Nothing in either register affects the TB. | 3 | When PSTATE.SM, VL = SVL even if SVE is disabled. |
4 | This is visible in kselftest ssve-test. | ||
4 | 5 | ||
6 | Reported-by: Mark Brown <broonie@kernel.org> | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Message-id: 20180211205848.4568-4-richard.henderson@linaro.org | 8 | Message-id: 20220713045848.217364-2-richard.henderson@linaro.org |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 11 | --- |
10 | target/arm/helper.c | 4 ++-- | 12 | target/arm/helper.c | 10 ++++++++-- |
11 | 1 file changed, 2 insertions(+), 2 deletions(-) | 13 | 1 file changed, 8 insertions(+), 2 deletions(-) |
12 | 14 | ||
13 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 15 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
14 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.c | 17 | --- a/target/arm/helper.c |
16 | +++ b/target/arm/helper.c | 18 | +++ b/target/arm/helper.c |
17 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v8_cp_reginfo[] = { | 19 | @@ -XXX,XX +XXX,XX @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, |
18 | .writefn = aa64_daif_write, .resetfn = arm_cp_reset_ignore }, | 20 | } |
19 | { .name = "FPCR", .state = ARM_CP_STATE_AA64, | 21 | if (cpu_isar_feature(aa64_sme, env_archcpu(env))) { |
20 | .opc0 = 3, .opc1 = 3, .opc2 = 0, .crn = 4, .crm = 4, | 22 | int sme_el = sme_exception_el(env, el); |
21 | - .access = PL0_RW, .type = ARM_CP_FPU, | 23 | + bool sm = FIELD_EX64(env->svcr, SVCR, SM); |
22 | + .access = PL0_RW, .type = ARM_CP_FPU | ARM_CP_SUPPRESS_TB_END, | 24 | |
23 | .readfn = aa64_fpcr_read, .writefn = aa64_fpcr_write }, | 25 | DP_TBFLAG_A64(flags, SMEEXC_EL, sme_el); |
24 | { .name = "FPSR", .state = ARM_CP_STATE_AA64, | 26 | if (sme_el == 0) { |
25 | .opc0 = 3, .opc1 = 3, .opc2 = 1, .crn = 4, .crm = 4, | 27 | /* Similarly, do not compute SVL if SME is disabled. */ |
26 | - .access = PL0_RW, .type = ARM_CP_FPU, | 28 | - DP_TBFLAG_A64(flags, SVL, sve_vqm1_for_el_sm(env, el, true)); |
27 | + .access = PL0_RW, .type = ARM_CP_FPU | ARM_CP_SUPPRESS_TB_END, | 29 | + int svl = sve_vqm1_for_el_sm(env, el, true); |
28 | .readfn = aa64_fpsr_read, .writefn = aa64_fpsr_write }, | 30 | + DP_TBFLAG_A64(flags, SVL, svl); |
29 | { .name = "DCZID_EL0", .state = ARM_CP_STATE_AA64, | 31 | + if (sm) { |
30 | .opc0 = 3, .opc1 = 3, .opc2 = 7, .crn = 0, .crm = 0, | 32 | + /* If SVE is disabled, we will not have set VL above. */ |
33 | + DP_TBFLAG_A64(flags, VL, svl); | ||
34 | + } | ||
35 | } | ||
36 | - if (FIELD_EX64(env->svcr, SVCR, SM)) { | ||
37 | + if (sm) { | ||
38 | DP_TBFLAG_A64(flags, PSTATE_SM, 1); | ||
39 | DP_TBFLAG_A64(flags, SME_TRAP_NONSTREAMING, !sme_fa64(env, el)); | ||
40 | } | ||
31 | -- | 41 | -- |
32 | 2.16.1 | 42 | 2.25.1 |
33 | |||
34 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Because they are ARM_CP_STATE_AA64, ARM_CP_64BIT is implied. | 3 | We were only checking for SVE disabled and not taking into |
4 | account PSTATE.SM to check SME disabled, which resulted in | ||
5 | vectors being incorrectly truncated. | ||
4 | 6 | ||
5 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
6 | Message-id: 20180211205848.4568-2-richard.henderson@linaro.org | 8 | Message-id: 20220713045848.217364-3-richard.henderson@linaro.org |
7 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 11 | --- |
10 | target/arm/helper.c | 8 ++++---- | 12 | target/arm/helper.c | 31 +++++++++++++++++++++++++------ |
11 | 1 file changed, 4 insertions(+), 4 deletions(-) | 13 | 1 file changed, 25 insertions(+), 6 deletions(-) |
12 | 14 | ||
13 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 15 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
14 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/helper.c | 17 | --- a/target/arm/helper.c |
16 | +++ b/target/arm/helper.c | 18 | +++ b/target/arm/helper.c |
17 | @@ -XXX,XX +XXX,XX @@ static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri, | 19 | @@ -XXX,XX +XXX,XX @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq) |
18 | static const ARMCPRegInfo zcr_el1_reginfo = { | 20 | } |
19 | .name = "ZCR_EL1", .state = ARM_CP_STATE_AA64, | 21 | } |
20 | .opc0 = 3, .opc1 = 0, .crn = 1, .crm = 2, .opc2 = 0, | 22 | |
21 | - .access = PL1_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | 23 | +static uint32_t sve_vqm1_for_el_sm_ena(CPUARMState *env, int el, bool sm) |
22 | + .access = PL1_RW, .accessfn = zcr_access, | 24 | +{ |
23 | .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[1]), | 25 | + int exc_el; |
24 | .writefn = zcr_write, .raw_writefn = raw_write | 26 | + |
25 | }; | 27 | + if (sm) { |
26 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo zcr_el1_reginfo = { | 28 | + exc_el = sme_exception_el(env, el); |
27 | static const ARMCPRegInfo zcr_el2_reginfo = { | 29 | + } else { |
28 | .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, | 30 | + exc_el = sve_exception_el(env, el); |
29 | .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, | 31 | + } |
30 | - .access = PL2_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | 32 | + if (exc_el) { |
31 | + .access = PL2_RW, .accessfn = zcr_access, | 33 | + return 0; /* disabled */ |
32 | .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[2]), | 34 | + } |
33 | .writefn = zcr_write, .raw_writefn = raw_write | 35 | + return sve_vqm1_for_el_sm(env, el, sm); |
34 | }; | 36 | +} |
35 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo zcr_el2_reginfo = { | 37 | + |
36 | static const ARMCPRegInfo zcr_no_el2_reginfo = { | 38 | /* |
37 | .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, | 39 | * Notice a change in SVE vector size when changing EL. |
38 | .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, | 40 | */ |
39 | - .access = PL2_RW, .type = ARM_CP_64BIT, | 41 | @@ -XXX,XX +XXX,XX @@ void aarch64_sve_change_el(CPUARMState *env, int old_el, |
40 | + .access = PL2_RW, | 42 | { |
41 | .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore | 43 | ARMCPU *cpu = env_archcpu(env); |
42 | }; | 44 | int old_len, new_len; |
43 | 45 | - bool old_a64, new_a64; | |
44 | static const ARMCPRegInfo zcr_el3_reginfo = { | 46 | + bool old_a64, new_a64, sm; |
45 | .name = "ZCR_EL3", .state = ARM_CP_STATE_AA64, | 47 | |
46 | .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 2, .opc2 = 0, | 48 | /* Nothing to do if no SVE. */ |
47 | - .access = PL3_RW, .accessfn = zcr_access, .type = ARM_CP_64BIT, | 49 | if (!cpu_isar_feature(aa64_sve, cpu)) { |
48 | + .access = PL3_RW, .accessfn = zcr_access, | 50 | @@ -XXX,XX +XXX,XX @@ void aarch64_sve_change_el(CPUARMState *env, int old_el, |
49 | .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[3]), | 51 | * invoke ResetSVEState when taking an exception from, or |
50 | .writefn = zcr_write, .raw_writefn = raw_write | 52 | * returning to, AArch32 state when PSTATE.SM is enabled. |
51 | }; | 53 | */ |
54 | - if (old_a64 != new_a64 && FIELD_EX64(env->svcr, SVCR, SM)) { | ||
55 | + sm = FIELD_EX64(env->svcr, SVCR, SM); | ||
56 | + if (old_a64 != new_a64 && sm) { | ||
57 | arm_reset_sve_state(env); | ||
58 | return; | ||
59 | } | ||
60 | @@ -XXX,XX +XXX,XX @@ void aarch64_sve_change_el(CPUARMState *env, int old_el, | ||
61 | * we already have the correct register contents when encountering the | ||
62 | * vq0->vq0 transition between EL0->EL1. | ||
63 | */ | ||
64 | - old_len = (old_a64 && !sve_exception_el(env, old_el) | ||
65 | - ? sve_vqm1_for_el(env, old_el) : 0); | ||
66 | - new_len = (new_a64 && !sve_exception_el(env, new_el) | ||
67 | - ? sve_vqm1_for_el(env, new_el) : 0); | ||
68 | + old_len = new_len = 0; | ||
69 | + if (old_a64) { | ||
70 | + old_len = sve_vqm1_for_el_sm_ena(env, old_el, sm); | ||
71 | + } | ||
72 | + if (new_a64) { | ||
73 | + new_len = sve_vqm1_for_el_sm_ena(env, new_el, sm); | ||
74 | + } | ||
75 | |||
76 | /* When changing vector length, clear inaccessible state. */ | ||
77 | if (new_len < old_len) { | ||
52 | -- | 78 | -- |
53 | 2.16.1 | 79 | 2.25.1 |
54 | |||
55 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | The documentation for PROT_MTE says that it cannot be cleared | ||
4 | by mprotect. Further, the implementation of the VM_ARCH_CLEAR bit, | ||
5 | contains PROT_BTI confiming that bit should be cleared. | ||
6 | |||
7 | Introduce PAGE_TARGET_STICKY to allow target/arch/cpu.h to control | ||
8 | which bits may be reset during page_set_flags. This is sort of the | ||
9 | opposite of VM_ARCH_CLEAR, but works better with qemu's PAGE_* bits | ||
10 | that are separate from PROT_* bits. | ||
11 | |||
12 | Reported-by: Vitaly Buka <vitalybuka@google.com> | ||
3 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | 13 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> |
4 | Message-id: 20180211205848.4568-3-richard.henderson@linaro.org | 14 | Message-id: 20220711031420.17820-1-richard.henderson@linaro.org |
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 17 | --- |
8 | target/arm/cpu.h | 35 ++++++++++++++++++----------------- | 18 | target/arm/cpu.h | 7 +++++-- |
9 | target/arm/helper.c | 6 ++++-- | 19 | accel/tcg/translate-all.c | 13 +++++++++++-- |
10 | target/arm/translate-a64.c | 3 +++ | 20 | 2 files changed, 16 insertions(+), 4 deletions(-) |
11 | 3 files changed, 25 insertions(+), 19 deletions(-) | ||
12 | 21 | ||
13 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 22 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
14 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/target/arm/cpu.h | 24 | --- a/target/arm/cpu.h |
16 | +++ b/target/arm/cpu.h | 25 | +++ b/target/arm/cpu.h |
17 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t cpreg_to_kvm_id(uint32_t cpregid) | 26 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) |
27 | |||
28 | /* | ||
29 | * AArch64 usage of the PAGE_TARGET_* bits for linux-user. | ||
30 | + * Note that with the Linux kernel, PROT_MTE may not be cleared by mprotect | ||
31 | + * mprotect but PROT_BTI may be cleared. C.f. the kernel's VM_ARCH_CLEAR. | ||
32 | */ | ||
33 | -#define PAGE_BTI PAGE_TARGET_1 | ||
34 | -#define PAGE_MTE PAGE_TARGET_2 | ||
35 | +#define PAGE_BTI PAGE_TARGET_1 | ||
36 | +#define PAGE_MTE PAGE_TARGET_2 | ||
37 | +#define PAGE_TARGET_STICKY PAGE_MTE | ||
38 | |||
39 | #ifdef TARGET_TAGGED_ADDRESSES | ||
40 | /** | ||
41 | diff --git a/accel/tcg/translate-all.c b/accel/tcg/translate-all.c | ||
42 | index XXXXXXX..XXXXXXX 100644 | ||
43 | --- a/accel/tcg/translate-all.c | ||
44 | +++ b/accel/tcg/translate-all.c | ||
45 | @@ -XXX,XX +XXX,XX @@ int page_get_flags(target_ulong address) | ||
46 | return p->flags; | ||
18 | } | 47 | } |
19 | 48 | ||
20 | /* ARMCPRegInfo type field bits. If the SPECIAL bit is set this is a | 49 | +/* |
21 | - * special-behaviour cp reg and bits [15..8] indicate what behaviour | 50 | + * Allow the target to decide if PAGE_TARGET_[12] may be reset. |
22 | + * special-behaviour cp reg and bits [11..8] indicate what behaviour | 51 | + * By default, they are not kept. |
23 | * it has. Otherwise it is a simple cp reg, where CONST indicates that | 52 | + */ |
24 | * TCG can assume the value to be constant (ie load at translate time) | 53 | +#ifndef PAGE_TARGET_STICKY |
25 | * and 64BIT indicates a 64 bit wide coprocessor register. SUPPRESS_TB_END | 54 | +#define PAGE_TARGET_STICKY 0 |
26 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t cpreg_to_kvm_id(uint32_t cpregid) | 55 | +#endif |
27 | * need to be surrounded by gen_io_start()/gen_io_end(). In particular, | 56 | +#define PAGE_STICKY (PAGE_ANON | PAGE_TARGET_STICKY) |
28 | * registers which implement clocks or timers require this. | 57 | + |
29 | */ | 58 | /* Modify the flags of a page and invalidate the code if necessary. |
30 | -#define ARM_CP_SPECIAL 1 | 59 | The flag PAGE_WRITE_ORG is positioned automatically depending |
31 | -#define ARM_CP_CONST 2 | 60 | on PAGE_WRITE. The mmap_lock should already be held. */ |
32 | -#define ARM_CP_64BIT 4 | 61 | @@ -XXX,XX +XXX,XX @@ void page_set_flags(target_ulong start, target_ulong end, int flags) |
33 | -#define ARM_CP_SUPPRESS_TB_END 8 | 62 | p->target_data = NULL; |
34 | -#define ARM_CP_OVERRIDE 16 | 63 | p->flags = flags; |
35 | -#define ARM_CP_ALIAS 32 | 64 | } else { |
36 | -#define ARM_CP_IO 64 | 65 | - /* Using mprotect on a page does not change MAP_ANON. */ |
37 | -#define ARM_CP_NO_RAW 128 | 66 | - p->flags = (p->flags & PAGE_ANON) | flags; |
38 | -#define ARM_CP_NOP (ARM_CP_SPECIAL | (1 << 8)) | 67 | + /* Using mprotect on a page does not change sticky bits. */ |
39 | -#define ARM_CP_WFI (ARM_CP_SPECIAL | (2 << 8)) | 68 | + p->flags = (p->flags & PAGE_STICKY) | flags; |
40 | -#define ARM_CP_NZCV (ARM_CP_SPECIAL | (3 << 8)) | 69 | } |
41 | -#define ARM_CP_CURRENTEL (ARM_CP_SPECIAL | (4 << 8)) | ||
42 | -#define ARM_CP_DC_ZVA (ARM_CP_SPECIAL | (5 << 8)) | ||
43 | -#define ARM_LAST_SPECIAL ARM_CP_DC_ZVA | ||
44 | +#define ARM_CP_SPECIAL 0x0001 | ||
45 | +#define ARM_CP_CONST 0x0002 | ||
46 | +#define ARM_CP_64BIT 0x0004 | ||
47 | +#define ARM_CP_SUPPRESS_TB_END 0x0008 | ||
48 | +#define ARM_CP_OVERRIDE 0x0010 | ||
49 | +#define ARM_CP_ALIAS 0x0020 | ||
50 | +#define ARM_CP_IO 0x0040 | ||
51 | +#define ARM_CP_NO_RAW 0x0080 | ||
52 | +#define ARM_CP_NOP (ARM_CP_SPECIAL | 0x0100) | ||
53 | +#define ARM_CP_WFI (ARM_CP_SPECIAL | 0x0200) | ||
54 | +#define ARM_CP_NZCV (ARM_CP_SPECIAL | 0x0300) | ||
55 | +#define ARM_CP_CURRENTEL (ARM_CP_SPECIAL | 0x0400) | ||
56 | +#define ARM_CP_DC_ZVA (ARM_CP_SPECIAL | 0x0500) | ||
57 | +#define ARM_LAST_SPECIAL ARM_CP_DC_ZVA | ||
58 | +#define ARM_CP_FPU 0x1000 | ||
59 | /* Used only as a terminator for ARMCPRegInfo lists */ | ||
60 | -#define ARM_CP_SENTINEL 0xffff | ||
61 | +#define ARM_CP_SENTINEL 0xffff | ||
62 | /* Mask of only the flag bits in a type field */ | ||
63 | -#define ARM_CP_FLAG_MASK 0xff | ||
64 | +#define ARM_CP_FLAG_MASK 0x10ff | ||
65 | |||
66 | /* Valid values for ARMCPRegInfo state field, indicating which of | ||
67 | * the AArch32 and AArch64 execution states this register is visible in. | ||
68 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
69 | index XXXXXXX..XXXXXXX 100644 | ||
70 | --- a/target/arm/helper.c | ||
71 | +++ b/target/arm/helper.c | ||
72 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo v8_cp_reginfo[] = { | ||
73 | .writefn = aa64_daif_write, .resetfn = arm_cp_reset_ignore }, | ||
74 | { .name = "FPCR", .state = ARM_CP_STATE_AA64, | ||
75 | .opc0 = 3, .opc1 = 3, .opc2 = 0, .crn = 4, .crm = 4, | ||
76 | - .access = PL0_RW, .readfn = aa64_fpcr_read, .writefn = aa64_fpcr_write }, | ||
77 | + .access = PL0_RW, .type = ARM_CP_FPU, | ||
78 | + .readfn = aa64_fpcr_read, .writefn = aa64_fpcr_write }, | ||
79 | { .name = "FPSR", .state = ARM_CP_STATE_AA64, | ||
80 | .opc0 = 3, .opc1 = 3, .opc2 = 1, .crn = 4, .crm = 4, | ||
81 | - .access = PL0_RW, .readfn = aa64_fpsr_read, .writefn = aa64_fpsr_write }, | ||
82 | + .access = PL0_RW, .type = ARM_CP_FPU, | ||
83 | + .readfn = aa64_fpsr_read, .writefn = aa64_fpsr_write }, | ||
84 | { .name = "DCZID_EL0", .state = ARM_CP_STATE_AA64, | ||
85 | .opc0 = 3, .opc1 = 3, .opc2 = 7, .crn = 0, .crm = 0, | ||
86 | .access = PL0_R, .type = ARM_CP_NO_RAW, | ||
87 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
88 | index XXXXXXX..XXXXXXX 100644 | ||
89 | --- a/target/arm/translate-a64.c | ||
90 | +++ b/target/arm/translate-a64.c | ||
91 | @@ -XXX,XX +XXX,XX @@ static void handle_sys(DisasContext *s, uint32_t insn, bool isread, | ||
92 | default: | ||
93 | break; | ||
94 | } | 70 | } |
95 | + if ((ri->type & ARM_CP_FPU) && !fp_access_check(s)) { | 71 | } |
96 | + return; | ||
97 | + } | ||
98 | |||
99 | if ((tb_cflags(s->base.tb) & CF_USE_ICOUNT) && (ri->type & ARM_CP_IO)) { | ||
100 | gen_io_start(); | ||
101 | -- | 72 | -- |
102 | 2.16.1 | 73 | 2.25.1 |
103 | |||
104 | diff view generated by jsdifflib |
1 | M profile cores have a similar setup for cache ID registers | 1 | The regime_tcr() function returns a pointer to a struct TCR |
---|---|---|---|
2 | to A profile: | 2 | corresponding to the TCR controlling a translation regime. The |
3 | * Cache Level ID Register (CLIDR) is a fixed value | 3 | struct TCR has the raw value of the register, plus two fields mask |
4 | * Cache Type Register (CTR) is a fixed value | 4 | and base_mask which are used as a small optimization in the case of |
5 | * Cache Size ID Registers (CCSIDR) are a bank of registers; | 5 | 32-bit short-descriptor lookups. Almost all callers of regime_tcr() |
6 | which one you see is selected by the Cache Size Selection | 6 | only want the raw register value. Define and use a new |
7 | Register (CSSELR) | 7 | regime_tcr_value() function which returns only the raw 64-bit |
8 | register value. | ||
8 | 9 | ||
9 | The only difference is that they're in the NVIC memory mapped | 10 | This is a preliminary to removing the 32-bit short descriptor |
10 | register space rather than being coprocessor registers. | 11 | optimization -- it only saves a handful of bit operations, which is |
11 | Implement the M profile view of them. | 12 | tiny compared to the overhead of doing a page table walk at all, and |
12 | 13 | the TCR struct is awkward and makes fixing | |
13 | Since neither Cortex-M3 nor Cortex-M4 implement caches, | 14 | https://gitlab.com/qemu-project/qemu/-/issues/1103 unnecessarily |
14 | we don't need to update their init functions and can leave | 15 | difficult. |
15 | the ctr/clidr/ccsidr[] fields in their ARMCPU structs at zero. | ||
16 | Newer cores (like the Cortex-M33) will want to be able to | ||
17 | set these ID registers to non-zero values, though. | ||
18 | 16 | ||
19 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
20 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 18 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
21 | Message-id: 20180209165810.6668-6-peter.maydell@linaro.org | 19 | Message-id: 20220714132303.1287193-2-peter.maydell@linaro.org |
22 | --- | 20 | --- |
23 | target/arm/cpu.h | 26 ++++++++++++++++++++++++++ | 21 | target/arm/internals.h | 6 ++++++ |
24 | hw/intc/armv7m_nvic.c | 16 ++++++++++++++++ | 22 | target/arm/helper.c | 6 +++--- |
25 | target/arm/machine.c | 36 ++++++++++++++++++++++++++++++++++++ | 23 | target/arm/ptw.c | 8 ++++---- |
26 | 3 files changed, 78 insertions(+) | 24 | target/arm/tlb_helper.c | 2 +- |
25 | 4 files changed, 14 insertions(+), 8 deletions(-) | ||
27 | 26 | ||
28 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 27 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
29 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/target/arm/cpu.h | 29 | --- a/target/arm/internals.h |
31 | +++ b/target/arm/cpu.h | 30 | +++ b/target/arm/internals.h |
32 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | 31 | @@ -XXX,XX +XXX,XX @@ static inline TCR *regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
33 | uint32_t faultmask[M_REG_NUM_BANKS]; | 32 | return &env->cp15.tcr_el[regime_el(env, mmu_idx)]; |
34 | uint32_t aircr; /* only holds r/w state if security extn implemented */ | ||
35 | uint32_t secure; /* Is CPU in Secure state? (not guest visible) */ | ||
36 | + uint32_t csselr[M_REG_NUM_BANKS]; | ||
37 | } v7m; | ||
38 | |||
39 | /* Information associated with an exception about to be taken: | ||
40 | @@ -XXX,XX +XXX,XX @@ FIELD(V7M_MPU_CTRL, ENABLE, 0, 1) | ||
41 | FIELD(V7M_MPU_CTRL, HFNMIENA, 1, 1) | ||
42 | FIELD(V7M_MPU_CTRL, PRIVDEFENA, 2, 1) | ||
43 | |||
44 | +/* v7M CLIDR bits */ | ||
45 | +FIELD(V7M_CLIDR, CTYPE_ALL, 0, 21) | ||
46 | +FIELD(V7M_CLIDR, LOUIS, 21, 3) | ||
47 | +FIELD(V7M_CLIDR, LOC, 24, 3) | ||
48 | +FIELD(V7M_CLIDR, LOUU, 27, 3) | ||
49 | +FIELD(V7M_CLIDR, ICB, 30, 2) | ||
50 | + | ||
51 | +FIELD(V7M_CSSELR, IND, 0, 1) | ||
52 | +FIELD(V7M_CSSELR, LEVEL, 1, 3) | ||
53 | +/* We use the combination of InD and Level to index into cpu->ccsidr[]; | ||
54 | + * define a mask for this and check that it doesn't permit running off | ||
55 | + * the end of the array. | ||
56 | + */ | ||
57 | +FIELD(V7M_CSSELR, INDEX, 0, 4) | ||
58 | + | ||
59 | +QEMU_BUILD_BUG_ON(ARRAY_SIZE(((ARMCPU *)0)->ccsidr) <= R_V7M_CSSELR_INDEX_MASK); | ||
60 | + | ||
61 | /* If adding a feature bit which corresponds to a Linux ELF | ||
62 | * HWCAP bit, remember to update the feature-bit-to-hwcap | ||
63 | * mapping in linux-user/elfload.c:get_elf_hwcap(). | ||
64 | @@ -XXX,XX +XXX,XX @@ static inline int arm_debug_target_el(CPUARMState *env) | ||
65 | } | ||
66 | } | 33 | } |
67 | 34 | ||
68 | +static inline bool arm_v7m_csselr_razwi(ARMCPU *cpu) | 35 | +/* Return the raw value of the TCR controlling this translation regime */ |
36 | +static inline uint64_t regime_tcr_value(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
69 | +{ | 37 | +{ |
70 | + /* If all the CLIDR.Ctypem bits are 0 there are no caches, and | 38 | + return regime_tcr(env, mmu_idx)->raw_tcr; |
71 | + * CSSELR is RAZ/WI. | ||
72 | + */ | ||
73 | + return (cpu->clidr & R_V7M_CLIDR_CTYPE_ALL_MASK) != 0; | ||
74 | +} | 39 | +} |
75 | + | 40 | + |
76 | static inline bool aa64_generate_debug_exceptions(CPUARMState *env) | 41 | /** |
42 | * arm_num_brps: Return number of implemented breakpoints. | ||
43 | * Note that the ID register BRPS field is "number of bps - 1", | ||
44 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
45 | index XXXXXXX..XXXXXXX 100644 | ||
46 | --- a/target/arm/helper.c | ||
47 | +++ b/target/arm/helper.c | ||
48 | @@ -XXX,XX +XXX,XX @@ static int vae1_tlbmask(CPUARMState *env) | ||
49 | static int tlbbits_for_regime(CPUARMState *env, ARMMMUIdx mmu_idx, | ||
50 | uint64_t addr) | ||
77 | { | 51 | { |
78 | if (arm_is_secure(env)) { | 52 | - uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; |
79 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | 53 | + uint64_t tcr = regime_tcr_value(env, mmu_idx); |
54 | int tbi = aa64_va_parameter_tbi(tcr, mmu_idx); | ||
55 | int select = extract64(addr, 55, 1); | ||
56 | |||
57 | @@ -XXX,XX +XXX,XX @@ static int aa64_va_parameter_tcma(uint64_t tcr, ARMMMUIdx mmu_idx) | ||
58 | ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, | ||
59 | ARMMMUIdx mmu_idx, bool data) | ||
60 | { | ||
61 | - uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; | ||
62 | + uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
63 | bool epd, hpd, using16k, using64k, tsz_oob, ds; | ||
64 | int select, tsz, tbi, max_tsz, min_tsz, ps, sh; | ||
65 | ARMCPU *cpu = env_archcpu(env); | ||
66 | @@ -XXX,XX +XXX,XX @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, | ||
67 | { | ||
68 | CPUARMTBFlags flags = {}; | ||
69 | ARMMMUIdx stage1 = stage_1_mmu_idx(mmu_idx); | ||
70 | - uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; | ||
71 | + uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
72 | uint64_t sctlr; | ||
73 | int tbii, tbid; | ||
74 | |||
75 | diff --git a/target/arm/ptw.c b/target/arm/ptw.c | ||
80 | index XXXXXXX..XXXXXXX 100644 | 76 | index XXXXXXX..XXXXXXX 100644 |
81 | --- a/hw/intc/armv7m_nvic.c | 77 | --- a/target/arm/ptw.c |
82 | +++ b/hw/intc/armv7m_nvic.c | 78 | +++ b/target/arm/ptw.c |
83 | @@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs) | 79 | @@ -XXX,XX +XXX,XX @@ static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, |
84 | return cpu->id_isar4; | 80 | static ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, |
85 | case 0xd74: /* ISAR5. */ | 81 | ARMMMUIdx mmu_idx) |
86 | return cpu->id_isar5; | 82 | { |
87 | + case 0xd78: /* CLIDR */ | 83 | - uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; |
88 | + return cpu->clidr; | 84 | + uint64_t tcr = regime_tcr_value(env, mmu_idx); |
89 | + case 0xd7c: /* CTR */ | 85 | uint32_t el = regime_el(env, mmu_idx); |
90 | + return cpu->ctr; | 86 | int select, tsz; |
91 | + case 0xd80: /* CSSIDR */ | 87 | bool epd, hpd; |
92 | + { | 88 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, |
93 | + int idx = cpu->env.v7m.csselr[attrs.secure] & R_V7M_CSSELR_INDEX_MASK; | 89 | uint32_t attrs; |
94 | + return cpu->ccsidr[idx]; | 90 | int32_t stride; |
95 | + } | 91 | int addrsize, inputsize, outputsize; |
96 | + case 0xd84: /* CSSELR */ | 92 | - TCR *tcr = regime_tcr(env, mmu_idx); |
97 | + return cpu->env.v7m.csselr[attrs.secure]; | 93 | + uint64_t tcr = regime_tcr_value(env, mmu_idx); |
98 | /* TODO: Implement debug registers. */ | 94 | int ap, ns, xn, pxn; |
99 | case 0xd90: /* MPU_TYPE */ | 95 | uint32_t el = regime_el(env, mmu_idx); |
100 | /* Unified MPU; if the MPU is not present this value is zero */ | 96 | uint64_t descaddrmask; |
101 | @@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value, | 97 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, |
102 | qemu_log_mask(LOG_UNIMP, | 98 | * For stage 2 translations the starting level is specified by the |
103 | "NVIC: Aux fault status registers unimplemented\n"); | 99 | * VTCR_EL2.SL0 field (whose interpretation depends on the page size) |
104 | break; | 100 | */ |
105 | + case 0xd84: /* CSSELR */ | 101 | - uint32_t sl0 = extract32(tcr->raw_tcr, 6, 2); |
106 | + if (!arm_v7m_csselr_razwi(cpu)) { | 102 | - uint32_t sl2 = extract64(tcr->raw_tcr, 33, 1); |
107 | + cpu->env.v7m.csselr[attrs.secure] = value & R_V7M_CSSELR_INDEX_MASK; | 103 | + uint32_t sl0 = extract32(tcr, 6, 2); |
108 | + } | 104 | + uint32_t sl2 = extract64(tcr, 33, 1); |
109 | + break; | 105 | uint32_t startlevel; |
110 | case 0xd90: /* MPU_TYPE */ | 106 | bool ok; |
111 | return; /* RO */ | 107 | |
112 | case 0xd94: /* MPU_CTRL */ | 108 | diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c |
113 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
114 | index XXXXXXX..XXXXXXX 100644 | 109 | index XXXXXXX..XXXXXXX 100644 |
115 | --- a/target/arm/machine.c | 110 | --- a/target/arm/tlb_helper.c |
116 | +++ b/target/arm/machine.c | 111 | +++ b/target/arm/tlb_helper.c |
117 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m_faultmask_primask = { | 112 | @@ -XXX,XX +XXX,XX @@ bool regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx) |
113 | return true; | ||
118 | } | 114 | } |
119 | }; | 115 | if (arm_feature(env, ARM_FEATURE_LPAE) |
120 | 116 | - && (regime_tcr(env, mmu_idx)->raw_tcr & TTBCR_EAE)) { | |
121 | +/* CSSELR is in a subsection because we didn't implement it previously. | 117 | + && (regime_tcr_value(env, mmu_idx) & TTBCR_EAE)) { |
122 | + * Migration from an old implementation will leave it at zero, which | 118 | return true; |
123 | + * is OK since the only CPUs in the old implementation make the | ||
124 | + * register RAZ/WI. | ||
125 | + * Since there was no version of QEMU which implemented the CSSELR for | ||
126 | + * just non-secure, we transfer both banks here rather than putting | ||
127 | + * the secure banked version in the m-security subsection. | ||
128 | + */ | ||
129 | +static bool csselr_vmstate_validate(void *opaque, int version_id) | ||
130 | +{ | ||
131 | + ARMCPU *cpu = opaque; | ||
132 | + | ||
133 | + return cpu->env.v7m.csselr[M_REG_NS] <= R_V7M_CSSELR_INDEX_MASK | ||
134 | + && cpu->env.v7m.csselr[M_REG_S] <= R_V7M_CSSELR_INDEX_MASK; | ||
135 | +} | ||
136 | + | ||
137 | +static bool m_csselr_needed(void *opaque) | ||
138 | +{ | ||
139 | + ARMCPU *cpu = opaque; | ||
140 | + | ||
141 | + return !arm_v7m_csselr_razwi(cpu); | ||
142 | +} | ||
143 | + | ||
144 | +static const VMStateDescription vmstate_m_csselr = { | ||
145 | + .name = "cpu/m/csselr", | ||
146 | + .version_id = 1, | ||
147 | + .minimum_version_id = 1, | ||
148 | + .needed = m_csselr_needed, | ||
149 | + .fields = (VMStateField[]) { | ||
150 | + VMSTATE_UINT32_ARRAY(env.v7m.csselr, ARMCPU, M_REG_NUM_BANKS), | ||
151 | + VMSTATE_VALIDATE("CSSELR is valid", csselr_vmstate_validate), | ||
152 | + VMSTATE_END_OF_LIST() | ||
153 | + } | ||
154 | +}; | ||
155 | + | ||
156 | static const VMStateDescription vmstate_m = { | ||
157 | .name = "cpu/m", | ||
158 | .version_id = 4, | ||
159 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m = { | ||
160 | }, | ||
161 | .subsections = (const VMStateDescription*[]) { | ||
162 | &vmstate_m_faultmask_primask, | ||
163 | + &vmstate_m_csselr, | ||
164 | NULL | ||
165 | } | 119 | } |
166 | }; | 120 | return false; |
167 | -- | 121 | -- |
168 | 2.16.1 | 122 | 2.25.1 |
169 | |||
170 | diff view generated by jsdifflib |
1 | In commit abc24d86cc0364f we accidentally broke migration of | 1 | In get_level1_table_address(), instead of using precalculated values |
---|---|---|---|
2 | the stack pointer value for the mode (process, handler) the CPU | 2 | of mask and base_mask from the TCR struct, calculate them directly |
3 | is not currently running as. (The commit correctly removed the | 3 | (in the same way we currently do in vmsa_ttbcr_raw_write() to |
4 | no-longer-used v7m.current_sp flag from the VMState but also | 4 | populate the TCR struct fields). |
5 | deleted the still very much in use v7m.other_sp SP value field.) | ||
6 | |||
7 | Add a subsection to migrate it again. (We don't need to care | ||
8 | about trying to retain compatibility with pre-abc24d86cc0364f | ||
9 | versions of QEMU, because that commit bumped the version_id | ||
10 | and we've since bumped it again a couple of times.) | ||
11 | 5 | ||
12 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
14 | Message-id: 20180209165810.6668-11-peter.maydell@linaro.org | 8 | Message-id: 20220714132303.1287193-3-peter.maydell@linaro.org |
15 | --- | 9 | --- |
16 | target/arm/machine.c | 11 +++++++++++ | 10 | target/arm/ptw.c | 14 +++++++++----- |
17 | 1 file changed, 11 insertions(+) | 11 | 1 file changed, 9 insertions(+), 5 deletions(-) |
18 | 12 | ||
19 | diff --git a/target/arm/machine.c b/target/arm/machine.c | 13 | diff --git a/target/arm/ptw.c b/target/arm/ptw.c |
20 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/target/arm/machine.c | 15 | --- a/target/arm/ptw.c |
22 | +++ b/target/arm/machine.c | 16 | +++ b/target/arm/ptw.c |
23 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m_scr = { | 17 | @@ -XXX,XX +XXX,XX @@ static bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, |
18 | uint32_t *table, uint32_t address) | ||
19 | { | ||
20 | /* Note that we can only get here for an AArch32 PL0/PL1 lookup */ | ||
21 | - TCR *tcr = regime_tcr(env, mmu_idx); | ||
22 | + uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
23 | + int maskshift = extract32(tcr, 0, 3); | ||
24 | + uint32_t mask = ~(((uint32_t)0xffffffffu) >> maskshift); | ||
25 | + uint32_t base_mask; | ||
26 | |||
27 | - if (address & tcr->mask) { | ||
28 | - if (tcr->raw_tcr & TTBCR_PD1) { | ||
29 | + if (address & mask) { | ||
30 | + if (tcr & TTBCR_PD1) { | ||
31 | /* Translation table walk disabled for TTBR1 */ | ||
32 | return false; | ||
33 | } | ||
34 | *table = regime_ttbr(env, mmu_idx, 1) & 0xffffc000; | ||
35 | } else { | ||
36 | - if (tcr->raw_tcr & TTBCR_PD0) { | ||
37 | + if (tcr & TTBCR_PD0) { | ||
38 | /* Translation table walk disabled for TTBR0 */ | ||
39 | return false; | ||
40 | } | ||
41 | - *table = regime_ttbr(env, mmu_idx, 0) & tcr->base_mask; | ||
42 | + base_mask = ~((uint32_t)0x3fffu >> maskshift); | ||
43 | + *table = regime_ttbr(env, mmu_idx, 0) & base_mask; | ||
24 | } | 44 | } |
25 | }; | 45 | *table |= (address >> 18) & 0x3ffc; |
26 | 46 | return true; | |
27 | +static const VMStateDescription vmstate_m_other_sp = { | ||
28 | + .name = "cpu/m/other-sp", | ||
29 | + .version_id = 1, | ||
30 | + .minimum_version_id = 1, | ||
31 | + .fields = (VMStateField[]) { | ||
32 | + VMSTATE_UINT32(env.v7m.other_sp, ARMCPU), | ||
33 | + VMSTATE_END_OF_LIST() | ||
34 | + } | ||
35 | +}; | ||
36 | + | ||
37 | static const VMStateDescription vmstate_m = { | ||
38 | .name = "cpu/m", | ||
39 | .version_id = 4, | ||
40 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m = { | ||
41 | &vmstate_m_faultmask_primask, | ||
42 | &vmstate_m_csselr, | ||
43 | &vmstate_m_scr, | ||
44 | + &vmstate_m_other_sp, | ||
45 | NULL | ||
46 | } | ||
47 | }; | ||
48 | -- | 47 | -- |
49 | 2.16.1 | 48 | 2.25.1 |
50 | |||
51 | diff view generated by jsdifflib |
1 | The PENDNMISET/CLR bits in the ICSR should be RAZ/WI from | 1 | The only caller of regime_tcr() is now regime_tcr_value(); fold the |
---|---|---|---|
2 | NonSecure state if the AIRCR.BFHFNMINS bit is zero. We had | 2 | two together, and use the shorter and more natural 'regime_tcr' |
3 | misimplemented this as making the bits RAZ/WI from both | 3 | name for the new function. |
4 | Secure and NonSecure states. Fix this bug by checking | ||
5 | attrs.secure so that Secure code can pend and unpend NMIs. | ||
6 | 4 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Message-id: 20180209165810.6668-3-peter.maydell@linaro.org | 7 | Message-id: 20220714132303.1287193-4-peter.maydell@linaro.org |
10 | --- | 8 | --- |
11 | hw/intc/armv7m_nvic.c | 6 +++--- | 9 | target/arm/internals.h | 16 +++++----------- |
12 | 1 file changed, 3 insertions(+), 3 deletions(-) | 10 | target/arm/helper.c | 6 +++--- |
11 | target/arm/ptw.c | 6 +++--- | ||
12 | target/arm/tlb_helper.c | 2 +- | ||
13 | 4 files changed, 12 insertions(+), 18 deletions(-) | ||
13 | 14 | ||
14 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | 15 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
15 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/intc/armv7m_nvic.c | 17 | --- a/target/arm/internals.h |
17 | +++ b/hw/intc/armv7m_nvic.c | 18 | +++ b/target/arm/internals.h |
18 | @@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs) | 19 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx) |
19 | } | 20 | return env->cp15.sctlr_el[regime_el(env, mmu_idx)]; |
20 | } | 21 | } |
21 | /* NMIPENDSET */ | 22 | |
22 | - if ((cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) && | 23 | -/* Return the TCR controlling this translation regime */ |
23 | - s->vectors[ARMV7M_EXCP_NMI].pending) { | 24 | -static inline TCR *regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
24 | + if ((attrs.secure || (cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK)) | 25 | +/* Return the value of the TCR controlling this translation regime */ |
25 | + && s->vectors[ARMV7M_EXCP_NMI].pending) { | 26 | +static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
26 | val |= (1 << 31); | 27 | { |
27 | } | 28 | if (mmu_idx == ARMMMUIdx_Stage2) { |
28 | /* ISRPREEMPT: RES0 when halting debug not implemented */ | 29 | - return &env->cp15.vtcr_el2; |
29 | @@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value, | 30 | + return env->cp15.vtcr_el2.raw_tcr; |
30 | break; | ||
31 | } | 31 | } |
32 | case 0xd04: /* Interrupt Control State (ICSR) */ | 32 | if (mmu_idx == ARMMMUIdx_Stage2_S) { |
33 | - if (cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) { | 33 | /* |
34 | + if (attrs.secure || cpu->env.v7m.aircr & R_V7M_AIRCR_BFHFNMINS_MASK) { | 34 | * Note: Secure stage 2 nominally shares fields from VTCR_EL2, but |
35 | if (value & (1 << 31)) { | 35 | * those are not currently used by QEMU, so just return VSTCR_EL2. |
36 | armv7m_nvic_set_pending(s, ARMV7M_EXCP_NMI, false); | 36 | */ |
37 | } else if (value & (1 << 30) && | 37 | - return &env->cp15.vstcr_el2; |
38 | + return env->cp15.vstcr_el2.raw_tcr; | ||
39 | } | ||
40 | - return &env->cp15.tcr_el[regime_el(env, mmu_idx)]; | ||
41 | -} | ||
42 | - | ||
43 | -/* Return the raw value of the TCR controlling this translation regime */ | ||
44 | -static inline uint64_t regime_tcr_value(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
45 | -{ | ||
46 | - return regime_tcr(env, mmu_idx)->raw_tcr; | ||
47 | + return env->cp15.tcr_el[regime_el(env, mmu_idx)].raw_tcr; | ||
48 | } | ||
49 | |||
50 | /** | ||
51 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
52 | index XXXXXXX..XXXXXXX 100644 | ||
53 | --- a/target/arm/helper.c | ||
54 | +++ b/target/arm/helper.c | ||
55 | @@ -XXX,XX +XXX,XX @@ static int vae1_tlbmask(CPUARMState *env) | ||
56 | static int tlbbits_for_regime(CPUARMState *env, ARMMMUIdx mmu_idx, | ||
57 | uint64_t addr) | ||
58 | { | ||
59 | - uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
60 | + uint64_t tcr = regime_tcr(env, mmu_idx); | ||
61 | int tbi = aa64_va_parameter_tbi(tcr, mmu_idx); | ||
62 | int select = extract64(addr, 55, 1); | ||
63 | |||
64 | @@ -XXX,XX +XXX,XX @@ static int aa64_va_parameter_tcma(uint64_t tcr, ARMMMUIdx mmu_idx) | ||
65 | ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, | ||
66 | ARMMMUIdx mmu_idx, bool data) | ||
67 | { | ||
68 | - uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
69 | + uint64_t tcr = regime_tcr(env, mmu_idx); | ||
70 | bool epd, hpd, using16k, using64k, tsz_oob, ds; | ||
71 | int select, tsz, tbi, max_tsz, min_tsz, ps, sh; | ||
72 | ARMCPU *cpu = env_archcpu(env); | ||
73 | @@ -XXX,XX +XXX,XX @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, | ||
74 | { | ||
75 | CPUARMTBFlags flags = {}; | ||
76 | ARMMMUIdx stage1 = stage_1_mmu_idx(mmu_idx); | ||
77 | - uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
78 | + uint64_t tcr = regime_tcr(env, mmu_idx); | ||
79 | uint64_t sctlr; | ||
80 | int tbii, tbid; | ||
81 | |||
82 | diff --git a/target/arm/ptw.c b/target/arm/ptw.c | ||
83 | index XXXXXXX..XXXXXXX 100644 | ||
84 | --- a/target/arm/ptw.c | ||
85 | +++ b/target/arm/ptw.c | ||
86 | @@ -XXX,XX +XXX,XX @@ static bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, | ||
87 | uint32_t *table, uint32_t address) | ||
88 | { | ||
89 | /* Note that we can only get here for an AArch32 PL0/PL1 lookup */ | ||
90 | - uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
91 | + uint64_t tcr = regime_tcr(env, mmu_idx); | ||
92 | int maskshift = extract32(tcr, 0, 3); | ||
93 | uint32_t mask = ~(((uint32_t)0xffffffffu) >> maskshift); | ||
94 | uint32_t base_mask; | ||
95 | @@ -XXX,XX +XXX,XX @@ static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, | ||
96 | static ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, | ||
97 | ARMMMUIdx mmu_idx) | ||
98 | { | ||
99 | - uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
100 | + uint64_t tcr = regime_tcr(env, mmu_idx); | ||
101 | uint32_t el = regime_el(env, mmu_idx); | ||
102 | int select, tsz; | ||
103 | bool epd, hpd; | ||
104 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, | ||
105 | uint32_t attrs; | ||
106 | int32_t stride; | ||
107 | int addrsize, inputsize, outputsize; | ||
108 | - uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
109 | + uint64_t tcr = regime_tcr(env, mmu_idx); | ||
110 | int ap, ns, xn, pxn; | ||
111 | uint32_t el = regime_el(env, mmu_idx); | ||
112 | uint64_t descaddrmask; | ||
113 | diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c | ||
114 | index XXXXXXX..XXXXXXX 100644 | ||
115 | --- a/target/arm/tlb_helper.c | ||
116 | +++ b/target/arm/tlb_helper.c | ||
117 | @@ -XXX,XX +XXX,XX @@ bool regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
118 | return true; | ||
119 | } | ||
120 | if (arm_feature(env, ARM_FEATURE_LPAE) | ||
121 | - && (regime_tcr_value(env, mmu_idx) & TTBCR_EAE)) { | ||
122 | + && (regime_tcr(env, mmu_idx) & TTBCR_EAE)) { | ||
123 | return true; | ||
124 | } | ||
125 | return false; | ||
38 | -- | 126 | -- |
39 | 2.16.1 | 127 | 2.25.1 |
40 | |||
41 | diff view generated by jsdifflib |
1 | In commit 50f11062d4c896 we added support for MSR/MRS access | 1 | We have a bug in our handling of accesses to the AArch32 VTCR |
---|---|---|---|
2 | to the NS banked special registers, but we forgot to implement | 2 | register on big-endian hosts: we were not adjusting the part of the |
3 | the support for writing to CONTROL_NS. Correct the omission. | 3 | uint64_t field within TCR that the generated code would access. That |
4 | can be done with offsetoflow32(), by using an ARM_CP_STATE_BOTH cpreg | ||
5 | struct, or by defining a full set of read/write/reset functions -- | ||
6 | the various other TCR cpreg structs used one or another of those | ||
7 | strategies, but for VTCR we did not, so on a big-endian host VTCR | ||
8 | accesses would touch the wrong half of the register. | ||
9 | |||
10 | Use offsetoflow32() in the VTCR register struct. This works even | ||
11 | though the field in the CPU struct is currently a struct TCR, because | ||
12 | the first field in that struct is the uint64_t raw_tcr. | ||
13 | |||
14 | None of the other TCR registers have this bug -- either they are | ||
15 | AArch64 only, or else they define resetfn, writefn, etc, and | ||
16 | expect to be passed the full struct pointer. | ||
4 | 17 | ||
5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 19 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20180209165810.6668-8-peter.maydell@linaro.org | 20 | Message-id: 20220714132303.1287193-5-peter.maydell@linaro.org |
8 | --- | 21 | --- |
9 | target/arm/helper.c | 10 ++++++++++ | 22 | target/arm/helper.c | 2 +- |
10 | 1 file changed, 10 insertions(+) | 23 | 1 file changed, 1 insertion(+), 1 deletion(-) |
11 | 24 | ||
12 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 25 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
13 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/target/arm/helper.c | 27 | --- a/target/arm/helper.c |
15 | +++ b/target/arm/helper.c | 28 | +++ b/target/arm/helper.c |
16 | @@ -XXX,XX +XXX,XX @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val) | 29 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = { |
17 | } | 30 | .cp = 15, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, |
18 | env->v7m.faultmask[M_REG_NS] = val & 1; | 31 | .type = ARM_CP_ALIAS, |
19 | return; | 32 | .access = PL2_RW, .accessfn = access_el3_aa32ns, |
20 | + case 0x94: /* CONTROL_NS */ | 33 | - .fieldoffset = offsetof(CPUARMState, cp15.vtcr_el2) }, |
21 | + if (!env->v7m.secure) { | 34 | + .fieldoffset = offsetoflow32(CPUARMState, cp15.vtcr_el2) }, |
22 | + return; | 35 | { .name = "VTCR_EL2", .state = ARM_CP_STATE_AA64, |
23 | + } | 36 | .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, |
24 | + write_v7m_control_spsel_for_secstate(env, | 37 | .access = PL2_RW, |
25 | + val & R_V7M_CONTROL_SPSEL_MASK, | ||
26 | + M_REG_NS); | ||
27 | + env->v7m.control[M_REG_NS] &= ~R_V7M_CONTROL_NPRIV_MASK; | ||
28 | + env->v7m.control[M_REG_NS] |= val & R_V7M_CONTROL_NPRIV_MASK; | ||
29 | + return; | ||
30 | case 0x98: /* SP_NS */ | ||
31 | { | ||
32 | /* This gives the non-secure SP selected based on whether we're | ||
33 | -- | 38 | -- |
34 | 2.16.1 | 39 | 2.25.1 |
35 | |||
36 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | Change the representation of the VSTCR_EL2 and VTCR_EL2 registers in |
---|---|---|---|
2 | the CPU state struct from struct TCR to uint64_t. | ||
2 | 3 | ||
3 | This also makes sure that we get the correct ordering of | ||
4 | SVE vs FP exceptions. | ||
5 | |||
6 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
7 | Message-id: 20180211205848.4568-5-richard.henderson@linaro.org | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 4 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
5 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
6 | Message-id: 20220714132303.1287193-6-peter.maydell@linaro.org | ||
10 | --- | 7 | --- |
11 | target/arm/cpu.h | 3 ++- | 8 | target/arm/cpu.h | 4 ++-- |
12 | target/arm/internals.h | 6 ++++++ | 9 | target/arm/internals.h | 4 ++-- |
13 | target/arm/helper.c | 22 ++++------------------ | 10 | target/arm/helper.c | 4 +--- |
14 | target/arm/translate-a64.c | 16 ++++++++++++++++ | 11 | target/arm/ptw.c | 14 +++++++------- |
15 | 4 files changed, 28 insertions(+), 19 deletions(-) | 12 | 4 files changed, 12 insertions(+), 14 deletions(-) |
16 | 13 | ||
17 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 14 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
18 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
19 | --- a/target/arm/cpu.h | 16 | --- a/target/arm/cpu.h |
20 | +++ b/target/arm/cpu.h | 17 | +++ b/target/arm/cpu.h |
21 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t cpreg_to_kvm_id(uint32_t cpregid) | 18 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState { |
22 | #define ARM_CP_DC_ZVA (ARM_CP_SPECIAL | 0x0500) | 19 | uint64_t vsttbr_el2; /* Secure Virtualization Translation Table. */ |
23 | #define ARM_LAST_SPECIAL ARM_CP_DC_ZVA | 20 | /* MMU translation table base control. */ |
24 | #define ARM_CP_FPU 0x1000 | 21 | TCR tcr_el[4]; |
25 | +#define ARM_CP_SVE 0x2000 | 22 | - TCR vtcr_el2; /* Virtualization Translation Control. */ |
26 | /* Used only as a terminator for ARMCPRegInfo lists */ | 23 | - TCR vstcr_el2; /* Secure Virtualization Translation Control. */ |
27 | #define ARM_CP_SENTINEL 0xffff | 24 | + uint64_t vtcr_el2; /* Virtualization Translation Control. */ |
28 | /* Mask of only the flag bits in a type field */ | 25 | + uint64_t vstcr_el2; /* Secure Virtualization Translation Control. */ |
29 | -#define ARM_CP_FLAG_MASK 0x10ff | 26 | uint32_t c2_data; /* MPU data cacheable bits. */ |
30 | +#define ARM_CP_FLAG_MASK 0x30ff | 27 | uint32_t c2_insn; /* MPU instruction cacheable bits. */ |
31 | 28 | union { /* MMU domain access control register | |
32 | /* Valid values for ARMCPRegInfo state field, indicating which of | ||
33 | * the AArch32 and AArch64 execution states this register is visible in. | ||
34 | diff --git a/target/arm/internals.h b/target/arm/internals.h | 29 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
35 | index XXXXXXX..XXXXXXX 100644 | 30 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/target/arm/internals.h | 31 | --- a/target/arm/internals.h |
37 | +++ b/target/arm/internals.h | 32 | +++ b/target/arm/internals.h |
38 | @@ -XXX,XX +XXX,XX @@ enum arm_exception_class { | 33 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx) |
39 | EC_AA64_HVC = 0x16, | 34 | static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
40 | EC_AA64_SMC = 0x17, | 35 | { |
41 | EC_SYSTEMREGISTERTRAP = 0x18, | 36 | if (mmu_idx == ARMMMUIdx_Stage2) { |
42 | + EC_SVEACCESSTRAP = 0x19, | 37 | - return env->cp15.vtcr_el2.raw_tcr; |
43 | EC_INSNABORT = 0x20, | 38 | + return env->cp15.vtcr_el2; |
44 | EC_INSNABORT_SAME_EL = 0x21, | 39 | } |
45 | EC_PCALIGNMENT = 0x22, | 40 | if (mmu_idx == ARMMMUIdx_Stage2_S) { |
46 | @@ -XXX,XX +XXX,XX @@ static inline uint32_t syn_fp_access_trap(int cv, int cond, bool is_16bit) | 41 | /* |
47 | | (cv << 24) | (cond << 20); | 42 | * Note: Secure stage 2 nominally shares fields from VTCR_EL2, but |
43 | * those are not currently used by QEMU, so just return VSTCR_EL2. | ||
44 | */ | ||
45 | - return env->cp15.vstcr_el2.raw_tcr; | ||
46 | + return env->cp15.vstcr_el2; | ||
47 | } | ||
48 | return env->cp15.tcr_el[regime_el(env, mmu_idx)].raw_tcr; | ||
48 | } | 49 | } |
49 | |||
50 | +static inline uint32_t syn_sve_access_trap(void) | ||
51 | +{ | ||
52 | + return EC_SVEACCESSTRAP << ARM_EL_EC_SHIFT; | ||
53 | +} | ||
54 | + | ||
55 | static inline uint32_t syn_insn_abort(int same_el, int ea, int s1ptw, int fsc) | ||
56 | { | ||
57 | return (EC_INSNABORT << ARM_EL_EC_SHIFT) | (same_el << ARM_EL_EC_SHIFT) | ||
58 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 50 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
59 | index XXXXXXX..XXXXXXX 100644 | 51 | index XXXXXXX..XXXXXXX 100644 |
60 | --- a/target/arm/helper.c | 52 | --- a/target/arm/helper.c |
61 | +++ b/target/arm/helper.c | 53 | +++ b/target/arm/helper.c |
62 | @@ -XXX,XX +XXX,XX @@ static int sve_exception_el(CPUARMState *env) | 54 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = { |
63 | return 0; | 55 | { .name = "VTCR_EL2", .state = ARM_CP_STATE_AA64, |
64 | } | 56 | .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, |
65 | 57 | .access = PL2_RW, | |
66 | -static CPAccessResult zcr_access(CPUARMState *env, const ARMCPRegInfo *ri, | 58 | - /* no .writefn needed as this can't cause an ASID change; |
67 | - bool isread) | 59 | - * no .raw_writefn or .resetfn needed as we never use mask/base_mask |
68 | -{ | 60 | - */ |
69 | - switch (sve_exception_el(env)) { | 61 | + /* no .writefn needed as this can't cause an ASID change */ |
70 | - case 3: | 62 | .fieldoffset = offsetof(CPUARMState, cp15.vtcr_el2) }, |
71 | - return CP_ACCESS_TRAP_EL3; | 63 | { .name = "VTTBR", .state = ARM_CP_STATE_AA32, |
72 | - case 2: | 64 | .cp = 15, .opc1 = 6, .crm = 2, |
73 | - return CP_ACCESS_TRAP_EL2; | 65 | diff --git a/target/arm/ptw.c b/target/arm/ptw.c |
74 | - case 1: | ||
75 | - return CP_ACCESS_TRAP; | ||
76 | - } | ||
77 | - return CP_ACCESS_OK; | ||
78 | -} | ||
79 | - | ||
80 | static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
81 | uint64_t value) | ||
82 | { | ||
83 | @@ -XXX,XX +XXX,XX @@ static void zcr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
84 | static const ARMCPRegInfo zcr_el1_reginfo = { | ||
85 | .name = "ZCR_EL1", .state = ARM_CP_STATE_AA64, | ||
86 | .opc0 = 3, .opc1 = 0, .crn = 1, .crm = 2, .opc2 = 0, | ||
87 | - .access = PL1_RW, .accessfn = zcr_access, | ||
88 | + .access = PL1_RW, .type = ARM_CP_SVE | ARM_CP_FPU, | ||
89 | .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[1]), | ||
90 | .writefn = zcr_write, .raw_writefn = raw_write | ||
91 | }; | ||
92 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo zcr_el1_reginfo = { | ||
93 | static const ARMCPRegInfo zcr_el2_reginfo = { | ||
94 | .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, | ||
95 | .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, | ||
96 | - .access = PL2_RW, .accessfn = zcr_access, | ||
97 | + .access = PL2_RW, .type = ARM_CP_SVE | ARM_CP_FPU, | ||
98 | .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[2]), | ||
99 | .writefn = zcr_write, .raw_writefn = raw_write | ||
100 | }; | ||
101 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo zcr_el2_reginfo = { | ||
102 | static const ARMCPRegInfo zcr_no_el2_reginfo = { | ||
103 | .name = "ZCR_EL2", .state = ARM_CP_STATE_AA64, | ||
104 | .opc0 = 3, .opc1 = 4, .crn = 1, .crm = 2, .opc2 = 0, | ||
105 | - .access = PL2_RW, | ||
106 | + .access = PL2_RW, .type = ARM_CP_SVE | ARM_CP_FPU, | ||
107 | .readfn = arm_cp_read_zero, .writefn = arm_cp_write_ignore | ||
108 | }; | ||
109 | |||
110 | static const ARMCPRegInfo zcr_el3_reginfo = { | ||
111 | .name = "ZCR_EL3", .state = ARM_CP_STATE_AA64, | ||
112 | .opc0 = 3, .opc1 = 6, .crn = 1, .crm = 2, .opc2 = 0, | ||
113 | - .access = PL3_RW, .accessfn = zcr_access, | ||
114 | + .access = PL3_RW, .type = ARM_CP_SVE | ARM_CP_FPU, | ||
115 | .fieldoffset = offsetof(CPUARMState, vfp.zcr_el[3]), | ||
116 | .writefn = zcr_write, .raw_writefn = raw_write | ||
117 | }; | ||
118 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | ||
119 | index XXXXXXX..XXXXXXX 100644 | 66 | index XXXXXXX..XXXXXXX 100644 |
120 | --- a/target/arm/translate-a64.c | 67 | --- a/target/arm/ptw.c |
121 | +++ b/target/arm/translate-a64.c | 68 | +++ b/target/arm/ptw.c |
122 | @@ -XXX,XX +XXX,XX @@ static inline bool fp_access_check(DisasContext *s) | 69 | @@ -XXX,XX +XXX,XX @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, |
123 | return false; | 70 | if (arm_is_secure_below_el3(env)) { |
124 | } | 71 | /* Check if page table walk is to secure or non-secure PA space. */ |
125 | 72 | if (*is_secure) { | |
126 | +/* Check that SVE access is enabled. If it is, return true. | 73 | - *is_secure = !(env->cp15.vstcr_el2.raw_tcr & VSTCR_SW); |
127 | + * If not, emit code to generate an appropriate exception and return false. | 74 | + *is_secure = !(env->cp15.vstcr_el2 & VSTCR_SW); |
128 | + */ | 75 | } else { |
129 | +static inline bool sve_access_check(DisasContext *s) | 76 | - *is_secure = !(env->cp15.vtcr_el2.raw_tcr & VTCR_NSW); |
130 | +{ | 77 | + *is_secure = !(env->cp15.vtcr_el2 & VTCR_NSW); |
131 | + if (s->sve_excp_el) { | 78 | } |
132 | + gen_exception_insn(s, 4, EXCP_UDEF, syn_sve_access_trap(), | 79 | } else { |
133 | + s->sve_excp_el); | 80 | assert(!*is_secure); |
134 | + return false; | 81 | @@ -XXX,XX +XXX,XX @@ bool get_phys_addr(CPUARMState *env, target_ulong address, |
135 | + } | 82 | ipa_secure = attrs->secure; |
136 | + return true; | 83 | if (arm_is_secure_below_el3(env)) { |
137 | +} | 84 | if (ipa_secure) { |
138 | + | 85 | - attrs->secure = !(env->cp15.vstcr_el2.raw_tcr & VSTCR_SW); |
139 | /* | 86 | + attrs->secure = !(env->cp15.vstcr_el2 & VSTCR_SW); |
140 | * This utility function is for doing register extension with an | 87 | } else { |
141 | * optional shift. You will likely want to pass a temporary for the | 88 | - attrs->secure = !(env->cp15.vtcr_el2.raw_tcr & VTCR_NSW); |
142 | @@ -XXX,XX +XXX,XX @@ static void handle_sys(DisasContext *s, uint32_t insn, bool isread, | 89 | + attrs->secure = !(env->cp15.vtcr_el2 & VTCR_NSW); |
143 | default: | 90 | } |
144 | break; | 91 | } else { |
145 | } | 92 | assert(!ipa_secure); |
146 | + if ((ri->type & ARM_CP_SVE) && !sve_access_check(s)) { | 93 | @@ -XXX,XX +XXX,XX @@ bool get_phys_addr(CPUARMState *env, target_ulong address, |
147 | + return; | 94 | if (arm_is_secure_below_el3(env)) { |
148 | + } | 95 | if (ipa_secure) { |
149 | if ((ri->type & ARM_CP_FPU) && !fp_access_check(s)) { | 96 | attrs->secure = |
150 | return; | 97 | - !(env->cp15.vstcr_el2.raw_tcr & (VSTCR_SA | VSTCR_SW)); |
151 | } | 98 | + !(env->cp15.vstcr_el2 & (VSTCR_SA | VSTCR_SW)); |
99 | } else { | ||
100 | attrs->secure = | ||
101 | - !((env->cp15.vtcr_el2.raw_tcr & (VTCR_NSA | VTCR_NSW)) | ||
102 | - || (env->cp15.vstcr_el2.raw_tcr & (VSTCR_SA | VSTCR_SW))); | ||
103 | + !((env->cp15.vtcr_el2 & (VTCR_NSA | VTCR_NSW)) | ||
104 | + || (env->cp15.vstcr_el2 & (VSTCR_SA | VSTCR_SW))); | ||
105 | } | ||
106 | } | ||
107 | return 0; | ||
152 | -- | 108 | -- |
153 | 2.16.1 | 109 | 2.25.1 |
154 | |||
155 | diff view generated by jsdifflib |
1 | The v8M architecture includes hardware support for enforcing | 1 | Change the representation of the TCR_EL* registers in the CPU state |
---|---|---|---|
2 | stack pointer limits. We don't implement this behaviour yet, | 2 | struct from struct TCR to uint64_t. This allows us to drop the |
3 | but provide the MSPLIM and PSPLIM stack pointer limit registers | 3 | custom vmsa_ttbcr_raw_write() function, moving the "enforce RES0" |
4 | as reads-as-written, so that when we do implement the checks | 4 | checks to their more usual location in the writefn |
5 | in future this won't break guest migration. | 5 | vmsa_ttbcr_write(). We also don't need the resetfn any more. |
6 | 6 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
9 | Message-id: 20180209165810.6668-12-peter.maydell@linaro.org | 9 | Message-id: 20220714132303.1287193-7-peter.maydell@linaro.org |
10 | --- | 10 | --- |
11 | target/arm/cpu.h | 2 ++ | 11 | target/arm/cpu.h | 8 +---- |
12 | target/arm/helper.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ | 12 | target/arm/internals.h | 6 ++-- |
13 | target/arm/machine.c | 21 +++++++++++++++++++++ | 13 | target/arm/cpu.c | 2 +- |
14 | 3 files changed, 69 insertions(+) | 14 | target/arm/debug_helper.c | 2 +- |
15 | target/arm/helper.c | 75 +++++++++++---------------------------- | ||
16 | target/arm/ptw.c | 2 +- | ||
17 | 6 files changed, 27 insertions(+), 68 deletions(-) | ||
15 | 18 | ||
16 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 19 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
17 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/target/arm/cpu.h | 21 | --- a/target/arm/cpu.h |
19 | +++ b/target/arm/cpu.h | 22 | +++ b/target/arm/cpu.h |
20 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | 23 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMGenericTimer { |
21 | uint32_t secure; /* Is CPU in Secure state? (not guest visible) */ | 24 | #define GTIMER_HYPVIRT 4 |
22 | uint32_t csselr[M_REG_NUM_BANKS]; | 25 | #define NUM_GTIMERS 5 |
23 | uint32_t scr[M_REG_NUM_BANKS]; | 26 | |
24 | + uint32_t msplim[M_REG_NUM_BANKS]; | 27 | -typedef struct { |
25 | + uint32_t psplim[M_REG_NUM_BANKS]; | 28 | - uint64_t raw_tcr; |
26 | } v7m; | 29 | - uint32_t mask; |
27 | 30 | - uint32_t base_mask; | |
28 | /* Information associated with an exception about to be taken: | 31 | -} TCR; |
32 | - | ||
33 | #define VTCR_NSW (1u << 29) | ||
34 | #define VTCR_NSA (1u << 30) | ||
35 | #define VSTCR_SW VTCR_NSW | ||
36 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState { | ||
37 | uint64_t vttbr_el2; /* Virtualization Translation Table Base. */ | ||
38 | uint64_t vsttbr_el2; /* Secure Virtualization Translation Table. */ | ||
39 | /* MMU translation table base control. */ | ||
40 | - TCR tcr_el[4]; | ||
41 | + uint64_t tcr_el[4]; | ||
42 | uint64_t vtcr_el2; /* Virtualization Translation Control. */ | ||
43 | uint64_t vstcr_el2; /* Secure Virtualization Translation Control. */ | ||
44 | uint32_t c2_data; /* MPU data cacheable bits. */ | ||
45 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
46 | index XXXXXXX..XXXXXXX 100644 | ||
47 | --- a/target/arm/internals.h | ||
48 | +++ b/target/arm/internals.h | ||
49 | @@ -XXX,XX +XXX,XX @@ unsigned int arm_pamax(ARMCPU *cpu); | ||
50 | */ | ||
51 | static inline bool extended_addresses_enabled(CPUARMState *env) | ||
52 | { | ||
53 | - TCR *tcr = &env->cp15.tcr_el[arm_is_secure(env) ? 3 : 1]; | ||
54 | + uint64_t tcr = env->cp15.tcr_el[arm_is_secure(env) ? 3 : 1]; | ||
55 | return arm_el_is_aa64(env, 1) || | ||
56 | - (arm_feature(env, ARM_FEATURE_LPAE) && (tcr->raw_tcr & TTBCR_EAE)); | ||
57 | + (arm_feature(env, ARM_FEATURE_LPAE) && (tcr & TTBCR_EAE)); | ||
58 | } | ||
59 | |||
60 | /* Update a QEMU watchpoint based on the information the guest has set in the | ||
61 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
62 | */ | ||
63 | return env->cp15.vstcr_el2; | ||
64 | } | ||
65 | - return env->cp15.tcr_el[regime_el(env, mmu_idx)].raw_tcr; | ||
66 | + return env->cp15.tcr_el[regime_el(env, mmu_idx)]; | ||
67 | } | ||
68 | |||
69 | /** | ||
70 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/target/arm/cpu.c | ||
73 | +++ b/target/arm/cpu.c | ||
74 | @@ -XXX,XX +XXX,XX @@ static void arm_cpu_reset(DeviceState *dev) | ||
75 | * Enable TBI0 but not TBI1. | ||
76 | * Note that this must match useronly_clean_ptr. | ||
77 | */ | ||
78 | - env->cp15.tcr_el[1].raw_tcr = 5 | (1ULL << 37); | ||
79 | + env->cp15.tcr_el[1] = 5 | (1ULL << 37); | ||
80 | |||
81 | /* Enable MTE */ | ||
82 | if (cpu_isar_feature(aa64_mte, cpu)) { | ||
83 | diff --git a/target/arm/debug_helper.c b/target/arm/debug_helper.c | ||
84 | index XXXXXXX..XXXXXXX 100644 | ||
85 | --- a/target/arm/debug_helper.c | ||
86 | +++ b/target/arm/debug_helper.c | ||
87 | @@ -XXX,XX +XXX,XX @@ static uint32_t arm_debug_exception_fsr(CPUARMState *env) | ||
88 | using_lpae = true; | ||
89 | } else { | ||
90 | if (arm_feature(env, ARM_FEATURE_LPAE) && | ||
91 | - (env->cp15.tcr_el[target_el].raw_tcr & TTBCR_EAE)) { | ||
92 | + (env->cp15.tcr_el[target_el] & TTBCR_EAE)) { | ||
93 | using_lpae = true; | ||
94 | } | ||
95 | } | ||
29 | diff --git a/target/arm/helper.c b/target/arm/helper.c | 96 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
30 | index XXXXXXX..XXXXXXX 100644 | 97 | index XXXXXXX..XXXXXXX 100644 |
31 | --- a/target/arm/helper.c | 98 | --- a/target/arm/helper.c |
32 | +++ b/target/arm/helper.c | 99 | +++ b/target/arm/helper.c |
33 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg) | 100 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo pmsav5_cp_reginfo[] = { |
34 | return 0; | 101 | .fieldoffset = offsetof(CPUARMState, cp15.c6_region[7]) }, |
35 | } | 102 | }; |
36 | return env->v7m.other_ss_psp; | 103 | |
37 | + case 0x8a: /* MSPLIM_NS */ | 104 | -static void vmsa_ttbcr_raw_write(CPUARMState *env, const ARMCPRegInfo *ri, |
38 | + if (!env->v7m.secure) { | 105 | - uint64_t value) |
39 | + return 0; | 106 | +static void vmsa_ttbcr_write(CPUARMState *env, const ARMCPRegInfo *ri, |
40 | + } | 107 | + uint64_t value) |
41 | + return env->v7m.msplim[M_REG_NS]; | 108 | { |
42 | + case 0x8b: /* PSPLIM_NS */ | 109 | - TCR *tcr = raw_ptr(env, ri); |
43 | + if (!env->v7m.secure) { | 110 | - int maskshift = extract32(value, 0, 3); |
44 | + return 0; | 111 | + ARMCPU *cpu = env_archcpu(env); |
45 | + } | 112 | |
46 | + return env->v7m.psplim[M_REG_NS]; | 113 | if (!arm_feature(env, ARM_FEATURE_V8)) { |
47 | case 0x90: /* PRIMASK_NS */ | 114 | if (arm_feature(env, ARM_FEATURE_LPAE) && (value & TTBCR_EAE)) { |
48 | if (!env->v7m.secure) { | 115 | - /* Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when |
49 | return 0; | 116 | - * using Long-desciptor translation table format */ |
50 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg) | 117 | + /* |
51 | return v7m_using_psp(env) ? env->v7m.other_sp : env->regs[13]; | 118 | + * Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when |
52 | case 9: /* PSP */ | 119 | + * using Long-descriptor translation table format |
53 | return v7m_using_psp(env) ? env->regs[13] : env->v7m.other_sp; | 120 | + */ |
54 | + case 10: /* MSPLIM */ | 121 | value &= ~((7 << 19) | (3 << 14) | (0xf << 3)); |
55 | + if (!arm_feature(env, ARM_FEATURE_V8)) { | 122 | } else if (arm_feature(env, ARM_FEATURE_EL3)) { |
56 | + goto bad_reg; | 123 | - /* In an implementation that includes the Security Extensions |
57 | + } | 124 | + /* |
58 | + return env->v7m.msplim[env->v7m.secure]; | 125 | + * In an implementation that includes the Security Extensions |
59 | + case 11: /* PSPLIM */ | 126 | * TTBCR has additional fields PD0 [4] and PD1 [5] for |
60 | + if (!arm_feature(env, ARM_FEATURE_V8)) { | 127 | * Short-descriptor translation table format. |
61 | + goto bad_reg; | 128 | */ |
62 | + } | 129 | @@ -XXX,XX +XXX,XX @@ static void vmsa_ttbcr_raw_write(CPUARMState *env, const ARMCPRegInfo *ri, |
63 | + return env->v7m.psplim[env->v7m.secure]; | ||
64 | case 16: /* PRIMASK */ | ||
65 | return env->v7m.primask[env->v7m.secure]; | ||
66 | case 17: /* BASEPRI */ | ||
67 | @@ -XXX,XX +XXX,XX @@ uint32_t HELPER(v7m_mrs)(CPUARMState *env, uint32_t reg) | ||
68 | case 19: /* FAULTMASK */ | ||
69 | return env->v7m.faultmask[env->v7m.secure]; | ||
70 | default: | ||
71 | + bad_reg: | ||
72 | qemu_log_mask(LOG_GUEST_ERROR, "Attempt to read unknown special" | ||
73 | " register %d\n", reg); | ||
74 | return 0; | ||
75 | @@ -XXX,XX +XXX,XX @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val) | ||
76 | } | ||
77 | env->v7m.other_ss_psp = val; | ||
78 | return; | ||
79 | + case 0x8a: /* MSPLIM_NS */ | ||
80 | + if (!env->v7m.secure) { | ||
81 | + return; | ||
82 | + } | ||
83 | + env->v7m.msplim[M_REG_NS] = val & ~7; | ||
84 | + return; | ||
85 | + case 0x8b: /* PSPLIM_NS */ | ||
86 | + if (!env->v7m.secure) { | ||
87 | + return; | ||
88 | + } | ||
89 | + env->v7m.psplim[M_REG_NS] = val & ~7; | ||
90 | + return; | ||
91 | case 0x90: /* PRIMASK_NS */ | ||
92 | if (!env->v7m.secure) { | ||
93 | return; | ||
94 | @@ -XXX,XX +XXX,XX @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val) | ||
95 | env->v7m.other_sp = val; | ||
96 | } | 130 | } |
97 | break; | 131 | } |
98 | + case 10: /* MSPLIM */ | 132 | |
99 | + if (!arm_feature(env, ARM_FEATURE_V8)) { | 133 | - /* Update the masks corresponding to the TCR bank being written |
100 | + goto bad_reg; | 134 | - * Note that we always calculate mask and base_mask, but |
101 | + } | 135 | - * they are only used for short-descriptor tables (ie if EAE is 0); |
102 | + env->v7m.msplim[env->v7m.secure] = val & ~7; | 136 | - * for long-descriptor tables the TCR fields are used differently |
103 | + break; | 137 | - * and the mask and base_mask values are meaningless. |
104 | + case 11: /* PSPLIM */ | 138 | - */ |
105 | + if (!arm_feature(env, ARM_FEATURE_V8)) { | 139 | - tcr->raw_tcr = value; |
106 | + goto bad_reg; | 140 | - tcr->mask = ~(((uint32_t)0xffffffffu) >> maskshift); |
107 | + } | 141 | - tcr->base_mask = ~((uint32_t)0x3fffu >> maskshift); |
108 | + env->v7m.psplim[env->v7m.secure] = val & ~7; | 142 | -} |
109 | + break; | 143 | - |
110 | case 16: /* PRIMASK */ | 144 | -static void vmsa_ttbcr_write(CPUARMState *env, const ARMCPRegInfo *ri, |
111 | env->v7m.primask[env->v7m.secure] = val & 1; | 145 | - uint64_t value) |
112 | break; | 146 | -{ |
113 | @@ -XXX,XX +XXX,XX @@ void HELPER(v7m_msr)(CPUARMState *env, uint32_t maskreg, uint32_t val) | 147 | - ARMCPU *cpu = env_archcpu(env); |
114 | env->v7m.control[env->v7m.secure] |= val & R_V7M_CONTROL_NPRIV_MASK; | 148 | - TCR *tcr = raw_ptr(env, ri); |
115 | break; | 149 | - |
116 | default: | 150 | if (arm_feature(env, ARM_FEATURE_LPAE)) { |
117 | + bad_reg: | 151 | /* With LPAE the TTBCR could result in a change of ASID |
118 | qemu_log_mask(LOG_GUEST_ERROR, "Attempt to write unknown special" | 152 | * via the TTBCR.A1 bit, so do a TLB flush. |
119 | " register %d\n", reg); | 153 | */ |
120 | return; | 154 | tlb_flush(CPU(cpu)); |
121 | diff --git a/target/arm/machine.c b/target/arm/machine.c | 155 | } |
122 | index XXXXXXX..XXXXXXX 100644 | 156 | - /* Preserve the high half of TCR_EL1, set via TTBCR2. */ |
123 | --- a/target/arm/machine.c | 157 | - value = deposit64(tcr->raw_tcr, 0, 32, value); |
124 | +++ b/target/arm/machine.c | 158 | - vmsa_ttbcr_raw_write(env, ri, value); |
125 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m_other_sp = { | 159 | -} |
126 | } | 160 | - |
161 | -static void vmsa_ttbcr_reset(CPUARMState *env, const ARMCPRegInfo *ri) | ||
162 | -{ | ||
163 | - TCR *tcr = raw_ptr(env, ri); | ||
164 | - | ||
165 | - /* Reset both the TCR as well as the masks corresponding to the bank of | ||
166 | - * the TCR being reset. | ||
167 | - */ | ||
168 | - tcr->raw_tcr = 0; | ||
169 | - tcr->mask = 0; | ||
170 | - tcr->base_mask = 0xffffc000u; | ||
171 | + raw_write(env, ri, value); | ||
172 | } | ||
173 | |||
174 | static void vmsa_tcr_el12_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
175 | uint64_t value) | ||
176 | { | ||
177 | ARMCPU *cpu = env_archcpu(env); | ||
178 | - TCR *tcr = raw_ptr(env, ri); | ||
179 | |||
180 | /* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */ | ||
181 | tlb_flush(CPU(cpu)); | ||
182 | - tcr->raw_tcr = value; | ||
183 | + raw_write(env, ri, value); | ||
184 | } | ||
185 | |||
186 | static void vmsa_ttbr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
187 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = { | ||
188 | .opc0 = 3, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 2, | ||
189 | .access = PL1_RW, .accessfn = access_tvm_trvm, | ||
190 | .writefn = vmsa_tcr_el12_write, | ||
191 | - .resetfn = vmsa_ttbcr_reset, .raw_writefn = raw_write, | ||
192 | + .raw_writefn = raw_write, | ||
193 | + .resetvalue = 0, | ||
194 | .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[1]) }, | ||
195 | { .name = "TTBCR", .cp = 15, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 2, | ||
196 | .access = PL1_RW, .accessfn = access_tvm_trvm, | ||
197 | .type = ARM_CP_ALIAS, .writefn = vmsa_ttbcr_write, | ||
198 | - .raw_writefn = vmsa_ttbcr_raw_write, | ||
199 | - /* No offsetoflow32 -- pass the entire TCR to writefn/raw_writefn. */ | ||
200 | - .bank_fieldoffsets = { offsetof(CPUARMState, cp15.tcr_el[3]), | ||
201 | - offsetof(CPUARMState, cp15.tcr_el[1])} }, | ||
202 | + .raw_writefn = raw_write, | ||
203 | + .bank_fieldoffsets = { offsetoflow32(CPUARMState, cp15.tcr_el[3]), | ||
204 | + offsetoflow32(CPUARMState, cp15.tcr_el[1])} }, | ||
127 | }; | 205 | }; |
128 | 206 | ||
129 | +static bool m_v8m_needed(void *opaque) | 207 | /* Note that unlike TTBCR, writing to TTBCR2 does not require flushing |
130 | +{ | 208 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo ttbcr2_reginfo = { |
131 | + ARMCPU *cpu = opaque; | 209 | .access = PL1_RW, .accessfn = access_tvm_trvm, |
132 | + CPUARMState *env = &cpu->env; | 210 | .type = ARM_CP_ALIAS, |
133 | + | 211 | .bank_fieldoffsets = { |
134 | + return arm_feature(env, ARM_FEATURE_M) && arm_feature(env, ARM_FEATURE_V8); | 212 | - offsetofhigh32(CPUARMState, cp15.tcr_el[3].raw_tcr), |
135 | +} | 213 | - offsetofhigh32(CPUARMState, cp15.tcr_el[1].raw_tcr), |
136 | + | 214 | + offsetofhigh32(CPUARMState, cp15.tcr_el[3]), |
137 | +static const VMStateDescription vmstate_m_v8m = { | 215 | + offsetofhigh32(CPUARMState, cp15.tcr_el[1]), |
138 | + .name = "cpu/m/v8m", | 216 | }, |
139 | + .version_id = 1, | ||
140 | + .minimum_version_id = 1, | ||
141 | + .needed = m_v8m_needed, | ||
142 | + .fields = (VMStateField[]) { | ||
143 | + VMSTATE_UINT32_ARRAY(env.v7m.msplim, ARMCPU, M_REG_NUM_BANKS), | ||
144 | + VMSTATE_UINT32_ARRAY(env.v7m.psplim, ARMCPU, M_REG_NUM_BANKS), | ||
145 | + VMSTATE_END_OF_LIST() | ||
146 | + } | ||
147 | +}; | ||
148 | + | ||
149 | static const VMStateDescription vmstate_m = { | ||
150 | .name = "cpu/m", | ||
151 | .version_id = 4, | ||
152 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m = { | ||
153 | &vmstate_m_csselr, | ||
154 | &vmstate_m_scr, | ||
155 | &vmstate_m_other_sp, | ||
156 | + &vmstate_m_v8m, | ||
157 | NULL | ||
158 | } | ||
159 | }; | 217 | }; |
218 | |||
219 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = { | ||
220 | { .name = "TCR_EL2", .state = ARM_CP_STATE_BOTH, | ||
221 | .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 0, .opc2 = 2, | ||
222 | .access = PL2_RW, .writefn = vmsa_tcr_el12_write, | ||
223 | - /* no .raw_writefn or .resetfn needed as we never use mask/base_mask */ | ||
224 | .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[2]) }, | ||
225 | { .name = "VTCR", .state = ARM_CP_STATE_AA32, | ||
226 | .cp = 15, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, | ||
227 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el3_cp_reginfo[] = { | ||
228 | { .name = "TCR_EL3", .state = ARM_CP_STATE_AA64, | ||
229 | .opc0 = 3, .opc1 = 6, .crn = 2, .crm = 0, .opc2 = 2, | ||
230 | .access = PL3_RW, | ||
231 | - /* no .writefn needed as this can't cause an ASID change; | ||
232 | - * we must provide a .raw_writefn and .resetfn because we handle | ||
233 | - * reset and migration for the AArch32 TTBCR(S), which might be | ||
234 | - * using mask and base_mask. | ||
235 | - */ | ||
236 | - .resetfn = vmsa_ttbcr_reset, .raw_writefn = vmsa_ttbcr_raw_write, | ||
237 | + /* no .writefn needed as this can't cause an ASID change */ | ||
238 | + .resetvalue = 0, | ||
239 | .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[3]) }, | ||
240 | { .name = "ELR_EL3", .state = ARM_CP_STATE_AA64, | ||
241 | .type = ARM_CP_ALIAS, | ||
242 | diff --git a/target/arm/ptw.c b/target/arm/ptw.c | ||
243 | index XXXXXXX..XXXXXXX 100644 | ||
244 | --- a/target/arm/ptw.c | ||
245 | +++ b/target/arm/ptw.c | ||
246 | @@ -XXX,XX +XXX,XX @@ bool get_phys_addr(CPUARMState *env, target_ulong address, | ||
247 | int r_el = regime_el(env, mmu_idx); | ||
248 | if (arm_el_is_aa64(env, r_el)) { | ||
249 | int pamax = arm_pamax(env_archcpu(env)); | ||
250 | - uint64_t tcr = env->cp15.tcr_el[r_el].raw_tcr; | ||
251 | + uint64_t tcr = env->cp15.tcr_el[r_el]; | ||
252 | int addrtop, tbi; | ||
253 | |||
254 | tbi = aa64_va_parameter_tbi(tcr, mmu_idx); | ||
160 | -- | 255 | -- |
161 | 2.16.1 | 256 | 2.25.1 |
162 | |||
163 | diff view generated by jsdifflib |
1 | We were previously making the system control register (SCR) | 1 | In regime_tcr() we return the appropriate TCR register for the |
---|---|---|---|
2 | just RAZ/WI. Although we don't implement the functionality | 2 | translation regime. For Secure EL2, we return the VSTCR_EL2 value, |
3 | this register controls, we should at least provide the state, | 3 | but in this translation regime some fields that control behaviour are |
4 | including the banked state for v8M. | 4 | in VTCR_EL2. When this code was originally written (as the comment |
5 | notes), QEMU didn't care about any of those fields, but we have since | ||
6 | added support for features such as LPA2 which do need the values from | ||
7 | those fields. | ||
5 | 8 | ||
9 | Synthesize a TCR value by merging in the relevant VTCR_EL2 fields to | ||
10 | the VSTCR_EL2 value. | ||
11 | |||
12 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1103 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | 14 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
8 | Message-id: 20180209165810.6668-7-peter.maydell@linaro.org | 15 | Message-id: 20220714132303.1287193-8-peter.maydell@linaro.org |
9 | --- | 16 | --- |
10 | target/arm/cpu.h | 7 +++++++ | 17 | target/arm/cpu.h | 19 +++++++++++++++++++ |
11 | hw/intc/armv7m_nvic.c | 12 ++++++++---- | 18 | target/arm/internals.h | 22 +++++++++++++++++++--- |
12 | target/arm/machine.c | 12 ++++++++++++ | 19 | 2 files changed, 38 insertions(+), 3 deletions(-) |
13 | 3 files changed, 27 insertions(+), 4 deletions(-) | ||
14 | 20 | ||
15 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h | 21 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
16 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/cpu.h | 23 | --- a/target/arm/cpu.h |
18 | +++ b/target/arm/cpu.h | 24 | +++ b/target/arm/cpu.h |
19 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUARMState { | 25 | @@ -XXX,XX +XXX,XX @@ FIELD(CPTR_EL3, TCPAC, 31, 1) |
20 | uint32_t aircr; /* only holds r/w state if security extn implemented */ | 26 | #define TTBCR_SH1 (1U << 28) |
21 | uint32_t secure; /* Is CPU in Secure state? (not guest visible) */ | 27 | #define TTBCR_EAE (1U << 31) |
22 | uint32_t csselr[M_REG_NUM_BANKS]; | 28 | |
23 | + uint32_t scr[M_REG_NUM_BANKS]; | 29 | +FIELD(VTCR, T0SZ, 0, 6) |
24 | } v7m; | 30 | +FIELD(VTCR, SL0, 6, 2) |
25 | 31 | +FIELD(VTCR, IRGN0, 8, 2) | |
26 | /* Information associated with an exception about to be taken: | 32 | +FIELD(VTCR, ORGN0, 10, 2) |
27 | @@ -XXX,XX +XXX,XX @@ FIELD(V7M_CCR, STKALIGN, 9, 1) | 33 | +FIELD(VTCR, SH0, 12, 2) |
28 | FIELD(V7M_CCR, DC, 16, 1) | 34 | +FIELD(VTCR, TG0, 14, 2) |
29 | FIELD(V7M_CCR, IC, 17, 1) | 35 | +FIELD(VTCR, PS, 16, 3) |
30 | 36 | +FIELD(VTCR, VS, 19, 1) | |
31 | +/* V7M SCR bits */ | 37 | +FIELD(VTCR, HA, 21, 1) |
32 | +FIELD(V7M_SCR, SLEEPONEXIT, 1, 1) | 38 | +FIELD(VTCR, HD, 22, 1) |
33 | +FIELD(V7M_SCR, SLEEPDEEP, 2, 1) | 39 | +FIELD(VTCR, HWU59, 25, 1) |
34 | +FIELD(V7M_SCR, SLEEPDEEPS, 3, 1) | 40 | +FIELD(VTCR, HWU60, 26, 1) |
35 | +FIELD(V7M_SCR, SEVONPEND, 4, 1) | 41 | +FIELD(VTCR, HWU61, 27, 1) |
42 | +FIELD(VTCR, HWU62, 28, 1) | ||
43 | +FIELD(VTCR, NSW, 29, 1) | ||
44 | +FIELD(VTCR, NSA, 30, 1) | ||
45 | +FIELD(VTCR, DS, 32, 1) | ||
46 | +FIELD(VTCR, SL2, 33, 1) | ||
36 | + | 47 | + |
37 | /* V7M AIRCR bits */ | 48 | /* Bit definitions for ARMv8 SPSR (PSTATE) format. |
38 | FIELD(V7M_AIRCR, VECTRESET, 0, 1) | 49 | * Only these are valid when in AArch64 mode; in |
39 | FIELD(V7M_AIRCR, VECTCLRACTIVE, 1, 1) | 50 | * AArch32 mode SPSRs are basically CPSR-format. |
40 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | 51 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
41 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
42 | --- a/hw/intc/armv7m_nvic.c | 53 | --- a/target/arm/internals.h |
43 | +++ b/hw/intc/armv7m_nvic.c | 54 | +++ b/target/arm/internals.h |
44 | @@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs) | 55 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx) |
45 | } | 56 | return env->cp15.sctlr_el[regime_el(env, mmu_idx)]; |
46 | return val; | 57 | } |
47 | case 0xd10: /* System Control. */ | 58 | |
48 | - /* TODO: Implement SLEEPONEXIT. */ | 59 | +/* |
49 | - return 0; | 60 | + * These are the fields in VTCR_EL2 which affect both the Secure stage 2 |
50 | + return cpu->env.v7m.scr[attrs.secure]; | 61 | + * and the Non-Secure stage 2 translation regimes (and hence which are |
51 | case 0xd14: /* Configuration Control. */ | 62 | + * not present in VSTCR_EL2). |
52 | /* The BFHFNMIGN bit is the only non-banked bit; we | 63 | + */ |
53 | * keep it in the non-secure copy of the register. | 64 | +#define VTCR_SHARED_FIELD_MASK \ |
54 | @@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value, | 65 | + (R_VTCR_IRGN0_MASK | R_VTCR_ORGN0_MASK | R_VTCR_SH0_MASK | \ |
55 | } | 66 | + R_VTCR_PS_MASK | R_VTCR_VS_MASK | R_VTCR_HA_MASK | R_VTCR_HD_MASK | \ |
56 | break; | 67 | + R_VTCR_DS_MASK) |
57 | case 0xd10: /* System Control. */ | 68 | + |
58 | - /* TODO: Implement control registers. */ | 69 | /* Return the value of the TCR controlling this translation regime */ |
59 | - qemu_log_mask(LOG_UNIMP, "NVIC: SCR unimplemented\n"); | 70 | static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
60 | + /* We don't implement deep-sleep so these bits are RAZ/WI. | 71 | { |
61 | + * The other bits in the register are banked. | 72 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
62 | + * QEMU's implementation ignores SEVONPEND and SLEEPONEXIT, which | ||
63 | + * is architecturally permitted. | ||
64 | + */ | ||
65 | + value &= ~(R_V7M_SCR_SLEEPDEEP_MASK | R_V7M_SCR_SLEEPDEEPS_MASK); | ||
66 | + cpu->env.v7m.scr[attrs.secure] = value; | ||
67 | break; | ||
68 | case 0xd14: /* Configuration Control. */ | ||
69 | /* Enforce RAZ/WI on reserved and must-RAZ/WI bits */ | ||
70 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/target/arm/machine.c | ||
73 | +++ b/target/arm/machine.c | ||
74 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m_csselr = { | ||
75 | } | 73 | } |
76 | }; | 74 | if (mmu_idx == ARMMMUIdx_Stage2_S) { |
77 | 75 | /* | |
78 | +static const VMStateDescription vmstate_m_scr = { | 76 | - * Note: Secure stage 2 nominally shares fields from VTCR_EL2, but |
79 | + .name = "cpu/m/scr", | 77 | - * those are not currently used by QEMU, so just return VSTCR_EL2. |
80 | + .version_id = 1, | 78 | + * Secure stage 2 shares fields from VTCR_EL2. We merge those |
81 | + .minimum_version_id = 1, | 79 | + * in with the VSTCR_EL2 value to synthesize a single VTCR_EL2 format |
82 | + .fields = (VMStateField[]) { | 80 | + * value so the callers don't need to special case this. |
83 | + VMSTATE_UINT32(env.v7m.scr[M_REG_NS], ARMCPU), | 81 | + * |
84 | + VMSTATE_END_OF_LIST() | 82 | + * If a future architecture change defines bits in VSTCR_EL2 that |
85 | + } | 83 | + * overlap with these VTCR_EL2 fields we may need to revisit this. |
86 | +}; | 84 | */ |
87 | + | 85 | - return env->cp15.vstcr_el2; |
88 | static const VMStateDescription vmstate_m = { | 86 | + uint64_t v = env->cp15.vstcr_el2 & ~VTCR_SHARED_FIELD_MASK; |
89 | .name = "cpu/m", | 87 | + v |= env->cp15.vtcr_el2 & VTCR_SHARED_FIELD_MASK; |
90 | .version_id = 4, | 88 | + return v; |
91 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m = { | ||
92 | .subsections = (const VMStateDescription*[]) { | ||
93 | &vmstate_m_faultmask_primask, | ||
94 | &vmstate_m_csselr, | ||
95 | + &vmstate_m_scr, | ||
96 | NULL | ||
97 | } | 89 | } |
98 | }; | 90 | return env->cp15.tcr_el[regime_el(env, mmu_idx)]; |
99 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m_security = { | 91 | } |
100 | VMSTATE_UINT32(env.sau.rnr, ARMCPU), | ||
101 | VMSTATE_VALIDATE("SAU_RNR is valid", sau_rnr_vmstate_validate), | ||
102 | VMSTATE_UINT32(env.sau.ctrl, ARMCPU), | ||
103 | + VMSTATE_UINT32(env.v7m.scr[M_REG_S], ARMCPU), | ||
104 | VMSTATE_END_OF_LIST() | ||
105 | } | ||
106 | }; | ||
107 | -- | 92 | -- |
108 | 2.16.1 | 93 | 2.25.1 |
109 | |||
110 | diff view generated by jsdifflib |
1 | From: Pekka Enberg <penberg@iki.fi> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | This patch adds a "cpu-type" property to BCM2836 SoC in preparation for | 3 | The correct bit for the CONV bit in NPCM7XX ADC is bit 13. This patch |
4 | reusing the code for the Raspberry Pi 3, which has a different processor | 4 | fixes that in the module, and also lower the IRQ when the guest |
5 | model. | 5 | is done handling an interrupt event from the ADC module. |
6 | 6 | ||
7 | Signed-off-by: Pekka Enberg <penberg@iki.fi> | 7 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
8 | Reviewed-by: Patrick Venture<venture@google.com> | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Message-id: 20220714182836.89602-4-wuhaotsh@google.com | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 12 | --- |
11 | include/hw/arm/bcm2836.h | 1 + | 13 | hw/adc/npcm7xx_adc.c | 2 +- |
12 | hw/arm/bcm2836.c | 17 +++++++++-------- | 14 | tests/qtest/npcm7xx_adc-test.c | 2 +- |
13 | hw/arm/raspi.c | 3 +++ | 15 | 2 files changed, 2 insertions(+), 2 deletions(-) |
14 | 3 files changed, 13 insertions(+), 8 deletions(-) | ||
15 | 16 | ||
16 | diff --git a/include/hw/arm/bcm2836.h b/include/hw/arm/bcm2836.h | 17 | diff --git a/hw/adc/npcm7xx_adc.c b/hw/adc/npcm7xx_adc.c |
17 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/include/hw/arm/bcm2836.h | 19 | --- a/hw/adc/npcm7xx_adc.c |
19 | +++ b/include/hw/arm/bcm2836.h | 20 | +++ b/hw/adc/npcm7xx_adc.c |
20 | @@ -XXX,XX +XXX,XX @@ typedef struct BCM2836State { | 21 | @@ -XXX,XX +XXX,XX @@ REG32(NPCM7XX_ADC_DATA, 0x4) |
21 | DeviceState parent_obj; | 22 | #define NPCM7XX_ADC_CON_INT BIT(18) |
22 | /*< public >*/ | 23 | #define NPCM7XX_ADC_CON_EN BIT(17) |
23 | 24 | #define NPCM7XX_ADC_CON_RST BIT(16) | |
24 | + char *cpu_type; | 25 | -#define NPCM7XX_ADC_CON_CONV BIT(14) |
25 | uint32_t enabled_cpus; | 26 | +#define NPCM7XX_ADC_CON_CONV BIT(13) |
26 | 27 | #define NPCM7XX_ADC_CON_DIV(rv) extract32(rv, 1, 8) | |
27 | ARMCPU cpus[BCM2836_NCPUS]; | 28 | |
28 | diff --git a/hw/arm/bcm2836.c b/hw/arm/bcm2836.c | 29 | #define NPCM7XX_ADC_MAX_RESULT 1023 |
30 | diff --git a/tests/qtest/npcm7xx_adc-test.c b/tests/qtest/npcm7xx_adc-test.c | ||
29 | index XXXXXXX..XXXXXXX 100644 | 31 | index XXXXXXX..XXXXXXX 100644 |
30 | --- a/hw/arm/bcm2836.c | 32 | --- a/tests/qtest/npcm7xx_adc-test.c |
31 | +++ b/hw/arm/bcm2836.c | 33 | +++ b/tests/qtest/npcm7xx_adc-test.c |
32 | @@ -XXX,XX +XXX,XX @@ | 34 | @@ -XXX,XX +XXX,XX @@ |
33 | static void bcm2836_init(Object *obj) | 35 | #define CON_INT BIT(18) |
34 | { | 36 | #define CON_EN BIT(17) |
35 | BCM2836State *s = BCM2836(obj); | 37 | #define CON_RST BIT(16) |
36 | - int n; | 38 | -#define CON_CONV BIT(14) |
37 | - | 39 | +#define CON_CONV BIT(13) |
38 | - for (n = 0; n < BCM2836_NCPUS; n++) { | 40 | #define CON_DIV(rv) extract32(rv, 1, 8) |
39 | - object_initialize(&s->cpus[n], sizeof(s->cpus[n]), | 41 | |
40 | - "cortex-a15-" TYPE_ARM_CPU); | 42 | #define FST_RDST BIT(1) |
41 | - object_property_add_child(obj, "cpu[*]", OBJECT(&s->cpus[n]), | ||
42 | - &error_abort); | ||
43 | - } | ||
44 | |||
45 | object_initialize(&s->control, sizeof(s->control), TYPE_BCM2836_CONTROL); | ||
46 | object_property_add_child(obj, "control", OBJECT(&s->control), NULL); | ||
47 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
48 | |||
49 | /* common peripherals from bcm2835 */ | ||
50 | |||
51 | + obj = OBJECT(dev); | ||
52 | + for (n = 0; n < BCM2836_NCPUS; n++) { | ||
53 | + object_initialize(&s->cpus[n], sizeof(s->cpus[n]), | ||
54 | + s->cpu_type); | ||
55 | + object_property_add_child(obj, "cpu[*]", OBJECT(&s->cpus[n]), | ||
56 | + &error_abort); | ||
57 | + } | ||
58 | + | ||
59 | obj = object_property_get_link(OBJECT(dev), "ram", &err); | ||
60 | if (obj == NULL) { | ||
61 | error_setg(errp, "%s: required ram link not found: %s", | ||
62 | @@ -XXX,XX +XXX,XX @@ static void bcm2836_realize(DeviceState *dev, Error **errp) | ||
63 | } | ||
64 | |||
65 | static Property bcm2836_props[] = { | ||
66 | + DEFINE_PROP_STRING("cpu-type", BCM2836State, cpu_type), | ||
67 | DEFINE_PROP_UINT32("enabled-cpus", BCM2836State, enabled_cpus, BCM2836_NCPUS), | ||
68 | DEFINE_PROP_END_OF_LIST() | ||
69 | }; | ||
70 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
71 | index XXXXXXX..XXXXXXX 100644 | ||
72 | --- a/hw/arm/raspi.c | ||
73 | +++ b/hw/arm/raspi.c | ||
74 | @@ -XXX,XX +XXX,XX @@ static void raspi2_init(MachineState *machine) | ||
75 | /* Setup the SOC */ | ||
76 | object_property_add_const_link(OBJECT(&s->soc), "ram", OBJECT(&s->ram), | ||
77 | &error_abort); | ||
78 | + object_property_set_str(OBJECT(&s->soc), machine->cpu_type, "cpu-type", | ||
79 | + &error_abort); | ||
80 | object_property_set_int(OBJECT(&s->soc), smp_cpus, "enabled-cpus", | ||
81 | &error_abort); | ||
82 | object_property_set_int(OBJECT(&s->soc), 0xa21041, "board-rev", | ||
83 | @@ -XXX,XX +XXX,XX @@ static void raspi2_machine_init(MachineClass *mc) | ||
84 | mc->no_parallel = 1; | ||
85 | mc->no_floppy = 1; | ||
86 | mc->no_cdrom = 1; | ||
87 | + mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a15"); | ||
88 | mc->max_cpus = BCM2836_NCPUS; | ||
89 | mc->min_cpus = BCM2836_NCPUS; | ||
90 | mc->default_cpus = BCM2836_NCPUS; | ||
91 | -- | 43 | -- |
92 | 2.16.1 | 44 | 2.25.1 |
93 | |||
94 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | (qemu) info mtree | 3 | Our sensor test requires both reading and writing from a sensor's |
4 | address-space: cpu-memory-0 | 4 | QOM property. So we need to make the input of ADC module R/W instead |
5 | 0000000000000000-ffffffffffffffff (prio 0, i/o): system | 5 | of write only for that to work. |
6 | 0000000000000000-0000000007ffffff (prio 0, rom): aspeed.boot_rom | ||
7 | - 000000001e600000-000000001e7fffff (prio -1, i/o): aspeed_soc.io | ||
8 | + 000000001e600000-000000001e7fffff (prio -1000, i/o): aspeed_soc.io | ||
9 | 000000001e620000-000000001e6200ff (prio 0, i/o): aspeed.smc.ast2500-fmc | ||
10 | 000000001e630000-000000001e6300ff (prio 0, i/o): aspeed.smc.ast2500-spi1 | ||
11 | 000000001e631000-000000001e6310ff (prio 0, i/o): aspeed.smc.ast2500-spi2 | ||
12 | 6 | ||
13 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
14 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | 8 | Reviewed-by: Titus Rwantare <titusr@google.com> |
15 | Reviewed-by: Andrew Jeffery <andrew@aj.id.au> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
16 | Message-id: 20180209085755.30414-3-f4bug@amsat.org | 10 | Message-id: 20220714182836.89602-5-wuhaotsh@google.com |
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | --- | 12 | --- |
19 | include/hw/arm/aspeed_soc.h | 1 - | 13 | hw/adc/npcm7xx_adc.c | 2 +- |
20 | hw/arm/aspeed_soc.c | 32 +++----------------------------- | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
21 | 2 files changed, 3 insertions(+), 30 deletions(-) | ||
22 | 15 | ||
23 | diff --git a/include/hw/arm/aspeed_soc.h b/include/hw/arm/aspeed_soc.h | 16 | diff --git a/hw/adc/npcm7xx_adc.c b/hw/adc/npcm7xx_adc.c |
24 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
25 | --- a/include/hw/arm/aspeed_soc.h | 18 | --- a/hw/adc/npcm7xx_adc.c |
26 | +++ b/include/hw/arm/aspeed_soc.h | 19 | +++ b/hw/adc/npcm7xx_adc.c |
27 | @@ -XXX,XX +XXX,XX @@ typedef struct AspeedSoCState { | 20 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_adc_init(Object *obj) |
28 | 21 | ||
29 | /*< public >*/ | 22 | for (i = 0; i < NPCM7XX_ADC_NUM_INPUTS; ++i) { |
30 | ARMCPU cpu; | 23 | object_property_add_uint32_ptr(obj, "adci[*]", |
31 | - MemoryRegion iomem; | 24 | - &s->adci[i], OBJ_PROP_FLAG_WRITE); |
32 | MemoryRegion sram; | 25 | + &s->adci[i], OBJ_PROP_FLAG_READWRITE); |
33 | AspeedVICState vic; | 26 | } |
34 | AspeedTimerCtrlState timerctrl; | 27 | object_property_add_uint32_ptr(obj, "vref", |
35 | diff --git a/hw/arm/aspeed_soc.c b/hw/arm/aspeed_soc.c | 28 | &s->vref, OBJ_PROP_FLAG_WRITE); |
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/hw/arm/aspeed_soc.c | ||
38 | +++ b/hw/arm/aspeed_soc.c | ||
39 | @@ -XXX,XX +XXX,XX @@ | ||
40 | #include "qemu-common.h" | ||
41 | #include "cpu.h" | ||
42 | #include "exec/address-spaces.h" | ||
43 | +#include "hw/misc/unimp.h" | ||
44 | #include "hw/arm/aspeed_soc.h" | ||
45 | #include "hw/char/serial.h" | ||
46 | #include "qemu/log.h" | ||
47 | @@ -XXX,XX +XXX,XX @@ static const AspeedSoCInfo aspeed_socs[] = { | ||
48 | }, | ||
49 | }; | ||
50 | |||
51 | -/* | ||
52 | - * IO handlers: simply catch any reads/writes to IO addresses that aren't | ||
53 | - * handled by a device mapping. | ||
54 | - */ | ||
55 | - | ||
56 | -static uint64_t aspeed_soc_io_read(void *p, hwaddr offset, unsigned size) | ||
57 | -{ | ||
58 | - qemu_log_mask(LOG_UNIMP, "%s: 0x%" HWADDR_PRIx " [%u]\n", | ||
59 | - __func__, offset, size); | ||
60 | - return 0; | ||
61 | -} | ||
62 | - | ||
63 | -static void aspeed_soc_io_write(void *opaque, hwaddr offset, uint64_t value, | ||
64 | - unsigned size) | ||
65 | -{ | ||
66 | - qemu_log_mask(LOG_UNIMP, "%s: 0x%" HWADDR_PRIx " <- 0x%" PRIx64 " [%u]\n", | ||
67 | - __func__, offset, value, size); | ||
68 | -} | ||
69 | - | ||
70 | -static const MemoryRegionOps aspeed_soc_io_ops = { | ||
71 | - .read = aspeed_soc_io_read, | ||
72 | - .write = aspeed_soc_io_write, | ||
73 | - .endianness = DEVICE_LITTLE_ENDIAN, | ||
74 | -}; | ||
75 | - | ||
76 | static void aspeed_soc_init(Object *obj) | ||
77 | { | ||
78 | AspeedSoCState *s = ASPEED_SOC(obj); | ||
79 | @@ -XXX,XX +XXX,XX @@ static void aspeed_soc_realize(DeviceState *dev, Error **errp) | ||
80 | Error *err = NULL, *local_err = NULL; | ||
81 | |||
82 | /* IO space */ | ||
83 | - memory_region_init_io(&s->iomem, NULL, &aspeed_soc_io_ops, NULL, | ||
84 | - "aspeed_soc.io", ASPEED_SOC_IOMEM_SIZE); | ||
85 | - memory_region_add_subregion_overlap(get_system_memory(), | ||
86 | - ASPEED_SOC_IOMEM_BASE, &s->iomem, -1); | ||
87 | + create_unimplemented_device("aspeed_soc.io", | ||
88 | + ASPEED_SOC_IOMEM_BASE, ASPEED_SOC_IOMEM_SIZE); | ||
89 | |||
90 | /* CPU */ | ||
91 | object_property_set_bool(OBJECT(&s->cpu), true, "realized", &err); | ||
92 | -- | 29 | -- |
93 | 2.16.1 | 30 | 2.25.1 |
94 | |||
95 | diff view generated by jsdifflib |
1 | From: Richard Henderson <richard.henderson@linaro.org> | 1 | The architecture requires that for faults on loads and stores which |
---|---|---|---|
2 | do writeback, the syndrome information does not have the ISS | ||
3 | instruction syndrome information (i.e. ISV is 0). We got this wrong | ||
4 | for the load and store instructions covered by disas_ldst_reg_imm9(). | ||
5 | Calculate iss_valid correctly so that if the insn is a writeback one | ||
6 | it is false. | ||
2 | 7 | ||
3 | When storing to an AdvSIMD FP register, all of the high | 8 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1057 |
4 | bits of the SVE register are zeroed. Therefore, call it | ||
5 | more often with is_q as a parameter. | ||
6 | |||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20180211205848.4568-6-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> |
10 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
11 | Message-id: 20220715123323.1550983-1-peter.maydell@linaro.org | ||
11 | --- | 12 | --- |
12 | target/arm/translate-a64.c | 162 +++++++++++++++++---------------------------- | 13 | target/arm/translate-a64.c | 4 +++- |
13 | 1 file changed, 62 insertions(+), 100 deletions(-) | 14 | 1 file changed, 3 insertions(+), 1 deletion(-) |
14 | 15 | ||
15 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c | 16 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
16 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/target/arm/translate-a64.c | 18 | --- a/target/arm/translate-a64.c |
18 | +++ b/target/arm/translate-a64.c | 19 | +++ b/target/arm/translate-a64.c |
19 | @@ -XXX,XX +XXX,XX @@ static TCGv_i32 read_fp_sreg(DisasContext *s, int reg) | 20 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn, |
20 | return v; | 21 | bool is_store = false; |
21 | } | 22 | bool is_extended = false; |
22 | 23 | bool is_unpriv = (idx == 2); | |
23 | +/* Clear the bits above an N-bit vector, for N = (is_q ? 128 : 64). | 24 | - bool iss_valid = !is_vector; |
24 | + * If SVE is not enabled, then there are only 128 bits in the vector. | 25 | + bool iss_valid; |
25 | + */ | 26 | bool post_index; |
26 | +static void clear_vec_high(DisasContext *s, bool is_q, int rd) | 27 | bool writeback; |
27 | +{ | 28 | int memidx; |
28 | + unsigned ofs = fp_reg_offset(s, rd, MO_64); | 29 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn, |
29 | + unsigned vsz = vec_full_reg_size(s); | 30 | g_assert_not_reached(); |
31 | } | ||
32 | |||
33 | + iss_valid = !is_vector && !writeback; | ||
30 | + | 34 | + |
31 | + if (!is_q) { | 35 | if (rn == 31) { |
32 | + TCGv_i64 tcg_zero = tcg_const_i64(0); | 36 | gen_check_sp_alignment(s); |
33 | + tcg_gen_st_i64(tcg_zero, cpu_env, ofs + 8); | ||
34 | + tcg_temp_free_i64(tcg_zero); | ||
35 | + } | ||
36 | + if (vsz > 16) { | ||
37 | + tcg_gen_gvec_dup8i(ofs + 16, vsz - 16, vsz - 16, 0); | ||
38 | + } | ||
39 | +} | ||
40 | + | ||
41 | static void write_fp_dreg(DisasContext *s, int reg, TCGv_i64 v) | ||
42 | { | ||
43 | - TCGv_i64 tcg_zero = tcg_const_i64(0); | ||
44 | + unsigned ofs = fp_reg_offset(s, reg, MO_64); | ||
45 | |||
46 | - tcg_gen_st_i64(v, cpu_env, fp_reg_offset(s, reg, MO_64)); | ||
47 | - tcg_gen_st_i64(tcg_zero, cpu_env, fp_reg_hi_offset(s, reg)); | ||
48 | - tcg_temp_free_i64(tcg_zero); | ||
49 | + tcg_gen_st_i64(v, cpu_env, ofs); | ||
50 | + clear_vec_high(s, false, reg); | ||
51 | } | ||
52 | |||
53 | static void write_fp_sreg(DisasContext *s, int reg, TCGv_i32 v) | ||
54 | @@ -XXX,XX +XXX,XX @@ static void do_fp_ld(DisasContext *s, int destidx, TCGv_i64 tcg_addr, int size) | ||
55 | |||
56 | tcg_temp_free_i64(tmplo); | ||
57 | tcg_temp_free_i64(tmphi); | ||
58 | + | ||
59 | + clear_vec_high(s, true, destidx); | ||
60 | } | ||
61 | |||
62 | /* | ||
63 | @@ -XXX,XX +XXX,XX @@ static void write_vec_element_i32(DisasContext *s, TCGv_i32 tcg_src, | ||
64 | } | 37 | } |
65 | } | ||
66 | |||
67 | -/* Clear the high 64 bits of a 128 bit vector (in general non-quad | ||
68 | - * vector ops all need to do this). | ||
69 | - */ | ||
70 | -static void clear_vec_high(DisasContext *s, int rd) | ||
71 | -{ | ||
72 | - TCGv_i64 tcg_zero = tcg_const_i64(0); | ||
73 | - | ||
74 | - write_vec_element(s, tcg_zero, rd, 1, MO_64); | ||
75 | - tcg_temp_free_i64(tcg_zero); | ||
76 | -} | ||
77 | - | ||
78 | /* Store from vector register to memory */ | ||
79 | static void do_vec_st(DisasContext *s, int srcidx, int element, | ||
80 | TCGv_i64 tcg_addr, int size) | ||
81 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_multiple_struct(DisasContext *s, uint32_t insn) | ||
82 | /* For non-quad operations, setting a slice of the low | ||
83 | * 64 bits of the register clears the high 64 bits (in | ||
84 | * the ARM ARM pseudocode this is implicit in the fact | ||
85 | - * that 'rval' is a 64 bit wide variable). We optimize | ||
86 | - * by noticing that we only need to do this the first | ||
87 | - * time we touch a register. | ||
88 | + * that 'rval' is a 64 bit wide variable). | ||
89 | + * For quad operations, we might still need to zero the | ||
90 | + * high bits of SVE. We optimize by noticing that we only | ||
91 | + * need to do this the first time we touch a register. | ||
92 | */ | ||
93 | - if (!is_q && e == 0 && (r == 0 || xs == selem - 1)) { | ||
94 | - clear_vec_high(s, tt); | ||
95 | + if (e == 0 && (r == 0 || xs == selem - 1)) { | ||
96 | + clear_vec_high(s, is_q, tt); | ||
97 | } | ||
98 | } | ||
99 | tcg_gen_addi_i64(tcg_addr, tcg_addr, ebytes); | ||
100 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_single_struct(DisasContext *s, uint32_t insn) | ||
101 | write_vec_element(s, tcg_tmp, rt, 0, MO_64); | ||
102 | if (is_q) { | ||
103 | write_vec_element(s, tcg_tmp, rt, 1, MO_64); | ||
104 | - } else { | ||
105 | - clear_vec_high(s, rt); | ||
106 | } | ||
107 | tcg_temp_free_i64(tcg_tmp); | ||
108 | + clear_vec_high(s, is_q, rt); | ||
109 | } else { | ||
110 | /* Load/store one element per register */ | ||
111 | if (is_load) { | ||
112 | @@ -XXX,XX +XXX,XX @@ static void handle_vec_simd_sqshrn(DisasContext *s, bool is_scalar, bool is_q, | ||
113 | } | ||
114 | |||
115 | if (!is_q) { | ||
116 | - clear_vec_high(s, rd); | ||
117 | write_vec_element(s, tcg_final, rd, 0, MO_64); | ||
118 | } else { | ||
119 | write_vec_element(s, tcg_final, rd, 1, MO_64); | ||
120 | @@ -XXX,XX +XXX,XX @@ static void handle_vec_simd_sqshrn(DisasContext *s, bool is_scalar, bool is_q, | ||
121 | tcg_temp_free_i64(tcg_rd); | ||
122 | tcg_temp_free_i32(tcg_rd_narrowed); | ||
123 | tcg_temp_free_i64(tcg_final); | ||
124 | - return; | ||
125 | + | ||
126 | + clear_vec_high(s, is_q, rd); | ||
127 | } | ||
128 | |||
129 | /* SQSHLU, UQSHL, SQSHL: saturating left shifts */ | ||
130 | @@ -XXX,XX +XXX,XX @@ static void handle_simd_qshl(DisasContext *s, bool scalar, bool is_q, | ||
131 | tcg_temp_free_i64(tcg_op); | ||
132 | } | ||
133 | tcg_temp_free_i64(tcg_shift); | ||
134 | - | ||
135 | - if (!is_q) { | ||
136 | - clear_vec_high(s, rd); | ||
137 | - } | ||
138 | + clear_vec_high(s, is_q, rd); | ||
139 | } else { | ||
140 | TCGv_i32 tcg_shift = tcg_const_i32(shift); | ||
141 | static NeonGenTwoOpEnvFn * const fns[2][2][3] = { | ||
142 | @@ -XXX,XX +XXX,XX @@ static void handle_simd_qshl(DisasContext *s, bool scalar, bool is_q, | ||
143 | } | ||
144 | tcg_temp_free_i32(tcg_shift); | ||
145 | |||
146 | - if (!is_q && !scalar) { | ||
147 | - clear_vec_high(s, rd); | ||
148 | + if (!scalar) { | ||
149 | + clear_vec_high(s, is_q, rd); | ||
150 | } | ||
151 | } | ||
152 | } | ||
153 | @@ -XXX,XX +XXX,XX @@ static void handle_simd_intfp_conv(DisasContext *s, int rd, int rn, | ||
154 | } | ||
155 | } | ||
156 | |||
157 | - if (!is_double && elements == 2) { | ||
158 | - clear_vec_high(s, rd); | ||
159 | - } | ||
160 | - | ||
161 | tcg_temp_free_i64(tcg_int); | ||
162 | tcg_temp_free_ptr(tcg_fpst); | ||
163 | tcg_temp_free_i32(tcg_shift); | ||
164 | + | ||
165 | + clear_vec_high(s, elements << size == 16, rd); | ||
166 | } | ||
167 | |||
168 | /* UCVTF/SCVTF - Integer to FP conversion */ | ||
169 | @@ -XXX,XX +XXX,XX @@ static void handle_simd_shift_fpint_conv(DisasContext *s, bool is_scalar, | ||
170 | write_vec_element(s, tcg_op, rd, pass, MO_64); | ||
171 | tcg_temp_free_i64(tcg_op); | ||
172 | } | ||
173 | - if (!is_q) { | ||
174 | - clear_vec_high(s, rd); | ||
175 | - } | ||
176 | + clear_vec_high(s, is_q, rd); | ||
177 | } else { | ||
178 | int maxpass = is_scalar ? 1 : is_q ? 4 : 2; | ||
179 | for (pass = 0; pass < maxpass; pass++) { | ||
180 | @@ -XXX,XX +XXX,XX @@ static void handle_simd_shift_fpint_conv(DisasContext *s, bool is_scalar, | ||
181 | } | ||
182 | tcg_temp_free_i32(tcg_op); | ||
183 | } | ||
184 | - if (!is_q && !is_scalar) { | ||
185 | - clear_vec_high(s, rd); | ||
186 | + if (!is_scalar) { | ||
187 | + clear_vec_high(s, is_q, rd); | ||
188 | } | ||
189 | } | ||
190 | |||
191 | @@ -XXX,XX +XXX,XX @@ static void handle_3same_float(DisasContext *s, int size, int elements, | ||
192 | |||
193 | tcg_temp_free_ptr(fpst); | ||
194 | |||
195 | - if ((elements << size) < 4) { | ||
196 | - /* scalar, or non-quad vector op */ | ||
197 | - clear_vec_high(s, rd); | ||
198 | - } | ||
199 | + clear_vec_high(s, elements * (size ? 8 : 4) > 8, rd); | ||
200 | } | ||
201 | |||
202 | /* AdvSIMD scalar three same | ||
203 | @@ -XXX,XX +XXX,XX @@ static void handle_2misc_fcmp_zero(DisasContext *s, int opcode, | ||
204 | } | ||
205 | write_vec_element(s, tcg_res, rd, pass, MO_64); | ||
206 | } | ||
207 | - if (is_scalar) { | ||
208 | - clear_vec_high(s, rd); | ||
209 | - } | ||
210 | - | ||
211 | tcg_temp_free_i64(tcg_res); | ||
212 | tcg_temp_free_i64(tcg_zero); | ||
213 | tcg_temp_free_i64(tcg_op); | ||
214 | + | ||
215 | + clear_vec_high(s, !is_scalar, rd); | ||
216 | } else { | ||
217 | TCGv_i32 tcg_op = tcg_temp_new_i32(); | ||
218 | TCGv_i32 tcg_zero = tcg_const_i32(0); | ||
219 | @@ -XXX,XX +XXX,XX @@ static void handle_2misc_fcmp_zero(DisasContext *s, int opcode, | ||
220 | tcg_temp_free_i32(tcg_res); | ||
221 | tcg_temp_free_i32(tcg_zero); | ||
222 | tcg_temp_free_i32(tcg_op); | ||
223 | - if (!is_q && !is_scalar) { | ||
224 | - clear_vec_high(s, rd); | ||
225 | + if (!is_scalar) { | ||
226 | + clear_vec_high(s, is_q, rd); | ||
227 | } | ||
228 | } | ||
229 | |||
230 | @@ -XXX,XX +XXX,XX @@ static void handle_2misc_reciprocal(DisasContext *s, int opcode, | ||
231 | } | ||
232 | write_vec_element(s, tcg_res, rd, pass, MO_64); | ||
233 | } | ||
234 | - if (is_scalar) { | ||
235 | - clear_vec_high(s, rd); | ||
236 | - } | ||
237 | - | ||
238 | tcg_temp_free_i64(tcg_res); | ||
239 | tcg_temp_free_i64(tcg_op); | ||
240 | + clear_vec_high(s, !is_scalar, rd); | ||
241 | } else { | ||
242 | TCGv_i32 tcg_op = tcg_temp_new_i32(); | ||
243 | TCGv_i32 tcg_res = tcg_temp_new_i32(); | ||
244 | @@ -XXX,XX +XXX,XX @@ static void handle_2misc_reciprocal(DisasContext *s, int opcode, | ||
245 | } | ||
246 | tcg_temp_free_i32(tcg_res); | ||
247 | tcg_temp_free_i32(tcg_op); | ||
248 | - if (!is_q && !is_scalar) { | ||
249 | - clear_vec_high(s, rd); | ||
250 | + if (!is_scalar) { | ||
251 | + clear_vec_high(s, is_q, rd); | ||
252 | } | ||
253 | } | ||
254 | tcg_temp_free_ptr(fpst); | ||
255 | @@ -XXX,XX +XXX,XX @@ static void handle_2misc_narrow(DisasContext *s, bool scalar, | ||
256 | write_vec_element_i32(s, tcg_res[pass], rd, destelt + pass, MO_32); | ||
257 | tcg_temp_free_i32(tcg_res[pass]); | ||
258 | } | ||
259 | - if (!is_q) { | ||
260 | - clear_vec_high(s, rd); | ||
261 | - } | ||
262 | + clear_vec_high(s, is_q, rd); | ||
263 | } | ||
264 | |||
265 | /* Remaining saturating accumulating ops */ | ||
266 | @@ -XXX,XX +XXX,XX @@ static void handle_2misc_satacc(DisasContext *s, bool is_scalar, bool is_u, | ||
267 | } | ||
268 | write_vec_element(s, tcg_rd, rd, pass, MO_64); | ||
269 | } | ||
270 | - if (is_scalar) { | ||
271 | - clear_vec_high(s, rd); | ||
272 | - } | ||
273 | - | ||
274 | tcg_temp_free_i64(tcg_rd); | ||
275 | tcg_temp_free_i64(tcg_rn); | ||
276 | + clear_vec_high(s, !is_scalar, rd); | ||
277 | } else { | ||
278 | TCGv_i32 tcg_rn = tcg_temp_new_i32(); | ||
279 | TCGv_i32 tcg_rd = tcg_temp_new_i32(); | ||
280 | @@ -XXX,XX +XXX,XX @@ static void handle_2misc_satacc(DisasContext *s, bool is_scalar, bool is_u, | ||
281 | } | ||
282 | write_vec_element_i32(s, tcg_rd, rd, pass, MO_32); | ||
283 | } | ||
284 | - | ||
285 | - if (!is_q) { | ||
286 | - clear_vec_high(s, rd); | ||
287 | - } | ||
288 | - | ||
289 | tcg_temp_free_i32(tcg_rd); | ||
290 | tcg_temp_free_i32(tcg_rn); | ||
291 | + clear_vec_high(s, is_q, rd); | ||
292 | } | ||
293 | } | ||
294 | |||
295 | @@ -XXX,XX +XXX,XX @@ static void handle_vec_simd_shri(DisasContext *s, bool is_q, bool is_u, | ||
296 | tcg_temp_free_i64(tcg_round); | ||
297 | |||
298 | done: | ||
299 | - if (!is_q) { | ||
300 | - clear_vec_high(s, rd); | ||
301 | - } | ||
302 | + clear_vec_high(s, is_q, rd); | ||
303 | } | ||
304 | |||
305 | static void gen_shl8_ins_i64(TCGv_i64 d, TCGv_i64 a, int64_t shift) | ||
306 | @@ -XXX,XX +XXX,XX @@ static void handle_vec_simd_shrn(DisasContext *s, bool is_q, | ||
307 | } | ||
308 | |||
309 | if (!is_q) { | ||
310 | - clear_vec_high(s, rd); | ||
311 | write_vec_element(s, tcg_final, rd, 0, MO_64); | ||
312 | } else { | ||
313 | write_vec_element(s, tcg_final, rd, 1, MO_64); | ||
314 | } | ||
315 | - | ||
316 | if (round) { | ||
317 | tcg_temp_free_i64(tcg_round); | ||
318 | } | ||
319 | tcg_temp_free_i64(tcg_rn); | ||
320 | tcg_temp_free_i64(tcg_rd); | ||
321 | tcg_temp_free_i64(tcg_final); | ||
322 | - return; | ||
323 | + | ||
324 | + clear_vec_high(s, is_q, rd); | ||
325 | } | ||
326 | |||
327 | |||
328 | @@ -XXX,XX +XXX,XX @@ static void handle_3rd_narrowing(DisasContext *s, int is_q, int is_u, int size, | ||
329 | write_vec_element_i32(s, tcg_res[pass], rd, pass + part, MO_32); | ||
330 | tcg_temp_free_i32(tcg_res[pass]); | ||
331 | } | ||
332 | - if (!is_q) { | ||
333 | - clear_vec_high(s, rd); | ||
334 | - } | ||
335 | + clear_vec_high(s, is_q, rd); | ||
336 | } | ||
337 | |||
338 | static void handle_pmull_64(DisasContext *s, int is_q, int rd, int rn, int rm) | ||
339 | @@ -XXX,XX +XXX,XX @@ static void handle_simd_3same_pair(DisasContext *s, int is_q, int u, int opcode, | ||
340 | write_vec_element_i32(s, tcg_res[pass], rd, pass, MO_32); | ||
341 | tcg_temp_free_i32(tcg_res[pass]); | ||
342 | } | ||
343 | - if (!is_q) { | ||
344 | - clear_vec_high(s, rd); | ||
345 | - } | ||
346 | + clear_vec_high(s, is_q, rd); | ||
347 | } | ||
348 | |||
349 | if (fpst) { | ||
350 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_3same_int(DisasContext *s, uint32_t insn) | ||
351 | tcg_temp_free_i32(tcg_op2); | ||
352 | } | ||
353 | } | ||
354 | - | ||
355 | - if (!is_q) { | ||
356 | - clear_vec_high(s, rd); | ||
357 | - } | ||
358 | + clear_vec_high(s, is_q, rd); | ||
359 | } | ||
360 | |||
361 | /* AdvSIMD three same | ||
362 | @@ -XXX,XX +XXX,XX @@ static void handle_rev(DisasContext *s, int opcode, bool u, | ||
363 | write_vec_element(s, tcg_tmp, rd, i, grp_size); | ||
364 | tcg_temp_free_i64(tcg_tmp); | ||
365 | } | ||
366 | - if (!is_q) { | ||
367 | - clear_vec_high(s, rd); | ||
368 | - } | ||
369 | + clear_vec_high(s, is_q, rd); | ||
370 | } else { | ||
371 | int revmask = (1 << grp_size) - 1; | ||
372 | int esize = 8 << size; | ||
373 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_two_reg_misc(DisasContext *s, uint32_t insn) | ||
374 | tcg_temp_free_i32(tcg_op); | ||
375 | } | ||
376 | } | ||
377 | - if (!is_q) { | ||
378 | - clear_vec_high(s, rd); | ||
379 | - } | ||
380 | + clear_vec_high(s, is_q, rd); | ||
381 | |||
382 | if (need_rmode) { | ||
383 | gen_helper_set_rmode(tcg_rmode, tcg_rmode, cpu_env); | ||
384 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
385 | tcg_temp_free_i64(tcg_res); | ||
386 | } | ||
387 | |||
388 | - if (is_scalar) { | ||
389 | - clear_vec_high(s, rd); | ||
390 | - } | ||
391 | - | ||
392 | tcg_temp_free_i64(tcg_idx); | ||
393 | + clear_vec_high(s, !is_scalar, rd); | ||
394 | } else if (!is_long) { | ||
395 | /* 32 bit floating point, or 16 or 32 bit integer. | ||
396 | * For the 16 bit scalar case we use the usual Neon helpers and | ||
397 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
398 | } | ||
399 | |||
400 | tcg_temp_free_i32(tcg_idx); | ||
401 | - | ||
402 | - if (!is_q) { | ||
403 | - clear_vec_high(s, rd); | ||
404 | - } | ||
405 | + clear_vec_high(s, is_q, rd); | ||
406 | } else { | ||
407 | /* long ops: 16x16->32 or 32x32->64 */ | ||
408 | TCGv_i64 tcg_res[2]; | ||
409 | @@ -XXX,XX +XXX,XX @@ static void disas_simd_indexed(DisasContext *s, uint32_t insn) | ||
410 | } | ||
411 | tcg_temp_free_i64(tcg_idx); | ||
412 | |||
413 | - if (is_scalar) { | ||
414 | - clear_vec_high(s, rd); | ||
415 | - } | ||
416 | + clear_vec_high(s, !is_scalar, rd); | ||
417 | } else { | ||
418 | TCGv_i32 tcg_idx = tcg_temp_new_i32(); | ||
419 | |||
420 | -- | 38 | -- |
421 | 2.16.1 | 39 | 2.25.1 |
422 | |||
423 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | Instead of hardcoding the values of M profile ID registers in the | ||
2 | NVIC, use the fields in the CPU struct. This will allow us to | ||
3 | give different M profile CPU types different ID register values. | ||
4 | 1 | ||
5 | This commit includes the addition of the missing ID_ISAR5, | ||
6 | which exists as RES0 in both v7M and v8M. | ||
7 | |||
8 | (The values of the ID registers might be wrong for the M4 -- | ||
9 | this commit leaves the behaviour there unchanged.) | ||
10 | |||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
13 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 20180209165810.6668-2-peter.maydell@linaro.org | ||
15 | --- | ||
16 | hw/intc/armv7m_nvic.c | 30 ++++++++++++++++-------------- | ||
17 | target/arm/cpu.c | 28 ++++++++++++++++++++++++++++ | ||
18 | 2 files changed, 44 insertions(+), 14 deletions(-) | ||
19 | |||
20 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/hw/intc/armv7m_nvic.c | ||
23 | +++ b/hw/intc/armv7m_nvic.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs) | ||
25 | "Aux Fault status registers unimplemented\n"); | ||
26 | return 0; | ||
27 | case 0xd40: /* PFR0. */ | ||
28 | - return 0x00000030; | ||
29 | - case 0xd44: /* PRF1. */ | ||
30 | - return 0x00000200; | ||
31 | + return cpu->id_pfr0; | ||
32 | + case 0xd44: /* PFR1. */ | ||
33 | + return cpu->id_pfr1; | ||
34 | case 0xd48: /* DFR0. */ | ||
35 | - return 0x00100000; | ||
36 | + return cpu->id_dfr0; | ||
37 | case 0xd4c: /* AFR0. */ | ||
38 | - return 0x00000000; | ||
39 | + return cpu->id_afr0; | ||
40 | case 0xd50: /* MMFR0. */ | ||
41 | - return 0x00000030; | ||
42 | + return cpu->id_mmfr0; | ||
43 | case 0xd54: /* MMFR1. */ | ||
44 | - return 0x00000000; | ||
45 | + return cpu->id_mmfr1; | ||
46 | case 0xd58: /* MMFR2. */ | ||
47 | - return 0x00000000; | ||
48 | + return cpu->id_mmfr2; | ||
49 | case 0xd5c: /* MMFR3. */ | ||
50 | - return 0x00000000; | ||
51 | + return cpu->id_mmfr3; | ||
52 | case 0xd60: /* ISAR0. */ | ||
53 | - return 0x01141110; | ||
54 | + return cpu->id_isar0; | ||
55 | case 0xd64: /* ISAR1. */ | ||
56 | - return 0x02111000; | ||
57 | + return cpu->id_isar1; | ||
58 | case 0xd68: /* ISAR2. */ | ||
59 | - return 0x21112231; | ||
60 | + return cpu->id_isar2; | ||
61 | case 0xd6c: /* ISAR3. */ | ||
62 | - return 0x01111110; | ||
63 | + return cpu->id_isar3; | ||
64 | case 0xd70: /* ISAR4. */ | ||
65 | - return 0x01310102; | ||
66 | + return cpu->id_isar4; | ||
67 | + case 0xd74: /* ISAR5. */ | ||
68 | + return cpu->id_isar5; | ||
69 | /* TODO: Implement debug registers. */ | ||
70 | case 0xd90: /* MPU_TYPE */ | ||
71 | /* Unified MPU; if the MPU is not present this value is zero */ | ||
72 | diff --git a/target/arm/cpu.c b/target/arm/cpu.c | ||
73 | index XXXXXXX..XXXXXXX 100644 | ||
74 | --- a/target/arm/cpu.c | ||
75 | +++ b/target/arm/cpu.c | ||
76 | @@ -XXX,XX +XXX,XX @@ static void cortex_m3_initfn(Object *obj) | ||
77 | set_feature(&cpu->env, ARM_FEATURE_M); | ||
78 | cpu->midr = 0x410fc231; | ||
79 | cpu->pmsav7_dregion = 8; | ||
80 | + cpu->id_pfr0 = 0x00000030; | ||
81 | + cpu->id_pfr1 = 0x00000200; | ||
82 | + cpu->id_dfr0 = 0x00100000; | ||
83 | + cpu->id_afr0 = 0x00000000; | ||
84 | + cpu->id_mmfr0 = 0x00000030; | ||
85 | + cpu->id_mmfr1 = 0x00000000; | ||
86 | + cpu->id_mmfr2 = 0x00000000; | ||
87 | + cpu->id_mmfr3 = 0x00000000; | ||
88 | + cpu->id_isar0 = 0x01141110; | ||
89 | + cpu->id_isar1 = 0x02111000; | ||
90 | + cpu->id_isar2 = 0x21112231; | ||
91 | + cpu->id_isar3 = 0x01111110; | ||
92 | + cpu->id_isar4 = 0x01310102; | ||
93 | + cpu->id_isar5 = 0x00000000; | ||
94 | } | ||
95 | |||
96 | static void cortex_m4_initfn(Object *obj) | ||
97 | @@ -XXX,XX +XXX,XX @@ static void cortex_m4_initfn(Object *obj) | ||
98 | set_feature(&cpu->env, ARM_FEATURE_THUMB_DSP); | ||
99 | cpu->midr = 0x410fc240; /* r0p0 */ | ||
100 | cpu->pmsav7_dregion = 8; | ||
101 | + cpu->id_pfr0 = 0x00000030; | ||
102 | + cpu->id_pfr1 = 0x00000200; | ||
103 | + cpu->id_dfr0 = 0x00100000; | ||
104 | + cpu->id_afr0 = 0x00000000; | ||
105 | + cpu->id_mmfr0 = 0x00000030; | ||
106 | + cpu->id_mmfr1 = 0x00000000; | ||
107 | + cpu->id_mmfr2 = 0x00000000; | ||
108 | + cpu->id_mmfr3 = 0x00000000; | ||
109 | + cpu->id_isar0 = 0x01141110; | ||
110 | + cpu->id_isar1 = 0x02111000; | ||
111 | + cpu->id_isar2 = 0x21112231; | ||
112 | + cpu->id_isar3 = 0x01111110; | ||
113 | + cpu->id_isar4 = 0x01310102; | ||
114 | + cpu->id_isar5 = 0x00000000; | ||
115 | } | ||
116 | |||
117 | static void arm_v7m_class_init(ObjectClass *oc, void *data) | ||
118 | -- | ||
119 | 2.16.1 | ||
120 | |||
121 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | For M profile cores, cache maintenance operations are done by | ||
2 | writing to special registers in the system register space. | ||
3 | For QEMU, cache operations are always NOPs, since we don't | ||
4 | implement the cache. Implementing these explicitly avoids | ||
5 | a spurious LOG_GUEST_ERROR when the guest uses them. | ||
6 | 1 | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
9 | Message-id: 20180209165810.6668-4-peter.maydell@linaro.org | ||
10 | --- | ||
11 | hw/intc/armv7m_nvic.c | 12 ++++++++++++ | ||
12 | 1 file changed, 12 insertions(+) | ||
13 | |||
14 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/intc/armv7m_nvic.c | ||
17 | +++ b/hw/intc/armv7m_nvic.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value, | ||
19 | } | ||
20 | break; | ||
21 | } | ||
22 | + case 0xf50: /* ICIALLU */ | ||
23 | + case 0xf58: /* ICIMVAU */ | ||
24 | + case 0xf5c: /* DCIMVAC */ | ||
25 | + case 0xf60: /* DCISW */ | ||
26 | + case 0xf64: /* DCCMVAU */ | ||
27 | + case 0xf68: /* DCCMVAC */ | ||
28 | + case 0xf6c: /* DCCSW */ | ||
29 | + case 0xf70: /* DCCIMVAC */ | ||
30 | + case 0xf74: /* DCCISW */ | ||
31 | + case 0xf78: /* BPIALL */ | ||
32 | + /* Cache and branch predictor maintenance: for QEMU these always NOP */ | ||
33 | + break; | ||
34 | default: | ||
35 | bad_offset: | ||
36 | qemu_log_mask(LOG_GUEST_ERROR, | ||
37 | -- | ||
38 | 2.16.1 | ||
39 | |||
40 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | The Coprocessor Power Control Register (CPPWR) is new in v8M. | ||
2 | It allows software to control whether coprocessors are allowed | ||
3 | to power down and lose their state. QEMU doesn't have any | ||
4 | notion of power control, so we choose the IMPDEF option of | ||
5 | making the whole register RAZ/WI (indicating that no coprocessors | ||
6 | can ever power down and lose state). | ||
7 | 1 | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
10 | Message-id: 20180209165810.6668-5-peter.maydell@linaro.org | ||
11 | --- | ||
12 | hw/intc/armv7m_nvic.c | 14 ++++++++++++++ | ||
13 | 1 file changed, 14 insertions(+) | ||
14 | |||
15 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c | ||
16 | index XXXXXXX..XXXXXXX 100644 | ||
17 | --- a/hw/intc/armv7m_nvic.c | ||
18 | +++ b/hw/intc/armv7m_nvic.c | ||
19 | @@ -XXX,XX +XXX,XX @@ static uint32_t nvic_readl(NVICState *s, uint32_t offset, MemTxAttrs attrs) | ||
20 | switch (offset) { | ||
21 | case 4: /* Interrupt Control Type. */ | ||
22 | return ((s->num_irq - NVIC_FIRST_IRQ) / 32) - 1; | ||
23 | + case 0xc: /* CPPWR */ | ||
24 | + if (!arm_feature(&cpu->env, ARM_FEATURE_V8)) { | ||
25 | + goto bad_offset; | ||
26 | + } | ||
27 | + /* We make the IMPDEF choice that nothing can ever go into a | ||
28 | + * non-retentive power state, which allows us to RAZ/WI this. | ||
29 | + */ | ||
30 | + return 0; | ||
31 | case 0x380 ... 0x3bf: /* NVIC_ITNS<n> */ | ||
32 | { | ||
33 | int startvec = 8 * (offset - 0x380) + NVIC_FIRST_IRQ; | ||
34 | @@ -XXX,XX +XXX,XX @@ static void nvic_writel(NVICState *s, uint32_t offset, uint32_t value, | ||
35 | ARMCPU *cpu = s->cpu; | ||
36 | |||
37 | switch (offset) { | ||
38 | + case 0xc: /* CPPWR */ | ||
39 | + if (!arm_feature(&cpu->env, ARM_FEATURE_V8)) { | ||
40 | + goto bad_offset; | ||
41 | + } | ||
42 | + /* Make the IMPDEF choice to RAZ/WI this. */ | ||
43 | + break; | ||
44 | case 0x380 ... 0x3bf: /* NVIC_ITNS<n> */ | ||
45 | { | ||
46 | int startvec = 8 * (offset - 0x380) + NVIC_FIRST_IRQ; | ||
47 | -- | ||
48 | 2.16.1 | ||
49 | |||
50 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | In commit commit 3b2e934463121 we added support for the AIRCR | ||
2 | register holding state, but forgot to add it to the vmstate | ||
3 | structs. Since it only holds r/w state if the security extension | ||
4 | is implemented, we can just add it to vmstate_m_security. | ||
5 | 1 | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20180209165810.6668-10-peter.maydell@linaro.org | ||
9 | --- | ||
10 | target/arm/machine.c | 4 ++++ | ||
11 | 1 file changed, 4 insertions(+) | ||
12 | |||
13 | diff --git a/target/arm/machine.c b/target/arm/machine.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/target/arm/machine.c | ||
16 | +++ b/target/arm/machine.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_m_security = { | ||
18 | VMSTATE_VALIDATE("SAU_RNR is valid", sau_rnr_vmstate_validate), | ||
19 | VMSTATE_UINT32(env.sau.ctrl, ARMCPU), | ||
20 | VMSTATE_UINT32(env.v7m.scr[M_REG_S], ARMCPU), | ||
21 | + /* AIRCR is not secure-only, but our implementation is R/O if the | ||
22 | + * security extension is unimplemented, so we migrate it here. | ||
23 | + */ | ||
24 | + VMSTATE_UINT32(env.v7m.aircr, ARMCPU), | ||
25 | VMSTATE_END_OF_LIST() | ||
26 | } | ||
27 | }; | ||
28 | -- | ||
29 | 2.16.1 | ||
30 | |||
31 | diff view generated by jsdifflib |
1 | From: Pekka Enberg <penberg@iki.fi> | 1 | From: Andrey Makarov <ph.makarov@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | This patch adds Raspberry Pi 3 support to hw/arm/raspi.c. The | 3 | There is nothing in the specs on DMA engine interrupt lines: it should have |
4 | differences to Pi 2 are: | 4 | been in the "BCM2835 ARM Peripherals" datasheet but the appropriate |
5 | 5 | "ARM peripherals interrupt table" (p.113) is nearly empty. | |
6 | - Firmware address | 6 | |
7 | - Board ID | 7 | All Raspberry Pi models 1-3 (based on bcm2835) have |
8 | - Board revision | 8 | Linux device tree (arch/arm/boot/dts/bcm2835-common.dtsi +25): |
9 | 9 | ||
10 | The CPU is different too, but that's going to be configured as part of | 10 | /* dma channel 11-14 share one irq */ |
11 | the machine default CPU when we introduce a new machine type. | 11 | |
12 | 12 | This information is repeated in the driver code | |
13 | The patch was written from scratch by me but the logic is similar to | 13 | (drivers/dma/bcm2835-dma.c +1344): |
14 | Zoltán Baldaszti's previous work, which I used as a reference (with | 14 | |
15 | permission from the author): | 15 | /* |
16 | 16 | * in case of channel >= 11 | |
17 | https://github.com/bztsrc/qemu-raspi3 | 17 | * use the 11th interrupt and that is shared |
18 | 18 | */ | |
19 | Signed-off-by: Pekka Enberg <penberg@iki.fi> | 19 | |
20 | [PMM: fixed trailing whitespace on one line] | 20 | In this patch channels 0--10 and 11--14 are handled separately. |
21 | |||
22 | Signed-off-by: Andrey Makarov <andrey.makarov@auriga.com> | ||
23 | Message-id: 20220716113210.349153-1-andrey.makarov@auriga.com | ||
24 | [PMM: fixed checkpatch nits] | ||
21 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 25 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
22 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 26 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
23 | --- | 27 | --- |
24 | hw/arm/raspi.c | 31 +++++++++++++++++++++---------- | 28 | include/hw/arm/bcm2835_peripherals.h | 2 + |
25 | 1 file changed, 21 insertions(+), 10 deletions(-) | 29 | hw/arm/bcm2835_peripherals.c | 26 +++++- |
26 | 30 | tests/qtest/bcm2835-dma-test.c | 118 +++++++++++++++++++++++++++ | |
27 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | 31 | tests/qtest/meson.build | 3 +- |
32 | 4 files changed, 147 insertions(+), 2 deletions(-) | ||
33 | create mode 100644 tests/qtest/bcm2835-dma-test.c | ||
34 | |||
35 | diff --git a/include/hw/arm/bcm2835_peripherals.h b/include/hw/arm/bcm2835_peripherals.h | ||
28 | index XXXXXXX..XXXXXXX 100644 | 36 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/hw/arm/raspi.c | 37 | --- a/include/hw/arm/bcm2835_peripherals.h |
30 | +++ b/hw/arm/raspi.c | 38 | +++ b/include/hw/arm/bcm2835_peripherals.h |
31 | @@ -XXX,XX +XXX,XX @@ | 39 | @@ -XXX,XX +XXX,XX @@ |
32 | * Rasperry Pi 2 emulation Copyright (c) 2015, Microsoft | 40 | #include "hw/char/bcm2835_aux.h" |
33 | * Written by Andrew Baumann | 41 | #include "hw/display/bcm2835_fb.h" |
34 | * | 42 | #include "hw/dma/bcm2835_dma.h" |
35 | + * Raspberry Pi 3 emulation Copyright (c) 2018 Zoltán Baldaszti | 43 | +#include "hw/or-irq.h" |
36 | + * Upstream code cleanup (c) 2018 Pekka Enberg | 44 | #include "hw/intc/bcm2835_ic.h" |
45 | #include "hw/misc/bcm2835_property.h" | ||
46 | #include "hw/misc/bcm2835_rng.h" | ||
47 | @@ -XXX,XX +XXX,XX @@ struct BCM2835PeripheralState { | ||
48 | BCM2835AuxState aux; | ||
49 | BCM2835FBState fb; | ||
50 | BCM2835DMAState dma; | ||
51 | + qemu_or_irq orgated_dma_irq; | ||
52 | BCM2835ICState ic; | ||
53 | BCM2835PropertyState property; | ||
54 | BCM2835RngState rng; | ||
55 | diff --git a/hw/arm/bcm2835_peripherals.c b/hw/arm/bcm2835_peripherals.c | ||
56 | index XXXXXXX..XXXXXXX 100644 | ||
57 | --- a/hw/arm/bcm2835_peripherals.c | ||
58 | +++ b/hw/arm/bcm2835_peripherals.c | ||
59 | @@ -XXX,XX +XXX,XX @@ | ||
60 | /* Capabilities for SD controller: no DMA, high-speed, default clocks etc. */ | ||
61 | #define BCM2835_SDHC_CAPAREG 0x52134b4 | ||
62 | |||
63 | +/* | ||
64 | + * According to Linux driver & DTS, dma channels 0--10 have separate IRQ, | ||
65 | + * while channels 11--14 share one IRQ: | ||
66 | + */ | ||
67 | +#define SEPARATE_DMA_IRQ_MAX 10 | ||
68 | +#define ORGATED_DMA_IRQ_COUNT 4 | ||
69 | + | ||
70 | static void create_unimp(BCM2835PeripheralState *ps, | ||
71 | UnimplementedDeviceState *uds, | ||
72 | const char *name, hwaddr ofs, hwaddr size) | ||
73 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_init(Object *obj) | ||
74 | /* DMA Channels */ | ||
75 | object_initialize_child(obj, "dma", &s->dma, TYPE_BCM2835_DMA); | ||
76 | |||
77 | + object_initialize_child(obj, "orgated-dma-irq", | ||
78 | + &s->orgated_dma_irq, TYPE_OR_IRQ); | ||
79 | + object_property_set_int(OBJECT(&s->orgated_dma_irq), "num-lines", | ||
80 | + ORGATED_DMA_IRQ_COUNT, &error_abort); | ||
81 | + | ||
82 | object_property_add_const_link(OBJECT(&s->dma), "dma-mr", | ||
83 | OBJECT(&s->gpu_bus_mr)); | ||
84 | |||
85 | @@ -XXX,XX +XXX,XX @@ static void bcm2835_peripherals_realize(DeviceState *dev, Error **errp) | ||
86 | memory_region_add_subregion(&s->peri_mr, DMA15_OFFSET, | ||
87 | sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->dma), 1)); | ||
88 | |||
89 | - for (n = 0; n <= 12; n++) { | ||
90 | + for (n = 0; n <= SEPARATE_DMA_IRQ_MAX; n++) { | ||
91 | sysbus_connect_irq(SYS_BUS_DEVICE(&s->dma), n, | ||
92 | qdev_get_gpio_in_named(DEVICE(&s->ic), | ||
93 | BCM2835_IC_GPU_IRQ, | ||
94 | INTERRUPT_DMA0 + n)); | ||
95 | } | ||
96 | + if (!qdev_realize(DEVICE(&s->orgated_dma_irq), NULL, errp)) { | ||
97 | + return; | ||
98 | + } | ||
99 | + for (n = 0; n < ORGATED_DMA_IRQ_COUNT; n++) { | ||
100 | + sysbus_connect_irq(SYS_BUS_DEVICE(&s->dma), | ||
101 | + SEPARATE_DMA_IRQ_MAX + 1 + n, | ||
102 | + qdev_get_gpio_in(DEVICE(&s->orgated_dma_irq), n)); | ||
103 | + } | ||
104 | + qdev_connect_gpio_out(DEVICE(&s->orgated_dma_irq), 0, | ||
105 | + qdev_get_gpio_in_named(DEVICE(&s->ic), | ||
106 | + BCM2835_IC_GPU_IRQ, | ||
107 | + INTERRUPT_DMA0 + SEPARATE_DMA_IRQ_MAX + 1)); | ||
108 | |||
109 | /* THERMAL */ | ||
110 | if (!sysbus_realize(SYS_BUS_DEVICE(&s->thermal), errp)) { | ||
111 | diff --git a/tests/qtest/bcm2835-dma-test.c b/tests/qtest/bcm2835-dma-test.c | ||
112 | new file mode 100644 | ||
113 | index XXXXXXX..XXXXXXX | ||
114 | --- /dev/null | ||
115 | +++ b/tests/qtest/bcm2835-dma-test.c | ||
116 | @@ -XXX,XX +XXX,XX @@ | ||
117 | +/* | ||
118 | + * QTest testcase for BCM283x DMA engine (on Raspberry Pi 3) | ||
119 | + * and its interrupts coming to Interrupt Controller. | ||
37 | + * | 120 | + * |
38 | * This code is licensed under the GNU GPLv2 and later. | 121 | + * Copyright (c) 2022 Auriga LLC |
39 | */ | 122 | + * |
40 | 123 | + * SPDX-License-Identifier: GPL-2.0-or-later | |
41 | @@ -XXX,XX +XXX,XX @@ | 124 | + */ |
42 | #define SMPBOOT_ADDR 0x300 /* this should leave enough space for ATAGS */ | 125 | + |
43 | #define MVBAR_ADDR 0x400 /* secure vectors */ | 126 | +#include "qemu/osdep.h" |
44 | #define BOARDSETUP_ADDR (MVBAR_ADDR + 0x20) /* board setup code */ | 127 | +#include "libqtest-single.h" |
45 | -#define FIRMWARE_ADDR 0x8000 /* Pi loads kernel.img here by default */ | 128 | + |
46 | +#define FIRMWARE_ADDR_2 0x8000 /* Pi 2 loads kernel.img here by default */ | 129 | +/* Offsets in raspi3b platform: */ |
47 | +#define FIRMWARE_ADDR_3 0x80000 /* Pi 3 loads kernel.img here by default */ | 130 | +#define RASPI3_DMA_BASE 0x3f007000 |
48 | 131 | +#define RASPI3_IC_BASE 0x3f00b200 | |
49 | /* Table of Linux board IDs for different Pi versions */ | 132 | + |
50 | -static const int raspi_boardid[] = {[1] = 0xc42, [2] = 0xc43}; | 133 | +/* Used register/fields definitions */ |
51 | +static const int raspi_boardid[] = {[1] = 0xc42, [2] = 0xc43, [3] = 0xc44}; | 134 | + |
52 | 135 | +/* DMA engine registers: */ | |
53 | typedef struct RasPiState { | 136 | +#define BCM2708_DMA_CS 0 |
54 | BCM2836State soc; | 137 | +#define BCM2708_DMA_ACTIVE (1 << 0) |
55 | @@ -XXX,XX +XXX,XX @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) | 138 | +#define BCM2708_DMA_INT (1 << 2) |
56 | binfo.secure_board_setup = true; | 139 | + |
57 | binfo.secure_boot = true; | 140 | +#define BCM2708_DMA_ADDR 0x04 |
58 | 141 | + | |
59 | - /* Pi2 requires SMP setup */ | 142 | +#define BCM2708_DMA_INT_STATUS 0xfe0 |
60 | - if (version == 2) { | 143 | + |
61 | + /* Pi2 and Pi3 requires SMP setup */ | 144 | +/* DMA Trasfer Info fields: */ |
62 | + if (version >= 2) { | 145 | +#define BCM2708_DMA_INT_EN (1 << 0) |
63 | binfo.smp_loader_start = SMPBOOT_ADDR; | 146 | +#define BCM2708_DMA_D_INC (1 << 4) |
64 | binfo.write_secondary_boot = write_smpboot; | 147 | +#define BCM2708_DMA_S_INC (1 << 8) |
65 | binfo.secondary_cpu_reset_hook = reset_secondary; | 148 | + |
66 | @@ -XXX,XX +XXX,XX @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) | 149 | +/* Interrupt controller registers: */ |
67 | * the normal Linux boot process | 150 | +#define IRQ_PENDING_BASIC 0x00 |
68 | */ | 151 | +#define IRQ_GPU_PENDING1_AGGR (1 << 8) |
69 | if (machine->firmware) { | 152 | +#define IRQ_PENDING_1 0x04 |
70 | + hwaddr firmware_addr = version == 3 ? FIRMWARE_ADDR_3 : FIRMWARE_ADDR_2; | 153 | +#define IRQ_ENABLE_1 0x10 |
71 | /* load the firmware image (typically kernel.img) */ | 154 | + |
72 | - r = load_image_targphys(machine->firmware, FIRMWARE_ADDR, | 155 | +/* Data for the test: */ |
73 | - ram_size - FIRMWARE_ADDR); | 156 | +#define SCB_ADDR 256 |
74 | + r = load_image_targphys(machine->firmware, firmware_addr, | 157 | +#define S_ADDR 32 |
75 | + ram_size - firmware_addr); | 158 | +#define D_ADDR 64 |
76 | if (r < 0) { | 159 | +#define TXFR_LEN 32 |
77 | error_report("Failed to load firmware from %s", machine->firmware); | 160 | +const uint32_t check_data = 0x12345678; |
78 | exit(1); | 161 | + |
79 | } | 162 | +static void bcm2835_dma_test_interrupt(int dma_c, int irq_line) |
80 | 163 | +{ | |
81 | - binfo.entry = FIRMWARE_ADDR; | 164 | + uint64_t dma_base = RASPI3_DMA_BASE + dma_c * 0x100; |
82 | + binfo.entry = firmware_addr; | 165 | + int gpu_irq_line = 16 + irq_line; |
83 | binfo.firmware_loaded = true; | 166 | + |
84 | } else { | 167 | + /* Check that interrupts are silent by default: */ |
85 | binfo.kernel_filename = machine->kernel_filename; | 168 | + writel(RASPI3_IC_BASE + IRQ_ENABLE_1, 1 << gpu_irq_line); |
86 | @@ -XXX,XX +XXX,XX @@ static void setup_boot(MachineState *machine, int version, size_t ram_size) | 169 | + int isr = readl(dma_base + BCM2708_DMA_INT_STATUS); |
87 | arm_load_kernel(ARM_CPU(first_cpu), &binfo); | 170 | + g_assert_cmpint(isr, ==, 0); |
88 | } | 171 | + uint32_t reg0 = readl(dma_base + BCM2708_DMA_CS); |
89 | 172 | + g_assert_cmpint(reg0, ==, 0); | |
90 | -static void raspi2_init(MachineState *machine) | 173 | + uint32_t ic_pending = readl(RASPI3_IC_BASE + IRQ_PENDING_BASIC); |
91 | +static void raspi_init(MachineState *machine, int version) | 174 | + g_assert_cmpint(ic_pending, ==, 0); |
92 | { | 175 | + uint32_t gpu_pending1 = readl(RASPI3_IC_BASE + IRQ_PENDING_1); |
93 | RasPiState *s = g_new0(RasPiState, 1); | 176 | + g_assert_cmpint(gpu_pending1, ==, 0); |
94 | uint32_t vcram_size; | 177 | + |
95 | @@ -XXX,XX +XXX,XX @@ static void raspi2_init(MachineState *machine) | 178 | + /* Prepare Control Block: */ |
96 | &error_abort); | 179 | + writel(SCB_ADDR + 0, BCM2708_DMA_S_INC | BCM2708_DMA_D_INC | |
97 | object_property_set_int(OBJECT(&s->soc), smp_cpus, "enabled-cpus", | 180 | + BCM2708_DMA_INT_EN); /* transfer info */ |
98 | &error_abort); | 181 | + writel(SCB_ADDR + 4, S_ADDR); /* source address */ |
99 | - object_property_set_int(OBJECT(&s->soc), 0xa21041, "board-rev", | 182 | + writel(SCB_ADDR + 8, D_ADDR); /* destination address */ |
100 | + int board_rev = version == 3 ? 0xa02082 : 0xa21041; | 183 | + writel(SCB_ADDR + 12, TXFR_LEN); /* transfer length */ |
101 | + object_property_set_int(OBJECT(&s->soc), board_rev, "board-rev", | 184 | + writel(dma_base + BCM2708_DMA_ADDR, SCB_ADDR); |
102 | &error_abort); | 185 | + |
103 | object_property_set_bool(OBJECT(&s->soc), true, "realized", &error_abort); | 186 | + writel(S_ADDR, check_data); |
104 | 187 | + for (int word = S_ADDR + 4; word < S_ADDR + TXFR_LEN; word += 4) { | |
105 | @@ -XXX,XX +XXX,XX @@ static void raspi2_init(MachineState *machine) | 188 | + writel(word, ~check_data); |
106 | 189 | + } | |
107 | vcram_size = object_property_get_uint(OBJECT(&s->soc), "vcram-size", | 190 | + /* Perform the transfer: */ |
108 | &error_abort); | 191 | + writel(dma_base + BCM2708_DMA_CS, BCM2708_DMA_ACTIVE); |
109 | - setup_boot(machine, 2, machine->ram_size - vcram_size); | 192 | + |
110 | + setup_boot(machine, version, machine->ram_size - vcram_size); | 193 | + /* Check that destination == source: */ |
194 | + uint32_t data = readl(D_ADDR); | ||
195 | + g_assert_cmpint(data, ==, check_data); | ||
196 | + for (int word = D_ADDR + 4; word < D_ADDR + TXFR_LEN; word += 4) { | ||
197 | + data = readl(word); | ||
198 | + g_assert_cmpint(data, ==, ~check_data); | ||
199 | + } | ||
200 | + | ||
201 | + /* Check that interrupt status is set both in DMA and IC controllers: */ | ||
202 | + isr = readl(RASPI3_DMA_BASE + BCM2708_DMA_INT_STATUS); | ||
203 | + g_assert_cmpint(isr, ==, 1 << dma_c); | ||
204 | + | ||
205 | + ic_pending = readl(RASPI3_IC_BASE + IRQ_PENDING_BASIC); | ||
206 | + g_assert_cmpint(ic_pending, ==, IRQ_GPU_PENDING1_AGGR); | ||
207 | + | ||
208 | + gpu_pending1 = readl(RASPI3_IC_BASE + IRQ_PENDING_1); | ||
209 | + g_assert_cmpint(gpu_pending1, ==, 1 << gpu_irq_line); | ||
210 | + | ||
211 | + /* Clean up, clear interrupt: */ | ||
212 | + writel(dma_base + BCM2708_DMA_CS, BCM2708_DMA_INT); | ||
111 | +} | 213 | +} |
112 | + | 214 | + |
113 | +static void raspi2_init(MachineState *machine) | 215 | +static void bcm2835_dma_test_interrupts(void) |
114 | +{ | 216 | +{ |
115 | + raspi_init(machine, 2); | 217 | + /* DMA engines 0--10 have separate IRQ lines, 11--14 - only one: */ |
116 | } | 218 | + bcm2835_dma_test_interrupt(0, 0); |
117 | 219 | + bcm2835_dma_test_interrupt(10, 10); | |
118 | static void raspi2_machine_init(MachineClass *mc) | 220 | + bcm2835_dma_test_interrupt(11, 11); |
221 | + bcm2835_dma_test_interrupt(14, 11); | ||
222 | +} | ||
223 | + | ||
224 | +int main(int argc, char **argv) | ||
225 | +{ | ||
226 | + int ret; | ||
227 | + g_test_init(&argc, &argv, NULL); | ||
228 | + qtest_add_func("/bcm2835/dma/test_interrupts", | ||
229 | + bcm2835_dma_test_interrupts); | ||
230 | + qtest_start("-machine raspi3b"); | ||
231 | + ret = g_test_run(); | ||
232 | + qtest_end(); | ||
233 | + return ret; | ||
234 | +} | ||
235 | diff --git a/tests/qtest/meson.build b/tests/qtest/meson.build | ||
236 | index XXXXXXX..XXXXXXX 100644 | ||
237 | --- a/tests/qtest/meson.build | ||
238 | +++ b/tests/qtest/meson.build | ||
239 | @@ -XXX,XX +XXX,XX @@ qtests_aarch64 = \ | ||
240 | ['arm-cpu-features', | ||
241 | 'numa-test', | ||
242 | 'boot-serial-test', | ||
243 | - 'migration-test'] | ||
244 | + 'migration-test', | ||
245 | + 'bcm2835-dma-test'] | ||
246 | |||
247 | qtests_s390x = \ | ||
248 | (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) + \ | ||
119 | -- | 249 | -- |
120 | 2.16.1 | 250 | 2.25.1 |
121 | |||
122 | diff view generated by jsdifflib |