public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@intel.com>
To: Kunal Joshi <kunal1.joshi@intel.com>,
	igt-dev@lists.freedesktop.org, Simon Ser <contact@emersion.fr>
Cc: Kunal Joshi <kunal1.joshi@intel.com>,
	Arun R Murthy <arun.r.murthy@gmail.com>
Subject: Re: [PATCH i-g-t 1/6] lib/igt_edid: add EDID serial extraction helpers
Date: Tue, 14 Apr 2026 12:11:04 +0300	[thread overview]
Message-ID: <57222f9789fda352ed26606c1f80e35fcdeb3d37@intel.com> (raw)
In-Reply-To: <20260409043714.284108-2-kunal1.joshi@intel.com>

On Thu, 09 Apr 2026, Kunal Joshi <kunal1.joshi@intel.com> wrote:
> Add helpers to extract serial identification from EDID data.
>
>  - edid_get_serial_string(): extract ASCII serial from descriptor 0xFF
>  - edid_get_serial_number(): extract 32-bit serial from EDID header
>  - edid_get_any_serial(): convenience helper that tries ASCII serial
>    first, then falls back to 32-bit header serial formatted as hex
>
> These are needed by the connector helper and USB4 switch test suite
> for EDID-based display verification after dock/undock events.

Time to consider using libdisplay-info [1] in IGT?


BR,
Jani.


[1] https://gitlab.freedesktop.org/emersion/libdisplay-info


