Skip to contentSkip to conversation

drm/omap: Add virtual-planes support

PATCH Superseded Neil Armstrong 2 participants 27 messages Sep 23, 2021 – Oct 12, 2021

Subsystems (3)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v5 cover drm/omap: Add virtual-planes support

This patchset is the follow-up the v4 patchset from Benoit Parrot at [1].

This patch series adds virtual-plane support to omapdrm driver to allow the use of display wider than 2048 pixels.

In order to do so we introduce the concept of hw_overlay which can then be dynamically allocated to a plane. When the requested output width exceed what be supported by one overlay a second is then allocated if possible to handle display wider then 2048.

This series replaces an earlier series which was DT based and using statically allocated resources.

This implementation is inspired from the work done in msm/disp/mdp5 driver.

Changes since v4 at [1]:
- rebased on v5.15-rc2
- adapted to drm_atomic_get_new/old_plane_state()
- tested on Beagle-x15
- checked for non-regression on Beagle-x15
- removed unused "state" variable in omap_global_state

[1] https://lore.kernel.org/all/[email protected]/

Benoit Parrot (8):
drm/omap: Add ability to check if requested plane modes can be
supported
drm/omap: Add ovl checking funcs to dispc_ops drm/omap: introduce omap_hw_overlay
drm/omap: omap_plane: subclass drm_plane_state drm/omap: Add global state as a private atomic object drm/omap: dynamically assign hw overlays to planes drm/omap: add plane_atomic_print_state support drm/omap: Add a 'right overlay' to plane state

 drivers/gpu/drm/omapdrm/Makefile       |   1 +
 drivers/gpu/drm/omapdrm/dss/dispc.c    |  31 +-
 drivers/gpu/drm/omapdrm/dss/dss.h      |   5 +
 drivers/gpu/drm/omapdrm/omap_drv.c     | 189 ++++++++++++-
 drivers/gpu/drm/omapdrm/omap_drv.h     |  28 ++
 drivers/gpu/drm/omapdrm/omap_fb.c      |  33 ++-
 drivers/gpu/drm/omapdrm/omap_fb.h      |   4 +-
 drivers/gpu/drm/omapdrm/omap_overlay.c | 254 +++++++++++++++++
 drivers/gpu/drm/omapdrm/omap_overlay.h |  41 +++
 drivers/gpu/drm/omapdrm/omap_plane.c   | 375 +++++++++++++++++++++----
 drivers/gpu/drm/omapdrm/omap_plane.h   |   1 +
 11 files changed, 903 insertions(+), 59 deletions(-)
 create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.c
 create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.h
Signature · 1 line
2.25.1
#1 lore raw

PATCH v5 1/8 drm/omap: Add ability to check if requested plane modes can be supported

From: Benoit Parrot <[email protected]>

We currently assume that an overlay has the same maximum width and maximum height as the overlay manager. This assumption is incorrect. On some variants the overlay manager maximum width is twice the maximum width that the overlay can handle. We need to add the appropriate data per variant as well as export a helper function to retrieve the data so check can be made dynamically in omap_plane_atomic_check().

---
 drivers/gpu/drm/omapdrm/dss/dispc.c  | 22 ++++++++++++++++++++++
 drivers/gpu/drm/omapdrm/dss/dss.h    |  2 ++
 drivers/gpu/drm/omapdrm/omap_plane.c | 14 ++++++++++++++
 3 files changed, 38 insertions(+)
