Skip to contentSkip to conversation

Add support for getting EDID over ACPI to DRM

PATCH Superseded Mario Limonciello 2 participants 8 messages Feb 11, 2024 – Feb 15, 2024

Subsystems (6)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover Add support for getting EDID over ACPI to DRM

This series adds the ability to fetch the EDID through ACPI for laptop panels. Drivers need to opt into the behavior.

In this series it's enabled by default for all eDP or LVDS panels with AMDGPU and certain panels for Nouveau.

Mario Limonciello (3):
drm: Add support to get EDID from ACPI drm/amd: Fetch the EDID from _DDC if available for eDP drm/nouveau: Use drm_edid_read_acpi() helper

 drivers/gpu/drm/Kconfig                       |   7 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu.h           |   1 +
 .../gpu/drm/amd/amdgpu/amdgpu_connectors.c    |   3 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c       |   8 ++
 .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c |   2 +
 .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c |   2 +
 drivers/gpu/drm/drm_edid.c                    | 113 ++++++++++++++++--
 drivers/gpu/drm/nouveau/nouveau_acpi.c        |  27 -----
 drivers/gpu/drm/nouveau/nouveau_acpi.h        |   2 -
 drivers/gpu/drm/nouveau/nouveau_connector.c   |  35 +++---
 include/drm/drm_connector.h                   |   6 +
 include/drm/drm_edid.h                        |   1 +
 12 files changed, 149 insertions(+), 58 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 1/3 drm: Add support to get EDID from ACPI

Some manufacturers have intentionally put an EDID that differs from the EDID on the internal panel on laptops. Drivers that prefer to fetch this EDID can set a bit on the drm_connector to indicate that the DRM EDID helpers should try to fetch it and it is preferred if it's present.

---
v1->v2:
* Split code from previous amdgpu specific helper to generic drm helper.
v2->v3:
* Add an extra select to fix a variety of randconfig errors found from LKP robot.
v3->v4:
* Return struct drm_edid
v4->v5:
* Rename to drm_edid_read_acpi
* Drop selects

---
 drivers/gpu/drm/Kconfig     |   7 +++
 drivers/gpu/drm/drm_edid.c  | 113 +++++++++++++++++++++++++++++++++---
 include/drm/drm_connector.h |   6 ++
 include/drm/drm_edid.h      |   1 +
 4 files changed, 119 insertions(+), 8 deletions(-)
drivers/gpu/drm/Kconfig +7 -0
index 2520db0b776e..a49740c528b9 100644
@@ -103,6 +103,13 @@ config DRM_KMS_HELPER
 	help
 	  CRTC helpers for KMS drivers.
 
+config DRM_ACPI_HELPER
+	tristate "ACPI support in DRM"
+	depends on DRM
+	depends on (ACPI_VIDEO || ACPI_VIDEO=n)
+	help
+	  ACPI helpers for DRM drivers.
+
 config DRM_DEBUG_DP_MST_TOPOLOGY_REFS
         bool "Enable refcount backtrace history in the DP MST helpers"
 	depends on STACKTRACE_SUPPORT
drivers/gpu/drm/drm_edid.c +105 -8

164 lines not on this page · raw message

include/drm/drm_connector.h +6 -0
index fe88d7fc6b8f..74ed47f37a69 100644
@@ -1886,6 +1886,12 @@ struct drm_connector {
 
 	/** @hdr_sink_metadata: HDR Metadata Information read from sink */
 	struct hdr_sink_metadata hdr_sink_metadata;
+
+	/**
+	 * @acpi_edid_allowed: Get the EDID from the BIOS, if available.
+	 * This is only applicable to eDP and LVDS displays.
+	 */
+	bool acpi_edid_allowed;
 };
 
 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
include/drm/drm_edid.h +1 -0
index 518d1b8106c7..38b5e1b5c773 100644
@@ -463,5 +463,6 @@ bool drm_edid_is_digital(const struct drm_edid *drm_edid);
 
 const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid,
 				  int ext_id, int *ext_index);
+const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector);
 
 #endif /* __DRM_EDID_H__ */
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v5 1/3] drm: Add support to get EDID from ACPI

Quoted 30 lines · Mario Limonciello

Some manufacturers have intentionally put an EDID that differs from the EDID on the internal panel on laptops. Drivers that prefer to fetch this EDID can set a bit on the drm_connector to indicate that the DRM EDID helpers should try to fetch it and it is preferred if it's present.

---
v1->v2:
* Split code from previous amdgpu specific helper to generic drm helper.
v2->v3:
* Add an extra select to fix a variety of randconfig errors found from LKP robot.
v3->v4:
* Return struct drm_edid
v4->v5:
* Rename to drm_edid_read_acpi
* Drop selects

---
  drivers/gpu/drm/Kconfig     |   7 +++
  drivers/gpu/drm/drm_edid.c  | 113 +++++++++++++++++++++++++++++++++---
  include/drm/drm_connector.h |   6 ++
  include/drm/drm_edid.h      |   1 +
  4 files changed, 119 insertions(+), 8 deletions(-)
drivers/gpu/drm/Kconfig +0 -0
index 2520db0b776e..a49740c528b9 100644

drivers/gpu/drm/Kconfig config DRM_KMS_HELPER · line 112

Quoted 10 lines
drivers/gpu/drm/Kconfig +7 -0
@@ -103,6 +103,13 @@ config DRM_KMS_HELPER
  	help
  	  CRTC helpers for KMS drivers.
 
+config DRM_ACPI_HELPER
+	tristate "ACPI support in DRM"
+	depends on DRM
+	depends on (ACPI_VIDEO || ACPI_VIDEO=n)
+	help
+	  ACPI helpers for DRM drivers.
+

Unfortunately in my wider testing this still fails with a few combinations.

This combination fails to link:

CONFIG_ACPI_VIDEO=m
CONFIG_DRM_ACPI_HELPER=y
CONFIG_DRM=y

This combination links but doesn't work because the IS_REACHABLE() fails (-EOPNOTSUPP):

CONFIG_ACPI_VIDEO=m
CONFIG_DRM_ACPI_HELPER=M
CONFIG_DRM=y

I'm tempted to split off all of drm_edid to it's own module instead of CONFIG_DRM_ACPI_HELPER which has a depends on (ACPI_VIDEO || ACPI_VIDEIO=n).

Or Daniel, any better ideas?

Quoted 205 lines
drivers/gpu/drm/Kconfig +0 -0
  config DRM_DEBUG_DP_MST_TOPOLOGY_REFS
          bool "Enable refcount backtrace history in the DP MST helpers"
  	depends on STACKTRACE_SUPPORT
drivers/gpu/drm/drm_edid.c +105 -8
index 69c68804023f..096c278b6f66 100644
@@ -28,6 +28,7 @@
   * DEALINGS IN THE SOFTWARE.
   */
 
+#include <acpi/video.h>
  #include <linux/bitfield.h>
  #include <linux/cec.h>
  #include <linux/hdmi.h>
