From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pm@vger.kernel.org, Keith Busch <keith.busch@intel.com>,
Sinan Kaya <okaya@codeaurora.org>, Lukas Wunner <lukas@wunner.de>
Subject: Re: [PATCH v1 5/9] PCI/portdrv: Remove pcie_port_bus_type link order dependency
Date: Wed, 07 Mar 2018 11:33:48 +0100 [thread overview]
Message-ID: <7571217.yaDH5TzqWC@aspire.rjw.lan> (raw)
In-Reply-To: <152040323121.240786.5383276983544773869.stgit@bhelgaas-glaptop.roam.corp.google.com>
On Wednesday, March 7, 2018 7:13:51 AM CET Bjorn Helgaas wrote:
> From: Bjorn Helgaas <bhelgaas@google.com>
>
> The pcie_port_bus_type must be registered before drivers that depend on it
> can be registered. Those drivers include:
>
> pcied_init() # PCIe native hotplug driver
> aer_service_init() # AER driver
> dpc_service_init() # DPC driver
> pcie_pme_service_init() # PME driver
>
> Previously we registered pcie_port_bus_type from pcie_portdrv_init(), a
> device_initcall. The callers of pcie_port_service_register() (above) are
> also device_initcalls. This is fragile because the device_initcall
> ordering depends on link order, which is not explicit.
>
> Register pcie_port_bus_type from pci_driver_init() along with pci_bus_type.
> This removes the link order dependency between portdrv and the pciehp, AER,
> DPC, and PCIe PME drivers.
>
> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
> ---
> drivers/pci/pci-driver.c | 45 +++++++++++++++++++++++++++++++-
> drivers/pci/pcie/Makefile | 2 +
> drivers/pci/pcie/portdrv_bus.c | 56 ----------------------------------------
> drivers/pci/pcie/portdrv_pci.c | 13 +--------
> 4 files changed, 46 insertions(+), 70 deletions(-)
> delete mode 100644 drivers/pci/pcie/portdrv_bus.c
>
> diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
> index 38ee7c8b4d1a..4db85a0faf34 100644
> --- a/drivers/pci/pci-driver.c
> +++ b/drivers/pci/pci-driver.c
> @@ -7,6 +7,7 @@
> */
>
> #include <linux/pci.h>
> +#include <linux/pcieport_if.h>
> #include <linux/module.h>
> #include <linux/init.h>
> #include <linux/device.h>
> @@ -19,6 +20,7 @@
> #include <linux/suspend.h>
> #include <linux/kexec.h>
> #include "pci.h"
> +#include "pcie/portdrv.h"
>
> struct pci_dynid {
> struct list_head node;
> @@ -1553,8 +1555,49 @@ struct bus_type pci_bus_type = {
> };
> EXPORT_SYMBOL(pci_bus_type);
>
> +#ifdef CONFIG_PCIEPORTBUS
> +static int pcie_port_bus_match(struct device *dev, struct device_driver *drv)
> +{
> + struct pcie_device *pciedev;
> + struct pcie_port_service_driver *driver;
> +
> + if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type)
> + return 0;
> +
> + pciedev = to_pcie_device(dev);
> + driver = to_service_driver(drv);
> +
> + if (driver->service != pciedev->service)
> + return 0;
> +
> + if ((driver->port_type != PCIE_ANY_PORT) &&
> + (driver->port_type != pci_pcie_type(pciedev->port)))
> + return 0;
> +
> + return 1;
> +}
> +
> +struct bus_type pcie_port_bus_type = {
> + .name = "pci_express",
> + .match = pcie_port_bus_match,
> +};
> +EXPORT_SYMBOL_GPL(pcie_port_bus_type);
> +#endif
> +
> static int __init pci_driver_init(void)
> {
> - return bus_register(&pci_bus_type);
> + int ret;
> +
> + ret = bus_register(&pci_bus_type);
> + if (ret)
> + return ret;
> +
> +#ifdef CONFIG_PCIEPORTBUS
> + ret = bus_register(&pcie_port_bus_type);
> + if (ret)
> + return ret;
> +#endif
> +
> + return 0;
> }
> postcore_initcall(pci_driver_init);
> diff --git a/drivers/pci/pcie/Makefile b/drivers/pci/pcie/Makefile
> index 223e4c34c29a..e01c10c97b95 100644
> --- a/drivers/pci/pcie/Makefile
> +++ b/drivers/pci/pcie/Makefile
> @@ -6,7 +6,7 @@
> # Build PCI Express ASPM if needed
> obj-$(CONFIG_PCIEASPM) += aspm.o
>
> -pcieportdrv-y := portdrv_core.o portdrv_pci.o portdrv_bus.o
> +pcieportdrv-y := portdrv_core.o portdrv_pci.o
> pcieportdrv-$(CONFIG_ACPI) += portdrv_acpi.o
>
> obj-$(CONFIG_PCIEPORTBUS) += pcieportdrv.o
> diff --git a/drivers/pci/pcie/portdrv_bus.c b/drivers/pci/pcie/portdrv_bus.c
> deleted file mode 100644
> index f0fba552a0e2..000000000000
> --- a/drivers/pci/pcie/portdrv_bus.c
> +++ /dev/null
> @@ -1,56 +0,0 @@
> -// SPDX-License-Identifier: GPL-2.0
> -/*
> - * File: portdrv_bus.c
> - * Purpose: PCI Express Port Bus Driver's Bus Overloading Functions
> - *
> - * Copyright (C) 2004 Intel
> - * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
> - */
> -
> -#include <linux/module.h>
> -#include <linux/pci.h>
> -#include <linux/kernel.h>
> -#include <linux/errno.h>
> -#include <linux/pm.h>
> -
> -#include <linux/pcieport_if.h>
> -#include "portdrv.h"
> -
> -static int pcie_port_bus_match(struct device *dev, struct device_driver *drv);
> -
> -struct bus_type pcie_port_bus_type = {
> - .name = "pci_express",
> - .match = pcie_port_bus_match,
> -};
> -EXPORT_SYMBOL_GPL(pcie_port_bus_type);
> -
> -static int pcie_port_bus_match(struct device *dev, struct device_driver *drv)
> -{
> - struct pcie_device *pciedev;
> - struct pcie_port_service_driver *driver;
> -
> - if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type)
> - return 0;
> -
> - pciedev = to_pcie_device(dev);
> - driver = to_service_driver(drv);
> -
> - if (driver->service != pciedev->service)
> - return 0;
> -
> - if ((driver->port_type != PCIE_ANY_PORT) &&
> - (driver->port_type != pci_pcie_type(pciedev->port)))
> - return 0;
> -
> - return 1;
> -}
> -
> -int pcie_port_bus_register(void)
> -{
> - return bus_register(&pcie_port_bus_type);
> -}
> -
> -void pcie_port_bus_unregister(void)
> -{
> - bus_unregister(&pcie_port_bus_type);
> -}
> diff --git a/drivers/pci/pcie/portdrv_pci.c b/drivers/pci/pcie/portdrv_pci.c
> index c08ebd237242..9475886eeb62 100644
> --- a/drivers/pci/pcie/portdrv_pci.c
> +++ b/drivers/pci/pcie/portdrv_pci.c
> @@ -259,22 +259,11 @@ static const struct dmi_system_id pcie_portdrv_dmi_table[] __initconst = {
>
> static int __init pcie_portdrv_init(void)
> {
> - int retval;
> -
> if (pcie_ports_disabled)
> return -EACCES;
>
> dmi_check_system(pcie_portdrv_dmi_table);
>
> - retval = pcie_port_bus_register();
> - if (retval) {
> - printk(KERN_WARNING "PCIE: bus_register error: %d\n", retval);
> - goto out;
> - }
> - retval = pci_register_driver(&pcie_portdriver);
> - if (retval)
> - pcie_port_bus_unregister();
> - out:
> - return retval;
> + return pci_register_driver(&pcie_portdriver);
> }
> device_initcall(pcie_portdrv_init);
>
>
Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
next prev parent reply other threads:[~2018-03-07 10:33 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-07 6:13 [PATCH v1 0/9] PCI: Simplify PCIe port driver Bjorn Helgaas
2018-03-07 6:13 ` [PATCH v1 1/9] PCI/PM: Move pcie_clear_root_pme_status() to core Bjorn Helgaas
2018-03-07 10:24 ` Rafael J. Wysocki
2018-03-07 6:13 ` [PATCH v1 2/9] PCI/PM: Clear PCIe PME Status bit in core, not PCIe port driver Bjorn Helgaas
2018-03-07 10:27 ` Rafael J. Wysocki
2018-03-08 8:03 ` Lukas Wunner
2018-03-08 9:13 ` Rafael J. Wysocki
2018-03-07 6:13 ` [PATCH v1 3/9] PCI/PM: Clear PCIe PME Status bit for Root Complex Event Collectors Bjorn Helgaas
2018-03-07 10:27 ` Rafael J. Wysocki
2018-03-07 6:13 ` [PATCH v1 4/9] PCI/portdrv: Disable port driver in compat mode Bjorn Helgaas
2018-03-07 10:29 ` Rafael J. Wysocki
2018-03-07 6:13 ` [PATCH v1 5/9] PCI/portdrv: Remove pcie_port_bus_type link order dependency Bjorn Helgaas
2018-03-07 10:33 ` Rafael J. Wysocki [this message]
2018-03-07 6:13 ` [PATCH v1 6/9] PCI/portdrv: Remove unused PCIE_PORT_SERVICE_VC Bjorn Helgaas
2018-03-07 10:34 ` Rafael J. Wysocki
2018-03-07 6:14 ` [PATCH v1 7/9] PCI/portdrv: Simplify PCIe feature permission checking Bjorn Helgaas
2018-03-07 11:12 ` Rafael J. Wysocki
2018-03-07 6:14 ` [PATCH v1 8/9] PCI/portdrv: Remove unnecessary include of <linux/pci-aspm.h> Bjorn Helgaas
2018-03-07 11:12 ` Rafael J. Wysocki
2018-03-07 6:14 ` [PATCH v1 9/9] PCI/portdrv: Remove "pcie_hp=nomsi" kernel parameter Bjorn Helgaas
2018-03-07 11:13 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7571217.yaDH5TzqWC@aspire.rjw.lan \
--to=rjw@rjwysocki.net \
--cc=helgaas@kernel.org \
--cc=keith.busch@intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=lukas@wunner.de \
--cc=okaya@codeaurora.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox