1 // SPDX-License-Identifier: MIT
3 * Copyright © 2021 Intel Corporation
6 #include <drm/drm_displayid.h>
7 #include <drm/drm_edid.h>
8 #include <drm/drm_print.h>
10 static int validate_displayid(const u8 *displayid, int length, int idx)
14 const struct displayid_header *base;
16 base = (const struct displayid_header *)&displayid[idx];
18 DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
19 base->rev, base->bytes, base->prod_id, base->ext_count);
21 /* +1 for DispID checksum */
22 dispid_length = sizeof(*base) + base->bytes + 1;
23 if (dispid_length > length - idx)
26 for (i = 0; i < dispid_length; i++)
27 csum += displayid[idx + i];
29 DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
36 static const u8 *drm_find_displayid_extension(const struct edid *edid,
37 int *length, int *idx,
40 const u8 *displayid = drm_find_edid_extension(edid, DISPLAYID_EXT, ext_index);
41 const struct displayid_header *base;
47 /* EDID extensions block checksum isn't for us */
48 *length = EDID_LENGTH - 1;
51 ret = validate_displayid(displayid, *length, *idx);
55 base = (const struct displayid_header *)&displayid[*idx];
56 *length = *idx + sizeof(*base) + base->bytes;
61 void displayid_iter_edid_begin(const struct edid *edid,
62 struct displayid_iter *iter)
64 memset(iter, 0, sizeof(*iter));
69 static const struct displayid_block *
70 displayid_iter_block(const struct displayid_iter *iter)
72 const struct displayid_block *block;
77 block = (const struct displayid_block *)&iter->section[iter->idx];
79 if (iter->idx + sizeof(*block) <= iter->length &&
80 iter->idx + sizeof(*block) + block->num_bytes <= iter->length)
86 const struct displayid_block *
87 __displayid_iter_next(struct displayid_iter *iter)
89 const struct displayid_block *block;
95 /* current block should always be valid */
96 block = displayid_iter_block(iter);
97 if (WARN_ON(!block)) {
103 /* next block in section */
104 iter->idx += sizeof(*block) + block->num_bytes;
106 block = displayid_iter_block(iter);
112 iter->section = drm_find_displayid_extension(iter->edid,
116 if (!iter->section) {
121 iter->idx += sizeof(struct displayid_header);
123 block = displayid_iter_block(iter);
129 void displayid_iter_end(struct displayid_iter *iter)
131 memset(iter, 0, sizeof(*iter));