[edk2,1/1] MdeModulePkg/Sd: append CMD12 for multiple blocks

Message ID 1524893045-2958-1-git-send-email-haojian.zhuang@linaro.org
State New
Headers show
Series
  • [edk2,1/1] MdeModulePkg/Sd: append CMD12 for multiple blocks
Related show

Commit Message

Haojian Zhuang April 28, 2018, 5:24 a.m.
Send CMD12 to stop transimission for accessing multiple blocks. It's
required by SD Card protocol.

Cc: Star Zeng <star.zeng@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Leif Lindholm <leif.lindholm@linaro.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>

---
 MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

-- 
2.7.4

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Comments

Wu, Hao A May 3, 2018, 2:45 a.m. | #1
Hi Haojian,

Sorry for the delayed response.

As far as I know, we enabled the auto CMD12 feature within:
SdMmcExecTrb(), MdeModulePkg\Bus\Pci\SdMmcPciHcDxe\SdMmcPciHci.c

    //
    // Only SD memory card needs to use AUTO CMD12 feature.
    //
    if (Private->Slot[Trb->Slot].CardType == SdCardType) {
      if (BlkCount > 1) {
        TransMode |= BIT2;
      }
    }

So I think the explicitly sending CMD12 in SdRwMultiBlocks() is not needed.

Have you met problems when using SdRwMultiBlocks()? Could you help to
provide detailed device information when you meet the problem?

Thanks in advance.

Best Regards,
Hao Wu

> -----Original Message-----

> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of

> Haojian Zhuang

> Sent: Saturday, April 28, 2018 1:24 PM

> To: edk2-devel@lists.01.org

> Cc: Ni, Ruiyu; Dong, Eric; Ard Biesheuvel; Leif Lindholm; Haojian Zhuang; Zeng,

> Star

> Subject: [edk2] [PATCH 1/1] MdeModulePkg/Sd: append CMD12 for multiple

> blocks

> 

> Send CMD12 to stop transimission for accessing multiple blocks. It's

> required by SD Card protocol.

> 

> Cc: Star Zeng <star.zeng@intel.com>

> Cc: Eric Dong <eric.dong@intel.com>

> Cc: Ruiyu Ni <ruiyu.ni@intel.com>

> Cc: Leif Lindholm <leif.lindholm@linaro.org>

> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>

> Contributed-under: TianoCore Contribution Agreement 1.1

> Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>

> ---

>  MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c | 35

> +++++++++++++++++++++++++++++++++++

>  1 file changed, 35 insertions(+)

> 

> diff --git a/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c

> b/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c

> index 516c3e704288..64259f99f9bc 100644

> --- a/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c

> +++ b/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c

> @@ -426,6 +426,36 @@ Error:

>    return Status;

>  }

> 

> +EFI_STATUS

> +SdStopTrans (

> +  IN  SD_DEVICE                 *Device

> +  )

> +{

> +  EFI_STATUS                           Status;

> +  EFI_SD_MMC_PASS_THRU_PROTOCOL        *PassThru;

> +  EFI_SD_MMC_COMMAND_BLOCK             SdMmcCmdBlk;

> +  EFI_SD_MMC_STATUS_BLOCK              SdMmcStatusBlk;

> +  EFI_SD_MMC_PASS_THRU_COMMAND_PACKET  Packet;

> +

> +  PassThru = Device->Private->PassThru;

> +

> +  ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));

> +  ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));

> +  ZeroMem (&Packet, sizeof (Packet));

> +

> +  Packet.SdMmcCmdBlk    = &SdMmcCmdBlk;

> +  Packet.SdMmcStatusBlk = &SdMmcStatusBlk;

> +  Packet.Timeout        = SD_GENERIC_TIMEOUT;

> +

> +  SdMmcCmdBlk.CommandIndex = SD_STOP_TRANSMISSION;

> +  SdMmcCmdBlk.CommandType  = SdMmcCommandTypeAc;

> +  SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;

> +  SdMmcCmdBlk.CommandArgument = 0;

> +

> +  Status = PassThru->PassThru (PassThru, Device->Slot, &Packet, NULL);

> +  return Status;

> +}

> +

