Skip to content

Commit

Permalink
video/hdmi: Add Unpack only function for DRM infoframe
Browse files Browse the repository at this point in the history
It adds an unpack only function for DRM infoframe for dynamic range and
mastering infoframe readout.
It unpacks the information data block contained in the binary buffer into
a structured frame of the HDMI Dynamic Range and Mastering (DRM)
information frame.

In contrast to hdmi_drm_infoframe_unpack() function, it does not verify
a checksum.

It can be used for unpacking a DP HDR Metadata Infoframe SDP case.
DP HDR Metadata Infoframe SDP uses the same Dynamic Range and Mastering
(DRM) information (CTA-861-G spec.) such as HDMI DRM infoframe.
But DP SDP header and payload structure are different from HDMI DRM
Infoframe. Therefore unpacking DRM infoframe for DP requires skipping of
a verifying checksum.

v9: Add clear comments to hdmi_drm_infoframe_unpack_only() and
    hdmi_drm_infoframe_unpack() (Laurent Pinchart)

Signed-off-by: Gwan-gyeong Mun <[email protected]>
Reviewed-by: Uma Shankar <[email protected]>
Cc: Laurent Pinchart <[email protected]>
Cc: Ville Syrjala <[email protected]>
Acked-by: Daniel Vetter <[email protected]>
Signed-off-by: Jani Nikula <[email protected]>
Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
  • Loading branch information
elongbug authored and jnikula committed May 14, 2020
1 parent 0f4013f commit f45ce93
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
65 changes: 46 additions & 19 deletions drivers/video/hdmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1768,20 +1768,21 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
}

/**
* hdmi_drm_infoframe_unpack() - unpack binary buffer to a HDMI DRM infoframe
* hdmi_drm_infoframe_unpack_only() - unpack binary buffer of CTA-861-G DRM
* infoframe DataBytes to a HDMI DRM
* infoframe
* @frame: HDMI DRM infoframe
* @buffer: source buffer
* @size: size of buffer
*
* Unpacks the information contained in binary @buffer into a structured
* @frame of the HDMI Dynamic Range and Mastering (DRM) information frame.
* Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
* specification.
* Unpacks CTA-861-G DRM infoframe DataBytes contained in the binary @buffer
* into a structured @frame of the HDMI Dynamic Range and Mastering (DRM)
* infoframe.
*
* Returns 0 on success or a negative error code on failure.
*/
static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,
const void *buffer, size_t size)
int hdmi_drm_infoframe_unpack_only(struct hdmi_drm_infoframe *frame,
const void *buffer, size_t size)
{
const u8 *ptr = buffer;
const u8 *temp;
Expand All @@ -1790,31 +1791,21 @@ static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,
int ret;
int i;

if (size < HDMI_INFOFRAME_SIZE(DRM))
return -EINVAL;

if (ptr[0] != HDMI_INFOFRAME_TYPE_DRM ||
ptr[1] != 1 ||
ptr[2] != HDMI_DRM_INFOFRAME_SIZE)
return -EINVAL;

if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(DRM)) != 0)
if (size < HDMI_DRM_INFOFRAME_SIZE)
return -EINVAL;

ret = hdmi_drm_infoframe_init(frame);
if (ret)
return ret;

ptr += HDMI_INFOFRAME_HEADER_SIZE;

frame->eotf = ptr[0] & 0x7;
frame->metadata_type = ptr[1] & 0x7;

temp = ptr + 2;
for (i = 0; i < 3; i++) {
x_lsb = *temp++;
x_msb = *temp++;
frame->display_primaries[i].x = (x_msb << 8) | x_lsb;
frame->display_primaries[i].x = (x_msb << 8) | x_lsb;
y_lsb = *temp++;
y_msb = *temp++;
frame->display_primaries[i].y = (y_msb << 8) | y_lsb;
Expand All @@ -1830,6 +1821,42 @@ static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,

return 0;
}
EXPORT_SYMBOL(hdmi_drm_infoframe_unpack_only);

/**
* hdmi_drm_infoframe_unpack() - unpack binary buffer to a HDMI DRM infoframe
* @frame: HDMI DRM infoframe
* @buffer: source buffer
* @size: size of buffer
*
* Unpacks the CTA-861-G DRM infoframe contained in the binary @buffer into
* a structured @frame of the HDMI Dynamic Range and Mastering (DRM)
* infoframe. It also verifies the checksum as required by section 5.3.5 of
* the HDMI 1.4 specification.
*
* Returns 0 on success or a negative error code on failure.
*/
static int hdmi_drm_infoframe_unpack(struct hdmi_drm_infoframe *frame,
const void *buffer, size_t size)
{
const u8 *ptr = buffer;
int ret;

if (size < HDMI_INFOFRAME_SIZE(DRM))
return -EINVAL;

if (ptr[0] != HDMI_INFOFRAME_TYPE_DRM ||
ptr[1] != 1 ||
ptr[2] != HDMI_DRM_INFOFRAME_SIZE)
return -EINVAL;

if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(DRM)) != 0)
return -EINVAL;

ret = hdmi_drm_infoframe_unpack_only(frame, ptr + HDMI_INFOFRAME_HEADER_SIZE,
size - HDMI_INFOFRAME_HEADER_SIZE);
return ret;
}

/**
* hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe
Expand Down
2 changes: 2 additions & 0 deletions include/linux/hdmi.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ ssize_t hdmi_drm_infoframe_pack(struct hdmi_drm_infoframe *frame, void *buffer,
ssize_t hdmi_drm_infoframe_pack_only(const struct hdmi_drm_infoframe *frame,
void *buffer, size_t size);
int hdmi_drm_infoframe_check(struct hdmi_drm_infoframe *frame);
int hdmi_drm_infoframe_unpack_only(struct hdmi_drm_infoframe *frame,
const void *buffer, size_t size);

enum hdmi_spd_sdi {
HDMI_SPD_SDI_UNKNOWN,
Expand Down

0 comments on commit f45ce93

Please sign in to comment.