public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Simon Ser <simon.ser@intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH i-g-t 2/2] lib/igt_alsa: check ELD comes from IGT
Date: Thu, 12 Sep 2019 13:28:15 +0300	[thread overview]
Message-ID: <20190912102815.32663-2-simon.ser@intel.com> (raw)
In-Reply-To: <20190912102815.32663-1-simon.ser@intel.com>

Prior to this commit, audio tests play sound on all HDMI/DisplayPort PCM
devices (by filtering devices with the "HDMI" prefix). This had several issues.
First, the PCM device → connector mapping via the ELD wasn't checked. Second,
it makes debugging more complicated: if ALSA doesn't detect the screen, we just
get a Chamelium failure (because it doesn't receive any audio stream). Third,
it would play sounds on real screens too (not only Chamelium) and this could
theorically damage bad hardware (though this is just speculation).

To mitigate this issue, check the monitor name of PCM devices we open and only
keep them if it's an IGT EDID (ie. connected to the Chamelium board).

Note that while this is a good improvement, it isn't a complete fix: the ELD
is only exposed by the HDA Intel driver. This means non-IGT PCM devices won't
be filtered out on non-Intel hardware. There is no driver-agnostic way to get
the screen name, I'm afraid.

Signed-off-by: Simon Ser <simon.ser@intel.com>
---
 lib/igt_alsa.c | 93 +++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 81 insertions(+), 12 deletions(-)

diff --git a/lib/igt_alsa.c b/lib/igt_alsa.c
index 5b5980a94888..e1836be7cdd5 100644
--- a/lib/igt_alsa.c
+++ b/lib/igt_alsa.c
@@ -31,6 +31,7 @@
 #include "igt_alsa.h"
 #include "igt_aux.h"
 #include "igt_core.h"
+#include "igt_eld.h"
 
 #define HANDLES_MAX	8
 
@@ -105,6 +106,68 @@ struct alsa *alsa_init(void)
 	return alsa;
 }
 
+static bool alsa_dev_has_igt_eld(snd_ctl_t *ctl, int dev)
+{
+	snd_hctl_t *handle;
+	snd_hctl_elem_t *elem;
+	snd_ctl_elem_info_t *info;
+	snd_ctl_elem_value_t *value;
+	const char *name;
+	snd_ctl_elem_type_t type;
+	unsigned int count;
+	const char *eld;
+	bool is_igt, eld_found;
+
+	igt_assert(snd_hctl_open_ctl(&handle, ctl) == 0);
+	igt_assert(snd_hctl_load(handle) == 0);
+	igt_assert(snd_ctl_elem_info_malloc(&info) == 0);
+	igt_assert(snd_ctl_elem_value_malloc(&value) == 0);
+
+	is_igt = eld_found = false;
+	for (elem = snd_hctl_first_elem(handle); elem;
+	     elem = snd_hctl_elem_next(elem)) {
+		igt_assert(snd_hctl_elem_info(elem, info) == 0);
+		name = snd_ctl_elem_info_get_name(info);
+		type = snd_ctl_elem_info_get_type(info);
+		count = snd_ctl_elem_info_get_count(info);
+
+		if (strcmp(name, "ELD") != 0)
+			continue;
+		igt_assert(type == SND_CTL_ELEM_TYPE_BYTES);
+		if (snd_ctl_elem_info_get_device(info) != dev)
+			continue;
+
+		eld_found = true;
+
+		igt_assert(snd_hctl_elem_read(elem, value) == 0);
+		if (count == 0) {
+			igt_debug("ELD found for device %s,%d, but it's empty "
+				  "(the screen is probably disconnected)\n",
+				  snd_hctl_name(handle), dev);
+			break;
+		}
+
+		igt_debug("ELD found for device %s,%d\n",
+			  snd_hctl_name(handle), dev);
+		eld = snd_ctl_elem_value_get_bytes(value);
+		is_igt = eld_is_igt(eld, count);
+		break;
+	}
+
+	if (!eld_found) {
+		/* ELDs are probably not supported */
+		igt_debug("ELD not found for device %s,%d, skipping ELD check\n",
+			  snd_hctl_name(handle), dev);
+		is_igt = true;
+	}
+
+	snd_ctl_elem_info_free(info);
+	snd_ctl_elem_value_free(value);
+	snd_hctl_free(handle);
+
+	return is_igt;
+}
+
 static char *alsa_resolve_indentifier(const char *device_name, int skip)
 {
 	snd_ctl_card_info_t *card_info;
@@ -148,7 +211,6 @@ static char *alsa_resolve_indentifier(const char *device_name, int skip)
 		}
 
 		dev = -1;
-
 		do {
 			ret = snd_ctl_pcm_next_device(handle, &dev);
 			if (ret < 0 || dev < 0)
@@ -167,21 +229,28 @@ static char *alsa_resolve_indentifier(const char *device_name, int skip)
 
 			ret = strncmp(device_name, pcm_name,
 				      strlen(device_name));
+			if (ret != 0)
+				continue;
 
-			if (ret == 0) {
-				if (skip > 0) {
-					skip--;
-					continue;
-				}
+			if (!alsa_dev_has_igt_eld(handle, dev)) {
+				igt_debug("Device hw:%d,%d matches the name "
+					  "but doesn't have an IGT ELD\n",
+					  card, dev);
+				continue;
+			}
 
-				igt_debug("Matched device \"%s\"\n", pcm_name);
+			if (skip > 0) {
+				skip--;
+				continue;
+			}
 
-				snprintf(name, sizeof(name), "hw:%d,%d", card,
-					 dev);
+			igt_debug("Matched device \"%s\" (hw:%d,%d)\n",
+				  pcm_name, card, dev);
 
-				identifier = strdup(name);
-				goto resolved;
-			}
+			snprintf(name, sizeof(name), "hw:%d,%d", card,
+				 dev);
+			identifier = strdup(name);
+			goto resolved;
 		} while (dev >= 0);
 
 		snd_ctl_close(handle);
-- 
2.23.0

_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev

  reply	other threads:[~2019-09-12 10:27 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12 10:28 [igt-dev] [PATCH i-g-t 1/2] igt_eld: add igt_is_igt Simon Ser
2019-09-12 10:28 ` Simon Ser [this message]
2019-09-12 10:53 ` Chris Wilson
2019-09-12 11:41 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,1/2] " Patchwork
2019-09-12 15:01 ` [igt-dev] [PATCH i-g-t 1/2] " Andi Shyti
2019-09-12 15:44 ` [igt-dev] [PATCH i-g-t v2] " Simon Ser
2019-09-13 11:08   ` Ser, Simon
2019-09-12 16:37 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,v2] igt_eld: add igt_is_igt (rev2) Patchwork
2019-09-12 20:11 ` [igt-dev] ✓ Fi.CI.IGT: success for series starting with [i-g-t,1/2] igt_eld: add igt_is_igt Patchwork
2019-09-13  5:39 ` [igt-dev] ✓ Fi.CI.IGT: success for series starting with [i-g-t,v2] igt_eld: add igt_is_igt (rev2) Patchwork

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20190912102815.32663-2-simon.ser@intel.com \
    --to=simon.ser@intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

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

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