From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by mx.groups.io with SMTP id smtpd.web09.9821.1609738449737906525 for ; Sun, 03 Jan 2021 21:34:10 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=zDj8yhAz; spf=pass (domain: intel.com, ip: 134.134.136.126, mailfrom: ray.ni@intel.com) IronPort-SDR: AkKi0Mh2mUmo6YM14KntxMr9nqg0EYx0BSNYIfsljlTA5oxeUvrT15FkrXLUcMEOsvv50/5MVt HkPrsCPpjhjQ== X-IronPort-AV: E=McAfee;i="6000,8403,9853"; a="164618340" X-IronPort-AV: E=Sophos;i="5.78,473,1599548400"; d="scan'208";a="164618340" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jan 2021 21:34:08 -0800 IronPort-SDR: yv2/yt3LBKfCLkp0GxkEUvBwUubfatSaB/fsmCoudf6Nm3S9B1kJU39o5Ltdx9wn0Yxsvaeb9n 8rvI5mreEGVw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,473,1599548400"; d="scan'208";a="349768002" Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by fmsmga008.fm.intel.com with ESMTP; 03 Jan 2021 21:34:07 -0800 Received: from orsmsx606.amr.corp.intel.com (10.22.229.19) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5; Sun, 3 Jan 2021 21:34:07 -0800 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx606.amr.corp.intel.com (10.22.229.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1713.5 via Frontend Transport; Sun, 3 Jan 2021 21:34:07 -0800 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (104.47.70.103) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.1713.5; Sun, 3 Jan 2021 21:34:06 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HLsFuzxI9oObDMoM5wIImZTCzrbqeXiX+E9suNI2YnhiOA4xT3Ei9lxhVM/Nwpx3caJ8RRL1EYjipEctd3Q3Mf1Rg5Iz95clDQVztkItlWvoiAkM9W1YEqZ0nnnaRCWE9jZaATIkHr5qGLa5tASlCNTTS2nGC8nbr7K6JS74yrRnBp3jE3i5D5vGyL4stUcDcOGAbVxQexOxh+6EMh/bl3Un7GzO17D+q1WgZDBdCxodtLvcWTuMJUJdMhEuo3QQpTs76p36l13He1y6OXDEWJL1ODSDb9y9Fi4MU470BHezoBqo9yBE3Rak7HNPaop36oFPwgSvMw92rWHxxK+hew== 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-SenderADCheck; bh=9d/vcbMUH/mN6f33nslp7cEeOGRWf2rsA2wfj45IDQ4=; b=OkwB1hKpnxvtojPuvHxggVSnYVTiYHZp8iJO3tS/k0we92ImgcJ/YJjyIQX6wUaRSZOorFYDs33iu11CVXsE0sjIlUsk9GSEhNqY68+8ZBV6HAuvhUXfl9NLwL56BNmm0WVTSk8sWuW3dFh6afVsVtbzqkeIsBgfCo31NLihONt6lA5GUXlHGJnNCJFsLMgXOfk5LBOjqu4jJUBthExcuULyIaN1mn7H3+9tBKj+mRMlgZx7lLwFWDGx5JGKU/CdCEn7b7mBRWuruVz7yaw34uXk5tkF2TtOekfxkwmeCCbkCjIlasHjVlyQnCyFg3EWrwz1KMK5fJ5xXkckexENCQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9d/vcbMUH/mN6f33nslp7cEeOGRWf2rsA2wfj45IDQ4=; b=zDj8yhAzXdF/WDmsBwhF20p1dkcai8/pzxJlFHjs2NT6JfjUHjhipM/FTt2kk8kCQRIIIMSp2LC6b7OXNfPC3xDvE4DkYEdNHgkXAYxal1eQIBT6FmiVkhj8AOpu0ra7cLvHhwzV3IkGrn+Xnik6Ifny2uq+URwMdQY9MnAZsq4= Received: from CO1PR11MB4930.namprd11.prod.outlook.com (2603:10b6:303:9b::11) by MWHPR11MB1936.namprd11.prod.outlook.com (2603:10b6:300:111::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.20; Mon, 4 Jan 2021 05:34:05 +0000 Received: from CO1PR11MB4930.namprd11.prod.outlook.com ([fe80::d18:1234:c1d6:5936]) by CO1PR11MB4930.namprd11.prod.outlook.com ([fe80::d18:1234:c1d6:5936%7]) with mapi id 15.20.3721.024; Mon, 4 Jan 2021 05:34:05 +0000 From: "Ni, Ray" To: "devel@edk2.groups.io" , "Luo, Heng" CC: "Wu, Hao A" Subject: Re: [edk2-devel] [PATCH 2/2] MdeModulePkg/Bus/Pci/PciBusDxe: Support PCIe Resizable BAR Capability Thread-Topic: [edk2-devel] [PATCH 2/2] MdeModulePkg/Bus/Pci/PciBusDxe: Support PCIe Resizable BAR Capability Thread-Index: AQHW3PNPbh9kR2eWT0e/jmP2ksOOk6oW9CuQ Date: Mon, 4 Jan 2021 05:34:05 +0000 Message-ID: References: <20201228082610.2565-1-heng.luo@intel.com> <20201228082610.2565-2-heng.luo@intel.com> In-Reply-To: <20201228082610.2565-2-heng.luo@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.194] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: d67d7658-bdd1-4fc1-5f28-08d8b07259c5 x-ms-traffictypediagnostic: MWHPR11MB1936: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: mYRtCVmIxxnOxo8+j2JmA3fszCXlkXoL0AgyitLm+kOEdmesn1kmpceXlXH7aKWHFDKR2DwracHO5QhYz6Z35JELsJ1JlEcHG/BBMgQEH9qYZ4Rd4Fpr8jQCPIcoijDoRDzWocDPKqq0iSZqDODjdhjKprhEQ4/AnAnTywDnt6+YekH07+2eLLrWoXCh0ZJe4xzgIHEINtewBHSJCTR7KGDnJ9ZkSSNL9t8vPQEk/H75HIPKikItpHM8BTuH+YRwWPzqnfXyqv571dSyThsBkyGDw80lJqWmaEtTMUrc/kEKVgUKsqDT9iYdIYpBhzix2js0X0byroaKHeadGl/Kh0qQS6wrCKwi8/EXTeBXzmntUiYt48fhFjWdvqsN1/NCSnWRI+Snnxi1O/orz/+2nsg9NM/Zdsc2f11qLqVNm5NUcNTmRAu1+wut1GoaRC5LTO2f2DHMp8X6g1HwYbyK3A== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CO1PR11MB4930.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(39860400002)(136003)(346002)(366004)(396003)(55016002)(9686003)(83380400001)(8936002)(316002)(107886003)(966005)(110136005)(478600001)(7696005)(76116006)(66946007)(52536014)(30864003)(4326008)(8676002)(33656002)(2906002)(66476007)(86362001)(5660300002)(66446008)(64756008)(66556008)(6636002)(26005)(6506007)(53546011)(186003)(71200400001)(579004);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: =?us-ascii?Q?+IxnTbjE6/WfFkexHKnuOpdYtC3ILAZfAC5Zwu9LuqQMlG1YkHJro5C4JPEA?= =?us-ascii?Q?frXIecE2JiPZEbxqXsgmfe6/wF/l4AN/wiDfXIt6eoKqT6DAU4hnUyxyvfMl?= =?us-ascii?Q?P0GEr9/Pq53j2kNjgtVtOBDpN4V9CBJVRYMhjtDFSPm4Fa+bRHPUIUYFrLay?= =?us-ascii?Q?8GXkep8jG9UJyD58D1fEj1moyecZEd7Y1FbwoTy6f/Nwbw3sTzkyWJpsrVjJ?= =?us-ascii?Q?Q1gd5bUHNyQj4DtnChSKWWPz4h1uDgkDfyHy5ce+ovHOc1xX1pLC10r8zTbf?= =?us-ascii?Q?RNbLDkMrka9uZknMIN0sSeuce/z4kLLCLgMOhypA2ea7XJ1JlTZkb/4BEBye?= =?us-ascii?Q?3d5+l0NSg7s51QuY2x/MibqjtF3hMjrJkJqiPe4X+pfBhIHcz1fK87QrczG6?= =?us-ascii?Q?6CZ55zDoRS0EtnzsRAzZuntN0SAfXfC44Q0ybgOcwrJkjCLGPk7y0Q+Qve9u?= =?us-ascii?Q?wVoCh2DEbmzYrLtC26upgZxi6tiKvVHPcbSTOrcZ2R0VVkCUnHJRTN1pXskW?= =?us-ascii?Q?gToF+UgF4Ihs7L7MvKbIa9C2XoPqM1eiJ4iYFfrP/Bwy3wmBYQuBIqHx8Ssa?= =?us-ascii?Q?FoiDTq2weIIwgHV+RtgnSd9Y98ioIh50ZBxvHNZGF+F9jouXyV4gWbKEfqGP?= =?us-ascii?Q?KGUZDz//+ALNA1yY6WosuBybnZfghzHiBI2FpsOS731GztoytWvSCOrsNaBj?= =?us-ascii?Q?J1niSujdB9UZUIEWM+Hg95tPXT8W9ki4D35wmSABWAk8DoMxMSBu2ffYXrq/?= =?us-ascii?Q?Megu1fY7Vc0qYWmvyW0FBNSf4FnBiDJ0VCwpHPnR/kUFyJLdOBNrX/Y8lVsE?= =?us-ascii?Q?XQdZ1qzczgFsJiNviOWyStAMzWj352L2AlnaFD0E4k2zJz4xMvgVfkUXYGwi?= =?us-ascii?Q?sVTXLaolZQTBvFTgfVdfaTdlIoEF6+K3vbgxNJ4DHnxok5Azcacta8XrnRNn?= =?us-ascii?Q?H+l8mkA/qOQshg0pT8aQxIuupBqnPnMwSCkQujQhFsM=3D?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: CO1PR11MB4930.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d67d7658-bdd1-4fc1-5f28-08d8b07259c5 X-MS-Exchange-CrossTenant-originalarrivaltime: 04 Jan 2021 05:34:05.0378 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: ft+QrdBBfr/0sEsug1wzIvYMbnlzhG7YUPNULfqaQUqar7JQW9xfueZKHExiseRfh8e+51HB8Xo22DKSjedEeg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR11MB1936 Return-Path: ray.ni@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable 1. PcdPcieResizableBarCapabilitySupport: can you rename to PcdPcieResizable= BarSupport? I understand your name is more precise but it's a bit long.:) 2. =20 // // Try to adjust the Devices' BAR size to minimum value in first loop // if enabling PCIe Resizable BAR Capability support. // call PciHostBridgeAdjustAllocation() only if BAR size is not adjus= t. // --> // // When resource conflict happens, adjust the BAR size first. // Only when adjusting BAR size doesn't help or BAR size cannot be adj= usted, // reject the device who requests largest resource that causes conflic= t. // 3. PCI_RESIZEABLE_BAR_CAP: Can you please rename the type to PCI_RESIZABLE_= BAR_OPERATION? Similar comments to ResizableBarCap. Can you please rename to Resizable= BarOp? 4. Capabilities =3D Entries[BarIndex].ResizableBarControl.Bits.BarSizeCapab= ility << 28 | Entries[BarIndex].ResizableBarCapability.Bits.BarSizeCa= pability; You need to use LShiftU64() 5. Entries[BarIndex].ResizableBarControl.Bits.BarIndex I suggest you rename BarIndex to Index. Because it can avoid confusion. So = the above code will be: Entries[Index].ResizableBarControl.Bits.BarIndex Thanks, Ray > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Heng Luo > Sent: Monday, December 28, 2020 4:26 PM > To: devel@edk2.groups.io > Cc: Ni, Ray ; Wu, Hao A > Subject: [edk2-devel] [PATCH 2/2] MdeModulePkg/Bus/Pci/PciBusDxe: Support > PCIe Resizable BAR Capability >=20 > REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D313 >=20 > Add PcdPcieResizableBarCapabilitySupport to enable/disable PCIe Resizable > BAR Capability fearture. > Program the Resizable BAR Register if the device suports PCIe Resizable > BAR Capability and PcdPcieResizableBarCapabilitySupport is TRUE. >=20 > Cc: Ray Ni > Cc: Hao A Wu > Signed-off-by: Heng Luo > --- > MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h | 4 +++- > MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf | 3 ++- > MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c | 27 > ++++++++++++++++++++++++++- > MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.h | 12 > +++++++++++- > MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c | 185 > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ > +++++++++++++++++++++++++++++++++++++++++++-------------- > MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.h | 22 > +++++++++++++++++++++- > MdeModulePkg/MdeModulePkg.dec | 6 ++++++ > 7 files changed, 240 insertions(+), 19 deletions(-) >=20 > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > index d4113993c8..add1756d5c 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBus.h > @@ -1,7 +1,7 @@ > /** @file >=20 > Header files and data structures needed by PCI Bus module. >=20 >=20 >=20 > -Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 > @@ -280,6 +280,8 @@ struct _PCI_IO_DEVICE { > // This field is used to support this case. >=20 > // >=20 > UINT16 BridgeIoAlignment; >=20 > + UINT32 ResizableBarOffset; >=20 > + UINT32 ResizableBarNumber; >=20 > }; >=20 >=20 >=20 > #define PCI_IO_DEVICE_FROM_PCI_IO_THIS(a) \ >=20 > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf > index 9284998f36..b3e5213b92 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf > @@ -2,7 +2,7 @@ > # The PCI bus driver will probe all PCI devices and allocate MMIO and I= O > space for these devices. >=20 > # Please use PCD feature flag PcdPciBusHotplugDeviceSupport to enable h= ot > plug supporting. >=20 > # >=20 > -# Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved. >=20 > +# Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved. >=20 > # >=20 > # SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > # >=20 > @@ -106,6 +106,7 @@ > gEfiMdeModulePkgTokenSpaceGuid.PcdAriSupport ## CONSU= MES >=20 > gEfiMdeModulePkgTokenSpaceGuid.PcdMrIovSupport ## > CONSUMES >=20 > gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration ## > SOMETIMES_CONSUMES >=20 > + gEfiMdeModulePkgTokenSpaceGuid.PcdPcieResizableBarCapabilitySupport > ## CONSUMES >=20 >=20 >=20 > [UserExtensions.TianoCore."ExtraFiles"] >=20 > PciBusDxeExtra.uni >=20 > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c > index 6c68a97d4e..d1d38241da 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.c > @@ -1,7 +1,7 @@ > /** @file >=20 > PCI emumeration support functions implementation for PCI Bus module. >=20 >=20 >=20 > -Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
>=20 > (C) Copyright 2015 Hewlett Packard Enterprise Development LP
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > @@ -2426,6 +2426,31 @@ CreatePciIoDevice ( > } >=20 > } >=20 >=20 >=20 > + PciIoDevice->ResizableBarOffset =3D 0; >=20 > + if (PcdGetBool (PcdPcieResizableBarCapabilitySupport)) { >=20 > + Status =3D LocatePciExpressCapabilityRegBlock ( >=20 > + PciIoDevice, >=20 > + PCI_EXPRESS_EXTENDED_CAPABILITY_RESIZABLE_BAR_ID, >=20 > + &PciIoDevice->ResizableBarOffset, >=20 > + NULL >=20 > + ); >=20 > + if (!EFI_ERROR (Status)) { >=20 > + PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_CONTROL > ResizableBarControl; >=20 > + UINT32 Offset; >=20 > + Offset =3D PciIoDevice->ResizableBarOffset + sizeof > (PCI_EXPRESS_EXTENDED_CAPABILITIES_HEADER) >=20 > + + sizeof > (PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_CAPABILITY), >=20 > + PciIo->Pci.Read ( >=20 > + PciIo, >=20 > + EfiPciIoWidthUint8, >=20 > + Offset, >=20 > + sizeof > (PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_CONTROL), >=20 > + &ResizableBarControl >=20 > + ); >=20 > + PciIoDevice->ResizableBarNumber =3D > ResizableBarControl.Bits.ResizableBarNumber; >=20 > + PciProgramResizableBar (PciIoDevice, PciResizableBarMax); >=20 > + } >=20 > + } >=20 > + >=20 > // >=20 > // Initialize the reserved resource list >=20 > // >=20 > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.h > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.h > index d76606c7df..919d678e2f 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.h > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciEnumeratorSupport.h > @@ -1,7 +1,7 @@ > /** @file >=20 > PCI enumeration support functions declaration for PCI Bus module. >=20 >=20 >=20 > -Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 > @@ -467,4 +467,14 @@ DumpPpbPaddingResource ( > IN PCI_BAR_TYPE ResourceType >=20 > ); >=20 >=20 >=20 > +/** >=20 > + Dump the PCI BAR information. >=20 > + >=20 > + @param PciIoDevice PCI IO instance. >=20 > +**/ >=20 > +VOID >=20 > +DumpPciBars ( >=20 > + IN PCI_IO_DEVICE *PciIoDevice >=20 > + ); >=20 > + >=20 > #endif >=20 > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c > index 72690ab647..1a7ddb4455 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c > @@ -1,7 +1,7 @@ > /** @file >=20 > Internal library implementation for PCI Bus module. >=20 >=20 >=20 > -Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
>=20 > (C) Copyright 2015 Hewlett Packard Enterprise Development LP
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > @@ -377,6 +377,60 @@ DumpResourceMap ( > } >=20 > } >=20 >=20 >=20 > +/** >=20 > + Adjust the Devices' BAR size to minimum value if it support Resizeable= BAR > capability. >=20 > + >=20 > + @param RootBridgeDev Pointer to instance of PCI_IO_DEVICE.. >=20 > + >=20 > + @return TRUE if BAR size is adjusted. >=20 > + >=20 > +**/ >=20 > +BOOLEAN >=20 > +AdjustPciDeviceBarSize ( >=20 > + IN PCI_IO_DEVICE *RootBridgeDev >=20 > + ) >=20 > +{ >=20 > + PCI_IO_DEVICE *PciIoDevice; >=20 > + LIST_ENTRY *CurrentLink; >=20 > + BOOLEAN Adjusted; >=20 > + UINTN Offset; >=20 > + UINTN BarIndex; >=20 > + >=20 > + Adjusted =3D FALSE; >=20 > + CurrentLink =3D RootBridgeDev->ChildList.ForwardLink; >=20 > + >=20 > + while (CurrentLink !=3D NULL && CurrentLink !=3D &RootBridgeDev->Child= List) { >=20 > + PciIoDevice =3D PCI_IO_DEVICE_FROM_LINK (CurrentLink); >=20 > + >=20 > + if (IS_PCI_BRIDGE (&PciIoDevice->Pci)) { >=20 > + if (AdjustPciDeviceBarSize (PciIoDevice)) { >=20 > + Adjusted =3D TRUE; >=20 > + } >=20 > + } else { >=20 > + if (PciIoDevice->ResizableBarOffset !=3D 0) { >=20 > + DEBUG (( >=20 > + DEBUG_ERROR, >=20 > + "PciBus: [%02x|%02x|%02x] Adjust Pci Device Bar Size\n", >=20 > + PciIoDevice->BusNumber, PciIoDevice->DeviceNumber, PciIoDevice= - > >FunctionNumber >=20 > + )); >=20 > + PciProgramResizableBar (PciIoDevice, PciResizableBarMin); >=20 > + // >=20 > + // Start to parse the bars >=20 > + // >=20 > + for (Offset =3D 0x10, BarIndex =3D 0; Offset <=3D 0x24 && BarInd= ex < > PCI_MAX_BAR; BarIndex++) { >=20 > + Offset =3D PciParseBar (PciIoDevice, Offset, BarIndex); >=20 > + } >=20 > + Adjusted =3D TRUE; >=20 > + DEBUG_CODE (DumpPciBars (PciIoDevice);); >=20 > + } >=20 > + } >=20 > + >=20 > + CurrentLink =3D CurrentLink->ForwardLink; >=20 > + } >=20 > + >=20 > + return Adjusted; >=20 > +} >=20 > + >=20 > /** >=20 > Submits the I/O and memory resource requirements for the specified PCI > Host Bridge. >=20 >=20 >=20 > @@ -422,6 +476,10 @@ PciHostBridgeResourceAllocator ( > PCI_RESOURCE_NODE PMem64Pool; >=20 > EFI_DEVICE_HANDLE_EXTENDED_DATA_PAYLOAD HandleExtendedData; >=20 > EFI_RESOURCE_ALLOC_FAILURE_ERROR_DATA_PAYLOAD > AllocFailExtendedData; >=20 > + BOOLEAN ResizableBarNeedAdjust; >=20 > + BOOLEAN ResizableBarAdjusted; >=20 > + >=20 > + ResizableBarNeedAdjust =3D PcdGetBool > (PcdPcieResizableBarCapabilitySupport); >=20 >=20 >=20 > // >=20 > // It may try several times if the resource allocation fails >=20 > @@ -703,19 +761,30 @@ PciHostBridgeResourceAllocator ( > sizeof (AllocFailExtendedData) >=20 > ); >=20 >=20 >=20 > - Status =3D PciHostBridgeAdjustAllocation ( >=20 > - &IoPool, >=20 > - &Mem32Pool, >=20 > - &PMem32Pool, >=20 > - &Mem64Pool, >=20 > - &PMem64Pool, >=20 > - IoResStatus, >=20 > - Mem32ResStatus, >=20 > - PMem32ResStatus, >=20 > - Mem64ResStatus, >=20 > - PMem64ResStatus >=20 > - ); >=20 > - >=20 > + // >=20 > + // Try to adjust the Devices' BAR size to minimum value in first l= oop >=20 > + // if enabling PCIe Resizable BAR Capability support. >=20 > + // call PciHostBridgeAdjustAllocation() only if BAR size is not ad= just. >=20 > + // >=20 > + ResizableBarAdjusted =3D FALSE; >=20 > + if (ResizableBarNeedAdjust) { >=20 > + ResizableBarAdjusted =3D AdjustPciDeviceBarSize (RootBridgeDev); >=20 > + ResizableBarNeedAdjust =3D FALSE; >=20 > + } >=20 > + if (!ResizableBarAdjusted) { >=20 > + Status =3D PciHostBridgeAdjustAllocation ( >=20 > + &IoPool, >=20 > + &Mem32Pool, >=20 > + &PMem32Pool, >=20 > + &Mem64Pool, >=20 > + &PMem64Pool, >=20 > + IoResStatus, >=20 > + Mem32ResStatus, >=20 > + PMem32ResStatus, >=20 > + Mem64ResStatus, >=20 > + PMem64ResStatus >=20 > + ); >=20 > + } >=20 > // >=20 > // Destroy all the resource tree >=20 > // >=20 > @@ -1651,3 +1720,91 @@ PciHostBridgeEnumerator ( >=20 >=20 > return EFI_SUCCESS; >=20 > } >=20 > + >=20 > +/** >=20 > + This function is used to program the Resizable BAR Register. >=20 > + >=20 > + @param PciIoDevice A pointer to the PCI_IO_DEVICE. >=20 > + @param ResizableBarCap PciResizableBarMax: Set BAR to max size >=20 > + PciResizableBarMin: set BAR to min size. >=20 > + >=20 > + @retval EFI_SUCCESS Successfully enumerated the host bridge. >=20 > + @retval other Some error occurred when enumerating the= host > bridge. >=20 > + >=20 > +**/ >=20 > +EFI_STATUS >=20 > +PciProgramResizableBar ( >=20 > + IN PCI_IO_DEVICE *PciIoDevice, >=20 > + IN PCI_RESIZEABLE_BAR_CAP ResizableBarCap >=20 > + ) >=20 > +{ >=20 > + EFI_PCI_IO_PROTOCOL *PciIo; >=20 > + UINT64 Capabilities; >=20 > + UINT32 BarIndex; >=20 > + UINT32 Offset; >=20 > + INTN Bit; >=20 > + UINTN ResizableBarNumber; >=20 > + EFI_STATUS Status; >=20 > + PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_ENTRY > Entries[PCI_MAX_BAR]; >=20 > + >=20 > + ASSERT (PciIoDevice->ResizableBarOffset !=3D 0); >=20 > + >=20 > + DEBUG ((DEBUG_INFO, " Programs Resizable BAR register, offset: 0x%08= x, > number: %d\n", >=20 > + PciIoDevice->ResizableBarOffset, PciIoDevice->ResizableBarNumber= )); >=20 > + >=20 > + ResizableBarNumber =3D MIN (PciIoDevice->ResizableBarNumber, > PCI_MAX_BAR); >=20 > + PciIo =3D &PciIoDevice->PciIo; >=20 > + Status =3D PciIo->Pci.Read ( >=20 > + PciIo, >=20 > + EfiPciIoWidthUint8, >=20 > + PciIoDevice->ResizableBarOffset + sizeof > (PCI_EXPRESS_EXTENDED_CAPABILITIES_HEADER), >=20 > + sizeof (PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_ENTRY) > * ResizableBarNumber, >=20 > + (VOID *)(&Entries) >=20 > + ); >=20 > + ASSERT_EFI_ERROR (Status); >=20 > + >=20 > + for (BarIndex =3D 0; BarIndex < ResizableBarNumber; BarIndex++) { >=20 > + >=20 > + // >=20 > + // When the bit of Capabilities Set, indicates that the Function sup= ports >=20 > + // operating with the BAR sized to (2^Bit) MB. >=20 > + // Example: >=20 > + // Bit 0 is set: supports operating with the BAR sized to 1 MB >=20 > + // Bit 1 is set: supports operating with the BAR sized to 2 MB >=20 > + // Bit n is set: supports operating with the BAR sized to (2^n) MB >=20 > + // >=20 > + Capabilities =3D Entries[BarIndex].ResizableBarControl.Bits.BarSizeC= apability > << 28 >=20 > + | Entries[BarIndex].ResizableBarCapability.Bits.BarSiz= eCapability; >=20 > + >=20 > + if (ResizableBarCap =3D=3D PciResizableBarMax) { >=20 > + Bit =3D HighBitSet64(Capabilities); >=20 > + } else if (ResizableBarCap =3D=3D PciResizableBarMin) { >=20 > + Bit =3D LowBitSet64(Capabilities); >=20 > + } else { >=20 > + ASSERT ((ResizableBarCap =3D=3D PciResizableBarMax) || (ResizableB= arCap > =3D=3D PciResizableBarMin)); >=20 > + } >=20 > + >=20 > + ASSERT (Bit >=3D 0); >=20 > + >=20 > + Offset =3D PciIoDevice->ResizableBarOffset + sizeof > (PCI_EXPRESS_EXTENDED_CAPABILITIES_HEADER) >=20 > + + BarIndex * sizeof > (PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_ENTRY) >=20 > + + OFFSET_OF > (PCI_EXPRESS_EXTENDED_CAPABILITIES_RESIZABLE_BAR_ENTRY, > ResizableBarControl); >=20 > + >=20 > + Entries[BarIndex].ResizableBarControl.Bits.BarSize =3D (UINT32) Bit; >=20 > + DEBUG (( >=20 > + DEBUG_INFO, >=20 > + " Resizable Bar: Offset =3D 0x%x, Bar Size Capability =3D 0x%016= lx, New Bar > Size =3D 0x%lx\n", >=20 > + OFFSET_OF (PCI_TYPE00, > Device.Bar[Entries[BarIndex].ResizableBarControl.Bits.BarIndex]), >=20 > + Capabilities, LShiftU64 (SIZE_1MB, Bit) >=20 > + )); >=20 > + PciIo->Pci.Write ( >=20 > + PciIo, >=20 > + EfiPciIoWidthUint32, >=20 > + Offset, >=20 > + 1, >=20 > + &Entries[BarIndex].ResizableBarControl.Uint32 >=20 > + ); >=20 > + } >=20 > + >=20 > + return EFI_SUCCESS; >=20 > +} >=20 > diff --git a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.h > b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.h > index 10b435d146..94b20f18e8 100644 > --- a/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.h > +++ b/MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.h > @@ -1,7 +1,7 @@ > /** @file >=20 > Internal library declaration for PCI Bus module. >=20 >=20 >=20 > -Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
>=20 > +Copyright (c) 2006 - 2020, Intel Corporation. All rights reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > **/ >=20 > @@ -24,6 +24,10 @@ typedef struct { > UINT8 *AllocRes; >=20 > } EFI_RESOURCE_ALLOC_FAILURE_ERROR_DATA_PAYLOAD; >=20 >=20 >=20 > +typedef enum { >=20 > + PciResizableBarMin =3D 0x00, >=20 > + PciResizableBarMax =3D 0xFF >=20 > +} PCI_RESIZEABLE_BAR_CAP; >=20 >=20 >=20 > /** >=20 > Retrieve the PCI Card device BAR information via PciIo interface. >=20 > @@ -156,4 +160,20 @@ PciHostBridgeEnumerator ( > IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL > *PciResAlloc >=20 > ); >=20 >=20 >=20 > +/** >=20 > + This function is used to program the Resizable BAR Register. >=20 > + >=20 > + @param PciIoDevice A pointer to the PCI_IO_DEVICE. >=20 > + @param ResizableBarCap PciResizableBarMax: Set BAR to max size >=20 > + PciResizableBarMin: set BAR to min size. >=20 > + >=20 > + @retval EFI_SUCCESS Successfully enumerated the host bridge. >=20 > + @retval other Some error occurred when enumerating the= host > bridge. >=20 > + >=20 > +**/ >=20 > +EFI_STATUS >=20 > +PciProgramResizableBar ( >=20 > + IN PCI_IO_DEVICE *PciIoDevice, >=20 > + IN PCI_RESIZEABLE_BAR_CAP ResizableBarCap >=20 > + ); >=20 > #endif >=20 > diff --git a/MdeModulePkg/MdeModulePkg.dec > b/MdeModulePkg/MdeModulePkg.dec > index 9b52b34494..10c819ee39 100644 > --- a/MdeModulePkg/MdeModulePkg.dec > +++ b/MdeModulePkg/MdeModulePkg.dec > @@ -2043,6 +2043,12 @@ > # @Prompt Enable StatusCode via memory. >=20 >=20 > gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeUseMemory|FALSE|BOOLE > AN|0x00010023 >=20 >=20 >=20 > + ## Indicates if the PCIe Resizable BAR Capability Supported.

>=20 > + # TRUE - PCIe Resizable BAR Capability is supported.
>=20 > + # FALSE - PCIe Resizable BAR Capability is not supported.
>=20 > + # @Prompt Enable PCIe Resizable BAR Capability support. >=20 > + > gEfiMdeModulePkgTokenSpaceGuid.PcdPcieResizableBarCapabilitySupport|TR > UE|BOOLEAN|0x10000024 >=20 > + >=20 > [PcdsPatchableInModule] >=20 > ## Specify memory size with page number for PEI code when >=20 > # Loading Module at Fixed Address feature is enabled. >=20 > -- > 2.24.0.windows.2 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#69478): https://edk2.groups.io/g/devel/message/69478 > Mute This Topic: https://groups.io/mt/79265865/1712937 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [ray.ni@intel.com] > -=3D-=3D-=3D-=3D-=3D-=3D >=20