From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 2A01521A09130 for ; Wed, 10 Oct 2018 01:57:46 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2018 01:57:46 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,363,1534834800"; d="scan'208";a="80250520" Received: from fmsmsx103.amr.corp.intel.com ([10.18.124.201]) by orsmga008.jf.intel.com with ESMTP; 10 Oct 2018 01:55:50 -0700 Received: from fmsmsx156.amr.corp.intel.com (10.18.116.74) by FMSMSX103.amr.corp.intel.com (10.18.124.201) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 10 Oct 2018 01:55:50 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx156.amr.corp.intel.com (10.18.116.74) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 10 Oct 2018 01:55:50 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.217]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.245]) with mapi id 14.03.0319.002; Wed, 10 Oct 2018 16:55:48 +0800 From: "Zeng, Star" To: Ard Biesheuvel , "edk2-devel@lists.01.org" CC: "Zeng, Star" Thread-Topic: [edk2] [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: expose unique B/D/F identifiers Thread-Index: AQHUYHQzKYHZHAegSEeZwKmFC5AbiKUYLDrg Date: Wed, 10 Oct 2018 08:55:47 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BC17EAF@shsmsx102.ccr.corp.intel.com> References: <20181010083450.22298-1-ard.biesheuvel@linaro.org> In-Reply-To: <20181010083450.22298-1-ard.biesheuvel@linaro.org> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: expose unique B/D/F identifiers X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Oct 2018 08:57:47 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Star Zeng -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ard = Biesheuvel Sent: Wednesday, October 10, 2018 4:35 PM To: edk2-devel@lists.01.org Cc: Zeng, Star Subject: [edk2] [PATCH v2] MdeModulePkg/NonDiscoverablePciDeviceDxe: expose= unique B/D/F identifiers Currently, the implementation of EFI_PCI_IO_PROTOCOL::GetLocation() in NonDiscoverablePciDeviceDxe returns the same set of dummy values for each instance of the NON_DISCOVERABLE_DEVICE protocol that it attaches itself to. However, this turns out to be causing problems in cases where software (such as the ARM Compliance Test Suite [ACS]) attempts to use these values to uniquely identify controllers, since the collisions create ambiguity in this regard. So let's modify GetLocation() to return an arbitrary bus/device tuple on segment 0xff instead. This is guaranteed not to clash with other non-discoverable PCI devices, and highly unlikely to clash with real PCIe devices. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel Tested-by: Marcin Wojtas --- v2: add sanity check on id value so we don't exceed 256 buses initialize counter to 0 explicitly - this isn't strictly necessary but = clarifies the code MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceD= xe.c | 10 ++++++++++ MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceI= o.c | 10 +++++++--- MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceI= o.h | 6 ++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceDxe.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisc= overablePciDeviceDxe.c index 3e9ff6620d8d..2483c7296912 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceDxe.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceDxe.c @@ -16,6 +16,9 @@ =20 #include =20 +#define MAX_NON_DISCOVERABLE_PCI_DEVICE_ID (32 * 256) + +STATIC UINTN mUniqueIdCounter =3D 0; EFI_CPU_ARCH_PROTOCOL *mCpu; =20 // @@ -141,6 +144,11 @@ NonDiscoverablePciDeviceStart ( NON_DISCOVERABLE_PCI_DEVICE *Dev; EFI_STATUS Status; =20 + ASSERT (mUniqueIdCounter < MAX_NON_DISCOVERABLE_PCI_DEVICE_ID); + if (mUniqueIdCounter >=3D MAX_NON_DISCOVERABLE_PCI_DEVICE_ID) { + return EFI_OUT_OF_RESOURCES; + } + Dev =3D AllocateZeroPool (sizeof *Dev); if (Dev =3D=3D NULL) { return EFI_OUT_OF_RESOURCES; @@ -167,6 +175,8 @@ NonDiscoverablePciDeviceStart ( goto CloseProtocol; } =20 + Dev->UniqueId =3D mUniqueIdCounter++; + return EFI_SUCCESS; =20 CloseProtocol: diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceIo.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisco= verablePciDeviceIo.c index 0e42ae4bf6ec..58cb5d8b1fc5 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.c @@ -1181,6 +1181,8 @@ PciIoGetLocation ( OUT UINTN *FunctionNumber ) { + NON_DISCOVERABLE_PCI_DEVICE *Dev; + if (SegmentNumber =3D=3D NULL || BusNumber =3D=3D NULL || DeviceNumber =3D=3D NULL || @@ -1188,9 +1190,11 @@ PciIoGetLocation ( return EFI_INVALID_PARAMETER; } =20 - *SegmentNumber =3D 0; - *BusNumber =3D 0xff; - *DeviceNumber =3D 0; + Dev =3D NON_DISCOVERABLE_PCI_DEVICE_FROM_PCI_IO(This); + + *SegmentNumber =3D 0xff; + *BusNumber =3D Dev->UniqueId >> 5; + *DeviceNumber =3D Dev->UniqueId & 0x1f; *FunctionNumber =3D 0; =20 return EFI_SUCCESS; diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceIo.h b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisco= verablePciDeviceIo.h index e641189267ee..5b4c57fa2a8e 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.h +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceIo.h @@ -100,6 +100,12 @@ typedef struct { // on behalf of this device // LIST_ENTRY UncachedAllocationList; + // + // Unique ID for this device instance: needed so that we can report uniq= ue + // segment/bus/device number for each device instance. Note that this nu= mber + // may change when disconnecting/reconnecting the driver. + // + UINTN UniqueId; } NON_DISCOVERABLE_PCI_DEVICE; =20 /** --=20 2.19.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel