[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 15/20] sdcard: Add SDFrame136 struct and 136-bit SD
From: |
Philippe Mathieu-Daudé |
Subject: |
[Qemu-devel] [PATCH 15/20] sdcard: Add SDFrame136 struct and 136-bit SD response frames functions |
Date: |
Fri, 4 May 2018 12:59:13 -0300 |
The 'read CID/CSD register' request returns a 136-bit frame
containing those 128-bit registers.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
include/hw/sd/sd.h | 29 +++++++++++++++++++++++++++++
hw/sd/sdmmc-internal.c | 15 +++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h
index 13de1b30c3..c76be51b32 100644
--- a/include/hw/sd/sd.h
+++ b/include/hw/sd/sd.h
@@ -91,6 +91,17 @@ typedef struct SDFrame48 {
uint8_t crc;
} SDFrame48;
+/**
+ * SDFrame136: 136 bits CID or CSD responses
+ *
+ * @content: CID or CSD register
+ * @crc: 7-bit CRC checksum
+ */
+typedef struct SDFrame136 {
+ uint8_t content[15];
+ uint8_t crc;
+} SDFrame136;
+
typedef struct SDFrame48 SDRequest;
typedef struct SDState SDState;
@@ -193,6 +204,14 @@ void sd_prepare_frame48(SDFrame48 *frame, uint8_t cmd,
uint32_t arg,
*/
void sd_update_frame48_checksum(SDFrame48 *frame, bool is_response);
+/**
+ * sd_update_frame136_checksum:
+ * @frame: the #SDFrame136 to verify
+ *
+ * Update the 16-bit CRC checksum of a SD 136-bit frame.
+ */
+void sd_update_frame136_checksum(SDFrame136 *frame);
+
/**
* sd_verify_frame48_checksum:
* @frame: the #SDFrame48 to verify
@@ -204,6 +223,16 @@ void sd_update_frame48_checksum(SDFrame48 *frame, bool
is_response);
*/
bool sd_verify_frame48_checksum(SDFrame48 *frame, bool is_response);
+/**
+ * sd_verify_frame136_checksum:
+ * @frame: the #SDFrame48 to verify
+ *
+ * Verify the 16-bit CRC checksum of a SD 136-bit frame.
+ *
+ * Returns: A boolean indicating whether the frame 16-bit CRC is correct.
+ */
+bool sd_verify_frame136_checksum(SDFrame136 *frame);
+
/* Legacy functions to be used only by non-qdevified callers */
SDState *sd_init(BlockBackend *bs, bool is_spi);
int sd_do_command(SDState *sd, SDRequest *req,
diff --git a/hw/sd/sdmmc-internal.c b/hw/sd/sdmmc-internal.c
index c990cc9e8e..68350a2304 100644
--- a/hw/sd/sdmmc-internal.c
+++ b/hw/sd/sdmmc-internal.c
@@ -117,6 +117,11 @@ static uint8_t sd_calc_frame48_crc7(uint8_t cmd, uint32_t
arg, bool is_response)
return sd_crc7(buffer, sizeof(buffer));
}
+static uint8_t sd_calc_frame136_crc7(SDFrame136 *frame)
+{
+ return (sd_crc7(frame->content, sizeof(frame->content)) << 1) | 1;
+}
+
bool sd_verify_frame48_checksum(SDFrame48 *frame, bool is_response)
{
uint8_t crc = sd_calc_frame48_crc7(frame->cmd, frame->arg, is_response);
@@ -124,11 +129,21 @@ bool sd_verify_frame48_checksum(SDFrame48 *frame, bool
is_response)
return crc == frame->crc;
}
+bool sd_verify_frame136_checksum(SDFrame136 *frame)
+{
+ return sd_calc_frame136_crc7(frame) == frame->crc;
+}
+
void sd_update_frame48_checksum(SDFrame48 *frame, bool is_response)
{
frame->crc = sd_calc_frame48_crc7(frame->cmd, frame->arg, is_response);
}
+void sd_update_frame136_checksum(SDFrame136 *frame)
+{
+ frame->crc = (sd_crc7(frame->content, sizeof(frame->content)) << 1) | 1;
+}
+
void sd_prepare_frame48(SDFrame48 *frame, uint8_t cmd, uint32_t arg,
bool is_response, bool gen_crc)
{
--
2.17.0
- [Qemu-devel] [PATCH 05/20] sdcard: Use the sd_prepare_request*() functions, (continued)
- [Qemu-devel] [PATCH 05/20] sdcard: Use the sd_prepare_request*() functions, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 07/20] sdcard: Constify sd_crc*()'s message argument, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 08/20] sdcard: Fix sd_crc*() style, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 09/20] sdcard: Expose sd_crc*() functions for QTest use, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 10/20] sdcard: Expose sd_prepare_request*() functions for QTest use, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 11/20] sdcard: Add test_sd_request_frame_crc7() qtest (request command CRC7), Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 12/20] sdcard: Let sd_frame48_crc7_calc() work on response frames, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 14/20] sdcard: Add test_sd_response_frame48_crc7 qtest (command response CRC7), Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 13/20] sdcard: Expose sd_prepare_frame48() for QTest use, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 15/20] sdcard: Add SDFrame136 struct and 136-bit SD response frames functions,
Philippe Mathieu-Daudé <=
- [Qemu-devel] [PATCH 16/20] sdcard: Add test_sd_response_frame136_crc7() qtest, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 19/20] sdcard: Add test_sd_data_frame_crc16() qtest, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 17/20] sdcard: Add SDFrameData struct and data frame checksum functions, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 18/20] sdcard: Fix sd_crc16(), Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 20/20] sdcard: Add test_sd_verify_cksum_frame48() qtest, Philippe Mathieu-Daudé, 2018/05/04
- Re: [Qemu-devel] [PATCH 00/20] sdcard: proper implementation of CRC, Philippe Mathieu-Daudé, 2018/05/07