From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Jani Nikula <jani.nikula@intel.com>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [Intel-gfx] [RFC v1 3/6] drm/displayid: add new displayid section/block iterators
Date: Wed, 10 Mar 2021 21:10:04 +0200 [thread overview]
Message-ID: <YEkZjAzG0izQmN/A@intel.com> (raw)
In-Reply-To: <d0fd3a830b0ebc082250fb6c1381bb8383715263.1615297748.git.jani.nikula@intel.com>
On Tue, Mar 09, 2021 at 03:54:11PM +0200, Jani Nikula wrote:
> Iterating DisplayID blocks across sections (in EDID extensions) is
> unnecessarily complicated for the caller. Implement DisplayID iterators
> to go through all blocks in all sections.
>
> Usage example:
>
> const struct displayid_block *block;
> struct displayid_iter iter;
>
> displayid_iter_edid_begin(edid, &iter);
> displayid_iter_for_each(block, &iter) {
> /* operate on block */
> }
> displayid_iter_end(&iter);
>
> When DisplayID is stored in EDID extensions, the DisplayID sections map
> to extensions as described in VESA DisplayID v1.3 Appendix B: DisplayID
> as an EDID Extension. This is implemented here.
>
> When DisplayID is stored in its dedicated DDC device 0xA4, according to
> VESA E-DDC v1.3, different rules apply for the structure. This is not
> implemented here, as we don't currently use it, but the idea is you'd
> have a different call for beginning the iteration, for example simply:
>
> displayid_iter_begin(displayid, &iter);
>
> instead of displayid_iter_edid_begin(), and everything else would be
> hidden away in the iterator functions.
>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> ---
> drivers/gpu/drm/drm_displayid.c | 74 +++++++++++++++++++++++++++++++++
> include/drm/drm_displayid.h | 18 ++++++++
> 2 files changed, 92 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_displayid.c b/drivers/gpu/drm/drm_displayid.c
> index 908bbe6feb61..88070267aac9 100644
> --- a/drivers/gpu/drm/drm_displayid.c
> +++ b/drivers/gpu/drm/drm_displayid.c
> @@ -57,3 +57,77 @@ const u8 *drm_find_displayid_extension(const struct edid *edid,
>
> return displayid;
> }
> +
> +void displayid_iter_edid_begin(const struct edid *edid,
> + struct displayid_iter *iter)
> +{
> + memset(iter, 0, sizeof(*iter));
> +
> + iter->edid = edid;
> +}
> +
> +static const struct displayid_block *
> +__displayid_iter_block(const struct displayid_iter *iter)
> +{
> + const struct displayid_block *block;
> +
> + if (!iter->section)
> + return NULL;
> +
> + block = (const struct displayid_block *)&iter->section[iter->idx];
> +
> + if (iter->idx + sizeof(struct displayid_block) <= iter->length &&
> + iter->idx + sizeof(struct displayid_block) + block->num_bytes <= iter->length &&
sizeof(*block) perhaps
> + block->num_bytes > 0)
> + return block;
> +
> + return NULL;
> +}
> +
> +const struct displayid_block *
> +__displayid_iter_next(struct displayid_iter *iter)
> +{
> + const struct displayid_block *block;
> +
> + if (!iter->edid)
> + return NULL;
> +
> + if (iter->section) {
> + /* current block should always be valid */
> + block = __displayid_iter_block(iter);
> + if (WARN_ON(!block)) {
> + iter->section = NULL;
> + iter->edid = NULL;
> + return NULL;
> + }
> +
> + /* next block in section */
> + iter->idx += sizeof(struct displayid_block) + block->num_bytes;
ditto
Looks like this should do the same thing the current thing does,
or at least I couldn't immediately spot nay differences.
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> +
> + block = __displayid_iter_block(iter);
> + if (block)
> + return block;
> + }
> +
> + for (;;) {
> + iter->section = drm_find_displayid_extension(iter->edid,
> + &iter->length,
> + &iter->idx,
> + &iter->ext_index);
> + if (!iter->section) {
> + iter->edid = NULL;
> + return NULL;
> + }
> +
> + iter->idx += sizeof(struct displayid_hdr);
> +
> + block = __displayid_iter_block(iter);
> + if (block)
> + return block;
> + }
> +}
> +
> +void displayid_iter_end(struct displayid_iter *iter)
> +{
> + memset(iter, 0, sizeof(*iter));
> +}
> diff --git a/include/drm/drm_displayid.h b/include/drm/drm_displayid.h
> index 3c6db22a518a..27e06c98db17 100644
> --- a/include/drm/drm_displayid.h
> +++ b/include/drm/drm_displayid.h
> @@ -108,4 +108,22 @@ const u8 *drm_find_displayid_extension(const struct edid *edid,
> int *length, int *idx,
> int *ext_index);
>
> +/* DisplayID iteration */
> +struct displayid_iter {
> + const struct edid *edid;
> +
> + const u8 *section;
> + int length;
> + int idx;
> + int ext_index;
> +};
> +
> +void displayid_iter_edid_begin(const struct edid *edid,
> + struct displayid_iter *iter);
> +const struct displayid_block *
> +__displayid_iter_next(struct displayid_iter *iter);
> +#define displayid_iter_for_each(__block, __iter) \
> + while (((__block) = __displayid_iter_next(__iter)))
> +void displayid_iter_end(struct displayid_iter *iter);
> +
> #endif
> --
> 2.20.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
--
Ville Syrjälä
Intel
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
next prev parent reply other threads:[~2021-03-10 19:10 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-09 13:54 [Intel-gfx] [RFC v1 0/6] drm/edid: overhaul displayid iterator Jani Nikula
2021-03-09 13:54 ` [Intel-gfx] [RFC v1 1/6] drm/edid: make a number of functions, parameters and variables const Jani Nikula
2021-03-10 18:54 ` Ville Syrjälä
2021-03-09 13:54 ` [Intel-gfx] [RFC v1 2/6] drm/displayid: add separate drm_displayid.c Jani Nikula
2021-03-10 19:00 ` Ville Syrjälä
2021-03-09 13:54 ` [Intel-gfx] [RFC v1 3/6] drm/displayid: add new displayid section/block iterators Jani Nikula
2021-03-10 19:10 ` Ville Syrjälä [this message]
2021-03-09 13:54 ` [Intel-gfx] [RFC v1 4/6] drm/edid: use the new displayid iterator for detailed modes Jani Nikula
2021-03-10 19:10 ` Ville Syrjälä
2021-03-09 13:54 ` [Intel-gfx] [RFC v1 5/6] drm/edid: use the new displayid iterator for finding CEA extension Jani Nikula
2021-03-10 19:12 ` Ville Syrjälä
2021-03-09 13:54 ` [Intel-gfx] [RFC v1 6/6] drm/edid: use the new displayid iterator for tile info Jani Nikula
2021-03-10 19:16 ` Ville Syrjälä
2021-03-10 8:27 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/edid: overhaul displayid iterator Patchwork
2021-03-10 8:29 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2021-03-10 8:56 ` [Intel-gfx] ✗ Fi.CI.BAT: failure " Patchwork
2021-03-10 9:26 ` [Intel-gfx] ✗ Fi.CI.CHECKPATCH: warning for drm/edid: overhaul displayid iterator (rev2) Patchwork
2021-03-10 9:29 ` [Intel-gfx] ✗ Fi.CI.SPARSE: " Patchwork
2021-03-10 9:54 ` [Intel-gfx] ✓ Fi.CI.BAT: success " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=YEkZjAzG0izQmN/A@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox