linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Hamza Mahfooz <hamza.mahfooz@amd.com>
To: <linux-kernel@vger.kernel.org>
Cc: "Hamza Mahfooz" <hamza.mahfooz@amd.com>,
	stable@vger.kernel.org,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Pan, Xinhui" <Xinhui.Pan@amd.com>,
	"David Airlie" <airlied@gmail.com>,
	"Daniel Vetter" <daniel@ffwll.ch>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Mario Limonciello" <mario.limonciello@amd.com>,
	"Lijo Lazar" <lijo.lazar@amd.com>,
	"Srinivasan Shanmugam" <srinivasan.shanmugam@amd.com>,
	"Le Ma" <le.ma@amd.com>, "André Almeida" <andrealmeid@igalia.com>,
	"James Zhu" <James.Zhu@amd.com>,
	"Aurabindo Pillai" <aurabindo.pillai@amd.com>,
	"Jason Gunthorpe" <jgg@ziepe.ca>, "Wei Liu" <wei.liu@kernel.org>,
	"Robin Murphy" <robin.murphy@arm.com>,
	amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	linux-pci@vger.kernel.org
Subject: [PATCH 2/3] PCI: introduce can_remove()
Date: Fri, 2 Feb 2024 17:25:55 -0500	[thread overview]
Message-ID: <20240202222603.141240-2-hamza.mahfooz@amd.com> (raw)
In-Reply-To: <20240202222603.141240-1-hamza.mahfooz@amd.com>

Wire up the can_remove() callback, such that pci drivers can implement
their own version of it.

Cc: stable@vger.kernel.org
Signed-off-by: Hamza Mahfooz <hamza.mahfooz@amd.com>
---
 drivers/pci/pci-driver.c | 12 ++++++++++++
 include/linux/pci.h      |  5 +++++
 2 files changed, 17 insertions(+)

diff --git a/drivers/pci/pci-driver.c b/drivers/pci/pci-driver.c
index 51ec9e7e784f..8aae484c5494 100644
--- a/drivers/pci/pci-driver.c
+++ b/drivers/pci/pci-driver.c
@@ -466,6 +466,17 @@ static int pci_device_probe(struct device *dev)
 	return error;
 }
 
+static bool pci_device_can_remove(struct device *dev)
+{
+	struct pci_dev *pci_dev = to_pci_dev(dev);
+	struct pci_driver *drv = pci_dev->driver;
+
+	if (drv->can_remove)
+		return drv->can_remove(pci_dev);
+
+	return true;
+}
+
 static void pci_device_remove(struct device *dev)
 {
 	struct pci_dev *pci_dev = to_pci_dev(dev);
@@ -1680,6 +1691,7 @@ struct bus_type pci_bus_type = {
 	.match		= pci_bus_match,
 	.uevent		= pci_uevent,
 	.probe		= pci_device_probe,
+	.can_remove	= pci_device_can_remove,
 	.remove		= pci_device_remove,
 	.shutdown	= pci_device_shutdown,
 	.dev_groups	= pci_dev_groups,
diff --git a/include/linux/pci.h b/include/linux/pci.h
index add9368e6314..95276f44b23b 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -902,6 +902,10 @@ struct module;
  *		(negative number) otherwise.
  *		The probe function always gets called from process
  *		context, so it can sleep.
+ * @can_remove:	The can_remove() function gets called during driver
+ *		deregistration to determine if remove() can be called.
+ *		The probe function always gets called from process
+ *		context, so it can sleep.
  * @remove:	The remove() function gets called whenever a device
  *		being handled by this driver is removed (either during
  *		deregistration of the driver or when it's manually
@@ -943,6 +947,7 @@ struct pci_driver {
 	const char		*name;
 	const struct pci_device_id *id_table;	/* Must be non-NULL for probe to be called */
 	int  (*probe)(struct pci_dev *dev, const struct pci_device_id *id);	/* New device inserted */
+	bool (*can_remove)(struct pci_dev *dev);
 	void (*remove)(struct pci_dev *dev);	/* Device removed (NULL if not a hot-plug capable driver) */
 	int  (*suspend)(struct pci_dev *dev, pm_message_t state);	/* Device suspended */
 	int  (*resume)(struct pci_dev *dev);	/* Device woken up */
-- 
2.43.0


  reply	other threads:[~2024-02-02 22:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 22:25 [PATCH 1/3] driver core: bus: introduce can_remove() Hamza Mahfooz
2024-02-02 22:25 ` Hamza Mahfooz [this message]
2024-02-02 23:38   ` [PATCH 2/3] PCI: " Greg Kroah-Hartman
2024-02-02 22:25 ` [PATCH 3/3] drm/amdgpu: wire up the can_remove() callback Hamza Mahfooz
2024-02-02 22:41   ` Bjorn Helgaas
2024-02-02 23:40   ` Greg Kroah-Hartman
2024-02-06 14:29     ` Daniel Vetter
2024-02-06 18:42       ` Christian König
2024-02-09 11:00         ` Daniel Vetter
2024-02-02 23:41   ` Greg Kroah-Hartman
2024-02-02 23:38 ` [PATCH 1/3] driver core: bus: introduce can_remove() Greg Kroah-Hartman
2024-02-05  8:48 ` Christian König

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=20240202222603.141240-2-hamza.mahfooz@amd.com \
    --to=hamza.mahfooz@amd.com \
    --cc=James.Zhu@amd.com \
    --cc=Xinhui.Pan@amd.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=andrealmeid@igalia.com \
    --cc=aurabindo.pillai@amd.com \
    --cc=bhelgaas@google.com \
    --cc=christian.koenig@amd.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jgg@ziepe.ca \
    --cc=le.ma@amd.com \
    --cc=lijo.lazar@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=rafael@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=srinivasan.shanmugam@amd.com \
    --cc=stable@vger.kernel.org \
    --cc=wei.liu@kernel.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;
as well as URLs for NNTP newsgroup(s).