>  /**

>    Read/write multiple blocks through sync or async I/O request.

> 

> @@ -555,6 +585,11 @@ Error:

>      }

>    }

> 

> +  if (EFI_ERROR (Status)) {

> +    return Status;

> +  }

> +

> +  Status = SdStopTrans (Device);

>    return Status;

>  }

> 

> --

> 2.7.4

> 

> _______________________________________________

> edk2-devel mailing list

> edk2-devel@lists.01.org

> https://lists.01.org/mailman/listinfo/edk2-devel

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel
Haojian Zhuang May 9, 2018, 9:56 a.m. | #2
Hi Hao,

OK. I tried to enable auto stop command in Designware MMC driver. So this
patch could be ignored.

Thanks
Haojian

On 3 May 2018 at 10:45, Wu, Hao A <hao.a.wu@intel.com> wrote:
> Hi Haojian,

>

> Sorry for the delayed response.

>

> As far as I know, we enabled the auto CMD12 feature within:

> SdMmcExecTrb(), MdeModulePkg\Bus\Pci\SdMmcPciHcDxe\SdMmcPciHci.c

>

>     //

>     // Only SD memory card needs to use AUTO CMD12 feature.

>     //

>     if (Private->Slot[Trb->Slot].CardType == SdCardType) {

>       if (BlkCount > 1) {

>         TransMode |= BIT2;

>       }

>     }

>

> So I think the explicitly sending CMD12 in SdRwMultiBlocks() is not needed.

>

> Have you met problems when using SdRwMultiBlocks()? Could you help to

> provide detailed device information when you meet the problem?

>

> Thanks in advance.

>

> Best Regards,

> Hao Wu

>

>> -----Original Message-----

>> From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of

>> Haojian Zhuang

>> Sent: Saturday, April 28, 2018 1:24 PM

>> To: edk2-devel@lists.01.org

>> Cc: Ni, Ruiyu; Dong, Eric; Ard Biesheuvel; Leif Lindholm; Haojian Zhuang; Zeng,

>> Star

>> Subject: [edk2] [PATCH 1/1] MdeModulePkg/Sd: append CMD12 for multiple

>> blocks

>>

>> Send CMD12 to stop transimission for accessing multiple blocks. It's

>> required by SD Card protocol.

>>

>> Cc: Star Zeng <star.zeng@intel.com>

>> Cc: Eric Dong <eric.dong@intel.com>

>> Cc: Ruiyu Ni <ruiyu.ni@intel.com>

>> Cc: Leif Lindholm <leif.lindholm@linaro.org>

>> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>

>> Contributed-under: TianoCore Contribution Agreement 1.1

>> Signed-off-by: Haojian Zhuang <haojian.zhuang@linaro.org>

>> ---

>>  MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c | 35

>> +++++++++++++++++++++++++++++++++++

>>  1 file changed, 35 insertions(+)

>>

>> diff --git a/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c

>> b/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c

>> index 516c3e704288..64259f99f9bc 100644

>> --- a/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c

>> +++ b/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c

>> @@ -426,6 +426,36 @@ Error:

>>    return Status;

>>  }

>>

>> +EFI_STATUS

>> +SdStopTrans (

>> +  IN  SD_DEVICE                 *Device

>> +  )

>> +{

>> +  EFI_STATUS                           Status;

>> +  EFI_SD_MMC_PASS_THRU_PROTOCOL        *PassThru;

>> +  EFI_SD_MMC_COMMAND_BLOCK             SdMmcCmdBlk;

>> +  EFI_SD_MMC_STATUS_BLOCK              SdMmcStatusBlk;

>> +  EFI_SD_MMC_PASS_THRU_COMMAND_PACKET  Packet;

>> +

>> +  PassThru = Device->Private->PassThru;

>> +

>> +  ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));

>> +  ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));

>> +  ZeroMem (&Packet, sizeof (Packet));

>> +

>> +  Packet.SdMmcCmdBlk    = &SdMmcCmdBlk;

>> +  Packet.SdMmcStatusBlk = &SdMmcStatusBlk;

>> +  Packet.Timeout        = SD_GENERIC_TIMEOUT;

>> +

>> +  SdMmcCmdBlk.CommandIndex = SD_STOP_TRANSMISSION;

>> +  SdMmcCmdBlk.CommandType  = SdMmcCommandTypeAc;

>> +  SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;

>> +  SdMmcCmdBlk.CommandArgument = 0;

>> +

>> +  Status = PassThru->PassThru (PassThru, Device->Slot, &Packet, NULL);

>> +  return Status;

>> +}

>> +

>>  /**

>>    Read/write multiple blocks through sync or async I/O request.

>>

>> @@ -555,6 +585,11 @@ Error:

>>      }

>>    }

>>

>> +  if (EFI_ERROR (Status)) {

>> +    return Status;

>> +  }

>> +

>> +  Status = SdStopTrans (Device);

>>    return Status;

>>  }

>>

>> --

>> 2.7.4

>>

>> _______________________________________________

>> edk2-devel mailing list

>> edk2-devel@lists.01.org

>> https://lists.01.org/mailman/listinfo/edk2-devel

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Patch

diff --git a/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c b/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c
index 516c3e704288..64259f99f9bc 100644
--- a/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c
+++ b/MdeModulePkg/Bus/Sd/SdDxe/SdBlockIo.c
@@ -426,6 +426,36 @@  Error:
   return Status;
 }
 
+EFI_STATUS
+SdStopTrans (
+  IN  SD_DEVICE                 *Device
+  )
+{
+  EFI_STATUS                           Status;
+  EFI_SD_MMC_PASS_THRU_PROTOCOL        *PassThru;
+  EFI_SD_MMC_COMMAND_BLOCK             SdMmcCmdBlk;
+  EFI_SD_MMC_STATUS_BLOCK              SdMmcStatusBlk;
+  EFI_SD_MMC_PASS_THRU_COMMAND_PACKET  Packet;
+
+  PassThru = Device->Private->PassThru;
+
+  ZeroMem (&SdMmcCmdBlk, sizeof (SdMmcCmdBlk));
+  ZeroMem (&SdMmcStatusBlk, sizeof (SdMmcStatusBlk));
+  ZeroMem (&Packet, sizeof (Packet));
+
+  Packet.SdMmcCmdBlk    = &SdMmcCmdBlk;
+  Packet.SdMmcStatusBlk = &SdMmcStatusBlk;
+  Packet.Timeout        = SD_GENERIC_TIMEOUT;
+
+  SdMmcCmdBlk.CommandIndex = SD_STOP_TRANSMISSION;
+  SdMmcCmdBlk.CommandType  = SdMmcCommandTypeAc;
+  SdMmcCmdBlk.ResponseType = SdMmcResponseTypeR1b;
+  SdMmcCmdBlk.CommandArgument = 0;
+
+  Status = PassThru->PassThru (PassThru, Device->Slot, &Packet, NULL);
+  return Status;
+}
+
 /**
   Read/write multiple blocks through sync or async I/O request.
 
@@ -555,6 +585,11 @@  Error:
     }
   }
 
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  Status = SdStopTrans (Device);
   return Status;
 }