@@ -2188,6 +2189,62 @@ drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
  	return ret == xfers ? 0 : -1;
  }
 
+/**
+ * drm_do_probe_acpi_edid() - get EDID information via ACPI _DDC
+ * @data: struct drm_connector
+ * @buf: EDID data buffer to be filled
+ * @block: 128 byte EDID block to start fetching from
+ * @len: EDID data buffer length to fetch
+ *
+ * Try to fetch EDID information by calling acpi_video_get_edid() function.
+ *
+ * Return: 0 on success or error code on failure.
+ */
+static int
+drm_do_probe_acpi_edid(void *data, u8 *buf, unsigned int block, size_t len)
+{
+	struct drm_connector *connector = data;
+	struct drm_device *ddev = connector->dev;
+	struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev);
+	unsigned char start = block * EDID_LENGTH;
+	void *edid;
+	int r;
+
+	if (!acpidev)
+		return -ENODEV;
+
+	switch (connector->connector_type) {
+	case DRM_MODE_CONNECTOR_LVDS:
+	case DRM_MODE_CONNECTOR_eDP:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* fetch the entire edid from BIOS */
+	if (IS_REACHABLE(CONFIG_DRM_ACPI_HELPER)) {
+		r = acpi_video_get_edid(acpidev, ACPI_VIDEO_DISPLAY_LCD, -1, &edid);
+		if (r < 0) {
+			DRM_DEBUG_KMS("Failed to get EDID from ACPI: %d\n", r);
+			return -EINVAL;
+		}
+	} else {
+		r = -EOPNOTSUPP;
+	}
+	if (len > r || start > r || start + len > r) {
+		r = -EINVAL;
+		goto cleanup;
+	}
+
+	memcpy(buf, edid + start, len);
+	r = 0;
+
+cleanup:
+	kfree(edid);
+
+	return r;
+}
+
  static void connector_bad_edid(struct drm_connector *connector,
  			       const struct edid *edid, int num_blocks)
  {
@@ -2621,7 +2678,8 @@ EXPORT_SYMBOL(drm_probe_ddc);
   * @connector: connector we're probing
   * @adapter: I2C adapter to use for DDC
   *
- * Poke the given I2C channel to grab EDID data if possible.  If found,
+ * If the connector allows it, try to fetch EDID data using ACPI. If not found
+ * poke the given I2C channel to grab EDID data if possible.  If found,
   * attach it to the connector.
   *
   * Return: Pointer to valid EDID or NULL if we couldn't find any.
@@ -2629,20 +2687,50 @@ EXPORT_SYMBOL(drm_probe_ddc);
  struct edid *drm_get_edid(struct drm_connector *connector,
  			  struct i2c_adapter *adapter)
  {
-	struct edid *edid;
+	struct edid *edid = NULL;
 
  	if (connector->force == DRM_FORCE_OFF)
  		return NULL;
 
-	if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
-		return NULL;
+	if (connector->acpi_edid_allowed)
+		edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, connector, NULL);
+
+	if (!edid) {
+		if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
+			return NULL;
+		edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL);
+	}
 
-	edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL);
  	drm_connector_update_edid_property(connector, edid);
  	return edid;
  }
  EXPORT_SYMBOL(drm_get_edid);
 
+/**
+ * drm_edid_read_acpi - get EDID data, if available
+ * @connector: connector we're probing
+ *
+ * Use the BIOS to attempt to grab EDID data if possible.
+ *
+ * The returned pointer must be freed using drm_edid_free().
+ *
+ * Return: Pointer to valid EDID or NULL if we couldn't find any.
+ */
+const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector)
+{
+	const struct drm_edid *drm_edid;
+
+	if (connector->force == DRM_FORCE_OFF)
+		return NULL;
+
+	drm_edid = drm_edid_read_custom(connector, drm_do_probe_acpi_edid, connector);
+
+	/* Note: Do *not* call connector updates here. */
+
+	return drm_edid;
+}
+EXPORT_SYMBOL(drm_edid_read_acpi);
+
  /**
   * drm_edid_read_custom - Read EDID data using given EDID block read function
   * @connector: Connector to use
@@ -2727,10 +2815,11 @@ const struct drm_edid *drm_edid_read_ddc(struct drm_connector *connector,
  EXPORT_SYMBOL(drm_edid_read_ddc);
 
  /**
- * drm_edid_read - Read EDID data using connector's I2C adapter
+ * drm_edid_read - Read EDID data using BIOS or connector's I2C adapter
   * @connector: Connector to use
   *
- * Read EDID using the connector's I2C adapter.
+ * Read EDID from BIOS if allowed by connector or by using the connector's
+ * I2C adapter.
   *
   * The EDID may be overridden using debugfs override_edid or firmware EDID
   * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority
@@ -2742,10 +2831,18 @@ EXPORT_SYMBOL(drm_edid_read_ddc);
   */
  const struct drm_edid *drm_edid_read(struct drm_connector *connector)
  {
+	const struct drm_edid *drm_edid = NULL;
+
  	if (drm_WARN_ON(connector->dev, !connector->ddc))
  		return NULL;
 
-	return drm_edid_read_ddc(connector, connector->ddc);
+	if (connector->acpi_edid_allowed)
+		drm_edid = drm_edid_read_acpi(connector);
+
+	if (!drm_edid)
+		drm_edid = drm_edid_read_ddc(connector, connector->ddc);
+
+	return drm_edid;
  }
  EXPORT_SYMBOL(drm_edid_read);
 
include/drm/drm_connector.h +6 -0
index fe88d7fc6b8f..74ed47f37a69 100644
@@ -1886,6 +1886,12 @@ struct drm_connector {
 
  	/** @hdr_sink_metadata: HDR Metadata Information read from sink */
  	struct hdr_sink_metadata hdr_sink_metadata;
+
+	/**
+	 * @acpi_edid_allowed: Get the EDID from the BIOS, if available.
+	 * This is only applicable to eDP and LVDS displays.
+	 */
+	bool acpi_edid_allowed;
  };
 
  #define obj_to_connector(x) container_of(x, struct drm_connector, base)
include/drm/drm_edid.h +1 -0
index 518d1b8106c7..38b5e1b5c773 100644
@@ -463,5 +463,6 @@ bool drm_edid_is_digital(const struct drm_edid *drm_edid);
 
  const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid,
  				  int ext_id, int *ext_index);
+const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector);
 
  #endif /* __DRM_EDID_H__ */
#3 lore raw

Re: [PATCH v5 1/3] drm: Add support to get EDID from ACPI

Quoted 51 lines · Mario Limonciello
Quoted 32 lines · Mario Limonciello

Some manufacturers have intentionally put an EDID that differs from the EDID on the internal panel on laptops.  Drivers that prefer to fetch this EDID can set a bit on the drm_connector to indicate that the DRM EDID helpers should try to fetch it and it is preferred if it's present.

---
v1->v2:
  * Split code from previous amdgpu specific helper to generic drm helper. v2->v3:
  * Add an extra select to fix a variety of randconfig errors found from LKP robot.
v3->v4:
  * Return struct drm_edid
v4->v5:
  * Rename to drm_edid_read_acpi
  * Drop selects
---
  drivers/gpu/drm/Kconfig     |   7 +++ drivers/gpu/drm/drm_edid.c  | 113 +++++++++++++++++++++++++++++++++--- include/drm/drm_connector.h |   6 ++
  include/drm/drm_edid.h      |   1 +

  4 files changed, 119 insertions(+), 8 deletions(-)
drivers/gpu/drm/Kconfig +0 -0
index 2520db0b776e..a49740c528b9 100644
@@ -103,6 +103,13 @@ config DRM_KMS_HELPER

      help
        CRTC helpers for KMS drivers.

drivers/gpu/drm/Kconfig

Quoted 7 lines
drivers/gpu/drm/Kconfig +7 -0
+config DRM_ACPI_HELPER
+    tristate "ACPI support in DRM"
+    depends on DRM
+    depends on (ACPI_VIDEO || ACPI_VIDEO=n)
+    help
+      ACPI helpers for DRM drivers.
+

Unfortunately in my wider testing this still fails with a few combinations.

This combination fails to link:

CONFIG_ACPI_VIDEO=m
CONFIG_DRM_ACPI_HELPER=y
CONFIG_DRM=y

This combination links but doesn't work because the IS_REACHABLE() fails (-EOPNOTSUPP):

Quoted 7 lines

CONFIG_ACPI_VIDEO=m
CONFIG_DRM_ACPI_HELPER=M
CONFIG_DRM=y

I'm tempted to split off all of drm_edid to it's own module instead  of CONFIG_DRM_ACPI_HELPER which has a depends on (ACPI_VIDEO || ACPI_VIDEIO=n).

Or Daniel, any better ideas?

I've come up with a solution that undoes all the select mess in preceding patches.

This patch will be swapped around to

drivers/gpu/drm/Kconfig +0 -0
@@ -8,6 +8,7 @@
 menuconfig DRM
        tristate "Direct Rendering Manager (XFree86 4.1.0 and higher 

DRI support)"

        depends on (AGP || AGP=n) && !EMULATED_CMPXCHG && HAS_DMA

+ depends on (ACPI_VIDEO || ACPI_VIDEO=n)
select DRM_PANEL_ORIENTATION_QUIRKS select DRM_KMS_HELPER if DRM_FBDEV_EMULATION select FB_CORE if DRM_FBDEV_EMULATION

I'll wait a little for any other feedback and then post the updated series. None of the other patches change in any material way.

Quoted 210 lines
Quoted 209 lines

  config DRM_DEBUG_DP_MST_TOPOLOGY_REFS
          bool "Enable refcount backtrace history in the DP MST helpers" depends on STACKTRACE_SUPPORT

drivers/gpu/drm/drm_edid.c +9 -0
index 69c68804023f..096c278b6f66 100644
@@ -28,6 +28,7 @@
    * DEALINGS IN THE SOFTWARE.
    */
+#include <acpi/video.h>
   #include <linux/bitfield.h>
   #include <linux/cec.h>
   #include <linux/hdmi.h>
@@ -2188,6 +2189,62 @@ drm_do_probe_ddc_edid(void *data, u8 *buf, 
 unsigned int block, size_t len)
       return ret == xfers ? 0 : -1;
   }
+/**
+ * drm_do_probe_acpi_edid() - get EDID information via ACPI _DDC
+ * @data: struct drm_connector
+ * @buf: EDID data buffer to be filled
+ * @block: 128 byte EDID block to start fetching from
+ * @len: EDID data buffer length to fetch
+ *
+ * Try to fetch EDID information by calling acpi_video_get_edid() 

function.
+ *
+ * Return: 0 on success or error code on failure.
+ */

drivers/gpu/drm/drm_edid.c +2 -0
+static int
+drm_do_probe_acpi_edid(void *data, u8 *buf, unsigned int block, 

size_t len)

drivers/gpu/drm/drm_edid.c +22 -0
+{
+    struct drm_connector *connector = data;
+    struct drm_device *ddev = connector->dev;
+    struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev);
+    unsigned char start = block * EDID_LENGTH;
+    void *edid;
+    int r;
+
+    if (!acpidev)
+        return -ENODEV;
+
+    switch (connector->connector_type) {
+    case DRM_MODE_CONNECTOR_LVDS:
+    case DRM_MODE_CONNECTOR_eDP:
+        break;
+    default:
+        return -EINVAL;
+    }
+
+    /* fetch the entire edid from BIOS */
+    if (IS_REACHABLE(CONFIG_DRM_ACPI_HELPER)) {
+        r = acpi_video_get_edid(acpidev, ACPI_VIDEO_DISPLAY_LCD, -1, 

&edid);
+        if (r < 0) {
+            DRM_DEBUG_KMS("Failed to get EDID from ACPI: %d\n", r); +            return -EINVAL;
+        }
+    } else {
+        r = -EOPNOTSUPP;
+    }
+    if (len > r || start > r || start + len > r) {
+        r = -EINVAL;
+        goto cleanup;
+    }

drivers/gpu/drm/drm_edid.c +10 -0
+
+    memcpy(buf, edid + start, len);
+    r = 0;
+
+cleanup:
+    kfree(edid);
+
+    return r;
+}
+

  static void connector_bad_edid(struct drm_connector *connector, const struct edid *edid, int num_blocks) {

drivers/gpu/drm/drm_edid.c +1 -1
@@ -2621,7 +2678,8 @@ EXPORT_SYMBOL(drm_probe_ddc);
    * @connector: connector we're probing
    * @adapter: I2C adapter to use for DDC
    *
- * Poke the given I2C channel to grab EDID data if possible.  If found,
+ * If the connector allows it, try to fetch EDID data using ACPI. If 

not found
+ * poke the given I2C channel to grab EDID data if possible.  If found,
   * attach it to the connector.
   *
   * Return: Pointer to valid EDID or NULL if we couldn't find any.

drivers/gpu/drm/drm_edid.c +34 -4
@@ -2629,20 +2687,50 @@ EXPORT_SYMBOL(drm_probe_ddc);
   struct edid *drm_get_edid(struct drm_connector *connector,
                 struct i2c_adapter *adapter)
   {
-    struct edid *edid;
+    struct edid *edid = NULL;
       if (connector->force == DRM_FORCE_OFF)
           return NULL;
-    if (connector->force == DRM_FORCE_UNSPECIFIED && 
 !drm_probe_ddc(adapter))
-        return NULL;
+    if (connector->acpi_edid_allowed)
+        edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, 
 connector, NULL);
+
+    if (!edid) {
+        if (connector->force == DRM_FORCE_UNSPECIFIED && 
 !drm_probe_ddc(adapter))
+            return NULL;
+        edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, 
 adapter, NULL);
+    }
-    edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, 
 adapter, NULL);
       drm_connector_update_edid_property(connector, edid);
       return edid;
   }
   EXPORT_SYMBOL(drm_get_edid);
