[igt-dev] [PATCH i-g-t 2/6] lib/igt_device: Introduce igt_device_get_card_index

Chris Wilson chris at chris-wilson.co.uk
Wed Mar 13 13:02:27 UTC 2019


Quoting Michał Winiarski (2019-03-13 12:53:28)
> And use it! But let's start small.
> Rather than going with "and by the way, here's the card index" from
> igt_sysfs_path, we're making things more explicit.
> 
> Signed-off-by: Michał Winiarski <michal.winiarski at intel.com>
> ---
>  lib/igt_device.c         | 19 +++++++++++++++++++
>  lib/igt_device.h         |  2 ++
>  lib/igt_sysfs.c          | 11 +++++++----
>  lib/igt_sysfs.h          |  2 +-
>  tests/i915/i915_pm_rpm.c |  2 +-
>  5 files changed, 30 insertions(+), 6 deletions(-)
> 
> diff --git a/lib/igt_device.c b/lib/igt_device.c
> index 5b3722c8..08f39c8b 100644
> --- a/lib/igt_device.c
> +++ b/lib/igt_device.c
> @@ -22,6 +22,8 @@
>   *
>   */
>  
> +#include <sys/stat.h>
> +#include <sys/sysmacros.h>
>  #include "igt.h"
>  #include "igt_device.h"
>  
> @@ -84,3 +86,20 @@ void igt_device_drop_master(int fd)
>                               "Failed to drop DRM master.\n");
>         }
>  }
> +
> +/**
> + * igt_device_get_card_index:
> + * @fd: the device
> + *
> + * Returns:
> + * Index (N) of /dev/dri/cardN or /dev/dri/renderDN corresponding with fd.
> + *
> + */
> +int igt_device_get_card_index(int fd)
> +{
> +       struct stat st;
> +
> +       igt_fail_on(fstat(fd, &st) || !S_ISCHR(st.st_mode));

I wonder... My desire for internal_assert() grows stronger so that we
can distinguish between test failures (igt_assert) and programming
failures, of which I'd class this.

> +
> +       return minor(st.st_rdev);

Hmm. Render nodes?

Ok, you mention it returns the high values for renderD.

> +}
> diff --git a/lib/igt_device.h b/lib/igt_device.h
> index 2995f969..9d7dc2c3 100644
> --- a/lib/igt_device.h
> +++ b/lib/igt_device.h
> @@ -31,4 +31,6 @@ void igt_device_set_master(int fd);
>  int __igt_device_drop_master(int fd);
>  void igt_device_drop_master(int fd);
>  
> +int igt_device_get_card_index(int fd);
> +
>  #endif /* __IGT_DEVICE_H__ */
> diff --git a/lib/igt_sysfs.c b/lib/igt_sysfs.c
> index c57e4ae2..fd075cd6 100644
> --- a/lib/igt_sysfs.c
> +++ b/lib/igt_sysfs.c
> @@ -41,6 +41,7 @@
>  
>  #include "igt_core.h"
>  #include "igt_sysfs.h"
> +#include "igt_device.h"
>  
>  /**
>   * SECTION:igt_sysfs
> @@ -96,7 +97,7 @@ static int writeN(int fd, const char *buf, int len)
>   * Returns:
>   * The directory path, or NULL on failure.
>   */
> -char *igt_sysfs_path(int device, char *path, int pathlen, int *idx)
> +char *igt_sysfs_path(int device, char *path, int pathlen)

And not a single tear was shed. But there appears to be random comments
above still referring to @idx.

Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
-Chris


More information about the igt-dev mailing list