qtest/npcm7xx_sdhci: Use card-provided address (RCA)
cover qtest/npcm7xx_sdhci: Use card-provided address (RCA)
Avoid to use the SDCard hardcoded 0x4567 RCA in npcm7xx SDHCI qtest, so we can generate one in the card model.
Philippe Mathieu-Daudé (4):
hw/sd/npcm7xx_sdhci: Use TYPE_SYSBUS_SDHCI definition hw/sd/sdhci: Log non-sequencial access as GUEST_ERROR tests/qtest/npcm7xx_sdhci: Access the card using its published address hw/sd/sdcard: Generate random RCA value
tests/qtest/libqos/sdhci-cmd.h | 2 ++ hw/sd/npcm7xx_sdhci.c | 3 ++- hw/sd/sd.c | 11 ++++++++--- hw/sd/sdhci.c | 5 +++-- tests/qtest/npcm7xx_sdhci-test.c | 8 ++++++-- hw/sd/trace-events | 1 + 6 files changed, 22 insertions(+), 8 deletions(-)
Signature · 1 line
2.41.0
PATCH 1/4 hw/sd/npcm7xx_sdhci: Use TYPE_SYSBUS_SDHCI definition
Use the macro instead of two explicit string literals.
--- hw/sd/npcm7xx_sdhci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/sd/npcm7xx_sdhci.c +2 -1
@@ -16,6 +16,7 @@#include "qemu/osdep.h" +#include "hw/sd/sdhci.h" #include "hw/sd/npcm7xx_sdhci.h" #include "migration/vmstate.h" #include "sdhci-internal.h"
@@ -162,7 +163,7 @@ static void npcm7xx_sdhci_instance_init(Object *obj) {NPCM7xxSDHCIState *s =NPCM7XX_SDHCI (obj); -object_initialize_child (OBJECT (s),"generic-sdhci" , &s->sdhci, +object_initialize_child (OBJECT (s),TYPE_SYSBUS_SDHCI , &s->sdhci,TYPE_SYSBUS_SDHCI ); }
Signature · 1 line
2.41.0
Re: [PATCH 1/4] hw/sd/npcm7xx_sdhci: Use TYPE_SYSBUS_SDHCI definition
Quoted 3 lines · Philippe Mathieu-Daudé
Use the macro instead of two explicit string literals.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 25 lines
--- hw/sd/npcm7xx_sdhci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)hw/sd/npcm7xx_sdhci.c +2
-1@@ -16,6 +16,7 @@#include "qemu/osdep.h" +#include "hw/sd/sdhci.h" #include "hw/sd/npcm7xx_sdhci.h" #include "migration/vmstate.h" #include "sdhci-internal.h" @@ -162,7 +163,7 @@ static void npcm7xx_sdhci_instance_init(Object *obj) {NPCM7xxSDHCIState *s =NPCM7XX_SDHCI (obj); -object_initialize_child (OBJECT (s),"generic-sdhci" , &s->sdhci, +object_initialize_child (OBJECT (s),TYPE_SYSBUS_SDHCI , &s->sdhci,TYPE_SYSBUS_SDHCI ); }
PATCH 2/4 hw/sd/sdhci: Log non-sequencial access as GUEST_ERROR
In reply to Philippe Mathieu-Daudé--- hw/sd/sdhci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/sd/sdhci.c +3 -2
@@ -983,8 +983,9 @@ static inline bool sdhci_buff_access_is_sequential(SDHCIState *s, unsigned byte_num) {if ((s->data_count &0x3 ) != byte_num) { -trace_sdhci_error ("Non-sequential access to Buffer Data Port register" -"is prohibited\n" ); +qemu_log_mask (LOG_GUEST_ERROR , +"SDHCI: Non-sequential access to Buffer Data Port" +" register is prohibited\n" );return false; }return true;
Signature · 1 line
2.41.0
Re: [PATCH 2/4] hw/sd/sdhci: Log non-sequencial access as GUEST_ERROR
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 20 lines
--- hw/sd/sdhci.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/sd/sdhci.c +3
-2@@ -983,8 +983,9 @@ static inline bool sdhci_buff_access_is_sequential(SDHCIState *s, unsigned byte_num) {if ((s->data_count &0x3 ) != byte_num) { -trace_sdhci_error ("Non-sequential access to Buffer Data Port register" -"is prohibited\n" ); +qemu_log_mask (LOG_GUEST_ERROR , +"SDHCI: Non-sequential access to Buffer Data Port" +" register is prohibited\n" );return false; }return true;
PATCH 3/4 tests/qtest/npcm7xx_sdhci: Access the card using its published address
In reply to Philippe Mathieu-DaudéCurrently setup_sd_card() asks the card its address, but discard the response and use hardcoded 0x4567.
Set the SDHC_CMD_RESPONSE bit to have the controller record the bus response, and read the response from the RSPREG0 register. Then we can select the card with its real address.
---
Cc: Hao Wu <[email protected]>
Cc: Chris Rauer <[email protected]>
Cc: Shengtan Mao <[email protected]>
Cc: Patrick Venture <[email protected]>
Cc: Tyrone Ting <[email protected]>
--- tests/qtest/libqos/sdhci-cmd.h | 2 ++ tests/qtest/npcm7xx_sdhci-test.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
tests/qtest/libqos/sdhci-cmd.h +2 -0
@@ -22,6 +22,7 @@#define SDHC_ARGUMENT 0x08#define SDHC_TRNMOD 0x0C#define SDHC_CMDREG 0x0E +#define SDHC_RSPREG0 0x10#define SDHC_BDATA 0x20#define SDHC_PRNSTS 0x24#define SDHC_BLKGAP 0x2A
@@ -38,6 +39,7 @@#define SDHC_TRNS_MULTI 0x0020/* CMD Reg */ +#define SDHC_CMD_RESPONSE (3 << 0)#define SDHC_CMD_DATA_PRESENT (1 << 5)#define SDHC_ALL_SEND_CID (2 << 8)#define SDHC_SEND_RELATIVE_ADDR (3 << 8)
tests/qtest/npcm7xx_sdhci-test.c +6 -2
@@ -30,6 +30,8 @@ char *sd_path;static QTestState *setup_sd_card (void ) { +uint16_t rca; +QTestState *qts =qtest_initf ("-machine kudo-bmc " "-device sd-card,drive=drive0 "
@@ -43,8 +45,10 @@ static QTestState *setup_sd_card(void)sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0 ,0 ,SDHC_APP_CMD );sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0x41200000 ,0 , (41 <<8 ));sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0 ,0 ,SDHC_ALL_SEND_CID ); -sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0 ,0 ,SDHC_SEND_RELATIVE_ADDR ); -sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0x45670000 ,0 , +sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0 ,0 ,SDHC_SEND_RELATIVE_ADDR + |SDHC_CMD_RESPONSE ); + rca =qtest_readl (qts,NPCM7XX_MMC_BA +SDHC_RSPREG0 ) >>16 ; +sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 , rca <<16 ,0 ,SDHC_SELECT_DESELECT_CARD );return qts;
Signature · 1 line
2.41.0
Re: [PATCH 3/4] tests/qtest/npcm7xx_sdhci: Access the card using its published address
Quoted 15 lines · Philippe Mathieu-Daudé
Currently
setup_sd_card()asks the card its address, but discard the response and use hardcoded0x4567.Set the
SDHC_CMD_RESPONSEbit to have the controller record the bus response, and read the response from the RSPREG0 register. Then we can select the card with its real address.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
Cc: Hao Wu <[email protected]>
Cc: Chris Rauer <[email protected]>
Cc: Shengtan Mao <[email protected]>
Cc: Patrick Venture <[email protected]>
Cc: Tyrone Ting <[email protected]>
Quoted 4 lines
--- tests/qtest/libqos/sdhci-cmd.h | 2 ++ tests/qtest/npcm7xx_sdhci-test.c | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-)
Thanks,
C.
Quoted 47 lines
tests/qtest/libqos/sdhci-cmd.h +2
-0@@ -22,6 +22,7 @@#define SDHC_ARGUMENT 0x08#define SDHC_TRNMOD 0x0C#define SDHC_CMDREG 0x0E +#define SDHC_RSPREG0 0x10#define SDHC_BDATA 0x20#define SDHC_PRNSTS 0x24#define SDHC_BLKGAP 0x2A@@ -38,6 +39,7 @@#define SDHC_TRNS_MULTI 0x0020/* CMD Reg */ +#define SDHC_CMD_RESPONSE (3 << 0)#define SDHC_CMD_DATA_PRESENT (1 << 5)#define SDHC_ALL_SEND_CID (2 << 8)#define SDHC_SEND_RELATIVE_ADDR (3 << 8)tests/qtest/npcm7xx_sdhci-test.c +6
-2@@ -30,6 +30,8 @@ char *sd_path;static QTestState *setup_sd_card (void ) { +uint16_t rca; +QTestState *qts =qtest_initf ("-machine kudo-bmc " "-device sd-card,drive=drive0 "@@ -43,8 +45,10 @@ static QTestState *setup_sd_card(void)sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0 ,0 ,SDHC_APP_CMD );sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0x41200000 ,0 , (41 <<8 ));sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0 ,0 ,SDHC_ALL_SEND_CID ); -sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0 ,0 ,SDHC_SEND_RELATIVE_ADDR ); -sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0x45670000 ,0 , +sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0 ,0 ,SDHC_SEND_RELATIVE_ADDR + |SDHC_CMD_RESPONSE ); + rca =qtest_readl (qts,NPCM7XX_MMC_BA +SDHC_RSPREG0 ) >>16 ; +sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 , rca <<16 ,0 ,SDHC_SELECT_DESELECT_CARD );return qts;
PATCH 4/4 hw/sd/sdcard: Generate random RCA value
In reply to Philippe Mathieu-DaudéRather than using the obscure 0x4567 magic value, use a real random one.
--- hw/sd/sd.c | 11 ++++++++--- hw/sd/trace-events | 1 + 2 files changed, 9 insertions(+), 3 deletions(-)
hw/sd/sd.c +8 -3
@@ -46,6 +46,7 @@#include "qemu/error-report.h" #include "qemu/timer.h" #include "qemu/log.h" +#include "qemu/guest-random.h" #include "qemu/module.h" #include "sdmmc-internal.h" #include "trace.h"
@@ -490,9 +491,10 @@ static void sd_set_csd(SDState *sd, uint64_t size)/* Relative Card Address register */ -static void sd_set_rca (SDState *sd) +static void sd_set_rca (SDState *sd,uint16_t value) { - sd->rca +=0x4567 ; +trace_sdcard_set_rca (value); + sd->rca = value; }static uint16_t sd_req_get_rca (SDState *s,SDRequest req)
@@ -1103,11 +1105,14 @@ static sd_rsp_type_t sd_cmd_ALL_SEND_CID(SDState *sd, SDRequest req)/* CMD3 */ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR (SDState *sd,SDRequest req) { +uint16_t random_rca; +switch (sd->state) {case sd_identification_state:case sd_standby_state: sd->state = sd_standby_state; -sd_set_rca (sd); +qemu_guest_getrandom_nofail (&random_rca,sizeof (random_rca)); +sd_set_rca (sd, random_rca);return sd_r6;default :
hw/sd/trace-events +1 -0
@@ -43,6 +43,7 @@ sdcard_response(const char *rspdesc, int rsplen) "%s (sz:%d)" sdcard_powerup(void) "" sdcard_inquiry_cmd41(void) "" sdcard_reset(void) "" +sdcard_set_rca(uint16_t value) "new RCA: 0x%04x" sdcard_set_blocklen(uint16_t length) "block len 0x%03x" sdcard_set_block_count(uint32_t cnt) "block cnt 0x%"PRIx32 sdcard_inserted(bool readonly) "read_only: %u"
Signature · 1 line
2.41.0
Quoted 5 lines · Philippe Mathieu-Daudé
Philippe Mathieu-Daudé (4):
hw/sd/npcm7xx_sdhci: UseTYPE_SYSBUS_SDHCIdefinition hw/sd/sdhci: Log non-sequencial access asGUEST_ERRORtests/qtest/npcm7xx_sdhci: Access the card using its published address hw/sd/sdcard: Generate random RCA value
Series queued, thanks.