qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
To: "Markus Armbruster" <armbru@redhat.com>,
	"Kevin Wolf" <kwolf@redhat.com>, "Max Reitz" <mreitz@redhat.com>,
	"Vladimir Sementsov-Ogievskiy" <vsementsov@virtuozzo.com>,
	"Eric Blake" <eblake@redhat.com>, "Joel Stanley" <joel@jms.id.au>,
	"Cédric Le Goater" <clg@kaod.org>,
	"Vincent Palatin" <vpalatin@chromium.org>,
	"Dr. David Alan Gilbert" <dgilbert@redhat.com>,
	"Thomas Huth" <thuth@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Alistair Francis" <alistair.francis@wdc.com>,
	"Edgar E. Iglesias" <edgar.iglesias@xilinx.com>,
	"Luc Michel" <luc.michel@greensocs.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>
Cc: saipava@xilinx.com, qemu-devel@nongnu.org, qemu-block@nongnu.org
Subject: [PATCH v2 11/22] sd: emmc: Add mmc switch function support
Date: Mon, 22 Feb 2021 13:50:28 +0530	[thread overview]
Message-ID: <1613982039-13861-12-git-send-email-sai.pavan.boddu@xilinx.com> (raw)
In-Reply-To: <1613982039-13861-1-git-send-email-sai.pavan.boddu@xilinx.com>

switch operation in eMMC card updates the ext_csd register to
request changes in card operations. Here we implement similar
sequence but requests are mostly dummy and make no change.

Implement SWITCH_ERROR if the write operation extends goes beyond length
of ext_csd.

Signed-off-by: Sai Pavan Boddu <sai.pavan.boddu@xilinx.com>
Signed-off-by: Edgar E. Iglesias <edgar.iglesias@xilinx.com>
---
 hw/sd/sd.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 50 insertions(+), 6 deletions(-)

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index ae5c5e8..e50d40b 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -515,6 +515,7 @@ static void sd_set_rca(SDState *sd, uint16_t value)
 FIELD(CSR, AKE_SEQ_ERROR,               3,  1)
 FIELD(CSR, APP_CMD,                     5,  1)
 FIELD(CSR, FX_EVENT,                    6,  1)
+FIELD(CSR, SWITCH_ERROR,                7,  1)
 FIELD(CSR, READY_FOR_DATA,              8,  1)
 FIELD(CSR, CURRENT_STATE,               9,  4)
 FIELD(CSR, ERASE_RESET,                13,  1)
@@ -878,6 +879,43 @@ static uint32_t sd_wpbits(SDState *sd, uint64_t addr)
     return ret;
 }
 
