[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 04/20] sdcard: Add sd_prepare_request[_with_crc]()
From: |
Philippe Mathieu-Daudé |
Subject: |
[Qemu-devel] [PATCH 04/20] sdcard: Add sd_prepare_request[_with_crc]() |
Date: |
Fri, 4 May 2018 12:59:02 -0300 |
The sd_prepare_request*() functions fill all the request frame members.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
include/hw/sd/sd.h | 27 +++++++++++++++++++++++++++
hw/sd/sd.c | 37 ++++++++++++++++++++++++++++++++++++-
2 files changed, 63 insertions(+), 1 deletion(-)
diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h
index f0b41232f7..7d9c906897 100644
--- a/include/hw/sd/sd.h
+++ b/include/hw/sd/sd.h
@@ -141,6 +141,33 @@ typedef struct {
void (*set_readonly)(DeviceState *dev, bool readonly);
} SDBusClass;
+/**
+ * sd_prepare_request:
+ * @req: the #SDRequest to be filled
+ * @cmd: the SD command
+ * @arg: the SD command argument
+ * @gen_crc: generates the frame CRC7 if true, else fill with zeroes
+ *
+ * Initialize a SD request buffer.
+ *
+ * If @gen_crc the frame checksum will be calculated
+ * and filled in the request buffer.
+ */
+void sd_prepare_request(SDRequest *req, uint8_t cmd, uint32_t arg,
+ bool gen_crc);
+
+/**
+ * sd_prepare_request_with_crc:
+ * @req: the #SDRequest to be filled
+ * @cmd: the SD command
+ * @arg: the SD command argument
+ * @crc: the calculated request CRC7
+ *
+ * Initialize a SD request buffer.
+ */
+void sd_prepare_request_with_crc(SDRequest *req, uint8_t cmd, uint32_t arg,
+ uint8_t crc);
+
/* 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/sd.c b/hw/sd/sd.c
index 861bba197d..be75e118c0 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -489,10 +489,45 @@ static uint8_t sd_calc_frame48_crc7(uint8_t cmd, uint32_t
arg)
return sd_crc7(buffer, sizeof(buffer));
}
+static bool sd_verify_frame48_checksum(SDFrame48 *frame)
+{
+ uint8_t crc = sd_calc_frame48_crc7(frame->cmd, frame->arg);
+
+ return crc == frame->crc;
+}
+
static int sd_req_crc_validate(SDRequest *req)
{
return 0;
- return sd_calc_frame48_crc7(req->cmd, req->arg) != req->crc; /* TODO */
+ return !sd_verify_frame48_checksum(req); /* TODO */
+}
+
+static void sd_update_frame48_checksum(SDFrame48 *frame)
+{
+ frame->crc = sd_calc_frame48_crc7(frame->cmd, frame->arg);
+}
+
+static void sd_prepare_frame48(SDFrame48 *frame, uint8_t cmd, uint32_t arg,
+ bool gen_crc)
+{
+ frame->cmd = cmd;
+ frame->arg = arg;
+ frame->crc = 0x00;
+ if (gen_crc) {
+ sd_update_frame48_checksum(frame);
+ }
+}
+
+void sd_prepare_request(SDFrame48 *req, uint8_t cmd, uint32_t arg, bool
gen_crc)
+{
+ sd_prepare_frame48(req, cmd, arg, gen_crc);
+}
+
+void sd_prepare_request_with_crc(SDRequest *req, uint8_t cmd, uint32_t arg,
+ uint8_t crc)
+{
+ sd_prepare_frame48(req, cmd, arg, /* gen_crc */ false);
+ req->crc = crc;
}
static void sd_response_r1_make(SDState *sd, uint8_t *response)
--
2.17.0
- [Qemu-devel] [PATCH 00/20] sdcard: proper implementation of CRC, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 03/20] sdcard: Rename the SDRequest as SDFrame48, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 02/20] sdcard: Extract sd_calc_frame48_crc7() from sd_req_crc_validate(), Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 01/20] sdcard: Use the ldst API, Philippe Mathieu-Daudé, 2018/05/04
- [Qemu-devel] [PATCH 04/20] sdcard: Add sd_prepare_request[_with_crc](),
Philippe Mathieu-Daudé <=
- [Qemu-devel] [PATCH 06/20] sdcard: Add a "validate-crc" property, Philippe Mathieu-Daudé, 2018/05/04
- [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