Skip to content

Commit c3ff0cd

Browse files
aknautiyalmlankhorst
authored andcommitted
drm: Expose modes with aspect ratio, only if requested
We parse the EDID and add all the modes in the connector's modelist. This adds CEA modes with aspect ratio information too, regardless of whether user space requested this information or not. This patch: -prunes the modes with aspect-ratio information, from the drm_mode_get_connector modelist supplied to the user, if the user-space has not set the aspect ratio DRM client cap. However if such a mode is unique in the list, it is kept in the list, with aspect-ratio flags reset. -prepares a list of exposed modes, which is used to find unique modes if aspect-ratio is not allowed. -adds a new list_head 'exposed_head' in drm_mode_display, to traverse the list of exposed modes. Cc: Ville Syrjala <ville.syrjala@linux.intel.com> Cc: Shashank Sharma <shashank.sharma@intel.com> Cc: Jose Abreu <jose.abreu@synopsys.com> Signed-off-by: Ankit Nautiyal <ankit.k.nautiyal@intel.com> V3: As suggested by Ville, modified the mechanism of pruning of modes with aspect-ratio, if the aspect-ratio is not supported. Instead of straight away pruning such a mode, the mode is retained with aspect ratio bits set to zero, provided it is unique. V4: rebase V5: Addressed review comments from Ville: -used a pointer to store last valid mode. -avoided, modifying of picture_aspect_ratio in kernel mode, instead only flags bits of user mode are reset (if aspect-ratio is not supported). V6: As suggested by Ville, corrected the mode pruning logic and elaborated the mode pruning logic and the assumptions taken. V7: rebase V8: rebase V9: rebase V10: rebase V11: Fixed the issue caused in kms_3d test, and enhanced the pruning logic to correctly identify and prune modes with aspect-ratio, if aspect-ratio cap is not set. V12: As suggested by Ville, added another list_head in drm_mode_display to traverse the list of exposed modes and avoided duplication of modes. V13: Minor modifications, as suggested by Ville. v14: As suggested by Daniel Vetter and Ville Syrjala, corrected the pruning logic to avoid any dependency in the order of mode with aspect-ratio. Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/1525777785-9740-9-git-send-email-ankit.k.nautiyal@intel.com
1 parent ace5bf0 commit c3ff0cd

2 files changed

Lines changed: 50 additions & 7 deletions

File tree

‎drivers/gpu/drm/drm_connector.c‎

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,15 +1531,34 @@ static struct drm_encoder *drm_connector_get_encoder(struct drm_connector *conne
15311531
return connector->encoder;
15321532
}
15331533

1534-
static bool drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
1535-
const struct drm_file *file_priv)
1534+
static bool
1535+
drm_mode_expose_to_userspace(const struct drm_display_mode *mode,
1536+
const struct list_head *export_list,
1537+
const struct drm_file *file_priv)
15361538
{
15371539
/*
15381540
* If user-space hasn't configured the driver to expose the stereo 3D
15391541
* modes, don't expose them.
15401542
*/
15411543
if (!file_priv->stereo_allowed && drm_mode_is_stereo(mode))
15421544
return false;
1545+
/*
1546+
* If user-space hasn't configured the driver to expose the modes
1547+
* with aspect-ratio, don't expose them. However if such a mode
1548+
* is unique, let it be exposed, but reset the aspect-ratio flags
1549+
* while preparing the list of user-modes.
1550+
*/
1551+
if (!file_priv->aspect_ratio_allowed) {
1552+
struct drm_display_mode *mode_itr;
1553+
1554+
list_for_each_entry(mode_itr, export_list, export_head)
1555+
if (drm_mode_match(mode_itr, mode,
1556+
DRM_MODE_MATCH_TIMINGS |
1557+
DRM_MODE_MATCH_CLOCK |
1558+
DRM_MODE_MATCH_FLAGS |
1559+
DRM_MODE_MATCH_3D_FLAGS))
1560+
return false;
1561+
}
15431562

15441563
return true;
15451564
}
@@ -1559,6 +1578,7 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
15591578
struct drm_mode_modeinfo u_mode;
15601579
struct drm_mode_modeinfo __user *mode_ptr;
15611580
uint32_t __user *encoder_ptr;
1581+
LIST_HEAD(export_list);
15621582

15631583
if (!drm_core_check_feature(dev, DRIVER_MODESET))
15641584
return -EINVAL;
@@ -1607,21 +1627,31 @@ int drm_mode_getconnector(struct drm_device *dev, void *data,
16071627

16081628
/* delayed so we get modes regardless of pre-fill_modes state */
16091629
list_for_each_entry(mode, &connector->modes, head)
1610-
if (drm_mode_expose_to_userspace(mode, file_priv))
1630+
if (drm_mode_expose_to_userspace(mode, &export_list,
1631+
file_priv)) {
1632+
list_add_tail(&mode->export_head, &export_list);
16111633
mode_count++;
1634+
}
16121635

16131636
/*
16141637
* This ioctl is called twice, once to determine how much space is
16151638
* needed, and the 2nd time to fill it.
1639+
* The modes that need to be exposed to the user are maintained in the
1640+
* 'export_list'. When the ioctl is called first time to determine the,
1641+
* space, the export_list gets filled, to find the no.of modes. In the
1642+
* 2nd time, the user modes are filled, one by one from the export_list.
16161643
*/
16171644
if ((out_resp->count_modes >= mode_count) && mode_count) {
16181645
copied = 0;
16191646
mode_ptr = (struct drm_mode_modeinfo __user *)(unsigned long)out_resp->modes_ptr;
1620-
list_for_each_entry(mode, &connector->modes, head) {
1621-
if (!drm_mode_expose_to_userspace(mode, file_priv))
1622-
continue;
1623-
1647+
list_for_each_entry(mode, &export_list, export_head) {
16241648
drm_mode_convert_to_umode(&u_mode, mode);
1649+
/*
1650+
* Reset aspect ratio flags of user-mode, if modes with
1651+
* aspect-ratio are not supported.
1652+
*/
1653+
if (!file_priv->aspect_ratio_allowed)
1654+
u_mode.flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
16251655
if (copy_to_user(mode_ptr + copied,
16261656
&u_mode, sizeof(u_mode))) {
16271657
ret = -EFAULT;

‎include/drm/drm_modes.h‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,19 @@ struct drm_display_mode {
411411
* Field for setting the HDMI picture aspect ratio of a mode.
412412
*/
413413
enum hdmi_picture_aspect picture_aspect_ratio;
414+
415+
/**
416+
* @export_head:
417+
*
418+
* struct list_head for modes to be exposed to the userspace.
419+
* This is to maintain a list of exposed modes while preparing
420+
* user-mode's list in drm_mode_getconnector ioctl. The purpose of this
421+
* list_head only lies in the ioctl function, and is not expected to be
422+
* used outside the function.
423+
* Once used, the stale pointers are not reset, but left as it is, to
424+
* avoid overhead of protecting it by mode_config.mutex.
425+
*/
426+
struct list_head export_head;
414427
};
415428

416429
/**

0 commit comments

Comments
 (0)