>
> Signed-off-by: Kunal Joshi <kunal1.joshi@intel.com>
> Reviewed-by: Arun R Murthy <arun.r.murthy@gmail.com>
> ---
>  lib/igt_edid.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  lib/igt_edid.h |  5 +++
>  2 files changed, 96 insertions(+)
>
> diff --git a/lib/igt_edid.c b/lib/igt_edid.c
> index c68ccf671..e7fcbf0b9 100644
> --- a/lib/igt_edid.c
> +++ b/lib/igt_edid.c
> @@ -249,6 +249,97 @@ void edid_get_monitor_name(const struct edid *edid, char *name, size_t name_size
>  	name[0] = '\0';
>  }
>  
> +/**
> + * edid_get_serial_string:
> + * @edid: EDID structure
> + * @serial: buffer to write serial string
> + * @serial_size: size of serial buffer; must be > 1
> + *
> + * Extract the serial string from EDID descriptor block type 0xFF.
> + * The descriptor payload is a 13-byte fixed-width field; trailing
> + * whitespace is stripped and the result is NUL-terminated.
> + * @serial is left empty when no 0xFF descriptor is found.
> + */
> +void edid_get_serial_string(const struct edid *edid,
> +			    char *serial, size_t serial_size)
> +{
> +	size_t copy_len, i, n;
> +
> +	igt_assert(edid);
> +	igt_assert(serial);
> +	igt_assert(serial_size > 1);
> +	serial[0] = '\0';
> +
> +	for (i = 0; i < DETAILED_TIMINGS_LEN; i++) {
> +		const uint8_t *d = (const uint8_t *)&edid->detailed_timings[i];
> +
> +		if (d[0] != 0x00 || d[1] != 0x00 || d[2] != 0x00)
> +			continue;
> +
> +		if (d[3] != EDID_DETAIL_MONITOR_SERIAL || d[4] != 0x00)
> +			continue;
> +
> +		/* Descriptor string payload is 13 bytes starting at d[5] */
> +		copy_len = serial_size - 1 < 13 ? serial_size - 1 : 13;
> +		memcpy(serial, &d[5], copy_len);
> +		serial[copy_len] = '\0';
> +
> +		for (n = strlen(serial);
> +		     n > 0 && isspace((unsigned char)serial[n - 1]); n--)
> +			serial[n - 1] = '\0';
> +
> +		return;
> +	}
> +}
> +
> +/**
> + * edid_get_serial_number:
> + * @edid: EDID structure
> + *
> + * Extract the 32-bit serial number from the EDID base block header
> + * (bytes 12–15, the manufacturer/product section).  This is different
> + * from the ASCII serial string in descriptor block 0xFF.
> + *
> + * Returns: 32-bit serial number (little-endian), 0 if absent.
> + */
> +uint32_t edid_get_serial_number(const struct edid *edid)
> +{
> +	return (uint32_t)edid->serial[0] |
> +	       ((uint32_t)edid->serial[1] << 8) |
> +	       ((uint32_t)edid->serial[2] << 16) |
> +	       ((uint32_t)edid->serial[3] << 24);
> +}
> +
> +/**
> + * edid_get_any_serial:
> + * @edid: EDID structure
> + * @serial: buffer to write serial string
> + * @serial_size: size of serial buffer; must be > 1
> + *
> + * Convenience helper that tries to extract a serial identifier from EDID.
> + * First tries the ASCII serial string descriptor (0xFF). If that is empty,
> + * falls back to the 32-bit header serial number formatted as 8-char hex.
> + * If neither source provides a usable serial (no 0xFF descriptor and the
> + * header serial is 0), @serial is left empty.
> + */
> +void edid_get_any_serial(const struct edid *edid,
> +			 char *serial, size_t serial_size)
> +{
> +	uint32_t serial_num;
> +
> +	igt_assert(edid);
> +	igt_assert(serial);
> +	igt_assert(serial_size > 1);
> +
> +	edid_get_serial_string(edid, serial, serial_size);
> +	if (serial[0])
> +		return;
> +
> +	serial_num = edid_get_serial_number(edid);
> +	if (serial_num != 0)
> +		snprintf(serial, serial_size, "%08X", serial_num);
> +}
> +
>  static void edid_set_mfg(struct edid *edid, const char mfg[static 3])
>  {
>  	edid->mfg_id[0] = (mfg[0] - '@') << 2 | (mfg[1] - '@') >> 3;
> diff --git a/lib/igt_edid.h b/lib/igt_edid.h
> index be0ccf529..d9e396065 100644
> --- a/lib/igt_edid.h
> +++ b/lib/igt_edid.h
> @@ -457,5 +457,10 @@ void *dispid_block_tiled(void *ptr,
>  			 int hsize, int vsize,
>  			 const char *topology_id);
>  void edid_get_monitor_name(const struct edid *edid, char *name, size_t name_size);
> +void edid_get_serial_string(const struct edid *edid,
> +			    char *serial, size_t serial_size);
> +uint32_t edid_get_serial_number(const struct edid *edid);
> +void edid_get_any_serial(const struct edid *edid,
> +			 char *serial, size_t serial_size);
>  
>  #endif

-- 
Jani Nikula, Intel

  reply	other threads:[~2026-04-14  9:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-09  4:37 [PATCH i-g-t 0/6] add test to validate dock/undock and switch Kunal Joshi
2026-04-09  4:37 ` [PATCH i-g-t 1/6] lib/igt_edid: add EDID serial extraction helpers Kunal Joshi
2026-04-14  9:11   ` Jani Nikula [this message]
2026-04-14  9:55     ` Simon Ser
2026-04-09  4:37 ` [PATCH i-g-t 2/6] lib/igt_connector_helper: Add generic connector helpers Kunal Joshi
2026-04-09  4:37 ` [PATCH i-g-t 3/6] lib/igt_serial: add generic serial communication helper Kunal Joshi
2026-04-14  9:20   ` Jani Nikula
2026-04-09  4:37 ` [PATCH i-g-t 4/6] lib/igt_usb4_switch: add helper library for USB4 Switch 3141 Kunal Joshi
2026-04-09  4:37 ` [PATCH i-g-t 5/6] tests/kms_feature_discovery: add basic usb4 switch discovery Kunal Joshi
2026-04-14  9:23   ` Jani Nikula
2026-04-09  4:37 ` [PATCH i-g-t 6/6] tests/intel/kms_usb4_switch: Add USB4 switch test suite Kunal Joshi
2026-04-14  9:27   ` Jani Nikula
2026-04-10  0:18 ` ✓ i915.CI.BAT: success for add test to validate dock/undock and switch (rev4) Patchwork
2026-04-10  0:19 ` ✓ Xe.CI.BAT: " Patchwork
2026-04-10  2:45 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-04-10 17:16 ` ✗ i915.CI.Full: " Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2026-02-25 21:28 [PATCH i-g-t 0/6] add test to validate dock/undock and switch Kunal Joshi
2026-02-25 21:28 ` [PATCH i-g-t 1/6] lib/igt_edid: add EDID serial extraction helpers Kunal Joshi
2026-02-25 19:42 [PATCH i-g-t 0/6] add test to validate dock/undock and switch Kunal Joshi
2026-02-25 19:42 ` [PATCH i-g-t 1/6] lib/igt_edid: add EDID serial extraction helpers Kunal Joshi

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=57222f9789fda352ed26606c1f80e35fcdeb3d37@intel.com \
    --to=jani.nikula@intel.com \
    --cc=arun.r.murthy@gmail.com \
    --cc=contact@emersion.fr \
    --cc=igt-dev@lists.freedesktop.org \
    --cc=kunal1.joshi@intel.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