From nobody Fri Apr 26 01:38:11 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+60022+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60022+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1590059467; cv=none; d=zohomail.com; s=zohoarc; b=b+U7XozMXDrts8/xPyENWsVAbaq9leEmR16pKzUxTRXWvTHdyAst9SNCVseYtdMe79Yz9ab9hnyQE6yiU9Znc6imweZGayNRUZBxNFGS0DpvWSnFvljSS1c8eUoirRl9DrWtkg81Mzg6rDMThOjf47fDtrkHEgCEfU061+tuF8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1590059467; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=04qdVtUSKVvjAhHmMNOQl/cJLMw74rqH0DvlQ1plhVk=; b=EXd+Cj6DTKSLg3fsWjzEtd5yHpR2rikKdQ3tGL7nseN1yKNxJEbWjxEOrQe5vbHkNXo8TGaRrfhtwpMl/8U0mYKFl8HV+L9bhIyesMA3KfFstBH6t4ojgFSV3kyjKYQ0qZfOYYyRAORAyN//5lAJK1Tv3dQVc8ty40PMdhAIEBE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60022+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1590059467308113.53605612543709; Thu, 21 May 2020 04:11:07 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 14s1YY1788612xxbRQxKlwfC; Thu, 21 May 2020 04:11:07 -0700 X-Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web10.3569.1590059465860138018 for ; Thu, 21 May 2020 04:11:06 -0700 X-Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6A92A30E; Thu, 21 May 2020 04:11:04 -0700 (PDT) X-Received: from e123331-lin.nice.arm.com (unknown [10.37.8.250]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 8C9D83F68F; Thu, 21 May 2020 04:11:02 -0700 (PDT) From: "Ard Biesheuvel" To: devel@edk2.groups.io Cc: liming.gao@intel.com, leif@nuviainc.com, lersek@redhat.com, Ard Biesheuvel , Hao A Wu , Ray Ni Subject: [edk2-devel] [PATCH] MdeModulePkg/NonDiscoverablePciDeviceDxe: connect handles on registration Date: Thu, 21 May 2020 13:10:28 +0200 Message-Id: <20200521111028.25864-1-ard.biesheuvel@arm.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,ard.biesheuvel@arm.com X-Gm-Message-State: A5pJ9KvG41ttRYn4viZnnxA5x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1590059467; bh=1T8Q27cTImrXY/OXxyg8BJhl43M6EM8O3+qFQENeCe4=; h=Cc:Date:From:Reply-To:Subject:To; b=P/dKMqDQUPq1rZP+X1PYPsuQSk5o5IoDib1I/kRTUMRT0hPQ9QZjVNRzlfE3j0p2t3X MxmR3XF2pjKwwMtvM3CrWpVJ0O7d+SlunpDTg9PkQzzgQb9s+xPyTyovwgmXnj1BRhaW3 C/Bk/Q0bVuMVb5EMafYZLhm/ng4mBdSHCCI= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The way EDK2 invokes the UEFI driver model assumes that PCI I/O protocol instances exist for all PCI I/O controllers in the system. For instance, UefiBootManagerLib connects the short-form USB device path of the console input by looking for PCI I/O controllers that have the 'USB host controller' class code, and passing each one to ConnectController(), using the device path as the 'RemainingDevicePath' argument. For true PCI I/O protocol instances produced by the PCI root bridge driver, this works fine, since it always enumerates the PCIe hierarchy exhaustively. However, for platform devices that are wired to PCI class drivers using the non-discoverable PCIe driver, this breaks down, due to the fact that the PCI I/O protocol instance does not exist unless the non-discoverable device protocol handle is connected first. So let's connect these handles non-recursively as soon as they appear. Cc: Hao A Wu Cc: Ray Ni Signed-off-by: Ard Biesheuvel Acked-by: Leif Lindholm --- MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceD= xe.c | 43 ++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverab= lePciDeviceDxe.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDisc= overablePciDeviceDxe.c index 5c93e2a7663c..a14c06e7f4e1 100644 --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceDxe.c +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDe= viceDxe.c @@ -15,6 +15,8 @@ STATIC UINTN mUniqueIdCounter =3D 0; EFI_CPU_ARCH_PROTOCOL *mCpu; =20 +STATIC VOID *mProtocolNotifyRegistration; + // // We only support the following device types // @@ -250,6 +252,43 @@ STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding =3D { NULL }; =20 +STATIC +VOID +EFIAPI +NonDiscoverablePciDeviceProtocolNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + EFI_HANDLE *Handles; + UINTN HandleCount; + UINTN Index; + + Status =3D gBS->LocateHandleBuffer (ByRegisterNotify, NULL, + mProtocolNotifyRegistration, &HandleCount, &Handles); + if (EFI_ERROR (Status)) { + if (Status !=3D EFI_NOT_FOUND) { + DEBUG ((DEBUG_WARN, "%a: LocateHandleBuffer() failed - %r\n", + __FUNCTION__, Status)); + } + return; + } + + for (Index =3D 0; Index < HandleCount; Index++) { + // + // Connect each newly registered gEdkiiNonDiscoverableDeviceProtocolGu= id + // instance non-recursively to this driver specifically. This ensures = that + // PCI I/O instances exist for each, regardless of whether ConnectAll(= ) is + // used at any point. + // + Status =3D gBS->ConnectController (Handles[Index], gImageHandle, NULL,= FALSE); + DEBUG ((DEBUG_VERBOSE, "%a: ConnectController () returned %r\n", + __FUNCTION__, Status)); + } + gBS->FreePool (Handles); +} + /** Entry point of this driver. =20 @@ -272,6 +311,10 @@ NonDiscoverablePciDeviceDxeEntryPoint ( Status =3D gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **= )&mCpu); ASSERT_EFI_ERROR(Status); =20 + EfiCreateProtocolNotifyEvent (&gEdkiiNonDiscoverableDeviceProtocolGuid, + TPL_CALLBACK, NonDiscoverablePciDeviceProtocolNotify, NULL, + &mProtocolNotifyRegistration); + return EfiLibInstallDriverBindingComponentName2 ( ImageHandle, SystemTable, --=20 2.17.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#60022): https://edk2.groups.io/g/devel/message/60022 Mute This Topic: https://groups.io/mt/74372159/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-