1 /*
2 * Copyright © 2019 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors: Simon Ser <[email protected]>
24 */
25
26 #include "config.h"
27
28 #include <stdbool.h>
29
30 #include "igt_core.h"
31 #include "igt_kms.h"
32 #include "igt_edid.h"
33
34 static const unsigned char edid_header[] = {
35 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00
36 };
37
38 /**
39 * Sanity check the header of the base EDID block.
40 */
edid_header_is_valid(const unsigned char * raw_edid)41 static bool edid_header_is_valid(const unsigned char *raw_edid)
42 {
43 size_t i;
44
45 for (i = 0; i < sizeof(edid_header); i++)
46 if (raw_edid[i] != edid_header[i])
47 return false;
48
49 return true;
50 }
51
52 /**
53 * Sanity check the checksum of the EDID block.
54 */
edid_block_checksum(const unsigned char * raw_edid)55 static bool edid_block_checksum(const unsigned char *raw_edid)
56 {
57 size_t i;
58 unsigned char csum = 0;
59
60 for (i = 0; i < EDID_BLOCK_SIZE; i++) {
61 csum += raw_edid[i];
62 }
63
64 return csum == 0;
65 }
66
67 typedef const struct edid *(*get_edid_func)(void);
68
69 igt_simple_main
70 {
71 const struct {
72 const char *desc;
73 get_edid_func f;
74 size_t exts;
75 } funcs[] = {
76 { "base", igt_kms_get_base_edid, 0 },
77 { "alt", igt_kms_get_alt_edid, 0 },
78 { "hdmi_audio", igt_kms_get_hdmi_audio_edid, 1 },
79 { "4k", igt_kms_get_4k_edid, 1 },
80 { "3d", igt_kms_get_3d_edid, 1 },
81 {0},
82 }, *f;
83 const struct edid *edid;
84 const uint8_t *raw_edid, *raw_block;
85 size_t i;
86
87 for (f = funcs; f->f; f++) {
88 edid = f->f();
89 raw_edid = (uint8_t *) edid;
90
91 igt_assert_f(edid_header_is_valid(raw_edid),
92 "invalid header on %s EDID", f->desc);
93 /* check base edid block */
94 igt_assert_f(edid_block_checksum(raw_edid),
95 "checksum failed on %s EDID", f->desc);
96 /* check extension blocks, if any */
97 igt_assert_f(raw_edid[126] == f->exts,
98 "unexpected number of extensions on %s EDID",
99 f->desc);
100 for (i = 0; i < f->exts; i++) {
101 raw_block = raw_edid + (i + 1) * EDID_BLOCK_SIZE;
102 igt_assert_f(edid_block_checksum(raw_block),
103 "CEA block checksum failed on %s EDID",
104 f->desc);
105 }
106 }
107 }
108