diff mbox series

[i-g-t,3/5] lib: Report if kms is enabled on the display

Message ID 20180914201310.19527-3-chris@chris-wilson.co.uk (mailing list archive)
State New, archived
Headers show
Series [i-g-t,1/5] igt/kms_getfb: Check the iface exists before use | expand

Commit Message

Chris Wilson Sept. 14, 2018, 8:13 p.m. UTC
Some drivers may have disabled KMS or there may simply nothing attached
to the device. In either case KMS is unusable and we may prefer to skip.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
---
 lib/igt_kms.c | 14 ++++++++++++--
 lib/igt_kms.h |  3 ++-
 2 files changed, 14 insertions(+), 3 deletions(-)

Comments

Daniel Vetter Oct. 1, 2018, 8:46 a.m. UTC | #1
On Fri, Sep 14, 2018 at 09:13:08PM +0100, Chris Wilson wrote:
> Some drivers may have disabled KMS or there may simply nothing attached
> to the device. In either case KMS is unusable and we may prefer to skip.
> 
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
>  lib/igt_kms.c | 14 ++++++++++++--
>  lib/igt_kms.h |  3 ++-
>  2 files changed, 14 insertions(+), 3 deletions(-)
> 
> diff --git a/lib/igt_kms.c b/lib/igt_kms.c
> index 4563bfd9d..9710bcae1 100644
> --- a/lib/igt_kms.c
> +++ b/lib/igt_kms.c
> @@ -1843,8 +1843,9 @@ static void igt_fill_display_format_mod(igt_display_t *display);
>   * Initialize @display and allocate the various resources required. Use
>   * #igt_display_fini to release the resources when they are no longer required.
>   *
> + * Returns: true if the display has outputs and pipes available, false otherwise
>   */
> -void igt_display_init(igt_display_t *display, int drm_fd)
> +bool igt_display_init(igt_display_t *display, int drm_fd)
>  {
>  	drmModeRes *resources;
>  	drmModePlaneRes *plane_resources;
> @@ -1857,7 +1858,8 @@ void igt_display_init(igt_display_t *display, int drm_fd)
>  	display->drm_fd = drm_fd;
>  
>  	resources = drmModeGetResources(display->drm_fd);
> -	igt_assert(resources);
> +	if (!resources)
> +		goto out;
>  
>  	/*
>  	 * We cache the number of pipes, that number is a physical limit of the
> @@ -2004,7 +2006,15 @@ void igt_display_init(igt_display_t *display, int drm_fd)
>  	/* Set reasonable default values for every object in the display. */
>  	igt_display_reset(display);
>  
> +out:
>  	LOG_UNINDENT(display);
> +
> +	return display->n_pipes && display->n_outputs;
> +}
> +

Do we have any genuine cases where we want to init the display helpers and
not require pipes/outputs? I'm kinda leaning towards keeping the helper
api as-is, and putting the igt_require into igt_display_init(). We can
always have an __igt_display_init or stuff a bunch of subtests into an
igt_subtest_group.
-Daniel


> +void igt_display_require(igt_display_t *display, int drm_fd)
> +{
> +	igt_require(igt_display_init(display, drm_fd));
>  }
>  
>  /**
> diff --git a/lib/igt_kms.h b/lib/igt_kms.h
> index 3862efa28..73624399b 100644
> --- a/lib/igt_kms.h
> +++ b/lib/igt_kms.h
> @@ -378,7 +378,8 @@ struct igt_display {
>  	int format_mod_count;
>  };
>  
> -void igt_display_init(igt_display_t *display, int drm_fd);
> +bool igt_display_init(igt_display_t *display, int drm_fd);
> +void igt_display_require(igt_display_t *display, int drm_fd);
>  void igt_display_fini(igt_display_t *display);
>  void igt_display_reset(igt_display_t *display);
>  int  igt_display_commit2(igt_display_t *display, enum igt_commit_style s);
> -- 
> 2.19.0
> 
> _______________________________________________
> Intel-gfx mailing list
> Intel-gfx@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/intel-gfx
diff mbox series

Patch

diff --git a/lib/igt_kms.c b/lib/igt_kms.c
index 4563bfd9d..9710bcae1 100644
--- a/lib/igt_kms.c
+++ b/lib/igt_kms.c
@@ -1843,8 +1843,9 @@  static void igt_fill_display_format_mod(igt_display_t *display);
  * Initialize @display and allocate the various resources required. Use
  * #igt_display_fini to release the resources when they are no longer required.
  *
+ * Returns: true if the display has outputs and pipes available, false otherwise
  */
-void igt_display_init(igt_display_t *display, int drm_fd)
+bool igt_display_init(igt_display_t *display, int drm_fd)
 {
 	drmModeRes *resources;
 	drmModePlaneRes *plane_resources;
@@ -1857,7 +1858,8 @@  void igt_display_init(igt_display_t *display, int drm_fd)
 	display->drm_fd = drm_fd;
 
 	resources = drmModeGetResources(display->drm_fd);
-	igt_assert(resources);
+	if (!resources)
+		goto out;
 
 	/*
 	 * We cache the number of pipes, that number is a physical limit of the
@@ -2004,7 +2006,15 @@  void igt_display_init(igt_display_t *display, int drm_fd)
 	/* Set reasonable default values for every object in the display. */
 	igt_display_reset(display);
 
+out:
 	LOG_UNINDENT(display);
+
+	return display->n_pipes && display->n_outputs;
+}
+
+void igt_display_require(igt_display_t *display, int drm_fd)
+{
+	igt_require(igt_display_init(display, drm_fd));
 }
 
 /**
diff --git a/lib/igt_kms.h b/lib/igt_kms.h
index 3862efa28..73624399b 100644
--- a/lib/igt_kms.h
+++ b/lib/igt_kms.h
@@ -378,7 +378,8 @@  struct igt_display {
 	int format_mod_count;
 };
 
-void igt_display_init(igt_display_t *display, int drm_fd);
+bool igt_display_init(igt_display_t *display, int drm_fd);
+void igt_display_require(igt_display_t *display, int drm_fd);
 void igt_display_fini(igt_display_t *display);
 void igt_display_reset(igt_display_t *display);
 int  igt_display_commit2(igt_display_t *display, enum igt_commit_style s);