2021-03-29 21:37:16 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
/*
|
|
|
|
* Copyright © 2021 Intel Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <drm/drm_displayid.h>
|
|
|
|
#include <drm/drm_edid.h>
|
|
|
|
#include <drm/drm_print.h>
|
|
|
|
|
2023-02-17 04:44:58 +08:00
|
|
|
static const struct displayid_header *
|
|
|
|
displayid_get_header(const u8 *displayid, int length, int index)
|
|
|
|
{
|
|
|
|
const struct displayid_header *base;
|
|
|
|
|
|
|
|
if (sizeof(*base) > length - index)
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
base = (const struct displayid_header *)&displayid[index];
|
|
|
|
|
|
|
|
return base;
|
|
|
|
}
|
|
|
|
|
2023-02-17 04:44:59 +08:00
|
|
|
static const struct displayid_header *
|
|
|
|
validate_displayid(const u8 *displayid, int length, int idx)
|
2021-03-29 21:37:16 +08:00
|
|
|
{
|
|
|
|
int i, dispid_length;
|
|
|
|
u8 csum = 0;
|
2021-03-29 21:37:22 +08:00
|
|
|
const struct displayid_header *base;
|
2021-03-29 21:37:16 +08:00
|
|
|
|
2023-02-17 04:44:58 +08:00
|
|
|
base = displayid_get_header(displayid, length, idx);
|
|
|
|
if (IS_ERR(base))
|
2023-02-17 04:44:59 +08:00
|
|
|
return base;
|
2021-03-29 21:37:16 +08:00
|
|
|
|
|
|
|
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)
|
2023-02-17 04:44:59 +08:00
|
|
|
return ERR_PTR(-EINVAL);
|
2021-03-29 21:37:16 +08:00
|
|
|
|
|
|
|
for (i = 0; i < dispid_length; i++)
|
|
|
|
csum += displayid[idx + i];
|
|
|
|
if (csum) {
|
|
|
|
DRM_NOTE("DisplayID checksum invalid, remainder is %d\n", csum);
|
2023-02-17 04:44:59 +08:00
|
|
|
return ERR_PTR(-EINVAL);
|
2021-03-29 21:37:16 +08:00
|
|
|
}
|
|
|
|
|
2023-02-17 04:44:59 +08:00
|
|
|
return base;
|
2021-03-29 21:37:16 +08:00
|
|
|
}
|
|
|
|
|
2022-05-09 20:03:23 +08:00
|
|
|
static const u8 *drm_find_displayid_extension(const struct drm_edid *drm_edid,
|
2021-03-29 21:37:20 +08:00
|
|
|
int *length, int *idx,
|
|
|
|
int *ext_index)
|
2021-03-29 21:37:16 +08:00
|
|
|
{
|
2022-05-09 20:03:23 +08:00
|
|
|
const u8 *displayid = drm_find_edid_extension(drm_edid, DISPLAYID_EXT, ext_index);
|
2021-03-29 21:37:22 +08:00
|
|
|
const struct displayid_header *base;
|
2021-03-29 21:37:16 +08:00
|
|
|
|
|
|
|
if (!displayid)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* EDID extensions block checksum isn't for us */
|
|
|
|
*length = EDID_LENGTH - 1;
|
|
|
|
*idx = 1;
|
|
|
|
|
2023-02-17 04:44:59 +08:00
|
|
|
base = validate_displayid(displayid, *length, *idx);
|
|
|
|
if (IS_ERR(base))
|
2021-03-29 21:37:16 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
*length = *idx + sizeof(*base) + base->bytes;
|
|
|
|
|
|
|
|
return displayid;
|
|
|
|
}
|
drm/displayid: add new displayid section/block iterators
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.
v2:
- sizeof(struct displayid_block) -> sizeof(*block) (Ville)
- remove __ prefix from displayid_iter_block
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/da3dead1752ab16c061f7bd248ac1a4268f7fefb.1617024940.git.jani.nikula@intel.com
2021-03-29 21:37:17 +08:00
|
|
|
|
2022-05-09 20:03:23 +08:00
|
|
|
void displayid_iter_edid_begin(const struct drm_edid *drm_edid,
|
drm/displayid: add new displayid section/block iterators
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.
v2:
- sizeof(struct displayid_block) -> sizeof(*block) (Ville)
- remove __ prefix from displayid_iter_block
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/da3dead1752ab16c061f7bd248ac1a4268f7fefb.1617024940.git.jani.nikula@intel.com
2021-03-29 21:37:17 +08:00
|
|
|
struct displayid_iter *iter)
|
|
|
|
{
|
|
|
|
memset(iter, 0, sizeof(*iter));
|
|
|
|
|
2022-05-09 20:03:23 +08:00
|
|
|
iter->drm_edid = drm_edid;
|
drm/displayid: add new displayid section/block iterators
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.
v2:
- sizeof(struct displayid_block) -> sizeof(*block) (Ville)
- remove __ prefix from displayid_iter_block
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/da3dead1752ab16c061f7bd248ac1a4268f7fefb.1617024940.git.jani.nikula@intel.com
2021-03-29 21:37:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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(*block) <= iter->length &&
|
2021-03-29 21:37:21 +08:00
|
|
|
iter->idx + sizeof(*block) + block->num_bytes <= iter->length)
|
drm/displayid: add new displayid section/block iterators
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.
v2:
- sizeof(struct displayid_block) -> sizeof(*block) (Ville)
- remove __ prefix from displayid_iter_block
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/da3dead1752ab16c061f7bd248ac1a4268f7fefb.1617024940.git.jani.nikula@intel.com
2021-03-29 21:37:17 +08:00
|
|
|
return block;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct displayid_block *
|
|
|
|
__displayid_iter_next(struct displayid_iter *iter)
|
|
|
|
{
|
|
|
|
const struct displayid_block *block;
|
|
|
|
|
2022-05-09 20:03:23 +08:00
|
|
|
if (!iter->drm_edid)
|
drm/displayid: add new displayid section/block iterators
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.
v2:
- sizeof(struct displayid_block) -> sizeof(*block) (Ville)
- remove __ prefix from displayid_iter_block
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/da3dead1752ab16c061f7bd248ac1a4268f7fefb.1617024940.git.jani.nikula@intel.com
2021-03-29 21:37:17 +08:00
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (iter->section) {
|
|
|
|
/* current block should always be valid */
|
|
|
|
block = displayid_iter_block(iter);
|
|
|
|
if (WARN_ON(!block)) {
|
|
|
|
iter->section = NULL;
|
2022-05-09 20:03:23 +08:00
|
|
|
iter->drm_edid = NULL;
|
drm/displayid: add new displayid section/block iterators
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.
v2:
- sizeof(struct displayid_block) -> sizeof(*block) (Ville)
- remove __ prefix from displayid_iter_block
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/da3dead1752ab16c061f7bd248ac1a4268f7fefb.1617024940.git.jani.nikula@intel.com
2021-03-29 21:37:17 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* next block in section */
|
|
|
|
iter->idx += sizeof(*block) + block->num_bytes;
|
|
|
|
|
|
|
|
block = displayid_iter_block(iter);
|
|
|
|
if (block)
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (;;) {
|
2023-02-17 04:45:00 +08:00
|
|
|
/* The first section we encounter is the base section */
|
|
|
|
bool base_section = !iter->section;
|
|
|
|
|
2022-05-09 20:03:23 +08:00
|
|
|
iter->section = drm_find_displayid_extension(iter->drm_edid,
|
drm/displayid: add new displayid section/block iterators
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.
v2:
- sizeof(struct displayid_block) -> sizeof(*block) (Ville)
- remove __ prefix from displayid_iter_block
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/da3dead1752ab16c061f7bd248ac1a4268f7fefb.1617024940.git.jani.nikula@intel.com
2021-03-29 21:37:17 +08:00
|
|
|
&iter->length,
|
|
|
|
&iter->idx,
|
|
|
|
&iter->ext_index);
|
|
|
|
if (!iter->section) {
|
2022-05-09 20:03:23 +08:00
|
|
|
iter->drm_edid = NULL;
|
drm/displayid: add new displayid section/block iterators
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.
v2:
- sizeof(struct displayid_block) -> sizeof(*block) (Ville)
- remove __ prefix from displayid_iter_block
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/da3dead1752ab16c061f7bd248ac1a4268f7fefb.1617024940.git.jani.nikula@intel.com
2021-03-29 21:37:17 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2023-02-17 04:45:00 +08:00
|
|
|
/* Save the structure version and primary use case. */
|
|
|
|
if (base_section) {
|
|
|
|
const struct displayid_header *base;
|
|
|
|
|
|
|
|
base = displayid_get_header(iter->section, iter->length,
|
|
|
|
iter->idx);
|
|
|
|
if (!IS_ERR(base)) {
|
|
|
|
iter->version = base->rev;
|
|
|
|
iter->primary_use = base->prod_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 21:37:22 +08:00
|
|
|
iter->idx += sizeof(struct displayid_header);
|
drm/displayid: add new displayid section/block iterators
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.
v2:
- sizeof(struct displayid_block) -> sizeof(*block) (Ville)
- remove __ prefix from displayid_iter_block
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/da3dead1752ab16c061f7bd248ac1a4268f7fefb.1617024940.git.jani.nikula@intel.com
2021-03-29 21:37:17 +08:00
|
|
|
|
|
|
|
block = displayid_iter_block(iter);
|
|
|
|
if (block)
|
|
|
|
return block;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void displayid_iter_end(struct displayid_iter *iter)
|
|
|
|
{
|
|
|
|
memset(iter, 0, sizeof(*iter));
|
|
|
|
}
|
2023-02-17 04:45:00 +08:00
|
|
|
|
|
|
|
/* DisplayID Structure Version/Revision from the Base Section. */
|
|
|
|
u8 displayid_version(const struct displayid_iter *iter)
|
|
|
|
{
|
|
|
|
return iter->version;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* DisplayID Primary Use Case (2.0+) or Product Type Identifier (1.0-1.3) from
|
|
|
|
* the Base Section.
|
|
|
|
*/
|
|
|
|
u8 displayid_primary_use(const struct displayid_iter *iter)
|
|
|
|
{
|
|
|
|
return iter->primary_use;
|
|
|
|
}
|