drivers/gpu/drm/omapdrm/dss/dispc.c +22 -0
index 3c4a4991e45a..bdecec8f4d88 100644
@@ -92,6 +92,8 @@ struct dispc_features {
 	u8 mgr_height_start;
 	u16 mgr_width_max;
 	u16 mgr_height_max;
+	u16 ovl_width_max;
+	u16 ovl_height_max;
 	unsigned long max_lcd_pclk;
 	unsigned long max_tv_pclk;
 	unsigned int max_downscale;
@@ -2599,6 +2601,12 @@ static int dispc_ovl_calc_scaling(struct dispc_device *dispc,
 	return 0;
 }
 
+void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height)
+{
+	*width = dispc->feat->ovl_width_max;
+	*height = dispc->feat->ovl_height_max;
+}
+
 static int dispc_ovl_setup_common(struct dispc_device *dispc,
 				  enum omap_plane_id plane,
 				  enum omap_overlay_caps caps,
@@ -4240,6 +4248,8 @@ static const struct dispc_features omap24xx_dispc_feats = {
 	.mgr_height_start	=	26,
 	.mgr_width_max		=	2048,
 	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
 	.max_lcd_pclk		=	66500000,
 	.max_downscale		=	2,
 	/*
@@ -4278,6 +4288,8 @@ static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
 	.mgr_height_start	=	26,
 	.mgr_width_max		=	2048,
 	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
 	.max_lcd_pclk		=	173000000,
 	.max_tv_pclk		=	59000000,
 	.max_downscale		=	4,
@@ -4313,6 +4325,8 @@ static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
 	.mgr_height_start	=	26,
 	.mgr_width_max		=	2048,
 	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
 	.max_lcd_pclk		=	173000000,
 	.max_tv_pclk		=	59000000,
 	.max_downscale		=	4,
@@ -4348,6 +4362,8 @@ static const struct dispc_features omap36xx_dispc_feats = {
 	.mgr_height_start	=	26,
 	.mgr_width_max		=	2048,
 	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
 	.max_lcd_pclk		=	173000000,
 	.max_tv_pclk		=	59000000,
 	.max_downscale		=	4,
@@ -4383,6 +4399,8 @@ static const struct dispc_features am43xx_dispc_feats = {
 	.mgr_height_start	=	26,
 	.mgr_width_max		=	2048,
 	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
 	.max_lcd_pclk		=	173000000,
 	.max_tv_pclk		=	59000000,
 	.max_downscale		=	4,
@@ -4418,6 +4436,8 @@ static const struct dispc_features omap44xx_dispc_feats = {
 	.mgr_height_start	=	26,
 	.mgr_width_max		=	2048,
 	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
 	.max_lcd_pclk		=	170000000,
 	.max_tv_pclk		=	185625000,
 	.max_downscale		=	4,
@@ -4457,6 +4477,8 @@ static const struct dispc_features omap54xx_dispc_feats = {
 	.mgr_height_start	=	27,
 	.mgr_width_max		=	4096,
 	.mgr_height_max		=	4096,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	4096,
 	.max_lcd_pclk		=	170000000,
 	.max_tv_pclk		=	192000000,
 	.max_downscale		=	4,
drivers/gpu/drm/omapdrm/dss/dss.h +2 -0
index a547527bb2f3..14c39f7c3988 100644
@@ -397,6 +397,8 @@ int dispc_get_num_mgrs(struct dispc_device *dispc);
 const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
 					    enum omap_plane_id plane);
 
+void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height);
+
 u32 dispc_read_irqstatus(struct dispc_device *dispc);
 void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask);
 void dispc_write_irqenable(struct dispc_device *dispc, u32 mask);
drivers/gpu/drm/omapdrm/omap_plane.c +14 -0
index 512af976b7e9..d0a67b7ed1a0 100644
@@ -109,11 +109,18 @@ static int omap_plane_atomic_check(struct drm_plane *plane,
 {
 	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
 										 plane);
+	struct omap_drm_private *priv = plane->dev->dev_private;
 	struct drm_crtc_state *crtc_state;
+	u16 width, height;
+	u32 width_fp, height_fp;
 
 	if (!new_plane_state->fb)
 		return 0;
 
+	dispc_ovl_get_max_size(priv->dispc, &width, &height);
+	width_fp = width << 16;
+	height_fp = height << 16;
+
 	/* crtc should only be NULL when disabling (i.e., !new_plane_state->fb) */
 	if (WARN_ON(!new_plane_state->crtc))
 		return 0;
@@ -136,6 +143,13 @@ static int omap_plane_atomic_check(struct drm_plane *plane,
 	if (new_plane_state->crtc_y + new_plane_state->crtc_h > crtc_state->adjusted_mode.vdisplay)
 		return -EINVAL;
 
+	/* Make sure dimensions are within bounds. */
+	if (new_plane_state->src_h > height_fp || new_plane_state->crtc_h > height)
+		return -EINVAL;
+
+	if (new_plane_state->src_w > width_fp || new_plane_state->crtc_w > width)
+		return -EINVAL;
+
 	if (new_plane_state->rotation != DRM_MODE_ROTATE_0 &&
 	    !omap_framebuffer_supports_rotation(new_plane_state->fb))
 		return -EINVAL;
Signature · 1 line
2.25.1
maintainer
#2 lore raw

Re: [PATCH v5 1/8] drm/omap: Add ability to check if requested plane modes can be supported

Hi,

Quoted 124 lines · Neil Armstrong

From: Benoit Parrot <[email protected]>

We currently assume that an overlay has the same maximum width and maximum height as the overlay manager. This assumption is incorrect. On some variants the overlay manager maximum width is twice the maximum width that the overlay can handle. We need to add the appropriate data per variant as well as export a helper function to retrieve the data so check can be made dynamically in omap_plane_atomic_check().

---
  drivers/gpu/drm/omapdrm/dss/dispc.c  | 22 ++++++++++++++++++++++
  drivers/gpu/drm/omapdrm/dss/dss.h    |  2 ++
  drivers/gpu/drm/omapdrm/omap_plane.c | 14 ++++++++++++++
  3 files changed, 38 insertions(+)
drivers/gpu/drm/omapdrm/dss/dispc.c +22 -0
index 3c4a4991e45a..bdecec8f4d88 100644
@@ -92,6 +92,8 @@ struct dispc_features {
  	u8 mgr_height_start;
  	u16 mgr_width_max;
  	u16 mgr_height_max;
+	u16 ovl_width_max;
+	u16 ovl_height_max;
  	unsigned long max_lcd_pclk;
  	unsigned long max_tv_pclk;
  	unsigned int max_downscale;
@@ -2599,6 +2601,12 @@ static int dispc_ovl_calc_scaling(struct dispc_device *dispc,
  	return 0;
  }
 
+void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height)
+{
+	*width = dispc->feat->ovl_width_max;
+	*height = dispc->feat->ovl_height_max;
+}
+
  static int dispc_ovl_setup_common(struct dispc_device *dispc,
  				  enum omap_plane_id plane,
  				  enum omap_overlay_caps caps,
@@ -4240,6 +4248,8 @@ static const struct dispc_features omap24xx_dispc_feats = {
  	.mgr_height_start	=	26,
  	.mgr_width_max		=	2048,
  	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
  	.max_lcd_pclk		=	66500000,
  	.max_downscale		=	2,
  	/*
@@ -4278,6 +4288,8 @@ static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
  	.mgr_height_start	=	26,
  	.mgr_width_max		=	2048,
  	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
  	.max_lcd_pclk		=	173000000,
  	.max_tv_pclk		=	59000000,
  	.max_downscale		=	4,
@@ -4313,6 +4325,8 @@ static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
  	.mgr_height_start	=	26,
  	.mgr_width_max		=	2048,
  	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
  	.max_lcd_pclk		=	173000000,
  	.max_tv_pclk		=	59000000,
  	.max_downscale		=	4,
@@ -4348,6 +4362,8 @@ static const struct dispc_features omap36xx_dispc_feats = {
  	.mgr_height_start	=	26,
  	.mgr_width_max		=	2048,
  	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
  	.max_lcd_pclk		=	173000000,
  	.max_tv_pclk		=	59000000,
  	.max_downscale		=	4,
@@ -4383,6 +4399,8 @@ static const struct dispc_features am43xx_dispc_feats = {
  	.mgr_height_start	=	26,
  	.mgr_width_max		=	2048,
  	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
  	.max_lcd_pclk		=	173000000,
  	.max_tv_pclk		=	59000000,
  	.max_downscale		=	4,
@@ -4418,6 +4436,8 @@ static const struct dispc_features omap44xx_dispc_feats = {
  	.mgr_height_start	=	26,
  	.mgr_width_max		=	2048,
  	.mgr_height_max		=	2048,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	2048,
  	.max_lcd_pclk		=	170000000,
  	.max_tv_pclk		=	185625000,
  	.max_downscale		=	4,
@@ -4457,6 +4477,8 @@ static const struct dispc_features omap54xx_dispc_feats = {
  	.mgr_height_start	=	27,
  	.mgr_width_max		=	4096,
  	.mgr_height_max		=	4096,
+	.ovl_width_max		=	2048,
+	.ovl_height_max		=	4096,
  	.max_lcd_pclk		=	170000000,
  	.max_tv_pclk		=	192000000,
  	.max_downscale		=	4,
drivers/gpu/drm/omapdrm/dss/dss.h +2 -0
index a547527bb2f3..14c39f7c3988 100644
@@ -397,6 +397,8 @@ int dispc_get_num_mgrs(struct dispc_device *dispc);
  const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
  					    enum omap_plane_id plane);
 
+void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height);
+
  u32 dispc_read_irqstatus(struct dispc_device *dispc);
  void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask);
  void dispc_write_irqenable(struct dispc_device *dispc, u32 mask);
drivers/gpu/drm/omapdrm/omap_plane.c +0 -0
index 512af976b7e9..d0a67b7ed1a0 100644

drivers/gpu/drm/omapdrm/omap_plane.c static int omap_plane_atomic_check(struct drm_plane *plane, · line 115

Quoted 7 lines
drivers/gpu/drm/omapdrm/omap_plane.c +3 -0
@@ -109,11 +109,18 @@ static int omap_plane_atomic_check(struct drm_plane *plane,
  {
  	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
  										 plane);
+	struct omap_drm_private *priv = plane->dev->dev_private;
  	struct drm_crtc_state *crtc_state;
+	u16 width, height;
+	u32 width_fp, height_fp;

I think naming these max_w/max_width etc. would be better.

Tomi

#3 lore raw

Re: [PATCH v5 1/8] drm/omap: Add ability to check if requested plane modes can be supported

Quoted 126 lines · Tomi Valkeinen

Hi,

Quoted 123 lines · Neil Armstrong

From: Benoit Parrot <[email protected]>

We currently assume that an overlay has the same maximum width and maximum height as the overlay manager. This assumption is incorrect. On some variants the overlay manager maximum width is twice the maximum width that the overlay can handle. We need to add the appropriate data per variant as well as export a helper function to retrieve the data so check can be made dynamically in omap_plane_atomic_check().

---
  drivers/gpu/drm/omapdrm/dss/dispc.c  | 22 ++++++++++++++++++++++ drivers/gpu/drm/omapdrm/dss/dss.h    |  2 ++ drivers/gpu/drm/omapdrm/omap_plane.c | 14 ++++++++++++++

  3 files changed, 38 insertions(+)
drivers/gpu/drm/omapdrm/dss/dispc.c +21 -0
index 3c4a4991e45a..bdecec8f4d88 100644
@@ -92,6 +92,8 @@ struct dispc_features {
       u8 mgr_height_start;
       u16 mgr_width_max;
       u16 mgr_height_max;
+    u16 ovl_width_max;
+    u16 ovl_height_max;
       unsigned long max_lcd_pclk;
       unsigned long max_tv_pclk;
       unsigned int max_downscale;
@@ -2599,6 +2601,12 @@ static int dispc_ovl_calc_scaling(struct dispc_device *dispc,
       return 0;
   }
   +void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height)
+{
+    *width = dispc->feat->ovl_width_max;
+    *height = dispc->feat->ovl_height_max;
+}
+
   static int dispc_ovl_setup_common(struct dispc_device *dispc,
                     enum omap_plane_id plane,
                     enum omap_overlay_caps caps,
@@ -4240,6 +4248,8 @@ static const struct dispc_features omap24xx_dispc_feats = {
       .mgr_height_start    =    26,
       .mgr_width_max        =    2048,
       .mgr_height_max        =    2048,
+    .ovl_width_max        =    2048,
+    .ovl_height_max        =    2048,
       .max_lcd_pclk        =    66500000,
       .max_downscale        =    2,
       /*
@@ -4278,6 +4288,8 @@ static const struct dispc_features omap34xx_rev1_0_dispc_feats = {
       .mgr_height_start    =    26,
       .mgr_width_max        =    2048,
       .mgr_height_max        =    2048,
+    .ovl_width_max        =    2048,
+    .ovl_height_max        =    2048,
       .max_lcd_pclk        =    173000000,
       .max_tv_pclk        =    59000000,
       .max_downscale        =    4,
@@ -4313,6 +4325,8 @@ static const struct dispc_features omap34xx_rev3_0_dispc_feats = {
       .mgr_height_start    =    26,
       .mgr_width_max        =    2048,
       .mgr_height_max        =    2048,
+    .ovl_width_max        =    2048,
+    .ovl_height_max        =    2048,
       .max_lcd_pclk        =    173000000,
       .max_tv_pclk        =    59000000,
       .max_downscale        =    4,
@@ -4348,6 +4362,8 @@ static const struct dispc_features omap36xx_dispc_feats = {
       .mgr_height_start    =    26,
       .mgr_width_max        =    2048,
       .mgr_height_max        =    2048,
+    .ovl_width_max        =    2048,
+    .ovl_height_max        =    2048,
       .max_lcd_pclk        =    173000000,
       .max_tv_pclk        =    59000000,
       .max_downscale        =    4,
@@ -4383,6 +4399,8 @@ static const struct dispc_features am43xx_dispc_feats = {
       .mgr_height_start    =    26,
       .mgr_width_max        =    2048,
       .mgr_height_max        =    2048,
+    .ovl_width_max        =    2048,
+    .ovl_height_max        =    2048,
       .max_lcd_pclk        =    173000000,
       .max_tv_pclk        =    59000000,
       .max_downscale        =    4,
@@ -4418,6 +4436,8 @@ static const struct dispc_features omap44xx_dispc_feats = {
       .mgr_height_start    =    26,
       .mgr_width_max        =    2048,
       .mgr_height_max        =    2048,
+    .ovl_width_max        =    2048,
+    .ovl_height_max        =    2048,
       .max_lcd_pclk        =    170000000,
       .max_tv_pclk        =    185625000,
       .max_downscale        =    4,
@@ -4457,6 +4477,8 @@ static const struct dispc_features omap54xx_dispc_feats = {
       .mgr_height_start    =    27,
       .mgr_width_max        =    4096,
       .mgr_height_max        =    4096,
+    .ovl_width_max        =    2048,
+    .ovl_height_max        =    4096,
       .max_lcd_pclk        =    170000000,
       .max_tv_pclk        =    192000000,
       .max_downscale        =    4,
drivers/gpu/drm/omapdrm/dss/dss.h +1 -0
index a547527bb2f3..14c39f7c3988 100644
@@ -397,6 +397,8 @@ int dispc_get_num_mgrs(struct dispc_device *dispc);
   const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
                           enum omap_plane_id plane);
   +void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height);
+
   u32 dispc_read_irqstatus(struct dispc_device *dispc);
   void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask);
   void dispc_write_irqenable(struct dispc_device *dispc, u32 mask);
drivers/gpu/drm/omapdrm/omap_plane.c +0 -0
index 512af976b7e9..d0a67b7ed1a0 100644
@@ -109,11 +109,18 @@ static int omap_plane_atomic_check(struct drm_plane *plane,
   {
Quoted 8 lines

drivers/gpu/drm/omapdrm/omap_plane.c static int omap_plane_atomic_check(struct drm_plane *plane, · line 115

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_plane.c +3 -0
       struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
                                            plane);
+    struct omap_drm_private *priv = plane->dev->dev_private;
       struct drm_crtc_state *crtc_state;
+    u16 width, height;
+    u32 width_fp, height_fp;

I think naming these max_w/max_width etc. would be better.

Ack

Neil

Quoted 2 lines

 Tomi

#4 lore raw

PATCH v5 2/8 drm/omap: Add ovl checking funcs to dispc_ops

In reply to Neil Armstrong

From: Benoit Parrot <[email protected]>

In order to be able to dynamically assign overlays to planes we need to be able to asses the overlay capabilities.

Add a helper function to be able to retrieve the supported capabilities of an overlay.

And export the function to check if a fourcc is supported on a given overlay.

---
 drivers/gpu/drm/omapdrm/dss/dispc.c | 9 +++++++--
 drivers/gpu/drm/omapdrm/dss/dss.h   | 3 +++
 2 files changed, 10 insertions(+), 2 deletions(-)
drivers/gpu/drm/omapdrm/dss/dispc.c +7 -2
index bdecec8f4d88..df945e4b1fd3 100644
@@ -1281,8 +1281,8 @@ static u32 dispc_ovl_get_burst_size(struct dispc_device *dispc,
 	return dispc->feat->burst_size_unit * 8;
 }
 
-static bool dispc_ovl_color_mode_supported(struct dispc_device *dispc,
-					   enum omap_plane_id plane, u32 fourcc)
+bool dispc_ovl_color_mode_supported(struct dispc_device *dispc,
+				    enum omap_plane_id plane, u32 fourcc)
 {
 	const u32 *modes;
 	unsigned int i;
@@ -2489,6 +2489,11 @@ static int dispc_ovl_calc_scaling_44xx(struct dispc_device *dispc,
 	return 0;
 }
 
+enum omap_overlay_caps dispc_ovl_get_caps(struct dispc_device *dispc, enum omap_plane_id plane)
+{
+	return dispc->feat->overlay_caps[plane];
+}
+
 #define DIV_FRAC(dividend, divisor) \
 	((dividend) * 100 / (divisor) - ((dividend) / (divisor) * 100))
 
drivers/gpu/drm/omapdrm/dss/dss.h +3 -0
index 14c39f7c3988..4ff02fbc0e71 100644
@@ -398,6 +398,9 @@ const u32 *dispc_ovl_get_color_modes(struct dispc_device *dispc,
 					    enum omap_plane_id plane);
 
 void dispc_ovl_get_max_size(struct dispc_device *dispc, u16 *width, u16 *height);
+bool dispc_ovl_color_mode_supported(struct dispc_device *dispc,
+				    enum omap_plane_id plane, u32 fourcc);
+enum omap_overlay_caps dispc_ovl_get_caps(struct dispc_device *dispc, enum omap_plane_id plane);
 
 u32 dispc_read_irqstatus(struct dispc_device *dispc);
 void dispc_clear_irqstatus(struct dispc_device *dispc, u32 mask);
Signature · 1 line
2.25.1
#5 lore raw

PATCH v5 3/8 drm/omap: introduce omap_hw_overlay

In reply to Neil Armstrong

From: Benoit Parrot <[email protected]>

Split out the hardware overlay specifics from omap_plane. To start, the hw overlays are statically assigned to planes.

The goal is to eventually assign hw overlays dynamically to planes during plane->atomic_check() based on requested caps (scaling, YUV, etc). And then perform hw overlay re-assignment if required.

---
 drivers/gpu/drm/omapdrm/Makefile       |  1 +
 drivers/gpu/drm/omapdrm/omap_drv.c     |  9 ++-
 drivers/gpu/drm/omapdrm/omap_drv.h     |  4 ++
 drivers/gpu/drm/omapdrm/omap_overlay.c | 87 ++++++++++++++++++++++++++
 drivers/gpu/drm/omapdrm/omap_overlay.h | 31 +++++++++
 drivers/gpu/drm/omapdrm/omap_plane.c   | 42 ++++++-------
 6 files changed, 151 insertions(+), 23 deletions(-)
 create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.c
 create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.h
drivers/gpu/drm/omapdrm/Makefile +1 -0
index 21e8277ff88f..710b4e0abcf0 100644
@@ -9,6 +9,7 @@ omapdrm-y := omap_drv.o \
 	omap_debugfs.o \
 	omap_crtc.o \
 	omap_plane.o \
+	omap_overlay.o \
 	omap_encoder.o \
 	omap_fb.o \
 	omap_gem.o \
drivers/gpu/drm/omapdrm/omap_drv.c +8 -1
index f86e20578143..b994014b22e8 100644
@@ -583,10 +583,14 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
 
 	omap_gem_init(ddev);
 
+	ret = omap_hwoverlays_init(priv);
+	if (ret)
+		goto err_gem_deinit;
+
 	ret = omap_modeset_init(ddev);
 	if (ret) {
 		dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
-		goto err_gem_deinit;
+		goto err_free_overlays;
 	}
 
 	/* Initialize vblank handling, start with all CRTCs disabled. */
@@ -618,6 +622,8 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
 	omap_fbdev_fini(ddev);
 err_cleanup_modeset:
 	omap_modeset_fini(ddev);
+err_free_overlays:
+	omap_hwoverlays_destroy(priv);
 err_gem_deinit:
 	omap_gem_deinit(ddev);
 	destroy_workqueue(priv->wq);
@@ -642,6 +648,7 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
 	drm_atomic_helper_shutdown(ddev);
 
 	omap_modeset_fini(ddev);
+	omap_hwoverlays_destroy(priv);
 	omap_gem_deinit(ddev);
 
 	destroy_workqueue(priv->wq);
drivers/gpu/drm/omapdrm/omap_drv.h +4 -0
index 591d4c273f02..b4d9c2062723 100644
@@ -24,6 +24,7 @@
 #include "omap_gem.h"
 #include "omap_irq.h"
 #include "omap_plane.h"
+#include "omap_overlay.h"
 
 #define DBG(fmt, ...) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
 #define VERB(fmt, ...) if (0) DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__) /* verbose debug */
@@ -57,6 +58,9 @@ struct omap_drm_private {
 	unsigned int num_planes;
 	struct drm_plane *planes[8];
 
+	unsigned int num_ovls;
+	struct omap_hw_overlay *overlays[8];
+
 	struct drm_fb_helper *fbdev;
 
 	struct workqueue_struct *wq;
drivers/gpu/drm/omapdrm/omap_overlay.c new file +87 -0

87 lines not on this page · raw message

drivers/gpu/drm/omapdrm/omap_overlay.h new file +31 -0
new file mode 100644
index 000000000000..892fecb67adb
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2018 Texas Instruments Incorporated -  http://www.ti.com/
+ * Author: Benoit Parrot, <[email protected]>
+ */
+
+#ifndef __OMAPDRM_OVERLAY_H__
+#define __OMAPDRM_OVERLAY_H__
+
+#include <linux/types.h>
+
+enum drm_plane_type;
+
+struct drm_device;
+struct drm_mode_object;
+struct drm_plane;
+
+/* Used to associate a HW overlay/plane to a plane */
+struct omap_hw_overlay {
+	int idx;
+
+	const char *name;
+	enum omap_plane_id overlay_id;
+
+	enum omap_overlay_caps caps;
+	u32 possible_crtcs;
+};
+
+int omap_hwoverlays_init(struct omap_drm_private *priv);
+void omap_hwoverlays_destroy(struct omap_drm_private *priv);
+#endif /* __OMAPDRM_OVERLAY_H__ */
drivers/gpu/drm/omapdrm/omap_plane.c +20 -22

114 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#6 lore raw

Re: [PATCH v5 3/8] drm/omap: introduce omap_hw_overlay

Quoted 99 lines · Neil Armstrong

From: Benoit Parrot <[email protected]>

Split out the hardware overlay specifics from omap_plane. To start, the hw overlays are statically assigned to planes.

The goal is to eventually assign hw overlays dynamically to planes during plane->atomic_check() based on requested caps (scaling, YUV, etc). And then perform hw overlay re-assignment if required.

---
  drivers/gpu/drm/omapdrm/Makefile       |  1 +
  drivers/gpu/drm/omapdrm/omap_drv.c     |  9 ++-
  drivers/gpu/drm/omapdrm/omap_drv.h     |  4 ++
  drivers/gpu/drm/omapdrm/omap_overlay.c | 87 ++++++++++++++++++++++++++
  drivers/gpu/drm/omapdrm/omap_overlay.h | 31 +++++++++
  drivers/gpu/drm/omapdrm/omap_plane.c   | 42 ++++++-------
  6 files changed, 151 insertions(+), 23 deletions(-)

create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.c create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.h

drivers/gpu/drm/omapdrm/Makefile +1 -0
index 21e8277ff88f..710b4e0abcf0 100644
@@ -9,6 +9,7 @@ omapdrm-y := omap_drv.o \
  	omap_debugfs.o \
  	omap_crtc.o \
  	omap_plane.o \
+	omap_overlay.o \
  	omap_encoder.o \
  	omap_fb.o \
  	omap_gem.o \
drivers/gpu/drm/omapdrm/omap_drv.c +8 -1
index f86e20578143..b994014b22e8 100644
@@ -583,10 +583,14 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
 
  	omap_gem_init(ddev);
 
+	ret = omap_hwoverlays_init(priv);
+	if (ret)
+		goto err_gem_deinit;
+
  	ret = omap_modeset_init(ddev);
  	if (ret) {
  		dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
-		goto err_gem_deinit;
+		goto err_free_overlays;
  	}
 
  	/* Initialize vblank handling, start with all CRTCs disabled. */
@@ -618,6 +622,8 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
  	omap_fbdev_fini(ddev);
  err_cleanup_modeset:
  	omap_modeset_fini(ddev);
+err_free_overlays:
+	omap_hwoverlays_destroy(priv);
  err_gem_deinit:
  	omap_gem_deinit(ddev);
  	destroy_workqueue(priv->wq);
@@ -642,6 +648,7 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
  	drm_atomic_helper_shutdown(ddev);
 
  	omap_modeset_fini(ddev);
+	omap_hwoverlays_destroy(priv);
  	omap_gem_deinit(ddev);
 
  	destroy_workqueue(priv->wq);
drivers/gpu/drm/omapdrm/omap_drv.h +4 -0
index 591d4c273f02..b4d9c2062723 100644
@@ -24,6 +24,7 @@
  #include "omap_gem.h"
  #include "omap_irq.h"
  #include "omap_plane.h"
+#include "omap_overlay.h"
 
  #define DBG(fmt, ...) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
  #define VERB(fmt, ...) if (0) DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__) /* verbose debug */
@@ -57,6 +58,9 @@ struct omap_drm_private {
  	unsigned int num_planes;
  	struct drm_plane *planes[8];
 
+	unsigned int num_ovls;
+	struct omap_hw_overlay *overlays[8];
+
  	struct drm_fb_helper *fbdev;
 
  	struct workqueue_struct *wq;
drivers/gpu/drm/omapdrm/omap_overlay.c new file +0 -0
new file mode 100644
index 000000000000..2b1416d2aad2

drivers/gpu/drm/omapdrm/omap_overlay.c line 4

Quoted 4 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +4 -0
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2018 Texas Instruments Incorporated -  http://www.ti.com/
+ * Author: Benoit Parrot, <[email protected]>

Extra comma there, and similar case below.

Quoted 8 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +8 -0
+ */
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_plane_helper.h>
+
+#include "omap_dmm_tiler.h"
+#include "omap_drv.h"

drivers/gpu/drm/omapdrm/omap_overlay.c line 22

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +10 -0
+
+/*
+ * overlay funcs
+ */
+static const char * const overlay_id_to_name[] = {
+	[OMAP_DSS_GFX] = "gfx",
+	[OMAP_DSS_VIDEO1] = "vid1",
+	[OMAP_DSS_VIDEO2] = "vid2",
+	[OMAP_DSS_VIDEO3] = "vid3",
+};

I was expecting to see the name array to be removed from omap_plane.c as it's moved here, but that's not the case. Why is that? Especially as after this series these names make no sense with the planes.

Quoted 13 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +13 -0
+static void omap_overlay_destroy(struct omap_hw_overlay *overlay)
+{
+	kfree(overlay);
+}
+
+static struct omap_hw_overlay *omap_overlay_init(enum omap_plane_id overlay_id,
+						 enum omap_overlay_caps caps)
+{
+	struct omap_hw_overlay *overlay;
+
+	overlay = kzalloc(sizeof(*overlay), GFP_KERNEL);
+	if (!overlay)
+		return ERR_PTR(-ENOMEM);

drivers/gpu/drm/omapdrm/omap_overlay.c line 46

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +10 -0
+
+	overlay->name = overlay_id_to_name[overlay_id];
+	overlay->overlay_id = overlay_id;
+	overlay->caps = caps;
+	/*
+	 * When this is called priv->num_crtcs is not known yet.
+	 * Use a safe mask value to start with, it will get updated to the
+	 * proper value after the first use.
+	 */
+	overlay->possible_crtcs = 0xff;

This sounds like a hack. Why do we need possible_crtcs anyway? If I'm not mistaken, on all DSS versions any overlay can be used on any ctrtc. On the DRM plane level we need the possible_crtc as the DRM framework needs that (i.e. we just always set all crtcs available for all planes), but why is it needed here?

Quoted 14 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +14 -0
+	return overlay;
+}
+
+int omap_hwoverlays_init(struct omap_drm_private *priv)
+{
+	static const enum omap_plane_id hw_plane_ids[] = {
+			OMAP_DSS_GFX, OMAP_DSS_VIDEO1,
+			OMAP_DSS_VIDEO2, OMAP_DSS_VIDEO3,
+	};
+	u32 num_overlays = dispc_get_num_ovls(priv->dispc);
+	enum omap_overlay_caps caps;
+	int i, ret;
+
+	for (i = 0; i < num_overlays; i++) {

drivers/gpu/drm/omapdrm/omap_overlay.c line 71

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +10 -0
+		struct omap_hw_overlay *overlay;
+
+		caps = dispc_ovl_get_caps(priv->dispc, hw_plane_ids[i]);
+		overlay = omap_overlay_init(hw_plane_ids[i], caps);
+		if (IS_ERR(overlay)) {
+			ret = PTR_ERR(overlay);
+			dev_err(priv->dev, "failed to construct overlay for %s (%d)\n",
+				overlay_id_to_name[i], ret);
+			return ret;
+		}

I think this leaks memory if omap_overlay_init() fails.

Quoted 32 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +16 -0
+		overlay->idx = priv->num_ovls;
+		priv->overlays[priv->num_ovls++] = overlay;
+	}
+
+	return 0;
+}
+
+void omap_hwoverlays_destroy(struct omap_drm_private *priv)
+{
+	int i;
+
+	for (i = 0; i < priv->num_ovls; i++) {
+		omap_overlay_destroy(priv->overlays[i]);
+		priv->overlays[i] = NULL;
+	}
+}
drivers/gpu/drm/omapdrm/omap_overlay.h new file +10 -0
new file mode 100644
index 000000000000..892fecb67adb
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2018 Texas Instruments Incorporated -  http://www.ti.com/
+ * Author: Benoit Parrot, <[email protected]>
+ */
+
+#ifndef __OMAPDRM_OVERLAY_H__
+#define __OMAPDRM_OVERLAY_H__
+
+#include <linux/types.h>

drivers/gpu/drm/omapdrm/omap_overlay.h line 20

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.h new file +10 -0
+
+enum drm_plane_type;
+
+struct drm_device;
+struct drm_mode_object;
+struct drm_plane;
+
+/* Used to associate a HW overlay/plane to a plane */
+struct omap_hw_overlay {
+	int idx;

unsigned int.

drivers/gpu/drm/omapdrm/omap_overlay.h line 23

Quoted 3 lines
drivers/gpu/drm/omapdrm/omap_overlay.h new file +3 -0
+
+	const char *name;
+	enum omap_plane_id overlay_id;

Perhaps just "id" is fine. You don't have "overlay_name" there either, but just "name".

Tomi

#7 lore raw

Re: [PATCH v5 3/8] drm/omap: introduce omap_hw_overlay

Quoted 90 lines · Tomi Valkeinen
Quoted 89 lines · Neil Armstrong

From: Benoit Parrot <[email protected]>

Split out the hardware overlay specifics from omap_plane. To start, the hw overlays are statically assigned to planes.

The goal is to eventually assign hw overlays dynamically to planes during plane->atomic_check() based on requested caps (scaling, YUV, etc). And then perform hw overlay re-assignment if required.

---
  drivers/gpu/drm/omapdrm/Makefile       |  1 + drivers/gpu/drm/omapdrm/omap_drv.c     |  9 ++- drivers/gpu/drm/omapdrm/omap_drv.h     |  4 ++ drivers/gpu/drm/omapdrm/omap_overlay.c | 87 ++++++++++++++++++++++++++ drivers/gpu/drm/omapdrm/omap_overlay.h | 31 +++++++++ drivers/gpu/drm/omapdrm/omap_plane.c   | 42 ++++++-------

  6 files changed, 151 insertions(+), 23 deletions(-)

  create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.c create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.h

drivers/gpu/drm/omapdrm/Makefile +1 -0
index 21e8277ff88f..710b4e0abcf0 100644
@@ -9,6 +9,7 @@ omapdrm-y := omap_drv.o \
       omap_debugfs.o \
       omap_crtc.o \
       omap_plane.o \
+    omap_overlay.o \
       omap_encoder.o \
       omap_fb.o \
       omap_gem.o \
drivers/gpu/drm/omapdrm/omap_drv.c +4 -1
index f86e20578143..b994014b22e8 100644
@@ -583,10 +583,14 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
         omap_gem_init(ddev);
   +    ret = omap_hwoverlays_init(priv);
+    if (ret)
+        goto err_gem_deinit;
+
       ret = omap_modeset_init(ddev);
       if (ret) {
           dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
-        goto err_gem_deinit;
+        goto err_free_overlays;
       }
         /* Initialize vblank handling, start with all CRTCs disabled. */
@@ -618,6 +622,8 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
       omap_fbdev_fini(ddev);

  err_cleanup_modeset:
      omap_modeset_fini(ddev);
+err_free_overlays:
+    omap_hwoverlays_destroy(priv);
  err_gem_deinit:
      omap_gem_deinit(ddev);
      destroy_workqueue(priv->wq);

drivers/gpu/drm/omapdrm/omap_drv.c +1 -0
@@ -642,6 +648,7 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
       drm_atomic_helper_shutdown(ddev);
         omap_modeset_fini(ddev);
+    omap_hwoverlays_destroy(priv);
       omap_gem_deinit(ddev);
         destroy_workqueue(priv->wq);
drivers/gpu/drm/omapdrm/omap_drv.h +3 -0
index 591d4c273f02..b4d9c2062723 100644
@@ -24,6 +24,7 @@
   #include "omap_gem.h"
   #include "omap_irq.h"
   #include "omap_plane.h"
+#include "omap_overlay.h"
     #define DBG(fmt, ...) DRM_DEBUG_DRIVER(fmt"\n", ##__VA_ARGS__)
   #define VERB(fmt, ...) if (0) DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__) /* verbose debug */
@@ -57,6 +58,9 @@ struct omap_drm_private {
       unsigned int num_planes;
       struct drm_plane *planes[8];
   +    unsigned int num_ovls;
+    struct omap_hw_overlay *overlays[8];
+
       struct drm_fb_helper *fbdev;
         struct workqueue_struct *wq;
drivers/gpu/drm/omapdrm/omap_overlay.c new file +0 -1
new file mode 100644
index 000000000000..2b1416d2aad2
--- /dev/null
Quoted 8 lines

drivers/gpu/drm/omapdrm/omap_overlay.c line 4

Quoted 6 lines

+++ b/drivers/gpu/drm/omapdrm/omap_overlay.c

drivers/gpu/drm/omapdrm/omap_overlay.c new file +4 -0
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2018 Texas Instruments Incorporated -  http://www.ti.com/
+ * Author: Benoit Parrot, <[email protected]>

Extra comma there, and similar case below.

Fixed

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +12 -0
+ */
+
+#include <drm/drm_atomic.h>
+#include <drm/drm_atomic_helper.h>
+#include <drm/drm_plane_helper.h>
+
+#include "omap_dmm_tiler.h"
+#include "omap_drv.h"
+
+/*
+ * overlay funcs
+ */
Quoted 8 lines

drivers/gpu/drm/omapdrm/omap_overlay.c line 22

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +6 -0
+static const char * const overlay_id_to_name[] = {
+    [OMAP_DSS_GFX] = "gfx",
+    [OMAP_DSS_VIDEO1] = "vid1",
+    [OMAP_DSS_VIDEO2] = "vid2",
+    [OMAP_DSS_VIDEO3] = "vid3",
+};

I was expecting to see the name array to be removed from omap_plane.c as it's moved here, but that's not the case. Why is that? Especially as after this series these names make no sense with the planes.

You're right, I'll remove the one from omap_plane.c and where it's used.

Quoted 18 lines
Quoted 18 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +17 -0
+static void omap_overlay_destroy(struct omap_hw_overlay *overlay)
+{
+    kfree(overlay);
+}
+
+static struct omap_hw_overlay *omap_overlay_init(enum omap_plane_id overlay_id,
+                         enum omap_overlay_caps caps)
+{
+    struct omap_hw_overlay *overlay;
+
+    overlay = kzalloc(sizeof(*overlay), GFP_KERNEL);
+    if (!overlay)
+        return ERR_PTR(-ENOMEM);
+
+    overlay->name = overlay_id_to_name[overlay_id];
+    overlay->overlay_id = overlay_id;
+    overlay->caps = caps;
Quoted 8 lines

drivers/gpu/drm/omapdrm/omap_overlay.c line 46

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +6 -0
+    /*
+     * When this is called priv->num_crtcs is not known yet.
+     * Use a safe mask value to start with, it will get updated to the
+     * proper value after the first use.
+     */
+    overlay->possible_crtcs = 0xff;

This sounds like a hack. Why do we need possible_crtcs anyway? If I'm not mistaken, on all DSS versions any overlay can be used on any ctrtc. On the DRM plane level we need the possible_crtc as the DRM framework needs that (i.e. we just always set all crtcs available for all planes), but why is it needed here?

Indeed, in omap_drv.c we have:
plane_crtc_mask = (1 << priv->num_pipes) - 1;

for all planes, so I'll rework this.

Quoted 19 lines
Quoted 19 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +18 -0
+    return overlay;
+}
+
+int omap_hwoverlays_init(struct omap_drm_private *priv)
+{
+    static const enum omap_plane_id hw_plane_ids[] = {
+            OMAP_DSS_GFX, OMAP_DSS_VIDEO1,
+            OMAP_DSS_VIDEO2, OMAP_DSS_VIDEO3,
+    };
+    u32 num_overlays = dispc_get_num_ovls(priv->dispc);
+    enum omap_overlay_caps caps;
+    int i, ret;
+
+    for (i = 0; i < num_overlays; i++) {
+        struct omap_hw_overlay *overlay;
+
+        caps = dispc_ovl_get_caps(priv->dispc, hw_plane_ids[i]);
+        overlay = omap_overlay_init(hw_plane_ids[i], caps);
Quoted 8 lines

drivers/gpu/drm/omapdrm/omap_overlay.c line 71

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +6 -0
+        if (IS_ERR(overlay)) {
+            ret = PTR_ERR(overlay);
+            dev_err(priv->dev, "failed to construct overlay for %s (%d)\n",
+                overlay_id_to_name[i], ret);
+            return ret;
+        }

I think this leaks memory if omap_overlay_init() fails.

Fixed

Quoted 46 lines
Quoted 33 lines
drivers/gpu/drm/omapdrm/omap_overlay.c new file +16 -0
+        overlay->idx = priv->num_ovls;
+        priv->overlays[priv->num_ovls++] = overlay;
+    }
+
+    return 0;
+}
+
+void omap_hwoverlays_destroy(struct omap_drm_private *priv)
+{
+    int i;
+
+    for (i = 0; i < priv->num_ovls; i++) {
+        omap_overlay_destroy(priv->overlays[i]);
+        priv->overlays[i] = NULL;
+    }
+}
drivers/gpu/drm/omapdrm/omap_overlay.h new file +10 -0
new file mode 100644
index 000000000000..892fecb67adb
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2018 Texas Instruments Incorporated -  http://www.ti.com/
+ * Author: Benoit Parrot, <[email protected]>
+ */
+
+#ifndef __OMAPDRM_OVERLAY_H__
+#define __OMAPDRM_OVERLAY_H__
+
+#include <linux/types.h>

drivers/gpu/drm/omapdrm/omap_overlay.h line 20

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.h new file +10 -0
+
+enum drm_plane_type;
+
+struct drm_device;
+struct drm_mode_object;
+struct drm_plane;
+
+/* Used to associate a HW overlay/plane to a plane */
+struct omap_hw_overlay {
+    int idx;

unsigned int.

Quoted 5 lines

drivers/gpu/drm/omapdrm/omap_overlay.h line 23

Quoted 3 lines
drivers/gpu/drm/omapdrm/omap_overlay.h new file +3 -0
+
+    const char *name;
+    enum omap_plane_id overlay_id;

Perhaps just "id" is fine. You don't have "overlay_name" there either, but just "name".

Ack

Quoted 2 lines

 Tomi

Thanks,
Neil

#8 lore raw

PATCH v5 4/8 drm/omap: omap_plane: subclass drm_plane_state

In reply to Neil Armstrong

From: Benoit Parrot <[email protected]>

In preparation to add omap plane state specific extensions we need to subclass drm_plane_state and add the relevant helpers.

The addition of specific extension will be done separately.

---
 drivers/gpu/drm/omapdrm/omap_plane.c | 38 +++++++++++++++++++++++++---
 1 file changed, 35 insertions(+), 3 deletions(-)
drivers/gpu/drm/omapdrm/omap_plane.c +35 -3
index 0df5381cc015..bda794b4c915 100644
@@ -16,6 +16,13 @@
  * plane funcs
  */
 
+#define to_omap_plane_state(x) container_of(x, struct omap_plane_state, base)
+
+struct omap_plane_state {
+	/* Must be first. */
+	struct drm_plane_state base;
+};
+
 #define to_omap_plane(x) container_of(x, struct omap_plane, base)
 
 struct omap_plane {
@@ -207,11 +214,17 @@ void omap_plane_install_properties(struct drm_plane *plane,
 static void omap_plane_reset(struct drm_plane *plane)
 {
 	struct omap_plane *omap_plane = to_omap_plane(plane);
+	struct omap_plane_state *omap_state;
 
-	drm_atomic_helper_plane_reset(plane);
-	if (!plane->state)
+	if (plane->state)
+		drm_atomic_helper_plane_destroy_state(plane, plane->state);
+
+	omap_state = kzalloc(sizeof(*omap_state), GFP_KERNEL);
+	if (!omap_state)
 		return;
 
+	__drm_atomic_helper_plane_reset(plane, &omap_state->base);
+
 	/*
 	 * Set the zpos default depending on whether we are a primary or overlay
 	 * plane.
@@ -222,6 +235,25 @@ static void omap_plane_reset(struct drm_plane *plane)
 	plane->state->color_range = DRM_COLOR_YCBCR_FULL_RANGE;
 }
 
+static struct drm_plane_state *
+omap_plane_atomic_duplicate_state(struct drm_plane *plane)
+{
+	struct omap_plane_state *state;
+	struct omap_plane_state *copy;
+
+	if (WARN_ON(!plane->state))
+		return NULL;
+
+	state = to_omap_plane_state(plane->state);
+	copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
+	if (!copy)
+		return NULL;
+
+	__drm_atomic_helper_plane_duplicate_state(plane, &copy->base);
+
+	return &copy->base;
+}
+
 static int omap_plane_atomic_set_property(struct drm_plane *plane,
 					  struct drm_plane_state *state,
 					  struct drm_property *property,
@@ -257,7 +289,7 @@ static const struct drm_plane_funcs omap_plane_funcs = {
 	.disable_plane = drm_atomic_helper_disable_plane,
 	.reset = omap_plane_reset,
 	.destroy = omap_plane_destroy,
-	.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
+	.atomic_duplicate_state = omap_plane_atomic_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 	.atomic_set_property = omap_plane_atomic_set_property,
 	.atomic_get_property = omap_plane_atomic_get_property,
Signature · 1 line
2.25.1
maintainer
#9 lore raw

Re: [PATCH v5 4/8] drm/omap: omap_plane: subclass drm_plane_state

Quoted 64 lines · Neil Armstrong

From: Benoit Parrot <[email protected]>

In preparation to add omap plane state specific extensions we need to subclass drm_plane_state and add the relevant helpers.

The addition of specific extension will be done separately.

---
  drivers/gpu/drm/omapdrm/omap_plane.c | 38 +++++++++++++++++++++++++---
  1 file changed, 35 insertions(+), 3 deletions(-)
drivers/gpu/drm/omapdrm/omap_plane.c +24 -2
index 0df5381cc015..bda794b4c915 100644
@@ -16,6 +16,13 @@
   * plane funcs
   */
 
+#define to_omap_plane_state(x) container_of(x, struct omap_plane_state, base)
+
+struct omap_plane_state {
+	/* Must be first. */
+	struct drm_plane_state base;
+};
+
  #define to_omap_plane(x) container_of(x, struct omap_plane, base)
 
  struct omap_plane {
@@ -207,11 +214,17 @@ void omap_plane_install_properties(struct drm_plane *plane,
  static void omap_plane_reset(struct drm_plane *plane)
  {
  	struct omap_plane *omap_plane = to_omap_plane(plane);
+	struct omap_plane_state *omap_state;
 
-	drm_atomic_helper_plane_reset(plane);
-	if (!plane->state)
+	if (plane->state)
+		drm_atomic_helper_plane_destroy_state(plane, plane->state);
+
+	omap_state = kzalloc(sizeof(*omap_state), GFP_KERNEL);
+	if (!omap_state)
  		return;
 
+	__drm_atomic_helper_plane_reset(plane, &omap_state->base);
+
  	/*
  	 * Set the zpos default depending on whether we are a primary or overlay
  	 * plane.
@@ -222,6 +235,25 @@ static void omap_plane_reset(struct drm_plane *plane)
  	plane->state->color_range = DRM_COLOR_YCBCR_FULL_RANGE;
  }
 
+static struct drm_plane_state *
+omap_plane_atomic_duplicate_state(struct drm_plane *plane)
+{
+	struct omap_plane_state *state;
+	struct omap_plane_state *copy;
+
+	if (WARN_ON(!plane->state))
+		return NULL;
+

drivers/gpu/drm/omapdrm/omap_plane.c static void omap_plane_reset(struct drm_plane *plane) · line 256

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_plane.c +10 -0
+	state = to_omap_plane_state(plane->state);
+	copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
+	if (!copy)
+		return NULL;
+
+	__drm_atomic_helper_plane_duplicate_state(plane, &copy->base);
+
+	return &copy->base;
+}
+

omap_crtc.c has similar, but slightly different, functions. I think it would be good to use the same style in omap_plane, or, if the approach above is better, change omap_crtc to match the style here.

Tomi

#10 lore raw

Re: [PATCH v5 4/8] drm/omap: omap_plane: subclass drm_plane_state

Quoted 64 lines · Tomi Valkeinen
Quoted 63 lines · Neil Armstrong

From: Benoit Parrot <[email protected]>

In preparation to add omap plane state specific extensions we need to subclass drm_plane_state and add the relevant helpers.

The addition of specific extension will be done separately.

---
  drivers/gpu/drm/omapdrm/omap_plane.c | 38 +++++++++++++++++++++++++---

  1 file changed, 35 insertions(+), 3 deletions(-)
drivers/gpu/drm/omapdrm/omap_plane.c +13 -1
index 0df5381cc015..bda794b4c915 100644
@@ -16,6 +16,13 @@
    * plane funcs
    */
   +#define to_omap_plane_state(x) container_of(x, struct omap_plane_state, base)
+
+struct omap_plane_state {
+    /* Must be first. */
+    struct drm_plane_state base;
+};
+
   #define to_omap_plane(x) container_of(x, struct omap_plane, base)
     struct omap_plane {
@@ -207,11 +214,17 @@ void omap_plane_install_properties(struct drm_plane *plane,
   static void omap_plane_reset(struct drm_plane *plane)
   {
       struct omap_plane *omap_plane = to_omap_plane(plane);
+    struct omap_plane_state *omap_state;
   -    drm_atomic_helper_plane_reset(plane);
-    if (!plane->state)
+    if (plane->state)
+        drm_atomic_helper_plane_destroy_state(plane, plane->state);
+
+    omap_state = kzalloc(sizeof(*omap_state), GFP_KERNEL);
+    if (!omap_state)
           return;
   +    __drm_atomic_helper_plane_reset(plane, &omap_state->base);
+
       /*
        * Set the zpos default depending on whether we are a primary or overlay
        * plane.
@@ -222,6 +235,25 @@ static void omap_plane_reset(struct drm_plane *plane)
       plane->state->color_range = DRM_COLOR_YCBCR_FULL_RANGE;
   }

  +static struct drm_plane_state *

drivers/gpu/drm/omapdrm/omap_plane.c +12 -0
+omap_plane_atomic_duplicate_state(struct drm_plane *plane)
+{
+    struct omap_plane_state *state;
+    struct omap_plane_state *copy;
+
+    if (WARN_ON(!plane->state))
+        return NULL;
+
+    state = to_omap_plane_state(plane->state);
+    copy = kmemdup(state, sizeof(*state), GFP_KERNEL);
+    if (!copy)
+        return NULL;
Quoted 8 lines

drivers/gpu/drm/omapdrm/omap_plane.c static void omap_plane_reset(struct drm_plane *plane) · line 256

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_plane.c +6 -0
+
+    __drm_atomic_helper_plane_duplicate_state(plane, &copy->base);
+
+    return &copy->base;
+}
+

omap_crtc.c has similar, but slightly different, functions. I think it would be good to use the same style in omap_plane, or, if the approach above is better, change omap_crtc to match the style here.

Indeed the crtc version is better, I used the same style.

Thanks,
Neil

Quoted 2 lines

 Tomi

#11 lore raw

PATCH v5 5/8 drm/omap: Add global state as a private atomic object

In reply to Neil Armstrong

From: Benoit Parrot <[email protected]>

Global shared resources (like hw overlays) for omapdrm are implemented as a part of atomic state using the drm_private_obj infrastructure available in the atomic core.

omap_global_state is introduced as a drm atomic private object. The two funcs omap_get_global_state() and omap_get_existing_global_state() are the two variants that will be used to access omap_global_state.

drm_mode_config_init() needs to be called earlier because it creates/initializes the private_obj link list maintained by the atomic framework. The private_obj link list has to exist prior to calling drm_atomic_private_obj_init(). Similarly the cleanup handler are reordered appropriately.

---
 drivers/gpu/drm/omapdrm/omap_drv.c | 91 +++++++++++++++++++++++++++++-
 drivers/gpu/drm/omapdrm/omap_drv.h | 21 +++++++
 2 files changed, 109 insertions(+), 3 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.c +88 -3
index b994014b22e8..c7912374d393 100644
@@ -128,6 +128,82 @@ static const struct drm_mode_config_funcs omap_mode_config_funcs = {
 	.atomic_commit = drm_atomic_helper_commit,
 };
 
+/* Global/shared object state funcs */
+
+/*
+ * This is a helper that returns the private state currently in operation.
+ * Note that this would return the "old_state" if called in the atomic check
+ * path, and the "new_state" after the atomic swap has been done.
+ */
+struct omap_global_state *
+omap_get_existing_global_state(struct omap_drm_private *priv)
+{
+	return to_omap_global_state(priv->glob_obj.state);
+}
+
+/*
+ * This acquires the modeset lock set aside for global state, creates
+ * a new duplicated private object state.
+ */
+struct omap_global_state *__must_check
+omap_get_global_state(struct drm_atomic_state *s)
+{
+	struct omap_drm_private *priv = s->dev->dev_private;
+	struct drm_private_state *priv_state;
+
+	priv_state = drm_atomic_get_private_obj_state(s, &priv->glob_obj);
+	if (IS_ERR(priv_state))
+		return ERR_CAST(priv_state);
+
+	return to_omap_global_state(priv_state);
+}
+
+static struct drm_private_state *
+omap_global_duplicate_state(struct drm_private_obj *obj)
+{
+	struct omap_global_state *state;
+
+	state = kmemdup(obj->state, sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return NULL;
+
+	__drm_atomic_helper_private_obj_duplicate_state(obj, &state->base);
+
+	return &state->base;
+}
+
+static void omap_global_destroy_state(struct drm_private_obj *obj,
+				      struct drm_private_state *state)
+{
+	struct omap_global_state *omap_state = to_omap_global_state(state);
+
+	kfree(omap_state);
+}
+
+static const struct drm_private_state_funcs omap_global_state_funcs = {
+	.atomic_duplicate_state = omap_global_duplicate_state,
+	.atomic_destroy_state = omap_global_destroy_state,
+};
+
+static int omap_global_obj_init(struct drm_device *dev)
+{
+	struct omap_drm_private *priv = dev->dev_private;
+	struct omap_global_state *state;
+
+	state = kzalloc(sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return -ENOMEM;
+
+	drm_atomic_private_obj_init(dev, &priv->glob_obj, &state->base,
+				    &omap_global_state_funcs);
+	return 0;
+}
+
+static void omap_global_obj_fini(struct omap_drm_private *priv)
+{
+	drm_atomic_private_obj_fini(&priv->glob_obj);
+}
+
 static void omap_disconnect_pipelines(struct drm_device *ddev)
 {
 	struct omap_drm_private *priv = ddev->dev_private;
@@ -231,8 +307,6 @@ static int omap_modeset_init(struct drm_device *dev)
 	if (!omapdss_stack_is_ready())
 		return -EPROBE_DEFER;
 
-	drm_mode_config_init(dev);
-
 	ret = omap_modeset_init_properties(dev);
 	if (ret < 0)
 		return ret;
@@ -583,10 +657,16 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
 
 	omap_gem_init(ddev);
 
-	ret = omap_hwoverlays_init(priv);
+	drm_mode_config_init(ddev);
+
+	ret = omap_global_obj_init(ddev);
 	if (ret)
 		goto err_gem_deinit;
 
+	ret = omap_hwoverlays_init(priv);
+	if (ret)
+		goto err_free_priv_obj;
+
 	ret = omap_modeset_init(ddev);
 	if (ret) {
 		dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
@@ -624,7 +704,10 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
 	omap_modeset_fini(ddev);
 err_free_overlays:
 	omap_hwoverlays_destroy(priv);
+err_free_priv_obj:
+	omap_global_obj_fini(priv);
 err_gem_deinit:
+	drm_mode_config_cleanup(ddev);
 	omap_gem_deinit(ddev);
 	destroy_workqueue(priv->wq);
 	omap_disconnect_pipelines(ddev);
@@ -649,6 +732,8 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
 
 	omap_modeset_fini(ddev);
 	omap_hwoverlays_destroy(priv);
+	omap_global_obj_fini(priv);
+	drm_mode_config_cleanup(ddev);
 	omap_gem_deinit(ddev);
 
 	destroy_workqueue(priv->wq);
drivers/gpu/drm/omapdrm/omap_drv.h +21 -0
index b4d9c2062723..280cdd27bc8e 100644
@@ -14,6 +14,7 @@
 #include "dss/omapdss.h"
 #include "dss/dss.h"
 
+#include <drm/drm_atomic.h>
 #include <drm/drm_gem.h>
 #include <drm/omap_drm.h>
 
@@ -41,6 +42,15 @@ struct omap_drm_pipeline {
 	unsigned int alias_id;
 };
 
+/*
+ * Global private object state for tracking resources that are shared across
+ * multiple kms objects (planes/crtcs/etc).
+ */
+#define to_omap_global_state(x) container_of(x, struct omap_global_state, base)
+struct omap_global_state {
+	struct drm_private_state base;
+};
+
 struct omap_drm_private {
 	struct drm_device *ddev;
 	struct device *dev;
@@ -61,6 +71,13 @@ struct omap_drm_private {
 	unsigned int num_ovls;
 	struct omap_hw_overlay *overlays[8];
 
+	/*
+	 * Global private object state, Do not access directly, use
+	 * omap_global_get_state()
+	 */
+	struct drm_modeset_lock glob_obj_lock;
+	struct drm_private_obj glob_obj;
+
 	struct drm_fb_helper *fbdev;
 
 	struct workqueue_struct *wq;
@@ -88,5 +105,9 @@ struct omap_drm_private {
 
 
 void omap_debugfs_init(struct drm_minor *minor);
+struct omap_global_state *__must_check
+omap_get_global_state(struct drm_atomic_state *s);
+struct omap_global_state *
+omap_get_existing_global_state(struct omap_drm_private *priv);
 
 #endif /* __OMAPDRM_DRV_H__ */
Signature · 1 line
2.25.1
maintainer
#12 lore raw

Re: [PATCH v5 5/8] drm/omap: Add global state as a private atomic object

Quoted 10 lines · Neil Armstrong

From: Benoit Parrot <[email protected]>

Global shared resources (like hw overlays) for omapdrm are implemented as a part of atomic state using the drm_private_obj infrastructure available in the atomic core.

omap_global_state is introduced as a drm atomic private object. The two funcs omap_get_global_state() and omap_get_existing_global_state() are the two variants that will be used to access omap_global_state.

Quoted 5 lines

drm_mode_config_init() needs to be called earlier because it creates/initializes the private_obj link list maintained by the atomic framework. The private_obj link list has to exist prior to calling drm_atomic_private_obj_init(). Similarly the cleanup handler are reordered appropriately.

I'm not really familiar with the private object. Did you check how current drivers use it? These patches are 3 years old, and things might have changed around the private object.

Quoted 154 lines
---
  drivers/gpu/drm/omapdrm/omap_drv.c | 91 +++++++++++++++++++++++++++++-
  drivers/gpu/drm/omapdrm/omap_drv.h | 21 +++++++
  2 files changed, 109 insertions(+), 3 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.c +88 -3
index b994014b22e8..c7912374d393 100644
@@ -128,6 +128,82 @@ static const struct drm_mode_config_funcs omap_mode_config_funcs = {
  	.atomic_commit = drm_atomic_helper_commit,
  };
 
+/* Global/shared object state funcs */
+
+/*
+ * This is a helper that returns the private state currently in operation.
+ * Note that this would return the "old_state" if called in the atomic check
+ * path, and the "new_state" after the atomic swap has been done.
+ */
+struct omap_global_state *
+omap_get_existing_global_state(struct omap_drm_private *priv)
+{
+	return to_omap_global_state(priv->glob_obj.state);
+}
+
+/*
+ * This acquires the modeset lock set aside for global state, creates
+ * a new duplicated private object state.
+ */
+struct omap_global_state *__must_check
+omap_get_global_state(struct drm_atomic_state *s)
+{
+	struct omap_drm_private *priv = s->dev->dev_private;
+	struct drm_private_state *priv_state;
+
+	priv_state = drm_atomic_get_private_obj_state(s, &priv->glob_obj);
+	if (IS_ERR(priv_state))
+		return ERR_CAST(priv_state);
+
+	return to_omap_global_state(priv_state);
+}
+
+static struct drm_private_state *
+omap_global_duplicate_state(struct drm_private_obj *obj)
+{
+	struct omap_global_state *state;
+
+	state = kmemdup(obj->state, sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return NULL;
+
+	__drm_atomic_helper_private_obj_duplicate_state(obj, &state->base);
+
+	return &state->base;
+}
+
+static void omap_global_destroy_state(struct drm_private_obj *obj,
+				      struct drm_private_state *state)
+{
+	struct omap_global_state *omap_state = to_omap_global_state(state);
+
+	kfree(omap_state);
+}
+
+static const struct drm_private_state_funcs omap_global_state_funcs = {
+	.atomic_duplicate_state = omap_global_duplicate_state,
+	.atomic_destroy_state = omap_global_destroy_state,
+};
+
+static int omap_global_obj_init(struct drm_device *dev)
+{
+	struct omap_drm_private *priv = dev->dev_private;
+	struct omap_global_state *state;
+
+	state = kzalloc(sizeof(*state), GFP_KERNEL);
+	if (!state)
+		return -ENOMEM;
+
+	drm_atomic_private_obj_init(dev, &priv->glob_obj, &state->base,
+				    &omap_global_state_funcs);
+	return 0;
+}
+
+static void omap_global_obj_fini(struct omap_drm_private *priv)
+{
+	drm_atomic_private_obj_fini(&priv->glob_obj);
+}
+
  static void omap_disconnect_pipelines(struct drm_device *ddev)
  {
  	struct omap_drm_private *priv = ddev->dev_private;
@@ -231,8 +307,6 @@ static int omap_modeset_init(struct drm_device *dev)
  	if (!omapdss_stack_is_ready())
  		return -EPROBE_DEFER;
 
-	drm_mode_config_init(dev);
-
  	ret = omap_modeset_init_properties(dev);
  	if (ret < 0)
  		return ret;
@@ -583,10 +657,16 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
 
  	omap_gem_init(ddev);
 
-	ret = omap_hwoverlays_init(priv);
+	drm_mode_config_init(ddev);
+
+	ret = omap_global_obj_init(ddev);
  	if (ret)
  		goto err_gem_deinit;
 
+	ret = omap_hwoverlays_init(priv);
+	if (ret)
+		goto err_free_priv_obj;
+
  	ret = omap_modeset_init(ddev);
  	if (ret) {
  		dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
@@ -624,7 +704,10 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
  	omap_modeset_fini(ddev);
  err_free_overlays:
  	omap_hwoverlays_destroy(priv);
+err_free_priv_obj:
+	omap_global_obj_fini(priv);
  err_gem_deinit:
+	drm_mode_config_cleanup(ddev);
  	omap_gem_deinit(ddev);
  	destroy_workqueue(priv->wq);
  	omap_disconnect_pipelines(ddev);
@@ -649,6 +732,8 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
 
  	omap_modeset_fini(ddev);
  	omap_hwoverlays_destroy(priv);
+	omap_global_obj_fini(priv);
+	drm_mode_config_cleanup(ddev);
  	omap_gem_deinit(ddev);
 
  	destroy_workqueue(priv->wq);
drivers/gpu/drm/omapdrm/omap_drv.h +1 -0
index b4d9c2062723..280cdd27bc8e 100644
@@ -14,6 +14,7 @@
  #include "dss/omapdss.h"
  #include "dss/dss.h"
 
+#include <drm/drm_atomic.h>
  #include <drm/drm_gem.h>
  #include <drm/omap_drm.h>
 

drivers/gpu/drm/omapdrm/omap_drv.h struct omap_drm_pipeline { · line 49

Quoted 8 lines
drivers/gpu/drm/omapdrm/omap_drv.h +5 -0
@@ -41,6 +42,15 @@ struct omap_drm_pipeline {
  	unsigned int alias_id;
  };
 
+/*
+ * Global private object state for tracking resources that are shared across
+ * multiple kms objects (planes/crtcs/etc).
+ */
+#define to_omap_global_state(x) container_of(x, struct omap_global_state, base)

Add empty line here.

Quoted 8 lines
drivers/gpu/drm/omapdrm/omap_drv.h +4 -0
+struct omap_global_state {
+	struct drm_private_state base;
+};
+
  struct omap_drm_private {
  	struct drm_device *ddev;
  	struct device *dev;

drivers/gpu/drm/omapdrm/omap_drv.h struct omap_drm_private { · line 78

Quoted 8 lines
drivers/gpu/drm/omapdrm/omap_drv.h +5 -0
@@ -61,6 +71,13 @@ struct omap_drm_private {
  	unsigned int num_ovls;
  	struct omap_hw_overlay *overlays[8];
 
+	/*
+	 * Global private object state, Do not access directly, use
+	 * omap_global_get_state()
+	 */
+	struct drm_modeset_lock glob_obj_lock;

This is not used... What am I missing?

drivers/gpu/drm/omapdrm/omap_drv.h struct omap_drm_private { · line 111

Quoted 13 lines
drivers/gpu/drm/omapdrm/omap_drv.h +6 -0
+	struct drm_private_obj glob_obj;
+
  	struct drm_fb_helper *fbdev;
 
  	struct workqueue_struct *wq;
@@ -88,5 +105,9 @@ struct omap_drm_private {
 
 
  void omap_debugfs_init(struct drm_minor *minor);
+struct omap_global_state *__must_check
+omap_get_global_state(struct drm_atomic_state *s);
+struct omap_global_state *
+omap_get_existing_global_state(struct omap_drm_private *priv);

These could also be separated by empty lines. At least to my eyes it gets confusing if those declarations are not separated.

Tomi

#13 lore raw

Re: [PATCH v5 5/8] drm/omap: Add global state as a private atomic object

Hi,

Quoted 11 lines · Tomi Valkeinen
Quoted 10 lines · Neil Armstrong

From: Benoit Parrot <[email protected]>

Global shared resources (like hw overlays) for omapdrm are implemented as a part of atomic state using the drm_private_obj infrastructure available in the atomic core.

omap_global_state is introduced as a drm atomic private object. The two funcs omap_get_global_state() and omap_get_existing_global_state() are the two variants that will be used to access omap_global_state.

Quoted 7 lines
Quoted 5 lines

drm_mode_config_init() needs to be called earlier because it creates/initializes the private_obj link list maintained by the atomic framework. The private_obj link list has to exist prior to calling drm_atomic_private_obj_init(). Similarly the cleanup handler are reordered appropriately.

I'm not really familiar with the private object. Did you check how current drivers use it? These patches are 3 years old, and things might have changed around the private object.

Indeed, I checked and this is used in vc4/tegra/arm/amd & msm in the same as way.

Quoted 147 lines
Quoted 147 lines

---
  drivers/gpu/drm/omapdrm/omap_drv.c | 91 +++++++++++++++++++++++++++++- drivers/gpu/drm/omapdrm/omap_drv.h | 21 +++++++

  2 files changed, 109 insertions(+), 3 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.c +0 -0
index b994014b22e8..c7912374d393 100644
@@ -128,6 +128,82 @@ static const struct drm_mode_config_funcs omap_mode_config_funcs = {
       .atomic_commit = drm_atomic_helper_commit,
   };

  +/* Global/shared object state funcs */

drivers/gpu/drm/omapdrm/omap_drv.c +75 -0
+
+/*
+ * This is a helper that returns the private state currently in operation.
+ * Note that this would return the "old_state" if called in the atomic check
+ * path, and the "new_state" after the atomic swap has been done.
+ */
+struct omap_global_state *
+omap_get_existing_global_state(struct omap_drm_private *priv)
+{
+    return to_omap_global_state(priv->glob_obj.state);
+}
+
+/*
+ * This acquires the modeset lock set aside for global state, creates
+ * a new duplicated private object state.
+ */
+struct omap_global_state *__must_check
+omap_get_global_state(struct drm_atomic_state *s)
+{
+    struct omap_drm_private *priv = s->dev->dev_private;
+    struct drm_private_state *priv_state;
+
+    priv_state = drm_atomic_get_private_obj_state(s, &priv->glob_obj);
+    if (IS_ERR(priv_state))
+        return ERR_CAST(priv_state);
+
+    return to_omap_global_state(priv_state);
+}
+
+static struct drm_private_state *
+omap_global_duplicate_state(struct drm_private_obj *obj)
+{
+    struct omap_global_state *state;
+
+    state = kmemdup(obj->state, sizeof(*state), GFP_KERNEL);
+    if (!state)
+        return NULL;
+
+    __drm_atomic_helper_private_obj_duplicate_state(obj, &state->base);
+
+    return &state->base;
+}
+
+static void omap_global_destroy_state(struct drm_private_obj *obj,
+                      struct drm_private_state *state)
+{
+    struct omap_global_state *omap_state = to_omap_global_state(state);
+
+    kfree(omap_state);
+}
+
+static const struct drm_private_state_funcs omap_global_state_funcs = {
+    .atomic_duplicate_state = omap_global_duplicate_state,
+    .atomic_destroy_state = omap_global_destroy_state,
+};
+
+static int omap_global_obj_init(struct drm_device *dev)
+{
+    struct omap_drm_private *priv = dev->dev_private;
+    struct omap_global_state *state;
+
+    state = kzalloc(sizeof(*state), GFP_KERNEL);
+    if (!state)
+        return -ENOMEM;
+
+    drm_atomic_private_obj_init(dev, &priv->glob_obj, &state->base,
+                    &omap_global_state_funcs);
+    return 0;
+}
+
+static void omap_global_obj_fini(struct omap_drm_private *priv)
+{
+    drm_atomic_private_obj_fini(&priv->glob_obj);
+}
+

  static void omap_disconnect_pipelines(struct drm_device *ddev) {
      struct omap_drm_private *priv = ddev->dev_private;

drivers/gpu/drm/omapdrm/omap_drv.c +6 -1
@@ -231,8 +307,6 @@ static int omap_modeset_init(struct drm_device *dev)
       if (!omapdss_stack_is_ready())
           return -EPROBE_DEFER;
   -    drm_mode_config_init(dev);
-
       ret = omap_modeset_init_properties(dev);
       if (ret < 0)
           return ret;
@@ -583,10 +657,16 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
         omap_gem_init(ddev);
   -    ret = omap_hwoverlays_init(priv);
+    drm_mode_config_init(ddev);
+
+    ret = omap_global_obj_init(ddev);
       if (ret)
           goto err_gem_deinit;
   +    ret = omap_hwoverlays_init(priv);
+    if (ret)
+        goto err_free_priv_obj;
+
       ret = omap_modeset_init(ddev);
       if (ret) {
           dev_err(priv->dev, "omap_modeset_init failed: ret=%d\n", ret);
@@ -624,7 +704,10 @@ static int omapdrm_init(struct omap_drm_private *priv, struct device *dev)
       omap_modeset_fini(ddev);

  err_free_overlays:
      omap_hwoverlays_destroy(priv);
+err_free_priv_obj:
+    omap_global_obj_fini(priv);
  err_gem_deinit:
+    drm_mode_config_cleanup(ddev);
      omap_gem_deinit(ddev);
      destroy_workqueue(priv->wq);
      omap_disconnect_pipelines(ddev);

drivers/gpu/drm/omapdrm/omap_drv.c +2 -0
@@ -649,6 +732,8 @@ static void omapdrm_cleanup(struct omap_drm_private *priv)
         omap_modeset_fini(ddev);
       omap_hwoverlays_destroy(priv);
+    omap_global_obj_fini(priv);
+    drm_mode_config_cleanup(ddev);
       omap_gem_deinit(ddev);
         destroy_workqueue(priv->wq);
drivers/gpu/drm/omapdrm/omap_drv.h +0 -0
index b4d9c2062723..280cdd27bc8e 100644
@@ -14,6 +14,7 @@
   #include "dss/omapdss.h"
   #include "dss/dss.h"

  +#include <drm/drm_atomic.h>
  #include <drm/drm_gem.h>
  #include <drm/omap_drm.h>
  @@ -41,6 +42,15 @@ struct omap_drm_pipeline {
      unsigned int alias_id;

Quoted 8 lines
Quoted 6 lines

  };
  +/*
+ * Global private object state for tracking resources that are shared across
+ * multiple kms objects (planes/crtcs/etc).
+ */
+#define to_omap_global_state(x) container_of(x, struct omap_global_state, base)

Add empty line here.

Ack

Quoted 10 lines
Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_drv.h +4 -0
+struct omap_global_state {
+    struct drm_private_state base;
+};
+

  struct omap_drm_private {
      struct drm_device *ddev;
      struct device *dev;

drivers/gpu/drm/omapdrm/omap_drv.h +0 -0
@@ -61,6 +71,13 @@ struct omap_drm_private {
       unsigned int num_ovls;
Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_drv.h +0 -0
       struct omap_hw_overlay *overlays[8];

  +    /*
+     * Global private object state, Do not access directly, use +     * omap_global_get_state()
+     */
+    struct drm_modeset_lock glob_obj_lock;

This is not used... What am I missing?

It's a leftover from v4, now the lock has been moved into drm_atomic_get_private_obj_state()

Quoted 13 lines

drivers/gpu/drm/omapdrm/omap_drv.h struct omap_drm_private { · line 109

Quoted 11 lines

+    struct drm_private_obj glob_obj;
+
      struct drm_fb_helper *fbdev;
        struct workqueue_struct *wq;

drivers/gpu/drm/omapdrm/omap_drv.h +4 -0
@@ -88,5 +105,9 @@ struct omap_drm_private {
       void omap_debugfs_init(struct drm_minor *minor);
+struct omap_global_state *__must_check
+omap_get_global_state(struct drm_atomic_state *s);
+struct omap_global_state *
+omap_get_existing_global_state(struct omap_drm_private *priv);

These could also be separated by empty lines. At least to my eyes it gets confusing if those declarations are not separated.

Atomic states can be extremely confusing, and hard to track. I checked and they do what they are documented for...

The omap_get_existing_global_state() is the most confusing since the result depends if we are in an atomic transaction of not.

Neil

Quoted 2 lines

 Tomi

maintainer
#14 lore raw

Re: [PATCH v5 5/8] drm/omap: Add global state as a private atomic object

Quoted 13 lines · Neil Armstrong
Quoted 4 lines
Quoted 4 lines

+    struct drm_private_obj glob_obj;
+
      struct drm_fb_helper *fbdev;
        struct workqueue_struct *wq;

Quoted 8 lines

drivers/gpu/drm/omapdrm/omap_drv.h struct omap_drm_private { · line 109

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_drv.h +4 -0
@@ -88,5 +105,9 @@ struct omap_drm_private {
       void omap_debugfs_init(struct drm_minor *minor);
+struct omap_global_state *__must_check
+omap_get_global_state(struct drm_atomic_state *s);
+struct omap_global_state *
+omap_get_existing_global_state(struct omap_drm_private *priv);

These could also be separated by empty lines. At least to my eyes it gets confusing if those declarations are not separated.

Quoted 5 lines

Atomic states can be extremely confusing, and hard to track. I checked and they do what they are documented for...

The omap_get_existing_global_state() is the most confusing since the result depends if we are in an atomic transaction of not.

So here I was just talking about the cosmetics, how the lines above look like. I have trouble seeing where the function declaration starts and where it ends without looking closely, as both lines of the declaration start at the first column, and there are no empty lines between the declarations.

But now that you mention, yes, the states are confusing =). And this series is somewhat difficult. I think it's important for future maintainability to include explanations and comments in this series for the confusing parts (plane-overlay mapping and state handling, mostly).

Tomi

#15 lore raw

Re: [PATCH v5 5/8] drm/omap: Add global state as a private atomic object

Quoted 15 lines · Tomi Valkeinen
Quoted 13 lines · Neil Armstrong
Quoted 12 lines

drivers/gpu/drm/omapdrm/omap_drv.h struct omap_drm_private { · line 109

Quoted 10 lines

+    struct drm_private_obj glob_obj;
+
       struct drm_fb_helper *fbdev;
         struct workqueue_struct *wq;

drivers/gpu/drm/omapdrm/omap_drv.h +4 -0
@@ -88,5 +105,9 @@ struct omap_drm_private {
        void omap_debugfs_init(struct drm_minor *minor);
+struct omap_global_state *__must_check
+omap_get_global_state(struct drm_atomic_state *s);
+struct omap_global_state *
+omap_get_existing_global_state(struct omap_drm_private *priv);

These could also be separated by empty lines. At least to my eyes it gets confusing if those declarations are not separated.

Quoted 7 lines
Quoted 5 lines

Atomic states can be extremely confusing, and hard to track. I checked and they do what they are documented for...

The omap_get_existing_global_state() is the most confusing since the result depends if we are in an atomic transaction of not.

So here I was just talking about the cosmetics, how the lines above look like. I have trouble seeing where the function declaration starts and where it ends without looking closely, as both lines of the declaration start at the first column, and there are no empty lines between the declarations.

Ok, it's a legacy of the 80chars max, will reformat.

Quoted 2 lines

But now that you mention, yes, the states are confusing =). And this series is somewhat difficult. I think it's important for future maintainability to include explanations and comments in this series for the confusing parts (plane-overlay mapping and state handling, mostly).

Yep I added some hopefully useful comments explaining that.

Neil

Quoted 2 lines

 Tomi

#16 lore raw

PATCH v5 6/8 drm/omap: dynamically assign hw overlays to planes

In reply to Neil Armstrong

From: Benoit Parrot <[email protected]>

(re)assign the hw overlays to planes based on required caps, and to handle situations where we could not modify an in-use plane.

This means all planes advertise the superset of formats and properties. Userspace must (as always) use atomic TEST_ONLY step for atomic updates, as not all planes may be available for use on every frame.

The mapping of hwoverlays to plane is stored in omap_global_state, so that state updates are atomically committed in the same way that plane/etc state updates are managed. This is needed because the omap_plane_state keeps a pointer to the hwoverlay, and we don't want global state to become out of sync with the plane state if an atomic update fails, we hit deadlock/ backoff scenario, etc. The use of global_state_lock keeps multiple parallel updates which both re-assign hwoverlays properly serialized.

---
 drivers/gpu/drm/omapdrm/omap_drv.h     |   3 +
 drivers/gpu/drm/omapdrm/omap_overlay.c | 140 ++++++++++++++++++++
 drivers/gpu/drm/omapdrm/omap_overlay.h |   9 ++
 drivers/gpu/drm/omapdrm/omap_plane.c   | 170 ++++++++++++++++++++-----
 4 files changed, 287 insertions(+), 35 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.h +3 -0
index 280cdd27bc8e..2d5928f05a23 100644
@@ -49,6 +49,9 @@ struct omap_drm_pipeline {
 #define to_omap_global_state(x) container_of(x, struct omap_global_state, base)
 struct omap_global_state {
 	struct drm_private_state base;
+
+	/* global atomic state of assignment between overlays and planes */
+	struct drm_plane *hwoverlay_to_plane[8];
 };
 
 struct omap_drm_private {
drivers/gpu/drm/omapdrm/omap_overlay.c +140 -0

146 lines not on this page · raw message

drivers/gpu/drm/omapdrm/omap_overlay.h +9 -0
index 892fecb67adb..d5033ee481c2 100644
@@ -28,4 +28,13 @@ struct omap_hw_overlay {
 
 int omap_hwoverlays_init(struct omap_drm_private *priv);
 void omap_hwoverlays_destroy(struct omap_drm_private *priv);
+int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane,
+			u32 caps, u32 fourcc, u32 crtc_mask,
+			struct omap_hw_overlay **overlay);
+void omap_overlay_release(struct drm_atomic_state *s,
+			  struct drm_plane *plane,
+			  struct omap_hw_overlay *overlay);
+void omap_overlay_disable(struct drm_atomic_state *s,
+			  struct drm_plane *plane,
+			  struct omap_hw_overlay *overlay);
 #endif /* __OMAPDRM_OVERLAY_H__ */
drivers/gpu/drm/omapdrm/omap_plane.c +135 -35

258 lines not on this page · raw message

Signature · 1 line
2.25.1
maintainer
#17 lore raw

Re: [PATCH v5 6/8] drm/omap: dynamically assign hw overlays to planes

Quoted 118 lines · Neil Armstrong

From: Benoit Parrot <[email protected]>

(re)assign the hw overlays to planes based on required caps, and to handle situations where we could not modify an in-use plane.

This means all planes advertise the superset of formats and properties. Userspace must (as always) use atomic TEST_ONLY step for atomic updates, as not all planes may be available for use on every frame.

The mapping of hwoverlays to plane is stored in omap_global_state, so that state updates are atomically committed in the same way that plane/etc state updates are managed. This is needed because the omap_plane_state keeps a pointer to the hwoverlay, and we don't want global state to become out of sync with the plane state if an atomic update fails, we hit deadlock/ backoff scenario, etc. The use of global_state_lock keeps multiple parallel updates which both re-assign hwoverlays properly serialized.

---
  drivers/gpu/drm/omapdrm/omap_drv.h     |   3 +
  drivers/gpu/drm/omapdrm/omap_overlay.c | 140 ++++++++++++++++++++
  drivers/gpu/drm/omapdrm/omap_overlay.h |   9 ++
  drivers/gpu/drm/omapdrm/omap_plane.c   | 170 ++++++++++++++++++++-----
  4 files changed, 287 insertions(+), 35 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.h +3 -0
index 280cdd27bc8e..2d5928f05a23 100644
@@ -49,6 +49,9 @@ struct omap_drm_pipeline {
  #define to_omap_global_state(x) container_of(x, struct omap_global_state, base)
  struct omap_global_state {
  	struct drm_private_state base;
+
+	/* global atomic state of assignment between overlays and planes */
+	struct drm_plane *hwoverlay_to_plane[8];
  };
 
  struct omap_drm_private {
drivers/gpu/drm/omapdrm/omap_overlay.c +69 -0
index 2b1416d2aad2..f1a23c2203aa 100644
@@ -21,6 +21,146 @@ static const char * const overlay_id_to_name[] = {
  	[OMAP_DSS_VIDEO3] = "vid3",
  };
 
+static struct omap_hw_overlay *
+omap_plane_find_free_overlay(struct drm_device *dev,
+			     struct drm_plane *hwoverlay_to_plane[],
+			     u32 caps, u32 fourcc, u32 crtc_mask)
+{
+	struct omap_drm_private *priv = dev->dev_private;
+	int i;
+
+	DBG("caps: %x fourcc: %x crtc: %x", caps, fourcc, crtc_mask);
+
+	for (i = 0; i < priv->num_ovls; i++) {
+		struct omap_hw_overlay *cur = priv->overlays[i];
+
+		DBG("%d: id: %d cur->caps: %x cur->crtc: %x",
+		    cur->idx, cur->overlay_id, cur->caps, cur->possible_crtcs);
+
+		/* skip if already in-use */
+		if (hwoverlay_to_plane[cur->idx])
+			continue;
+
+		/* check if allowed on crtc */
+		if (!(cur->possible_crtcs & crtc_mask))
+			continue;
+
+		/* skip if doesn't support some required caps: */
+		if (caps & ~cur->caps)
+			continue;
+
+		/* check supported format */
+		if (!dispc_ovl_color_mode_supported(priv->dispc,
+						    cur->overlay_id, fourcc))
+			continue;
+
+		return cur;
+	}
+
+	DBG("no match");
+	return NULL;
+}
+
+int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane,
+			u32 caps, u32 fourcc, u32 crtc_mask,
+			struct omap_hw_overlay **overlay)
+{
+	struct omap_drm_private *priv = s->dev->dev_private;
+	struct omap_global_state *new_global_state, *old_global_state;
+	struct drm_plane **overlay_map;
+	struct omap_hw_overlay *ovl;
+
+	new_global_state = omap_get_global_state(s);
+	if (IS_ERR(new_global_state))
+		return PTR_ERR(new_global_state);
+
+	/*
+	 * grab old_state after omap_get_global_state(),
+	 * since now we hold lock:
+	 */
+	old_global_state = omap_get_existing_global_state(priv);
+	DBG("new_global_state: %p old_global_state: %p",
+	    new_global_state, old_global_state);
+
+	overlay_map = new_global_state->hwoverlay_to_plane;
+
+	if (!*overlay) {
+		ovl = omap_plane_find_free_overlay(s->dev, overlay_map,
+						   caps, fourcc, crtc_mask);
+		if (!ovl)
+			return -ENOMEM;
+

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 102

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +10 -0
+		ovl->possible_crtcs = crtc_mask;
+		overlay_map[ovl->idx] = plane;
+		*overlay = ovl;
+
+		DBG("%s: assign to plane %s caps %x on crtc %x",
+		    (*overlay)->name, plane->name, caps, crtc_mask);
+	}
+
+	return 0;
+}

Why would one call this function with overlay == NULL? What does the function do in that case?

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 106

Quoted 4 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +4 -0
+
+void omap_overlay_release(struct drm_atomic_state *s,
+			  struct drm_plane *plane,
+			  struct omap_hw_overlay *overlay)

It feels odd to pass both plane and overlay here. If we're unassigning (is that a verb? =) the overlay, isn't it enough to just pass either the plane or the overlay?

Quoted 8 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +8 -0
+{
+	struct omap_global_state *state = omap_get_global_state(s);
+	struct drm_plane **overlay_map = state->hwoverlay_to_plane;
+
+	if (!overlay)
+		return;
+
+	if (WARN_ON(!overlay_map[overlay->idx]))

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 124

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +10 -0
+		return;
+	/*
+	 * Check that the overlay we are releasing is actually
+	 * assigned to the plane we are trying to release it from.
+	 */
+	if (overlay_map[overlay->idx] == plane) {
+		DBG("%s: release from plane %s", overlay->name, plane->name);
+
+		overlay_map[overlay->idx] = NULL;
+	}

So it's normal that overlay_map[overlay->idx] != plane? When does that happen?

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +6 -0
+}
+
+void omap_overlay_disable(struct drm_atomic_state *s,
+			  struct drm_plane *plane,
+			  struct omap_hw_overlay *overlay)
+{

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 140

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +10 -0
+	struct omap_drm_private *priv = s->dev->dev_private;
+	struct drm_plane **overlay_map;
+	struct omap_global_state *old_state;
+
+	old_state = omap_get_existing_global_state(priv);
+	overlay_map = old_state->hwoverlay_to_plane;
+
+	if (!overlay)
+		return;
+

You can move the if above to the beginning of the func.

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +6 -0
+	/*
+	 * Check that the overlay we are trying to disable has not
+	 * been re-assigned to another plane already
+	 */
+	if (!overlay_map[overlay->idx]) {
+		DBG("%s: on %s disabled", overlay->name, plane->name);

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 156

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +10 -0
+
+		/* disable the overlay */
+		dispc_ovl_enable(priv->dispc, overlay->overlay_id, false);
+
+		/*
+		 * Since we are disabling this overlay in this
+		 * atomic cycle we can reset the available crtcs
+		 * it can be used on
+		 */
+		overlay->possible_crtcs = (1 << priv->num_pipes) - 1;

This is changing data in the overlay struct itself. Shouldn't the mutable data be in the atomic state?

I'm also a bit confused on what the "possible_crtcs" is. But I think it's either a bitmask of all the crtcs when the overlay is free, or a mask of a single crtc when allocated.

I think a variable that's either 0 when the overlay is not assigned, or the mask of the crtc when in use, would be more clear. Also with some other name (active_crtc?).

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 162

Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +6 -0
+	}
+
+	/*
+	 * Otherwise the overlay is still in use so leave it alone
+	 */
+}

This function also has interesting behavior, possibly not disabling the hw overlay. I think these new exposed overlay functions could use a comment above each of them, explaining what they do.

Quoted 64 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +1 -0
+
  static void omap_overlay_destroy(struct omap_hw_overlay *overlay)
  {
  	kfree(overlay);
drivers/gpu/drm/omapdrm/omap_overlay.h +9 -0
index 892fecb67adb..d5033ee481c2 100644
@@ -28,4 +28,13 @@ struct omap_hw_overlay {
 
  int omap_hwoverlays_init(struct omap_drm_private *priv);
  void omap_hwoverlays_destroy(struct omap_drm_private *priv);
+int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane,
+			u32 caps, u32 fourcc, u32 crtc_mask,
+			struct omap_hw_overlay **overlay);
+void omap_overlay_release(struct drm_atomic_state *s,
+			  struct drm_plane *plane,
+			  struct omap_hw_overlay *overlay);
+void omap_overlay_disable(struct drm_atomic_state *s,
+			  struct drm_plane *plane,
+			  struct omap_hw_overlay *overlay);
  #endif /* __OMAPDRM_OVERLAY_H__ */
drivers/gpu/drm/omapdrm/omap_plane.c +8 -3
index bda794b4c915..4b400a8bfe9e 100644
@@ -8,6 +8,7 @@
  #include <drm/drm_atomic_helper.h>
  #include <drm/drm_gem_atomic_helper.h>
  #include <drm/drm_plane_helper.h>
+#include <drm/drm_fourcc.h>
 
  #include "omap_dmm_tiler.h"
  #include "omap_drv.h"
@@ -21,6 +22,8 @@
  struct omap_plane_state {
  	/* Must be first. */
  	struct drm_plane_state base;
+
+	struct omap_hw_overlay *overlay;
  };
 
  #define to_omap_plane(x) container_of(x, struct omap_plane, base)
@@ -29,8 +32,6 @@ struct omap_plane {
  	struct drm_plane base;
  	enum omap_plane_id id;
  	const char *name;
-
-	struct omap_hw_overlay *overlay;
  };
 
  static int omap_plane_prepare_fb(struct drm_plane *plane,
@@ -58,10 +59,27 @@ static void omap_plane_atomic_update(struct drm_plane *plane,
  	struct omap_plane *omap_plane = to_omap_plane(plane);
  	struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
  									   plane);
-	enum omap_plane_id ovl_id = omap_plane->overlay->overlay_id;
+	struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
+									   plane);
+	struct omap_plane_state *new_omap_state;
+	struct omap_plane_state *old_omap_state;
  	struct omap_overlay_info info;
+	enum omap_plane_id ovl_id;
  	int ret;

drivers/gpu/drm/omapdrm/omap_plane.c static void omap_plane_atomic_update(struct drm_plane *plane, · line 78

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_plane.c +9 -0
 
+	new_omap_state = to_omap_plane_state(new_state);
+	old_omap_state = to_omap_plane_state(old_state);
+
+	/* Cleanup previously held overlay if needed */
+	omap_overlay_disable(old_state->state, plane, old_omap_state->overlay);
+
+	if (!new_omap_state->overlay) {
+		DBG("[PLANE:%d:%s] overlay_id: ??? (%p)", plane->base.id, plane->name,
+		    new_omap_state->overlay);

I wonder what the ??? means here.

Already in earlier patches I wondered if the DBG prints were good or not, but I thought I'll comment on those after I can run this and see what they actually print. But some of them felt like debug prints used during development, not something to leave in the production code (at least in the form they were).

Quoted 32 lines
drivers/gpu/drm/omapdrm/omap_plane.c +12 -6
+		return;
+	}
+
+	ovl_id = new_omap_state->overlay->overlay_id;
  	DBG("%s, crtc=%p fb=%p", omap_plane->name, new_state->crtc,
  	    new_state->fb);
 
@@ -80,9 +98,9 @@ static void omap_plane_atomic_update(struct drm_plane *plane,
  	/* update scanout: */
  	omap_framebuffer_update_scanout(new_state->fb, new_state, &info);
 
-	DBG("%dx%d -> %dx%d (%d)", info.width, info.height,
-			info.out_width, info.out_height,
-			info.screen_width);
+	DBG("%s: %dx%d -> %dx%d (%d)",
+			new_omap_state->overlay->name, info.width, info.height,
+			info.out_width, info.out_height, info.screen_width);
  	DBG("%d,%d %pad %pad", info.pos_x, info.pos_y,
  			&info.paddr, &info.p_uv_addr);
 
@@ -105,55 +123,66 @@ static void omap_plane_atomic_disable(struct drm_plane *plane,
  {
  	struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
  									   plane);
-	struct omap_drm_private *priv = plane->dev->dev_private;
-	struct omap_plane *omap_plane = to_omap_plane(plane);
-	enum omap_plane_id ovl_id = omap_plane->overlay->overlay_id;
+	struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
+									   plane);
+	struct omap_plane_state *new_omap_state;
+	struct omap_plane_state *old_omap_state;
+

drivers/gpu/drm/omapdrm/omap_plane.c static void omap_plane_atomic_disable(struct drm_plane *plane, · line 139

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_plane.c +7 -1
+	new_omap_state = to_omap_plane_state(new_state);
+	old_omap_state = to_omap_plane_state(old_state);
+
+	if (!old_omap_state->overlay)
+		return;
 
  	new_state->rotation = DRM_MODE_ROTATE_0;
-	new_state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY ? 0 : omap_plane->id;
+	new_state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY
+			? 0 : old_omap_state->overlay->overlay_id;

I'm not sure if I'm right here, but... doesn't the above mean that the plane's zpos can change, depending on which hw overlay it happened to use?

Quoted 78 lines
drivers/gpu/drm/omapdrm/omap_plane.c +25 -22
-	dispc_ovl_enable(priv->dispc, ovl_id, false);
+	omap_overlay_disable(old_state->state, plane, old_omap_state->overlay);
+	new_omap_state->overlay = NULL;
  }
 
+#define FRAC_16_16(mult, div)    (((mult) << 16) / (div))
  static int omap_plane_atomic_check(struct drm_plane *plane,
  				   struct drm_atomic_state *state)
  {
  	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
  										 plane);
+	struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state,
+										 plane);
+	struct drm_crtc *crtc;
  	struct omap_drm_private *priv = plane->dev->dev_private;
+	struct omap_plane_state *omap_state = to_omap_plane_state(new_plane_state);
+	struct omap_global_state *omap_overlay_global_state;
+	u32 crtc_mask;
+	u32 fourcc;
+	u32 caps = 0;
+	bool new_hw_overlay = false;
+	int min_scale, max_scale;
+	int ret;
  	struct drm_crtc_state *crtc_state;
  	u16 width, height;
  	u32 width_fp, height_fp;
 
-	if (!new_plane_state->fb)
-		return 0;
+	omap_overlay_global_state = omap_get_global_state(state);
+	if (IS_ERR(omap_overlay_global_state))
+		return PTR_ERR(omap_overlay_global_state);
+	DBG("%s: omap_overlay_global_state: %p", plane->name,
+	    omap_overlay_global_state);
 
  	dispc_ovl_get_max_size(priv->dispc, &width, &height);
  	width_fp = width << 16;
  	height_fp = height << 16;
 
-	/* crtc should only be NULL when disabling (i.e., !new_plane_state->fb) */
-	if (WARN_ON(!new_plane_state->crtc))
+	crtc = new_plane_state->crtc ? new_plane_state->crtc : plane->state->crtc;
+	if (!crtc)
  		return 0;
 
-	crtc_state = drm_atomic_get_existing_crtc_state(state,
-							new_plane_state->crtc);
+	crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
  	/* we should have a crtc state if the plane is attached to a crtc */
  	if (WARN_ON(!crtc_state))
  		return 0;
 
-	if (!crtc_state->enable)
-		return 0;
-
-	if (new_plane_state->crtc_x < 0 || new_plane_state->crtc_y < 0)
-		return -EINVAL;
-
-	if (new_plane_state->crtc_x + new_plane_state->crtc_w > crtc_state->adjusted_mode.hdisplay)
-		return -EINVAL;
-
-	if (new_plane_state->crtc_y + new_plane_state->crtc_h > crtc_state->adjusted_mode.vdisplay)
-		return -EINVAL;
-
  	/* Make sure dimensions are within bounds. */
  	if (new_plane_state->src_h > height_fp || new_plane_state->crtc_h > height)
  		return -EINVAL;
@@ -161,9 +190,81 @@ static int omap_plane_atomic_check(struct drm_plane *plane,
  	if (new_plane_state->src_w > width_fp || new_plane_state->crtc_w > width)
  		return -EINVAL;
 
-	if (new_plane_state->rotation != DRM_MODE_ROTATE_0 &&
-	    !omap_framebuffer_supports_rotation(new_plane_state->fb))
-		return -EINVAL;
+
+	/*
+	 * Note: these are just sanity checks to filter out totally bad scaling

drivers/gpu/drm/omapdrm/omap_plane.c static int omap_plane_atomic_check(struct drm_plane *plane, · line 205

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_plane.c +10 -0
+	 * factors. The real limits must be calculated case by case, and
+	 * unfortunately we currently do those checks only at the commit
+	 * phase in dispc.
+	 */
+	min_scale = FRAC_16_16(1, 8);
+	max_scale = FRAC_16_16(8, 1);
+
+	ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state,
+						  min_scale, max_scale,
+						  true, true);

This piece here feels a bit out of context (wrt. to this patch). Why do we need it here, when adding support to hw overlays?

And I think it's fine to use the above helper, but maybe it can be in a separate patch earlier?

drivers/gpu/drm/omapdrm/omap_plane.c static int omap_plane_atomic_check(struct drm_plane *plane, · line 210

Quoted 5 lines
drivers/gpu/drm/omapdrm/omap_plane.c +5 -0
+	if (ret)
+		return ret;
+
+	DBG("%s: check (%d -> %d)", plane->name,
+	    old_plane_state->visible, new_plane_state->visible);

Here's an example of the debug prints I mentioned earlier. I think this prints:

"GFX: check (1 -> 0)"

I'm fine with terse debug prints, but... maybe something like "visible 1 -> 0" would be much better? =)

Quoted 60 lines
drivers/gpu/drm/omapdrm/omap_plane.c +56 -0
+	if (new_plane_state->visible) {
+		if (new_plane_state->rotation != DRM_MODE_ROTATE_0 &&
+		    !omap_framebuffer_supports_rotation(new_plane_state->fb))
+			return -EINVAL;
+
+		if ((new_plane_state->src_w >> 16) != new_plane_state->crtc_w ||
+		    (new_plane_state->src_h >> 16) != new_plane_state->crtc_h)
+			caps |= OMAP_DSS_OVL_CAP_SCALE;
+
+		fourcc = new_plane_state->fb->format->format;
+		crtc_mask = drm_crtc_mask(new_plane_state->crtc);
+
+		/*
+		 * (re)allocate hw overlay if we don't have one or
+		 * there is a caps mismatch
+		 */
+		if (!omap_state->overlay ||
+		    (caps & ~omap_state->overlay->caps)) {
+			new_hw_overlay = true;
+		} else {
+			/* check if allowed on crtc */
+			if (!(omap_state->overlay->possible_crtcs & crtc_mask))
+				new_hw_overlay = true;
+
+			/* check supported format */
+			if (!dispc_ovl_color_mode_supported(priv->dispc,
+						omap_state->overlay->overlay_id,
+						fourcc))
+				new_hw_overlay = true;
+		}
+
+		if (new_hw_overlay) {
+			struct omap_hw_overlay *old_ovl = omap_state->overlay;
+			struct omap_hw_overlay *new_ovl = NULL;
+
+			omap_overlay_release(state, plane, old_ovl);
+
+			ret = omap_overlay_assign(state, plane, caps,
+						  fourcc, crtc_mask, &new_ovl);
+			if (ret) {
+				DBG("%s: failed to assign hw_overlay(s)!",
+				    plane->name);
+				omap_state->overlay = NULL;
+				return ret;
+			}
+
+			omap_state->overlay = new_ovl;
+		}
+	} else {
+		omap_overlay_release(state, plane, omap_state->overlay);
+		omap_state->overlay = NULL;
+	}
+
+	if (omap_state->overlay)
+		DBG("plane: %s overlay_id: %d", plane->name,
+		    omap_state->overlay->overlay_id);
 
  	return 0;
  }

drivers/gpu/drm/omapdrm/omap_plane.c static void omap_plane_reset(struct drm_plane *plane) · line 334

Quoted 5 lines
drivers/gpu/drm/omapdrm/omap_plane.c +1 -1
@@ -230,7 +331,7 @@ static void omap_plane_reset(struct drm_plane *plane)
  	 * plane.
  	 */
  	plane->state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY
-			   ? 0 : omap_plane->overlay->overlay_id;
+			   ? 0 : omap_plane->id;

Hmm... On plane reset we now set the zpos to plane->id, but on disable we reset zpos to overlay->id. And before this patch we set the vice versa. I don't follow.

Tomi

#18 lore raw

Re: [PATCH v5 6/8] drm/omap: dynamically assign hw overlays to planes

Quoted 121 lines · Tomi Valkeinen
Quoted 120 lines · Neil Armstrong

From: Benoit Parrot <[email protected]>

(re)assign the hw overlays to planes based on required caps, and to handle situations where we could not modify an in-use plane.

This means all planes advertise the superset of formats and properties. Userspace must (as always) use atomic TEST_ONLY step for atomic updates, as not all planes may be available for use on every frame.

The mapping of hwoverlays to plane is stored in omap_global_state, so that state updates are atomically committed in the same way that plane/etc state updates are managed.  This is needed because the omap_plane_state keeps a pointer to the hwoverlay, and we don't want global state to become out of sync with the plane state if an atomic update fails, we hit deadlock/ backoff scenario, etc.  The use of global_state_lock keeps multiple parallel updates which both re-assign hwoverlays properly serialized.

---
  drivers/gpu/drm/omapdrm/omap_drv.h     |   3 + drivers/gpu/drm/omapdrm/omap_overlay.c | 140 ++++++++++++++++++++ drivers/gpu/drm/omapdrm/omap_overlay.h |   9 ++ drivers/gpu/drm/omapdrm/omap_plane.c   | 170 ++++++++++++++++++++-----

  4 files changed, 287 insertions(+), 35 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.h +3 -0
index 280cdd27bc8e..2d5928f05a23 100644
@@ -49,6 +49,9 @@ struct omap_drm_pipeline {
   #define to_omap_global_state(x) container_of(x, struct omap_global_state, base)
   struct omap_global_state {
       struct drm_private_state base;
+
+    /* global atomic state of assignment between overlays and planes */
+    struct drm_plane *hwoverlay_to_plane[8];
   };
     struct omap_drm_private {
drivers/gpu/drm/omapdrm/omap_overlay.c +0 -0
index 2b1416d2aad2..f1a23c2203aa 100644
@@ -21,6 +21,146 @@ static const char * const overlay_id_to_name[] = {
       [OMAP_DSS_VIDEO3] = "vid3",
   };

  +static struct omap_hw_overlay *

drivers/gpu/drm/omapdrm/omap_overlay.c +72 -0
+omap_plane_find_free_overlay(struct drm_device *dev,
+                 struct drm_plane *hwoverlay_to_plane[],
+                 u32 caps, u32 fourcc, u32 crtc_mask)
+{
+    struct omap_drm_private *priv = dev->dev_private;
+    int i;
+
+    DBG("caps: %x fourcc: %x crtc: %x", caps, fourcc, crtc_mask);
+
+    for (i = 0; i < priv->num_ovls; i++) {
+        struct omap_hw_overlay *cur = priv->overlays[i];
+
+        DBG("%d: id: %d cur->caps: %x cur->crtc: %x",
+            cur->idx, cur->overlay_id, cur->caps, cur->possible_crtcs);
+
+        /* skip if already in-use */
+        if (hwoverlay_to_plane[cur->idx])
+            continue;
+
+        /* check if allowed on crtc */
+        if (!(cur->possible_crtcs & crtc_mask))
+            continue;
+
+        /* skip if doesn't support some required caps: */
+        if (caps & ~cur->caps)
+            continue;
+
+        /* check supported format */
+        if (!dispc_ovl_color_mode_supported(priv->dispc,
+                            cur->overlay_id, fourcc))
+            continue;
+
+        return cur;
+    }
+
+    DBG("no match");
+    return NULL;
+}
+
+int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane,
+            u32 caps, u32 fourcc, u32 crtc_mask,
+            struct omap_hw_overlay **overlay)
+{
+    struct omap_drm_private *priv = s->dev->dev_private;
+    struct omap_global_state *new_global_state, *old_global_state;
+    struct drm_plane **overlay_map;
+    struct omap_hw_overlay *ovl;
+
+    new_global_state = omap_get_global_state(s);
+    if (IS_ERR(new_global_state))
+        return PTR_ERR(new_global_state);
+
+    /*
+     * grab old_state after omap_get_global_state(),
+     * since now we hold lock:
+     */
+    old_global_state = omap_get_existing_global_state(priv);
+    DBG("new_global_state: %p old_global_state: %p",
+        new_global_state, old_global_state);
+
+    overlay_map = new_global_state->hwoverlay_to_plane;
+
+    if (!*overlay) {
+        ovl = omap_plane_find_free_overlay(s->dev, overlay_map,
+                           caps, fourcc, crtc_mask);
+        if (!ovl)
+            return -ENOMEM;
+
+        ovl->possible_crtcs = crtc_mask;
+        overlay_map[ovl->idx] = plane;
+        *overlay = ovl;
+
Quoted 8 lines

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 102

Quoted 6 lines

+        DBG("%s: assign to plane %s caps %x on crtc %x", +            (*overlay)->name, plane->name, caps, crtc_mask); +    }

drivers/gpu/drm/omapdrm/omap_overlay.c +3 -0
+
+    return 0;
+}

Why would one call this function with overlay == NULL? What does the function do in that case?

This function is only called with !*overlay, no ide why it would be called with *overlay != NULL... I'll try to simplify this.

Quoted 7 lines

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 106

Quoted 5 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +4 -0
+
+void omap_overlay_release(struct drm_atomic_state *s,
+              struct drm_plane *plane,
+              struct omap_hw_overlay *overlay)

It feels odd to pass both plane and overlay here. If we're unassigning (is that a verb? =) the overlay, isn't it enough to just pass either the plane or the overlay?

Passing the overlay is necessary when having 2 overlays for a plane, but the plane parameter is definitely unneeded here.

Quoted 13 lines
Quoted 13 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +12 -0
+{
+    struct omap_global_state *state = omap_get_global_state(s);
+    struct drm_plane **overlay_map = state->hwoverlay_to_plane;
+
+    if (!overlay)
+        return;
+
+    if (WARN_ON(!overlay_map[overlay->idx]))
+        return;
+    /*
+     * Check that the overlay we are releasing is actually
+     * assigned to the plane we are trying to release it from.
Quoted 8 lines
Quoted 6 lines

+     */
+    if (overlay_map[overlay->idx] == plane) {
+        DBG("%s: release from plane %s", overlay->name, plane->name); +
+        overlay_map[overlay->idx] = NULL;
+    }

So it's normal that overlay_map[overlay->idx] != plane? When does that happen?

It's impossible since the overlay is taken from the plane state, will simplify this, remove the plane parameter and remove the unnecessary checks.

Quoted 39 lines
Quoted 7 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +6 -0
+}
+
+void omap_overlay_disable(struct drm_atomic_state *s,
+              struct drm_plane *plane,
+              struct omap_hw_overlay *overlay)
+{

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 140

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +10 -0
+    struct omap_drm_private *priv = s->dev->dev_private;
+    struct drm_plane **overlay_map;
+    struct omap_global_state *old_state;
+
+    old_state = omap_get_existing_global_state(priv);
+    overlay_map = old_state->hwoverlay_to_plane;
+
+    if (!overlay)
+        return;
+

You can move the if above to the beginning of the func.

Quoted 6 lines

+    /*
+     * Check that the overlay we are trying to disable has not +     * been re-assigned to another plane already
+     */
+    if (!overlay_map[overlay->idx]) {
+        DBG("%s: on %s disabled", overlay->name, plane->name);

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 156

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_overlay.c +10 -0
+
+        /* disable the overlay */
+        dispc_ovl_enable(priv->dispc, overlay->overlay_id, false);
+
+        /*
+         * Since we are disabling this overlay in this
+         * atomic cycle we can reset the available crtcs
+         * it can be used on
+         */
+        overlay->possible_crtcs = (1 << priv->num_pipes) - 1;

This is changing data in the overlay struct itself. Shouldn't the mutable data be in the atomic state?

Quoted 3 lines

I'm also a bit confused on what the "possible_crtcs" is. But I think it's either a bitmask of all the crtcs when the overlay is free, or a mask of a single crtc when allocated.

I think a variable that's either 0 when the overlay is not assigned, or the mask of the crtc when in use, would be more clear. Also with some other name (active_crtc?).

I dropped entirely this possible_crtcs.

Quoted 9 lines

drivers/gpu/drm/omapdrm/omap_overlay.c static const char * const overlay_id_to_name[] = { · line 162

Quoted 7 lines

+    }

drivers/gpu/drm/omapdrm/omap_overlay.c +5 -0
+
+    /*
+     * Otherwise the overlay is still in use so leave it alone
+     */
+}

This function also has interesting behavior, possibly not disabling the hw overlay. I think these new exposed overlay functions could use a comment above each of them, explaining what they do.

I renamed this function to "omap_overlay_update_state()" which will disable an overlay if not more used. This name looks much more appropriate.

Quoted 73 lines
Quoted 60 lines

+
  static void omap_overlay_destroy(struct omap_hw_overlay *overlay) {
      kfree(overlay);

drivers/gpu/drm/omapdrm/omap_overlay.h +9 -0
index 892fecb67adb..d5033ee481c2 100644
@@ -28,4 +28,13 @@ struct omap_hw_overlay {
     int omap_hwoverlays_init(struct omap_drm_private *priv);
   void omap_hwoverlays_destroy(struct omap_drm_private *priv);
+int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane,
+            u32 caps, u32 fourcc, u32 crtc_mask,
+            struct omap_hw_overlay **overlay);
+void omap_overlay_release(struct drm_atomic_state *s,
+              struct drm_plane *plane,
+              struct omap_hw_overlay *overlay);
+void omap_overlay_disable(struct drm_atomic_state *s,
+              struct drm_plane *plane,
+              struct omap_hw_overlay *overlay);
   #endif /* __OMAPDRM_OVERLAY_H__ */
drivers/gpu/drm/omapdrm/omap_plane.c +8 -3
index bda794b4c915..4b400a8bfe9e 100644
@@ -8,6 +8,7 @@
   #include <drm/drm_atomic_helper.h>
   #include <drm/drm_gem_atomic_helper.h>
   #include <drm/drm_plane_helper.h>
+#include <drm/drm_fourcc.h>
     #include "omap_dmm_tiler.h"
   #include "omap_drv.h"
@@ -21,6 +22,8 @@
   struct omap_plane_state {
       /* Must be first. */
       struct drm_plane_state base;
+
+    struct omap_hw_overlay *overlay;
   };
     #define to_omap_plane(x) container_of(x, struct omap_plane, base)
@@ -29,8 +32,6 @@ struct omap_plane {
       struct drm_plane base;
       enum omap_plane_id id;
       const char *name;
-
-    struct omap_hw_overlay *overlay;
   };
     static int omap_plane_prepare_fb(struct drm_plane *plane,
@@ -58,10 +59,27 @@ static void omap_plane_atomic_update(struct drm_plane *plane,
       struct omap_plane *omap_plane = to_omap_plane(plane);
       struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
                                          plane);
-    enum omap_plane_id ovl_id = omap_plane->overlay->overlay_id;
+    struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
+                                       plane);
+    struct omap_plane_state *new_omap_state;
+    struct omap_plane_state *old_omap_state;
       struct omap_overlay_info info;
+    enum omap_plane_id ovl_id;

drivers/gpu/drm/omapdrm/omap_plane.c static void omap_plane_atomic_update(struct drm_plane *plane, · line 77

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_plane.c +8 -0
       int ret;
   +    new_omap_state = to_omap_plane_state(new_state);
+    old_omap_state = to_omap_plane_state(old_state);
+
+    /* Cleanup previously held overlay if needed */
+    omap_overlay_disable(old_state->state, plane, old_omap_state->overlay);
+
+    if (!new_omap_state->overlay) {
+        DBG("[PLANE:%d:%s] overlay_id: ??? (%p)", plane->base.id, plane->name,
+            new_omap_state->overlay);

I wonder what the ??? means here.

Quoted 1 line

Already in earlier patches I wondered if the DBG prints were good or not, but I thought I'll comment on those after I can run this and see what they actually print. But some of them felt like debug prints used during development, not something to leave in the production code (at least in the form they were).

I changed the print to something more interesting.

Quoted 33 lines
Quoted 33 lines
drivers/gpu/drm/omapdrm/omap_plane.c +4 -0
+        return;
+    }
+
+    ovl_id = new_omap_state->overlay->overlay_id;
       DBG("%s, crtc=%p fb=%p", omap_plane->name, new_state->crtc,
           new_state->fb);
   @@ -80,9 +98,9 @@ static void omap_plane_atomic_update(struct drm_plane *plane,

      /* update scanout: */ omap_framebuffer_update_scanout(new_state->fb, new_state, &info); -    DBG("%dx%d -> %dx%d (%d)", info.width, info.height,
-            info.out_width, info.out_height,
-            info.screen_width);
+    DBG("%s: %dx%d -> %dx%d (%d)",
+            new_omap_state->overlay->name, info.width, info.height,
+            info.out_width, info.out_height, info.screen_width); DBG("%d,%d %pad %pad", info.pos_x, info.pos_y,
              &info.paddr, &info.p_uv_addr);
  @@ -105,55 +123,66 @@ static void omap_plane_atomic_disable(struct drm_plane *plane, {
      struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state, plane);
-    struct omap_drm_private *priv = plane->dev->dev_private;
-    struct omap_plane *omap_plane = to_omap_plane(plane);
-    enum omap_plane_id ovl_id = omap_plane->overlay->overlay_id;
+    struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state, +                                       plane);
+    struct omap_plane_state *new_omap_state;
+    struct omap_plane_state *old_omap_state;

drivers/gpu/drm/omapdrm/omap_plane.c +4 -0
+
+    new_omap_state = to_omap_plane_state(new_state);
+    old_omap_state = to_omap_plane_state(old_state);
+
Quoted 8 lines
Quoted 6 lines

+    if (!old_omap_state->overlay)
+        return;
        new_state->rotation = DRM_MODE_ROTATE_0;
-    new_state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY ? 0 : omap_plane->id; +    new_state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY
+            ? 0 : old_omap_state->overlay->overlay_id;

I'm not sure if I'm right here, but... doesn't the above mean that the plane's zpos can change, depending on which hw overlay it happened to use?

I'll need to investigate more on this.

Quoted 84 lines
Quoted 71 lines

  -    dispc_ovl_enable(priv->dispc, ovl_id, false);
+    omap_overlay_disable(old_state->state, plane, old_omap_state->overlay); +    new_omap_state->overlay = NULL;
  }
  +#define FRAC_16_16(mult, div)    (((mult) << 16) / (div))
  static int omap_plane_atomic_check(struct drm_plane *plane,
                     struct drm_atomic_state *state)
  {
      struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state, plane);
+    struct drm_plane_state *old_plane_state = drm_atomic_get_old_plane_state(state, +                                         plane);
+    struct drm_crtc *crtc;
      struct omap_drm_private *priv = plane->dev->dev_private;
+    struct omap_plane_state *omap_state = to_omap_plane_state(new_plane_state); +    struct omap_global_state *omap_overlay_global_state;
+    u32 crtc_mask;
+    u32 fourcc;
+    u32 caps = 0;
+    bool new_hw_overlay = false;
+    int min_scale, max_scale;
+    int ret;
      struct drm_crtc_state *crtc_state;
      u16 width, height;
      u32 width_fp, height_fp;
  -    if (!new_plane_state->fb)
-        return 0;
+    omap_overlay_global_state = omap_get_global_state(state);
+    if (IS_ERR(omap_overlay_global_state))
+        return PTR_ERR(omap_overlay_global_state);
+    DBG("%s: omap_overlay_global_state: %p", plane->name,
+        omap_overlay_global_state); dispc_ovl_get_max_size(priv->dispc, &width, &height);
      width_fp = width << 16;
      height_fp = height << 16;
  -    /* crtc should only be NULL when disabling (i.e., !new_plane_state->fb) */ -    if (WARN_ON(!new_plane_state->crtc))
+    crtc = new_plane_state->crtc ? new_plane_state->crtc : plane->state->crtc; +    if (!crtc)
          return 0;
  -    crtc_state = drm_atomic_get_existing_crtc_state(state,
-                            new_plane_state->crtc);
+    crtc_state = drm_atomic_get_existing_crtc_state(state, crtc);
      /* we should have a crtc state if the plane is attached to a crtc */ if (WARN_ON(!crtc_state))
          return 0;
  -    if (!crtc_state->enable)
-        return 0;

drivers/gpu/drm/omapdrm/omap_plane.c +0 -10
-
-    if (new_plane_state->crtc_x < 0 || new_plane_state->crtc_y < 0)
-        return -EINVAL;
-
-    if (new_plane_state->crtc_x + new_plane_state->crtc_w > crtc_state->adjusted_mode.hdisplay)
-        return -EINVAL;
-
-    if (new_plane_state->crtc_y + new_plane_state->crtc_h > crtc_state->adjusted_mode.vdisplay)
-        return -EINVAL;
-

      /* Make sure dimensions are within bounds. */
      if (new_plane_state->src_h > height_fp || new_plane_state->crtc_h > height) return -EINVAL;

drivers/gpu/drm/omapdrm/omap_plane.c +0 -0
@@ -161,9 +190,81 @@ static int omap_plane_atomic_check(struct drm_plane *plane,
       if (new_plane_state->src_w > width_fp || new_plane_state->crtc_w > width)
           return -EINVAL;

  -    if (new_plane_state->rotation != DRM_MODE_ROTATE_0 && -        !omap_framebuffer_supports_rotation(new_plane_state->fb)) -        return -EINVAL;

drivers/gpu/drm/omapdrm/omap_plane.c +3 -0
+
+    /*
+     * Note: these are just sanity checks to filter out totally bad scaling

drivers/gpu/drm/omapdrm/omap_plane.c static int omap_plane_atomic_check(struct drm_plane *plane, · line 205

Quoted 10 lines
drivers/gpu/drm/omapdrm/omap_plane.c +10 -0
+     * factors. The real limits must be calculated case by case, and
+     * unfortunately we currently do those checks only at the commit
+     * phase in dispc.
+     */
+    min_scale = FRAC_16_16(1, 8);
+    max_scale = FRAC_16_16(8, 1);
+
+    ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state,
+                          min_scale, max_scale,
+                          true, true);

This piece here feels a bit out of context (wrt. to this patch). Why do we need it here, when adding support to hw overlays?

Quoted 1 line

And I think it's fine to use the above helper, but maybe it can be in a separate patch earlier?

I'll move it out of this patch.

Quoted 8 lines
Quoted 7 lines

+    if (ret)
+        return ret;
+
+    DBG("%s: check (%d -> %d)", plane->name,
+        old_plane_state->visible, new_plane_state->visible);

Quoted 5 lines

Here's an example of the debug prints I mentioned earlier. I think this prints:

"GFX: check (1 -> 0)"

I'm fine with terse debug prints, but... maybe something like "visible 1 -> 0" would be much better? =)

Fixed

Quoted 59 lines
Quoted 59 lines

+    if (new_plane_state->visible) {
+        if (new_plane_state->rotation != DRM_MODE_ROTATE_0 && +            !omap_framebuffer_supports_rotation(new_plane_state->fb)) +            return -EINVAL;

drivers/gpu/drm/omapdrm/omap_plane.c +52 -0
+
+        if ((new_plane_state->src_w >> 16) != new_plane_state->crtc_w ||
+            (new_plane_state->src_h >> 16) != new_plane_state->crtc_h)
+            caps |= OMAP_DSS_OVL_CAP_SCALE;
+
+        fourcc = new_plane_state->fb->format->format;
+        crtc_mask = drm_crtc_mask(new_plane_state->crtc);
+
+        /*
+         * (re)allocate hw overlay if we don't have one or
+         * there is a caps mismatch
+         */
+        if (!omap_state->overlay ||
+            (caps & ~omap_state->overlay->caps)) {
+            new_hw_overlay = true;
+        } else {
+            /* check if allowed on crtc */
+            if (!(omap_state->overlay->possible_crtcs & crtc_mask))
+                new_hw_overlay = true;
+
+            /* check supported format */
+            if (!dispc_ovl_color_mode_supported(priv->dispc,
+                        omap_state->overlay->overlay_id,
+                        fourcc))
+                new_hw_overlay = true;
+        }
+
+        if (new_hw_overlay) {
+            struct omap_hw_overlay *old_ovl = omap_state->overlay;
+            struct omap_hw_overlay *new_ovl = NULL;
+
+            omap_overlay_release(state, plane, old_ovl);
+
+            ret = omap_overlay_assign(state, plane, caps,
+                          fourcc, crtc_mask, &new_ovl);
+            if (ret) {
+                DBG("%s: failed to assign hw_overlay(s)!",
+                    plane->name);
+                omap_state->overlay = NULL;
+                return ret;
+            }
+
+            omap_state->overlay = new_ovl;
+        }
+    } else {
+        omap_overlay_release(state, plane, omap_state->overlay);
+        omap_state->overlay = NULL;
+    }
+
+    if (omap_state->overlay)
+        DBG("plane: %s overlay_id: %d", plane->name,
+            omap_state->overlay->overlay_id);

        return 0;
  }

Quoted 8 lines
Quoted 6 lines
drivers/gpu/drm/omapdrm/omap_plane.c +0 -0
@@ -230,7 +331,7 @@ static void omap_plane_reset(struct drm_plane *plane)
        * plane.
        */

      plane->state->zpos = plane->type == DRM_PLANE_TYPE_PRIMARY -               ? 0 : omap_plane->overlay->overlay_id; +               ? 0 : omap_plane->id;

Hmm... On plane reset we now set the zpos to plane->id, but on disable we reset zpos to overlay->id. And before this patch we set the vice versa. I don't follow.

I'll aswell need to investigate more on this.

Quoted 2 lines

 Tomi

Neil

#19 lore raw

PATCH v5 7/8 drm/omap: add plane_atomic_print_state support

In reply to Neil Armstrong

From: Benoit Parrot <[email protected]>

Now that we added specific item to our subclassed drm_plane_state we can add omap_plane_atomic_print_state() helper to dump out our own driver specific plane state.

---
 drivers/gpu/drm/omapdrm/omap_plane.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
drivers/gpu/drm/omapdrm/omap_plane.c +18 -0
index 4b400a8bfe9e..badbafeb3402 100644
@@ -355,6 +355,23 @@ omap_plane_atomic_duplicate_state(struct drm_plane *plane)
 	return &copy->base;
 }
 
+static void omap_plane_atomic_print_state(struct drm_printer *p,
+					  const struct drm_plane_state *state)
+{
+	struct omap_plane_state *omap_state = to_omap_plane_state(state);
+
+	drm_printf(p, "\toverlay=%s\n", omap_state->overlay ?
+					omap_state->overlay->name : "(null)");
+	if (omap_state->overlay) {
+		drm_printf(p, "\t\tidx=%d\n", omap_state->overlay->idx);
+		drm_printf(p, "\t\toverlay_id=%d\n",
+			   omap_state->overlay->overlay_id);
+		drm_printf(p, "\t\tcaps=0x%x\n", omap_state->overlay->caps);
+		drm_printf(p, "\t\tpossible_crtcs=0x%x\n",
+			   omap_state->overlay->possible_crtcs);
+	}
+}
+
 static int omap_plane_atomic_set_property(struct drm_plane *plane,
 					  struct drm_plane_state *state,
 					  struct drm_property *property,
@@ -394,6 +411,7 @@ static const struct drm_plane_funcs omap_plane_funcs = {
 	.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 	.atomic_set_property = omap_plane_atomic_set_property,
 	.atomic_get_property = omap_plane_atomic_get_property,
+	.atomic_print_state = omap_plane_atomic_print_state,
 };
 
 static bool omap_plane_supports_yuv(struct drm_plane *plane)
Signature · 1 line
2.25.1
#20 lore raw

PATCH v5 8/8 drm/omap: Add a 'right overlay' to plane state

In reply to Neil Armstrong

From: Benoit Parrot <[email protected]>

If the drm_plane has a source width that's greater than the max width supported by a single hw overlay, then we assign a 'r_overlay' to it in omap_plane_atomic_check().

Both overlays should have the capabilities required to handle the source framebuffer. The only parameters that vary between the left and right hwoverlays are the src_w, crtc_w, src_x and crtc_x as we just even chop the fb into left and right halves.

We also take care of not creating odd width size when dealing with YUV formats.

Since both halves need to be 'appear' side by side the zpos is recalculated when dealing with dual overlay cases so that the other planes zpos is consistent.

Depending on user space usage it is possible that on occasion the number of requested planes exceeds the numbers of overlays required to display them. In that case a failure would be returned for the plane that cannot be handled at that time. It is up to user space to make sure the H/W resource are not over-subscribed.

---
 drivers/gpu/drm/omapdrm/omap_drv.c     |  91 +++++++++++++++++-
 drivers/gpu/drm/omapdrm/omap_fb.c      |  33 ++++++-
 drivers/gpu/drm/omapdrm/omap_fb.h      |   4 +-
 drivers/gpu/drm/omapdrm/omap_overlay.c |  31 +++++-
 drivers/gpu/drm/omapdrm/omap_overlay.h |   3 +-
 drivers/gpu/drm/omapdrm/omap_plane.c   | 127 +++++++++++++++++++++++--
 drivers/gpu/drm/omapdrm/omap_plane.h   |   1 +
 7 files changed, 276 insertions(+), 14 deletions(-)
drivers/gpu/drm/omapdrm/omap_drv.c +90 -1
index c7912374d393..f088b6313950 100644
@@ -117,6 +117,95 @@ static void omap_atomic_commit_tail(struct drm_atomic_state *old_state)
 	dispc_runtime_put(priv->dispc);
 }
 
+static int drm_atomic_state_normalized_zpos_cmp(const void *a, const void *b)
+{
+	const struct drm_plane_state *sa = *(struct drm_plane_state **)a;
+	const struct drm_plane_state *sb = *(struct drm_plane_state **)b;
+
+	if (sa->normalized_zpos != sb->normalized_zpos)
+		return sa->normalized_zpos - sb->normalized_zpos;
+	else
+		return sa->plane->base.id - sb->plane->base.id;
+}
+
+static int omap_atomic_update_normalize_zpos(struct drm_device *dev,
+					     struct drm_atomic_state *state)
+{
+	struct drm_crtc *crtc;
+	struct drm_crtc_state *old_state, *new_state;
+	struct drm_plane *plane;
+	int c, i, n, inc;
+	int total_planes = dev->mode_config.num_total_plane;
+	struct drm_plane_state **states;
+	int ret = 0;
+
+	states = kmalloc_array(total_planes, sizeof(*states), GFP_KERNEL);
+	if (!states)
+		return -ENOMEM;
+
+	for_each_oldnew_crtc_in_state(state, crtc, old_state, new_state, c) {
+		if (old_state->plane_mask == new_state->plane_mask &&
+		    !new_state->zpos_changed)
+			continue;
+
+		/* Reset plane increment and index value for every crtc */
+		n = 0;
+
+		/*
+		 * Normalization process might create new states for planes
+		 * which normalized_zpos has to be recalculated.
+		 */
+		drm_for_each_plane_mask(plane, dev, new_state->plane_mask) {
+			struct drm_plane_state *plane_state =
+				drm_atomic_get_plane_state(new_state->state,
+							   plane);
+			if (IS_ERR(plane_state)) {
+				ret = PTR_ERR(plane_state);
+				goto done;
+			}
+			states[n++] = plane_state;
+		}
+
+		sort(states, n, sizeof(*states),
+		     drm_atomic_state_normalized_zpos_cmp, NULL);
+
+		for (i = 0, inc = 0; i < n; i++) {
+			plane = states[i]->plane;
+
+			states[i]->normalized_zpos = i + inc;
+			DRM_DEBUG_ATOMIC("[PLANE:%d:%s] updated normalized zpos value %d\n",
+					 plane->base.id, plane->name,
+					 states[i]->normalized_zpos);
+
+			if (is_omap_plane_dual_overlay(states[i]))
+				inc++;
+		}
+		new_state->zpos_changed = true;
+	}
+
+done:
+	kfree(states);
+	return ret;
+}
+
+static int omap_atomic_check(struct drm_device *dev,
+			     struct drm_atomic_state *state)
+{
+	int ret;
+
+	ret = drm_atomic_helper_check(dev, state);
+	if (ret)
+		return ret;
+
+	if (dev->mode_config.normalize_zpos) {
+		ret = omap_atomic_update_normalize_zpos(dev, state);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
+}
+
 static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs = {
 	.atomic_commit_tail = omap_atomic_commit_tail,
 };
@@ -124,7 +213,7 @@ static const struct drm_mode_config_helper_funcs omap_mode_config_helper_funcs =
 static const struct drm_mode_config_funcs omap_mode_config_funcs = {
 	.fb_create = omap_framebuffer_create,
 	.output_poll_changed = drm_fb_helper_output_poll_changed,
-	.atomic_check = drm_atomic_helper_check,
+	.atomic_check = omap_atomic_check,
 	.atomic_commit = drm_atomic_helper_commit,
 };
 
drivers/gpu/drm/omapdrm/omap_fb.c +32 -1
index 190afc564914..895e66b08a81 100644
@@ -131,7 +131,9 @@ static u32 drm_rotation_to_tiler(unsigned int drm_rot)
 /* update ovl info for scanout, handles cases of multi-planar fb's, etc.
  */
 void omap_framebuffer_update_scanout(struct drm_framebuffer *fb,
-		struct drm_plane_state *state, struct omap_overlay_info *info)
+		struct drm_plane_state *state,
+		struct omap_overlay_info *info,
+		struct omap_overlay_info *r_info)
 {
 	struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb);
 	const struct drm_format_info *format = omap_fb->format;
@@ -218,6 +220,35 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb,
 	} else {
 		info->p_uv_addr = 0;
 	}
+
+	if (r_info) {
+		info->width /= 2;
+		info->out_width /= 2;
+
+		*r_info = *info;
+
+		if (fb->format->is_yuv) {
+			if (info->width & 1) {
+				info->width++;
+				r_info->width--;
+			}
+
+			if (info->out_width & 1) {
+				info->out_width++;
+				r_info->out_width--;
+			}
+		}
+
+		r_info->pos_x = info->pos_x + info->out_width;
+
+		r_info->paddr =	get_linear_addr(fb, format, 0,
+						x + info->width, y);
+		if (fb->format->format == DRM_FORMAT_NV12) {
+			r_info->p_uv_addr =
+				get_linear_addr(fb, format, 1,
+						x + info->width, y);
+		}
+	}
 }
 
 /* pin, prepare for scanout: */
drivers/gpu/drm/omapdrm/omap_fb.h +3 -1
index c0e19aed8220..b75f0b5ef1d8 100644
@@ -26,7 +26,9 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev,
 int omap_framebuffer_pin(struct drm_framebuffer *fb);
 void omap_framebuffer_unpin(struct drm_framebuffer *fb);
 void omap_framebuffer_update_scanout(struct drm_framebuffer *fb,
-		struct drm_plane_state *state, struct omap_overlay_info *info);
+		struct drm_plane_state *state,
+		struct omap_overlay_info *info,
+		struct omap_overlay_info *r_info);
 bool omap_framebuffer_supports_rotation(struct drm_framebuffer *fb);
 void omap_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m);
 
drivers/gpu/drm/omapdrm/omap_overlay.c +29 -2
index f1a23c2203aa..a4f4be008bd5 100644
@@ -63,12 +63,14 @@ omap_plane_find_free_overlay(struct drm_device *dev,
 
 int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane,
 			u32 caps, u32 fourcc, u32 crtc_mask,
-			struct omap_hw_overlay **overlay)
+			struct omap_hw_overlay **overlay,
+			struct omap_hw_overlay **r_overlay)
 {
 	struct omap_drm_private *priv = s->dev->dev_private;
 	struct omap_global_state *new_global_state, *old_global_state;
 	struct drm_plane **overlay_map;
-	struct omap_hw_overlay *ovl;
+	struct omap_hw_overlay *ovl, *r_ovl;
+	u32 save_possible_crtcs;
 
 	new_global_state = omap_get_global_state(s);
 	if (IS_ERR(new_global_state))
@@ -90,12 +92,37 @@ int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane,
 		if (!ovl)
 			return -ENOMEM;
 
+		/* in case we need to backtrack */
+		save_possible_crtcs = ovl->possible_crtcs;
+
 		ovl->possible_crtcs = crtc_mask;
 		overlay_map[ovl->idx] = plane;
 		*overlay = ovl;
 
+		if (r_overlay) {
+			r_ovl = omap_plane_find_free_overlay(s->dev,
+							     overlay_map,
+							     caps, fourcc,
+							     crtc_mask);
+			if (!r_ovl) {
+				ovl->possible_crtcs = save_possible_crtcs;
+				overlay_map[ovl->idx] = NULL;
+				*overlay = NULL;
+				return -ENOMEM;
+			}
+
+			r_ovl->possible_crtcs = crtc_mask;
+			overlay_map[r_ovl->idx] = plane;
+			*r_overlay = r_ovl;
+		}
+
 		DBG("%s: assign to plane %s caps %x on crtc %x",
 		    (*overlay)->name, plane->name, caps, crtc_mask);
+
+		if (r_overlay) {
+			DBG("%s: assign to right of plane %s caps %x on crtc %x",
+			    (*r_overlay)->name, plane->name, caps, crtc_mask);
+		}
 	}
 
 	return 0;
drivers/gpu/drm/omapdrm/omap_overlay.h +2 -1
index d5033ee481c2..a800468511f1 100644
@@ -30,7 +30,8 @@ int omap_hwoverlays_init(struct omap_drm_private *priv);
 void omap_hwoverlays_destroy(struct omap_drm_private *priv);
 int omap_overlay_assign(struct drm_atomic_state *s, struct drm_plane *plane,
 			u32 caps, u32 fourcc, u32 crtc_mask,
-			struct omap_hw_overlay **overlay);
+			struct omap_hw_overlay **overlay,
+			struct omap_hw_overlay **r_overlay);
 void omap_overlay_release(struct drm_atomic_state *s,
 			  struct drm_plane *plane,
 			  struct omap_hw_overlay *overlay);
drivers/gpu/drm/omapdrm/omap_plane.c +119 -8

231 lines not on this page · raw message

drivers/gpu/drm/omapdrm/omap_plane.h +1 -0
index 0c28fe8ffa20..a9a33e12722a 100644
@@ -22,5 +22,6 @@ struct drm_plane *omap_plane_init(struct drm_device *dev,
 		u32 possible_crtcs);
 void omap_plane_install_properties(struct drm_plane *plane,
 		struct drm_mode_object *obj);
+bool is_omap_plane_dual_overlay(struct drm_plane_state *state);
 
 #endif /* __OMAPDRM_PLANE_H__ */
Signature · 1 line
2.25.1
#21 lore raw
In reply to Neil Armstrong

Hi,

Quoted 10 lines · Neil Armstrong

This patchset is the follow-up the v4 patchset from Benoit Parrot at [1].

This patch series adds virtual-plane support to omapdrm driver to allow the use of display wider than 2048 pixels.

In order to do so we introduce the concept of hw_overlay which can then be dynamically allocated to a plane. When the requested output width exceed what be supported by one overlay a second is then allocated if possible to handle display wider then 2048.

Quoted 5 lines

This series replaces an earlier series which was DT based and using statically allocated resources.

This implementation is inspired from the work done in msm/disp/mdp5 driver.

Gentle ping, who is supposed reviewing those patches ?

Thanks,
Neil

Quoted 36 lines

Changes since v4 at [1]:
- rebased on v5.15-rc2
- adapted to drm_atomic_get_new/old_plane_state()
- tested on Beagle-x15
- checked for non-regression on Beagle-x15
- removed unused "state" variable in omap_global_state

[1] https://lore.kernel.org/all/[email protected]/

Benoit Parrot (8):
drm/omap: Add ability to check if requested plane modes can be
supported
drm/omap: Add ovl checking funcs to dispc_ops drm/omap: introduce omap_hw_overlay
drm/omap: omap_plane: subclass drm_plane_state drm/omap: Add global state as a private atomic object drm/omap: dynamically assign hw overlays to planes drm/omap: add plane_atomic_print_state support drm/omap: Add a 'right overlay' to plane state

 drivers/gpu/drm/omapdrm/Makefile       |   1 +
 drivers/gpu/drm/omapdrm/dss/dispc.c    |  31 +-
 drivers/gpu/drm/omapdrm/dss/dss.h      |   5 +
 drivers/gpu/drm/omapdrm/omap_drv.c     | 189 ++++++++++++-
 drivers/gpu/drm/omapdrm/omap_drv.h     |  28 ++
 drivers/gpu/drm/omapdrm/omap_fb.c      |  33 ++-
 drivers/gpu/drm/omapdrm/omap_fb.h      |   4 +-
 drivers/gpu/drm/omapdrm/omap_overlay.c | 254 +++++++++++++++++
 drivers/gpu/drm/omapdrm/omap_overlay.h |  41 +++
 drivers/gpu/drm/omapdrm/omap_plane.c   | 375 +++++++++++++++++++++----
 drivers/gpu/drm/omapdrm/omap_plane.h   |   1 +
 11 files changed, 903 insertions(+), 59 deletions(-)
 create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.c
 create mode 100644 drivers/gpu/drm/omapdrm/omap_overlay.h
maintainer
#22 lore raw

Hi Neil,

Quoted 13 lines · Neil Armstrong

Hi,

Quoted 10 lines · Neil Armstrong

This patchset is the follow-up the v4 patchset from Benoit Parrot at [1].

This patch series adds virtual-plane support to omapdrm driver to allow the use of display wider than 2048 pixels.

In order to do so we introduce the concept of hw_overlay which can then be dynamically allocated to a plane. When the requested output width exceed what be supported by one overlay a second is then allocated if possible to handle display wider then 2048.

Quoted 7 lines
Quoted 5 lines

This series replaces an earlier series which was DT based and using statically allocated resources.

This implementation is inspired from the work done in msm/disp/mdp5 driver.

Gentle ping, who is supposed reviewing those patches ?

I think that would be me. I'll try to find time in the nearby future to do the review.

Tomi

maintainer
#23 lore raw
In reply to Neil Armstrong
Quoted 10 lines · Neil Armstrong

This patchset is the follow-up the v4 patchset from Benoit Parrot at [1].

This patch series adds virtual-plane support to omapdrm driver to allow the use of display wider than 2048 pixels.

In order to do so we introduce the concept of hw_overlay which can then be dynamically allocated to a plane. When the requested output width exceed what be supported by one overlay a second is then allocated if possible to handle display wider then 2048.

Quoted 8 lines

This series replaces an earlier series which was DT based and using statically allocated resources.

This implementation is inspired from the work done in msm/disp/mdp5 driver.

Changes since v4 at [1]:
- rebased on v5.15-rc2

What is this based on? Doesn't apply to v5.15-rc2, and "error: sha1 information is lacking or useless".

Tomi

#24 lore raw
Quoted 14 lines · Tomi Valkeinen
Quoted 13 lines · Neil Armstrong

This patchset is the follow-up the v4 patchset from Benoit Parrot at [1].

This patch series adds virtual-plane support to omapdrm driver to allow the use of display wider than 2048 pixels.

In order to do so we introduce the concept of hw_overlay which can then be dynamically allocated to a plane. When the requested output width exceed what be supported by one overlay a second is then allocated if possible to handle display wider then 2048.

This series replaces an earlier series which was DT based and using statically allocated resources.

Quoted 7 lines
Quoted 5 lines

This implementation is inspired from the work done in msm/disp/mdp5 driver.

Changes since v4 at [1]:
- rebased on v5.15-rc2

What is this based on? Doesn't apply to v5.15-rc2, and "error: sha1 information is lacking or useless".

Indeed the sha1 info is useless, it's based on v5.15-rc2 on top of "HACK: drm/omap: increase DSS5 max tv pclk to 192MHz" in order to validate on 2k monitors.

My bad, I thought it would apply based on this patch, I'll rebase on v5.15-rc2 for v6.

Thanks for the review,
Neil

Quoted 2 lines

 Tomi

maintainer
#25 lore raw
Quoted 18 lines · Neil Armstrong
Quoted 17 lines · Tomi Valkeinen
Quoted 16 lines · Neil Armstrong

This patchset is the follow-up the v4 patchset from Benoit Parrot at [1].

This patch series adds virtual-plane support to omapdrm driver to allow the use of display wider than 2048 pixels.

In order to do so we introduce the concept of hw_overlay which can then be dynamically allocated to a plane. When the requested output width exceed what be supported by one overlay a second is then allocated if possible to handle display wider then 2048.

This series replaces an earlier series which was DT based and using statically allocated resources.

This implementation is inspired from the work done in msm/disp/mdp5 driver.

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Changes since v4 at [1]:
- rebased on v5.15-rc2

What is this based on? Doesn't apply to v5.15-rc2, and "error: sha1 information is lacking or useless".

Indeed the sha1 info is useless, it's based on v5.15-rc2 on top of "HACK: drm/omap: increase DSS5 max tv pclk to 192MHz" in order to validate on 2k monitors.

I'm personally fine with removing the HACK from that, and applying it too. I used the patch for a long time without any issues. However, I never found anyone to confirm that 192MHz is fine (or that it's not fine). Too old HW for finding HW engineers to look at it =).

Tomi

#26 lore raw

Hi,

Quoted 22 lines · Tomi Valkeinen
Quoted 21 lines · Neil Armstrong
Quoted 20 lines · Tomi Valkeinen
Quoted 18 lines · Neil Armstrong

This patchset is the follow-up the v4 patchset from Benoit Parrot at [1].

This patch series adds virtual-plane support to omapdrm driver to allow the use of display wider than 2048 pixels.

In order to do so we introduce the concept of hw_overlay which can then be dynamically allocated to a plane. When the requested output width exceed what be supported by one overlay a second is then allocated if possible to handle display wider then 2048.

This series replaces an earlier series which was DT based and using statically allocated resources.

This implementation is inspired from the work done in msm/disp/mdp5 driver.

Changes since v4 at [1]:
- rebased on v5.15-rc2

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

What is this based on? Doesn't apply to v5.15-rc2, and "error: sha1 information is lacking or useless".

Indeed the sha1 info is useless, it's based on v5.15-rc2 on top of "HACK: drm/omap: increase DSS5 max tv pclk to 192MHz" in order to validate on 2k monitors.

I'm personally fine with removing the HACK from that, and applying it too. I used the patch for a long time without any issues. However, I never found anyone to confirm that 192MHz is fine (or that it's not fine). Too old HW for finding HW engineers to look at it =).

Indeed it seems to be applied the TI trees for a long time now, will post it.

Thanks,
Neil

Quoted 2 lines

 Tomi