From: "Chang, Abner" <abner.chang@amd.com>
To: <devel@edk2.groups.io>
Cc: <Kuei-Hung.Lin@amd.com>, Hao A Wu <hao.a.wu@intel.com>,
Ray Ni <ray.ni@intel.com>,
Garrett Kirkendall <garrett.kirkendall@amd.com>,
"Abner Chang" <abner.chang@amd.com>
Subject: [PATCH] MdeModulePkg/Usb: Read a large number of blocks
Date: Sat, 10 Dec 2022 20:52:40 +0800 [thread overview]
Message-ID: <20221210125240.1270-1-abner.chang@amd.com> (raw)
From: Abner Chang <abner.chang@amd.com>
Changes to allow reading blocks that greater than 65535 sectors.
Signed-off-by: Kuei-Hung Lin <Kuei-Hung.Lin@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>
---
MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c | 24 +++++++++++------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c b/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
index 422ac5fec99..35b79804879 100644
--- a/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
+++ b/MdeModulePkg/Bus/Usb/UsbBotPei/PeiAtapi.c
@@ -382,14 +382,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 +401,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 +432,7 @@ PeiUsbRead10 (
ByteCount = SectorCount * BlockSize;
- TimeOut = (UINT16)(SectorCount * 2000);
+ TimeOut = SectorCount * 2000;
//
// send command packet
@@ -448,16 +445,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
reply other threads:[~2022-12-10 12:53 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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-list 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=20221210125240.1270-1-abner.chang@amd.com \
--to=devel@edk2.groups.io \
/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