All of lore.kernel.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 1/4] lib/igt_kms: use struct edid instead of unsigned char
Date: Fri, 19 Jul 2019 14:38:44 +0300	[thread overview]
Message-ID: <20190719113847.32626-2-simon.ser@intel.com> (raw)
In-Reply-To: <20190719113847.32626-1-simon.ser@intel.com>

This has several advantages:

* No more need to convert back and forth between these two (everybody should
  use struct edid, the exception being lib/tests/igt_edid which performs sanity
  checks)
* Makes it clearer that users can call edid_get_size on a returned EDID blob
* Improves type safety (it's more obvious is a random blob is used as an EDID)

Signed-off-by: Simon Ser <simon.ser@intel.com>
---
 lib/igt_chamelium.c     |  3 +--
 lib/igt_chamelium.h     |  3 ++-
 lib/igt_kms.c           | 38 +++++++++++++++++++-------------------
 lib/igt_kms.h           | 18 ++++++++----------
 lib/tests/igt_edid.c    | 14 ++++++++------
 tests/kms_3d.c          |  2 +-
 tests/kms_chamelium.c   |  4 ++--
 tests/kms_hdmi_inject.c |  4 ++--
 8 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/lib/igt_chamelium.c b/lib/igt_chamelium.c
index 301e9d214dd1..ad30e803d2a5 100644
--- a/lib/igt_chamelium.c
+++ b/lib/igt_chamelium.c
@@ -562,10 +562,9 @@ static void chamelium_destroy_edid(struct chamelium *chamelium, int edid_id)
  * Returns: An opaque pointer to the Chamelium EDID
  */
 struct chamelium_edid *chamelium_new_edid(struct chamelium *chamelium,
-					  const unsigned char *raw_edid)
+					  const struct edid *edid)
 {
 	struct chamelium_edid *chamelium_edid;
-	const struct edid *edid = (struct edid *) raw_edid;
 	size_t edid_size = edid_get_size(edid);
 
 	chamelium_edid = calloc(1, sizeof(struct chamelium_edid));
diff --git a/lib/igt_chamelium.h b/lib/igt_chamelium.h
index b6b7eb4436f8..ca6aef801b6f 100644
--- a/lib/igt_chamelium.h
+++ b/lib/igt_chamelium.h
@@ -34,6 +34,7 @@
 #include "igt_debugfs.h"
 
 struct igt_fb;
+struct edid;
 
 struct chamelium;
 struct chamelium_port;
@@ -114,7 +115,7 @@ void chamelium_schedule_hpd_toggle(struct chamelium *chamelium,
 				   struct chamelium_port *port, int delay_ms,
 				   bool rising_edge);
 struct chamelium_edid *chamelium_new_edid(struct chamelium *chamelium,
-					  const unsigned char *edid);
+					  const struct edid *edid);
 const struct edid *chamelium_edid_get_raw(struct chamelium_edid *edid,
 					  struct chamelium_port *port);
 void chamelium_port_set_edid(struct chamelium *chamelium,
diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 175e71c310b7..b7fb165e0678 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -100,7 +100,7 @@ static int forced_connectors_device[MAX_CONNECTORS + 1];
  *
  * Returns: a basic edid block
  */
-const unsigned char *igt_kms_get_base_edid(void)
+const struct edid *igt_kms_get_base_edid(void)
 {
 	static struct edid edid;
 	drmModeModeInfo mode = {};
@@ -119,7 +119,7 @@ const unsigned char *igt_kms_get_base_edid(void)
 	edid_init_with_mode(&edid, &mode);
 	edid_update_checksum(&edid);
 
-	return (unsigned char *) &edid;
+	return &edid;
 }
 
 /**
@@ -136,7 +136,7 @@ const unsigned char *igt_kms_get_base_edid(void)
  *
  * Returns: an alternate edid block
  */
-const unsigned char *igt_kms_get_alt_edid(void)
+const struct edid *igt_kms_get_alt_edid(void)
 {
 	static struct edid edid;
 	drmModeModeInfo mode = {};
@@ -155,12 +155,12 @@ const unsigned char *igt_kms_get_alt_edid(void)
 	edid_init_with_mode(&edid, &mode);
 	edid_update_checksum(&edid);
 
-	return (unsigned char *) &edid;
+	return &edid;
 }
 
 #define AUDIO_EDID_LENGTH (2 * EDID_LENGTH)
 
-static void
+static const struct edid *
 generate_audio_edid(unsigned char raw_edid[static AUDIO_EDID_LENGTH],
 		    bool with_vsdb, struct cea_sad *sad,
 		    struct cea_speaker_alloc *speaker_alloc)
@@ -206,9 +206,11 @@ generate_audio_edid(unsigned char raw_edid[static AUDIO_EDID_LENGTH],
 
 	edid_update_checksum(edid);
 	edid_ext_update_cea_checksum(edid_ext);
+
+	return edid;
 }
 
-const unsigned char *igt_kms_get_hdmi_audio_edid(void)
+const struct edid *igt_kms_get_hdmi_audio_edid(void)
 {
 	int channels;
 	uint8_t sampling_rates, sample_sizes;
@@ -229,12 +231,10 @@ const unsigned char *igt_kms_get_hdmi_audio_edid(void)
 	/* Initialize the Speaker Allocation Data */
 	speaker_alloc.speakers = CEA_SPEAKER_FRONT_LEFT_RIGHT_CENTER;
 
-	generate_audio_edid(raw_edid, true, &sad, &speaker_alloc);
-
-	return raw_edid;
+	return generate_audio_edid(raw_edid, true, &sad, &speaker_alloc);
 }
 
-const unsigned char *igt_kms_get_dp_audio_edid(void)
+const struct edid *igt_kms_get_dp_audio_edid(void)
 {
 	int channels;
 	uint8_t sampling_rates, sample_sizes;
@@ -255,9 +255,7 @@ const unsigned char *igt_kms_get_dp_audio_edid(void)
 	/* Initialize the Speaker Allocation Data */
 	speaker_alloc.speakers = CEA_SPEAKER_FRONT_LEFT_RIGHT_CENTER;
 
-	generate_audio_edid(raw_edid, false, &sad, &speaker_alloc);
-
-	return raw_edid;
+	return generate_audio_edid(raw_edid, false, &sad, &speaker_alloc);
 }
 
 static const uint8_t edid_4k_svds[] = {
@@ -268,7 +266,7 @@ static const uint8_t edid_4k_svds[] = {
 	19,                  /* 720p @ 50Hz */
 };
 
-const unsigned char *igt_kms_get_4k_edid(void)
+const struct edid *igt_kms_get_4k_edid(void)
 {
 	static unsigned char raw_edid[256] = {0};
 	struct edid *edid;
@@ -317,10 +315,11 @@ const unsigned char *igt_kms_get_4k_edid(void)
 
 	edid_update_checksum(edid);
 	edid_ext_update_cea_checksum(edid_ext);
-	return raw_edid;
+
+	return edid;
 }
 
-const unsigned char *igt_kms_get_3d_edid(void)
+const struct edid *igt_kms_get_3d_edid(void)
 {
 	static unsigned char raw_edid[256] = {0};
 	struct edid *edid;
@@ -368,7 +367,8 @@ const unsigned char *igt_kms_get_3d_edid(void)
 
 	edid_update_checksum(edid);
 	edid_ext_update_cea_checksum(edid_ext);
-	return raw_edid;
+
+	return edid;
 }
 
 const char * const igt_plane_prop_names[IGT_NUM_PLANE_PROPS] = {
@@ -1084,7 +1084,7 @@ bool kmstest_force_connector(int drm_fd, drmModeConnector *connector,
  * If @edid is NULL, the forced EDID will be removed.
  */
 void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
-			const unsigned char *edid)
+			const struct edid *edid)
 {
 	char *path;
 	int debugfs_fd, ret;
@@ -1101,7 +1101,7 @@ void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
 		ret = write(debugfs_fd, "reset", 5);
 	else
 		ret = write(debugfs_fd, edid,
-			    edid_get_size((struct edid *) edid));
+			    edid_get_size(edid));
 	close(debugfs_fd);
 
 	/* To allow callers to always use GetConnectorCurrent we need to force a
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 0486737bb8be..0b9374a16b0e 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -191,11 +191,12 @@ enum intel_broadcast_rgb_mode {
 	BROADCAST_RGB_16_235
 };
 
+struct edid;
 
 bool kmstest_force_connector(int fd, drmModeConnector *connector,
 			     enum kmstest_force_connector_state state);
 void kmstest_force_edid(int drm_fd, drmModeConnector *connector,
-			const unsigned char *edid);
+			const struct edid *edid);
 
 bool kmstest_get_connector_default_mode(int drm_fd, drmModeConnector *connector,
 					drmModeModeInfo *mode);
@@ -753,16 +754,13 @@ void igt_reset_connectors(void);
 
 uint32_t kmstest_get_vbl_flag(uint32_t pipe_id);
 
-struct cea_sad;
-struct cea_speaker_alloc;
-
 #define EDID_LENGTH 128
-const unsigned char *igt_kms_get_base_edid(void);
-const unsigned char *igt_kms_get_alt_edid(void);
-const unsigned char *igt_kms_get_hdmi_audio_edid(void);
-const unsigned char *igt_kms_get_dp_audio_edid(void);
-const unsigned char *igt_kms_get_4k_edid(void);
-const unsigned char *igt_kms_get_3d_edid(void);
+const struct edid *igt_kms_get_base_edid(void);
+const struct edid *igt_kms_get_alt_edid(void);
+const struct edid *igt_kms_get_hdmi_audio_edid(void);
+const struct edid *igt_kms_get_dp_audio_edid(void);
+const struct edid *igt_kms_get_4k_edid(void);
+const struct edid *igt_kms_get_3d_edid(void);
 
 struct udev_monitor *igt_watch_hotplug(void);
 bool igt_hotplug_detected(struct udev_monitor *mon,
diff --git a/lib/tests/igt_edid.c b/lib/tests/igt_edid.c
index fc98f1bb71ce..bbbf15058982 100644
--- a/lib/tests/igt_edid.c
+++ b/lib/tests/igt_edid.c
@@ -64,7 +64,7 @@ static bool edid_block_checksum(const unsigned char *raw_edid)
 	return csum == 0;
 }
 
-typedef const unsigned char *(*get_edid_func)(void);
+typedef const struct edid *(*get_edid_func)(void);
 
 igt_simple_main
 {
@@ -80,23 +80,25 @@ igt_simple_main
 		{ "3d", igt_kms_get_3d_edid, 1 },
 		{0},
 	}, *f;
-	const unsigned char *edid;
+	const struct edid *edid;
+	const uint8_t *raw_edid;
 	size_t i;
 
 	for (f = funcs; f->f; f++) {
 		edid = f->f();
+		raw_edid = (uint8_t *) edid;
 
-		igt_assert_f(edid_header_is_valid(edid),
+		igt_assert_f(edid_header_is_valid(raw_edid),
 			     "invalid header on %s EDID", f->desc);
 		/* check base edid block */
-		igt_assert_f(edid_block_checksum(edid),
+		igt_assert_f(edid_block_checksum(raw_edid),
 			     "checksum failed on %s EDID", f->desc);
 		/* check extension blocks, if any */
-		igt_assert_f(edid[126] == f->exts,
+		igt_assert_f(raw_edid[126] == f->exts,
 			     "unexpected number of extensions on %s EDID",
 			     f->desc);
 		for (i = 0; i < f->exts; i++)
-			igt_assert_f(edid_block_checksum(edid + (i + 1) * EDID_LENGTH),
+			igt_assert_f(edid_block_checksum(raw_edid + (i + 1) * EDID_LENGTH),
 				     "CEA block checksum failed on %s EDID", f->desc);
 	}
 }
diff --git a/tests/kms_3d.c b/tests/kms_3d.c
index 8ade6d347a29..7e880dd22e30 100644
--- a/tests/kms_3d.c
+++ b/tests/kms_3d.c
@@ -31,7 +31,7 @@ igt_simple_main
 	int drm_fd;
 	drmModeRes *res;
 	drmModeConnector *connector;
-	const unsigned char *edid;
+	const struct edid *edid;
 	int mode_count, connector_id;
 
 	drm_fd = drm_open_driver_master(DRIVER_INTEL);
diff --git a/tests/kms_chamelium.c b/tests/kms_chamelium.c
index b7d30a2d0f55..03cd9370c84f 100644
--- a/tests/kms_chamelium.c
+++ b/tests/kms_chamelium.c
@@ -260,7 +260,7 @@ test_basic_hotplug(data_t *data, struct chamelium_port *port, int toggle_count)
 	igt_hpd_storm_reset(data->drm_fd);
 }
 
-static const unsigned char *get_edid(enum test_edid edid);
+static const struct edid *get_edid(enum test_edid edid);
 
 static void set_edid(data_t *data, struct chamelium_port *port,
 		     enum test_edid edid)
@@ -2141,7 +2141,7 @@ test_hpd_storm_disable(data_t *data, struct chamelium_port *port, int width)
 	igt_hpd_storm_reset(data->drm_fd);
 }
 
-static const unsigned char *get_edid(enum test_edid edid)
+static const struct edid *get_edid(enum test_edid edid)
 {
 	switch (edid) {
 	case TEST_EDID_BASE:
diff --git a/tests/kms_hdmi_inject.c b/tests/kms_hdmi_inject.c
index 78684241737b..157d58275107 100644
--- a/tests/kms_hdmi_inject.c
+++ b/tests/kms_hdmi_inject.c
@@ -79,7 +79,7 @@ get_connector(int drm_fd, drmModeRes *res)
 static void
 hdmi_inject_4k(int drm_fd, drmModeConnector *connector)
 {
-	const unsigned char *edid;
+	const struct edid *edid;
 	struct kmstest_connector_config config;
 	int ret, cid, i, crtc_mask = -1;
 	int fb_id;
@@ -140,7 +140,7 @@ hdmi_inject_4k(int drm_fd, drmModeConnector *connector)
 static void
 hdmi_inject_audio(int drm_fd, drmModeConnector *connector)
 {
-	const unsigned char *edid;
+	const struct edid *edid;
 	int fb_id, cid, ret, crtc_mask = -1;
 	struct igt_fb fb;
 	struct kmstest_connector_config config;
-- 
2.22.0

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

  reply	other threads:[~2019-07-19 11:38 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-19 11:38 [igt-dev] [PATCH i-g-t 0/4] lib/igt_edid: misc quality-of-life improvements Simon Ser
2019-07-19 11:38 ` Simon Ser [this message]
2019-07-19 11:38 ` [igt-dev] [PATCH i-g-t 2/4] lib/igt_kms: drop EDID_LENGTH, replace with EDID_BLOCK_SIZE Simon Ser
2019-07-19 11:38 ` [igt-dev] [PATCH i-g-t 3/4] lib/igt_edid: make HDMI VSDB data array unsigned Simon Ser
2019-07-19 11:38 ` [igt-dev] [PATCH i-g-t 4/4] lib/igt_edid: merge edid_ext_update_cea_checksum into edid_update_checksum Simon Ser
2019-07-19 12:11 ` [igt-dev] ✗ Fi.CI.BAT: failure for lib/igt_edid: misc quality-of-life improvements Patchwork
2019-07-19 12:13   ` Ser, Simon
2019-07-19 13:49     ` Martin Peres
2019-07-19 14:26 ` [igt-dev] ✓ Fi.CI.BAT: success " Patchwork
2019-07-19 17:11 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
2019-08-15  8:25 ` [igt-dev] [PATCH i-g-t 0/4] " Arkadiusz Hiler

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=20190719113847.32626-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.