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_hdr *base;
16 base = (const struct displayid_hdr *)&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 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_hdr *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_hdr *)&displayid[*idx];
56 *length = *idx + sizeof(*base) + base->bytes;