[Intel-gfx] [PATCH 06/11] drm/i915: Demidlayer driver loading
Chris Wilson
chris at chris-wilson.co.uk
Fri May 27 14:00:39 UTC 2016
Take control over allocating, loading and registering the driver from the
DRM midlayer by performing it manually from i915_pci_probe. This allows
us to carefully control the order of when we setup the hardware vs when
it becomes visible to third parties (including userspace). The current
ordering makes the driver visible to userspace first (in order to
coordinate with removed DRI1 userspace), but that ordering incurs risk.
The risk increases as we strive for more asynchronous loading.
One side effect of controlling the allocation is that we can allocate
both the drm_device + drm_i915_private in one block, the next step
towards subclassing.
Unload is still left as before, a mix of midlayer and driver.
Suggested-by: Daniel Vetter <daniel.vetter at ffwll.ch>
Signed-off-by: Chris Wilson <chris at chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
Cc: Ville Syrjälä <ville.syrjala at linux.intel.com>
---
drivers/gpu/drm/i915/i915_dma.c | 67 ++++++++++++++++++++++++++---------------
drivers/gpu/drm/i915/i915_drv.c | 3 +-
drivers/gpu/drm/i915/i915_drv.h | 6 +++-
3 files changed, 49 insertions(+), 27 deletions(-)
diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index 6b36bca585c5..b5eeee6693f7 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1046,9 +1046,10 @@ static void i915_workqueues_cleanup(struct drm_i915_private *dev_priv)
* function hooks not requiring accessing the device.
*/
static int i915_driver_init_early(struct drm_i915_private *dev_priv,
- struct drm_device *dev,
- struct intel_device_info *info)
+ const struct pci_device_id *ent)
{
+ const struct intel_device_info *match_info =
+ (struct intel_device_info *)ent->driver_data;
struct intel_device_info *device_info;
int ret = 0;
@@ -1057,8 +1058,8 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,
/* Setup the write-once "constant" device info */
device_info = (struct intel_device_info *)&dev_priv->info;
- memcpy(device_info, info, sizeof(dev_priv->info));
- device_info->device_id = dev->pdev->device;
+ memcpy(device_info, match_info, sizeof(*device_info));
+ device_info->device_id = dev_priv->drm.pdev->device;
BUG_ON(device_info->gen > sizeof(device_info->gen_mask) * BITS_PER_BYTE);
device_info->gen_mask = BIT(device_info->gen - 1);
@@ -1080,18 +1081,18 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,
return ret;
/* This must be called before any calls to HAS_PCH_* */
- intel_detect_pch(dev);
+ intel_detect_pch(&dev_priv->drm);
- intel_pm_setup(dev);
+ intel_pm_setup(&dev_priv->drm);
intel_init_dpio(dev_priv);
intel_power_domains_init(dev_priv);
intel_irq_init(dev_priv);
intel_init_display_hooks(dev_priv);
intel_init_clock_gating_hooks(dev_priv);
intel_init_audio_hooks(dev_priv);
- i915_gem_load_init(dev);
+ i915_gem_load_init(&dev_priv->drm);
- intel_display_crc_init(dev);
+ intel_display_crc_init(&dev_priv->drm);
i915_dump_device_info(dev_priv);
@@ -1099,7 +1100,7 @@ static int i915_driver_init_early(struct drm_i915_private *dev_priv,
* very first ones. Almost everything should work, except for maybe
* suspend/resume. And we don't implement workarounds that affect only
* pre-production machines. */
- if (IS_HSW_EARLY_SDV(dev))
+ if (IS_HSW_EARLY_SDV(dev_priv))
DRM_INFO("This is an early pre-production Haswell machine. "
"It may not be fully functional.\n");
@@ -1353,6 +1354,7 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
struct drm_device *dev = dev_priv->dev;
i915_gem_shrinker_init(dev_priv);
+
/*
* Notify a valid surface after modesetting,
* when running inside a VM.
@@ -1360,9 +1362,13 @@ static void i915_driver_register(struct drm_i915_private *dev_priv)
if (intel_vgpu_active(dev_priv))
I915_WRITE(vgtif_reg(display_ready), VGT_DRV_DISPLAY_READY);
- i915_debugfs_register(dev_priv);
- i915_setup_sysfs(dev);
- intel_modeset_register(dev_priv);
+ /* Reveal our presence to userspace */
+ if (drm_dev_register(dev, 0) == 0) {
+ i915_debugfs_register(dev_priv);
+ i915_setup_sysfs(dev);
+ intel_modeset_register(dev_priv);
+ } else
+ DRM_ERROR("Failed to register driver for userspace access!\n");
if (INTEL_INFO(dev_priv)->num_pipes) {
/* Must be done after probing outputs */
@@ -1415,25 +1421,36 @@ static void i915_driver_unregister(struct drm_i915_private *dev_priv)
* - allocate initial config memory
* - setup the DRM framebuffer with the allocated memory
*/
-int i915_driver_load(struct drm_device *dev, unsigned long flags)
+int i915_driver_load(struct pci_dev *pdev,
+ const struct pci_device_id *ent,
+ struct drm_driver *driver)
{
struct drm_i915_private *dev_priv;
- int ret = 0;
+ int ret;
dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
if (dev_priv == NULL)
return -ENOMEM;
- dev->dev_private = dev_priv;
- /* Must be set before calling __i915_printk */
- dev_priv->dev = dev;
+ ret = drm_dev_init(&dev_priv->drm, driver, &pdev->dev);
+ if (ret)
+ goto out_free_priv;
- ret = i915_driver_init_early(dev_priv, dev,
- (struct intel_device_info *)flags);
+ /* Must be set before calling __i915_printk */
+ dev_priv->drm.pdev = pdev;
+ dev_priv->drm.dev_private = dev_priv;
+ dev_priv->dev = &dev_priv->drm;
+ ret = i915_driver_init_early(dev_priv, ent);
if (ret < 0)
goto out_free_priv;
+ ret = pci_enable_device(pdev);
+ if (ret)
+ goto out_cleanup_early;
+
+ pci_set_drvdata(pdev, &dev_priv->drm);
+
intel_runtime_pm_get(dev_priv);
ret = i915_driver_init_mmio(dev_priv);
@@ -1449,13 +1466,14 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
* of the i915_driver_init_/i915_driver_register functions according
* to the role/effect of the given init step.
*/
- if (INTEL_INFO(dev)->num_pipes) {
- ret = drm_vblank_init(dev, INTEL_INFO(dev)->num_pipes);
+ if (INTEL_INFO(dev_priv)->num_pipes) {
+ ret = drm_vblank_init(dev_priv->dev,
+ INTEL_INFO(dev_priv)->num_pipes);
if (ret)
goto out_cleanup_hw;
}
- ret = i915_load_modeset_init(dev);
+ ret = i915_load_modeset_init(dev_priv->dev);
if (ret < 0)
goto out_cleanup_vblank;
@@ -1468,13 +1486,15 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
return 0;
out_cleanup_vblank:
- drm_vblank_cleanup(dev);
+ drm_vblank_cleanup(dev_priv->dev);
out_cleanup_hw:
i915_driver_cleanup_hw(dev_priv);
out_cleanup_mmio:
i915_driver_cleanup_mmio(dev_priv);
out_runtime_pm_put:
intel_runtime_pm_put(dev_priv);
+ pci_disable_device(pdev);
+out_cleanup_early:
i915_driver_cleanup_early(dev_priv);
out_free_priv:
i915_load_error(dev_priv, "Device initialization failed (%d)\n", ret);
@@ -1543,7 +1563,6 @@ int i915_driver_unload(struct drm_device *dev)
intel_display_power_put(dev_priv, POWER_DOMAIN_INIT);
i915_driver_cleanup_early(dev_priv);
- kfree(dev_priv);
return 0;
}
diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
index fa9e16b2247c..d2792ce12c5f 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -1039,7 +1039,7 @@ static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
!vga_switcheroo_handler_flags())
return -EPROBE_DEFER;
- return drm_get_pci_dev(pdev, ent, &driver);
+ return i915_driver_load(pdev, ent, &driver);
}
static void
@@ -1753,7 +1753,6 @@ static struct drm_driver driver = {
.driver_features =
DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | DRIVER_GEM | DRIVER_PRIME |
DRIVER_RENDER | DRIVER_MODESET,
- .load = i915_driver_load,
.unload = i915_driver_unload,
.open = i915_driver_open,
.lastclose = i915_driver_lastclose,
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 5e9f8d5cb7eb..3f6a3648c50a 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1722,6 +1722,8 @@ struct intel_wm_config {
};
struct drm_i915_private {
+ struct drm_device drm;
+
struct drm_device *dev;
struct kmem_cache *objects;
struct kmem_cache *vmas;
@@ -2872,7 +2874,9 @@ __i915_printk(struct drm_i915_private *dev_priv, const char *level,
#define i915_report_error(dev_priv, fmt, ...) \
__i915_printk(dev_priv, KERN_ERR, fmt, ##__VA_ARGS__)
-extern int i915_driver_load(struct drm_device *, unsigned long flags);
+extern int i915_driver_load(struct pci_dev *pdev,
+ const struct pci_device_id *ent,
+ struct drm_driver *driver);
extern int i915_driver_unload(struct drm_device *);
extern int i915_driver_open(struct drm_device *dev, struct drm_file *file);
extern void i915_driver_lastclose(struct drm_device * dev);
--
2.8.1
More information about the Intel-gfx
mailing list