Skip to content

Commit 83e5af5

Browse files
committed
drm/i915 & drm/xe: save struct drm_device to drvdata
In the future, the display code shall not have any idea about struct xe_device or struct drm_i915_private, but will need to get at the struct drm_device via drvdata. Store the struct drm_device pointer to drvdata instead of the driver specific pointer. Avoid passing NULL to container_of() via to_i915()/to_xe_device(). (It does return NULL for NULL pointers when the offset happens to be 0, but otherwise returns garbage pointers for NULL.) Reviewed-by: Gustavo Sousa <gustavo.sousa@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/946805b32e38d4785880cc7857e01e6a309126a9.1724942754.git.jani.nikula@intel.com Signed-off-by: Jani Nikula <jani.nikula@intel.com>
1 parent 8be4dce commit 83e5af5

6 files changed

Lines changed: 18 additions & 8 deletions

File tree

drivers/gpu/drm/i915/i915_driver.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ i915_driver_create(struct pci_dev *pdev, const struct pci_device_id *ent)
723723
if (IS_ERR(i915))
724724
return i915;
725725

726-
pci_set_drvdata(pdev, i915);
726+
pci_set_drvdata(pdev, &i915->drm);
727727

728728
/* Device parameters start as a copy of module parameters. */
729729
i915_params_copy(&i915->params, &i915_modparams);

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,16 @@ static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
365365

366366
static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
367367
{
368-
return dev_get_drvdata(kdev);
368+
struct drm_device *drm = dev_get_drvdata(kdev);
369+
370+
return drm ? to_i915(drm) : NULL;
369371
}
370372

371373
static inline struct drm_i915_private *pdev_to_i915(struct pci_dev *pdev)
372374
{
373-
return pci_get_drvdata(pdev);
375+
struct drm_device *drm = pci_get_drvdata(pdev);
376+
377+
return drm ? to_i915(drm) : NULL;
374378
}
375379

376380
static inline struct intel_gt *to_gt(const struct drm_i915_private *i915)

drivers/gpu/drm/i915/selftests/mock_gem_device.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ struct drm_i915_private *mock_gem_device(void)
172172
return NULL;
173173
}
174174

175-
pci_set_drvdata(pdev, i915);
175+
pci_set_drvdata(pdev, &i915->drm);
176176

177177
/* Device parameters start as a copy of module parameters. */
178178
i915_params_copy(&i915->params, &i915_modparams);

drivers/gpu/drm/xe/compat-i915-headers/i915_drv.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ static inline struct drm_i915_private *to_i915(const struct drm_device *dev)
2323

2424
static inline struct drm_i915_private *kdev_to_i915(struct device *kdev)
2525
{
26-
return dev_get_drvdata(kdev);
26+
struct drm_device *drm = dev_get_drvdata(kdev);
27+
28+
return drm ? to_i915(drm) : NULL;
2729
}
2830

2931
#define IS_PLATFORM(xe, x) ((xe)->info.platform == x)

drivers/gpu/drm/xe/xe_device.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,16 @@ static inline struct xe_device *to_xe_device(const struct drm_device *dev)
1717

1818
static inline struct xe_device *kdev_to_xe_device(struct device *kdev)
1919
{
20-
return dev_get_drvdata(kdev);
20+
struct drm_device *drm = dev_get_drvdata(kdev);
21+
22+
return drm ? to_xe_device(drm) : NULL;
2123
}
2224

2325
static inline struct xe_device *pdev_to_xe_device(struct pci_dev *pdev)
2426
{
25-
return pci_get_drvdata(pdev);
27+
struct drm_device *drm = pci_get_drvdata(pdev);
28+
29+
return drm ? to_xe_device(drm) : NULL;
2630
}
2731

2832
static inline struct xe_device *xe_device_const_cast(const struct xe_device *xe)

drivers/gpu/drm/xe/xe_pci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ static int xe_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
793793
if (IS_ERR(xe))
794794
return PTR_ERR(xe);
795795

796-
pci_set_drvdata(pdev, xe);
796+
pci_set_drvdata(pdev, &xe->drm);
797797

798798
xe_pm_assert_unbounded_bridge(xe);
799799
subplatform_desc = find_subplatform(xe, desc);

0 commit comments

Comments
 (0)