[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 10/20] sdcard: Expose sd_prepare_request*() function
From: |
Philippe Mathieu-Daudé |
Subject: |
[Qemu-devel] [PATCH 10/20] sdcard: Expose sd_prepare_request*() functions for QTest use |
Date: |
Fri, 4 May 2018 12:59:08 -0300 |
Take those functions out of hw/sd/sd.c (via "sdmmc-internal.h")
to be able to write QTests for them.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
hw/sd/sdmmc-internal.h | 2 ++
include/hw/sd/sd.h | 18 ++++++++++++++++++
hw/sd/sd.c | 43 ------------------------------------------
hw/sd/sdmmc-internal.c | 43 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 63 insertions(+), 43 deletions(-)
diff --git a/hw/sd/sdmmc-internal.h b/hw/sd/sdmmc-internal.h
index 62c0ff250d..d672112200 100644
--- a/hw/sd/sdmmc-internal.h
+++ b/hw/sd/sdmmc-internal.h
@@ -10,6 +10,8 @@
#ifndef SD_INTERNAL_H
#define SD_INTERNAL_H
+#include "hw/sd/sd.h"
+
#define SDMMC_CMD_MAX 64
/**
diff --git a/include/hw/sd/sd.h b/include/hw/sd/sd.h
index 7d9c906897..b65107ffe1 100644
--- a/include/hw/sd/sd.h
+++ b/include/hw/sd/sd.h
@@ -168,6 +168,24 @@ void sd_prepare_request(SDRequest *req, uint8_t cmd,
uint32_t arg,
void sd_prepare_request_with_crc(SDRequest *req, uint8_t cmd, uint32_t arg,
uint8_t crc);
+/**
+ * sd_update_frame48_checksum:
+ * @frame: the #SDFrame48 to verify
+ *
+ * Update the 7-bit CRC checksum of a SD 48-bit frame.
+ */
+void sd_update_frame48_checksum(SDFrame48 *frame);
+
+/**
+ * sd_verify_frame48_checksum:
+ * @frame: the #SDFrame48 to verify
+ *
+ * Verify the 7-bit CRC checksum of a SD 48-bit frame.
+ *
+ * Returns: A boolean indicating whether the frame 7-bit CRC is correct.
+ */
+bool sd_verify_frame48_checksum(SDFrame48 *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/sd.c b/hw/sd/sd.c
index 11b4606051..2d2c31d308 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -449,21 +449,6 @@ static void sd_set_sdstatus(SDState *sd)
memset(sd->sd_status, 0, 64);
}
-static uint8_t sd_calc_frame48_crc7(uint8_t cmd, uint32_t arg)
-{
- uint8_t buffer[5];
- buffer[0] = 0x40 | cmd;
- stl_be_p(&buffer[1], 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 bool sd_req_crc_validate(SDState *sd, SDRequest *req)
{
if (sd->validate_crc) {
@@ -472,34 +457,6 @@ static bool sd_req_crc_validate(SDState *sd, SDRequest
*req)
return true;
}
-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)
{
stl_be_p(response, sd->card_status);
diff --git a/hw/sd/sdmmc-internal.c b/hw/sd/sdmmc-internal.c
index 69ad0a99e6..97f5f71569 100644
--- a/hw/sd/sdmmc-internal.c
+++ b/hw/sd/sdmmc-internal.c
@@ -108,3 +108,46 @@ uint16_t sd_crc16(const void *message, size_t width)
return shift_reg;
}
+
+static uint8_t sd_calc_frame48_crc7(uint8_t cmd, uint32_t arg)
+{
+ uint8_t buffer[5];
+ buffer[0] = 0x40 | cmd;
+ stl_be_p(&buffer[1], arg);
+ return sd_crc7(buffer, sizeof(buffer));
+}
+
+bool sd_verify_frame48_checksum(SDFrame48 *frame)
+{
+ uint8_t crc = sd_calc_frame48_crc7(frame->cmd, frame->arg);
+
+ return crc == frame->crc;
+}
+
+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;
+}
--
2.17.0
- [Qemu-devel] [PATCH 02/20] sdcard: Extract sd_calc_frame48_crc7() from sd_req_crc_validate(), (continued)
- [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é, 2018/05/04
- [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é <=
- [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é, 2018/05/04
- [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