drm/amd/display: more DRM edid common-code to the display driver
Subsystems (3)
cover drm/amd/display: more DRM edid common-code to the display driver
Hi,
I've been working on a new version of [1] that ports the AMD display driver to use the common drm_edid code instead of open and raw edid handling.
The part of the previous series that didn't make the cut was to replace the open coded edid parser with drm_edid_product_id and eld data. However, when addressing feedback I ran into a design issue in the latest version because I was trying to not add any Linux-specific code to the DC code, specifically, DC link detection. In short, we have a few paths in the DM code that allocate a temporary drm_edid, go to the DC, and back to the DM to handle drm_edid data. In the last version, I was storing this temporary drm_edid in the aconnector, but it was erroneously overriding a still in use drm_edid.
In this new version I allocate a temporary drm_edid in the DM parser from raw edid data stored in dc_edid, which was actually extracted from another drm_edid in the previous DM caller. This is a workaround to bypass DC boundaries and parse edid capabilities, but I think we can do better if we can find a clean way to pass the drm_edid through this kind of DM -> DC -> DM paths.
I checked working on top of Thomas' work[2] that replaces dc_edid by drm_edid and adds this DRM struct and its helpers inside DC. The resulted changes work stable and as expected[3], but I believe that adding linux-specific code to DC is not desirable.
Siqueira and I have discussed other alternatives, such as updating the DC code to match drm_edid structs or checking how well the change in this series could work with drm_edid as a private obj[4], however we would like to know AMD team's opinion before making this big effort (and probably noisy change). The main goal here is removing drm_edid_raw calls and duplicated code to handle edid in DC/link_detection that can take advantage of DRM common-code instead.
Please, let me know your thoughts.
Melissa
[1] https://lore.kernel.org/amd-gfx/[email protected]/
[2] https://lore.kernel.org/amd-gfx/[email protected]/
[3] https://gitlab.freedesktop.org/mwen/linux-amd/-/commits/drm_edid_product_id_v4
[4] https://gitlab.freedesktop.org/mwen/linux-amd/-/commits/drm_edid_priv
Melissa Wen (7):
drm/amd/display: make sure drm_edid stored in aconnector doesn't leak drm/amd/display: start using drm_edid helpers to parse EDID caps drm/amd/display: use drm_edid_product_id for parsing EDID product info drm/amd/display: parse display name from drm_eld drm/amd/display: get panel id with drm_edid helper drm/amd/display: get SAD from drm_eld when parsing EDID caps drm/amd/display: get SADB from drm_eld when parsing EDID caps
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 + .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 85 +++++++++---------- 2 files changed, 42 insertions(+), 45 deletions(-)
Signature · 1 line
2.47.2
RFC PATCH 1/7 drm/amd/display: make sure drm_edid stored in aconnector doesn't leak
Make sure the drm_edid container stored in aconnector is freed when detroying the aconnector.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +2 -0
@@ -7271,6 +7271,8 @@ static void amdgpu_dm_connector_destroy(struct drm_connector *connector)dc_sink_release (aconnector->dc_sink); aconnector->dc_sink =NULL ; +drm_edid_free (aconnector->drm_edid); +drm_dp_cec_unregister_connector (&aconnector->dm_dp_aux.aux);drm_connector_unregister (connector);drm_connector_cleanup (connector);
Signature · 1 line
2.47.2
RFC PATCH 2/7 drm/amd/display: start using drm_edid helpers to parse EDID caps
In reply to Melissa WenGroundwork that allocates a temporary drm_edid from raw edid to take advantage of DRM common-code helpers instead of driver-specific code.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +9 -2
@@ -108,6 +108,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(struct drm_connector *connector = &aconnector->base;struct drm_device *dev = connector->dev;struct edid *edid_buf = edid ? (struct edid *) edid->raw_edid :NULL ; +struct drm_edid *drm_edid;struct cea_sad *sads;int sad_count =-1 ;int sadb_count =-1 ;
@@ -116,10 +117,13 @@ enum dc_edid_status dm_helpers_parse_edid_caps(enum dc_edid_status result =EDID_OK ; +if (!edid_caps || !edid)return EDID_BAD_INPUT ; -if (!drm_edid_is_valid (edid_buf)) + drm_edid =drm_edid_alloc (edid_buf,EDID_LENGTH * (edid_buf->extensions +1 )); + +if (!drm_edid_valid (drm_edid)) result =EDID_BAD_CHECKSUM ; edid_caps->manufacturer_id = (uint16_t) edid_buf->mfg_id[0] |
@@ -139,8 +143,10 @@ enum dc_edid_status dm_helpers_parse_edid_caps(apply_edid_quirks (dev, edid_buf, edid_caps); sad_count =drm_edid_to_sad ((struct edid *) edid->raw_edid, &sads); -if (sad_count <=0 ) +if (sad_count <=0 ) { +drm_edid_free (drm_edid);return result; + } edid_caps->audio_mode_count =min (sad_count,DC_MAX_AUDIO_DESC_COUNT );for (i =0 ; i < edid_caps->audio_mode_count; ++i) {
@@ -166,6 +172,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(kfree (sads);kfree (sadb); +drm_edid_free (drm_edid);return result; }
Signature · 1 line
2.47.2
Re: [RFC PATCH 2/7] drm/amd/display: start using drm_edid helpers to parse EDID caps
Quoted 13 lines · Melissa Wen
Groundwork that allocates a temporary
drm_edidfrom raw edid to take advantage of DRM common-code helpers instead of driver-specific code.Signed-off-by Melissa Wen <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +0
-0
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c enum dc_edid_status dm_helpers_parse_edid_caps( · line 111
Quoted 4 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +1
-0@@ -108,6 +108,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(struct drm_connector *connector = &aconnector->base;struct drm_device *dev = connector->dev;struct edid *edid_buf = edid ? (struct edid *) edid->raw_edid :NULL ; +struct drm_edid *drm_edid;
This declaration generates the below build warning:
drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_helpers.c: In function ‘dm_helpers_parse_edid_caps’:drivers/gpu/drm/amd/amdgpu/../display/amdgpu_dm/amdgpu_dm_helpers.c:116:18: error: assignment discards ‘const’ qualifier from pointer target type [-Werror=discarded-qualifiers]
116 | drm_edid = drm_edid_alloc(edid_buf, EDID_LENGTH *
(edid_buf->extensions + 1));
| ^
cc1: all warnings being treated as errors
It can be fixed as the following change
- struct drm_edid *drm_edid;
+ const struct drm_edid *drm_edid;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c enum dc_edid_status dm_helpers_parse_edid_caps( · line 124
Quoted 13 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +2
-1struct cea_sad *sads;int sad_count =-1 ;int sadb_count =-1 ;@@ -116,10 +117,13 @@ enum dc_edid_status dm_helpers_parse_edid_caps(enum dc_edid_status result =EDID_OK ; +if (!edid_caps || !edid)return EDID_BAD_INPUT ; -if (!drm_edid_is_valid (edid_buf)) + drm_edid =drm_edid_alloc (edid_buf,EDID_LENGTH * (edid_buf->extensions +1 ));
drm_edid_alloc returns "const struct drm_edid *", so drm_edid needs to be const as well.
Quoted 25 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +6
-1+ +if (!drm_edid_valid (drm_edid)) result =EDID_BAD_CHECKSUM ; edid_caps->manufacturer_id = (uint16_t) edid_buf->mfg_id[0] |@@ -139,8 +143,10 @@ enum dc_edid_status dm_helpers_parse_edid_caps(apply_edid_quirks (dev, edid_buf, edid_caps); sad_count =drm_edid_to_sad ((struct edid *) edid->raw_edid, &sads); -if (sad_count <=0 ) +if (sad_count <=0 ) { +drm_edid_free (drm_edid);return result; + } edid_caps->audio_mode_count =min (sad_count,DC_MAX_AUDIO_DESC_COUNT );for (i =0 ; i < edid_caps->audio_mode_count; ++i) {@@ -166,6 +172,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(kfree (sads);kfree (sadb); +drm_edid_free (drm_edid);return result; }
RFC PATCH 3/7 drm/amd/display: use drm_edid_product_id for parsing EDID product info
In reply to Melissa WenSince [1], we can use drm_edid_product_id to get debug info from drm_edid instead of directly parsing EDID.
--- .../drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +8 -7
@@ -109,6 +109,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(struct drm_device *dev = connector->dev;struct edid *edid_buf = edid ? (struct edid *) edid->raw_edid :NULL ;struct drm_edid *drm_edid; +struct drm_edid_product_id product_id;struct cea_sad *sads;int sad_count =-1 ;int sadb_count =-1 ;
@@ -126,13 +127,13 @@ enum dc_edid_status dm_helpers_parse_edid_caps(if (!drm_edid_valid (drm_edid)) result =EDID_BAD_CHECKSUM ; - edid_caps->manufacturer_id = (uint16_t ) edid_buf->mfg_id[0 ] | - ((uint16_t ) edid_buf->mfg_id[1 ])<<8 ; - edid_caps->product_id = (uint16_t ) edid_buf->prod_code[0 ] | - ((uint16_t ) edid_buf->prod_code[1 ])<<8 ; - edid_caps->serial_number = edid_buf->serial; - edid_caps->manufacture_week = edid_buf->mfg_week; - edid_caps->manufacture_year = edid_buf->mfg_year; +drm_edid_get_product_id (drm_edid, &product_id); + + edid_caps->manufacturer_id =le16_to_cpu (product_id.manufacturer_name); + edid_caps->product_id =le16_to_cpu (product_id.product_code); + edid_caps->serial_number =le32_to_cpu (product_id.serial_number); + edid_caps->manufacture_week = product_id.week_of_manufacture; + edid_caps->manufacture_year = product_id.year_of_manufacture; drm_edid_get_monitor_name(edid_buf, edid_caps->display_name,
Signature · 1 line
2.47.2
RFC PATCH 4/7 drm/amd/display: parse display name from drm_eld
In reply to Melissa WenWe don't need to parse dc_edid to get the display name since it's already set in drm_eld which in turn had it values updated when updating connector with the opaque drm_edid.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +6 -4
@@ -34,7 +34,7 @@#include <drm/amdgpu_drm.h> #include <drm/drm_edid.h> #include <drm/drm_fixed.h> - +#include <drm/drm_eld.h> #include "dm_services.h" #include "amdgpu.h" #include "dc.h"
@@ -90,6 +90,7 @@ static void apply_edid_quirks(struct drm_device *dev, struct edid *edid, struct } } +#define AMDGPU_ELD_DISPLAY_NAME_SIZE_IN_CHARS 13/** * dm_helpers_parse_edid_caps() - Parse edid caps *
@@ -135,9 +136,10 @@ enum dc_edid_status dm_helpers_parse_edid_caps( edid_caps->manufacture_week = product_id.week_of_manufacture; edid_caps->manufacture_year = product_id.year_of_manufacture; -drm_edid_get_monitor_name (edid_buf, - edid_caps->display_name, -AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS ); +memset (edid_caps->display_name,0 ,AUDIO_INFO_DISPLAY_NAME_SIZE_IN_CHARS ); +memcpy (edid_caps->display_name, + &connector->eld[DRM_ELD_MONITOR_NAME_STRING ], +AMDGPU_ELD_DISPLAY_NAME_SIZE_IN_CHARS ); edid_caps->edid_hdmi = connector->display_info.is_hdmi;
Signature · 1 line
2.47.2
RFC PATCH 5/7 drm/amd/display: get panel id with drm_edid helper
In reply to Melissa WenInstead of using driver-specific code, use DRM helpers.
--- .../drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +5 -10
@@ -48,16 +48,11 @@#include "ddc_service_types.h" #include "clk_mgr.h" -static u32 edid_extract_panel_id (struct edid *edid) +static void apply_edid_quirks (struct drm_device *dev, +const struct drm_edid *drm_edid, +struct dc_edid_caps *edid_caps) { -return (u32 )edid->mfg_id[0 ] <<24 | - (u32 )edid->mfg_id[1 ] <<16 | - (u32 )EDID_PRODUCT_ID (edid); -} - -static void apply_edid_quirks (struct drm_device *dev,struct edid *edid,struct dc_edid_caps *edid_caps) -{ -uint32_t panel_id =edid_extract_panel_id (edid); +uint32_t panel_id =drm_edid_get_panel_id (drm_edid);switch (panel_id) {/* Workaround for monitors that need a delay after detecting the link */
@@ -143,7 +138,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps( edid_caps->edid_hdmi = connector->display_info.is_hdmi; -apply_edid_quirks (dev, edid_buf, edid_caps); +apply_edid_quirks (dev, drm_edid, edid_caps); sad_count =drm_edid_to_sad ((struct edid *) edid->raw_edid, &sads);if (sad_count <=0 ) {
Signature · 1 line
2.47.2
RFC PATCH 6/7 drm/amd/display: get SAD from drm_eld when parsing EDID caps
In reply to Melissa Wendrm_edid_connector_update() updates display info, filling ELD with audio info from Short-Audio Descriptors in the last step of update_dislay_info(). Our goal is stopping using raw edid, so we can extract SAD from drm_eld instead of access raw edid to get audio caps.
--- .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +11 -10
@@ -106,9 +106,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(struct edid *edid_buf = edid ? (struct edid *) edid->raw_edid :NULL ;struct drm_edid *drm_edid;struct drm_edid_product_id product_id; -struct cea_sad *sads; -int sad_count =-1 ; -int sadb_count =-1 ; +int sad_count, sadb_count;int i =0 ;uint8_t *sadb =NULL ;
@@ -123,6 +121,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(if (!drm_edid_valid (drm_edid)) result =EDID_BAD_CHECKSUM ; +drm_edid_connector_update (connector, drm_edid);drm_edid_get_product_id (drm_edid, &product_id); edid_caps->manufacturer_id =le16_to_cpu (product_id.manufacturer_name);
@@ -140,7 +139,7 @@ enum dc_edid_status dm_helpers_parse_edid_caps(apply_edid_quirks (dev, drm_edid, edid_caps); - sad_count =drm_edid_to_sad ((struct edid *) edid->raw_edid, &sads); + sad_count =drm_eld_sad_count (connector->eld);if (sad_count <=0 ) {drm_edid_free (drm_edid);return result;
@@ -148,12 +147,15 @@ enum dc_edid_status dm_helpers_parse_edid_caps( edid_caps->audio_mode_count =min (sad_count,DC_MAX_AUDIO_DESC_COUNT );for (i =0 ; i < edid_caps->audio_mode_count; ++i) { -struct cea_sad *sad = &sads[i]; +struct cea_sad sad; - edid_caps->audio_modes[i].format_code = sad->format; - edid_caps->audio_modes[i].channel_count = sad->channels +1 ; - edid_caps->audio_modes[i].sample_rate = sad->freq; - edid_caps->audio_modes[i].sample_size = sad->byte2; +if (drm_eld_sad_get (connector->eld, i, &sad) <0 ) +continue ; + + edid_caps->audio_modes[i].format_code = sad.format; + edid_caps->audio_modes[i].channel_count = sad.channels +1 ; + edid_caps->audio_modes[i].sample_rate = sad.freq; + edid_caps->audio_modes[i].sample_size = sad.byte2; } sadb_count =drm_edid_to_speaker_allocation ((struct edid *) edid->raw_edid, &sadb);
@@ -168,7 +170,6 @@ enum dc_edid_status dm_helpers_parse_edid_caps(else edid_caps->speaker_flags =DEFAULT_SPEAKER_LOCATION ; -kfree (sads);kfree (sadb);drm_edid_free (drm_edid);
Signature · 1 line
2.47.2
RFC PATCH 7/7 drm/amd/display: get SADB from drm_eld when parsing EDID caps
In reply to Melissa Wendrm_edid_connector_update() updates display info, filling ELD with speaker allocation data in the last step of update_dislay_info(). Our goal is stopping using raw edid, so we can extract SADB from drm_eld instead of access raw edid to get audio caps.
--- .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c +3 -14
@@ -106,13 +106,10 @@ enum dc_edid_status dm_helpers_parse_edid_caps(struct edid *edid_buf = edid ? (struct edid *) edid->raw_edid :NULL ;struct drm_edid *drm_edid;struct drm_edid_product_id product_id; -int sad_count, sadb_count; +int sad_count;int i =0 ; -uint8_t *sadb =NULL ; -enum dc_edid_status result =EDID_OK ; -if (!edid_caps || !edid)return EDID_BAD_INPUT ;
@@ -158,19 +155,11 @@ enum dc_edid_status dm_helpers_parse_edid_caps( edid_caps->audio_modes[i].sample_size = sad.byte2; } - sadb_count =drm_edid_to_speaker_allocation ((struct edid *) edid->raw_edid, &sadb); - -if (sadb_count <0 ) { -DRM_ERROR ("Couldn't read Speaker Allocation Data Block: %d\n" , sadb_count); - sadb_count =0 ; - } - -if (sadb_count) - edid_caps->speaker_flags = sadb[0 ]; +if (connector->eld[DRM_ELD_SPEAKER ]) + edid_caps->speaker_flags = connector->eld[DRM_ELD_SPEAKER ];else edid_caps->speaker_flags =DEFAULT_SPEAKER_LOCATION ; -kfree (sadb);drm_edid_free (drm_edid);return result;
Signature · 1 line
2.47.2
The series look fine to me, except one small error in patch 2. I can send this series to promotion tests once the error is addressed. Let me also check others for comments.
Hi Harry and Leo,
Do you have other concerns before I sent this series to promotion tests?
Quoted 58 lines · Melissa Wen
Hi,
I've been working on a new version of [1] that ports the AMD display driver to use the common
drm_edidcode instead of open and raw edid handling.The part of the previous series that didn't make the cut was to replace the open coded edid parser with
drm_edid_product_idandelddata. However, when addressing feedback I ran into a design issue in the latest version because I was trying to not add any Linux-specific code to the DC code, specifically, DC link detection. In short, we have a few paths in the DM code that allocate a temporarydrm_edid, go to the DC, and back to the DM to handledrm_ediddata. In the last version, I was storing this temporarydrm_edidin the aconnector, but it was erroneously overriding a still in usedrm_edid.In this new version I allocate a temporary
drm_edidin the DM parser from raw edid data stored indc_edid, which was actually extracted from anotherdrm_edidin the previous DM caller. This is a workaround to bypass DC boundaries and parse edid capabilities, but I think we can do better if we can find a clean way to pass thedrm_edidthrough this kind of DM -> DC -> DM paths.I checked working on top of Thomas' work[2] that replaces
dc_edidbydrm_edidand adds this DRM struct and its helpers inside DC. The resulted changes work stable and as expected[3], but I believe that adding linux-specific code to DC is not desirable.Siqueira and I have discussed other alternatives, such as updating the DC code to match
drm_edidstructs or checking how well the change in this series could work withdrm_edidas a private obj[4], however we would like to know AMD team's opinion before making this big effort (and probably noisy change). The main goal here is removingdrm_edid_rawcalls and duplicated code to handle edid in DC/link_detection that can take advantage of DRM common-code instead.Please, let me know your thoughts.
Melissa
[1] https://lore.kernel.org/amd-gfx/[email protected]/
[2] https://lore.kernel.org/amd-gfx/[email protected]/
[3] https://gitlab.freedesktop.org/mwen/linux-amd/-/commits/drm_edid_product_id_v4
[4] https://gitlab.freedesktop.org/mwen/linux-amd/-/commits/drm_edid_privMelissa Wen (7):
drm/amd/display: make suredrm_edidstored in aconnector doesn't leak drm/amd/display: start usingdrm_edidhelpers to parse EDID caps drm/amd/display: usedrm_edid_product_idfor parsing EDID product info drm/amd/display: parse display name fromdrm_elddrm/amd/display: get panel id withdrm_edidhelper drm/amd/display: get SAD fromdrm_eldwhen parsing EDID caps drm/amd/display: get SADB fromdrm_eldwhen parsing EDID caps.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 2 + .../amd/display/amdgpu_dm/amdgpu_dm_helpers.c | 85 +++++++++---------- 2 files changed, 42 insertions(+), 45 deletions(-)