drm/displayid: add separate drm_displayid.c
authorJani Nikula <jani.nikula@intel.com>
Mon, 29 Mar 2021 13:37:16 +0000 (16:37 +0300)
committerJani Nikula <jani.nikula@intel.com>
Wed, 31 Mar 2021 12:41:35 +0000 (15:41 +0300)
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
drivers/gpu/drm/Makefile
drivers/gpu/drm/drm_displayid.c [new file with mode: 0644]
drivers/gpu/drm/drm_edid.c
include/drm/drm_displayid.h
include/drm/drm_edid.h

index e932730a1706ec2c40030e4d23db4a761bd53cc8..5279db4392dffd5198f4cc67e3021f486674d579 100644 (file)
@@ -7,7 +7,7 @@ drm-y       :=  drm_auth.o drm_cache.o \
                drm_file.o drm_gem.o drm_ioctl.o drm_irq.o \
                drm_drv.o \
                drm_sysfs.o drm_hashtab.o drm_mm.o \
-               drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \
+               drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o drm_displayid.o \
                drm_encoder_slave.o \
                drm_trace_points.o drm_prime.o \
                drm_rect.o drm_vma_manager.o drm_flip_work.o \
diff --git a/drivers/gpu/drm/drm_displayid.c b/drivers/gpu/drm/drm_displayid.c
new file mode 100644 (file)
index 0000000..908bbe6
--- /dev/null
@@ -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;
+}
index d510b827a1f8ab82b55d1721c26307a16ed35224..58e61f792bc7dcd6d5eb946e206f9428909c802b 100644 (file)
@@ -1585,8 +1585,6 @@ module_param_named(edid_fixup, edid_fixup, int, 0400);
 MODULE_PARM_DESC(edid_fixup,
                 "Minimum number of valid EDID header bytes (0-8, default 6)");
 
-static int validate_displayid(const u8 *displayid, int length, int idx);
-
 static int drm_edid_block_checksum(const u8 *raw_edid)
 {
        int i;
@@ -3241,8 +3239,8 @@ add_detailed_modes(struct drm_connector *connector, struct edid *edid,
 /*
  * Search EDID for CEA extension block.
  */
-static const u8 *drm_find_edid_extension(const struct edid *edid,
-                                        int ext_id, int *ext_index)
+const u8 *drm_find_edid_extension(const struct edid *edid,
+                                 int ext_id, int *ext_index)
 {
        const u8 *edid_ext = NULL;
        int i;
@@ -3266,32 +3264,6 @@ static const u8 *drm_find_edid_extension(const struct edid *edid,
        return edid_ext;
 }
 
-
-static 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;
-}
-
 static const u8 *drm_find_cea_extension(const struct edid *edid)
 {
        int length, idx;
@@ -5287,32 +5259,6 @@ u32 drm_add_display_info(struct drm_connector *connector, const struct edid *edi
        return quirks;
 }
 
-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;
-}
-
 static struct drm_display_mode *drm_mode_displayid_detailed(struct drm_device *dev,
                                                            struct displayid_detailed_timings_1 *timings)
 {
index f141c0eff08395f0debba0b7cb975d70c789380a..3c6db22a518a14e7aac846b3e1f00ab50bcba21c 100644 (file)
 #ifndef DRM_DISPLAYID_H
 #define DRM_DISPLAYID_H
 
+#include <linux/types.h>
+
+struct edid;
+
 #define DATA_BLOCK_PRODUCT_ID 0x00
 #define DATA_BLOCK_DISPLAY_PARAMETERS 0x01
 #define DATA_BLOCK_COLOR_CHARACTERISTICS 0x02
@@ -100,4 +104,8 @@ struct displayid_detailed_timing_block {
             (idx) += sizeof(struct displayid_block) + (block)->num_bytes, \
             (block) = (const struct displayid_block *)&(displayid)[idx])
 
+const u8 *drm_find_displayid_extension(const struct edid *edid,
+                                      int *length, int *idx,
+                                      int *ext_index);
+
 #endif
index a158f585f658b4a89ff06f840ad6ea30ae3a70e8..759328a5eeb201aa966a6b65d0c661d8ac546122 100644 (file)
@@ -543,5 +543,8 @@ struct drm_display_mode *drm_mode_find_dmt(struct drm_device *dev,
 struct drm_display_mode *
 drm_display_mode_from_cea_vic(struct drm_device *dev,
                              u8 video_code);
+const u8 *drm_find_edid_extension(const struct edid *edid,
+                                 int ext_id, int *ext_index);
+
 
 #endif /* __DRM_EDID_H__ */