diff mbox

[v4,1/3] drm: add bus_formats and num_bus_formats fields to drm_display_info

Message ID 1417422061-10384-6-git-send-email-boris.brezillon@free-electrons.com (mailing list archive)
State New, archived
Headers show

Commit Message

Boris BREZILLON Dec. 1, 2014, 8:20 a.m. UTC
Add bus_formats and num_bus_formats fields and
drm_display_info_set_bus_formats helper function to specify the bus
formats supported by a given display.

This information can be used by display controller drivers to configure
the output interface appropriately (i.e. RGB565, RGB666 or RGB888 on raw
RGB or LVDS busses).

Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
---
 drivers/gpu/drm/drm_crtc.c | 32 ++++++++++++++++++++++++++++++++
 include/drm/drm_crtc.h     |  7 +++++++
 2 files changed, 39 insertions(+)

Comments

Thierry Reding Dec. 1, 2014, 3:42 p.m. UTC | #1
On Mon, Dec 01, 2014 at 09:20:59AM +0100, Boris Brezillon wrote:
> Add bus_formats and num_bus_formats fields and
> drm_display_info_set_bus_formats helper function to specify the bus
> formats supported by a given display.
> 
> This information can be used by display controller drivers to configure
> the output interface appropriately (i.e. RGB565, RGB666 or RGB888 on raw
> RGB or LVDS busses).
> 
> Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> ---
>  drivers/gpu/drm/drm_crtc.c | 32 ++++++++++++++++++++++++++++++++
>  include/drm/drm_crtc.h     |  7 +++++++
>  2 files changed, 39 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> index e79c8d3..d3b7ed0 100644
> --- a/drivers/gpu/drm/drm_crtc.c
> +++ b/drivers/gpu/drm/drm_crtc.c
> @@ -763,6 +763,38 @@ static void drm_mode_remove(struct drm_connector *connector,
>  	drm_mode_destroy(connector->dev, mode);
>  }
>  
> +/*

This needs a /** marker to make it a valid kerneldoc comment.

> + * drm_display_info_set_bus_formats - set the supported bus formats
> + * @info: display info to store bus formats in
> + * @fmts: array containing the supported bus formats
> + * @nfmts: the number of entries in the fmts array
> + *
> + * Store the suppported bus formats in display info structure.
> + * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
> + * a full list of available formats.
> + */
> +int drm_display_info_set_bus_formats(struct drm_display_info *info, const u32 *fmts,

This one still exceeds 80-characters per line, but perhaps I'm reviewing
the wrong patch? Also I think fmts should be formats here.

> +				     unsigned int num_fmts)

And this should be num_formats, for consistency. Also make sure to keep
this consistent with the kerneldoc.

