Skip to contentSkip to conversation

Aspect ratio support in DRM layer

PATCH In review Shashank Sharma 3 participants 11 messages Nov 17, 2017 – Nov 24, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Aspect ratio support in DRM layer

This patch series is a re-attempt to enable aspect ratio support in DRM layer. Currently the aspect ratio information gets lost in translation during a user->kernel mode or vice versa.

The old patch series (https://pw-emeril.freedesktop.org/series/10850/) had 4 patches, out of which 2 patches were reverted due to lack of drm client protection while loading the aspect information.

This patch series, adds a DRM client option for aspect ratio, and loads aspect ratio flags, only when the client sets this cap. Also, to test this patch series there is a userspace implementation by Ankit Nautiyal in Wayland/weston layer:
https://patchwork.freedesktop.org/patch/188125/

This, helps us in passing HDMI compliance test cases like 7-27, where the test equipment applies a CEA mode, and expects the exact VIC in the AVI infoframes.

Ankit Nautiyal (1):
drm: Handle aspect ratio in modeset paths

Shashank Sharma (2):
drm: Add aspect ratio parsing in DRM layer
drm: Add and handle new aspect ratios in DRM layer

aknautiy (2):
drm: Add DRM client cap for aspect-ratio
drm: Expose modes with aspect ratio, only if requested

 drivers/gpu/drm/drm_atomic.c    | 40 +++++++++++++++++++++++++++++++-------
 drivers/gpu/drm/drm_connector.c |  7 +++++++
 drivers/gpu/drm/drm_crtc.c      | 19 ++++++++++++++++++
 drivers/gpu/drm/drm_ioctl.c     |  5 +++++
 drivers/gpu/drm/drm_modes.c     | 43 +++++++++++++++++++++++++++++++++++++++++
 include/drm/drm_atomic.h        |  2 ++
 include/drm/drm_file.h          |  7 +++++++
 include/uapi/drm/drm.h          |  7 +++++++
 include/uapi/drm/drm_mode.h     |  6 ++++++
 9 files changed, 129 insertions(+), 7 deletions(-)
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

PATCH 1/5 drm: Add DRM client cap for aspect-ratio

From: aknautiy <[email protected]>

A new drm client cap is required to enable user-space to advertise if it supports modes with aspect-ratio. Based on this cap value, the kernel will take a call on exposing the aspect ratio information in modes or not.

This patch adds the client cap for aspect-ratio.

Cc Ville Syrjala <[email protected]>
Cc Shashank Sharma <[email protected]>
---
 drivers/gpu/drm/drm_ioctl.c | 5 +++++
 include/drm/drm_file.h      | 7 +++++++
 include/uapi/drm/drm.h      | 7 +++++++
 3 files changed, 19 insertions(+)
drivers/gpu/drm/drm_ioctl.c +5 -0
index 4aafe48..e092550 100644
@@ -325,6 +325,11 @@ drm_setclientcap(struct drm_device *dev, void *data, struct drm_file *file_priv)
 		file_priv->atomic = req->value;
 		file_priv->universal_planes = req->value;
 		break;
+	case DRM_CLIENT_CAP_ASPECT_RATIO:
+		if (req->value > 1)
+			return -EINVAL;
+		file_priv->aspect_ratio_allowed = req->value;
+		break;
 	default:
 		return -EINVAL;
 	}
include/drm/drm_file.h +7 -0
index 0e0c868..6e0e435 100644
@@ -182,6 +182,13 @@ struct drm_file {
 	unsigned atomic:1;
 
 	/**
+	 * @aspect_ratio_allowed:
+	 *
+	 * True if client has asked to expose the aspect-ratio flags with mode.
+	 */
+	unsigned aspect_ratio_allowed:1;
+
+	/**
 	 * @is_master:
 	 *
 	 * This client is the creator of @master. Protected by struct
include/uapi/drm/drm.h +7 -0
index 6fdff59..fe5f531 100644
@@ -680,6 +680,13 @@ struct drm_get_cap {
  */
 #define DRM_CLIENT_CAP_ATOMIC	3
 
+/**
+ * DRM_CLIENT_CAP_ASPECT_RATIO
+ *
+ * If set to 1, the DRM core will expose aspect ratio flags to userspace.
+ */
+#define DRM_CLIENT_CAP_ASPECT_RATIO    4
+
 /** DRM_IOCTL_SET_CLIENT_CAP ioctl argument type */
 struct drm_set_client_cap {
 	__u64 capability;
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#2 lore raw

PATCH 2/5 drm: Handle aspect ratio in modeset paths

In reply to Shashank Sharma

From: Ankit Nautiyal <[email protected]>

If the user mode does not support aspect-ratio, and requests for a modeset with aspect ratio flags, then the flag bits reprsenting aspect ratio must be ignored.

Similarly, if user space doesn't set the aspect ratio client cap, while preparing a usermode, the aspect-ratio info must not be given into it.

This patch:
1. adds a new bit field aspect_ratio_allowed in drm_atomic_state, which is set only if the aspect-ratio is supported by the user.
2. discards the aspect-ratio info from the user mode while preparing kernel mode structure, during modeset, if the user does not support aspect ratio.
3. avoids setting the aspect-ratio info in user-mode, while converting user-mode from the kernel-mode.

Cc Ville Syrjala <[email protected]>
Cc Shashank Sharma <[email protected]>
Cc Jose Abreu <[email protected]>
---
 drivers/gpu/drm/drm_atomic.c | 40 +++++++++++++++++++++++++++++++++-------
 drivers/gpu/drm/drm_crtc.c   | 19 +++++++++++++++++++
 include/drm/drm_atomic.h     |  2 ++
 3 files changed, 54 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_atomic.c +33 -7
index 37445d5..b9743af 100644
@@ -338,18 +338,30 @@ int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
 	state->mode_blob = NULL;
 
 	if (mode) {
-		drm_mode_convert_to_umode(&umode, mode);
+		/*
+		 * If the user has not asked for aspect ratio support,
+		 * take a copy of the 'mode' and set the aspect ratio as
+		 * None. This copy is used to prepare the user-mode with no
+		 * aspect-ratio info.
+		 */
+		struct drm_display_mode ar_mode;
+		struct drm_atomic_state *atomic_state = state->state;
+
+		drm_mode_copy(&ar_mode, mode);
+		if (atomic_state && !atomic_state->allow_aspect_ratio)
+			ar_mode.picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
+		drm_mode_convert_to_umode(&umode, &ar_mode);
 		state->mode_blob =
 			drm_property_create_blob(state->crtc->dev,
-		                                 sizeof(umode),
-		                                 &umode);
+						 sizeof(umode),
+						 &umode);
 		if (IS_ERR(state->mode_blob))
 			return PTR_ERR(state->mode_blob);
 
-		drm_mode_copy(&state->mode, mode);
+		drm_mode_copy(&state->mode, &ar_mode);
 		state->enable = true;
 		DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
-				 mode->name, state);
+				 ar_mode.name, state);
 	} else {
 		memset(&state->mode, 0, sizeof(state->mode));
 		state->enable = false;
@@ -386,10 +398,23 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
 	memset(&state->mode, 0, sizeof(state->mode));
 
 	if (blob) {
+		struct drm_mode_modeinfo *ar_umode;
+		struct drm_atomic_state *atomic_state;
+
+		/*
+		 * If the user-space does not ask for aspect-ratio
+		 * the aspect ratio bits in the drmModeModeinfo from user,
+		 * does not mean anything. Therefore these bits must be
+		 * discarded.
+		 */
+		ar_umode = (struct drm_mode_modeinfo *) blob->data;
+		atomic_state = state->state;
+		if (atomic_state && !atomic_state->allow_aspect_ratio)
+			ar_umode->flags &= (~DRM_MODE_FLAG_PIC_AR_MASK);
 		if (blob->length != sizeof(struct drm_mode_modeinfo) ||
 		    drm_mode_convert_umode(&state->mode,
-		                           (const struct drm_mode_modeinfo *)
-		                            blob->data))
+					   (const struct drm_mode_modeinfo *)
+					    ar_umode))
 			return -EINVAL;
 
 		state->mode_blob = drm_property_blob_get(blob);
@@ -2229,6 +2254,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
 
 	state->acquire_ctx = &ctx;
 	state->allow_modeset = !!(arg->flags & DRM_MODE_ATOMIC_ALLOW_MODESET);
+	state->allow_aspect_ratio = file_priv->aspect_ratio_allowed;
 
 retry:
 	plane_mask = 0;
drivers/gpu/drm/drm_crtc.c +19 -0
index f0556e6..a2d34fa 100644
@@ -425,6 +425,13 @@ int drm_mode_getcrtc(struct drm_device *dev,
 	drm_modeset_lock(&crtc->mutex, NULL);
 	if (crtc->state) {
 		if (crtc->state->enable) {
+			/*
+			 * If the aspect-ratio is not required by the,
+			 * userspace, do not set the aspect-ratio flags.
+			 */
+			if (!file_priv->aspect_ratio_allowed)
+				crtc->state->mode.picture_aspect_ratio =
+					HDMI_PICTURE_ASPECT_NONE;
 			drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode);
 			crtc_resp->mode_valid = 1;
 
@@ -435,6 +442,13 @@ int drm_mode_getcrtc(struct drm_device *dev,
 		crtc_resp->x = crtc->x;
 		crtc_resp->y = crtc->y;
 		if (crtc->enabled) {
+			/*
+			 * If the aspect-ratio is not required by the,
+			 * userspace, do not set the aspect-ratio flags.
+			 */
+			if (!file_priv->aspect_ratio_allowed)
+				crtc->mode.picture_aspect_ratio =
+					HDMI_PICTURE_ASPECT_NONE;
 			drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode);
 			crtc_resp->mode_valid = 1;
 
@@ -610,6 +624,11 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 			goto out;
 		}
 
+		/* If the user does not ask for aspect ratio, reset the aspect
+		 * ratio bits in the usermode.
+		 */
+		if (!file_priv->aspect_ratio_allowed)
+			crtc_req->mode.flags &= (~DRM_MODE_FLAG_PIC_AR_MASK);
 		ret = drm_mode_convert_umode(mode, &crtc_req->mode);
 		if (ret) {
 			DRM_DEBUG_KMS("Invalid mode\n");
include/drm/drm_atomic.h +2 -0
index 5afd6e3..ae74b2c 100644
@@ -209,6 +209,7 @@ struct __drm_private_objs_state {
  * @ref: count of all references to this state (will not be freed until zero)
  * @dev: parent DRM device
  * @allow_modeset: allow full modeset
+ * @allow_aspect_ratio: allow the aspect ratio info to be passes to user
  * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
  * @async_update: hint for asynchronous plane update
  * @planes: pointer to array of structures with per-plane data
@@ -224,6 +225,7 @@ struct drm_atomic_state {
 
 	struct drm_device *dev;
 	bool allow_modeset : 1;
+	bool allow_aspect_ratio : 1;
 	bool legacy_cursor_update : 1;
 	bool async_update : 1;
 	struct __drm_planes_state *planes;
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#3 lore raw

Re: [REBASE 2/5] drm: Handle aspect ratio in modeset paths

Quoted 5 lines · Shashank Sharma

From: Ankit Nautiyal <[email protected]>

If the user mode does not support aspect-ratio, and requests for a modeset with aspect ratio flags, then the flag bits reprsenting aspect ratio must be ignored.

Rejected, not ignored. Rejection should happen when converting the umode to mode.

And filtering should happen in getcrtc and getblob. The way you're currently doing things will corrupt the current state, which is not good.

Quoted 163 lines

Similarly, if user space doesn't set the aspect ratio client cap, while preparing a usermode, the aspect-ratio info must not be given into it.

This patch:
1. adds a new bit field aspect_ratio_allowed in drm_atomic_state, which is set only if the aspect-ratio is supported by the user.
2. discards the aspect-ratio info from the user mode while preparing kernel mode structure, during modeset, if the user does not support aspect ratio.
3. avoids setting the aspect-ratio info in user-mode, while converting user-mode from the kernel-mode.

Cc Ville Syrjala <[email protected]>
Cc Shashank Sharma <[email protected]>
Cc Jose Abreu <[email protected]>
---
 drivers/gpu/drm/drm_atomic.c | 40 +++++++++++++++++++++++++++++++++-------
 drivers/gpu/drm/drm_crtc.c   | 19 +++++++++++++++++++
 include/drm/drm_atomic.h     |  2 ++
 3 files changed, 54 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_atomic.c +33 -7
index 37445d5..b9743af 100644
@@ -338,18 +338,30 @@ int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
 	state->mode_blob = NULL;
 
 	if (mode) {
-		drm_mode_convert_to_umode(&umode, mode);
+		/*
+		 * If the user has not asked for aspect ratio support,
+		 * take a copy of the 'mode' and set the aspect ratio as
+		 * None. This copy is used to prepare the user-mode with no
+		 * aspect-ratio info.
+		 */
+		struct drm_display_mode ar_mode;
+		struct drm_atomic_state *atomic_state = state->state;
+
+		drm_mode_copy(&ar_mode, mode);
+		if (atomic_state && !atomic_state->allow_aspect_ratio)
+			ar_mode.picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
+		drm_mode_convert_to_umode(&umode, &ar_mode);
 		state->mode_blob =
 			drm_property_create_blob(state->crtc->dev,
-		                                 sizeof(umode),
-		                                 &umode);
+						 sizeof(umode),
+						 &umode);
 		if (IS_ERR(state->mode_blob))
 			return PTR_ERR(state->mode_blob);
 
-		drm_mode_copy(&state->mode, mode);
+		drm_mode_copy(&state->mode, &ar_mode);
 		state->enable = true;
 		DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
-				 mode->name, state);
+				 ar_mode.name, state);
 	} else {
 		memset(&state->mode, 0, sizeof(state->mode));
 		state->enable = false;
@@ -386,10 +398,23 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
 	memset(&state->mode, 0, sizeof(state->mode));
 
 	if (blob) {
+		struct drm_mode_modeinfo *ar_umode;
+		struct drm_atomic_state *atomic_state;
+
+		/*
+		 * If the user-space does not ask for aspect-ratio
+		 * the aspect ratio bits in the drmModeModeinfo from user,
+		 * does not mean anything. Therefore these bits must be
+		 * discarded.
+		 */
+		ar_umode = (struct drm_mode_modeinfo *) blob->data;
+		atomic_state = state->state;
+		if (atomic_state && !atomic_state->allow_aspect_ratio)
+			ar_umode->flags &= (~DRM_MODE_FLAG_PIC_AR_MASK);
 		if (blob->length != sizeof(struct drm_mode_modeinfo) ||
 		    drm_mode_convert_umode(&state->mode,
-		                           (const struct drm_mode_modeinfo *)
-		                            blob->data))
+					   (const struct drm_mode_modeinfo *)
+					    ar_umode))
 			return -EINVAL;
 
 		state->mode_blob = drm_property_blob_get(blob);
@@ -2229,6 +2254,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
 
 	state->acquire_ctx = &ctx;
 	state->allow_modeset = !!(arg->flags & DRM_MODE_ATOMIC_ALLOW_MODESET);
+	state->allow_aspect_ratio = file_priv->aspect_ratio_allowed;
 
 retry:
 	plane_mask = 0;
drivers/gpu/drm/drm_crtc.c +19 -0
index f0556e6..a2d34fa 100644
@@ -425,6 +425,13 @@ int drm_mode_getcrtc(struct drm_device *dev,
 	drm_modeset_lock(&crtc->mutex, NULL);
 	if (crtc->state) {
 		if (crtc->state->enable) {
+			/*
+			 * If the aspect-ratio is not required by the,
+			 * userspace, do not set the aspect-ratio flags.
+			 */
+			if (!file_priv->aspect_ratio_allowed)
+				crtc->state->mode.picture_aspect_ratio =
+					HDMI_PICTURE_ASPECT_NONE;
 			drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode);
 			crtc_resp->mode_valid = 1;
 
@@ -435,6 +442,13 @@ int drm_mode_getcrtc(struct drm_device *dev,
 		crtc_resp->x = crtc->x;
 		crtc_resp->y = crtc->y;
 		if (crtc->enabled) {
+			/*
+			 * If the aspect-ratio is not required by the,
+			 * userspace, do not set the aspect-ratio flags.
+			 */
+			if (!file_priv->aspect_ratio_allowed)
+				crtc->mode.picture_aspect_ratio =
+					HDMI_PICTURE_ASPECT_NONE;
 			drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode);
 			crtc_resp->mode_valid = 1;
 
@@ -610,6 +624,11 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
 			goto out;
 		}
 
+		/* If the user does not ask for aspect ratio, reset the aspect
+		 * ratio bits in the usermode.
+		 */
+		if (!file_priv->aspect_ratio_allowed)
+			crtc_req->mode.flags &= (~DRM_MODE_FLAG_PIC_AR_MASK);
 		ret = drm_mode_convert_umode(mode, &crtc_req->mode);
 		if (ret) {
 			DRM_DEBUG_KMS("Invalid mode\n");
include/drm/drm_atomic.h +2 -0
index 5afd6e3..ae74b2c 100644
@@ -209,6 +209,7 @@ struct __drm_private_objs_state {
  * @ref: count of all references to this state (will not be freed until zero)
  * @dev: parent DRM device
  * @allow_modeset: allow full modeset
+ * @allow_aspect_ratio: allow the aspect ratio info to be passes to user
  * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
  * @async_update: hint for asynchronous plane update
  * @planes: pointer to array of structures with per-plane data
@@ -224,6 +225,7 @@ struct drm_atomic_state {
 
 	struct drm_device *dev;
 	bool allow_modeset : 1;
+	bool allow_aspect_ratio : 1;
 	bool legacy_cursor_update : 1;
 	bool async_update : 1;
 	struct __drm_planes_state *planes;
Signature · 1 line
2.7.4
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

Re: [REBASE 2/5] drm: Handle aspect ratio in modeset paths

Hi Ville,

Thanks for the suggestions. Please find my response inline

Quoted 6 lines · Ville Syrjälä
Quoted 5 lines · Shashank Sharma

From: Ankit Nautiyal <[email protected]>

If the user mode does not support aspect-ratio, and requests for a modeset with aspect ratio flags, then the flag bits reprsenting aspect ratio must be ignored.

Quoted 6 lines

Rejected, not ignored. Rejection should happen when converting the umode to mode.

And filtering should happen in getcrtc and getblob. The way you're currently doing things will corrupt the current state, which is not good.

Agreed.
The filtering is being done in getcrtc but getblob was missing. Will add the changes in getblob and send the new patch.

Regards,
Ankit

Quoted 155 lines
Quoted 155 lines

Similarly, if user space doesn't set the aspect ratio client cap, while preparing a usermode, the aspect-ratio info must not be given into it.

This patch:
1. adds a new bit field aspect_ratio_allowed in drm_atomic_state, which is set only if the aspect-ratio is supported by the user.
2. discards the aspect-ratio info from the user mode while preparing kernel mode structure, during modeset, if the user does not support aspect ratio.
3. avoids setting the aspect-ratio info in user-mode, while converting user-mode from the kernel-mode.

Cc Ville Syrjala <[email protected]>
Cc Shashank Sharma <[email protected]>
Cc Jose Abreu <[email protected]>
---
  drivers/gpu/drm/drm_atomic.c | 40 +++++++++++++++++++++++++++++++++-------
  drivers/gpu/drm/drm_crtc.c   | 19 +++++++++++++++++++
  include/drm/drm_atomic.h     |  2 ++
  3 files changed, 54 insertions(+), 7 deletions(-)
drivers/gpu/drm/drm_atomic.c +33 -7
index 37445d5..b9743af 100644
@@ -338,18 +338,30 @@ int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state,
  	state->mode_blob = NULL;
 
  	if (mode) {
-		drm_mode_convert_to_umode(&umode, mode);
+		/*
+		 * If the user has not asked for aspect ratio support,
+		 * take a copy of the 'mode' and set the aspect ratio as
+		 * None. This copy is used to prepare the user-mode with no
+		 * aspect-ratio info.
+		 */
+		struct drm_display_mode ar_mode;
+		struct drm_atomic_state *atomic_state = state->state;
+
+		drm_mode_copy(&ar_mode, mode);
+		if (atomic_state && !atomic_state->allow_aspect_ratio)
+			ar_mode.picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
+		drm_mode_convert_to_umode(&umode, &ar_mode);
  		state->mode_blob =
  			drm_property_create_blob(state->crtc->dev,
-		                                 sizeof(umode),
-		                                 &umode);
+						 sizeof(umode),
+						 &umode);
  		if (IS_ERR(state->mode_blob))
  			return PTR_ERR(state->mode_blob);
 
-		drm_mode_copy(&state->mode, mode);
+		drm_mode_copy(&state->mode, &ar_mode);
  		state->enable = true;
  		DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n",
-				 mode->name, state);
+				 ar_mode.name, state);
  	} else {
  		memset(&state->mode, 0, sizeof(state->mode));
  		state->enable = false;
@@ -386,10 +398,23 @@ int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state,
  	memset(&state->mode, 0, sizeof(state->mode));
 
  	if (blob) {
+		struct drm_mode_modeinfo *ar_umode;
+		struct drm_atomic_state *atomic_state;
+
+		/*
+		 * If the user-space does not ask for aspect-ratio
+		 * the aspect ratio bits in the drmModeModeinfo from user,
+		 * does not mean anything. Therefore these bits must be
+		 * discarded.
+		 */
+		ar_umode = (struct drm_mode_modeinfo *) blob->data;
+		atomic_state = state->state;
+		if (atomic_state && !atomic_state->allow_aspect_ratio)
+			ar_umode->flags &= (~DRM_MODE_FLAG_PIC_AR_MASK);
  		if (blob->length != sizeof(struct drm_mode_modeinfo) ||
  		    drm_mode_convert_umode(&state->mode,
-		                           (const struct drm_mode_modeinfo *)
-		                            blob->data))
+					   (const struct drm_mode_modeinfo *)
+					    ar_umode))
  			return -EINVAL;
 
  		state->mode_blob = drm_property_blob_get(blob);
@@ -2229,6 +2254,7 @@ int drm_mode_atomic_ioctl(struct drm_device *dev,
 
  	state->acquire_ctx = &ctx;
  	state->allow_modeset = !!(arg->flags & DRM_MODE_ATOMIC_ALLOW_MODESET);
+	state->allow_aspect_ratio = file_priv->aspect_ratio_allowed;
 
  retry:
  	plane_mask = 0;
drivers/gpu/drm/drm_crtc.c +19 -0
index f0556e6..a2d34fa 100644
@@ -425,6 +425,13 @@ int drm_mode_getcrtc(struct drm_device *dev,
  	drm_modeset_lock(&crtc->mutex, NULL);
  	if (crtc->state) {
  		if (crtc->state->enable) {
+			/*
+			 * If the aspect-ratio is not required by the,
+			 * userspace, do not set the aspect-ratio flags.
+			 */
+			if (!file_priv->aspect_ratio_allowed)
+				crtc->state->mode.picture_aspect_ratio =
+					HDMI_PICTURE_ASPECT_NONE;
  			drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode);
  			crtc_resp->mode_valid = 1;
 
@@ -435,6 +442,13 @@ int drm_mode_getcrtc(struct drm_device *dev,
  		crtc_resp->x = crtc->x;
  		crtc_resp->y = crtc->y;
  		if (crtc->enabled) {
+			/*
+			 * If the aspect-ratio is not required by the,
+			 * userspace, do not set the aspect-ratio flags.
+			 */
+			if (!file_priv->aspect_ratio_allowed)
+				crtc->mode.picture_aspect_ratio =
+					HDMI_PICTURE_ASPECT_NONE;
  			drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode);
  			crtc_resp->mode_valid = 1;
 
@@ -610,6 +624,11 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data,
  			goto out;
  		}
 
+		/* If the user does not ask for aspect ratio, reset the aspect
+		 * ratio bits in the usermode.
+		 */
+		if (!file_priv->aspect_ratio_allowed)
+			crtc_req->mode.flags &= (~DRM_MODE_FLAG_PIC_AR_MASK);
  		ret = drm_mode_convert_umode(mode, &crtc_req->mode);
  		if (ret) {
  			DRM_DEBUG_KMS("Invalid mode\n");
include/drm/drm_atomic.h +1 -0
index 5afd6e3..ae74b2c 100644
@@ -209,6 +209,7 @@ struct __drm_private_objs_state {
   * @ref: count of all references to this state (will not be freed until zero)
   * @dev: parent DRM device
   * @allow_modeset: allow full modeset
+ * @allow_aspect_ratio: allow the aspect ratio info to be passes to user
   * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics
   * @async_update: hint for asynchronous plane update
   * @planes: pointer to array of structures with per-plane data
@@ -224,6 +225,7 @@ struct drm_atomic_state {
 
Quoted 8 lines
Quoted 8 lines
include/drm/drm_atomic.h +1 -0
  	struct drm_device *dev;
  	bool allow_modeset : 1;
+	bool allow_aspect_ratio : 1;
  	bool legacy_cursor_update : 1;
  	bool async_update : 1;
  	struct __drm_planes_state *planes;
Signature · 1 line
2.7.4

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

#5 lore raw

PATCH 3/5 drm: Expose modes with aspect ratio, only if requested

In reply to Shashank Sharma

From: aknautiy <[email protected]>

We parse the EDID and add all the modes in the connector's modelist. This adds CEA modes with aspect ratio information too, regadless of if user space requested this information or not.

This patch prunes the modes with aspect-ratio information, from a connector's modelist, if the user-space has not set the aspect ratio DRM client cap.

Cc Ville Syrjala <[email protected]>
Cc Shashank Sharma <[email protected]>
Cc Jose Abreu <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_connector.c +7 -0
index 704fc89..a246bb5 100644
@@ -1285,6 +1285,13 @@ static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
 	 */
 	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
 		return false;
+	/*
+	 * If user-space hasn't configured the driver to expose the modes
+	 * with aspect-ratio, don't expose them.
+	 */
+	if (!file_priv->aspect_ratio_allowed &&
+	    mode->picture_aspect_ratio != HDMI_PICTURE_ASPECT_NONE)
+		return false;
 
 	return true;
 }
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

Re: [REBASE 3/5] drm: Expose modes with aspect ratio, only if requested

Quoted 25 lines · Shashank Sharma

From: aknautiy <[email protected]>

We parse the EDID and add all the modes in the connector's modelist. This adds CEA modes with aspect ratio information too, regadless of if user space requested this information or not.

This patch prunes the modes with aspect-ratio information, from a connector's modelist, if the user-space has not set the aspect ratio DRM client cap.

Cc Ville Syrjala <[email protected]>
Cc Shashank Sharma <[email protected]>
Cc Jose Abreu <[email protected]>
---
 drivers/gpu/drm/drm_connector.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_connector.c +0 -0
index 704fc89..a246bb5 100644

drivers/gpu/drm/drm_connector.c static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode, · line 1294

Quoted 10 lines
drivers/gpu/drm/drm_connector.c +7 -0
@@ -1285,6 +1285,13 @@ static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
 	 */
 	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
 		return false;
+	/*
+	 * If user-space hasn't configured the driver to expose the modes
+	 * with aspect-ratio, don't expose them.
+	 */
+	if (!file_priv->aspect_ratio_allowed &&
+	    mode->picture_aspect_ratio != HDMI_PICTURE_ASPECT_NONE)
+		return false;

I don't think we can just blindly drop the modes. We would have to expose them with the aspect ratio cleared. That could lead to duplicates, but I'm thinking that shouldn't be a real problem for userspace. Having to filteri out the duplicates would certainly complicate things a bit.

Quoted 5 lines
drivers/gpu/drm/drm_connector.c +0 -0
 	return true;
 }
Signature · 1 line
2.7.4
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

Re: [REBASE 3/5] drm: Expose modes with aspect ratio, only if requested

Regards

Shashank

Quoted 33 lines · Ville Syrjälä
Quoted 32 lines · Shashank Sharma

From: aknautiy <[email protected]>

We parse the EDID and add all the modes in the connector's modelist. This adds CEA modes with aspect ratio information too, regadless of if user space requested this information or not.

This patch prunes the modes with aspect-ratio information, from a connector's modelist, if the user-space has not set the aspect ratio DRM client cap.

Cc Ville Syrjala <[email protected]>
Cc Shashank Sharma <[email protected]>
Cc Jose Abreu <[email protected]>
---
  drivers/gpu/drm/drm_connector.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_connector.c +4 -0
index 704fc89..a246bb5 100644
@@ -1285,6 +1285,13 @@ static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
  	 */
  	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
  		return false;
+	/*
+	 * If user-space hasn't configured the driver to expose the modes
+	 * with aspect-ratio, don't expose them.
+	 */
Quoted 8 lines

drivers/gpu/drm/drm_connector.c static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode, · line 1294

Quoted 3 lines
drivers/gpu/drm/drm_connector.c +3 -0
+	if (!file_priv->aspect_ratio_allowed &&
+	    mode->picture_aspect_ratio != HDMI_PICTURE_ASPECT_NONE)
+		return false;

I don't think we can just blindly drop the modes. We would have to expose them with the aspect ratio cleared. That could lead to duplicates, but I'm thinking that shouldn't be a real problem for userspace. Having to filteri out the duplicates would certainly complicate things a bit.

Yes, Agree. Even I was thinking that the right way should be to:
- add a drm_mode_equal_no_aspect function (like drm_mode_equal_no_clock_no_stereo).
- clear the aspect ratio information from the mode, when not asked for.
- check the sorted connector->modes list for duplicates for this mode, using above function.
- if mode exists, remove it from the list
- if not, keep it in the list

Sounds like a plan ?

- Shashank

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/drm_connector.c +0 -0
  	return true;
  }
Signature · 1 line
2.7.4

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

#8 lore raw

Re: [REBASE 3/5] drm: Expose modes with aspect ratio, only if requested

Quoted 47 lines · Shashank

Regards

Shashank

Quoted 33 lines · Ville Syrjälä
Quoted 32 lines · Shashank Sharma

From: aknautiy <[email protected]>

We parse the EDID and add all the modes in the connector's modelist. This adds CEA modes with aspect ratio information too, regadless of if user space requested this information or not.

This patch prunes the modes with aspect-ratio information, from a connector's modelist, if the user-space has not set the aspect ratio DRM client cap.

Cc Ville Syrjala <[email protected]>
Cc Shashank Sharma <[email protected]>
Cc Jose Abreu <[email protected]>
---
  drivers/gpu/drm/drm_connector.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/drm_connector.c +4 -0
index 704fc89..a246bb5 100644
@@ -1285,6 +1285,13 @@ static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
  	 */
  	if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
  		return false;
+	/*
+	 * If user-space hasn't configured the driver to expose the modes
+	 * with aspect-ratio, don't expose them.
+	 */
Quoted 8 lines

drivers/gpu/drm/drm_connector.c static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode, · line 1294

Quoted 3 lines
drivers/gpu/drm/drm_connector.c +3 -0
+	if (!file_priv->aspect_ratio_allowed &&
+	    mode->picture_aspect_ratio != HDMI_PICTURE_ASPECT_NONE)
+		return false;

I don't think we can just blindly drop the modes. We would have to expose them with the aspect ratio cleared. That could lead to duplicates, but I'm thinking that shouldn't be a real problem for userspace. Having to filteri out the duplicates would certainly complicate things a bit.

Quoted 3 lines

Yes, Agree. Even I was thinking that the right way should be to:
- add a drm_mode_equal_no_aspect function (like drm_mode_equal_no_clock_no_stereo).

Or just drm_mode_match() with the right flags ;)

Quoted 5 lines

- clear the aspect ratio information from the mode, when not asked for.
- check the sorted connector->modes list for duplicates for this mode, using above function.
- if mode exists, remove it from the list
- if not, keep it in the list

Hmm. Since the list should be sorted I guess this won't even have to traverse the list mutliple times. We can just keep skipping modes as long they match the last mode we've already decided to expose.

Quoted 9 lines

Sounds like a plan ?

- Shashank

Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/drm_connector.c +0 -0
  	return true;
  }
Signature · 1 line
2.7.4
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw

PATCH 4/5 drm: Add aspect ratio parsing in DRM layer

In reply to Shashank Sharma

Current DRM layer functions don't parse aspect ratio information while converting a user mode->kernel mode or vice versa. This causes modeset to pick mode with wrong aspect ratio, eventually causing failures in HDMI compliance test cases, due to wrong VIC.

This patch adds aspect ratio information in DRM's mode conversion and mode comparision functions, to make sure kernel picks mode with right aspect ratio (as per the VIC).

Background:
This patch was once reviewed and merged, and later reverted due to lack of DRM cap protection. This is a re-spin of this patch, this time with DRM cap protection, to avoid aspect ratio information, when the client doesn't request for it.

Review link: https://pw-emeril.freedesktop.org/patch/104068/
Background discussion: https://patchwork.kernel.org/patch/9379057/

Cc Ville Syrjala <[email protected]>
Cc Jim Bride <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Ankit Nautiyal <[email protected]>
---
 drivers/gpu/drm/drm_modes.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
drivers/gpu/drm/drm_modes.c +31 -0
index 4a3f68a..2e8a11e 100644
@@ -1015,6 +1015,7 @@ bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
 	    mode1->vsync_end == mode2->vsync_end &&
 	    mode1->vtotal == mode2->vtotal &&
 	    mode1->vscan == mode2->vscan &&
+	    mode1->picture_aspect_ratio == mode2->picture_aspect_ratio &&
 	    (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
 	     (mode2->flags & ~DRM_MODE_FLAG_3D_MASK))
 		return true;
@@ -1549,6 +1550,21 @@ void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
 	out->vrefresh = in->vrefresh;
 	out->flags = in->flags;
 	out->type = in->type;
+	out->flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
+
+	switch (in->picture_aspect_ratio) {
+	case HDMI_PICTURE_ASPECT_4_3:
+		out->flags |= DRM_MODE_FLAG_PIC_AR_4_3;
+		break;
+	case HDMI_PICTURE_ASPECT_16_9:
+		out->flags |= DRM_MODE_FLAG_PIC_AR_16_9;
+		break;
+	case HDMI_PICTURE_ASPECT_RESERVED:
+	default:
+		out->flags |= DRM_MODE_FLAG_PIC_AR_NONE;
+		break;
+	}
+
 	strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
 	out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
 }
@@ -1594,6 +1610,21 @@ int drm_mode_convert_umode(struct drm_display_mode *out,
 	strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
 	out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
 
+	/* Clearing picture aspect ratio bits from out flags */
+	out->flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
+
+	switch (in->flags & DRM_MODE_FLAG_PIC_AR_MASK) {
+	case DRM_MODE_FLAG_PIC_AR_4_3:
+		out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_4_3;
+		break;
+	case DRM_MODE_FLAG_PIC_AR_16_9:
+		out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_16_9;
+		break;
+	default:
+		out->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
+		break;
+	}
+
 	out->status = drm_mode_validate_basic(out);
 	if (out->status != MODE_OK)
 		goto out;
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#10 lore raw

PATCH 5/5 drm: Add and handle new aspect ratios in DRM layer

In reply to Shashank Sharma

HDMI 2.0/CEA-861-F introduces two new aspect ratios:
- 64:27
- 256:135

This patch:
- Adds new DRM flags for to represent these new aspect ratios.
- Adds new cases to handle these aspect ratios while converting from user->kernel mode or vise versa.

This patch was once reviewed and merged, and later reverted due to lack of DRM client protection, while adding aspect ratio bits in user modes. This is a re-spin of the series, with DRM client cap protection.

The previous series can be found here:
https://pw-emeril.freedesktop.org/series/10850/

Cc Ville Syrjala <[email protected]>
Cc Sean Paul <[email protected]>
Cc Jose Abreu <[email protected]>
Cc Ankit Nautiyal <[email protected]>
---
 drivers/gpu/drm/drm_modes.c | 12 ++++++++++++
 include/uapi/drm/drm_mode.h |  6 ++++++
 2 files changed, 18 insertions(+)
drivers/gpu/drm/drm_modes.c +12 -0
index 2e8a11e..b9ec35b 100644
@@ -1559,6 +1559,12 @@ void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
 	case HDMI_PICTURE_ASPECT_16_9:
 		out->flags |= DRM_MODE_FLAG_PIC_AR_16_9;
 		break;
+	case HDMI_PICTURE_ASPECT_64_27:
+		out->flags |= DRM_MODE_FLAG_PIC_AR_64_27;
+		break;
+	case DRM_MODE_PICTURE_ASPECT_256_135:
+		out->flags |= DRM_MODE_FLAG_PIC_AR_256_135;
+		break;
 	case HDMI_PICTURE_ASPECT_RESERVED:
 	default:
 		out->flags |= DRM_MODE_FLAG_PIC_AR_NONE;
@@ -1620,6 +1626,12 @@ int drm_mode_convert_umode(struct drm_display_mode *out,
 	case DRM_MODE_FLAG_PIC_AR_16_9:
 		out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_16_9;
 		break;
+	case DRM_MODE_FLAG_PIC_AR_64_27:
+		out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_64_27;
+		break;
+	case DRM_MODE_FLAG_PIC_AR_256_135:
+		out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_256_135;
+		break;
 	default:
 		out->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
 		break;
include/uapi/drm/drm_mode.h +6 -0
index 5597a87..64177d7 100644
@@ -89,6 +89,8 @@ extern "C" {
 #define DRM_MODE_PICTURE_ASPECT_NONE		0
 #define DRM_MODE_PICTURE_ASPECT_4_3		1
 #define DRM_MODE_PICTURE_ASPECT_16_9		2
+#define DRM_MODE_PICTURE_ASPECT_64_27		3
+#define DRM_MODE_PICTURE_ASPECT_256_135		4
 
 /* Aspect ratio flag bitmask (4 bits 22:19) */
 #define DRM_MODE_FLAG_PIC_AR_MASK		(0x0F<<19)
@@ -98,6 +100,10 @@ extern "C" {
 			(DRM_MODE_PICTURE_ASPECT_4_3<<19)
 #define  DRM_MODE_FLAG_PIC_AR_16_9 \
 			(DRM_MODE_PICTURE_ASPECT_16_9<<19)
+#define  DRM_MODE_FLAG_PIC_AR_64_27 \
+			(DRM_MODE_PICTURE_ASPECT_64_27<<19)
+#define  DRM_MODE_FLAG_PIC_AR_256_135 \
+			(DRM_MODE_PICTURE_ASPECT_256_135<<19)
 
 /* DPMS flags */
 /* bit compatible with the xorg definitions. */
Signature · 6 lines
2.7.4

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