diff mbox series

[2/3] drm: Add Wrapper Functions for ELD SAD Extraction

Message ID 20230821160004.2821445-3-mitulkumar.ajitkumar.golani@intel.com (mailing list archive)
State New, archived
Headers show
Series Get optimal audio frequency and channels | expand

Commit Message

Golani, Mitulkumar Ajitkumar Aug. 21, 2023, 4 p.m. UTC
Add wrapper functions to facilitate extracting Short Audio
Descriptor (SAD) information from EDID-Like Data (ELD) pointers
with different constness requirements.

1. `drm_eld_sad`: This function returns a constant `uint8_t`
pointer and wraps the main extraction function, allowing access
to SAD information while maintaining const correctness.

2. `drm_extract_sad_from_eld`: This function returns a mutable
`uint8_t` pointer and implements the core logic for extracting
SAD from the provided ELD pointer. It performs version and
maximum channel checks to ensure proper extraction.

These wrapper functions provide flexibility to the codebase,
allowing users to access SAD information while adhering to
const correctness when needed and modifying the pointer when
required.

Signed-off-by: Mitul Golani <mitulkumar.ajitkumar.golani@intel.com>
---
 include/drm/drm_edid.h | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

Comments

Kandpal, Suraj Sept. 5, 2023, 6:26 a.m. UTC | #1
> Subject: [Intel-gfx] [PATCH 2/3] drm: Add Wrapper Functions for ELD SAD
> Extraction
> 
> Add wrapper functions to facilitate extracting Short Audio Descriptor (SAD)
> information from EDID-Like Data (ELD) pointers with different constness
> requirements.
> 
> 1. `drm_eld_sad`: This function returns a constant `uint8_t` pointer and wraps
> the main extraction function, allowing access to SAD information while
> maintaining const correctness.
> 
> 2. `drm_extract_sad_from_eld`: This function returns a mutable `uint8_t`
> pointer and implements the core logic for extracting SAD from the provided ELD
> pointer. It performs version and maximum channel checks to ensure proper
> extraction.
> 
> These wrapper functions provide flexibility to the codebase, allowing users to
> access SAD information while adhering to const correctness when needed and
> modifying the pointer when required.
> 
> Signed-off-by: Mitul Golani <mitulkumar.ajitkumar.golani@intel.com>

This should also be floated in drm-devel mailing list.

> ---
>  include/drm/drm_edid.h | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h index
> 48e93f909ef6..626bc0d542eb 100644
> --- a/include/drm/drm_edid.h
> +++ b/include/drm/drm_edid.h
> @@ -418,11 +418,7 @@ static inline int drm_eld_mnl(const uint8_t *eld)
>  	return (eld[DRM_ELD_CEA_EDID_VER_MNL] &
> DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;  }
> 
> -/**
> - * drm_eld_sad - Get ELD SAD structures.
> - * @eld: pointer to an eld memory structure with sad_count set
> - */
> -static inline const uint8_t *drm_eld_sad(const uint8_t *eld)
> +static uint8_t *drm_extract_sad_from_eld(uint8_t *eld)
>  {
>  	unsigned int ver, mnl;
> 
> @@ -437,6 +433,15 @@ static inline const uint8_t *drm_eld_sad(const uint8_t
> *eld)
>  	return eld + DRM_ELD_CEA_SAD(mnl, 0);
>  }
> 
> +/**
> + * drm_eld_sad - Get ELD SAD structures.
> + * @eld: pointer to an eld memory structure with sad_count set  */
> +static inline const uint8_t *drm_eld_sad(const uint8_t *eld) {
> +	return drm_extract_sad_from_eld((uint8_t *)eld); }
> +

Not sure about the wrapper here the point of the const variable here was we do not want the eld to be changed
but adding a wrapper seems to make it irrelevant
Also why do you want to change pointer data that is a const.

