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.24; helo=mga09.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (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 E834E21A07A82 for ; Wed, 10 Oct 2018 01:12:42 -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 orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Oct 2018 01:12:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,363,1534834800"; d="scan'208";a="80236669" Received: from fmsmsx108.amr.corp.intel.com ([10.18.124.206]) by orsmga008.jf.intel.com with ESMTP; 10 Oct 2018 01:09:30 -0700 Received: from fmsmsx118.amr.corp.intel.com (10.18.116.18) by FMSMSX108.amr.corp.intel.com (10.18.124.206) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 10 Oct 2018 01:09:30 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx118.amr.corp.intel.com (10.18.116.18) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 10 Oct 2018 01:09:30 -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:08:38 +0800 From: "Zeng, Star" To: Ard Biesheuvel , "edk2-devel@lists.01.org" CC: "Ni, Ruiyu" , "Zeng, Star" Thread-Topic: [edk2] [PATCH] MdeModulePkg/NonDiscoverablePciDeviceDxe: expose unique B/D/F identifiers Thread-Index: AQHUX9ikfxQxVNOzr0Kj43B6FVFNc6UYIE2w Date: Wed, 10 Oct 2018 08:08:38 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BC16DE7@shsmsx102.ccr.corp.intel.com> References: <20181009140128.21378-1-ard.biesheuvel@linaro.org> In-Reply-To: <20181009140128.21378-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] 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:12:43 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Two minor comments. 1. Is it better to initialize mUniqueIdCounter to 0? 2. With this patch, the Bus value returned may be > 0xFF, right? Should the= code restrict the Bus value to be <=3D 0xFF? Thanks, Star -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Ard = Biesheuvel Sent: Tuesday, October 9, 2018 10:01 PM To: edk2-devel@lists.01.org Cc: Ni, Ruiyu ; Zeng, Star Subject: [edk2] [PATCH] MdeModulePkg/NonDiscoverablePciDeviceDxe: expose un= ique 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 --- MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceD= xe.c | 4 ++++ MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceI= o.c | 10 +++++++--- MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceI= o.h | 6 ++++++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceDxe.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisc= overablePciDeviceDxe.c index 3e9ff6620d8d..ed5256f3c7ea 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceDxe.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceDxe.c @@ -18,6 +18,8 @@ =20 EFI_CPU_ARCH_PROTOCOL *mCpu; =20 +STATIC UINTN mUniqueIdCounter; + // // We only support the following device types // @@ -167,6 +169,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.17.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel