[PATCH v3 25/28] drm/xe/pci: Introduce a helper to allow VF access to PF xe_device

Michał Winiarski posted 28 patches 3 months, 1 week ago
There is a newer version of this series
[PATCH v3 25/28] drm/xe/pci: Introduce a helper to allow VF access to PF xe_device
Posted by Michał Winiarski 3 months, 1 week ago
In certain scenarios (such as VF migration), VF driver needs to interact
with PF driver.
Add a helper to allow VF driver access to PF xe_device.

Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
---
 drivers/gpu/drm/xe/xe_pci.c | 17 +++++++++++++++++
 drivers/gpu/drm/xe/xe_pci.h |  3 +++
 2 files changed, 20 insertions(+)

diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c
index aeae675c912b7..3e7b03c847a42 100644
--- a/drivers/gpu/drm/xe/xe_pci.c
+++ b/drivers/gpu/drm/xe/xe_pci.c
@@ -1224,6 +1224,23 @@ static struct pci_driver xe_pci_driver = {
 #endif
 };
 
+/**
+ * xe_pci_get_pf_xe_device() - Get PF &xe_device.
+ * @pdev: the VF &pci_dev device
+ *
+ * Return: pointer to PF &xe_device, NULL otherwise.
+ */
+struct xe_device *xe_pci_get_pf_xe_device(struct pci_dev *pdev)
+{
+	struct drm_device *drm;
+
+	drm = pci_iov_get_pf_drvdata(pdev, &xe_pci_driver);
+	if (IS_ERR(drm))
+		return NULL;
+
+	return to_xe_device(drm);
+}
+
 int xe_register_pci_driver(void)
 {
 	return pci_register_driver(&xe_pci_driver);
diff --git a/drivers/gpu/drm/xe/xe_pci.h b/drivers/gpu/drm/xe/xe_pci.h
index 611c1209b14cc..2bb2e486756db 100644
--- a/drivers/gpu/drm/xe/xe_pci.h
+++ b/drivers/gpu/drm/xe/xe_pci.h
@@ -6,6 +6,9 @@
 #ifndef _XE_PCI_H_
 #define _XE_PCI_H_
 
+struct pci_dev;
+
+struct xe_device *xe_pci_get_pf_xe_device(struct pci_dev *pdev);
 int xe_register_pci_driver(void);
 void xe_unregister_pci_driver(void);
 
-- 
2.50.1

Re: [PATCH v3 25/28] drm/xe/pci: Introduce a helper to allow VF access to PF xe_device
Posted by Michal Wajdeczko 3 months, 1 week ago

On 10/30/2025 9:31 PM, Michał Winiarski wrote:
> In certain scenarios (such as VF migration), VF driver needs to interact
> with PF driver.
> Add a helper to allow VF driver access to PF xe_device.
> 
> Signed-off-by: Michał Winiarski <michal.winiarski@intel.com>
> ---
>  drivers/gpu/drm/xe/xe_pci.c | 17 +++++++++++++++++
>  drivers/gpu/drm/xe/xe_pci.h |  3 +++
>  2 files changed, 20 insertions(+)
> 
> diff --git a/drivers/gpu/drm/xe/xe_pci.c b/drivers/gpu/drm/xe/xe_pci.c
> index aeae675c912b7..3e7b03c847a42 100644
> --- a/drivers/gpu/drm/xe/xe_pci.c
> +++ b/drivers/gpu/drm/xe/xe_pci.c
> @@ -1224,6 +1224,23 @@ static struct pci_driver xe_pci_driver = {
>  #endif
>  };
>  
> +/**
> + * xe_pci_get_pf_xe_device() - Get PF &xe_device.
> + * @pdev: the VF &pci_dev device
> + *
> + * Return: pointer to PF &xe_device, NULL otherwise.
> + */
> +struct xe_device *xe_pci_get_pf_xe_device(struct pci_dev *pdev)
> +{
> +	struct drm_device *drm;
> +
> +	drm = pci_iov_get_pf_drvdata(pdev, &xe_pci_driver);
> +	if (IS_ERR(drm))
> +		return NULL;
> +
> +	return to_xe_device(drm);
> +}

I would rather expose xe_pci_driver from xe_pci.c (*) and then
make this a static helper as part of the vfio export file

	static struct xe_device *to_xe_pf(struct pci_dev *pdev)

but maybe Lucas or Matt has a different opinion

(*) this will also help us to move our live-kunit generator to a better place 


> +
>  int xe_register_pci_driver(void)
>  {
>  	return pci_register_driver(&xe_pci_driver);
> diff --git a/drivers/gpu/drm/xe/xe_pci.h b/drivers/gpu/drm/xe/xe_pci.h
> index 611c1209b14cc..2bb2e486756db 100644
> --- a/drivers/gpu/drm/xe/xe_pci.h
> +++ b/drivers/gpu/drm/xe/xe_pci.h
> @@ -6,6 +6,9 @@
>  #ifndef _XE_PCI_H_
>  #define _XE_PCI_H_
>  
> +struct pci_dev;
> +
> +struct xe_device *xe_pci_get_pf_xe_device(struct pci_dev *pdev);
>  int xe_register_pci_driver(void);
>  void xe_unregister_pci_driver(void);
>