mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Kai Vehmanen <kai.vehmanen@linux.intel.com>
To: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org,
	dri-devel@lists.freedesktop.org
Cc: "Jani Nikula" <jani.nikula@linux.intel.com>,
	"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Tvrtko Ursulin" <tursulin@ursulin.net>,
	"Maarten Lankhorst" <maarten.lankhorst@linux.intel.com>,
	"Maxime Ripard" <mripard@kernel.org>,
	"Thomas Zimmermann" <tzimmermann@suse.de>,
	"David Airlie" <airlied@gmail.com>,
	"Simona Vetter" <simona@ffwll.ch>,
	"Takashi Iwai" <tiwai@suse.com>,
	"Jaroslav Kysela" <perex@perex.cz>,
	linux-sound@vger.kernel.org,
	"Harry Wentland" <harry.wentland@amd.com>,
	"Leo Li" <sunpeng.li@amd.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	amd-gfx@lists.freedesktop.org, "Lyude Paul" <lyude@redhat.com>,
	"Danilo Krummrich" <dakr@kernel.org>,
	"Tomáš Hnyk" <tomashnyk@gmail.com>,
	"Wim Taymans" <wtaymans@redhat.com>,
	nouveau@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	"Kai Vehmanen" <kai.vehmanen@linux.intel.com>
Subject: [PATCH 1/2] drm/eld: Add drm_eld_set_port_id() helper
Date: Thu,  5 Nov 2026 18:02:39 +0200	[thread overview]
Message-ID: <20261105160240.2850042-2-kai.vehmanen@linux.intel.com> (raw)
In-Reply-To: <20261105160240.2850042-1-kai.vehmanen@linux.intel.com>

The ELD baseline block reserves bytes 8..15 for a 64-bit Port_ID that
identifies the source port of the audio endpoint. drm_edid_to_eld()
leaves the field zero, and no driver fills it in, so it carries no
information.

When two identical monitors are connected, their ELDs are then
byte-identical, and userspace has no passive way to tell which HDMI/DP
PCM belongs to which DRM connector. The only workaround is to toggle
the connector audio property and watch which ELD goes away, which
disrupts the endpoint.

Add a helper that drivers can use to fill in Port_ID with a common
layout:

  bits 63:48 - PCI domain of the DRM device
  bits 47:32 - PCI bus/device/function of the DRM device
  bits 31:0  - DRM connector object ID

Userspace can read the connector object ID directly from KMS, and the
PCI address tells GPUs apart in multi-GPU systems. For non-PCI devices
the upper half is left zero.

The split between a 16-bit PCI BDF in the upper half and a per-device
display identifier in the lower half follows the Port_ID layout
documented for the AMD Azalia sink info registers in dce_audio.c.

Signed-off-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
---
 drivers/gpu/drm/drm_eld.c | 42 +++++++++++++++++++++++++++++++++++++++
 include/drm/drm_eld.h     |  3 +++
 2 files changed, 45 insertions(+)

diff --git a/drivers/gpu/drm/drm_eld.c b/drivers/gpu/drm/drm_eld.c
index c0428d07de53..baebece7b4ed 100644
--- a/drivers/gpu/drm/drm_eld.c
+++ b/drivers/gpu/drm/drm_eld.c
@@ -4,7 +4,11 @@
  */
 
 #include <linux/export.h>
+#include <linux/pci.h>
+#include <linux/unaligned.h>
 
+#include <drm/drm_connector.h>
+#include <drm/drm_device.h>
 #include <drm/drm_edid.h>
 #include <drm/drm_eld.h>
 
@@ -55,3 +59,41 @@ int drm_eld_sad_set(u8 *eld, int sad_index, const struct cea_sad *cta_sad)
 	return 0;
 }
 EXPORT_SYMBOL(drm_eld_sad_set);
