drm/i915/opregion: convert intel_opregion_get_edid() to struct drm_edid
authorJani Nikula <jani.nikula@intel.com>
Wed, 25 Jan 2023 11:10:51 +0000 (13:10 +0200)
committerJani Nikula <jani.nikula@intel.com>
Thu, 26 Jan 2023 10:27:30 +0000 (12:27 +0200)
Simplify validation and use by converting to drm_edid.

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/6abb01f1e97d54a3c11bec24377f035df412b492.1674643465.git.jani.nikula@intel.com
drivers/gpu/drm/i915/display/intel_dp.c
drivers/gpu/drm/i915/display/intel_opregion.c
drivers/gpu/drm/i915/display/intel_opregion.h

index cffaa5131e5478fc13fb599e3a121482dd1cf121..123138b911cdde93924fa81da41e1cf104c4916b 100644 (file)
@@ -5298,18 +5298,12 @@ static bool intel_edp_init_connector(struct intel_dp *intel_dp,
        mutex_lock(&dev_priv->drm.mode_config.mutex);
        drm_edid = drm_edid_read_ddc(connector, &intel_dp->aux.ddc);
        if (!drm_edid) {
-               const struct edid *edid;
-
                /* Fallback to EDID from ACPI OpRegion, if any */
-               /* FIXME: Make intel_opregion_get_edid() return drm_edid */
-               edid = intel_opregion_get_edid(intel_connector);
-               if (edid) {
-                       drm_edid = drm_edid_alloc(edid, (edid->extensions + 1) * EDID_LENGTH);
+               drm_edid = intel_opregion_get_edid(intel_connector);
+               if (drm_edid)
                        drm_dbg_kms(&dev_priv->drm,
                                    "[CONNECTOR:%d:%s] Using OpRegion EDID\n",
                                    connector->base.id, connector->name);
-                       kfree(edid);
-               }
        }
        if (drm_edid) {
                if (drm_edid_connector_update(connector, drm_edid) ||
index e0184745632c079bd90b8eba74ea05d584aeaab8..b8dce0576512aab714d340e1a0e851f810102ca7 100644 (file)
@@ -1101,41 +1101,34 @@ intel_opregion_get_panel_type(struct drm_i915_private *dev_priv)
  * The EDID in the OpRegion, or NULL if there is none or it's invalid.
  *
  */
-struct edid *intel_opregion_get_edid(struct intel_connector *intel_connector)
+const struct drm_edid *intel_opregion_get_edid(struct intel_connector *intel_connector)
 {
        struct drm_connector *connector = &intel_connector->base;
        struct drm_i915_private *i915 = to_i915(connector->dev);
        struct intel_opregion *opregion = &i915->display.opregion;
-       const void *in_edid;
-       const struct edid *edid;
-       struct edid *new_edid;
+       const struct drm_edid *drm_edid;
+       const void *edid;
        int len;
 
        if (!opregion->asle_ext)
                return NULL;
 
-       in_edid = opregion->asle_ext->bddc;
+       edid = opregion->asle_ext->bddc;
 
        /* Validity corresponds to number of 128-byte blocks */
        len = (opregion->asle_ext->phed & ASLE_PHED_EDID_VALID_MASK) * 128;
-       if (!len || !memchr_inv(in_edid, 0, len))
+       if (!len || !memchr_inv(edid, 0, len))
                return NULL;
 
-       edid = in_edid;
+       drm_edid = drm_edid_alloc(edid, len);
 
-       if (len < EDID_LENGTH * (1 + edid->extensions)) {
-               drm_dbg_kms(&i915->drm, "Invalid EDID in ACPI OpRegion (Mailbox #5): too short\n");
-               return NULL;
-       }
-       new_edid = drm_edid_duplicate(edid);
-       if (!new_edid)
-               return NULL;
-       if (!drm_edid_is_valid(new_edid)) {
-               kfree(new_edid);
+       if (!drm_edid_valid(drm_edid)) {
                drm_dbg_kms(&i915->drm, "Invalid EDID in ACPI OpRegion (Mailbox #5)\n");
-               return NULL;
+               drm_edid_free(drm_edid);
+               drm_edid = NULL;
        }
-       return new_edid;
+
+       return drm_edid;
 }
 
 bool intel_opregion_headless_sku(struct drm_i915_private *i915)
index 2f261f98540081e4593f4da32cdd29d3aeabec12..d02e6696a050e12dec491bd2674bdbda88f3cf28 100644 (file)
@@ -74,7 +74,7 @@ int intel_opregion_notify_encoder(struct intel_encoder *intel_encoder,
 int intel_opregion_notify_adapter(struct drm_i915_private *dev_priv,
                                  pci_power_t state);
 int intel_opregion_get_panel_type(struct drm_i915_private *dev_priv);
-struct edid *intel_opregion_get_edid(struct intel_connector *connector);
+const struct drm_edid *intel_opregion_get_edid(struct intel_connector *connector);
 
 bool intel_opregion_headless_sku(struct drm_i915_private *i915);
 
@@ -123,7 +123,7 @@ static inline int intel_opregion_get_panel_type(struct drm_i915_private *dev)
        return -ENODEV;
 }
 
-static inline struct edid *
+static inline const struct drm_edid *
 intel_opregion_get_edid(struct intel_connector *connector)
 {
        return NULL;