From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by mx.groups.io with SMTP id smtpd.web11.3691.1590059815523434448 for ; Thu, 21 May 2020 04:16:55 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@nuviainc-com.20150623.gappssmtp.com header.s=20150623 header.b=kAJBeA4T; spf=pass (domain: nuviainc.com, ip: 209.85.221.65, mailfrom: leif@nuviainc.com) Received: by mail-wr1-f65.google.com with SMTP id x14so902430wrp.2 for ; Thu, 21 May 2020 04:16:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nuviainc-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=gcxQ14VmQ7Lg5ADiG7SZtUfpo1QsRXD5S+bRtp/zPlQ=; b=kAJBeA4TDNzl8mb2GF3C18FBdyAM6oCibgQLo8hP9/HKDFE5BMa5rm2k4jeGF1TRGY VDAPSkETP29NLyrOOJVieqGXP3jDm+pwIFchmU+d9wCTzglJLrE8bOZ6ubRtxcjV/f+s Rlg8FSatbGAUNOVQgyw+8g3waE8hc/fcd2aTDKA2CHy54TVMAdwG05Mo/mwOKy4c6IFc EAQUROZ16cZzi5YCbAFVI4hCDZr1GSMZkZephrCMa9pSpDf4lP4elB5M7aagySqY9gt0 E2kGJhrRN8jUJqo+lRiUpbyv9FNSsC7YK9rfkSN3NOSlbYCisfHPS49BIzeoI49Y0BvP pgnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=gcxQ14VmQ7Lg5ADiG7SZtUfpo1QsRXD5S+bRtp/zPlQ=; b=JmGvkpxBd81vmXt6iPhM6nMKKNBkjGCOCLpEL4uQw6E/19r3OGQ9CYk4dhtccyAf+V 0cbxDk2NflmmGWGF2Zgp7jlJD59yKTNznWqOrSisdXYFW/WzOqcUyq0/iWLNa0HvGiIP yse7biNrFWw55PfOaChoqWpZOrFSIv0Sz/R6Q/p9ajXW1z0VGKrinv1FVSpUtz18PGAi R1uj8L5MgnZB9Mctv2X26cARF6XX8PLKJVvfRRUp8a1IE1KFkH+qxFmBM3gwT6IH1iWC krEeOJbFjgrRM91qsnkRgtb8a9VxINmSOYZEDkw586gQoLz8O7oN7MwhAbNnoLDLs6li Hikg== X-Gm-Message-State: AOAM531CfNPQlLcSm9gtyq3W7VeuP7s1xcyhoPXtHDLwFw6HUrrMvYaS zhoNvYPlybGcGiN1C//EO+8T2A== X-Google-Smtp-Source: ABdhPJxCPieHfgnbeEdsuTmrBKVCfCaUjBUYkRyJ9TyxlyXclQ69PPijmZkZMCrmaTaNierANe1ELQ== X-Received: by 2002:adf:a35c:: with SMTP id d28mr7704352wrb.37.1590059814044; Thu, 21 May 2020 04:16:54 -0700 (PDT) Return-Path: Received: from vanye ([2001:470:1f09:12f0:b26e:bfff:fea9:f1b8]) by smtp.gmail.com with ESMTPSA id w9sm6383902wrc.27.2020.05.21.04.16.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 May 2020 04:16:53 -0700 (PDT) Date: Thu, 21 May 2020 12:16:51 +0100 From: "Leif Lindholm" To: Ard Biesheuvel Cc: devel@edk2.groups.io, liming.gao@intel.com, lersek@redhat.com, Hao A Wu , Ray Ni Subject: Re: [PATCH] MdeModulePkg/NonDiscoverablePciDeviceDxe: connect handles on registration Message-ID: <20200521111651.GR1923@vanye> References: <20200521111028.25864-1-ard.biesheuvel@arm.com> MIME-Version: 1.0 In-Reply-To: <20200521111028.25864-1-ard.biesheuvel@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Thu, May 21, 2020 at 13:10:28 +0200, Ard Biesheuvel wrote: > 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/NonDiscoverablePciDeviceDxe.c | 43 ++++++++++++++++++++ > 1 file changed, 43 insertions(+) > > diff --git a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c > index 5c93e2a7663c..a14c06e7f4e1 100644 > --- a/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c > +++ b/MdeModulePkg/Bus/Pci/NonDiscoverablePciDeviceDxe/NonDiscoverablePciDeviceDxe.c > @@ -15,6 +15,8 @@ > STATIC UINTN mUniqueIdCounter = 0; > EFI_CPU_ARCH_PROTOCOL *mCpu; > > +STATIC VOID *mProtocolNotifyRegistration; > + > // > // We only support the following device types > // > @@ -250,6 +252,43 @@ STATIC EFI_DRIVER_BINDING_PROTOCOL gDriverBinding = { > NULL > }; > > +STATIC > +VOID > +EFIAPI > +NonDiscoverablePciDeviceProtocolNotify ( > + IN EFI_EVENT Event, > + IN VOID *Context > + ) > +{ > + EFI_STATUS Status; > + EFI_HANDLE *Handles; > + UINTN HandleCount; > + UINTN Index; > + > + Status = gBS->LocateHandleBuffer (ByRegisterNotify, NULL, > + mProtocolNotifyRegistration, &HandleCount, &Handles); > + if (EFI_ERROR (Status)) { > + if (Status != EFI_NOT_FOUND) { > + DEBUG ((DEBUG_WARN, "%a: LocateHandleBuffer() failed - %r\n", > + __FUNCTION__, Status)); > + } > + return; > + } > + > + for (Index = 0; Index < HandleCount; Index++) { > + // > + // Connect each newly registered gEdkiiNonDiscoverableDeviceProtocolGuid > + // 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 = 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. > > @@ -272,6 +311,10 @@ NonDiscoverablePciDeviceDxeEntryPoint ( > Status = gBS->LocateProtocol (&gEfiCpuArchProtocolGuid, NULL, (VOID **)&mCpu); > ASSERT_EFI_ERROR(Status); > > + EfiCreateProtocolNotifyEvent (&gEdkiiNonDiscoverableDeviceProtocolGuid, > + TPL_CALLBACK, NonDiscoverablePciDeviceProtocolNotify, NULL, > + &mProtocolNotifyRegistration); > + > return EfiLibInstallDriverBindingComponentName2 ( > ImageHandle, > SystemTable, > -- > 2.17.1 >