+/**
+ * drm_edid_read_acpi - get EDID data, if available
+ * @connector: connector we're probing
+ *
+ * Use the BIOS to attempt to grab EDID data if possible.
+ *
+ * The returned pointer must be freed using drm_edid_free().
+ *
+ * Return: Pointer to valid EDID or NULL if we couldn't find any.
+ */
+const struct drm_edid *drm_edid_read_acpi(struct drm_connector 
 *connector)
+{
+    const struct drm_edid *drm_edid;
+
+    if (connector->force == DRM_FORCE_OFF)
+        return NULL;
+
+    drm_edid = drm_edid_read_custom(connector, 
 drm_do_probe_acpi_edid, connector);
+
+    /* Note: Do *not* call connector updates here. */
+
+    return drm_edid;
+}
+EXPORT_SYMBOL(drm_edid_read_acpi);
+

  /**
   * drm_edid_read_custom - Read EDID data using given EDID block read function
   * @connector: Connector to use

drivers/gpu/drm/drm_edid.c +2 -2
@@ -2727,10 +2815,11 @@ const struct drm_edid 
 *drm_edid_read_ddc(struct drm_connector *connector,
   EXPORT_SYMBOL(drm_edid_read_ddc);
   /**
- * drm_edid_read - Read EDID data using connector's I2C adapter
+ * drm_edid_read - Read EDID data using BIOS or connector's I2C adapter
    * @connector: Connector to use
    *
- * Read EDID using the connector's I2C adapter.
+ * Read EDID from BIOS if allowed by connector or by using the 

connector's
+ * I2C adapter.
   *
   * The EDID may be overridden using debugfs override_edid or firmware EDID
   * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority

drivers/gpu/drm/drm_edid.c +9 -1
@@ -2742,10 +2831,18 @@ EXPORT_SYMBOL(drm_edid_read_ddc);
    */
   const struct drm_edid *drm_edid_read(struct drm_connector *connector)
   {
+    const struct drm_edid *drm_edid = NULL;
+
       if (drm_WARN_ON(connector->dev, !connector->ddc))
           return NULL;
-    return drm_edid_read_ddc(connector, connector->ddc);
+    if (connector->acpi_edid_allowed)
+        drm_edid = drm_edid_read_acpi(connector);
+
+    if (!drm_edid)
+        drm_edid = drm_edid_read_ddc(connector, connector->ddc);
+
+    return drm_edid;
   }
   EXPORT_SYMBOL(drm_edid_read);
include/drm/drm_connector.h +6 -0
index fe88d7fc6b8f..74ed47f37a69 100644
@@ -1886,6 +1886,12 @@ struct drm_connector {
       /** @hdr_sink_metadata: HDR Metadata Information read from sink */
       struct hdr_sink_metadata hdr_sink_metadata;
+
+    /**
+     * @acpi_edid_allowed: Get the EDID from the BIOS, if available.
+     * This is only applicable to eDP and LVDS displays.
+     */
+    bool acpi_edid_allowed;
   };
   #define obj_to_connector(x) container_of(x, struct drm_connector, base)
include/drm/drm_edid.h +1 -0
index 518d1b8106c7..38b5e1b5c773 100644
@@ -463,5 +463,6 @@ bool drm_edid_is_digital(const struct drm_edid 
 *drm_edid);
   const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid,
                     int ext_id, int *ext_index);
+const struct drm_edid *drm_edid_read_acpi(struct drm_connector 
 *connector);
   #endif /* __DRM_EDID_H__ */
#4 lore raw

Re: [PATCH v5 1/3] drm: Add support to get EDID from ACPI

In reply to Mario Limonciello
Quoted 138 lines · Mario Limonciello

Some manufacturers have intentionally put an EDID that differs from the EDID on the internal panel on laptops. Drivers that prefer to fetch this EDID can set a bit on the drm_connector to indicate that the DRM EDID helpers should try to fetch it and it is preferred if it's present.

---
v1->v2:
* Split code from previous amdgpu specific helper to generic drm helper.
v2->v3:
* Add an extra select to fix a variety of randconfig errors found from LKP robot.
v3->v4:
* Return struct drm_edid
v4->v5:
* Rename to drm_edid_read_acpi
* Drop selects

---
 drivers/gpu/drm/Kconfig     |   7 +++
 drivers/gpu/drm/drm_edid.c  | 113 +++++++++++++++++++++++++++++++++---
 include/drm/drm_connector.h |   6 ++
 include/drm/drm_edid.h      |   1 +
 4 files changed, 119 insertions(+), 8 deletions(-)
drivers/gpu/drm/Kconfig +7 -0
index 2520db0b776e..a49740c528b9 100644
@@ -103,6 +103,13 @@ config DRM_KMS_HELPER
 	help
 	  CRTC helpers for KMS drivers.
 
+config DRM_ACPI_HELPER
+	tristate "ACPI support in DRM"
+	depends on DRM
+	depends on (ACPI_VIDEO || ACPI_VIDEO=n)
+	help
+	  ACPI helpers for DRM drivers.
+
 config DRM_DEBUG_DP_MST_TOPOLOGY_REFS
         bool "Enable refcount backtrace history in the DP MST helpers"
 	depends on STACKTRACE_SUPPORT
drivers/gpu/drm/drm_edid.c +60 -2
index 69c68804023f..096c278b6f66 100644
@@ -28,6 +28,7 @@
  * DEALINGS IN THE SOFTWARE.
  */
 
+#include <acpi/video.h>
 #include <linux/bitfield.h>
 #include <linux/cec.h>
 #include <linux/hdmi.h>
@@ -2188,6 +2189,62 @@ drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
 	return ret == xfers ? 0 : -1;
 }
 
