[PATCH v3 05/17] drm/connector: Use common colorspace_names array

Sebastian Wick sebastian.wick at redhat.com
Thu Mar 9 01:39:43 UTC 2023


On Tue, Mar 7, 2023 at 4:12 PM Harry Wentland <harry.wentland at amd.com> wrote:
>
> We an use bitfields to track the support ones for HDMI
> and DP. This allows us to print colorspaces in a consistent
> manner without needing to know whether we're dealing with
> DP or HDMI.
>
> Signed-off-by: Harry Wentland <harry.wentland at amd.com>
> Cc: Pekka Paalanen <ppaalanen at gmail.com>
> Cc: Sebastian Wick <sebastian.wick at redhat.com>
> Cc: Vitaly.Prosyak at amd.com
> Cc: Uma Shankar <uma.shankar at intel.com>
> Cc: Ville Syrjälä <ville.syrjala at linux.intel.com>
> Cc: Joshua Ashton <joshua at froggi.es>
> Cc: Jani Nikula <jani.nikula at linux.intel.com>
> Cc: dri-devel at lists.freedesktop.org
> Cc: amd-gfx at lists.freedesktop.org
> ---
>  drivers/gpu/drm/drm_connector.c | 131 +++++++++++++++++++-------------
>  include/drm/drm_connector.h     |   1 +
>  2 files changed, 78 insertions(+), 54 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c
> index ff4af48c029a..7649f0ac454f 100644
> --- a/drivers/gpu/drm/drm_connector.c
> +++ b/drivers/gpu/drm/drm_connector.c
> @@ -1012,64 +1012,70 @@ static const struct drm_prop_enum_list drm_dp_subconnector_enum_list[] = {
>  DRM_ENUM_NAME_FN(drm_get_dp_subconnector_name,
>                  drm_dp_subconnector_enum_list)
>
> -static const struct drm_prop_enum_list hdmi_colorspaces[] = {
> +
> +static const char * const colorspace_names[] = {
>         /* For Default case, driver will set the colorspace */
> -       { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
> +       [DRM_MODE_COLORIMETRY_DEFAULT] = "Default",
>         /* Standard Definition Colorimetry based on CEA 861 */
> -       { DRM_MODE_COLORIMETRY_SMPTE_170M_YCC, "SMPTE_170M_YCC" },
> -       { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
> +       [DRM_MODE_COLORIMETRY_SMPTE_170M_YCC] = "SMPTE_170M_YCC",
> +       [DRM_MODE_COLORIMETRY_BT709_YCC] = "BT709_YCC",
>         /* Standard Definition Colorimetry based on IEC 61966-2-4 */
> -       { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
> +       [DRM_MODE_COLORIMETRY_XVYCC_601] = "XVYCC_601",
>         /* High Definition Colorimetry based on IEC 61966-2-4 */
> -       { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
> +       [DRM_MODE_COLORIMETRY_XVYCC_709] = "XVYCC_709",
>         /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
> -       { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
> +       [DRM_MODE_COLORIMETRY_SYCC_601] = "SYCC_601",
>         /* Colorimetry based on IEC 61966-2-5 [33] */
> -       { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
> +       [DRM_MODE_COLORIMETRY_OPYCC_601] = "opYCC_601",
>         /* Colorimetry based on IEC 61966-2-5 */
> -       { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
> +       [DRM_MODE_COLORIMETRY_OPRGB] = "opRGB",
>         /* Colorimetry based on ITU-R BT.2020 */
> -       { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
> +       [DRM_MODE_COLORIMETRY_BT2020_CYCC] = "BT2020_CYCC",
>         /* Colorimetry based on ITU-R BT.2020 */
> -       { DRM_MODE_COLORIMETRY_BT2020, "BT2020" },
> +       [DRM_MODE_COLORIMETRY_BT2020] = "BT2020",
>         /* Colorimetry based on ITU-R BT.2020 */
> -       { DRM_MODE_COLORIMETRY_BT2020_DEPRECATED, "BT2020_DEPRECATED" },
> -       /* Added as part of Additional Colorimetry Extension in 861.G */
> -       { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
> -       { DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER, "DCI-P3_RGB_Theater" },
> +       [DRM_MODE_COLORIMETRY_BT2020_DEPRECATED] = "BT2020_DEPRECATED",
> +       /* Colorimetry based on SMPTE RP 431-2 */
> +       [DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65] = "P3_RGB_D65",
> +       [DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER] = "P3_RGB_Theater",
> +       [DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED] = "RGB_WIDE_FIXED",
> +       /* Colorimetry based on scRGB (IEC 61966-2-2) */
> +       [DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT] = "RGB_WIDE_FLOAT",
> +       [DRM_MODE_COLORIMETRY_BT601_YCC] = "BT601_YCC",
>  };
>
> +static const u32 hdmi_colorspaces =
> +       BIT(DRM_MODE_COLORIMETRY_SMPTE_170M_YCC) |
> +       BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
> +       BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |
> +       BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |
> +       BIT(DRM_MODE_COLORIMETRY_SYCC_601) |
> +       BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |
> +       BIT(DRM_MODE_COLORIMETRY_OPRGB) |
> +       BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |
> +       BIT(DRM_MODE_COLORIMETRY_BT2020) |
> +       BIT(DRM_MODE_COLORIMETRY_BT2020_DEPRECATED) |
> +       BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |
> +       BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_THEATER);
> +
>  /*
>   * As per DP 1.4a spec, 2.2.5.7.5 VSC SDP Payload for Pixel Encoding/Colorimetry
>   * Format Table 2-120
>   */
> -static const struct drm_prop_enum_list dp_colorspaces[] = {
> -       /* For Default case, driver will set the colorspace */
> -       { DRM_MODE_COLORIMETRY_DEFAULT, "Default" },
> -       { DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED, "RGB_Wide_Gamut_Fixed_Point" },
> -       /* Colorimetry based on scRGB (IEC 61966-2-2) */
> -       { DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT, "RGB_Wide_Gamut_Floating_Point" },
> -       /* Colorimetry based on IEC 61966-2-5 */
> -       { DRM_MODE_COLORIMETRY_OPRGB, "opRGB" },
> -       /* Colorimetry based on SMPTE RP 431-2 */
> -       { DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65, "DCI-P3_RGB_D65" },
> -       /* Colorimetry based on ITU-R BT.2020 */
> -       { DRM_MODE_COLORIMETRY_BT2020, "BT2020" },
> -       { DRM_MODE_COLORIMETRY_BT601_YCC, "BT601_YCC" },
> -       { DRM_MODE_COLORIMETRY_BT709_YCC, "BT709_YCC" },
> -       /* Standard Definition Colorimetry based on IEC 61966-2-4 */
> -       { DRM_MODE_COLORIMETRY_XVYCC_601, "XVYCC_601" },
> -       /* High Definition Colorimetry based on IEC 61966-2-4 */
> -       { DRM_MODE_COLORIMETRY_XVYCC_709, "XVYCC_709" },
> -       /* Colorimetry based on IEC 61966-2-1/Amendment 1 */
> -       { DRM_MODE_COLORIMETRY_SYCC_601, "SYCC_601" },
> -       /* Colorimetry based on IEC 61966-2-5 [33] */
> -       { DRM_MODE_COLORIMETRY_OPYCC_601, "opYCC_601" },
> -       /* Colorimetry based on ITU-R BT.2020 */
> -       { DRM_MODE_COLORIMETRY_BT2020_CYCC, "BT2020_CYCC" },
> -       /* Colorimetry based on ITU-R BT.2020 */
> -       { DRM_MODE_COLORIMETRY_BT2020_DEPRECATED, "BT2020_DEPRECATED" },
> -};
> +static const u32 dp_colorspaces =
> +       BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED) |
> +       BIT(DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT) |
> +       BIT(DRM_MODE_COLORIMETRY_OPRGB) |
> +       BIT(DRM_MODE_COLORIMETRY_DCI_P3_RGB_D65) |
> +       BIT(DRM_MODE_COLORIMETRY_BT2020) |
> +       BIT(DRM_MODE_COLORIMETRY_BT601_YCC) |
> +       BIT(DRM_MODE_COLORIMETRY_BT709_YCC) |
> +       BIT(DRM_MODE_COLORIMETRY_XVYCC_601) |
> +       BIT(DRM_MODE_COLORIMETRY_XVYCC_709) |
> +       BIT(DRM_MODE_COLORIMETRY_SYCC_601) |
> +       BIT(DRM_MODE_COLORIMETRY_OPYCC_601) |
> +       BIT(DRM_MODE_COLORIMETRY_BT2020_CYCC) |
> +       BIT(DRM_MODE_COLORIMETRY_BT2020_DEPRECATED);
>
>  /**
>   * DOC: standard connector properties
> @@ -1972,30 +1978,49 @@ EXPORT_SYMBOL(drm_mode_create_aspect_ratio_property);
>   */
>
>  static int drm_mode_create_colorspace_property(struct drm_connector *connector,
> -                                       const struct drm_prop_enum_list *colorspaces,
> -                                       int size)
> +                                       u32 supported_colorspaces)
>  {
>         struct drm_device *dev = connector->dev;
> +       u32 colorspaces = supported_colorspaces | BIT(DRM_MODE_COLORIMETRY_DEFAULT);
> +       struct drm_prop_enum_list enum_list[DRM_MODE_COLORIMETRY_MAX];
> +       int i, len;
>
>         if (connector->colorspace_property)
>                 return 0;
>
> -       if (!colorspaces)
> -               return 0;
> +       if (!supported_colorspaces)
> +               drm_dbg_kms(dev, "Driver is not passing supported colorspaces on [CONNECTOR:%d:%s]\n",
> +                           connector->base.id, connector->name);
> +
> +       if ((supported_colorspaces & -BIT(DRM_MODE_COLORIMETRY_MAX)) != 0)
> +               return -EINVAL;
> +
> +       len = 0;
> +       for (i = 0; i < DRM_MODE_COLORIMETRY_MAX; i++) {
> +               if (supported_colorspaces != 0 && (colorspaces & BIT(i)) == 0)
> +                       continue;
> +
> +               enum_list[len].type = i;
> +               enum_list[len].name = colorspace_names[i];
> +               len++;
> +       }
>
>         connector->colorspace_property =
>                 drm_property_create_enum(dev, DRM_MODE_PROP_ENUM, "Colorspace",
> -                                       colorspaces,
> -                                       size);
> +                                       enum_list,
> +                                       len);
>
>         if (!connector->colorspace_property)
>                 return -ENOMEM;
>
>         return 0;
>  }
> +
>  /**
>   * drm_mode_create_hdmi_colorspace_property - create hdmi colorspace property
>   * @connector: connector to create the Colorspace property on.
> + * @supported_colorspaces: A bitfield of supported colorspaces or 0 for all
> + *                         HDMI colorspaces

That belongs in a later patch. Same on drm_mode_create_dp_colorspace_property.

>   *
>   * Called by a driver the first time it's needed, must be attached to desired
>   * HDMI connectors.
> @@ -2005,15 +2030,15 @@ static int drm_mode_create_colorspace_property(struct drm_connector *connector,
>   */
>  int drm_mode_create_hdmi_colorspace_property(struct drm_connector *connector)
>  {
> -       return drm_mode_create_colorspace_property(connector,
> -                                                  hdmi_colorspaces,
> -                                                  ARRAY_SIZE(hdmi_colorspaces));
> +       return drm_mode_create_colorspace_property(connector, hdmi_colorspaces);
>  }
>  EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
>
>  /**
>   * drm_mode_create_dp_colorspace_property - create dp colorspace property
>   * @connector: connector to create the Colorspace property on.
> + * @supported_colorspaces: A bitfield of supported colorspaces or 0 for all
> + *                         DP colorspaces
>   *
>   * Called by a driver the first time it's needed, must be attached to desired
>   * DP connectors.
> @@ -2023,9 +2048,7 @@ EXPORT_SYMBOL(drm_mode_create_hdmi_colorspace_property);
>   */
>  int drm_mode_create_dp_colorspace_property(struct drm_connector *connector)
>  {
> -       return drm_mode_create_colorspace_property(connector,
> -                                                  dp_colorspaces,
> -                                                  ARRAY_SIZE(dp_colorspaces));
> +       return drm_mode_create_colorspace_property(connector, dp_colorspaces);
>  }
>  EXPORT_SYMBOL(drm_mode_create_dp_colorspace_property);
>
> diff --git a/include/drm/drm_connector.h b/include/drm/drm_connector.h
> index 3e2e1bc7aa04..46c064d9ffef 100644
> --- a/include/drm/drm_connector.h
> +++ b/include/drm/drm_connector.h
> @@ -460,6 +460,7 @@ enum drm_colorspace {
>         DRM_MODE_COLORIMETRY_RGB_WIDE_FIXED     = 13,
>         DRM_MODE_COLORIMETRY_RGB_WIDE_FLOAT     = 14,
>         DRM_MODE_COLORIMETRY_BT601_YCC          = 15,
> +       DRM_MODE_COLORIMETRY_MAX
>  };
>
>  /**
> --
> 2.39.2
>



More information about the amd-gfx mailing list