Regards,
Suraj Kandpal
>  /**
>   * drm_eld_sad_count - Get ELD SAD count.
>   * @eld: pointer to an eld memory structure with sad_count set
> --
> 2.25.1
Jani Nikula Sept. 7, 2023, 9:35 a.m. UTC | #2
On Mon, 21 Aug 2023, Mitul Golani <mitulkumar.ajitkumar.golani@intel.com> wrote:
> Add wrapper functions to facilitate extracting Short Audio
> Descriptor (SAD) information from EDID-Like Data (ELD) pointers
> with different constness requirements.
>
> 1. `drm_eld_sad`: This function returns a constant `uint8_t`
> pointer and wraps the main extraction function, allowing access
> to SAD information while maintaining const correctness.
>
> 2. `drm_extract_sad_from_eld`: This function returns a mutable
> `uint8_t` pointer and implements the core logic for extracting
> SAD from the provided ELD pointer. It performs version and
> maximum channel checks to ensure proper extraction.
>
> These wrapper functions provide flexibility to the codebase,
> allowing users to access SAD information while adhering to
> const correctness when needed and modifying the pointer when
> required.

I've considered this, and in the end I think it's better to *not* make
it easier for drivers to modify the ELD buffer directly.

To that end, I wrote some helpers to modify the SADs using the existing
struct cea_sad abstraction [1]. Please have a look. It should make your
changes better focus on what you need to do here, instead of getting
distracted with ELD parsing details.

BR,
Jani.


[1] https://patchwork.freedesktop.org/series/123384/


>
> Signed-off-by: Mitul Golani <mitulkumar.ajitkumar.golani@intel.com>
> ---
>  include/drm/drm_edid.h | 15 ++++++++++-----
>  1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
> index 48e93f909ef6..626bc0d542eb 100644
> --- a/include/drm/drm_edid.h
> +++ b/include/drm/drm_edid.h
> @@ -418,11 +418,7 @@ static inline int drm_eld_mnl(const uint8_t *eld)
>  	return (eld[DRM_ELD_CEA_EDID_VER_MNL] & DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;
>  }
>  
> -/**
> - * drm_eld_sad - Get ELD SAD structures.
> - * @eld: pointer to an eld memory structure with sad_count set
> - */
> -static inline const uint8_t *drm_eld_sad(const uint8_t *eld)
> +static uint8_t *drm_extract_sad_from_eld(uint8_t *eld)
>  {
>  	unsigned int ver, mnl;
>  
> @@ -437,6 +433,15 @@ static inline const uint8_t *drm_eld_sad(const uint8_t *eld)
>  	return eld + DRM_ELD_CEA_SAD(mnl, 0);
>  }
>  
> +/**
> + * drm_eld_sad - Get ELD SAD structures.
> + * @eld: pointer to an eld memory structure with sad_count set
> + */
> +static inline const uint8_t *drm_eld_sad(const uint8_t *eld)
> +{
> +	return drm_extract_sad_from_eld((uint8_t *)eld);
> +}
> +
>  /**
>   * drm_eld_sad_count - Get ELD SAD count.
>   * @eld: pointer to an eld memory structure with sad_count set
diff mbox series

Patch

diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index 48e93f909ef6..626bc0d542eb 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -418,11 +418,7 @@  static inline int drm_eld_mnl(const uint8_t *eld)
 	return (eld[DRM_ELD_CEA_EDID_VER_MNL] & DRM_ELD_MNL_MASK) >> DRM_ELD_MNL_SHIFT;
 }
 
-/**
- * drm_eld_sad - Get ELD SAD structures.
- * @eld: pointer to an eld memory structure with sad_count set
- */
-static inline const uint8_t *drm_eld_sad(const uint8_t *eld)
+static uint8_t *drm_extract_sad_from_eld(uint8_t *eld)
 {
 	unsigned int ver, mnl;
 
@@ -437,6 +433,15 @@  static inline const uint8_t *drm_eld_sad(const uint8_t *eld)
 	return eld + DRM_ELD_CEA_SAD(mnl, 0);
 }
 
+/**
+ * drm_eld_sad - Get ELD SAD structures.
+ * @eld: pointer to an eld memory structure with sad_count set
+ */
+static inline const uint8_t *drm_eld_sad(const uint8_t *eld)
+{
+	return drm_extract_sad_from_eld((uint8_t *)eld);
+}
+
 /**
  * drm_eld_sad_count - Get ELD SAD count.
  * @eld: pointer to an eld memory structure with sad_count set