Commit cd01269d authored by Daniel Vetter's avatar Daniel Vetter

drm/i915/selftests: align more to real device lifetimes

To avoid having to create all the device and driver scaffolding we
just manually create and destroy a devres_group.

v2: Rebased

v3: use devres_open/release_group so we can use devm without real
hacks in the driver core or having to create an entire fake bus for
testing drivers. Might want to extract this into helpers eventually,
maybe as a mock_drm_dev_alloc or test_drm_dev_alloc.

v4:
- Fix IS_ERR handling (Matt)
- Delete surplus put_device() in mock_device_release (intel-gfx-ci)

v5:
- do not switch to device_add - it breaks runtime pm in the tests and
  with the devres_group_add/release no longer needed for automatic
  cleanup (CI). Update commit message to match.
- print correct error in pr_err (Matt)

v6: Remove now unused err variable (CI).

v7: More warning fixes ...
Acked-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Matthew Auld <matthew.william.auld@gmail.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> (v3)
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: Matthew Auld <matthew.william.auld@gmail.com> (v4)
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200919134032.2488403-1-daniel.vetter@ffwll.ch
parent 82be0d75
...@@ -79,8 +79,6 @@ static void mock_device_release(struct drm_device *dev) ...@@ -79,8 +79,6 @@ static void mock_device_release(struct drm_device *dev)
out: out:
i915_params_free(&i915->params); i915_params_free(&i915->params);
put_device(&i915->drm.pdev->dev);
i915->drm.pdev = NULL;
} }
static struct drm_driver mock_driver = { static struct drm_driver mock_driver = {
...@@ -123,17 +121,10 @@ struct drm_i915_private *mock_gem_device(void) ...@@ -123,17 +121,10 @@ struct drm_i915_private *mock_gem_device(void)
#if IS_ENABLED(CONFIG_IOMMU_API) && defined(CONFIG_INTEL_IOMMU) #if IS_ENABLED(CONFIG_IOMMU_API) && defined(CONFIG_INTEL_IOMMU)
struct dev_iommu iommu; struct dev_iommu iommu;
#endif #endif
int err;
pdev = kzalloc(sizeof(*pdev), GFP_KERNEL); pdev = kzalloc(sizeof(*pdev), GFP_KERNEL);
if (!pdev) if (!pdev)
return NULL; return NULL;
i915 = kzalloc(sizeof(*i915), GFP_KERNEL);
if (!i915) {
kfree(pdev);
return NULL;
}
device_initialize(&pdev->dev); device_initialize(&pdev->dev);
pdev->class = PCI_BASE_CLASS_DISPLAY << 16; pdev->class = PCI_BASE_CLASS_DISPLAY << 16;
pdev->dev.release = release_dev; pdev->dev.release = release_dev;
...@@ -146,8 +137,23 @@ struct drm_i915_private *mock_gem_device(void) ...@@ -146,8 +137,23 @@ struct drm_i915_private *mock_gem_device(void)
iommu.priv = (void *)-1; iommu.priv = (void *)-1;
pdev->dev.iommu = &iommu; pdev->dev.iommu = &iommu;
#endif #endif
if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
put_device(&pdev->dev);
return NULL;
}
i915 = devm_drm_dev_alloc(&pdev->dev, &mock_driver,
struct drm_i915_private, drm);
if (IS_ERR(i915)) {
pr_err("Failed to allocate mock GEM device: err=%ld\n", PTR_ERR(i915));
devres_release_group(&pdev->dev, NULL);
put_device(&pdev->dev);
return NULL;
}
pci_set_drvdata(pdev, i915); pci_set_drvdata(pdev, i915);
i915->drm.pdev = pdev;
dev_pm_domain_set(&pdev->dev, &pm_domain); dev_pm_domain_set(&pdev->dev, &pm_domain);
pm_runtime_enable(&pdev->dev); pm_runtime_enable(&pdev->dev);
...@@ -155,16 +161,6 @@ struct drm_i915_private *mock_gem_device(void) ...@@ -155,16 +161,6 @@ struct drm_i915_private *mock_gem_device(void)
if (pm_runtime_enabled(&pdev->dev)) if (pm_runtime_enabled(&pdev->dev))
WARN_ON(pm_runtime_get_sync(&pdev->dev)); WARN_ON(pm_runtime_get_sync(&pdev->dev));
err = drm_dev_init(&i915->drm, &mock_driver, &pdev->dev);
if (err) {
pr_err("Failed to initialise mock GEM device: err=%d\n", err);
put_device(&pdev->dev);
kfree(i915);
return NULL;
}
i915->drm.pdev = pdev;
drmm_add_final_kfree(&i915->drm, i915);
i915_params_copy(&i915->params, &i915_modparams); i915_params_copy(&i915->params, &i915_modparams);
...@@ -231,5 +227,8 @@ struct drm_i915_private *mock_gem_device(void) ...@@ -231,5 +227,8 @@ struct drm_i915_private *mock_gem_device(void)
void mock_destroy_device(struct drm_i915_private *i915) void mock_destroy_device(struct drm_i915_private *i915)
{ {
drm_dev_put(&i915->drm); struct device *dev = i915->drm.dev;
devres_release_group(dev, NULL);
put_device(dev);
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment