All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chris Wilson <chris@chris-wilson.co.uk>
To: intel-gfx@lists.freedesktop.org
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Subject: [PATCH 24/44] drm/i915: Demidlayer driver loading
Date: Wed, 15 Jun 2016 13:18:09 +0100	[thread overview]
Message-ID: <1465993109-19523-25-git-send-email-chris@chris-wilson.co.uk> (raw)
In-Reply-To: <1465993109-19523-1-git-send-email-chris@chris-wilson.co.uk>

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.

v2: After drm_dev_init(), we should call drm_dev_unref() so that we call
drm_dev_release() and free everything from drm_dev_init().

Suggested-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/i915_dma.c | 76 ++++++++++++++++++++++++++---------------
 drivers/gpu/drm/i915/i915_drv.c |  3 +-
 drivers/gpu/drm/i915/i915_drv.h |  6 +++-
 3 files changed, 54 insertions(+), 31 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index cb3c5be78f61..b64d34fabf18 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -1075,9 +1075,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;
 
@@ -1086,8 +1087,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);
@@ -1109,18 +1110,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);
 
@@ -1128,7 +1129,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");
 
@@ -1382,6 +1383,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.
@@ -1389,9 +1391,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 */
@@ -1444,24 +1450,38 @@ 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;
 
+	ret = 0;
 	dev_priv = kzalloc(sizeof(*dev_priv), GFP_KERNEL);
-	if (dev_priv == NULL)
+	if (dev_priv)
+		ret = drm_dev_init(&dev_priv->drm, driver, &pdev->dev);
+	if (ret) {
+		dev_printk(KERN_ERR, &pdev->dev,
+			   "[" DRM_NAME ":%s] allocation failed\n", __func__);
+		kfree(dev_priv);
 		return -ENOMEM;
+	}
 
-	dev->dev_private = dev_priv;
 	/* Must be set before calling __i915_printk */
-	dev_priv->dev = dev;
+	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, dev,
-				     (struct intel_device_info *)flags);
+	ret = pci_enable_device(pdev);
+	if (ret)
+		goto out_free_priv;
 
+	pci_set_drvdata(pdev, &dev_priv->drm);
+
+	ret = i915_driver_init_early(dev_priv, ent);
 	if (ret < 0)
-		goto out_free_priv;
+		goto out_pci_disable;
 
 	intel_runtime_pm_get(dev_priv);
 
@@ -1478,13 +1498,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;
 
@@ -1497,7 +1518,7 @@ 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:
@@ -1505,11 +1526,11 @@ out_cleanup_mmio:
 out_runtime_pm_put:
 	intel_runtime_pm_put(dev_priv);
 	i915_driver_cleanup_early(dev_priv);
+out_pci_disable:
+	pci_disable_device(pdev);
 out_free_priv:
 	i915_load_error(dev_priv, "Device initialization failed (%d)\n", ret);
-
-	kfree(dev_priv);
-
+	drm_dev_unref(&dev_priv->drm);
 	return ret;
 }
 
@@ -1572,7 +1593,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 3ea09bd83a5a..1a335e1a8b62 100644
--- a/drivers/gpu/drm/i915/i915_drv.c
+++ b/drivers/gpu/drm/i915/i915_drv.c
@@ -1034,7 +1034,7 @@ static int i915_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 	if (vga_switcheroo_client_probe_defer(pdev))
 		return -EPROBE_DEFER;
 
-	return drm_get_pci_dev(pdev, ent, &driver);
+	return i915_driver_load(pdev, ent, &driver);
 }
 
 static void
@@ -1748,7 +1748,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 e9962ad76e46..185f4bfbe5e3 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -1726,6 +1726,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;
@@ -2887,7 +2889,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

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

  parent reply	other threads:[~2016-06-15 12:19 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-15 12:17 BAT bug 95634, take 4 Chris Wilson
2016-06-15 12:17 ` [PATCH 01/44] drm: Export drm_dev_init() for subclassing Chris Wilson
2016-06-15 12:17 ` [PATCH 02/44] drm: Add a callback from connector registering Chris Wilson
2016-06-17  7:41   ` Daniel Vetter
2016-06-15 12:17 ` [PATCH 03/44] drm: Make drm_connector_register() safe against multiple calls Chris Wilson
2016-06-15 12:17 ` [PATCH 04/44] drm: Automatically unregister the connector during cleanup Chris Wilson
2016-06-17  7:44   ` Daniel Vetter
2016-06-15 12:17 ` [PATCH 05/44] drm: Automatically register/unregister all connectors Chris Wilson
2016-06-15 12:17 ` Chris Wilson
2016-06-15 12:17 ` [PATCH 06/44] drm/arc: Remove redundant calls to drm_connector_register_all() Chris Wilson
2016-06-15 12:17 ` [PATCH 07/44] drm/atmel-hlcdc: " Chris Wilson
2016-06-15 12:17 ` [PATCH 08/44] drm/hisilicon: " Chris Wilson
2016-06-15 12:17 ` [PATCH 09/44] drm/mediatek: " Chris Wilson
2016-06-15 12:17   ` Chris Wilson
2016-06-15 12:17 ` [PATCH 10/44] drm/msm: " Chris Wilson
2016-06-15 12:17 ` [PATCH 11/44] drm/rcar-du: " Chris Wilson
2016-06-15 12:17 ` [PATCH 12/44] drm: Pass the drm_dp_aux->hw_mutex to i2c for its locking Chris Wilson
2016-06-15 12:17 ` [PATCH 13/44] drm: Minimally initialise drm_dp_aux Chris Wilson
2016-06-15 12:17 ` [PATCH 14/44] drm/i915: Perform async fbdev initialisation much later Chris Wilson
2016-06-15 12:18 ` [PATCH 15/44] drm/i915: Make panel/backlight safe to setup/cleanup multiple times Chris Wilson
2016-06-16  6:34   ` Jani Nikula
2016-06-16  9:00     ` Chris Wilson
2016-06-15 12:18 ` [PATCH 16/44] drm/i915: Move panel's backlight setup next to panel init Chris Wilson
2016-06-15 12:18 ` [PATCH 17/44] drm/i915: Move intel_connector->unregister to connector->early_unregister Chris Wilson
2016-06-15 12:18 ` [PATCH 18/44] drm/i915: Move backlight unregistration to connector unregistration Chris Wilson
2016-06-15 12:18 ` [PATCH 19/44] drm/i915: Move registration actions to connector->late_register Chris Wilson
2016-06-15 12:18 ` [PATCH 20/44] drm/i915/dp: Free the drm_dp_aux along with the encoder Chris Wilson
2016-06-15 12:18 ` [PATCH 21/44] drm/i915: Move backlight registration to connector registration Chris Wilson
2016-06-15 12:18 ` [PATCH 22/44] drm/i915: Move connector registration to driver registration Chris Wilson
2016-06-15 12:18 ` [PATCH 23/44] drm/i915: Register debugfs interface last Chris Wilson
2016-06-15 12:18 ` Chris Wilson [this message]
2016-06-15 12:18 ` [PATCH 25/44] drm/i915: Demidlayer driver unloading Chris Wilson
2016-06-15 12:18 ` [PATCH 26/44] drm/i915: Remove redundant drm_connector_register_all() Chris Wilson
2016-06-15 12:18 ` [PATCH 27/44] drm/i915: Start exploiting drm_device subclassing Chris Wilson
2016-06-15 12:18 ` [PATCH 28/44] drm/i915: Merge i915_dma.c into i915_drv.c Chris Wilson
2016-06-15 12:18 ` [PATCH 29/44] drm/i915: Remove user controllable DRM_ERROR for i915_getparam() Chris Wilson
2016-06-15 12:33   ` Tvrtko Ursulin
2016-06-15 12:18 ` [PATCH 30/44] drm/i915: Remove user controllable DRM_ERROR for intel_get_pipe_from_crtc_id() Chris Wilson
2016-06-15 12:34   ` Tvrtko Ursulin
2016-06-15 12:18 ` [PATCH 31/44] drm/i915: Split out the PCI driver interface to i915_pci.c Chris Wilson
2016-06-15 12:18 ` [PATCH 32/44] drm/i915: Move module init/exit " Chris Wilson
2016-07-12 10:45   ` Joonas Lahtinen
2016-06-15 12:18 ` [PATCH 33/44] drm/i915: Skip idling an idle engine Chris Wilson
2016-06-15 12:18 ` [PATCH 34/44] drm/i915: Move legacy kernel context pinning to intel_ringbuffer.c Chris Wilson
2016-06-15 12:18 ` [PATCH 35/44] drm/i915: Treat kernel context as initialised Chris Wilson
2016-06-16  8:20   ` Mika Kuoppala
2016-06-16 11:00     ` Chris Wilson
2016-06-15 12:18 ` [PATCH 36/44] drm/i915: Mark all default contexts as uninitialised after context loss Chris Wilson
2016-06-15 12:18 ` [PATCH 37/44] drm/i915: No need to wait for idle on L3 remap Chris Wilson
2016-06-15 12:18 ` [PATCH 38/44] drm/i915: Split idling from forcing context switch Chris Wilson
2016-06-16  8:51   ` Mika Kuoppala
2016-06-16 10:58     ` Chris Wilson
2016-06-15 12:18 ` [PATCH 39/44] drm/i915: Only switch to default context when evicting from GGTT Chris Wilson
2016-06-15 12:18 ` [PATCH 40/44] drm/i915: Preserve current RPS frequency Chris Wilson
2016-06-16  9:15   ` Mika Kuoppala
2016-06-16 10:56     ` Chris Wilson
2016-06-15 12:18 ` [PATCH 41/44] drm/i915: Remove superfluous powersave work flushing Chris Wilson
2016-06-21 15:15   ` Chris Wilson
2016-06-15 12:18 ` [PATCH 42/44] drm/i915: Defer enabling rc6 til after we submit the first batch/context Chris Wilson
2016-06-21 15:16   ` Chris Wilson
2016-06-15 12:18 ` [PATCH 43/44] drm/i915/fbdev: Limit the global async-domain synchronization Chris Wilson
2016-06-15 12:18 ` [PATCH 44/44] drm/i915/fbdev: Flush mode configuration before lastclose Chris Wilson
2016-06-15 16:09 ` ✗ Ro.CI.BAT: warning for series starting with [01/44] drm: Export drm_dev_init() for subclassing Patchwork

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=1465993109-19523-25-git-send-email-chris@chris-wilson.co.uk \
    --to=chris@chris-wilson.co.uk \
    --cc=daniel.vetter@ffwll.ch \
    --cc=intel-gfx@lists.freedesktop.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.