Re: [Intel-gfx] [PATCH 06/18] video/hdmi: Handle the MPEG Source infoframe
On Fri, Sep 21, 2018 at 10:28:09AM +0200, Hans Verkuil wrote: > On 09/20/18 20:51, Ville Syrjala wrote: > > From: Ville Syrjälä > > > > Add the code to deal with the MPEG source infoframe. > > > > Blindly typed from the spec, and totally untested. > > I'm not sure this patch should be added at all. The CTA-861-G spec (section > 6.7) > says that the implementation of this infoframe is not recommended due to > unresolved > issues. > > I don't think I've ever seen it either. > > It obviously doesn't hurt to have this code, but I prefer to wait until there > are devices that actively set/use this infoframe. Sure. I'm totally fine with leaving it out. Just figured I'd send it out in case anyone has some use for it. > > Regards, > > Hans > > > > > Cc: Thierry Reding > > Cc: Hans Verkuil > > Cc: linux-me...@vger.kernel.org > > Signed-off-by: Ville Syrjälä > > --- > > drivers/video/hdmi.c | 229 > > +++ > > include/linux/hdmi.h | 27 ++ > > 2 files changed, 256 insertions(+) > > > > diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c > > index 9507f668a569..3d24c7746c51 100644 > > --- a/drivers/video/hdmi.c > > +++ b/drivers/video/hdmi.c > > @@ -706,6 +706,131 @@ hdmi_vendor_any_infoframe_pack(union > > hdmi_vendor_any_infoframe *frame, > > return hdmi_vendor_any_infoframe_pack_only(frame, buffer, size); > > } > > > > +/** > > + * hdmi_mpeg_source_infoframe_init() - initialize an HDMI MPEG Source > > infoframe > > + * @frame: HDMI MPEG Source infoframe > > + * > > + * Returns 0 on success or a negative error code on failure. > > + */ > > +int hdmi_mpeg_source_infoframe_init(struct hdmi_mpeg_source_infoframe > > *frame) > > +{ > > + memset(frame, 0, sizeof(*frame)); > > + > > + frame->type = HDMI_INFOFRAME_TYPE_MPEG_SOURCE; > > + frame->version = 1; > > + frame->length = HDMI_MPEG_SOURCE_INFOFRAME_SIZE; > > + > > + return 0; > > +} > > +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_init); > > + > > +static int hdmi_mpeg_source_infoframe_check_only(const struct > > hdmi_mpeg_source_infoframe *frame) > > +{ > > + if (frame->type != HDMI_INFOFRAME_TYPE_MPEG_SOURCE || > > + frame->version != 1 || > > + frame->length != HDMI_MPEG_SOURCE_INFOFRAME_SIZE) > > + return -EINVAL; > > + > > + return 0; > > +} > > + > > +/** > > + * hdmi_mpeg_source_infoframe_check() - Check and check a HDMI MPEG Source > > infoframe > > + * @frame: HDMI MPEG Source infoframe > > + * > > + * Validates that the infoframe is consistent and updates derived fields > > + * (eg. length) based on other fields. > > + * > > + * Returns 0 on success or a negative error code on failure. > > + */ > > +int hdmi_mpeg_source_infoframe_check(struct hdmi_mpeg_source_infoframe > > *frame) > > +{ > > + return hdmi_mpeg_source_infoframe_check_only(frame); > > +} > > +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_check); > > + > > +/** > > + * hdmi_mpeg_source_infoframe_pack_only() - write HDMI MPEG Source > > infoframe to binary buffer > > + * @frame: HDMI MPEG Source infoframe > > + * @buffer: destination buffer > > + * @size: size of buffer > > + * > > + * Packs the information contained in the @frame structure into a binary > > + * representation that can be written into the corresponding controller > > + * registers. Also computes the checksum as required by section 5.3.5 of > > + * the HDMI 1.4 specification. > > + * > > + * Returns the number of bytes packed into the binary buffer or a negative > > + * error code on failure. > > + */ > > +ssize_t hdmi_mpeg_source_infoframe_pack_only(const struct > > hdmi_mpeg_source_infoframe *frame, > > +void *buffer, size_t size) > > +{ > > + u8 *ptr = buffer; > > + size_t length; > > + int ret; > > + > > + ret = hdmi_mpeg_source_infoframe_check_only(frame); > > + if (ret) > > + return ret; > > + > > + length = HDMI_INFOFRAME_HEADER_SIZE + frame->length; > > + > > + if (size < length) > > + return -ENOSPC; > > + > > + memset(buffer, 0, size); > > + > > + ptr[0] = frame->type; > > + ptr[1] = frame->version; > > + ptr[2] = frame->length; > > + ptr[3] = 0; /* checksum */ > > + > > + /* start infoframe payload */ > > + ptr += HDMI_INFOFRAME_HEADER_SIZE; > > + > > + ptr[0] = frame->mpeg_bit_rate >> 0; > > + ptr[1] = frame->mpeg_bit_rate >> 8; > > + ptr[2] = frame->mpeg_bit_rate >> 16; > > + ptr[3] = frame->mpeg_bit_rate >> 24; > > + ptr[4] = (frame->field_repeat << 4) | frame->mpeg_frame; > > + > > + hdmi_infoframe_set_checksum(buffer, length); > > + > > + return length; > > +} > > +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_pack_only); > > + > > +/** > > + * hdmi_mpeg_source_infoframe_pack() - Check and check a HDMI MPEG Source > > infoframe, > > + * and write it to binary buffer > > + * @frame: HDMI MPEG Source infoframe > > + * @buffer: destination buffer > > + * @s
Re: [Intel-gfx] [PATCH 06/18] video/hdmi: Handle the MPEG Source infoframe
On 09/20/18 20:51, Ville Syrjala wrote: > From: Ville Syrjälä > > Add the code to deal with the MPEG source infoframe. > > Blindly typed from the spec, and totally untested. I'm not sure this patch should be added at all. The CTA-861-G spec (section 6.7) says that the implementation of this infoframe is not recommended due to unresolved issues. I don't think I've ever seen it either. It obviously doesn't hurt to have this code, but I prefer to wait until there are devices that actively set/use this infoframe. Regards, Hans > > Cc: Thierry Reding > Cc: Hans Verkuil > Cc: linux-me...@vger.kernel.org > Signed-off-by: Ville Syrjälä > --- > drivers/video/hdmi.c | 229 > +++ > include/linux/hdmi.h | 27 ++ > 2 files changed, 256 insertions(+) > > diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c > index 9507f668a569..3d24c7746c51 100644 > --- a/drivers/video/hdmi.c > +++ b/drivers/video/hdmi.c > @@ -706,6 +706,131 @@ hdmi_vendor_any_infoframe_pack(union > hdmi_vendor_any_infoframe *frame, > return hdmi_vendor_any_infoframe_pack_only(frame, buffer, size); > } > > +/** > + * hdmi_mpeg_source_infoframe_init() - initialize an HDMI MPEG Source > infoframe > + * @frame: HDMI MPEG Source infoframe > + * > + * Returns 0 on success or a negative error code on failure. > + */ > +int hdmi_mpeg_source_infoframe_init(struct hdmi_mpeg_source_infoframe *frame) > +{ > + memset(frame, 0, sizeof(*frame)); > + > + frame->type = HDMI_INFOFRAME_TYPE_MPEG_SOURCE; > + frame->version = 1; > + frame->length = HDMI_MPEG_SOURCE_INFOFRAME_SIZE; > + > + return 0; > +} > +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_init); > + > +static int hdmi_mpeg_source_infoframe_check_only(const struct > hdmi_mpeg_source_infoframe *frame) > +{ > + if (frame->type != HDMI_INFOFRAME_TYPE_MPEG_SOURCE || > + frame->version != 1 || > + frame->length != HDMI_MPEG_SOURCE_INFOFRAME_SIZE) > + return -EINVAL; > + > + return 0; > +} > + > +/** > + * hdmi_mpeg_source_infoframe_check() - Check and check a HDMI MPEG Source > infoframe > + * @frame: HDMI MPEG Source infoframe > + * > + * Validates that the infoframe is consistent and updates derived fields > + * (eg. length) based on other fields. > + * > + * Returns 0 on success or a negative error code on failure. > + */ > +int hdmi_mpeg_source_infoframe_check(struct hdmi_mpeg_source_infoframe > *frame) > +{ > + return hdmi_mpeg_source_infoframe_check_only(frame); > +} > +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_check); > + > +/** > + * hdmi_mpeg_source_infoframe_pack_only() - write HDMI MPEG Source infoframe > to binary buffer > + * @frame: HDMI MPEG Source infoframe > + * @buffer: destination buffer > + * @size: size of buffer > + * > + * Packs the information contained in the @frame structure into a binary > + * representation that can be written into the corresponding controller > + * registers. Also computes the checksum as required by section 5.3.5 of > + * the HDMI 1.4 specification. > + * > + * Returns the number of bytes packed into the binary buffer or a negative > + * error code on failure. > + */ > +ssize_t hdmi_mpeg_source_infoframe_pack_only(const struct > hdmi_mpeg_source_infoframe *frame, > + void *buffer, size_t size) > +{ > + u8 *ptr = buffer; > + size_t length; > + int ret; > + > + ret = hdmi_mpeg_source_infoframe_check_only(frame); > + if (ret) > + return ret; > + > + length = HDMI_INFOFRAME_HEADER_SIZE + frame->length; > + > + if (size < length) > + return -ENOSPC; > + > + memset(buffer, 0, size); > + > + ptr[0] = frame->type; > + ptr[1] = frame->version; > + ptr[2] = frame->length; > + ptr[3] = 0; /* checksum */ > + > + /* start infoframe payload */ > + ptr += HDMI_INFOFRAME_HEADER_SIZE; > + > + ptr[0] = frame->mpeg_bit_rate >> 0; > + ptr[1] = frame->mpeg_bit_rate >> 8; > + ptr[2] = frame->mpeg_bit_rate >> 16; > + ptr[3] = frame->mpeg_bit_rate >> 24; > + ptr[4] = (frame->field_repeat << 4) | frame->mpeg_frame; > + > + hdmi_infoframe_set_checksum(buffer, length); > + > + return length; > +} > +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_pack_only); > + > +/** > + * hdmi_mpeg_source_infoframe_pack() - Check and check a HDMI MPEG Source > infoframe, > + * and write it to binary buffer > + * @frame: HDMI MPEG Source infoframe > + * @buffer: destination buffer > + * @size: size of buffer > + * > + * Validates that the infoframe is consistent and updates derived fields > + * (eg. length) based on other fields, after which packs the information > + * contained in the @frame structure into a binary representation that > + * can be written into the corresponding controller registers. Also > + * computes the checksum as required by section 5.3.5 of the HDMI 1.4 > + * spe
[Intel-gfx] [PATCH 06/18] video/hdmi: Handle the MPEG Source infoframe
From: Ville Syrjälä Add the code to deal with the MPEG source infoframe. Blindly typed from the spec, and totally untested. Cc: Thierry Reding Cc: Hans Verkuil Cc: linux-me...@vger.kernel.org Signed-off-by: Ville Syrjälä --- drivers/video/hdmi.c | 229 +++ include/linux/hdmi.h | 27 ++ 2 files changed, 256 insertions(+) diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c index 9507f668a569..3d24c7746c51 100644 --- a/drivers/video/hdmi.c +++ b/drivers/video/hdmi.c @@ -706,6 +706,131 @@ hdmi_vendor_any_infoframe_pack(union hdmi_vendor_any_infoframe *frame, return hdmi_vendor_any_infoframe_pack_only(frame, buffer, size); } +/** + * hdmi_mpeg_source_infoframe_init() - initialize an HDMI MPEG Source infoframe + * @frame: HDMI MPEG Source infoframe + * + * Returns 0 on success or a negative error code on failure. + */ +int hdmi_mpeg_source_infoframe_init(struct hdmi_mpeg_source_infoframe *frame) +{ + memset(frame, 0, sizeof(*frame)); + + frame->type = HDMI_INFOFRAME_TYPE_MPEG_SOURCE; + frame->version = 1; + frame->length = HDMI_MPEG_SOURCE_INFOFRAME_SIZE; + + return 0; +} +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_init); + +static int hdmi_mpeg_source_infoframe_check_only(const struct hdmi_mpeg_source_infoframe *frame) +{ + if (frame->type != HDMI_INFOFRAME_TYPE_MPEG_SOURCE || + frame->version != 1 || + frame->length != HDMI_MPEG_SOURCE_INFOFRAME_SIZE) + return -EINVAL; + + return 0; +} + +/** + * hdmi_mpeg_source_infoframe_check() - Check and check a HDMI MPEG Source infoframe + * @frame: HDMI MPEG Source infoframe + * + * Validates that the infoframe is consistent and updates derived fields + * (eg. length) based on other fields. + * + * Returns 0 on success or a negative error code on failure. + */ +int hdmi_mpeg_source_infoframe_check(struct hdmi_mpeg_source_infoframe *frame) +{ + return hdmi_mpeg_source_infoframe_check_only(frame); +} +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_check); + +/** + * hdmi_mpeg_source_infoframe_pack_only() - write HDMI MPEG Source infoframe to binary buffer + * @frame: HDMI MPEG Source infoframe + * @buffer: destination buffer + * @size: size of buffer + * + * Packs the information contained in the @frame structure into a binary + * representation that can be written into the corresponding controller + * registers. Also computes the checksum as required by section 5.3.5 of + * the HDMI 1.4 specification. + * + * Returns the number of bytes packed into the binary buffer or a negative + * error code on failure. + */ +ssize_t hdmi_mpeg_source_infoframe_pack_only(const struct hdmi_mpeg_source_infoframe *frame, +void *buffer, size_t size) +{ + u8 *ptr = buffer; + size_t length; + int ret; + + ret = hdmi_mpeg_source_infoframe_check_only(frame); + if (ret) + return ret; + + length = HDMI_INFOFRAME_HEADER_SIZE + frame->length; + + if (size < length) + return -ENOSPC; + + memset(buffer, 0, size); + + ptr[0] = frame->type; + ptr[1] = frame->version; + ptr[2] = frame->length; + ptr[3] = 0; /* checksum */ + + /* start infoframe payload */ + ptr += HDMI_INFOFRAME_HEADER_SIZE; + + ptr[0] = frame->mpeg_bit_rate >> 0; + ptr[1] = frame->mpeg_bit_rate >> 8; + ptr[2] = frame->mpeg_bit_rate >> 16; + ptr[3] = frame->mpeg_bit_rate >> 24; + ptr[4] = (frame->field_repeat << 4) | frame->mpeg_frame; + + hdmi_infoframe_set_checksum(buffer, length); + + return length; +} +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_pack_only); + +/** + * hdmi_mpeg_source_infoframe_pack() - Check and check a HDMI MPEG Source infoframe, + * and write it to binary buffer + * @frame: HDMI MPEG Source infoframe + * @buffer: destination buffer + * @size: size of buffer + * + * Validates that the infoframe is consistent and updates derived fields + * (eg. length) based on other fields, after which packs the information + * contained in the @frame structure into a binary representation that + * can be written into the corresponding controller registers. Also + * computes the checksum as required by section 5.3.5 of the HDMI 1.4 + * specification. + * + * Returns the number of bytes packed into the binary buffer or a negative + * error code on failure. + */ +ssize_t hdmi_mpeg_source_infoframe_pack(struct hdmi_mpeg_source_infoframe *frame, + void *buffer, size_t size) +{ + int ret; + + ret = hdmi_mpeg_source_infoframe_check(frame); + if (ret) + return ret; + + return hdmi_mpeg_source_infoframe_pack_only(frame, buffer, size); +} +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_pack); + /** * hdmi_infoframe_check() - Check check a HDMI infoframe * @frame: HDMI infoframe @@ -