diff mbox

[i-g-t,v2] lib/igt_kms: Introduce get_first_connected_output macro

Message ID 1448074610-8661-1-git-send-email-vivek.kasireddy@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Vivek Kasireddy Nov. 21, 2015, 2:56 a.m. UTC
In some cases, we just need one valid (connected) output to perform
a test. This macro can help in these situations by not having to
put the test code inside a for loop that iterates over all the outputs.

v2: Added a brief documentation for this macro.

Suggested-by: Matt Roper <matthew.d.roper at intel.com>
Cc: Thomas Wood <thomas.wood@intel.com>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
---
 lib/igt_kms.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

Comments

Ander Conselvan de Oliveira Nov. 23, 2015, 1:49 p.m. UTC | #1
On Fri, 2015-11-20 at 18:56 -0800, Vivek Kasireddy wrote:
> In some cases, we just need one valid (connected) output to perform
> a test. This macro can help in these situations by not having to
> put the test code inside a for loop that iterates over all the outputs.
> 
> v2: Added a brief documentation for this macro.
> 
> Suggested-by: Matt Roper <matthew.d.roper at intel.com>
> Cc: Thomas Wood <thomas.wood@intel.com>
> Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
> ---
>  lib/igt_kms.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> index 965c47c..a0bb066 100644
> --- a/lib/igt_kms.h
> +++ b/lib/igt_kms.h
> @@ -279,6 +279,18 @@ void igt_wait_for_vblank(int drm_fd, enum pipe pipe);
>  	for (int i__ = 0; (plane) = &(display)->pipes[(pipe)].planes[i__], \
>  		     i__ < (display)->pipes[(pipe)].n_planes; i__++)
>  
> +/**
> + * get_first_connected_output:
> + * @display: Initialized igt_display_t type object
> + * @output: igt_output_t type object
> + *
> + * Returns: First valid (connected) output.
> + */
> +#define get_first_connected_output(display, output)		\
> +	for (int i__ = 0;  i__ < (display)->n_outputs; i__++)	\
> +		if ((output = &(display)->outputs[i__]), output->valid) \
> +			break
> +

Is it possible that there is no valid output?

Ander
Daniel Vetter Nov. 24, 2015, 12:20 p.m. UTC | #2
On Mon, Nov 23, 2015 at 03:49:20PM +0200, Ander Conselvan De Oliveira wrote:
> On Fri, 2015-11-20 at 18:56 -0800, Vivek Kasireddy wrote:
> > In some cases, we just need one valid (connected) output to perform
> > a test. This macro can help in these situations by not having to
> > put the test code inside a for loop that iterates over all the outputs.
> > 
> > v2: Added a brief documentation for this macro.
> > 
> > Suggested-by: Matt Roper <matthew.d.roper at intel.com>
> > Cc: Thomas Wood <thomas.wood@intel.com>
> > Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
> > ---
> >  lib/igt_kms.h | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> > 
> > diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> > index 965c47c..a0bb066 100644
> > --- a/lib/igt_kms.h
> > +++ b/lib/igt_kms.h
> > @@ -279,6 +279,18 @@ void igt_wait_for_vblank(int drm_fd, enum pipe pipe);
> >  	for (int i__ = 0; (plane) = &(display)->pipes[(pipe)].planes[i__], \
> >  		     i__ < (display)->pipes[(pipe)].n_planes; i__++)
> >  
> > +/**
> > + * get_first_connected_output:
> > + * @display: Initialized igt_display_t type object
> > + * @output: igt_output_t type object
> > + *
> > + * Returns: First valid (connected) output.
> > + */
> > +#define get_first_connected_output(display, output)		\
> > +	for (int i__ = 0;  i__ < (display)->n_outputs; i__++)	\
> > +		if ((output = &(display)->outputs[i__]), output->valid) \
> > +			break
> > +
> 
> Is it possible that there is no valid output?
> 

We also need to check at least crtc restrictions, otherwise bsw will fall
over mightly. Or well anything with MIPI DSI encoders.
-Daniel
Ville Syrjala Nov. 24, 2015, 1:03 p.m. UTC | #3
On Fri, Nov 20, 2015 at 06:56:50PM -0800, Vivek Kasireddy wrote:
> In some cases, we just need one valid (connected) output to perform
> a test. This macro can help in these situations by not having to
> put the test code inside a for loop that iterates over all the outputs.
> 
> v2: Added a brief documentation for this macro.
> 
> Suggested-by: Matt Roper <matthew.d.roper at intel.com>
> Cc: Thomas Wood <thomas.wood@intel.com>
> Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
> ---
>  lib/igt_kms.h | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
> 
> diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> index 965c47c..a0bb066 100644
> --- a/lib/igt_kms.h
> +++ b/lib/igt_kms.h
> @@ -279,6 +279,18 @@ void igt_wait_for_vblank(int drm_fd, enum pipe pipe);
>  	for (int i__ = 0; (plane) = &(display)->pipes[(pipe)].planes[i__], \
>  		     i__ < (display)->pipes[(pipe)].n_planes; i__++)
>  
> +/**
> + * get_first_connected_output:
> + * @display: Initialized igt_display_t type object
> + * @output: igt_output_t type object
> + *
> + * Returns: First valid (connected) output.
> + */
> +#define get_first_connected_output(display, output)		\
> +	for (int i__ = 0;  i__ < (display)->n_outputs; i__++)	\
> +		if ((output = &(display)->outputs[i__]), output->valid) \
> +			break

Why is this a fragile macro instead of a simple function that just
returns what we need?

> +
>  #define IGT_FIXED(i,f)	((i) << 16 | (f))
>  
>  void igt_enable_connectors(void);
> -- 
> 2.4.3
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff mbox

Patch

diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 965c47c..a0bb066 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -279,6 +279,18 @@  void igt_wait_for_vblank(int drm_fd, enum pipe pipe);
 	for (int i__ = 0; (plane) = &(display)->pipes[(pipe)].planes[i__], \
 		     i__ < (display)->pipes[(pipe)].n_planes; i__++)
 
+/**
+ * get_first_connected_output:
+ * @display: Initialized igt_display_t type object
+ * @output: igt_output_t type object
+ *
+ * Returns: First valid (connected) output.
+ */
+#define get_first_connected_output(display, output)		\
+	for (int i__ = 0;  i__ < (display)->n_outputs; i__++)	\
+		if ((output = &(display)->outputs[i__]), output->valid) \
+			break
+
 #define IGT_FIXED(i,f)	((i) << 16 | (f))
 
 void igt_enable_connectors(void);