All of lore.kernel.org
 help / color / mirror / Atom feed
From: Egbert Eich <eich@suse.com>
To: dri-devel@lists.freedesktop.org
Cc: Egbert Eich <eich@suse.com>, tiwai@suse.com
Subject: [PATCH v3] DRM/KMS/EDID: Cache EDID blobs with extensions (v3)
Date: Thu, 22 Nov 2012 09:43:13 -0500	[thread overview]
Message-ID: <1353595393-23118-1-git-send-email-eich@suse.com> (raw)
In-Reply-To: <1353579788-30637-14-git-send-email-eich@suse.com>

According the the VESA specs there can be up to 254 EEDID extension blocks.
Since we may read the EDID (including extensions) in 10 second intervals to
probe for display hotplugging (at least in cases where no hardware hotplug
detection exists) and I2C transfer is rather slow we may end up consuming
a considerable amount on CPU time for just that.
This patch caches the EDID block if it contains at least one extension.
To determine if the blocks match we only tranfer the base block, on a match
we use the cached data.

V2: Use kmemdup() instead of a kmalloc()/memcpy() combo,
    erase cache when reading a 'firmware'-supplied EDID or on error.
V3: Uncache when only one extension block is found. This chunk had
    accidentally gone into the next patch of the series. Found by
    Ville Syrjälä <ville.syrjala@linux.intel.com>.

Signed-off-by: Egbert Eich <eich@suse.com>
---
 drivers/gpu/drm/drm_crtc.c |    1 +
 drivers/gpu/drm/drm_edid.c |   60 +++++++++++++++++++++++++++++++++++++------
 include/drm/drm_crtc.h     |    1 +
 include/drm/drm_edid.h     |    1 +
 4 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index 3533609..e283355 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -598,6 +598,7 @@ void drm_connector_cleanup(struct drm_connector *connector)
 		drm_mode_remove(connector, mode);
 
 	mutex_lock(&dev->mode_config.mutex);
+	drm_cache_edid(connector, NULL);
 	drm_mode_object_put(dev, &connector->base);
 	list_del(&connector->head);
 	dev->mode_config.num_connector--;
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index e269739..dd0df60 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -419,6 +419,38 @@ fixup_edid(u8 **blockp, int valid_extensions)
 	}
 }
 
+static bool
+compare_get_edid_from_cache(struct drm_connector *connector, struct edid **edidp)
+{
+	if (connector->edid_cache &&
+	    connector->edid_cache->prod_code[0] == (*edidp)->prod_code[0] &&
+	    connector->edid_cache->prod_code[1] == (*edidp)->prod_code[1] &&
+	    connector->edid_cache->serial == (*edidp)->serial &&
+	    connector->edid_cache->input == (*edidp)->input) {
+		int size = (connector->edid_cache->extensions + 1) * EDID_LENGTH;
+		struct edid *new = kmemdup(connector->edid_cache, size, GFP_KERNEL);
+		if (!new)
+			return false;
+		DRM_DEBUG_KMS("Got EDID for %s from cache.\n", drm_get_connector_name(connector));
+		kfree(*edidp);
+		*edidp = new;
+		return true;
+	}
+	return false;
+}
+
+void
+drm_cache_edid(struct drm_connector *connector, struct edid *edid)
+{
+	struct edid *new = NULL;
+	kfree(connector->edid_cache);
+	if (edid) {
+		int size = (edid->extensions + 1) * EDID_LENGTH;
+		new = kmemdup(edid, size, GFP_KERNEL);
+	}
+	connector->edid_cache = new;
+}
+
 static u8 *
 drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
 {
@@ -429,35 +461,41 @@ drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
 #ifdef CONFIG_DRM_LOAD_EDID_FIRMWARE
 	/* check if the user has specified a 'firmware' EDID file */
 	block = (u8 *)drm_load_edid_firmware(connector);
-	if (block)
+	if (block) {
+		drm_cache_edid(connector, NULL);
 		return block;
+	}
 #endif
 
 	if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL)
-		return NULL;
+		goto error;
 
 	/* base block fetch */
 	for (i = 0; i < 4; i++) {
 		if (drm_do_probe_ddc_edid(adapter, block, 0, EDID_LENGTH))
-			goto out;
+			goto error_free;
 		if (drm_edid_block_valid(block, 0, print_bad_edid))
 			break;
 		if (i == 0 && drm_edid_is_zero(block, EDID_LENGTH)) {
 			connector->null_edid_counter++;
-			goto carp;
+			goto error_carp;
 		}
 	}
 	if (i == 4)
-		goto carp;
+		goto error_carp;
 
-	/* if there's no extensions, we're done */
+	/* if there are no extensions, we're done - don't bother caching */
 	if (block[EDID_EXTENSION_FLAG_OFFSET] == 0)
-		return block;
+		goto done;
 
 	/* don't expect extension blocks in EDID Versions < 1.3: return base block with correct extension flag */
 	if (block[EDID_VERSION_MINOR_OFFSET] < 3)
 		goto done_fix_extension_count;
 
+	/* see if EDID is in the cache - no need to read all extension blocks */
+	if (compare_get_edid_from_cache(connector, (struct edid **)&block))
+		return block;
+
 	new = krealloc(block, (block[EDID_EXTENSION_FLAG_OFFSET] + 1) * EDID_LENGTH, GFP_KERNEL);
 	if (!new) {
 		dev_warn(connector->dev->dev, "%s: cannot allocate memory for %d EDID blocks: truncating.\n",
@@ -497,18 +535,22 @@ drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter)
 
 done_fix_extension_count:
 	fixup_edid(&block, valid_extensions);
+done:
+	drm_cache_edid(connector, (valid_extensions > 0) ? (struct edid *)block : NULL);
 
 	return block;
 
-carp:
+error_carp:
 	if (print_bad_edid) {
 		dev_warn(connector->dev->dev, "%s: EDID block %d invalid.\n",
 			 drm_get_connector_name(connector), j);
 	}
 	connector->bad_edid_counter++;
 
-out:
+error_free:
 	kfree(block);
+error:
+	drm_cache_edid(connector, NULL);
 	return NULL;
 }
 
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index 49dd8c2..6a1054c 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -601,6 +601,7 @@ struct drm_connector {
 	struct drm_encoder *encoder; /* currently active encoder */
 
 	/* EDID bits */
+	struct edid *edid_cache;
 	uint8_t eld[MAX_ELD_BYTES];
 	bool dvi_dual;
 	int max_tmds_clock;	/* in MHz */
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index 53c619c..c880510 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -256,5 +256,6 @@ struct drm_connector *drm_select_eld(struct drm_encoder *encoder,
 struct edid *drm_load_edid_firmware(struct drm_connector *connector);
 #endif
 int drm_validate_edid_blob(struct drm_connector *connector, u8 **blockp, int len);
+void drm_cache_edid(struct drm_connector *connector, struct edid *edid);
 
 #endif /* __DRM_EDID_H__ */
-- 
1.7.7

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2012-11-22 15:10 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-19 20:23 [PATCH 00/17] DRM/KMS/EDID: Various EDID handling related fixes Egbert Eich
2012-11-19 20:23 ` [PATCH 01/17] DRM/KMS/EDID: Mask out Segment Bits when calculating Offset Egbert Eich
2012-11-19 20:23 ` [PATCH 03/17] DRM/KMS/EDID: Return Base EDID block if reading EEDID Blocks fails Egbert Eich
2012-11-19 20:23 ` [PATCH 04/17] DRM/KMS/EDID: Test EDDC if EDID announces more than one Extension Block Egbert Eich
2012-11-19 20:23 ` [PATCH 05/17] DRM/KMS/EDID: Fix up EEDID Map Blocks if Extension block count has changed Egbert Eich
2012-11-20  8:13   ` Takashi Iwai
2012-11-19 20:23 ` [PATCH 06/17] DRM/exynos: Fix Memory Leak: free EDID blcok returned by drm_get_edid() Egbert Eich
2012-11-20  4:17   ` Inki Dae
2012-11-20  9:30     ` [PATCH] drm/exynos: fix memory leak: free EDID block Egbert Eich
2012-11-20 19:58       ` Sean Paul
2012-11-20 20:29         ` Egbert Eich
2012-11-20 21:18           ` Sean Paul
2012-12-14 10:24         ` Jani Nikula
2012-11-21  3:50       ` Inki Dae
2012-11-19 20:23 ` [PATCH 07/17] DRM/KMS/EDID: Move drm_edid_load.o to drm.ko Egbert Eich
2012-11-20  8:26   ` Takashi Iwai
2012-11-19 20:23 ` [PATCH 08/17] DRM/KMS/EDID: Use Extension Block Fixup Code also for 'firmware' EDID Egbert Eich
2012-11-20  8:21   ` Takashi Iwai
2012-11-19 20:23 ` [PATCH 09/17] DRM/KMS/EDID: Feed 'firmware' supplied EDID blocks whenever the EDID is read Egbert Eich
2012-11-19 20:23 ` [PATCH 10/17] DRM/KMS/EDID: Cache EDID blobs with extensions Egbert Eich
2012-11-20  8:29   ` Takashi Iwai
2012-11-19 20:23 ` [PATCH 11/17] DRM/KMS/EDID: Avoid failing on krealloc on EDID blocks Egbert Eich
2012-11-19 20:23 ` [PATCH 12/17] DRM/KMS/EDID: Consolidate EDID Error Handling Egbert Eich
2012-11-19 20:23 ` [PATCH 13/17] DRM/KMS/EDID: Allow for multiple Connectors when specifying 'firmware'-EDID Files Egbert Eich
2012-11-20  8:38   ` Takashi Iwai
2012-11-19 20:23 ` [PATCH 14/17] DRM/KMS/ast: Include drm_edid.h in file using drm_get_edid() Egbert Eich
2012-11-19 20:23 ` [PATCH 15/17] DRM/KMS/gma500: " Egbert Eich
2012-11-19 20:23 ` [PATCH 16/17] DRM/KMS/mgag200: " Egbert Eich
2012-11-19 20:23 ` [PATCH 17/17] DRM/KMS/EDID: Move EDID related Functions to drm_edid.h Egbert Eich
2012-11-22 10:22 ` [PATCH v2 00/18] DRM/KMS/EDID: Various EDID handling related fixes Egbert Eich
2012-11-22 10:22   ` [PATCH v2 01/18] DRM/KMS/EDID: Mask out Segment Bits when calculating Offset Egbert Eich
2012-11-22 10:22   ` [PATCH v2 02/18] DRM/KMS/EDID: 0x7e -> EDID_EXTENSION_FLAG_OFFSET (v2) Egbert Eich
2012-11-22 10:22   ` [PATCH v2 03/18] DRM/KMS/EDID: Return Base EDID block if reading EEDID Blocks fails (v2) Egbert Eich
2012-11-22 10:22   ` [PATCH v2 04/18] DRM/KMS/EDID: Don't fail when failing to allocate memory for EDID extensions Egbert Eich
2012-11-22 10:22   ` [PATCH v2 05/18] DRM/KMS/EDID: Test EDDC if EDID announces more than one Extension Block (v2) Egbert Eich
2012-11-22 11:20     ` Ville Syrjälä
2012-11-22 12:07       ` Egbert Eich
2012-11-22 12:29         ` Ville Syrjälä
2012-11-22 13:18           ` Egbert Eich
2012-11-22 14:39     ` [PATCH v3] DRM/KMS/EDID: Test EDDC if EDID announces more than one Extension Block (v3) Egbert Eich
2012-11-22 10:22   ` [PATCH v2 06/18] DRM/KMS/EDID: Don't expect extension blocks for EDID Versions < 1.3 Egbert Eich
2012-11-22 10:22   ` [PATCH v2 07/18] DRM/KMS/EDID: Don't reallocate EDID blob when size has shrunk Egbert Eich
2012-11-22 10:22   ` [PATCH v2 08/18] DRM/KMS/EDID: Fix up EEDID Map Blogs if Extension Block Count has changed (v2) Egbert Eich
2012-11-22 10:22   ` [PATCH v2 09/18] DRM/KMS/EDID: Move drm_edid_load.o to drm.ko (v2) Egbert Eich
2012-11-22 10:23   ` [PATCH v2 10/18] DRM/KMS/EDID: Feed 'firmware' supplied EDID blocks whenever the EDID is read (v2) Egbert Eich
2012-11-22 10:23   ` [PATCH v2 11/18] DRM/KMS/EDID: Allow for multiple Connectors when specifying 'firmware'-EDID Files (v2) Egbert Eich
2012-11-22 10:23   ` [PATCH v2 12/18] DRM/KMS/EDID: Use Extension Block Fixup Code also for 'firmware' EDID (v2) Egbert Eich
2012-11-22 10:23   ` [PATCH v2 13/18] DRM/KMS/EDID: Cache EDID blobs with extensions (v2) Egbert Eich
2012-11-22 14:14     ` Ville Syrjälä
2012-11-22 14:29       ` Egbert Eich
2012-11-22 14:43     ` Egbert Eich [this message]
2012-11-22 10:23   ` [PATCH v2 14/18] DRM/KMS/EDID: Consolidate EDID Error Handling (v2) Egbert Eich
2012-11-22 14:44     ` [PATCH v3] DRM/KMS/EDID: Consolidate EDID Error Handling (v3) Egbert Eich
2012-11-22 16:09       ` Ville Syrjälä
2012-11-22 18:28         ` Egbert Eich
2012-11-22 18:54           ` Ville Syrjälä
2012-11-22 20:01             ` Egbert Eich
2012-11-22 18:57       ` [PATCH v4] DRM/KMS/EDID: Consolidate EDID Error Handling (v4) Egbert Eich
2012-11-22 20:29         ` [PATCH v5] DRM/KMS/EDID: Consolidate EDID Error Handling (v5) Egbert Eich
2012-11-22 10:23   ` [PATCH v2 15/18] DRM/KMS/ast: Include drm_edid.h in file using drm_get_edid() Egbert Eich
2012-11-22 10:23   ` [PATCH v2 16/18] DRM/KMS/gma500: " Egbert Eich
2012-11-22 10:23   ` [PATCH v2 17/18] DRM/KMS/mgag200: " Egbert Eich
2012-11-22 10:23   ` [PATCH v2 18/18] DRM/KMS/EDID: Move EDID related Functions to drm_edid.h Egbert Eich
2012-11-22 19:00 ` [PATCH v4] DRM/KMS/EDID: Move EDID related Functions to drm_edid.h (v2) Egbert Eich

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1353595393-23118-1-git-send-email-eich@suse.com \
    --to=eich@suse.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.