From 8a7b044493e8dcdd7df02a124ea14daf95752cec Mon Sep 17 00:00:00 2001 From: Simon Ser <simon.ser@intel.com> Date: Fri, 19 Jul 2019 13:48:27 +0300 Subject: [PATCH] lib/igt_kms: use struct edid instead of unsigned char 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> Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@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 a09473d07..49ddadfb4 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 8e3e33205..af53557f0 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; @@ -127,7 +128,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 964a5747e..e6e8b93b4 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] = { @@ -1085,7 +1085,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; @@ -1102,7 +1102,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 c0dcb6f2a..2b1c072e0 100644 --- a/lib/igt_kms.h +++ b/lib/igt_kms.h @@ -192,11 +192,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); @@ -754,16 +755,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 fc98f1bb7..bbbf15058 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 6117dfe00..b970b3b55 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 f25d13c6e..913a4cd85 100644 --- a/tests/kms_chamelium.c +++ b/tests/kms_chamelium.c @@ -261,7 +261,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) @@ -2197,7 +2197,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 2a52087da..521105062 100644 --- a/tests/kms_hdmi_inject.c +++ b/tests/kms_hdmi_inject.c @@ -78,7 +78,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; @@ -139,7 +139,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; -- GitLab