Support to parse multiple CEA extension blocks and HF-EEODB to extend drm edid driver's capability.
v4: add one more patch to support HF-SCDB v5: HF-SCDB and HF-VSDBS carry the same SCDS data. Reuse drm_parse_hdmi_forum_vsdb() to parse this packet. v6: save proper extension block index if CTA data information was found in DispalyID block. v7: using different parameters to store CEA and DisplayID block index. configure DisplayID extansion block index before search available DisplayID block.
Lee Shawn C (5): drm/edid: seek for available CEA and DisplayID block from specific EDID block index drm/edid: parse multiple CEA extension block drm/edid: read HF-EEODB ext block drm/edid: parse HF-EEODB CEA extension block drm/edid: check for HF-SCDB block
drivers/gpu/drm/drm_connector.c | 8 +- drivers/gpu/drm/drm_displayid.c | 15 ++- drivers/gpu/drm/drm_edid.c | 216 +++++++++++++++++++++++++------- include/drm/drm_displayid.h | 4 +- include/drm/drm_edid.h | 3 +- 5 files changed, 194 insertions(+), 52 deletions(-)
drm_find_cea_extension() always look for a top level CEA block. Pass ext_index from caller then this function to search next available CEA ext block from a specific EDID block pointer.
v2: save proper extension block index if CTA data information was found in DispalyID block. v3: using different parameters to store CEA and DisplayID block index. configure DisplayID extansion block index before search available DisplayID block.
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com --- drivers/gpu/drm/drm_displayid.c | 10 +++++-- drivers/gpu/drm/drm_edid.c | 53 ++++++++++++++++++--------------- include/drm/drm_displayid.h | 4 +-- 3 files changed, 39 insertions(+), 28 deletions(-)
diff --git a/drivers/gpu/drm/drm_displayid.c b/drivers/gpu/drm/drm_displayid.c index 32da557b960f..31c3e6d7d549 100644 --- a/drivers/gpu/drm/drm_displayid.c +++ b/drivers/gpu/drm/drm_displayid.c @@ -59,11 +59,14 @@ static const u8 *drm_find_displayid_extension(const struct edid *edid, }
void displayid_iter_edid_begin(const struct edid *edid, - struct displayid_iter *iter) + struct displayid_iter *iter, int *ext_index) { memset(iter, 0, sizeof(*iter));
iter->edid = edid; + + if (ext_index) + iter->ext_index = *ext_index; }
static const struct displayid_block * @@ -126,7 +129,10 @@ __displayid_iter_next(struct displayid_iter *iter) } }
-void displayid_iter_end(struct displayid_iter *iter) +void displayid_iter_end(struct displayid_iter *iter, int *ext_index) { + if (ext_index) + *ext_index = iter->ext_index; + memset(iter, 0, sizeof(*iter)); } diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 561f53831e29..78c415aa6889 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -3353,28 +3353,27 @@ const u8 *drm_find_edid_extension(const struct edid *edid, return edid_ext; }
-static const u8 *drm_find_cea_extension(const struct edid *edid) +static const u8 *drm_find_cea_extension(const struct edid *edid, + int *cea_ext_index, int *displayid_ext_index) { const struct displayid_block *block; struct displayid_iter iter; const u8 *cea; - int ext_index = 0;
- /* Look for a top level CEA extension block */ - /* FIXME: make callers iterate through multiple CEA ext blocks? */ - cea = drm_find_edid_extension(edid, CEA_EXT, &ext_index); + /* Look for a CEA extension block from ext_index */ + cea = drm_find_edid_extension(edid, CEA_EXT, cea_ext_index); if (cea) return cea;
/* CEA blocks can also be found embedded in a DisplayID block */ - displayid_iter_edid_begin(edid, &iter); + displayid_iter_edid_begin(edid, &iter, displayid_ext_index); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_CTA) { cea = (const u8 *)block; break; } } - displayid_iter_end(&iter); + displayid_iter_end(&iter, displayid_ext_index);
return cea; } @@ -3643,10 +3642,10 @@ add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid) struct drm_device *dev = connector->dev; struct drm_display_mode *mode, *tmp; LIST_HEAD(list); - int modes = 0; + int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
/* Don't add CEA modes if the CEA extension block is missing */ - if (!drm_find_cea_extension(edid)) + if (!drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index)) return 0;
/* @@ -4321,11 +4320,11 @@ static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, static int add_cea_modes(struct drm_connector *connector, struct edid *edid) { - const u8 *cea = drm_find_cea_extension(edid); - const u8 *db, *hdmi = NULL, *video = NULL; + const u8 *cea, *db, *hdmi = NULL, *video = NULL; u8 dbl, hdmi_len, video_len = 0; - int modes = 0; + int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
+ cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (cea && cea_revision(cea) >= 3) { int i, start, end;
@@ -4563,6 +4562,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) const u8 *cea; const u8 *db; int total_sad_count = 0; + int cea_ext_index = 0, displayid_ext_index = 0; int mnl; int dbl;
@@ -4571,7 +4571,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) if (!edid) return;
- cea = drm_find_cea_extension(edid); + cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("ELD: no CEA Extension found\n"); return; @@ -4657,9 +4657,10 @@ int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads) { int count = 0; int i, start, end, dbl; + int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid); + cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0; @@ -4719,9 +4720,10 @@ int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb) { int count = 0; int i, start, end, dbl; + int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid); + cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0; @@ -4815,8 +4817,9 @@ bool drm_detect_hdmi_monitor(struct edid *edid) const u8 *edid_ext; int i; int start_offset, end_offset; + int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid); + edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) return false;
@@ -4854,8 +4857,9 @@ bool drm_detect_monitor_audio(struct edid *edid) int i, j; bool has_audio = false; int start_offset, end_offset; + int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid); + edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) goto end;
@@ -5178,8 +5182,9 @@ static void drm_parse_cea_ext(struct drm_connector *connector, struct drm_display_info *info = &connector->display_info; const u8 *edid_ext; int i, start, end; + int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid); + edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) return;
@@ -5311,12 +5316,12 @@ static void drm_update_mso(struct drm_connector *connector, const struct edid *e const struct displayid_block *block; struct displayid_iter iter;
- displayid_iter_edid_begin(edid, &iter); + displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_2_VENDOR_SPECIFIC) drm_parse_vesa_mso_data(connector, block); } - displayid_iter_end(&iter); + displayid_iter_end(&iter, NULL); }
/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset @@ -5516,13 +5521,13 @@ static int add_displayid_detailed_modes(struct drm_connector *connector, struct displayid_iter iter; int num_modes = 0;
- displayid_iter_edid_begin(edid, &iter); + displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TYPE_1_DETAILED_TIMING || block->tag == DATA_BLOCK_2_TYPE_7_DETAILED_TIMING) num_modes += add_displayid_detailed_1_modes(connector, block); } - displayid_iter_end(&iter); + displayid_iter_end(&iter, NULL);
return num_modes; } @@ -6164,12 +6169,12 @@ void drm_update_tile_info(struct drm_connector *connector,
connector->has_tile = false;
- displayid_iter_edid_begin(edid, &iter); + displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TILED_DISPLAY) drm_parse_tiled_block(connector, block); } - displayid_iter_end(&iter); + displayid_iter_end(&iter, NULL);
if (!connector->has_tile && connector->tile_group) { drm_mode_put_tile_group(connector->dev, connector->tile_group); diff --git a/include/drm/drm_displayid.h b/include/drm/drm_displayid.h index 7ffbd9f7bfc7..15442a161c11 100644 --- a/include/drm/drm_displayid.h +++ b/include/drm/drm_displayid.h @@ -150,11 +150,11 @@ struct displayid_iter { };
void displayid_iter_edid_begin(const struct edid *edid, - struct displayid_iter *iter); + struct displayid_iter *iter, int *ext_index); const struct displayid_block * __displayid_iter_next(struct displayid_iter *iter); #define displayid_iter_for_each(__block, __iter) \ while (((__block) = __displayid_iter_next(__iter))) -void displayid_iter_end(struct displayid_iter *iter); +void displayid_iter_end(struct displayid_iter *iter, int *ext_index);
#endif
On Sun, 13 Mar 2022, Lee Shawn C shawn.c.lee@intel.com wrote:
drm_find_cea_extension() always look for a top level CEA block. Pass ext_index from caller then this function to search next available CEA ext block from a specific EDID block pointer.
v2: save proper extension block index if CTA data information was found in DispalyID block. v3: using different parameters to store CEA and DisplayID block index. configure DisplayID extansion block index before search available DisplayID block.
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com
drivers/gpu/drm/drm_displayid.c | 10 +++++-- drivers/gpu/drm/drm_edid.c | 53 ++++++++++++++++++--------------- include/drm/drm_displayid.h | 4 +-- 3 files changed, 39 insertions(+), 28 deletions(-)
diff --git a/drivers/gpu/drm/drm_displayid.c b/drivers/gpu/drm/drm_displayid.c index 32da557b960f..31c3e6d7d549 100644 --- a/drivers/gpu/drm/drm_displayid.c +++ b/drivers/gpu/drm/drm_displayid.c @@ -59,11 +59,14 @@ static const u8 *drm_find_displayid_extension(const struct edid *edid, }
void displayid_iter_edid_begin(const struct edid *edid,
struct displayid_iter *iter)
struct displayid_iter *iter, int *ext_index)
Please don't do this. This just ruins the clean approach displayid iterator added.
Instead of making the displayid iterator ugly, and leaking its abstractions, I'll repeat what I said should be done in reply to the very first version of this patch series [1]:
"I think we're going to need abstracted EDID iteration similar to what I've done for DisplayID iteration. We can't have all places reimplementing the iteration like we have now."
This isn't a problem that should be solved by having all the callers hold a bunch of local variables and pass them around to all the functions. Nobody's going to be able to keep track of this anymore. And this series, as it is, makes it harder to fix this properly later on.
BR, Jani.
[1] https://lore.kernel.org/r/87czjf8dik.fsf@intel.com
{ memset(iter, 0, sizeof(*iter));
iter->edid = edid;
- if (ext_index)
iter->ext_index = *ext_index;
}
static const struct displayid_block * @@ -126,7 +129,10 @@ __displayid_iter_next(struct displayid_iter *iter) } }
-void displayid_iter_end(struct displayid_iter *iter) +void displayid_iter_end(struct displayid_iter *iter, int *ext_index) {
- if (ext_index)
*ext_index = iter->ext_index;
- memset(iter, 0, sizeof(*iter));
} diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 561f53831e29..78c415aa6889 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -3353,28 +3353,27 @@ const u8 *drm_find_edid_extension(const struct edid *edid, return edid_ext; }
-static const u8 *drm_find_cea_extension(const struct edid *edid) +static const u8 *drm_find_cea_extension(const struct edid *edid,
int *cea_ext_index, int *displayid_ext_index)
{ const struct displayid_block *block; struct displayid_iter iter; const u8 *cea;
int ext_index = 0;
/* Look for a top level CEA extension block */
/* FIXME: make callers iterate through multiple CEA ext blocks? */
cea = drm_find_edid_extension(edid, CEA_EXT, &ext_index);
/* Look for a CEA extension block from ext_index */
cea = drm_find_edid_extension(edid, CEA_EXT, cea_ext_index); if (cea) return cea;
/* CEA blocks can also be found embedded in a DisplayID block */
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, displayid_ext_index); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_CTA) { cea = (const u8 *)block; break; } }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, displayid_ext_index);
return cea;
} @@ -3643,10 +3642,10 @@ add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid) struct drm_device *dev = connector->dev; struct drm_display_mode *mode, *tmp; LIST_HEAD(list);
- int modes = 0;
int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
/* Don't add CEA modes if the CEA extension block is missing */
- if (!drm_find_cea_extension(edid))
if (!drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index)) return 0;
/*
@@ -4321,11 +4320,11 @@ static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, static int add_cea_modes(struct drm_connector *connector, struct edid *edid) {
- const u8 *cea = drm_find_cea_extension(edid);
- const u8 *db, *hdmi = NULL, *video = NULL;
- const u8 *cea, *db, *hdmi = NULL, *video = NULL; u8 dbl, hdmi_len, video_len = 0;
- int modes = 0;
int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (cea && cea_revision(cea) >= 3) { int i, start, end;
@@ -4563,6 +4562,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) const u8 *cea; const u8 *db; int total_sad_count = 0;
- int cea_ext_index = 0, displayid_ext_index = 0; int mnl; int dbl;
@@ -4571,7 +4571,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) if (!edid) return;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("ELD: no CEA Extension found\n"); return;
@@ -4657,9 +4657,10 @@ int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads) { int count = 0; int i, start, end, dbl;
- int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0;
@@ -4719,9 +4720,10 @@ int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb) { int count = 0; int i, start, end, dbl;
- int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0;
@@ -4815,8 +4817,9 @@ bool drm_detect_hdmi_monitor(struct edid *edid) const u8 *edid_ext; int i; int start_offset, end_offset;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) return false;
@@ -4854,8 +4857,9 @@ bool drm_detect_monitor_audio(struct edid *edid) int i, j; bool has_audio = false; int start_offset, end_offset;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) goto end;
@@ -5178,8 +5182,9 @@ static void drm_parse_cea_ext(struct drm_connector *connector, struct drm_display_info *info = &connector->display_info; const u8 *edid_ext; int i, start, end;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) return;
@@ -5311,12 +5316,12 @@ static void drm_update_mso(struct drm_connector *connector, const struct edid *e const struct displayid_block *block; struct displayid_iter iter;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_2_VENDOR_SPECIFIC) drm_parse_vesa_mso_data(connector, block); }
- displayid_iter_end(&iter);
- displayid_iter_end(&iter, NULL);
}
/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset @@ -5516,13 +5521,13 @@ static int add_displayid_detailed_modes(struct drm_connector *connector, struct displayid_iter iter; int num_modes = 0;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TYPE_1_DETAILED_TIMING || block->tag == DATA_BLOCK_2_TYPE_7_DETAILED_TIMING) num_modes += add_displayid_detailed_1_modes(connector, block); }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, NULL);
return num_modes;
} @@ -6164,12 +6169,12 @@ void drm_update_tile_info(struct drm_connector *connector,
connector->has_tile = false;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TILED_DISPLAY) drm_parse_tiled_block(connector, block); }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, NULL);
if (!connector->has_tile && connector->tile_group) { drm_mode_put_tile_group(connector->dev, connector->tile_group);
diff --git a/include/drm/drm_displayid.h b/include/drm/drm_displayid.h index 7ffbd9f7bfc7..15442a161c11 100644 --- a/include/drm/drm_displayid.h +++ b/include/drm/drm_displayid.h @@ -150,11 +150,11 @@ struct displayid_iter { };
void displayid_iter_edid_begin(const struct edid *edid,
struct displayid_iter *iter);
struct displayid_iter *iter, int *ext_index);
const struct displayid_block * __displayid_iter_next(struct displayid_iter *iter); #define displayid_iter_for_each(__block, __iter) \ while (((__block) = __displayid_iter_next(__iter))) -void displayid_iter_end(struct displayid_iter *iter); +void displayid_iter_end(struct displayid_iter *iter, int *ext_index);
#endif
On Mon, Mar 14, 2022 at 10:40:47AM +0200, Jani Nikula wrote:
On Sun, 13 Mar 2022, Lee Shawn C shawn.c.lee@intel.com wrote:
drm_find_cea_extension() always look for a top level CEA block. Pass ext_index from caller then this function to search next available CEA ext block from a specific EDID block pointer.
v2: save proper extension block index if CTA data information was found in DispalyID block. v3: using different parameters to store CEA and DisplayID block index. configure DisplayID extansion block index before search available DisplayID block.
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com
drivers/gpu/drm/drm_displayid.c | 10 +++++-- drivers/gpu/drm/drm_edid.c | 53 ++++++++++++++++++--------------- include/drm/drm_displayid.h | 4 +-- 3 files changed, 39 insertions(+), 28 deletions(-)
diff --git a/drivers/gpu/drm/drm_displayid.c b/drivers/gpu/drm/drm_displayid.c index 32da557b960f..31c3e6d7d549 100644 --- a/drivers/gpu/drm/drm_displayid.c +++ b/drivers/gpu/drm/drm_displayid.c @@ -59,11 +59,14 @@ static const u8 *drm_find_displayid_extension(const struct edid *edid, }
void displayid_iter_edid_begin(const struct edid *edid,
struct displayid_iter *iter)
struct displayid_iter *iter, int *ext_index)
Please don't do this. This just ruins the clean approach displayid iterator added.
Instead of making the displayid iterator ugly, and leaking its abstractions, I'll repeat what I said should be done in reply to the very first version of this patch series [1]:
"I think we're going to need abstracted EDID iteration similar to what I've done for DisplayID iteration. We can't have all places reimplementing the iteration like we have now."
This isn't a problem that should be solved by having all the callers hold a bunch of local variables and pass them around to all the functions. Nobody's going to be able to keep track of this anymore. And this series, as it is, makes it harder to fix this properly later on.
I missed your original review comment, so apologies for repeating what you said there already.
I'd agree that passing a starting index to the displayid_iter_* functions is probably not the right direction here. More thoughts below.
BR, Jani.
[1] https://lore.kernel.org/r/87czjf8dik.fsf@intel.com
{ memset(iter, 0, sizeof(*iter));
iter->edid = edid;
- if (ext_index)
iter->ext_index = *ext_index;
}
static const struct displayid_block * @@ -126,7 +129,10 @@ __displayid_iter_next(struct displayid_iter *iter) } }
-void displayid_iter_end(struct displayid_iter *iter) +void displayid_iter_end(struct displayid_iter *iter, int *ext_index) {
- if (ext_index)
*ext_index = iter->ext_index;
- memset(iter, 0, sizeof(*iter));
} diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 561f53831e29..78c415aa6889 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -3353,28 +3353,27 @@ const u8 *drm_find_edid_extension(const struct edid *edid, return edid_ext; }
-static const u8 *drm_find_cea_extension(const struct edid *edid) +static const u8 *drm_find_cea_extension(const struct edid *edid,
int *cea_ext_index, int *displayid_ext_index)
As discussed above, passing both indices into this function may not be the best approach here. But I think we need to keep track of some kind of state in order to know which was the last CEA block that was returned, and thus this function can return the next one after that, whether it's in the CEA extension block or DisplayID block.
What do you think of using the pointer returned from this function as that state? The caller could pass in a u8* that was returned from a previous call. This function would iterate through the extension blocks and skip the CEA blocks it finds until it finds the passed in pointer, and then return the next one after (or NULL).
An alternative might be to create a linked list of ptrs to the edid extension blocks, and allow a caller to iterate over them in whatever way they need, but I'm not sure how useful that is elsewhere.
{ const struct displayid_block *block; struct displayid_iter iter; const u8 *cea;
int ext_index = 0;
/* Look for a top level CEA extension block */
/* FIXME: make callers iterate through multiple CEA ext blocks? */
cea = drm_find_edid_extension(edid, CEA_EXT, &ext_index);
/* Look for a CEA extension block from ext_index */
cea = drm_find_edid_extension(edid, CEA_EXT, cea_ext_index); if (cea) return cea;
/* CEA blocks can also be found embedded in a DisplayID block */
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, displayid_ext_index); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_CTA) { cea = (const u8 *)block; break; } }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, displayid_ext_index);
return cea;
} @@ -3643,10 +3642,10 @@ add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid) struct drm_device *dev = connector->dev; struct drm_display_mode *mode, *tmp; LIST_HEAD(list);
- int modes = 0;
int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
/* Don't add CEA modes if the CEA extension block is missing */
- if (!drm_find_cea_extension(edid))
if (!drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index)) return 0;
/*
@@ -4321,11 +4320,11 @@ static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, static int add_cea_modes(struct drm_connector *connector, struct edid *edid) {
- const u8 *cea = drm_find_cea_extension(edid);
- const u8 *db, *hdmi = NULL, *video = NULL;
- const u8 *cea, *db, *hdmi = NULL, *video = NULL; u8 dbl, hdmi_len, video_len = 0;
- int modes = 0;
int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (cea && cea_revision(cea) >= 3) { int i, start, end;
@@ -4563,6 +4562,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) const u8 *cea; const u8 *db; int total_sad_count = 0;
- int cea_ext_index = 0, displayid_ext_index = 0; int mnl; int dbl;
@@ -4571,7 +4571,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) if (!edid) return;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("ELD: no CEA Extension found\n"); return;
@@ -4657,9 +4657,10 @@ int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads) { int count = 0; int i, start, end, dbl;
- int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0;
@@ -4719,9 +4720,10 @@ int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb) { int count = 0; int i, start, end, dbl;
- int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0;
@@ -4815,8 +4817,9 @@ bool drm_detect_hdmi_monitor(struct edid *edid) const u8 *edid_ext; int i; int start_offset, end_offset;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) return false;
@@ -4854,8 +4857,9 @@ bool drm_detect_monitor_audio(struct edid *edid) int i, j; bool has_audio = false; int start_offset, end_offset;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) goto end;
@@ -5178,8 +5182,9 @@ static void drm_parse_cea_ext(struct drm_connector *connector, struct drm_display_info *info = &connector->display_info; const u8 *edid_ext; int i, start, end;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) return;
@@ -5311,12 +5316,12 @@ static void drm_update_mso(struct drm_connector *connector, const struct edid *e const struct displayid_block *block; struct displayid_iter iter;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_2_VENDOR_SPECIFIC) drm_parse_vesa_mso_data(connector, block); }
- displayid_iter_end(&iter);
- displayid_iter_end(&iter, NULL);
}
/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset @@ -5516,13 +5521,13 @@ static int add_displayid_detailed_modes(struct drm_connector *connector, struct displayid_iter iter; int num_modes = 0;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TYPE_1_DETAILED_TIMING || block->tag == DATA_BLOCK_2_TYPE_7_DETAILED_TIMING) num_modes += add_displayid_detailed_1_modes(connector, block); }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, NULL);
return num_modes;
} @@ -6164,12 +6169,12 @@ void drm_update_tile_info(struct drm_connector *connector,
connector->has_tile = false;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TILED_DISPLAY) drm_parse_tiled_block(connector, block); }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, NULL);
if (!connector->has_tile && connector->tile_group) { drm_mode_put_tile_group(connector->dev, connector->tile_group);
diff --git a/include/drm/drm_displayid.h b/include/drm/drm_displayid.h index 7ffbd9f7bfc7..15442a161c11 100644 --- a/include/drm/drm_displayid.h +++ b/include/drm/drm_displayid.h @@ -150,11 +150,11 @@ struct displayid_iter { };
void displayid_iter_edid_begin(const struct edid *edid,
struct displayid_iter *iter);
struct displayid_iter *iter, int *ext_index);
const struct displayid_block * __displayid_iter_next(struct displayid_iter *iter); #define displayid_iter_for_each(__block, __iter) \ while (((__block) = __displayid_iter_next(__iter))) -void displayid_iter_end(struct displayid_iter *iter); +void displayid_iter_end(struct displayid_iter *iter, int *ext_index);
#endif
-- Jani Nikula, Intel Open Source Graphics Center
On Mon, 14 Mar 2022, Drew Davenport ddavenport@chromium.org wrote:
On Mon, Mar 14, 2022 at 10:40:47AM +0200, Jani Nikula wrote:
On Sun, 13 Mar 2022, Lee Shawn C shawn.c.lee@intel.com wrote:
drm_find_cea_extension() always look for a top level CEA block. Pass ext_index from caller then this function to search next available CEA ext block from a specific EDID block pointer.
v2: save proper extension block index if CTA data information was found in DispalyID block. v3: using different parameters to store CEA and DisplayID block index. configure DisplayID extansion block index before search available DisplayID block.
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com
drivers/gpu/drm/drm_displayid.c | 10 +++++-- drivers/gpu/drm/drm_edid.c | 53 ++++++++++++++++++--------------- include/drm/drm_displayid.h | 4 +-- 3 files changed, 39 insertions(+), 28 deletions(-)
diff --git a/drivers/gpu/drm/drm_displayid.c b/drivers/gpu/drm/drm_displayid.c index 32da557b960f..31c3e6d7d549 100644 --- a/drivers/gpu/drm/drm_displayid.c +++ b/drivers/gpu/drm/drm_displayid.c @@ -59,11 +59,14 @@ static const u8 *drm_find_displayid_extension(const struct edid *edid, }
void displayid_iter_edid_begin(const struct edid *edid,
struct displayid_iter *iter)
struct displayid_iter *iter, int *ext_index)
Please don't do this. This just ruins the clean approach displayid iterator added.
Instead of making the displayid iterator ugly, and leaking its abstractions, I'll repeat what I said should be done in reply to the very first version of this patch series [1]:
"I think we're going to need abstracted EDID iteration similar to what I've done for DisplayID iteration. We can't have all places reimplementing the iteration like we have now."
This isn't a problem that should be solved by having all the callers hold a bunch of local variables and pass them around to all the functions. Nobody's going to be able to keep track of this anymore. And this series, as it is, makes it harder to fix this properly later on.
I missed your original review comment, so apologies for repeating what you said there already.
I'd agree that passing a starting index to the displayid_iter_* functions is probably not the right direction here. More thoughts below.
BR, Jani.
[1] https://lore.kernel.org/r/87czjf8dik.fsf@intel.com
{ memset(iter, 0, sizeof(*iter));
iter->edid = edid;
- if (ext_index)
iter->ext_index = *ext_index;
}
static const struct displayid_block * @@ -126,7 +129,10 @@ __displayid_iter_next(struct displayid_iter *iter) } }
-void displayid_iter_end(struct displayid_iter *iter) +void displayid_iter_end(struct displayid_iter *iter, int *ext_index) {
- if (ext_index)
*ext_index = iter->ext_index;
- memset(iter, 0, sizeof(*iter));
} diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 561f53831e29..78c415aa6889 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -3353,28 +3353,27 @@ const u8 *drm_find_edid_extension(const struct edid *edid, return edid_ext; }
-static const u8 *drm_find_cea_extension(const struct edid *edid) +static const u8 *drm_find_cea_extension(const struct edid *edid,
int *cea_ext_index, int *displayid_ext_index)
As discussed above, passing both indices into this function may not be the best approach here. But I think we need to keep track of some kind of state in order to know which was the last CEA block that was returned, and thus this function can return the next one after that, whether it's in the CEA extension block or DisplayID block.
Per DisplayID v1.3 Appendix B: DisplayID as an EDID Extension, it's recommended that DisplayID extensions are exposed after all of the CEA extensions.
I think it should be fine to first iterate over all CEA extensions across the EDID, followed by iterating over all the DisplayID extensions. No need to keep track of the order between CEA and DisplayID, as the former should precede the latter.
What do you think of using the pointer returned from this function as that state? The caller could pass in a u8* that was returned from a previous call. This function would iterate through the extension blocks and skip the CEA blocks it finds until it finds the passed in pointer, and then return the next one after (or NULL).
An alternative might be to create a linked list of ptrs to the edid extension blocks, and allow a caller to iterate over them in whatever way they need, but I'm not sure how useful that is elsewhere.
I think the main problem here is trying to hack a for loop around drm_find_cea_extension() and drm_find_edid_extension(), and duplicating that all over the place, without adding more structure or abstractions.
Contrast with displayid_iter_edid_begin(), displayid_iter_for_each(), and displayid_iter_end() and their usage. They hide all the complexity of looping across DisplayID data blocks inside EDID extensions, and none of the users need to be aware of that complexity. All the state is hidden in struct displayid_iter, and the users don't need to look inside. No allocations, no linked lists.
I think it's particularly bad to have the changes here break the abstractions in displayid_iter_*, especially because they should be usable for pure DisplayID 2.0 *without* an EDID block structure. They'll just need a displayid_iter_begin() for pure DisplayID and some internal changes.
Looking at the usage, the iteration should probably be done at the CEA data block level, something like this:
struct cea_iter iter; const struct cea_block *block;
cea_iter_edid_begin(edid, &iter); cea_iter_for_each(block, &iter) { /* ... */ } cea_iter_end(&iter);
This would replace cea_db_offsets() and for_each_cea_db(), and would iterate across the all CEA and DisplayID extensions in the entire EDID.
This looks usable, and then you'd start figuring out how to implement that, instead of trying to retrofit all the existing usages to abstractions that don't cut it. You'll probably need an EDID extension iterator too, and then use that and __displayid_iter_next() within cea_iter_for_each() i.e. you'd embed the edid_iter and displayid_iter within struct cea_iter. Exhaust the former first, and then the latter.
BR, Jani.
{ const struct displayid_block *block; struct displayid_iter iter; const u8 *cea;
int ext_index = 0;
/* Look for a top level CEA extension block */
/* FIXME: make callers iterate through multiple CEA ext blocks? */
cea = drm_find_edid_extension(edid, CEA_EXT, &ext_index);
/* Look for a CEA extension block from ext_index */
cea = drm_find_edid_extension(edid, CEA_EXT, cea_ext_index); if (cea) return cea;
/* CEA blocks can also be found embedded in a DisplayID block */
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, displayid_ext_index); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_CTA) { cea = (const u8 *)block; break; } }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, displayid_ext_index);
return cea;
} @@ -3643,10 +3642,10 @@ add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid) struct drm_device *dev = connector->dev; struct drm_display_mode *mode, *tmp; LIST_HEAD(list);
- int modes = 0;
int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
/* Don't add CEA modes if the CEA extension block is missing */
- if (!drm_find_cea_extension(edid))
if (!drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index)) return 0;
/*
@@ -4321,11 +4320,11 @@ static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, static int add_cea_modes(struct drm_connector *connector, struct edid *edid) {
- const u8 *cea = drm_find_cea_extension(edid);
- const u8 *db, *hdmi = NULL, *video = NULL;
- const u8 *cea, *db, *hdmi = NULL, *video = NULL; u8 dbl, hdmi_len, video_len = 0;
- int modes = 0;
int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (cea && cea_revision(cea) >= 3) { int i, start, end;
@@ -4563,6 +4562,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) const u8 *cea; const u8 *db; int total_sad_count = 0;
- int cea_ext_index = 0, displayid_ext_index = 0; int mnl; int dbl;
@@ -4571,7 +4571,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) if (!edid) return;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("ELD: no CEA Extension found\n"); return;
@@ -4657,9 +4657,10 @@ int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads) { int count = 0; int i, start, end, dbl;
- int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0;
@@ -4719,9 +4720,10 @@ int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb) { int count = 0; int i, start, end, dbl;
- int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0;
@@ -4815,8 +4817,9 @@ bool drm_detect_hdmi_monitor(struct edid *edid) const u8 *edid_ext; int i; int start_offset, end_offset;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) return false;
@@ -4854,8 +4857,9 @@ bool drm_detect_monitor_audio(struct edid *edid) int i, j; bool has_audio = false; int start_offset, end_offset;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) goto end;
@@ -5178,8 +5182,9 @@ static void drm_parse_cea_ext(struct drm_connector *connector, struct drm_display_info *info = &connector->display_info; const u8 *edid_ext; int i, start, end;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); if (!edid_ext) return;
@@ -5311,12 +5316,12 @@ static void drm_update_mso(struct drm_connector *connector, const struct edid *e const struct displayid_block *block; struct displayid_iter iter;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_2_VENDOR_SPECIFIC) drm_parse_vesa_mso_data(connector, block); }
- displayid_iter_end(&iter);
- displayid_iter_end(&iter, NULL);
}
/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset @@ -5516,13 +5521,13 @@ static int add_displayid_detailed_modes(struct drm_connector *connector, struct displayid_iter iter; int num_modes = 0;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TYPE_1_DETAILED_TIMING || block->tag == DATA_BLOCK_2_TYPE_7_DETAILED_TIMING) num_modes += add_displayid_detailed_1_modes(connector, block); }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, NULL);
return num_modes;
} @@ -6164,12 +6169,12 @@ void drm_update_tile_info(struct drm_connector *connector,
connector->has_tile = false;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TILED_DISPLAY) drm_parse_tiled_block(connector, block); }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, NULL);
if (!connector->has_tile && connector->tile_group) { drm_mode_put_tile_group(connector->dev, connector->tile_group);
diff --git a/include/drm/drm_displayid.h b/include/drm/drm_displayid.h index 7ffbd9f7bfc7..15442a161c11 100644 --- a/include/drm/drm_displayid.h +++ b/include/drm/drm_displayid.h @@ -150,11 +150,11 @@ struct displayid_iter { };
void displayid_iter_edid_begin(const struct edid *edid,
struct displayid_iter *iter);
struct displayid_iter *iter, int *ext_index);
const struct displayid_block * __displayid_iter_next(struct displayid_iter *iter); #define displayid_iter_for_each(__block, __iter) \ while (((__block) = __displayid_iter_next(__iter))) -void displayid_iter_end(struct displayid_iter *iter); +void displayid_iter_end(struct displayid_iter *iter, int *ext_index);
#endif
-- Jani Nikula, Intel Open Source Graphics Center
On Tuesday, March 15, 2022 8:33 PM, Nikula, Jani jani.nikula@intel.com wrote:
On Mon, 14 Mar 2022, Drew Davenport ddavenport@chromium.org wrote:
On Mon, Mar 14, 2022 at 10:40:47AM +0200, Jani Nikula wrote:
On Sun, 13 Mar 2022, Lee Shawn C shawn.c.lee@intel.com wrote:
drm_find_cea_extension() always look for a top level CEA block. Pass ext_index from caller then this function to search next available CEA ext block from a specific EDID block pointer.
v2: save proper extension block index if CTA data information was found in DispalyID block. v3: using different parameters to store CEA and DisplayID block index. configure DisplayID extansion block index before search available DisplayID block.
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com
drivers/gpu/drm/drm_displayid.c | 10 +++++-- drivers/gpu/drm/drm_edid.c | 53 ++++++++++++++++++--------------- include/drm/drm_displayid.h | 4 +-- 3 files changed, 39 insertions(+), 28 deletions(-)
diff --git a/drivers/gpu/drm/drm_displayid.c b/drivers/gpu/drm/drm_displayid.c index 32da557b960f..31c3e6d7d549 100644 --- a/drivers/gpu/drm/drm_displayid.c +++ b/drivers/gpu/drm/drm_displayid.c @@ -59,11 +59,14 @@ static const u8 *drm_find_displayid_extension(const struct edid *edid, }
void displayid_iter_edid_begin(const struct edid *edid,
struct displayid_iter *iter)
struct displayid_iter *iter, int *ext_index)
Please don't do this. This just ruins the clean approach displayid iterator added.
Instead of making the displayid iterator ugly, and leaking its abstractions, I'll repeat what I said should be done in reply to the very first version of this patch series [1]:
"I think we're going to need abstracted EDID iteration similar to what I've done for DisplayID iteration. We can't have all places reimplementing the iteration like we have now."
This isn't a problem that should be solved by having all the callers hold a bunch of local variables and pass them around to all the functions. Nobody's going to be able to keep track of this anymore. And this series, as it is, makes it harder to fix this properly later on.
I missed your original review comment, so apologies for repeating what you said there already.
I'd agree that passing a starting index to the displayid_iter_* functions is probably not the right direction here. More thoughts below.
BR, Jani.
[1] https://lore.kernel.org/r/87czjf8dik.fsf@intel.com
{ memset(iter, 0, sizeof(*iter));
iter->edid = edid;
- if (ext_index)
iter->ext_index = *ext_index;
}
static const struct displayid_block * @@ -126,7 +129,10 @@ __displayid_iter_next(struct displayid_iter *iter) } }
-void displayid_iter_end(struct displayid_iter *iter) +void displayid_iter_end(struct displayid_iter *iter, int +*ext_index) {
- if (ext_index)
*ext_index = iter->ext_index;
- memset(iter, 0, sizeof(*iter));
} diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 561f53831e29..78c415aa6889 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -3353,28 +3353,27 @@ const u8 *drm_find_edid_extension(const struct edid *edid, return edid_ext; }
-static const u8 *drm_find_cea_extension(const struct edid *edid) +static const u8 *drm_find_cea_extension(const struct edid *edid,
int *cea_ext_index, int *displayid_ext_index)
As discussed above, passing both indices into this function may not be the best approach here. But I think we need to keep track of some kind of state in order to know which was the last CEA block that was returned, and thus this function can return the next one after that, whether it's in the CEA extension block or DisplayID block.
Per DisplayID v1.3 Appendix B: DisplayID as an EDID Extension, it's recommended that DisplayID extensions are exposed after all of the CEA extensions.
I think it should be fine to first iterate over all CEA extensions across the EDID, followed by iterating over all the DisplayID extensions. No need to keep track of the order between CEA and DisplayID, as the former should precede the latter.
Refer to "DisplayID extensions are exposed after all of the CEA extensions". It looks to me patch v5 is able to support this. And did not touch DisplayID iterator. https://patchwork.freedesktop.org/series/100690/#rev5
What do you think of using the pointer returned from this function as that state? The caller could pass in a u8* that was returned from a previous call. This function would iterate through the extension blocks and skip the CEA blocks it finds until it finds the passed in pointer, and then return the next one after (or NULL).
An alternative might be to create a linked list of ptrs to the edid extension blocks, and allow a caller to iterate over them in whatever way they need, but I'm not sure how useful that is elsewhere.
I think the main problem here is trying to hack a for loop around drm_find_cea_extension() and drm_find_edid_extension(), and duplicating that all over the place, without adding more structure or abstractions.
Contrast with displayid_iter_edid_begin(), displayid_iter_for_each(), and displayid_iter_end() and their usage. They hide all the complexity of looping across DisplayID data blocks inside EDID extensions, and none of the users need to be aware of that complexity. All the state is hidden in struct displayid_iter, and the users don't need to look inside. No allocations, no linked lists.
I think it's particularly bad to have the changes here break the abstractions in displayid_iter_*, especially because they should be usable for pure DisplayID 2.0 *without* an EDID block structure. They'll just need a displayid_iter_begin() for pure DisplayID and some internal changes.
Looking at the usage, the iteration should probably be done at the CEA data block level, something like this:
struct cea_iter iter; const struct cea_block *block;
cea_iter_edid_begin(edid, &iter); cea_iter_for_each(block, &iter) { /* ... */ } cea_iter_end(&iter);
This would replace cea_db_offsets() and for_each_cea_db(), and would iterate across the all CEA and DisplayID extensions in the entire EDID.
This looks usable, and then you'd start figuring out how to implement that, instead of trying to retrofit all the existing usages to abstractions that don't cut it. You'll probably need an EDID extension iterator too, and then use that and __displayid_iter_next() within cea_iter_for_each() i.e. you'd embed the edid_iter and displayid_iter within struct cea_iter. Exhaust the former first, and then the latter.
BR, Jani.
Hi Jani, Drew, thank you all for your comment! Agree that edid driver may need abstracted EDID iteration similar to what you did for DisplayID iteration. It will need a lot of code changes in drm driver.
But, we have a tight schedule and have to meet HDMI 2.1 compliance test requirement. Do you think this series can be a short term solution to pass HDMI CTS test? And we can have another long term plan to work on your opinion to modify the iterator and make edid driver more efficient and easier to maintain.
Best regards, Shawn
{ const struct displayid_block *block; struct displayid_iter iter; const u8 *cea;
int ext_index = 0;
/* Look for a top level CEA extension block */
/* FIXME: make callers iterate through multiple CEA ext blocks? */
cea = drm_find_edid_extension(edid, CEA_EXT, &ext_index);
/* Look for a CEA extension block from ext_index */
cea = drm_find_edid_extension(edid, CEA_EXT, cea_ext_index); if (cea) return cea;
/* CEA blocks can also be found embedded in a DisplayID block */
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, displayid_ext_index); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_CTA) { cea = (const u8 *)block; break; } }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, displayid_ext_index);
return cea;
} @@ -3643,10 +3642,10 @@ add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid) struct drm_device *dev = connector->dev; struct drm_display_mode *mode, *tmp; LIST_HEAD(list);
- int modes = 0;
int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
/* Don't add CEA modes if the CEA extension block is missing */
- if (!drm_find_cea_extension(edid))
- if (!drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index)) return 0;
/* @@ -4321,11 +4320,11 @@ static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, static int add_cea_modes(struct drm_connector *connector, struct edid *edid) {
- const u8 *cea = drm_find_cea_extension(edid);
- const u8 *db, *hdmi = NULL, *video = NULL;
- const u8 *cea, *db, *hdmi = NULL, *video = NULL; u8 dbl, hdmi_len, video_len = 0;
- int modes = 0;
int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
cea = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (cea && cea_revision(cea) >= 3) { int i, start, end;
@@ -4563,6 +4562,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) const u8 *cea; const u8 *db; int total_sad_count = 0;
- int cea_ext_index = 0, displayid_ext_index = 0; int mnl; int dbl;
@@ -4571,7 +4571,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) if (!edid) return;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("ELD: no CEA Extension found\n"); return; @@ -4657,9 +4657,10 @@ int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads) { int count = 0; int i, start, end, dbl;
- int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0; @@ -4719,9 +4720,10 @@ int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb) { int count = 0; int i, start, end, dbl;
- int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0; @@ -4815,8 +4817,9 @@ bool drm_detect_hdmi_monitor(struct edid *edid) const u8 *edid_ext; int i; int start_offset, end_offset;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!edid_ext) return false;
@@ -4854,8 +4857,9 @@ bool drm_detect_monitor_audio(struct edid *edid) int i, j; bool has_audio = false; int start_offset, end_offset;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!edid_ext) goto end;
@@ -5178,8 +5182,9 @@ static void drm_parse_cea_ext(struct drm_connector *connector, struct drm_display_info *info = &connector->display_info; const u8 *edid_ext; int i, start, end;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!edid_ext) return;
@@ -5311,12 +5316,12 @@ static void drm_update_mso(struct drm_connector *connector, const struct edid *e const struct displayid_block *block; struct displayid_iter iter;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_2_VENDOR_SPECIFIC) drm_parse_vesa_mso_data(connector, block); }
- displayid_iter_end(&iter);
- displayid_iter_end(&iter, NULL);
}
/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset @@ -5516,13 +5521,13 @@ static int add_displayid_detailed_modes(struct drm_connector *connector, struct displayid_iter iter; int num_modes = 0;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TYPE_1_DETAILED_TIMING || block->tag == DATA_BLOCK_2_TYPE_7_DETAILED_TIMING) num_modes += add_displayid_detailed_1_modes(connector, block); }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, NULL);
return num_modes;
} @@ -6164,12 +6169,12 @@ void drm_update_tile_info(struct drm_connector *connector,
connector->has_tile = false;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TILED_DISPLAY) drm_parse_tiled_block(connector, block); }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, NULL);
if (!connector->has_tile && connector->tile_group) { drm_mode_put_tile_group(connector->dev, connector->tile_group);
diff --git a/include/drm/drm_displayid.h b/include/drm/drm_displayid.h index 7ffbd9f7bfc7..15442a161c11 100644 --- a/include/drm/drm_displayid.h +++ b/include/drm/drm_displayid.h @@ -150,11 +150,11 @@ struct displayid_iter { };
void displayid_iter_edid_begin(const struct edid *edid,
struct displayid_iter *iter);
struct displayid_iter *iter, int *ext_index);
const struct displayid_block * __displayid_iter_next(struct displayid_iter *iter); #define displayid_iter_for_each(__block, __iter) \ while (((__block) = __displayid_iter_next(__iter))) -void displayid_iter_end(struct displayid_iter *iter); +void displayid_iter_end(struct displayid_iter *iter, int +*ext_index);
#endif
-- Jani Nikula, Intel Open Source Graphics Center
-- Jani Nikula, Intel Open Source Graphics Center
On Tue, Mar 15, 2022 at 03:21:05PM +0000, Lee, Shawn C wrote:
On Tuesday, March 15, 2022 8:33 PM, Nikula, Jani jani.nikula@intel.com wrote:
On Mon, 14 Mar 2022, Drew Davenport ddavenport@chromium.org wrote:
On Mon, Mar 14, 2022 at 10:40:47AM +0200, Jani Nikula wrote:
On Sun, 13 Mar 2022, Lee Shawn C shawn.c.lee@intel.com wrote:
drm_find_cea_extension() always look for a top level CEA block. Pass ext_index from caller then this function to search next available CEA ext block from a specific EDID block pointer.
v2: save proper extension block index if CTA data information was found in DispalyID block. v3: using different parameters to store CEA and DisplayID block index. configure DisplayID extansion block index before search available DisplayID block.
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com
drivers/gpu/drm/drm_displayid.c | 10 +++++-- drivers/gpu/drm/drm_edid.c | 53 ++++++++++++++++++--------------- include/drm/drm_displayid.h | 4 +-- 3 files changed, 39 insertions(+), 28 deletions(-)
diff --git a/drivers/gpu/drm/drm_displayid.c b/drivers/gpu/drm/drm_displayid.c index 32da557b960f..31c3e6d7d549 100644 --- a/drivers/gpu/drm/drm_displayid.c +++ b/drivers/gpu/drm/drm_displayid.c @@ -59,11 +59,14 @@ static const u8 *drm_find_displayid_extension(const struct edid *edid, }
void displayid_iter_edid_begin(const struct edid *edid,
struct displayid_iter *iter)
struct displayid_iter *iter, int *ext_index)
Please don't do this. This just ruins the clean approach displayid iterator added.
Instead of making the displayid iterator ugly, and leaking its abstractions, I'll repeat what I said should be done in reply to the very first version of this patch series [1]:
"I think we're going to need abstracted EDID iteration similar to what I've done for DisplayID iteration. We can't have all places reimplementing the iteration like we have now."
This isn't a problem that should be solved by having all the callers hold a bunch of local variables and pass them around to all the functions. Nobody's going to be able to keep track of this anymore. And this series, as it is, makes it harder to fix this properly later on.
I missed your original review comment, so apologies for repeating what you said there already.
I'd agree that passing a starting index to the displayid_iter_* functions is probably not the right direction here. More thoughts below.
BR, Jani.
[1] https://lore.kernel.org/r/87czjf8dik.fsf@intel.com
{ memset(iter, 0, sizeof(*iter));
iter->edid = edid;
- if (ext_index)
iter->ext_index = *ext_index;
}
static const struct displayid_block * @@ -126,7 +129,10 @@ __displayid_iter_next(struct displayid_iter *iter) } }
-void displayid_iter_end(struct displayid_iter *iter) +void displayid_iter_end(struct displayid_iter *iter, int +*ext_index) {
- if (ext_index)
*ext_index = iter->ext_index;
- memset(iter, 0, sizeof(*iter));
} diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 561f53831e29..78c415aa6889 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -3353,28 +3353,27 @@ const u8 *drm_find_edid_extension(const struct edid *edid, return edid_ext; }
-static const u8 *drm_find_cea_extension(const struct edid *edid) +static const u8 *drm_find_cea_extension(const struct edid *edid,
int *cea_ext_index, int *displayid_ext_index)
As discussed above, passing both indices into this function may not be the best approach here. But I think we need to keep track of some kind of state in order to know which was the last CEA block that was returned, and thus this function can return the next one after that, whether it's in the CEA extension block or DisplayID block.
Per DisplayID v1.3 Appendix B: DisplayID as an EDID Extension, it's recommended that DisplayID extensions are exposed after all of the CEA extensions.
I think it should be fine to first iterate over all CEA extensions across the EDID, followed by iterating over all the DisplayID extensions. No need to keep track of the order between CEA and DisplayID, as the former should precede the latter.
Refer to "DisplayID extensions are exposed after all of the CEA extensions". It looks to me patch v5 is able to support this. And did not touch DisplayID iterator. https://patchwork.freedesktop.org/series/100690/#rev5
Patch v5 does not iterate over all the DisplayID extensions, and it has the previously mentioned problem about resulting in a possible infinite loop when depending on ext_index to iterate over the CEA extensions.
What do you think of using the pointer returned from this function as that state? The caller could pass in a u8* that was returned from a previous call. This function would iterate through the extension blocks and skip the CEA blocks it finds until it finds the passed in pointer, and then return the next one after (or NULL).
An alternative might be to create a linked list of ptrs to the edid extension blocks, and allow a caller to iterate over them in whatever way they need, but I'm not sure how useful that is elsewhere.
I think the main problem here is trying to hack a for loop around drm_find_cea_extension() and drm_find_edid_extension(), and duplicating that all over the place, without adding more structure or abstractions.
Contrast with displayid_iter_edid_begin(), displayid_iter_for_each(), and displayid_iter_end() and their usage. They hide all the complexity of looping across DisplayID data blocks inside EDID extensions, and none of the users need to be aware of that complexity. All the state is hidden in struct displayid_iter, and the users don't need to look inside. No allocations, no linked lists.
I think it's particularly bad to have the changes here break the abstractions in displayid_iter_*, especially because they should be usable for pure DisplayID 2.0 *without* an EDID block structure. They'll just need a displayid_iter_begin() for pure DisplayID and some internal changes.
Looking at the usage, the iteration should probably be done at the CEA data block level, something like this:
struct cea_iter iter; const struct cea_block *block;
cea_iter_edid_begin(edid, &iter); cea_iter_for_each(block, &iter) { /* ... */ } cea_iter_end(&iter);
This would replace cea_db_offsets() and for_each_cea_db(), and would iterate across the all CEA and DisplayID extensions in the entire EDID.
This looks usable, and then you'd start figuring out how to implement that, instead of trying to retrofit all the existing usages to abstractions that don't cut it. You'll probably need an EDID extension iterator too, and then use that and __displayid_iter_next() within cea_iter_for_each() i.e. you'd embed the edid_iter and displayid_iter within struct cea_iter. Exhaust the former first, and then the latter.
BR, Jani.
Hi Jani, Drew, thank you all for your comment! Agree that edid driver may need abstracted EDID iteration similar to what you did for DisplayID iteration. It will need a lot of code changes in drm driver.
But, we have a tight schedule and have to meet HDMI 2.1 compliance test requirement. Do you think this series can be a short term solution to pass HDMI CTS test? And we can have another long term plan to work on your opinion to modify the iterator and make edid driver more efficient and easier to maintain.
Best regards, Shawn
{ const struct displayid_block *block; struct displayid_iter iter; const u8 *cea;
int ext_index = 0;
/* Look for a top level CEA extension block */
/* FIXME: make callers iterate through multiple CEA ext blocks? */
cea = drm_find_edid_extension(edid, CEA_EXT, &ext_index);
/* Look for a CEA extension block from ext_index */
cea = drm_find_edid_extension(edid, CEA_EXT, cea_ext_index); if (cea) return cea;
/* CEA blocks can also be found embedded in a DisplayID block */
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, displayid_ext_index); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_CTA) { cea = (const u8 *)block; break; } }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, displayid_ext_index);
return cea;
} @@ -3643,10 +3642,10 @@ add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid) struct drm_device *dev = connector->dev; struct drm_display_mode *mode, *tmp; LIST_HEAD(list);
- int modes = 0;
int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
/* Don't add CEA modes if the CEA extension block is missing */
- if (!drm_find_cea_extension(edid))
- if (!drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index)) return 0;
/* @@ -4321,11 +4320,11 @@ static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, static int add_cea_modes(struct drm_connector *connector, struct edid *edid) {
- const u8 *cea = drm_find_cea_extension(edid);
- const u8 *db, *hdmi = NULL, *video = NULL;
- const u8 *cea, *db, *hdmi = NULL, *video = NULL; u8 dbl, hdmi_len, video_len = 0;
- int modes = 0;
int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
cea = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (cea && cea_revision(cea) >= 3) { int i, start, end;
@@ -4563,6 +4562,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) const u8 *cea; const u8 *db; int total_sad_count = 0;
- int cea_ext_index = 0, displayid_ext_index = 0; int mnl; int dbl;
@@ -4571,7 +4571,7 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) if (!edid) return;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("ELD: no CEA Extension found\n"); return; @@ -4657,9 +4657,10 @@ int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads) { int count = 0; int i, start, end, dbl;
- int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0; @@ -4719,9 +4720,10 @@ int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb) { int count = 0; int i, start, end, dbl;
- int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid);
- cea = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0; @@ -4815,8 +4817,9 @@ bool drm_detect_hdmi_monitor(struct edid *edid) const u8 *edid_ext; int i; int start_offset, end_offset;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!edid_ext) return false;
@@ -4854,8 +4857,9 @@ bool drm_detect_monitor_audio(struct edid *edid) int i, j; bool has_audio = false; int start_offset, end_offset;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!edid_ext) goto end;
@@ -5178,8 +5182,9 @@ static void drm_parse_cea_ext(struct drm_connector *connector, struct drm_display_info *info = &connector->display_info; const u8 *edid_ext; int i, start, end;
- int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid);
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index); if (!edid_ext) return;
@@ -5311,12 +5316,12 @@ static void drm_update_mso(struct drm_connector *connector, const struct edid *e const struct displayid_block *block; struct displayid_iter iter;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_2_VENDOR_SPECIFIC) drm_parse_vesa_mso_data(connector, block); }
- displayid_iter_end(&iter);
- displayid_iter_end(&iter, NULL);
}
/* A connector has no EDID information, so we've got no EDID to compute quirks from. Reset @@ -5516,13 +5521,13 @@ static int add_displayid_detailed_modes(struct drm_connector *connector, struct displayid_iter iter; int num_modes = 0;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TYPE_1_DETAILED_TIMING || block->tag == DATA_BLOCK_2_TYPE_7_DETAILED_TIMING) num_modes += add_displayid_detailed_1_modes(connector, block); }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, NULL);
return num_modes;
} @@ -6164,12 +6169,12 @@ void drm_update_tile_info(struct drm_connector *connector,
connector->has_tile = false;
- displayid_iter_edid_begin(edid, &iter);
- displayid_iter_edid_begin(edid, &iter, NULL); displayid_iter_for_each(block, &iter) { if (block->tag == DATA_BLOCK_TILED_DISPLAY) drm_parse_tiled_block(connector, block); }
- displayid_iter_end(&iter);
displayid_iter_end(&iter, NULL);
if (!connector->has_tile && connector->tile_group) { drm_mode_put_tile_group(connector->dev, connector->tile_group);
diff --git a/include/drm/drm_displayid.h b/include/drm/drm_displayid.h index 7ffbd9f7bfc7..15442a161c11 100644 --- a/include/drm/drm_displayid.h +++ b/include/drm/drm_displayid.h @@ -150,11 +150,11 @@ struct displayid_iter { };
void displayid_iter_edid_begin(const struct edid *edid,
struct displayid_iter *iter);
struct displayid_iter *iter, int *ext_index);
const struct displayid_block * __displayid_iter_next(struct displayid_iter *iter); #define displayid_iter_for_each(__block, __iter) \ while (((__block) = __displayid_iter_next(__iter))) -void displayid_iter_end(struct displayid_iter *iter); +void displayid_iter_end(struct displayid_iter *iter, int +*ext_index);
#endif
-- Jani Nikula, Intel Open Source Graphics Center
-- Jani Nikula, Intel Open Source Graphics Center
Try to find and parse more CEA ext blocks if edid->extensions is greater than one.
v2: split prvious patch to two. And do CEA block parsing in this one. v3: simplify this patch based on previous change. v4: refine patch v3.
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com --- drivers/gpu/drm/drm_edid.c | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 78c415aa6889..9fa84881fbba 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -4320,16 +4320,22 @@ static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, static int add_cea_modes(struct drm_connector *connector, struct edid *edid) { - const u8 *cea, *db, *hdmi = NULL, *video = NULL; - u8 dbl, hdmi_len, video_len = 0; int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); - if (cea && cea_revision(cea) >= 3) { + for (;;) { + const u8 *cea, *db, *hdmi = NULL, *video = NULL; + u8 dbl, hdmi_len = 0, video_len = 0; int i, start, end;
+ cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); + if (!cea) + break; + + if (cea_revision(cea) < 3) + continue; + if (cea_db_offsets(cea, &start, &end)) - return 0; + continue;
for_each_cea_db(cea, i, start, end) { db = &cea[i]; @@ -4351,15 +4357,15 @@ add_cea_modes(struct drm_connector *connector, struct edid *edid) dbl - 1); } } - }
- /* - * We parse the HDMI VSDB after having added the cea modes as we will - * be patching their flags when the sink supports stereo 3D. - */ - if (hdmi) - modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video, - video_len); + /* + * We parse the HDMI VSDB after having added the cea modes as we will + * be patching their flags when the sink supports stereo 3D. + */ + if (hdmi) + modes += do_hdmi_vsdb_modes(connector, hdmi, hdmi_len, video, + video_len); + }
return modes; }
According to HDMI 2.1 spec.
"The HDMI Forum EDID Extension Override Data Block (HF-EEODB) is utilized by Sink Devices to provide an alternate method to indicate an EDID Extension Block count larger than 1, while avoiding the need to present a VESA Block Map in the first E-EDID Extension Block."
It is a mandatory for HDMI 2.1 protocol compliance as well. This patch help to know how many HF_EEODB blocks report by sink and read allo HF_EEODB blocks back.
v2: support to find CEA block, check EEODB block format, and return available block number in drm_edid_read_hf_eeodb_blk_count().
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com --- drivers/gpu/drm/drm_connector.c | 8 +++- drivers/gpu/drm/drm_edid.c | 71 +++++++++++++++++++++++++++++++-- include/drm/drm_edid.h | 1 + 3 files changed, 74 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index a50c82bc2b2f..16011023c12e 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -2129,7 +2129,7 @@ int drm_connector_update_edid_property(struct drm_connector *connector, const struct edid *edid) { struct drm_device *dev = connector->dev; - size_t size = 0; + size_t size = 0, hf_eeodb_blk_count; int ret; const struct edid *old_edid;
@@ -2137,8 +2137,12 @@ int drm_connector_update_edid_property(struct drm_connector *connector, if (connector->override_edid) return 0;
- if (edid) + if (edid) { size = EDID_LENGTH * (1 + edid->extensions); + hf_eeodb_blk_count = drm_edid_read_hf_eeodb_blk_count(edid); + if (hf_eeodb_blk_count) + size = EDID_LENGTH * (1 + hf_eeodb_blk_count); + }
/* Set the display info, using edid if available, otherwise * resetting the values to defaults. This duplicates the work diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 9fa84881fbba..5ae4e83fa5e3 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1992,6 +1992,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, { int i, j = 0, valid_extensions = 0; u8 *edid, *new; + size_t hf_eeodb_blk_count; struct edid *override;
override = drm_get_override_edid(connector); @@ -2051,7 +2052,35 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, }
kfree(edid); + return (struct edid *)new; + } + + hf_eeodb_blk_count = drm_edid_read_hf_eeodb_blk_count((struct edid *)edid); + if (hf_eeodb_blk_count >= 2) { + new = krealloc(edid, (hf_eeodb_blk_count + 1) * EDID_LENGTH, GFP_KERNEL); + if (!new) + goto out; edid = new; + + valid_extensions = hf_eeodb_blk_count - 1; + for (j = 2; j <= hf_eeodb_blk_count; j++) { + u8 *block = edid + j * EDID_LENGTH; + + for (i = 0; i < 4; i++) { + if (get_edid_block(data, block, j, EDID_LENGTH)) + goto out; + if (drm_edid_block_valid(block, j, false, NULL)) + break; + } + + if (i == 4) + valid_extensions--; + } + + if (valid_extensions != hf_eeodb_blk_count - 1) { + DRM_ERROR("Not able to retrieve proper EDID contain HF-EEODB data.\n"); + goto out; + } }
return (struct edid *)edid; @@ -3315,15 +3344,17 @@ add_detailed_modes(struct drm_connector *connector, struct edid *edid, #define VIDEO_BLOCK 0x02 #define VENDOR_BLOCK 0x03 #define SPEAKER_BLOCK 0x04 -#define HDR_STATIC_METADATA_BLOCK 0x6 -#define USE_EXTENDED_TAG 0x07 -#define EXT_VIDEO_CAPABILITY_BLOCK 0x00 +#define EXT_VIDEO_CAPABILITY_BLOCK 0x00 +#define HDR_STATIC_METADATA_BLOCK 0x06 +#define USE_EXTENDED_TAG 0x07 #define EXT_VIDEO_DATA_BLOCK_420 0x0E -#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F +#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F +#define EXT_VIDEO_HF_EEODB_DATA_BLOCK 0x78 #define EDID_BASIC_AUDIO (1 << 6) #define EDID_CEA_YCRCB444 (1 << 5) #define EDID_CEA_YCRCB422 (1 << 4) #define EDID_CEA_VCDB_QS (1 << 6) +#define HF_EEODB_LENGTH 2
/* * Search EDID for CEA extension block. @@ -4274,9 +4305,41 @@ static bool cea_db_is_y420vdb(const u8 *db) return true; }
+static bool cea_db_is_hdmi_forum_eeodb(const u8 *db) +{ + if (cea_db_tag(db) != USE_EXTENDED_TAG) + return false; + + if (cea_db_payload_len(db) != HF_EEODB_LENGTH) + return false; + + if (cea_db_extended_tag(db) != EXT_VIDEO_HF_EEODB_DATA_BLOCK) + return false; + + return true; +} + #define for_each_cea_db(cea, i, start, end) \ for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
+size_t drm_edid_read_hf_eeodb_blk_count(const struct edid *edid) +{ + const u8 *cea; + int i, start, end, cea_ext_index = 0, displayid_ext_index = 0; + + if (edid->extensions) { + cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); + + if (cea && !cea_db_offsets(cea, &start, &end)) + for_each_cea_db(cea, i, start, end) + if (cea_db_is_hdmi_forum_eeodb(&cea[i])) + return cea[i + 2]; + } + + return 0; +} +EXPORT_SYMBOL_GPL(drm_edid_read_hf_eeodb_blk_count); + static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, const u8 *db) { diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 144c495b99c4..585f0ed932d4 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -593,5 +593,6 @@ drm_display_mode_from_cea_vic(struct drm_device *dev, const u8 *drm_find_edid_extension(const struct edid *edid, int ext_id, int *ext_index);
+size_t drm_edid_read_hf_eeodb_blk_count(const struct edid *edid);
#endif /* __DRM_EDID_H__ */
On Sun, 13 Mar 2022, Lee Shawn C shawn.c.lee@intel.com wrote:
According to HDMI 2.1 spec.
"The HDMI Forum EDID Extension Override Data Block (HF-EEODB) is utilized by Sink Devices to provide an alternate method to indicate an EDID Extension Block count larger than 1, while avoiding the need to present a VESA Block Map in the first E-EDID Extension Block."
It is a mandatory for HDMI 2.1 protocol compliance as well. This patch help to know how many HF_EEODB blocks report by sink and read allo HF_EEODB blocks back.
v2: support to find CEA block, check EEODB block format, and return available block number in drm_edid_read_hf_eeodb_blk_count().
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com
drivers/gpu/drm/drm_connector.c | 8 +++- drivers/gpu/drm/drm_edid.c | 71 +++++++++++++++++++++++++++++++-- include/drm/drm_edid.h | 1 + 3 files changed, 74 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index a50c82bc2b2f..16011023c12e 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -2129,7 +2129,7 @@ int drm_connector_update_edid_property(struct drm_connector *connector, const struct edid *edid) { struct drm_device *dev = connector->dev;
- size_t size = 0;
- size_t size = 0, hf_eeodb_blk_count; int ret; const struct edid *old_edid;
@@ -2137,8 +2137,12 @@ int drm_connector_update_edid_property(struct drm_connector *connector, if (connector->override_edid) return 0;
- if (edid)
- if (edid) { size = EDID_LENGTH * (1 + edid->extensions);
hf_eeodb_blk_count = drm_edid_read_hf_eeodb_blk_count(edid);
if (hf_eeodb_blk_count)
size = EDID_LENGTH * (1 + hf_eeodb_blk_count);
This approach does not scale. If the number of extensions and thus the total EDID size depend on HF-EEODB, this *must* be abstracted.
Consider, for example, drm_edid_duplicate(), which only looks at edid->extensions. A subsequent HF-EEODB aware access on an EDID duplicated using drm_edid_duplicate() will access beyond the allocated buffer.
Yes, it's a lot of work to introduce drm_edid_size() and drm_edid_extension_count() or similar, and use them everywhere, but this is what we must do. It's a lot more work to try to take HF-EEODB into account everywhere. The latter is going to be riddled with bugs with everyone doing it a little different.
}
/* Set the display info, using edid if available, otherwise
- resetting the values to defaults. This duplicates the work
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 9fa84881fbba..5ae4e83fa5e3 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1992,6 +1992,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, { int i, j = 0, valid_extensions = 0; u8 *edid, *new;
size_t hf_eeodb_blk_count; struct edid *override;
override = drm_get_override_edid(connector);
@@ -2051,7 +2052,35 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, }
kfree(edid);
return (struct edid *)new;
}
hf_eeodb_blk_count = drm_edid_read_hf_eeodb_blk_count((struct edid *)edid);
if (hf_eeodb_blk_count >= 2) {
new = krealloc(edid, (hf_eeodb_blk_count + 1) * EDID_LENGTH, GFP_KERNEL);
if (!new)
goto out;
edid = new;
valid_extensions = hf_eeodb_blk_count - 1;
for (j = 2; j <= hf_eeodb_blk_count; j++) {
u8 *block = edid + j * EDID_LENGTH;
for (i = 0; i < 4; i++) {
if (get_edid_block(data, block, j, EDID_LENGTH))
goto out;
if (drm_edid_block_valid(block, j, false, NULL))
break;
}
if (i == 4)
valid_extensions--;
}
if (valid_extensions != hf_eeodb_blk_count - 1) {
DRM_ERROR("Not able to retrieve proper EDID contain HF-EEODB data.\n");
goto out;
}
}
return (struct edid *)edid;
@@ -3315,15 +3344,17 @@ add_detailed_modes(struct drm_connector *connector, struct edid *edid, #define VIDEO_BLOCK 0x02 #define VENDOR_BLOCK 0x03 #define SPEAKER_BLOCK 0x04 -#define HDR_STATIC_METADATA_BLOCK 0x6 -#define USE_EXTENDED_TAG 0x07 -#define EXT_VIDEO_CAPABILITY_BLOCK 0x00 +#define EXT_VIDEO_CAPABILITY_BLOCK 0x00 +#define HDR_STATIC_METADATA_BLOCK 0x06 +#define USE_EXTENDED_TAG 0x07 #define EXT_VIDEO_DATA_BLOCK_420 0x0E -#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F +#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F +#define EXT_VIDEO_HF_EEODB_DATA_BLOCK 0x78 #define EDID_BASIC_AUDIO (1 << 6) #define EDID_CEA_YCRCB444 (1 << 5) #define EDID_CEA_YCRCB422 (1 << 4) #define EDID_CEA_VCDB_QS (1 << 6) +#define HF_EEODB_LENGTH 2
/*
- Search EDID for CEA extension block.
@@ -4274,9 +4305,41 @@ static bool cea_db_is_y420vdb(const u8 *db) return true; }
+static bool cea_db_is_hdmi_forum_eeodb(const u8 *db) +{
- if (cea_db_tag(db) != USE_EXTENDED_TAG)
return false;
- if (cea_db_payload_len(db) != HF_EEODB_LENGTH)
return false;
- if (cea_db_extended_tag(db) != EXT_VIDEO_HF_EEODB_DATA_BLOCK)
return false;
- return true;
+}
#define for_each_cea_db(cea, i, start, end) \ for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
+size_t drm_edid_read_hf_eeodb_blk_count(const struct edid *edid) +{
- const u8 *cea;
- int i, start, end, cea_ext_index = 0, displayid_ext_index = 0;
- if (edid->extensions) {
cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index);
if (cea && !cea_db_offsets(cea, &start, &end))
for_each_cea_db(cea, i, start, end)
if (cea_db_is_hdmi_forum_eeodb(&cea[i]))
return cea[i + 2];
- }
- return 0;
+} +EXPORT_SYMBOL_GPL(drm_edid_read_hf_eeodb_blk_count);
This should be static and not exported.
BR, Jani.
static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, const u8 *db) { diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 144c495b99c4..585f0ed932d4 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -593,5 +593,6 @@ drm_display_mode_from_cea_vic(struct drm_device *dev, const u8 *drm_find_edid_extension(const struct edid *edid, int ext_id, int *ext_index);
+size_t drm_edid_read_hf_eeodb_blk_count(const struct edid *edid);
#endif /* __DRM_EDID_H__ */
On Tuesday, March 15, 2022 7:03 PM, Nikula, Jani jani.nikula@intel.com wrote:
On Sun, 13 Mar 2022, Lee Shawn C shawn.c.lee@intel.com wrote:
According to HDMI 2.1 spec.
"The HDMI Forum EDID Extension Override Data Block (HF-EEODB) is utilized by Sink Devices to provide an alternate method to indicate an EDID Extension Block count larger than 1, while avoiding the need to present a VESA Block Map in the first E-EDID Extension Block."
It is a mandatory for HDMI 2.1 protocol compliance as well. This patch help to know how many HF_EEODB blocks report by sink and read allo HF_EEODB blocks back.
v2: support to find CEA block, check EEODB block format, and return available block number in drm_edid_read_hf_eeodb_blk_count().
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com
drivers/gpu/drm/drm_connector.c | 8 +++- drivers/gpu/drm/drm_edid.c | 71 +++++++++++++++++++++++++++++++-- include/drm/drm_edid.h | 1 + 3 files changed, 74 insertions(+), 6 deletions(-)
diff --git a/drivers/gpu/drm/drm_connector.c b/drivers/gpu/drm/drm_connector.c index a50c82bc2b2f..16011023c12e 100644 --- a/drivers/gpu/drm/drm_connector.c +++ b/drivers/gpu/drm/drm_connector.c @@ -2129,7 +2129,7 @@ int drm_connector_update_edid_property(struct drm_connector *connector, const struct edid *edid) { struct drm_device *dev = connector->dev;
- size_t size = 0;
- size_t size = 0, hf_eeodb_blk_count; int ret; const struct edid *old_edid;
@@ -2137,8 +2137,12 @@ int drm_connector_update_edid_property(struct drm_connector *connector, if (connector->override_edid) return 0;
- if (edid)
- if (edid) { size = EDID_LENGTH * (1 + edid->extensions);
hf_eeodb_blk_count = drm_edid_read_hf_eeodb_blk_count(edid);
if (hf_eeodb_blk_count)
size = EDID_LENGTH * (1 + hf_eeodb_blk_count);
This approach does not scale. If the number of extensions and thus the total EDID size depend on HF-EEODB, this *must* be abstracted.
Consider, for example, drm_edid_duplicate(), which only looks at edid->extensions. A subsequent HF-EEODB aware access on an EDID duplicated using drm_edid_duplicate() will access beyond the allocated buffer.
Yes, it's a lot of work to introduce drm_edid_size() and drm_edid_extension_count() or similar, and use them everywhere, but this is what we must do. It's a lot more work to try to take HF-EEODB into account everywhere. The latter is going to be riddled with bugs with everyone doing it a little different.
As you mentioned, we should have new functions to provide proper EDID byte size or extension counter. And reuse them to handle/retrieve EDID more accurately in drm driver. Thanks for your comment!
}
/* Set the display info, using edid if available, otherwise
- resetting the values to defaults. This duplicates the work diff
--git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 9fa84881fbba..5ae4e83fa5e3 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1992,6 +1992,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, { int i, j = 0, valid_extensions = 0; u8 *edid, *new;
size_t hf_eeodb_blk_count; struct edid *override;
override = drm_get_override_edid(connector); @@ -2051,7 +2052,35 @@
struct edid *drm_do_get_edid(struct drm_connector *connector, }
kfree(edid);
return (struct edid *)new;
}
hf_eeodb_blk_count = drm_edid_read_hf_eeodb_blk_count((struct edid *)edid);
if (hf_eeodb_blk_count >= 2) {
new = krealloc(edid, (hf_eeodb_blk_count + 1) * EDID_LENGTH, GFP_KERNEL);
if (!new)
goto out;
edid = new;
valid_extensions = hf_eeodb_blk_count - 1;
for (j = 2; j <= hf_eeodb_blk_count; j++) {
u8 *block = edid + j * EDID_LENGTH;
for (i = 0; i < 4; i++) {
if (get_edid_block(data, block, j, EDID_LENGTH))
goto out;
if (drm_edid_block_valid(block, j, false, NULL))
break;
}
if (i == 4)
valid_extensions--;
}
if (valid_extensions != hf_eeodb_blk_count - 1) {
DRM_ERROR("Not able to retrieve proper EDID contain HF-EEODB data.\n");
goto out;
}
}
return (struct edid *)edid;
@@ -3315,15 +3344,17 @@ add_detailed_modes(struct drm_connector *connector, struct edid *edid, #define VIDEO_BLOCK 0x02 #define VENDOR_BLOCK 0x03 #define SPEAKER_BLOCK 0x04 -#define HDR_STATIC_METADATA_BLOCK 0x6 -#define USE_EXTENDED_TAG 0x07 -#define EXT_VIDEO_CAPABILITY_BLOCK 0x00 +#define EXT_VIDEO_CAPABILITY_BLOCK 0x00 +#define HDR_STATIC_METADATA_BLOCK 0x06 +#define USE_EXTENDED_TAG 0x07 #define EXT_VIDEO_DATA_BLOCK_420 0x0E -#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F +#define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F +#define EXT_VIDEO_HF_EEODB_DATA_BLOCK 0x78 #define EDID_BASIC_AUDIO (1 << 6) #define EDID_CEA_YCRCB444 (1 << 5) #define EDID_CEA_YCRCB422 (1 << 4) #define EDID_CEA_VCDB_QS (1 << 6) +#define HF_EEODB_LENGTH 2
/*
- Search EDID for CEA extension block.
@@ -4274,9 +4305,41 @@ static bool cea_db_is_y420vdb(const u8 *db) return true; }
+static bool cea_db_is_hdmi_forum_eeodb(const u8 *db) {
- if (cea_db_tag(db) != USE_EXTENDED_TAG)
return false;
- if (cea_db_payload_len(db) != HF_EEODB_LENGTH)
return false;
- if (cea_db_extended_tag(db) != EXT_VIDEO_HF_EEODB_DATA_BLOCK)
return false;
- return true;
+}
#define for_each_cea_db(cea, i, start, end) \ for ((i) = (start); (i) < (end) && (i) + cea_db_payload_len(&(cea)[(i)]) < (end); (i) += cea_db_payload_len(&(cea)[(i)]) + 1)
+size_t drm_edid_read_hf_eeodb_blk_count(const struct edid *edid) {
- const u8 *cea;
- int i, start, end, cea_ext_index = 0, displayid_ext_index = 0;
- if (edid->extensions) {
cea = drm_find_cea_extension(edid, &cea_ext_index,
+&displayid_ext_index);
if (cea && !cea_db_offsets(cea, &start, &end))
for_each_cea_db(cea, i, start, end)
if (cea_db_is_hdmi_forum_eeodb(&cea[i]))
return cea[i + 2];
- }
- return 0;
+} +EXPORT_SYMBOL_GPL(drm_edid_read_hf_eeodb_blk_count);
This should be static and not exported.
BR, Jani.
static void drm_parse_y420cmdb_bitmap(struct drm_connector *connector, const u8 *db) { diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 144c495b99c4..585f0ed932d4 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -593,5 +593,6 @@ drm_display_mode_from_cea_vic(struct drm_device *dev, const u8 *drm_find_edid_extension(const struct edid *edid, int ext_id, int *ext_index);
+size_t drm_edid_read_hf_eeodb_blk_count(const struct edid *edid);
#endif /* __DRM_EDID_H__ */
-- Jani Nikula, Intel Open Source Graphics Center
While adding CEA modes, try to get available EEODB block number. Then based on it to parse numbers of ext blocks, retrieve CEA information and add more CEA modes.
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com --- drivers/gpu/drm/drm_displayid.c | 5 ++- drivers/gpu/drm/drm_edid.c | 68 +++++++++++++++++++++++++-------- include/drm/drm_edid.h | 2 +- 3 files changed, 58 insertions(+), 17 deletions(-)
diff --git a/drivers/gpu/drm/drm_displayid.c b/drivers/gpu/drm/drm_displayid.c index 31c3e6d7d549..a769c55146f4 100644 --- a/drivers/gpu/drm/drm_displayid.c +++ b/drivers/gpu/drm/drm_displayid.c @@ -37,7 +37,10 @@ static const u8 *drm_find_displayid_extension(const struct edid *edid, int *length, int *idx, int *ext_index) { - const u8 *displayid = drm_find_edid_extension(edid, DISPLAYID_EXT, ext_index); + const u8 *displayid = drm_find_edid_extension(edid, + DISPLAYID_EXT, + ext_index, + edid->extensions); const struct displayid_header *base; int ret;
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 5ae4e83fa5e3..5de85ba20bdf 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -3360,23 +3360,25 @@ add_detailed_modes(struct drm_connector *connector, struct edid *edid, * Search EDID for CEA extension block. */ const u8 *drm_find_edid_extension(const struct edid *edid, - int ext_id, int *ext_index) + int ext_id, + int *ext_index, + int ext_blk_num) { const u8 *edid_ext = NULL; int i;
/* No EDID or EDID extensions */ - if (edid == NULL || edid->extensions == 0) + if (edid == NULL || edid->extensions == 0 || *ext_index >= ext_blk_num) return NULL;
/* Find CEA extension */ - for (i = *ext_index; i < edid->extensions; i++) { + for (i = *ext_index; i < ext_blk_num; i++) { edid_ext = (const u8 *)edid + EDID_LENGTH * (i + 1); if (edid_ext[0] == ext_id) break; }
- if (i >= edid->extensions) + if (i >= ext_blk_num) return NULL;
*ext_index = i + 1; @@ -3385,14 +3387,19 @@ const u8 *drm_find_edid_extension(const struct edid *edid, }
static const u8 *drm_find_cea_extension(const struct edid *edid, - int *cea_ext_index, int *displayid_ext_index) + int *cea_ext_index, + int *displayid_ext_index, + int ext_blk_num) { const struct displayid_block *block; struct displayid_iter iter; const u8 *cea;
/* Look for a CEA extension block from ext_index */ - cea = drm_find_edid_extension(edid, CEA_EXT, cea_ext_index); + cea = drm_find_edid_extension(edid, + CEA_EXT, + cea_ext_index, + ext_blk_num); if (cea) return cea;
@@ -3676,7 +3683,10 @@ add_alternate_cea_modes(struct drm_connector *connector, struct edid *edid) int modes = 0, cea_ext_index = 0, displayid_ext_index = 0;
/* Don't add CEA modes if the CEA extension block is missing */ - if (!drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index)) + if (!drm_find_cea_extension(edid, + &cea_ext_index, + &displayid_ext_index, + edid->extensions)) return 0;
/* @@ -4328,7 +4338,10 @@ size_t drm_edid_read_hf_eeodb_blk_count(const struct edid *edid) int i, start, end, cea_ext_index = 0, displayid_ext_index = 0;
if (edid->extensions) { - cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); + cea = drm_find_cea_extension(edid, + &cea_ext_index, + &displayid_ext_index, + edid->extensions);
if (cea && !cea_db_offsets(cea, &start, &end)) for_each_cea_db(cea, i, start, end) @@ -4384,13 +4397,20 @@ static int add_cea_modes(struct drm_connector *connector, struct edid *edid) { int modes = 0, cea_ext_index = 0, displayid_ext_index = 0; + int ext_blk_num = drm_edid_read_hf_eeodb_blk_count(edid); + + if (!ext_blk_num) + ext_blk_num = edid->extensions;
for (;;) { const u8 *cea, *db, *hdmi = NULL, *video = NULL; u8 dbl, hdmi_len = 0, video_len = 0; int i, start, end;
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); + cea = drm_find_cea_extension(edid, + &cea_ext_index, + &displayid_ext_index, + ext_blk_num); if (!cea) break;
@@ -4640,7 +4660,10 @@ static void drm_edid_to_eld(struct drm_connector *connector, struct edid *edid) if (!edid) return;
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); + cea = drm_find_cea_extension(edid, + &cea_ext_index, + &displayid_ext_index, + edid->extensions); if (!cea) { DRM_DEBUG_KMS("ELD: no CEA Extension found\n"); return; @@ -4729,7 +4752,10 @@ int drm_edid_to_sad(struct edid *edid, struct cea_sad **sads) int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); + cea = drm_find_cea_extension(edid, + &cea_ext_index, + &displayid_ext_index, + edid->extensions); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0; @@ -4792,7 +4818,10 @@ int drm_edid_to_speaker_allocation(struct edid *edid, u8 **sadb) int cea_ext_index = 0, displayid_ext_index = 0; const u8 *cea;
- cea = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); + cea = drm_find_cea_extension(edid, + &cea_ext_index, + &displayid_ext_index, + edid->extensions); if (!cea) { DRM_DEBUG_KMS("SAD: no CEA Extension found\n"); return 0; @@ -4888,7 +4917,10 @@ bool drm_detect_hdmi_monitor(struct edid *edid) int start_offset, end_offset; int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); + edid_ext = drm_find_cea_extension(edid, + &cea_ext_index, + &displayid_ext_index, + edid->extensions); if (!edid_ext) return false;
@@ -4928,7 +4960,10 @@ bool drm_detect_monitor_audio(struct edid *edid) int start_offset, end_offset; int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); + edid_ext = drm_find_cea_extension(edid, + &cea_ext_index, + &displayid_ext_index, + edid->extensions); if (!edid_ext) goto end;
@@ -5253,7 +5288,10 @@ static void drm_parse_cea_ext(struct drm_connector *connector, int i, start, end; int cea_ext_index = 0, displayid_ext_index = 0;
- edid_ext = drm_find_cea_extension(edid, &cea_ext_index, &displayid_ext_index); + edid_ext = drm_find_cea_extension(edid, + &cea_ext_index, + &displayid_ext_index, + edid->extensions); if (!edid_ext) return;
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index 585f0ed932d4..fa06f9a468c4 100644 --- a/include/drm/drm_edid.h +++ b/include/drm/drm_edid.h @@ -591,7 +591,7 @@ struct drm_display_mode * drm_display_mode_from_cea_vic(struct drm_device *dev, u8 video_code); const u8 *drm_find_edid_extension(const struct edid *edid, - int ext_id, int *ext_index); + int ext_id, int *ext_index, int ext_blk_num);
size_t drm_edid_read_hf_eeodb_blk_count(const struct edid *edid);
Find HF-SCDB information in CEA extensions block. And retrieve Max_TMDS_Character_Rate that support by sink device.
v2: HF-SCDB and HF-VSDBS carry the same SCDS data. Reuse drm_parse_hdmi_forum_vsdb() to parse this packet.
Cc: Jani Nikula jani.nikula@linux.intel.com Cc: Ville Syrjala ville.syrjala@linux.intel.com Cc: Ankit Nautiyal ankit.k.nautiyal@intel.com Cc: Drew Davenport ddavenport@chromium.org Cc: intel-gfx intel-gfx@lists.freedesktop.org Signed-off-by: Lee Shawn C shawn.c.lee@intel.com --- drivers/gpu/drm/drm_edid.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 5de85ba20bdf..351a729bddb6 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -3350,6 +3350,7 @@ add_detailed_modes(struct drm_connector *connector, struct edid *edid, #define EXT_VIDEO_DATA_BLOCK_420 0x0E #define EXT_VIDEO_CAP_BLOCK_Y420CMDB 0x0F #define EXT_VIDEO_HF_EEODB_DATA_BLOCK 0x78 +#define EXT_VIDEO_HF_SCDB_DATA_BLOCK 0x79 #define EDID_BASIC_AUDIO (1 << 6) #define EDID_CEA_YCRCB444 (1 << 5) #define EDID_CEA_YCRCB422 (1 << 4) @@ -4287,6 +4288,20 @@ static bool cea_db_is_vcdb(const u8 *db) return true; }
+static bool cea_db_is_hdmi_forum_scdb(const u8 *db) +{ + if (cea_db_tag(db) != USE_EXTENDED_TAG) + return false; + + if (cea_db_payload_len(db) < 7) + return false; + + if (cea_db_extended_tag(db) != EXT_VIDEO_HF_SCDB_DATA_BLOCK) + return false; + + return true; +} + static bool cea_db_is_y420cmdb(const u8 *db) { if (cea_db_tag(db) != USE_EXTENDED_TAG) @@ -5312,7 +5327,8 @@ static void drm_parse_cea_ext(struct drm_connector *connector,
if (cea_db_is_hdmi_vsdb(db)) drm_parse_hdmi_vsdb_video(connector, db); - if (cea_db_is_hdmi_forum_vsdb(db)) + if (cea_db_is_hdmi_forum_vsdb(db) || + cea_db_is_hdmi_forum_scdb(db)) drm_parse_hdmi_forum_vsdb(connector, db); if (cea_db_is_microsoft_vsdb(db)) drm_parse_microsoft_vsdb(connector, db);
dri-devel@lists.freedesktop.org