4K and audio HDMI EDID injection
v3 cover 4K and audio HDMI EDID injection
This series adds support for HDMI injection (4K and audio), and it needs
https://lists.freedesktop.org/archives/intel-gfx/2016-March/090698.html.
v3:
- extend kms_force_connector_basic instead of creating a new test.
- upon reloading the driver the number of outputs increases so we need to make sure we're checking all of them.
v2:
- Use a proper subject.
- Added speaker data block and check that we get indeed a valid ELD for audio injection, otherwise we can not tell if the audio injection succeeded.
Marius Vlad (3):
lib/igt_kms: Add helpers for injecting 4k HDMI EDID, and HDMI-capable
audio.
lib/igt_kms: Allow forcing HDMI connectors and remove checks against
BDW and HSW.
tests/kms_force_connector_basic: Add HDMI and audio EDID injection.
lib/igt_kms.c | 193 +++++++++++++++++++++++++++++-- lib/igt_kms.h | 2 + tests/kms_force_connector_basic.c | 236 +++++++++++++++++++++++++++++++++++++- 3 files changed, 417 insertions(+), 14 deletions(-)
Signature · 6 lines
2.5.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 1/3 lib/igt_kms: Add helpers for injecting 4k HDMI EDID, and HDMI-capable audio.
--- lib/igt_kms.c | 182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/igt_kms.h | 2 + 2 files changed, 184 insertions(+)
lib/igt_kms.c +182 -0
@@ -1005,6 +1005,188 @@ void kmstest_edid_add_3d(const unsigned char *edid, size_t length, }/** +* kmstest_edid_add_4k: +* @edid: an existing valid edid block +* @length: length of @edid +* @new_edid_ptr: pointer to where the new edid will be placed +* @new_length: pointer to the size of the new edid +* +* Makes a copy of an existing edid block and adds an extension indicating +* a HDMI 4K mode in vsdb. +*/ +void kmstest_edid_add_4k (const unsigned char *edid,size_t length, +unsigned char *new_edid_ptr[],size_t *new_length) +{ +unsigned char *new_edid; +int n_extensions; +char sum =0 ; +int pos; +int i; +char cea_header_len =4 , video_block_len =6 , vsdb_block_len =12 ; + +igt_assert (new_edid_ptr !=NULL && new_length !=NULL ); + + *new_length = length +128 ; + + new_edid =calloc (*new_length,sizeof (char )); +memcpy (new_edid, edid, length); + *new_edid_ptr = new_edid; + + n_extensions = new_edid[126 ]; + n_extensions++; + new_edid[126 ] = n_extensions; + +/* recompute checksum */ +for (i =0 ; i <127 ; i++) { + sum = sum + new_edid[i]; + } + new_edid[127 ] =256 - sum; + +/* add a cea-861 extension block */ + pos = length; + new_edid[pos++] =0x2 ; + new_edid[pos++] =0x3 ; + new_edid[pos++] = cea_header_len + video_block_len + vsdb_block_len; + new_edid[pos++] =0x0 ; + +/* video block (id | length) */ + new_edid[pos++] =2 <<5 | (video_block_len -1 ); + new_edid[pos++] =32 |0x80 ;/* 1080p @ 24Hz | (native)*/ + new_edid[pos++] =5 ;/* 1080i @ 60Hz */ + new_edid[pos++] =20 ;/* 1080i @ 50Hz */ + new_edid[pos++] =4 ;/* 720p @ 60Hz*/ + new_edid[pos++] =19 ;/* 720p @ 50Hz*/ + +/* vsdb block ( id | length ) */ + new_edid[pos++] =3 <<5 | (vsdb_block_len -1 ); +/* registration id */ + new_edid[pos++] =0x3 ; + new_edid[pos++] =0xc ; + new_edid[pos++] =0x0 ; +/* source physical address */ + new_edid[pos++] =0x10 ; + new_edid[pos++] =0x00 ; +/* Supports_AI ... etc */ + new_edid[pos++] =0x00 ; +/* Max TMDS Clock */ + new_edid[pos++] =0x00 ; +/* Latency present, HDMI Video Present */ + new_edid[pos++] =0x20 ; +/* HDMI Video */ + new_edid[pos++] =0x00 ;/* 3D present */ + +/* HDMI MODE LEN -- how many entries */ + new_edid[pos++] =0x20 ; +/* 2160p, specified as short descriptor */ + new_edid[pos++] =0x01 ; + + +/* checksum */ + sum =0 ; +for (i =0 ; i <127 ; i++) { + sum = sum + new_edid[length + i]; + } + new_edid[length +127 ] =256 - sum; +} + +/** +* kmstest_edid_add_audio: +* @edid: an existing valid edid block +* @length: length of @edid +* @new_edid_ptr: pointer to where the new edid will be placed +* @new_length: pointer to the size of the new edid +* +* Makes a copy of an existing edid block and adds an extension indicating +* basic audio support and speaker data block. +* +*/ +void kmstest_edid_add_audio (const unsigned char *edid,size_t length, +unsigned char *new_edid_ptr[],size_t *new_length) +{ +unsigned char *new_edid; +int n_extensions; +char sum =0 ; +int pos; +int i; +char cea_header_len =4 , video_block_len =6 , vsdb_block_len =10 ; +char audio_block_len =4 , spkr_block_len =4 ; + +igt_assert (new_edid_ptr !=NULL && new_length !=NULL ); + + *new_length = length +128 ; + + new_edid =calloc (*new_length,sizeof (char )); +memcpy (new_edid, edid, length); + *new_edid_ptr = new_edid; + + n_extensions = new_edid[126 ]; + n_extensions++; + new_edid[126 ] = n_extensions; + +/* recompute checksum */ +for (i =0 ; i <127 ; i++) { + sum = sum + new_edid[i]; + } + new_edid[127 ] =256 - sum; + +/* add a cea-861 extension block */ + pos = length; + new_edid[pos++] =0x2 ; + new_edid[pos++] =0x3 ; + new_edid[pos++] = cea_header_len + audio_block_len + + video_block_len + vsdb_block_len + spkr_block_len; + new_edid[pos++] = (1 <<6 );/* support basic audio */ + +/* audio block, short audio block descriptors */ + new_edid[pos++] = (1 <<5 ) | (audio_block_len -1 ); + new_edid[pos++] =0x09 ;/* Audio Format, PCM */ + new_edid[pos++] =0x07 ;/* Frequency, 32, 44.1, 48kHz */ + new_edid[pos++] =0x07 ;/* Bit Rate 16, 20, 24 bit */ + +/* video block (id | length) */ + new_edid[pos++] =2 <<5 | (video_block_len -1 ); + new_edid[pos++] =32 |0x80 ;/* 1080p @ 24Hz | (native)*/ + new_edid[pos++] =5 ;/* 1080i @ 60Hz */ + new_edid[pos++] =20 ;/* 1080i @ 50Hz */ + new_edid[pos++] =4 ;/* 720p @ 60Hz*/ + new_edid[pos++] =19 ;/* 720p @ 50Hz*/ + + +/* vsdb block ( id | length ) -- need vsdb as well +* otherwise the kernel will fallback to lower clock modes */ + new_edid[pos++] =3 <<5 | (vsdb_block_len -1 ); +/* registration id */ + new_edid[pos++] =0x3 ; + new_edid[pos++] =0xc ; + new_edid[pos++] =0x0 ; +/* source physical address */ + new_edid[pos++] =0x10 ; + new_edid[pos++] =0x00 ; +/* Supports_AI ... etc */ + new_edid[pos++] =0x00 ; +/* Max TMDS Clock */ + new_edid[pos++] =0x00 ; +/* Latency present, HDMI Video Present */ + new_edid[pos++] =0x20 ; +/* HDMI Video */ + new_edid[pos++] =0x00 ;/* 3D present */ + +/* speaker data block */ + new_edid[pos++] = (4 <<5 ) | (spkr_block_len -1 ); + new_edid[pos++] = (1 <<5 ); + new_edid[pos++] =0x00 ; + new_edid[pos++] =0x00 ; + +/* checksum */ + sum =0 ; +for (i =0 ; i <127 ; i++) { + sum = sum + new_edid[length + i]; + } + new_edid[length +127 ] =256 - sum; +} + + +/** * kmstest_unset_all_crtcs: * @drm_fd: the DRM fd * @resources: libdrm resources pointer
lib/igt_kms.h +2 -0
@@ -152,6 +152,8 @@ enum kmstest_force_connector_state {bool kmstest_force_connector (int fd,drmModeConnector *connector,enum kmstest_force_connector_state state);void kmstest_edid_add_3d (const unsigned char *edid,size_t length,unsigned char *new_edid_ptr[],size_t *new_length); +void kmstest_edid_add_4k (const unsigned char *edid,size_t length,unsigned char *new_edid_ptr[],size_t *new_length); +void kmstest_edid_add_audio (const unsigned char *edid,size_t length,unsigned char *new_edid_ptr[],size_t *new_length);void kmstest_force_edid (int drm_fd,drmModeConnector *connector,const unsigned char *edid,size_t length);
Signature · 6 lines
2.5.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 2/3 lib/igt_kms: Allow forcing HDMI connectors and remove checks against BDW and HSW.
In reply to Marius Vlad--- lib/igt_kms.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-)
lib/igt_kms.c +2 -9
@@ -531,16 +531,9 @@ bool kmstest_force_connector(int drm_fd, drmModeConnector *connector,const char *value;int debugfs_fd, ret, len;drmModeConnector *temp; -uint32_t devid; - devid =intel_get_drm_devid (drm_fd); - -/* forcing hdmi or dp connectors on HSW and BDW doesn't currently work, -* so fail early to allow the test to skip if required */ -if ((connector->connector_type ==DRM_MODE_CONNECTOR_HDMIA || - connector->connector_type ==DRM_MODE_CONNECTOR_HDMIB || - connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort) - && (IS_HASWELL (devid) ||IS_BROADWELL (devid))) +/* forcing dp connectors doesn't currently work */ +if (connector->connector_type == DRM_MODE_CONNECTOR_DisplayPort)return false;switch (state) {
Signature · 6 lines
2.5.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx
PATCH v3 3/3 tests/kms_force_connector_basic: Add HDMI and audio EDID injection.
In reply to Marius Vlad--- tests/kms_force_connector_basic.c | 236 +++++++++++++++++++++++++++++++++++++- 1 file changed, 231 insertions(+), 5 deletions(-)
tests/kms_force_connector_basic.c +231 -5
@@ -22,6 +22,8 @@* */ +#define _GNU_SOURCE +#include <stdio.h> #include "igt.h" IGT_TEST_DESCRIPTION("Check the debugfs force connector/edid features work"
@@ -31,6 +33,11 @@ IGT_TEST_DESCRIPTION("Check the debugfs force connector/edid features work"igt_assert_eq (m.hdisplay, h);igt_assert_eq (m.vdisplay, w); \igt_assert_eq (m.vrefresh, r); +#define HDISPLAY_4K 3840 +#define VDISPLAY_4K 2160 +/* magic number of audio outputs when reloading the driver */ +#define AUDIO_OUTPUTS 3 +static void reset_connectors (void ) {int drm_fd =0 ;
@@ -68,12 +75,191 @@ static int opt_handler(int opt, int opt_index, void *data)return 0 ; } +static int +eld_is_valid (uint8_t no_outputs) +{ +FILE *in; +char buf[1024 ]; +char *eld_path; +int ret; +uint8_t eld_valid =0 ; +uint8_t mon_valid =0 ; +uint8_t i; + +/* +* Reloading the driver would reset the #no of outputs, so we need to +* check of them. +*/ +for (i =0 ; i < no_outputs; i++) { + + ret =asprintf (&eld_path,"/proc/asound/HDMI/eld#0.%hu" , i); +igt_assert_neq (ret,-1 ); + + in =fopen (eld_path,"r" ); +if (!in) { +igt_debug ("Failed to open '%s'\n" , eld_path); +return 0 ; + } + +memset (buf,0 ,1024 ); + +while ((fgets (buf,1024 , in)) !=NULL ) { + +char *line = buf; +igt_debug ("'%s'" , line); + +if (!strncasecmp (line,"eld_valid" ,9 ) && +strstr (line,"1" )) { + eld_valid++; + } + +if (!strncasecmp (line,"monitor_name" ,12 ) && +strstr (line,"IGT" )) { + mon_valid++; + } + } + +if (mon_valid && eld_valid) { +free (eld_path); +fclose (in); +return 1 ; + } + +fclose (in); +free (eld_path); + } + +return 0 ; +} + +static void +hdmi_inject_4k (int drm_fd,drmModeConnector *connector,int start_n_modes) +{ +unsigned char *edid; +size_t length; +struct kmstest_connector_config config; +int ret, crtc_mask =-1 ; +int fb_id; +struct igt_fb fb; +uint32_t devid; +drmModeConnector *temp; + + devid =intel_get_drm_devid (drm_fd); + +/* 4K requires at least HSW */ +igt_require (IS_HASWELL (devid) ||IS_BROADWELL (devid)); + +kmstest_edid_add_4k (igt_kms_get_base_edid (),EDID_LENGTH , &edid, + &length); + +kmstest_force_connector (drm_fd, connector,FORCE_CONNECTOR_ON ); + temp =drmModeGetConnectorCurrent (drm_fd, connector->connector_id); + +drmModeFreeConnector (temp); + +kmstest_force_edid (drm_fd, connector, edid, length); + temp =drmModeGetConnectorCurrent (drm_fd, connector->connector_id); + +CHECK_MODE (temp->modes[1 ],HDISPLAY_4K ,VDISPLAY_4K ,30 ); + +/* create a configuration */ + ret =kmstest_get_connector_config (drm_fd, temp->connector_id, crtc_mask, &config); +igt_assert (ret); + +igt_info (" " ); +kmstest_dump_mode (&temp->modes[1 ]); + +/* create framebuffer */ + fb_id =igt_create_fb (drm_fd, temp->modes[1 ].hdisplay, + temp->modes[1 ].vdisplay, +DRM_FORMAT_XRGB8888 , +LOCAL_DRM_FORMAT_MOD_NONE , &fb); + + ret =drmModeSetCrtc (drm_fd, config.crtc->crtc_id, fb_id,0 ,0 , + &temp->connector_id,1 , &temp->modes[1 ]); + +igt_assert (ret ==0 ); +drmModeFreeConnector (temp); + +igt_remove_fb (drm_fd, &fb); + +kmstest_force_edid (drm_fd, connector,NULL ,0 ); +kmstest_force_connector (drm_fd, connector,FORCE_CONNECTOR_UNSPECIFIED ); + + temp =drmModeGetConnectorCurrent (drm_fd, connector->connector_id); +igt_assert_eq (temp->count_modes, start_n_modes); + +drmModeFreeConnector (temp); + +free (edid); +} + + +static void +hdmi_inject_audio (int drm_fd,drmModeConnector *connector,int start_n_modes) +{ +unsigned char *edid; +size_t length; +int fb_id, ret, crtc_mask =-1 ; +struct igt_fb fb; +struct kmstest_connector_config config; +drmModeConnector *temp; + +kmstest_edid_add_audio (igt_kms_get_base_edid (),EDID_LENGTH , &edid, + &length); + +kmstest_force_connector (drm_fd, connector,FORCE_CONNECTOR_ON ); + temp =drmModeGetConnectorCurrent (drm_fd, connector->connector_id); + +drmModeFreeConnector (temp); + +kmstest_force_edid (drm_fd, connector, edid, length); + temp =drmModeGetConnectorCurrent (drm_fd, connector->connector_id); + + +/* create a configuration */ + ret =kmstest_get_connector_config (drm_fd, temp->connector_id, crtc_mask, &config); +igt_assert (ret); + +/* +* Create a framebuffer as to allow the kernel to enable the pipe and +* enable the audio encoder. +*/ + fb_id =igt_create_fb (drm_fd, temp->modes[0 ].hdisplay, + temp->modes[0 ].vdisplay, +DRM_FORMAT_XRGB8888 , +LOCAL_DRM_FORMAT_MOD_NONE , &fb); + + ret =drmModeSetCrtc (drm_fd, config.crtc->crtc_id, fb_id,0 ,0 , + &temp->connector_id,1 , &temp->modes[0 ]); + + +igt_assert (ret ==0 ); + +/* +* Test if we have /proc/asound/HDMI/eld#0.0 and its contents are valid. +*/ +igt_assert (eld_is_valid (AUDIO_OUTPUTS )); + +igt_remove_fb (drm_fd, &fb); +drmModeFreeConnector (temp); + +kmstest_force_edid (drm_fd, connector,NULL ,0 ); +kmstest_force_connector (drm_fd, connector,FORCE_CONNECTOR_UNSPECIFIED ); + temp =drmModeGetConnectorCurrent (drm_fd, connector->connector_id); +igt_assert_eq (temp->count_modes, start_n_modes); + +drmModeFreeConnector (temp); +free (edid); +} +int main (int argc,char **argv) {/* force the VGA output and test that it worked */ int drm_fd =0 ;drmModeRes *res;drmModeConnector *vga_connector =NULL , *temp; +drmModeConnector *hdmi_connector =NULL ;int start_n_modes, start_connection;struct option long_opts[] = { {"reset" ,0 ,0 ,'r' },
@@ -86,12 +272,13 @@ int main(int argc, char **argv) opt_handler, NULL); igt_fixture { +int i; drm_fd =drm_open_driver_master (DRIVER_INTEL ); res =drmModeGetResources (drm_fd);igt_assert (res);/* find the vga connector */ -for (int i =0 ; i < res->count_connectors; i++) { +for (i =0 ; i < res->count_connectors; i++) { vga_connector =drmModeGetConnectorCurrent (drm_fd, res->connectors[i]);
@@ -101,17 +288,31 @@ int main(int argc, char **argv) start_connection = vga_connector->connection;break ; } -drmModeFreeConnector (vga_connector); vga_connector =NULL ; } -igt_require (vga_connector); -igt_skip_on (vga_connector->connection ==DRM_MODE_CONNECTED ); +/* find the HDMI connector */ +for (i =0 ; i < res->count_connectors; i++) { + + hdmi_connector =drmModeGetConnectorCurrent (drm_fd, + res->connectors[i]); + +if (hdmi_connector->connector_type ==DRM_MODE_CONNECTOR_HDMIA ) { + start_n_modes = hdmi_connector->count_modes; + start_connection = hdmi_connector->connection; +break ; + } +drmModeFreeConnector (hdmi_connector); + + hdmi_connector =NULL ; + } } igt_subtest("force-load-detect") { +igt_require (vga_connector); +igt_skip_on (vga_connector->connection ==DRM_MODE_CONNECTED );/* * disable all outputs to make sure we have a * free crtc available for load detect
@@ -136,6 +337,9 @@ int main(int argc, char **argv) igt_subtest("force-connector-state") {igt_display_t display; +igt_require (vga_connector); +igt_skip_on (vga_connector->connection ==DRM_MODE_CONNECTED ); +/* force the connector on and check the reported values */ kmstest_force_connector (drm_fd, vga_connector,FORCE_CONNECTOR_ON ); temp = drmModeGetConnectorCurrent(drm_fd,
@@ -169,7 +373,10 @@ int main(int argc, char **argv)drmModeFreeConnector (temp); } - igt_subtest("force-edid") { + igt_subtest("force-edid-vga") { +igt_require (vga_connector); +igt_skip_on (vga_connector->connection ==DRM_MODE_CONNECTED ); +kmstest_force_connector (drm_fd, vga_connector,FORCE_CONNECTOR_ON ); temp = drmModeGetConnectorCurrent(drm_fd,
@@ -203,9 +410,28 @@ int main(int argc, char **argv) } + igt_subtest("force-edid-hdmi-4k") { + +igt_require (hdmi_connector); +igt_skip_on (hdmi_connector->connection ==DRM_MODE_CONNECTED ); + +hdmi_inject_4k (drm_fd, hdmi_connector, start_n_modes); + } + + igt_subtest("force-edid-hdmi-audio") { + +igt_require (hdmi_connector); +igt_skip_on (hdmi_connector->connection ==DRM_MODE_CONNECTED ); + +hdmi_inject_audio (drm_fd, hdmi_connector, start_n_modes); + } + igt_subtest("prune-stale-modes") {int i; +igt_require (vga_connector); +igt_skip_on (vga_connector->connection ==DRM_MODE_CONNECTED ); +kmstest_force_connector (drm_fd, vga_connector,FORCE_CONNECTOR_ON );
Signature · 6 lines
2.5.0 _______________________________________________ Intel-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/intel-gfx