+enum {
+    MMC_CMD6_ACCESS_COMMAND_SET = 0,
+    MMC_CMD6_ACCESS_SET_BITS,
+    MMC_CMD6_ACCESS_CLEAR_BITS,
+    MMC_CMD6_ACCESS_WRITE_BYTE,
+};
+
+static void mmc_function_switch(SDState *sd, uint32_t arg)
+{
+    uint32_t access = extract32(arg, 24, 2);
+    uint32_t index = extract32(arg, 16, 8);
+    uint32_t value = extract32(arg, 8, 8);
+    uint8_t b = sd->ext_csd[index];
+
+    switch (access) {
+    case MMC_CMD6_ACCESS_COMMAND_SET:
+        qemu_log_mask(LOG_UNIMP, "MMC Command set switching not supported\n");
+        return;
+    case MMC_CMD6_ACCESS_SET_BITS:
+        b |= value;
+        break;
+    case MMC_CMD6_ACCESS_CLEAR_BITS:
+        b &= ~value;
+        break;
+    case MMC_CMD6_ACCESS_WRITE_BYTE:
+        b = value;
+        break;
+    }
+
+    if (index >= 192) {
+        sd->card_status |= R_CSR_SWITCH_ERROR_MASK;
+        return;
+    }
+
+    sd->ext_csd[index] = b;
+}
+
 static void sd_function_switch(SDState *sd, uint32_t arg)
 {
     int i, mode, new_func;
@@ -1097,12 +1135,18 @@ static sd_rsp_type_t sd_normal_command(SDState *sd, SDRequest req)
     case 6: /* CMD6:   SWITCH_FUNCTION */
         switch (sd->mode) {
         case sd_data_transfer_mode:
-            sd_function_switch(sd, req.arg);
-            sd->state = sd_sendingdata_state;
-            sd->data_start = 0;
-            sd->data_offset = 0;
-            return sd_r1;
-
+            if (sd->emmc) {
+                sd->state = sd_programming_state;
+                mmc_function_switch(sd, req.arg);
+                sd->state = sd_transfer_state;
+                return sd_r1b;
+            } else {
+                sd_function_switch(sd, req.arg);
+                sd->state = sd_sendingdata_state;
+                sd->data_start = 0;
+                sd->data_offset = 0;
+                return sd_r1;
+            }
         default:
             break;
         }
-- 
2.7.4



  parent reply	other threads:[~2021-02-22  8:26 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-22  8:20 [PATCH v2 00/22] eMMC support Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 01/22] block: add eMMC block device type Sai Pavan Boddu
2021-02-22 12:04   ` Philippe Mathieu-Daudé
2021-02-22 12:19     ` Markus Armbruster
2021-02-22 13:16       ` Dr. David Alan Gilbert
2021-02-22 13:23         ` Philippe Mathieu-Daudé
2021-02-22 16:17           ` Sai Pavan Boddu
2021-02-22 16:26             ` Dr. David Alan Gilbert
2021-02-23 17:35     ` Sai Pavan Boddu
2021-02-24 11:40       ` Stefan Hajnoczi
2021-02-24 13:55         ` Cédric Le Goater
2021-02-24 19:13           ` Sai Pavan Boddu
2021-02-25 14:43             ` Cédric Le Goater
2021-02-24 19:06         ` Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 02/22] sd: sd: Remove usage of tabs in the file Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 03/22] sd: emmc: Add support for eMMC cards Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 04/22] sd: emmc: update OCR fields for eMMC Sai Pavan Boddu
2021-02-22  9:51   ` Cédric Le Goater
2021-02-22  9:55     ` Sai Pavan Boddu
2021-02-22 11:59       ` Philippe Mathieu-Daudé
2021-02-22  8:20 ` [PATCH v2 05/22] sd: emmc: Add support for EXT_CSD & CSD " Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 06/22] sd: emmc: Update CMD8 to send EXT_CSD register Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 07/22] sd: sdmmc-internal: Add command string for SEND_OP_CMD Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 08/22] sd: emmc: Dont not update CARD_CAPACITY for eMMC cards Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 09/22] sd: emmc: Update CMD1 definition for eMMC Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 10/22] sd: emmc: support idle state in CMD2 Sai Pavan Boddu
2021-02-22  8:20 ` Sai Pavan Boddu [this message]
2021-02-22  8:20 ` [PATCH v2 12/22] sd: emmc: add CMD21 tuning sequence Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 13/22] sd: emmc: Make ACMD41 illegal for mmc Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 14/22] sd: emmc: Add support for emmc erase Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 15/22] sd: emmc: Update CID structure for eMMC Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 16/22] sd: emmc: Add Extended CSD register definitions Sai Pavan Boddu
2021-02-22  9:54   ` Cédric Le Goater
2021-02-22  8:20 ` [PATCH v2 17/22] sd: emmc: Support boot area in emmc image Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 18/22] sd: emmc: Subtract bootarea size from blk Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 19/22] sd: sdhci: Support eMMC devices Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 20/22] arm: xlnx-versal: Add emmc to versal Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 21/22] docs: devel: emmc: Add a doc for emmc card emulation Sai Pavan Boddu
2021-02-22  8:20 ` [PATCH v2 22/22] docs: arm: xlnx-versal-virt: Add eMMC support documentation Sai Pavan Boddu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1613982039-13861-12-git-send-email-sai.pavan.boddu@xilinx.com \
    --to=sai.pavan.boddu@xilinx.com \
    --cc=alistair.francis@wdc.com \
    --cc=armbru@redhat.com \
    --cc=clg@kaod.org \
    --cc=dgilbert@redhat.com \
    --cc=eblake@redhat.com \
    --cc=edgar.iglesias@xilinx.com \
    --cc=joel@jms.id.au \
    --cc=kwolf@redhat.com \
    --cc=luc.michel@greensocs.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=saipava@xilinx.com \
    --cc=stefanha@redhat.com \
    --cc=thuth@redhat.com \
    --cc=vpalatin@chromium.org \
    --cc=vsementsov@virtuozzo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).