History

drm: Enable HDR infoframe support

Enable Dynamic Range and Mastering Infoframe for HDR content, which is defined in CEA 861.3 spec. The metadata will be computed based on blending policy in userspace compositors and passed as a connector property blob to driver. The same will be sent as infoframe to panel which support HDR. Added the const version of infoframe for DRM metadata for HDR. v2: Rebase and added Ville's POC changes. v3: No Change v4: Addressed Shashank's review comments and merged the patch making drm infoframe function arguments as constant. v5: Rebase v6: Fixed checkpatch warnings with --strict option. Addressed Shashank's review comments and added his RB. v7: Addressed Brian Starkey's review comments. Merged 2 patches into one. v8: Addressed Jonas Karlman review comments. v9: Addressed Jonas Karlman review comments. v10: Addressed Ville's review comments. v11: Added BUILD_BUG_ON and sizeof instead of magic numbers as per Ville's comments.

Uma Shankar committed 7 years ago

Commit 2cdbfd61 parent e85959d4 files · +295 −0Browse files

Unified · Split

4 files
  1. drivers/gpu/drm/drm_edid.c +72 −0
  2. drivers/video/hdmi.c +190 −0
  3. include/drm/drm_edid.h +5 −0
  4. include/linux/hdmi.h +28 −0
