[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 24/67] hw/sd/sdcard: Introduce sd_cmd_to_receivingdata / sd_generi
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 24/67] hw/sd/sdcard: Introduce sd_cmd_to_receivingdata / sd_generic_write_byte |
Date: |
Tue, 2 Jul 2024 11:20:07 +0200 |
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é <philmd@linaro.org>
Tested-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Message-Id: <20240628070216.92609-30-philmd@linaro.org>
---
hw/sd/sd.c | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 78aabb65ac..990f038b79 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -1095,6 +1095,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,
@@ -1943,6 +1959,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)
{
--
2.41.0
- [PULL 14/67] hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte, (continued)
- [PULL 14/67] hw/sd/sdcard: Introduce sd_cmd_to_sendingdata and sd_generic_read_byte, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 15/67] hw/sd/sdcard: Convert SWITCH_FUNCTION to generic_read_byte (CMD6), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 16/67] hw/sd/sdcard: Convert SEND_CSD/SEND_CID to generic_read_byte (CMD9 & 10), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 18/67] hw/sd/sdcard: Convert READ_SINGLE_BLOCK to generic_read_byte (CMD17), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 17/67] hw/sd/sdcard: Duplicate READ_SINGLE_BLOCK / READ_MULTIPLE_BLOCK cases, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 19/67] hw/sd/sdcard: Convert SEND_TUNING_BLOCK to generic_read_byte (CMD19), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 20/67] hw/sd/sdcard: Convert SEND_WRITE_PROT to generic_read_byte (CMD30), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 21/67] hw/sd/sdcard: Convert SD_STATUS to generic_read_byte (ACMD13), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 22/67] hw/sd/sdcard: Convert SEND_NUM_WR_BLOCKS to generic_read_byte (ACMD22), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 23/67] hw/sd/sdcard: Convert SEND_SCR to generic_read_byte (ACMD51), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 24/67] hw/sd/sdcard: Introduce sd_cmd_to_receivingdata / sd_generic_write_byte,
Philippe Mathieu-Daudé <=
- [PULL 25/67] hw/sd/sdcard: Duplicate WRITE_SINGLE_BLOCK / WRITE_MULTIPLE_BLOCK cases, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 26/67] hw/sd/sdcard: Convert WRITE_SINGLE_BLOCK to generic_write_byte (CMD24), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 27/67] hw/sd/sdcard: Convert PROGRAM_CID to generic_write_byte (CMD26), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 28/67] hw/sd/sdcard: Convert PROGRAM_CSD to generic_write_byte (CMD27), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 29/67] hw/sd/sdcard: Convert LOCK_UNLOCK to generic_write_byte (CMD42), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 30/67] hw/sd/sdcard: Move sd_[a]cmd_name() methods to sd.c, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 31/67] hw/sd/sdcard: Pass SDState as argument to sd_[a]cmd_name(), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 32/67] hw/sd/sdcard: Prepare SDProto to contain more fields, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 33/67] hw/sd/sdcard: Store command name in SDProto, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 34/67] hw/sd/sdcard: Store command type in SDProto, Philippe Mathieu-Daudé, 2024/07/02