+/**
+ * drm_do_probe_acpi_edid() - get EDID information via ACPI _DDC
+ * @data: struct drm_connector
+ * @buf: EDID data buffer to be filled
+ * @block: 128 byte EDID block to start fetching from
+ * @len: EDID data buffer length to fetch
+ *
+ * Try to fetch EDID information by calling acpi_video_get_edid() function.
+ *
+ * Return: 0 on success or error code on failure.
+ */
+static int
+drm_do_probe_acpi_edid(void *data, u8 *buf, unsigned int block, size_t len)
+{
+	struct drm_connector *connector = data;
+	struct drm_device *ddev = connector->dev;
+	struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev);
+	unsigned char start = block * EDID_LENGTH;
+	void *edid;
+	int r;
+
+	if (!acpidev)
+		return -ENODEV;
+
+	switch (connector->connector_type) {
+	case DRM_MODE_CONNECTOR_LVDS:
+	case DRM_MODE_CONNECTOR_eDP:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* fetch the entire edid from BIOS */
+	if (IS_REACHABLE(CONFIG_DRM_ACPI_HELPER)) {
+		r = acpi_video_get_edid(acpidev, ACPI_VIDEO_DISPLAY_LCD, -1, &edid);
+		if (r < 0) {
+			DRM_DEBUG_KMS("Failed to get EDID from ACPI: %d\n", r);
+			return -EINVAL;
+		}
+	} else {
+		r = -EOPNOTSUPP;
+	}
+	if (len > r || start > r || start + len > r) {
+		r = -EINVAL;
+		goto cleanup;
+	}
+
+	memcpy(buf, edid + start, len);
+	r = 0;
+
+cleanup:
+	kfree(edid);
+
+	return r;
+}
+
 static void connector_bad_edid(struct drm_connector *connector,
 			       const struct edid *edid, int num_blocks)
 {
@@ -2621,7 +2678,8 @@ EXPORT_SYMBOL(drm_probe_ddc);
  * @connector: connector we're probing
  * @adapter: I2C adapter to use for DDC
  *
- * Poke the given I2C channel to grab EDID data if possible.  If found,
+ * If the connector allows it, try to fetch EDID data using ACPI. If not found
+ * poke the given I2C channel to grab EDID data if possible.  If found,
  * attach it to the connector.
  *
  * Return: Pointer to valid EDID or NULL if we couldn't find any.
@@ -2629,20 +2687,50 @@ EXPORT_SYMBOL(drm_probe_ddc);
 struct edid *drm_get_edid(struct drm_connector *connector,
 			  struct i2c_adapter *adapter)
 {
-	struct edid *edid;
+	struct edid *edid = NULL;
 
 	if (connector->force == DRM_FORCE_OFF)
 		return NULL;
 

drivers/gpu/drm/drm_edid.c EXPORT_SYMBOL(drm_probe_ddc); · line 2702

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +8 -2
-	if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
-		return NULL;
+	if (connector->acpi_edid_allowed)
+		edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, connector, NULL);
+
+	if (!edid) {
+		if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
+			return NULL;
+		edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL);
+	}

Hmm. So do you want the presence of ACPI EDID to determine whether the display is there or not?

Note how the override and firmware EDID mechanisms only override the EDID *contents*. They are orthogonal from connector forcing. So you can override the EDID, but still rely on the DDC probe to determine if the display is there.

The question is, how likely is it that the ACPI EDID is used not just because the actual EDID is bogus, but also because the display just doesn't respond to DDC at all?

If possible, I'd like ACPI EDID to follow the override/firmware EDID semantics on this.

Quoted 13 lines
drivers/gpu/drm/drm_edid.c +6 -1
-	edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL);
 	drm_connector_update_edid_property(connector, edid);
 	return edid;
 }
 EXPORT_SYMBOL(drm_get_edid);
 
+/**
+ * drm_edid_read_acpi - get EDID data, if available
+ * @connector: connector we're probing
+ *
+ * Use the BIOS to attempt to grab EDID data if possible.
+ *

drivers/gpu/drm/drm_edid.c EXPORT_SYMBOL(drm_probe_ddc); · line 2724

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +10 -0
+ * The returned pointer must be freed using drm_edid_free().
+ *
+ * Return: Pointer to valid EDID or NULL if we couldn't find any.
+ */
+const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector)
+{
+	const struct drm_edid *drm_edid;
+
+	if (connector->force == DRM_FORCE_OFF)
+		return NULL;

If the caller handled all the connector->force stuff, this could be dropped.

Quoted 31 lines
drivers/gpu/drm/drm_edid.c +13 -2
+
+	drm_edid = drm_edid_read_custom(connector, drm_do_probe_acpi_edid, connector);
+
+	/* Note: Do *not* call connector updates here. */
+
+	return drm_edid;
+}
+EXPORT_SYMBOL(drm_edid_read_acpi);
+
 /**
  * drm_edid_read_custom - Read EDID data using given EDID block read function
  * @connector: Connector to use
@@ -2727,10 +2815,11 @@ const struct drm_edid *drm_edid_read_ddc(struct drm_connector *connector,
 EXPORT_SYMBOL(drm_edid_read_ddc);
 
 /**
- * drm_edid_read - Read EDID data using connector's I2C adapter
+ * drm_edid_read - Read EDID data using BIOS or connector's I2C adapter
  * @connector: Connector to use
  *
- * Read EDID using the connector's I2C adapter.
+ * Read EDID from BIOS if allowed by connector or by using the connector's
+ * I2C adapter.
  *
  * The EDID may be overridden using debugfs override_edid or firmware EDID
  * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority
@@ -2742,10 +2831,18 @@ EXPORT_SYMBOL(drm_edid_read_ddc);
  */
 const struct drm_edid *drm_edid_read(struct drm_connector *connector)
 {
+	const struct drm_edid *drm_edid = NULL;

drivers/gpu/drm/drm_edid.c EXPORT_SYMBOL(drm_edid_read_ddc); · line 2843

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +6 -1
+
 	if (drm_WARN_ON(connector->dev, !connector->ddc))
 		return NULL;
 
-	return drm_edid_read_ddc(connector, connector->ddc);
+	if (connector->acpi_edid_allowed)
+		drm_edid = drm_edid_read_acpi(connector);
+
+	if (!drm_edid)
+		drm_edid = drm_edid_read_ddc(connector, connector->ddc);

This should be in drm_edid_read_ddc() not drm_edid_read(). Please let's not make the two behave any different. It would be really weird if one had an ACPI check and the other not.

Quoted 33 lines
drivers/gpu/drm/drm_edid.c +2 -0
+
+	return drm_edid;
 }
 EXPORT_SYMBOL(drm_edid_read);
 
include/drm/drm_connector.h +6 -0
index fe88d7fc6b8f..74ed47f37a69 100644
@@ -1886,6 +1886,12 @@ struct drm_connector {
 
 	/** @hdr_sink_metadata: HDR Metadata Information read from sink */
 	struct hdr_sink_metadata hdr_sink_metadata;
+
+	/**
+	 * @acpi_edid_allowed: Get the EDID from the BIOS, if available.
+	 * This is only applicable to eDP and LVDS displays.
+	 */
+	bool acpi_edid_allowed;
 };
 
 #define obj_to_connector(x) container_of(x, struct drm_connector, base)
include/drm/drm_edid.h +1 -0
index 518d1b8106c7..38b5e1b5c773 100644
@@ -463,5 +463,6 @@ bool drm_edid_is_digital(const struct drm_edid *drm_edid);
 
 const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid,
 				  int ext_id, int *ext_index);
+const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector);
 
 #endif /* __DRM_EDID_H__ */
Signature · 1 line
Jani Nikula, Intel
#5 lore raw

Re: [PATCH v5 1/3] drm: Add support to get EDID from ACPI

Quoted 153 lines · Jani Nikula
Quoted 138 lines · Mario Limonciello

Some manufacturers have intentionally put an EDID that differs from the EDID on the internal panel on laptops. Drivers that prefer to fetch this EDID can set a bit on the drm_connector to indicate that the DRM EDID helpers should try to fetch it and it is preferred if it's present.

