1 | Latest run of arm patches -- most of these are Philippe's SD card | 1 | Some arm patches before softfreeze. These are all bug fixes. |
---|---|---|---|
2 | cleanups. I have more in my queue to review, but 32 is enough | ||
3 | patches to warrant sending out. | ||
4 | 2 | ||
5 | thanks | ||
6 | -- PMM | 3 | -- PMM |
7 | 4 | ||
8 | The following changes since commit ff8689611a1d954897d857b28f7ef404e11cfa2c: | 5 | The following changes since commit 0ebf76aae58324b8f7bf6af798696687f5f4c2a9: |
9 | 6 | ||
10 | Merge remote-tracking branch 'remotes/mcayland/tags/qemu-openbios-signed' into staging (2018-02-22 11:37:05 +0000) | 7 | Merge tag 'nvme-next-pull-request' of git://git.infradead.org/qemu-nvme into staging (2022-07-15 15:38:13 +0100) |
11 | 8 | ||
12 | are available in the Git repository at: | 9 | are available in the Git repository at: |
13 | 10 | ||
14 | git://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20180222 | 11 | https://git.linaro.org/people/pmaydell/qemu-arm.git tags/pull-target-arm-20220718 |
15 | 12 | ||
16 | for you to fetch changes up to 4e5cc6756586e967993187657dfcdde4e00288d9: | 13 | for you to fetch changes up to 004c8a8bc569c8b18fca6fc90ffe3223daaf17b7: |
17 | 14 | ||
18 | sdcard: simplify SD_SEND_OP_COND (ACMD41) (2018-02-22 15:12:54 +0000) | 15 | Align Raspberry Pi DMA interrupts with Linux DTS (2022-07-18 13:25:13 +0100) |
19 | 16 | ||
20 | ---------------------------------------------------------------- | 17 | ---------------------------------------------------------------- |
21 | * New "raspi3" machine emulating RaspberryPi 3 | 18 | target-arm queue: |
22 | * Fix bad register definitions for VMIDR and VMPIDR (which caused | 19 | * hw/intc/armv7m_nvic: ICPRn must not unpend an IRQ that is being held high |
23 | assertions for 64-bit guest CPUs with EL2 on big-endian hosts) | 20 | * target/arm: Fill in VL for tbflags when SME enabled and SVE disabled |
24 | * hw/char/stm32f2xx_usart: fix TXE/TC bit handling | 21 | * target/arm: Fix aarch64_sve_change_el for SME |
25 | * Fix ast2500 protection register emulation | 22 | * linux-user/aarch64: Do not clear PROT_MTE on mprotect |
26 | * Lots of SD card emulation cleanups and bugfixes | 23 | * target/arm: Honour VTCR_EL2 bits in Secure EL2 |
24 | * hw/adc: Fix CONV bit in NPCM7XX ADC CON register | ||
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 | ||
27 | 28 | ||
28 | ---------------------------------------------------------------- | 29 | ---------------------------------------------------------------- |
29 | Hugo Landau (1): | 30 | Andrey Makarov (1): |
30 | Fix ast2500 protection register emulation | 31 | Align Raspberry Pi DMA interrupts with Linux DTS |
31 | 32 | ||
32 | Pekka Enberg (1): | 33 | Hao Wu (2): |
33 | raspi: Add "raspi3" machine type | 34 | hw/adc: Fix CONV bit in NPCM7XX ADC CON register |
35 | hw/adc: Make adci[*] R/W in NPCM7XX ADC | ||
34 | 36 | ||
35 | Peter Maydell (1): | 37 | Peter Maydell (9): |
36 | target/arm: Fix register definitions for VMIDR and VMPIDR | 38 | hw/intc/armv7m_nvic: ICPRn must not unpend an IRQ that is being held high |
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 | ||
37 | 47 | ||
38 | Philippe Mathieu-Daudé (28): | 48 | Richard Henderson (3): |
39 | hw/sd/milkymist-memcard: use qemu_log_mask() | 49 | target/arm: Fill in VL for tbflags when SME enabled and SVE disabled |
40 | hw/sd/milkymist-memcard: split realize() out of SysBusDevice init() | 50 | target/arm: Fix aarch64_sve_change_el for SME |
41 | hw/sd/milkymist-memcard: expose a SDBus and connect the SDCard to it | 51 | linux-user/aarch64: Do not clear PROT_MTE on mprotect |
42 | hw/sd/ssi-sd: use the SDBus API, connect the SDCard to the bus | ||
43 | sdcard: reorder SDState struct members | ||
44 | sdcard: replace DPRINTF() by trace events | ||
45 | sdcard: add a trace event for command responses | ||
46 | sdcard: replace fprintf() by qemu_hexdump() | ||
47 | sdcard: add more trace events | ||
48 | sdcard: define SDMMC_CMD_MAX instead of using the magic '64' | ||
49 | sdcard: use G_BYTE from cutils | ||
50 | sdcard: use the registerfields API to access the OCR register | ||
51 | sdcard: Don't always set the high capacity bit | ||
52 | sdcard: update the CSD CRC register regardless the CSD structure version | ||
53 | sdcard: fix the 'maximum data transfer rate' to 25MHz | ||
54 | sdcard: clean the SCR register and add few comments | ||
55 | sdcard: remove commands from unsupported old MMC specification | ||
56 | sdcard: simplify using the ldst API | ||
57 | sdcard: use the correct masked OCR in the R3 reply | ||
58 | sdcard: use the registerfields API for the CARD_STATUS register masks | ||
59 | sdcard: handle CMD54 (SDIO) | ||
60 | sdcard: handle the Security Specification commands | ||
61 | sdcard: use a more descriptive label 'unimplemented_spi_cmd' | ||
62 | sdcard: handles more commands in SPI mode | ||
63 | sdcard: check the card is in correct state for APP CMD (CMD55) | ||
64 | sdcard: warn if host uses an incorrect address for APP CMD (CMD55) | ||
65 | sdcard: simplify SEND_IF_COND (CMD8) | ||
66 | sdcard: simplify SD_SEND_OP_COND (ACMD41) | ||
67 | 52 | ||
68 | Richard Braun (1): | 53 | include/hw/arm/bcm2835_peripherals.h | 2 + |
69 | hw/char/stm32f2xx_usart: fix TXE/TC bit handling | 54 | target/arm/cpu.h | 38 ++++++++--- |
70 | 55 | target/arm/internals.h | 34 +++++++--- | |
71 | hw/sd/sdmmc-internal.h | 15 ++ | 56 | accel/tcg/translate-all.c | 13 +++- |
72 | include/hw/char/stm32f2xx_usart.h | 7 +- | 57 | hw/adc/npcm7xx_adc.c | 4 +- |
73 | include/hw/sd/sd.h | 1 - | 58 | hw/arm/bcm2835_peripherals.c | 26 ++++++- |
74 | hw/arm/raspi.c | 23 ++ | 59 | hw/intc/armv7m_nvic.c | 9 ++- |
75 | hw/char/stm32f2xx_usart.c | 12 +- | 60 | target/arm/cpu.c | 2 +- |
76 | hw/misc/aspeed_scu.c | 6 +- | 61 | target/arm/debug_helper.c | 2 +- |
77 | hw/misc/aspeed_sdmc.c | 8 +- | 62 | target/arm/helper.c | 128 ++++++++++++++++------------------- |
78 | hw/sd/milkymist-memcard.c | 87 +++---- | 63 | target/arm/ptw.c | 38 ++++++----- |
79 | hw/sd/sd.c | 467 +++++++++++++++++++++++--------------- | 64 | target/arm/tlb_helper.c | 2 +- |
80 | hw/sd/ssi-sd.c | 32 +-- | 65 | target/arm/translate-a64.c | 4 +- |
81 | target/arm/helper.c | 8 +- | 66 | tests/qtest/bcm2835-dma-test.c | 118 ++++++++++++++++++++++++++++++++ |
82 | hw/sd/trace-events | 20 ++ | 67 | tests/qtest/npcm7xx_adc-test.c | 2 +- |
83 | 12 files changed, 446 insertions(+), 240 deletions(-) | 68 | tests/qtest/meson.build | 3 +- |
84 | create mode 100644 hw/sd/sdmmc-internal.h | 69 | 16 files changed, 306 insertions(+), 119 deletions(-) |
85 | 70 | create mode 100644 tests/qtest/bcm2835-dma-test.c | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | In the M-profile Arm ARM, rule R_CVJS defines when an interrupt should |
---|---|---|---|
2 | be set to the Pending state: | ||
3 | A) when the input line is high and the interrupt is not Active | ||
4 | B) when the input line transitions from low to high and the interrupt | ||
5 | is Active | ||
6 | (Note that the first of these is an ongoing condition, and the | ||
7 | second is a point-in-time event.) | ||
2 | 8 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | This can be rephrased as: |
4 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | 10 | 1 when the line goes from low to high, set Pending |
5 | Message-id: 20180215221325.7611-15-f4bug@amsat.org | 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> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 36 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
37 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
38 | Message-id: 20220628154724.3297442-1-peter.maydell@linaro.org | ||
7 | --- | 39 | --- |
8 | hw/sd/sd.c | 5 +++++ | 40 | hw/intc/armv7m_nvic.c | 9 ++++++++- |
9 | 1 file changed, 5 insertions(+) | 41 | 1 file changed, 8 insertions(+), 1 deletion(-) |
10 | 42 | ||
11 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 43 | diff --git a/hw/intc/armv7m_nvic.c b/hw/intc/armv7m_nvic.c |
12 | index XXXXXXX..XXXXXXX 100644 | 44 | index XXXXXXX..XXXXXXX 100644 |
13 | --- a/hw/sd/sd.c | 45 | --- a/hw/intc/armv7m_nvic.c |
14 | +++ b/hw/sd/sd.c | 46 | +++ b/hw/intc/armv7m_nvic.c |
15 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | 47 | @@ -XXX,XX +XXX,XX @@ static MemTxResult nvic_sysreg_write(void *opaque, hwaddr addr, |
16 | case sd_identification_state: | 48 | startvec = 8 * (offset - 0x280) + NVIC_FIRST_IRQ; /* vector # */ |
17 | case sd_inactive_state: | 49 | |
18 | return sd_illegal; | 50 | for (i = 0, end = size * 8; i < end && startvec + i < s->num_irq; i++) { |
19 | + case sd_idle_state: | 51 | + /* |
20 | + if (rca) { | 52 | + * Note that if the input line is still held high and the interrupt |
21 | + qemu_log_mask(LOG_GUEST_ERROR, | 53 | + * is not active then rule R_CVJS requires that the Pending state |
22 | + "SD: illegal RCA 0x%04x for APP_CMD\n", req.cmd); | 54 | + * remains set; in that case we mustn't let it be cleared. |
23 | + } | 55 | + */ |
24 | default: | 56 | if (value & (1 << i) && |
25 | break; | 57 | - (attrs.secure || s->itns[startvec + i])) { |
58 | + (attrs.secure || s->itns[startvec + i]) && | ||
59 | + !(setval == 0 && s->vectors[startvec + i].level && | ||
60 | + !s->vectors[startvec + i].active)) { | ||
61 | s->vectors[startvec + i].pending = setval; | ||
62 | } | ||
26 | } | 63 | } |
27 | -- | 64 | -- |
28 | 2.16.1 | 65 | 2.25.1 |
29 | 66 | ||
30 | 67 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 3 | When PSTATE.SM, VL = SVL even if SVE is disabled. |
4 | Acked-by: Alistair Francis <alistair.francis@xilinx.com> | 4 | This is visible in kselftest ssve-test. |
5 | Message-id: 20180215221325.7611-9-f4bug@amsat.org | 5 | |
6 | Reported-by: Mark Brown <broonie@kernel.org> | ||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20220713045848.217364-2-richard.henderson@linaro.org | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
8 | --- | 11 | --- |
9 | hw/sd/sd.c | 48 +++++++++++++++++++++++++++++++++++++++++++++--- | 12 | target/arm/helper.c | 10 ++++++++-- |
10 | 1 file changed, 45 insertions(+), 3 deletions(-) | 13 | 1 file changed, 8 insertions(+), 2 deletions(-) |
11 | 14 | ||
12 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 15 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
13 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/sd/sd.c | 17 | --- a/target/arm/helper.c |
15 | +++ b/hw/sd/sd.c | 18 | +++ b/target/arm/helper.c |
16 | @@ -XXX,XX +XXX,XX @@ static void sd_set_rca(SDState *sd) | 19 | @@ -XXX,XX +XXX,XX @@ static CPUARMTBFlags rebuild_hflags_a64(CPUARMState *env, int el, int fp_el, |
17 | sd->rca += 0x4567; | 20 | } |
18 | } | 21 | if (cpu_isar_feature(aa64_sme, env_archcpu(env))) { |
19 | 22 | int sme_el = sme_exception_el(env, el); | |
20 | +FIELD(CSR, AKE_SEQ_ERROR, 3, 1) | 23 | + bool sm = FIELD_EX64(env->svcr, SVCR, SM); |
21 | +FIELD(CSR, APP_CMD, 5, 1) | 24 | |
22 | +FIELD(CSR, FX_EVENT, 6, 1) | 25 | DP_TBFLAG_A64(flags, SMEEXC_EL, sme_el); |
23 | +FIELD(CSR, READY_FOR_DATA, 8, 1) | 26 | if (sme_el == 0) { |
24 | +FIELD(CSR, CURRENT_STATE, 9, 4) | 27 | /* Similarly, do not compute SVL if SME is disabled. */ |
25 | +FIELD(CSR, ERASE_RESET, 13, 1) | 28 | - DP_TBFLAG_A64(flags, SVL, sve_vqm1_for_el_sm(env, el, true)); |
26 | +FIELD(CSR, CARD_ECC_DISABLED, 14, 1) | 29 | + int svl = sve_vqm1_for_el_sm(env, el, true); |
27 | +FIELD(CSR, WP_ERASE_SKIP, 15, 1) | 30 | + DP_TBFLAG_A64(flags, SVL, svl); |
28 | +FIELD(CSR, CSD_OVERWRITE, 16, 1) | 31 | + if (sm) { |
29 | +FIELD(CSR, DEFERRED_RESPONSE, 17, 1) | 32 | + /* If SVE is disabled, we will not have set VL above. */ |
30 | +FIELD(CSR, ERROR, 19, 1) | 33 | + DP_TBFLAG_A64(flags, VL, svl); |
31 | +FIELD(CSR, CC_ERROR, 20, 1) | 34 | + } |
32 | +FIELD(CSR, CARD_ECC_FAILED, 21, 1) | 35 | } |
33 | +FIELD(CSR, ILLEGAL_COMMAND, 22, 1) | 36 | - if (FIELD_EX64(env->svcr, SVCR, SM)) { |
34 | +FIELD(CSR, COM_CRC_ERROR, 23, 1) | 37 | + if (sm) { |
35 | +FIELD(CSR, LOCK_UNLOCK_FAILED, 24, 1) | 38 | DP_TBFLAG_A64(flags, PSTATE_SM, 1); |
36 | +FIELD(CSR, CARD_IS_LOCKED, 25, 1) | 39 | DP_TBFLAG_A64(flags, SME_TRAP_NONSTREAMING, !sme_fa64(env, el)); |
37 | +FIELD(CSR, WP_VIOLATION, 26, 1) | 40 | } |
38 | +FIELD(CSR, ERASE_PARAM, 27, 1) | ||
39 | +FIELD(CSR, ERASE_SEQ_ERROR, 28, 1) | ||
40 | +FIELD(CSR, BLOCK_LEN_ERROR, 29, 1) | ||
41 | +FIELD(CSR, ADDRESS_ERROR, 30, 1) | ||
42 | +FIELD(CSR, OUT_OF_RANGE, 31, 1) | ||
43 | + | ||
44 | /* Card status bits, split by clear condition: | ||
45 | * A : According to the card current state | ||
46 | * B : Always related to the previous command | ||
47 | * C : Cleared by read | ||
48 | */ | ||
49 | -#define CARD_STATUS_A 0x02004100 | ||
50 | -#define CARD_STATUS_B 0x00c01e00 | ||
51 | -#define CARD_STATUS_C 0xfd39a028 | ||
52 | +#define CARD_STATUS_A (R_CSR_READY_FOR_DATA_MASK \ | ||
53 | + | R_CSR_CARD_ECC_DISABLED_MASK \ | ||
54 | + | R_CSR_CARD_IS_LOCKED_MASK) | ||
55 | +#define CARD_STATUS_B (R_CSR_CURRENT_STATE_MASK \ | ||
56 | + | R_CSR_ILLEGAL_COMMAND_MASK \ | ||
57 | + | R_CSR_COM_CRC_ERROR_MASK) | ||
58 | +#define CARD_STATUS_C (R_CSR_AKE_SEQ_ERROR_MASK \ | ||
59 | + | R_CSR_APP_CMD_MASK \ | ||
60 | + | R_CSR_ERASE_RESET_MASK \ | ||
61 | + | R_CSR_WP_ERASE_SKIP_MASK \ | ||
62 | + | R_CSR_CSD_OVERWRITE_MASK \ | ||
63 | + | R_CSR_ERROR_MASK \ | ||
64 | + | R_CSR_CC_ERROR_MASK \ | ||
65 | + | R_CSR_CARD_ECC_FAILED_MASK \ | ||
66 | + | R_CSR_LOCK_UNLOCK_FAILED_MASK \ | ||
67 | + | R_CSR_WP_VIOLATION_MASK \ | ||
68 | + | R_CSR_ERASE_PARAM_MASK \ | ||
69 | + | R_CSR_ERASE_SEQ_ERROR_MASK \ | ||
70 | + | R_CSR_BLOCK_LEN_ERROR_MASK \ | ||
71 | + | R_CSR_ADDRESS_ERROR_MASK \ | ||
72 | + | R_CSR_OUT_OF_RANGE_MASK) | ||
73 | |||
74 | static void sd_set_cardstatus(SDState *sd) | ||
75 | { | ||
76 | -- | 41 | -- |
77 | 2.16.1 | 42 | 2.25.1 |
78 | |||
79 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 3 | We were only checking for SVE disabled and not taking into |
4 | Message-id: 20180215220540.6556-4-f4bug@amsat.org | 4 | account PSTATE.SM to check SME disabled, which resulted in |
5 | vectors being incorrectly truncated. | ||
6 | |||
7 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20220713045848.217364-3-richard.henderson@linaro.org | ||
5 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 11 | --- |
8 | hw/sd/sd.c | 27 ++++++++++++++++++++++++--- | 12 | target/arm/helper.c | 31 +++++++++++++++++++++++++------ |
9 | hw/sd/trace-events | 1 + | 13 | 1 file changed, 25 insertions(+), 6 deletions(-) |
10 | 2 files changed, 25 insertions(+), 3 deletions(-) | ||
11 | 14 | ||
12 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 15 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
13 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/sd/sd.c | 17 | --- a/target/arm/helper.c |
15 | +++ b/hw/sd/sd.c | 18 | +++ b/target/arm/helper.c |
16 | @@ -XXX,XX +XXX,XX @@ static const char *sd_state_name(enum SDCardStates state) | 19 | @@ -XXX,XX +XXX,XX @@ void aarch64_sve_narrow_vq(CPUARMState *env, unsigned vq) |
17 | return state_name[state]; | 20 | } |
18 | } | 21 | } |
19 | 22 | ||
20 | +static const char *sd_response_name(sd_rsp_type_t rsp) | 23 | +static uint32_t sve_vqm1_for_el_sm_ena(CPUARMState *env, int el, bool sm) |
21 | +{ | 24 | +{ |
22 | + static const char *response_name[] = { | 25 | + int exc_el; |
23 | + [sd_r0] = "RESP#0 (no response)", | 26 | + |
24 | + [sd_r1] = "RESP#1 (normal cmd)", | 27 | + if (sm) { |
25 | + [sd_r2_i] = "RESP#2 (CID reg)", | 28 | + exc_el = sme_exception_el(env, el); |
26 | + [sd_r2_s] = "RESP#2 (CSD reg)", | 29 | + } else { |
27 | + [sd_r3] = "RESP#3 (OCR reg)", | 30 | + exc_el = sve_exception_el(env, el); |
28 | + [sd_r6] = "RESP#6 (RCA)", | ||
29 | + [sd_r7] = "RESP#7 (operating voltage)", | ||
30 | + }; | ||
31 | + if (rsp == sd_illegal) { | ||
32 | + return "ILLEGAL RESP"; | ||
33 | + } | 31 | + } |
34 | + if (rsp == sd_r1b) { | 32 | + if (exc_el) { |
35 | + rsp = sd_r1; | 33 | + return 0; /* disabled */ |
36 | + } | 34 | + } |
37 | + assert(rsp <= ARRAY_SIZE(response_name)); | 35 | + return sve_vqm1_for_el_sm(env, el, sm); |
38 | + return response_name[rsp]; | ||
39 | +} | 36 | +} |
40 | + | 37 | + |
41 | static uint8_t sd_get_dat_lines(SDState *sd) | 38 | /* |
39 | * Notice a change in SVE vector size when changing EL. | ||
40 | */ | ||
41 | @@ -XXX,XX +XXX,XX @@ void aarch64_sve_change_el(CPUARMState *env, int old_el, | ||
42 | { | 42 | { |
43 | return sd->enable ? sd->dat_lines : 0; | 43 | ARMCPU *cpu = env_archcpu(env); |
44 | @@ -XXX,XX +XXX,XX @@ send_response: | 44 | int old_len, new_len; |
45 | 45 | - bool old_a64, new_a64; | |
46 | case sd_r0: | 46 | + bool old_a64, new_a64, sm; |
47 | case sd_illegal: | 47 | |
48 | - default: | 48 | /* Nothing to do if no SVE. */ |
49 | rsplen = 0; | 49 | if (!cpu_isar_feature(aa64_sve, cpu)) { |
50 | break; | 50 | @@ -XXX,XX +XXX,XX @@ void aarch64_sve_change_el(CPUARMState *env, int old_el, |
51 | + default: | 51 | * invoke ResetSVEState when taking an exception from, or |
52 | + g_assert_not_reached(); | 52 | * returning to, AArch32 state when PSTATE.SM is enabled. |
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; | ||
53 | } | 59 | } |
54 | + trace_sdcard_response(sd_response_name(rtype), rsplen); | 60 | @@ -XXX,XX +XXX,XX @@ void aarch64_sve_change_el(CPUARMState *env, int old_el, |
55 | 61 | * we already have the correct register contents when encountering the | |
56 | if (rtype != sd_illegal) { | 62 | * vq0->vq0 transition between EL0->EL1. |
57 | /* Clear the "clear on valid command" status bits now we've | 63 | */ |
58 | @@ -XXX,XX +XXX,XX @@ send_response: | 64 | - old_len = (old_a64 && !sve_exception_el(env, old_el) |
59 | DPRINTF(" %02x", response[i]); | 65 | - ? sve_vqm1_for_el(env, old_el) : 0); |
60 | } | 66 | - new_len = (new_a64 && !sve_exception_el(env, new_el) |
61 | DPRINTF(" state %d\n", sd->state); | 67 | - ? sve_vqm1_for_el(env, new_el) : 0); |
62 | - } else { | 68 | + old_len = new_len = 0; |
63 | - DPRINTF("No response %d\n", sd->state); | 69 | + if (old_a64) { |
64 | } | 70 | + old_len = sve_vqm1_for_el_sm_ena(env, old_el, sm); |
65 | #endif | 71 | + } |
66 | 72 | + if (new_a64) { | |
67 | diff --git a/hw/sd/trace-events b/hw/sd/trace-events | 73 | + new_len = sve_vqm1_for_el_sm_ena(env, new_el, sm); |
68 | index XXXXXXX..XXXXXXX 100644 | 74 | + } |
69 | --- a/hw/sd/trace-events | 75 | |
70 | +++ b/hw/sd/trace-events | 76 | /* When changing vector length, clear inaccessible state. */ |
71 | @@ -XXX,XX +XXX,XX @@ sdhci_capareg(const char *desc, uint16_t val) "%s: %u" | 77 | if (new_len < old_len) { |
72 | # hw/sd/sd.c | ||
73 | sdcard_normal_command(uint8_t cmd, uint32_t arg, const char *state) "CMD%d arg 0x%08x (state %s)" | ||
74 | sdcard_app_command(uint8_t acmd, uint32_t arg) "ACMD%d arg 0x%08x" | ||
75 | +sdcard_response(const char *rspdesc, int rsplen) "%s (sz:%d)" | ||
76 | sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" | ||
77 | sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" | ||
78 | |||
79 | -- | 78 | -- |
80 | 2.16.1 | 79 | 2.25.1 |
81 | |||
82 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Richard Henderson <richard.henderson@linaro.org> |
---|---|---|---|
2 | 2 | ||
3 | the code is easier to review/refactor. | 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. | ||
4 | 6 | ||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Introduce PAGE_TARGET_STICKY to allow target/arch/cpu.h to control |
6 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | 8 | which bits may be reset during page_set_flags. This is sort of the |
7 | Message-id: 20180215221325.7611-7-f4bug@amsat.org | 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> | ||
13 | Signed-off-by: Richard Henderson <richard.henderson@linaro.org> | ||
14 | Message-id: 20220711031420.17820-1-richard.henderson@linaro.org | ||
8 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | 15 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 16 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
10 | --- | 17 | --- |
11 | hw/sd/sd.c | 38 +++++++++----------------------------- | 18 | target/arm/cpu.h | 7 +++++-- |
12 | 1 file changed, 9 insertions(+), 29 deletions(-) | 19 | accel/tcg/translate-all.c | 13 +++++++++++-- |
20 | 2 files changed, 16 insertions(+), 4 deletions(-) | ||
13 | 21 | ||
14 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 22 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
15 | index XXXXXXX..XXXXXXX 100644 | 23 | index XXXXXXX..XXXXXXX 100644 |
16 | --- a/hw/sd/sd.c | 24 | --- a/target/arm/cpu.h |
17 | +++ b/hw/sd/sd.c | 25 | +++ b/target/arm/cpu.h |
18 | @@ -XXX,XX +XXX,XX @@ static int sd_req_crc_validate(SDRequest *req) | 26 | @@ -XXX,XX +XXX,XX @@ static inline MemTxAttrs *typecheck_memtxattrs(MemTxAttrs *x) |
19 | { | 27 | |
20 | uint8_t buffer[5]; | 28 | /* |
21 | buffer[0] = 0x40 | req->cmd; | 29 | * AArch64 usage of the PAGE_TARGET_* bits for linux-user. |
22 | - buffer[1] = (req->arg >> 24) & 0xff; | 30 | + * Note that with the Linux kernel, PROT_MTE may not be cleared by mprotect |
23 | - buffer[2] = (req->arg >> 16) & 0xff; | 31 | + * mprotect but PROT_BTI may be cleared. C.f. the kernel's VM_ARCH_CLEAR. |
24 | - buffer[3] = (req->arg >> 8) & 0xff; | 32 | */ |
25 | - buffer[4] = (req->arg >> 0) & 0xff; | 33 | -#define PAGE_BTI PAGE_TARGET_1 |
26 | + stl_be_p(&buffer[1], req->arg); | 34 | -#define PAGE_MTE PAGE_TARGET_2 |
27 | return 0; | 35 | +#define PAGE_BTI PAGE_TARGET_1 |
28 | return sd_crc7(buffer, 5) != req->crc; /* TODO */ | 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; | ||
29 | } | 47 | } |
30 | 48 | ||
31 | static void sd_response_r1_make(SDState *sd, uint8_t *response) | 49 | +/* |
32 | { | 50 | + * Allow the target to decide if PAGE_TARGET_[12] may be reset. |
33 | - uint32_t status = sd->card_status; | 51 | + * By default, they are not kept. |
34 | + stl_be_p(response, sd->card_status); | 52 | + */ |
53 | +#ifndef PAGE_TARGET_STICKY | ||
54 | +#define PAGE_TARGET_STICKY 0 | ||
55 | +#endif | ||
56 | +#define PAGE_STICKY (PAGE_ANON | PAGE_TARGET_STICKY) | ||
35 | + | 57 | + |
36 | /* Clear the "clear on read" status bits */ | 58 | /* Modify the flags of a page and invalidate the code if necessary. |
37 | sd->card_status &= ~CARD_STATUS_C; | 59 | The flag PAGE_WRITE_ORG is positioned automatically depending |
38 | - | 60 | on PAGE_WRITE. The mmap_lock should already be held. */ |
39 | - response[0] = (status >> 24) & 0xff; | 61 | @@ -XXX,XX +XXX,XX @@ void page_set_flags(target_ulong start, target_ulong end, int flags) |
40 | - response[1] = (status >> 16) & 0xff; | 62 | p->target_data = NULL; |
41 | - response[2] = (status >> 8) & 0xff; | 63 | p->flags = flags; |
42 | - response[3] = (status >> 0) & 0xff; | 64 | } else { |
65 | - /* Using mprotect on a page does not change MAP_ANON. */ | ||
66 | - p->flags = (p->flags & PAGE_ANON) | flags; | ||
67 | + /* Using mprotect on a page does not change sticky bits. */ | ||
68 | + p->flags = (p->flags & PAGE_STICKY) | flags; | ||
69 | } | ||
70 | } | ||
43 | } | 71 | } |
44 | |||
45 | static void sd_response_r3_make(SDState *sd, uint8_t *response) | ||
46 | { | ||
47 | - response[0] = (sd->ocr >> 24) & 0xff; | ||
48 | - response[1] = (sd->ocr >> 16) & 0xff; | ||
49 | - response[2] = (sd->ocr >> 8) & 0xff; | ||
50 | - response[3] = (sd->ocr >> 0) & 0xff; | ||
51 | + stl_be_p(response, sd->ocr); | ||
52 | } | ||
53 | |||
54 | static void sd_response_r6_make(SDState *sd, uint8_t *response) | ||
55 | { | ||
56 | - uint16_t arg; | ||
57 | uint16_t status; | ||
58 | |||
59 | - arg = sd->rca; | ||
60 | status = ((sd->card_status >> 8) & 0xc000) | | ||
61 | ((sd->card_status >> 6) & 0x2000) | | ||
62 | (sd->card_status & 0x1fff); | ||
63 | sd->card_status &= ~(CARD_STATUS_C & 0xc81fff); | ||
64 | - | ||
65 | - response[0] = (arg >> 8) & 0xff; | ||
66 | - response[1] = arg & 0xff; | ||
67 | - response[2] = (status >> 8) & 0xff; | ||
68 | - response[3] = status & 0xff; | ||
69 | + stw_be_p(response + 0, sd->rca); | ||
70 | + stw_be_p(response + 2, status); | ||
71 | } | ||
72 | |||
73 | static void sd_response_r7_make(SDState *sd, uint8_t *response) | ||
74 | { | ||
75 | - response[0] = (sd->vhs >> 24) & 0xff; | ||
76 | - response[1] = (sd->vhs >> 16) & 0xff; | ||
77 | - response[2] = (sd->vhs >> 8) & 0xff; | ||
78 | - response[3] = (sd->vhs >> 0) & 0xff; | ||
79 | + stl_be_p(response, sd->vhs); | ||
80 | } | ||
81 | |||
82 | static inline uint64_t sd_addr_to_wpnum(uint64_t addr) | ||
83 | @@ -XXX,XX +XXX,XX @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr) | ||
84 | |||
85 | static void sd_function_switch(SDState *sd, uint32_t arg) | ||
86 | { | ||
87 | - int i, mode, new_func, crc; | ||
88 | + int i, mode, new_func; | ||
89 | mode = !!(arg & 0x80000000); | ||
90 | |||
91 | sd->data[0] = 0x00; /* Maximum current consumption */ | ||
92 | @@ -XXX,XX +XXX,XX @@ static void sd_function_switch(SDState *sd, uint32_t arg) | ||
93 | sd->data[14 + (i >> 1)] = new_func << ((i * 4) & 4); | ||
94 | } | ||
95 | memset(&sd->data[17], 0, 47); | ||
96 | - crc = sd_crc16(sd->data, 64); | ||
97 | - sd->data[65] = crc >> 8; | ||
98 | - sd->data[66] = crc & 0xff; | ||
99 | + stw_be_p(sd->data + 65, sd_crc16(sd->data, 64)); | ||
100 | } | ||
101 | |||
102 | static inline bool sd_wp_addr(SDState *sd, uint64_t addr) | ||
103 | -- | 72 | -- |
104 | 2.16.1 | 73 | 2.25.1 |
105 | |||
106 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | The regime_tcr() function returns a pointer to a struct TCR |
---|---|---|---|
2 | corresponding to the TCR controlling a translation regime. The | ||
3 | struct TCR has the raw value of the register, plus two fields mask | ||
4 | and base_mask which are used as a small optimization in the case of | ||
5 | 32-bit short-descriptor lookups. Almost all callers of regime_tcr() | ||
6 | only want the raw register value. Define and use a new | ||
7 | regime_tcr_value() function which returns only the raw 64-bit | ||
8 | register value. | ||
2 | 9 | ||
3 | Create the SDCard in the realize() function. | 10 | This is a preliminary to removing the 32-bit short descriptor |
11 | optimization -- it only saves a handful of bit operations, which is | ||
12 | tiny compared to the overhead of doing a page table walk at all, and | ||
13 | the TCR struct is awkward and makes fixing | ||
14 | https://gitlab.com/qemu-project/qemu/-/issues/1103 unnecessarily | ||
15 | difficult. | ||
4 | 16 | ||
5 | Suggested-by: Michael Walle <michael@walle.cc> | ||
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
8 | Acked-by: Michael Walle <michael@walle.cc> | ||
9 | Message-id: 20180216022933.10945-3-f4bug@amsat.org | ||
10 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
19 | Message-id: 20220714132303.1287193-2-peter.maydell@linaro.org | ||
11 | --- | 20 | --- |
12 | hw/sd/milkymist-memcard.c | 28 ++++++++++++++++------------ | 21 | target/arm/internals.h | 6 ++++++ |
13 | 1 file changed, 16 insertions(+), 12 deletions(-) | 22 | target/arm/helper.c | 6 +++--- |
23 | target/arm/ptw.c | 8 ++++---- | ||
24 | target/arm/tlb_helper.c | 2 +- | ||
25 | 4 files changed, 14 insertions(+), 8 deletions(-) | ||
14 | 26 | ||
15 | diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c | 27 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
16 | index XXXXXXX..XXXXXXX 100644 | 28 | index XXXXXXX..XXXXXXX 100644 |
17 | --- a/hw/sd/milkymist-memcard.c | 29 | --- a/target/arm/internals.h |
18 | +++ b/hw/sd/milkymist-memcard.c | 30 | +++ b/target/arm/internals.h |
19 | @@ -XXX,XX +XXX,XX @@ static void milkymist_memcard_reset(DeviceState *d) | 31 | @@ -XXX,XX +XXX,XX @@ static inline TCR *regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
20 | device_reset(DEVICE(s->card)); | 32 | return &env->cp15.tcr_el[regime_el(env, mmu_idx)]; |
21 | } | 33 | } |
22 | 34 | ||
23 | -static int milkymist_memcard_init(SysBusDevice *dev) | 35 | +/* Return the raw value of the TCR controlling this translation regime */ |
24 | +static void milkymist_memcard_init(Object *obj) | 36 | +static inline uint64_t regime_tcr_value(CPUARMState *env, ARMMMUIdx mmu_idx) |
25 | +{ | 37 | +{ |
26 | + MilkymistMemcardState *s = MILKYMIST_MEMCARD(obj); | 38 | + return regime_tcr(env, mmu_idx)->raw_tcr; |
27 | + SysBusDevice *dev = SYS_BUS_DEVICE(obj); | ||
28 | + | ||
29 | + memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s, | ||
30 | + "milkymist-memcard", R_MAX * 4); | ||
31 | + sysbus_init_mmio(dev, &s->regs_region); | ||
32 | +} | 39 | +} |
33 | + | 40 | + |
34 | +static void milkymist_memcard_realize(DeviceState *dev, Error **errp) | 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) | ||
35 | { | 51 | { |
36 | MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev); | 52 | - uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; |
37 | - DriveInfo *dinfo; | 53 | + uint64_t tcr = regime_tcr_value(env, mmu_idx); |
38 | BlockBackend *blk; | 54 | int tbi = aa64_va_parameter_tbi(tcr, mmu_idx); |
39 | + DriveInfo *dinfo; | 55 | int select = extract64(addr, 55, 1); |
40 | 56 | ||
41 | /* FIXME use a qdev drive property instead of drive_get_next() */ | 57 | @@ -XXX,XX +XXX,XX @@ static int aa64_va_parameter_tcma(uint64_t tcr, ARMMMUIdx mmu_idx) |
42 | dinfo = drive_get_next(IF_SD); | 58 | ARMVAParameters aa64_va_parameters(CPUARMState *env, uint64_t va, |
43 | blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; | 59 | ARMMMUIdx mmu_idx, bool data) |
44 | s->card = sd_init(blk, false); | 60 | { |
45 | if (s->card == NULL) { | 61 | - uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; |
46 | - return -1; | 62 | + uint64_t tcr = regime_tcr_value(env, mmu_idx); |
47 | + error_setg(errp, "failed to init SD card"); | 63 | bool epd, hpd, using16k, using64k, tsz_oob, ds; |
48 | + return; | 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 | ||
76 | index XXXXXXX..XXXXXXX 100644 | ||
77 | --- a/target/arm/ptw.c | ||
78 | +++ b/target/arm/ptw.c | ||
79 | @@ -XXX,XX +XXX,XX @@ static int get_S1prot(CPUARMState *env, ARMMMUIdx mmu_idx, bool is_aa64, | ||
80 | static ARMVAParameters aa32_va_parameters(CPUARMState *env, uint32_t va, | ||
81 | ARMMMUIdx mmu_idx) | ||
82 | { | ||
83 | - uint64_t tcr = regime_tcr(env, mmu_idx)->raw_tcr; | ||
84 | + uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
85 | uint32_t el = regime_el(env, mmu_idx); | ||
86 | int select, tsz; | ||
87 | bool epd, hpd; | ||
88 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, | ||
89 | uint32_t attrs; | ||
90 | int32_t stride; | ||
91 | int addrsize, inputsize, outputsize; | ||
92 | - TCR *tcr = regime_tcr(env, mmu_idx); | ||
93 | + uint64_t tcr = regime_tcr_value(env, mmu_idx); | ||
94 | int ap, ns, xn, pxn; | ||
95 | uint32_t el = regime_el(env, mmu_idx); | ||
96 | uint64_t descaddrmask; | ||
97 | @@ -XXX,XX +XXX,XX @@ static bool get_phys_addr_lpae(CPUARMState *env, uint64_t address, | ||
98 | * For stage 2 translations the starting level is specified by the | ||
99 | * VTCR_EL2.SL0 field (whose interpretation depends on the page size) | ||
100 | */ | ||
101 | - uint32_t sl0 = extract32(tcr->raw_tcr, 6, 2); | ||
102 | - uint32_t sl2 = extract64(tcr->raw_tcr, 33, 1); | ||
103 | + uint32_t sl0 = extract32(tcr, 6, 2); | ||
104 | + uint32_t sl2 = extract64(tcr, 33, 1); | ||
105 | uint32_t startlevel; | ||
106 | bool ok; | ||
107 | |||
108 | diff --git a/target/arm/tlb_helper.c b/target/arm/tlb_helper.c | ||
109 | index XXXXXXX..XXXXXXX 100644 | ||
110 | --- a/target/arm/tlb_helper.c | ||
111 | +++ b/target/arm/tlb_helper.c | ||
112 | @@ -XXX,XX +XXX,XX @@ bool regime_using_lpae_format(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
113 | return true; | ||
49 | } | 114 | } |
50 | - | 115 | if (arm_feature(env, ARM_FEATURE_LPAE) |
51 | s->enabled = blk && blk_is_inserted(blk); | 116 | - && (regime_tcr(env, mmu_idx)->raw_tcr & TTBCR_EAE)) { |
52 | - | 117 | + && (regime_tcr_value(env, mmu_idx) & TTBCR_EAE)) { |
53 | - memory_region_init_io(&s->regs_region, OBJECT(s), &memcard_mmio_ops, s, | 118 | return true; |
54 | - "milkymist-memcard", R_MAX * 4); | 119 | } |
55 | - sysbus_init_mmio(dev, &s->regs_region); | 120 | return false; |
56 | - | ||
57 | - return 0; | ||
58 | } | ||
59 | |||
60 | static const VMStateDescription vmstate_milkymist_memcard = { | ||
61 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_milkymist_memcard = { | ||
62 | static void milkymist_memcard_class_init(ObjectClass *klass, void *data) | ||
63 | { | ||
64 | DeviceClass *dc = DEVICE_CLASS(klass); | ||
65 | - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); | ||
66 | |||
67 | - k->init = milkymist_memcard_init; | ||
68 | + dc->realize = milkymist_memcard_realize; | ||
69 | dc->reset = milkymist_memcard_reset; | ||
70 | dc->vmsd = &vmstate_milkymist_memcard; | ||
71 | /* Reason: init() method uses drive_get_next() */ | ||
72 | @@ -XXX,XX +XXX,XX @@ static const TypeInfo milkymist_memcard_info = { | ||
73 | .name = TYPE_MILKYMIST_MEMCARD, | ||
74 | .parent = TYPE_SYS_BUS_DEVICE, | ||
75 | .instance_size = sizeof(MilkymistMemcardState), | ||
76 | + .instance_init = milkymist_memcard_init, | ||
77 | .class_init = milkymist_memcard_class_init, | ||
78 | }; | ||
79 | |||
80 | -- | 121 | -- |
81 | 2.16.1 | 122 | 2.25.1 |
82 | |||
83 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | In get_level1_table_address(), instead of using precalculated values |
---|---|---|---|
2 | of mask and base_mask from the TCR struct, calculate them directly | ||
3 | (in the same way we currently do in vmsa_ttbcr_raw_write() to | ||
4 | populate the TCR struct fields). | ||
2 | 5 | ||
3 | replace switch(single case) -> if() | 6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
8 | Message-id: 20220714132303.1287193-3-peter.maydell@linaro.org | ||
9 | --- | ||
10 | target/arm/ptw.c | 14 +++++++++----- | ||
11 | 1 file changed, 9 insertions(+), 5 deletions(-) | ||
4 | 12 | ||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 13 | diff --git a/target/arm/ptw.c b/target/arm/ptw.c |
6 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
7 | Message-id: 20180215221325.7611-17-f4bug@amsat.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | hw/sd/sd.c | 56 ++++++++++++++++++++++++++------------------------------ | ||
11 | 1 file changed, 26 insertions(+), 30 deletions(-) | ||
12 | |||
13 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | 14 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/sd/sd.c | 15 | --- a/target/arm/ptw.c |
16 | +++ b/hw/sd/sd.c | 16 | +++ b/target/arm/ptw.c |
17 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_app_command(SDState *sd, | 17 | @@ -XXX,XX +XXX,XX @@ static bool get_level1_table_address(CPUARMState *env, ARMMMUIdx mmu_idx, |
18 | sd->state = sd_transfer_state; | 18 | uint32_t *table, uint32_t address) |
19 | return sd_r1; | 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; | ||
20 | } | 33 | } |
21 | - switch (sd->state) { | 34 | *table = regime_ttbr(env, mmu_idx, 1) & 0xffffc000; |
22 | - case sd_idle_state: | 35 | } else { |
23 | - /* If it's the first ACMD41 since reset, we need to decide | 36 | - if (tcr->raw_tcr & TTBCR_PD0) { |
24 | - * whether to power up. If this is not an enquiry ACMD41, | 37 | + if (tcr & TTBCR_PD0) { |
25 | - * we immediately report power on and proceed below to the | 38 | /* Translation table walk disabled for TTBR0 */ |
26 | - * ready state, but if it is, we set a timer to model a | 39 | return false; |
27 | - * delay for power up. This works around a bug in EDK2 | ||
28 | - * UEFI, which sends an initial enquiry ACMD41, but | ||
29 | - * assumes that the card is in ready state as soon as it | ||
30 | - * sees the power up bit set. */ | ||
31 | - if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { | ||
32 | - if ((req.arg & ACMD41_ENQUIRY_MASK) != 0) { | ||
33 | - timer_del(sd->ocr_power_timer); | ||
34 | - sd_ocr_powerup(sd); | ||
35 | - } else { | ||
36 | - trace_sdcard_inquiry_cmd41(); | ||
37 | - if (!timer_pending(sd->ocr_power_timer)) { | ||
38 | - timer_mod_ns(sd->ocr_power_timer, | ||
39 | - (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) | ||
40 | - + OCR_POWER_DELAY_NS)); | ||
41 | - } | ||
42 | + if (sd->state != sd_idle_state) { | ||
43 | + break; | ||
44 | + } | ||
45 | + /* If it's the first ACMD41 since reset, we need to decide | ||
46 | + * whether to power up. If this is not an enquiry ACMD41, | ||
47 | + * we immediately report power on and proceed below to the | ||
48 | + * ready state, but if it is, we set a timer to model a | ||
49 | + * delay for power up. This works around a bug in EDK2 | ||
50 | + * UEFI, which sends an initial enquiry ACMD41, but | ||
51 | + * assumes that the card is in ready state as soon as it | ||
52 | + * sees the power up bit set. */ | ||
53 | + if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { | ||
54 | + if ((req.arg & ACMD41_ENQUIRY_MASK) != 0) { | ||
55 | + timer_del(sd->ocr_power_timer); | ||
56 | + sd_ocr_powerup(sd); | ||
57 | + } else { | ||
58 | + trace_sdcard_inquiry_cmd41(); | ||
59 | + if (!timer_pending(sd->ocr_power_timer)) { | ||
60 | + timer_mod_ns(sd->ocr_power_timer, | ||
61 | + (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) | ||
62 | + + OCR_POWER_DELAY_NS)); | ||
63 | } | ||
64 | } | ||
65 | + } | ||
66 | |||
67 | + if (FIELD_EX32(sd->ocr & req.arg, OCR, VDD_VOLTAGE_WINDOW)) { | ||
68 | /* We accept any voltage. 10000 V is nothing. | ||
69 | * | ||
70 | * Once we're powered up, we advance straight to ready state | ||
71 | * unless it's an enquiry ACMD41 (bits 23:0 == 0). | ||
72 | */ | ||
73 | - if (req.arg & ACMD41_ENQUIRY_MASK) { | ||
74 | - sd->state = sd_ready_state; | ||
75 | - } | ||
76 | - | ||
77 | - return sd_r3; | ||
78 | - | ||
79 | - default: | ||
80 | - break; | ||
81 | + sd->state = sd_ready_state; | ||
82 | } | 40 | } |
83 | - break; | 41 | - *table = regime_ttbr(env, mmu_idx, 0) & tcr->base_mask; |
84 | + | 42 | + base_mask = ~((uint32_t)0x3fffu >> maskshift); |
85 | + return sd_r3; | 43 | + *table = regime_ttbr(env, mmu_idx, 0) & base_mask; |
86 | 44 | } | |
87 | case 42: /* ACMD42: SET_CLR_CARD_DETECT */ | 45 | *table |= (address >> 18) & 0x3ffc; |
88 | switch (sd->state) { | 46 | return true; |
89 | -- | 47 | -- |
90 | 2.16.1 | 48 | 2.25.1 |
91 | |||
92 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | The only caller of regime_tcr() is now regime_tcr_value(); fold the |
---|---|---|---|
2 | two together, and use the shorter and more natural 'regime_tcr' | ||
3 | name for the new function. | ||
2 | 4 | ||
3 | Don't set the high capacity bit by default as it will be set if required | 5 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
4 | in the sd_set_csd() function. | 6 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
7 | Message-id: 20220714132303.1287193-4-peter.maydell@linaro.org | ||
8 | --- | ||
9 | target/arm/internals.h | 16 +++++----------- | ||
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(-) | ||
5 | 14 | ||
6 | [based on a patch from Alistair Francis <alistair.francis@xilinx.com> | 15 | diff --git a/target/arm/internals.h b/target/arm/internals.h |
7 | and Peter Ogden <ogden@xilinx.com> from qemu/xilinx tag xilinx-v2015.4] | ||
8 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
9 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
10 | Message-id: 20180215221325.7611-2-f4bug@amsat.org | ||
11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
12 | --- | ||
13 | hw/sd/sd.c | 5 ++++- | ||
14 | 1 file changed, 4 insertions(+), 1 deletion(-) | ||
15 | |||
16 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
17 | index XXXXXXX..XXXXXXX 100644 | 16 | index XXXXXXX..XXXXXXX 100644 |
18 | --- a/hw/sd/sd.c | 17 | --- a/target/arm/internals.h |
19 | +++ b/hw/sd/sd.c | 18 | +++ b/target/arm/internals.h |
20 | @@ -XXX,XX +XXX,XX @@ static void sd_ocr_powerup(void *opaque) | 19 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx) |
21 | 20 | return env->cp15.sctlr_el[regime_el(env, mmu_idx)]; | |
22 | /* card power-up OK */ | ||
23 | sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_POWER_UP, 1); | ||
24 | + | ||
25 | + if (sd->size > 1 * G_BYTE) { | ||
26 | + sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_CAPACITY, 1); | ||
27 | + } | ||
28 | } | 21 | } |
29 | 22 | ||
30 | static void sd_set_scr(SDState *sd) | 23 | -/* Return the TCR controlling this translation regime */ |
31 | @@ -XXX,XX +XXX,XX @@ static void sd_set_csd(SDState *sd, uint64_t size) | 24 | -static inline TCR *regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
32 | sd->csd[13] = 0x40; | 25 | +/* Return the value of the TCR controlling this translation regime */ |
33 | sd->csd[14] = 0x00; | 26 | +static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
34 | sd->csd[15] = 0x00; | 27 | { |
35 | - sd->ocr |= 1 << 30; /* High Capacity SD Memory Card */ | 28 | if (mmu_idx == ARMMMUIdx_Stage2) { |
29 | - return &env->cp15.vtcr_el2; | ||
30 | + return env->cp15.vtcr_el2.raw_tcr; | ||
36 | } | 31 | } |
32 | if (mmu_idx == ARMMMUIdx_Stage2_S) { | ||
33 | /* | ||
34 | * Note: Secure stage 2 nominally shares fields from VTCR_EL2, but | ||
35 | * those are not currently used by QEMU, so just return VSTCR_EL2. | ||
36 | */ | ||
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; | ||
37 | } | 48 | } |
38 | 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; | ||
39 | -- | 126 | -- |
40 | 2.16.1 | 127 | 2.25.1 |
41 | |||
42 | diff view generated by jsdifflib |
1 | The register definitions for VMIDR and VMPIDR have separate | 1 | We have a bug in our handling of accesses to the AArch32 VTCR |
---|---|---|---|
2 | reginfo structs for the AArch32 and AArch64 registers. However | 2 | register on big-endian hosts: we were not adjusting the part of the |
3 | the 32-bit versions are wrong: | 3 | uint64_t field within TCR that the generated code would access. That |
4 | * they use offsetof instead of offsetoflow32 to mark where | 4 | can be done with offsetoflow32(), by using an ARM_CP_STATE_BOTH cpreg |
5 | the 32-bit value lives in the uint64_t CPU state field | 5 | struct, or by defining a full set of read/write/reset functions -- |
6 | * they don't mark themselves as ARM_CP_ALIAS | 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. | ||
7 | 9 | ||
8 | In particular this means that if you try to use an Arm guest CPU | 10 | Use offsetoflow32() in the VTCR register struct. This works even |
9 | which enables EL2 on a big-endian host it will assert at reset: | 11 | though the field in the CPU struct is currently a struct TCR, because |
10 | target/arm/cpu.c:114: cp_reg_check_reset: Assertion `oldvalue == newvalue' failed. | 12 | the first field in that struct is the uint64_t raw_tcr. |
11 | 13 | ||
12 | because the reset of the 32-bit register writes to the top | 14 | None of the other TCR registers have this bug -- either they are |
13 | half of the uint64_t. | 15 | AArch64 only, or else they define resetfn, writefn, etc, and |
14 | 16 | expect to be passed the full struct pointer. | |
15 | Correct the errors in the structures. | ||
16 | 17 | ||
17 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 18 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
18 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 19 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> |
20 | Message-id: 20220714132303.1287193-5-peter.maydell@linaro.org | ||
19 | --- | 21 | --- |
20 | This is necessary for 'make check' to pass on big endian | 22 | target/arm/helper.c | 2 +- |
21 | systems with the 'raspi3' board enabled, which is the | 23 | 1 file changed, 1 insertion(+), 1 deletion(-) |
22 | first board which has an EL2-enabled-by-default CPU. | ||
23 | --- | ||
24 | target/arm/helper.c | 8 ++++---- | ||
25 | 1 file changed, 4 insertions(+), 4 deletions(-) | ||
26 | 24 | ||
27 | 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 |
28 | index XXXXXXX..XXXXXXX 100644 | 26 | index XXXXXXX..XXXXXXX 100644 |
29 | --- a/target/arm/helper.c | 27 | --- a/target/arm/helper.c |
30 | +++ b/target/arm/helper.c | 28 | +++ b/target/arm/helper.c |
31 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | 29 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = { |
32 | { .name = "VPIDR", .state = ARM_CP_STATE_AA32, | 30 | .cp = 15, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, |
33 | .cp = 15, .opc1 = 4, .crn = 0, .crm = 0, .opc2 = 0, | 31 | .type = ARM_CP_ALIAS, |
34 | .access = PL2_RW, .accessfn = access_el3_aa32ns, | 32 | .access = PL2_RW, .accessfn = access_el3_aa32ns, |
35 | - .resetvalue = cpu->midr, | 33 | - .fieldoffset = offsetof(CPUARMState, cp15.vtcr_el2) }, |
36 | - .fieldoffset = offsetof(CPUARMState, cp15.vpidr_el2) }, | 34 | + .fieldoffset = offsetoflow32(CPUARMState, cp15.vtcr_el2) }, |
37 | + .resetvalue = cpu->midr, .type = ARM_CP_ALIAS, | 35 | { .name = "VTCR_EL2", .state = ARM_CP_STATE_AA64, |
38 | + .fieldoffset = offsetoflow32(CPUARMState, cp15.vpidr_el2) }, | 36 | .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, |
39 | { .name = "VPIDR_EL2", .state = ARM_CP_STATE_AA64, | 37 | .access = PL2_RW, |
40 | .opc0 = 3, .opc1 = 4, .crn = 0, .crm = 0, .opc2 = 0, | ||
41 | .access = PL2_RW, .resetvalue = cpu->midr, | ||
42 | @@ -XXX,XX +XXX,XX @@ void register_cp_regs_for_features(ARMCPU *cpu) | ||
43 | { .name = "VMPIDR", .state = ARM_CP_STATE_AA32, | ||
44 | .cp = 15, .opc1 = 4, .crn = 0, .crm = 0, .opc2 = 5, | ||
45 | .access = PL2_RW, .accessfn = access_el3_aa32ns, | ||
46 | - .resetvalue = vmpidr_def, | ||
47 | - .fieldoffset = offsetof(CPUARMState, cp15.vmpidr_el2) }, | ||
48 | + .resetvalue = vmpidr_def, .type = ARM_CP_ALIAS, | ||
49 | + .fieldoffset = offsetoflow32(CPUARMState, cp15.vmpidr_el2) }, | ||
50 | { .name = "VMPIDR_EL2", .state = ARM_CP_STATE_AA64, | ||
51 | .opc0 = 3, .opc1 = 4, .crn = 0, .crm = 0, .opc2 = 5, | ||
52 | .access = PL2_RW, | ||
53 | -- | 38 | -- |
54 | 2.16.1 | 39 | 2.25.1 |
55 | |||
56 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Pekka Enberg <penberg@iki.fi> | ||
2 | 1 | ||
3 | This patch adds a "raspi3" machine type, which can now be selected as | ||
4 | the machine to run on by users via the "-M" command line option to QEMU. | ||
5 | |||
6 | The machine type does *not* ignore memory transaction failures so we | ||
7 | likely need to add some dummy devices later when people run something | ||
8 | more complicated than what I'm using for testing. | ||
9 | |||
10 | Signed-off-by: Pekka Enberg <penberg@iki.fi> | ||
11 | [PMM: added #ifdef TARGET_AARCH64 so we don't provide the 64-bit | ||
12 | board in the 32-bit only arm-softmmu build.] | ||
13 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
15 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
16 | --- | ||
17 | hw/arm/raspi.c | 23 +++++++++++++++++++++++ | ||
18 | 1 file changed, 23 insertions(+) | ||
19 | |||
20 | diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c | ||
21 | index XXXXXXX..XXXXXXX 100644 | ||
22 | --- a/hw/arm/raspi.c | ||
23 | +++ b/hw/arm/raspi.c | ||
24 | @@ -XXX,XX +XXX,XX @@ static void raspi2_machine_init(MachineClass *mc) | ||
25 | mc->ignore_memory_transaction_failures = true; | ||
26 | }; | ||
27 | DEFINE_MACHINE("raspi2", raspi2_machine_init) | ||
28 | + | ||
29 | +#ifdef TARGET_AARCH64 | ||
30 | +static void raspi3_init(MachineState *machine) | ||
31 | +{ | ||
32 | + raspi_init(machine, 3); | ||
33 | +} | ||
34 | + | ||
35 | +static void raspi3_machine_init(MachineClass *mc) | ||
36 | +{ | ||
37 | + mc->desc = "Raspberry Pi 3"; | ||
38 | + mc->init = raspi3_init; | ||
39 | + mc->block_default_type = IF_SD; | ||
40 | + mc->no_parallel = 1; | ||
41 | + mc->no_floppy = 1; | ||
42 | + mc->no_cdrom = 1; | ||
43 | + mc->default_cpu_type = ARM_CPU_TYPE_NAME("cortex-a53"); | ||
44 | + mc->max_cpus = BCM2836_NCPUS; | ||
45 | + mc->min_cpus = BCM2836_NCPUS; | ||
46 | + mc->default_cpus = BCM2836_NCPUS; | ||
47 | + mc->default_ram_size = 1024 * 1024 * 1024; | ||
48 | +} | ||
49 | +DEFINE_MACHINE("raspi3", raspi3_machine_init) | ||
50 | +#endif | ||
51 | -- | ||
52 | 2.16.1 | ||
53 | |||
54 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Richard Braun <rbraun@sceen.net> | ||
2 | 1 | ||
3 | I/O currently being synchronous, there is no reason to ever clear the | ||
4 | SR_TXE bit. However the SR_TC bit may be cleared by software writing | ||
5 | to the SR register, so set it on each write. | ||
6 | |||
7 | In addition, fix the reset value of the USART status register. | ||
8 | |||
9 | Signed-off-by: Richard Braun <rbraun@sceen.net> | ||
10 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
11 | [PMM: removed XXX tag from comment, since it isn't something | ||
12 | we need to come back and fix in QEMU] | ||
13 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
14 | --- | ||
15 | include/hw/char/stm32f2xx_usart.h | 7 ++++++- | ||
16 | hw/char/stm32f2xx_usart.c | 12 ++++++++---- | ||
17 | 2 files changed, 14 insertions(+), 5 deletions(-) | ||
18 | |||
19 | diff --git a/include/hw/char/stm32f2xx_usart.h b/include/hw/char/stm32f2xx_usart.h | ||
20 | index XXXXXXX..XXXXXXX 100644 | ||
21 | --- a/include/hw/char/stm32f2xx_usart.h | ||
22 | +++ b/include/hw/char/stm32f2xx_usart.h | ||
23 | @@ -XXX,XX +XXX,XX @@ | ||
24 | #define USART_CR3 0x14 | ||
25 | #define USART_GTPR 0x18 | ||
26 | |||
27 | -#define USART_SR_RESET 0x00C00000 | ||
28 | +/* | ||
29 | + * NB: The reset value mentioned in "24.6.1 Status register" seems bogus. | ||
30 | + * Looking at "Table 98 USART register map and reset values", it seems it | ||
31 | + * should be 0xc0, and that's how real hardware behaves. | ||
32 | + */ | ||
33 | +#define USART_SR_RESET (USART_SR_TXE | USART_SR_TC) | ||
34 | |||
35 | #define USART_SR_TXE (1 << 7) | ||
36 | #define USART_SR_TC (1 << 6) | ||
37 | diff --git a/hw/char/stm32f2xx_usart.c b/hw/char/stm32f2xx_usart.c | ||
38 | index XXXXXXX..XXXXXXX 100644 | ||
39 | --- a/hw/char/stm32f2xx_usart.c | ||
40 | +++ b/hw/char/stm32f2xx_usart.c | ||
41 | @@ -XXX,XX +XXX,XX @@ static uint64_t stm32f2xx_usart_read(void *opaque, hwaddr addr, | ||
42 | switch (addr) { | ||
43 | case USART_SR: | ||
44 | retvalue = s->usart_sr; | ||
45 | - s->usart_sr &= ~USART_SR_TC; | ||
46 | qemu_chr_fe_accept_input(&s->chr); | ||
47 | return retvalue; | ||
48 | case USART_DR: | ||
49 | DB_PRINT("Value: 0x%" PRIx32 ", %c\n", s->usart_dr, (char) s->usart_dr); | ||
50 | - s->usart_sr |= USART_SR_TXE; | ||
51 | s->usart_sr &= ~USART_SR_RXNE; | ||
52 | qemu_chr_fe_accept_input(&s->chr); | ||
53 | qemu_set_irq(s->irq, 0); | ||
54 | @@ -XXX,XX +XXX,XX @@ static void stm32f2xx_usart_write(void *opaque, hwaddr addr, | ||
55 | switch (addr) { | ||
56 | case USART_SR: | ||
57 | if (value <= 0x3FF) { | ||
58 | - s->usart_sr = value; | ||
59 | + /* I/O being synchronous, TXE is always set. In addition, it may | ||
60 | + only be set by hardware, so keep it set here. */ | ||
61 | + s->usart_sr = value | USART_SR_TXE; | ||
62 | } else { | ||
63 | s->usart_sr &= value; | ||
64 | } | ||
65 | @@ -XXX,XX +XXX,XX @@ static void stm32f2xx_usart_write(void *opaque, hwaddr addr, | ||
66 | /* XXX this blocks entire thread. Rewrite to use | ||
67 | * qemu_chr_fe_write and background I/O callbacks */ | ||
68 | qemu_chr_fe_write_all(&s->chr, &ch, 1); | ||
69 | + /* XXX I/O are currently synchronous, making it impossible for | ||
70 | + software to observe transient states where TXE or TC aren't | ||
71 | + set. Unlike TXE however, which is read-only, software may | ||
72 | + clear TC by writing 0 to the SR register, so set it again | ||
73 | + on each write. */ | ||
74 | s->usart_sr |= USART_SR_TC; | ||
75 | - s->usart_sr &= ~USART_SR_TXE; | ||
76 | } | ||
77 | return; | ||
78 | case USART_BRR: | ||
79 | -- | ||
80 | 2.16.1 | ||
81 | |||
82 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Hugo Landau <hlandau@devever.net> | ||
2 | 1 | ||
3 | Some register blocks of the ast2500 are protected by protection key | ||
4 | registers which require the right magic value to be written to those | ||
5 | registers to allow those registers to be mutated. | ||
6 | |||
7 | Register manuals indicate that writing the correct magic value to these | ||
8 | registers should cause subsequent reads from those values to return 1, | ||
9 | and writing any other value should cause subsequent reads to return 0. | ||
10 | |||
11 | Previously, qemu implemented these registers incorrectly: the registers | ||
12 | were handled as simple memory, meaning that writing some value x to a | ||
13 | protection key register would result in subsequent reads from that | ||
14 | register returning the same value x. The protection was implemented by | ||
15 | ensuring that the current value of that register equaled the magic | ||
16 | value. | ||
17 | |||
18 | This modifies qemu to have the correct behaviour: attempts to write to a | ||
19 | ast2500 protection register results in a transition to 1 or 0 depending | ||
20 | on whether the written value is the correct magic. The protection logic | ||
21 | is updated to ensure that the value of the register is nonzero. | ||
22 | |||
23 | This bug caused deadlocks with u-boot HEAD: when u-boot is done with a | ||
24 | protectable register block, it attempts to lock it by writing the | ||
25 | bitwise inverse of the correct magic value, and then spinning forever | ||
26 | until the register reads as zero. Since qemu implemented writes to these | ||
27 | registers as ordinary memory writes, writing the inverse of the magic | ||
28 | value resulted in subsequent reads returning that value, leading to | ||
29 | u-boot spinning forever. | ||
30 | |||
31 | Signed-off-by: Hugo Landau <hlandau@devever.net> | ||
32 | Reviewed-by: Cédric Le Goater <clg@kaod.org> | ||
33 | Acked-by: Andrew Jeffery <andrew@aj.id.au> | ||
34 | Message-id: 20180220132627.4163-1-hlandau@devever.net | ||
35 | [PMM: fixed incorrect code indentation] | ||
36 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
37 | --- | ||
38 | hw/misc/aspeed_scu.c | 6 +++++- | ||
39 | hw/misc/aspeed_sdmc.c | 8 +++++++- | ||
40 | 2 files changed, 12 insertions(+), 2 deletions(-) | ||
41 | |||
42 | diff --git a/hw/misc/aspeed_scu.c b/hw/misc/aspeed_scu.c | ||
43 | index XXXXXXX..XXXXXXX 100644 | ||
44 | --- a/hw/misc/aspeed_scu.c | ||
45 | +++ b/hw/misc/aspeed_scu.c | ||
46 | @@ -XXX,XX +XXX,XX @@ static void aspeed_scu_write(void *opaque, hwaddr offset, uint64_t data, | ||
47 | } | ||
48 | |||
49 | if (reg > PROT_KEY && reg < CPU2_BASE_SEG1 && | ||
50 | - s->regs[PROT_KEY] != ASPEED_SCU_PROT_KEY) { | ||
51 | + !s->regs[PROT_KEY]) { | ||
52 | qemu_log_mask(LOG_GUEST_ERROR, "%s: SCU is locked!\n", __func__); | ||
53 | return; | ||
54 | } | ||
55 | @@ -XXX,XX +XXX,XX @@ static void aspeed_scu_write(void *opaque, hwaddr offset, uint64_t data, | ||
56 | trace_aspeed_scu_write(offset, size, data); | ||
57 | |||
58 | switch (reg) { | ||
59 | + case PROT_KEY: | ||
60 | + s->regs[reg] = (data == ASPEED_SCU_PROT_KEY) ? 1 : 0; | ||
61 | + return; | ||
62 | + | ||
63 | case FREQ_CNTR_EVAL: | ||
64 | case VGA_SCRATCH1 ... VGA_SCRATCH8: | ||
65 | case RNG_DATA: | ||
66 | diff --git a/hw/misc/aspeed_sdmc.c b/hw/misc/aspeed_sdmc.c | ||
67 | index XXXXXXX..XXXXXXX 100644 | ||
68 | --- a/hw/misc/aspeed_sdmc.c | ||
69 | +++ b/hw/misc/aspeed_sdmc.c | ||
70 | @@ -XXX,XX +XXX,XX @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data, | ||
71 | return; | ||
72 | } | ||
73 | |||
74 | - if (addr != R_PROT && s->regs[R_PROT] != PROT_KEY_UNLOCK) { | ||
75 | + if (addr == R_PROT) { | ||
76 | + s->regs[addr] = (data == PROT_KEY_UNLOCK) ? 1 : 0; | ||
77 | + return; | ||
78 | + } | ||
79 | + | ||
80 | + if (!s->regs[R_PROT]) { | ||
81 | qemu_log_mask(LOG_GUEST_ERROR, "%s: SDMC is locked!\n", __func__); | ||
82 | return; | ||
83 | } | ||
84 | @@ -XXX,XX +XXX,XX @@ static void aspeed_sdmc_write(void *opaque, hwaddr addr, uint64_t data, | ||
85 | data &= ~ASPEED_SDMC_READONLY_MASK; | ||
86 | break; | ||
87 | case AST2500_A0_SILICON_REV: | ||
88 | + case AST2500_A1_SILICON_REV: | ||
89 | data &= ~ASPEED_SDMC_AST2500_READONLY_MASK; | ||
90 | break; | ||
91 | default: | ||
92 | -- | ||
93 | 2.16.1 | ||
94 | |||
95 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.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 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Acked-by: Alistair Francis <alistair.francis@xilinx.com> | ||
5 | Message-id: 20180215220540.6556-6-f4bug@amsat.org | ||
6 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | 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 | ||
8 | --- | 7 | --- |
9 | hw/sd/sd.c | 32 ++++++++++++++++++++++++++------ | 8 | target/arm/cpu.h | 4 ++-- |
10 | hw/sd/trace-events | 13 +++++++++++++ | 9 | target/arm/internals.h | 4 ++-- |
11 | 2 files changed, 39 insertions(+), 6 deletions(-) | 10 | target/arm/helper.c | 4 +--- |
11 | target/arm/ptw.c | 14 +++++++------- | ||
12 | 4 files changed, 12 insertions(+), 14 deletions(-) | ||
12 | 13 | ||
13 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 14 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
14 | index XXXXXXX..XXXXXXX 100644 | 15 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/sd/sd.c | 16 | --- a/target/arm/cpu.h |
16 | +++ b/hw/sd/sd.c | 17 | +++ b/target/arm/cpu.h |
17 | @@ -XXX,XX +XXX,XX @@ static bool sd_get_cmd_line(SDState *sd) | 18 | @@ -XXX,XX +XXX,XX @@ typedef struct CPUArchState { |
18 | 19 | uint64_t vsttbr_el2; /* Secure Virtualization Translation Table. */ | |
19 | static void sd_set_voltage(SDState *sd, uint16_t millivolts) | 20 | /* MMU translation table base control. */ |
21 | TCR tcr_el[4]; | ||
22 | - TCR vtcr_el2; /* Virtualization Translation Control. */ | ||
23 | - TCR vstcr_el2; /* Secure Virtualization Translation Control. */ | ||
24 | + uint64_t vtcr_el2; /* Virtualization Translation Control. */ | ||
25 | + uint64_t vstcr_el2; /* Secure Virtualization Translation Control. */ | ||
26 | uint32_t c2_data; /* MPU data cacheable bits. */ | ||
27 | uint32_t c2_insn; /* MPU instruction cacheable bits. */ | ||
28 | union { /* MMU domain access control register | ||
29 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
30 | index XXXXXXX..XXXXXXX 100644 | ||
31 | --- a/target/arm/internals.h | ||
32 | +++ b/target/arm/internals.h | ||
33 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
34 | static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) | ||
20 | { | 35 | { |
21 | + trace_sdcard_set_voltage(millivolts); | 36 | if (mmu_idx == ARMMMUIdx_Stage2) { |
22 | + | 37 | - return env->cp15.vtcr_el2.raw_tcr; |
23 | switch (millivolts) { | 38 | + return env->cp15.vtcr_el2; |
24 | case 3001 ... 3600: /* SD_VOLTAGE_3_3V */ | ||
25 | case 2001 ... 3000: /* SD_VOLTAGE_3_0V */ | ||
26 | @@ -XXX,XX +XXX,XX @@ static void sd_ocr_powerup(void *opaque) | ||
27 | { | ||
28 | SDState *sd = opaque; | ||
29 | |||
30 | + trace_sdcard_powerup(); | ||
31 | /* Set powered up bit in OCR */ | ||
32 | assert(!(sd->ocr & OCR_POWER_UP)); | ||
33 | sd->ocr |= OCR_POWER_UP; | ||
34 | @@ -XXX,XX +XXX,XX @@ static void sd_reset(DeviceState *dev) | ||
35 | uint64_t size; | ||
36 | uint64_t sect; | ||
37 | |||
38 | + trace_sdcard_reset(); | ||
39 | if (sd->blk) { | ||
40 | blk_get_geometry(sd->blk, §); | ||
41 | } else { | ||
42 | @@ -XXX,XX +XXX,XX @@ static void sd_cardchange(void *opaque, bool load, Error **errp) | ||
43 | bool readonly = sd_get_readonly(sd); | ||
44 | |||
45 | if (inserted) { | ||
46 | + trace_sdcard_inserted(readonly); | ||
47 | sd_reset(dev); | ||
48 | + } else { | ||
49 | + trace_sdcard_ejected(); | ||
50 | } | 39 | } |
51 | 40 | if (mmu_idx == ARMMMUIdx_Stage2_S) { | |
52 | /* The IRQ notification is for legacy non-QOM SD controller devices; | 41 | /* |
53 | @@ -XXX,XX +XXX,XX @@ static void sd_erase(SDState *sd) | 42 | * Note: Secure stage 2 nominally shares fields from VTCR_EL2, but |
54 | uint64_t erase_start = sd->erase_start; | 43 | * those are not currently used by QEMU, so just return VSTCR_EL2. |
55 | uint64_t erase_end = sd->erase_end; | 44 | */ |
56 | 45 | - return env->cp15.vstcr_el2.raw_tcr; | |
57 | + trace_sdcard_erase(); | 46 | + return env->cp15.vstcr_el2; |
58 | if (!sd->erase_start || !sd->erase_end) { | 47 | } |
59 | sd->card_status |= ERASE_SEQ_ERROR; | 48 | return env->cp15.tcr_el[regime_el(env, mmu_idx)].raw_tcr; |
60 | return; | 49 | } |
61 | @@ -XXX,XX +XXX,XX @@ static void sd_lock_command(SDState *sd) | 50 | diff --git a/target/arm/helper.c b/target/arm/helper.c |
62 | else | 51 | index XXXXXXX..XXXXXXX 100644 |
63 | pwd_len = 0; | 52 | --- a/target/arm/helper.c |
64 | 53 | +++ b/target/arm/helper.c | |
65 | + if (lock) { | 54 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo el2_cp_reginfo[] = { |
66 | + trace_sdcard_lock(); | 55 | { .name = "VTCR_EL2", .state = ARM_CP_STATE_AA64, |
67 | + } else { | 56 | .opc0 = 3, .opc1 = 4, .crn = 2, .crm = 1, .opc2 = 2, |
68 | + trace_sdcard_unlock(); | 57 | .access = PL2_RW, |
69 | + } | 58 | - /* no .writefn needed as this can't cause an ASID change; |
70 | if (erase) { | 59 | - * no .raw_writefn or .resetfn needed as we never use mask/base_mask |
71 | if (!(sd->card_status & CARD_IS_LOCKED) || sd->blk_len > 1 || | 60 | - */ |
72 | set_pwd || clr_pwd || lock || sd->wp_switch || | 61 | + /* no .writefn needed as this can't cause an ASID change */ |
73 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | 62 | .fieldoffset = offsetof(CPUARMState, cp15.vtcr_el2) }, |
74 | case 16: /* CMD16: SET_BLOCKLEN */ | 63 | { .name = "VTTBR", .state = ARM_CP_STATE_AA32, |
75 | switch (sd->state) { | 64 | .cp = 15, .opc1 = 6, .crm = 2, |
76 | case sd_transfer_state: | 65 | diff --git a/target/arm/ptw.c b/target/arm/ptw.c |
77 | - if (req.arg > (1 << HWBLOCK_SHIFT)) | 66 | index XXXXXXX..XXXXXXX 100644 |
78 | + if (req.arg > (1 << HWBLOCK_SHIFT)) { | 67 | --- a/target/arm/ptw.c |
79 | sd->card_status |= BLOCK_LEN_ERROR; | 68 | +++ b/target/arm/ptw.c |
80 | - else | 69 | @@ -XXX,XX +XXX,XX @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx, |
81 | + } else { | 70 | if (arm_is_secure_below_el3(env)) { |
82 | + trace_sdcard_set_blocklen(req.arg); | 71 | /* Check if page table walk is to secure or non-secure PA space. */ |
83 | sd->blk_len = req.arg; | 72 | if (*is_secure) { |
84 | + } | 73 | - *is_secure = !(env->cp15.vstcr_el2.raw_tcr & VSTCR_SW); |
85 | 74 | + *is_secure = !(env->cp15.vstcr_el2 & VSTCR_SW); | |
86 | return sd_r1; | 75 | } else { |
87 | 76 | - *is_secure = !(env->cp15.vtcr_el2.raw_tcr & VTCR_NSW); | |
88 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_app_command(SDState *sd, | 77 | + *is_secure = !(env->cp15.vtcr_el2 & VTCR_NSW); |
89 | if ((req.arg & ACMD41_ENQUIRY_MASK) != 0) { | 78 | } |
90 | timer_del(sd->ocr_power_timer); | 79 | } else { |
91 | sd_ocr_powerup(sd); | 80 | assert(!*is_secure); |
92 | - } else if (!timer_pending(sd->ocr_power_timer)) { | 81 | @@ -XXX,XX +XXX,XX @@ bool get_phys_addr(CPUARMState *env, target_ulong address, |
93 | - timer_mod_ns(sd->ocr_power_timer, | 82 | ipa_secure = attrs->secure; |
94 | - (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) | 83 | if (arm_is_secure_below_el3(env)) { |
95 | - + OCR_POWER_DELAY_NS)); | 84 | if (ipa_secure) { |
96 | + } else { | 85 | - attrs->secure = !(env->cp15.vstcr_el2.raw_tcr & VSTCR_SW); |
97 | + trace_sdcard_inquiry_cmd41(); | 86 | + attrs->secure = !(env->cp15.vstcr_el2 & VSTCR_SW); |
98 | + if (!timer_pending(sd->ocr_power_timer)) { | 87 | } else { |
99 | + timer_mod_ns(sd->ocr_power_timer, | 88 | - attrs->secure = !(env->cp15.vtcr_el2.raw_tcr & VTCR_NSW); |
100 | + (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) | 89 | + attrs->secure = !(env->cp15.vtcr_el2 & VTCR_NSW); |
101 | + + OCR_POWER_DELAY_NS)); | 90 | } |
102 | + } | 91 | } else { |
92 | assert(!ipa_secure); | ||
93 | @@ -XXX,XX +XXX,XX @@ bool get_phys_addr(CPUARMState *env, target_ulong address, | ||
94 | if (arm_is_secure_below_el3(env)) { | ||
95 | if (ipa_secure) { | ||
96 | attrs->secure = | ||
97 | - !(env->cp15.vstcr_el2.raw_tcr & (VSTCR_SA | VSTCR_SW)); | ||
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))); | ||
103 | } | 105 | } |
104 | } | 106 | } |
105 | 107 | return 0; | |
106 | @@ -XXX,XX +XXX,XX @@ void sd_write_data(SDState *sd, uint8_t value) | ||
107 | if (sd->card_status & (ADDRESS_ERROR | WP_VIOLATION)) | ||
108 | return; | ||
109 | |||
110 | + trace_sdcard_write_data(sd->current_cmd, value); | ||
111 | switch (sd->current_cmd) { | ||
112 | case 24: /* CMD24: WRITE_SINGLE_BLOCK */ | ||
113 | sd->data[sd->data_offset ++] = value; | ||
114 | @@ -XXX,XX +XXX,XX @@ uint8_t sd_read_data(SDState *sd) | ||
115 | |||
116 | io_len = (sd->ocr & (1 << 30)) ? 512 : sd->blk_len; | ||
117 | |||
118 | + trace_sdcard_read_data(sd->current_cmd, io_len); | ||
119 | switch (sd->current_cmd) { | ||
120 | case 6: /* CMD6: SWITCH_FUNCTION */ | ||
121 | ret = sd->data[sd->data_offset ++]; | ||
122 | diff --git a/hw/sd/trace-events b/hw/sd/trace-events | ||
123 | index XXXXXXX..XXXXXXX 100644 | ||
124 | --- a/hw/sd/trace-events | ||
125 | +++ b/hw/sd/trace-events | ||
126 | @@ -XXX,XX +XXX,XX @@ sdhci_capareg(const char *desc, uint16_t val) "%s: %u" | ||
127 | sdcard_normal_command(uint8_t cmd, uint32_t arg, const char *state) "CMD%d arg 0x%08x (state %s)" | ||
128 | sdcard_app_command(uint8_t acmd, uint32_t arg) "ACMD%d arg 0x%08x" | ||
129 | sdcard_response(const char *rspdesc, int rsplen) "%s (sz:%d)" | ||
130 | +sdcard_powerup(void) "" | ||
131 | +sdcard_inquiry_cmd41(void) "" | ||
132 | +sdcard_set_enable(bool current_state, bool new_state) "%u -> %u" | ||
133 | +sdcard_reset(void) "" | ||
134 | +sdcard_set_blocklen(uint16_t length) "0x%04x" | ||
135 | +sdcard_inserted(bool readonly) "read_only: %u" | ||
136 | +sdcard_ejected(void) "" | ||
137 | +sdcard_erase(void) "" | ||
138 | +sdcard_lock(void) "" | ||
139 | +sdcard_unlock(void) "" | ||
140 | sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" | ||
141 | sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" | ||
142 | +sdcard_write_data(uint8_t cmd, uint8_t value) "CMD%02d value 0x%02x" | ||
143 | +sdcard_read_data(uint8_t cmd, int length) "CMD%02d len %d" | ||
144 | +sdcard_set_voltage(uint16_t millivolts) "%u mV" | ||
145 | |||
146 | # hw/sd/milkymist-memcard.c | ||
147 | milkymist_memcard_memory_read(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" | ||
148 | -- | 108 | -- |
149 | 2.16.1 | 109 | 2.25.1 |
150 | |||
151 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | Change the representation of the TCR_EL* registers in the CPU state |
---|---|---|---|
2 | struct from struct TCR to uint64_t. This allows us to drop the | ||
3 | custom vmsa_ttbcr_raw_write() function, moving the "enforce RES0" | ||
4 | checks to their more usual location in the writefn | ||
5 | vmsa_ttbcr_write(). We also don't need the resetfn any more. | ||
2 | 6 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
5 | Message-id: 20180215220540.6556-3-f4bug@amsat.org | ||
6 | 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> | ||
9 | Message-id: 20220714132303.1287193-7-peter.maydell@linaro.org | ||
7 | --- | 10 | --- |
8 | hw/sd/sd.c | 32 ++++++++++++++++++++++++++------ | 11 | target/arm/cpu.h | 8 +---- |
9 | hw/sd/trace-events | 6 ++++++ | 12 | target/arm/internals.h | 6 ++-- |
10 | 2 files changed, 32 insertions(+), 6 deletions(-) | 13 | target/arm/cpu.c | 2 +- |
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(-) | ||
11 | 18 | ||
12 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 19 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
13 | index XXXXXXX..XXXXXXX 100644 | 20 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/sd/sd.c | 21 | --- a/target/arm/cpu.h |
15 | +++ b/hw/sd/sd.c | 22 | +++ b/target/arm/cpu.h |
16 | @@ -XXX,XX +XXX,XX @@ | 23 | @@ -XXX,XX +XXX,XX @@ typedef struct ARMGenericTimer { |
17 | #include "qemu/error-report.h" | 24 | #define GTIMER_HYPVIRT 4 |
18 | #include "qemu/timer.h" | 25 | #define NUM_GTIMERS 5 |
19 | #include "qemu/log.h" | 26 | |
20 | +#include "trace.h" | 27 | -typedef struct { |
21 | 28 | - uint64_t raw_tcr; | |
22 | //#define DEBUG_SD 1 | 29 | - uint32_t mask; |
23 | 30 | - uint32_t base_mask; | |
24 | @@ -XXX,XX +XXX,XX @@ struct SDState { | 31 | -} TCR; |
25 | bool cmd_line; | 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 | } | ||
96 | diff --git a/target/arm/helper.c b/target/arm/helper.c | ||
97 | index XXXXXXX..XXXXXXX 100644 | ||
98 | --- a/target/arm/helper.c | ||
99 | +++ b/target/arm/helper.c | ||
100 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo pmsav5_cp_reginfo[] = { | ||
101 | .fieldoffset = offsetof(CPUARMState, cp15.c6_region[7]) }, | ||
26 | }; | 102 | }; |
27 | 103 | ||
28 | +static const char *sd_state_name(enum SDCardStates state) | 104 | -static void vmsa_ttbcr_raw_write(CPUARMState *env, const ARMCPRegInfo *ri, |
29 | +{ | 105 | - uint64_t value) |
30 | + static const char *state_name[] = { | 106 | +static void vmsa_ttbcr_write(CPUARMState *env, const ARMCPRegInfo *ri, |
31 | + [sd_idle_state] = "idle", | 107 | + uint64_t value) |
32 | + [sd_ready_state] = "ready", | ||
33 | + [sd_identification_state] = "identification", | ||
34 | + [sd_standby_state] = "standby", | ||
35 | + [sd_transfer_state] = "transfer", | ||
36 | + [sd_sendingdata_state] = "sendingdata", | ||
37 | + [sd_receivingdata_state] = "receivingdata", | ||
38 | + [sd_programming_state] = "programming", | ||
39 | + [sd_disconnect_state] = "disconnect", | ||
40 | + }; | ||
41 | + if (state == sd_inactive_state) { | ||
42 | + return "inactive"; | ||
43 | + } | ||
44 | + assert(state <= ARRAY_SIZE(state_name)); | ||
45 | + return state_name[state]; | ||
46 | +} | ||
47 | + | ||
48 | static uint8_t sd_get_dat_lines(SDState *sd) | ||
49 | { | 108 | { |
50 | return sd->enable ? sd->dat_lines : 0; | 109 | - TCR *tcr = raw_ptr(env, ri); |
51 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | 110 | - int maskshift = extract32(value, 0, 3); |
52 | uint32_t rca = 0x0000; | 111 | + ARMCPU *cpu = env_archcpu(env); |
53 | uint64_t addr = (sd->ocr & (1 << 30)) ? (uint64_t) req.arg << 9 : req.arg; | 112 | |
54 | 113 | if (!arm_feature(env, ARM_FEATURE_V8)) { | |
55 | + trace_sdcard_normal_command(req.cmd, req.arg, sd_state_name(sd->state)); | 114 | if (arm_feature(env, ARM_FEATURE_LPAE) && (value & TTBCR_EAE)) { |
56 | + | 115 | - /* Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when |
57 | /* Not interpreting this as an app command */ | 116 | - * using Long-desciptor translation table format */ |
58 | sd->card_status &= ~APP_CMD; | 117 | + /* |
59 | 118 | + * Pre ARMv8 bits [21:19], [15:14] and [6:3] are UNK/SBZP when | |
60 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | 119 | + * using Long-descriptor translation table format |
61 | sd->multi_blk_cnt = 0; | 120 | + */ |
62 | } | 121 | value &= ~((7 << 19) | (3 << 14) | (0xf << 3)); |
63 | 122 | } else if (arm_feature(env, ARM_FEATURE_EL3)) { | |
64 | - DPRINTF("CMD%d 0x%08x state %d\n", req.cmd, req.arg, sd->state); | 123 | - /* In an implementation that includes the Security Extensions |
65 | switch (req.cmd) { | 124 | + /* |
66 | /* Basic commands (Class 0 and Class 1) */ | 125 | + * In an implementation that includes the Security Extensions |
67 | case 0: /* CMD0: GO_IDLE_STATE */ | 126 | * TTBCR has additional fields PD0 [4] and PD1 [5] for |
68 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | 127 | * Short-descriptor translation table format. |
69 | return sd_r1; | 128 | */ |
70 | 129 | @@ -XXX,XX +XXX,XX @@ static void vmsa_ttbcr_raw_write(CPUARMState *env, const ARMCPRegInfo *ri, | |
71 | case 56: /* CMD56: GEN_CMD */ | 130 | } |
72 | - fprintf(stderr, "SD: GEN_CMD 0x%08x\n", req.arg); | 131 | } |
73 | - | 132 | |
74 | switch (sd->state) { | 133 | - /* Update the masks corresponding to the TCR bank being written |
75 | case sd_transfer_state: | 134 | - * Note that we always calculate mask and base_mask, but |
76 | sd->data_offset = 0; | 135 | - * they are only used for short-descriptor tables (ie if EAE is 0); |
77 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | 136 | - * for long-descriptor tables the TCR fields are used differently |
78 | static sd_rsp_type_t sd_app_command(SDState *sd, | 137 | - * and the mask and base_mask values are meaningless. |
79 | SDRequest req) | 138 | - */ |
139 | - tcr->raw_tcr = value; | ||
140 | - tcr->mask = ~(((uint32_t)0xffffffffu) >> maskshift); | ||
141 | - tcr->base_mask = ~((uint32_t)0x3fffu >> maskshift); | ||
142 | -} | ||
143 | - | ||
144 | -static void vmsa_ttbcr_write(CPUARMState *env, const ARMCPRegInfo *ri, | ||
145 | - uint64_t value) | ||
146 | -{ | ||
147 | - ARMCPU *cpu = env_archcpu(env); | ||
148 | - TCR *tcr = raw_ptr(env, ri); | ||
149 | - | ||
150 | if (arm_feature(env, ARM_FEATURE_LPAE)) { | ||
151 | /* With LPAE the TTBCR could result in a change of ASID | ||
152 | * via the TTBCR.A1 bit, so do a TLB flush. | ||
153 | */ | ||
154 | tlb_flush(CPU(cpu)); | ||
155 | } | ||
156 | - /* Preserve the high half of TCR_EL1, set via TTBCR2. */ | ||
157 | - value = deposit64(tcr->raw_tcr, 0, 32, value); | ||
158 | - vmsa_ttbcr_raw_write(env, ri, value); | ||
159 | -} | ||
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) | ||
80 | { | 176 | { |
81 | - DPRINTF("ACMD%d 0x%08x\n", req.cmd, req.arg); | 177 | ARMCPU *cpu = env_archcpu(env); |
82 | + trace_sdcard_app_command(req.cmd, req.arg); | 178 | - TCR *tcr = raw_ptr(env, ri); |
83 | sd->card_status |= APP_CMD; | 179 | |
84 | switch (req.cmd) { | 180 | /* For AArch64 the A1 bit could result in a change of ASID, so TLB flush. */ |
85 | case 6: /* ACMD6: SET_BUS_WIDTH */ | 181 | tlb_flush(CPU(cpu)); |
86 | @@ -XXX,XX +XXX,XX @@ send_response: | 182 | - tcr->raw_tcr = value; |
87 | 183 | + raw_write(env, ri, value); | |
88 | static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) | 184 | } |
89 | { | 185 | |
90 | - DPRINTF("sd_blk_read: addr = 0x%08llx, len = %d\n", | 186 | static void vmsa_ttbr_write(CPUARMState *env, const ARMCPRegInfo *ri, |
91 | - (unsigned long long) addr, len); | 187 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo vmsa_cp_reginfo[] = { |
92 | + trace_sdcard_read_block(addr, len); | 188 | .opc0 = 3, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 2, |
93 | if (!sd->blk || blk_pread(sd->blk, addr, sd->data, len) < 0) { | 189 | .access = PL1_RW, .accessfn = access_tvm_trvm, |
94 | fprintf(stderr, "sd_blk_read: read error on host side\n"); | 190 | .writefn = vmsa_tcr_el12_write, |
95 | } | 191 | - .resetfn = vmsa_ttbcr_reset, .raw_writefn = raw_write, |
96 | @@ -XXX,XX +XXX,XX @@ static void sd_blk_read(SDState *sd, uint64_t addr, uint32_t len) | 192 | + .raw_writefn = raw_write, |
97 | 193 | + .resetvalue = 0, | |
98 | static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) | 194 | .fieldoffset = offsetof(CPUARMState, cp15.tcr_el[1]) }, |
99 | { | 195 | { .name = "TTBCR", .cp = 15, .crn = 2, .crm = 0, .opc1 = 0, .opc2 = 2, |
100 | + trace_sdcard_write_block(addr, len); | 196 | .access = PL1_RW, .accessfn = access_tvm_trvm, |
101 | if (!sd->blk || blk_pwrite(sd->blk, addr, sd->data, len, 0) < 0) { | 197 | .type = ARM_CP_ALIAS, .writefn = vmsa_ttbcr_write, |
102 | fprintf(stderr, "sd_blk_write: write error on host side\n"); | 198 | - .raw_writefn = vmsa_ttbcr_raw_write, |
103 | } | 199 | - /* No offsetoflow32 -- pass the entire TCR to writefn/raw_writefn. */ |
104 | diff --git a/hw/sd/trace-events b/hw/sd/trace-events | 200 | - .bank_fieldoffsets = { offsetof(CPUARMState, cp15.tcr_el[3]), |
105 | index XXXXXXX..XXXXXXX 100644 | 201 | - offsetof(CPUARMState, cp15.tcr_el[1])} }, |
106 | --- a/hw/sd/trace-events | 202 | + .raw_writefn = raw_write, |
107 | +++ b/hw/sd/trace-events | 203 | + .bank_fieldoffsets = { offsetoflow32(CPUARMState, cp15.tcr_el[3]), |
108 | @@ -XXX,XX +XXX,XX @@ sdhci_read_dataport(uint16_t data_count) "all %u bytes of data have been read fr | 204 | + offsetoflow32(CPUARMState, cp15.tcr_el[1])} }, |
109 | sdhci_write_dataport(uint16_t data_count) "write buffer filled with %u bytes of data" | 205 | }; |
110 | sdhci_capareg(const char *desc, uint16_t val) "%s: %u" | 206 | |
111 | 207 | /* Note that unlike TTBCR, writing to TTBCR2 does not require flushing | |
112 | +# hw/sd/sd.c | 208 | @@ -XXX,XX +XXX,XX @@ static const ARMCPRegInfo ttbcr2_reginfo = { |
113 | +sdcard_normal_command(uint8_t cmd, uint32_t arg, const char *state) "CMD%d arg 0x%08x (state %s)" | 209 | .access = PL1_RW, .accessfn = access_tvm_trvm, |
114 | +sdcard_app_command(uint8_t acmd, uint32_t arg) "ACMD%d arg 0x%08x" | 210 | .type = ARM_CP_ALIAS, |
115 | +sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" | 211 | .bank_fieldoffsets = { |
116 | +sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" | 212 | - offsetofhigh32(CPUARMState, cp15.tcr_el[3].raw_tcr), |
117 | + | 213 | - offsetofhigh32(CPUARMState, cp15.tcr_el[1].raw_tcr), |
118 | # hw/sd/milkymist-memcard.c | 214 | + offsetofhigh32(CPUARMState, cp15.tcr_el[3]), |
119 | milkymist_memcard_memory_read(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" | 215 | + offsetofhigh32(CPUARMState, cp15.tcr_el[1]), |
120 | milkymist_memcard_memory_write(uint32_t addr, uint32_t value) "addr 0x%08x value 0x%08x" | 216 | }, |
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); | ||
121 | -- | 255 | -- |
122 | 2.16.1 | 256 | 2.25.1 |
123 | |||
124 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | In regime_tcr() we return the appropriate TCR register for the |
---|---|---|---|
2 | translation regime. For Secure EL2, we return the VSTCR_EL2 value, | ||
3 | but in this translation regime some fields that control behaviour are | ||
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. | ||
2 | 8 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 9 | Synthesize a TCR value by merging in the relevant VTCR_EL2 fields to |
4 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | 10 | the VSTCR_EL2 value. |
5 | Message-id: 20180215220540.6556-12-f4bug@amsat.org | 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> |
14 | Reviewed-by: Richard Henderson <richard.henderson@linaro.org> | ||
15 | Message-id: 20220714132303.1287193-8-peter.maydell@linaro.org | ||
7 | --- | 16 | --- |
8 | include/hw/sd/sd.h | 1 - | 17 | target/arm/cpu.h | 19 +++++++++++++++++++ |
9 | hw/sd/sd.c | 21 +++++++++++++-------- | 18 | target/arm/internals.h | 22 +++++++++++++++++++--- |
10 | 2 files changed, 13 insertions(+), 9 deletions(-) | 19 | 2 files changed, 38 insertions(+), 3 deletions(-) |
11 | 20 | ||
12 | diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h | 21 | diff --git a/target/arm/cpu.h b/target/arm/cpu.h |
13 | index XXXXXXX..XXXXXXX 100644 | 22 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/include/hw/sd/sd.h | 23 | --- a/target/arm/cpu.h |
15 | +++ b/include/hw/sd/sd.h | 24 | +++ b/target/arm/cpu.h |
16 | @@ -XXX,XX +XXX,XX @@ | 25 | @@ -XXX,XX +XXX,XX @@ FIELD(CPTR_EL3, TCPAC, 31, 1) |
17 | #define READY_FOR_DATA (1 << 8) | 26 | #define TTBCR_SH1 (1U << 28) |
18 | #define APP_CMD (1 << 5) | 27 | #define TTBCR_EAE (1U << 31) |
19 | #define AKE_SEQ_ERROR (1 << 3) | 28 | |
20 | -#define OCR_CCS_BITN 30 | 29 | +FIELD(VTCR, T0SZ, 0, 6) |
21 | 30 | +FIELD(VTCR, SL0, 6, 2) | |
22 | typedef enum { | 31 | +FIELD(VTCR, IRGN0, 8, 2) |
23 | SD_VOLTAGE_0_4V = 400, /* currently not supported */ | 32 | +FIELD(VTCR, ORGN0, 10, 2) |
24 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 33 | +FIELD(VTCR, SH0, 12, 2) |
34 | +FIELD(VTCR, TG0, 14, 2) | ||
35 | +FIELD(VTCR, PS, 16, 3) | ||
36 | +FIELD(VTCR, VS, 19, 1) | ||
37 | +FIELD(VTCR, HA, 21, 1) | ||
38 | +FIELD(VTCR, HD, 22, 1) | ||
39 | +FIELD(VTCR, HWU59, 25, 1) | ||
40 | +FIELD(VTCR, HWU60, 26, 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) | ||
47 | + | ||
48 | /* Bit definitions for ARMv8 SPSR (PSTATE) format. | ||
49 | * Only these are valid when in AArch64 mode; in | ||
50 | * AArch32 mode SPSRs are basically CPSR-format. | ||
51 | diff --git a/target/arm/internals.h b/target/arm/internals.h | ||
25 | index XXXXXXX..XXXXXXX 100644 | 52 | index XXXXXXX..XXXXXXX 100644 |
26 | --- a/hw/sd/sd.c | 53 | --- a/target/arm/internals.h |
27 | +++ b/hw/sd/sd.c | 54 | +++ b/target/arm/internals.h |
28 | @@ -XXX,XX +XXX,XX @@ | 55 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx) |
29 | #include "qemu/osdep.h" | 56 | return env->cp15.sctlr_el[regime_el(env, mmu_idx)]; |
30 | #include "hw/qdev.h" | ||
31 | #include "hw/hw.h" | ||
32 | +#include "hw/registerfields.h" | ||
33 | #include "sysemu/block-backend.h" | ||
34 | #include "hw/sd/sd.h" | ||
35 | #include "qapi/error.h" | ||
36 | @@ -XXX,XX +XXX,XX @@ | ||
37 | //#define DEBUG_SD 1 | ||
38 | |||
39 | #define ACMD41_ENQUIRY_MASK 0x00ffffff | ||
40 | -#define OCR_POWER_UP 0x80000000 | ||
41 | -#define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ | ||
42 | |||
43 | typedef enum { | ||
44 | sd_r0 = 0, /* no response */ | ||
45 | @@ -XXX,XX +XXX,XX @@ static uint16_t sd_crc16(void *message, size_t width) | ||
46 | return shift_reg; | ||
47 | } | 57 | } |
48 | 58 | ||
49 | +#define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ | 59 | +/* |
60 | + * These are the fields in VTCR_EL2 which affect both the Secure stage 2 | ||
61 | + * and the Non-Secure stage 2 translation regimes (and hence which are | ||
62 | + * not present in VSTCR_EL2). | ||
63 | + */ | ||
64 | +#define VTCR_SHARED_FIELD_MASK \ | ||
65 | + (R_VTCR_IRGN0_MASK | R_VTCR_ORGN0_MASK | R_VTCR_SH0_MASK | \ | ||
66 | + R_VTCR_PS_MASK | R_VTCR_VS_MASK | R_VTCR_HA_MASK | R_VTCR_HD_MASK | \ | ||
67 | + R_VTCR_DS_MASK) | ||
50 | + | 68 | + |
51 | +FIELD(OCR, CARD_CAPACITY, 30, 1) /* 0:SDSC, 1:SDHC/SDXC */ | 69 | /* Return the value of the TCR controlling this translation regime */ |
52 | +FIELD(OCR, CARD_POWER_UP, 31, 1) | 70 | static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
53 | + | ||
54 | static void sd_set_ocr(SDState *sd) | ||
55 | { | 71 | { |
56 | /* All voltages OK, Standard Capacity SD Memory Card, not yet powered up */ | 72 | @@ -XXX,XX +XXX,XX @@ static inline uint64_t regime_tcr(CPUARMState *env, ARMMMUIdx mmu_idx) |
57 | @@ -XXX,XX +XXX,XX @@ static void sd_ocr_powerup(void *opaque) | 73 | } |
58 | SDState *sd = opaque; | 74 | if (mmu_idx == ARMMMUIdx_Stage2_S) { |
59 | 75 | /* | |
60 | trace_sdcard_powerup(); | 76 | - * Note: Secure stage 2 nominally shares fields from VTCR_EL2, but |
61 | - /* Set powered up bit in OCR */ | 77 | - * those are not currently used by QEMU, so just return VSTCR_EL2. |
62 | - assert(!(sd->ocr & OCR_POWER_UP)); | 78 | + * Secure stage 2 shares fields from VTCR_EL2. We merge those |
63 | - sd->ocr |= OCR_POWER_UP; | 79 | + * in with the VSTCR_EL2 value to synthesize a single VTCR_EL2 format |
64 | + assert(!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)); | 80 | + * value so the callers don't need to special case this. |
65 | + | 81 | + * |
66 | + /* card power-up OK */ | 82 | + * If a future architecture change defines bits in VSTCR_EL2 that |
67 | + sd->ocr = FIELD_DP32(sd->ocr, OCR, CARD_POWER_UP, 1); | 83 | + * overlap with these VTCR_EL2 fields we may need to revisit this. |
84 | */ | ||
85 | - return env->cp15.vstcr_el2; | ||
86 | + uint64_t v = env->cp15.vstcr_el2 & ~VTCR_SHARED_FIELD_MASK; | ||
87 | + v |= env->cp15.vtcr_el2 & VTCR_SHARED_FIELD_MASK; | ||
88 | + return v; | ||
89 | } | ||
90 | return env->cp15.tcr_el[regime_el(env, mmu_idx)]; | ||
68 | } | 91 | } |
69 | |||
70 | static void sd_set_scr(SDState *sd) | ||
71 | @@ -XXX,XX +XXX,XX @@ static bool sd_ocr_vmstate_needed(void *opaque) | ||
72 | SDState *sd = opaque; | ||
73 | |||
74 | /* Include the OCR state (and timer) if it is not yet powered up */ | ||
75 | - return !(sd->ocr & OCR_POWER_UP); | ||
76 | + return !FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP); | ||
77 | } | ||
78 | |||
79 | static const VMStateDescription sd_ocr_vmstate = { | ||
80 | @@ -XXX,XX +XXX,XX @@ static void sd_erase(SDState *sd) | ||
81 | return; | ||
82 | } | ||
83 | |||
84 | - if (extract32(sd->ocr, OCR_CCS_BITN, 1)) { | ||
85 | + if (FIELD_EX32(sd->ocr, OCR, CARD_CAPACITY)) { | ||
86 | /* High capacity memory card: erase units are 512 byte blocks */ | ||
87 | erase_start *= 512; | ||
88 | erase_end *= 512; | ||
89 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_app_command(SDState *sd, | ||
90 | * UEFI, which sends an initial enquiry ACMD41, but | ||
91 | * assumes that the card is in ready state as soon as it | ||
92 | * sees the power up bit set. */ | ||
93 | - if (!(sd->ocr & OCR_POWER_UP)) { | ||
94 | + if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { | ||
95 | if ((req.arg & ACMD41_ENQUIRY_MASK) != 0) { | ||
96 | timer_del(sd->ocr_power_timer); | ||
97 | sd_ocr_powerup(sd); | ||
98 | -- | 92 | -- |
99 | 2.16.1 | 93 | 2.25.1 |
100 | |||
101 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | replace switch(single case) -> if() | 3 | The correct bit for the CONV bit in NPCM7XX ADC is bit 13. This patch |
4 | fixes that in the module, and also lower the IRQ when the guest | ||
5 | is done handling an interrupt event from the ADC module. | ||
4 | 6 | ||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 7 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
6 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | 8 | Reviewed-by: Patrick Venture<venture@google.com> |
7 | Message-id: 20180215221325.7611-16-f4bug@amsat.org | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
10 | Message-id: 20220714182836.89602-4-wuhaotsh@google.com | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
9 | --- | 12 | --- |
10 | hw/sd/sd.c | 26 +++++++++++--------------- | 13 | hw/adc/npcm7xx_adc.c | 2 +- |
11 | 1 file changed, 11 insertions(+), 15 deletions(-) | 14 | tests/qtest/npcm7xx_adc-test.c | 2 +- |
15 | 2 files changed, 2 insertions(+), 2 deletions(-) | ||
12 | 16 | ||
13 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 17 | diff --git a/hw/adc/npcm7xx_adc.c b/hw/adc/npcm7xx_adc.c |
14 | index XXXXXXX..XXXXXXX 100644 | 18 | index XXXXXXX..XXXXXXX 100644 |
15 | --- a/hw/sd/sd.c | 19 | --- a/hw/adc/npcm7xx_adc.c |
16 | +++ b/hw/sd/sd.c | 20 | +++ b/hw/adc/npcm7xx_adc.c |
17 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | 21 | @@ -XXX,XX +XXX,XX @@ REG32(NPCM7XX_ADC_DATA, 0x4) |
18 | 22 | #define NPCM7XX_ADC_CON_INT BIT(18) | |
19 | case 8: /* CMD8: SEND_IF_COND */ | 23 | #define NPCM7XX_ADC_CON_EN BIT(17) |
20 | /* Physical Layer Specification Version 2.00 command */ | 24 | #define NPCM7XX_ADC_CON_RST BIT(16) |
21 | - switch (sd->state) { | 25 | -#define NPCM7XX_ADC_CON_CONV BIT(14) |
22 | - case sd_idle_state: | 26 | +#define NPCM7XX_ADC_CON_CONV BIT(13) |
23 | - sd->vhs = 0; | 27 | #define NPCM7XX_ADC_CON_DIV(rv) extract32(rv, 1, 8) |
24 | - | 28 | |
25 | - /* No response if not exactly one VHS bit is set. */ | 29 | #define NPCM7XX_ADC_MAX_RESULT 1023 |
26 | - if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1))) { | 30 | diff --git a/tests/qtest/npcm7xx_adc-test.c b/tests/qtest/npcm7xx_adc-test.c |
27 | - return sd->spi ? sd_r7 : sd_r0; | 31 | index XXXXXXX..XXXXXXX 100644 |
28 | - } | 32 | --- a/tests/qtest/npcm7xx_adc-test.c |
29 | - | 33 | +++ b/tests/qtest/npcm7xx_adc-test.c |
30 | - /* Accept. */ | 34 | @@ -XXX,XX +XXX,XX @@ |
31 | - sd->vhs = req.arg; | 35 | #define CON_INT BIT(18) |
32 | - return sd_r7; | 36 | #define CON_EN BIT(17) |
33 | - | 37 | #define CON_RST BIT(16) |
34 | - default: | 38 | -#define CON_CONV BIT(14) |
35 | + if (sd->state != sd_idle_state) { | 39 | +#define CON_CONV BIT(13) |
36 | break; | 40 | #define CON_DIV(rv) extract32(rv, 1, 8) |
37 | } | 41 | |
38 | - break; | 42 | #define FST_RDST BIT(1) |
39 | + sd->vhs = 0; | ||
40 | + | ||
41 | + /* No response if not exactly one VHS bit is set. */ | ||
42 | + if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1))) { | ||
43 | + return sd->spi ? sd_r7 : sd_r0; | ||
44 | + } | ||
45 | + | ||
46 | + /* Accept. */ | ||
47 | + sd->vhs = req.arg; | ||
48 | + return sd_r7; | ||
49 | |||
50 | case 9: /* CMD9: SEND_CSD */ | ||
51 | switch (sd->state) { | ||
52 | -- | 43 | -- |
53 | 2.16.1 | 44 | 2.25.1 |
54 | |||
55 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Hao Wu <wuhaotsh@google.com> |
---|---|---|---|
2 | 2 | ||
3 | To comply with Spec v1.10 (and 2.00, 3.01): | 3 | Our sensor test requires both reading and writing from a sensor's |
4 | QOM property. So we need to make the input of ADC module R/W instead | ||
5 | of write only for that to work. | ||
4 | 6 | ||
5 | . TRAN_SPEED | 7 | Signed-off-by: Hao Wu <wuhaotsh@google.com> |
6 | 8 | Reviewed-by: Titus Rwantare <titusr@google.com> | |
7 | for current SD Memory Cards that field must be always 0_0110_010b (032h) which is | 9 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> |
8 | equal to 25MHz - the mandatory maximum operating frequency of SD Memory Card. | 10 | Message-id: 20220714182836.89602-5-wuhaotsh@google.com |
9 | |||
10 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
11 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
12 | Message-id: 20180215221325.7611-4-f4bug@amsat.org | ||
13 | [PMM: fixed comment indent] | ||
14 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 11 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
15 | --- | 12 | --- |
16 | hw/sd/sd.c | 2 +- | 13 | hw/adc/npcm7xx_adc.c | 2 +- |
17 | 1 file changed, 1 insertion(+), 1 deletion(-) | 14 | 1 file changed, 1 insertion(+), 1 deletion(-) |
18 | 15 | ||
19 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 16 | diff --git a/hw/adc/npcm7xx_adc.c b/hw/adc/npcm7xx_adc.c |
20 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
21 | --- a/hw/sd/sd.c | 18 | --- a/hw/adc/npcm7xx_adc.c |
22 | +++ b/hw/sd/sd.c | 19 | +++ b/hw/adc/npcm7xx_adc.c |
23 | @@ -XXX,XX +XXX,XX @@ static void sd_set_csd(SDState *sd, uint64_t size) | 20 | @@ -XXX,XX +XXX,XX @@ static void npcm7xx_adc_init(Object *obj) |
24 | sd->csd[0] = 0x00; /* CSD structure */ | 21 | |
25 | sd->csd[1] = 0x26; /* Data read access-time-1 */ | 22 | for (i = 0; i < NPCM7XX_ADC_NUM_INPUTS; ++i) { |
26 | sd->csd[2] = 0x00; /* Data read access-time-2 */ | 23 | object_property_add_uint32_ptr(obj, "adci[*]", |
27 | - sd->csd[3] = 0x5a; /* Max. data transfer rate */ | 24 | - &s->adci[i], OBJ_PROP_FLAG_WRITE); |
28 | + sd->csd[3] = 0x32; /* Max. data transfer rate: 25 MHz */ | 25 | + &s->adci[i], OBJ_PROP_FLAG_READWRITE); |
29 | sd->csd[4] = 0x5f; /* Card Command Classes */ | 26 | } |
30 | sd->csd[5] = 0x50 | /* Max. read data block length */ | 27 | object_property_add_uint32_ptr(obj, "vref", |
31 | HWBLOCK_SHIFT; | 28 | &s->vref, OBJ_PROP_FLAG_WRITE); |
32 | -- | 29 | -- |
33 | 2.16.1 | 30 | 2.25.1 |
34 | |||
35 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.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 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 8 | Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1057 |
4 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
5 | Acked-by: Michael Walle <michael@walle.cc> | ||
6 | Message-id: 20180216022933.10945-2-f4bug@amsat.org | ||
7 | 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 | ||
8 | --- | 12 | --- |
9 | hw/sd/milkymist-memcard.c | 17 ++++++++++------- | 13 | target/arm/translate-a64.c | 4 +++- |
10 | 1 file changed, 10 insertions(+), 7 deletions(-) | 14 | 1 file changed, 3 insertions(+), 1 deletion(-) |
11 | 15 | ||
12 | diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c | 16 | diff --git a/target/arm/translate-a64.c b/target/arm/translate-a64.c |
13 | index XXXXXXX..XXXXXXX 100644 | 17 | index XXXXXXX..XXXXXXX 100644 |
14 | --- a/hw/sd/milkymist-memcard.c | 18 | --- a/target/arm/translate-a64.c |
15 | +++ b/hw/sd/milkymist-memcard.c | 19 | +++ b/target/arm/translate-a64.c |
16 | @@ -XXX,XX +XXX,XX @@ | 20 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn, |
17 | */ | 21 | bool is_store = false; |
18 | 22 | bool is_extended = false; | |
19 | #include "qemu/osdep.h" | 23 | bool is_unpriv = (idx == 2); |
20 | +#include "qemu/log.h" | 24 | - bool iss_valid = !is_vector; |
21 | #include "hw/hw.h" | 25 | + bool iss_valid; |
22 | #include "hw/sysbus.h" | 26 | bool post_index; |
23 | #include "sysemu/sysemu.h" | 27 | bool writeback; |
24 | #include "trace.h" | 28 | int memidx; |
25 | -#include "qemu/error-report.h" | 29 | @@ -XXX,XX +XXX,XX @@ static void disas_ldst_reg_imm9(DisasContext *s, uint32_t insn, |
26 | +#include "include/qapi/error.h" | 30 | g_assert_not_reached(); |
27 | #include "sysemu/block-backend.h" | ||
28 | #include "sysemu/blockdev.h" | ||
29 | #include "hw/sd/sd.h" | ||
30 | @@ -XXX,XX +XXX,XX @@ static uint64_t memcard_read(void *opaque, hwaddr addr, | ||
31 | } else { | ||
32 | r = s->response[s->response_read_ptr++]; | ||
33 | if (s->response_read_ptr > s->response_len) { | ||
34 | - error_report("milkymist_memcard: " | ||
35 | - "read more cmd bytes than available. Clipping."); | ||
36 | + qemu_log_mask(LOG_GUEST_ERROR, "milkymist_memcard: " | ||
37 | + "read more cmd bytes than available. Clipping."); | ||
38 | s->response_read_ptr = 0; | ||
39 | } | ||
40 | } | ||
41 | @@ -XXX,XX +XXX,XX @@ static uint64_t memcard_read(void *opaque, hwaddr addr, | ||
42 | break; | ||
43 | |||
44 | default: | ||
45 | - error_report("milkymist_memcard: read access to unknown register 0x" | ||
46 | - TARGET_FMT_plx, addr << 2); | ||
47 | + qemu_log_mask(LOG_UNIMP, "milkymist_memcard: " | ||
48 | + "read access to unknown register 0x%" HWADDR_PRIx "\n", | ||
49 | + addr << 2); | ||
50 | break; | ||
51 | } | 31 | } |
52 | 32 | ||
53 | @@ -XXX,XX +XXX,XX @@ static void memcard_write(void *opaque, hwaddr addr, uint64_t value, | 33 | + iss_valid = !is_vector && !writeback; |
54 | break; | 34 | + |
55 | 35 | if (rn == 31) { | |
56 | default: | 36 | gen_check_sp_alignment(s); |
57 | - error_report("milkymist_memcard: write access to unknown register 0x" | ||
58 | - TARGET_FMT_plx, addr << 2); | ||
59 | + qemu_log_mask(LOG_UNIMP, "milkymist_memcard: " | ||
60 | + "write access to unknown register 0x%" HWADDR_PRIx " " | ||
61 | + "(value 0x%" PRIx64 ")\n", addr << 2, value); | ||
62 | break; | ||
63 | } | 37 | } |
64 | } | ||
65 | -- | 38 | -- |
66 | 2.16.1 | 39 | 2.25.1 |
67 | |||
68 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | using the sdbus_*() API. | ||
4 | |||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
7 | Acked-by: Michael Walle <michael@walle.cc> | ||
8 | Message-id: 20180216022933.10945-4-f4bug@amsat.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/sd/milkymist-memcard.c | 38 +++++++++++++++++++++----------------- | ||
12 | 1 file changed, 21 insertions(+), 17 deletions(-) | ||
13 | |||
14 | diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/sd/milkymist-memcard.c | ||
17 | +++ b/hw/sd/milkymist-memcard.c | ||
18 | @@ -XXX,XX +XXX,XX @@ struct MilkymistMemcardState { | ||
19 | SysBusDevice parent_obj; | ||
20 | |||
21 | MemoryRegion regs_region; | ||
22 | - SDState *card; | ||
23 | + SDBus sdbus; | ||
24 | |||
25 | int command_write_ptr; | ||
26 | int response_read_ptr; | ||
27 | @@ -XXX,XX +XXX,XX @@ static void memcard_sd_command(MilkymistMemcardState *s) | ||
28 | req.crc = s->command[5]; | ||
29 | |||
30 | s->response[0] = req.cmd; | ||
31 | - s->response_len = sd_do_command(s->card, &req, s->response+1); | ||
32 | + s->response_len = sdbus_do_command(&s->sdbus, &req, s->response + 1); | ||
33 | s->response_read_ptr = 0; | ||
34 | |||
35 | if (s->response_len == 16) { | ||
36 | @@ -XXX,XX +XXX,XX @@ static uint64_t memcard_read(void *opaque, hwaddr addr, | ||
37 | r = 0xffffffff; | ||
38 | } else { | ||
39 | r = 0; | ||
40 | - r |= sd_read_data(s->card) << 24; | ||
41 | - r |= sd_read_data(s->card) << 16; | ||
42 | - r |= sd_read_data(s->card) << 8; | ||
43 | - r |= sd_read_data(s->card); | ||
44 | + r |= sdbus_read_data(&s->sdbus) << 24; | ||
45 | + r |= sdbus_read_data(&s->sdbus) << 16; | ||
46 | + r |= sdbus_read_data(&s->sdbus) << 8; | ||
47 | + r |= sdbus_read_data(&s->sdbus); | ||
48 | } | ||
49 | break; | ||
50 | case R_CLK2XDIV: | ||
51 | @@ -XXX,XX +XXX,XX @@ static void memcard_write(void *opaque, hwaddr addr, uint64_t value, | ||
52 | if (!s->enabled) { | ||
53 | break; | ||
54 | } | ||
55 | - sd_write_data(s->card, (value >> 24) & 0xff); | ||
56 | - sd_write_data(s->card, (value >> 16) & 0xff); | ||
57 | - sd_write_data(s->card, (value >> 8) & 0xff); | ||
58 | - sd_write_data(s->card, value & 0xff); | ||
59 | + sdbus_write_data(&s->sdbus, (value >> 24) & 0xff); | ||
60 | + sdbus_write_data(&s->sdbus, (value >> 16) & 0xff); | ||
61 | + sdbus_write_data(&s->sdbus, (value >> 8) & 0xff); | ||
62 | + sdbus_write_data(&s->sdbus, value & 0xff); | ||
63 | break; | ||
64 | case R_ENABLE: | ||
65 | s->regs[addr] = value; | ||
66 | @@ -XXX,XX +XXX,XX @@ static void milkymist_memcard_reset(DeviceState *d) | ||
67 | for (i = 0; i < R_MAX; i++) { | ||
68 | s->regs[i] = 0; | ||
69 | } | ||
70 | - /* Since we're still using the legacy SD API the card is not plugged | ||
71 | - * into any bus, and we must reset it manually. | ||
72 | - */ | ||
73 | - device_reset(DEVICE(s->card)); | ||
74 | } | ||
75 | |||
76 | static void milkymist_memcard_init(Object *obj) | ||
77 | @@ -XXX,XX +XXX,XX @@ static void milkymist_memcard_init(Object *obj) | ||
78 | static void milkymist_memcard_realize(DeviceState *dev, Error **errp) | ||
79 | { | ||
80 | MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev); | ||
81 | + DeviceState *carddev; | ||
82 | BlockBackend *blk; | ||
83 | DriveInfo *dinfo; | ||
84 | + Error *err = NULL; | ||
85 | |||
86 | + qbus_create_inplace(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, | ||
87 | + dev, "sd-bus"); | ||
88 | + | ||
89 | + /* Create and plug in the sd card */ | ||
90 | /* FIXME use a qdev drive property instead of drive_get_next() */ | ||
91 | dinfo = drive_get_next(IF_SD); | ||
92 | blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL; | ||
93 | - s->card = sd_init(blk, false); | ||
94 | - if (s->card == NULL) { | ||
95 | - error_setg(errp, "failed to init SD card"); | ||
96 | + carddev = qdev_create(&s->sdbus.qbus, TYPE_SD_CARD); | ||
97 | + qdev_prop_set_drive(carddev, "drive", blk, &err); | ||
98 | + object_property_set_bool(OBJECT(carddev), true, "realized", &err); | ||
99 | + if (err) { | ||
100 | + error_setg(errp, "failed to init SD card: %s", error_get_pretty(err)); | ||
101 | return; | ||
102 | } | ||
103 | s->enabled = blk && blk_is_inserted(blk); | ||
104 | -- | ||
105 | 2.16.1 | ||
106 | |||
107 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | On reset the bus will reset the card, | ||
4 | we can now drop the device_reset() call. | ||
5 | |||
6 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
7 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
8 | Message-id: 20180216022933.10945-5-f4bug@amsat.org | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/sd/ssi-sd.c | 32 +++++++++++++++++++------------- | ||
12 | 1 file changed, 19 insertions(+), 13 deletions(-) | ||
13 | |||
14 | diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/sd/ssi-sd.c | ||
17 | +++ b/hw/sd/ssi-sd.c | ||
18 | @@ -XXX,XX +XXX,XX @@ typedef struct { | ||
19 | int32_t arglen; | ||
20 | int32_t response_pos; | ||
21 | int32_t stopping; | ||
22 | - SDState *sd; | ||
23 | + SDBus sdbus; | ||
24 | } ssi_sd_state; | ||
25 | |||
26 | #define TYPE_SSI_SD "ssi-sd" | ||
27 | @@ -XXX,XX +XXX,XX @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val) | ||
28 | request.arg = (s->cmdarg[0] << 24) | (s->cmdarg[1] << 16) | ||
29 | | (s->cmdarg[2] << 8) | s->cmdarg[3]; | ||
30 | DPRINTF("CMD%d arg 0x%08x\n", s->cmd, request.arg); | ||
31 | - s->arglen = sd_do_command(s->sd, &request, longresp); | ||
32 | + s->arglen = sdbus_do_command(&s->sdbus, &request, longresp); | ||
33 | if (s->arglen <= 0) { | ||
34 | s->arglen = 1; | ||
35 | s->response[0] = 4; | ||
36 | @@ -XXX,XX +XXX,XX @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val) | ||
37 | DPRINTF("Response 0x%02x\n", s->response[s->response_pos]); | ||
38 | return s->response[s->response_pos++]; | ||
39 | } | ||
40 | - if (sd_data_ready(s->sd)) { | ||
41 | + if (sdbus_data_ready(&s->sdbus)) { | ||
42 | DPRINTF("Data read\n"); | ||
43 | s->mode = SSI_SD_DATA_START; | ||
44 | } else { | ||
45 | @@ -XXX,XX +XXX,XX @@ static uint32_t ssi_sd_transfer(SSISlave *dev, uint32_t val) | ||
46 | s->mode = SSI_SD_DATA_READ; | ||
47 | return 0xfe; | ||
48 | case SSI_SD_DATA_READ: | ||
49 | - val = sd_read_data(s->sd); | ||
50 | - if (!sd_data_ready(s->sd)) { | ||
51 | + val = sdbus_read_data(&s->sdbus); | ||
52 | + if (!sdbus_data_ready(&s->sdbus)) { | ||
53 | DPRINTF("Data read end\n"); | ||
54 | s->mode = SSI_SD_CMD; | ||
55 | } | ||
56 | @@ -XXX,XX +XXX,XX @@ static const VMStateDescription vmstate_ssi_sd = { | ||
57 | static void ssi_sd_realize(SSISlave *d, Error **errp) | ||
58 | { | ||
59 | ssi_sd_state *s = FROM_SSI_SLAVE(ssi_sd_state, d); | ||
60 | + DeviceState *carddev; | ||
61 | DriveInfo *dinfo; | ||
62 | + Error *err = NULL; | ||
63 | |||
64 | + qbus_create_inplace(&s->sdbus, sizeof(s->sdbus), TYPE_SD_BUS, | ||
65 | + DEVICE(d), "sd-bus"); | ||
66 | + | ||
67 | + /* Create and plug in the sd card */ | ||
68 | /* FIXME use a qdev drive property instead of drive_get_next() */ | ||
69 | dinfo = drive_get_next(IF_SD); | ||
70 | - s->sd = sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, true); | ||
71 | - if (s->sd == NULL) { | ||
72 | - error_setg(errp, "Device initialization failed."); | ||
73 | + carddev = qdev_create(&s->sdbus.qbus, TYPE_SD_CARD); | ||
74 | + if (dinfo) { | ||
75 | + qdev_prop_set_drive(carddev, "drive", blk_by_legacy_dinfo(dinfo), &err); | ||
76 | + } | ||
77 | + object_property_set_bool(OBJECT(carddev), true, "spi", &err); | ||
78 | + object_property_set_bool(OBJECT(carddev), true, "realized", &err); | ||
79 | + if (err) { | ||
80 | + error_setg(errp, "failed to init SD card: %s", error_get_pretty(err)); | ||
81 | return; | ||
82 | } | ||
83 | } | ||
84 | @@ -XXX,XX +XXX,XX @@ static void ssi_sd_reset(DeviceState *dev) | ||
85 | s->arglen = 0; | ||
86 | s->response_pos = 0; | ||
87 | s->stopping = 0; | ||
88 | - | ||
89 | - /* Since we're still using the legacy SD API the card is not plugged | ||
90 | - * into any bus, and we must reset it manually. | ||
91 | - */ | ||
92 | - device_reset(DEVICE(s->sd)); | ||
93 | } | ||
94 | |||
95 | static void ssi_sd_class_init(ObjectClass *klass, void *data) | ||
96 | -- | ||
97 | 2.16.1 | ||
98 | |||
99 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | place card registers first, this will ease further code movements. | ||
4 | |||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
7 | Message-id: 20180215220540.6556-2-f4bug@amsat.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | hw/sd/sd.c | 16 +++++++++------- | ||
11 | 1 file changed, 9 insertions(+), 7 deletions(-) | ||
12 | |||
13 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/hw/sd/sd.c | ||
16 | +++ b/hw/sd/sd.c | ||
17 | @@ -XXX,XX +XXX,XX @@ enum SDCardStates { | ||
18 | struct SDState { | ||
19 | DeviceState parent_obj; | ||
20 | |||
21 | - uint32_t mode; /* current card mode, one of SDCardModes */ | ||
22 | - int32_t state; /* current card state, one of SDCardStates */ | ||
23 | + /* SD Memory Card Registers */ | ||
24 | uint32_t ocr; | ||
25 | - QEMUTimer *ocr_power_timer; | ||
26 | uint8_t scr[8]; | ||
27 | uint8_t cid[16]; | ||
28 | uint8_t csd[16]; | ||
29 | uint16_t rca; | ||
30 | uint32_t card_status; | ||
31 | uint8_t sd_status[64]; | ||
32 | + | ||
33 | + /* Configurable properties */ | ||
34 | + BlockBackend *blk; | ||
35 | + bool spi; | ||
36 | + | ||
37 | + uint32_t mode; /* current card mode, one of SDCardModes */ | ||
38 | + int32_t state; /* current card state, one of SDCardStates */ | ||
39 | uint32_t vhs; | ||
40 | bool wp_switch; | ||
41 | unsigned long *wp_groups; | ||
42 | @@ -XXX,XX +XXX,XX @@ struct SDState { | ||
43 | uint8_t pwd[16]; | ||
44 | uint32_t pwd_len; | ||
45 | uint8_t function_group[6]; | ||
46 | - | ||
47 | - bool spi; | ||
48 | uint8_t current_cmd; | ||
49 | /* True if we will handle the next command as an ACMD. Note that this does | ||
50 | * *not* track the APP_CMD status bit! | ||
51 | @@ -XXX,XX +XXX,XX @@ struct SDState { | ||
52 | uint8_t data[512]; | ||
53 | qemu_irq readonly_cb; | ||
54 | qemu_irq inserted_cb; | ||
55 | - BlockBackend *blk; | ||
56 | - | ||
57 | + QEMUTimer *ocr_power_timer; | ||
58 | bool enable; | ||
59 | uint8_t dat_lines; | ||
60 | bool cmd_line; | ||
61 | -- | ||
62 | 2.16.1 | ||
63 | |||
64 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
5 | Message-id: 20180215220540.6556-5-f4bug@amsat.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | hw/sd/sd.c | 16 +--------------- | ||
9 | 1 file changed, 1 insertion(+), 15 deletions(-) | ||
10 | |||
11 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/hw/sd/sd.c | ||
14 | +++ b/hw/sd/sd.c | ||
15 | @@ -XXX,XX +XXX,XX @@ | ||
16 | |||
17 | //#define DEBUG_SD 1 | ||
18 | |||
19 | -#ifdef DEBUG_SD | ||
20 | -#define DPRINTF(fmt, ...) \ | ||
21 | -do { fprintf(stderr, "SD: " fmt , ## __VA_ARGS__); } while (0) | ||
22 | -#else | ||
23 | -#define DPRINTF(fmt, ...) do {} while(0) | ||
24 | -#endif | ||
25 | - | ||
26 | #define ACMD41_ENQUIRY_MASK 0x00ffffff | ||
27 | #define OCR_POWER_UP 0x80000000 | ||
28 | #define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ | ||
29 | @@ -XXX,XX +XXX,XX @@ send_response: | ||
30 | } | ||
31 | |||
32 | #ifdef DEBUG_SD | ||
33 | - if (rsplen) { | ||
34 | - int i; | ||
35 | - DPRINTF("Response:"); | ||
36 | - for (i = 0; i < rsplen; i++) { | ||
37 | - DPRINTF(" %02x", response[i]); | ||
38 | - } | ||
39 | - DPRINTF(" state %d\n", sd->state); | ||
40 | - } | ||
41 | + qemu_hexdump((const char *)response, stderr, "Response", rsplen); | ||
42 | #endif | ||
43 | |||
44 | return rsplen; | ||
45 | -- | ||
46 | 2.16.1 | ||
47 | |||
48 | diff view generated by jsdifflib |
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | 1 | From: Andrey Makarov <ph.makarov@gmail.com> |
---|---|---|---|
2 | 2 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | 3 | There is nothing in the specs on DMA engine interrupt lines: it should have |
4 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | 4 | been in the "BCM2835 ARM Peripherals" datasheet but the appropriate |
5 | Message-id: 20180215220540.6556-8-f4bug@amsat.org | 5 | "ARM peripherals interrupt table" (p.113) is nearly empty. |
6 | |||
7 | All Raspberry Pi models 1-3 (based on bcm2835) have | ||
8 | Linux device tree (arch/arm/boot/dts/bcm2835-common.dtsi +25): | ||
9 | |||
10 | /* dma channel 11-14 share one irq */ | ||
11 | |||
12 | This information is repeated in the driver code | ||
13 | (drivers/dma/bcm2835-dma.c +1344): | ||
14 | |||
15 | /* | ||
16 | * in case of channel >= 11 | ||
17 | * use the 11th interrupt and that is shared | ||
18 | */ | ||
19 | |||
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] | ||
25 | Reviewed-by: Peter Maydell <peter.maydell@linaro.org> | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | 26 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> |
7 | --- | 27 | --- |
8 | hw/sd/sdmmc-internal.h | 15 +++++++++++++++ | 28 | include/hw/arm/bcm2835_peripherals.h | 2 + |
9 | hw/sd/sd.c | 22 ++++++++++++++++------ | 29 | hw/arm/bcm2835_peripherals.c | 26 +++++- |
10 | 2 files changed, 31 insertions(+), 6 deletions(-) | 30 | tests/qtest/bcm2835-dma-test.c | 118 +++++++++++++++++++++++++++ |
11 | create mode 100644 hw/sd/sdmmc-internal.h | 31 | tests/qtest/meson.build | 3 +- |
12 | 32 | 4 files changed, 147 insertions(+), 2 deletions(-) | |
13 | diff --git a/hw/sd/sdmmc-internal.h b/hw/sd/sdmmc-internal.h | 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 | ||
36 | index XXXXXXX..XXXXXXX 100644 | ||
37 | --- a/include/hw/arm/bcm2835_peripherals.h | ||
38 | +++ b/include/hw/arm/bcm2835_peripherals.h | ||
39 | @@ -XXX,XX +XXX,XX @@ | ||
40 | #include "hw/char/bcm2835_aux.h" | ||
41 | #include "hw/display/bcm2835_fb.h" | ||
42 | #include "hw/dma/bcm2835_dma.h" | ||
43 | +#include "hw/or-irq.h" | ||
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 | ||
14 | new file mode 100644 | 112 | new file mode 100644 |
15 | index XXXXXXX..XXXXXXX | 113 | index XXXXXXX..XXXXXXX |
16 | --- /dev/null | 114 | --- /dev/null |
17 | +++ b/hw/sd/sdmmc-internal.h | 115 | +++ b/tests/qtest/bcm2835-dma-test.c |
18 | @@ -XXX,XX +XXX,XX @@ | 116 | @@ -XXX,XX +XXX,XX @@ |
19 | +/* | 117 | +/* |
20 | + * SD/MMC cards common | 118 | + * QTest testcase for BCM283x DMA engine (on Raspberry Pi 3) |
119 | + * and its interrupts coming to Interrupt Controller. | ||
21 | + * | 120 | + * |
22 | + * Copyright (c) 2018 Philippe Mathieu-Daudé <f4bug@amsat.org> | 121 | + * Copyright (c) 2022 Auriga LLC |
23 | + * | 122 | + * |
24 | + * This work is licensed under the terms of the GNU GPL, version 2 or later. | ||
25 | + * See the COPYING file in the top-level directory. | ||
26 | + * SPDX-License-Identifier: GPL-2.0-or-later | 123 | + * SPDX-License-Identifier: GPL-2.0-or-later |
27 | + */ | 124 | + */ |
28 | +#ifndef SD_INTERNAL_H | 125 | + |
29 | +#define SD_INTERNAL_H | 126 | +#include "qemu/osdep.h" |
30 | + | 127 | +#include "libqtest-single.h" |
31 | +#define SDMMC_CMD_MAX 64 | 128 | + |
32 | + | 129 | +/* Offsets in raspi3b platform: */ |
33 | +#endif | 130 | +#define RASPI3_DMA_BASE 0x3f007000 |
34 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | 131 | +#define RASPI3_IC_BASE 0x3f00b200 |
132 | + | ||
133 | +/* Used register/fields definitions */ | ||
134 | + | ||
135 | +/* DMA engine registers: */ | ||
136 | +#define BCM2708_DMA_CS 0 | ||
137 | +#define BCM2708_DMA_ACTIVE (1 << 0) | ||
138 | +#define BCM2708_DMA_INT (1 << 2) | ||
139 | + | ||
140 | +#define BCM2708_DMA_ADDR 0x04 | ||
141 | + | ||
142 | +#define BCM2708_DMA_INT_STATUS 0xfe0 | ||
143 | + | ||
144 | +/* DMA Trasfer Info fields: */ | ||
145 | +#define BCM2708_DMA_INT_EN (1 << 0) | ||
146 | +#define BCM2708_DMA_D_INC (1 << 4) | ||
147 | +#define BCM2708_DMA_S_INC (1 << 8) | ||
148 | + | ||
149 | +/* Interrupt controller registers: */ | ||
150 | +#define IRQ_PENDING_BASIC 0x00 | ||
151 | +#define IRQ_GPU_PENDING1_AGGR (1 << 8) | ||
152 | +#define IRQ_PENDING_1 0x04 | ||
153 | +#define IRQ_ENABLE_1 0x10 | ||
154 | + | ||
155 | +/* Data for the test: */ | ||
156 | +#define SCB_ADDR 256 | ||
157 | +#define S_ADDR 32 | ||
158 | +#define D_ADDR 64 | ||
159 | +#define TXFR_LEN 32 | ||
160 | +const uint32_t check_data = 0x12345678; | ||
161 | + | ||
162 | +static void bcm2835_dma_test_interrupt(int dma_c, int irq_line) | ||
163 | +{ | ||
164 | + uint64_t dma_base = RASPI3_DMA_BASE + dma_c * 0x100; | ||
165 | + int gpu_irq_line = 16 + irq_line; | ||
166 | + | ||
167 | + /* Check that interrupts are silent by default: */ | ||
168 | + writel(RASPI3_IC_BASE + IRQ_ENABLE_1, 1 << gpu_irq_line); | ||
169 | + int isr = readl(dma_base + BCM2708_DMA_INT_STATUS); | ||
170 | + g_assert_cmpint(isr, ==, 0); | ||
171 | + uint32_t reg0 = readl(dma_base + BCM2708_DMA_CS); | ||
172 | + g_assert_cmpint(reg0, ==, 0); | ||
173 | + uint32_t ic_pending = readl(RASPI3_IC_BASE + IRQ_PENDING_BASIC); | ||
174 | + g_assert_cmpint(ic_pending, ==, 0); | ||
175 | + uint32_t gpu_pending1 = readl(RASPI3_IC_BASE + IRQ_PENDING_1); | ||
176 | + g_assert_cmpint(gpu_pending1, ==, 0); | ||
177 | + | ||
178 | + /* Prepare Control Block: */ | ||
179 | + writel(SCB_ADDR + 0, BCM2708_DMA_S_INC | BCM2708_DMA_D_INC | | ||
180 | + BCM2708_DMA_INT_EN); /* transfer info */ | ||
181 | + writel(SCB_ADDR + 4, S_ADDR); /* source address */ | ||
182 | + writel(SCB_ADDR + 8, D_ADDR); /* destination address */ | ||
183 | + writel(SCB_ADDR + 12, TXFR_LEN); /* transfer length */ | ||
184 | + writel(dma_base + BCM2708_DMA_ADDR, SCB_ADDR); | ||
185 | + | ||
186 | + writel(S_ADDR, check_data); | ||
187 | + for (int word = S_ADDR + 4; word < S_ADDR + TXFR_LEN; word += 4) { | ||
188 | + writel(word, ~check_data); | ||
189 | + } | ||
190 | + /* Perform the transfer: */ | ||
191 | + writel(dma_base + BCM2708_DMA_CS, BCM2708_DMA_ACTIVE); | ||
192 | + | ||
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); | ||
213 | +} | ||
214 | + | ||
215 | +static void bcm2835_dma_test_interrupts(void) | ||
216 | +{ | ||
217 | + /* DMA engines 0--10 have separate IRQ lines, 11--14 - only one: */ | ||
218 | + bcm2835_dma_test_interrupt(0, 0); | ||
219 | + bcm2835_dma_test_interrupt(10, 10); | ||
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 | ||
35 | index XXXXXXX..XXXXXXX 100644 | 236 | index XXXXXXX..XXXXXXX 100644 |
36 | --- a/hw/sd/sd.c | 237 | --- a/tests/qtest/meson.build |
37 | +++ b/hw/sd/sd.c | 238 | +++ b/tests/qtest/meson.build |
38 | @@ -XXX,XX +XXX,XX @@ | 239 | @@ -XXX,XX +XXX,XX @@ qtests_aarch64 = \ |
39 | #include "qemu/error-report.h" | 240 | ['arm-cpu-features', |
40 | #include "qemu/timer.h" | 241 | 'numa-test', |
41 | #include "qemu/log.h" | 242 | 'boot-serial-test', |
42 | +#include "sdmmc-internal.h" | 243 | - 'migration-test'] |
43 | #include "trace.h" | 244 | + 'migration-test', |
44 | 245 | + 'bcm2835-dma-test'] | |
45 | //#define DEBUG_SD 1 | 246 | |
46 | @@ -XXX,XX +XXX,XX @@ static void sd_set_mode(SDState *sd) | 247 | qtests_s390x = \ |
47 | } | 248 | (slirp.found() ? ['pxe-test', 'test-netfilter'] : []) + \ |
48 | } | ||
49 | |||
50 | -static const sd_cmd_type_t sd_cmd_type[64] = { | ||
51 | +static const sd_cmd_type_t sd_cmd_type[SDMMC_CMD_MAX] = { | ||
52 | sd_bc, sd_none, sd_bcr, sd_bcr, sd_none, sd_none, sd_none, sd_ac, | ||
53 | sd_bcr, sd_ac, sd_ac, sd_adtc, sd_ac, sd_ac, sd_none, sd_ac, | ||
54 | + /* 16 */ | ||
55 | sd_ac, sd_adtc, sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, | ||
56 | sd_adtc, sd_adtc, sd_adtc, sd_adtc, sd_ac, sd_ac, sd_adtc, sd_none, | ||
57 | + /* 32 */ | ||
58 | sd_ac, sd_ac, sd_none, sd_none, sd_none, sd_none, sd_ac, sd_none, | ||
59 | sd_none, sd_none, sd_bc, sd_none, sd_none, sd_none, sd_none, sd_none, | ||
60 | + /* 48 */ | ||
61 | sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_ac, | ||
62 | sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, | ||
63 | }; | ||
64 | |||
65 | -static const int sd_cmd_class[64] = { | ||
66 | +static const int sd_cmd_class[SDMMC_CMD_MAX] = { | ||
67 | 0, 0, 0, 0, 0, 9, 10, 0, 0, 0, 0, 1, 0, 0, 0, 0, | ||
68 | 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 6, 6, 6, 6, | ||
69 | 5, 5, 10, 10, 10, 10, 5, 9, 9, 9, 7, 7, 7, 7, 7, 7, | ||
70 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
71 | /* Not interpreting this as an app command */ | ||
72 | sd->card_status &= ~APP_CMD; | ||
73 | |||
74 | - if (sd_cmd_type[req.cmd & 0x3F] == sd_ac | ||
75 | - || sd_cmd_type[req.cmd & 0x3F] == sd_adtc) { | ||
76 | + if (sd_cmd_type[req.cmd] == sd_ac | ||
77 | + || sd_cmd_type[req.cmd] == sd_adtc) { | ||
78 | rca = req.arg >> 16; | ||
79 | } | ||
80 | |||
81 | @@ -XXX,XX +XXX,XX @@ static int cmd_valid_while_locked(SDState *sd, SDRequest *req) | ||
82 | if (req->cmd == 16 || req->cmd == 55) { | ||
83 | return 1; | ||
84 | } | ||
85 | - return sd_cmd_class[req->cmd & 0x3F] == 0 | ||
86 | - || sd_cmd_class[req->cmd & 0x3F] == 7; | ||
87 | + return sd_cmd_class[req->cmd] == 0 | ||
88 | + || sd_cmd_class[req->cmd] == 7; | ||
89 | } | ||
90 | |||
91 | int sd_do_command(SDState *sd, SDRequest *req, | ||
92 | @@ -XXX,XX +XXX,XX @@ int sd_do_command(SDState *sd, SDRequest *req, | ||
93 | goto send_response; | ||
94 | } | ||
95 | |||
96 | + if (req->cmd >= SDMMC_CMD_MAX) { | ||
97 | + qemu_log_mask(LOG_GUEST_ERROR, "SD: incorrect command 0x%02x\n", | ||
98 | + req->cmd); | ||
99 | + req->cmd &= 0x3f; | ||
100 | + } | ||
101 | + | ||
102 | if (sd->card_status & CARD_IS_LOCKED) { | ||
103 | if (!cmd_valid_while_locked(sd, req)) { | ||
104 | sd->card_status |= ILLEGAL_COMMAND; | ||
105 | -- | 249 | -- |
106 | 2.16.1 | 250 | 2.25.1 |
107 | |||
108 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | code is now easier to read. | ||
4 | |||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
7 | Message-id: 20180215220540.6556-11-f4bug@amsat.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | hw/sd/sd.c | 3 ++- | ||
11 | 1 file changed, 2 insertions(+), 1 deletion(-) | ||
12 | |||
13 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/hw/sd/sd.c | ||
16 | +++ b/hw/sd/sd.c | ||
17 | @@ -XXX,XX +XXX,XX @@ | ||
18 | #include "hw/sd/sd.h" | ||
19 | #include "qapi/error.h" | ||
20 | #include "qemu/bitmap.h" | ||
21 | +#include "qemu/cutils.h" | ||
22 | #include "hw/qdev-properties.h" | ||
23 | #include "qemu/error-report.h" | ||
24 | #include "qemu/timer.h" | ||
25 | @@ -XXX,XX +XXX,XX @@ static void sd_set_csd(SDState *sd, uint64_t size) | ||
26 | uint32_t sectsize = (1 << (SECTOR_SHIFT + 1)) - 1; | ||
27 | uint32_t wpsize = (1 << (WPGROUP_SHIFT + 1)) - 1; | ||
28 | |||
29 | - if (size <= 0x40000000) { /* Standard Capacity SD */ | ||
30 | + if (size <= 1 * G_BYTE) { /* Standard Capacity SD */ | ||
31 | sd->csd[0] = 0x00; /* CSD structure */ | ||
32 | sd->csd[1] = 0x26; /* Data read access-time-1 */ | ||
33 | sd->csd[2] = 0x00; /* Data read access-time-2 */ | ||
34 | -- | ||
35 | 2.16.1 | ||
36 | |||
37 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
5 | Message-id: 20180215221325.7611-3-f4bug@amsat.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | hw/sd/sd.c | 3 +-- | ||
9 | 1 file changed, 1 insertion(+), 2 deletions(-) | ||
10 | |||
11 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/hw/sd/sd.c | ||
14 | +++ b/hw/sd/sd.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static void sd_set_csd(SDState *sd, uint64_t size) | ||
16 | sd->csd[13] = 0x20 | /* Max. write data block length */ | ||
17 | ((HWBLOCK_SHIFT << 6) & 0xc0); | ||
18 | sd->csd[14] = 0x00; /* File format group */ | ||
19 | - sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1; | ||
20 | } else { /* SDHC */ | ||
21 | size /= 512 * 1024; | ||
22 | size -= 1; | ||
23 | @@ -XXX,XX +XXX,XX @@ static void sd_set_csd(SDState *sd, uint64_t size) | ||
24 | sd->csd[12] = 0x0a; | ||
25 | sd->csd[13] = 0x40; | ||
26 | sd->csd[14] = 0x00; | ||
27 | - sd->csd[15] = 0x00; | ||
28 | } | ||
29 | + sd->csd[15] = (sd_crc7(sd->csd, 15) << 1) | 1; | ||
30 | } | ||
31 | |||
32 | static void sd_set_rca(SDState *sd) | ||
33 | -- | ||
34 | 2.16.1 | ||
35 | |||
36 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
5 | Message-id: 20180215221325.7611-5-f4bug@amsat.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | hw/sd/sd.c | 9 ++++++--- | ||
9 | 1 file changed, 6 insertions(+), 3 deletions(-) | ||
10 | |||
11 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/hw/sd/sd.c | ||
14 | +++ b/hw/sd/sd.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static void sd_ocr_powerup(void *opaque) | ||
16 | |||
17 | static void sd_set_scr(SDState *sd) | ||
18 | { | ||
19 | - sd->scr[0] = 0x00; /* SCR Structure */ | ||
20 | - sd->scr[1] = 0x2f; /* SD Security Support */ | ||
21 | - sd->scr[2] = 0x00; | ||
22 | + sd->scr[0] = (0 << 4) /* SCR version 1.0 */ | ||
23 | + | 0; /* Spec Versions 1.0 and 1.01 */ | ||
24 | + sd->scr[1] = (2 << 4) /* SDSC Card (Security Version 1.01) */ | ||
25 | + | 0b0101; /* 1-bit or 4-bit width bus modes */ | ||
26 | + sd->scr[2] = 0x00; /* Extended Security is not supported. */ | ||
27 | sd->scr[3] = 0x00; | ||
28 | + /* reserved for manufacturer usage */ | ||
29 | sd->scr[4] = 0x00; | ||
30 | sd->scr[5] = 0x00; | ||
31 | sd->scr[6] = 0x00; | ||
32 | -- | ||
33 | 2.16.1 | ||
34 | |||
35 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | This device does not model MMCA Specification previous to v4.2 | ||
4 | |||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
7 | Message-id: 20180215221325.7611-6-f4bug@amsat.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | hw/sd/sd.c | 33 --------------------------------- | ||
11 | 1 file changed, 33 deletions(-) | ||
12 | |||
13 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/hw/sd/sd.c | ||
16 | +++ b/hw/sd/sd.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
18 | } | ||
19 | break; | ||
20 | |||
21 | - case 11: /* CMD11: READ_DAT_UNTIL_STOP */ | ||
22 | - if (sd->spi) | ||
23 | - goto bad_cmd; | ||
24 | - switch (sd->state) { | ||
25 | - case sd_transfer_state: | ||
26 | - sd->state = sd_sendingdata_state; | ||
27 | - sd->data_start = req.arg; | ||
28 | - sd->data_offset = 0; | ||
29 | - | ||
30 | - if (sd->data_start + sd->blk_len > sd->size) | ||
31 | - sd->card_status |= ADDRESS_ERROR; | ||
32 | - return sd_r0; | ||
33 | - | ||
34 | - default: | ||
35 | - break; | ||
36 | - } | ||
37 | - break; | ||
38 | - | ||
39 | case 12: /* CMD12: STOP_TRANSMISSION */ | ||
40 | switch (sd->state) { | ||
41 | case sd_sendingdata_state: | ||
42 | @@ -XXX,XX +XXX,XX @@ uint8_t sd_read_data(SDState *sd) | ||
43 | sd->state = sd_transfer_state; | ||
44 | break; | ||
45 | |||
46 | - case 11: /* CMD11: READ_DAT_UNTIL_STOP */ | ||
47 | - if (sd->data_offset == 0) | ||
48 | - BLK_READ_BLOCK(sd->data_start, io_len); | ||
49 | - ret = sd->data[sd->data_offset ++]; | ||
50 | - | ||
51 | - if (sd->data_offset >= io_len) { | ||
52 | - sd->data_start += io_len; | ||
53 | - sd->data_offset = 0; | ||
54 | - if (sd->data_start + io_len > sd->size) { | ||
55 | - sd->card_status |= ADDRESS_ERROR; | ||
56 | - break; | ||
57 | - } | ||
58 | - } | ||
59 | - break; | ||
60 | - | ||
61 | case 13: /* ACMD13: SD_STATUS */ | ||
62 | ret = sd->sd_status[sd->data_offset ++]; | ||
63 | |||
64 | -- | ||
65 | 2.16.1 | ||
66 | |||
67 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | use the registerfields API to access the OCR register | ||
4 | |||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
7 | Message-id: 20180215221325.7611-8-f4bug@amsat.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | hw/sd/sd.c | 21 ++++++++++++++++----- | ||
11 | 1 file changed, 16 insertions(+), 5 deletions(-) | ||
12 | |||
13 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/hw/sd/sd.c | ||
16 | +++ b/hw/sd/sd.c | ||
17 | @@ -XXX,XX +XXX,XX @@ | ||
18 | |||
19 | //#define DEBUG_SD 1 | ||
20 | |||
21 | -#define ACMD41_ENQUIRY_MASK 0x00ffffff | ||
22 | - | ||
23 | typedef enum { | ||
24 | sd_r0 = 0, /* no response */ | ||
25 | sd_r1, /* normal response command */ | ||
26 | @@ -XXX,XX +XXX,XX @@ static uint16_t sd_crc16(void *message, size_t width) | ||
27 | |||
28 | #define OCR_POWER_DELAY_NS 500000 /* 0.5ms */ | ||
29 | |||
30 | +FIELD(OCR, VDD_VOLTAGE_WINDOW, 0, 24) | ||
31 | +FIELD(OCR, VDD_VOLTAGE_WIN_LO, 0, 8) | ||
32 | +FIELD(OCR, DUAL_VOLTAGE_CARD, 7, 1) | ||
33 | +FIELD(OCR, VDD_VOLTAGE_WIN_HI, 8, 16) | ||
34 | +FIELD(OCR, ACCEPT_SWITCH_1V8, 24, 1) /* Only UHS-I */ | ||
35 | +FIELD(OCR, UHS_II_CARD, 29, 1) /* Only UHS-II */ | ||
36 | FIELD(OCR, CARD_CAPACITY, 30, 1) /* 0:SDSC, 1:SDHC/SDXC */ | ||
37 | FIELD(OCR, CARD_POWER_UP, 31, 1) | ||
38 | |||
39 | +#define ACMD41_ENQUIRY_MASK 0x00ffffff | ||
40 | +#define ACMD41_R3_MASK (R_OCR_VDD_VOLTAGE_WIN_HI_MASK \ | ||
41 | + | R_OCR_ACCEPT_SWITCH_1V8_MASK \ | ||
42 | + | R_OCR_UHS_II_CARD_MASK \ | ||
43 | + | R_OCR_CARD_CAPACITY_MASK \ | ||
44 | + | R_OCR_CARD_POWER_UP_MASK) | ||
45 | + | ||
46 | static void sd_set_ocr(SDState *sd) | ||
47 | { | ||
48 | - /* All voltages OK, Standard Capacity SD Memory Card, not yet powered up */ | ||
49 | - sd->ocr = 0x00ffff00; | ||
50 | + /* All voltages OK */ | ||
51 | + sd->ocr = R_OCR_VDD_VOLTAGE_WIN_HI_MASK; | ||
52 | } | ||
53 | |||
54 | static void sd_ocr_powerup(void *opaque) | ||
55 | @@ -XXX,XX +XXX,XX @@ static void sd_response_r1_make(SDState *sd, uint8_t *response) | ||
56 | |||
57 | static void sd_response_r3_make(SDState *sd, uint8_t *response) | ||
58 | { | ||
59 | - stl_be_p(response, sd->ocr); | ||
60 | + stl_be_p(response, sd->ocr & ACMD41_R3_MASK); | ||
61 | } | ||
62 | |||
63 | static void sd_response_r6_make(SDState *sd, uint8_t *response) | ||
64 | -- | ||
65 | 2.16.1 | ||
66 | |||
67 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | Linux uses it to poll the bus before polling for a card. | ||
4 | |||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
7 | Message-id: 20180215221325.7611-10-f4bug@amsat.org | ||
8 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
9 | --- | ||
10 | hw/sd/sd.c | 5 ++--- | ||
11 | 1 file changed, 2 insertions(+), 3 deletions(-) | ||
12 | |||
13 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
14 | index XXXXXXX..XXXXXXX 100644 | ||
15 | --- a/hw/sd/sd.c | ||
16 | +++ b/hw/sd/sd.c | ||
17 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
18 | } | ||
19 | break; | ||
20 | |||
21 | - case 52: | ||
22 | - case 53: | ||
23 | - /* CMD52, CMD53: reserved for SDIO cards | ||
24 | + case 52 ... 54: | ||
25 | + /* CMD52, CMD53, CMD54: reserved for SDIO cards | ||
26 | * (see the SDIO Simplified Specification V2.0) | ||
27 | * Handle as illegal command but do not complain | ||
28 | * on stderr, as some OSes may use these in their | ||
29 | -- | ||
30 | 2.16.1 | ||
31 | |||
32 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | returning sd_illegal, since they are not implemented. | ||
4 | |||
5 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
6 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
7 | Message-id: 20180215221325.7611-11-f4bug@amsat.org | ||
8 | [PMM: tweak multiline comment format] | ||
9 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
10 | --- | ||
11 | hw/sd/sd.c | 12 ++++++++++++ | ||
12 | 1 file changed, 12 insertions(+) | ||
13 | |||
14 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
15 | index XXXXXXX..XXXXXXX 100644 | ||
16 | --- a/hw/sd/sd.c | ||
17 | +++ b/hw/sd/sd.c | ||
18 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_app_command(SDState *sd, | ||
19 | } | ||
20 | break; | ||
21 | |||
22 | + case 18: /* Reserved for SD security applications */ | ||
23 | + case 25: | ||
24 | + case 26: | ||
25 | + case 38: | ||
26 | + case 43 ... 49: | ||
27 | + /* Refer to the "SD Specifications Part3 Security Specification" for | ||
28 | + * information about the SD Security Features. | ||
29 | + */ | ||
30 | + qemu_log_mask(LOG_UNIMP, "SD: CMD%i Security not implemented\n", | ||
31 | + req.cmd); | ||
32 | + return sd_illegal; | ||
33 | + | ||
34 | default: | ||
35 | /* Fall back to standard commands. */ | ||
36 | return sd_normal_command(sd, req); | ||
37 | -- | ||
38 | 2.16.1 | ||
39 | |||
40 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | Suggested-by: Alistair Francis <alistair.francis@xilinx.com> | ||
4 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
5 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
6 | Message-id: 20180215221325.7611-12-f4bug@amsat.org | ||
7 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
8 | --- | ||
9 | hw/sd/sd.c | 22 +++++++++++++--------- | ||
10 | 1 file changed, 13 insertions(+), 9 deletions(-) | ||
11 | |||
12 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
13 | index XXXXXXX..XXXXXXX 100644 | ||
14 | --- a/hw/sd/sd.c | ||
15 | +++ b/hw/sd/sd.c | ||
16 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
17 | |||
18 | /* Block write commands (Class 4) */ | ||
19 | case 24: /* CMD24: WRITE_SINGLE_BLOCK */ | ||
20 | - if (sd->spi) | ||
21 | - goto unimplemented_cmd; | ||
22 | + if (sd->spi) { | ||
23 | + goto unimplemented_spi_cmd; | ||
24 | + } | ||
25 | switch (sd->state) { | ||
26 | case sd_transfer_state: | ||
27 | /* Writing in SPI mode not implemented. */ | ||
28 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
29 | break; | ||
30 | |||
31 | case 25: /* CMD25: WRITE_MULTIPLE_BLOCK */ | ||
32 | - if (sd->spi) | ||
33 | - goto unimplemented_cmd; | ||
34 | + if (sd->spi) { | ||
35 | + goto unimplemented_spi_cmd; | ||
36 | + } | ||
37 | switch (sd->state) { | ||
38 | case sd_transfer_state: | ||
39 | /* Writing in SPI mode not implemented. */ | ||
40 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
41 | break; | ||
42 | |||
43 | case 27: /* CMD27: PROGRAM_CSD */ | ||
44 | - if (sd->spi) | ||
45 | - goto unimplemented_cmd; | ||
46 | + if (sd->spi) { | ||
47 | + goto unimplemented_spi_cmd; | ||
48 | + } | ||
49 | switch (sd->state) { | ||
50 | case sd_transfer_state: | ||
51 | sd->state = sd_receivingdata_state; | ||
52 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
53 | |||
54 | /* Lock card commands (Class 7) */ | ||
55 | case 42: /* CMD42: LOCK_UNLOCK */ | ||
56 | - if (sd->spi) | ||
57 | - goto unimplemented_cmd; | ||
58 | + if (sd->spi) { | ||
59 | + goto unimplemented_spi_cmd; | ||
60 | + } | ||
61 | switch (sd->state) { | ||
62 | case sd_transfer_state: | ||
63 | sd->state = sd_receivingdata_state; | ||
64 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
65 | qemu_log_mask(LOG_GUEST_ERROR, "SD: Unknown CMD%i\n", req.cmd); | ||
66 | return sd_illegal; | ||
67 | |||
68 | - unimplemented_cmd: | ||
69 | + unimplemented_spi_cmd: | ||
70 | /* Commands that are recognised but not yet implemented in SPI mode. */ | ||
71 | qemu_log_mask(LOG_UNIMP, "SD: CMD%i not implemented in SPI mode\n", | ||
72 | req.cmd); | ||
73 | -- | ||
74 | 2.16.1 | ||
75 | |||
76 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
5 | Message-id: 20180215221325.7611-13-f4bug@amsat.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | hw/sd/sd.c | 29 ++++++++++++++++++++++++++--- | ||
9 | 1 file changed, 26 insertions(+), 3 deletions(-) | ||
10 | |||
11 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/hw/sd/sd.c | ||
14 | +++ b/hw/sd/sd.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
16 | |||
17 | /* Application specific commands (Class 8) */ | ||
18 | case 55: /* CMD55: APP_CMD */ | ||
19 | - if (sd->rca != rca) | ||
20 | - return sd_r0; | ||
21 | - | ||
22 | + if (!sd->spi) { | ||
23 | + if (sd->rca != rca) { | ||
24 | + return sd_r0; | ||
25 | + } | ||
26 | + } | ||
27 | sd->expecting_acmd = true; | ||
28 | sd->card_status |= APP_CMD; | ||
29 | return sd_r1; | ||
30 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
31 | } | ||
32 | break; | ||
33 | |||
34 | + case 58: /* CMD58: READ_OCR (SPI) */ | ||
35 | + if (!sd->spi) { | ||
36 | + goto bad_cmd; | ||
37 | + } | ||
38 | + return sd_r3; | ||
39 | + | ||
40 | + case 59: /* CMD59: CRC_ON_OFF (SPI) */ | ||
41 | + if (!sd->spi) { | ||
42 | + goto bad_cmd; | ||
43 | + } | ||
44 | + goto unimplemented_spi_cmd; | ||
45 | + | ||
46 | default: | ||
47 | bad_cmd: | ||
48 | qemu_log_mask(LOG_GUEST_ERROR, "SD: Unknown CMD%i\n", req.cmd); | ||
49 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_app_command(SDState *sd, | ||
50 | sd->card_status |= APP_CMD; | ||
51 | switch (req.cmd) { | ||
52 | case 6: /* ACMD6: SET_BUS_WIDTH */ | ||
53 | + if (sd->spi) { | ||
54 | + goto unimplemented_spi_cmd; | ||
55 | + } | ||
56 | switch (sd->state) { | ||
57 | case sd_transfer_state: | ||
58 | sd->sd_status[0] &= 0x3f; | ||
59 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_app_command(SDState *sd, | ||
60 | default: | ||
61 | /* Fall back to standard commands. */ | ||
62 | return sd_normal_command(sd, req); | ||
63 | + | ||
64 | + unimplemented_spi_cmd: | ||
65 | + /* Commands that are recognised but not yet implemented in SPI mode. */ | ||
66 | + qemu_log_mask(LOG_UNIMP, "SD: CMD%i not implemented in SPI mode\n", | ||
67 | + req.cmd); | ||
68 | + return sd_illegal; | ||
69 | } | ||
70 | |||
71 | qemu_log_mask(LOG_GUEST_ERROR, "SD: ACMD%i in a wrong state\n", req.cmd); | ||
72 | -- | ||
73 | 2.16.1 | ||
74 | |||
75 | diff view generated by jsdifflib |
Deleted patch | |||
---|---|---|---|
1 | From: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
2 | 1 | ||
3 | Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org> | ||
4 | Reviewed-by: Alistair Francis <alistair.francis@xilinx.com> | ||
5 | Message-id: 20180215221325.7611-14-f4bug@amsat.org | ||
6 | Signed-off-by: Peter Maydell <peter.maydell@linaro.org> | ||
7 | --- | ||
8 | hw/sd/sd.c | 8 ++++++++ | ||
9 | 1 file changed, 8 insertions(+) | ||
10 | |||
11 | diff --git a/hw/sd/sd.c b/hw/sd/sd.c | ||
12 | index XXXXXXX..XXXXXXX 100644 | ||
13 | --- a/hw/sd/sd.c | ||
14 | +++ b/hw/sd/sd.c | ||
15 | @@ -XXX,XX +XXX,XX @@ static sd_rsp_type_t sd_normal_command(SDState *sd, | ||
16 | |||
17 | /* Application specific commands (Class 8) */ | ||
18 | case 55: /* CMD55: APP_CMD */ | ||
19 | + switch (sd->state) { | ||
20 | + case sd_ready_state: | ||
21 | + case sd_identification_state: | ||
22 | + case sd_inactive_state: | ||
23 | + return sd_illegal; | ||
24 | + default: | ||
25 | + break; | ||
26 | + } | ||
27 | if (!sd->spi) { | ||
28 | if (sd->rca != rca) { | ||
29 | return sd_r0; | ||
30 | -- | ||
31 | 2.16.1 | ||
32 | |||
33 | diff view generated by jsdifflib |