> +{
> +	u32 *formats = NULL;

If you name the parameter formats, maybe bus_formats would be a good
alternative for this local variable. Or fmts here. I think it's most
important that the public API gets the more idiomatic name.

> +
> +	if (!fmts && num_fmts)
> +		return -EINVAL;
> +
> +	if (fmts && num_fmts) {
> +		formats = kmemdup(fmts, sizeof(*fmts) * num_fmts, GFP_KERNEL);
> +		if (!formats)
> +			return -ENOMEM;
> +	}
> +
> +	kfree(info->bus_formats);
> +	info->bus_formats = formats;
> +	info->num_bus_formats = num_fmts;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL(drm_display_info_set_bus_formats);

I think you'll want to call kfree() on the bus_formats array from
drm_connector_cleanup() as well to make sure you don't leak this on
driver unload.

Thierry
Boris BREZILLON Dec. 1, 2014, 9:22 p.m. UTC | #2
Hi Thierry,

On Mon, 1 Dec 2014 16:42:58 +0100
Thierry Reding <thierry.reding@gmail.com> wrote:

> On Mon, Dec 01, 2014 at 09:20:59AM +0100, Boris Brezillon wrote:
> > Add bus_formats and num_bus_formats fields and
> > drm_display_info_set_bus_formats helper function to specify the bus
> > formats supported by a given display.
> > 
> > This information can be used by display controller drivers to configure
> > the output interface appropriately (i.e. RGB565, RGB666 or RGB888 on raw
> > RGB or LVDS busses).
> > 
> > Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
> > ---
> >  drivers/gpu/drm/drm_crtc.c | 32 ++++++++++++++++++++++++++++++++
> >  include/drm/drm_crtc.h     |  7 +++++++
> >  2 files changed, 39 insertions(+)
> > 
> > diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
> > index e79c8d3..d3b7ed0 100644
> > --- a/drivers/gpu/drm/drm_crtc.c
> > +++ b/drivers/gpu/drm/drm_crtc.c
> > @@ -763,6 +763,38 @@ static void drm_mode_remove(struct drm_connector *connector,
> >  	drm_mode_destroy(connector->dev, mode);
> >  }
> >  
> > +/*
> 
> This needs a /** marker to make it a valid kerneldoc comment.

Yep, I'll fix that.

> 
> > + * drm_display_info_set_bus_formats - set the supported bus formats
> > + * @info: display info to store bus formats in
> > + * @fmts: array containing the supported bus formats
> > + * @nfmts: the number of entries in the fmts array
> > + *
> > + * Store the suppported bus formats in display info structure.
> > + * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
> > + * a full list of available formats.
> > + */
> > +int drm_display_info_set_bus_formats(struct drm_display_info *info, const u32 *fmts,
> 
> This one still exceeds 80-characters per line, but perhaps I'm reviewing
> the wrong patch? Also I think fmts should be formats here.
> 
> > +				     unsigned int num_fmts)
> 
> And this should be num_formats, for consistency. Also make sure to keep
> this consistent with the kerneldoc.
> 
> > +{
> > +	u32 *formats = NULL;
> 
> If you name the parameter formats, maybe bus_formats would be a good
> alternative for this local variable. Or fmts here. I think it's most
> important that the public API gets the more idiomatic name.

Okay, I'll rework the argument and variable names.

> 
> > +
> > +	if (!fmts && num_fmts)
> > +		return -EINVAL;
> > +
> > +	if (fmts && num_fmts) {
> > +		formats = kmemdup(fmts, sizeof(*fmts) * num_fmts, GFP_KERNEL);
> > +		if (!formats)
> > +			return -ENOMEM;
> > +	}
> > +
> > +	kfree(info->bus_formats);
> > +	info->bus_formats = formats;
> > +	info->num_bus_formats = num_fmts;
> > +
> > +	return 0;
> > +}
> > +EXPORT_SYMBOL(drm_display_info_set_bus_formats);
> 
> I think you'll want to call kfree() on the bus_formats array from
> drm_connector_cleanup() as well to make sure you don't leak this on
> driver unload.

Indeed, I'll fix that memory leak.

Thanks,

Boris
diff mbox

Patch

diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
index e79c8d3..d3b7ed0 100644
--- a/drivers/gpu/drm/drm_crtc.c
+++ b/drivers/gpu/drm/drm_crtc.c
@@ -763,6 +763,38 @@  static void drm_mode_remove(struct drm_connector *connector,
 	drm_mode_destroy(connector->dev, mode);
 }
 
+/*
+ * drm_display_info_set_bus_formats - set the supported bus formats
+ * @info: display info to store bus formats in
+ * @fmts: array containing the supported bus formats
+ * @nfmts: the number of entries in the fmts array
+ *
+ * Store the suppported bus formats in display info structure.
+ * See MEDIA_BUS_FMT_* definitions in include/uapi/linux/media-bus-format.h for
+ * a full list of available formats.
+ */
+int drm_display_info_set_bus_formats(struct drm_display_info *info, const u32 *fmts,
+				     unsigned int num_fmts)
+{
+	u32 *formats = NULL;
+
+	if (!fmts && num_fmts)
+		return -EINVAL;
+
+	if (fmts && num_fmts) {
+		formats = kmemdup(fmts, sizeof(*fmts) * num_fmts, GFP_KERNEL);
+		if (!formats)
+			return -ENOMEM;
+	}
+
+	kfree(info->bus_formats);
+	info->bus_formats = formats;
+	info->num_bus_formats = num_fmts;
+
+	return 0;
+}
+EXPORT_SYMBOL(drm_display_info_set_bus_formats);
+
 /**
  * drm_connector_get_cmdline_mode - reads the user's cmdline mode
  * @connector: connector to quwery
diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h
index c40070a..a35844f 100644
--- a/include/drm/drm_crtc.h
+++ b/include/drm/drm_crtc.h
@@ -31,6 +31,7 @@ 
 #include <linux/idr.h>
 #include <linux/fb.h>
 #include <linux/hdmi.h>
+#include <linux/media-bus-format.h>
 #include <uapi/drm/drm_mode.h>
 #include <uapi/drm/drm_fourcc.h>
 #include <drm/drm_modeset_lock.h>
@@ -130,6 +131,9 @@  struct drm_display_info {
 	enum subpixel_order subpixel_order;
 	u32 color_formats;
 
+	const u32 *bus_formats;
+	unsigned int num_bus_formats;
+
 	/* Mask of supported hdmi deep color modes */
 	u8 edid_hdmi_dc_modes;
 
@@ -982,6 +986,9 @@  extern int drm_mode_connector_set_path_property(struct drm_connector *connector,
 extern int drm_mode_connector_update_edid_property(struct drm_connector *connector,
 						struct edid *edid);
 
+extern int drm_display_info_set_bus_formats(struct drm_display_info *info,
+					    const u32 *fmts, unsigned int nfmts);
+
 static inline bool drm_property_type_is(struct drm_property *property,
 		uint32_t type)
 {