Skip to contentSkip to conversation

Unified plane support

RFC In review Matt Roper 7 participants 46 messages Mar 19, 2014 – Apr 7, 2014 Page 2 of 2

Subsystems (22)
lore
Share & tools
lore
#34 lore raw

Re: [Intel-gfx] [RFCv3 11/14] drm/i915: Intel-specific primary plane handling

In reply to Matt Roper
Quoted 5 lines · Matt Roper

Intel hardware allows the primary plane to be disabled independently of the CRTC. Provide custom primary plane handling to allow this.

Cc Intel Graphics Development <[email protected]>

Overall this is imo a new feature since it exposes primary plane disabling to userspace. Which means I want a crc based igt for this. Two interesting cases imo:

1) Partially visible primary plane behind an overlay plane. Disabling it should change those areas from the primary plane to grey or something, so easy to check with CRCs.

2) Primary plane + cursor, disable primary plane. Then check that the cursor is still working. Same for overlay sprites.

At least on all currently supported platforms we don't have unified planes in the hardware, so imo it's worth to check that this works properly.

Quoted 39 lines
---
 drivers/gpu/drm/i915/intel_display.c | 132 ++++++++++++++++++++++++++++++++++-
 drivers/gpu/drm/i915/intel_drv.h     |   1 +
 2 files changed, 130 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/intel_display.c +19 -0
index 849a241..7d6878b 100644
@@ -39,6 +39,7 @@
 #include "i915_trace.h"
 #include <drm/drm_dp_helper.h>
 #include <drm/drm_crtc_helper.h>
+#include <drm/drm_rect.h>
 #include <linux/dma_remapping.h>
 
 static void intel_increase_pllclock(struct drm_crtc *crtc);
@@ -10589,19 +10590,144 @@ static void intel_shared_dpll_init(struct drm_device *dev)
 	BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS);
 }
 
+static int
+intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc,
+			     struct drm_framebuffer *fb, int crtc_x, int crtc_y,
+			     unsigned int crtc_w, unsigned int crtc_h,
+			     uint32_t src_x, uint32_t src_y,
+			     uint32_t src_w, uint32_t src_h)
+{
+	struct drm_device *dev = crtc->dev;
+	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
+	struct drm_framebuffer *tmpfb;
+	struct drm_rect dest = {
+		.x1 = crtc_x,
+		.y1 = crtc_y,
+		.x2 = crtc_x + crtc_w,
+		.y2 = crtc_y + crtc_h,
+	};
+	struct drm_rect clip = {

drivers/gpu/drm/i915/intel_display.c static void intel_shared_dpll_init(struct drm_device *dev) · line 10620

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +10 -0
+		.x2 = crtc->mode.hdisplay,
+		.y2 = crtc->mode.vdisplay,
+	};
+	int ret;
+
+	/* setplane API takes shifted source rectangle values; unshift them */
+	src_x >>= 16;
+	src_y >>= 16;
+	src_w >>= 16;
+	src_h >>= 16;

Similar comments as with the generic helper: We need to check the scaling constraints here better. Looks like a good opportunity to extract the logic into some drm_rect helpers maybe?

Quoted 78 lines
drivers/gpu/drm/i915/intel_display.c +78 -0
+
+	/*
+	 * Current hardware can't reposition the primary plane or scale it
+	 * (although this could change in the future).
+	 */
+	drm_rect_intersect(&dest, &clip);
+	if (dest.x1 != 0 || dest.y1 != 0 ||
+	    dest.x2 != crtc->mode.hdisplay || dest.y2 != crtc->mode.vdisplay) {
+		DRM_DEBUG_KMS("Primary plane must cover entire CRTC\n");
+		return -EINVAL;
+	}
+
+	if (crtc_w != src_w || crtc_h != src_h) {
+		DRM_DEBUG_KMS("Can't scale primary plane\n");
+		return -EINVAL;
+	}
+
+	/*
+	 * pipe_set_base() adjusts crtc->primary->fb; however the DRM setplane
+	 * code that called us expects to handle the framebuffer update and
+	 * reference counting; save and restore the current fb before
+	 * calling it.
+	 */
+	tmpfb = plane->fb;
+	ret = intel_pipe_set_base(crtc, src_x, src_y, fb);
+	if (ret)
+		return ret;
+	plane->fb = tmpfb;
+
+	if (!intel_crtc->primary_enabled)
+		intel_enable_primary_hw_plane(dev_priv, intel_crtc->plane,
+					      intel_crtc->pipe);
+
+	return 0;
+}
+
+static int
+intel_primary_plane_disable(struct drm_plane *plane)
+{
+	struct drm_device *dev = plane->dev;
+	drm_i915_private_t *dev_priv = dev->dev_private;
+	struct intel_plane *intel_plane = to_intel_plane(plane);
+	struct intel_crtc *intel_crtc;
+
+	if (!plane->fb)
+		return 0;
+
+	if (WARN_ON(!plane->crtc))
+		return -EINVAL;
+
+	intel_crtc = to_intel_crtc(plane->crtc);
+	if (intel_crtc->primary_enabled)
+		intel_disable_primary_hw_plane(dev_priv, intel_plane->plane,
+					       intel_plane->pipe);
+
+	return 0;
+}
+
+static void intel_primary_plane_destroy(struct drm_plane *plane)
+{
+	struct intel_plane *intel_plane = to_intel_plane(plane);
+	intel_primary_plane_disable(plane);
+	drm_plane_cleanup(plane);
+	kfree(intel_plane);
+}
+
+static const struct drm_plane_funcs intel_primary_plane_funcs = {
+	.update_plane = intel_primary_plane_setplane,
+	.disable_plane = intel_primary_plane_disable,
+	.destroy = intel_primary_plane_destroy,
+};
+
+static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
+						    int pipe)
+{
+	struct intel_plane *primary;
+
+	primary = kzalloc(sizeof(*primary), GFP_KERNEL);

drivers/gpu/drm/i915/intel_display.c static void intel_shared_dpll_init(struct drm_device *dev) · line 10708

Quoted 10 lines
drivers/gpu/drm/i915/intel_display.c +10 -0
+	if (primary == NULL)
+		return NULL;
+
+	primary->can_scale = false;
+	primary->pipe = pipe;
+	primary->plane = pipe;
+
+	drm_plane_init(dev, &primary->base, 0,
+		       &intel_primary_plane_funcs, legacy_modeset_formats,
+		       ARRAY_SIZE(legacy_modeset_formats),

We need our own proper format list for primary planes - we don't support yuv and other crazy stuff like that on them. Also since we can now expose this, I think we should have per-platform lists. E.g. only gen2/3 support xrgb1555 and only gen4+ support xrgb2101010. Our framebuffer creation code has all the limits properly encoded atm.

Quoted 47 lines
drivers/gpu/drm/i915/intel_display.c +12 -3
+		       DRM_PLANE_TYPE_PRIMARY);
+	return &primary->base;
+}
+
 static void intel_crtc_init(struct drm_device *dev, int pipe)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc;
 	struct drm_plane *primary;
-	int i;
+	int i, ret;
 
 	intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
 	if (intel_crtc == NULL)
 		return;
 
-	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, &intel_crtc->base, primary, &intel_crtc_funcs);
+	primary = intel_primary_plane_create(dev, pipe);
+	ret = drm_crtc_init(dev, &intel_crtc->base, primary, &intel_crtc_funcs);
+	if (ret) {
+		drm_crtc_cleanup(&intel_crtc->base);
+		kfree(intel_crtc);
+		return;
+	}
 
 	drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256);
 	for (i = 0; i < 256; i++) {
drivers/gpu/drm/i915/intel_drv.h +1 -0
index 890c5cd..770f80d 100644
@@ -351,6 +351,7 @@ struct intel_crtc {
 	bool active;
 	unsigned long enabled_power_domains;
 	bool eld_vld;
+	struct intel_plane *primary_plane;
 	bool primary_enabled; /* is the primary plane (partially) visible? */
 	bool lowfreq_avail;
 	struct intel_overlay *overlay;
Signature · 6 lines
1.8.5.1

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#35 lore raw

Re: [RFCv3 11/14] drm/i915: Intel-specific primary plane handling

Quoted 15 lines · Daniel Vetter
Quoted 5 lines · Matt Roper

Intel hardware allows the primary plane to be disabled independently of the CRTC. Provide custom primary plane handling to allow this.

Cc Intel Graphics Development <[email protected]>

Overall this is imo a new feature since it exposes primary plane disabling to userspace. Which means I want a crc based igt for this. Two interesting cases imo:

1) Partially visible primary plane behind an overlay plane. Disabling it should change those areas from the primary plane to grey or something, so easy to check with CRCs.

Quoted 5 lines

2) Primary plane + cursor, disable primary plane. Then check that the cursor is still working. Same for overlay sprites.

At least on all currently supported platforms we don't have unified planes in the hardware, so imo it's worth to check that this works properly.

One big reason I've forgotten why I really want testcase for this is that historically our code has fallen over in _really_ bad ways without a primary fb. fastboot has brought a lot of these issues to light (since we occasionally fail to wrap up the firmware's fb properly). So having a bit of a baseline testcase so that we can easily add regression tests for specific bugs once we inevitably run into them is good prep work, too. -Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
author
#36 lore raw

RFC v3 12/14 drm: Specify cursor plane at CRTC initialization

In reply to Matt Roper

Add cursor plane as a parameter to drm_crtc_init() and update all existing DRM drivers to use a helper-provided primary plane. Passing NULL for this parameter indicates that there is no hardware cursor supported by the driver and no cursor plane should be provided to userspace.

---
 drivers/gpu/drm/armada/armada_crtc.c       | 2 +-
 drivers/gpu/drm/ast/ast_mode.c             | 2 +-
 drivers/gpu/drm/bochs/bochs_kms.c          | 2 +-
 drivers/gpu/drm/cirrus/cirrus_mode.c       | 3 ++-
 drivers/gpu/drm/drm_crtc.c                 | 6 ++++++
 drivers/gpu/drm/exynos/exynos_drm_crtc.c   | 2 +-
 drivers/gpu/drm/gma500/psb_intel_display.c | 3 ++-
 drivers/gpu/drm/i915/intel_display.c       | 3 ++-
 drivers/gpu/drm/mgag200/mgag200_mode.c     | 3 ++-
 drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c   | 2 +-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c   | 2 +-
 drivers/gpu/drm/nouveau/dispnv04/crtc.c    | 2 +-
 drivers/gpu/drm/nouveau/nv50_display.c     | 2 +-
 drivers/gpu/drm/omapdrm/omap_crtc.c        | 2 +-
 drivers/gpu/drm/qxl/qxl_display.c          | 2 +-
 drivers/gpu/drm/radeon/radeon_display.c    | 3 ++-
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c     | 2 +-
 drivers/gpu/drm/shmobile/shmob_drm_crtc.c  | 2 +-
 drivers/gpu/drm/tegra/dc.c                 | 2 +-
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c       | 2 +-
 drivers/gpu/drm/udl/udl_modeset.c          | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c        | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c       | 2 +-
 drivers/staging/imx-drm/imx-drm-core.c     | 2 +-
 include/drm/drm_crtc.h                     | 6 ++++++
 25 files changed, 40 insertions(+), 23 deletions(-)
drivers/gpu/drm/armada/armada_crtc.c +1 -1
index 0a14d24..a6eec51 100644
@@ -1088,7 +1088,7 @@ int armada_drm_crtc_create(struct drm_device *dev, unsigned num,
 	priv->dcrtc[dcrtc->num] = dcrtc;
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, &dcrtc->crtc, primary, &armada_crtc_funcs);
+	drm_crtc_init(dev, &dcrtc->crtc, primary, NULL, &armada_crtc_funcs);
 	drm_crtc_helper_add(&dcrtc->crtc, &armada_crtc_helper_funcs);
 
 	drm_object_attach_property(&dcrtc->crtc.base, priv->csc_yuv_prop,
drivers/gpu/drm/ast/ast_mode.c +1 -1
index bd1e156..52415ca 100644
@@ -634,7 +634,7 @@ static int ast_crtc_init(struct drm_device *dev)
 		return -ENOMEM;
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, &crtc->base, primary, &ast_crtc_funcs);
+	drm_crtc_init(dev, &crtc->base, primary, NULL, &ast_crtc_funcs);
 	drm_mode_crtc_set_gamma_size(&crtc->base, 256);
 	drm_crtc_helper_add(&crtc->base, &ast_crtc_helper_funcs);
 
drivers/gpu/drm/bochs/bochs_kms.c +1 -1
index b67ad12..e88101a 100644
@@ -132,7 +132,7 @@ static void bochs_crtc_init(struct drm_device *dev)
 	struct drm_plane *primary;
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, crtc, primary, &bochs_crtc_funcs);
+	drm_crtc_init(dev, crtc, primary, NULL, &bochs_crtc_funcs);
 	drm_mode_crtc_set_gamma_size(crtc, 256);
 	drm_crtc_helper_add(crtc, &bochs_helper_funcs);
 }
drivers/gpu/drm/cirrus/cirrus_mode.c +2 -1
index 5291d2f..04a002b 100644
@@ -392,7 +392,8 @@ static void cirrus_crtc_init(struct drm_device *dev)
 		return;
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, &cirrus_crtc->base, primary, &cirrus_crtc_funcs);
+	drm_crtc_init(dev, &cirrus_crtc->base, primary, NULL,
+		      &cirrus_crtc_funcs);
 
 	drm_mode_crtc_set_gamma_size(&cirrus_crtc->base, CIRRUS_LUT_SIZE);
 	cdev->mode_info.crtc = cirrus_crtc;
drivers/gpu/drm/drm_crtc.c +6 -0
index fb8e493..e6e1f39 100644
@@ -683,6 +683,7 @@ EXPORT_SYMBOL(drm_framebuffer_remove);
  * @dev: DRM device
  * @crtc: CRTC object to init
  * @primary: Primary plane for CRTC
+ * @cursor: Cursor plane for CRTC; may be NULL if no hardware cursor exists
  * @funcs: callbacks for the new CRTC
  *
  * Inits a new object created as base part of a driver crtc object.
@@ -692,6 +693,7 @@ EXPORT_SYMBOL(drm_framebuffer_remove);
  */
 int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
 		  struct drm_plane *primary,
+		  struct drm_plane *cursor,
 		  const struct drm_crtc_funcs *funcs)
 {
 	int ret;
@@ -716,6 +718,10 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
 	crtc->primary = primary;
 	primary->possible_crtcs = 1 << drm_crtc_index(crtc);
 
+	crtc->cursor = cursor;
+	if (cursor)
+		cursor->possible_crtcs = 1 << drm_crtc_index(crtc);
+
  out:
 	drm_modeset_unlock_all(dev);
 
drivers/gpu/drm/exynos/exynos_drm_crtc.c +1 -1
index 507abd5..a17eb1d 100644
@@ -344,7 +344,7 @@ int exynos_drm_crtc_create(struct drm_device *dev, unsigned int nr)
 	private->crtc[nr] = crtc;
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, crtc, primary, &exynos_crtc_funcs);
+	drm_crtc_init(dev, crtc, primary, NULL, &exynos_crtc_funcs);
 	drm_crtc_helper_add(crtc, &exynos_crtc_helper_funcs);
 
 	exynos_drm_crtc_attach_mode_property(crtc);
drivers/gpu/drm/gma500/psb_intel_display.c +2 -1
index 25c174c..26a363e 100644
@@ -513,7 +513,8 @@ void psb_intel_crtc_init(struct drm_device *dev, int pipe,
 
 	/* Set the CRTC operations from the chip specific data */
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, &gma_crtc->base, primary, dev_priv->ops->crtc_funcs);
+	drm_crtc_init(dev, &gma_crtc->base, primary, NULL,
+		      dev_priv->ops->crtc_funcs);
 
 	/* Set the CRTC clock functions from chip specific data */
 	gma_crtc->clock_funcs = dev_priv->ops->clock_funcs;
drivers/gpu/drm/i915/intel_display.c +2 -1
index 7d6878b..d43b31d 100644
@@ -10722,7 +10722,8 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
 		return;
 
 	primary = intel_primary_plane_create(dev, pipe);
-	ret = drm_crtc_init(dev, &intel_crtc->base, primary, &intel_crtc_funcs);
+	ret = drm_crtc_init(dev, &intel_crtc->base, primary, NULL,
+			    &intel_crtc_funcs);
 	if (ret) {
 		drm_crtc_cleanup(&intel_crtc->base);
 		kfree(intel_crtc);
drivers/gpu/drm/mgag200/mgag200_mode.c +2 -1
index f8c42b1..befa249 100644
@@ -1327,7 +1327,8 @@ static void mga_crtc_init(struct mga_device *mdev)
 		return;
 
 	primary = drm_primary_helper_create_plane(mdev->dev);
-	drm_crtc_init(mdev->dev, &mga_crtc->base, primary, &mga_crtc_funcs);
+	drm_crtc_init(mdev->dev, &mga_crtc->base, primary, NULL,
+		      &mga_crtc_funcs);
 
 	drm_mode_crtc_set_gamma_size(&mga_crtc->base, MGAG200_LUT_SIZE);
 	mdev->mode_info.crtc = mga_crtc;
drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c +1 -1
index f96497b..2dcd224 100644
@@ -794,7 +794,7 @@ struct drm_crtc *mdp4_crtc_init(struct drm_device *dev,
 
 	INIT_FENCE_CB(&mdp4_crtc->pageflip_cb, pageflip_cb);
 
-	drm_crtc_init(dev, crtc, plane, &mdp4_crtc_funcs);
+	drm_crtc_init(dev, crtc, plane, NULL, &mdp4_crtc_funcs);
 	drm_crtc_helper_add(crtc, &mdp4_crtc_helper_funcs);
 
 	mdp4_plane_install_properties(mdp4_crtc->plane, &crtc->base);
drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c +1 -1
index f200048..e74751f 100644
@@ -562,7 +562,7 @@ struct drm_crtc *mdp5_crtc_init(struct drm_device *dev,
 
 	INIT_FENCE_CB(&mdp5_crtc->pageflip_cb, pageflip_cb);
 
-	drm_crtc_init(dev, crtc, plane, &mdp5_crtc_funcs);
+	drm_crtc_init(dev, crtc, plane, NULL, &mdp5_crtc_funcs);
 	drm_crtc_helper_add(crtc, &mdp5_crtc_helper_funcs);
 
 	mdp5_plane_install_properties(mdp5_crtc->plane, &crtc->base);
drivers/gpu/drm/nouveau/dispnv04/crtc.c +1 -1
index 2a5e9db..974babe 100644
@@ -1124,7 +1124,7 @@ nv04_crtc_create(struct drm_device *dev, int crtc_num)
 	nv_crtc->last_dpms = NV_DPMS_CLEARED;
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, &nv_crtc->base, primary, &nv04_crtc_funcs);
+	drm_crtc_init(dev, &nv_crtc->base, primary, NULL, &nv04_crtc_funcs);
 	drm_crtc_helper_add(&nv_crtc->base, &nv04_crtc_helper_funcs);
 	drm_mode_crtc_set_gamma_size(&nv_crtc->base, 256);
 
drivers/gpu/drm/nouveau/nv50_display.c +1 -1
index c744bf6..b1cc440 100644
@@ -1372,7 +1372,7 @@ nv50_crtc_create(struct drm_device *dev, struct nouveau_object *core, int index)
 
 	crtc = &head->base.base;
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, crtc, primary, &nv50_crtc_func);
+	drm_crtc_init(dev, crtc, primary, NULL, &nv50_crtc_func);
 	drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
 	drm_mode_crtc_set_gamma_size(crtc, 256);
 
drivers/gpu/drm/omapdrm/omap_crtc.c +1 -1
index fdf9dc0..9623c6f 100644
@@ -677,7 +677,7 @@ struct drm_crtc *omap_crtc_init(struct drm_device *dev,
 	info->trans_key_type = OMAP_DSS_COLOR_KEY_GFX_DST;
 	info->trans_enabled = false;
 
-	drm_crtc_init(dev, crtc, plane, &omap_crtc_funcs);
+	drm_crtc_init(dev, crtc, plane, NULL, &omap_crtc_funcs);
 	drm_crtc_helper_add(crtc, &omap_crtc_helper_funcs);
 
 	omap_plane_install_properties(omap_crtc->plane, &crtc->base);
drivers/gpu/drm/qxl/qxl_display.c +1 -1
index 5be0b87..50ad5fc 100644
@@ -644,7 +644,7 @@ static int qdev_crtc_init(struct drm_device *dev, int crtc_id)
 		return -ENOMEM;
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, &qxl_crtc->base, primary, &qxl_crtc_funcs);
+	drm_crtc_init(dev, &qxl_crtc->base, primary, NULL, &qxl_crtc_funcs);
 	qxl_crtc->index = crtc_id;
 	drm_mode_crtc_set_gamma_size(&qxl_crtc->base, 256);
 	drm_crtc_helper_add(&qxl_crtc->base, &qxl_crtc_helper_funcs);
drivers/gpu/drm/radeon/radeon_display.c +2 -1
index 4e90049..1ef84c5 100644
@@ -560,7 +560,8 @@ static void radeon_crtc_init(struct drm_device *dev, int index)
 		return;
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, &radeon_crtc->base, primary, &radeon_crtc_funcs);
+	drm_crtc_init(dev, &radeon_crtc->base, primary, NULL,
+		      &radeon_crtc_funcs);
 
 	drm_mode_crtc_set_gamma_size(&radeon_crtc->base, 256);
 	radeon_crtc->crtc_id = index;
drivers/gpu/drm/rcar-du/rcar_du_crtc.c +1 -1
index 151ffaa..dca3c4c 100644
@@ -570,7 +570,7 @@ int rcar_du_crtc_create(struct rcar_du_group *rgrp, unsigned int index)
 	rcrtc->plane->crtc = crtc;
 
 	primary = drm_primary_helper_create_plane(dev);
-	ret = drm_crtc_init(rcdu->ddev, crtc, primary, &crtc_funcs);
+	ret = drm_crtc_init(rcdu->ddev, crtc, primary, NULL, &crtc_funcs);
 	if (ret < 0)
 		return ret;
 
drivers/gpu/drm/shmobile/shmob_drm_crtc.c +1 -1
index e806553..dedbd33 100644
@@ -517,7 +517,7 @@ int shmob_drm_crtc_create(struct shmob_drm_device *sdev)
 
 	sdev->crtc.dpms = DRM_MODE_DPMS_OFF;
 
-	ret = drm_crtc_init(sdev->ddev, crtc, primary, &crtc_funcs);
+	ret = drm_crtc_init(sdev->ddev, crtc, primary, NULL, &crtc_funcs);
 	if (ret < 0)
 		return ret;
 
drivers/gpu/drm/tegra/dc.c +1 -1
index 5e2ee9d..3b2e73f 100644
@@ -1103,7 +1103,7 @@ static int tegra_dc_init(struct host1x_client *client)
 	int err;
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(tegra->drm, &dc->base, primary, &tegra_crtc_funcs);
+	drm_crtc_init(tegra->drm, &dc->base, primary, NULL, &tegra_crtc_funcs);
 	drm_mode_crtc_set_gamma_size(&dc->base, 256);
 	drm_crtc_helper_add(&dc->base, &tegra_crtc_helper_funcs);
 
drivers/gpu/drm/tilcdc/tilcdc_crtc.c +1 -1
index 310314c..002c88c 100644
@@ -673,7 +673,7 @@ struct drm_crtc *tilcdc_crtc_create(struct drm_device *dev)
 	}
 
 	primary = drm_primary_helper_create_plane(dev);
-	ret = drm_crtc_init(dev, crtc, primary, &tilcdc_crtc_funcs);
+	ret = drm_crtc_init(dev, crtc, primary, NULL, &tilcdc_crtc_funcs);
 	if (ret < 0)
 		goto fail;
 
drivers/gpu/drm/udl/udl_modeset.c +1 -1
index c63b5e7..9490cf5 100644
@@ -396,7 +396,7 @@ static int udl_crtc_init(struct drm_device *dev)
 		return -ENOMEM;
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, crtc, primary, &udl_crtc_funcs);
+	drm_crtc_init(dev, crtc, primary, NULL, &udl_crtc_funcs);
 	drm_crtc_helper_add(crtc, &udl_helper_funcs);
 
 	return 0;
drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c +1 -1
index 08fdd7f..07888c5 100644
@@ -375,7 +375,7 @@ static int vmw_ldu_init(struct vmw_private *dev_priv, unsigned unit)
 	(void) drm_sysfs_connector_add(connector);
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, crtc, primary, &vmw_legacy_crtc_funcs);
+	drm_crtc_init(dev, crtc, primary, NULL, &vmw_legacy_crtc_funcs);
 
 	drm_mode_crtc_set_gamma_size(crtc, 256);
 
drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c +1 -1
index 46ea096..b1ad841 100644
@@ -471,7 +471,7 @@ static int vmw_sou_init(struct vmw_private *dev_priv, unsigned unit)
 	(void) drm_sysfs_connector_add(connector);
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(dev, crtc, primary, &vmw_screen_object_crtc_funcs);
+	drm_crtc_init(dev, crtc, primary, NULL, &vmw_screen_object_crtc_funcs);
 
 	drm_mode_crtc_set_gamma_size(crtc, 256);
 
drivers/staging/imx-drm/imx-drm-core.c +1 -1
index 8c7b1d3..0710196 100644
@@ -522,7 +522,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
 			imx_drm_crtc->imx_drm_helper_funcs.crtc_helper_funcs);
 
 	primary = drm_primary_helper_create_plane(dev);
-	drm_crtc_init(imxdrm->drm, crtc, primary,
+	drm_crtc_init(imxdrm->drm, crtc, primary, NULL,
 			imx_drm_crtc->imx_drm_helper_funcs.crtc_funcs);
 
 	drm_mode_group_reinit(imxdrm->drm);
include/drm/drm_crtc.h +6 -0
index 9f7824d..1c9704b 100644
@@ -271,6 +271,8 @@ struct drm_crtc_funcs {
  * @head: list management
  * @base: base KMS object for ID tracking etc.
  * @primary: primary plane for this CRTC
+ * @cursor: cursor plane for this CRTC; may be NULL if no cursor
+ *    is supported
  * @enabled: is this CRTC enabled?
  * @mode: current mode timings
  * @hwmode: mode timings as programmed to hw regs
@@ -309,6 +311,9 @@ struct drm_crtc {
 	/* primary plane for CRTC */
 	struct drm_plane *primary;
 
+	/* cursor plane for CRTC */
+	struct drm_plane *cursor;
+
 	/* Temporary tracking of the old fb while a modeset is ongoing. Used
 	 * by drm_mode_set_config_internal to implement correct refcounting. */
 	struct drm_framebuffer *old_fb;
@@ -909,6 +914,7 @@ extern void drm_warn_on_modeset_not_all_locked(struct drm_device *dev);
 extern int drm_crtc_init(struct drm_device *dev,
 			 struct drm_crtc *crtc,
 			 struct drm_plane *primary,
+			 struct drm_plane *cursor,
 			 const struct drm_crtc_funcs *funcs);
 extern void drm_crtc_cleanup(struct drm_crtc *crtc);
 extern unsigned int drm_crtc_index(struct drm_crtc *crtc);
Signature · 1 line
1.8.5.1
#37 lore raw

Re: [RFCv3 12/14] drm: Specify cursor plane at CRTC initialization

Quoted 7 lines · Matt Roper

Add cursor plane as a parameter to drm_crtc_init() and update all existing DRM drivers to use a helper-provided primary plane. Passing NULL for this parameter indicates that there is no hardware cursor supported by the driver and no cursor plane should be provided to userspace.

Ok, cursor planes. I've poked around in this a lot and unfortunately I don't think we can achieve nirvana :(

The first direction is automatically getting cursor plane support from existing drivers using the existing callbacks. The irky thing is that we don't have any means to sanely unwrap the framebuffer since both the bo handle used by the legacy cursor ioctl and how a framebuffer would wrap such a handle isn't generic. And e.g. vmwgfx doesn't even use gem for those.

So I think we'll have to give up on that and drivers which want to expose cursors with the atomic ioctls simply have to have proper support.

The other direction is that converted drivers don't need to have support for legacy ioctls should be possible and is imo something we want - at least for i915 I don't want to carry around two interfaces doing the same.

Which means we need some way to forward the legacy cursor ioctls to the new plane callbacks exposed when using cursor planes. Unfortunately we have a bit an api mismatch between the legacy cursor interfaces:

int (*cursor_set2)(struct drm_crtc *crtc, struct drm_file *file_priv,

		   uint32_t handle, uint32_t width, uint32_t height,
		   int32_t hot_x, int32_t hot_y);

int (*cursor_move)(struct drm_crtc *crtc, int x, int y);

And the plane interfaces:

int (*update_plane)(struct drm_plane *plane,
struct drm_crtc *crtc, struct drm_framebuffer *fb, int crtc_x, int crtc_y,
unsigned int crtc_w, unsigned int crtc_h, uint32_t src_x, uint32_t src_y, uint32_t src_w, uint32_t src_h);
int (*disable_plane)(struct drm_plane *plane);

cursor_set2 with handle == 0 simply maps to a disable_plane call. But any other call of the legacy ioctls simply maps to an update_plane, but we don't have all the information available all the time.

- width, height and handle isn't a real concern - we can just wrap this all up into a drm private drm framebuffer. As long as the only reference to that framebuffer is held by crtc->cursor->fb it will also get cleaned up at the right time and so won't extend the lifetime of the underlying buffer object. And we don't need to cache width/height anywhere since they're accessible through crtc->cursor->fb.

- For the pixel format I think it's ok to always assume RGBA.

- hot_x and hot_y can simply be mapped to new plane properties. I think it'd be good for this to be generally available, just to have a consistent interface.

- The x/y coordinates of cursor_move are more annoying - userspace potentially doesn't supply them, so we need to cache them in the crtc struct somewhere. Originally I've thought it would be good to have a special struct drm_cursor_plane and use that as the blessed cursor plane object in drm_crtc_init_with_planes. But that will wreak havoc with hw platforms which have fully unified planes and want to use the same struct everywhere. So I think we need to add crtc->cursor_x/y fields.

With these bits we should be able to always create a valid call to update_plane. Which allows drivers to not implement the legacy cursor_set/move interface. Of course we also need to go through the drm core to make sure that all the cursor code also works when crtc->cursor is set.

To make driver writers life as easy as possible I think we should provide a default helper for their cursor_update_plane callback which checks that the update_plane call is indeed valid for a cursor:

- Checks that widht == pitch*bpp since that's what we assume with cursors.

- Checks that there's no scaling going on.

- Checks that the viewport matches the full cursor size.

- Checks that there's no subpixel positioning.

With that the only thing drivers need to do is:
- Kill the handle to bo pointer lookup, just use the one wrapped up in the framebuffer object.
- Call the above helper.
- Call into the low-level set_cursor_bo/move_cursor functions - all the arguments of the old ioctls have a 1:1 mapping in update_plane, so this should be simple.

... and of course they need to set up the cursor plane object.

Cheers, Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#38 lore raw

Re: [RFCv3 12/14] drm: Specify cursor plane at CRTC initialization

Quoted 11 lines · Daniel Vetter
Quoted 7 lines · Matt Roper

Add cursor plane as a parameter to drm_crtc_init() and update all existing DRM drivers to use a helper-provided primary plane. Passing NULL for this parameter indicates that there is no hardware cursor supported by the driver and no cursor plane should be provided to userspace.

Ok, cursor planes. I've poked around in this a lot and unfortunately I don't think we can achieve nirvana :(

[...]

Quoted 1 line

- For the pixel format I think it's ok to always assume RGBA.

How so? We do have hardware on Tegra that doesn't support RGBA cursors and if at all possible I'd very much like to support that as well. New generations can do RGBA but still support the old pixel format. Having the option of supporting all formats would be nice.

There was some discussion about implementing a bunch of plane properties so I think having one to enumerate a set of pixel formats wouldn't be such a big deal.

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#39 lore raw

Re: [RFCv3 12/14] drm: Specify cursor plane at CRTC initialization

Quoted 15 lines · Thierry Reding
Quoted 11 lines · Daniel Vetter
Quoted 7 lines · Matt Roper

Add cursor plane as a parameter to drm_crtc_init() and update all existing DRM drivers to use a helper-provided primary plane. Passing NULL for this parameter indicates that there is no hardware cursor supported by the driver and no cursor plane should be provided to userspace.

Ok, cursor planes. I've poked around in this a lot and unfortunately I don't think we can achieve nirvana :(

[...]

Quoted 1 line

- For the pixel format I think it's ok to always assume RGBA.

Quoted 8 lines

How so? We do have hardware on Tegra that doesn't support RGBA cursors and if at all possible I'd very much like to support that as well. New generations can do RGBA but still support the old pixel format. Having the option of supporting all formats would be nice.

There was some discussion about implementing a bunch of plane properties so I think having one to enumerate a set of pixel formats wouldn't be such a big deal.

No need for properties to expose formats, we already have that in getplane ioctl. But would be nice to support more than just RGBA.

BR,
-R

Quoted 7 lines

Thierry

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#40 lore raw

Re: [RFCv3 12/14] drm: Specify cursor plane at CRTC initialization

Quoted 21 lines · Rob Clark
Quoted 20 lines · Thierry Reding
Quoted 11 lines · Daniel Vetter
Quoted 7 lines · Matt Roper

Add cursor plane as a parameter to drm_crtc_init() and update all existing DRM drivers to use a helper-provided primary plane. Passing NULL for this parameter indicates that there is no hardware cursor supported by the driver and no cursor plane should be provided to userspace.

Ok, cursor planes. I've poked around in this a lot and unfortunately I don't think we can achieve nirvana :(

[...]

Quoted 1 line

- For the pixel format I think it's ok to always assume RGBA.

How so? We do have hardware on Tegra that doesn't support RGBA cursors and if at all possible I'd very much like to support that as well. New generations can do RGBA but still support the old pixel format. Having the option of supporting all formats would be nice.

Quoted 6 lines
Quoted 3 lines

There was some discussion about implementing a bunch of plane properties so I think having one to enumerate a set of pixel formats wouldn't be such a big deal.

No need for properties to expose formats, we already have that in getplane ioctl. But would be nice to support more than just RGBA.

This is _just_ for the compat cursor plane setup helper. Of course we can add whatever insane cursor formats exist out there as fourcc codes and then drivers can add them for their custom-created cursor planes. This is similar to the current primary plane helper code which only exposes 32bit XRGB atm. If you want to take full advantage of this you need to do a bit of work in your driver ;-)
-Daniel

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
#41 lore raw

Re: [RFCv3 12/14] drm: Specify cursor plane at CRTC initialization

Quoted 29 lines · Daniel Vetter
Quoted 21 lines · Rob Clark
Quoted 20 lines · Thierry Reding
Quoted 11 lines · Daniel Vetter
Quoted 7 lines · Matt Roper

Add cursor plane as a parameter to drm_crtc_init() and update all existing DRM drivers to use a helper-provided primary plane. Passing NULL for this parameter indicates that there is no hardware cursor supported by the driver and no cursor plane should be provided to userspace.

Ok, cursor planes. I've poked around in this a lot and unfortunately I don't think we can achieve nirvana :(

[...]

Quoted 1 line

- For the pixel format I think it's ok to always assume RGBA.

How so? We do have hardware on Tegra that doesn't support RGBA cursors and if at all possible I'd very much like to support that as well. New generations can do RGBA but still support the old pixel format. Having the option of supporting all formats would be nice.

Quoted 6 lines
Quoted 3 lines

There was some discussion about implementing a bunch of plane properties so I think having one to enumerate a set of pixel formats wouldn't be such a big deal.

No need for properties to expose formats, we already have that in getplane ioctl. But would be nice to support more than just RGBA.

Quoted 6 lines

This is _just_ for the compat cursor plane setup helper. Of course we can add whatever insane cursor formats exist out there as fourcc codes and then drivers can add them for their custom-created cursor planes. This is similar to the current primary plane helper code which only exposes 32bit XRGB atm. If you want to take full advantage of this you need to do a bit of work in your driver ;-)

oh, heh.. should have read the whole thread first :-P

yeah, for compat helpers, only ARGB makes sense

BR,
-R

Quoted 5 lines

-Daniel
--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

author
#42 lore raw

RFC v3 13/14 drm/i915: Split cursor update code from cursor ioctl handling

In reply to Matt Roper

Legacy cursor ioctls took GEM buffer handles from userspace directly whereas the new unified plane handling assigns drm_framebuffer's to cursor planes. Splitting the code that actually updates the cursor plane from the code that handles object lookup and reference counting allows us to share common code between both interfaces.

Cc Intel Graphics Development <[email protected]>
---
 drivers/gpu/drm/i915/intel_display.c | 197 ++++++++++++++++++++++++-----------
 drivers/gpu/drm/i915/intel_drv.h     |   2 -
 2 files changed, 134 insertions(+), 65 deletions(-)
drivers/gpu/drm/i915/intel_display.c +134 -63
index d43b31d..f661469 100644
@@ -43,7 +43,8 @@
 #include <linux/dma_remapping.h>
 
 static void intel_increase_pllclock(struct drm_crtc *crtc);
-static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on);
+static void intel_crtc_update_cursor(struct drm_crtc *crtc,
+				     struct drm_framebuffer *fb);
 
 static void i9xx_crtc_clock_get(struct intel_crtc *crtc,
 				struct intel_crtc_config *pipe_config);
@@ -56,6 +57,11 @@ static int intel_framebuffer_init(struct drm_device *dev,
 				  struct intel_framebuffer *ifb,
 				  struct drm_mode_fb_cmd2 *mode_cmd,
 				  struct drm_i915_gem_object *obj);
+static struct drm_framebuffer *
+intel_user_framebuffer_create(struct drm_device *dev,
+			      struct drm_file *filp,
+			      struct drm_mode_fb_cmd2 *mode_cmd);
+static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb);
 
 typedef struct {
 	int	min, max;
@@ -3709,7 +3715,7 @@ static void ironlake_crtc_enable(struct drm_crtc *crtc)
 	intel_enable_pipe(intel_crtc);
 	intel_enable_primary_hw_plane(dev_priv, plane, pipe);
 	intel_enable_planes(crtc);
-	intel_crtc_update_cursor(crtc, true);
+	intel_crtc_update_cursor(crtc, crtc->cursor->fb);
 
 	if (intel_crtc->config.has_pch_encoder)
 		ironlake_pch_enable(crtc);
@@ -3753,7 +3759,7 @@ static void haswell_crtc_enable_planes(struct drm_crtc *crtc)
 
 	intel_enable_primary_hw_plane(dev_priv, plane, pipe);
 	intel_enable_planes(crtc);
-	intel_crtc_update_cursor(crtc, true);
+	intel_crtc_update_cursor(crtc, crtc->cursor->fb);
 
 	hsw_enable_ips(intel_crtc);
 
@@ -3781,7 +3787,7 @@ static void haswell_crtc_disable_planes(struct drm_crtc *crtc)
 
 	hsw_disable_ips(intel_crtc);
 
-	intel_crtc_update_cursor(crtc, false);
+	intel_crtc_update_cursor(crtc, NULL);
 	intel_disable_planes(crtc);
 	intel_disable_primary_hw_plane(dev_priv, plane, pipe);
 }
@@ -3909,7 +3915,7 @@ static void ironlake_crtc_disable(struct drm_crtc *crtc)
 	if (dev_priv->fbc.plane == plane)
 		intel_disable_fbc(dev);
 
-	intel_crtc_update_cursor(crtc, false);
+	intel_crtc_update_cursor(crtc, NULL);
 	intel_disable_planes(crtc);
 	intel_disable_primary_hw_plane(dev_priv, plane, pipe);
 
@@ -4396,7 +4402,7 @@ static void valleyview_crtc_enable(struct drm_crtc *crtc)
 	intel_set_cpu_fifo_underrun_reporting(dev, pipe, true);
 	intel_enable_primary_hw_plane(dev_priv, plane, pipe);
 	intel_enable_planes(crtc);
-	intel_crtc_update_cursor(crtc, true);
+	intel_crtc_update_cursor(crtc, crtc->cursor->fb);
 
 	intel_update_fbc(dev);
 
@@ -4440,7 +4446,7 @@ static void i9xx_crtc_enable(struct drm_crtc *crtc)
 	/* The fixup needs to happen before cursor is enabled */
 	if (IS_G4X(dev))
 		g4x_fixup_plane(dev_priv, pipe);
-	intel_crtc_update_cursor(crtc, true);
+	intel_crtc_update_cursor(crtc, crtc->cursor->fb);
 
 	/* Give the overlay scaler a chance to enable if it's on this pipe */
 	intel_crtc_dpms_overlay(intel_crtc, true);
@@ -4491,7 +4497,7 @@ static void i9xx_crtc_disable(struct drm_crtc *crtc)
 		intel_disable_fbc(dev);
 
 	intel_crtc_dpms_overlay(intel_crtc, false);
-	intel_crtc_update_cursor(crtc, false);
+	intel_crtc_update_cursor(crtc, NULL);
 	intel_disable_planes(crtc);
 	intel_disable_primary_hw_plane(dev_priv, plane, pipe);
 
@@ -7739,7 +7745,7 @@ static void ivb_update_cursor(struct drm_crtc *crtc, u32 base)
 
 /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */
 static void intel_crtc_update_cursor(struct drm_crtc *crtc,
-				     bool on)
+				     struct drm_framebuffer *fb)
 {
 	struct drm_device *dev = crtc->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
@@ -7750,32 +7756,36 @@ static void intel_crtc_update_cursor(struct drm_crtc *crtc,
 	u32 base = 0, pos = 0;
 	bool visible;
 
-	if (on)
-		base = intel_crtc->cursor_addr;
+	if (!intel_crtc->active)
+		return;
 
-	if (x >= intel_crtc->config.pipe_src_w)
-		base = 0;
+	if (fb != NULL) {
+		base = intel_crtc->cursor_addr;
 
-	if (y >= intel_crtc->config.pipe_src_h)
-		base = 0;
+		if (x >= intel_crtc->config.pipe_src_w)
+			base = 0;
 
-	if (x < 0) {
-		if (x + intel_crtc->cursor_width <= 0)
+		if (y >= intel_crtc->config.pipe_src_h)
 			base = 0;
 
-		pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
-		x = -x;
-	}
-	pos |= x << CURSOR_X_SHIFT;
+		if (x < 0) {
+			if (x + fb->width <= 0)
+				base = 0;
 
-	if (y < 0) {
-		if (y + intel_crtc->cursor_height <= 0)
-			base = 0;
+			pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT;
+			x = -x;
+		}
+		pos |= x << CURSOR_X_SHIFT;
 
-		pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
-		y = -y;
+		if (y < 0) {
+			if (y + fb->height <= 0)
+				base = 0;
+
+			pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT;
+			y = -y;
+		}
+		pos |= y << CURSOR_Y_SHIFT;
 	}
-	pos |= y << CURSOR_Y_SHIFT;
 
 	visible = base != 0;
 	if (!visible && !intel_crtc->cursor_visible)
@@ -7793,41 +7803,46 @@ static void intel_crtc_update_cursor(struct drm_crtc *crtc,
 	}
 }
 
-static int intel_crtc_cursor_set(struct drm_crtc *crtc,
-				 struct drm_file *file,
-				 uint32_t handle,
-				 uint32_t width, uint32_t height)
+/*
+ * Common cursor-setting code shared by both the legacy cursor ioctls (which
+ * take a GEM bo handle directly from userspace) and the new unified plane
+ * interface (which takes drm_framebuffer's).  By the time we get here, the
+ * desired new buffer will be in the form of a DRM framebuffer, regardless
+ * of which userspace API was used.
+ */
+static int cursor_set_common(struct drm_crtc *crtc,
+			     struct drm_plane *cursor,
+			     struct drm_framebuffer *fb)
 {
-	struct drm_device *dev = crtc->dev;
+	struct drm_device *dev = cursor->dev;
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
-	struct drm_i915_gem_object *obj;
-	uint32_t addr;
+	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
+	struct drm_i915_gem_object *obj = NULL;
+	struct drm_i915_gem_object *cursor_bo = NULL;
+	uint32_t addr = 0;
 	int ret;
 
-	/* if we want to turn off the cursor ignore width and height */
-	if (!handle) {
+	BUG_ON(cursor != crtc->cursor);
+	BUG_ON(cursor->possible_crtcs != drm_crtc_mask(crtc));
+
+	if (fb == NULL) {
 		DRM_DEBUG_KMS("cursor off\n");
-		addr = 0;
-		obj = NULL;
 		mutex_lock(&dev->struct_mutex);
 		goto finish;
 	}
 
+	obj = intel_fb->obj;
+
 	/* Currently we only support 64x64 cursors */
-	if (width != 64 || height != 64) {
+	if (fb->width != 64 || fb->height != 64) {
 		DRM_ERROR("we currently only support 64x64 cursors\n");
 		return -EINVAL;
 	}
 
-	obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle));
-	if (&obj->base == NULL)
-		return -ENOENT;
-
-	if (obj->base.size < width * height * 4) {
-		DRM_DEBUG_KMS("buffer is to small\n");
-		ret = -ENOMEM;
-		goto fail;
+	if (obj->base.size < fb->width * fb->height * 4) {
+		DRM_DEBUG_KMS("Cursor buffer is too small\n");
+		return -ENOMEM;
 	}
 
 	/* we only need to pin inside GTT if cursor is non-phy */
@@ -7876,35 +7891,87 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc,
 	}
 
 	if (IS_GEN2(dev))
-		I915_WRITE(CURSIZE, (height << 12) | width);
+		I915_WRITE(CURSIZE, (fb->height << 12) | fb->width);
 
- finish:
-	if (intel_crtc->cursor_bo) {
+finish:
+	if (cursor->fb) {
+		cursor_bo = to_intel_framebuffer(cursor->fb)->obj;
 		if (INTEL_INFO(dev)->cursor_needs_physical) {
-			if (intel_crtc->cursor_bo != obj)
-				i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo);
+			if (cursor_bo != obj)
+				i915_gem_detach_phys_object(dev, cursor_bo);
 		} else
-			i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo);
-		drm_gem_object_unreference(&intel_crtc->cursor_bo->base);
+			i915_gem_object_unpin_from_display_plane(cursor_bo);
 	}
 
 	mutex_unlock(&dev->struct_mutex);
 
 	intel_crtc->cursor_addr = addr;
-	intel_crtc->cursor_bo = obj;
-	intel_crtc->cursor_width = width;
-	intel_crtc->cursor_height = height;
-
-	if (intel_crtc->active)
-		intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
 
 	return 0;
+
 fail_unpin:
 	i915_gem_object_unpin_from_display_plane(obj);
 fail_locked:
 	mutex_unlock(&dev->struct_mutex);
-fail:
-	drm_gem_object_unreference_unlocked(&obj->base);
+	return ret;
+}
+
+static int intel_crtc_cursor_set(struct drm_crtc *crtc,
+				 struct drm_file *file,
+				 uint32_t handle,
+				 uint32_t width, uint32_t height)
+{
+	struct drm_device *dev = crtc->dev;
+	struct drm_plane *cursor = crtc->cursor;
+	struct drm_framebuffer *fb = NULL;
+	struct drm_framebuffer *old_fb = NULL;
+	struct drm_i915_gem_object *new_obj = NULL;
+	struct drm_i915_gem_object *old_obj = NULL;
+	struct drm_mode_fb_cmd2 cmd = {
+		.width = width,
+		.height = height,
+		.pixel_format = DRM_FORMAT_ARGB8888,
+	};
+	int ret = 0;
+
+	/* i915 cursor support may be disabled for debugging */
+	if (cursor == NULL)
+		return -ENXIO;
+
+	old_fb = cursor->fb;
+
+	/* Wrap the buffer handle we got in a drm framebuffer */
+	if (handle != 0) {
+		cmd.handles[0] = handle;
+		fb = intel_user_framebuffer_create(dev, file, &cmd);
+		if (IS_ERR(fb))
+			return PTR_ERR(fb);
+	}
+
+	new_obj = fb ? to_intel_framebuffer(fb)->obj : NULL;
+	old_obj = old_fb ? to_intel_framebuffer(old_fb)->obj : NULL;
+
+	/* If this buffer is already the cursor image, no work is needed */
+	if (new_obj == old_obj) {
+		DRM_DEBUG_KMS("Cursor is already set with this object\n");
+		old_fb = NULL;
+		goto done;
+	}
+
+	ret = cursor_set_common(crtc, cursor, fb);
+	if (ret != 0) {
+		old_fb = NULL;
+	} else {
+		intel_crtc_update_cursor(crtc, fb);
+		cursor->fb = fb;
+		fb = NULL;
+	}
+
+done:
+	if (fb)
+		intel_user_framebuffer_destroy(fb);
+	if (old_fb)
+		intel_user_framebuffer_destroy(old_fb);
 	return ret;
 }
 
@@ -7912,11 +7979,15 @@ static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
 {
 	struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
 
+	/* i915 cursor support may be disabled for debugging */
+	if (crtc->cursor == NULL)
+		return -ENXIO;
+
 	intel_crtc->cursor_x = clamp_t(int, x, SHRT_MIN, SHRT_MAX);
 	intel_crtc->cursor_y = clamp_t(int, y, SHRT_MIN, SHRT_MAX);
 
 	if (intel_crtc->active)
-		intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL);
+		intel_crtc_update_cursor(crtc, crtc->cursor->fb);
 
 	return 0;
 }
drivers/gpu/drm/i915/intel_drv.h +0 -2
index 770f80d..76950bb 100644
@@ -364,10 +364,8 @@ struct intel_crtc {
 	 * handled in the hw itself (with the TILEOFF register). */
 	unsigned long dspaddr_offset;
 
-	struct drm_i915_gem_object *cursor_bo;
 	uint32_t cursor_addr;
 	int16_t cursor_x, cursor_y;
-	int16_t cursor_width, cursor_height;
 	bool cursor_visible;
 
 	struct intel_plane_config plane_config;
Signature · 1 line
1.8.5.1
#43 lore raw

Re: [RFCv3 13/14] drm/i915: Split cursor update code from cursor ioctl handling

Quoted 5 lines · Matt Roper

Legacy cursor ioctls took GEM buffer handles from userspace directly whereas the new unified plane handling assigns drm_framebuffer's to cursor planes. Splitting the code that actually updates the cursor plane from the code that handles object lookup and reference counting allows us to share common code between both interfaces.

This exposes an internal fb, a bo that was private is now public.

So maybe drm_framebuffer_init_private() and
intel_private_framebuffer_create().
-Chris

Signature · 1 line
Chris Wilson, Intel Open Source Technology Centre
author
#44 lore raw

RFC v3 14/14 drm/i915: Add cursor handlers and create cursor at crtc init

In reply to Matt Roper
Cc Intel Graphics Development <[email protected]>
---
 drivers/gpu/drm/i915/intel_display.c | 90 +++++++++++++++++++++++++++++++++++-
 1 file changed, 89 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_display.c +89 -1
index f661469..36bee38 100644
@@ -10781,11 +10781,98 @@ static struct drm_plane *intel_primary_plane_create(struct drm_device *dev,
 	return &primary->base;
 }
 
+static int
+intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc,
+			  struct drm_framebuffer *fb, int crtc_x, int crtc_y,
+			  unsigned int crtc_w, unsigned int crtc_h,
+			  uint32_t src_x, uint32_t src_y,
+			  uint32_t src_w, uint32_t src_h)
+{
+	int ret;
+
+	/* setplane API takes shifted source rectangle values; unshift them */
+	src_x >>= 16;
+	src_y >>= 16;
+	src_w >>= 16;
+	src_h >>= 16;
+
+	/* Cursor planes are locked to their owning CRTC */
+	if (plane->possible_crtcs != drm_crtc_mask(crtc)) {
+		DRM_DEBUG_KMS("Cannot change cursor plane CRTC\n");
+		return -EINVAL;
+	}
+
+	/* Current hardware can't scale the cursor plane. */
+	if (crtc_w != src_w || crtc_h != src_h) {
+		DRM_DEBUG_KMS("Can't scale cursor plane\n");
+		return -EINVAL;
+	}
+
+	ret = cursor_set_common(crtc, crtc->cursor, fb);
+	if (ret)
+		return ret;
+
+	intel_crtc_cursor_move(crtc, crtc_x, crtc_y);
+	intel_crtc_update_cursor(crtc, fb);
+
+	return 0;
+}
+
+static int
+intel_cursor_plane_disable(struct drm_plane *plane)
+{
+	if (!plane->fb)
+		return 0;
+
+	BUG_ON(!plane->crtc);
+
+	return cursor_set_common(plane->crtc, plane, NULL);
+}
+
+static void intel_cursor_plane_destroy(struct drm_plane *plane)
+{
+	struct intel_plane *intel_plane = to_intel_plane(plane);
+	intel_cursor_plane_disable(plane);
+	drm_plane_cleanup(plane);
+	kfree(intel_plane);
+}
+
+static const struct drm_plane_funcs intel_cursor_plane_funcs = {
+	.update_plane = intel_cursor_plane_update,
+	.disable_plane = intel_cursor_plane_disable,
+	.destroy = intel_cursor_plane_destroy,
+};
+
+static const uint32_t cursor_formats[] = {
+	DRM_FORMAT_ARGB8888,
+};
+
+static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev,
+						   int pipe)
+{
+	struct intel_plane *cursor;
+
+	cursor = kzalloc(sizeof(*cursor), GFP_KERNEL);
+	if (cursor == NULL)
+		return NULL;
+
+	cursor->can_scale = false;
+	cursor->pipe = pipe;
+	cursor->plane = pipe;
+
+	drm_plane_init(dev, &cursor->base, 0,
+		       &intel_cursor_plane_funcs, cursor_formats,
+		       ARRAY_SIZE(cursor_formats),
+		       DRM_PLANE_TYPE_CURSOR);
+	return &cursor->base;
+}
+
 static void intel_crtc_init(struct drm_device *dev, int pipe)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
 	struct intel_crtc *intel_crtc;
 	struct drm_plane *primary;
+	struct drm_plane *cursor;
 	int i, ret;
 
 	intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL);
@@ -10793,7 +10880,8 @@ static void intel_crtc_init(struct drm_device *dev, int pipe)
 		return;
 
 	primary = intel_primary_plane_create(dev, pipe);
-	ret = drm_crtc_init(dev, &intel_crtc->base, primary, NULL,
+	cursor = intel_cursor_plane_create(dev, pipe);
+	ret = drm_crtc_init(dev, &intel_crtc->base, primary, cursor,
 			    &intel_crtc_funcs);
 	if (ret) {
 		drm_crtc_cleanup(&intel_crtc->base);
Signature · 1 line
1.8.5.1
#45 lore raw
In reply to Matt Roper
Quoted 17 lines · Matt Roper

Previous revision and explanation of series:

   http://lists.freedesktop.org/archives/dri-devel/2014-March/055222.html

Main changes since last pass:
* Added cursor plane support on i915. Unfortunately it isn't possible to create nice generic helper functions that make use of the legacy API's for cursor planes as was done for primary planes; the legacy cursor ioctl's take a driver handle directly (e.g., from GEM) rather than a DRM framebuffer. With the unified plane support, we receive a DRM framebuffer via the SetPlane API, but have no way of turning that into a driver handle that can be passed to the legacy interfaces.
* Updated msm and omapdrm to use their existing "private" planes as primary rather than using the primary helper functions. (thanks Rob Clark!)
* Fixed several s/crtc->fb/crtc->primary->fb/ conversions that were missed on the first pass (or new instances that popped up due to rebasing to the latest code).

Quoted 16 lines

I believe some of the next steps are:
* Create some new read-only plane properties that describe in more detail the capabilities & limitations of various planes (max/min size, scaling capabilities, tiling restrictions, etc.) so that generic userspace compositors can make intelligent decisions about how best to use the various planes on the plane list. If anyone has strong feelings on what these properties should look like, this would be a good time to start the discussion.
* Update cursor support for the rest of the non-i915 drivers. I believe the list of drivers that currently support cursors are: armada, ast, gma500, mgag200, msm, nouveau, radeon, vmwgfx, and qxl.
* Update imx-drm's CRTC creation to use its existing private primary plane rather than using the primary helper function to create one.
* Provide patches for weston & xf86-video-modesetting that make use of the unified plane interface to make real-world testing of this patchset a bit easier.

not sure other's opionions, but personally I wouldn't object to doing some of this as follow-up patchsets. Ofc my selfish motivation is that basing atomic on top of primary plane really seems like the right move, and so sooner we can get the initial parts of this patchset merged, the sooner we can try to merge atomic ;-)

BR,
-R

Quoted 100 lines

Note that the first patch here is simply a build fix for current breakage of the drm-intel-nightly branch of the drm-intel repo.

Matt Roper (14):
SQUASH! drm/i915: Do not dereference pointers from ring buffer in
evict event
drm: Add support for multiple plane types
drm: Add primary plane helpers
drm/exynos: Restrict plane loops to only operate on overlay planes drm/i915: Restrict plane loops to only operate on overlay planes
drm: Add plane type property
drm: Specify primary plane at CRTC initialization (v2)
drm: Replace crtc fb with primary plane fb (v2)
drm: Allow userspace to ask for full plane list (universal planes) drm/i915: Rename similar plane functions to avoid confusion drm/i915: Intel-specific primary plane handling
drm: Specify cursor plane at CRTC initialization drm/i915: Split cursor update code from cursor ioctl handling drm/i915: Add cursor handlers and create cursor at crtc init

 drivers/gpu/drm/armada/armada_crtc.c         |   4 +-
 drivers/gpu/drm/armada/armada_overlay.c      |   3 +-
 drivers/gpu/drm/ast/ast_mode.c               |  16 +-
 drivers/gpu/drm/bochs/bochs_kms.c            |   8 +-
 drivers/gpu/drm/cirrus/cirrus_mode.c         |  15 +-
 drivers/gpu/drm/drm_crtc.c                   | 441 +++++++++++++++----
 drivers/gpu/drm/drm_crtc_helper.c            |  21 +-
 drivers/gpu/drm/drm_fb_helper.c              |   9 +-
 drivers/gpu/drm/drm_ioctl.c                  |   5 +
 drivers/gpu/drm/exynos/exynos_drm_crtc.c     |   4 +-
 drivers/gpu/drm/exynos/exynos_drm_encoder.c  |   6 +
 drivers/gpu/drm/exynos/exynos_drm_plane.c    |   4 +-
 drivers/gpu/drm/gma500/cdv_intel_display.c   |   2 +-
 drivers/gpu/drm/gma500/cdv_intel_dp.c        |   2 +-
 drivers/gpu/drm/gma500/cdv_intel_hdmi.c      |   3 +-
 drivers/gpu/drm/gma500/cdv_intel_lvds.c      |   2 +-
 drivers/gpu/drm/gma500/gma_display.c         |  17 +-
 drivers/gpu/drm/gma500/mdfld_dsi_output.c    |   2 +-
 drivers/gpu/drm/gma500/mdfld_intel_display.c |  17 +-
 drivers/gpu/drm/gma500/oaktrail_crtc.c       |  13 +-
 drivers/gpu/drm/gma500/psb_intel_display.c   |   7 +-
 drivers/gpu/drm/gma500/psb_intel_lvds.c      |   2 +-
 drivers/gpu/drm/gma500/psb_intel_sdvo.c      |   2 +-
 drivers/gpu/drm/i915/i915_debugfs.c          |   4 +-
 drivers/gpu/drm/i915/i915_drv.h              |   5 +-
 drivers/gpu/drm/i915/i915_irq.c              |   4 +-
 drivers/gpu/drm/i915/i915_trace.h            |   2 +-
 drivers/gpu/drm/i915/intel_display.c         | 623 ++++++++++++++++++++-------
 drivers/gpu/drm/i915/intel_dp.c              |   5 +-
 drivers/gpu/drm/i915/intel_drv.h             |   3 +-
 drivers/gpu/drm/i915/intel_fbdev.c           |   6 +-
 drivers/gpu/drm/i915/intel_overlay.c         |   4 +-
 drivers/gpu/drm/i915/intel_pm.c              |  39 +-
 drivers/gpu/drm/i915/intel_sprite.c          |   2 +-
 drivers/gpu/drm/mgag200/mgag200_mode.c       |  33 +-
 drivers/gpu/drm/msm/mdp/mdp4/mdp4_crtc.c     |  33 +-
 drivers/gpu/drm/msm/mdp/mdp4/mdp4_plane.c    |   4 +-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_crtc.c     |  27 +-
 drivers/gpu/drm/msm/mdp/mdp5/mdp5_plane.c    |   4 +-
 drivers/gpu/drm/nouveau/dispnv04/crtc.c      |  24 +-
 drivers/gpu/drm/nouveau/dispnv04/dfp.c       |   2 +-
 drivers/gpu/drm/nouveau/dispnv04/overlay.c   |   4 +-
 drivers/gpu/drm/nouveau/nouveau_display.c    |   8 +-
 drivers/gpu/drm/nouveau/nv50_display.c       |  21 +-
 drivers/gpu/drm/omapdrm/omap_crtc.c          |   2 +-
 drivers/gpu/drm/omapdrm/omap_plane.c         |   4 +-
 drivers/gpu/drm/qxl/qxl_display.c            |  15 +-
 drivers/gpu/drm/radeon/atombios_crtc.c       |  20 +-
 drivers/gpu/drm/radeon/r100.c                |   4 +-
 drivers/gpu/drm/radeon/radeon_connectors.c   |   2 +-
 drivers/gpu/drm/radeon/radeon_device.c       |   3 +-
 drivers/gpu/drm/radeon/radeon_display.c      |   9 +-
 drivers/gpu/drm/radeon/radeon_legacy_crtc.c  |  16 +-
 drivers/gpu/drm/rcar-du/rcar_du_crtc.c       |   4 +-
 drivers/gpu/drm/rcar-du/rcar_du_plane.c      |   3 +-
 drivers/gpu/drm/shmobile/shmob_drm_crtc.c    |   3 +-
 drivers/gpu/drm/shmobile/shmob_drm_plane.c   |   2 +-
 drivers/gpu/drm/tegra/dc.c                   |   7 +-
 drivers/gpu/drm/tilcdc/tilcdc_crtc.c         |   4 +-
 drivers/gpu/drm/udl/udl_modeset.c            |   6 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_kms.c          |  14 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c          |  12 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c         |  12 +-
 drivers/staging/imx-drm/imx-drm-core.c       |   4 +-
 drivers/staging/imx-drm/ipuv3-plane.c        |   4 +-
 include/drm/drmP.h                           |   5 +
 include/drm/drm_crtc.h                       | 115 ++++-
 include/uapi/drm/drm.h                       |   8 +
 68 files changed, 1252 insertions(+), 488 deletions(-)

Cc: Intel Graphics Development <[email protected]> --
1.8.5.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel