Pei USB ATAPI command implementations.\r
\r
Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.<BR>\r
+Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.<BR>\r
\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
ATAPI_PACKET_COMMAND Packet;\r
ATAPI_READ10_CMD *Read10Packet;\r
UINT16 MaxBlock;\r
- UINT16 BlocksRemaining;\r
- UINT16 SectorCount;\r
+ UINT32 BlocksRemaining;\r
+ UINT32 SectorCount;\r
UINT32 Lba32;\r
UINT32 BlockSize;\r
UINT32 ByteCount;\r
VOID *PtrBuffer;\r
EFI_STATUS Status;\r
- UINT16 TimeOut;\r
+ UINT32 TimeOut;\r
\r
//\r
// prepare command packet for the Inquiry Packet Command.\r
\r
BlockSize = (UINT32)PeiBotDevice->Media.BlockSize;\r
\r
- MaxBlock = (UINT16)(65535 / BlockSize);\r
- BlocksRemaining = (UINT16)NumberOfBlocks;\r
+ MaxBlock = (UINT16)(MAX_UINT16 / BlockSize);\r
+ ASSERT (NumberOfBlocks < MAX_UINT32);\r
+ BlocksRemaining = (UINT32)NumberOfBlocks;\r
\r
Status = EFI_SUCCESS;\r
while (BlocksRemaining > 0) {\r
- if (BlocksRemaining <= MaxBlock) {\r
- SectorCount = BlocksRemaining;\r
- } else {\r
- SectorCount = MaxBlock;\r
- }\r
+ SectorCount = MIN (BlocksRemaining, MaxBlock);\r
\r
//\r
// fill the Packet data structure\r
\r
ByteCount = SectorCount * BlockSize;\r
\r
- TimeOut = (UINT16)(SectorCount * 2000);\r
+ TimeOut = SectorCount * 2000;\r
\r
//\r
// send command packet\r
(VOID *)PtrBuffer,\r
ByteCount,\r
EfiUsbDataIn,\r
- TimeOut\r
+ (UINT16)MIN (TimeOut, MAX_UINT16)\r
);\r
\r
if (Status != EFI_SUCCESS) {\r
return Status;\r
}\r
\r
+ ASSERT (Lba32 <= (MAX_UINT32-SectorCount));\r
Lba32 += SectorCount;\r
PtrBuffer = (UINT8 *)PtrBuffer + SectorCount * BlockSize;\r
- BlocksRemaining = (UINT16)(BlocksRemaining - SectorCount);\r
+ BlocksRemaining = BlocksRemaining - SectorCount;\r
}\r
\r
return Status;\r