---
v1->v2:
* Split code from previous amdgpu specific helper to generic drm helper.
v2->v3:
* Add an extra select to fix a variety of randconfig errors found from LKP robot.
v3->v4:
* Return struct drm_edid
v4->v5:
* Rename to drm_edid_read_acpi
* Drop selects

---
  drivers/gpu/drm/Kconfig     |   7 +++
  drivers/gpu/drm/drm_edid.c  | 113 +++++++++++++++++++++++++++++++++---
  include/drm/drm_connector.h |   6 ++
  include/drm/drm_edid.h      |   1 +
  4 files changed, 119 insertions(+), 8 deletions(-)
drivers/gpu/drm/Kconfig +7 -0
index 2520db0b776e..a49740c528b9 100644
@@ -103,6 +103,13 @@ config DRM_KMS_HELPER
  	help
  	  CRTC helpers for KMS drivers.
 
+config DRM_ACPI_HELPER
+	tristate "ACPI support in DRM"
+	depends on DRM
+	depends on (ACPI_VIDEO || ACPI_VIDEO=n)
+	help
+	  ACPI helpers for DRM drivers.
+
  config DRM_DEBUG_DP_MST_TOPOLOGY_REFS
          bool "Enable refcount backtrace history in the DP MST helpers"
  	depends on STACKTRACE_SUPPORT
drivers/gpu/drm/drm_edid.c +60 -2
index 69c68804023f..096c278b6f66 100644
@@ -28,6 +28,7 @@
   * DEALINGS IN THE SOFTWARE.
   */
 
+#include <acpi/video.h>
  #include <linux/bitfield.h>
  #include <linux/cec.h>
  #include <linux/hdmi.h>
@@ -2188,6 +2189,62 @@ drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len)
  	return ret == xfers ? 0 : -1;
  }
 
+/**
+ * drm_do_probe_acpi_edid() - get EDID information via ACPI _DDC
+ * @data: struct drm_connector
+ * @buf: EDID data buffer to be filled
+ * @block: 128 byte EDID block to start fetching from
+ * @len: EDID data buffer length to fetch
+ *
+ * Try to fetch EDID information by calling acpi_video_get_edid() function.
+ *
+ * Return: 0 on success or error code on failure.
+ */
+static int
+drm_do_probe_acpi_edid(void *data, u8 *buf, unsigned int block, size_t len)
+{
+	struct drm_connector *connector = data;
+	struct drm_device *ddev = connector->dev;
+	struct acpi_device *acpidev = ACPI_COMPANION(ddev->dev);
+	unsigned char start = block * EDID_LENGTH;
+	void *edid;
+	int r;
+
+	if (!acpidev)
+		return -ENODEV;
+
+	switch (connector->connector_type) {
+	case DRM_MODE_CONNECTOR_LVDS:
+	case DRM_MODE_CONNECTOR_eDP:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/* fetch the entire edid from BIOS */
+	if (IS_REACHABLE(CONFIG_DRM_ACPI_HELPER)) {
+		r = acpi_video_get_edid(acpidev, ACPI_VIDEO_DISPLAY_LCD, -1, &edid);
+		if (r < 0) {
+			DRM_DEBUG_KMS("Failed to get EDID from ACPI: %d\n", r);
+			return -EINVAL;
+		}
+	} else {
+		r = -EOPNOTSUPP;
+	}
+	if (len > r || start > r || start + len > r) {
+		r = -EINVAL;
+		goto cleanup;
+	}
+
+	memcpy(buf, edid + start, len);
+	r = 0;
+
+cleanup:
+	kfree(edid);
+
+	return r;
+}
+
  static void connector_bad_edid(struct drm_connector *connector,
  			       const struct edid *edid, int num_blocks)
  {
@@ -2621,7 +2678,8 @@ EXPORT_SYMBOL(drm_probe_ddc);
   * @connector: connector we're probing
   * @adapter: I2C adapter to use for DDC
   *
- * Poke the given I2C channel to grab EDID data if possible.  If found,
+ * If the connector allows it, try to fetch EDID data using ACPI. If not found
+ * poke the given I2C channel to grab EDID data if possible.  If found,
   * attach it to the connector.
   *
   * Return: Pointer to valid EDID or NULL if we couldn't find any.
@@ -2629,20 +2687,50 @@ EXPORT_SYMBOL(drm_probe_ddc);
  struct edid *drm_get_edid(struct drm_connector *connector,
  			  struct i2c_adapter *adapter)
  {
-	struct edid *edid;
+	struct edid *edid = NULL;
 
  	if (connector->force == DRM_FORCE_OFF)
  		return NULL;
 

drivers/gpu/drm/drm_edid.c EXPORT_SYMBOL(drm_probe_ddc); · line 2702

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +8 -2
-	if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
-		return NULL;
+	if (connector->acpi_edid_allowed)
+		edid = _drm_do_get_edid(connector, drm_do_probe_acpi_edid, connector, NULL);
+
+	if (!edid) {
+		if (connector->force == DRM_FORCE_UNSPECIFIED && !drm_probe_ddc(adapter))
+			return NULL;
+		edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL);
+	}

Hmm. So do you want the presence of ACPI EDID to determine whether the display is there or not?

Quoted 9 lines

Note how the override and firmware EDID mechanisms only override the EDID *contents*. They are orthogonal from connector forcing. So you can override the EDID, but still rely on the DDC probe to determine if the display is there.

The question is, how likely is it that the ACPI EDID is used not just because the actual EDID is bogus, but also because the display just doesn't respond to DDC at all?

The cases that prompted this the panel "responds" to DDC fine, but the EDID data doesn't match what is expected to be used which leads to other unexpected functional problems.

Quoted 3 lines

If possible, I'd like ACPI EDID to follow the override/firmware EDID semantics on this.

So basically probe with DDC but if the driver specifies on the connector to use ACPI if present then try that (similar to how override is only used if specified by the user)?

Quoted 62 lines
Quoted 13 lines
drivers/gpu/drm/drm_edid.c +6 -1
-	edid = _drm_do_get_edid(connector, drm_do_probe_ddc_edid, adapter, NULL);
  	drm_connector_update_edid_property(connector, edid);
  	return edid;
  }
  EXPORT_SYMBOL(drm_get_edid);
 
+/**
+ * drm_edid_read_acpi - get EDID data, if available
+ * @connector: connector we're probing
+ *
+ * Use the BIOS to attempt to grab EDID data if possible.
+ *

drivers/gpu/drm/drm_edid.c EXPORT_SYMBOL(drm_probe_ddc); · line 2724

Quoted 10 lines
drivers/gpu/drm/drm_edid.c +10 -0
+ * The returned pointer must be freed using drm_edid_free().
+ *
+ * Return: Pointer to valid EDID or NULL if we couldn't find any.
+ */
+const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector)
+{
+	const struct drm_edid *drm_edid;
+
+	if (connector->force == DRM_FORCE_OFF)
+		return NULL;

If the caller handled all the connector->force stuff, this could be dropped.

Quoted 35 lines
drivers/gpu/drm/drm_edid.c +14 -2
+
+	drm_edid = drm_edid_read_custom(connector, drm_do_probe_acpi_edid, connector);
+
+	/* Note: Do *not* call connector updates here. */
+
+	return drm_edid;
+}
+EXPORT_SYMBOL(drm_edid_read_acpi);
+
  /**
   * drm_edid_read_custom - Read EDID data using given EDID block read function
   * @connector: Connector to use
@@ -2727,10 +2815,11 @@ const struct drm_edid *drm_edid_read_ddc(struct drm_connector *connector,
  EXPORT_SYMBOL(drm_edid_read_ddc);
 
  /**
- * drm_edid_read - Read EDID data using connector's I2C adapter
+ * drm_edid_read - Read EDID data using BIOS or connector's I2C adapter
   * @connector: Connector to use
   *
- * Read EDID using the connector's I2C adapter.
+ * Read EDID from BIOS if allowed by connector or by using the connector's
+ * I2C adapter.
   *
   * The EDID may be overridden using debugfs override_edid or firmware EDID
   * (drm_edid_load_firmware() and drm.edid_firmware parameter), in this priority
@@ -2742,10 +2831,18 @@ EXPORT_SYMBOL(drm_edid_read_ddc);
   */
  const struct drm_edid *drm_edid_read(struct drm_connector *connector)
  {
+	const struct drm_edid *drm_edid = NULL;
+
  	if (drm_WARN_ON(connector->dev, !connector->ddc))
  		return NULL;
 
Quoted 10 lines

drivers/gpu/drm/drm_edid.c EXPORT_SYMBOL(drm_edid_read_ddc); · line 2843

Quoted 6 lines
drivers/gpu/drm/drm_edid.c +5 -1
-	return drm_edid_read_ddc(connector, connector->ddc);
+	if (connector->acpi_edid_allowed)
+		drm_edid = drm_edid_read_acpi(connector);
+
+	if (!drm_edid)
+		drm_edid = drm_edid_read_ddc(connector, connector->ddc);

This should be in drm_edid_read_ddc() not drm_edid_read(). Please let's not make the two behave any different. It would be really weird if one had an ACPI check and the other not.

OK, I'll move things around.

Quoted 35 lines
Quoted 34 lines
drivers/gpu/drm/drm_edid.c +2 -0
+
+	return drm_edid;
  }
  EXPORT_SYMBOL(drm_edid_read);
 
