public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH 2/3] MdeModulePkg/Usb: Read a large number of blocks
@ 2022-12-21 15:41 Chang, Abner
  2022-12-23  1:00 ` [edk2-devel] " Wu, Hao A
  0 siblings, 1 reply; 2+ messages in thread
From: Chang, Abner @ 2022-12-21 15:41 UTC (permalink / raw)
  To: devel; +Cc: Hao A Wu, Ray Ni, Garrett Kirkendall, Abner Chang, Kuei-Hung Lin

From: Abner Chang <abner.chang@amd.com>

Changes to allow reading blocks that greater than 65535 sectors.

Signed-off-by: Jiangang He <jiangang.he@amd.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
Cc: Abner Chang <abner.chang@amd.com>
Cc: Kuei-Hung Lin <Kuei-Hung.Lin@amd.com>
---
 MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c | 25 +++++++++++------------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c b/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
index 422ac5fec99..5111e4579e2 100644
--- a/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
+++ b/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
@@ -2,6 +2,7 @@
 Pei USB ATAPI command implementations.
 
 Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.<BR>
+Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>
 
 SPDX-License-Identifier: BSD-2-Clause-Patent
 
@@ -382,14 +383,14 @@ PeiUsbRead10 (
   ATAPI_PACKET_COMMAND  Packet;
   ATAPI_READ10_CMD      *Read10Packet;
   UINT16                MaxBlock;
-  UINT16                BlocksRemaining;
-  UINT16                SectorCount;
+  UINT32                BlocksRemaining;
+  UINT32                SectorCount;
   UINT32                Lba32;
   UINT32                BlockSize;
   UINT32                ByteCount;
   VOID                  *PtrBuffer;
   EFI_STATUS            Status;
-  UINT16                TimeOut;
+  UINT32                TimeOut;
 
   //
   // prepare command packet for the Inquiry Packet Command.
@@ -401,16 +402,13 @@ PeiUsbRead10 (
 
   BlockSize = (UINT32)PeiBotDevice->Media.BlockSize;
 
-  MaxBlock        = (UINT16)(65535 / BlockSize);
-  BlocksRemaining = (UINT16)NumberOfBlocks;
+  MaxBlock = (UINT16)(MAX_UINT16 / BlockSize);
+  ASSERT (NumberOfBlocks < MAX_UINT32);
+  BlocksRemaining = (UINT32)NumberOfBlocks;
 
   Status = EFI_SUCCESS;
   while (BlocksRemaining > 0) {
-    if (BlocksRemaining <= MaxBlock) {
-      SectorCount = BlocksRemaining;
-    } else {
-      SectorCount = MaxBlock;
-    }
+    SectorCount = MIN (BlocksRemaining, MaxBlock);
 
     //
     // fill the Packet data structure
@@ -435,7 +433,7 @@ PeiUsbRead10 (
 
     ByteCount = SectorCount * BlockSize;
 
-    TimeOut = (UINT16)(SectorCount * 2000);
+    TimeOut = SectorCount * 2000;
 
     //
     // send command packet
@@ -448,16 +446,17 @@ PeiUsbRead10 (
                (VOID *)PtrBuffer,
                ByteCount,
                EfiUsbDataIn,
-               TimeOut
+               (UINT16)MIN (TimeOut, MAX_UINT16)
                );
 
     if (Status != EFI_SUCCESS) {
       return Status;
     }
 
+    ASSERT (Lba32 <= (MAX_UINT32-SectorCount));
     Lba32          += SectorCount;
     PtrBuffer       = (UINT8 *)PtrBuffer + SectorCount * BlockSize;
-    BlocksRemaining = (UINT16)(BlocksRemaining - SectorCount);
+    BlocksRemaining = BlocksRemaining - SectorCount;
   }
 
   return Status;
-- 
2.37.1.windows.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [edk2-devel] [PATCH 2/3] MdeModulePkg/Usb: Read a large number of blocks
  2022-12-21 15:41 [PATCH 2/3] MdeModulePkg/Usb: Read a large number of blocks Chang, Abner
@ 2022-12-23  1:00 ` Wu, Hao A
  0 siblings, 0 replies; 2+ messages in thread
From: Wu, Hao A @ 2022-12-23  1:00 UTC (permalink / raw)
  To: devel@edk2.groups.io, abner.chang@amd.com
  Cc: Ni, Ray, Garrett Kirkendall, Kuei-Hung Lin

Reviewed-by: Hao A Wu <hao.a.wu@intel.com>

Best Regards,
Hao Wu

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Chang,
> Abner via groups.io
> Sent: Wednesday, December 21, 2022 11:42 PM
> To: devel@edk2.groups.io
> Cc: Wu, Hao A <hao.a.wu@intel.com>; Ni, Ray <ray.ni@intel.com>; Garrett
> Kirkendall <garrett.kirkendall@amd.com>; Abner Chang
> <abner.chang@amd.com>; Kuei-Hung Lin <Kuei-Hung.Lin@amd.com>
> Subject: [edk2-devel] [PATCH 2/3] MdeModulePkg/Usb: Read a large number
> of blocks
> 
> From: Abner Chang <abner.chang@amd.com>
> 
> Changes to allow reading blocks that greater than 65535 sectors.
> 
> Signed-off-by: Jiangang He <jiangang.he@amd.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Cc: Ray Ni <ray.ni@intel.com>
> Cc: Garrett Kirkendall <garrett.kirkendall@amd.com>
> Cc: Abner Chang <abner.chang@amd.com>
> Cc: Kuei-Hung Lin <Kuei-Hung.Lin@amd.com>
> ---
>  MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c | 25 +++++++++++------------
>  1 file changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
> b/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
> index 422ac5fec99..5111e4579e2 100644
> --- a/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
> +++ b/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
> @@ -2,6 +2,7 @@
>  Pei USB ATAPI command implementations.
> 
>  Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.<BR>
> +Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>
> 
>  SPDX-License-Identifier: BSD-2-Clause-Patent
> 
> @@ -382,14 +383,14 @@ PeiUsbRead10 (
>    ATAPI_PACKET_COMMAND  Packet;
>    ATAPI_READ10_CMD      *Read10Packet;
>    UINT16                MaxBlock;
> -  UINT16                BlocksRemaining;
> -  UINT16                SectorCount;
> +  UINT32                BlocksRemaining;
> +  UINT32                SectorCount;
>    UINT32                Lba32;
>    UINT32                BlockSize;
>    UINT32                ByteCount;
>    VOID                  *PtrBuffer;
>    EFI_STATUS            Status;
> -  UINT16                TimeOut;
> +  UINT32                TimeOut;
> 
>    //
>    // prepare command packet for the Inquiry Packet Command.
> @@ -401,16 +402,13 @@ PeiUsbRead10 (
> 
>    BlockSize = (UINT32)PeiBotDevice->Media.BlockSize;
> 
> -  MaxBlock        = (UINT16)(65535 / BlockSize);
> -  BlocksRemaining = (UINT16)NumberOfBlocks;
> +  MaxBlock = (UINT16)(MAX_UINT16 / BlockSize);
> +  ASSERT (NumberOfBlocks < MAX_UINT32);
> +  BlocksRemaining = (UINT32)NumberOfBlocks;
> 
>    Status = EFI_SUCCESS;
>    while (BlocksRemaining > 0) {
> -    if (BlocksRemaining <= MaxBlock) {
> -      SectorCount = BlocksRemaining;
> -    } else {
> -      SectorCount = MaxBlock;
> -    }
> +    SectorCount = MIN (BlocksRemaining, MaxBlock);
> 
>      //
>      // fill the Packet data structure
> @@ -435,7 +433,7 @@ PeiUsbRead10 (
> 
>      ByteCount = SectorCount * BlockSize;
> 
> -    TimeOut = (UINT16)(SectorCount * 2000);
> +    TimeOut = SectorCount * 2000;
> 
>      //
>      // send command packet
> @@ -448,16 +446,17 @@ PeiUsbRead10 (
>                 (VOID *)PtrBuffer,
>                 ByteCount,
>                 EfiUsbDataIn,
> -               TimeOut
> +               (UINT16)MIN (TimeOut, MAX_UINT16)
>                 );
> 
>      if (Status != EFI_SUCCESS) {
>        return Status;
>      }
> 
> +    ASSERT (Lba32 <= (MAX_UINT32-SectorCount));
>      Lba32          += SectorCount;
>      PtrBuffer       = (UINT8 *)PtrBuffer + SectorCount * BlockSize;
> -    BlocksRemaining = (UINT16)(BlocksRemaining - SectorCount);
> +    BlocksRemaining = BlocksRemaining - SectorCount;
>    }
> 
>    return Status;
> --
> 2.37.1.windows.1
> 
> 
> 
> 
> 


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-23  1:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-12-21 15:41 [PATCH 2/3] MdeModulePkg/Usb: Read a large number of blocks Chang, Abner
2022-12-23  1:00 ` [edk2-devel] " Wu, Hao A

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox