[Mesa-dev] [PATCH] loader: add a libdrm case for loader_get_device_name_for_fd

Jonathan Gray jsg at jsg.id.au
Tue Apr 19 03:03:41 UTC 2016


Any objections to this?

On Mon, Dec 21, 2015 at 04:39:55PM +1100, Jonathan Gray wrote:
> Use dev_node_from_fd() with HAVE_LIBDRM to provide an implmentation
> of loader_get_device_name_for_fd() for non-linux systems that
> use libdrm but don't have udev or sysfs.
> 
> Signed-off-by: Jonathan Gray <jsg at jsg.id.au>
> ---
>  src/loader/loader.c | 26 +++++++++++++++++++++++++-
>  1 file changed, 25 insertions(+), 1 deletion(-)
> 
> diff --git a/src/loader/loader.c b/src/loader/loader.c
> index 8634f45..522fba3 100644
> --- a/src/loader/loader.c
> +++ b/src/loader/loader.c
> @@ -445,7 +445,7 @@ int loader_get_user_preferred_fd(int default_fd, int *different_device)
>  }
>  #endif
>  
> -#if defined(HAVE_SYSFS)
> +#if defined(HAVE_SYSFS) || defined(HAVE_LIBDRM)
>  static int
>  dev_node_from_fd(int fd, unsigned int *maj, unsigned int *min)
>  {
> @@ -466,7 +466,9 @@ dev_node_from_fd(int fd, unsigned int *maj, unsigned int *min)
>  
>     return 0;
>  }
> +#endif
>  
> +#if defined(HAVE_SYSFS)
>  static int
>  sysfs_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
>  {
> @@ -671,6 +673,24 @@ sysfs_get_device_name_for_fd(int fd)
>  }
>  #endif
>  
> +#if defined(HAVE_LIBDRM)
> +static char *
> +drm_get_device_name_for_fd(int fd)
> +{
> +   unsigned int maj, min;
> +   char buf[0x40];
> +   int n;
> +
> +   if (dev_node_from_fd(fd, &maj, &min) < 0)
> +      return NULL;
> +
> +   n = snprintf(buf, sizeof(buf), DRM_DEV_NAME, DRM_DIR_NAME, min);
> +   if (n == -1 || n >= sizeof(buf))
> +      return NULL;
> +
> +   return strdup(buf);
> +}
> +#endif
>  
>  char *
>  loader_get_device_name_for_fd(int fd)
> @@ -685,6 +705,10 @@ loader_get_device_name_for_fd(int fd)
>     if ((result = sysfs_get_device_name_for_fd(fd)))
>        return result;
>  #endif
> +#if HAVE_LIBDRM
> +   if ((result = drm_get_device_name_for_fd(fd)))
> +      return result;
> +#endif
>     return result;
>  }
>  
> -- 
> 2.6.4
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list