include/drm/drm_connector.h +6 -0
index fe88d7fc6b8f..74ed47f37a69 100644
@@ -1886,6 +1886,12 @@ struct drm_connector {
 
  	/** @hdr_sink_metadata: HDR Metadata Information read from sink */
  	struct hdr_sink_metadata hdr_sink_metadata;
+
+	/**
+	 * @acpi_edid_allowed: Get the EDID from the BIOS, if available.
+	 * This is only applicable to eDP and LVDS displays.
+	 */
+	bool acpi_edid_allowed;
  };
 
  #define obj_to_connector(x) container_of(x, struct drm_connector, base)
include/drm/drm_edid.h +1 -0
index 518d1b8106c7..38b5e1b5c773 100644
@@ -463,5 +463,6 @@ bool drm_edid_is_digital(const struct drm_edid *drm_edid);
 
  const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid,
  				  int ext_id, int *ext_index);
+const struct drm_edid *drm_edid_read_acpi(struct drm_connector *connector);
 
  #endif /* __DRM_EDID_H__ */
#6 lore raw

PATCH v5 2/3 drm/amd: Fetch the EDID from _DDC if available for eDP

In reply to Mario Limonciello

Some manufacturers have intentionally put an EDID that differs from the EDID on the internal panel on laptops.

Attempt to fetch this EDID if it exists and prefer it over the EDID that is provided by the panel. If a user prefers to use the EDID from the panel, offer a module parameter that would disable this.

---
v4->v5:
* rebase on v5 changes

---
 drivers/gpu/drm/amd/amdgpu/amdgpu.h                       | 1 +
 drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c            | 3 +++
 drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c                   | 8 ++++++++
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c         | 4 +++-
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 2 ++
 5 files changed, 17 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu.h +1 -0
index 543ed9de5a6d..399885251714 100644
@@ -217,6 +217,7 @@ extern int amdgpu_smartshift_bias;
 extern int amdgpu_use_xgmi_p2p;
 extern int amdgpu_mtype_local;
 extern bool enforce_isolation;
+extern bool acpi_edid;
 #ifdef CONFIG_HSA_AMD
 extern int sched_policy;
 extern bool debug_evictions;
drivers/gpu/drm/amd/amdgpu/amdgpu_connectors.c +3 -0
index 9caba10315a8..9165a199ac9b 100644
@@ -281,6 +281,9 @@ static void amdgpu_connector_get_edid(struct drm_connector *connector)
 	if (amdgpu_connector->edid)
 		return;
 
+	/* if the BIOS specifies the EDID via _DDC, prefer this */
+	connector->acpi_edid_allowed = acpi_edid;
+
 	/* on hw with routers, select right port */
 	if (amdgpu_connector->router.ddc_valid)
 		amdgpu_i2c_router_select_ddc_port(amdgpu_connector);
drivers/gpu/drm/amd/amdgpu/amdgpu_drv.c +8 -0
index edc042db4ea8..123f1128d14e 100644
@@ -166,6 +166,7 @@ uint amdgpu_sdma_phase_quantum = 32;
 char *amdgpu_disable_cu;
 char *amdgpu_virtual_display;
 bool enforce_isolation;
+bool acpi_edid = true;
 /*
  * OverDrive(bit 14) disabled by default
  * GFX DCS(bit 19) disabled by default
@@ -991,6 +992,13 @@ MODULE_PARM_DESC(wbrf,
 	"Enable Wifi RFI interference mitigation (0 = disabled, 1 = enabled, -1 = auto(default)");
 module_param_named(wbrf, amdgpu_wbrf, int, 0444);
 
+/**
+ * DOC: acpi_edid (bool)
+ * Try to fetch EDID for eDP display from BIOS using ACPI _DDC method.
+ */
+module_param(acpi_edid, bool, 0444);
+MODULE_PARM_DESC(acpi_edid, "Fetch EDID for eDP display from BIOS");
+
 /* These devices are not supported by amdgpu.
  * They are supported by the mach64, r128, radeon drivers
  */
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -1
index ed90fc8fee9f..0b3a19d3d43a 100644
@@ -6619,8 +6619,10 @@ static void amdgpu_dm_connector_funcs_force(struct drm_connector *connector)
 	 * Note: drm_get_edid gets edid in the following order:
 	 * 1) override EDID if set via edid_override debugfs,
 	 * 2) firmware EDID if set via edid_firmware module parameter
-	 * 3) regular DDC read.
+	 * 3) ACPI EDID if allowed via module parameter
+	 * 4) regular DDC read.
 	 */