+
+/**
+ * drm_eld_set_port_id - set the ELD Port_ID for a connector
+ * @eld: ELD buffer
+ * @connector: connector the ELD belongs to
+ *
+ * drm_edid_to_eld() leaves the 64-bit Port_ID field of the ELD baseline
+ * block zero. Drivers can use this helper to fill it in with a value
+ * that identifies the audio endpoint, so that userspace can associate an
+ * ELD, and the PCM device it belongs to, with a DRM connector, even when
+ * identical sinks are connected to multiple outputs.
+ *
+ * The Port_ID is stored in little-endian byte order, with the layout:
+ *
+ * - bits 63:48 - PCI domain of the DRM device, truncated to 16 bits
+ * - bits 47:32 - PCI bus/device/function of the DRM device
+ * - bits 31:0  - DRM connector object ID
+ *
+ * For non-PCI devices bits 63:32 are zero.
+ *
+ * The connector object ID is only stable for the lifetime of the
+ * connector, so userspace must look it up at runtime, and not store it.
+ */
+void drm_eld_set_port_id(u8 *eld, const struct drm_connector *connector)
+{
+	struct device *dev = connector->dev->dev;
+	u64 port_id = connector->base.id;
+
+	if (dev && dev_is_pci(dev)) {
+		struct pci_dev *pdev = to_pci_dev(dev);
+
+		port_id |= (u64)(pci_domain_nr(pdev->bus) & 0xffff) << 48 |
+			   (u64)pci_dev_id(pdev) << 32;
+	}
+
+	put_unaligned_le64(port_id, &eld[DRM_ELD_PORT_ID]);
+}
+EXPORT_SYMBOL(drm_eld_set_port_id);
diff --git a/include/drm/drm_eld.h b/include/drm/drm_eld.h
index 0a88d10b28b0..de0478720721 100644
--- a/include/drm/drm_eld.h
+++ b/include/drm/drm_eld.h
@@ -9,6 +9,7 @@
 #include <linux/types.h>
 
 struct cea_sad;
+struct drm_connector;
 
 /* ELD Header Block */
 #define DRM_ELD_HEADER_BLOCK_SIZE	4
@@ -80,6 +81,8 @@ static inline int drm_eld_mnl(const u8 *eld)
 int drm_eld_sad_get(const u8 *eld, int sad_index, struct cea_sad *cta_sad);
 int drm_eld_sad_set(u8 *eld, int sad_index, const struct cea_sad *cta_sad);
 
+void drm_eld_set_port_id(u8 *eld, const struct drm_connector *connector);
+
 /**
  * drm_eld_sad - Get ELD SAD structures.
  * @eld: pointer to an eld memory structure with sad_count set
-- 
2.43.0


  reply	other threads:[~2026-11-05 16:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-05 16:02 [PATCH 0/2] drm: Populate ELD Port_ID to identify audio endpoints Kai Vehmanen
2026-11-05 16:02 ` Kai Vehmanen [this message]
2026-11-05 17:08   ` [PATCH 1/2] drm/eld: Add drm_eld_set_port_id() helper Ville Syrjälä
2026-11-05 16:02 ` [PATCH 2/2] drm/i915/audio: Populate ELD Port_ID Kai Vehmanen
2026-11-05 17:09   ` Ville Syrjälä

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=20261105160240.2850042-2-kai.vehmanen@linux.intel.com \
    --to=kai.vehmanen@linux.intel.com \
    --cc=airlied@gmail.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dakr@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=harry.wentland@amd.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=lyude@redhat.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=nouveau@lists.freedesktop.org \
    --cc=perex@perex.cz \
    --cc=rodrigo.vivi@intel.com \
    --cc=simona@ffwll.ch \
    --cc=sunpeng.li@amd.com \
    --cc=tiwai@suse.com \
    --cc=tomashnyk@gmail.com \
    --cc=tursulin@ursulin.net \
    --cc=tzimmermann@suse.de \
    --cc=ville.syrjala@linux.intel.com \
    --cc=wtaymans@redhat.com \
    /path/to/YOUR_REPLY

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

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

all inboxes | Powered by JetHome®