hw/sd/sdcard: Add eMMC support
v42 cover hw/sd/sdcard: Add eMMC support
Cédric asked for one big series to review instead of various tiny ones...
I plan to send a pull request before v9.1 soft freeze with at least patches 1-81 (prerequisistes before the "Basis for eMMC support" patch) except qtest patch #15.
Also available as:
https://gitlab.com/philmd/qemu/-/commits/emmc-testing/
Cédric Le Goater (5):
hw/sd/sdcard: Introduce definitions for EXT_CSD register hw/sd/sdcard: Add emmc_cmd_SET_RELATIVE_ADDR() handler hw/sd/sdcard: Fix SET_BLOCK_COUNT command argument on eMMC (CMD23) hw/sd/sdcard: Adapt sd_cmd_ALL_SEND_CID handler for eMMC (CMD2) hw/sd/sdcard: Adapt sd_cmd_APP_CMD handler for eMMC (CMD55)
Joel Stanley (3):
hw/sd/sdcard: Support boot area in emmc image
hw/sd/sdcard: Subtract bootarea size from blk
hw/sd/sdcard: Add boot config support
Luc Michel (1):
hw/sd/sdcard: Implement eMMC sleep state (CMD5)
Philippe Mathieu-Daudé (85):
hw/sd/sdcard: Deprecate support for spec v1.10 hw/sd/sdcard: Use spec v3.01 by default
hw/sd/sdcard: Track last command used to help logging hw/sd/sdcard: Trace block offset in READ/WRITE data accesses hw/sd/sdcard: Trace requested address computed by sd_req_get_address() hw/sd/sdcard: Do not store vendor data on block drive (CMD56) hw/sd/sdcard: Send WRITE_PROT bits MSB first (CMD30) hw/sd/sdcard: Send NUM_WR_BLOCKS bits MSB first (ACMD22) hw/sd/sdcard: Use READY_FOR_DATA definition instead of magic value hw/sd/sdcard: Assign SDCardStates enum values hw/sd/sdcard: Simplify sd_inactive_state handling hw/sd/sdcard: Restrict SWITCH_FUNCTION to sd_transfer_state (CMD6) hw/sd/sdcard: Add direct reference to SDProto in SDState hw/sd/sdcard: Extract sd_blk_len() helper
tests/qtest: Disable npcm7xx_sdhci tests using hardcoded RCA hw/sd/sdcard: Generate random RCA value
hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte hw/sd/sdcard: Convert SWITCH_FUNCTION to generic_read_byte (CMD6) hw/sd/sdcard: Convert SEND_CSD/SEND_CID to generic_read_byte (CMD9 &
10)
hw/sd/sdcard: Duplicate READ_SINGLE_BLOCK / READ_MULTIPLE_BLOCK cases
hw/sd/sdcard: Convert READ_SINGLE_BLOCK to generic_read_byte (CMD17)
hw/sd/sdcard: Convert SEND_TUNING_BLOCK to generic_read_byte (CMD19)
hw/sd/sdcard: Convert SEND_WRITE_PROT to generic_read_byte (CMD30)
hw/sd/sdcard: Convert GEN_CMD to generic_read_byte (CMD56)
hw/sd/sdcard: Convert SD_STATUS to generic_read_byte (ACMD13)
hw/sd/sdcard: Convert SEND_NUM_WR_BLOCKS to generic_read_byte (ACMD22)
hw/sd/sdcard: Convert SEND_SCR to generic_read_byte (ACMD51)
hw/sd/sdcard: Introduce sd_cmd_to_receivingdata /
sd_generic_write_byte
hw/sd/sdcard: Duplicate WRITE_SINGLE_BLOCK / WRITE_MULTIPLE_BLOCK
cases
hw/sd/sdcard: Convert WRITE_SINGLE_BLOCK to generic_write_byte (CMD24)
hw/sd/sdcard: Convert PROGRAM_CID to generic_write_byte (CMD26)
hw/sd/sdcard: Convert PROGRAM_CSD to generic_write_byte (CMD27)
hw/sd/sdcard: Convert LOCK_UNLOCK to generic_write_byte (CMD42)
hw/sd/sdcard: Convert GEN_CMD to generic_write_byte (CMD56)
hw/sd/sdcard: Move sd_[a]cmd_name() methods to sd.c
hw/sd/sdcard: Pass SDState as argument to sd_[a]cmd_name()
hw/sd/sdcard: Prepare SDProto to contain more fields
hw/sd/sdcard: Store command name in SDProto
hw/sd/sdcard: Store command type in SDProto
hw/sd/sdcard: Store command class in SDProto
hw/sd/sdcard: Remove SEND_DSR dead case (CMD4)
hw/sd/sdcard: Register generic optional handlers (CMD11 and CMD20)
hw/sd/sdcard: Register optional handlers from spec v6.00
hw/sd/sdcard: Register SDIO optional handlers
hw/sd/sdcard: Register Security Extension optional handlers
hw/sd/sdcard: Add sd_cmd_SWITCH_FUNCTION handler (CMD6)
hw/sd/sdcard: Add sd_cmd_DE/SELECT_CARD handler (CMD7)
hw/sd/sdcard: Add sd_cmd_SEND_IF_COND handler (CMD8)
hw/sd/sdcard: Add sd_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
hw/sd/sdcard: Add sd_cmd_STOP_TRANSMISSION handler (CMD12)
hw/sd/sdcard: Add sd_cmd_SEND_STATUS handler (CMD13)
hw/sd/sdcard: Add sd_cmd_GO_INACTIVE_STATE handler (CMD15)
hw/sd/sdcard: Add sd_cmd_SET_BLOCKLEN handler (CMD16)
hw/sd/sdcard: Add sd_cmd_READ_SINGLE_BLOCK handler (CMD17)
hw/sd/sdcard: Add sd_cmd_WRITE_SINGLE_BLOCK handler (CMD24)
hw/sd/sdcard: Add sd_cmd_PROGRAM_CSD handler (CMD27)
hw/sd/sdcard: Add sd_cmd_SET/CLR_WRITE_PROT handler (CMD28 & CMD29)
hw/sd/sdcard: Add sd_cmd_SEND_WRITE_PROT handler (CMD30)
hw/sd/sdcard: Add sd_cmd_ERASE_WR_BLK_START/END handlers (CMD32 &
CMD33) hw/sd/sdcard: Add sd_cmd_ERASE handler (CMD38) hw/sd/sdcard: Add sd_cmd_LOCK_UNLOCK handler (CMD42) hw/sd/sdcard: Add sd_cmd_APP_CMD handler (CMD55) hw/sd/sdcard: Add sd_cmd_GEN_CMD handler (CMD56) hw/sd/sdcard: Add spi_cmd_READ_OCR handler (CMD58) hw/sd/sdcard: Add spi_cmd_CRC_ON_OFF handler (CMD59) hw/sd/sdcard: Add sd_acmd_SET_BUS_WIDTH handler (ACMD6) hw/sd/sdcard: Add sd_acmd_SD_STATUS handler (ACMD13) hw/sd/sdcard: Add sd_acmd_SEND_NUM_WR_BLOCKS handler (ACMD22) hw/sd/sdcard: Add sd_acmd_SET_WR_BLK_ERASE_COUNT handler (ACMD23) hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41) hw/sd/sdcard: Add sd_acmd_SET_CLR_CARD_DETECT handler (ACMD42) hw/sd/sdcard: Add sd_acmd_SEND_SCR handler (ACMD51) hw/sd/sdcard: Remove sd_none enum from sd_cmd_type_t hw/sd/sdcard: Remove noise from sd_acmd_name() hw/sd/sdcard: Remove noise from sd_cmd_name() hw/sd/sdcard: Remove default case in read/write on DAT lines hw/sd/sdcard: Trace length of data read on DAT lines hw/sd/sdcard: Introduce set_csd/set_cid handlers hw/sd/sdcard: Cover more SDCardStates
hw/sd/sdcard: Basis for eMMC support
hw/sd/sdcard: Register generic command handlers hw/sd/sdcard: Register unimplemented command handlers hw/sd/sdcard: Add mmc_cmd_PROGRAM_CID handler (CMD26) hw/sd/sdcard: Add experimental 'x-aspeed-emmc-kludge' property
Sai Pavan Boddu (3):
hw/sd/sdcard: Add emmc_cmd_SEND_OP_COND handler (CMD1) hw/sd/sdcard: add emmc_cmd_SEND_TUNING_BLOCK handler (CMD21) hw/sd/sdcard: Add mmc SWITCH function support (CMD6)
Vincent Palatin (1):
hw/sd/sdcard: Add emmc_cmd_SEND_EXT_CSD handler (CMD8)
docs/about/deprecated.rst | 6 + hw/sd/sdmmc-internal.h | 118 +- include/hw/sd/sd.h | 10 +- hw/sd/sd.c | 1917 +++++++++++++++++++----------- hw/sd/sdmmc-internal.c | 72 -- tests/qtest/npcm7xx_sdhci-test.c | 7 + hw/sd/meson.build | 2 +- hw/sd/trace-events | 6 +- 8 files changed, 1362 insertions(+), 776 deletions(-) delete mode 100644 hw/sd/sdmmc-internal.c
Signature · 1 line
2.41.0
PATCH v42 1/98 hw/sd/sdcard: Deprecate support for spec v1.10
We use the v2.00 spec by default since commit 2f0939c234 ("sdcard: Add a 'spec_version' property, default to Spec v2.00"). Time to deprecate the v1.10 which doesn't bring much, and is not tested.
--- docs/about/deprecated.rst | 6 ++++++ 1 file changed, 6 insertions(+)
docs/about/deprecated.rst +6 -0
@@ -362,6 +362,12 @@ recommending to switch to their stable counterparts: - "Zve64f" should be replaced with "zve64f" - "Zve64d" should be replaced with "zve64d" +``-device sd-card,spec_version=1`` (since 9.1) +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +SD physical layer specification v2.00 supersedes the v1.10 one. +v2.00 is the default since QEMU 3.0.0. + Block device options ''''''''''''''''''''
Signature · 1 line
2.41.0
PATCH v42 2/98 hw/sd/sdcard: Use spec v3.01 by default
In reply to Philippe Mathieu-DaudéRecent SDHCI expect cards to support the v3.01 spec to negociate lower I/O voltage. Select it by default.
--- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sd.c +1 -1
@@ -2280,7 +2280,7 @@ static void sd_realize(DeviceState *dev, Error **errp)static Property sd_properties[] = {DEFINE_PROP_UINT8 ("spec_version" , SDState, - spec_version, SD_PHY_SPECv2_00_VERS), + spec_version, SD_PHY_SPECv3_01_VERS),DEFINE_PROP_DRIVE ("drive" , SDState, blk),/* We do not model the chip select pin, so allow the board to select * whether card should be in SSI or MMC/SD mode. It is also up to the
Signature · 1 line
2.41.0
Re: [PATCH v42 02/98] hw/sd/sdcard: Use spec v3.01 by default
Quoted 14 lines · Philippe Mathieu-Daudé
Recent SDHCI expect cards to support the v3.01 spec to negociate lower I/O voltage. Select it by default.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>--- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/sd/sd.c +0
-0
hw/sd/sd.c static void sd_realize(DeviceState *dev, Error **errp) · line 2283
Quoted 5 lines
hw/sd/sd.c +1
-1@@ -2280,7 +2280,7 @@ static void sd_realize(DeviceState *dev, Error **errp)static Property sd_properties[] = {DEFINE_PROP_UINT8 ("spec_version" , SDState, - spec_version, SD_PHY_SPECv2_00_VERS), + spec_version, SD_PHY_SPECv3_01_VERS),
Shouldn't such a change be tied to machine type versions ?
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v42 02/98] hw/sd/sdcard: Use spec v3.01 by default
Quoted 16 lines · Daniel P. Berrangé
Quoted 15 lines · Philippe Mathieu-Daudé
Recent SDHCI expect cards to support the v3.01 spec to negociate lower I/O voltage. Select it by default.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>--- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/sd/sd.c +0
-0@@ -2280,7 +2280,7 @@ static void sd_realize(DeviceState *dev, Error **errp)
Quoted 6 lines
hw/sd/sd.c static void sd_realize(DeviceState *dev, Error **errp) · line 2283
Quoted 4 lines
hw/sd/sd.c +1
-1static Property sd_properties[] = {DEFINE_PROP_UINT8 ("spec_version" , SDState, - spec_version, SD_PHY_SPECv2_00_VERS), + spec_version, SD_PHY_SPECv3_01_VERS),Shouldn't such a change be tied to machine type versions ?
I don't think so, SD cards are external to machines (like CDROM you can use any brand). IOW machines only provide a SD card reader, user can insert any card there.
SD specs are backward compatible. If host FW only knows about v2.00 commands (spec is from 2006 btw) a v3.01 card will works.
BTW latest spec is v9.10 from 2023. The more recent card I bought supports spec v6.00 from 2018.
Re: [PATCH v42 02/98] hw/sd/sdcard: Use spec v3.01 by default
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Daniel P. Berrangé
Quoted 9 lines · Philippe Mathieu-Daudé
Recent SDHCI expect cards to support the v3.01 spec to negociate lower I/O voltage. Select it by default.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>--- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 11 lines
hw/sd/sd.c static void sd_realize(DeviceState *dev, Error **errp) · line 2282
Quoted 9 lines
hw/sd/sd.c +1
-1@@ -2280,7 +2280,7 @@ static void sd_realize(DeviceState *dev, Error **errp)static Property sd_properties[] = {DEFINE_PROP_UINT8 ("spec_version" , SDState, - spec_version, SD_PHY_SPECv2_00_VERS), + spec_version, SD_PHY_SPECv3_01_VERS),Shouldn't such a change be tied to machine type versions ?
Quoted 3 lines
I don't think so, SD cards are external to machines (like CDROM you can use any brand). IOW machines only provide a SD card reader, user can insert any card there.
Consider we release this in QEMU 9.1.0, and the user starts a VM with the 8.0 machine type. The guest will see an SD card supporting v3.
Now live migrate that guest to a host with QEMU 9.0.0, still using the 8.0 machine type. The guest will expect the SD card to still be v3, but QEMU will internally be set to v2, and will return illegal cmd errors if the guest tries to run v3 only cmds. Versioned machine types exist to prevent this kind of problem.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v42 02/98] hw/sd/sdcard: Use spec v3.01 by default
Quoted 28 lines · Daniel P. Berrangé
Quoted 23 lines · Philippe Mathieu-Daudé
Quoted 10 lines · Daniel P. Berrangé
Quoted 9 lines · Philippe Mathieu-Daudé
Recent SDHCI expect cards to support the v3.01 spec to negociate lower I/O voltage. Select it by default.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>--- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 11 lines
hw/sd/sd.c static void sd_realize(DeviceState *dev, Error **errp) · line 2282
Quoted 9 lines
hw/sd/sd.c +1
-1@@ -2280,7 +2280,7 @@ static void sd_realize(DeviceState *dev, Error **errp)static Property sd_properties[] = {DEFINE_PROP_UINT8 ("spec_version" , SDState, - spec_version, SD_PHY_SPECv2_00_VERS), + spec_version, SD_PHY_SPECv3_01_VERS),Shouldn't such a change be tied to machine type versions ?
Quoted 3 lines
I don't think so, SD cards are external to machines (like CDROM you can use any brand). IOW machines only provide a SD card reader, user can insert any card there.
Quoted 8 lines
Consider we release this in QEMU 9.1.0, and the user starts a VM with the 8.0 machine type. The guest will see an SD card supporting v3.
Now live migrate that guest to a host with QEMU 9.0.0, still using the 8.0 machine type. The guest will expect the SD card to still be v3, but QEMU will internally be set to v2, and will return illegal cmd errors if the guest tries to run v3 only cmds. Versioned machine types exist to prevent this kind of problem.
I guess I get it. So (besides rewording the commit description) what is missing is:
-- >8 --
hw/core/machine.c +1 -1
@@ -37,7 +37,8 @@GlobalProperty hw_compat_9_0[] = { {"arm-cpu" ,"backcompat-cntfrq" ,"true" }, {"scsi-disk-base" ,"migrate-emulated-scsi-request" ,"false" }, {"vfio-pci" ,"skip-vsc-check" ,"false" }, + {"sd-card" ,"spec_version" ,"2" }, };const size_t hw_compat_9_0_len =G_N_ELEMENTS (hw_compat_9_0); ---
?
PATCH v42 3/98 hw/sd/sdcard: Track last command used to help logging
In reply to Philippe Mathieu-DaudéThe command is selected on the I/O lines, and further processing might be done on the DAT lines via the sd_read_byte() and sd_write_byte() handlers. Since these methods can't distinct between normal and APP commands, keep the name of the current command in the SDState and use it in the DAT handlers. This fixes a bug that all normal commands were displayed as APP commands.
--- hw/sd/sd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)
hw/sd/sd.c +8 -4
@@ -133,6 +133,7 @@ struct SDState {uint32_t pwd_len;uint8_t function_group[6 ];uint8_t current_cmd; +const char *last_cmd_name;/* True if we will handle the next command as an ACMD. Note that this does * *not* track the APP_CMD status bit! */
@@ -1154,12 +1155,13 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)uint16_t rca;uint64_t addr; + sd->last_cmd_name =sd_cmd_name (req.cmd);/* CMD55 precedes an ACMD, so we are not interested in tracing it. * However there is no ACMD55, so we want to trace this particular case. */ if (req.cmd !=55 || sd->expecting_acmd) {trace_sdcard_normal_command (sd_proto (sd)->name, -sd_cmd_name (req.cmd), req.cmd, + sd->last_cmd_name, req.cmd, req.arg,sd_state_name (sd->state)); }
@@ -1620,7 +1622,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)static sd_rsp_type_t sd_app_command (SDState *sd,SDRequest req) { -trace_sdcard_app_command (sd_proto (sd)->name,sd_acmd_name (req.cmd), + sd->last_cmd_name =sd_acmd_name (req.cmd); +trace_sdcard_app_command (sd_proto (sd)->name, sd->last_cmd_name, req.cmd, req.arg,sd_state_name (sd->state)); sd->card_status |=APP_CMD ;
@@ -1913,7 +1916,7 @@ void sd_write_byte(SDState *sd, uint8_t value)return ;trace_sdcard_write_data (sd_proto (sd)->name, -sd_acmd_name (sd->current_cmd), + sd->last_cmd_name, sd->current_cmd, value);switch (sd->current_cmd) {case 24 :/* CMD24: WRITE_SINGLE_BLOCK */
@@ -2069,7 +2072,7 @@ uint8_t sd_read_byte(SDState *sd) io_len = (sd->ocr & (1 <<30 )) ?512 : sd->blk_len;trace_sdcard_read_data (sd_proto (sd)->name, -sd_acmd_name (sd->current_cmd), + sd->last_cmd_name, sd->current_cmd, io_len);switch (sd->current_cmd) {case 6 :/* CMD6: SWITCH_FUNCTION */
@@ -2214,6 +2217,7 @@ static void sd_instance_init(Object *obj) {SDState *sd =SD_CARD (obj); + sd->last_cmd_name ="UNSET" ; sd->enable = true; sd->ocr_power_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , sd_ocr_powerup, sd); }
Signature · 1 line
2.41.0
Re: [PATCH v42 03/98] hw/sd/sdcard: Track last command used to help logging
Quoted 9 lines · Philippe Mathieu-Daudé
The command is selected on the I/O lines, and further processing might be done on the DAT lines via the
sd_read_byte()andsd_write_byte()handlers. Since these methods can't distinct between normal and APP commands, keep the name of the current command in the SDState and use it in the DAT handlers. This fixes a bug that all normal commands were displayed as APP commands.
Quoted 3 lines
Fixes 2ed61fb57b ("sdcard: Display command name when tracing CMD/ACMD")Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>
Thanks,
C.
Quoted 67 lines
--- hw/sd/sd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-)hw/sd/sd.c +8
-4@@ -133,6 +133,7 @@ struct SDState {uint32_t pwd_len;uint8_t function_group[6 ];uint8_t current_cmd; +const char *last_cmd_name;/* True if we will handle the next command as an ACMD. Note that this does * *not* track the APP_CMD status bit! */ @@ -1154,12 +1155,13 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)uint16_t rca;uint64_t addr; + sd->last_cmd_name =sd_cmd_name (req.cmd);/* CMD55 precedes an ACMD, so we are not interested in tracing it. * However there is no ACMD55, so we want to trace this particular case. */ if (req.cmd !=55 || sd->expecting_acmd) {trace_sdcard_normal_command (sd_proto (sd)->name, -sd_cmd_name (req.cmd), req.cmd, + sd->last_cmd_name, req.cmd, req.arg,sd_state_name (sd->state)); }@@ -1620,7 +1622,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)static sd_rsp_type_t sd_app_command (SDState *sd,SDRequest req) { -trace_sdcard_app_command (sd_proto (sd)->name,sd_acmd_name (req.cmd), + sd->last_cmd_name =sd_acmd_name (req.cmd); +trace_sdcard_app_command (sd_proto (sd)->name, sd->last_cmd_name, req.cmd, req.arg,sd_state_name (sd->state)); sd->card_status |=APP_CMD ;@@ -1913,7 +1916,7 @@ void sd_write_byte(SDState *sd, uint8_t value)return ;trace_sdcard_write_data (sd_proto (sd)->name, -sd_acmd_name (sd->current_cmd), + sd->last_cmd_name, sd->current_cmd, value);switch (sd->current_cmd) {case 24 :/* CMD24: WRITE_SINGLE_BLOCK */ @@ -2069,7 +2072,7 @@ uint8_t sd_read_byte(SDState *sd) io_len = (sd->ocr & (1 <<30 )) ?512 : sd->blk_len;trace_sdcard_read_data (sd_proto (sd)->name, -sd_acmd_name (sd->current_cmd), + sd->last_cmd_name, sd->current_cmd, io_len);switch (sd->current_cmd) {case 6 :/* CMD6: SWITCH_FUNCTION */ @@ -2214,6 +2217,7 @@ static void sd_instance_init(Object *obj) {SDState *sd =SD_CARD (obj); + sd->last_cmd_name ="UNSET" ; sd->enable = true; sd->ocr_power_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , sd_ocr_powerup, sd); }
PATCH v42 4/98 hw/sd/sdcard: Trace block offset in READ/WRITE data accesses
In reply to Philippe Mathieu-DaudéUseful to detect out of bound accesses.
--- hw/sd/sd.c | 4 ++-- hw/sd/trace-events | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
hw/sd/sd.c +2 -2
@@ -1917,7 +1917,7 @@ void sd_write_byte(SDState *sd, uint8_t value)trace_sdcard_write_data (sd_proto (sd)->name, sd->last_cmd_name, - sd->current_cmd, value); + sd->current_cmd, sd->data_offset, value);switch (sd->current_cmd) {case 24 :/* CMD24: WRITE_SINGLE_BLOCK */ sd->data[sd->data_offset ++] = value;
@@ -2073,7 +2073,7 @@ uint8_t sd_read_byte(SDState *sd)trace_sdcard_read_data (sd_proto (sd)->name, sd->last_cmd_name, - sd->current_cmd, io_len); + sd->current_cmd, sd->data_offset, io_len);switch (sd->current_cmd) {case 6 :/* CMD6: SWITCH_FUNCTION */ ret = sd->data[sd->data_offset ++];
hw/sd/trace-events +2 -2
@@ -52,8 +52,8 @@ sdcard_lock(void) "" sdcard_unlock(void) "" sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" -sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint8_t value) "%s %20s/ CMD%02d value 0x%02x" -sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t length) "%s %20s/ CMD%02d len %" PRIu32 +sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint8_t value) "%s %20s/ CMD%02d ofs %"PRIu32" value 0x%02x" +sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint32_t length) "%s %20s/ CMD%02d ofs %"PRIu32" len %" PRIu32 sdcard_set_voltage(uint16_t millivolts) "%u mV" # pxa2xx_mmci.c
Signature · 1 line
2.41.0
Re: [PATCH v42 04/98] hw/sd/sdcard: Trace block offset in READ/WRITE data accesses
Quoted 4 lines · Philippe Mathieu-Daudé
Useful to detect out of bound accesses.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>
Thanks,
C.
Quoted 42 lines
--- hw/sd/sd.c | 4 ++-- hw/sd/trace-events | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)hw/sd/sd.c +2
-2@@ -1917,7 +1917,7 @@ void sd_write_byte(SDState *sd, uint8_t value)trace_sdcard_write_data (sd_proto (sd)->name, sd->last_cmd_name, - sd->current_cmd, value); + sd->current_cmd, sd->data_offset, value);switch (sd->current_cmd) {case 24 :/* CMD24: WRITE_SINGLE_BLOCK */ sd->data[sd->data_offset ++] = value;@@ -2073,7 +2073,7 @@ uint8_t sd_read_byte(SDState *sd)trace_sdcard_read_data (sd_proto (sd)->name, sd->last_cmd_name, - sd->current_cmd, io_len); + sd->current_cmd, sd->data_offset, io_len);switch (sd->current_cmd) {case 6 :/* CMD6: SWITCH_FUNCTION */ ret = sd->data[sd->data_offset ++];hw/sd/trace-events +2
-2@@ -52,8 +52,8 @@ sdcard_lock(void) "" sdcard_unlock(void) "" sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" -sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint8_t value) "%s %20s/ CMD%02d value 0x%02x" -sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t length) "%s %20s/ CMD%02d len %" PRIu32 +sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint8_t value) "%s %20s/ CMD%02d ofs %"PRIu32" value 0x%02x" +sdcard_read_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint32_t length) "%s %20s/ CMD%02d ofs %"PRIu32" len %" PRIu32 sdcard_set_voltage(uint16_t millivolts) "%u mV" # pxa2xx_mmci.c
PATCH v42 5/98 hw/sd/sdcard: Trace requested address computed by sd_req_get_address()
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 9 +++++++-- hw/sd/trace-events | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)
hw/sd/sd.c +7 -2
@@ -608,10 +608,15 @@ static void sd_response_r7_make(SDState *sd, uint8_t *response)static uint64_t sd_req_get_address (SDState *sd,SDRequest req) { +uint64_t addr; +if (FIELD_EX32 (sd->ocr,OCR ,CARD_CAPACITY )) { -return (uint64_t ) req.arg <<HWBLOCK_SHIFT ; + addr = (uint64_t ) req.arg <<HWBLOCK_SHIFT ; + }else { + addr = req.arg; } -return req.arg; +trace_sdcard_req_addr (req.arg, addr); +return addr; }static inline uint64_t sd_addr_to_wpnum (uint64_t addr)
hw/sd/trace-events +1 -0
@@ -50,6 +50,7 @@ sdcard_ejected(void) "" sdcard_erase(uint32_t first, uint32_t last) "addr first 0x%" PRIx32" last 0x%" PRIx32 sdcard_lock(void) "" sdcard_unlock(void) "" +sdcard_req_addr(uint32_t req_arg, uint64_t addr) "req 0x%" PRIx32 " addr 0x%" PRIx64 sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint8_t value) "%s %20s/ CMD%02d ofs %"PRIu32" value 0x%02x"
Signature · 1 line
2.41.0
Re: [PATCH v42 05/98] hw/sd/sdcard: Trace requested address computed by sd_req_get_address()
Quoted 4 lines · Philippe Mathieu-Daudé
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Quoted 43 lines
--- hw/sd/sd.c | 9 +++++++-- hw/sd/trace-events | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)hw/sd/sd.c +7
-2@@ -608,10 +608,15 @@ static void sd_response_r7_make(SDState *sd, uint8_t *response)static uint64_t sd_req_get_address (SDState *sd,SDRequest req) { +uint64_t addr; +if (FIELD_EX32 (sd->ocr,OCR ,CARD_CAPACITY )) { -return (uint64_t ) req.arg <<HWBLOCK_SHIFT ; + addr = (uint64_t ) req.arg <<HWBLOCK_SHIFT ; + }else { + addr = req.arg; } -return req.arg; +trace_sdcard_req_addr (req.arg, addr); +return addr; }static inline uint64_t sd_addr_to_wpnum (uint64_t addr)hw/sd/trace-events +1
-1@@ -50,6 +50,7 @@ sdcard_ejected(void) "" sdcard_erase(uint32_t first, uint32_t last) "addr first 0x%" PRIx32" last 0x%" PRIx32 sdcard_lock(void) "" sdcard_unlock(void) "" +sdcard_req_addr(uint32_t req_arg, uint64_t addr) "req 0x%" PRIx32 " addr 0x%" PRIx64 sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint8_t value) "%s %20s/ CMD%02d ofs %"PRIu32" value 0x%02x" --2.41.0
Re: [PATCH v42 05/98] hw/sd/sdcard: Trace requested address computed by sd_req_get_address()
In reply to Philippe Mathieu-DaudéQuoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 39 lines
--- hw/sd/sd.c | 9 +++++++-- hw/sd/trace-events | 1 + 2 files changed, 8 insertions(+), 2 deletions(-)hw/sd/sd.c +7
-2@@ -608,10 +608,15 @@ static void sd_response_r7_make(SDState *sd, uint8_t *response)static uint64_t sd_req_get_address (SDState *sd,SDRequest req) { +uint64_t addr; +if (FIELD_EX32 (sd->ocr,OCR ,CARD_CAPACITY )) { -return (uint64_t ) req.arg <<HWBLOCK_SHIFT ; + addr = (uint64_t ) req.arg <<HWBLOCK_SHIFT ; + }else { + addr = req.arg; } -return req.arg; +trace_sdcard_req_addr (req.arg, addr); +return addr; }static inline uint64_t sd_addr_to_wpnum (uint64_t addr)hw/sd/trace-events +1
-0@@ -50,6 +50,7 @@ sdcard_ejected(void) "" sdcard_erase(uint32_t first, uint32_t last) "addr first 0x%" PRIx32" last 0x%" PRIx32 sdcard_lock(void) "" sdcard_unlock(void) "" +sdcard_req_addr(uint32_t req_arg, uint64_t addr) "req 0x%" PRIx32 " addr 0x%" PRIx64 sdcard_read_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_block(uint64_t addr, uint32_t len) "addr 0x%" PRIx64 " size 0x%x" sdcard_write_data(const char *proto, const char *cmd_desc, uint8_t cmd, uint32_t offset, uint8_t value) "%s %20s/ CMD%02d ofs %"PRIu32" value 0x%02x"
PATCH v42 6/98 hw/sd/sdcard: Do not store vendor data on block drive (CMD56)
In reply to Philippe Mathieu-Daudé"General command" (GEN_CMD, CMD56) is described as:
GEN_CMD is the same as the single block read or write commands (CMD24 or CMD17). The difference is that [...] the data block is not a memory payload data but has a vendor specific format and meaning.
Thus this block must not be stored overwriting data block on underlying storage drive. Keep it in a dedicated 'vendor_data[]' array.
---
RFC: Is it safe to reuse VMSTATE_UNUSED_V() (which happens to be the same size)?
--- hw/sd/sd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
hw/sd/sd.c +9 -8
@@ -142,6 +142,8 @@ struct SDState {uint64_t data_start;uint32_t data_offset;uint8_t data[512 ]; +uint8_t vendor_data[512 ]; +qemu_irq readonly_cb;qemu_irq inserted_cb;QEMUTimer *ocr_power_timer;
@@ -656,6 +658,7 @@ static void sd_reset(DeviceState *dev) sd->wp_switch = sd->blk ? !blk_is_writable (sd->blk) : false; sd->wp_group_bits = sect; sd->wp_group_bmap =bitmap_new (sd->wp_group_bits); +memset (sd->vendor_data,0xec ,sizeof (sd->vendor_data));memset (sd->function_group,0 ,sizeof (sd->function_group)); sd->erase_start =INVALID_ADDRESS ; sd->erase_end =INVALID_ADDRESS ;
@@ -771,7 +774,7 @@ static const VMStateDescription sd_vmstate = {VMSTATE_UINT64 (data_start, SDState),VMSTATE_UINT32 (data_offset, SDState),VMSTATE_UINT8_ARRAY (data, SDState,512 ), -VMSTATE_UNUSED_V (1 ,512 ), +VMSTATE_UINT8_ARRAY (vendor_data, SDState,512 ),VMSTATE_BOOL (enable, SDState),VMSTATE_END_OF_LIST () },
@@ -2029,9 +2032,8 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;case 56 :/* CMD56: GEN_CMD */ - sd->data[sd->data_offset ++] = value; -if (sd->data_offset >= sd->blk_len) { -APP_WRITE_BLOCK (sd->data_start, sd->data_offset); + sd->vendor_data[sd->data_offset ++] = value; +if (sd->data_offset >=sizeof (sd->vendor_data)) { sd->state = sd_transfer_state; }break ;
@@ -2165,12 +2167,11 @@ uint8_t sd_read_byte(SDState *sd)break ;case 56 :/* CMD56: GEN_CMD */ -if (sd->data_offset ==0 ) -APP_READ_BLOCK (sd->data_start, sd->blk_len); - ret = sd->data[sd->data_offset ++]; + ret = sd->vendor_data[sd->data_offset ++]; -if (sd->data_offset >= sd->blk_len) +if (sd->data_offset >=sizeof (sd->vendor_data)) { sd->state = sd_transfer_state; + }break ;default :
Signature · 1 line
2.41.0
Re: [PATCH v42 06/98] hw/sd/sdcard: Do not store vendor data on block drive (CMD56)
Quoted 14 lines · Philippe Mathieu-Daudé
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
"General command" (
GEN_CMD, CMD56) is described as:
GEN_CMDis the same as the single block read or write commands (CMD24 or CMD17). The difference is that [...] the data block is not a memory payload data but has a vendor specific format and meaning.Thus this block must not be stored overwriting data block on underlying storage drive. Keep it in a dedicated 'vendor_data[]' array.
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>---
RFC: Is it safe to reuseVMSTATE_UNUSED_V()(which happens to be the same size)?Cc Peter Xu <[email protected]>Cc Fabiano Rosas <[email protected]>
I'm not sure about this migration question.
But IMHO you can simplify your implementation to avoid having to store and migrate this vendor_data array. After some research on this command, I came to the conclusion that it's used by manufacturers to return device health related vendor-specific data. (E.g.,
https://images-na.ssl-images-amazon.com/images/I/91tTtUMDM3L.pdf Section 1.6.1). So I guess you can simply discard writes and return 0s on reads (or "QEMU" in ASCII or... :)).
Quoted 66 lines
--- hw/sd/sd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)hw/sd/sd.c +9
-9@@ -142,6 +142,8 @@ struct SDState {uint64_t data_start;uint32_t data_offset;uint8_t data[512 ]; +uint8_t vendor_data[512 ]; +qemu_irq readonly_cb;qemu_irq inserted_cb;QEMUTimer *ocr_power_timer;@@ -656,6 +658,7 @@ static void sd_reset(DeviceState *dev) sd->wp_switch = sd->blk ? !blk_is_writable (sd->blk) : false; sd->wp_group_bits = sect; sd->wp_group_bmap =bitmap_new (sd->wp_group_bits); +memset (sd->vendor_data,0xec ,sizeof (sd->vendor_data));memset (sd->function_group,0 ,sizeof (sd->function_group)); sd->erase_start =INVALID_ADDRESS ; sd->erase_end =INVALID_ADDRESS ;@@ -771,7 +774,7 @@ static const VMStateDescription sd_vmstate = {VMSTATE_UINT64 (data_start, SDState),VMSTATE_UINT32 (data_offset, SDState),VMSTATE_UINT8_ARRAY (data, SDState,512 ), -VMSTATE_UNUSED_V (1 ,512 ), +VMSTATE_UINT8_ARRAY (vendor_data, SDState,512 ),VMSTATE_BOOL (enable, SDState),VMSTATE_END_OF_LIST () },@@ -2029,9 +2032,8 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;case 56 :/* CMD56: GEN_CMD */ - sd->data[sd->data_offset ++] = value; -if (sd->data_offset >= sd->blk_len) { -APP_WRITE_BLOCK (sd->data_start, sd->data_offset); + sd->vendor_data[sd->data_offset ++] = value; +if (sd->data_offset >=sizeof (sd->vendor_data)) { sd->state = sd_transfer_state; }break ;@@ -2165,12 +2167,11 @@ uint8_t sd_read_byte(SDState *sd)break ;case 56 :/* CMD56: GEN_CMD */ -if (sd->data_offset ==0 ) -APP_READ_BLOCK (sd->data_start, sd->blk_len); - ret = sd->data[sd->data_offset ++]; + ret = sd->vendor_data[sd->data_offset ++]; -if (sd->data_offset >= sd->blk_len) +if (sd->data_offset >=sizeof (sd->vendor_data)) { sd->state = sd_transfer_state; + }break ;default : --2.41.0
Re: [PATCH v42 06/98] hw/sd/sdcard: Do not store vendor data on block drive (CMD56)
Quoted 26 lines · Luc Michel
Quoted 14 lines · Philippe Mathieu-Daudé
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
"General command" (
GEN_CMD, CMD56) is described as:
GEN_CMDis the same as the single block read or write commands (CMD24 or CMD17). The difference is that [...] the data block is not a memory payload data but has a vendor specific format and meaning.Thus this block must not be stored overwriting data block on underlying storage drive. Keep it in a dedicated 'vendor_data[]' array.
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>---
RFC: Is it safe to reuseVMSTATE_UNUSED_V()(which happens to be the same size)?Cc Peter Xu <[email protected]>Cc Fabiano Rosas <[email protected]>I'm not sure about this migration question.
Quoted 7 lines
But IMHO you can simplify your implementation to avoid having to store and migrate this
vendor_dataarray. After some research on this command, I came to the conclusion that it's used by manufacturers to return device health related vendor-specific data. (E.g.,
https://images-na.ssl-images-amazon.com/images/I/91tTtUMDM3L.pdf Section 1.6.1). So I guess you can simply discard writes and return 0s on reads (or "QEMU" in ASCII or... :)).
Thanks, very interesting datasheet! Note the argument filter:
To query the Health Status register, CMD56 with
argument of [00 00 00 01] is used.
Since we can program this array, I'll simply add it as R/W (KISS).
Quoted 4 lines
Quoted 4 lines
--- hw/sd/sd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
Re: [PATCH v42 06/98] hw/sd/sdcard: Do not store vendor data on block drive (CMD56)
Quoted 35 lines · Philippe Mathieu-Daudé
Quoted 26 lines · Luc Michel
Quoted 14 lines · Philippe Mathieu-Daudé
Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.
"General command" (
GEN_CMD, CMD56) is described as:
GEN_CMDis the same as the single block read or write commands (CMD24 or CMD17). The difference is that [...] the data block is not a memory payload data but has a vendor specific format and meaning.Thus this block must not be stored overwriting data block on underlying storage drive. Keep it in a dedicated 'vendor_data[]' array.
Quoted 8 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>---
RFC: Is it safe to reuseVMSTATE_UNUSED_V()(which happens to be the same size)?Cc Peter Xu <[email protected]>Cc Fabiano Rosas <[email protected]>I'm not sure about this migration question.
Quoted 7 lines
But IMHO you can simplify your implementation to avoid having to store and migrate this
vendor_dataarray. After some research on this command, I came to the conclusion that it's used by manufacturers to return device health related vendor-specific data. (E.g.,
https://images-na.ssl-images-amazon.com/images/I/91tTtUMDM3L.pdf Section 1.6.1). So I guess you can simply discard writes and return 0s on reads (or "QEMU" in ASCII or... :)).
Quoted 6 lines
Thanks, very interesting datasheet! Note the argument filter:
To query the Health Status register, CMD56 with argument of [00 00 00 01] is used.
Since we can program this array, I'll simply add it as R/W (KISS).
(What really matters here is that we don't overwrite the generic
data[] array used to access the blocks)
Re: [PATCH v42 06/98] hw/sd/sdcard: Do not store vendor data on block drive (CMD56)
In reply to Philippe Mathieu-DaudéQuoted 11 lines · Philippe Mathieu-Daudé
"General command" (
GEN_CMD, CMD56) is described as:
GEN_CMDis the same as the single block read or write commands (CMD24 or CMD17). The difference is that [...] the data block is not a memory payload data but has a vendor specific format and meaning.Thus this block must not be stored overwriting data block on underlying storage drive. Keep it in a dedicated 'vendor_data[]' array.
Quoted 5 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>---
RFC: Is it safe to reuseVMSTATE_UNUSED_V()(which happens to be the same size)?
This field became unused with:
commit 12c125cba9c548929ccf4da2515e5b795c94afd9
Author: Eric Blake <[email protected]> Date: Fri May 6 10:26:39 2016 -0600
sd: Switch to byte-based block access
which was in 2.6.1 / 2.7.0
Thus if someone is using a machine type that is 2.6 or older, I don't think it is safe to unconditionally reuse that field.
My pending series deprecates everything upto 2.12, but we won't remove those machine types until 2 further release are past.
You could gamble that SD card usage is niche enough that its highly unlikely someone will be using SD card at the same time as these ancient machine types.
The safe thing would be a new field.
Quoted 5 lines
Cc Peter Xu <[email protected]>Cc Fabiano Rosas <[email protected]>--- hw/sd/sd.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v42 7/98 hw/sd/sdcard: Send WRITE_PROT bits MSB first (CMD30)
In reply to Philippe Mathieu-DaudéPer sections 3.6.1 (SD Bus Protocol) and 7.3.2 (Responses):
In the CMD line the Most Significant Bit is transmitted first.
Use the stl_be_p() helper to store the value in big-endian.
---
RFC because I'm surprised this has been unnoticed for 17 years (commit a1bb27b1e9 "initial SD card emulation", April 2007).
--- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sd.c +1 -1
@@ -1507,7 +1507,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) } sd->state = sd_sendingdata_state; - *(uint32_t *) sd->data =sd_wpbits (sd, req.arg); +stl_be_p (sd->data,sd_wpbits (sd, req.arg)); sd->data_start = addr; sd->data_offset =0 ;return sd_r1;
Signature · 1 line
2.41.0
Re: [PATCH v42 07/98] hw/sd/sdcard: Send WRITE_PROT bits MSB first (CMD30)
Quoted 9 lines · Philippe Mathieu-Daudé
Per sections 3.6.1 (SD Bus Protocol) and 7.3.2 (Responses):
In the CMD line the Most Significant Bit is transmitted first.
Use the
stl_be_p()helper to store the value in big-endian.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>
Quoted 8 lines
---
RFC because I'm surprised this has been unnoticed for 17 years (commita1bb27b1e9"initial SD card emulation", April 2007).Cc Peter Maydell <[email protected]>--- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
It looks like Linux never uses this command at all, which is probably why we haven't noticed the issue.
thanks
-- PMM
PATCH v42 8/98 hw/sd/sdcard: Send NUM_WR_BLOCKS bits MSB first (ACMD22)
In reply to Philippe Mathieu-DaudéPer sections 3.6.1 (SD Bus Protocol), 4.3.4 "Data Write" and 7.3.2 (Responses):
In the CMD line the Most Significant Bit is transmitted first.
Use the stl_be_p() helper to store the value in big-endian.
---
RFC because I'm surprised this has been unnoticed for 17 years (commit a1bb27b1e9 "initial SD card emulation", April 2007).
--- hw/sd/sd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
hw/sd/sd.c +1 -2
@@ -1668,8 +1668,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd,case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ switch (sd->state) {case sd_transfer_state: - *(uint32_t *) sd->data = sd->blk_written; - +stl_be_p (sd->data, sd->blk_written); sd->state = sd_sendingdata_state; sd->data_start =0 ; sd->data_offset =0 ;
Signature · 1 line
2.41.0
Re: [PATCH v42 08/98] hw/sd/sdcard: Send NUM_WR_BLOCKS bits MSB first (ACMD22)
Quoted 10 lines · Philippe Mathieu-Daudé
Per sections 3.6.1 (SD Bus Protocol), 4.3.4 "Data Write" and 7.3.2 (Responses):
In the CMD line the Most Significant Bit is transmitted first.
Use the
stl_be_p()helper to store the value in big-endian.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>
Quoted 8 lines
---
RFC because I'm surprised this has been unnoticed for 17 years (commita1bb27b1e9"initial SD card emulation", April 2007).Cc Peter Maydell <[email protected]>--- hw/sd/sd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
I think Linux only uses this command in an error-recovery code path (which we should never get into since our emulated SD card has 100% reliability ;-)), which is probably why we haven't noticed this before.
thanks
-- PMM
PATCH v42 9/98 hw/sd/sdcard: Use READY_FOR_DATA definition instead of magic value
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
hw/sd/sd.c +1 -1
@@ -561,7 +561,7 @@ FIELD(CSR, OUT_OF_RANGE, 31, 1)static void sd_set_cardstatus (SDState *sd) { - sd->card_status =0x00000100 ; + sd->card_status =READY_FOR_DATA ; }static void sd_set_sdstatus (SDState *sd)
Signature · 1 line
2.41.0
Re: [PATCH v42 09/98] hw/sd/sdcard: Use READY_FOR_DATA definition instead of magic value
Quoted 2 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>
Thanks,
C.
Quoted 17 lines
--- hw/sd/sd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)hw/sd/sd.c +1
-1@@ -561,7 +561,7 @@ FIELD(CSR, OUT_OF_RANGE, 31, 1)static void sd_set_cardstatus (SDState *sd) { - sd->card_status =0x00000100 ; + sd->card_status =READY_FOR_DATA ; }static void sd_set_sdstatus (SDState *sd)
PATCH v42 10/98 hw/sd/sdcard: Assign SDCardStates enum values
In reply to Philippe Mathieu-DaudéSDCardStates enum values are specified, so assign them correspondingly. It will be useful later when we add states from later specs, which might not be continuous.
See CURRENT_STATE bits in section 4.10.1 "Card Status".
--- hw/sd/sd.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
hw/sd/sd.c +10 -10
@@ -75,16 +75,16 @@ enum SDCardModes { };enum SDCardStates { - sd_inactive_state =-1 , - sd_idle_state =0 , - sd_ready_state, - sd_identification_state, - sd_standby_state, - sd_transfer_state, - sd_sendingdata_state, - sd_receivingdata_state, - sd_programming_state, - sd_disconnect_state, + sd_inactive_state =-1 , + sd_idle_state =0 , + sd_ready_state =1 , + sd_identification_state =2 , + sd_standby_state =3 , + sd_transfer_state =4 , + sd_sendingdata_state =5 , + sd_receivingdata_state =6 , + sd_programming_state =7 , + sd_disconnect_state =8 , };typedef sd_rsp_type_t (*sd_cmd_handler )(SDState *sd,SDRequest req);
Signature · 1 line
2.41.0
Re: [PATCH v42 10/98] hw/sd/sdcard: Assign SDCardStates enum values
Quoted 8 lines · Philippe Mathieu-Daudé
SDCardStates enum values are specified, so assign them correspondingly. It will be useful later when we add states from later specs, which might not be continuous.
See
CURRENT_STATEbits in section 4.10.1 "Card Status".Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>
Thanks,
C.
Quoted 35 lines
--- hw/sd/sd.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)hw/sd/sd.c +10
-10@@ -75,16 +75,16 @@ enum SDCardModes { };enum SDCardStates { - sd_inactive_state =-1 , - sd_idle_state =0 , - sd_ready_state, - sd_identification_state, - sd_standby_state, - sd_transfer_state, - sd_sendingdata_state, - sd_receivingdata_state, - sd_programming_state, - sd_disconnect_state, + sd_inactive_state =-1 , + sd_idle_state =0 , + sd_ready_state =1 , + sd_identification_state =2 , + sd_standby_state =3 , + sd_transfer_state =4 , + sd_sendingdata_state =5 , + sd_receivingdata_state =6 , + sd_programming_state =7 , + sd_disconnect_state =8 , };typedef sd_rsp_type_t (*sd_cmd_handler )(SDState *sd,SDRequest req);
PATCH v42 11/98 hw/sd/sdcard: Simplify sd_inactive_state handling
In reply to Philippe Mathieu-DaudéCard entering sd_inactive_state powers off, and won't respond anymore. Handle that once when entering sd_do_command().
Remove condition always true in sd_cmd_GO_IDLE_STATE().
--- hw/sd/sd.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
hw/sd/sd.c +7 -5
@@ -1081,10 +1081,8 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req)/* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE (SDState *sd,SDRequest req) { -if (sd->state != sd_inactive_state) { - sd->state = sd_idle_state; -sd_reset (DEVICE (sd)); - } + sd->state = sd_idle_state; +sd_reset (DEVICE (sd));return sd_is_spi (sd) ? sd_r1 : sd_r0; }
@@ -1579,7 +1577,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (sd->state) {case sd_ready_state:case sd_identification_state: -case sd_inactive_state:return sd_illegal;case sd_idle_state:if (rca) {
@@ -1800,6 +1797,11 @@ int sd_do_command(SDState *sd, SDRequest *req,return 0 ; } +if (sd->state == sd_inactive_state) { + rtype = sd_illegal; + goto send_response; + } +if (sd_req_crc_validate (req)) { sd->card_status |=COM_CRC_ERROR ; rtype = sd_illegal;
Signature · 1 line
2.41.0
Re: [PATCH v42 11/98] hw/sd/sdcard: Simplify sd_inactive_state handling
Quoted 7 lines · Philippe Mathieu-Daudé
Card entering
sd_inactive_statepowers off, and won't respond anymore. Handle that once when enteringsd_do_command().Remove condition always true in
sd_cmd_GO_IDLE_STATE().Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>
Thanks,
C.
Quoted 41 lines
--- hw/sd/sd.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)hw/sd/sd.c +7
-5@@ -1081,10 +1081,8 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req)/* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE (SDState *sd,SDRequest req) { -if (sd->state != sd_inactive_state) { - sd->state = sd_idle_state; -sd_reset (DEVICE (sd)); - } + sd->state = sd_idle_state; +sd_reset (DEVICE (sd));return sd_is_spi (sd) ? sd_r1 : sd_r0; }@@ -1579,7 +1577,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (sd->state) {case sd_ready_state:case sd_identification_state: -case sd_inactive_state:return sd_illegal;case sd_idle_state:if (rca) {@@ -1800,6 +1797,11 @@ int sd_do_command(SDState *sd, SDRequest *req,return 0 ; } +if (sd->state == sd_inactive_state) { + rtype = sd_illegal; + goto send_response; + } +if (sd_req_crc_validate (req)) { sd->card_status |=COM_CRC_ERROR ; rtype = sd_illegal;
PATCH v42 12/98 hw/sd/sdcard: Restrict SWITCH_FUNCTION to sd_transfer_state (CMD6)
In reply to Philippe Mathieu-DaudéSWITCH_FUNCTION is only allowed in TRANSFER state
(See 4.8 "Card State Transition Table).
--- hw/sd/sd.c | 4 ++++ 1 file changed, 4 insertions(+)
hw/sd/sd.c +4 -0
@@ -1205,6 +1205,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)if (sd->mode != sd_data_transfer_mode) {return sd_invalid_mode_for_cmd (sd, req); } +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } +sd_function_switch (sd, req.arg); sd->state = sd_sendingdata_state; sd->data_start =0 ;
Signature · 1 line
2.41.0
Re: [PATCH v42 12/98] hw/sd/sdcard: Restrict SWITCH_FUNCTION to sd_transfer_state (CMD6)
Quoted 5 lines · Philippe Mathieu-Daudé
SWITCH_FUNCTIONis only allowed in TRANSFER state
(See 4.8 "Card State Transition Table).Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>
Thanks,
C.
Quoted 19 lines
--- hw/sd/sd.c | 4 ++++ 1 file changed, 4 insertions(+)hw/sd/sd.c +4
-0@@ -1205,6 +1205,10 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)if (sd->mode != sd_data_transfer_mode) {return sd_invalid_mode_for_cmd (sd, req); } +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } +sd_function_switch (sd, req.arg); sd->state = sd_sendingdata_state; sd->data_start =0 ;
PATCH v42 13/98 hw/sd/sdcard: Add direct reference to SDProto in SDState
In reply to Philippe Mathieu-DaudéKeep direct reference to SDProto in SDState,
remove then unnecessary sd_proto().
--- hw/sd/sd.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)
hw/sd/sd.c +17 -20
@@ -116,6 +116,8 @@ struct SDState {uint8_t spec_version;BlockBackend *blk; +const SDProto *proto; +/* Runtime changeables */ uint32_t mode;/* current card mode, one of SDCardModes */
@@ -154,18 +156,11 @@ struct SDState {static void sd_realize (DeviceState *dev,Error **errp); -static const struct SDProto *sd_proto (SDState *sd) -{ -SDCardClass *sc =SD_CARD_GET_CLASS (sd); - -return sc->proto; -} -static const SDProto sd_proto_spi;static bool sd_is_spi (SDState *sd) { -return sd_proto (sd) == &sd_proto_spi; +return sd->proto == &sd_proto_spi; }static const char *sd_version_str (enum SDPhySpecificationVersion version)
@@ -1044,7 +1039,7 @@ static bool address_in_range(SDState *sd, const char *desc,static sd_rsp_type_t sd_invalid_state_for_cmd (SDState *sd,SDRequest req) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: CMD%i in a wrong state: %s (spec %s)\n" , -sd_proto (sd)->name, req.cmd,sd_state_name (sd->state), + sd->proto->name, req.cmd,sd_state_name (sd->state),sd_version_str (sd->spec_version));return sd_illegal;
@@ -1053,7 +1048,7 @@ static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req)static sd_rsp_type_t sd_invalid_mode_for_cmd (SDState *sd,SDRequest req) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: CMD%i in a wrong mode: %s (spec %s)\n" , -sd_proto (sd)->name, req.cmd,sd_mode_name (sd->mode), + sd->proto->name, req.cmd,sd_mode_name (sd->mode),sd_version_str (sd->spec_version));return sd_illegal;
@@ -1062,7 +1057,7 @@ static sd_rsp_type_t sd_invalid_mode_for_cmd(SDState *sd, SDRequest req)static sd_rsp_type_t sd_cmd_illegal (SDState *sd,SDRequest req) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: Unknown CMD%i for spec %s\n" , -sd_proto (sd)->name, req.cmd, + sd->proto->name, req.cmd,sd_version_str (sd->spec_version));return sd_illegal;
@@ -1073,7 +1068,7 @@ __attribute__((unused))static sd_rsp_type_t sd_cmd_unimplemented (SDState *sd,SDRequest req) {qemu_log_mask (LOG_UNIMP ,"%s: CMD%i not implemented\n" , -sd_proto (sd)->name, req.cmd); + sd->proto->name, req.cmd);return sd_illegal; }
@@ -1166,7 +1161,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)* However there is no ACMD55, so we want to trace this particular case. */ if (req.cmd !=55 || sd->expecting_acmd) { -trace_sdcard_normal_command (sd_proto (sd)->name, +trace_sdcard_normal_command (sd->proto->name, sd->last_cmd_name, req.cmd, req.arg,sd_state_name (sd->state)); }
@@ -1185,8 +1180,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_illegal; } -if (sd_proto (sd)->cmd[req.cmd]) { -return sd_proto (sd)->cmd[req.cmd](sd, req); +if (sd->proto->cmd[req.cmd]) { +return sd->proto->cmd[req.cmd](sd, req); }switch (req.cmd) {
@@ -1632,12 +1627,12 @@ static sd_rsp_type_t sd_app_command(SDState *sd, SDRequest req) { sd->last_cmd_name =sd_acmd_name (req.cmd); -trace_sdcard_app_command (sd_proto (sd)->name, sd->last_cmd_name, +trace_sdcard_app_command (sd->proto->name, sd->last_cmd_name, req.cmd, req.arg,sd_state_name (sd->state)); sd->card_status |=APP_CMD ; -if (sd_proto (sd)->acmd[req.cmd]) { -return sd_proto (sd)->acmd[req.cmd](sd, req); +if (sd->proto->acmd[req.cmd]) { +return sd->proto->acmd[req.cmd](sd, req); }switch (req.cmd) {
@@ -1928,7 +1923,7 @@ void sd_write_byte(SDState *sd, uint8_t value)if (sd->card_status & (ADDRESS_ERROR |WP_VIOLATION ))return ; -trace_sdcard_write_data (sd_proto (sd)->name, +trace_sdcard_write_data (sd->proto->name, sd->last_cmd_name, sd->current_cmd, sd->data_offset, value);switch (sd->current_cmd) {
@@ -2083,7 +2078,7 @@ uint8_t sd_read_byte(SDState *sd) io_len = (sd->ocr & (1 <<30 )) ?512 : sd->blk_len; -trace_sdcard_read_data (sd_proto (sd)->name, +trace_sdcard_read_data (sd->proto->name, sd->last_cmd_name, sd->current_cmd, sd->data_offset, io_len);switch (sd->current_cmd) {
@@ -2227,7 +2222,9 @@ static const SDProto sd_proto_sd = {static void sd_instance_init (Object *obj) {SDState *sd =SD_CARD (obj); +SDCardClass *sc =SD_CARD_GET_CLASS (sd); + sd->proto = sc->proto; sd->last_cmd_name ="UNSET" ; sd->enable = true; sd->ocr_power_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , sd_ocr_powerup, sd);
Signature · 1 line
2.41.0
Re: [PATCH v42 13/98] hw/sd/sdcard: Add direct reference to SDProto in SDState
Quoted 5 lines · Philippe Mathieu-Daudé
Keep direct reference to SDProto in SDState,
remove then unnecessarysd_proto().Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>
Thanks,
C.
Quoted 137 lines
--- hw/sd/sd.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-)hw/sd/sd.c +17
-20@@ -116,6 +116,8 @@ struct SDState {uint8_t spec_version;BlockBackend *blk; +const SDProto *proto; +/* Runtime changeables */ uint32_t mode;/* current card mode, one of SDCardModes */ @@ -154,18 +156,11 @@ struct SDState {static void sd_realize (DeviceState *dev,Error **errp); -static const struct SDProto *sd_proto (SDState *sd) -{ -SDCardClass *sc =SD_CARD_GET_CLASS (sd); - -return sc->proto; -} -static const SDProto sd_proto_spi;static bool sd_is_spi (SDState *sd) { -return sd_proto (sd) == &sd_proto_spi; +return sd->proto == &sd_proto_spi; }static const char *sd_version_str (enum SDPhySpecificationVersion version)@@ -1044,7 +1039,7 @@ static bool address_in_range(SDState *sd, const char *desc,static sd_rsp_type_t sd_invalid_state_for_cmd (SDState *sd,SDRequest req) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: CMD%i in a wrong state: %s (spec %s)\n" , -sd_proto (sd)->name, req.cmd,sd_state_name (sd->state), + sd->proto->name, req.cmd,sd_state_name (sd->state),sd_version_str (sd->spec_version));return sd_illegal;@@ -1053,7 +1048,7 @@ static sd_rsp_type_t sd_invalid_state_for_cmd(SDState *sd, SDRequest req)static sd_rsp_type_t sd_invalid_mode_for_cmd (SDState *sd,SDRequest req) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: CMD%i in a wrong mode: %s (spec %s)\n" , -sd_proto (sd)->name, req.cmd,sd_mode_name (sd->mode), + sd->proto->name, req.cmd,sd_mode_name (sd->mode),sd_version_str (sd->spec_version));return sd_illegal;@@ -1062,7 +1057,7 @@ static sd_rsp_type_t sd_invalid_mode_for_cmd(SDState *sd, SDRequest req)static sd_rsp_type_t sd_cmd_illegal (SDState *sd,SDRequest req) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: Unknown CMD%i for spec %s\n" , -sd_proto (sd)->name, req.cmd, + sd->proto->name, req.cmd,sd_version_str (sd->spec_version));return sd_illegal;@@ -1073,7 +1068,7 @@ __attribute__((unused))static sd_rsp_type_t sd_cmd_unimplemented (SDState *sd,SDRequest req) {qemu_log_mask (LOG_UNIMP ,"%s: CMD%i not implemented\n" , -sd_proto (sd)->name, req.cmd); + sd->proto->name, req.cmd);return sd_illegal; }@@ -1166,7 +1161,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)* However there is no ACMD55, so we want to trace this particular case. */ if (req.cmd !=55 || sd->expecting_acmd) { -trace_sdcard_normal_command (sd_proto (sd)->name, +trace_sdcard_normal_command (sd->proto->name, sd->last_cmd_name, req.cmd, req.arg,sd_state_name (sd->state)); }@@ -1185,8 +1180,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_illegal; } -if (sd_proto (sd)->cmd[req.cmd]) { -return sd_proto (sd)->cmd[req.cmd](sd, req); +if (sd->proto->cmd[req.cmd]) { +return sd->proto->cmd[req.cmd](sd, req); }switch (req.cmd) {@@ -1632,12 +1627,12 @@ static sd_rsp_type_t sd_app_command(SDState *sd, SDRequest req) { sd->last_cmd_name =sd_acmd_name (req.cmd); -trace_sdcard_app_command (sd_proto (sd)->name, sd->last_cmd_name, +trace_sdcard_app_command (sd->proto->name, sd->last_cmd_name, req.cmd, req.arg,sd_state_name (sd->state)); sd->card_status |=APP_CMD ; -if (sd_proto (sd)->acmd[req.cmd]) { -return sd_proto (sd)->acmd[req.cmd](sd, req); +if (sd->proto->acmd[req.cmd]) { +return sd->proto->acmd[req.cmd](sd, req); }switch (req.cmd) {@@ -1928,7 +1923,7 @@ void sd_write_byte(SDState *sd, uint8_t value)if (sd->card_status & (ADDRESS_ERROR |WP_VIOLATION ))return ; -trace_sdcard_write_data (sd_proto (sd)->name, +trace_sdcard_write_data (sd->proto->name, sd->last_cmd_name, sd->current_cmd, sd->data_offset, value);switch (sd->current_cmd) {@@ -2083,7 +2078,7 @@ uint8_t sd_read_byte(SDState *sd) io_len = (sd->ocr & (1 <<30 )) ?512 : sd->blk_len; -trace_sdcard_read_data (sd_proto (sd)->name, +trace_sdcard_read_data (sd->proto->name, sd->last_cmd_name, sd->current_cmd, sd->data_offset, io_len);switch (sd->current_cmd) {@@ -2227,7 +2222,9 @@ static const SDProto sd_proto_sd = {static void sd_instance_init (Object *obj) {SDState *sd =SD_CARD (obj); +SDCardClass *sc =SD_CARD_GET_CLASS (sd); + sd->proto = sc->proto; sd->last_cmd_name ="UNSET" ; sd->enable = true; sd->ocr_power_timer =timer_new_ns (QEMU_CLOCK_VIRTUAL , sd_ocr_powerup, sd);
PATCH v42 14/98 hw/sd/sdcard: Extract sd_blk_len() helper
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
Extract sd_blk_len() helper, use definitions instead of magic values.
--- hw/sd/sd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)
hw/sd/sd.c +9 -1
@@ -603,6 +603,14 @@ static void sd_response_r7_make(SDState *sd, uint8_t *response)stl_be_p (response, sd->vhs); } +static uint32_t sd_blk_len (SDState *sd) +{ +if (FIELD_EX32 (sd->ocr,OCR ,CARD_CAPACITY )) { +return 1 <<HWBLOCK_SHIFT ; + } +return sd->blk_len; +} +static uint64_t sd_req_get_address (SDState *sd,SDRequest req) {uint64_t addr;
@@ -2076,7 +2084,7 @@ uint8_t sd_read_byte(SDState *sd)if (sd->card_status & (ADDRESS_ERROR |WP_VIOLATION ))return 0x00 ; - io_len = (sd->ocr & (1 <<30 )) ?512 : sd->blk_len; + io_len =sd_blk_len (sd); trace_sdcard_read_data(sd->proto->name, sd->last_cmd_name,
Signature · 1 line
2.41.0
Re: [PATCH v42 14/98] hw/sd/sdcard: Extract sd_blk_len() helper
Quoted 7 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Extract
sd_blk_len()helper, use definitions instead of magic values.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 32 lines
--- hw/sd/sd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-)hw/sd/sd.c +9
-1@@ -603,6 +603,14 @@ static void sd_response_r7_make(SDState *sd, uint8_t *response)stl_be_p (response, sd->vhs); } +static uint32_t sd_blk_len (SDState *sd) +{ +if (FIELD_EX32 (sd->ocr,OCR ,CARD_CAPACITY )) { +return 1 <<HWBLOCK_SHIFT ; + } +return sd->blk_len; +} +static uint64_t sd_req_get_address (SDState *sd,SDRequest req) {uint64_t addr;@@ -2076,7 +2084,7 @@ uint8_t sd_read_byte(SDState *sd)if (sd->card_status & (ADDRESS_ERROR |WP_VIOLATION ))return 0x00 ; - io_len = (sd->ocr & (1 <<30 )) ?512 : sd->blk_len; + io_len =sd_blk_len (sd); trace_sdcard_read_data(sd->proto->name, sd->last_cmd_name,
PATCH v42 15/98 tests/qtest: Disable npcm7xx_sdhci tests using hardcoded RCA
In reply to Philippe Mathieu-DaudéDisable tests using 0x4567 hardcoded RCA otherwise when using random RCA we get:
ERROR:../../tests/qtest/npcm7xx_sdhci-test.c:69:write_sdread: assertion failed: (ret == len)
not ok /arm/npcm7xx_sdhci/read_sd - ERROR:../../tests/qtest/npcm7xx_sdhci-test.c:69:write_sdread: assertion failed: (ret == len) Bail out!
See https://lore.kernel.org/qemu-devel/[email protected]/
---
Cc: Hao Wu <[email protected]>
Cc: Shengtan Mao <[email protected]>
Cc: Tyrone Ting <[email protected]>
See also discussion with Thomas:
https://lore.kernel.org/qemu-devel/[email protected]/
--- tests/qtest/npcm7xx_sdhci-test.c | 7 +++++++ 1 file changed, 7 insertions(+)
tests/qtest/npcm7xx_sdhci-test.c +7 -0
@@ -44,6 +44,7 @@ static QTestState *setup_sd_card(void)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 ); +g_test_skip ("hardcoded 0x4567 card address" );sdhci_cmd_regs (qts,NPCM7XX_MMC_BA ,0 ,0 ,0x45670000 ,0 ,SDHC_SELECT_DESELECT_CARD );
@@ -76,6 +77,9 @@ static void test_read_sd(void) {QTestState *qts =setup_sd_card (); +g_test_skip ("hardcoded 0x4567 card address used in setup_sd_card()" ); +return ; +write_sdread (qts,"hello world" );write_sdread (qts,"goodbye" );
@@ -108,6 +112,9 @@ static void test_write_sd(void) {QTestState *qts =setup_sd_card (); +g_test_skip ("hardcoded 0x4567 card address used in setup_sd_card()" ); +return ; +sdwrite_read (qts,"hello world" );sdwrite_read (qts,"goodbye" );
Signature · 1 line
2.41.0
PATCH v42 16/98 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"
@@ -488,9 +489,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)
@@ -1113,11 +1115,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
Re: [PATCH v42 16/98] hw/sd/sdcard: Generate random RCA value
Quoted 5 lines · Philippe Mathieu-Daudé
Rather than using the obscure
0x4567magic value,
use a real random one.Signed-off-by Philippe Mathieu-Daudé <[email protected]>Tested-by Cédric Le Goater <[email protected]>
Thanks,
C.
Quoted 58 lines
--- 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" @@ -488,9 +489,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)@@ -1113,11 +1115,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"
PATCH v42 17/98 hw/sd/sdcard: Introduce definitions for EXT_CSD register
In reply to Philippe Mathieu-DaudéFrom: Cédric Le Goater <[email protected]>
--- hw/sd/sdmmc-internal.h | 97 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+)
hw/sd/sdmmc-internal.h +97 -0
@@ -11,6 +11,103 @@#ifndef SDMMC_INTERNAL_H #define SDMMC_INTERNAL_H +/* +* EXT_CSD fields +*/ + +#define EXT_CSD_CMDQ_MODE_EN 15/* R/W */ +#define EXT_CSD_FLUSH_CACHE 32/* W */ +#define EXT_CSD_CACHE_CTRL 33/* R/W */ +#define EXT_CSD_POWER_OFF_NOTIFICATION 34/* R/W */ +#define EXT_CSD_PACKED_FAILURE_INDEX 35/* RO */ +#define EXT_CSD_PACKED_CMD_STATUS 36/* RO */ +#define EXT_CSD_EXP_EVENTS_STATUS 54/* RO, 2 bytes */ +#define EXT_CSD_EXP_EVENTS_CTRL 56/* R/W, 2 bytes */ +#define EXT_CSD_DATA_SECTOR_SIZE 61/* R */ +#define EXT_CSD_GP_SIZE_MULT 143/* R/W */ +#define EXT_CSD_PARTITION_SETTING_COMPLETED 155/* R/W */ +#define EXT_CSD_PARTITION_ATTRIBUTE 156/* R/W */ +#define EXT_CSD_PARTITION_SUPPORT 160/* RO */ +#define EXT_CSD_HPI_MGMT 161/* R/W */ +#define EXT_CSD_RST_N_FUNCTION 162/* R/W */ +#define EXT_CSD_BKOPS_EN 163/* R/W */ +#define EXT_CSD_BKOPS_START 164/* W */ +#define EXT_CSD_SANITIZE_START 165/* W */ +#define EXT_CSD_WR_REL_PARAM 166/* RO */ +#define EXT_CSD_RPMB_MULT 168/* RO */ +#define EXT_CSD_FW_CONFIG 169/* R/W */ +#define EXT_CSD_BOOT_WP 173/* R/W */ +#define EXT_CSD_ERASE_GROUP_DEF 175/* R/W */ +#define EXT_CSD_PART_CONFIG 179/* R/W */ +#define EXT_CSD_ERASED_MEM_CONT 181/* RO */ +#define EXT_CSD_BUS_WIDTH 183/* R/W */ +#define EXT_CSD_STROBE_SUPPORT 184/* RO */ +#define EXT_CSD_HS_TIMING 185/* R/W */ +#define EXT_CSD_POWER_CLASS 187/* R/W */ +#define EXT_CSD_REV 192/* RO */ +#define EXT_CSD_STRUCTURE 194/* RO */ +#define EXT_CSD_CARD_TYPE 196/* RO */ +#define EXT_CSD_DRIVER_STRENGTH 197/* RO */ +#define EXT_CSD_OUT_OF_INTERRUPT_TIME 198/* RO */ +#define EXT_CSD_PART_SWITCH_TIME 199/* RO */ +#define EXT_CSD_PWR_CL_52_195 200/* RO */ +#define EXT_CSD_PWR_CL_26_195 201/* RO */ +#define EXT_CSD_PWR_CL_52_360 202/* RO */ +#define EXT_CSD_PWR_CL_26_360 203/* RO */ +#define EXT_CSD_SEC_CNT 212/* RO, 4 bytes */ +#define EXT_CSD_S_A_TIMEOUT 217/* RO */ +#define EXT_CSD_S_C_VCCQ 219/* RO */ +#define EXT_CSD_S_C_VCC 220/* RO */ +#define EXT_CSD_REL_WR_SEC_C 222/* RO */ +#define EXT_CSD_HC_WP_GRP_SIZE 221/* RO */ +#define EXT_CSD_ERASE_TIMEOUT_MULT 223/* RO */ +#define EXT_CSD_HC_ERASE_GRP_SIZE 224/* RO */ +#define EXT_CSD_ACC_SIZE 225/* RO */ +#define EXT_CSD_BOOT_MULT 226/* RO */ +#define EXT_CSD_BOOT_INFO 228/* RO */ +#define EXT_CSD_SEC_TRIM_MULT 229/* RO */ +#define EXT_CSD_SEC_ERASE_MULT 230/* RO */ +#define EXT_CSD_SEC_FEATURE_SUPPORT 231/* RO */ +#define EXT_CSD_TRIM_MULT 232/* RO */ +#define EXT_CSD_PWR_CL_200_195 236/* RO */ +#define EXT_CSD_PWR_CL_200_360 237/* RO */ +#define EXT_CSD_PWR_CL_DDR_52_195 238/* RO */ +#define EXT_CSD_PWR_CL_DDR_52_360 239/* RO */ +#define EXT_CSD_BKOPS_STATUS 246/* RO */ +#define EXT_CSD_POWER_OFF_LONG_TIME 247/* RO */ +#define EXT_CSD_GENERIC_CMD6_TIME 248/* RO */ +#define EXT_CSD_CACHE_SIZE 249/* RO, 4 bytes */ +#define EXT_CSD_PWR_CL_DDR_200_360 253/* RO */ +#define EXT_CSD_FIRMWARE_VERSION 254/* RO, 8 bytes */ +#define EXT_CSD_PRE_EOL_INFO 267/* RO */ +#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_A 268/* RO */ +#define EXT_CSD_DEVICE_LIFE_TIME_EST_TYP_B 269/* RO */ +#define EXT_CSD_CMDQ_DEPTH 307/* RO */ +#define EXT_CSD_CMDQ_SUPPORT 308/* RO */ +#define EXT_CSD_SUPPORTED_MODE 493/* RO */ +#define EXT_CSD_TAG_UNIT_SIZE 498/* RO */ +#define EXT_CSD_DATA_TAG_SUPPORT 499/* RO */ +#define EXT_CSD_MAX_PACKED_WRITES 500/* RO */ +#define EXT_CSD_MAX_PACKED_READS 501/* RO */ +#define EXT_CSD_BKOPS_SUPPORT 502/* RO */ +#define EXT_CSD_HPI_FEATURES 503/* RO */ +#define EXT_CSD_S_CMD_SET 504/* RO */ + +/* +* EXT_CSD field definitions +*/ + +#define EXT_CSD_WR_REL_PARAM_EN (1 << 2) +#define EXT_CSD_WR_REL_PARAM_EN_RPMB_REL_WR (1 << 4) + +#define EXT_CSD_PART_CONFIG_ACC_MASK (0x7) +#define EXT_CSD_PART_CONFIG_ACC_DEFAULT (0x0) +#define EXT_CSD_PART_CONFIG_ACC_BOOT0 (0x1) + +#define EXT_CSD_PART_CONFIG_EN_MASK (0x7 << 3) +#define EXT_CSD_PART_CONFIG_EN_BOOT0 (0x1 << 3) +#define EXT_CSD_PART_CONFIG_EN_USER (0x7 << 3) +#define SDMMC_CMD_MAX 64/**
Signature · 1 line
2.41.0
PATCH v42 18/98 hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte
In reply to Philippe Mathieu-DaudéAll commands switching from TRANSFER state to (sending)DATA do the same: send stream of data on the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers:
- sd_cmd_to_sendingdata() on the I/O line setup the data to be transferred,
- sd_generic_read_byte() on the DAT lines to fetch the data.
--- hw/sd/sd.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
hw/sd/sd.c +39 -0
@@ -142,8 +142,10 @@ struct SDState {*/ bool expecting_acmd;uint32_t blk_written; +uint64_t data_start;uint32_t data_offset; +size_t data_size;uint8_t data[512 ];uint8_t vendor_data[512 ];
@@ -1083,6 +1085,29 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req)return sd_illegal; } +/* Configure fields for following sd_generic_read_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_sendingdata (SDState *sd,SDRequest req, +uint64_t start, +const void *data,size_t size) +{ +if (sd->state != sd_transfer_state) { +sd_invalid_state_for_cmd (sd, req); + } + + sd->state = sd_sendingdata_state; + sd->data_start = start; + sd->data_offset =0 ; +if (data) { +assert (size); +memcpy (sd->data, data, size); + } +if (size) { + sd->data_size = size; + } +return sd_r1; +} +/* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE (SDState *sd,SDRequest req) {
@@ -1920,6 +1945,20 @@ send_response:return rsplen; } +/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ +__attribute__((unused)) +static bool sd_generic_read_byte (SDState *sd,uint8_t *value) +{ + *value = sd->data[sd->data_offset]; + +if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; +return true; + } + +return false; +} +void sd_write_byte (SDState *sd,uint8_t value) {int i;
Signature · 1 line
2.41.0
Re: [PATCH v42 18/98] hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte
Quoted 36 lines · Philippe Mathieu-Daudé
All commands switching from TRANSFER state to (sending)DATA do the same: send stream of data on the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers:
-sd_cmd_to_sendingdata()on the I/O line setup the data to be transferred,
-sd_generic_read_byte()on the DAT lines to fetch the data.Signed-off-by Philippe Mathieu-Daudé <[email protected]>--- hw/sd/sd.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)hw/sd/sd.c +7
-0@@ -142,8 +142,10 @@ struct SDState {*/ bool expecting_acmd;uint32_t blk_written; +uint64_t data_start;uint32_t data_offset; +size_t data_size;uint8_t data[512 ];uint8_t vendor_data[512 ];@@ -1083,6 +1085,29 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req)return sd_illegal; } +/* Configure fields for following sd_generic_read_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_sendingdata (SDState *sd,SDRequest req, +uint64_t start, +const void *data,size_t size)
hw/sd/sd.c static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) · line 1102
Quoted 10 lines
hw/sd/sd.c +10
-0+{ +if (sd->state != sd_transfer_state) { +sd_invalid_state_for_cmd (sd, req); + } + + sd->state = sd_sendingdata_state; + sd->data_start = start; + sd->data_offset =0 ; +if (data) { +assert (size);
Shouldn't we check for buffer overrun ? sizeof(sd->data)
Thanks,
C.
Quoted 32 lines
hw/sd/sd.c +22
-0+memcpy (sd->data, data, size); + } +if (size) { + sd->data_size = size; + } +return sd_r1; +} +/* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE (SDState *sd,SDRequest req) {@@ -1920,6 +1945,20 @@ send_response:return rsplen; } +/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ +__attribute__((unused)) +static bool sd_generic_read_byte (SDState *sd,uint8_t *value) +{ + *value = sd->data[sd->data_offset]; + +if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; +return true; + } + +return false; +} +void sd_write_byte (SDState *sd,uint8_t value) {int i;
Re: [PATCH v42 18/98] hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte
Quoted 41 lines · Cédric Le Goater
Quoted 40 lines · Philippe Mathieu-Daudé
All commands switching from TRANSFER state to (sending)DATA do the same: send stream of data on the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers:
-sd_cmd_to_sendingdata()on the I/O line setup the data to be transferred,
-sd_generic_read_byte()on the DAT lines to fetch the data.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/sd/sd.c| 39 +++++++++++++++++++++++++++++++++++++++1 file changed, 39 insertions(+)hw/sd/sd.c +11
-0@@ -142,8 +142,10 @@ struct SDState {*/ bool expecting_acmd; uint32_t blk_written; + uint64_t data_start; uint32_t data_offset; + size_t data_size; uint8_t data[512]; uint8_t vendor_data[512];@@ -1083,6 +1085,29 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +/* Configure fields for following sd_generic_read_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_sendingdata (SDState *sd,SDRequest req, + uint64_t start, + const void *data, size_t size) +{ + if (sd->state != sd_transfer_state) { + sd_invalid_state_for_cmd(sd, req); + }
Quoted 8 lines
hw/sd/sd.c static sd_rsp_type_t · line 1103
Quoted 6 lines
hw/sd/sd.c +6
-0+ + sd->state = sd_sendingdata_state; + sd->data_start = start; + sd->data_offset = 0; + if (data) { + assert(size);Shouldn't we check for buffer overrun ?
sizeof(sd->data)
OK if I squash this?
-- >8 --
hw/sd/sd.c +1 -2
@@ -1123,7 +1123,7 @@ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, sd->data_start = start; sd->data_offset =0 ;if (data) { -assert (size); +assert (size >0 && size <=sizeof (sd->data));memcpy (sd->data, data, size); } ---
Quoted 40 lines
Thanks,
C.
Quoted 32 lines
hw/sd/sd.c +8
-0+ memcpy(sd->data, data, size); + } + if (size) { + sd->data_size = size; + } + return sd_r1; +} + /* CMD0 */ static sd_rsp_type_t sd_cmd_GO_IDLE_STATE(SDState *sd, SDRequest req){
hw/sd/sd.c +1
-0@@ -1920,6 +1945,20 @@ send_response: return rsplen; } +/* Return true when buffer is consumed. Configured by
sd_cmd_to_sendingdata()*/hw/sd/sd.c +13
-0+__attribute__((unused)) +static bool sd_generic_read_byte (SDState *sd,uint8_t *value) +{ + *value = sd->data[sd->data_offset]; + + if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; + return true; + } + + return false; +} +void
sd_write_byte(SDState *sd, uint8_t value)
{
int i;
Re: [PATCH v42 18/98] hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte
Quoted 57 lines · Philippe Mathieu-Daudé
Quoted 39 lines · Cédric Le Goater
Quoted 38 lines · Philippe Mathieu-Daudé
All commands switching from TRANSFER state to (sending)DATA do the same: send stream of data on the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers:
-sd_cmd_to_sendingdata()on the I/O line setup the data to be transferred,
-sd_generic_read_byte()on the DAT lines to fetch the data.Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/sd/sd.c| 39 +++++++++++++++++++++++++++++++++++++++1 file changed, 39 insertions(+)hw/sd/sd.c +11
-0@@ -142,8 +142,10 @@ struct SDState {*/ bool expecting_acmd; uint32_t blk_written; + uint64_t data_start; uint32_t data_offset; + size_t data_size; uint8_t data[512]; uint8_t vendor_data[512];@@ -1083,6 +1085,29 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) return sd_illegal; } +/* Configure fields for following sd_generic_read_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_sendingdata (SDState *sd,SDRequest req, + uint64_t start, + const void *data, size_t size) +{ + if (sd->state != sd_transfer_state) { + sd_invalid_state_for_cmd(sd, req); + }Quoted 8 lines
hw/sd/sd.c static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) · line 1101
Quoted 6 lines
hw/sd/sd.c +6
-0+ + sd->state = sd_sendingdata_state; + sd->data_start = start; + sd->data_offset = 0; + if (data) { + assert(size);Shouldn't we check for buffer overrun ?
sizeof(sd->data)OK if I squash this?
-- >8 --
hw/sd/sd.c +0
-0
hw/sd/sd.c static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, · line 1129
Quoted 8 lines
hw/sd/sd.c +1
-2@@ -1123,7 +1123,7 @@ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, sd->data_start = start; sd->data_offset = 0; if (data) { - assert(size); + assert(size > 0 && size <= sizeof(sd->data)); memcpy(sd->data, data, size); } ---
sure.
Thanks,
C.
Re: [PATCH v42 18/98] hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte
Quoted 28 lines · Cédric Le Goater
Quoted 27 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Cédric Le Goater
Quoted 7 lines · Philippe Mathieu-Daudé
All commands switching from TRANSFER state to (sending)DATA do the same: send stream of data on the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers:
-sd_cmd_to_sendingdata()on the I/O line setup the data to be transferred,
-sd_generic_read_byte()on the DAT lines to fetch the data.Quoted 6 lines
Quoted 4 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/sd/sd.c| 39 +++++++++++++++++++++++++++++++++++++++1 file changed, 39 insertions(+)Shouldn't we check for buffer overrun ?
sizeof(sd->data)OK if I squash this?
-- >8 --
hw/sd/sd.c +0
-0@@ -1123,7 +1123,7 @@ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, sd->data_start = start; sd->data_offset = 0;
Quoted 8 lines
hw/sd/sd.c static sd_rsp_type_t
Quoted 6 lines
hw/sd/sd.c +1
-2if (data) { - assert(size); + assert(size > 0 && size <= sizeof(sd->data)); memcpy(sd->data, data, size); } ---sure.
Great. Can I get your R-b tag? The final patch is:
-- >8 --
Author: Philippe Mathieu-Daudé <[email protected]> Date: Thu Jun 13 16:21:12 2024 +0200
hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte
All commands switching from TRANSFER state to (sending)DATA do the same: send stream of data on the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers:
- sd_cmd_to_sendingdata() on the I/O line setup the data to be transferred,
- sd_generic_read_byte() on the DAT lines to fetch the data.
hw/sd/sd.c +39 -0
@@ -143,4 +143,6 @@ struct SDState {uint32_t blk_written; +uint64_t data_start;uint32_t data_offset; +size_t data_size;uint8_t data[512 ];
@@ -1080,2 +1082,25 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) +/* Configure fields for following sd_generic_read_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_sendingdata (SDState *sd,SDRequest req, +uint64_t start, +const void *data,size_t size) +{ +if (sd->state != sd_transfer_state) { +sd_invalid_state_for_cmd (sd, req); + } + + sd->state = sd_sendingdata_state; + sd->data_start = start; + sd->data_offset =0 ; +if (data) { +assert (size >0 && size <=sizeof (sd->data)); +memcpy (sd->data, data, size); + } +if (size) { + sd->data_size = size; + } +return sd_r1; +} +/* CMD0 */
@@ -1914,2 +1939,16 @@ send_response: +/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ +__attribute__((unused)) +static bool sd_generic_read_byte (SDState *sd,uint8_t *value) +{ + *value = sd->data[sd->data_offset]; + +if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; +return true; + } + +return false; +} +void sd_write_byte (SDState *sd,uint8_t value)
---
Cédric Le Goater
Reviewed-byRe: [PATCH v42 18/98] hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte
Quoted 37 lines · Philippe Mathieu-Daudé
Quoted 19 lines · Cédric Le Goater
Quoted 18 lines · Philippe Mathieu-Daudé
Quoted 8 lines · Cédric Le Goater
Quoted 7 lines · Philippe Mathieu-Daudé
All commands switching from TRANSFER state to (sending)DATA do the same: send stream of data on the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers:
-sd_cmd_to_sendingdata()on the I/O line setup the data to be transferred,
-sd_generic_read_byte()on the DAT lines to fetch the data.Quoted 6 lines
Quoted 4 lines
Signed-off-by Philippe Mathieu-Daudé <[email protected]>---
hw/sd/sd.c| 39 +++++++++++++++++++++++++++++++++++++++1 file changed, 39 insertions(+)Shouldn't we check for buffer overrun ?
sizeof(sd->data)OK if I squash this?
Quoted 16 lines
Quoted 6 lines
-- >8 --
hw/sd/sd.c +0
-0hw/sd/sd.c static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, · line 1129
Quoted 8 lines
hw/sd/sd.c +1
-2@@ -1123,7 +1123,7 @@ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, sd->data_start = start; sd->data_offset = 0; if (data) { - assert(size); + assert(size > 0 && size <= sizeof(sd->data)); memcpy(sd->data, data, size); } ---sure.
Quoted 1 line
Great. Can I get your R-b tag? The final patch is:
Thanks,
C.
Quoted 72 lines
-- >8 --
Author: Philippe Mathieu-Daudé <[email protected]> Date: Thu Jun 13 16:21:12 2024 +0200hw/sd/sdcard: Introduce
sd_cmd_to_sendingdataandsd_generic_read_byteAll commands switching from TRANSFER state to (sending)DATA do the same: send stream of data on the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers:
-sd_cmd_to_sendingdata()on the I/O line setup the data to be transferred,
-sd_generic_read_byte()on the DAT lines to fetch the data.Signed-off-by Philippe Mathieu-Daudé <[email protected]>hw/sd/sd.c +39
-1@@ -143,4 +143,6 @@ struct SDState { uint32_t blk_written; + uint64_t data_start; uint32_t data_offset; + size_t data_size; uint8_t data[512];@@ -1080,2 +1082,25 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) +/* Configure fields for following sd_generic_read_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_sendingdata (SDState *sd,SDRequest req, + uint64_t start, + const void *data, size_t size) +{ + if (sd->state != sd_transfer_state) { + sd_invalid_state_for_cmd(sd, req); + } + + sd->state = sd_sendingdata_state; + sd->data_start = start; + sd->data_offset = 0; + if (data) { + assert(size > 0 && size <= sizeof(sd->data)); + memcpy(sd->data, data, size); + } + if (size) { + sd->data_size = size; + } + return sd_r1; +} + /* CMD0 */@@ -1914,2 +1939,16 @@ send_response: +/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ +__attribute__((unused)) +static bool sd_generic_read_byte (SDState *sd,uint8_t *value) +{ + *value = sd->data[sd->data_offset]; + + if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; + return true; + } + + return false; +} + void sd_write_byte(SDState *sd, uint8_t value) ---
PATCH v42 19/98 hw/sd/sdcard: Convert SWITCH_FUNCTION to generic_read_byte (CMD6)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)
hw/sd/sd.c +2 -10
@@ -1086,7 +1086,6 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) }/* Configure fields for following sd_generic_read_byte() calls */ -__attribute__((unused))static sd_rsp_type_t sd_cmd_to_sendingdata (SDState *sd,SDRequest req,uint64_t start,const void *data,size_t size)
@@ -1243,10 +1242,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) }sd_function_switch (sd, req.arg); - sd->state = sd_sendingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 ,NULL ,64 );case 7 :/* CMD7: SELECT/DESELECT_CARD */ rca =sd_req_get_rca (sd, req);
@@ -1946,7 +1942,6 @@ send_response: }/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ -__attribute__((unused))static bool sd_generic_read_byte (SDState *sd,uint8_t *value) { *value = sd->data[sd->data_offset];
@@ -2135,10 +2130,7 @@ uint8_t sd_read_byte(SDState *sd) sd->current_cmd, sd->data_offset, io_len);switch (sd->current_cmd) {case 6 :/* CMD6: SWITCH_FUNCTION */ - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >=64 ) - sd->state = sd_transfer_state; +sd_generic_read_byte (sd, &ret);break ;case 9 :/* CMD9: SEND_CSD */
Signature · 1 line
2.41.0
Re: [PATCH v42 19/98] hw/sd/sdcard: Convert SWITCH_FUNCTION to generic_read_byte (CMD6)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 48 lines
--- hw/sd/sd.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)hw/sd/sd.c +2
-10@@ -1086,7 +1086,6 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) }/* Configure fields for following sd_generic_read_byte() calls */ -__attribute__((unused))static sd_rsp_type_t sd_cmd_to_sendingdata (SDState *sd,SDRequest req,uint64_t start,const void *data,size_t size)@@ -1243,10 +1242,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) }sd_function_switch (sd, req.arg); - sd->state = sd_sendingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 ,NULL ,64 );case 7 :/* CMD7: SELECT/DESELECT_CARD */ rca =sd_req_get_rca (sd, req);@@ -1946,7 +1942,6 @@ send_response: }/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ -__attribute__((unused))static bool sd_generic_read_byte (SDState *sd,uint8_t *value) { *value = sd->data[sd->data_offset];@@ -2135,10 +2130,7 @@ uint8_t sd_read_byte(SDState *sd) sd->current_cmd, sd->data_offset, io_len);switch (sd->current_cmd) {case 6 :/* CMD6: SWITCH_FUNCTION */ - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >=64 ) - sd->state = sd_transfer_state; +sd_generic_read_byte (sd, &ret);break ;case 9 :/* CMD9: SEND_CSD */
Re: [PATCH v42 19/98] hw/sd/sdcard: Convert SWITCH_FUNCTION to generic_read_byte (CMD6)
In reply to Philippe Mathieu-DaudéQuoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 48 lines
--- hw/sd/sd.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-)hw/sd/sd.c +2
-10@@ -1086,7 +1086,6 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) }/* Configure fields for following sd_generic_read_byte() calls */ -__attribute__((unused))static sd_rsp_type_t sd_cmd_to_sendingdata (SDState *sd,SDRequest req,uint64_t start,const void *data,size_t size)@@ -1243,10 +1242,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) }sd_function_switch (sd, req.arg); - sd->state = sd_sendingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 ,NULL ,64 );case 7 :/* CMD7: SELECT/DESELECT_CARD */ rca =sd_req_get_rca (sd, req);@@ -1946,7 +1942,6 @@ send_response: }/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ -__attribute__((unused))static bool sd_generic_read_byte (SDState *sd,uint8_t *value) { *value = sd->data[sd->data_offset];@@ -2135,10 +2130,7 @@ uint8_t sd_read_byte(SDState *sd) sd->current_cmd, sd->data_offset, io_len);switch (sd->current_cmd) {case 6 :/* CMD6: SWITCH_FUNCTION */ - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >=64 ) - sd->state = sd_transfer_state; +sd_generic_read_byte (sd, &ret);break ;case 9 :/* CMD9: SEND_CSD */
PATCH v42 20/98 hw/sd/sdcard: Convert SEND_CSD/SEND_CID to generic_read_byte (CMD9 & 10)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- hw/sd/sd.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)
hw/sd/sd.c +6 -18
@@ -1312,11 +1312,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)if (!sd_is_spi (sd)) {break ; } - sd->state = sd_sendingdata_state; -memcpy (sd->data, sd->csd,16 ); - sd->data_start =sd_req_get_address (sd, req); - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), + sd->csd,16 );default :break ;
@@ -1336,11 +1333,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)if (!sd_is_spi (sd)) {break ; } - sd->state = sd_sendingdata_state; -memcpy (sd->data, sd->cid,16 ); - sd->data_start =sd_req_get_address (sd, req); - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), + sd->cid,16 );default :break ;
@@ -2130,15 +2124,9 @@ uint8_t sd_read_byte(SDState *sd) sd->current_cmd, sd->data_offset, io_len);switch (sd->current_cmd) {case 6 :/* CMD6: SWITCH_FUNCTION */ -sd_generic_read_byte (sd, &ret); -break ; -case 9 :/* CMD9: SEND_CSD */ -case 10 :/* CMD10: SEND_CID */ - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >=16 ) - sd->state = sd_transfer_state; +case 10 :/* CMD10: SEND_CID */ +sd_generic_read_byte (sd, &ret);break ;case 13 :/* ACMD13: SD_STATUS */
Signature · 1 line
2.41.0
Re: [PATCH v42 20/98] hw/sd/sdcard: Convert SEND_CSD/SEND_CID to generic_read_byte (CMD9 & 10)
Quoted 4 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 54 lines
--- hw/sd/sd.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-)hw/sd/sd.c +6
-18@@ -1312,11 +1312,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)if (!sd_is_spi (sd)) {break ; } - sd->state = sd_sendingdata_state; -memcpy (sd->data, sd->csd,16 ); - sd->data_start =sd_req_get_address (sd, req); - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), + sd->csd,16 );default :break ;@@ -1336,11 +1333,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)if (!sd_is_spi (sd)) {break ; } - sd->state = sd_sendingdata_state; -memcpy (sd->data, sd->cid,16 ); - sd->data_start =sd_req_get_address (sd, req); - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), + sd->cid,16 );default :break ;@@ -2130,15 +2124,9 @@ uint8_t sd_read_byte(SDState *sd) sd->current_cmd, sd->data_offset, io_len);switch (sd->current_cmd) {case 6 :/* CMD6: SWITCH_FUNCTION */ -sd_generic_read_byte (sd, &ret); -break ; -case 9 :/* CMD9: SEND_CSD */ -case 10 :/* CMD10: SEND_CID */ - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >=16 ) - sd->state = sd_transfer_state; +case 10 :/* CMD10: SEND_CID */ +sd_generic_read_byte (sd, &ret);break ;case 13 :/* ACMD13: SD_STATUS */
PATCH v42 21/98 hw/sd/sdcard: Duplicate READ_SINGLE_BLOCK / READ_MULTIPLE_BLOCK cases
In reply to Philippe Mathieu-DaudéIn order to modify the READ_SINGLE_BLOCK case in the next commit, duplicate it first.
--- hw/sd/sd.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
hw/sd/sd.c +18 -0
@@ -1398,6 +1398,24 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)break ;case 17 :/* CMD17: READ_SINGLE_BLOCK */ + addr =sd_req_get_address (sd, req); +switch (sd->state) { +case sd_transfer_state: + +if (!address_in_range (sd,"READ_SINGLE_BLOCK" , addr, sd->blk_len)) { +return sd_r1; + } + + sd->state = sd_sendingdata_state; + sd->data_start = addr; + sd->data_offset =0 ; +return sd_r1; + +default : +break ; + } +break ; +case 18 :/* CMD18: READ_MULTIPLE_BLOCK */ addr =sd_req_get_address (sd, req);switch (sd->state) {
Signature · 1 line
2.41.0
Re: [PATCH v42 21/98] hw/sd/sdcard: Duplicate READ_SINGLE_BLOCK / READ_MULTIPLE_BLOCK cases
Quoted 4 lines · Philippe Mathieu-Daudé
In order to modify the
READ_SINGLE_BLOCKcase in the next commit, duplicate it first.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 33 lines
--- hw/sd/sd.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)hw/sd/sd.c +18
-0@@ -1398,6 +1398,24 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)break ;case 17 :/* CMD17: READ_SINGLE_BLOCK */ + addr =sd_req_get_address (sd, req); +switch (sd->state) { +case sd_transfer_state: + +if (!address_in_range (sd,"READ_SINGLE_BLOCK" , addr, sd->blk_len)) { +return sd_r1; + } + + sd->state = sd_sendingdata_state; + sd->data_start = addr; + sd->data_offset =0 ; +return sd_r1; + +default : +break ; + } +break ; +case 18 :/* CMD18: READ_MULTIPLE_BLOCK */ addr =sd_req_get_address (sd, req);switch (sd->state) {
PATCH v42 22/98 hw/sd/sdcard: Convert READ_SINGLE_BLOCK to generic_read_byte (CMD17)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- hw/sd/sd.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-)
hw/sd/sd.c +3 -15
@@ -1405,11 +1405,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)if (!address_in_range (sd,"READ_SINGLE_BLOCK" , addr, sd->blk_len)) {return sd_r1; } - - sd->state = sd_sendingdata_state; - sd->data_start = addr; - sd->data_offset =0 ; -return sd_r1; +sd_blk_read (sd, addr, sd->blk_len); +return sd_cmd_to_sendingdata (sd, req, addr,NULL , sd->blk_len);default :break ;
@@ -2144,6 +2141,7 @@ uint8_t sd_read_byte(SDState *sd)case 6 :/* CMD6: SWITCH_FUNCTION */ case 9 :/* CMD9: SEND_CSD */ case 10 :/* CMD10: SEND_CID */ +case 17 :/* CMD17: READ_SINGLE_BLOCK */ sd_generic_read_byte (sd, &ret);break ;
@@ -2154,16 +2152,6 @@ uint8_t sd_read_byte(SDState *sd) sd->state = sd_transfer_state;break ; -case 17 :/* CMD17: READ_SINGLE_BLOCK */ -if (sd->data_offset ==0 ) { -sd_blk_read (sd, sd->data_start, io_len); - } - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >= io_len) - sd->state = sd_transfer_state; -break ; -case 18 :/* CMD18: READ_MULTIPLE_BLOCK */ if (sd->data_offset == 0) { if (!address_in_range(sd, "READ_MULTIPLE_BLOCK",
Signature · 1 line
2.41.0
Re: [PATCH v42 22/98] hw/sd/sdcard: Convert READ_SINGLE_BLOCK to generic_read_byte (CMD17)
Quoted 4 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 47 lines
--- hw/sd/sd.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-)hw/sd/sd.c +3
-15@@ -1405,11 +1405,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)if (!address_in_range (sd,"READ_SINGLE_BLOCK" , addr, sd->blk_len)) {return sd_r1; } - - sd->state = sd_sendingdata_state; - sd->data_start = addr; - sd->data_offset =0 ; -return sd_r1; +sd_blk_read (sd, addr, sd->blk_len); +return sd_cmd_to_sendingdata (sd, req, addr,NULL , sd->blk_len);default :break ;@@ -2144,6 +2141,7 @@ uint8_t sd_read_byte(SDState *sd)case 6 :/* CMD6: SWITCH_FUNCTION */ case 9 :/* CMD9: SEND_CSD */ case 10 :/* CMD10: SEND_CID */ +case 17 :/* CMD17: READ_SINGLE_BLOCK */ sd_generic_read_byte (sd, &ret);break ;@@ -2154,16 +2152,6 @@ uint8_t sd_read_byte(SDState *sd) sd->state = sd_transfer_state;break ; -case 17 :/* CMD17: READ_SINGLE_BLOCK */ -if (sd->data_offset ==0 ) { -sd_blk_read (sd, sd->data_start, io_len); - } - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >= io_len) - sd->state = sd_transfer_state; -break ; -case 18 :/* CMD18: READ_MULTIPLE_BLOCK */ if (sd->data_offset == 0) { if (!address_in_range(sd, "READ_MULTIPLE_BLOCK",
PATCH v42 23/98 hw/sd/sdcard: Convert SEND_TUNING_BLOCK to generic_read_byte (CMD19)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- hw/sd/sd.c | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-)
hw/sd/sd.c +19 -29
@@ -568,6 +568,21 @@ static void sd_set_sdstatus(SDState *sd)memset (sd->sd_status,0 ,64 ); } +static const uint8_t sd_tuning_block_pattern4[64 ] = { +/* +* See: Physical Layer Simplified Specification Version 3.01, +* Table 4-2. +*/ +0xff ,0x0f ,0xff ,0x00 ,0x0f ,0xfc ,0xc3 ,0xcc , +0xc3 ,0x3c ,0xcc ,0xff ,0xfe ,0xff ,0xfe ,0xef , +0xff ,0xdf ,0xff ,0xdd ,0xff ,0xfb ,0xff ,0xfb , +0xbf ,0xff ,0x7f ,0xff ,0x77 ,0xf7 ,0xbd ,0xef , +0xff ,0xf0 ,0xff ,0xf0 ,0x0f ,0xfc ,0xcc ,0x3c , +0xcc ,0x33 ,0xcc ,0xcf ,0xff ,0xef ,0xff ,0xee , +0xff ,0xfd ,0xff ,0xfd ,0xdf ,0xff ,0xbf ,0xff , +0xbb ,0xff ,0xf7 ,0xff ,0xf7 ,0x7f ,0x7b ,0xde +}; +static int sd_req_crc_validate (SDRequest *req) {uint8_t buffer[5 ];
@@ -1161,14 +1176,9 @@ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req)return sd_cmd_illegal (sd, req); } -if (sd->state != sd_transfer_state) { -return sd_invalid_state_for_cmd (sd, req); - } - - sd->state = sd_sendingdata_state; - sd->data_offset =0 ; - -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 , + sd_tuning_block_pattern4, +sizeof (sd_tuning_block_pattern4)); }/* CMD23 */
@@ -2100,20 +2110,6 @@ void sd_write_byte(SDState *sd, uint8_t value) } } -#define SD_TUNING_BLOCK_SIZE 64 - -static const uint8_t sd_tuning_block_pattern[SD_TUNING_BLOCK_SIZE ] = { -/* See: Physical Layer Simplified Specification Version 3.01, Table 4-2 */ -0xff ,0x0f ,0xff ,0x00 ,0x0f ,0xfc ,0xc3 ,0xcc , -0xc3 ,0x3c ,0xcc ,0xff ,0xfe ,0xff ,0xfe ,0xef , -0xff ,0xdf ,0xff ,0xdd ,0xff ,0xfb ,0xff ,0xfb , -0xbf ,0xff ,0x7f ,0xff ,0x77 ,0xf7 ,0xbd ,0xef , -0xff ,0xf0 ,0xff ,0xf0 ,0x0f ,0xfc ,0xcc ,0x3c , -0xcc ,0x33 ,0xcc ,0xcf ,0xff ,0xef ,0xff ,0xee , -0xff ,0xfd ,0xff ,0xfd ,0xdf ,0xff ,0xbf ,0xff , -0xbb ,0xff ,0xf7 ,0xff ,0xf7 ,0x7f ,0x7b ,0xde , -}; -uint8_t sd_read_byte (SDState *sd) {/* TODO: Append CRCs */
@@ -2142,6 +2138,7 @@ uint8_t sd_read_byte(SDState *sd)case 9 :/* CMD9: SEND_CSD */ case 10 :/* CMD10: SEND_CID */ case 17 :/* CMD17: READ_SINGLE_BLOCK */ +case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ sd_generic_read_byte (sd, &ret);break ;
@@ -2176,13 +2173,6 @@ uint8_t sd_read_byte(SDState *sd) }break ; -case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ -if (sd->data_offset >=SD_TUNING_BLOCK_SIZE -1 ) { - sd->state = sd_transfer_state; - } - ret = sd_tuning_block_pattern[sd->data_offset++]; -break ; -case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ ret = sd->data[sd->data_offset ++];
Signature · 1 line
2.41.0
Re: [PATCH v42 23/98] hw/sd/sdcard: Convert SEND_TUNING_BLOCK to generic_read_byte (CMD19)
Quoted 4 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 91 lines
--- hw/sd/sd.c | 48 +++++++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 29 deletions(-)hw/sd/sd.c +19
-29@@ -568,6 +568,21 @@ static void sd_set_sdstatus(SDState *sd)memset (sd->sd_status,0 ,64 ); } +static const uint8_t sd_tuning_block_pattern4[64 ] = { +/* +* See: Physical Layer Simplified Specification Version 3.01, +* Table 4-2. +*/ +0xff ,0x0f ,0xff ,0x00 ,0x0f ,0xfc ,0xc3 ,0xcc , +0xc3 ,0x3c ,0xcc ,0xff ,0xfe ,0xff ,0xfe ,0xef , +0xff ,0xdf ,0xff ,0xdd ,0xff ,0xfb ,0xff ,0xfb , +0xbf ,0xff ,0x7f ,0xff ,0x77 ,0xf7 ,0xbd ,0xef , +0xff ,0xf0 ,0xff ,0xf0 ,0x0f ,0xfc ,0xcc ,0x3c , +0xcc ,0x33 ,0xcc ,0xcf ,0xff ,0xef ,0xff ,0xee , +0xff ,0xfd ,0xff ,0xfd ,0xdf ,0xff ,0xbf ,0xff , +0xbb ,0xff ,0xf7 ,0xff ,0xf7 ,0x7f ,0x7b ,0xde +}; +static int sd_req_crc_validate (SDRequest *req) {uint8_t buffer[5 ];@@ -1161,14 +1176,9 @@ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK(SDState *sd, SDRequest req)return sd_cmd_illegal (sd, req); } -if (sd->state != sd_transfer_state) { -return sd_invalid_state_for_cmd (sd, req); - } - - sd->state = sd_sendingdata_state; - sd->data_offset =0 ; - -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 , + sd_tuning_block_pattern4, +sizeof (sd_tuning_block_pattern4)); }/* CMD23 */ @@ -2100,20 +2110,6 @@ void sd_write_byte(SDState *sd, uint8_t value) } } -#define SD_TUNING_BLOCK_SIZE 64 - -static const uint8_t sd_tuning_block_pattern[SD_TUNING_BLOCK_SIZE ] = { -/* See: Physical Layer Simplified Specification Version 3.01, Table 4-2 */ -0xff ,0x0f ,0xff ,0x00 ,0x0f ,0xfc ,0xc3 ,0xcc , -0xc3 ,0x3c ,0xcc ,0xff ,0xfe ,0xff ,0xfe ,0xef , -0xff ,0xdf ,0xff ,0xdd ,0xff ,0xfb ,0xff ,0xfb , -0xbf ,0xff ,0x7f ,0xff ,0x77 ,0xf7 ,0xbd ,0xef , -0xff ,0xf0 ,0xff ,0xf0 ,0x0f ,0xfc ,0xcc ,0x3c , -0xcc ,0x33 ,0xcc ,0xcf ,0xff ,0xef ,0xff ,0xee , -0xff ,0xfd ,0xff ,0xfd ,0xdf ,0xff ,0xbf ,0xff , -0xbb ,0xff ,0xf7 ,0xff ,0xf7 ,0x7f ,0x7b ,0xde , -}; -uint8_t sd_read_byte (SDState *sd) {/* TODO: Append CRCs */ @@ -2142,6 +2138,7 @@ uint8_t sd_read_byte(SDState *sd)case 9 :/* CMD9: SEND_CSD */ case 10 :/* CMD10: SEND_CID */ case 17 :/* CMD17: READ_SINGLE_BLOCK */ +case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ sd_generic_read_byte (sd, &ret);break ;@@ -2176,13 +2173,6 @@ uint8_t sd_read_byte(SDState *sd) }break ; -case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ -if (sd->data_offset >=SD_TUNING_BLOCK_SIZE -1 ) { - sd->state = sd_transfer_state; - } - ret = sd_tuning_block_pattern[sd->data_offset++]; -break ; -case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ ret = sd->data[sd->data_offset ++];
PATCH v42 24/98 hw/sd/sdcard: Convert SEND_WRITE_PROT to generic_read_byte (CMD30)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)
hw/sd/sd.c +4 -13
@@ -1202,6 +1202,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) {uint16_t rca;uint64_t addr; +uint32_t data; sd->last_cmd_name =sd_cmd_name (req.cmd);/* CMD55 precedes an ACMD, so we are not interested in tracing it.
@@ -1555,12 +1556,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) req.arg, sd->blk_len)) {return sd_r1; } - - sd->state = sd_sendingdata_state; -stl_be_p (sd->data,sd_wpbits (sd, req.arg)); - sd->data_start = addr; - sd->data_offset =0 ; -return sd_r1; + data =sd_wpbits (sd, req.arg); +return sd_cmd_to_sendingdata (sd, req, addr, &data,sizeof (data));default :break ;
@@ -2139,6 +2136,7 @@ uint8_t sd_read_byte(SDState *sd)case 10 :/* CMD10: SEND_CID */ case 17 :/* CMD17: READ_SINGLE_BLOCK */ case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ +case 30 :/* CMD30: SEND_WRITE_PROT */ sd_generic_read_byte (sd, &ret);break ;
@@ -2180,13 +2178,6 @@ uint8_t sd_read_byte(SDState *sd) sd->state = sd_transfer_state;break ; -case 30 :/* CMD30: SEND_WRITE_PROT */ - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >=4 ) - sd->state = sd_transfer_state; -break ; -case 51 :/* ACMD51: SEND_SCR */ ret = sd->scr[sd->data_offset ++];
Signature · 1 line
2.41.0
Re: [PATCH v42 24/98] hw/sd/sdcard: Convert SEND_WRITE_PROT to generic_read_byte (CMD30)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 53 lines
--- hw/sd/sd.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-)hw/sd/sd.c +4
-13@@ -1202,6 +1202,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) {uint16_t rca;uint64_t addr; +uint32_t data; sd->last_cmd_name =sd_cmd_name (req.cmd);/* CMD55 precedes an ACMD, so we are not interested in tracing it. @@ -1555,12 +1556,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) req.arg, sd->blk_len)) {return sd_r1; } - - sd->state = sd_sendingdata_state; -stl_be_p (sd->data,sd_wpbits (sd, req.arg)); - sd->data_start = addr; - sd->data_offset =0 ; -return sd_r1; + data =sd_wpbits (sd, req.arg); +return sd_cmd_to_sendingdata (sd, req, addr, &data,sizeof (data));default :break ;@@ -2139,6 +2136,7 @@ uint8_t sd_read_byte(SDState *sd)case 10 :/* CMD10: SEND_CID */ case 17 :/* CMD17: READ_SINGLE_BLOCK */ case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ +case 30 :/* CMD30: SEND_WRITE_PROT */ sd_generic_read_byte (sd, &ret);break ;@@ -2180,13 +2178,6 @@ uint8_t sd_read_byte(SDState *sd) sd->state = sd_transfer_state;break ; -case 30 :/* CMD30: SEND_WRITE_PROT */ - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >=4 ) - sd->state = sd_transfer_state; -break ; -case 51 :/* ACMD51: SEND_SCR */ ret = sd->scr[sd->data_offset ++];
PATCH v42 25/98 hw/sd/sdcard: Convert GEN_CMD to generic_read_byte (CMD56)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- hw/sd/sd.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)
hw/sd/sd.c +7 -12
@@ -1648,10 +1648,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (sd->state) {case sd_transfer_state: sd->data_offset =0 ; -if (req.arg &1 ) - sd->state = sd_sendingdata_state; -else - sd->state = sd_receivingdata_state; +if (req.arg &1 ) { +return sd_cmd_to_sendingdata (sd, req,0 , + sd->vendor_data, +sizeof (sd->vendor_data)); + } + sd->state = sd_receivingdata_state;return sd_r1;default :
@@ -2137,6 +2139,7 @@ uint8_t sd_read_byte(SDState *sd)case 17 :/* CMD17: READ_SINGLE_BLOCK */ case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ case 30 :/* CMD30: SEND_WRITE_PROT */ +case 56 :/* CMD56: GEN_CMD */ sd_generic_read_byte (sd, &ret);break ;
@@ -2185,14 +2188,6 @@ uint8_t sd_read_byte(SDState *sd) sd->state = sd_transfer_state;break ; -case 56 :/* CMD56: GEN_CMD */ - ret = sd->vendor_data[sd->data_offset ++]; - -if (sd->data_offset >=sizeof (sd->vendor_data)) { - sd->state = sd_transfer_state; - } -break ; -default :qemu_log_mask (LOG_GUEST_ERROR ,"%s: unknown command\n" , __func__);return 0x00 ;
Signature · 1 line
2.41.0
Re: [PATCH v42 25/98] hw/sd/sdcard: Convert GEN_CMD to generic_read_byte (CMD56)
Quoted 4 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 48 lines
--- hw/sd/sd.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-)hw/sd/sd.c +7
-12@@ -1648,10 +1648,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (sd->state) {case sd_transfer_state: sd->data_offset =0 ; -if (req.arg &1 ) - sd->state = sd_sendingdata_state; -else - sd->state = sd_receivingdata_state; +if (req.arg &1 ) { +return sd_cmd_to_sendingdata (sd, req,0 , + sd->vendor_data, +sizeof (sd->vendor_data)); + } + sd->state = sd_receivingdata_state;return sd_r1;default :@@ -2137,6 +2139,7 @@ uint8_t sd_read_byte(SDState *sd)case 17 :/* CMD17: READ_SINGLE_BLOCK */ case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ case 30 :/* CMD30: SEND_WRITE_PROT */ +case 56 :/* CMD56: GEN_CMD */ sd_generic_read_byte (sd, &ret);break ;@@ -2185,14 +2188,6 @@ uint8_t sd_read_byte(SDState *sd) sd->state = sd_transfer_state;break ; -case 56 :/* CMD56: GEN_CMD */ - ret = sd->vendor_data[sd->data_offset ++]; - -if (sd->data_offset >=sizeof (sd->vendor_data)) { - sd->state = sd_transfer_state; - } -break ; -default :qemu_log_mask (LOG_GUEST_ERROR ,"%s: unknown command\n" , __func__);return 0x00 ;
PATCH v42 26/98 hw/sd/sdcard: Convert SD_STATUS to generic_read_byte (ACMD13)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- hw/sd/sd.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
hw/sd/sd.c +4 -11
@@ -1703,10 +1703,9 @@ static sd_rsp_type_t sd_app_command(SDState *sd,case 13 :/* ACMD13: SD_STATUS */ switch (sd->state) {case sd_transfer_state: - sd->state = sd_sendingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 , + sd->sd_status, +sizeof (sd->sd_status));default :break ;
@@ -2136,6 +2135,7 @@ uint8_t sd_read_byte(SDState *sd)case 6 :/* CMD6: SWITCH_FUNCTION */ case 9 :/* CMD9: SEND_CSD */ case 10 :/* CMD10: SEND_CID */ +case 13 :/* ACMD13: SD_STATUS */ case 17 :/* CMD17: READ_SINGLE_BLOCK */ case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ case 30 :/* CMD30: SEND_WRITE_PROT */
@@ -2143,13 +2143,6 @@ uint8_t sd_read_byte(SDState *sd)sd_generic_read_byte (sd, &ret);break ; -case 13 :/* ACMD13: SD_STATUS */ - ret = sd->sd_status[sd->data_offset ++]; - -if (sd->data_offset >=sizeof (sd->sd_status)) - sd->state = sd_transfer_state; -break ; -case 18 :/* CMD18: READ_MULTIPLE_BLOCK */ if (sd->data_offset == 0) { if (!address_in_range(sd, "READ_MULTIPLE_BLOCK",
Signature · 1 line
2.41.0
Re: [PATCH v42 26/98] hw/sd/sdcard: Convert SD_STATUS to generic_read_byte (ACMD13)
Quoted 4 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 44 lines
--- hw/sd/sd.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)hw/sd/sd.c +4
-11@@ -1703,10 +1703,9 @@ static sd_rsp_type_t sd_app_command(SDState *sd,case 13 :/* ACMD13: SD_STATUS */ switch (sd->state) {case sd_transfer_state: - sd->state = sd_sendingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 , + sd->sd_status, +sizeof (sd->sd_status));default :break ;@@ -2136,6 +2135,7 @@ uint8_t sd_read_byte(SDState *sd)case 6 :/* CMD6: SWITCH_FUNCTION */ case 9 :/* CMD9: SEND_CSD */ case 10 :/* CMD10: SEND_CID */ +case 13 :/* ACMD13: SD_STATUS */ case 17 :/* CMD17: READ_SINGLE_BLOCK */ case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ case 30 :/* CMD30: SEND_WRITE_PROT */ @@ -2143,13 +2143,6 @@ uint8_t sd_read_byte(SDState *sd)sd_generic_read_byte (sd, &ret);break ; -case 13 :/* ACMD13: SD_STATUS */ - ret = sd->sd_status[sd->data_offset ++]; - -if (sd->data_offset >=sizeof (sd->sd_status)) - sd->state = sd_transfer_state; -break ; -case 18 :/* CMD18: READ_MULTIPLE_BLOCK */ if (sd->data_offset == 0) { if (!address_in_range(sd, "READ_MULTIPLE_BLOCK",
PATCH v42 27/98 hw/sd/sdcard: Convert SEND_NUM_WR_BLOCKS to generic_read_byte (ACMD22)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
hw/sd/sd.c +4 -12
@@ -1715,11 +1715,9 @@ static sd_rsp_type_t sd_app_command(SDState *sd,case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ switch (sd->state) {case sd_transfer_state: -stl_be_p (sd->data, sd->blk_written); - sd->state = sd_sendingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 , + &sd->blk_written, +sizeof (sd->blk_written));default :break ;
@@ -2138,6 +2136,7 @@ uint8_t sd_read_byte(SDState *sd)case 13 :/* ACMD13: SD_STATUS */ case 17 :/* CMD17: READ_SINGLE_BLOCK */ case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ +case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ case 30 :/* CMD30: SEND_WRITE_PROT */ case 56 :/* CMD56: GEN_CMD */ sd_generic_read_byte (sd, &ret);
@@ -2167,13 +2166,6 @@ uint8_t sd_read_byte(SDState *sd) }break ; -case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >=4 ) - sd->state = sd_transfer_state; -break ; -case 51 :/* ACMD51: SEND_SCR */ ret = sd->scr[sd->data_offset ++];
Signature · 1 line
2.41.0
Re: [PATCH v42 27/98] hw/sd/sdcard: Convert SEND_NUM_WR_BLOCKS to generic_read_byte (ACMD22)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 45 lines
--- hw/sd/sd.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)hw/sd/sd.c +4
-12@@ -1715,11 +1715,9 @@ static sd_rsp_type_t sd_app_command(SDState *sd,case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ switch (sd->state) {case sd_transfer_state: -stl_be_p (sd->data, sd->blk_written); - sd->state = sd_sendingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 , + &sd->blk_written, +sizeof (sd->blk_written));default :break ;@@ -2138,6 +2136,7 @@ uint8_t sd_read_byte(SDState *sd)case 13 :/* ACMD13: SD_STATUS */ case 17 :/* CMD17: READ_SINGLE_BLOCK */ case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ +case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ case 30 :/* CMD30: SEND_WRITE_PROT */ case 56 :/* CMD56: GEN_CMD */ sd_generic_read_byte (sd, &ret);@@ -2167,13 +2166,6 @@ uint8_t sd_read_byte(SDState *sd) }break ; -case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ - ret = sd->data[sd->data_offset ++]; - -if (sd->data_offset >=4 ) - sd->state = sd_transfer_state; -break ; -case 51 :/* ACMD51: SEND_SCR */ ret = sd->scr[sd->data_offset ++];
PATCH v42 28/98 hw/sd/sdcard: Convert SEND_SCR to generic_read_byte (ACMD51)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- hw/sd/sd.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)
hw/sd/sd.c +2 -11
@@ -1785,10 +1785,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd,case 51 :/* ACMD51: SEND_SCR */ switch (sd->state) {case sd_transfer_state: - sd->state = sd_sendingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 , sd->scr,sizeof (sd->scr));default :break ;
@@ -2138,6 +2135,7 @@ uint8_t sd_read_byte(SDState *sd)case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ case 30 :/* CMD30: SEND_WRITE_PROT */ +case 51 :/* ACMD51: SEND_SCR */ case 56 :/* CMD56: GEN_CMD */ sd_generic_read_byte (sd, &ret);break ;
@@ -2166,13 +2164,6 @@ uint8_t sd_read_byte(SDState *sd) }break ; -case 51 :/* ACMD51: SEND_SCR */ - ret = sd->scr[sd->data_offset ++]; - -if (sd->data_offset >=sizeof (sd->scr)) - sd->state = sd_transfer_state; -break ; -default :qemu_log_mask (LOG_GUEST_ERROR ,"%s: unknown command\n" , __func__);return 0x00 ;
Signature · 1 line
2.41.0
Re: [PATCH v42 28/98] hw/sd/sdcard: Convert SEND_SCR to generic_read_byte (ACMD51)
Quoted 4 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 42 lines
--- hw/sd/sd.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-)hw/sd/sd.c +2
-11@@ -1785,10 +1785,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd,case 51 :/* ACMD51: SEND_SCR */ switch (sd->state) {case sd_transfer_state: - sd->state = sd_sendingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; +return sd_cmd_to_sendingdata (sd, req,0 , sd->scr,sizeof (sd->scr));default :break ;@@ -2138,6 +2135,7 @@ uint8_t sd_read_byte(SDState *sd)case 19 :/* CMD19: SEND_TUNING_BLOCK (SD) */ case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ case 30 :/* CMD30: SEND_WRITE_PROT */ +case 51 :/* ACMD51: SEND_SCR */ case 56 :/* CMD56: GEN_CMD */ sd_generic_read_byte (sd, &ret);break ;@@ -2166,13 +2164,6 @@ uint8_t sd_read_byte(SDState *sd) }break ; -case 51 :/* ACMD51: SEND_SCR */ - ret = sd->scr[sd->data_offset ++]; - -if (sd->data_offset >=sizeof (sd->scr)) - sd->state = sd_transfer_state; -break ; -default :qemu_log_mask (LOG_GUEST_ERROR ,"%s: unknown command\n" , __func__);return 0x00 ;
PATCH v42 29/98 hw/sd/sdcard: Introduce sd_cmd_to_receivingdata / sd_generic_write_byte
In reply to Philippe Mathieu-DaudéAll commands switching from TRANSFER state to (receiving)DATA do the same: receive stream of data from the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers:
- sd_cmd_to_receivingdata() on the I/O line setup the data to be received on the data[] buffer,
- sd_generic_write_byte() on the DAT lines to push the data.
--- hw/sd/sd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
hw/sd/sd.c +29 -0
@@ -1100,6 +1100,22 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req)return sd_illegal; } +/* Configure fields for following sd_generic_write_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_receivingdata (SDState *sd,SDRequest req, +uint64_t start,size_t size) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + sd->state = sd_receivingdata_state; + sd->data_start = start; + sd->data_offset =0 ; +/* sd->data[] used as receive buffer */ + sd->data_size = size ?:sizeof (sd->data); +return sd_r1; +} +/* Configure fields for following sd_generic_read_byte() calls */ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, uint64_t start,
@@ -1953,6 +1969,19 @@ send_response:return rsplen; } +/* Return true if buffer is consumed. Configured by sd_cmd_to_receivingdata() */ +__attribute__((unused)) +static bool sd_generic_write_byte (SDState *sd,uint8_t value) +{ + sd->data[sd->data_offset] = value; + +if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; +return true; + } +return false; +} +/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ static bool sd_generic_read_byte (SDState *sd,uint8_t *value) {
Signature · 1 line
2.41.0
Re: [PATCH v42 29/98] hw/sd/sdcard: Introduce sd_cmd_to_receivingdata / sd_generic_write_byte
Quoted 8 lines · Philippe Mathieu-Daudé
All commands switching from TRANSFER state to (receiving)DATA do the same: receive stream of data from the DAT lines. Instead of duplicating the same code many times, introduce 2 helpers:
-sd_cmd_to_receivingdata()on the I/O line setup the data to be received on the data[] buffer,
-sd_generic_write_byte()on the DAT lines to push the data.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 51 lines
--- hw/sd/sd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)hw/sd/sd.c +29
-0@@ -1100,6 +1100,22 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req)return sd_illegal; } +/* Configure fields for following sd_generic_write_byte() calls */ +__attribute__((unused)) +static sd_rsp_type_t sd_cmd_to_receivingdata (SDState *sd,SDRequest req, +uint64_t start,size_t size) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + sd->state = sd_receivingdata_state; + sd->data_start = start; + sd->data_offset =0 ; +/* sd->data[] used as receive buffer */ + sd->data_size = size ?:sizeof (sd->data); +return sd_r1; +} +/* Configure fields for following sd_generic_read_byte() calls */ static sd_rsp_type_t sd_cmd_to_sendingdata(SDState *sd, SDRequest req, uint64_t start,@@ -1953,6 +1969,19 @@ send_response:return rsplen; } +/* Return true if buffer is consumed. Configured by sd_cmd_to_receivingdata() */ +__attribute__((unused)) +static bool sd_generic_write_byte (SDState *sd,uint8_t value) +{ + sd->data[sd->data_offset] = value; + +if (++sd->data_offset >= sd->data_size) { + sd->state = sd_transfer_state; +return true; + } +return false; +} +/* Return true when buffer is consumed. Configured by sd_cmd_to_sendingdata() */ static bool sd_generic_read_byte (SDState *sd,uint8_t *value) {
PATCH v42 30/98 hw/sd/sdcard: Duplicate WRITE_SINGLE_BLOCK / WRITE_MULTIPLE_BLOCK cases
In reply to Philippe Mathieu-DaudéIn order to modify the WRITE_SINGLE_BLOCK case in the next commit, duplicate it first.
--- hw/sd/sd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
hw/sd/sd.c +29 -0
@@ -1461,6 +1461,35 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)/* Block write commands (Class 4) */ case 24 :/* CMD24: WRITE_SINGLE_BLOCK */ + addr =sd_req_get_address (sd, req); +switch (sd->state) { +case sd_transfer_state: + +if (!address_in_range (sd,"WRITE_SINGLE_BLOCK" , addr, + sd->blk_len)) { +return sd_r1; + } + + sd->state = sd_receivingdata_state; + sd->data_start = addr; + sd->data_offset =0 ; + +if (sd->size <=SDSC_MAX_CAPACITY ) { +if (sd_wp_addr (sd, sd->data_start)) { + sd->card_status |=WP_VIOLATION ; + } + } +if (sd->csd[14 ] &0x30 ) { + sd->card_status |=WP_VIOLATION ; + } + sd->blk_written =0 ; +return sd_r1; + +default : +break ; + } +break ; +case 25 :/* CMD25: WRITE_MULTIPLE_BLOCK */ addr =sd_req_get_address (sd, req);switch (sd->state) {
Signature · 1 line
2.41.0
Re: [PATCH v42 30/98] hw/sd/sdcard: Duplicate WRITE_SINGLE_BLOCK / WRITE_MULTIPLE_BLOCK cases
Quoted 4 lines · Philippe Mathieu-Daudé
In order to modify the
WRITE_SINGLE_BLOCKcase in the next commit, duplicate it first.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 44 lines
--- hw/sd/sd.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)hw/sd/sd.c +29
-0@@ -1461,6 +1461,35 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)/* Block write commands (Class 4) */ case 24 :/* CMD24: WRITE_SINGLE_BLOCK */ + addr =sd_req_get_address (sd, req); +switch (sd->state) { +case sd_transfer_state: + +if (!address_in_range (sd,"WRITE_SINGLE_BLOCK" , addr, + sd->blk_len)) { +return sd_r1; + } + + sd->state = sd_receivingdata_state; + sd->data_start = addr; + sd->data_offset =0 ; + +if (sd->size <=SDSC_MAX_CAPACITY ) { +if (sd_wp_addr (sd, sd->data_start)) { + sd->card_status |=WP_VIOLATION ; + } + } +if (sd->csd[14 ] &0x30 ) { + sd->card_status |=WP_VIOLATION ; + } + sd->blk_written =0 ; +return sd_r1; + +default : +break ; + } +break ; +case 25 :/* CMD25: WRITE_MULTIPLE_BLOCK */ addr =sd_req_get_address (sd, req);switch (sd->state) {
PATCH v42 31/98 hw/sd/sdcard: Convert WRITE_SINGLE_BLOCK to generic_write_byte (CMD24)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- hw/sd/sd.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
hw/sd/sd.c +2 -9
@@ -1101,7 +1101,6 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) }/* Configure fields for following sd_generic_write_byte() calls */ -__attribute__((unused))static sd_rsp_type_t sd_cmd_to_receivingdata (SDState *sd,SDRequest req,uint64_t start,size_t size) {
@@ -1470,10 +1469,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_r1; } - sd->state = sd_receivingdata_state; - sd->data_start = addr; - sd->data_offset =0 ; -if (sd->size <=SDSC_MAX_CAPACITY ) {if (sd_wp_addr (sd, sd->data_start)) { sd->card_status |=WP_VIOLATION ;
@@ -1483,7 +1478,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->card_status |=WP_VIOLATION ; } sd->blk_written =0 ; -return sd_r1; +return sd_cmd_to_receivingdata (sd, req, addr, sd->blk_len);default :break ;
@@ -1999,7 +1994,6 @@ send_response: }/* Return true if buffer is consumed. Configured by sd_cmd_to_receivingdata() */ -__attribute__((unused))static bool sd_generic_write_byte (SDState *sd,uint8_t value) { sd->data[sd->data_offset] = value;
@@ -2045,8 +2039,7 @@ void sd_write_byte(SDState *sd, uint8_t value) sd->current_cmd, sd->data_offset, value);switch (sd->current_cmd) {case 24 :/* CMD24: WRITE_SINGLE_BLOCK */ - sd->data[sd->data_offset ++] = value; -if (sd->data_offset >= sd->blk_len) { +if (sd_generic_write_byte (sd, value)) {/* TODO: Check CRC before committing */ sd->state = sd_programming_state;sd_blk_write (sd, sd->data_start, sd->data_offset);
Signature · 1 line
2.41.0
Re: [PATCH v42 31/98] hw/sd/sdcard: Convert WRITE_SINGLE_BLOCK to generic_write_byte (CMD24)
Quoted 4 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 54 lines
--- hw/sd/sd.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)hw/sd/sd.c +2
-9@@ -1101,7 +1101,6 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req) }/* Configure fields for following sd_generic_write_byte() calls */ -__attribute__((unused))static sd_rsp_type_t sd_cmd_to_receivingdata (SDState *sd,SDRequest req,uint64_t start,size_t size) {@@ -1470,10 +1469,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_r1; } - sd->state = sd_receivingdata_state; - sd->data_start = addr; - sd->data_offset =0 ; -if (sd->size <=SDSC_MAX_CAPACITY ) {if (sd_wp_addr (sd, sd->data_start)) { sd->card_status |=WP_VIOLATION ;@@ -1483,7 +1478,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->card_status |=WP_VIOLATION ; } sd->blk_written =0 ; -return sd_r1; +return sd_cmd_to_receivingdata (sd, req, addr, sd->blk_len);default :break ;@@ -1999,7 +1994,6 @@ send_response: }/* Return true if buffer is consumed. Configured by sd_cmd_to_receivingdata() */ -__attribute__((unused))static bool sd_generic_write_byte (SDState *sd,uint8_t value) { sd->data[sd->data_offset] = value;@@ -2045,8 +2039,7 @@ void sd_write_byte(SDState *sd, uint8_t value) sd->current_cmd, sd->data_offset, value);switch (sd->current_cmd) {case 24 :/* CMD24: WRITE_SINGLE_BLOCK */ - sd->data[sd->data_offset ++] = value; -if (sd->data_offset >= sd->blk_len) { +if (sd_generic_write_byte (sd, value)) {/* TODO: Check CRC before committing */ sd->state = sd_programming_state;sd_blk_write (sd, sd->data_start, sd->data_offset);
PATCH v42 32/98 hw/sd/sdcard: Convert PROGRAM_CID to generic_write_byte (CMD26)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
hw/sd/sd.c +2 -13
@@ -1515,17 +1515,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)break ;case 26 :/* CMD26: PROGRAM_CID */ -switch (sd->state) { -case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; - -default : -break ; - } -break ; +return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));case 27 :/* CMD27: PROGRAM_CSD */ switch (sd->state) {
@@ -2088,8 +2078,7 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;case 26 :/* CMD26: PROGRAM_CID */ - sd->data[sd->data_offset ++] = value; -if (sd->data_offset >=sizeof (sd->cid)) { +if (sd_generic_write_byte (sd, value)) {/* TODO: Check CRC before committing */ sd->state = sd_programming_state;for (i =0 ; i <sizeof (sd->cid); i ++)
Signature · 1 line
2.41.0
Re: [PATCH v42 32/98] hw/sd/sdcard: Convert PROGRAM_CID to generic_write_byte (CMD26)
Quoted 4 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 37 lines
--- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)hw/sd/sd.c +2
-13@@ -1515,17 +1515,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)break ;case 26 :/* CMD26: PROGRAM_CID */ -switch (sd->state) { -case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; - -default : -break ; - } -break ; +return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));case 27 :/* CMD27: PROGRAM_CSD */ switch (sd->state) {@@ -2088,8 +2078,7 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;case 26 :/* CMD26: PROGRAM_CID */ - sd->data[sd->data_offset ++] = value; -if (sd->data_offset >=sizeof (sd->cid)) { +if (sd_generic_write_byte (sd, value)) {/* TODO: Check CRC before committing */ sd->state = sd_programming_state;for (i =0 ; i <sizeof (sd->cid); i ++)
PATCH v42 33/98 hw/sd/sdcard: Convert PROGRAM_CSD to generic_write_byte (CMD27)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
hw/sd/sd.c +2 -13
@@ -1518,17 +1518,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));case 27 :/* CMD27: PROGRAM_CSD */ -switch (sd->state) { -case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; - -default : -break ; - } -break ; +return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->csd));/* Write protection (Class 6) */ case 28 :/* CMD28: SET_WRITE_PROT */
@@ -2096,8 +2086,7 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;case 27 :/* CMD27: PROGRAM_CSD */ - sd->data[sd->data_offset ++] = value; -if (sd->data_offset >=sizeof (sd->csd)) { +if (sd_generic_write_byte (sd, value)) {/* TODO: Check CRC before committing */ sd->state = sd_programming_state;for (i =0 ; i <sizeof (sd->csd); i ++)
Signature · 1 line
2.41.0
Re: [PATCH v42 33/98] hw/sd/sdcard: Convert PROGRAM_CSD to generic_write_byte (CMD27)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 37 lines
--- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)hw/sd/sd.c +2
-13@@ -1518,17 +1518,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));case 27 :/* CMD27: PROGRAM_CSD */ -switch (sd->state) { -case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; - -default : -break ; - } -break ; +return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->csd));/* Write protection (Class 6) */ case 28 :/* CMD28: SET_WRITE_PROT */ @@ -2096,8 +2086,7 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;case 27 :/* CMD27: PROGRAM_CSD */ - sd->data[sd->data_offset ++] = value; -if (sd->data_offset >=sizeof (sd->csd)) { +if (sd_generic_write_byte (sd, value)) {/* TODO: Check CRC before committing */ sd->state = sd_programming_state;for (i =0 ; i <sizeof (sd->csd); i ++)
PATCH v42 34/98 hw/sd/sdcard: Convert LOCK_UNLOCK to generic_write_byte (CMD42)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
hw/sd/sd.c +2 -13
@@ -1628,17 +1628,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)/* Lock card commands (Class 7) */ case 42 :/* CMD42: LOCK_UNLOCK */ -switch (sd->state) { -case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; - -default : -break ; - } -break ; +return sd_cmd_to_receivingdata (sd, req,0 ,0 );/* Application specific commands (Class 8) */ case 55 :/* CMD55: APP_CMD */
@@ -2109,8 +2099,7 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;case 42 :/* CMD42: LOCK_UNLOCK */ - sd->data[sd->data_offset ++] = value; -if (sd->data_offset >= sd->blk_len) { +if (sd_generic_write_byte (sd, value)) {/* TODO: Check CRC before committing */ sd->state = sd_programming_state;sd_lock_command (sd);
Signature · 1 line
2.41.0
Re: [PATCH v42 34/98] hw/sd/sdcard: Convert LOCK_UNLOCK to generic_write_byte (CMD42)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 37 lines
--- hw/sd/sd.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)hw/sd/sd.c +2
-13@@ -1628,17 +1628,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)/* Lock card commands (Class 7) */ case 42 :/* CMD42: LOCK_UNLOCK */ -switch (sd->state) { -case sd_transfer_state: - sd->state = sd_receivingdata_state; - sd->data_start =0 ; - sd->data_offset =0 ; -return sd_r1; - -default : -break ; - } -break ; +return sd_cmd_to_receivingdata (sd, req,0 ,0 );/* Application specific commands (Class 8) */ case 55 :/* CMD55: APP_CMD */ @@ -2109,8 +2099,7 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;case 42 :/* CMD42: LOCK_UNLOCK */ - sd->data[sd->data_offset ++] = value; -if (sd->data_offset >= sd->blk_len) { +if (sd_generic_write_byte (sd, value)) {/* TODO: Check CRC before committing */ sd->state = sd_programming_state;sd_lock_command (sd);
PATCH v42 35/98 hw/sd/sdcard: Convert GEN_CMD to generic_write_byte (CMD56)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
hw/sd/sd.c +3 -6
@@ -1657,14 +1657,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 56 :/* CMD56: GEN_CMD */ switch (sd->state) {case sd_transfer_state: - sd->data_offset =0 ;if (req.arg &1 ) {return sd_cmd_to_sendingdata (sd, req,0 , sd->vendor_data,sizeof (sd->vendor_data)); } - sd->state = sd_receivingdata_state; -return sd_r1; +return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->vendor_data));default :break ;
@@ -2109,9 +2107,8 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;case 56 :/* CMD56: GEN_CMD */ - sd->vendor_data[sd->data_offset ++] = value; -if (sd->data_offset >=sizeof (sd->vendor_data)) { - sd->state = sd_transfer_state; +if (sd_generic_write_byte (sd, value)) { +memcpy (sd->vendor_data, sd->data,sizeof (sd->vendor_data)); }break ;
Signature · 1 line
2.41.0
Re: [PATCH v42 35/98] hw/sd/sdcard: Convert GEN_CMD to generic_write_byte (CMD56)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 36 lines
--- hw/sd/sd.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)hw/sd/sd.c +3
-6@@ -1657,14 +1657,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 56 :/* CMD56: GEN_CMD */ switch (sd->state) {case sd_transfer_state: - sd->data_offset =0 ;if (req.arg &1 ) {return sd_cmd_to_sendingdata (sd, req,0 , sd->vendor_data,sizeof (sd->vendor_data)); } - sd->state = sd_receivingdata_state; -return sd_r1; +return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->vendor_data));default :break ;@@ -2109,9 +2107,8 @@ void sd_write_byte(SDState *sd, uint8_t value)break ;case 56 :/* CMD56: GEN_CMD */ - sd->vendor_data[sd->data_offset ++] = value; -if (sd->data_offset >=sizeof (sd->vendor_data)) { - sd->state = sd_transfer_state; +if (sd_generic_write_byte (sd, value)) { +memcpy (sd->vendor_data, sd->data,sizeof (sd->vendor_data)); }break ;
PATCH v42 36/98 hw/sd/sdcard: Move sd_[a]cmd_name() methods to sd.c
In reply to Philippe Mathieu-DaudéMerge sdmmc-internal.c into sd.c by movingsd_cmd_name() and sd_acmd_name() and updating
meson.build.
--- hw/sd/sdmmc-internal.h | 26 --------------- hw/sd/sd.c | 62 ++++++++++++++++++++++++++++++++++++ hw/sd/sdmmc-internal.c | 72 ------------------------------------------ hw/sd/meson.build | 2 +- 4 files changed, 63 insertions(+), 99 deletions(-) delete mode 100644 hw/sd/sdmmc-internal.c
hw/sd/sdmmc-internal.h +0 -26
@@ -108,30 +108,4 @@#define EXT_CSD_PART_CONFIG_EN_BOOT0 (0x1 << 3)#define EXT_CSD_PART_CONFIG_EN_USER (0x7 << 3) -#define SDMMC_CMD_MAX 64 - -/** -* sd_cmd_name: -* @cmd: A SD "normal" command, up to SDMMC_CMD_MAX. -* -* Returns a human-readable name describing the command. -* The return value is always a static string which does not need -* to be freed after use. -* -* Returns: The command name of @cmd or "UNKNOWN_CMD". -*/ -const char *sd_cmd_name (uint8_t cmd); - -/** -* sd_acmd_name: -* @cmd: A SD "Application-Specific" command, up to SDMMC_CMD_MAX. -* -* Returns a human-readable name describing the application command. -* The return value is always a static string which does not need -* to be freed after use. -* -* Returns: The application command name of @cmd or "UNKNOWN_ACMD". -*/ -const char *sd_acmd_name (uint8_t cmd); -#endif
hw/sd/sd.c +62 -0
74 lines not on this page · raw message
hw/sd/sdmmc-internal.c deleted +0 -72
72 lines not on this page · raw message
hw/sd/meson.build +1 -1
@@ -1,5 +1,5 @@ system_ss.add(when: 'CONFIG_PL181', if_true: files('pl181.c')) -system_ss.add(when: 'CONFIG_SD', if_true: files('sd.c', 'core.c', 'sdmmc-internal.c')) +system_ss.add(when: 'CONFIG_SD', if_true: files('sd.c', 'core.c')) system_ss.add(when: 'CONFIG_SDHCI', if_true: files('sdhci.c')) system_ss.add(when: 'CONFIG_SDHCI_PCI', if_true: files('sdhci-pci.c')) system_ss.add(when: 'CONFIG_SSI_SD', if_true: files('ssi-sd.c'))
Signature · 1 line
2.41.0
Re: [PATCH v42 36/98] hw/sd/sdcard: Move sd_[a]cmd_name() methods to sd.c
Quoted 5 lines · Philippe Mathieu-Daudé
Merge
sdmmc-internal.cintosd.cby movingsd_cmd_name()andsd_acmd_name()and updating
meson.build.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 212 lines
--- hw/sd/sdmmc-internal.h | 26 --------------- hw/sd/sd.c | 62 ++++++++++++++++++++++++++++++++++++ hw/sd/sdmmc-internal.c | 72 ------------------------------------------ hw/sd/meson.build | 2 +- 4 files changed, 63 insertions(+), 99 deletions(-)delete mode 100644
hw/sd/sdmmc-internal.chw/sd/sdmmc-internal.h +0
-26@@ -108,30 +108,4 @@#define EXT_CSD_PART_CONFIG_EN_BOOT0 (0x1 << 3)#define EXT_CSD_PART_CONFIG_EN_USER (0x7 << 3) -#define SDMMC_CMD_MAX 64 - -/** -* sd_cmd_name: -* @cmd: A SD "normal" command, up to SDMMC_CMD_MAX. -* -* Returns a human-readable name describing the command. -* The return value is always a static string which does not need -* to be freed after use. -* -* Returns: The command name of @cmd or "UNKNOWN_CMD". -*/ -const char *sd_cmd_name (uint8_t cmd); - -/** -* sd_acmd_name: -* @cmd: A SD "Application-Specific" command, up to SDMMC_CMD_MAX. -* -* Returns a human-readable name describing the application command. -* The return value is always a static string which does not need -* to be freed after use. -* -* Returns: The application command name of @cmd or "UNKNOWN_ACMD". -*/ -const char *sd_acmd_name (uint8_t cmd); -#endif hw/sd/sd.c +62
-0@@ -88,6 +88,8 @@ enum SDCardStates { sd_disconnect_state = 8, }; +#define SDMMC_CMD_MAX 64 +typedef sd_rsp_type_t (*sd_cmd_handler )(SDState *sd,SDRequest req); typedef struct SDProto {@@ -231,6 +233,66 @@ static const char *sd_response_name(sd_rsp_type_t rsp)return response_name[rsp]; } +static const char *sd_cmd_name (uint8_t cmd) +{ +static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { + [0 ] ="GO_IDLE_STATE" , [1 ] ="SEND_OP_COND" , + [2 ] ="ALL_SEND_CID" , [3 ] ="SEND_RELATIVE_ADDR" , + [4 ] ="SET_DSR" , [5 ] ="IO_SEND_OP_COND" , + [6 ] ="SWITCH_FUNC" , [7 ] ="SELECT/DESELECT_CARD" , + [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , + [10 ] ="SEND_CID" , [11 ] ="VOLTAGE_SWITCH" , + [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" , + [15 ] ="GO_INACTIVE_STATE" , + [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" , + [18 ] ="READ_MULTIPLE_BLOCK" , [19 ] ="SEND_TUNING_BLOCK" , + [20 ] ="SPEED_CLASS_CONTROL" , [21 ] ="DPS_spec" , + [23 ] ="SET_BLOCK_COUNT" , + [24 ] ="WRITE_BLOCK" , [25 ] ="WRITE_MULTIPLE_BLOCK" , + [26 ] ="MANUF_RSVD" , [27 ] ="PROGRAM_CSD" , + [28 ] ="SET_WRITE_PROT" , [29 ] ="CLR_WRITE_PROT" , + [30 ] ="SEND_WRITE_PROT" , + [32 ] ="ERASE_WR_BLK_START" , [33 ] ="ERASE_WR_BLK_END" , + [34 ] ="SW_FUNC_RSVD" , [35 ] ="SW_FUNC_RSVD" , + [36 ] ="SW_FUNC_RSVD" , [37 ] ="SW_FUNC_RSVD" , + [38 ] ="ERASE" , + [40 ] ="DPS_spec" , + [42 ] ="LOCK_UNLOCK" , [43 ] ="Q_MANAGEMENT" , + [44 ] ="Q_TASK_INFO_A" , [45 ] ="Q_TASK_INFO_B" , + [46 ] ="Q_RD_TASK" , [47 ] ="Q_WR_TASK" , + [48 ] ="READ_EXTR_SINGLE" , [49 ] ="WRITE_EXTR_SINGLE" , + [50 ] ="SW_FUNC_RSVD" , + [52 ] ="IO_RW_DIRECT" , [53 ] ="IO_RW_EXTENDED" , + [54 ] ="SDIO_RSVD" , [55 ] ="APP_CMD" , + [56 ] ="GEN_CMD" , [57 ] ="SW_FUNC_RSVD" , + [58 ] ="READ_EXTR_MULTI" , [59 ] ="WRITE_EXTR_MULTI" , + [60 ] ="MANUF_RSVD" , [61 ] ="MANUF_RSVD" , + [62 ] ="MANUF_RSVD" , [63 ] ="MANUF_RSVD" , + }; +return cmd_abbrev[cmd] ? cmd_abbrev[cmd] :"UNKNOWN_CMD" ; +} + +static const char *sd_acmd_name (uint8_t cmd) +{ +static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { + [6 ] ="SET_BUS_WIDTH" , + [13 ] ="SD_STATUS" , + [14 ] ="DPS_spec" , [15 ] ="DPS_spec" , + [16 ] ="DPS_spec" , + [18 ] ="SECU_spec" , + [22 ] ="SEND_NUM_WR_BLOCKS" , [23 ] ="SET_WR_BLK_ERASE_COUNT" , + [41 ] ="SD_SEND_OP_COND" , + [42 ] ="SET_CLR_CARD_DETECT" , + [51 ] ="SEND_SCR" , + [52 ] ="SECU_spec" , [53 ] ="SECU_spec" , + [54 ] ="SECU_spec" , + [56 ] ="SECU_spec" , [57 ] ="SECU_spec" , + [58 ] ="SECU_spec" , [59 ] ="SECU_spec" , + }; + +return acmd_abbrev[cmd] ? acmd_abbrev[cmd] :"UNKNOWN_ACMD" ; +} +static uint8_t sd_get_dat_lines (SDState *sd) {return sd->enable ? sd->dat_lines :0 ;hw/sd/sdmmc-internal.c deleted +0
-72@@ -1,72 +0,0 @@ -/* -* SD/MMC cards common helpers -* -* Copyright (c) 2018 Philippe Mathieu-Daudé <[email protected]> -* -* This work is licensed under the terms of the GNU GPL, version 2 or later. -* See the COPYING file in the top-level directory. -* SPDX-License-Identifier: GPL-2.0-or-later -*/ - -#include "qemu/osdep.h" -#include "sdmmc-internal.h" - -const char *sd_cmd_name (uint8_t cmd) -{ -static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [0 ] ="GO_IDLE_STATE" , [1 ] ="SEND_OP_COND" , - [2 ] ="ALL_SEND_CID" , [3 ] ="SEND_RELATIVE_ADDR" , - [4 ] ="SET_DSR" , [5 ] ="IO_SEND_OP_COND" , - [6 ] ="SWITCH_FUNC" , [7 ] ="SELECT/DESELECT_CARD" , - [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , - [10 ] ="SEND_CID" , [11 ] ="VOLTAGE_SWITCH" , - [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" , - [15 ] ="GO_INACTIVE_STATE" , - [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" , - [18 ] ="READ_MULTIPLE_BLOCK" , [19 ] ="SEND_TUNING_BLOCK" , - [20 ] ="SPEED_CLASS_CONTROL" , [21 ] ="DPS_spec" , - [23 ] ="SET_BLOCK_COUNT" , - [24 ] ="WRITE_BLOCK" , [25 ] ="WRITE_MULTIPLE_BLOCK" , - [26 ] ="MANUF_RSVD" , [27 ] ="PROGRAM_CSD" , - [28 ] ="SET_WRITE_PROT" , [29 ] ="CLR_WRITE_PROT" , - [30 ] ="SEND_WRITE_PROT" , - [32 ] ="ERASE_WR_BLK_START" , [33 ] ="ERASE_WR_BLK_END" , - [34 ] ="SW_FUNC_RSVD" , [35 ] ="SW_FUNC_RSVD" , - [36 ] ="SW_FUNC_RSVD" , [37 ] ="SW_FUNC_RSVD" , - [38 ] ="ERASE" , - [40 ] ="DPS_spec" , - [42 ] ="LOCK_UNLOCK" , [43 ] ="Q_MANAGEMENT" , - [44 ] ="Q_TASK_INFO_A" , [45 ] ="Q_TASK_INFO_B" , - [46 ] ="Q_RD_TASK" , [47 ] ="Q_WR_TASK" , - [48 ] ="READ_EXTR_SINGLE" , [49 ] ="WRITE_EXTR_SINGLE" , - [50 ] ="SW_FUNC_RSVD" , - [52 ] ="IO_RW_DIRECT" , [53 ] ="IO_RW_EXTENDED" , - [54 ] ="SDIO_RSVD" , [55 ] ="APP_CMD" , - [56 ] ="GEN_CMD" , [57 ] ="SW_FUNC_RSVD" , - [58 ] ="READ_EXTR_MULTI" , [59 ] ="WRITE_EXTR_MULTI" , - [60 ] ="MANUF_RSVD" , [61 ] ="MANUF_RSVD" , - [62 ] ="MANUF_RSVD" , [63 ] ="MANUF_RSVD" , - }; -return cmd_abbrev[cmd] ? cmd_abbrev[cmd] :"UNKNOWN_CMD" ; -} - -const char *sd_acmd_name (uint8_t cmd) -{ -static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { - [6 ] ="SET_BUS_WIDTH" , - [13 ] ="SD_STATUS" , - [14 ] ="DPS_spec" , [15 ] ="DPS_spec" , - [16 ] ="DPS_spec" , - [18 ] ="SECU_spec" , - [22 ] ="SEND_NUM_WR_BLOCKS" , [23 ] ="SET_WR_BLK_ERASE_COUNT" , - [41 ] ="SD_SEND_OP_COND" , - [42 ] ="SET_CLR_CARD_DETECT" , - [51 ] ="SEND_SCR" , - [52 ] ="SECU_spec" , [53 ] ="SECU_spec" , - [54 ] ="SECU_spec" , - [56 ] ="SECU_spec" , [57 ] ="SECU_spec" , - [58 ] ="SECU_spec" , [59 ] ="SECU_spec" , - }; - -return acmd_abbrev[cmd] ? acmd_abbrev[cmd] :"UNKNOWN_ACMD" ; -}hw/sd/meson.build +1
-1@@ -1,5 +1,5 @@ system_ss.add(when: 'CONFIG_PL181', if_true: files('pl181.c')) -system_ss.add(when: 'CONFIG_SD', if_true: files('sd.c', 'core.c', 'sdmmc-internal.c')) +system_ss.add(when: 'CONFIG_SD', if_true: files('sd.c', 'core.c')) system_ss.add(when: 'CONFIG_SDHCI', if_true: files('sdhci.c')) system_ss.add(when: 'CONFIG_SDHCI_PCI', if_true: files('sdhci-pci.c')) system_ss.add(when: 'CONFIG_SSI_SD', if_true: files('ssi-sd.c'))
PATCH v42 37/98 hw/sd/sdcard: Pass SDState as argument to sd_[a]cmd_name()
In reply to Philippe Mathieu-DaudéIn order to access SDState::SDProto from sd_[a]cmd_name(), pass SDState as argument.
--- hw/sd/sd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
hw/sd/sd.c +4 -4
@@ -233,7 +233,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)return response_name[rsp]; } -static const char *sd_cmd_name (uint8_t cmd) +static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { [0 ] ="GO_IDLE_STATE" , [1 ] ="SEND_OP_COND" ,
@@ -272,7 +272,7 @@ static const char *sd_cmd_name(uint8_t cmd)return cmd_abbrev[cmd] ? cmd_abbrev[cmd] :"UNKNOWN_CMD" ; } -static const char *sd_acmd_name (uint8_t cmd) +static const char *sd_acmd_name (SDState *sd,uint8_t cmd) {static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { [6 ] ="SET_BUS_WIDTH" ,
@@ -1281,7 +1281,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)uint64_t addr;uint32_t data; - sd->last_cmd_name =sd_cmd_name (req.cmd); + sd->last_cmd_name =sd_cmd_name (sd, req.cmd);/* CMD55 precedes an ACMD, so we are not interested in tracing it. * However there is no ACMD55, so we want to trace this particular case. */
@@ -1748,7 +1748,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)static sd_rsp_type_t sd_app_command (SDState *sd,SDRequest req) { - sd->last_cmd_name =sd_acmd_name (req.cmd); + sd->last_cmd_name =sd_acmd_name (sd, req.cmd);trace_sdcard_app_command (sd->proto->name, sd->last_cmd_name, req.cmd, req.arg,sd_state_name (sd->state)); sd->card_status |=APP_CMD ;
Signature · 1 line
2.41.0
Re: [PATCH v42 37/98] hw/sd/sdcard: Pass SDState as argument to sd_[a]cmd_name()
Quoted 4 lines · Philippe Mathieu-Daudé
In order to access
SDState::SDProtofrom sd_[a]cmd_name(), pass SDState as argument.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 44 lines
--- hw/sd/sd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)hw/sd/sd.c +4
-4@@ -233,7 +233,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)return response_name[rsp]; } -static const char *sd_cmd_name (uint8_t cmd) +static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { [0 ] ="GO_IDLE_STATE" , [1 ] ="SEND_OP_COND" ,@@ -272,7 +272,7 @@ static const char *sd_cmd_name(uint8_t cmd)return cmd_abbrev[cmd] ? cmd_abbrev[cmd] :"UNKNOWN_CMD" ; } -static const char *sd_acmd_name (uint8_t cmd) +static const char *sd_acmd_name (SDState *sd,uint8_t cmd) {static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { [6 ] ="SET_BUS_WIDTH" ,@@ -1281,7 +1281,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)uint64_t addr;uint32_t data; - sd->last_cmd_name =sd_cmd_name (req.cmd); + sd->last_cmd_name =sd_cmd_name (sd, req.cmd);/* CMD55 precedes an ACMD, so we are not interested in tracing it. * However there is no ACMD55, so we want to trace this particular case. */ @@ -1748,7 +1748,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)static sd_rsp_type_t sd_app_command (SDState *sd,SDRequest req) { - sd->last_cmd_name =sd_acmd_name (req.cmd); + sd->last_cmd_name =sd_acmd_name (sd, req.cmd);trace_sdcard_app_command (sd->proto->name, sd->last_cmd_name, req.cmd, req.arg,sd_state_name (sd->state)); sd->card_status |=APP_CMD ;
PATCH v42 38/98 hw/sd/sdcard: Prepare SDProto to contain more fields
In reply to Philippe Mathieu-DaudéConvert array of command handlers to array of structures. The structure contains the command handler. No logical change intended.
--- hw/sd/sd.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)
hw/sd/sd.c +15 -14
@@ -94,8 +94,9 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req);typedef struct SDProto {const char *name; -sd_cmd_handler cmd[SDMMC_CMD_MAX ]; -sd_cmd_handler acmd[SDMMC_CMD_MAX ]; +struct { +sd_cmd_handler handler; + } cmd[SDMMC_CMD_MAX ], acmd[SDMMC_CMD_MAX ]; }SDProto ;struct SDState {
@@ -1305,8 +1306,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_illegal; } -if (sd->proto->cmd[req.cmd]) { -return sd->proto->cmd[req.cmd](sd, req); +if (sd->proto->cmd[req.cmd].handler) { +return sd->proto->cmd[req.cmd].handler (sd, req); }switch (req.cmd) {
@@ -1753,8 +1754,8 @@ static sd_rsp_type_t sd_app_command(SDState *sd, req.cmd, req.arg, sd_state_name(sd->state)); sd->card_status |=APP_CMD ; -if (sd->proto->acmd[req.cmd]) { -return sd->proto->acmd[req.cmd](sd, req); +if (sd->proto->acmd[req.cmd].handler) { +return sd->proto->acmd[req.cmd].handler (sd, req); }switch (req.cmd) {
@@ -2267,22 +2268,22 @@ void sd_enable(SDState *sd, bool enable)static const SDProto sd_proto_spi = { .name ="SPI" , .cmd = { - [0 ] = sd_cmd_GO_IDLE_STATE, - [1 ] = spi_cmd_SEND_OP_COND, + [0 ] = {sd_cmd_GO_IDLE_STATE}, + [1 ] = {spi_cmd_SEND_OP_COND}, }, .acmd = { - [41 ] = spi_cmd_SEND_OP_COND, + [41 ] = {spi_cmd_SEND_OP_COND}, }, };static const SDProto sd_proto_sd = { .name ="SD" , .cmd = { - [0 ] = sd_cmd_GO_IDLE_STATE, - [2 ] = sd_cmd_ALL_SEND_CID, - [3 ] = sd_cmd_SEND_RELATIVE_ADDR, - [19 ] = sd_cmd_SEND_TUNING_BLOCK, - [23 ] = sd_cmd_SET_BLOCK_COUNT, + [0 ] = {sd_cmd_GO_IDLE_STATE}, + [2 ] = {sd_cmd_ALL_SEND_CID}, + [3 ] = {sd_cmd_SEND_RELATIVE_ADDR}, + [19 ] = {sd_cmd_SEND_TUNING_BLOCK}, + [23 ] = {sd_cmd_SET_BLOCK_COUNT}, }, };
Signature · 1 line
2.41.0
Re: [PATCH v42 38/98] hw/sd/sdcard: Prepare SDProto to contain more fields
Quoted 5 lines · Philippe Mathieu-Daudé
Convert array of command handlers to array of structures. The structure contains the command handler. No logical change intended.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 73 lines
--- hw/sd/sd.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-)hw/sd/sd.c +15
-14@@ -94,8 +94,9 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req);typedef struct SDProto {const char *name; -sd_cmd_handler cmd[SDMMC_CMD_MAX ]; -sd_cmd_handler acmd[SDMMC_CMD_MAX ]; +struct { +sd_cmd_handler handler; + } cmd[SDMMC_CMD_MAX ], acmd[SDMMC_CMD_MAX ]; }SDProto ;struct SDState {@@ -1305,8 +1306,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_illegal; } -if (sd->proto->cmd[req.cmd]) { -return sd->proto->cmd[req.cmd](sd, req); +if (sd->proto->cmd[req.cmd].handler) { +return sd->proto->cmd[req.cmd].handler (sd, req); }switch (req.cmd) {@@ -1753,8 +1754,8 @@ static sd_rsp_type_t sd_app_command(SDState *sd, req.cmd, req.arg, sd_state_name(sd->state)); sd->card_status |=APP_CMD ; -if (sd->proto->acmd[req.cmd]) { -return sd->proto->acmd[req.cmd](sd, req); +if (sd->proto->acmd[req.cmd].handler) { +return sd->proto->acmd[req.cmd].handler (sd, req); }switch (req.cmd) {@@ -2267,22 +2268,22 @@ void sd_enable(SDState *sd, bool enable)static const SDProto sd_proto_spi = { .name ="SPI" , .cmd = { - [0 ] = sd_cmd_GO_IDLE_STATE, - [1 ] = spi_cmd_SEND_OP_COND, + [0 ] = {sd_cmd_GO_IDLE_STATE}, + [1 ] = {spi_cmd_SEND_OP_COND}, }, .acmd = { - [41 ] = spi_cmd_SEND_OP_COND, + [41 ] = {spi_cmd_SEND_OP_COND}, }, };static const SDProto sd_proto_sd = { .name ="SD" , .cmd = { - [0 ] = sd_cmd_GO_IDLE_STATE, - [2 ] = sd_cmd_ALL_SEND_CID, - [3 ] = sd_cmd_SEND_RELATIVE_ADDR, - [19 ] = sd_cmd_SEND_TUNING_BLOCK, - [23 ] = sd_cmd_SET_BLOCK_COUNT, + [0 ] = {sd_cmd_GO_IDLE_STATE}, + [2 ] = {sd_cmd_ALL_SEND_CID}, + [3 ] = {sd_cmd_SEND_RELATIVE_ADDR}, + [19 ] = {sd_cmd_SEND_TUNING_BLOCK}, + [23 ] = {sd_cmd_SET_BLOCK_COUNT}, }, };
PATCH v42 39/98 hw/sd/sdcard: Store command name in SDProto
In reply to Philippe Mathieu-DaudéWe already have a const array where command handlers are listed. Store the command name there too.
--- hw/sd/sd.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-)
hw/sd/sd.c +22 -13
@@ -95,6 +95,7 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req);typedef struct SDProto {const char *name;struct { +const char *name;sd_cmd_handler handler; } cmd[SDMMC_CMD_MAX ], acmd[SDMMC_CMD_MAX ]; }SDProto ;
@@ -237,8 +238,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [0 ] ="GO_IDLE_STATE" , [1 ] ="SEND_OP_COND" , - [2 ] ="ALL_SEND_CID" , [3 ] ="SEND_RELATIVE_ADDR" , [4 ] ="SET_DSR" , [5 ] ="IO_SEND_OP_COND" , [6 ] ="SWITCH_FUNC" , [7 ] ="SELECT/DESELECT_CARD" , [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" ,
@@ -246,9 +245,8 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", [15] = "GO_INACTIVE_STATE", [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", - [18] = "READ_MULTIPLE_BLOCK", [19] = "SEND_TUNING_BLOCK", + [18] = "READ_MULTIPLE_BLOCK", [20] = "SPEED_CLASS_CONTROL", [21] = "DPS_spec", - [23] = "SET_BLOCK_COUNT", [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT",
@@ -270,6 +268,12 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", }; +const SDProto *sdp = sd->proto; + +if (sdp->cmd[cmd].handler) { +assert (!cmd_abbrev[cmd]); +return sdp->cmd[cmd].name; + }return cmd_abbrev[cmd] ? cmd_abbrev[cmd] :"UNKNOWN_CMD" ; }
@@ -282,7 +286,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [16] = "DPS_spec", [18] = "SECU_spec", [22] = "SEND_NUM_WR_BLOCKS", [23] = "SET_WR_BLK_ERASE_COUNT", - [41] = "SD_SEND_OP_COND", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec",
@@ -290,6 +293,12 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [56] = "SECU_spec", [57] = "SECU_spec", [58] = "SECU_spec", [59] = "SECU_spec", }; +const SDProto *sdp = sd->proto; + +if (sdp->acmd[cmd].handler) { +assert (!acmd_abbrev[cmd]); +return sdp->acmd[cmd].name; + }return acmd_abbrev[cmd] ? acmd_abbrev[cmd] :"UNKNOWN_ACMD" ; }
@@ -2268,22 +2277,22 @@ void sd_enable(SDState *sd, bool enable)static const SDProto sd_proto_spi = { .name ="SPI" , .cmd = { - [0 ] = {sd_cmd_GO_IDLE_STATE}, - [1 ] = {spi_cmd_SEND_OP_COND}, + [0 ] = {"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, + [1 ] = {"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, .acmd = { - [41 ] = {spi_cmd_SEND_OP_COND}, + [41 ] = {"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, };static const SDProto sd_proto_sd = { .name ="SD" , .cmd = { - [0 ] = {sd_cmd_GO_IDLE_STATE}, - [2 ] = {sd_cmd_ALL_SEND_CID}, - [3 ] = {sd_cmd_SEND_RELATIVE_ADDR}, - [19 ] = {sd_cmd_SEND_TUNING_BLOCK}, - [23 ] = {sd_cmd_SET_BLOCK_COUNT}, + [0 ] = {"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, + [2 ] = {"ALL_SEND_CID" , sd_cmd_ALL_SEND_CID}, + [3 ] = {"SEND_RELATIVE_ADDR" , sd_cmd_SEND_RELATIVE_ADDR}, + [19 ] = {"SEND_TUNING_BLOCK" , sd_cmd_SEND_TUNING_BLOCK}, + [23 ] = {"SET_BLOCK_COUNT" , sd_cmd_SET_BLOCK_COUNT}, }, };
Signature · 1 line
2.41.0
Re: [PATCH v42 39/98] hw/sd/sdcard: Store command name in SDProto
Quoted 4 lines · Philippe Mathieu-Daudé
We already have a const array where command handlers are listed. Store the command name there too.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 101 lines
--- hw/sd/sd.c | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-)hw/sd/sd.c +22
-13@@ -95,6 +95,7 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req);typedef struct SDProto {const char *name;struct { +const char *name;sd_cmd_handler handler; } cmd[SDMMC_CMD_MAX ], acmd[SDMMC_CMD_MAX ]; }SDProto ;@@ -237,8 +238,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [0 ] ="GO_IDLE_STATE" , [1 ] ="SEND_OP_COND" , - [2 ] ="ALL_SEND_CID" , [3 ] ="SEND_RELATIVE_ADDR" , [4 ] ="SET_DSR" , [5 ] ="IO_SEND_OP_COND" , [6 ] ="SWITCH_FUNC" , [7 ] ="SELECT/DESELECT_CARD" , [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" ,@@ -246,9 +245,8 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", [15] = "GO_INACTIVE_STATE", [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", - [18] = "READ_MULTIPLE_BLOCK", [19] = "SEND_TUNING_BLOCK", + [18] = "READ_MULTIPLE_BLOCK", [20] = "SPEED_CLASS_CONTROL", [21] = "DPS_spec", - [23] = "SET_BLOCK_COUNT", [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT",@@ -270,6 +268,12 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", }; +const SDProto *sdp = sd->proto; + +if (sdp->cmd[cmd].handler) { +assert (!cmd_abbrev[cmd]); +return sdp->cmd[cmd].name; + }return cmd_abbrev[cmd] ? cmd_abbrev[cmd] :"UNKNOWN_CMD" ; }@@ -282,7 +286,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [16] = "DPS_spec", [18] = "SECU_spec", [22] = "SEND_NUM_WR_BLOCKS", [23] = "SET_WR_BLK_ERASE_COUNT", - [41] = "SD_SEND_OP_COND", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec",@@ -290,6 +293,12 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [56] = "SECU_spec", [57] = "SECU_spec", [58] = "SECU_spec", [59] = "SECU_spec", }; +const SDProto *sdp = sd->proto; + +if (sdp->acmd[cmd].handler) { +assert (!acmd_abbrev[cmd]); +return sdp->acmd[cmd].name; + }return acmd_abbrev[cmd] ? acmd_abbrev[cmd] :"UNKNOWN_ACMD" ; }@@ -2268,22 +2277,22 @@ void sd_enable(SDState *sd, bool enable)static const SDProto sd_proto_spi = { .name ="SPI" , .cmd = { - [0 ] = {sd_cmd_GO_IDLE_STATE}, - [1 ] = {spi_cmd_SEND_OP_COND}, + [0 ] = {"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, + [1 ] = {"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, .acmd = { - [41 ] = {spi_cmd_SEND_OP_COND}, + [41 ] = {"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, };static const SDProto sd_proto_sd = { .name ="SD" , .cmd = { - [0 ] = {sd_cmd_GO_IDLE_STATE}, - [2 ] = {sd_cmd_ALL_SEND_CID}, - [3 ] = {sd_cmd_SEND_RELATIVE_ADDR}, - [19 ] = {sd_cmd_SEND_TUNING_BLOCK}, - [23 ] = {sd_cmd_SET_BLOCK_COUNT}, + [0 ] = {"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, + [2 ] = {"ALL_SEND_CID" , sd_cmd_ALL_SEND_CID}, + [3 ] = {"SEND_RELATIVE_ADDR" , sd_cmd_SEND_RELATIVE_ADDR}, + [19 ] = {"SEND_TUNING_BLOCK" , sd_cmd_SEND_TUNING_BLOCK}, + [23 ] = {"SET_BLOCK_COUNT" , sd_cmd_SET_BLOCK_COUNT}, }, };
PATCH v42 40/98 hw/sd/sdcard: Store command type in SDProto
In reply to Philippe Mathieu-DaudéStore the command type altogether with the command handler and name.
--- include/hw/sd/sd.h | 5 +++-- hw/sd/sd.c | 44 ++++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 26 deletions(-)
include/hw/sd/sd.h +3 -2
@@ -76,8 +76,9 @@ typedef enum { } sd_uhs_mode_t; typedef enum { - sd_none = -1, - sd_bc = 0, /* broadcast -- no response */ + sd_none = 0, + sd_spi, + sd_bc, /* broadcast -- no response */ sd_bcr, /* broadcast with response */ sd_ac, /* addressed -- no data transfer */ sd_adtc, /* addressed with data transfer */
hw/sd/sd.c +20 -24
78 lines not on this page · raw message
Signature · 1 line
2.41.0
Re: [PATCH v42 40/98] hw/sd/sdcard: Store command type in SDProto
Quoted 3 lines · Philippe Mathieu-Daudé
Store the command type altogether with the command handler and name.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 107 lines
--- include/hw/sd/sd.h | 5 +++-- hw/sd/sd.c | 44 ++++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 26 deletions(-)include/hw/sd/sd.h +3
-2@@ -76,8 +76,9 @@ typedef enum { } sd_uhs_mode_t; typedef enum { - sd_none = -1, - sd_bc = 0, /* broadcast -- no response */ + sd_none = 0, + sd_spi, + sd_bc, /* broadcast -- no response */ sd_bcr, /* broadcast with response */ sd_ac, /* addressed -- no data transfer */ sd_adtc, /* addressed with data transfer */hw/sd/sd.c +20
-24@@ -95,6 +95,7 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); typedef struct SDProto { const char *name; struct { + const sd_cmd_type_t type; const char *name; sd_cmd_handler handler; } cmd[SDMMC_CMD_MAX], acmd[SDMMC_CMD_MAX];@@ -351,20 +352,6 @@ static void sd_set_mode(SDState *sd) } } -static const sd_cmd_type_t sd_cmd_type[SDMMC_CMD_MAX ] = { - sd_bc, sd_none, sd_bcr, sd_bcr, sd_none, sd_none, sd_none, sd_ac, - sd_bcr, sd_ac, sd_ac, sd_adtc, sd_ac, sd_ac, sd_none, sd_ac, -/* 16 */ - sd_ac, sd_adtc, sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, - sd_adtc, sd_adtc, sd_adtc, sd_adtc, sd_ac, sd_ac, sd_adtc, sd_none, -/* 32 */ - sd_ac, sd_ac, sd_none, sd_none, sd_none, sd_none, sd_ac, sd_none, - sd_none, sd_none, sd_bc, sd_none, sd_none, sd_none, sd_none, sd_none, -/* 48 */ - sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_ac, - sd_adtc, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, sd_none, -}; -static const int sd_cmd_class[SDMMC_CMD_MAX ] = {0 ,0 ,0 ,0 ,0 ,9 ,10 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,0 ,2 ,2 ,2 ,2 ,3 ,3 ,3 ,3 ,4 ,4 ,4 ,4 ,6 ,6 ,6 ,6 ,@@ -571,10 +558,19 @@ static void sd_set_rca(SDState *sd, uint16_t value)static uint16_t sd_req_get_rca (SDState *s,SDRequest req) { -if (sd_cmd_type[req.cmd] == sd_ac || sd_cmd_type[req.cmd] == sd_adtc) { +switch (s->proto->cmd[req.cmd].type) { +case sd_none: +/* Called from legacy code not ported to SDProto array */ +assert (!s->proto->cmd[req.cmd].handler); +/* fall-through */ +case sd_ac: +case sd_adtc:return req.arg >>16 ; +case sd_spi: +g_assert_not_reached (); +default : +return 0 ; } -return 0 ; }/* Card Status register */ @@ -2277,22 +2273,22 @@ void sd_enable(SDState *sd, bool enable)static const SDProto sd_proto_spi = { .name ="SPI" , .cmd = { - [0 ] = {"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, - [1 ] = {"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, + [0 ] = { sd_spi,"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, + [1 ] = { sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, .acmd = { - [41 ] = {"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, + [41 ] = { sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, };static const SDProto sd_proto_sd = { .name ="SD" , .cmd = { - [0 ] = {"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, - [2 ] = {"ALL_SEND_CID" , sd_cmd_ALL_SEND_CID}, - [3 ] = {"SEND_RELATIVE_ADDR" , sd_cmd_SEND_RELATIVE_ADDR}, - [19 ] = {"SEND_TUNING_BLOCK" , sd_cmd_SEND_TUNING_BLOCK}, - [23 ] = {"SET_BLOCK_COUNT" , sd_cmd_SET_BLOCK_COUNT}, + [0 ] = { sd_bc,"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, + [2 ] = { sd_bcr,"ALL_SEND_CID" , sd_cmd_ALL_SEND_CID}, + [3 ] = { sd_bcr,"SEND_RELATIVE_ADDR" , sd_cmd_SEND_RELATIVE_ADDR}, + [19 ] = { sd_adtc,"SEND_TUNING_BLOCK" , sd_cmd_SEND_TUNING_BLOCK}, + [23 ] = { sd_ac,"SET_BLOCK_COUNT" , sd_cmd_SET_BLOCK_COUNT}, }, };
PATCH v42 41/98 hw/sd/sdcard: Store command class in SDProto
In reply to Philippe Mathieu-DaudéStore the command class altogether with the other command fields (handler, name and type).
--- hw/sd/sd.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)
hw/sd/sd.c +19 -17
@@ -95,6 +95,7 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); typedef struct SDProto { const char *name; struct { + const unsigned class; const sd_cmd_type_t type; const char *name; sd_cmd_handler handler;
@@ -352,13 +353,6 @@ static void sd_set_mode(SDState *sd) } } -static const int sd_cmd_class[SDMMC_CMD_MAX ] = { -0 ,0 ,0 ,0 ,0 ,9 ,10 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,0 , -2 ,2 ,2 ,2 ,3 ,3 ,3 ,3 ,4 ,4 ,4 ,4 ,6 ,6 ,6 ,6 , -5 ,5 ,10 ,10 ,10 ,10 ,5 ,9 ,9 ,9 ,7 ,7 ,7 ,7 ,7 ,7 , -7 ,7 ,10 ,7 ,9 ,9 ,9 ,8 ,8 ,10 ,8 ,8 ,8 ,8 ,8 ,8 , -}; -static uint8_t sd_crc7 (const void *message,size_t width) {int i, bit;
@@ -1306,7 +1300,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->multi_blk_cnt =0 ; } -if (sd_cmd_class[req.cmd] ==6 &&FIELD_EX32 (sd->ocr,OCR ,CARD_CAPACITY )) { +if (sd->proto->cmd[req.cmd].class ==6 &&FIELD_EX32 (sd->ocr,OCR , +CARD_CAPACITY )) {/* Only Standard Capacity cards support class 6 commands */ return sd_illegal; }
@@ -1891,6 +1886,8 @@ static sd_rsp_type_t sd_app_command(SDState *sd,static bool cmd_valid_while_locked (SDState *sd,unsigned cmd) { +unsigned cmd_class; +/* Valid commands in locked state: * basic class (0) * lock card class (7)
@@ -1905,7 +1902,12 @@ static bool cmd_valid_while_locked(SDState *sd, unsigned cmd)if (cmd ==16 || cmd ==55 ) {return true; } -return sd_cmd_class[cmd] ==0 || sd_cmd_class[cmd] ==7 ; +if (!sd->proto->cmd[cmd].handler) { +return false; + } + cmd_class = sd->proto->cmd[cmd].class; + +return cmd_class ==0 || cmd_class ==7 ; } int sd_do_command(SDState *sd, SDRequest *req,
@@ -2273,22 +2275,22 @@ void sd_enable(SDState *sd, bool enable)static const SDProto sd_proto_spi = { .name ="SPI" , .cmd = { - [0 ] = { sd_spi,"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, - [1 ] = { sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, + [0 ] = {0 , sd_spi,"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, + [1 ] = {0 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, .acmd = { - [41 ] = { sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, + [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, };static const SDProto sd_proto_sd = { .name ="SD" , .cmd = { - [0 ] = { sd_bc,"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, - [2 ] = { sd_bcr,"ALL_SEND_CID" , sd_cmd_ALL_SEND_CID}, - [3 ] = { sd_bcr,"SEND_RELATIVE_ADDR" , sd_cmd_SEND_RELATIVE_ADDR}, - [19 ] = { sd_adtc,"SEND_TUNING_BLOCK" , sd_cmd_SEND_TUNING_BLOCK}, - [23 ] = { sd_ac,"SET_BLOCK_COUNT" , sd_cmd_SET_BLOCK_COUNT}, + [0 ] = {0 , sd_bc,"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, + [2 ] = {0 , sd_bcr,"ALL_SEND_CID" , sd_cmd_ALL_SEND_CID}, + [3 ] = {0 , sd_bcr,"SEND_RELATIVE_ADDR" , sd_cmd_SEND_RELATIVE_ADDR}, + [19 ] = {2 , sd_adtc,"SEND_TUNING_BLOCK" , sd_cmd_SEND_TUNING_BLOCK}, + [23 ] = {2 , sd_ac,"SET_BLOCK_COUNT" , sd_cmd_SET_BLOCK_COUNT}, }, };
Signature · 1 line
2.41.0
Re: [PATCH v42 41/98] hw/sd/sdcard: Store command class in SDProto
Quoted 4 lines · Philippe Mathieu-Daudé
Store the command class altogether with the other command fields (handler, name and type).
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 94 lines
--- hw/sd/sd.c | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-)hw/sd/sd.c +19
-17@@ -95,6 +95,7 @@ typedef sd_rsp_type_t (*sd_cmd_handler)(SDState *sd, SDRequest req); typedef struct SDProto { const char *name; struct { + const unsigned class; const sd_cmd_type_t type; const char *name; sd_cmd_handler handler;@@ -352,13 +353,6 @@ static void sd_set_mode(SDState *sd) } } -static const int sd_cmd_class[SDMMC_CMD_MAX ] = { -0 ,0 ,0 ,0 ,0 ,9 ,10 ,0 ,0 ,0 ,0 ,1 ,0 ,0 ,0 ,0 , -2 ,2 ,2 ,2 ,3 ,3 ,3 ,3 ,4 ,4 ,4 ,4 ,6 ,6 ,6 ,6 , -5 ,5 ,10 ,10 ,10 ,10 ,5 ,9 ,9 ,9 ,7 ,7 ,7 ,7 ,7 ,7 , -7 ,7 ,10 ,7 ,9 ,9 ,9 ,8 ,8 ,10 ,8 ,8 ,8 ,8 ,8 ,8 , -}; -static uint8_t sd_crc7 (const void *message,size_t width) {int i, bit;@@ -1306,7 +1300,8 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) sd->multi_blk_cnt =0 ; } -if (sd_cmd_class[req.cmd] ==6 &&FIELD_EX32 (sd->ocr,OCR ,CARD_CAPACITY )) { +if (sd->proto->cmd[req.cmd].class ==6 &&FIELD_EX32 (sd->ocr,OCR , +CARD_CAPACITY )) {/* Only Standard Capacity cards support class 6 commands */ return sd_illegal; }@@ -1891,6 +1886,8 @@ static sd_rsp_type_t sd_app_command(SDState *sd,static bool cmd_valid_while_locked (SDState *sd,unsigned cmd) { +unsigned cmd_class; +/* Valid commands in locked state: * basic class (0) * lock card class (7) @@ -1905,7 +1902,12 @@ static bool cmd_valid_while_locked(SDState *sd, unsigned cmd)if (cmd ==16 || cmd ==55 ) {return true; } -return sd_cmd_class[cmd] ==0 || sd_cmd_class[cmd] ==7 ; +if (!sd->proto->cmd[cmd].handler) { +return false; + } + cmd_class = sd->proto->cmd[cmd].class; + +return cmd_class ==0 || cmd_class ==7 ; } int sd_do_command(SDState *sd, SDRequest *req,@@ -2273,22 +2275,22 @@ void sd_enable(SDState *sd, bool enable)static const SDProto sd_proto_spi = { .name ="SPI" , .cmd = { - [0 ] = { sd_spi,"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, - [1 ] = { sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, + [0 ] = {0 , sd_spi,"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, + [1 ] = {0 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, .acmd = { - [41 ] = { sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, + [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, };static const SDProto sd_proto_sd = { .name ="SD" , .cmd = { - [0 ] = { sd_bc,"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, - [2 ] = { sd_bcr,"ALL_SEND_CID" , sd_cmd_ALL_SEND_CID}, - [3 ] = { sd_bcr,"SEND_RELATIVE_ADDR" , sd_cmd_SEND_RELATIVE_ADDR}, - [19 ] = { sd_adtc,"SEND_TUNING_BLOCK" , sd_cmd_SEND_TUNING_BLOCK}, - [23 ] = { sd_ac,"SET_BLOCK_COUNT" , sd_cmd_SET_BLOCK_COUNT}, + [0 ] = {0 , sd_bc,"GO_IDLE_STATE" , sd_cmd_GO_IDLE_STATE}, + [2 ] = {0 , sd_bcr,"ALL_SEND_CID" , sd_cmd_ALL_SEND_CID}, + [3 ] = {0 , sd_bcr,"SEND_RELATIVE_ADDR" , sd_cmd_SEND_RELATIVE_ADDR}, + [19 ] = {2 , sd_adtc,"SEND_TUNING_BLOCK" , sd_cmd_SEND_TUNING_BLOCK}, + [23 ] = {2 , sd_ac,"SET_BLOCK_COUNT" , sd_cmd_SET_BLOCK_COUNT}, }, };
PATCH v42 42/98 hw/sd/sdcard: Remove SEND_DSR dead case (CMD4)
In reply to Philippe Mathieu-DaudéThe CSD::CSR_IMP bit defines whether the Driver Stage Register (DSR) is implemented or not. We do not set this bit in CSD:
static void sd_set_csd(SDState *sd, uint64_t size)
{
...
if (size <= SDSC_MAX_CAPACITY) { /* Standard Capacity SD */
...
sd->csd[6] = 0xe0 | /* Partial block for read allowed */
((csize >> 10) & 0x03);
...
} else { /* SDHC */
...
sd->csd[6] = 0x00;
...
}
...
}The sd_normal_command() switch case for the SEND_DSR command do nothing and fallback to "illegal command". Since the command is mandatory (although the register isn't...) call the sd_cmd_unimplemented() handler.
--- hw/sd/sd.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)
hw/sd/sd.c +2 -12
@@ -240,7 +240,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [4 ] ="SET_DSR" , [5 ] ="IO_SEND_OP_COND" , + [5 ] ="IO_SEND_OP_COND" , [6 ] ="SWITCH_FUNC" , [7 ] ="SELECT/DESELECT_CARD" , [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , [10 ] ="SEND_CID" , [11 ] ="VOLTAGE_SWITCH" ,
@@ -1153,7 +1153,6 @@ static sd_rsp_type_t sd_cmd_illegal(SDState *sd, SDRequest req) }/* Commands that are recognised but not yet implemented. */ -__attribute__((unused))static sd_rsp_type_t sd_cmd_unimplemented (SDState *sd,SDRequest req) { qemu_log_mask(LOG_UNIMP, "%s: CMD%i not implemented\n",
@@ -1312,16 +1311,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 4 :/* CMD4: SEND_DSR */ -switch (sd->state) { -case sd_standby_state: -break ; - -default : -break ; - } -break ; -case 6 :/* CMD6: SWITCH_FUNCTION */ if (sd->mode != sd_data_transfer_mode) {return sd_invalid_mode_for_cmd (sd, req);
@@ -2289,6 +2278,7 @@ static const SDProto sd_proto_sd = { [0] = {0, sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, + [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, },
Signature · 1 line
2.41.0
Re: [PATCH v42 42/98] hw/sd/sdcard: Remove SEND_DSR dead case (CMD4)
Quoted 20 lines · Philippe Mathieu-Daudé
The
CSD::CSR_IMPbit defines whether the Driver Stage Register (DSR) is implemented or not. We do not set this bit in CSD:static void sd_set_csd(SDState *sd, uint64_t size) { ... if (size <= SDSC_MAX_CAPACITY) { /* Standard Capacity SD */ ... sd->csd[6] = 0xe0 | /* Partial block for read allowed */ ((csize >> 10) & 0x03); ... } else { /* SDHC */ ... sd->csd[6] = 0x00; ... } ... }
Quoted 6 lines
The
sd_normal_command()switch case for theSEND_DSRcommand do nothing and fallback to "illegal command". Since the command is mandatory (although the register isn't...) call thesd_cmd_unimplemented()handler.Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 50 lines
--- hw/sd/sd.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)hw/sd/sd.c +2
-12@@ -240,7 +240,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [4 ] ="SET_DSR" , [5 ] ="IO_SEND_OP_COND" , + [5 ] ="IO_SEND_OP_COND" , [6 ] ="SWITCH_FUNC" , [7 ] ="SELECT/DESELECT_CARD" , [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , [10 ] ="SEND_CID" , [11 ] ="VOLTAGE_SWITCH" ,@@ -1153,7 +1153,6 @@ static sd_rsp_type_t sd_cmd_illegal(SDState *sd, SDRequest req) }/* Commands that are recognised but not yet implemented. */ -__attribute__((unused))static sd_rsp_type_t sd_cmd_unimplemented (SDState *sd,SDRequest req) { qemu_log_mask(LOG_UNIMP, "%s: CMD%i not implemented\n",@@ -1312,16 +1311,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 4 :/* CMD4: SEND_DSR */ -switch (sd->state) { -case sd_standby_state: -break ; - -default : -break ; - } -break ; -case 6 :/* CMD6: SWITCH_FUNCTION */ if (sd->mode != sd_data_transfer_mode) {return sd_invalid_mode_for_cmd (sd, req);@@ -2289,6 +2278,7 @@ static const SDProto sd_proto_sd = { [0] = {0, sd_bc, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, + [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, },
PATCH v42 43/98 hw/sd/sdcard: Register generic optional handlers (CMD11 and CMD20)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)
hw/sd/sd.c +12 -2
@@ -243,12 +243,12 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [5] = "IO_SEND_OP_COND", [6] = "SWITCH_FUNC", [7] = "SELECT/DESELECT_CARD", [8] = "SEND_IF_COND", [9] = "SEND_CSD", - [10] = "SEND_CID", [11] = "VOLTAGE_SWITCH", + [10] = "SEND_CID", [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", [15] = "GO_INACTIVE_STATE", [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", [18] = "READ_MULTIPLE_BLOCK", - [20] = "SPEED_CLASS_CONTROL", [21] = "DPS_spec", + [21] = "DPS_spec", [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT",
@@ -1161,6 +1161,14 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req)return sd_illegal; } +static sd_rsp_type_t sd_cmd_optional (SDState *sd,SDRequest req) +{ +qemu_log_mask (LOG_UNIMP ,"%s: Optional CMD%i not implemented\n" , + sd->proto->name, req.cmd); + +return sd_illegal; +} +/* Configure fields for following sd_generic_write_byte() calls */ static sd_rsp_type_t sd_cmd_to_receivingdata (SDState *sd,SDRequest req,uint64_t start,size_t size)
@@ -2279,7 +2287,9 @@ static const SDProto sd_proto_sd = { [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, + [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, + [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, }, };
Signature · 1 line
2.41.0
Re: [PATCH v42 43/98] hw/sd/sdcard: Register generic optional handlers (CMD11 and CMD20)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 48 lines
--- hw/sd/sd.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-)hw/sd/sd.c +12
-2@@ -243,12 +243,12 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [5] = "IO_SEND_OP_COND", [6] = "SWITCH_FUNC", [7] = "SELECT/DESELECT_CARD", [8] = "SEND_IF_COND", [9] = "SEND_CSD", - [10] = "SEND_CID", [11] = "VOLTAGE_SWITCH", + [10] = "SEND_CID", [12] = "STOP_TRANSMISSION", [13] = "SEND_STATUS", [15] = "GO_INACTIVE_STATE", [16] = "SET_BLOCKLEN", [17] = "READ_SINGLE_BLOCK", [18] = "READ_MULTIPLE_BLOCK", - [20] = "SPEED_CLASS_CONTROL", [21] = "DPS_spec", + [21] = "DPS_spec", [24] = "WRITE_BLOCK", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT",@@ -1161,6 +1161,14 @@ static sd_rsp_type_t sd_cmd_unimplemented(SDState *sd, SDRequest req)return sd_illegal; } +static sd_rsp_type_t sd_cmd_optional (SDState *sd,SDRequest req) +{ +qemu_log_mask (LOG_UNIMP ,"%s: Optional CMD%i not implemented\n" , + sd->proto->name, req.cmd); + +return sd_illegal; +} +/* Configure fields for following sd_generic_write_byte() calls */ static sd_rsp_type_t sd_cmd_to_receivingdata (SDState *sd,SDRequest req,uint64_t start,size_t size)@@ -2279,7 +2287,9 @@ static const SDProto sd_proto_sd = { [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, + [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, + [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, }, };
PATCH v42 44/98 hw/sd/sdcard: Register optional handlers from spec v6.00
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
hw/sd/sd.c +10 -5
@@ -258,15 +258,11 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [36] = "SW_FUNC_RSVD", [37] = "SW_FUNC_RSVD", [38] = "ERASE", [40] = "DPS_spec", - [42] = "LOCK_UNLOCK", [43] = "Q_MANAGEMENT", - [44] = "Q_TASK_INFO_A", [45] = "Q_TASK_INFO_B", - [46] = "Q_RD_TASK", [47] = "Q_WR_TASK", - [48] = "READ_EXTR_SINGLE", [49] = "WRITE_EXTR_SINGLE", + [42] = "LOCK_UNLOCK", [50] = "SW_FUNC_RSVD", [52] = "IO_RW_DIRECT", [53] = "IO_RW_EXTENDED", [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", - [58] = "READ_EXTR_MULTI", [59] = "WRITE_EXTR_MULTI", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", };
@@ -2291,6 +2287,15 @@ static const SDProto sd_proto_sd = { [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, + [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, + [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional}, + [46] = {1, sd_adtc, "Q_RD_TASK", sd_cmd_optional}, + [47] = {1, sd_adtc, "Q_WR_TASK", sd_cmd_optional}, + [48] = {1, sd_adtc, "READ_EXTR_SINGLE", sd_cmd_optional}, + [49] = {1, sd_adtc, "WRITE_EXTR_SINGLE", sd_cmd_optional}, + [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, + [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, }, };
Signature · 1 line
2.41.0
Re: [PATCH v42 44/98] hw/sd/sdcard: Register optional handlers from spec v6.00
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 41 lines
--- hw/sd/sd.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)hw/sd/sd.c +10
-5@@ -258,15 +258,11 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [36] = "SW_FUNC_RSVD", [37] = "SW_FUNC_RSVD", [38] = "ERASE", [40] = "DPS_spec", - [42] = "LOCK_UNLOCK", [43] = "Q_MANAGEMENT", - [44] = "Q_TASK_INFO_A", [45] = "Q_TASK_INFO_B", - [46] = "Q_RD_TASK", [47] = "Q_WR_TASK", - [48] = "READ_EXTR_SINGLE", [49] = "WRITE_EXTR_SINGLE", + [42] = "LOCK_UNLOCK", [50] = "SW_FUNC_RSVD", [52] = "IO_RW_DIRECT", [53] = "IO_RW_EXTENDED", [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", - [58] = "READ_EXTR_MULTI", [59] = "WRITE_EXTR_MULTI", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", };@@ -2291,6 +2287,15 @@ static const SDProto sd_proto_sd = { [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, + [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, + [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional}, + [46] = {1, sd_adtc, "Q_RD_TASK", sd_cmd_optional}, + [47] = {1, sd_adtc, "Q_WR_TASK", sd_cmd_optional}, + [48] = {1, sd_adtc, "READ_EXTR_SINGLE", sd_cmd_optional}, + [49] = {1, sd_adtc, "WRITE_EXTR_SINGLE", sd_cmd_optional}, + [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, + [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, }, };
PATCH v42 45/98 hw/sd/sdcard: Register SDIO optional handlers
In reply to Philippe Mathieu-DaudéSee "SD Input/Output Card Specification" v1.00.
--- hw/sd/sd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
hw/sd/sd.c +6 -2
@@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [5 ] ="IO_SEND_OP_COND" , [6 ] ="SWITCH_FUNC" , [7 ] ="SELECT/DESELECT_CARD" , [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , [10 ] ="SEND_CID" ,
@@ -260,7 +259,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [40] = "DPS_spec", [42] = "LOCK_UNLOCK", [50] = "SW_FUNC_RSVD", - [52] = "IO_RW_DIRECT", [53] = "IO_RW_EXTENDED", [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD",
@@ -2270,6 +2268,9 @@ static const SDProto sd_proto_spi = { .cmd = { [0] = {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, + [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, + [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, }, .acmd = { [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND},
@@ -2283,6 +2284,7 @@ static const SDProto sd_proto_sd = { [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, + [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional},
@@ -2294,6 +2296,8 @@ static const SDProto sd_proto_sd = { [47] = {1, sd_adtc, "Q_WR_TASK", sd_cmd_optional}, [48] = {1, sd_adtc, "READ_EXTR_SINGLE", sd_cmd_optional}, [49] = {1, sd_adtc, "WRITE_EXTR_SINGLE", sd_cmd_optional}, + [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, + [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, },
Signature · 1 line
2.41.0
Re: [PATCH v42 45/98] hw/sd/sdcard: Register SDIO optional handlers
Quoted 3 lines · Philippe Mathieu-Daudé
See "SD Input/Output Card Specification" v1.00.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 51 lines
--- hw/sd/sd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)hw/sd/sd.c +6
-2@@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [5 ] ="IO_SEND_OP_COND" , [6 ] ="SWITCH_FUNC" , [7 ] ="SELECT/DESELECT_CARD" , [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , [10 ] ="SEND_CID" ,@@ -260,7 +259,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [40] = "DPS_spec", [42] = "LOCK_UNLOCK", [50] = "SW_FUNC_RSVD", - [52] = "IO_RW_DIRECT", [53] = "IO_RW_EXTENDED", [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD",@@ -2270,6 +2268,9 @@ static const SDProto sd_proto_spi = { .cmd = { [0] = {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, + [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, + [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, }, .acmd = { [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND},@@ -2283,6 +2284,7 @@ static const SDProto sd_proto_sd = { [2] = {0, sd_bcr, "ALL_SEND_CID", sd_cmd_ALL_SEND_CID}, [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, + [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional},@@ -2294,6 +2296,8 @@ static const SDProto sd_proto_sd = { [47] = {1, sd_adtc, "Q_WR_TASK", sd_cmd_optional}, [48] = {1, sd_adtc, "READ_EXTR_SINGLE", sd_cmd_optional}, [49] = {1, sd_adtc, "WRITE_EXTR_SINGLE", sd_cmd_optional}, + [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, + [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, },
PATCH v42 46/98 hw/sd/sdcard: Register Security Extension optional handlers
In reply to Philippe Mathieu-DaudéSee "Advanced Security SD Extension Specification" v2.00.
--- hw/sd/sd.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)
hw/sd/sd.c +13 -4
@@ -253,14 +253,11 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", - [34] = "SW_FUNC_RSVD", [35] = "SW_FUNC_RSVD", - [36] = "SW_FUNC_RSVD", [37] = "SW_FUNC_RSVD", [38] = "ERASE", [40] = "DPS_spec", [42] = "LOCK_UNLOCK", - [50] = "SW_FUNC_RSVD", [54] = "SDIO_RSVD", [55] = "APP_CMD", - [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", + [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", };
@@ -2269,8 +2266,14 @@ static const SDProto sd_proto_spi = { [0] = {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, + [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, + [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, + [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional}, + [37] = {10, sd_spi, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, + [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, + [57 ] = {10 , sd_spi,"DIRECT_SECURE_WRITE" , sd_cmd_optional}, }, .acmd = { [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND},
@@ -2289,6 +2292,10 @@ static const SDProto sd_proto_sd = { [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, + [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, + [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, + [37] = {10, sd_ac, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional},
@@ -2296,8 +2303,10 @@ static const SDProto sd_proto_sd = { [47] = {1, sd_adtc, "Q_WR_TASK", sd_cmd_optional}, [48] = {1, sd_adtc, "READ_EXTR_SINGLE", sd_cmd_optional}, [49] = {1, sd_adtc, "WRITE_EXTR_SINGLE", sd_cmd_optional}, + [50] = {10, sd_adtc, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, + [57] = {10, sd_adtc, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, },
Signature · 1 line
2.41.0
Re: [PATCH v42 46/98] hw/sd/sdcard: Register Security Extension optional handlers
Quoted 3 lines · Philippe Mathieu-Daudé
See "Advanced Security SD Extension Specification" v2.00.
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 61 lines
--- hw/sd/sd.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-)hw/sd/sd.c +13
-4@@ -253,14 +253,11 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", - [34] = "SW_FUNC_RSVD", [35] = "SW_FUNC_RSVD", - [36] = "SW_FUNC_RSVD", [37] = "SW_FUNC_RSVD", [38] = "ERASE", [40] = "DPS_spec", [42] = "LOCK_UNLOCK", - [50] = "SW_FUNC_RSVD", [54] = "SDIO_RSVD", [55] = "APP_CMD", - [56] = "GEN_CMD", [57] = "SW_FUNC_RSVD", + [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", };@@ -2269,8 +2266,14 @@ static const SDProto sd_proto_spi = { [0] = {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, + [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, + [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, + [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional}, + [37] = {10, sd_spi, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, + [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, + [57 ] = {10 , sd_spi,"DIRECT_SECURE_WRITE" , sd_cmd_optional}, }, .acmd = { [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND},@@ -2289,6 +2292,10 @@ static const SDProto sd_proto_sd = { [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, + [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, + [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, + [37] = {10, sd_ac, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional},@@ -2296,8 +2303,10 @@ static const SDProto sd_proto_sd = { [47] = {1, sd_adtc, "Q_WR_TASK", sd_cmd_optional}, [48] = {1, sd_adtc, "READ_EXTR_SINGLE", sd_cmd_optional}, [49] = {1, sd_adtc, "WRITE_EXTR_SINGLE", sd_cmd_optional}, + [50] = {10, sd_adtc, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, + [57] = {10, sd_adtc, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional}, },
PATCH v42 47/98 hw/sd/sdcard: Add sd_cmd_SWITCH_FUNCTION handler (CMD6)
In reply to Philippe Mathieu-DaudéFrom: Philippe Mathieu-Daudé <[email protected]>
--- hw/sd/sd.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)
hw/sd/sd.c +17 -12
@@ -240,7 +240,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [6 ] ="SWITCH_FUNC" , [7 ] ="SELECT/DESELECT_CARD" , + [7 ] ="SELECT/DESELECT_CARD" , [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , [10 ] ="SEND_CID" , [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" ,
@@ -1244,6 +1244,20 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) } } +/* CMD6 */ +static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION (SDState *sd,SDRequest req) +{ +if (sd->mode != sd_data_transfer_mode) { +return sd_invalid_mode_for_cmd (sd, req); + } +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +sd_function_switch (sd, req.arg); +return sd_cmd_to_sendingdata (sd, req,0 ,NULL ,64 ); +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {
@@ -1310,17 +1324,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 6 :/* CMD6: SWITCH_FUNCTION */ -if (sd->mode != sd_data_transfer_mode) { -return sd_invalid_mode_for_cmd (sd, req); - } -if (sd->state != sd_transfer_state) { -return sd_invalid_state_for_cmd (sd, req); - } - -sd_function_switch (sd, req.arg); -return sd_cmd_to_sendingdata (sd, req,0 ,NULL ,64 ); -case 7 :/* CMD7: SELECT/DESELECT_CARD */ rca =sd_req_get_rca (sd, req);switch (sd->state) {
@@ -2266,6 +2269,7 @@ static const SDProto sd_proto_spi = { [0] = {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, + [6] = {10, sd_spi, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2288,6 +2292,7 @@ static const SDProto sd_proto_sd = { [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, + [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 47/98] hw/sd/sdcard: Add sd_cmd_SWITCH_FUNCTION handler (CMD6)
Quoted 4 lines · Philippe Mathieu-Daudé
From: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 72 lines
--- hw/sd/sd.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-)hw/sd/sd.c +17
-12@@ -240,7 +240,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [6 ] ="SWITCH_FUNC" , [7 ] ="SELECT/DESELECT_CARD" , + [7 ] ="SELECT/DESELECT_CARD" , [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , [10 ] ="SEND_CID" , [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" ,@@ -1244,6 +1244,20 @@ static sd_rsp_type_t sd_cmd_SEND_RELATIVE_ADDR(SDState *sd, SDRequest req) } } +/* CMD6 */ +static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION (SDState *sd,SDRequest req) +{ +if (sd->mode != sd_data_transfer_mode) { +return sd_invalid_mode_for_cmd (sd, req); + } +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +sd_function_switch (sd, req.arg); +return sd_cmd_to_sendingdata (sd, req,0 ,NULL ,64 ); +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {@@ -1310,17 +1324,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 6 :/* CMD6: SWITCH_FUNCTION */ -if (sd->mode != sd_data_transfer_mode) { -return sd_invalid_mode_for_cmd (sd, req); - } -if (sd->state != sd_transfer_state) { -return sd_invalid_state_for_cmd (sd, req); - } - -sd_function_switch (sd, req.arg); -return sd_cmd_to_sendingdata (sd, req,0 ,NULL ,64 ); -case 7 :/* CMD7: SELECT/DESELECT_CARD */ rca =sd_req_get_rca (sd, req);switch (sd->state) {@@ -2266,6 +2269,7 @@ static const SDProto sd_proto_spi = { [0] = {0, sd_spi, "GO_IDLE_STATE", sd_cmd_GO_IDLE_STATE}, [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, + [6] = {10, sd_spi, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2288,6 +2292,7 @@ static const SDProto sd_proto_sd = { [3] = {0, sd_bcr, "SEND_RELATIVE_ADDR", sd_cmd_SEND_RELATIVE_ADDR}, [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, + [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional},
PATCH v42 48/98 hw/sd/sdcard: Add sd_cmd_DE/SELECT_CARD handler (CMD7)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 85 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 38 deletions(-)
hw/sd/sd.c +47 -38
@@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [7 ] ="SELECT/DESELECT_CARD" , [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , [10 ] ="SEND_CID" , [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" ,
@@ -558,6 +557,11 @@ static uint16_t sd_req_get_rca(SDState *s, SDRequest req) } } +static bool sd_req_rca_same (SDState *s,SDRequest req) +{ +return sd_req_get_rca (s, req) == s->rca; +} +/* Card Status register */ FIELD (CSR ,AKE_SEQ_ERROR ,3 ,1 )
@@ -1258,6 +1262,47 @@ static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION(SDState *sd, SDRequest req)return sd_cmd_to_sendingdata (sd, req,0 ,NULL ,64 ); } +/* CMD7 */ +static sd_rsp_type_t sd_cmd_DE_SELECT_CARD (SDState *sd,SDRequest req) +{ +bool same_rca =sd_req_rca_same (sd, req); + +switch (sd->state) { +case sd_standby_state: +if (!same_rca) { +return sd_r0; + } + sd->state = sd_transfer_state; +return sd_r1b; + +case sd_transfer_state: +case sd_sendingdata_state: +if (same_rca) { +break ; + } + sd->state = sd_standby_state; +return sd_r1b; + +case sd_disconnect_state: +if (!same_rca) { +return sd_r0; + } + sd->state = sd_programming_state; +return sd_r1b; + +case sd_programming_state: +if (same_rca) { +break ; + } + sd->state = sd_disconnect_state; +return sd_r1b; + +default : +break ; + } +return sd_invalid_state_for_cmd (sd, req); +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {
@@ -1324,43 +1369,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 7 :/* CMD7: SELECT/DESELECT_CARD */ - rca =sd_req_get_rca (sd, req); -switch (sd->state) { -case sd_standby_state: -if (sd->rca != rca) -return sd_r0; - - sd->state = sd_transfer_state; -return sd_r1b; - -case sd_transfer_state: -case sd_sendingdata_state: -if (sd->rca == rca) -break ; - - sd->state = sd_standby_state; -return sd_r1b; - -case sd_disconnect_state: -if (sd->rca != rca) -return sd_r0; - - sd->state = sd_programming_state; -return sd_r1b; - -case sd_programming_state: -if (sd->rca == rca) -break ; - - sd->state = sd_disconnect_state; -return sd_r1b; - -default : -break ; - } -break ; -case 8 :/* CMD8: SEND_IF_COND */ if (sd->spec_version < SD_PHY_SPECv2_00_VERS) {break ;
@@ -2293,6 +2301,7 @@ static const SDProto sd_proto_sd = { [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, + [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 48/98] hw/sd/sdcard: Add sd_cmd_DE/SELECT_CARD handler (CMD7)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 128 lines
--- hw/sd/sd.c | 85 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 38 deletions(-)hw/sd/sd.c +47
-38@@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [7 ] ="SELECT/DESELECT_CARD" , [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , [10 ] ="SEND_CID" , [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" ,@@ -558,6 +557,11 @@ static uint16_t sd_req_get_rca(SDState *s, SDRequest req) } } +static bool sd_req_rca_same (SDState *s,SDRequest req) +{ +return sd_req_get_rca (s, req) == s->rca; +} +/* Card Status register */ FIELD (CSR ,AKE_SEQ_ERROR ,3 ,1 )@@ -1258,6 +1262,47 @@ static sd_rsp_type_t sd_cmd_SWITCH_FUNCTION(SDState *sd, SDRequest req)return sd_cmd_to_sendingdata (sd, req,0 ,NULL ,64 ); } +/* CMD7 */ +static sd_rsp_type_t sd_cmd_DE_SELECT_CARD (SDState *sd,SDRequest req) +{ +bool same_rca =sd_req_rca_same (sd, req); + +switch (sd->state) { +case sd_standby_state: +if (!same_rca) { +return sd_r0; + } + sd->state = sd_transfer_state; +return sd_r1b; + +case sd_transfer_state: +case sd_sendingdata_state: +if (same_rca) { +break ; + } + sd->state = sd_standby_state; +return sd_r1b; + +case sd_disconnect_state: +if (!same_rca) { +return sd_r0; + } + sd->state = sd_programming_state; +return sd_r1b; + +case sd_programming_state: +if (same_rca) { +break ; + } + sd->state = sd_disconnect_state; +return sd_r1b; + +default : +break ; + } +return sd_invalid_state_for_cmd (sd, req); +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {@@ -1324,43 +1369,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 7 :/* CMD7: SELECT/DESELECT_CARD */ - rca =sd_req_get_rca (sd, req); -switch (sd->state) { -case sd_standby_state: -if (sd->rca != rca) -return sd_r0; - - sd->state = sd_transfer_state; -return sd_r1b; - -case sd_transfer_state: -case sd_sendingdata_state: -if (sd->rca == rca) -break ; - - sd->state = sd_standby_state; -return sd_r1b; - -case sd_disconnect_state: -if (sd->rca != rca) -return sd_r0; - - sd->state = sd_programming_state; -return sd_r1b; - -case sd_programming_state: -if (sd->rca == rca) -break ; - - sd->state = sd_disconnect_state; -return sd_r1b; - -default : -break ; - } -break ; -case 8 :/* CMD8: SEND_IF_COND */ if (sd->spec_version < SD_PHY_SPECv2_00_VERS) {break ;@@ -2293,6 +2301,7 @@ static const SDProto sd_proto_sd = { [4] = {0, sd_bc, "SEND_DSR", sd_cmd_unimplemented}, [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, + [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional},
PATCH v42 49/98 hw/sd/sdcard: Add sd_cmd_SEND_IF_COND handler (CMD8)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-)
hw/sd/sd.c +24 -19
@@ -240,7 +240,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , + [9 ] ="SEND_CSD" , [10 ] ="SEND_CID" , [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" , [15 ] ="GO_INACTIVE_STATE" ,
@@ -1303,6 +1303,27 @@ static sd_rsp_type_t sd_cmd_DE_SELECT_CARD(SDState *sd, SDRequest req)return sd_invalid_state_for_cmd (sd, req); } +/* CMD8 */ +static sd_rsp_type_t sd_cmd_SEND_IF_COND (SDState *sd,SDRequest req) +{ +if (sd->spec_version < SD_PHY_SPECv2_00_VERS) { +return sd_cmd_illegal (sd, req); + } +if (sd->state != sd_idle_state) { +return sd_invalid_state_for_cmd (sd, req); + } + sd->vhs =0 ; + +/* No response if not exactly one VHS bit is set. */ +if (!(req.arg >>8 ) || (req.arg >> (ctz32 (req.arg & ~0xff ) +1 ))) { +return sd_is_spi (sd) ? sd_r7 : sd_r0; + } + +/* Accept. */ + sd->vhs = req.arg; +return sd_r7; +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {
@@ -1369,24 +1390,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 8 :/* CMD8: SEND_IF_COND */ -if (sd->spec_version < SD_PHY_SPECv2_00_VERS) { -break ; - } -if (sd->state != sd_idle_state) { -break ; - } - sd->vhs =0 ; - -/* No response if not exactly one VHS bit is set. */ -if (!(req.arg >>8 ) || (req.arg >> (ctz32 (req.arg & ~0xff ) +1 ))) { -return sd_is_spi (sd) ? sd_r7 : sd_r0; - } - -/* Accept. */ - sd->vhs = req.arg; -return sd_r7; -case 9 :/* CMD9: SEND_CSD */ rca =sd_req_get_rca (sd, req);switch (sd->state) {
@@ -2278,6 +2281,7 @@ static const SDProto sd_proto_spi = { [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_spi, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, + [8] = {0, sd_spi, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2302,6 +2306,7 @@ static const SDProto sd_proto_sd = { [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, + [8] = {0, sd_bcr, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 49/98] hw/sd/sdcard: Add sd_cmd_SEND_IF_COND handler (CMD8)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 86 lines
--- hw/sd/sd.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-)hw/sd/sd.c +24
-19@@ -240,7 +240,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [8 ] ="SEND_IF_COND" , [9 ] ="SEND_CSD" , + [9 ] ="SEND_CSD" , [10 ] ="SEND_CID" , [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" , [15 ] ="GO_INACTIVE_STATE" ,@@ -1303,6 +1303,27 @@ static sd_rsp_type_t sd_cmd_DE_SELECT_CARD(SDState *sd, SDRequest req)return sd_invalid_state_for_cmd (sd, req); } +/* CMD8 */ +static sd_rsp_type_t sd_cmd_SEND_IF_COND (SDState *sd,SDRequest req) +{ +if (sd->spec_version < SD_PHY_SPECv2_00_VERS) { +return sd_cmd_illegal (sd, req); + } +if (sd->state != sd_idle_state) { +return sd_invalid_state_for_cmd (sd, req); + } + sd->vhs =0 ; + +/* No response if not exactly one VHS bit is set. */ +if (!(req.arg >>8 ) || (req.arg >> (ctz32 (req.arg & ~0xff ) +1 ))) { +return sd_is_spi (sd) ? sd_r7 : sd_r0; + } + +/* Accept. */ + sd->vhs = req.arg; +return sd_r7; +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {@@ -1369,24 +1390,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 8 :/* CMD8: SEND_IF_COND */ -if (sd->spec_version < SD_PHY_SPECv2_00_VERS) { -break ; - } -if (sd->state != sd_idle_state) { -break ; - } - sd->vhs =0 ; - -/* No response if not exactly one VHS bit is set. */ -if (!(req.arg >>8 ) || (req.arg >> (ctz32 (req.arg & ~0xff ) +1 ))) { -return sd_is_spi (sd) ? sd_r7 : sd_r0; - } - -/* Accept. */ - sd->vhs = req.arg; -return sd_r7; -case 9 :/* CMD9: SEND_CSD */ rca =sd_req_get_rca (sd, req);switch (sd->state) {@@ -2278,6 +2281,7 @@ static const SDProto sd_proto_spi = { [1] = {0, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_spi, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, + [8] = {0, sd_spi, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2302,6 +2306,7 @@ static const SDProto sd_proto_sd = { [5] = {9, sd_bc, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, + [8] = {0, sd_bcr, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional},
PATCH v42 50/98 hw/sd/sdcard: Add sd_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)
hw/sd/sd.c +22 -14
@@ -240,8 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [9 ] ="SEND_CSD" , - [10 ] ="SEND_CID" , [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" , [15 ] ="GO_INACTIVE_STATE" , [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" ,
@@ -1324,6 +1322,26 @@ static sd_rsp_type_t sd_cmd_SEND_IF_COND(SDState *sd, SDRequest req)return sd_r7; } +/* CMD9 */ +static sd_rsp_type_t sd_cmd_SEND_CSD (SDState *sd,SDRequest req) +{ +if (sd->state != sd_standby_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +return sd_req_rca_same (sd, req) ? sd_r2_s : sd_r0; +} + +/* CMD10 */ +static sd_rsp_type_t sd_cmd_SEND_CID (SDState *sd,SDRequest req) +{ +if (sd->state != sd_standby_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +return sd_req_rca_same (sd, req) ? sd_r2_i : sd_r0; +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {
@@ -1393,12 +1411,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 9 :/* CMD9: SEND_CSD */ rca =sd_req_get_rca (sd, req);switch (sd->state) { -case sd_standby_state: -if (sd->rca != rca) -return sd_r0; - -return sd_r2_s; -case sd_transfer_state:if (!sd_is_spi (sd)) {break ;
@@ -1414,12 +1426,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 10 :/* CMD10: SEND_CID */ rca =sd_req_get_rca (sd, req);switch (sd->state) { -case sd_standby_state: -if (sd->rca != rca) -return sd_r0; - -return sd_r2_i; -case sd_transfer_state:if (!sd_is_spi (sd)) {break ;
@@ -2307,6 +2313,8 @@ static const SDProto sd_proto_sd = { [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [8] = {0, sd_bcr, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, + [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, + [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 50/98] hw/sd/sdcard: Add sd_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 79 lines
--- hw/sd/sd.c | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-)hw/sd/sd.c +22
-14@@ -240,8 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [9 ] ="SEND_CSD" , - [10 ] ="SEND_CID" , [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" , [15 ] ="GO_INACTIVE_STATE" , [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" ,@@ -1324,6 +1322,26 @@ static sd_rsp_type_t sd_cmd_SEND_IF_COND(SDState *sd, SDRequest req)return sd_r7; } +/* CMD9 */ +static sd_rsp_type_t sd_cmd_SEND_CSD (SDState *sd,SDRequest req) +{ +if (sd->state != sd_standby_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +return sd_req_rca_same (sd, req) ? sd_r2_s : sd_r0; +} + +/* CMD10 */ +static sd_rsp_type_t sd_cmd_SEND_CID (SDState *sd,SDRequest req) +{ +if (sd->state != sd_standby_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +return sd_req_rca_same (sd, req) ? sd_r2_i : sd_r0; +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {@@ -1393,12 +1411,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 9 :/* CMD9: SEND_CSD */ rca =sd_req_get_rca (sd, req);switch (sd->state) { -case sd_standby_state: -if (sd->rca != rca) -return sd_r0; - -return sd_r2_s; -case sd_transfer_state:if (!sd_is_spi (sd)) {break ;@@ -1414,12 +1426,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 10 :/* CMD10: SEND_CID */ rca =sd_req_get_rca (sd, req);switch (sd->state) { -case sd_standby_state: -if (sd->rca != rca) -return sd_r0; - -return sd_r2_i; -case sd_transfer_state:if (!sd_is_spi (sd)) {break ;@@ -2307,6 +2313,8 @@ static const SDProto sd_proto_sd = { [6] = {10, sd_adtc, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [7] = {0, sd_ac, "(DE)SELECT_CARD", sd_cmd_DE_SELECT_CARD}, [8] = {0, sd_bcr, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, + [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, + [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional},
PATCH v42 51/98 hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-)
hw/sd/sd.c +20 -30
@@ -1323,6 +1323,15 @@ static sd_rsp_type_t sd_cmd_SEND_IF_COND(SDState *sd, SDRequest req) }/* CMD9 */ +static sd_rsp_type_t spi_cmd_SEND_CSD (SDState *sd,SDRequest req) +{ +if (sd->state != sd_standby_state) { +return sd_invalid_state_for_cmd (sd, req); + } +return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), + sd->csd,16 ); +} +static sd_rsp_type_t sd_cmd_SEND_CSD (SDState *sd,SDRequest req) {if (sd->state != sd_standby_state) {
@@ -1333,6 +1342,15 @@ static sd_rsp_type_t sd_cmd_SEND_CSD(SDState *sd, SDRequest req) }/* CMD10 */ +static sd_rsp_type_t spi_cmd_SEND_CID (SDState *sd,SDRequest req) +{ +if (sd->state != sd_standby_state) { +return sd_invalid_state_for_cmd (sd, req); + } +return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), + sd->cid,16 ); +} +static sd_rsp_type_t sd_cmd_SEND_CID (SDState *sd,SDRequest req) {if (sd->state != sd_standby_state) {
@@ -1408,36 +1426,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 9 :/* CMD9: SEND_CSD */ - rca =sd_req_get_rca (sd, req); -switch (sd->state) { -case sd_transfer_state: -if (!sd_is_spi (sd)) { -break ; - } -return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), - sd->csd,16 ); - -default : -break ; - } -break ; - -case 10 :/* CMD10: SEND_CID */ - rca =sd_req_get_rca (sd, req); -switch (sd->state) { -case sd_transfer_state: -if (!sd_is_spi (sd)) { -break ; - } -return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), - sd->cid,16 ); - -default : -break ; - } -break ; -case 12 :/* CMD12: STOP_TRANSMISSION */ switch (sd->state) {case sd_sendingdata_state:
@@ -2288,6 +2276,8 @@ static const SDProto sd_proto_spi = { [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_spi, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [8] = {0, sd_spi, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, + [9] = {0, sd_spi, "SEND_CSD", spi_cmd_SEND_CSD}, + [10] = {0, sd_spi, "SEND_CID", spi_cmd_SEND_CID}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 51/98] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 86 lines
--- hw/sd/sd.c | 50 ++++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 30 deletions(-)hw/sd/sd.c +20
-30@@ -1323,6 +1323,15 @@ static sd_rsp_type_t sd_cmd_SEND_IF_COND(SDState *sd, SDRequest req) }/* CMD9 */ +static sd_rsp_type_t spi_cmd_SEND_CSD (SDState *sd,SDRequest req) +{ +if (sd->state != sd_standby_state) { +return sd_invalid_state_for_cmd (sd, req); + } +return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), + sd->csd,16 ); +} +static sd_rsp_type_t sd_cmd_SEND_CSD (SDState *sd,SDRequest req) {if (sd->state != sd_standby_state) {@@ -1333,6 +1342,15 @@ static sd_rsp_type_t sd_cmd_SEND_CSD(SDState *sd, SDRequest req) }/* CMD10 */ +static sd_rsp_type_t spi_cmd_SEND_CID (SDState *sd,SDRequest req) +{ +if (sd->state != sd_standby_state) { +return sd_invalid_state_for_cmd (sd, req); + } +return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), + sd->cid,16 ); +} +static sd_rsp_type_t sd_cmd_SEND_CID (SDState *sd,SDRequest req) {if (sd->state != sd_standby_state) {@@ -1408,36 +1426,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 9 :/* CMD9: SEND_CSD */ - rca =sd_req_get_rca (sd, req); -switch (sd->state) { -case sd_transfer_state: -if (!sd_is_spi (sd)) { -break ; - } -return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), - sd->csd,16 ); - -default : -break ; - } -break ; - -case 10 :/* CMD10: SEND_CID */ - rca =sd_req_get_rca (sd, req); -switch (sd->state) { -case sd_transfer_state: -if (!sd_is_spi (sd)) { -break ; - } -return sd_cmd_to_sendingdata (sd, req,sd_req_get_address (sd, req), - sd->cid,16 ); - -default : -break ; - } -break ; -case 12 :/* CMD12: STOP_TRANSMISSION */ switch (sd->state) {case sd_sendingdata_state:@@ -2288,6 +2276,8 @@ static const SDProto sd_proto_spi = { [5] = {9, sd_spi, "IO_SEND_OP_COND", sd_cmd_optional}, [6] = {10, sd_spi, "SWITCH_FUNCTION", sd_cmd_SWITCH_FUNCTION}, [8] = {0, sd_spi, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, + [9] = {0, sd_spi, "SEND_CSD", spi_cmd_SEND_CSD}, + [10] = {0, sd_spi, "SEND_CID", spi_cmd_SEND_CID}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
Re: [PATCH v42 51/98] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
In reply to Philippe Mathieu-DaudéHi,
Quoted 3 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>---
This patch results in:
[ 5.976133] Waiting for root device /dev/mmcblk0... [ 6.501462] mmc0: error -38 whilst initialising SD card [ 7.557473] mmc0: error -38 whilst initialising SD card
... (repeated until session is aborted)
when trying to boot Linux for sifive_u from sd card. The command used to boot the image is
qemu-system-riscv64 -M sifive_u -m 512M -no-reboot \
-kernel arch/riscv/boot/Image \
-snapshot -drive file=rootfs.ext2,format=raw,if=sd \
-bios default \
-append "root=/dev/mmcblk0 rootwait console=ttySIF0,115200 earlycon" \
-nographic -monitor noneBisect log is attached.
Guenter
---
# bad: [fd1952d814da738ed107e05583b3e02ac11e88ff] Update version for v9.1.0 release
# good: [c25df57ae8f9fe1c72eee2dab37d76d904ac382e] Update version for 9.0.0 release
git bisect start 'HEAD' 'v9.0.0'
# good: [2529ea2d561ea9fe359fb19ebdcfeb8b6cddd219] hw/acpi/ich9: Remove dead code related to 'acpi_memory_hotplug' git bisect good 2529ea2d561ea9fe359fb19ebdcfeb8b6cddd219
# bad: [76e375fc3c538bd6e4232314f693b56536a50b73] docs/qapidoc: add QMP highlighting to annotated qmp-example blocks git bisect bad 76e375fc3c538bd6e4232314f693b56536a50b73
# good: [720c0f3e6cf856fa62c06a8f0005d814684c30d9] hw/sd/sdcard: Register generic optional handlers (CMD11 and CMD20) git bisect good 720c0f3e6cf856fa62c06a8f0005d814684c30d9
# bad: [5915139aba1646220630596de30c673528e047c9] Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging git bisect bad 5915139aba1646220630596de30c673528e047c9
# bad: [188569c10d5dc6996bde90ce25645083e9661ecb] target/i386/SEV: implement mask_cpuid_features
git bisect bad 188569c10d5dc6996bde90ce25645083e9661ecb
# bad: [8442e1625ba6723bee2c6d0fdb7207a3e27a2b05] hw/sd/sdcard: Add sd_acmd_SEND_SCR handler (ACMD51) git bisect bad 8442e1625ba6723bee2c6d0fdb7207a3e27a2b05
# bad: [96f3d00ac1680f978984314d24ae6f2f6f281fdc] hw/sd/sdcard: Add sd_cmd_PROGRAM_CSD handler (CMD27) git bisect bad 96f3d00ac1680f978984314d24ae6f2f6f281fdc
# good: [1ec3cb893fa8883f5baf69850a4d0a97502bbad8] hw/sd/sdcard: Add sd_cmd_SEND_CSD/CID handlers (CMD9 & CMD10) git bisect good 1ec3cb893fa8883f5baf69850a4d0a97502bbad8
# bad: [9318be060506be33a0fbf01198b0024fdeb28f39] hw/sd/sdcard: Add sd_cmd_GO_INACTIVE_STATE handler (CMD15) git bisect bad 9318be060506be33a0fbf01198b0024fdeb28f39
# bad: [030897e89d3dff8ef7efd5cc570612da4476734f] hw/sd/sdcard: Add sd_cmd_STOP_TRANSMISSION handler (CMD12) git bisect bad 030897e89d3dff8ef7efd5cc570612da4476734f
# bad: [da954d0e32444f122a41c24948d4d1c718bf66d4] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10) git bisect bad da954d0e32444f122a41c24948d4d1c718bf66d4
# first bad commit: [da954d0e32444f122a41c24948d4d1c718bf66d4] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
Re: [PATCH v42 51/98] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
Hi Guenter,
Quoted 55 lines · Guenter Roeck
Hi,
Quoted 3 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>---
This patch results in:
[ 5.976133] Waiting for root device /dev/mmcblk0... [ 6.501462] mmc0: error -38 whilst initialising SD card [ 7.557473] mmc0: error -38 whilst initialising SD card... (repeated until session is aborted)
when trying to boot Linux for
sifive_ufrom sd card. The command used to boot the image isqemu-system-riscv64 -M sifive_u -m 512M -no-reboot \ -kernel arch/riscv/boot/Image \ -snapshot -drive file=rootfs.ext2,format=raw,if=sd \ -bios default \ -append "root=/dev/mmcblk0 rootwait console=ttySIF0,115200 earlycon" \ -nographic -monitor noneBisect log is attached.
Guenter
---
# bad: [fd1952d814da738ed107e05583b3e02ac11e88ff] Update version for v9.1.0 release
# good: [c25df57ae8f9fe1c72eee2dab37d76d904ac382e] Update version for 9.0.0 release
git bisect start 'HEAD' 'v9.0.0'
# good: [2529ea2d561ea9fe359fb19ebdcfeb8b6cddd219] hw/acpi/ich9: Remove dead code related to 'acpi_memory_hotplug' git bisect good2529ea2d561ea9fe359fb19ebdcfeb8b6cddd219
# bad: [76e375fc3c538bd6e4232314f693b56536a50b73] docs/qapidoc: add QMP highlighting to annotated qmp-example blocks git bisect bad76e375fc3c538bd6e4232314f693b56536a50b73
# good: [720c0f3e6cf856fa62c06a8f0005d814684c30d9] hw/sd/sdcard: Register generic optional handlers (CMD11 and CMD20) git bisect good720c0f3e6cf856fa62c06a8f0005d814684c30d9
# bad: [5915139aba1646220630596de30c673528e047c9] Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging git bisect bad5915139aba1646220630596de30c673528e047c9
# bad: [188569c10d5dc6996bde90ce25645083e9661ecb] target/i386/SEV: implementmask_cpuid_features
git bisect bad188569c10d5dc6996bde90ce25645083e9661ecb
# bad: [8442e1625ba6723bee2c6d0fdb7207a3e27a2b05] hw/sd/sdcard: Addsd_acmd_SEND_SCRhandler (ACMD51) git bisect bad8442e1625ba6723bee2c6d0fdb7207a3e27a2b05
# bad: [96f3d00ac1680f978984314d24ae6f2f6f281fdc] hw/sd/sdcard: Addsd_cmd_PROGRAM_CSDhandler (CMD27) git bisect bad96f3d00ac1680f978984314d24ae6f2f6f281fdc
# good: [1ec3cb893fa8883f5baf69850a4d0a97502bbad8] hw/sd/sdcard: Add sd_cmd_SEND_CSD/CID handlers (CMD9 & CMD10) git bisect good1ec3cb893fa8883f5baf69850a4d0a97502bbad8
# bad: [9318be060506be33a0fbf01198b0024fdeb28f39] hw/sd/sdcard: Addsd_cmd_GO_INACTIVE_STATEhandler (CMD15) git bisect bad9318be060506be33a0fbf01198b0024fdeb28f39
# bad: [030897e89d3dff8ef7efd5cc570612da4476734f] hw/sd/sdcard: Addsd_cmd_STOP_TRANSMISSIONhandler (CMD12) git bisect bad030897e89d3dff8ef7efd5cc570612da4476734f
# bad: [da954d0e32444f122a41c24948d4d1c718bf66d4] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10) git bisect badda954d0e32444f122a41c24948d4d1c718bf66d4
Quoted 1 line
# first bad commit: [da954d0e32444f122a41c24948d4d1c718bf66d4] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
I don't have access to my workstation, but looking at the patch, maybe the fix is simply:
---
hw/sd/sd.c +2 -2
@@ -1567,7 +1567,7 @@ static sd_rsp_type_t emmc_cmd_SEND_EXT_CSD(SDState *sd, SDRequest req)/* CMD9 */ static sd_rsp_type_t spi_cmd_SEND_CSD (SDState *sd,SDRequest req) { -if (sd->state != sd_standby_state) { +if (sd->state != sd_transfer_state) {return sd_invalid_state_for_cmd (sd, req); } return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req),
@@ -1586,7 +1586,7 @@ static sd_rsp_type_t sd_cmd_SEND_CSD(SDState *sd, SDRequest req)/* CMD10 */ static sd_rsp_type_t spi_cmd_SEND_CID (SDState *sd,SDRequest req) { -if (sd->state != sd_standby_state) { +if (sd->state != sd_transfer_state) {return sd_invalid_state_for_cmd (sd, req); } return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req),
---
Is it possible for you to test this snippet?
Regards,
Phil.
Re: [PATCH v42 51/98] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
Quoted 88 lines · Philippe Mathieu-Daudé
Hi Guenter,
Quoted 55 lines · Guenter Roeck
Hi,
Quoted 3 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>---
This patch results in:
[ 5.976133] Waiting for root device
/dev/mmcblk0... [ 6.501462] mmc0: error -38 whilst initialising SD card [ 7.557473] mmc0: error -38 whilst initialising SD card... (repeated until session is aborted)
when trying to boot Linux for
sifive_ufrom sd card. The command used to boot the image isqemu-system-riscv64 -M
sifive_u-m 512M -no-reboot \
-kernelarch/riscv/boot/Image\
-snapshot -drive file=rootfs.ext2,format=raw,if=sd \
-bios default \
-append "root=/dev/mmcblk0 rootwait console=ttySIF0,115200 earlycon" \
-nographic -monitor noneBisect log is attached.
Guenter
---
# bad: [fd1952d814da738ed107e05583b3e02ac11e88ff] Update version for v9.1.0 release
# good: [c25df57ae8f9fe1c72eee2dab37d76d904ac382e] Update version for 9.0.0 release
git bisect start 'HEAD' 'v9.0.0'
# good: [2529ea2d561ea9fe359fb19ebdcfeb8b6cddd219] hw/acpi/ich9: Remove dead code related to 'acpi_memory_hotplug' git bisect good2529ea2d561ea9fe359fb19ebdcfeb8b6cddd219
# bad: [76e375fc3c538bd6e4232314f693b56536a50b73] docs/qapidoc: add QMP highlighting to annotated qmp-example blocks git bisect bad76e375fc3c538bd6e4232314f693b56536a50b73
# good: [720c0f3e6cf856fa62c06a8f0005d814684c30d9] hw/sd/sdcard: Register generic optional handlers (CMD11 and CMD20) git bisect good720c0f3e6cf856fa62c06a8f0005d814684c30d9
# bad: [5915139aba1646220630596de30c673528e047c9] Merge tag 'for-upstream' of https://gitlab.com/bonzini/qemu into staging git bisect bad5915139aba1646220630596de30c673528e047c9
# bad: [188569c10d5dc6996bde90ce25645083e9661ecb] target/i386/SEV: implementmask_cpuid_features
git bisect bad188569c10d5dc6996bde90ce25645083e9661ecb
# bad: [8442e1625ba6723bee2c6d0fdb7207a3e27a2b05] hw/sd/sdcard: Addsd_acmd_SEND_SCRhandler (ACMD51) git bisect bad8442e1625ba6723bee2c6d0fdb7207a3e27a2b05
# bad: [96f3d00ac1680f978984314d24ae6f2f6f281fdc] hw/sd/sdcard: Addsd_cmd_PROGRAM_CSDhandler (CMD27) git bisect bad96f3d00ac1680f978984314d24ae6f2f6f281fdc
# good: [1ec3cb893fa8883f5baf69850a4d0a97502bbad8] hw/sd/sdcard: Add sd_cmd_SEND_CSD/CID handlers (CMD9 & CMD10) git bisect good1ec3cb893fa8883f5baf69850a4d0a97502bbad8
# bad: [9318be060506be33a0fbf01198b0024fdeb28f39] hw/sd/sdcard: Addsd_cmd_GO_INACTIVE_STATEhandler (CMD15) git bisect bad9318be060506be33a0fbf01198b0024fdeb28f39
# bad: [030897e89d3dff8ef7efd5cc570612da4476734f] hw/sd/sdcard: Addsd_cmd_STOP_TRANSMISSIONhandler (CMD12) git bisect bad030897e89d3dff8ef7efd5cc570612da4476734f
# bad: [da954d0e32444f122a41c24948d4d1c718bf66d4] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10) git bisect badda954d0e32444f122a41c24948d4d1c718bf66d4Quoted 1 line
# first bad commit: [da954d0e32444f122a41c24948d4d1c718bf66d4] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)I don't have access to my workstation, but looking at the patch, maybe the fix is simply:
---
hw/sd/sd.c +2
-3@@ -1567,7 +1567,7 @@ static sd_rsp_type_t emmc_cmd_SEND_EXT_CSD(SDState *sd, SDRequest req) /* CMD9 */ static sd_rsp_type_t spi_cmd_SEND_CSD(SDState *sd, SDRequest req) { - if (sd->state != sd_standby_state) { + if (sd->state != sd_transfer_state) { return sd_invalid_state_for_cmd(sd, req); } return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req),@@ -1586,7 +1586,7 @@ static sd_rsp_type_t sd_cmd_SEND_CSD(SDState *sd, SDRequest req) /* CMD10 */ static sd_rsp_type_t spi_cmd_SEND_CID(SDState *sd, SDRequest req) { - if (sd->state != sd_standby_state) { + if (sd->state != sd_transfer_state) { return sd_invalid_state_for_cmd(sd, req); } return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req), ---
Quoted 2 lines
Is it possible for you to test this snippet?
It must be related, but something else must be wrong. With the above, I get
[ 4.355063] Run /sbin/init as init process ssi_sd: error: Unexpected response to cmd 13 [ 4.780139] mmc0: SPI card removed [ 4.785194] EXT4-fs (mmcblk0): shut down requested (2) [ 4.812689] Starting init: /sbin/init exists but couldn't execute it (error -5) [ 4.813248] Run /etc/init as init process [ 4.825799] init: attempt to access beyond end of device
The state is always 4 when spi_cmd_SEND_CSD() and spi_cmd_SEND_CID() are called. With more debugging added:
ssi_sd: error: Unexpected response to cmd 13 (arglen expected 4, got 16)
Changing only one of the functions to check against sd_transfer_state doesn't help either; that brings back the repeated error -38.
Guenter
Re: [PATCH v42 51/98] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
Hi Guenter,
Quoted 75 lines · Guenter Roeck
Quoted 61 lines · Philippe Mathieu-Daudé
Hi Guenter,
Quoted 26 lines · Guenter Roeck
Hi,
Quoted 3 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>---
This patch results in:
[ 5.976133] Waiting for root device
/dev/mmcblk0... [ 6.501462] mmc0: error -38 whilst initialising SD card [ 7.557473] mmc0: error -38 whilst initialising SD card... (repeated until session is aborted)
when trying to boot Linux for
sifive_ufrom sd card. The command used to boot the image isqemu-system-riscv64 -M
sifive_u-m 512M -no-reboot \
-kernelarch/riscv/boot/Image\
-snapshot -drive file=rootfs.ext2,format=raw,if=sd \
-bios default \
-append "root=/dev/mmcblk0 rootwait console=ttySIF0,115200 earlycon" \
-nographic -monitor noneQuoted 1 line
# first bad commit: [da954d0e32444f122a41c24948d4d1c718bf66d4] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)I don't have access to my workstation, but looking at the patch, maybe the fix is simply:
---
hw/sd/sd.c +1
-1@@ -1567,7 +1567,7 @@ static sd_rsp_type_t emmc_cmd_SEND_EXT_CSD(SDState *sd, SDRequest req) /* CMD9 */ static sd_rsp_type_t spi_cmd_SEND_CSD(SDState *sd, SDRequest req) { - if (sd->state != sd_standby_state) { + if (sd->state != sd_transfer_state) { return sd_invalid_state_for_cmd(sd, req); }return sd_cmd_to_sendingdata(sd, req,
sd_req_get_address(sd, req),hw/sd/sd.c +1
-1@@ -1586,7 +1586,7 @@ static sd_rsp_type_t sd_cmd_SEND_CSD(SDState *sd, SDRequest req) /* CMD10 */ static sd_rsp_type_t spi_cmd_SEND_CID(SDState *sd, SDRequest req) { - if (sd->state != sd_standby_state) { + if (sd->state != sd_transfer_state) { return sd_invalid_state_for_cmd(sd, req); }return sd_cmd_to_sendingdata(sd, req,
sd_req_get_address(sd, req),
---Quoted 2 lines
Is it possible for you to test this snippet?
It must be related, but something else must be wrong. With the above, I get
[ 4.355063] Run
/sbin/initas init processssi_sd: error: Unexpected response to cmd 13
[ 4.780139] mmc0: SPI card removed
[ 4.785194] EXT4-fs (mmcblk0): shut down requested (2)
[ 4.812689] Starting init:/sbin/initexists but couldn't execute it (error -5) [ 4.813248] Run/etc/initas init process
[ 4.825799] init: attempt to access beyond end of device
Quoted 7 lines
The state is always 4 when
spi_cmd_SEND_CSD()andspi_cmd_SEND_CID()are called. With more debugging added:
ssi_sd: error: Unexpected response to cmd 13 (arglen expected 4, got 16)Changing only one of the functions to check against
sd_transfer_statedoesn't help either; that brings back the repeated error -38.
Looking at commit 807f6adac37 ("hw/sd/sdcard: Add sd_cmd_SEND_STATUS handler (CMD13)"), this should fix:
-- >8 --
@@ -1639,7 +1639,7 @@ static sd_rsp_type_t sd_cmd_SEND_STATUS(SDState *sd, SDRequest req)
}
if (sd_is_spi(sd)) {
- return sd_r2_s;
+ return sd_r1;
}
return sd_req_rca_same(sd, req) ? sd_r1 : sd_r0;---
But -- why the commit msg didn't mention the spec fix -- the commit looks correct to me. We might be missing smth from the spec. I'll
have a look during soft freeze. Having a test such the one recently added in https://lore.kernel.org/qemu-devel/[email protected]/
would help me ;)
Regards,
Phil.
Re: [PATCH v42 51/98] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
Quoted 79 lines · Philippe Mathieu-Daudé
Hi Guenter,
Quoted 76 lines · Guenter Roeck
Quoted 59 lines · Philippe Mathieu-Daudé
Hi Guenter,
Quoted 26 lines · Guenter Roeck
Hi,
Quoted 3 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>---
This patch results in:
[ 5.976133] Waiting for root device
/dev/mmcblk0... [ 6.501462] mmc0: error -38 whilst initialising SD card [ 7.557473] mmc0: error -38 whilst initialising SD card... (repeated until session is aborted)
when trying to boot Linux for
sifive_ufrom sd card. The command used to boot the image isqemu-system-riscv64 -M
sifive_u-m 512M -no-reboot \
-kernelarch/riscv/boot/Image\
-snapshot -drive file=rootfs.ext2,format=raw,if=sd \
-bios default \
-append "root=/dev/mmcblk0 rootwait console=ttySIF0,115200 earlycon" \
-nographic -monitor noneQuoted 1 line
# first bad commit: [da954d0e32444f122a41c24948d4d1c718bf66d4] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)I don't have access to my workstation, but looking at the patch, maybe the fix is simply:
---
hw/sd/sd.c +2
-3@@ -1567,7 +1567,7 @@ static sd_rsp_type_t emmc_cmd_SEND_EXT_CSD(SDState *sd, SDRequest req) /* CMD9 */ static sd_rsp_type_t spi_cmd_SEND_CSD(SDState *sd, SDRequest req) { - if (sd->state != sd_standby_state) { + if (sd->state != sd_transfer_state) { return sd_invalid_state_for_cmd(sd, req); } return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req),@@ -1586,7 +1586,7 @@ static sd_rsp_type_t sd_cmd_SEND_CSD(SDState *sd, SDRequest req) /* CMD10 */ static sd_rsp_type_t spi_cmd_SEND_CID(SDState *sd, SDRequest req) { - if (sd->state != sd_standby_state) { + if (sd->state != sd_transfer_state) { return sd_invalid_state_for_cmd(sd, req); } return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req), ---Quoted 2 lines
Is it possible for you to test this snippet?
It must be related, but something else must be wrong. With the above, I get
[ 4.355063] Run
/sbin/initas init processssi_sd: error: Unexpected response to cmd 13
[ 4.780139] mmc0: SPI card removed
[ 4.785194] EXT4-fs (mmcblk0): shut down requested (2)
[ 4.812689] Starting init:/sbin/initexists but couldn't execute it (error -5) [ 4.813248] Run/etc/initas init process
[ 4.825799] init: attempt to access beyond end of deviceThe state is always 4 when
spi_cmd_SEND_CSD()andspi_cmd_SEND_CID()are called. With more debugging added:
Quoted 8 lines
Quoted 4 lines
ssi_sd: error: Unexpected response to cmd 13 (arglen expected 4, got 16)Changing only one of the functions to check against
sd_transfer_statedoesn't help either; that brings back the repeated error -38.Looking at commit
807f6adac37("hw/sd/sdcard: Addsd_cmd_SEND_STATUShandler (CMD13)"), this should fix:
Yes, it does fix the problem, together with the sd_transfer_state changes above.
I noticed that sd_cmd_SEND_CSD() and sd_cmd_SEND_CID() also check against sd_standby_state. Is that wrong as well ?
Quoted 12 lines
-- >8 --
(quoted diff) +1
-2@@ -1639,7 +1639,7 @@ static sd_rsp_type_t sd_cmd_SEND_STATUS(SDState *sd, SDRequest req) } if (sd_is_spi(sd)) { - return sd_r2_s; + return sd_r1; } return sd_req_rca_same(sd, req) ? sd_r1 : sd_r0; ---
Quoted 6 lines
But -- why the commit msg didn't mention the spec fix -- the commit looks correct to me. We might be missing smth from the spec. I'll
have a look during soft freeze. Having a test such the one recently added in https://lore.kernel.org/qemu-devel/[email protected]/
would help me ;)
I'll see if I can add one to [email protected]:groeck/linux-test-downloads.git.
Thanks,
Guenter
Re: [PATCH v42 51/98] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)
Quoted 85 lines · Guenter Roeck
Quoted 84 lines · Philippe Mathieu-Daudé
Hi Guenter,
Quoted 80 lines · Guenter Roeck
Quoted 59 lines · Philippe Mathieu-Daudé
Hi Guenter,
Quoted 26 lines · Guenter Roeck
Hi,
Quoted 3 lines · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>Reviewed-by Cédric Le Goater <[email protected]>---
This patch results in:
[ 5.976133] Waiting for root device
/dev/mmcblk0... [ 6.501462] mmc0: error -38 whilst initialising SD card [ 7.557473] mmc0: error -38 whilst initialising SD card... (repeated until session is aborted)
when trying to boot Linux for
sifive_ufrom sd card. The command used to boot the image isqemu-system-riscv64 -M
sifive_u-m 512M -no-reboot \
-kernelarch/riscv/boot/Image\
-snapshot -drive file=rootfs.ext2,format=raw,if=sd \
-bios default \
-append "root=/dev/mmcblk0 rootwait console=ttySIF0,115200 earlycon" \
-nographic -monitor noneQuoted 1 line
# first bad commit: [da954d0e32444f122a41c24948d4d1c718bf66d4] hw/sd/sdcard: Add spi_cmd_SEND_CSD/CID handlers (CMD9 & CMD10)I don't have access to my workstation, but looking at the patch, maybe the fix is simply:
---
hw/sd/sd.c +2
-3@@ -1567,7 +1567,7 @@ static sd_rsp_type_t emmc_cmd_SEND_EXT_CSD(SDState *sd, SDRequest req) /* CMD9 */ static sd_rsp_type_t spi_cmd_SEND_CSD(SDState *sd, SDRequest req) { - if (sd->state != sd_standby_state) { + if (sd->state != sd_transfer_state) { return sd_invalid_state_for_cmd(sd, req); } return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req),@@ -1586,7 +1586,7 @@ static sd_rsp_type_t sd_cmd_SEND_CSD(SDState *sd, SDRequest req) /* CMD10 */ static sd_rsp_type_t spi_cmd_SEND_CID(SDState *sd, SDRequest req) { - if (sd->state != sd_standby_state) { + if (sd->state != sd_transfer_state) { return sd_invalid_state_for_cmd(sd, req); } return sd_cmd_to_sendingdata(sd, req, sd_req_get_address(sd, req), ---Quoted 2 lines
Is it possible for you to test this snippet?
It must be related, but something else must be wrong. With the above, I get
[ 4.355063] Run
/sbin/initas init processssi_sd: error: Unexpected response to cmd 13
[ 4.780139] mmc0: SPI card removed
[ 4.785194] EXT4-fs (mmcblk0): shut down requested (2)
[ 4.812689] Starting init:/sbin/initexists but couldn't execute it (error -5) [ 4.813248] Run/etc/initas init process
[ 4.825799] init: attempt to access beyond end of deviceThe state is always 4 when
spi_cmd_SEND_CSD()andspi_cmd_SEND_CID()are called. With more debugging added:
ssi_sd: error: Unexpected response to cmd 13 (arglen expected 4, got 16)Changing only one of the functions to check against
sd_transfer_statedoesn't help either; that brings back the repeated error -38.
Quoted 9 lines
Quoted 3 lines
Looking at commit
807f6adac37("hw/sd/sdcard: Addsd_cmd_SEND_STATUShandler (CMD13)"), this should fix:Yes, it does fix the problem, together with the
sd_transfer_statechanges above.I noticed that
sd_cmd_SEND_CSD()andsd_cmd_SEND_CID()also check againstsd_standby_state. Is that wrong as well ?
Never mind; those are correct.
Guenter
PATCH v42 52/98 hw/sd/sdcard: Add sd_cmd_STOP_TRANSMISSION handler (CMD12)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-)
hw/sd/sd.c +20 -18
@@ -240,7 +240,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" , + [13 ] ="SEND_STATUS" , [15 ] ="GO_INACTIVE_STATE" , [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" , [18 ] ="READ_MULTIPLE_BLOCK" ,
@@ -1360,6 +1360,23 @@ static sd_rsp_type_t sd_cmd_SEND_CID(SDState *sd, SDRequest req)return sd_req_rca_same (sd, req) ? sd_r2_i : sd_r0; } +/* CMD12 */ +static sd_rsp_type_t sd_cmd_STOP_TRANSMISSION (SDState *sd,SDRequest req) +{ +switch (sd->state) { +case sd_sendingdata_state: + sd->state = sd_transfer_state; +return sd_r1b; +case sd_receivingdata_state: + sd->state = sd_programming_state; +/* Bzzzzzzztt .... Operation complete. */ + sd->state = sd_transfer_state; +return sd_r1; +default : +return sd_invalid_state_for_cmd (sd, req); + } +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {
@@ -1426,23 +1443,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 12 :/* CMD12: STOP_TRANSMISSION */ -switch (sd->state) { -case sd_sendingdata_state: - sd->state = sd_transfer_state; -return sd_r1b; - -case sd_receivingdata_state: - sd->state = sd_programming_state; -/* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; -return sd_r1b; - -default : -break ; - } -break ; -case 13 :/* CMD13: SEND_STATUS */ rca =sd_req_get_rca (sd, req);if (sd->mode != sd_data_transfer_mode) {
@@ -2278,6 +2278,7 @@ static const SDProto sd_proto_spi = { [8] = {0, sd_spi, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, [9] = {0, sd_spi, "SEND_CSD", spi_cmd_SEND_CSD}, [10] = {0, sd_spi, "SEND_CID", spi_cmd_SEND_CID}, + [12] = {0, sd_spi, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2306,6 +2307,7 @@ static const SDProto sd_proto_sd = { [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, + [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},
Signature · 1 line
2.41.0
Re: [PATCH v42 52/98] hw/sd/sdcard: Add sd_cmd_STOP_TRANSMISSION handler (CMD12)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 80 lines
---
hw/sd/sd.c| 38 ++++++++++++++++++++------------------> 1 file changed, 20 insertions(+), 18 deletions(-)hw/sd/sd.c +20
-18@@ -240,7 +240,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [12 ] ="STOP_TRANSMISSION" , [13 ] ="SEND_STATUS" , + [13 ] ="SEND_STATUS" , [15 ] ="GO_INACTIVE_STATE" , [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" , [18 ] ="READ_MULTIPLE_BLOCK" ,@@ -1360,6 +1360,23 @@ static sd_rsp_type_t sd_cmd_SEND_CID(SDState *sd, SDRequest req)return sd_req_rca_same (sd, req) ? sd_r2_i : sd_r0; } +/* CMD12 */ +static sd_rsp_type_t sd_cmd_STOP_TRANSMISSION (SDState *sd,SDRequest req) +{ +switch (sd->state) { +case sd_sendingdata_state: + sd->state = sd_transfer_state; +return sd_r1b; +case sd_receivingdata_state: + sd->state = sd_programming_state; +/* Bzzzzzzztt .... Operation complete. */ + sd->state = sd_transfer_state; +return sd_r1; +default : +return sd_invalid_state_for_cmd (sd, req); + } +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {@@ -1426,23 +1443,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 12 :/* CMD12: STOP_TRANSMISSION */ -switch (sd->state) { -case sd_sendingdata_state: - sd->state = sd_transfer_state; -return sd_r1b; - -case sd_receivingdata_state: - sd->state = sd_programming_state; -/* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; -return sd_r1b; - -default : -break ; - } -break ; -case 13 :/* CMD13: SEND_STATUS */ rca =sd_req_get_rca (sd, req);if (sd->mode != sd_data_transfer_mode) {@@ -2278,6 +2278,7 @@ static const SDProto sd_proto_spi = { [8] = {0, sd_spi, "SEND_IF_COND", sd_cmd_SEND_IF_COND}, [9] = {0, sd_spi, "SEND_CSD", spi_cmd_SEND_CSD}, [10] = {0, sd_spi, "SEND_CID", spi_cmd_SEND_CID}, + [12] = {0, sd_spi, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2306,6 +2307,7 @@ static const SDProto sd_proto_sd = { [9] = {0, sd_ac, "SEND_CSD", sd_cmd_SEND_CSD}, [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, + [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},
PATCH v42 53/98 hw/sd/sdcard: Add sd_cmd_SEND_STATUS handler (CMD13)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)
hw/sd/sd.c +28 -12
@@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [13 ] ="SEND_STATUS" , [15 ] ="GO_INACTIVE_STATE" , [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" , [18 ] ="READ_MULTIPLE_BLOCK" ,
@@ -1377,6 +1376,32 @@ static sd_rsp_type_t sd_cmd_STOP_TRANSMISSION(SDState *sd, SDRequest req) } } +/* CMD13 */ +static sd_rsp_type_t sd_cmd_SEND_STATUS (SDState *sd,SDRequest req) +{ +if (sd->mode != sd_data_transfer_mode) { +return sd_invalid_mode_for_cmd (sd, req); + } + +switch (sd->state) { +case sd_standby_state: +case sd_transfer_state: +case sd_sendingdata_state: +case sd_receivingdata_state: +case sd_programming_state: +case sd_disconnect_state: +break ; +default : +return sd_invalid_state_for_cmd (sd, req); + } + +if (sd_is_spi (sd)) { +return sd_r2_s; + } + +return sd_req_rca_same (sd, req) ? sd_r1 : sd_r0; +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {
@@ -1443,17 +1468,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 13 :/* CMD13: SEND_STATUS */ - rca =sd_req_get_rca (sd, req); -if (sd->mode != sd_data_transfer_mode) { -return sd_invalid_mode_for_cmd (sd, req); - } -if (!sd_is_spi (sd) && sd->rca != rca) { -return sd_r0; - } - -return sd_r1; -case 15 :/* CMD15: GO_INACTIVE_STATE */ if (sd->mode != sd_data_transfer_mode) {return sd_invalid_mode_for_cmd (sd, req);
@@ -2279,6 +2293,7 @@ static const SDProto sd_proto_spi = { [9] = {0, sd_spi, "SEND_CSD", spi_cmd_SEND_CSD}, [10] = {0, sd_spi, "SEND_CID", spi_cmd_SEND_CID}, [12] = {0, sd_spi, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, + [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2308,6 +2323,7 @@ static const SDProto sd_proto_sd = { [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, + [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},
Signature · 1 line
2.41.0
Re: [PATCH v42 53/98] hw/sd/sdcard: Add sd_cmd_SEND_STATUS handler (CMD13)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 83 lines
--- hw/sd/sd.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-)hw/sd/sd.c +28
-12@@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [13 ] ="SEND_STATUS" , [15 ] ="GO_INACTIVE_STATE" , [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" , [18 ] ="READ_MULTIPLE_BLOCK" ,@@ -1377,6 +1376,32 @@ static sd_rsp_type_t sd_cmd_STOP_TRANSMISSION(SDState *sd, SDRequest req) } } +/* CMD13 */ +static sd_rsp_type_t sd_cmd_SEND_STATUS (SDState *sd,SDRequest req) +{ +if (sd->mode != sd_data_transfer_mode) { +return sd_invalid_mode_for_cmd (sd, req); + } + +switch (sd->state) { +case sd_standby_state: +case sd_transfer_state: +case sd_sendingdata_state: +case sd_receivingdata_state: +case sd_programming_state: +case sd_disconnect_state: +break ; +default : +return sd_invalid_state_for_cmd (sd, req); + } + +if (sd_is_spi (sd)) { +return sd_r2_s; + } + +return sd_req_rca_same (sd, req) ? sd_r1 : sd_r0; +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {@@ -1443,17 +1468,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Basic commands (Class 0 and Class 1) */ -case 13 :/* CMD13: SEND_STATUS */ - rca =sd_req_get_rca (sd, req); -if (sd->mode != sd_data_transfer_mode) { -return sd_invalid_mode_for_cmd (sd, req); - } -if (!sd_is_spi (sd) && sd->rca != rca) { -return sd_r0; - } - -return sd_r1; -case 15 :/* CMD15: GO_INACTIVE_STATE */ if (sd->mode != sd_data_transfer_mode) {return sd_invalid_mode_for_cmd (sd, req);@@ -2279,6 +2293,7 @@ static const SDProto sd_proto_spi = { [9] = {0, sd_spi, "SEND_CSD", spi_cmd_SEND_CSD}, [10] = {0, sd_spi, "SEND_CID", spi_cmd_SEND_CID}, [12] = {0, sd_spi, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, + [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2308,6 +2323,7 @@ static const SDProto sd_proto_sd = { [10] = {0, sd_ac, "SEND_CID", sd_cmd_SEND_CID}, [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, + [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},
PATCH v42 54/98 hw/sd/sdcard: Add sd_cmd_GO_INACTIVE_STATE handler (CMD15)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)
hw/sd/sd.c +25 -12
@@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [15 ] ="GO_INACTIVE_STATE" , [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" , [18 ] ="READ_MULTIPLE_BLOCK" , [21 ] ="DPS_spec" ,
@@ -1402,6 +1401,30 @@ static sd_rsp_type_t sd_cmd_SEND_STATUS(SDState *sd, SDRequest req)return sd_req_rca_same (sd, req) ? sd_r1 : sd_r0; } +/* CMD15 */ +static sd_rsp_type_t sd_cmd_GO_INACTIVE_STATE (SDState *sd,SDRequest req) +{ +if (sd->mode != sd_data_transfer_mode) { +return sd_invalid_mode_for_cmd (sd, req); + } +switch (sd->state) { +case sd_standby_state: +case sd_transfer_state: +case sd_sendingdata_state: +case sd_receivingdata_state: +case sd_programming_state: +case sd_disconnect_state: +break ; +default : +return sd_invalid_state_for_cmd (sd, req); + } +if (sd_req_rca_same (sd, req)) { + sd->state = sd_inactive_state; + } + +return sd_r0; +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {
@@ -1467,17 +1490,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) }switch (req.cmd) { -/* Basic commands (Class 0 and Class 1) */ -case 15 :/* CMD15: GO_INACTIVE_STATE */ -if (sd->mode != sd_data_transfer_mode) { -return sd_invalid_mode_for_cmd (sd, req); - } - rca =sd_req_get_rca (sd, req); -if (sd->rca == rca) { - sd->state = sd_inactive_state; - } -return sd_r0; -/* Block read commands (Class 2) */ case 16 :/* CMD16: SET_BLOCKLEN */ switch (sd->state) {
@@ -2324,6 +2336,7 @@ static const SDProto sd_proto_sd = { [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, + [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},
Signature · 1 line
2.41.0
Re: [PATCH v42 54/98] hw/sd/sdcard: Add sd_cmd_GO_INACTIVE_STATE handler (CMD15)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 73 lines
--- hw/sd/sd.c | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-)hw/sd/sd.c +25
-12@@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [15 ] ="GO_INACTIVE_STATE" , [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" , [18 ] ="READ_MULTIPLE_BLOCK" , [21 ] ="DPS_spec" ,@@ -1402,6 +1401,30 @@ static sd_rsp_type_t sd_cmd_SEND_STATUS(SDState *sd, SDRequest req)return sd_req_rca_same (sd, req) ? sd_r1 : sd_r0; } +/* CMD15 */ +static sd_rsp_type_t sd_cmd_GO_INACTIVE_STATE (SDState *sd,SDRequest req) +{ +if (sd->mode != sd_data_transfer_mode) { +return sd_invalid_mode_for_cmd (sd, req); + } +switch (sd->state) { +case sd_standby_state: +case sd_transfer_state: +case sd_sendingdata_state: +case sd_receivingdata_state: +case sd_programming_state: +case sd_disconnect_state: +break ; +default : +return sd_invalid_state_for_cmd (sd, req); + } +if (sd_req_rca_same (sd, req)) { + sd->state = sd_inactive_state; + } + +return sd_r0; +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {@@ -1467,17 +1490,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) }switch (req.cmd) { -/* Basic commands (Class 0 and Class 1) */ -case 15 :/* CMD15: GO_INACTIVE_STATE */ -if (sd->mode != sd_data_transfer_mode) { -return sd_invalid_mode_for_cmd (sd, req); - } - rca =sd_req_get_rca (sd, req); -if (sd->rca == rca) { - sd->state = sd_inactive_state; - } -return sd_r0; -/* Block read commands (Class 2) */ case 16 :/* CMD16: SET_BLOCKLEN */ switch (sd->state) {@@ -2324,6 +2336,7 @@ static const SDProto sd_proto_sd = { [11] = {0, sd_ac, "VOLTAGE_SWITCH", sd_cmd_optional}, [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, + [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},
PATCH v42 55/98 hw/sd/sdcard: Add sd_cmd_SET_BLOCKLEN handler (CMD16)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-)
hw/sd/sd.c +19 -18
@@ -240,7 +240,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" , + [17 ] ="READ_SINGLE_BLOCK" , [18 ] ="READ_MULTIPLE_BLOCK" , [21 ] ="DPS_spec" , [24 ] ="WRITE_BLOCK" , [25 ] ="WRITE_MULTIPLE_BLOCK" ,
@@ -1425,6 +1425,22 @@ static sd_rsp_type_t sd_cmd_GO_INACTIVE_STATE(SDState *sd, SDRequest req)return sd_r0; } +/* CMD16 */ +static sd_rsp_type_t sd_cmd_SET_BLOCKLEN (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } +if (req.arg > (1 <<HWBLOCK_SHIFT )) { + sd->card_status |=BLOCK_LEN_ERROR ; + }else { +trace_sdcard_set_blocklen (req.arg); + sd->blk_len = req.arg; + } + +return sd_r1; +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {
@@ -1491,23 +1507,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Block read commands (Class 2) */ -case 16 :/* CMD16: SET_BLOCKLEN */ -switch (sd->state) { -case sd_transfer_state: -if (req.arg > (1 <<HWBLOCK_SHIFT )) { - sd->card_status |=BLOCK_LEN_ERROR ; - }else { -trace_sdcard_set_blocklen (req.arg); - sd->blk_len = req.arg; - } - -return sd_r1; - -default : -break ; - } -break ; -case 17 :/* CMD17: READ_SINGLE_BLOCK */ addr =sd_req_get_address (sd, req);switch (sd->state) {
@@ -2306,6 +2305,7 @@ static const SDProto sd_proto_spi = { [10] = {0, sd_spi, "SEND_CID", spi_cmd_SEND_CID}, [12] = {0, sd_spi, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, + [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2337,6 +2337,7 @@ static const SDProto sd_proto_sd = { [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, + [16] = {2, sd_ac, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},
Signature · 1 line
2.41.0
Re: [PATCH v42 55/98] hw/sd/sdcard: Add sd_cmd_SET_BLOCKLEN handler (CMD16)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 80 lines
--- hw/sd/sd.c | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-)hw/sd/sd.c +19
-18@@ -240,7 +240,7 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [16 ] ="SET_BLOCKLEN" , [17 ] ="READ_SINGLE_BLOCK" , + [17 ] ="READ_SINGLE_BLOCK" , [18 ] ="READ_MULTIPLE_BLOCK" , [21 ] ="DPS_spec" , [24 ] ="WRITE_BLOCK" , [25 ] ="WRITE_MULTIPLE_BLOCK" ,@@ -1425,6 +1425,22 @@ static sd_rsp_type_t sd_cmd_GO_INACTIVE_STATE(SDState *sd, SDRequest req)return sd_r0; } +/* CMD16 */ +static sd_rsp_type_t sd_cmd_SET_BLOCKLEN (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } +if (req.arg > (1 <<HWBLOCK_SHIFT )) { + sd->card_status |=BLOCK_LEN_ERROR ; + }else { +trace_sdcard_set_blocklen (req.arg); + sd->blk_len = req.arg; + } + +return sd_r1; +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {@@ -1491,23 +1507,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Block read commands (Class 2) */ -case 16 :/* CMD16: SET_BLOCKLEN */ -switch (sd->state) { -case sd_transfer_state: -if (req.arg > (1 <<HWBLOCK_SHIFT )) { - sd->card_status |=BLOCK_LEN_ERROR ; - }else { -trace_sdcard_set_blocklen (req.arg); - sd->blk_len = req.arg; - } - -return sd_r1; - -default : -break ; - } -break ; -case 17 :/* CMD17: READ_SINGLE_BLOCK */ addr =sd_req_get_address (sd, req);switch (sd->state) {@@ -2306,6 +2305,7 @@ static const SDProto sd_proto_spi = { [10] = {0, sd_spi, "SEND_CID", spi_cmd_SEND_CID}, [12] = {0, sd_spi, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, + [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2337,6 +2337,7 @@ static const SDProto sd_proto_sd = { [12] = {0, sd_ac, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, + [16] = {2, sd_ac, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},
PATCH v42 56/98 hw/sd/sdcard: Add sd_cmd_READ_SINGLE_BLOCK handler (CMD17)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-)
hw/sd/sd.c +20 -17
@@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [17 ] ="READ_SINGLE_BLOCK" , [18 ] ="READ_MULTIPLE_BLOCK" , [21 ] ="DPS_spec" , [24 ] ="WRITE_BLOCK" , [25 ] ="WRITE_MULTIPLE_BLOCK" ,
@@ -1441,6 +1440,24 @@ static sd_rsp_type_t sd_cmd_SET_BLOCKLEN(SDState *sd, SDRequest req)return sd_r1; } +/* CMD17 */ +static sd_rsp_type_t sd_cmd_READ_SINGLE_BLOCK (SDState *sd,SDRequest req) +{ +uint64_t addr; + +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + addr =sd_req_get_address (sd, req); +if (!address_in_range (sd,"READ_SINGLE_BLOCK" , addr, sd->blk_len)) { +return sd_r1; + } + +sd_blk_read (sd, addr, sd->blk_len); +return sd_cmd_to_sendingdata (sd, req, addr,NULL , sd->blk_len); +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {
@@ -1507,22 +1524,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Block read commands (Class 2) */ -case 17 :/* CMD17: READ_SINGLE_BLOCK */ - addr =sd_req_get_address (sd, req); -switch (sd->state) { -case sd_transfer_state: - -if (!address_in_range (sd,"READ_SINGLE_BLOCK" , addr, sd->blk_len)) { -return sd_r1; - } -sd_blk_read (sd, addr, sd->blk_len); -return sd_cmd_to_sendingdata (sd, req, addr,NULL , sd->blk_len); - -default : -break ; - } -break ; -case 18 :/* CMD18: READ_MULTIPLE_BLOCK */ addr =sd_req_get_address (sd, req);switch (sd->state) {
@@ -2306,6 +2307,7 @@ static const SDProto sd_proto_spi = { [12] = {0, sd_spi, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, + [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2338,6 +2340,7 @@ static const SDProto sd_proto_sd = { [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, [16] = {2, sd_ac, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, + [17] = {2, sd_adtc, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},
Signature · 1 line
2.41.0
Re: [PATCH v42 56/98] hw/sd/sdcard: Add sd_cmd_READ_SINGLE_BLOCK handler (CMD17)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 80 lines
--- hw/sd/sd.c | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-)hw/sd/sd.c +20
-17@@ -240,7 +240,6 @@ static const char *sd_response_name(sd_rsp_type_t rsp)static const char *sd_cmd_name (SDState *sd,uint8_t cmd) {static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { - [17 ] ="READ_SINGLE_BLOCK" , [18 ] ="READ_MULTIPLE_BLOCK" , [21 ] ="DPS_spec" , [24 ] ="WRITE_BLOCK" , [25 ] ="WRITE_MULTIPLE_BLOCK" ,@@ -1441,6 +1440,24 @@ static sd_rsp_type_t sd_cmd_SET_BLOCKLEN(SDState *sd, SDRequest req)return sd_r1; } +/* CMD17 */ +static sd_rsp_type_t sd_cmd_READ_SINGLE_BLOCK (SDState *sd,SDRequest req) +{ +uint64_t addr; + +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + addr =sd_req_get_address (sd, req); +if (!address_in_range (sd,"READ_SINGLE_BLOCK" , addr, sd->blk_len)) { +return sd_r1; + } + +sd_blk_read (sd, addr, sd->blk_len); +return sd_cmd_to_sendingdata (sd, req, addr,NULL , sd->blk_len); +} +/* CMD19 */ static sd_rsp_type_t sd_cmd_SEND_TUNING_BLOCK (SDState *sd,SDRequest req) {@@ -1507,22 +1524,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)switch (req.cmd) {/* Block read commands (Class 2) */ -case 17 :/* CMD17: READ_SINGLE_BLOCK */ - addr =sd_req_get_address (sd, req); -switch (sd->state) { -case sd_transfer_state: - -if (!address_in_range (sd,"READ_SINGLE_BLOCK" , addr, sd->blk_len)) { -return sd_r1; - } -sd_blk_read (sd, addr, sd->blk_len); -return sd_cmd_to_sendingdata (sd, req, addr,NULL , sd->blk_len); - -default : -break ; - } -break ; -case 18 :/* CMD18: READ_MULTIPLE_BLOCK */ addr =sd_req_get_address (sd, req);switch (sd->state) {@@ -2306,6 +2307,7 @@ static const SDProto sd_proto_spi = { [12] = {0, sd_spi, "STOP_TRANSMISSION", sd_cmd_STOP_TRANSMISSION}, [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, + [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2338,6 +2340,7 @@ static const SDProto sd_proto_sd = { [13] = {0, sd_ac, "SEND_STATUS", sd_cmd_SEND_STATUS}, [15] = {0, sd_ac, "GO_INACTIVE_STATE", sd_cmd_GO_INACTIVE_STATE}, [16] = {2, sd_ac, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, + [17] = {2, sd_adtc, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT},
PATCH v42 57/98 hw/sd/sdcard: Add sd_cmd_WRITE_SINGLE_BLOCK handler (CMD24)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 57 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 27 deletions(-)
hw/sd/sd.c +30 -27
@@ -242,7 +242,7 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd)static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { [18 ] ="READ_MULTIPLE_BLOCK" , [21 ] ="DPS_spec" , - [24 ] ="WRITE_BLOCK" , [25 ] ="WRITE_MULTIPLE_BLOCK" , + [25 ] ="WRITE_MULTIPLE_BLOCK" , [26 ] ="MANUF_RSVD" , [27 ] ="PROGRAM_CSD" , [28 ] ="SET_WRITE_PROT" , [29 ] ="CLR_WRITE_PROT" , [30 ] ="SEND_WRITE_PROT" ,
@@ -1487,6 +1487,33 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req)return sd_r1; } +/* CMD24 */ +static sd_rsp_type_t sd_cmd_WRITE_SINGLE_BLOCK (SDState *sd,SDRequest req) +{ +uint64_t addr; + +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + addr =sd_req_get_address (sd, req); +if (!address_in_range (sd,"WRITE_SINGLE_BLOCK" , addr, sd->blk_len)) { +return sd_r1; + } + +if (sd->size <=SDSC_MAX_CAPACITY ) { +if (sd_wp_addr (sd, addr)) { + sd->card_status |=WP_VIOLATION ; + } + } +if (sd->csd[14 ] &0x30 ) { + sd->card_status |=WP_VIOLATION ; + } + + sd->blk_written =0 ; +return sd_cmd_to_receivingdata (sd, req, addr, sd->blk_len); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;
@@ -1544,32 +1571,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)break ;/* Block write commands (Class 4) */ -case 24 :/* CMD24: WRITE_SINGLE_BLOCK */ - addr =sd_req_get_address (sd, req); -switch (sd->state) { -case sd_transfer_state: - -if (!address_in_range (sd,"WRITE_SINGLE_BLOCK" , addr, - sd->blk_len)) { -return sd_r1; - } - -if (sd->size <=SDSC_MAX_CAPACITY ) { -if (sd_wp_addr (sd, sd->data_start)) { - sd->card_status |=WP_VIOLATION ; - } - } -if (sd->csd[14 ] &0x30 ) { - sd->card_status |=WP_VIOLATION ; - } - sd->blk_written =0 ; -return sd_cmd_to_receivingdata (sd, req, addr, sd->blk_len); - -default : -break ; - } -break ; -case 25 :/* CMD25: WRITE_MULTIPLE_BLOCK */ addr =sd_req_get_address (sd, req);switch (sd->state) {
@@ -2308,6 +2309,7 @@ static const SDProto sd_proto_spi = { [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, + [24] = {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2344,6 +2346,7 @@ static const SDProto sd_proto_sd = { [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 57/98] hw/sd/sdcard: Add sd_cmd_WRITE_SINGLE_BLOCK handler (CMD24)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 100 lines
--- hw/sd/sd.c | 57 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 27 deletions(-)hw/sd/sd.c +30
-27@@ -242,7 +242,7 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd)static const char *cmd_abbrev[SDMMC_CMD_MAX ] = { [18 ] ="READ_MULTIPLE_BLOCK" , [21 ] ="DPS_spec" , - [24 ] ="WRITE_BLOCK" , [25 ] ="WRITE_MULTIPLE_BLOCK" , + [25 ] ="WRITE_MULTIPLE_BLOCK" , [26 ] ="MANUF_RSVD" , [27 ] ="PROGRAM_CSD" , [28 ] ="SET_WRITE_PROT" , [29 ] ="CLR_WRITE_PROT" , [30 ] ="SEND_WRITE_PROT" ,@@ -1487,6 +1487,33 @@ static sd_rsp_type_t sd_cmd_SET_BLOCK_COUNT(SDState *sd, SDRequest req)return sd_r1; } +/* CMD24 */ +static sd_rsp_type_t sd_cmd_WRITE_SINGLE_BLOCK (SDState *sd,SDRequest req) +{ +uint64_t addr; + +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + addr =sd_req_get_address (sd, req); +if (!address_in_range (sd,"WRITE_SINGLE_BLOCK" , addr, sd->blk_len)) { +return sd_r1; + } + +if (sd->size <=SDSC_MAX_CAPACITY ) { +if (sd_wp_addr (sd, addr)) { + sd->card_status |=WP_VIOLATION ; + } + } +if (sd->csd[14 ] &0x30 ) { + sd->card_status |=WP_VIOLATION ; + } + + sd->blk_written =0 ; +return sd_cmd_to_receivingdata (sd, req, addr, sd->blk_len); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;@@ -1544,32 +1571,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)break ;/* Block write commands (Class 4) */ -case 24 :/* CMD24: WRITE_SINGLE_BLOCK */ - addr =sd_req_get_address (sd, req); -switch (sd->state) { -case sd_transfer_state: - -if (!address_in_range (sd,"WRITE_SINGLE_BLOCK" , addr, - sd->blk_len)) { -return sd_r1; - } - -if (sd->size <=SDSC_MAX_CAPACITY ) { -if (sd_wp_addr (sd, sd->data_start)) { - sd->card_status |=WP_VIOLATION ; - } - } -if (sd->csd[14 ] &0x30 ) { - sd->card_status |=WP_VIOLATION ; - } - sd->blk_written =0 ; -return sd_cmd_to_receivingdata (sd, req, addr, sd->blk_len); - -default : -break ; - } -break ; -case 25 :/* CMD25: WRITE_MULTIPLE_BLOCK */ addr =sd_req_get_address (sd, req);switch (sd->state) {@@ -2308,6 +2309,7 @@ static const SDProto sd_proto_spi = { [13] = {0, sd_spi, "SEND_STATUS", sd_cmd_SEND_STATUS}, [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, + [24] = {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2344,6 +2346,7 @@ static const SDProto sd_proto_sd = { [19] = {2, sd_adtc, "SEND_TUNING_BLOCK", sd_cmd_SEND_TUNING_BLOCK}, [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, + [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
PATCH v42 58/98 hw/sd/sdcard: Add sd_cmd_PROGRAM_CSD handler (CMD27)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)
hw/sd/sd.c +9 -4
@@ -243,7 +243,7 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [18] = "READ_MULTIPLE_BLOCK", [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", - [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", + [26] = "MANUF_RSVD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END",
@@ -1514,6 +1514,12 @@ static sd_rsp_type_t sd_cmd_WRITE_SINGLE_BLOCK(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req, addr, sd->blk_len); } +/* CMD27 */ +static sd_rsp_type_t sd_cmd_PROGRAM_CSD (SDState *sd,SDRequest req) +{ +return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->csd)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;
@@ -1603,9 +1609,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 26 :/* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid)); -case 27 :/* CMD27: PROGRAM_CSD */ -return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->csd)); -/* Write protection (Class 6) */ case 28 :/* CMD28: SET_WRITE_PROT */ if (sd->size >SDSC_MAX_CAPACITY ) {
@@ -2310,6 +2313,7 @@ static const SDProto sd_proto_spi = { [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [24] = {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, + [27] = {4, sd_spi, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2347,6 +2351,7 @@ static const SDProto sd_proto_sd = { [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, + [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 58/98] hw/sd/sdcard: Add sd_cmd_PROGRAM_CSD handler (CMD27)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 56 lines
--- hw/sd/sd.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-)hw/sd/sd.c +9
-4@@ -243,7 +243,7 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [18] = "READ_MULTIPLE_BLOCK", [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", - [26] = "MANUF_RSVD", [27] = "PROGRAM_CSD", + [26] = "MANUF_RSVD", [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END",@@ -1514,6 +1514,12 @@ static sd_rsp_type_t sd_cmd_WRITE_SINGLE_BLOCK(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req, addr, sd->blk_len); } +/* CMD27 */ +static sd_rsp_type_t sd_cmd_PROGRAM_CSD (SDState *sd,SDRequest req) +{ +return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->csd)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;@@ -1603,9 +1609,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 26 :/* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid)); -case 27 :/* CMD27: PROGRAM_CSD */ -return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->csd)); -/* Write protection (Class 6) */ case 28 :/* CMD28: SET_WRITE_PROT */ if (sd->size >SDSC_MAX_CAPACITY ) {@@ -2310,6 +2313,7 @@ static const SDProto sd_proto_spi = { [16] = {2, sd_spi, "SET_BLOCKLEN", sd_cmd_SET_BLOCKLEN}, [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [24] = {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, + [27] = {4, sd_spi, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2347,6 +2351,7 @@ static const SDProto sd_proto_sd = { [20] = {2, sd_ac, "SPEED_CLASS_CONTROL", sd_cmd_optional}, [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, + [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
PATCH v42 59/98 hw/sd/sdcard: Add sd_cmd_SET/CLR_WRITE_PROT handler (CMD28 & CMD29)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 91 +++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 45 deletions(-)
hw/sd/sd.c +46 -45
@@ -244,7 +244,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", [38] = "ERASE",
@@ -1520,6 +1519,48 @@ static sd_rsp_type_t sd_cmd_PROGRAM_CSD(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->csd)); } +static sd_rsp_type_t sd_cmd_SET_CLR_WRITE_PROT (SDState *sd,SDRequest req, +bool is_write) +{ +uint64_t addr; + +if (sd->size >SDSC_MAX_CAPACITY ) { +return sd_illegal; + } + +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + addr =sd_req_get_address (sd, req); +if (!address_in_range (sd, is_write ?"SET_WRITE_PROT" :"CLR_WRITE_PROT" , + addr,1 )) { +return sd_r1b; + } + + sd->state = sd_programming_state; +if (is_write) { +set_bit (sd_addr_to_wpnum (addr), sd->wp_group_bmap); + }else { +clear_bit (sd_addr_to_wpnum (addr), sd->wp_group_bmap); + } +/* Bzzzzzzztt .... Operation complete. */ + sd->state = sd_transfer_state; +return sd_r1; +} + +/* CMD28 */ +static sd_rsp_type_t sd_cmd_SET_WRITE_PROT (SDState *sd,SDRequest req) +{ +return sd_cmd_SET_CLR_WRITE_PROT (sd, req, true); +} + +/* CMD29 */ +static sd_rsp_type_t sd_cmd_CLR_WRITE_PROT (SDState *sd,SDRequest req) +{ +return sd_cmd_SET_CLR_WRITE_PROT (sd, req, false); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;
@@ -1610,50 +1651,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));/* Write protection (Class 6) */ -case 28 :/* CMD28: SET_WRITE_PROT */ -if (sd->size >SDSC_MAX_CAPACITY ) { -return sd_illegal; - } - addr =sd_req_get_address (sd, req); -switch (sd->state) { -case sd_transfer_state: -if (!address_in_range (sd,"SET_WRITE_PROT" , addr,1 )) { -return sd_r1b; - } - - sd->state = sd_programming_state; -set_bit (sd_addr_to_wpnum (addr), sd->wp_group_bmap); -/* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; -return sd_r1b; - -default : -break ; - } -break ; - -case 29 :/* CMD29: CLR_WRITE_PROT */ -if (sd->size >SDSC_MAX_CAPACITY ) { -return sd_illegal; - } - addr =sd_req_get_address (sd, req); -switch (sd->state) { -case sd_transfer_state: -if (!address_in_range (sd,"CLR_WRITE_PROT" , addr,1 )) { -return sd_r1b; - } - - sd->state = sd_programming_state; -clear_bit (sd_addr_to_wpnum (addr), sd->wp_group_bmap); -/* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; -return sd_r1b; - -default : -break ; - } -break ; -case 30 :/* CMD30: SEND_WRITE_PROT */ if (sd->size >SDSC_MAX_CAPACITY ) {return sd_illegal;
@@ -2314,6 +2311,8 @@ static const SDProto sd_proto_spi = { [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [24] = {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [27] = {4, sd_spi, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, + [28] = {6, sd_spi, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, + [29] = {6, sd_spi, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2352,6 +2351,8 @@ static const SDProto sd_proto_sd = { [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, + [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, + [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 59/98] hw/sd/sdcard: Add sd_cmd_SET/CLR_WRITE_PROT handler (CMD28 & CMD29)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 134 lines
--- hw/sd/sd.c | 91 +++++++++++++++++++++++++++--------------------------- 1 file changed, 46 insertions(+), 45 deletions(-)hw/sd/sd.c +46
-45@@ -244,7 +244,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [28] = "SET_WRITE_PROT", [29] = "CLR_WRITE_PROT", [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", [38] = "ERASE",@@ -1520,6 +1519,48 @@ static sd_rsp_type_t sd_cmd_PROGRAM_CSD(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->csd)); } +static sd_rsp_type_t sd_cmd_SET_CLR_WRITE_PROT (SDState *sd,SDRequest req, +bool is_write) +{ +uint64_t addr; + +if (sd->size >SDSC_MAX_CAPACITY ) { +return sd_illegal; + } + +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + addr =sd_req_get_address (sd, req); +if (!address_in_range (sd, is_write ?"SET_WRITE_PROT" :"CLR_WRITE_PROT" , + addr,1 )) { +return sd_r1b; + } + + sd->state = sd_programming_state; +if (is_write) { +set_bit (sd_addr_to_wpnum (addr), sd->wp_group_bmap); + }else { +clear_bit (sd_addr_to_wpnum (addr), sd->wp_group_bmap); + } +/* Bzzzzzzztt .... Operation complete. */ + sd->state = sd_transfer_state; +return sd_r1; +} + +/* CMD28 */ +static sd_rsp_type_t sd_cmd_SET_WRITE_PROT (SDState *sd,SDRequest req) +{ +return sd_cmd_SET_CLR_WRITE_PROT (sd, req, true); +} + +/* CMD29 */ +static sd_rsp_type_t sd_cmd_CLR_WRITE_PROT (SDState *sd,SDRequest req) +{ +return sd_cmd_SET_CLR_WRITE_PROT (sd, req, false); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;@@ -1610,50 +1651,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));/* Write protection (Class 6) */ -case 28 :/* CMD28: SET_WRITE_PROT */ -if (sd->size >SDSC_MAX_CAPACITY ) { -return sd_illegal; - } - addr =sd_req_get_address (sd, req); -switch (sd->state) { -case sd_transfer_state: -if (!address_in_range (sd,"SET_WRITE_PROT" , addr,1 )) { -return sd_r1b; - } - - sd->state = sd_programming_state; -set_bit (sd_addr_to_wpnum (addr), sd->wp_group_bmap); -/* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; -return sd_r1b; - -default : -break ; - } -break ; - -case 29 :/* CMD29: CLR_WRITE_PROT */ -if (sd->size >SDSC_MAX_CAPACITY ) { -return sd_illegal; - } - addr =sd_req_get_address (sd, req); -switch (sd->state) { -case sd_transfer_state: -if (!address_in_range (sd,"CLR_WRITE_PROT" , addr,1 )) { -return sd_r1b; - } - - sd->state = sd_programming_state; -clear_bit (sd_addr_to_wpnum (addr), sd->wp_group_bmap); -/* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; -return sd_r1b; - -default : -break ; - } -break ; -case 30 :/* CMD30: SEND_WRITE_PROT */ if (sd->size >SDSC_MAX_CAPACITY ) {return sd_illegal;@@ -2314,6 +2311,8 @@ static const SDProto sd_proto_spi = { [17] = {2, sd_spi, "READ_SINGLE_BLOCK", sd_cmd_READ_SINGLE_BLOCK}, [24] = {4, sd_spi, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [27] = {4, sd_spi, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, + [28] = {6, sd_spi, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, + [29] = {6, sd_spi, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2352,6 +2351,8 @@ static const SDProto sd_proto_sd = { [23] = {2, sd_ac, "SET_BLOCK_COUNT", sd_cmd_SET_BLOCK_COUNT}, [24] = {4, sd_adtc, "WRITE_SINGLE_BLOCK", sd_cmd_WRITE_SINGLE_BLOCK}, [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, + [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, + [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
PATCH v42 60/98 hw/sd/sdcard: Add sd_cmd_SEND_WRITE_PROT handler (CMD30)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-)
hw/sd/sd.c +25 -22
@@ -244,7 +244,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", [38] = "ERASE", [40] = "DPS_spec",
@@ -1561,11 +1560,33 @@ static sd_rsp_type_t sd_cmd_CLR_WRITE_PROT(SDState *sd, SDRequest req)return sd_cmd_SET_CLR_WRITE_PROT (sd, req, false); } +/* CMD30 */ +static sd_rsp_type_t sd_cmd_SEND_WRITE_PROT (SDState *sd,SDRequest req) +{ +uint64_t addr; +uint32_t data; + +if (sd->size >SDSC_MAX_CAPACITY ) { +return sd_illegal; + } + +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + addr =sd_req_get_address (sd, req); +if (!address_in_range (sd,"SEND_WRITE_PROT" , addr, sd->blk_len)) { +return sd_r1; + } + + data =sd_wpbits (sd, req.arg); +return sd_cmd_to_sendingdata (sd, req, addr, &data,sizeof (data)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;uint64_t addr; -uint32_t data; sd->last_cmd_name =sd_cmd_name (sd, req.cmd);/* CMD55 precedes an ACMD, so we are not interested in tracing it.
@@ -1650,26 +1671,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 26 :/* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid)); -/* Write protection (Class 6) */ -case 30 :/* CMD30: SEND_WRITE_PROT */ -if (sd->size >SDSC_MAX_CAPACITY ) { -return sd_illegal; - } - addr =sd_req_get_address (sd, req); -switch (sd->state) { -case sd_transfer_state: -if (!address_in_range (sd,"SEND_WRITE_PROT" , - req.arg, sd->blk_len)) { -return sd_r1; - } - data =sd_wpbits (sd, req.arg); -return sd_cmd_to_sendingdata (sd, req, addr, &data,sizeof (data)); - -default : -break ; - } -break ; -/* Erase commands (Class 5) */ case 32 :/* CMD32: ERASE_WR_BLK_START */ switch (sd->state) {
@@ -2313,6 +2314,7 @@ static const SDProto sd_proto_spi = { [27] = {4, sd_spi, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [28] = {6, sd_spi, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_spi, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, + [30] = {6, sd_spi, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2353,6 +2355,7 @@ static const SDProto sd_proto_sd = { [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, + [30] = {6, sd_adtc, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 60/98] hw/sd/sdcard: Add sd_cmd_SEND_WRITE_PROT handler (CMD30)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 94 lines
--- hw/sd/sd.c | 47 +++++++++++++++++++++++++---------------------- 1 file changed, 25 insertions(+), 22 deletions(-)hw/sd/sd.c +25
-22@@ -244,7 +244,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [30] = "SEND_WRITE_PROT", [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", [38] = "ERASE", [40] = "DPS_spec",@@ -1561,11 +1560,33 @@ static sd_rsp_type_t sd_cmd_CLR_WRITE_PROT(SDState *sd, SDRequest req)return sd_cmd_SET_CLR_WRITE_PROT (sd, req, false); } +/* CMD30 */ +static sd_rsp_type_t sd_cmd_SEND_WRITE_PROT (SDState *sd,SDRequest req) +{ +uint64_t addr; +uint32_t data; + +if (sd->size >SDSC_MAX_CAPACITY ) { +return sd_illegal; + } + +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + addr =sd_req_get_address (sd, req); +if (!address_in_range (sd,"SEND_WRITE_PROT" , addr, sd->blk_len)) { +return sd_r1; + } + + data =sd_wpbits (sd, req.arg); +return sd_cmd_to_sendingdata (sd, req, addr, &data,sizeof (data)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;uint64_t addr; -uint32_t data; sd->last_cmd_name =sd_cmd_name (sd, req.cmd);/* CMD55 precedes an ACMD, so we are not interested in tracing it. @@ -1650,26 +1671,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 26 :/* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid)); -/* Write protection (Class 6) */ -case 30 :/* CMD30: SEND_WRITE_PROT */ -if (sd->size >SDSC_MAX_CAPACITY ) { -return sd_illegal; - } - addr =sd_req_get_address (sd, req); -switch (sd->state) { -case sd_transfer_state: -if (!address_in_range (sd,"SEND_WRITE_PROT" , - req.arg, sd->blk_len)) { -return sd_r1; - } - data =sd_wpbits (sd, req.arg); -return sd_cmd_to_sendingdata (sd, req, addr, &data,sizeof (data)); - -default : -break ; - } -break ; -/* Erase commands (Class 5) */ case 32 :/* CMD32: ERASE_WR_BLK_START */ switch (sd->state) {@@ -2313,6 +2314,7 @@ static const SDProto sd_proto_spi = { [27] = {4, sd_spi, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [28] = {6, sd_spi, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_spi, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, + [30] = {6, sd_spi, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2353,6 +2355,7 @@ static const SDProto sd_proto_sd = { [27] = {4, sd_adtc, "PROGRAM_CSD", sd_cmd_PROGRAM_CSD}, [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, + [30] = {6, sd_adtc, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
PATCH v42 61/98 hw/sd/sdcard: Add sd_cmd_ERASE_WR_BLK_START/END handlers (CMD32 & CMD33)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-)
hw/sd/sd.c +24 -23
@@ -244,7 +244,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", [38] = "ERASE", [40] = "DPS_spec", [42] = "LOCK_UNLOCK",
@@ -1583,6 +1582,26 @@ static sd_rsp_type_t sd_cmd_SEND_WRITE_PROT(SDState *sd, SDRequest req)return sd_cmd_to_sendingdata (sd, req, addr, &data,sizeof (data)); } +/* CMD32 */ +static sd_rsp_type_t sd_cmd_ERASE_WR_BLK_START (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + sd->erase_start = req.arg; +return sd_r1; +} + +/* CMD33 */ +static sd_rsp_type_t sd_cmd_ERASE_WR_BLK_END (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + sd->erase_end = req.arg; +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;
@@ -1672,28 +1691,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));/* Erase commands (Class 5) */ -case 32 :/* CMD32: ERASE_WR_BLK_START */ -switch (sd->state) { -case sd_transfer_state: - sd->erase_start = req.arg; -return sd_r1; - -default : -break ; - } -break ; - -case 33 :/* CMD33: ERASE_WR_BLK_END */ -switch (sd->state) { -case sd_transfer_state: - sd->erase_end = req.arg; -return sd_r1; - -default : -break ; - } -break ; -case 38 :/* CMD38: ERASE */ switch (sd->state) {case sd_transfer_state:
@@ -2315,6 +2312,8 @@ static const SDProto sd_proto_spi = { [28] = {6, sd_spi, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_spi, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [30] = {6, sd_spi, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, + [32] = {5, sd_spi, "ERASE_WR_BLK_START", sd_cmd_ERASE_WR_BLK_START}, + [33] = {5, sd_spi, "ERASE_WR_BLK_END", sd_cmd_ERASE_WR_BLK_END}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},
@@ -2356,6 +2355,8 @@ static const SDProto sd_proto_sd = { [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [30] = {6, sd_adtc, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, + [32] = {5, sd_ac, "ERASE_WR_BLK_START", sd_cmd_ERASE_WR_BLK_START}, + [33] = {5, sd_ac, "ERASE_WR_BLK_END", sd_cmd_ERASE_WR_BLK_END}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 61/98] hw/sd/sdcard: Add sd_cmd_ERASE_WR_BLK_START/END handlers (CMD32 & CMD33)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 90 lines
--- hw/sd/sd.c | 47 ++++++++++++++++++++++++----------------------- 1 file changed, 24 insertions(+), 23 deletions(-)hw/sd/sd.c +24
-23@@ -244,7 +244,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [32] = "ERASE_WR_BLK_START", [33] = "ERASE_WR_BLK_END", [38] = "ERASE", [40] = "DPS_spec", [42] = "LOCK_UNLOCK",@@ -1583,6 +1582,26 @@ static sd_rsp_type_t sd_cmd_SEND_WRITE_PROT(SDState *sd, SDRequest req)return sd_cmd_to_sendingdata (sd, req, addr, &data,sizeof (data)); } +/* CMD32 */ +static sd_rsp_type_t sd_cmd_ERASE_WR_BLK_START (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + sd->erase_start = req.arg; +return sd_r1; +} + +/* CMD33 */ +static sd_rsp_type_t sd_cmd_ERASE_WR_BLK_END (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + sd->erase_end = req.arg; +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;@@ -1672,28 +1691,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));/* Erase commands (Class 5) */ -case 32 :/* CMD32: ERASE_WR_BLK_START */ -switch (sd->state) { -case sd_transfer_state: - sd->erase_start = req.arg; -return sd_r1; - -default : -break ; - } -break ; - -case 33 :/* CMD33: ERASE_WR_BLK_END */ -switch (sd->state) { -case sd_transfer_state: - sd->erase_end = req.arg; -return sd_r1; - -default : -break ; - } -break ; -case 38 :/* CMD38: ERASE */ switch (sd->state) {case sd_transfer_state:@@ -2315,6 +2312,8 @@ static const SDProto sd_proto_spi = { [28] = {6, sd_spi, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_spi, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [30] = {6, sd_spi, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, + [32] = {5, sd_spi, "ERASE_WR_BLK_START", sd_cmd_ERASE_WR_BLK_START}, + [33] = {5, sd_spi, "ERASE_WR_BLK_END", sd_cmd_ERASE_WR_BLK_END}, [34] = {10, sd_spi, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional},@@ -2356,6 +2355,8 @@ static const SDProto sd_proto_sd = { [28] = {6, sd_ac, "SET_WRITE_PROT", sd_cmd_SET_WRITE_PROT}, [29] = {6, sd_ac, "CLR_WRITE_PROT", sd_cmd_CLR_WRITE_PROT}, [30] = {6, sd_adtc, "SEND_WRITE_PROT", sd_cmd_SEND_WRITE_PROT}, + [32] = {5, sd_ac, "ERASE_WR_BLK_START", sd_cmd_ERASE_WR_BLK_START}, + [33] = {5, sd_ac, "ERASE_WR_BLK_END", sd_cmd_ERASE_WR_BLK_END}, [34] = {10, sd_adtc, "READ_SEC_CMD", sd_cmd_optional}, [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional},
PATCH v42 62/98 hw/sd/sdcard: Add sd_cmd_ERASE handler (CMD38)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-)
hw/sd/sd.c +20 -21
@@ -244,7 +244,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [38] = "ERASE", [40] = "DPS_spec", [42] = "LOCK_UNLOCK", [54] = "SDIO_RSVD", [55] = "APP_CMD",
@@ -1602,6 +1601,24 @@ static sd_rsp_type_t sd_cmd_ERASE_WR_BLK_END(SDState *sd, SDRequest req)return sd_r1; } +/* CMD38 */ +static sd_rsp_type_t sd_cmd_ERASE (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } +if (sd->csd[14 ] &0x30 ) { + sd->card_status |=WP_VIOLATION ; +return sd_r1b; + } + + sd->state = sd_programming_state; +sd_erase (sd); +/* Bzzzzzzztt .... Operation complete. */ + sd->state = sd_transfer_state; +return sd_r1b; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;
@@ -1690,26 +1707,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 26 :/* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid)); -/* Erase commands (Class 5) */ -case 38 :/* CMD38: ERASE */ -switch (sd->state) { -case sd_transfer_state: -if (sd->csd[14 ] &0x30 ) { - sd->card_status |=WP_VIOLATION ; -return sd_r1b; - } - - sd->state = sd_programming_state; -sd_erase (sd); -/* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; -return sd_r1b; - -default : -break ; - } -break ; -/* Lock card commands (Class 7) */ case 42 :/* CMD42: LOCK_UNLOCK */ return sd_cmd_to_receivingdata (sd, req,0 ,0 );
@@ -2318,6 +2315,7 @@ static const SDProto sd_proto_spi = { [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_spi, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, + [38] = {5, sd_spi, "ERASE", sd_cmd_ERASE}, [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional},
@@ -2361,6 +2359,7 @@ static const SDProto sd_proto_sd = { [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_ac, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, + [38] = {5, sd_ac, "ERASE", sd_cmd_ERASE}, [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 62/98] hw/sd/sdcard: Add sd_cmd_ERASE handler (CMD38)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 84 lines
--- hw/sd/sd.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-)hw/sd/sd.c +20
-21@@ -244,7 +244,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [21] = "DPS_spec", [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", - [38] = "ERASE", [40] = "DPS_spec", [42] = "LOCK_UNLOCK", [54] = "SDIO_RSVD", [55] = "APP_CMD",@@ -1602,6 +1601,24 @@ static sd_rsp_type_t sd_cmd_ERASE_WR_BLK_END(SDState *sd, SDRequest req)return sd_r1; } +/* CMD38 */ +static sd_rsp_type_t sd_cmd_ERASE (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } +if (sd->csd[14 ] &0x30 ) { + sd->card_status |=WP_VIOLATION ; +return sd_r1b; + } + + sd->state = sd_programming_state; +sd_erase (sd); +/* Bzzzzzzztt .... Operation complete. */ + sd->state = sd_transfer_state; +return sd_r1b; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;@@ -1690,26 +1707,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 26 :/* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid)); -/* Erase commands (Class 5) */ -case 38 :/* CMD38: ERASE */ -switch (sd->state) { -case sd_transfer_state: -if (sd->csd[14 ] &0x30 ) { - sd->card_status |=WP_VIOLATION ; -return sd_r1b; - } - - sd->state = sd_programming_state; -sd_erase (sd); -/* Bzzzzzzztt .... Operation complete. */ - sd->state = sd_transfer_state; -return sd_r1b; - -default : -break ; - } -break ; -/* Lock card commands (Class 7) */ case 42 :/* CMD42: LOCK_UNLOCK */ return sd_cmd_to_receivingdata (sd, req,0 ,0 );@@ -2318,6 +2315,7 @@ static const SDProto sd_proto_spi = { [35] = {10, sd_spi, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_spi, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, + [38] = {5, sd_spi, "ERASE", sd_cmd_ERASE}, [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional},@@ -2361,6 +2359,7 @@ static const SDProto sd_proto_sd = { [35] = {10, sd_adtc, "WRITE_SEC_CMD", sd_cmd_optional}, [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_ac, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, + [38] = {5, sd_ac, "ERASE", sd_cmd_ERASE}, [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional},
PATCH v42 63/98 hw/sd/sdcard: Add sd_cmd_LOCK_UNLOCK handler (CMD42)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
hw/sd/sd.c +8 -5
@@ -245,7 +245,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [40] = "DPS_spec", - [42] = "LOCK_UNLOCK", [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD",
@@ -1619,6 +1618,12 @@ static sd_rsp_type_t sd_cmd_ERASE(SDState *sd, SDRequest req)return sd_r1b; } +/* CMD42 */ +static sd_rsp_type_t sd_cmd_LOCK_UNLOCK (SDState *sd,SDRequest req) +{ +return sd_cmd_to_receivingdata (sd, req,0 ,0 ); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;
@@ -1707,10 +1712,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 26 :/* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid)); -/* Lock card commands (Class 7) */ -case 42 :/* CMD42: LOCK_UNLOCK */ -return sd_cmd_to_receivingdata (sd, req,0 ,0 ); -/* Application specific commands (Class 8) */ case 55 :/* CMD55: APP_CMD */ rca =sd_req_get_rca (sd, req);
@@ -2316,6 +2317,7 @@ static const SDProto sd_proto_spi = { [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_spi, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, [38] = {5, sd_spi, "ERASE", sd_cmd_ERASE}, + [42] = {7, sd_spi, "LOCK_UNLOCK", sd_cmd_LOCK_UNLOCK}, [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional},
@@ -2360,6 +2362,7 @@ static const SDProto sd_proto_sd = { [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_ac, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, [38] = {5, sd_ac, "ERASE", sd_cmd_ERASE}, + [42] = {7, sd_adtc, "LOCK_UNLOCK", sd_cmd_LOCK_UNLOCK}, [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 63/98] hw/sd/sdcard: Add sd_cmd_LOCK_UNLOCK handler (CMD42)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 56 lines
--- hw/sd/sd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)hw/sd/sd.c +8
-5@@ -245,7 +245,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [40] = "DPS_spec", - [42] = "LOCK_UNLOCK", [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD",@@ -1619,6 +1618,12 @@ static sd_rsp_type_t sd_cmd_ERASE(SDState *sd, SDRequest req)return sd_r1b; } +/* CMD42 */ +static sd_rsp_type_t sd_cmd_LOCK_UNLOCK (SDState *sd,SDRequest req) +{ +return sd_cmd_to_receivingdata (sd, req,0 ,0 ); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint16_t rca;@@ -1707,10 +1712,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 26 :/* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid)); -/* Lock card commands (Class 7) */ -case 42 :/* CMD42: LOCK_UNLOCK */ -return sd_cmd_to_receivingdata (sd, req,0 ,0 ); -/* Application specific commands (Class 8) */ case 55 :/* CMD55: APP_CMD */ rca =sd_req_get_rca (sd, req);@@ -2316,6 +2317,7 @@ static const SDProto sd_proto_spi = { [36] = {10, sd_spi, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_spi, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, [38] = {5, sd_spi, "ERASE", sd_cmd_ERASE}, + [42] = {7, sd_spi, "LOCK_UNLOCK", sd_cmd_LOCK_UNLOCK}, [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional},@@ -2360,6 +2362,7 @@ static const SDProto sd_proto_sd = { [36] = {10, sd_adtc, "SEND_PSI", sd_cmd_optional}, [37] = {10, sd_ac, "CONTROL_ASSD_SYSTEM", sd_cmd_optional}, [38] = {5, sd_ac, "ERASE", sd_cmd_ERASE}, + [42] = {7, sd_adtc, "LOCK_UNLOCK", sd_cmd_LOCK_UNLOCK}, [43] = {1, sd_ac, "Q_MANAGEMENT", sd_cmd_optional}, [44] = {1, sd_ac, "Q_TASK_INFO_A", sd_cmd_optional}, [45] = {1, sd_ac, "Q_TASK_INFO_B", sd_cmd_optional},
PATCH v42 64/98 hw/sd/sdcard: Add sd_cmd_APP_CMD handler (CMD55)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-)
hw/sd/sd.c +28 -25
@@ -245,7 +245,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [40] = "DPS_spec", - [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD",
@@ -1624,9 +1623,34 @@ static sd_rsp_type_t sd_cmd_LOCK_UNLOCK(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,0 ); } +/* CMD55 */ +static sd_rsp_type_t sd_cmd_APP_CMD (SDState *sd,SDRequest req) +{ +switch (sd->state) { +case sd_ready_state: +case sd_identification_state: +case sd_inactive_state: +return sd_invalid_state_for_cmd (sd, req); +case sd_idle_state: +if (!sd_is_spi (sd) &&sd_req_get_rca (sd, req) !=0x0000 ) { +qemu_log_mask (LOG_GUEST_ERROR , +"SD: illegal RCA 0x%04x for APP_CMD\n" , req.cmd); + } +/* fall-through */ +default : +break ; + } +if (!sd_is_spi (sd) && !sd_req_rca_same (sd, req)) { +return sd_r0; + } + sd->expecting_acmd = true; + sd->card_status |=APP_CMD ; + +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) { -uint16_t rca;uint64_t addr; sd->last_cmd_name =sd_cmd_name (sd, req.cmd);
@@ -1713,29 +1737,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));/* Application specific commands (Class 8) */ -case 55 :/* CMD55: APP_CMD */ - rca =sd_req_get_rca (sd, req); -switch (sd->state) { -case sd_ready_state: -case sd_identification_state: -return sd_illegal; -case sd_idle_state: -if (rca) { -qemu_log_mask (LOG_GUEST_ERROR , -"SD: illegal RCA 0x%04x for APP_CMD\n" , req.cmd); - } -default : -break ; - } -if (!sd_is_spi (sd)) { -if (sd->rca != rca) { -return sd_r0; - } - } - sd->expecting_acmd = true; - sd->card_status |=APP_CMD ; -return sd_r1; -case 56 :/* CMD56: GEN_CMD */ switch (sd->state) {case sd_transfer_state:
@@ -2321,6 +2322,7 @@ static const SDProto sd_proto_spi = { [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, + [55] = {8, sd_spi, "APP_CMD", sd_cmd_APP_CMD}, [57 ] = {10 , sd_spi,"DIRECT_SECURE_WRITE" , sd_cmd_optional}, }, .acmd = {
@@ -2373,6 +2375,7 @@ static const SDProto sd_proto_sd = { [50] = {10, sd_adtc, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, + [55] = {8, sd_ac, "APP_CMD", sd_cmd_APP_CMD}, [57] = {10, sd_adtc, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 64/98] hw/sd/sdcard: Add sd_cmd_APP_CMD handler (CMD55)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 98 lines
--- hw/sd/sd.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-)hw/sd/sd.c +28
-25@@ -245,7 +245,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [40] = "DPS_spec", - [54] = "SDIO_RSVD", [55] = "APP_CMD", [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD",@@ -1624,9 +1623,34 @@ static sd_rsp_type_t sd_cmd_LOCK_UNLOCK(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,0 ); } +/* CMD55 */ +static sd_rsp_type_t sd_cmd_APP_CMD (SDState *sd,SDRequest req) +{ +switch (sd->state) { +case sd_ready_state: +case sd_identification_state: +case sd_inactive_state: +return sd_invalid_state_for_cmd (sd, req); +case sd_idle_state: +if (!sd_is_spi (sd) &&sd_req_get_rca (sd, req) !=0x0000 ) { +qemu_log_mask (LOG_GUEST_ERROR , +"SD: illegal RCA 0x%04x for APP_CMD\n" , req.cmd); + } +/* fall-through */ +default : +break ; + } +if (!sd_is_spi (sd) && !sd_req_rca_same (sd, req)) { +return sd_r0; + } + sd->expecting_acmd = true; + sd->card_status |=APP_CMD ; + +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) { -uint16_t rca;uint64_t addr; sd->last_cmd_name =sd_cmd_name (sd, req.cmd);@@ -1713,29 +1737,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));/* Application specific commands (Class 8) */ -case 55 :/* CMD55: APP_CMD */ - rca =sd_req_get_rca (sd, req); -switch (sd->state) { -case sd_ready_state: -case sd_identification_state: -return sd_illegal; -case sd_idle_state: -if (rca) { -qemu_log_mask (LOG_GUEST_ERROR , -"SD: illegal RCA 0x%04x for APP_CMD\n" , req.cmd); - } -default : -break ; - } -if (!sd_is_spi (sd)) { -if (sd->rca != rca) { -return sd_r0; - } - } - sd->expecting_acmd = true; - sd->card_status |=APP_CMD ; -return sd_r1; -case 56 :/* CMD56: GEN_CMD */ switch (sd->state) {case sd_transfer_state:@@ -2321,6 +2322,7 @@ static const SDProto sd_proto_spi = { [50] = {10, sd_spi, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, + [55] = {8, sd_spi, "APP_CMD", sd_cmd_APP_CMD}, [57 ] = {10 , sd_spi,"DIRECT_SECURE_WRITE" , sd_cmd_optional}, }, .acmd = {@@ -2373,6 +2375,7 @@ static const SDProto sd_proto_sd = { [50] = {10, sd_adtc, "DIRECT_SECURE_READ", sd_cmd_optional}, [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, + [55] = {8, sd_ac, "APP_CMD", sd_cmd_APP_CMD}, [57] = {10, sd_adtc, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional},
PATCH v42 65/98 hw/sd/sdcard: Add sd_cmd_GEN_CMD handler (CMD56)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-)
hw/sd/sd.c +17 -19
@@ -245,7 +245,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [40] = "DPS_spec", - [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", };
@@ -910,9 +909,6 @@ static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) } } -#define APP_READ_BLOCK (a, len) memset(sd->data, 0xec, len) -#define APP_WRITE_BLOCK (a, len) -static void sd_erase (SDState *sd) {uint64_t erase_start = sd->erase_start;
@@ -1649,6 +1645,21 @@ static sd_rsp_type_t sd_cmd_APP_CMD(SDState *sd, SDRequest req)return sd_r1; } +/* CMD56 */ +static sd_rsp_type_t sd_cmd_GEN_CMD (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +if (req.arg &1 ) { +return sd_cmd_to_sendingdata (sd, req,0 , + sd->vendor_data,sizeof (sd->vendor_data)); + }else { +return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->vendor_data)); + } +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1737,21 +1748,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));/* Application specific commands (Class 8) */ -case 56 :/* CMD56: GEN_CMD */ -switch (sd->state) { -case sd_transfer_state: -if (req.arg &1 ) { -return sd_cmd_to_sendingdata (sd, req,0 , - sd->vendor_data, -sizeof (sd->vendor_data)); - } -return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->vendor_data)); - -default : -break ; - } -break ; -case 58 :/* CMD58: READ_OCR (SPI) */ return sd_r3;
@@ -2323,6 +2319,7 @@ static const SDProto sd_proto_spi = { [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, [55] = {8, sd_spi, "APP_CMD", sd_cmd_APP_CMD}, + [56] = {8, sd_spi, "GEN_CMD", sd_cmd_GEN_CMD}, [57 ] = {10 , sd_spi,"DIRECT_SECURE_WRITE" , sd_cmd_optional}, }, .acmd = {
@@ -2376,6 +2373,7 @@ static const SDProto sd_proto_sd = { [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, [55] = {8, sd_ac, "APP_CMD", sd_cmd_APP_CMD}, + [56] = {8, sd_adtc, "GEN_CMD", sd_cmd_GEN_CMD}, [57] = {10, sd_adtc, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional},
Signature · 1 line
2.41.0
Re: [PATCH v42 65/98] hw/sd/sdcard: Add sd_cmd_GEN_CMD handler (CMD56)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 86 lines
--- hw/sd/sd.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-)hw/sd/sd.c +17
-19@@ -245,7 +245,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd) [25] = "WRITE_MULTIPLE_BLOCK", [26] = "MANUF_RSVD", [40] = "DPS_spec", - [56] = "GEN_CMD", [60] = "MANUF_RSVD", [61] = "MANUF_RSVD", [62] = "MANUF_RSVD", [63] = "MANUF_RSVD", };@@ -910,9 +909,6 @@ static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len) } } -#define APP_READ_BLOCK (a, len) memset(sd->data, 0xec, len) -#define APP_WRITE_BLOCK (a, len) -static void sd_erase (SDState *sd) {uint64_t erase_start = sd->erase_start;@@ -1649,6 +1645,21 @@ static sd_rsp_type_t sd_cmd_APP_CMD(SDState *sd, SDRequest req)return sd_r1; } +/* CMD56 */ +static sd_rsp_type_t sd_cmd_GEN_CMD (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +if (req.arg &1 ) { +return sd_cmd_to_sendingdata (sd, req,0 , + sd->vendor_data,sizeof (sd->vendor_data)); + }else { +return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->vendor_data)); + } +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;@@ -1737,21 +1748,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));/* Application specific commands (Class 8) */ -case 56 :/* CMD56: GEN_CMD */ -switch (sd->state) { -case sd_transfer_state: -if (req.arg &1 ) { -return sd_cmd_to_sendingdata (sd, req,0 , - sd->vendor_data, -sizeof (sd->vendor_data)); - } -return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->vendor_data)); - -default : -break ; - } -break ; -case 58 :/* CMD58: READ_OCR (SPI) */ return sd_r3;@@ -2323,6 +2319,7 @@ static const SDProto sd_proto_spi = { [52] = {9, sd_spi, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_spi, "IO_RW_EXTENDED", sd_cmd_optional}, [55] = {8, sd_spi, "APP_CMD", sd_cmd_APP_CMD}, + [56] = {8, sd_spi, "GEN_CMD", sd_cmd_GEN_CMD}, [57 ] = {10 , sd_spi,"DIRECT_SECURE_WRITE" , sd_cmd_optional}, }, .acmd = {@@ -2376,6 +2373,7 @@ static const SDProto sd_proto_sd = { [52] = {9, sd_bc, "IO_RW_DIRECT", sd_cmd_optional}, [53] = {9, sd_bc, "IO_RW_EXTENDED", sd_cmd_optional}, [55] = {8, sd_ac, "APP_CMD", sd_cmd_APP_CMD}, + [56] = {8, sd_adtc, "GEN_CMD", sd_cmd_GEN_CMD}, [57] = {10, sd_adtc, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59] = {11, sd_adtc, "WRITE_EXTR_MULTI", sd_cmd_optional},
PATCH v42 66/98 hw/sd/sdcard: Add spi_cmd_READ_OCR handler (CMD58)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
hw/sd/sd.c +7 -3
@@ -1660,6 +1660,12 @@ static sd_rsp_type_t sd_cmd_GEN_CMD(SDState *sd, SDRequest req) } } +/* CMD58 */ +static sd_rsp_type_t spi_cmd_READ_OCR (SDState *sd,SDRequest req) +{ +return sd_r3; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1748,9 +1754,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));/* Application specific commands (Class 8) */ -case 58 :/* CMD58: READ_OCR (SPI) */ -return sd_r3; -case 59 :/* CMD59: CRC_ON_OFF (SPI) */ return sd_r1;
@@ -2321,6 +2324,7 @@ static const SDProto sd_proto_spi = { [55] = {8, sd_spi, "APP_CMD", sd_cmd_APP_CMD}, [56] = {8, sd_spi, "GEN_CMD", sd_cmd_GEN_CMD}, [57] = {10, sd_spi, "DIRECT_SECURE_WRITE", sd_cmd_optional}, + [58 ] = {0 , sd_spi,"READ_OCR" , spi_cmd_READ_OCR}, }, .acmd = { [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND},
Signature · 1 line
2.41.0
Re: [PATCH v42 66/98] hw/sd/sdcard: Add spi_cmd_READ_OCR handler (CMD58)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 39 lines
--- hw/sd/sd.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)hw/sd/sd.c +7
-3@@ -1660,6 +1660,12 @@ static sd_rsp_type_t sd_cmd_GEN_CMD(SDState *sd, SDRequest req) } } +/* CMD58 */ +static sd_rsp_type_t spi_cmd_READ_OCR (SDState *sd,SDRequest req) +{ +return sd_r3; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;@@ -1748,9 +1754,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid));/* Application specific commands (Class 8) */ -case 58 :/* CMD58: READ_OCR (SPI) */ -return sd_r3; -case 59 :/* CMD59: CRC_ON_OFF (SPI) */ return sd_r1;@@ -2321,6 +2324,7 @@ static const SDProto sd_proto_spi = { [55] = {8, sd_spi, "APP_CMD", sd_cmd_APP_CMD}, [56] = {8, sd_spi, "GEN_CMD", sd_cmd_GEN_CMD}, [57] = {10, sd_spi, "DIRECT_SECURE_WRITE", sd_cmd_optional}, + [58 ] = {0 , sd_spi,"READ_OCR" , spi_cmd_READ_OCR}, }, .acmd = { [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND},
PATCH v42 67/98 hw/sd/sdcard: Add spi_cmd_CRC_ON_OFF handler (CMD59)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
hw/sd/sd.c +7 -4
@@ -1666,6 +1666,12 @@ static sd_rsp_type_t spi_cmd_READ_OCR(SDState *sd, SDRequest req)return sd_r3; } +/* CMD59 */ +static sd_rsp_type_t spi_cmd_CRC_ON_OFF (SDState *sd,SDRequest req) +{ +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1753,10 +1759,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 26 :/* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid)); -/* Application specific commands (Class 8) */ -case 59 :/* CMD59: CRC_ON_OFF (SPI) */ -return sd_r1; -default :qemu_log_mask (LOG_GUEST_ERROR ,"SD: Unknown CMD%i\n" , req.cmd);return sd_illegal;
@@ -2325,6 +2327,7 @@ static const SDProto sd_proto_spi = { [56] = {8, sd_spi, "GEN_CMD", sd_cmd_GEN_CMD}, [57] = {10, sd_spi, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {0, sd_spi, "READ_OCR", spi_cmd_READ_OCR}, + [59 ] = {0 , sd_spi,"CRC_ON_OFF" , spi_cmd_CRC_ON_OFF}, }, .acmd = { [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND},
Signature · 1 line
2.41.0
Re: [PATCH v42 67/98] hw/sd/sdcard: Add spi_cmd_CRC_ON_OFF handler (CMD59)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 40 lines
--- hw/sd/sd.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)hw/sd/sd.c +7
-4@@ -1666,6 +1666,12 @@ static sd_rsp_type_t spi_cmd_READ_OCR(SDState *sd, SDRequest req)return sd_r3; } +/* CMD59 */ +static sd_rsp_type_t spi_cmd_CRC_ON_OFF (SDState *sd,SDRequest req) +{ +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;@@ -1753,10 +1759,6 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)case 26 :/* CMD26: PROGRAM_CID */ return sd_cmd_to_receivingdata (sd, req,0 ,sizeof (sd->cid)); -/* Application specific commands (Class 8) */ -case 59 :/* CMD59: CRC_ON_OFF (SPI) */ -return sd_r1; -default :qemu_log_mask (LOG_GUEST_ERROR ,"SD: Unknown CMD%i\n" , req.cmd);return sd_illegal;@@ -2325,6 +2327,7 @@ static const SDProto sd_proto_spi = { [56] = {8, sd_spi, "GEN_CMD", sd_cmd_GEN_CMD}, [57] = {10, sd_spi, "DIRECT_SECURE_WRITE", sd_cmd_optional}, [58] = {0, sd_spi, "READ_OCR", spi_cmd_READ_OCR}, + [59 ] = {0 , sd_spi,"CRC_ON_OFF" , spi_cmd_CRC_ON_OFF}, }, .acmd = { [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND},
PATCH v42 68/98 hw/sd/sdcard: Add sd_acmd_SET_BUS_WIDTH handler (ACMD6)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
hw/sd/sd.c +15 -13
@@ -260,7 +260,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd)static const char *sd_acmd_name (SDState *sd,uint8_t cmd) {static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { - [6 ] ="SET_BUS_WIDTH" , [13 ] ="SD_STATUS" , [14 ] ="DPS_spec" , [15 ] ="DPS_spec" , [16 ] ="DPS_spec" ,
@@ -1672,6 +1671,18 @@ static sd_rsp_type_t spi_cmd_CRC_ON_OFF(SDState *sd, SDRequest req)return sd_r1; } +/* ACMD6 */ +static sd_rsp_type_t sd_acmd_SET_BUS_WIDTH (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + sd->sd_status[0 ] &=0x3f ; + sd->sd_status[0 ] |= (req.arg &0x03 ) <<6 ; +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1780,18 +1791,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 6 :/* ACMD6: SET_BUS_WIDTH */ -switch (sd->state) { -case sd_transfer_state: - sd->sd_status[0 ] &=0x3f ; - sd->sd_status[0 ] |= (req.arg &0x03 ) <<6 ; -return sd_r1; - -default : -break ; - } -break ; -case 13 :/* ACMD13: SD_STATUS */ switch (sd->state) {case sd_transfer_state:
@@ -2385,6 +2384,9 @@ static const SDProto sd_proto_sd = { [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59 ] = {11 , sd_adtc,"WRITE_EXTR_MULTI" , sd_cmd_optional}, }, + .acmd = { + [6 ] = {8 , sd_ac,"SET_BUS_WIDTH" , sd_acmd_SET_BUS_WIDTH}, + }, };static void sd_instance_init (Object *obj)
Signature · 1 line
2.41.0
Re: [PATCH v42 68/98] hw/sd/sdcard: Add sd_acmd_SET_BUS_WIDTH handler (ACMD6)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 64 lines
--- hw/sd/sd.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)hw/sd/sd.c +15
-13@@ -260,7 +260,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd)static const char *sd_acmd_name (SDState *sd,uint8_t cmd) {static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { - [6 ] ="SET_BUS_WIDTH" , [13 ] ="SD_STATUS" , [14 ] ="DPS_spec" , [15 ] ="DPS_spec" , [16 ] ="DPS_spec" ,@@ -1672,6 +1671,18 @@ static sd_rsp_type_t spi_cmd_CRC_ON_OFF(SDState *sd, SDRequest req)return sd_r1; } +/* ACMD6 */ +static sd_rsp_type_t sd_acmd_SET_BUS_WIDTH (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + + sd->sd_status[0 ] &=0x3f ; + sd->sd_status[0 ] |= (req.arg &0x03 ) <<6 ; +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;@@ -1780,18 +1791,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 6 :/* ACMD6: SET_BUS_WIDTH */ -switch (sd->state) { -case sd_transfer_state: - sd->sd_status[0 ] &=0x3f ; - sd->sd_status[0 ] |= (req.arg &0x03 ) <<6 ; -return sd_r1; - -default : -break ; - } -break ; -case 13 :/* ACMD13: SD_STATUS */ switch (sd->state) {case sd_transfer_state:@@ -2385,6 +2384,9 @@ static const SDProto sd_proto_sd = { [58] = {11, sd_adtc, "READ_EXTR_MULTI", sd_cmd_optional}, [59 ] = {11 , sd_adtc,"WRITE_EXTR_MULTI" , sd_cmd_optional}, }, + .acmd = { + [6 ] = {8 , sd_ac,"SET_BUS_WIDTH" , sd_acmd_SET_BUS_WIDTH}, + }, };static void sd_instance_init (Object *obj)
PATCH v42 69/98 hw/sd/sdcard: Add sd_acmd_SD_STATUS handler (ACMD13)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)
hw/sd/sd.c +9 -13
@@ -260,7 +260,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd)static const char *sd_acmd_name (SDState *sd,uint8_t cmd) {static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { - [13 ] ="SD_STATUS" , [14 ] ="DPS_spec" , [15 ] ="DPS_spec" , [16 ] ="DPS_spec" , [18 ] ="SECU_spec" ,
@@ -1683,6 +1682,13 @@ static sd_rsp_type_t sd_acmd_SET_BUS_WIDTH(SDState *sd, SDRequest req)return sd_r1; } +/* ACMD13 */ +static sd_rsp_type_t sd_acmd_SD_STATUS (SDState *sd,SDRequest req) +{ +return sd_cmd_to_sendingdata (sd, req,0 , + sd->sd_status,sizeof (sd->sd_status)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1791,18 +1797,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 13 :/* ACMD13: SD_STATUS */ -switch (sd->state) { -case sd_transfer_state: -return sd_cmd_to_sendingdata (sd, req,0 , - sd->sd_status, -sizeof (sd->sd_status)); - -default : -break ; - } -break ; -case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ switch (sd->state) {case sd_transfer_state:
@@ -2329,6 +2323,7 @@ static const SDProto sd_proto_spi = { [59 ] = {0 , sd_spi,"CRC_ON_OFF" , spi_cmd_CRC_ON_OFF}, }, .acmd = { + [13 ] = {8 , sd_spi,"SD_STATUS" , sd_acmd_SD_STATUS}, [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, };
@@ -2386,6 +2381,7 @@ static const SDProto sd_proto_sd = { }, .acmd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, + [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, }, };
Signature · 1 line
2.41.0
Re: [PATCH v42 69/98] hw/sd/sdcard: Add sd_acmd_SD_STATUS handler (ACMD13)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 65 lines
--- hw/sd/sd.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-)hw/sd/sd.c +9
-13@@ -260,7 +260,6 @@ static const char *sd_cmd_name(SDState *sd, uint8_t cmd)static const char *sd_acmd_name (SDState *sd,uint8_t cmd) {static const char *acmd_abbrev[SDMMC_CMD_MAX ] = { - [13 ] ="SD_STATUS" , [14 ] ="DPS_spec" , [15 ] ="DPS_spec" , [16 ] ="DPS_spec" , [18 ] ="SECU_spec" ,@@ -1683,6 +1682,13 @@ static sd_rsp_type_t sd_acmd_SET_BUS_WIDTH(SDState *sd, SDRequest req)return sd_r1; } +/* ACMD13 */ +static sd_rsp_type_t sd_acmd_SD_STATUS (SDState *sd,SDRequest req) +{ +return sd_cmd_to_sendingdata (sd, req,0 , + sd->sd_status,sizeof (sd->sd_status)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;@@ -1791,18 +1797,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 13 :/* ACMD13: SD_STATUS */ -switch (sd->state) { -case sd_transfer_state: -return sd_cmd_to_sendingdata (sd, req,0 , - sd->sd_status, -sizeof (sd->sd_status)); - -default : -break ; - } -break ; -case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ switch (sd->state) {case sd_transfer_state:@@ -2329,6 +2323,7 @@ static const SDProto sd_proto_spi = { [59 ] = {0 , sd_spi,"CRC_ON_OFF" , spi_cmd_CRC_ON_OFF}, }, .acmd = { + [13 ] = {8 , sd_spi,"SD_STATUS" , sd_acmd_SD_STATUS}, [41 ] = {8 , sd_spi,"SEND_OP_COND" , spi_cmd_SEND_OP_COND}, }, };@@ -2386,6 +2381,7 @@ static const SDProto sd_proto_sd = { }, .acmd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, + [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, }, };
PATCH v42 70/98 hw/sd/sdcard: Add sd_acmd_SEND_NUM_WR_BLOCKS handler (ACMD22)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)
hw/sd/sd.c +10 -13
@@ -263,7 +263,7 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [22] = "SEND_NUM_WR_BLOCKS", [23] = "SET_WR_BLK_ERASE_COUNT", + [23] = "SET_WR_BLK_ERASE_COUNT", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec",
@@ -1689,6 +1689,13 @@ static sd_rsp_type_t sd_acmd_SD_STATUS(SDState *sd, SDRequest req) sd->sd_status, sizeof(sd->sd_status)); } +/* ACMD22 */ +static sd_rsp_type_t sd_acmd_SEND_NUM_WR_BLOCKS (SDState *sd,SDRequest req) +{ +return sd_cmd_to_sendingdata (sd, req,0 , + &sd->blk_written,sizeof (sd->blk_written)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1797,18 +1804,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ -switch (sd->state) { -case sd_transfer_state: -return sd_cmd_to_sendingdata (sd, req,0 , - &sd->blk_written, -sizeof (sd->blk_written)); - -default : -break ; - } -break ; -case 23 :/* ACMD23: SET_WR_BLK_ERASE_COUNT */ switch (sd->state) {case sd_transfer_state:
@@ -2324,6 +2319,7 @@ static const SDProto sd_proto_spi = { }, .acmd = { [13] = {8, sd_spi, "SD_STATUS", sd_acmd_SD_STATUS}, + [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, };
@@ -2382,6 +2378,7 @@ static const SDProto sd_proto_sd = { .acmd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, + [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, }, };
Signature · 1 line
2.41.0
Re: [PATCH v42 70/98] hw/sd/sdcard: Add sd_acmd_SEND_NUM_WR_BLOCKS handler (ACMD22)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 66 lines
--- hw/sd/sd.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-)hw/sd/sd.c +10
-13@@ -263,7 +263,7 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [22] = "SEND_NUM_WR_BLOCKS", [23] = "SET_WR_BLK_ERASE_COUNT", + [23] = "SET_WR_BLK_ERASE_COUNT", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec",@@ -1689,6 +1689,13 @@ static sd_rsp_type_t sd_acmd_SD_STATUS(SDState *sd, SDRequest req) sd->sd_status, sizeof(sd->sd_status)); } +/* ACMD22 */ +static sd_rsp_type_t sd_acmd_SEND_NUM_WR_BLOCKS (SDState *sd,SDRequest req) +{ +return sd_cmd_to_sendingdata (sd, req,0 , + &sd->blk_written,sizeof (sd->blk_written)); +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;@@ -1797,18 +1804,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 22 :/* ACMD22: SEND_NUM_WR_BLOCKS */ -switch (sd->state) { -case sd_transfer_state: -return sd_cmd_to_sendingdata (sd, req,0 , - &sd->blk_written, -sizeof (sd->blk_written)); - -default : -break ; - } -break ; -case 23 :/* ACMD23: SET_WR_BLK_ERASE_COUNT */ switch (sd->state) {case sd_transfer_state:@@ -2324,6 +2319,7 @@ static const SDProto sd_proto_spi = { }, .acmd = { [13] = {8, sd_spi, "SD_STATUS", sd_acmd_SD_STATUS}, + [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, };@@ -2382,6 +2378,7 @@ static const SDProto sd_proto_sd = { .acmd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, + [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, }, };
PATCH v42 71/98 hw/sd/sdcard: Add sd_acmd_SET_WR_BLK_ERASE_COUNT handler (ACMD23)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
hw/sd/sd.c +11 -11
@@ -263,7 +263,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [23] = "SET_WR_BLK_ERASE_COUNT", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec",
@@ -1696,6 +1695,15 @@ static sd_rsp_type_t sd_acmd_SEND_NUM_WR_BLOCKS(SDState *sd, SDRequest req) &sd->blk_written, sizeof(sd->blk_written)); } +/* ACMD23 */ +static sd_rsp_type_t sd_acmd_SET_WR_BLK_ERASE_COUNT (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1804,16 +1812,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 23 :/* ACMD23: SET_WR_BLK_ERASE_COUNT */ -switch (sd->state) { -case sd_transfer_state: -return sd_r1; - -default : -break ; - } -break ; -case 41 :/* ACMD41: SD_APP_OP_COND */ if (sd->state != sd_idle_state) {break ;
@@ -2320,6 +2318,7 @@ static const SDProto sd_proto_spi = { .acmd = { [13] = {8, sd_spi, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, + [23] = {8, sd_spi, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, };
@@ -2379,6 +2378,7 @@ static const SDProto sd_proto_sd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, + [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, }, };
Signature · 1 line
2.41.0
Re: [PATCH v42 71/98] hw/sd/sdcard: Add sd_acmd_SET_WR_BLK_ERASE_COUNT handler (ACMD23)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 65 lines
--- hw/sd/sd.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)hw/sd/sd.c +11
-11@@ -263,7 +263,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [23] = "SET_WR_BLK_ERASE_COUNT", [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec",@@ -1696,6 +1695,15 @@ static sd_rsp_type_t sd_acmd_SEND_NUM_WR_BLOCKS(SDState *sd, SDRequest req) &sd->blk_written, sizeof(sd->blk_written)); } +/* ACMD23 */ +static sd_rsp_type_t sd_acmd_SET_WR_BLK_ERASE_COUNT (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;@@ -1804,16 +1812,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 23 :/* ACMD23: SET_WR_BLK_ERASE_COUNT */ -switch (sd->state) { -case sd_transfer_state: -return sd_r1; - -default : -break ; - } -break ; -case 41 :/* ACMD41: SD_APP_OP_COND */ if (sd->state != sd_idle_state) {break ;@@ -2320,6 +2318,7 @@ static const SDProto sd_proto_spi = { .acmd = { [13] = {8, sd_spi, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, + [23] = {8, sd_spi, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, }, };@@ -2379,6 +2378,7 @@ static const SDProto sd_proto_sd = { [6] = {8, sd_ac, "SET_BUS_WIDTH", sd_acmd_SET_BUS_WIDTH}, [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, + [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, }, };
PATCH v42 72/98 hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 82 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 37 deletions(-)
hw/sd/sd.c +45 -37
@@ -1704,6 +1704,50 @@ static sd_rsp_type_t sd_acmd_SET_WR_BLK_ERASE_COUNT(SDState *sd, SDRequest req)return sd_r1; } +/* ACMD41 */ +static sd_rsp_type_t sd_acmd_SD_APP_OP_COND (SDState *sd,SDRequest req) +{ +if (sd->state != sd_idle_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +/* +* If it's the first ACMD41 since reset, we need to decide +* whether to power up. If this is not an enquiry ACMD41, +* we immediately report power on and proceed below to the +* ready state, but if it is, we set a timer to model a +* delay for power up. This works around a bug in EDK2 +* UEFI, which sends an initial enquiry ACMD41, but +* assumes that the card is in ready state as soon as it +* sees the power up bit set. +*/ +if (!FIELD_EX32 (sd->ocr,OCR ,CARD_POWER_UP )) { +if ((req.arg &ACMD41_ENQUIRY_MASK ) !=0 ) { +timer_del (sd->ocr_power_timer); +sd_ocr_powerup (sd); + }else { +trace_sdcard_inquiry_cmd41 (); +if (!timer_pending (sd->ocr_power_timer)) { +timer_mod_ns (sd->ocr_power_timer, + (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + +OCR_POWER_DELAY_NS )); + } + } + } + +if (FIELD_EX32 (sd->ocr & req.arg,OCR ,VDD_VOLTAGE_WINDOW )) { +/* +* We accept any voltage. 10000 V is nothing. +* +* Once we're powered up, we advance straight to ready state +* unless it's an enquiry ACMD41 (bits 23:0 == 0). +*/ + sd->state = sd_ready_state; + } + +return sd_r3; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1812,43 +1856,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 41 :/* ACMD41: SD_APP_OP_COND */ -if (sd->state != sd_idle_state) { -break ; - } -/* If it's the first ACMD41 since reset, we need to decide -* whether to power up. If this is not an enquiry ACMD41, -* we immediately report power on and proceed below to the -* ready state, but if it is, we set a timer to model a -* delay for power up. This works around a bug in EDK2 -* UEFI, which sends an initial enquiry ACMD41, but -* assumes that the card is in ready state as soon as it -* sees the power up bit set. */ -if (!FIELD_EX32 (sd->ocr,OCR ,CARD_POWER_UP )) { -if ((req.arg &ACMD41_ENQUIRY_MASK ) !=0 ) { -timer_del (sd->ocr_power_timer); -sd_ocr_powerup (sd); - }else { -trace_sdcard_inquiry_cmd41 (); -if (!timer_pending (sd->ocr_power_timer)) { -timer_mod_ns (sd->ocr_power_timer, - (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - +OCR_POWER_DELAY_NS )); - } - } - } - -if (FIELD_EX32 (sd->ocr & req.arg,OCR ,VDD_VOLTAGE_WINDOW )) { -/* We accept any voltage. 10000 V is nothing. -* -* Once we're powered up, we advance straight to ready state -* unless it's an enquiry ACMD41 (bits 23:0 == 0). -*/ - sd->state = sd_ready_state; - } - -return sd_r3; -case 42 :/* ACMD42: SET_CLR_CARD_DETECT */ switch (sd->state) {case sd_transfer_state:
@@ -2379,6 +2386,7 @@ static const SDProto sd_proto_sd = { [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, + [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, }, };
Signature · 1 line
2.41.0
Re: [SPAM] [PATCH v42 72/98] hw/sd/sdcard: Add sd_acmd_SD_APP_OP_COND handler (ACMD41)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 111 lines
--- hw/sd/sd.c | 82 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 45 insertions(+), 37 deletions(-)hw/sd/sd.c +45
-37@@ -1704,6 +1704,50 @@ static sd_rsp_type_t sd_acmd_SET_WR_BLK_ERASE_COUNT(SDState *sd, SDRequest req)return sd_r1; } +/* ACMD41 */ +static sd_rsp_type_t sd_acmd_SD_APP_OP_COND (SDState *sd,SDRequest req) +{ +if (sd->state != sd_idle_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +/* +* If it's the first ACMD41 since reset, we need to decide +* whether to power up. If this is not an enquiry ACMD41, +* we immediately report power on and proceed below to the +* ready state, but if it is, we set a timer to model a +* delay for power up. This works around a bug in EDK2 +* UEFI, which sends an initial enquiry ACMD41, but +* assumes that the card is in ready state as soon as it +* sees the power up bit set. +*/ +if (!FIELD_EX32 (sd->ocr,OCR ,CARD_POWER_UP )) { +if ((req.arg &ACMD41_ENQUIRY_MASK ) !=0 ) { +timer_del (sd->ocr_power_timer); +sd_ocr_powerup (sd); + }else { +trace_sdcard_inquiry_cmd41 (); +if (!timer_pending (sd->ocr_power_timer)) { +timer_mod_ns (sd->ocr_power_timer, + (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) + +OCR_POWER_DELAY_NS )); + } + } + } + +if (FIELD_EX32 (sd->ocr & req.arg,OCR ,VDD_VOLTAGE_WINDOW )) { +/* +* We accept any voltage. 10000 V is nothing. +* +* Once we're powered up, we advance straight to ready state +* unless it's an enquiry ACMD41 (bits 23:0 == 0). +*/ + sd->state = sd_ready_state; + } + +return sd_r3; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;@@ -1812,43 +1856,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 41 :/* ACMD41: SD_APP_OP_COND */ -if (sd->state != sd_idle_state) { -break ; - } -/* If it's the first ACMD41 since reset, we need to decide -* whether to power up. If this is not an enquiry ACMD41, -* we immediately report power on and proceed below to the -* ready state, but if it is, we set a timer to model a -* delay for power up. This works around a bug in EDK2 -* UEFI, which sends an initial enquiry ACMD41, but -* assumes that the card is in ready state as soon as it -* sees the power up bit set. */ -if (!FIELD_EX32 (sd->ocr,OCR ,CARD_POWER_UP )) { -if ((req.arg &ACMD41_ENQUIRY_MASK ) !=0 ) { -timer_del (sd->ocr_power_timer); -sd_ocr_powerup (sd); - }else { -trace_sdcard_inquiry_cmd41 (); -if (!timer_pending (sd->ocr_power_timer)) { -timer_mod_ns (sd->ocr_power_timer, - (qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ) - +OCR_POWER_DELAY_NS )); - } - } - } - -if (FIELD_EX32 (sd->ocr & req.arg,OCR ,VDD_VOLTAGE_WINDOW )) { -/* We accept any voltage. 10000 V is nothing. -* -* Once we're powered up, we advance straight to ready state -* unless it's an enquiry ACMD41 (bits 23:0 == 0). -*/ - sd->state = sd_ready_state; - } - -return sd_r3; -case 42 :/* ACMD42: SET_CLR_CARD_DETECT */ switch (sd->state) {case sd_transfer_state:@@ -2379,6 +2386,7 @@ static const SDProto sd_proto_sd = { [13] = {8, sd_adtc, "SD_STATUS", sd_acmd_SD_STATUS}, [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, + [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, }, };
PATCH v42 73/98 hw/sd/sdcard: Add sd_acmd_SET_CLR_CARD_DETECT handler (ACMD42)
In reply to Philippe Mathieu-Daudé--- hw/sd/sd.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)
hw/sd/sd.c +13 -12
@@ -263,7 +263,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec", [54] = "SECU_spec",
@@ -1748,6 +1747,17 @@ static sd_rsp_type_t sd_acmd_SD_APP_OP_COND(SDState *sd, SDRequest req)return sd_r3; } +/* ACMD42 */ +static sd_rsp_type_t sd_acmd_SET_CLR_CARD_DETECT (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +/* Bringing in the 50KOhm pull-up resistor... Done. */ +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;
@@ -1856,17 +1866,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 42 :/* ACMD42: SET_CLR_CARD_DETECT */ -switch (sd->state) { -case sd_transfer_state: -/* Bringing in the 50KOhm pull-up resistor... Done. */ -return sd_r1; - -default : -break ; - } -break ; -case 51 :/* ACMD51: SEND_SCR */ switch (sd->state) {case sd_transfer_state:
@@ -2327,6 +2326,7 @@ static const SDProto sd_proto_spi = { [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_spi, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [42] = {8, sd_spi, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, }, };
@@ -2387,6 +2387,7 @@ static const SDProto sd_proto_sd = { [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, + [42] = {8, sd_ac, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, }, };
Signature · 1 line
2.41.0
Re: [PATCH v42 73/98] hw/sd/sdcard: Add sd_acmd_SET_CLR_CARD_DETECT handler (ACMD42)
Quoted 1 line · Philippe Mathieu-Daudé
Signed-off-by Philippe Mathieu-Daudé <[email protected]>
Thanks,
C.
Quoted 68 lines
--- hw/sd/sd.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-)hw/sd/sd.c +13
-12@@ -263,7 +263,6 @@ static const char *sd_acmd_name(SDState *sd, uint8_t cmd) [14] = "DPS_spec", [15] = "DPS_spec", [16] = "DPS_spec", [18] = "SECU_spec", - [42] = "SET_CLR_CARD_DETECT", [51] = "SEND_SCR", [52] = "SECU_spec", [53] = "SECU_spec", [54] = "SECU_spec",@@ -1748,6 +1747,17 @@ static sd_rsp_type_t sd_acmd_SD_APP_OP_COND(SDState *sd, SDRequest req)return sd_r3; } +/* ACMD42 */ +static sd_rsp_type_t sd_acmd_SET_CLR_CARD_DETECT (SDState *sd,SDRequest req) +{ +if (sd->state != sd_transfer_state) { +return sd_invalid_state_for_cmd (sd, req); + } + +/* Bringing in the 50KOhm pull-up resistor... Done. */ +return sd_r1; +} +static sd_rsp_type_t sd_normal_command (SDState *sd,SDRequest req) {uint64_t addr;@@ -1856,17 +1866,6 @@ static sd_rsp_type_t sd_app_command(SDState *sd, }switch (req.cmd) { -case 42 :/* ACMD42: SET_CLR_CARD_DETECT */ -switch (sd->state) { -case sd_transfer_state: -/* Bringing in the 50KOhm pull-up resistor... Done. */ -return sd_r1; - -default : -break ; - } -break ; -case 51 :/* ACMD51: SEND_SCR */ switch (sd->state) {case sd_transfer_state:@@ -2327,6 +2326,7 @@ static const SDProto sd_proto_spi = { [22] = {8, sd_spi, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_spi, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_spi, "SEND_OP_COND", spi_cmd_SEND_OP_COND}, + [42] = {8, sd_spi, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, }, };@@ -2387,6 +2387,7 @@ static const SDProto sd_proto_sd = { [22] = {8, sd_adtc, "SEND_NUM_WR_BLOCKS", sd_acmd_SEND_NUM_WR_BLOCKS}, [23] = {8, sd_ac, "SET_WR_BLK_ERASE_COUNT", sd_acmd_SET_WR_BLK_ERASE_COUNT}, [41] = {8, sd_bcr, "SD_APP_OP_COND", sd_acmd_SD_APP_OP_COND}, + [42] = {8, sd_ac, "SET_CLR_CARD_DETECT", sd_acmd_SET_CLR_CARD_DETECT}, }, };