[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 11/67] hw/sd/sdcard: Add direct reference to SDProto in SDState
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 11/67] hw/sd/sdcard: Add direct reference to SDProto in SDState |
Date: |
Tue, 2 Jul 2024 11:19:54 +0200 |
Keep direct reference to SDProto in SDState,
remove then unnecessary sd_proto().
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-14-philmd@linaro.org>
---
hw/sd/sd.c | 37 +++++++++++++++++--------------------
1 file changed, 17 insertions(+), 20 deletions(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 30c1d299d4..d06e670024 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -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 */
@@ -152,18 +154,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)
@@ -1041,7 +1036,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;
@@ -1050,7 +1045,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;
@@ -1059,7 +1054,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;
@@ -1070,7 +1065,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;
}
@@ -1163,7 +1158,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));
}
@@ -1182,8 +1177,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) {
@@ -1629,12 +1624,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) {
@@ -1925,7 +1920,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) {
@@ -2081,7 +2076,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) {
@@ -2226,7 +2221,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);
--
2.41.0
- [PULL 01/67] hw/sd/sdcard: Deprecate support for spec v1.10, (continued)
- [PULL 01/67] hw/sd/sdcard: Deprecate support for spec v1.10, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 02/67] hw/sd/sdcard: Track last command used to help logging, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 03/67] hw/sd/sdcard: Trace block offset in READ/WRITE data accesses, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 04/67] hw/sd/sdcard: Trace requested address computed by sd_req_get_address(), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 08/67] hw/sd/sdcard: Use READY_FOR_DATA definition instead of magic value, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 06/67] hw/sd/sdcard: Send WRITE_PROT bits MSB first (CMD30), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 05/67] hw/sd/sdcard: Restrict SWITCH_FUNCTION to sd_transfer_state (CMD6), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 07/67] hw/sd/sdcard: Send NUM_WR_BLOCKS bits MSB first (ACMD22), Philippe Mathieu-Daudé, 2024/07/02
- [PULL 09/67] hw/sd/sdcard: Assign SDCardStates enum values, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 10/67] hw/sd/sdcard: Simplify sd_inactive_state handling, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 11/67] hw/sd/sdcard: Add direct reference to SDProto in SDState,
Philippe Mathieu-Daudé <=
- [PULL 12/67] hw/sd/sdcard: Extract sd_blk_len() helper, Philippe Mathieu-Daudé, 2024/07/02
- [PULL 13/67] hw/sd/sdcard: Introduce definitions for EXT_CSD register, Philippe Mathieu-Daudé, 2024/07/02
- [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