From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.85]) by mx.groups.io with SMTP id smtpd.web11.14508.1673406634335242933 for ; Tue, 10 Jan 2023 19:10:34 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@amd.com header.s=selector1 header.b=4iFKPEWi; spf=permerror, err=parse error for token &{10 18 %{i}._ip.%{h}._ehlo.%{d}._spf.vali.email}: invalid domain name (domain: amd.com, ip: 40.107.94.85, mailfrom: abner.chang@amd.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ejXq/J2ysLQIVKeM02nASWi2cSJn/kU1Wo4c9Lhnf+NPjgC7M2BUGqEJNTWjAfoPlDG2+qqUTk312zv9EUio2ILU3gnV+ailQ/fLJLHaHflTRLT3E3sSsTPOnuEkfcGuir6kemJiD+fv9w0E/iRfOpUek9s+dizCs2lGR3fOgYdBKOgqsXCOxdEze0zAB4cVWchlWnZLl3oId9yW9n+kkW843eu2Ek+HtgL5ahlKndbMA7VqRvCvhFqlU0rUWXilXeotkOnlt8P/o5MU1gCDg2cQ6vbluKpO5SSVDGVO9F2QTuUn5Pj0i7456D2/zhsE9eiglmufKs0W1yQaGMEaXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=0VX7qAok90nByjeoal1kDtKFJsRwQTcFmqqyx00UZ0c=; b=GPUg0GNQmr1qLrXZ4tJLZ6k5F8wNERHe6m0GFoqHazEzZyZLeMy1YAFgTvVideIOQGvW+DKgdD6BKIv+A8NRRIeQfxBSAgSMMwvsb2XDSZ4EsSb4Ky/OPWXazlyahp/jJH9pjggqyZOet3KfStM3qAPApPBNF9vUP822318PNCHw2FYJjcxAUC53TSIpG8E9XS6HAJ0HxW1k4VOhV6J04gDOXFY7SoFwZcA3lnc6xRmZl7e4aNdR1PSiJuexfmrOpLucglmxh+DrFaAac0/UZSj5YeF8hab+C9y0a0PfoLuF96PrhCoCbKWKK7okAe2RhyrqagXyvO67L6r6+0o7UA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=edk2.groups.io smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0VX7qAok90nByjeoal1kDtKFJsRwQTcFmqqyx00UZ0c=; b=4iFKPEWi8nVw7QUHnkIi40yJJVMTerIddHCRNPV20mDnYLr+AvO92BdR2X7kerm7vBaWex7yXzJJEUu5ZGISq+d+99Ubi8wzTnZPmS7tXgQxXghf8GCd7bszwB78XtbiRA8GpHiq0GaFlBksJVI7ezoeUTrLiuyzLFIR0dV0NzQ= Received: from MW4PR03CA0060.namprd03.prod.outlook.com (2603:10b6:303:8e::35) by DS7PR12MB5718.namprd12.prod.outlook.com (2603:10b6:8:71::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Wed, 11 Jan 2023 03:10:31 +0000 Received: from CO1NAM11FT017.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8e:cafe::3f) by MW4PR03CA0060.outlook.office365.com (2603:10b6:303:8e::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18 via Frontend Transport; Wed, 11 Jan 2023 03:10:31 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT017.mail.protection.outlook.com (10.13.175.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5986.18 via Frontend Transport; Wed, 11 Jan 2023 03:10:30 +0000 Received: from TPE-L1-ABNCHANG.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Tue, 10 Jan 2023 21:10:28 -0600 From: "Chang, Abner" To: CC: Hao A Wu , Ray Ni , "Garrett Kirkendall" , Abner Chang , Kuei-Hung Lin Subject: [PATCH V2 2/3] MdeModulePkg/Usb: Read a large number of blocks Date: Wed, 11 Jan 2023 11:10:07 +0800 Message-ID: <20230111031008.1476-2-abner.chang@amd.com> X-Mailer: git-send-email 2.37.1.windows.1 In-Reply-To: <20230111031008.1476-1-abner.chang@amd.com> References: <20230111031008.1476-1-abner.chang@amd.com> MIME-Version: 1.0 Return-Path: Abner.Chang@amd.com X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT017:EE_|DS7PR12MB5718:EE_ X-MS-Office365-Filtering-Correlation-Id: 5b04732b-8283-42d7-ac3c-08daf38165d3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vlOp2r0G6MG4Ui8LFNEpWR8rFYrwKAKTbz6iManB1MSsW4VAAJHsJ2zFo5DuvnTYji5RXqNVZApP+K9g89apNn4jT0sDgxxYrAoeDPKwgZihwGqrtR5UM3A/uT94RdWFi3XC7YU1zj6yk6dQbRhiMBJA+c6XKNt+xzA4rZvzaUXZgJXkQtL9cq234NTGBBm/RIa5OltiZJ2gtYBg6ys6n44WOfj7l/mB7bcEaOr2nuBMnD2M9Mtp43iWw3OrQMUDuYgX+ozRfz2OfHk4LfBprk4fqTI3QtzKi9gPa7q8yg9WHl7i9NSel+viHW7DG557dk98rrYD6aIwPyZYExYni5WBWknUwObM8qOsJoMvgJtRdV+8fkeVSXmtkl9YM2bj83qYbEwjFos+det1gC54m1+bZMmExb70gZLr4NrLZGFUwiwUq5J9b9QVavAy7CrqcZwK/OBFg9w2vt2pbV5TbgZHs58/sHs7K+a/SvrIyWvptPQMA+ZKAVzgjlHaZdHKZitBeN36wT8dk4Co1PX4oRJ8ZqAaWeFXtRPrgoZLU+Fn1LdDWnhkLRMteYWzm/3ptzriS5Pz4M9OOKK1rA3V1Rj35afqSFpDFolXw1mip735Gfhue449Z/OBAKUWGhgxLJx5pD3JAVo7fCDBZsLmdamBdJrI0fy5fOJgPKrNWQqAYc5Tcrpai43vesGvWmGPKv+uucyU+gAUDFqVHFh6iYhp1rcB8H5HTtgK8u2mhWU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230022)(4636009)(39860400002)(376002)(136003)(346002)(396003)(451199015)(36840700001)(40470700004)(46966006)(6916009)(70586007)(8676002)(7696005)(316002)(70206006)(4326008)(54906003)(356005)(2876002)(2906002)(5660300002)(47076005)(8936002)(81166007)(426003)(41300700001)(36756003)(36860700001)(83380400001)(478600001)(6666004)(336012)(1076003)(40480700001)(2616005)(16526019)(82740400003)(26005)(40460700003)(86362001)(186003)(82310400005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Jan 2023 03:10:30.9485 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5b04732b-8283-42d7-ac3c-08daf38165d3 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT017.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5718 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Abner Chang Changes to allow reading blocks that greater than 65535 sectors. Signed-off-by: Jiangang He Cc: Hao A Wu Cc: Ray Ni Cc: Garrett Kirkendall Cc: Abner Chang Cc: Kuei-Hung Lin Reviewed-by: Hao A Wu --- 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/U= sb/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. =20 Copyright (c) 1999 - 2018, Intel Corporation. All rights reserved.
+Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
=20 SPDX-License-Identifier: BSD-2-Clause-Patent =20 @@ -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; =20 // // prepare command packet for the Inquiry Packet Command. @@ -401,16 +402,13 @@ PeiUsbRead10 ( =20 BlockSize =3D (UINT32)PeiBotDevice->Media.BlockSize; =20 - MaxBlock =3D (UINT16)(65535 / BlockSize); - BlocksRemaining =3D (UINT16)NumberOfBlocks; + MaxBlock =3D (UINT16)(MAX_UINT16 / BlockSize); + ASSERT (NumberOfBlocks < MAX_UINT32); + BlocksRemaining =3D (UINT32)NumberOfBlocks; =20 Status =3D EFI_SUCCESS; while (BlocksRemaining > 0) { - if (BlocksRemaining <=3D MaxBlock) { - SectorCount =3D BlocksRemaining; - } else { - SectorCount =3D MaxBlock; - } + SectorCount =3D MIN (BlocksRemaining, MaxBlock); =20 // // fill the Packet data structure @@ -435,7 +433,7 @@ PeiUsbRead10 ( =20 ByteCount =3D SectorCount * BlockSize; =20 - TimeOut =3D (UINT16)(SectorCount * 2000); + TimeOut =3D SectorCount * 2000; =20 // // send command packet @@ -448,16 +446,17 @@ PeiUsbRead10 ( (VOID *)PtrBuffer, ByteCount, EfiUsbDataIn, - TimeOut + (UINT16)MIN (TimeOut, MAX_UINT16) ); =20 if (Status !=3D EFI_SUCCESS) { return Status; } =20 + ASSERT (Lba32 <=3D (MAX_UINT32-SectorCount)); Lba32 +=3D SectorCount; PtrBuffer =3D (UINT8 *)PtrBuffer + SectorCount * BlockSize; - BlocksRemaining =3D (UINT16)(BlocksRemaining - SectorCount); + BlocksRemaining =3D BlocksRemaining - SectorCount; } =20 return Status; --=20 2.37.1.windows.1