drivers/gpu/drm/drm_edid.c+72−0
@@ -4904,6 +4904,78 @@ static bool is_hdmi2_sink(struct drm_connector *connector) · 4903 unmodified lines
49044904 connector->display_info.color_formats & DRM_COLOR_FORMAT_YCRCB420;
49054905 }
49064906
4907+static inline bool is_eotf_supported(u8 output_eotf, u8 sink_eotf)
4908+{
4909+ return sink_eotf & BIT(output_eotf);
4910+}
4911+
4912+/**
4913+ * drm_hdmi_infoframe_set_hdr_metadata() - fill an HDMI DRM infoframe with
4914+ * HDR metadata from userspace
4915+ * @frame: HDMI DRM infoframe
4916+ * @hdr_metadata: hdr_source_metadata info from userspace
4917+ *
4918+ * Return: 0 on success or a negative error code on failure.
4919+ */
4920+int
4921+drm_hdmi_infoframe_set_hdr_metadata(struct hdmi_drm_infoframe *frame,
4922+ const struct drm_connector_state *conn_state)
4923+{
4924+ struct drm_connector *connector;
4925+ struct hdr_output_metadata *hdr_metadata;
4926+ int err;
4927+
4928+ if (!frame || !conn_state)
4929+ return -EINVAL;
4930+
4931+ connector = conn_state->connector;
4932+
4933+ if (!conn_state->hdr_output_metadata)
4934+ return -EINVAL;
4935+
4936+ hdr_metadata = conn_state->hdr_output_metadata->data;
4937+
4938+ if (!hdr_metadata || !connector)
4939+ return -EINVAL;
4940+
4941+ /* Sink EOTF is Bit map while infoframe is absolute values */
4942+ if (!is_eotf_supported(hdr_metadata->hdmi_metadata_type1.eotf,
4943+ connector->hdr_sink_metadata.hdmi_type1.eotf)) {
4944+ DRM_DEBUG_KMS("EOTF Not Supported\n");
4945+ return -EINVAL;
4946+ }
4947+
4948+ err = hdmi_drm_infoframe_init(frame);
4949+ if (err < 0)
4950+ return err;
4951+
4952+ frame->eotf = hdr_metadata->hdmi_metadata_type1.eotf;
4953+ frame->metadata_type = hdr_metadata->hdmi_metadata_type1.metadata_type;
4954+
4955+ BUILD_BUG_ON(sizeof(frame->display_primaries) !=
4956+ sizeof(hdr_metadata->hdmi_metadata_type1.display_primaries));
4957+ BUILD_BUG_ON(sizeof(frame->white_point) !=
4958+ sizeof(hdr_metadata->hdmi_metadata_type1.white_point));
4959+
4960+ memcpy(&frame->display_primaries,
4961+ &hdr_metadata->hdmi_metadata_type1.display_primaries,
4962+ sizeof(frame->display_primaries));
4963+
4964+ memcpy(&frame->white_point,
4965+ &hdr_metadata->hdmi_metadata_type1.white_point,
4966+ sizeof(frame->white_point));
4967+
4968+ frame->max_display_mastering_luminance =
4969+ hdr_metadata->hdmi_metadata_type1.max_display_mastering_luminance;
4970+ frame->min_display_mastering_luminance =
4971+ hdr_metadata->hdmi_metadata_type1.min_display_mastering_luminance;
4972+ frame->max_fall = hdr_metadata->hdmi_metadata_type1.max_fall;
4973+ frame->max_cll = hdr_metadata->hdmi_metadata_type1.max_cll;
4974+
4975+ return 0;
4976+}
4977+EXPORT_SYMBOL(drm_hdmi_infoframe_set_hdr_metadata);
4978+
49074979 /**
49084980 * drm_hdmi_avi_infoframe_from_display_mode() - fill an HDMI AVI infoframe with
49094981 * data from a DRM display mode
drivers/video/hdmi.c+190−0
@@ -650,6 +650,150 @@ hdmi_vendor_any_infoframe_check_only(const union hdmi_vendor_any_infoframe *fram · 649 unmodified lines
650650 return 0;
651651 }
652652
653+/**
654+ * hdmi_drm_infoframe_init() - initialize an HDMI Dynaminc Range and
655+ * mastering infoframe
656+ * @frame: HDMI DRM infoframe
657+ *
658+ * Returns 0 on success or a negative error code on failure.
659+ */
660+int hdmi_drm_infoframe_init(struct hdmi_drm_infoframe *frame)
661+{
662+ memset(frame, 0, sizeof(*frame));
663+
664+ frame->type = HDMI_INFOFRAME_TYPE_DRM;
665+ frame->version = 1;
666+ frame->length = HDMI_DRM_INFOFRAME_SIZE;
667+
668+ return 0;
669+}
670+EXPORT_SYMBOL(hdmi_drm_infoframe_init);
671+
672+static int hdmi_drm_infoframe_check_only(const struct hdmi_drm_infoframe *frame)
673+{
674+ if (frame->type != HDMI_INFOFRAME_TYPE_DRM ||
675+ frame->version != 1)
676+ return -EINVAL;
677+
678+ if (frame->length != HDMI_DRM_INFOFRAME_SIZE)
679+ return -EINVAL;
680+
681+ return 0;
682+}
683+
684+/**
685+ * hdmi_drm_infoframe_check() - check a HDMI DRM infoframe
686+ * @frame: HDMI DRM infoframe
687+ *
688+ * Validates that the infoframe is consistent.
689+ * Returns 0 on success or a negative error code on failure.
690+ */
691+int hdmi_drm_infoframe_check(struct hdmi_drm_infoframe *frame)
692+{
693+ return hdmi_drm_infoframe_check_only(frame);
694+}
695+EXPORT_SYMBOL(hdmi_drm_infoframe_check);
696+
697+/**
698+ * hdmi_drm_infoframe_pack_only() - write HDMI DRM infoframe to binary buffer
699+ * @frame: HDMI DRM infoframe
700+ * @buffer: destination buffer
701+ * @size: size of buffer
702+ *
703+ * Packs the information contained in the @frame structure into a binary
704+ * representation that can be written into the corresponding controller
705+ * registers. Also computes the checksum as required by section 5.3.5 of
706+ * the HDMI 1.4 specification.
707+ *
708+ * Returns the number of bytes packed into the binary buffer or a negative
709+ * error code on failure.
710+ */
711+ssize_t hdmi_drm_infoframe_pack_only(const struct hdmi_drm_infoframe *frame,
712+ void *buffer, size_t size)
713+{
714+ u8 *ptr = buffer;
715+ size_t length;
716+ int i;
717+
718+ length = HDMI_INFOFRAME_HEADER_SIZE + frame->length;
719+
720+ if (size < length)
721+ return -ENOSPC;
722+
723+ memset(buffer, 0, size);
724+
725+ ptr[0] = frame->type;
726+ ptr[1] = frame->version;
727+ ptr[2] = frame->length;
728+ ptr[3] = 0; /* checksum */
729+
730+ /* start infoframe payload */
731+ ptr += HDMI_INFOFRAME_HEADER_SIZE;
732+
733+ *ptr++ = frame->eotf;
734+ *ptr++ = frame->metadata_type;
735+
736+ for (i = 0; i < 3; i++) {
737+ *ptr++ = frame->display_primaries[i].x;
738+ *ptr++ = frame->display_primaries[i].x >> 8;
739+ *ptr++ = frame->display_primaries[i].y;
740+ *ptr++ = frame->display_primaries[i].y >> 8;
741+ }
742+
743+ *ptr++ = frame->white_point.x;
744+ *ptr++ = frame->white_point.x >> 8;
745+
746+ *ptr++ = frame->white_point.y;
747+ *ptr++ = frame->white_point.y >> 8;
748+
749+ *ptr++ = frame->max_display_mastering_luminance;
750+ *ptr++ = frame->max_display_mastering_luminance >> 8;
751+
752+ *ptr++ = frame->min_display_mastering_luminance;
753+ *ptr++ = frame->min_display_mastering_luminance >> 8;
754+
755+ *ptr++ = frame->max_cll;
756+ *ptr++ = frame->max_cll >> 8;
757+
758+ *ptr++ = frame->max_fall;
759+ *ptr++ = frame->max_fall >> 8;
760+
761+ hdmi_infoframe_set_checksum(buffer, length);
762+
763+ return length;
764+}
765+EXPORT_SYMBOL(hdmi_drm_infoframe_pack_only);
766+
767+/**
768+ * hdmi_drm_infoframe_pack() - check a HDMI DRM infoframe,
769+ * and write it to binary buffer
770+ * @frame: HDMI DRM infoframe
771+ * @buffer: destination buffer
772+ * @size: size of buffer
773+ *
774+ * Validates that the infoframe is consistent and updates derived fields
775+ * (eg. length) based on other fields, after which it packs the information
776+ * contained in the @frame structure into a binary representation that
777+ * can be written into the corresponding controller registers. This function
778+ * also computes the checksum as required by section 5.3.5 of the HDMI 1.4
779+ * specification.
780+ *
781+ * Returns the number of bytes packed into the binary buffer or a negative
782+ * error code on failure.
783+ */
784+ssize_t hdmi_drm_infoframe_pack(struct hdmi_drm_infoframe *frame,
785+ void *buffer, size_t size)
786+{
787+ int ret;
788+
789+ ret = hdmi_drm_infoframe_check(frame);
790+ if (ret)
791+ return ret;
792+
793+ return hdmi_drm_infoframe_pack_only(frame, buffer, size);
794+}
795+EXPORT_SYMBOL(hdmi_drm_infoframe_pack);
796+
653797 /*
654798 * hdmi_vendor_any_infoframe_check() - check a vendor infoframe
655799 */
@@ -758,6 +902,10 @@ hdmi_infoframe_pack_only(const union hdmi_infoframe *frame, void *buffer, size_t · 102 unmodified lines
758902 length = hdmi_avi_infoframe_pack_only(&frame->avi,
759903 buffer, size);
760904 break;
905+ case HDMI_INFOFRAME_TYPE_DRM:
906+ length = hdmi_drm_infoframe_pack_only(&frame->drm,
907+ buffer, size);
908+ break;
761909 case HDMI_INFOFRAME_TYPE_SPD:
762910 length = hdmi_spd_infoframe_pack_only(&frame->spd,
763911 buffer, size);
@@ -806,6 +954,9 @@ hdmi_infoframe_pack(union hdmi_infoframe *frame, · 42 unmodified lines
806954 case HDMI_INFOFRAME_TYPE_AVI:
807955 length = hdmi_avi_infoframe_pack(&frame->avi, buffer, size);
808956 break;
957+ case HDMI_INFOFRAME_TYPE_DRM:
958+ length = hdmi_drm_infoframe_pack(&frame->drm, buffer, size);
959+ break;
809960 case HDMI_INFOFRAME_TYPE_SPD:
810961 length = hdmi_spd_infoframe_pack(&frame->spd, buffer, size);
811962 break;
@@ -838,6 +989,8 @@ static const char *hdmi_infoframe_type_get_name(enum hdmi_infoframe_type type) · 26 unmodified lines
838989 return "Source Product Description (SPD)";
839990 case HDMI_INFOFRAME_TYPE_AUDIO:
840991 return "Audio";
992+ case HDMI_INFOFRAME_TYPE_DRM:
993+ return "Dynamic Range and Mastering";
841994 }
842995 return "Reserved";
843996 }
@@ -1284,6 +1437,40 @@ static void hdmi_audio_infoframe_log(const char *level, · 440 unmodified lines
12841437 frame->downmix_inhibit ? "Yes" : "No");
12851438 }
12861439
1440+/**
1441+ * hdmi_drm_infoframe_log() - log info of HDMI DRM infoframe
1442+ * @level: logging level
1443+ * @dev: device
1444+ * @frame: HDMI DRM infoframe
1445+ */
1446+static void hdmi_drm_infoframe_log(const char *level,
1447+ struct device *dev,
1448+ const struct hdmi_drm_infoframe *frame)
1449+{
1450+ int i;
1451+
1452+ hdmi_infoframe_log_header(level, dev,
1453+ (struct hdmi_any_infoframe *)frame);
1454+ hdmi_log("length: %d\n", frame->length);
1455+ hdmi_log("metadata type: %d\n", frame->metadata_type);
1456+ hdmi_log("eotf: %d\n", frame->eotf);
1457+ for (i = 0; i < 3; i++) {
1458+ hdmi_log("x[%d]: %d\n", i, frame->display_primaries[i].x);
1459+ hdmi_log("y[%d]: %d\n", i, frame->display_primaries[i].y);
1460+ }
1461+
1462+ hdmi_log("white point x: %d\n", frame->white_point.x);
1463+ hdmi_log("white point y: %d\n", frame->white_point.y);
1464+
1465+ hdmi_log("max_display_mastering_luminance: %d\n",
1466+ frame->max_display_mastering_luminance);
1467+ hdmi_log("min_display_mastering_luminance: %d\n",
1468+ frame->min_display_mastering_luminance);
1469+
1470+ hdmi_log("max_cll: %d\n", frame->max_cll);
1471+ hdmi_log("max_fall: %d\n", frame->max_fall);
1472+}
1473+
12871474 static const char *
12881475 hdmi_3d_structure_get_name(enum hdmi_3d_structure s3d_struct)
12891476 {
@@ -1372,6 +1559,9 @@ void hdmi_infoframe_log(const char *level, · 82 unmodified lines
13721559 case HDMI_INFOFRAME_TYPE_VENDOR:
13731560 hdmi_vendor_any_infoframe_log(level, dev, &frame->vendor);
13741561 break;
1562+ case HDMI_INFOFRAME_TYPE_DRM:
1563+ hdmi_drm_infoframe_log(level, dev, &frame->drm);
1564+ break;
13751565 }
13761566 }
13771567 EXPORT_SYMBOL(hdmi_infoframe_log);
include/drm/drm_edid.h+5−0
@@ -25,6 +25,7 @@ · 24 unmodified lines
2525
2626 #include <linux/types.h>
2727 #include <linux/hdmi.h>
28+#include <drm/drm_mode.h>
2829
2930 struct drm_device;
3031 struct i2c_adapter;
@@ -370,6 +371,10 @@ drm_hdmi_avi_infoframe_quant_range(struct hdmi_avi_infoframe *frame, · 339 unmodified lines
370371 const struct drm_display_mode *mode,
371372 enum hdmi_quantization_range rgb_quant_range);
372373
374+int
375+drm_hdmi_infoframe_set_hdr_metadata(struct hdmi_drm_infoframe *frame,
376+ const struct drm_connector_state *conn_state);
377+
373378 /**
374379 * drm_eld_mnl - Get ELD monitor name length in bytes.
375380 * @eld: pointer to an eld memory structure with mnl set
include/linux/hdmi.h+28−0
@@ -47,6 +47,7 @@ enum hdmi_infoframe_type { · 46 unmodified lines
4747 HDMI_INFOFRAME_TYPE_AVI = 0x82,
4848 HDMI_INFOFRAME_TYPE_SPD = 0x83,
4949 HDMI_INFOFRAME_TYPE_AUDIO = 0x84,
50+ HDMI_INFOFRAME_TYPE_DRM = 0x87,
5051 };
5152
5253 #define HDMI_IEEE_OUI 0x000c03
@@ -55,6 +56,7 @@ enum hdmi_infoframe_type { · 2 unmodified lines
5556 #define HDMI_AVI_INFOFRAME_SIZE 13
5657 #define HDMI_SPD_INFOFRAME_SIZE 25
5758 #define HDMI_AUDIO_INFOFRAME_SIZE 10
59+#define HDMI_DRM_INFOFRAME_SIZE 26
5860
5961 #define HDMI_INFOFRAME_SIZE(type) \
6062 (HDMI_INFOFRAME_HEADER_SIZE + HDMI_ ## type ## _INFOFRAME_SIZE)
@@ -185,12 +187,37 @@ struct hdmi_avi_infoframe { · 124 unmodified lines
185187 unsigned short right_bar;
186188 };
187189
190+/* DRM Infoframe as per CTA 861.G spec */
191+struct hdmi_drm_infoframe {
192+ enum hdmi_infoframe_type type;
193+ unsigned char version;
194+ unsigned char length;
195+ enum hdmi_eotf eotf;
196+ enum hdmi_metadata_type metadata_type;
197+ struct {
198+ u16 x, y;
199+ } display_primaries[3];
200+ struct {
201+ u16 x, y;
202+ } white_point;
203+ u16 max_display_mastering_luminance;
204+ u16 min_display_mastering_luminance;
205+ u16 max_cll;
206+ u16 max_fall;
207+};
208+
188209 int hdmi_avi_infoframe_init(struct hdmi_avi_infoframe *frame);
189210 ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
190211 size_t size);
191212 ssize_t hdmi_avi_infoframe_pack_only(const struct hdmi_avi_infoframe *frame,
192213 void *buffer, size_t size);
193214 int hdmi_avi_infoframe_check(struct hdmi_avi_infoframe *frame);
215+int hdmi_drm_infoframe_init(struct hdmi_drm_infoframe *frame);
216+ssize_t hdmi_drm_infoframe_pack(struct hdmi_drm_infoframe *frame, void *buffer,
217+ size_t size);
218+ssize_t hdmi_drm_infoframe_pack_only(const struct hdmi_drm_infoframe *frame,
219+ void *buffer, size_t size);
220+int hdmi_drm_infoframe_check(struct hdmi_drm_infoframe *frame);
194221
195222 enum hdmi_spd_sdi {
196223 HDMI_SPD_SDI_UNKNOWN,
@@ -381,6 +408,7 @@ union hdmi_infoframe { · 184 unmodified lines
381408 struct hdmi_spd_infoframe spd;
382409 union hdmi_vendor_any_infoframe vendor;
383410 struct hdmi_audio_infoframe audio;
411+ struct hdmi_drm_infoframe drm;
384412 };
385413
386414 ssize_t hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t