From nobody Wed Oct 29 22:59:18 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 15258382248501022.9210174793322; Tue, 8 May 2018 20:57:04 -0700 (PDT) Received: from localhost ([::1]:54317 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGGDw-0004zm-1q for importer@patchew.org; Tue, 08 May 2018 23:57:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fGG4q-0004h6-CD for qemu-devel@nongnu.org; Tue, 08 May 2018 23:47:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fGG4o-00038b-EA for qemu-devel@nongnu.org; Tue, 08 May 2018 23:47:40 -0400 Received: from mail-qt0-x242.google.com ([2607:f8b0:400d:c0d::242]:45685) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fGG4o-00038C-8D for qemu-devel@nongnu.org; Tue, 08 May 2018 23:47:38 -0400 Received: by mail-qt0-x242.google.com with SMTP id j42-v6so43940710qtj.12 for ; Tue, 08 May 2018 20:47:38 -0700 (PDT) Received: from x1.local ([138.117.48.222]) by smtp.gmail.com with ESMTPSA id w12-v6sm14497002qtb.80.2018.05.08.20.47.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 May 2018 20:47:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PE0jvDqc7ydGppO075eNYIhSUAFJ2u8znNr3J3z9Njs=; b=nP1lgvtrCpR7F9zvuNJrtJ7E94zhgHUQsv3SFtp7PLSEKNXYW+Jq2IkExFg/8tB6OU Lwj4Qokx2vdeGbH8DEk64ytx+OmDJjeFZ4ILk0mVo6wC5nXS9mX8OFiHQFpwAVnEKoUK CwnukIFgh3YO6yOvxYofgXOEU07loShUCIcg3wZTv7wgXDaYALLYHED5XTuqvFUwSiYE /RNSHzz11uORYRCCnY44wGCCYoQOrUP3LWtDMam6BJqrdocApq/2YzzTzrCmKyVtpYkN YQUBf23ThG1MclcflaZJhBlg1xVd+C/M+XFPON7l2QHUnW1391205PiEl27PBVhpAvom pmiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=PE0jvDqc7ydGppO075eNYIhSUAFJ2u8znNr3J3z9Njs=; b=Hzm15ICpqcbjDvBt0l3Ka+hh5DJDJhVtDNHLlrRVqqpAYqN/wghPOH7DSuV/vTbl9F ovb3piy8uCPYCrbm5FHoO79dcf0RDgt/xOK9KQIqk57ooDjfhmhcjsBXyuv10M4Eq9Bd POAN5W2o/vowAzAluAOXMP0fJMpk0i/U9+lb0NH9n1q3aOTyuykzsJEesSVlID38E4tE lm5JxsnJyPxxHuCvFdoNxo9dnJzPELkFEfW6yl878TYSqBIBIejWxMMsdkUV2r4OMEVk mCcEnoqKwZ5B+gRU1xdGZjnJUwIqmSgAdOTiy6zOfKrRbX5PM5viayTfHOn95Q64WWM5 FAxg== X-Gm-Message-State: ALQs6tAvUwvKGJbA9AumLjo8Fk0ruo0HIRUQCmk7v5ICvhHvbBKbiSqc lZOTDMofAAS/LdHcHe7/4sU= X-Google-Smtp-Source: AB8JxZpJ0X7FzdUgdTnLDM94fXOwMaN2M22K2kkEquToUx+9+UZ3K2GjA8dXwE0SQPjXMQjxPpCvIQ== X-Received: by 2002:ac8:31ca:: with SMTP id i10-v6mr37906385qte.166.1525837657333; Tue, 08 May 2018 20:47:37 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Peter Maydell , "Edgar E . Iglesias" Date: Wed, 9 May 2018 00:46:54 -0300 Message-Id: <20180509034658.26455-11-f4bug@amsat.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180509034658.26455-1-f4bug@amsat.org> References: <20180509034658.26455-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400d:c0d::242 Subject: [Qemu-devel] [PATCH v2 10/14] sdcard: Remove the SDRequest argument from internal functions X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paolo Bonzini , Alistair Francis , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Stefan Hajnoczi , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Replace the SDRequest argument using directly {uint8_t cmd, uint32_t arg}, it will be easier to remove the SDRequest struct in the next commit. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/sd/sd.c | 104 +++++++++++++++++++++++++++-------------------------- 1 file changed, 53 insertions(+), 51 deletions(-) diff --git a/hw/sd/sd.c b/hw/sd/sd.c index 125707a65c..0dfcaf480c 100644 --- a/hw/sd/sd.c +++ b/hw/sd/sd.c @@ -853,35 +853,34 @@ static void sd_lock_command(SDState *sd) sd->card_status &=3D ~CARD_IS_LOCKED; } =20 -static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req) +static sd_rsp_type_t sd_normal_command(SDState *sd, uint8_t cmd, uint32_t = arg) { uint32_t rca =3D 0x0000; - uint64_t addr =3D (sd->ocr & (1 << 30)) ? (uint64_t) req.arg << 9 : re= q.arg; + uint64_t addr =3D (sd->ocr & (1 << 30)) ? (uint64_t) arg << 9 : arg; =20 /* CMD55 precedes an ACMD, so we are not interested in tracing it. * However there is no ACMD55, so we want to trace this particular cas= e. */ - if (req.cmd !=3D 55 || sd->expecting_acmd) { + if (cmd !=3D 55 || sd->expecting_acmd) { trace_sdcard_normal_command(sd->proto_name, - sd_cmd_name(req.cmd), req.cmd, - req.arg, sd_state_name(sd->state)); + sd_cmd_name(cmd), cmd, + arg, sd_state_name(sd->state)); } =20 /* Not interpreting this as an app command */ sd->card_status &=3D ~APP_CMD; =20 - if (sd_cmd_type[req.cmd] =3D=3D sd_ac - || sd_cmd_type[req.cmd] =3D=3D sd_adtc) { - rca =3D req.arg >> 16; + if (sd_cmd_type[cmd] =3D=3D sd_ac || sd_cmd_type[cmd] =3D=3D sd_adtc) { + rca =3D arg >> 16; } =20 /* CMD23 (set block count) must be immediately followed by CMD18 or CM= D25 * if not, its effects are cancelled */ - if (sd->multi_blk_cnt !=3D 0 && !(req.cmd =3D=3D 18 || req.cmd =3D=3D = 25)) { + if (sd->multi_blk_cnt !=3D 0 && !(cmd =3D=3D 18 || cmd =3D=3D 25)) { sd->multi_blk_cnt =3D 0; } =20 - switch (req.cmd) { + switch (cmd) { /* Basic commands (Class 0 and Class 1) */ case 0: /* CMD0: GO_IDLE_STATE */ switch (sd->state) { @@ -950,7 +949,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDR= equest req) goto bad_cmd; switch (sd->mode) { case sd_data_transfer_mode: - sd_function_switch(sd, req.arg); + sd_function_switch(sd, arg); sd->state =3D sd_sendingdata_state; sd->data_start =3D 0; sd->data_offset =3D 0; @@ -1007,12 +1006,12 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,= SDRequest req) sd->vhs =3D 0; =20 /* No response if not exactly one VHS bit is set. */ - if (!(req.arg >> 8) || (req.arg >> (ctz32(req.arg & ~0xff) + 1))) { + if (!(arg >> 8) || (arg >> (ctz32(arg & ~0xff) + 1))) { return sd->spi ? sd_r7 : sd_r0; } =20 /* Accept. */ - sd->vhs =3D req.arg; + sd->vhs =3D arg; return sd_r7; =20 case 9: /* CMD9: SEND_CSD */ @@ -1109,11 +1108,11 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,= SDRequest req) case 16: /* CMD16: SET_BLOCKLEN */ switch (sd->state) { case sd_transfer_state: - if (req.arg > (1 << HWBLOCK_SHIFT)) { + if (arg > (1 << HWBLOCK_SHIFT)) { sd->card_status |=3D BLOCK_LEN_ERROR; } else { - trace_sdcard_set_blocklen(req.arg); - sd->blk_len =3D req.arg; + trace_sdcard_set_blocklen(arg); + sd->blk_len =3D arg; } =20 return sd_r1; @@ -1166,7 +1165,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) case 23: /* CMD23: SET_BLOCK_COUNT */ switch (sd->state) { case sd_transfer_state: - sd->multi_blk_cnt =3D req.arg; + sd->multi_blk_cnt =3D arg; return sd_r1; =20 default: @@ -1303,7 +1302,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) switch (sd->state) { case sd_transfer_state: sd->state =3D sd_sendingdata_state; - *(uint32_t *) sd->data =3D sd_wpbits(sd, req.arg); + *(uint32_t *) sd->data =3D sd_wpbits(sd, arg); sd->data_start =3D addr; sd->data_offset =3D 0; return sd_r1b; @@ -1317,7 +1316,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) case 32: /* CMD32: ERASE_WR_BLK_START */ switch (sd->state) { case sd_transfer_state: - sd->erase_start =3D req.arg; + sd->erase_start =3D arg; return sd_r1; =20 default: @@ -1328,7 +1327,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) case 33: /* CMD33: ERASE_WR_BLK_END */ switch (sd->state) { case sd_transfer_state: - sd->erase_end =3D req.arg; + sd->erase_end =3D arg; return sd_r1; =20 default: @@ -1391,7 +1390,7 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, S= DRequest req) case sd_idle_state: if (rca) { qemu_log_mask(LOG_GUEST_ERROR, - "SD: illegal RCA 0x%04x for APP_CMD\n", req.= cmd); + "SD: illegal RCA 0x%04x for APP_CMD\n", cmd); } default: break; @@ -1409,10 +1408,11 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,= SDRequest req) switch (sd->state) { case sd_transfer_state: sd->data_offset =3D 0; - if (req.arg & 1) + if (arg & 1) { sd->state =3D sd_sendingdata_state; - else + } else { sd->state =3D sd_receivingdata_state; + } return sd_r1; =20 default: @@ -1434,27 +1434,26 @@ static sd_rsp_type_t sd_normal_command(SDState *sd,= SDRequest req) =20 default: bad_cmd: - qemu_log_mask(LOG_GUEST_ERROR, "SD: Unknown CMD%i\n", req.cmd); + qemu_log_mask(LOG_GUEST_ERROR, "SD: Unknown CMD%i\n", cmd); return sd_illegal; =20 unimplemented_spi_cmd: /* Commands that are recognised but not yet implemented in SPI mod= e. */ qemu_log_mask(LOG_UNIMP, "SD: CMD%i not implemented in SPI mode\n", - req.cmd); + cmd); return sd_illegal; } =20 - qemu_log_mask(LOG_GUEST_ERROR, "SD: CMD%i in a wrong state\n", req.cmd= ); + qemu_log_mask(LOG_GUEST_ERROR, "SD: CMD%i in a wrong state\n", cmd); return sd_illegal; } =20 -static sd_rsp_type_t sd_app_command(SDState *sd, - SDRequest req) +static sd_rsp_type_t sd_app_command(SDState *sd, uint8_t cmd, uint32_t arg) { - trace_sdcard_app_command(sd->proto_name, sd_acmd_name(req.cmd), - req.cmd, req.arg, sd_state_name(sd->state)); + trace_sdcard_app_command(sd->proto_name, sd_acmd_name(cmd), + cmd, arg, sd_state_name(sd->state)); sd->card_status |=3D APP_CMD; - switch (req.cmd) { + switch (cmd) { case 6: /* ACMD6: SET_BUS_WIDTH */ if (sd->spi) { goto unimplemented_spi_cmd; @@ -1462,7 +1461,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd, switch (sd->state) { case sd_transfer_state: sd->sd_status[0] &=3D 0x3f; - sd->sd_status[0] |=3D (req.arg & 0x03) << 6; + sd->sd_status[0] |=3D (arg & 0x03) << 6; return sd_r1; =20 default: @@ -1526,7 +1525,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd, * assumes that the card is in ready state as soon as it * sees the power up bit set. */ if (!FIELD_EX32(sd->ocr, OCR, CARD_POWER_UP)) { - if ((req.arg & ACMD41_ENQUIRY_MASK) !=3D 0) { + if ((arg & ACMD41_ENQUIRY_MASK) !=3D 0) { timer_del(sd->ocr_power_timer); sd_ocr_powerup(sd); } else { @@ -1539,7 +1538,7 @@ static sd_rsp_type_t sd_app_command(SDState *sd, } } =20 - if (FIELD_EX32(sd->ocr & req.arg, OCR, VDD_VOLTAGE_WINDOW)) { + if (FIELD_EX32(sd->ocr & arg, OCR, VDD_VOLTAGE_WINDOW)) { /* We accept any voltage. 10000 V is nothing. * * Once we're powered up, we advance straight to ready state @@ -1583,25 +1582,25 @@ static sd_rsp_type_t sd_app_command(SDState *sd, * information about the SD Security Features. */ qemu_log_mask(LOG_UNIMP, "SD: CMD%i Security not implemented\n", - req.cmd); + cmd); return sd_illegal; =20 default: /* Fall back to standard commands. */ - return sd_normal_command(sd, req); + return sd_normal_command(sd, cmd, arg); =20 unimplemented_spi_cmd: /* Commands that are recognised but not yet implemented in SPI mod= e. */ qemu_log_mask(LOG_UNIMP, "SD: CMD%i not implemented in SPI mode\n", - req.cmd); + cmd); return sd_illegal; } =20 - qemu_log_mask(LOG_GUEST_ERROR, "SD: ACMD%i in a wrong state\n", req.cm= d); + qemu_log_mask(LOG_GUEST_ERROR, "SD: ACMD%i in a wrong state\n", cmd); return sd_illegal; } =20 -static int cmd_valid_while_locked(SDState *sd, SDRequest *req) +static int cmd_valid_while_locked(SDState *sd, uint8_t cmd) { /* Valid commands in locked state: * basic class (0) @@ -1612,13 +1611,12 @@ static int cmd_valid_while_locked(SDState *sd, SDRe= quest *req) * Anything else provokes an "illegal command" response. */ if (sd->expecting_acmd) { - return req->cmd =3D=3D 41 || req->cmd =3D=3D 42; + return cmd =3D=3D 41 || cmd =3D=3D 42; } - if (req->cmd =3D=3D 16 || req->cmd =3D=3D 55) { + if (cmd =3D=3D 16 || cmd =3D=3D 55) { return 1; } - return sd_cmd_class[req->cmd] =3D=3D 0 - || sd_cmd_class[req->cmd] =3D=3D 7; + return sd_cmd_class[cmd] =3D=3D 0 || sd_cmd_class[cmd] =3D=3D 7; } =20 int sd_do_command(SDState *sd, SDRequest *req, @@ -1626,25 +1624,29 @@ int sd_do_command(SDState *sd, SDRequest *req, int last_state; sd_rsp_type_t rtype; int rsplen; + uint8_t cmd; + uint32_t arg; =20 if (!sd->blk || !blk_is_inserted(sd->blk) || !sd->enable) { return 0; } =20 + cmd =3D req->cmd; + arg =3D req->arg; + if (!sd_req_crc_is_valid(req)) { sd->card_status |=3D COM_CRC_ERROR; rtype =3D sd_illegal; goto send_response; } =20 - if (req->cmd >=3D SDMMC_CMD_MAX) { - qemu_log_mask(LOG_GUEST_ERROR, "SD: incorrect command 0x%02x\n", - req->cmd); - req->cmd &=3D 0x3f; + if (cmd >=3D SDMMC_CMD_MAX) { + qemu_log_mask(LOG_GUEST_ERROR, "SD: incorrect command 0x%02x\n", c= md); + cmd &=3D 0x3f; } =20 if (sd->card_status & CARD_IS_LOCKED) { - if (!cmd_valid_while_locked(sd, req)) { + if (!cmd_valid_while_locked(sd, cmd)) { sd->card_status |=3D ILLEGAL_COMMAND; sd->expecting_acmd =3D false; qemu_log_mask(LOG_GUEST_ERROR, "SD: Card is locked\n"); @@ -1658,9 +1660,9 @@ int sd_do_command(SDState *sd, SDRequest *req, =20 if (sd->expecting_acmd) { sd->expecting_acmd =3D false; - rtype =3D sd_app_command(sd, *req); + rtype =3D sd_app_command(sd, cmd, arg); } else { - rtype =3D sd_normal_command(sd, *req); + rtype =3D sd_normal_command(sd, cmd, arg); } =20 if (rtype =3D=3D sd_illegal) { @@ -1669,7 +1671,7 @@ int sd_do_command(SDState *sd, SDRequest *req, /* Valid command, we can update the 'state before command' bits. * (Do this now so they appear in r1 responses.) */ - sd->current_cmd =3D req->cmd; + sd->current_cmd =3D cmd; sd->card_status &=3D ~CURRENT_STATE; sd->card_status |=3D (last_state << 9); } --=20 2.17.0