+	connector->acpi_edid_allowed = acpi_edid;
 	edid = drm_get_edid(connector, &amdgpu_connector->ddc_bus->aux.ddc);
 	if (!edid) {
 		DRM_ERROR("No EDID found on connector: %s.\n", connector->name);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +2 -0
index 85b7f58a7f35..d570a1b6141b 100644
@@ -910,6 +910,8 @@ enum dc_edid_status dm_helpers_read_local_edid(
 	 * do check sum and retry to make sure read correct edid.
 	 */
 	do {
+		/* prefer ACPI over panel for eDP */
+		connector->acpi_edid_allowed = acpi_edid;
 
 		edid = drm_get_edid(&aconnector->base, ddc);
 
Signature · 1 line
2.34.1
#7 lore raw

PATCH v5 3/3 drm/nouveau: Use drm_edid_read_acpi() helper

In reply to Mario Limonciello

Rather than inventing a wrapper to acpi_video_get_edid() use the one provided by drm. This fixes two problems:
1. A memory leak that the memory provided by the ACPI call was never freed.
2. Validation of the BIOS provided blob.

Convert the usage in nouveau_connector_detect_lvds() to use struct drm_edid at the same time.

---
v1->v2:
* New patch
v3->v4:
* Rebase on v4 changes
v4->v5:
* Rebase on v5 changes

---
 drivers/gpu/drm/nouveau/nouveau_acpi.c      | 27 ----------------
 drivers/gpu/drm/nouveau/nouveau_acpi.h      |  2 --
 drivers/gpu/drm/nouveau/nouveau_connector.c | 35 +++++++++------------
 3 files changed, 14 insertions(+), 50 deletions(-)
drivers/gpu/drm/nouveau/nouveau_acpi.c +0 -27
index 8f0c69aad248..de9daafb3fbb 100644
@@ -360,33 +360,6 @@ void nouveau_unregister_dsm_handler(void) {}
 void nouveau_switcheroo_optimus_dsm(void) {}
 #endif
 
-void *
-nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector)
-{
-	struct acpi_device *acpidev;
-	int type, ret;
-	void *edid;
-
-	switch (connector->connector_type) {
-	case DRM_MODE_CONNECTOR_LVDS:
-	case DRM_MODE_CONNECTOR_eDP:
-		type = ACPI_VIDEO_DISPLAY_LCD;
-		break;
-	default:
-		return NULL;
-	}
-
-	acpidev = ACPI_COMPANION(dev->dev);
-	if (!acpidev)
-		return NULL;
-
-	ret = acpi_video_get_edid(acpidev, type, -1, &edid);
-	if (ret < 0)
-		return NULL;
-
-	return kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
-}
-
 bool nouveau_acpi_video_backlight_use_native(void)
 {
 	return acpi_video_backlight_use_native();
drivers/gpu/drm/nouveau/nouveau_acpi.h +0 -2
index e39dd8b94b8b..6a3def8e6cca 100644
@@ -10,7 +10,6 @@ bool nouveau_is_v1_dsm(void);
 void nouveau_register_dsm_handler(void);
 void nouveau_unregister_dsm_handler(void);
 void nouveau_switcheroo_optimus_dsm(void);
-void *nouveau_acpi_edid(struct drm_device *, struct drm_connector *);
 bool nouveau_acpi_video_backlight_use_native(void);
 void nouveau_acpi_video_register_backlight(void);
 #else
@@ -19,7 +18,6 @@ static inline bool nouveau_is_v1_dsm(void) { return false; };
 static inline void nouveau_register_dsm_handler(void) {}
 static inline void nouveau_unregister_dsm_handler(void) {}
 static inline void nouveau_switcheroo_optimus_dsm(void) {}
-static inline void *nouveau_acpi_edid(struct drm_device *dev, struct drm_connector *connector) { return NULL; }
 static inline bool nouveau_acpi_video_backlight_use_native(void) { return true; }
 static inline void nouveau_acpi_video_register_backlight(void) {}
 #endif
drivers/gpu/drm/nouveau/nouveau_connector.c +14 -21
index 856b3ef5edb8..492035dc8453 100644
@@ -687,22 +687,13 @@ nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
 	struct nouveau_drm *drm = nouveau_drm(dev);
 	struct nouveau_connector *nv_connector = nouveau_connector(connector);
 	struct nouveau_encoder *nv_encoder = NULL;
-	struct edid *edid = NULL;
+	const struct drm_edid *drm_edid = NULL;
 	enum drm_connector_status status = connector_status_disconnected;
 
 	nv_encoder = find_encoder(connector, DCB_OUTPUT_LVDS);
 	if (!nv_encoder)
 		goto out;
 
-	/* Try retrieving EDID via DDC */
-	if (!drm->vbios.fp_no_ddc) {
-		status = nouveau_connector_detect(connector, force);
-		if (status == connector_status_connected) {
-			edid = nv_connector->edid;
-			goto out;
-		}
-	}
-
 	/* On some laptops (Sony, i'm looking at you) there appears to
 	 * be no direct way of accessing the panel's EDID.  The only
 	 * option available to us appears to be to ask ACPI for help..
@@ -712,10 +703,14 @@ nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
 	 * the nouveau decides an entry in the VBIOS FP mode table is
 	 * valid - it's not (rh#613284)
 	 */
-	if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
-		edid = nouveau_acpi_edid(dev, connector);
-		if (edid) {
-			status = connector_status_connected;
+	if (nv_encoder->dcb->lvdsconf.use_acpi_for_edid)
+		connector->acpi_edid_allowed = true;
+
+	/* Try retrieving EDID via BIOS or DDC */
+	if (!drm->vbios.fp_no_ddc || nv_encoder->dcb->lvdsconf.use_acpi_for_edid) {
+		status = nouveau_connector_detect(connector, force);
+		if (status == connector_status_connected) {
+			drm_edid = drm_edid_alloc(nv_connector->edid, EDID_LENGTH);
 			goto out;
 		}
 	}
@@ -734,12 +729,9 @@ nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
 	 * stored for the panel stored in them.
 	 */
 	if (!drm->vbios.fp_no_ddc) {
-		edid = (struct edid *)nouveau_bios_embedded_edid(dev);
-		if (edid) {
-			edid = kmemdup(edid, EDID_LENGTH, GFP_KERNEL);
-			if (edid)
-				status = connector_status_connected;
-		}
+		drm_edid = drm_edid_alloc(nouveau_bios_embedded_edid(dev), EDID_LENGTH);
+		if (drm_edid)
+			status = connector_status_connected;
 	}
 
 out:
@@ -750,7 +742,8 @@ nouveau_connector_detect_lvds(struct drm_connector *connector, bool force)
 		status = connector_status_unknown;
 #endif
 
-	nouveau_connector_set_edid(nv_connector, edid);
+	drm_edid_connector_update(connector, drm_edid);
+	drm_edid_free(drm_edid);
 	if (nv_encoder)
 		nouveau_connector_set_encoder(connector, nv_encoder);
 	return status;
Signature · 1 line
2.34.1