-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
drm/displayid: add separate drm_displayid.c
We'll be adding more DisplayID specific functions going forward, so start off by splitting out a few functions to a separate file. We don't bother with exporting the functions; at least for now they should be needed solely within drm.ko. No functional changes. Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com> Signed-off-by: Jani Nikula <jani.nikula@intel.com> Link: https://patchwork.freedesktop.org/patch/msgid/07942d5011891b8e8f77245c78b34f4af97a9315.1617024940.git.jani.nikula@intel.com
- Loading branch information
Jani Nikula
committed
Mar 31, 2021
1 parent
43d16d8
commit 4cc4f09
Showing
5 changed files
with
73 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: MIT | ||
/* | ||
* Copyright © 2021 Intel Corporation | ||
*/ | ||
|
||
#include <drm/drm_displayid.h> | ||
#include <drm/drm_edid.h> | ||
#include <drm/drm_print.h> | ||
|
||
static int validate_displayid(const u8 *displayid, int length, int idx) | ||
{ | ||
int i, dispid_length; | ||
u8 csum = 0; | ||
const struct displayid_hdr *base; | ||
|
||
base = (const struct displayid_hdr *)&displayid[idx]; | ||
|
||
DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n", | ||
base->rev, base->bytes, base->prod_id, base->ext_count); | ||
|
||
/* +1 for DispID checksum */ | ||
dispid_length = sizeof(*base) + base->bytes + 1; | ||
if (dispid_length > length - idx) | ||
return -EINVAL; | ||
|
||
for (i = 0; i < dispid_length; i++) | ||
csum += displayid[idx + i]; | ||
if (csum) { | ||
DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum); | ||
return -EINVAL; | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
const u8 *drm_find_displayid_extension(const struct edid *edid, | ||
int *length, int *idx, | ||
int *ext_index) | ||
{ | ||
const u8 *displayid = drm_find_edid_extension(edid, DISPLAYID_EXT, ext_index); | ||
const struct displayid_hdr *base; | ||
int ret; | ||
|
||
if (!displayid) | ||
return NULL; | ||
|
||
/* EDID extensions block checksum isn't for us */ | ||
*length = EDID_LENGTH - 1; | ||
*idx = 1; | ||
|
||
ret = validate_displayid(displayid, *length, *idx); | ||
if (ret) | ||
return NULL; | ||
|
||
base = (const struct displayid_hdr *)&displayid[*idx]; | ||
*length = *idx + sizeof(*base) + base->bytes; | ||
|
||
return displayid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters