Skip to content

Commit 4cc4f09

Browse files
committed
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ä <[email protected]> Signed-off-by: Jani Nikula <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/07942d5011891b8e8f77245c78b34f4af97a9315.1617024940.git.jani.nikula@intel.com
1 parent 43d16d8 commit 4cc4f09

File tree

5 files changed

+73
-57
lines changed

5 files changed

+73
-57
lines changed

drivers/gpu/drm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ drm-y := drm_auth.o drm_cache.o \
77
drm_file.o drm_gem.o drm_ioctl.o drm_irq.o \
88
drm_drv.o \
99
drm_sysfs.o drm_hashtab.o drm_mm.o \
10-
drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \
10+
drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o drm_displayid.o \
1111
drm_encoder_slave.o \
1212
drm_trace_points.o drm_prime.o \
1313
drm_rect.o drm_vma_manager.o drm_flip_work.o \

drivers/gpu/drm/drm_displayid.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// SPDX-License-Identifier: MIT
2+
/*
3+
* Copyright © 2021 Intel Corporation
4+
*/
5+
6+
#include <drm/drm_displayid.h>
7+
#include <drm/drm_edid.h>
8+
#include <drm/drm_print.h>
9+
10+
static int validate_displayid(const u8 *displayid, int length, int idx)
11+
{
12+
int i, dispid_length;
13+
u8 csum = 0;
14+
const struct displayid_hdr *base;
15+
16+
base = (const struct displayid_hdr *)&displayid[idx];
17+
18+
DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
19+
base->rev, base->bytes, base->prod_id, base->ext_count);
20+
21+
/* +1 for DispID checksum */
22+
dispid_length = sizeof(*base) + base->bytes + 1;
23+
if (dispid_length > length - idx)
24+
return -EINVAL;
25+
26+
for (i = 0; i < dispid_length; i++)
27+
csum += displayid[idx + i];
28+
if (csum) {
29+
DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
30+
return -EINVAL;
31+
}
32+
33+
return 0;
34+
}
35+
36+
const u8 *drm_find_displayid_extension(const struct edid *edid,
37+
int *length, int *idx,
38+
int *ext_index)
39+
{
40+
const u8 *displayid = drm_find_edid_extension(edid, DISPLAYID_EXT, ext_index);
41+
const struct displayid_hdr *base;
42+
int ret;
43+
44+
if (!displayid)
45+
return NULL;
46+
47+
/* EDID extensions block checksum isn't for us */
48+
*length = EDID_LENGTH - 1;
49+
*idx = 1;
50+
51+
ret = validate_displayid(displayid, *length, *idx);
52+
if (ret)
53+
return NULL;
54+
55+
base = (const struct displayid_hdr *)&displayid[*idx];
56+
*length = *idx + sizeof(*base) + base->bytes;
57+
58+
return displayid;
59+
}

drivers/gpu/drm/drm_edid.c

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,8 +1585,6 @@ module_param_named(edid_fixup, edid_fixup, int, 0400);
15851585
MODULE_PARM_DESC(edid_fixup,
15861586
"Minimum number of valid EDID header bytes (0-8, default 6)");
15871587

1588-
static int validate_displayid(const u8 *displayid, int length, int idx);
1589-
15901588
static int drm_edid_block_checksum(const u8 *raw_edid)
15911589
{
15921590
int i;
@@ -3241,8 +3239,8 @@ add_detailed_modes(struct drm_connector *connector, struct edid *edid,
32413239
/*
32423240
* Search EDID for CEA extension block.
32433241
*/
3244-
static const u8 *drm_find_edid_extension(const struct edid *edid,
3245-
int ext_id, int *ext_index)
3242+
const u8 *drm_find_edid_extension(const struct edid *edid,
3243+
int ext_id, int *ext_index)
32463244
{
32473245
const u8 *edid_ext = NULL;
32483246
int i;
@@ -3266,32 +3264,6 @@ static const u8 *drm_find_edid_extension(const struct edid *edid,
32663264
return edid_ext;
32673265
}
32683266

3269-
3270-
static const u8 *drm_find_displayid_extension(const struct edid *edid,
3271-
int *length, int *idx,
3272-
int *ext_index)
3273-
{
3274-
const u8 *displayid = drm_find_edid_extension(edid, DISPLAYID_EXT, ext_index);
3275-
const struct displayid_hdr *base;
3276-
int ret;
3277-
3278-
if (!displayid)
3279-
return NULL;
3280-
3281-
/* EDID extensions block checksum isn't for us */
3282-
*length = EDID_LENGTH - 1;
3283-
*idx = 1;
3284-
3285-
ret = validate_displayid(displayid, *length, *idx);
3286-
if (ret)
3287-
return NULL;
3288-
3289-
base = (const struct displayid_hdr *)&displayid[*idx];
3290-
*length = *idx + sizeof(*base) + base->bytes;
3291-
3292-
return displayid;
3293-
}
3294-
32953267
static const u8 *drm_find_cea_extension(const struct edid *edid)
32963268
{
32973269
int length, idx;
@@ -5287,32 +5259,6 @@ u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edi
52875259
return quirks;
52885260
}
52895261

5290-
static int validate_displayid(const u8 *displayid, int length, int idx)
5291-
{
5292-
int i, dispid_length;
5293-
u8 csum = 0;
5294-
const struct displayid_hdr *base;
5295-
5296-
base = (const struct displayid_hdr *)&displayid[idx];
5297-
5298-
DRM_DEBUG_KMS("base revision 0x%x, length %d, %d %d\n",
5299-
base->rev, base->bytes, base->prod_id, base->ext_count);
5300-
5301-
/* +1 for DispID checksum */
5302-
dispid_length = sizeof(*base) + base->bytes + 1;
5303-
if (dispid_length > length - idx)
5304-
return -EINVAL;
5305-
5306-
for (i = 0; i < dispid_length; i++)
5307-
csum += displayid[idx + i];
5308-
if (csum) {
5309-
DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
5310-
return -EINVAL;
5311-
}
5312-
5313-
return 0;
5314-
}
5315-
53165262
static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
53175263
struct displayid_detailed_timings_1 *timings)
53185264
{

include/drm/drm_displayid.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
#ifndef DRM_DISPLAYID_H
2323
#define DRM_DISPLAYID_H
2424

25+
#include <linux/types.h>
26+
27+
struct edid;
28+
2529
#define DATA_BLOCK_PRODUCT_ID 0x00
2630
#define DATA_BLOCK_DISPLAY_PARAMETERS 0x01
2731
#define DATA_BLOCK_COLOR_CHARACTERISTICS 0x02
@@ -100,4 +104,8 @@ struct displayid_detailed_timing_block {
100104
(idx) += sizeof(struct displayid_block) + (block)->num_bytes, \
101105
(block) = (const struct displayid_block *)&(displayid)[idx])
102106

107+
const u8 *drm_find_displayid_extension(const struct edid *edid,
108+
int *length, int *idx,
109+
int *ext_index);
110+
103111
#endif

include/drm/drm_edid.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,5 +543,8 @@ struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
543543
struct drm_display_mode *
544544
drm_display_mode_from_cea_vic(struct drm_device *dev,
545545
u8 video_code);
546+
const u8 *drm_find_edid_extension(const struct edid *edid,
547+
int ext_id, int *ext_index);
548+
546549

547550
#endif /* __DRM_EDID_H__ */

0 commit comments

Comments
 (0)