Re: [Mesa-dev] [PATCH 1/5] egl/android: use drmDevice instead of the manual /dev/dri iteration

2018-08-13 Thread Robert Foss

Hey again

On 13/08/2018 21.01, Robert Foss wrote:

Hey Emil,

On 13/08/2018 16.44, Emil Velikov wrote:

From: Emil Velikov 

Replace the manual handling of /dev/dri in famour of the drmDevice API.
The latter provides a consistent way of enumerating the devices,
providing device details as needed.

Cc: Robert Foss 
Cc: Tomasz Figa 
Signed-off-by: Emil Velikov 
---
If using VGEM the following patch is needed [1]. It's been on the list
for ages - will double-check and commmit it to drm-misc.

[1] https://lists.freedesktop.org/archives/dri-devel/2018-March/170944.html
---
  src/egl/drivers/dri2/platform_android.c | 23 +--
  1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c

index cc16fd8118f..685851acfc2 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -1290,6 +1290,7 @@ static int
  droid_open_device(_EGLDisplay *disp)
  {
 const int MAX_DRM_DEVICES = 32;
+   drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };


The android-8.0.0_r35 AOSP checkout I'm running doesn't want to compile the 
above line.


external/mesa3d/src/egl/drivers/dri2/platform_android.c:1259:33: error: 
variable-sized object may not be initialized

    drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };
     ^~~


external/mesa3d/src/egl/drivers/dri2/platform_android.c:1282:28: error: use of 
undeclared identifier 'dev_path'

  __func__, dev_path);



Sorry about the churn, but this error of course doesn't relate to the above one.
Still, this error string needs to be fixed.





 int prop_set, num_devices;
 int fd = -1, fallback_fd = -1;
@@ -1299,23 +1300,17 @@ droid_open_device(_EGLDisplay *disp)
 if (property_get("drm.gpu.vendor_name", vendor_buf, NULL) > 0)
    vendor_name = vendor_buf;
-   const char *drm_dir_name = "/dev/dri";
-   DIR *sysdir = opendir(drm_dir_name);
+   num_devices = drmGetDevices2(0, devices, MAX_DRM_DEVICES);
+   if (num_devices < 0)
+  return num_devices;
-   if (!sysdir)
-   return -errno;
+   for (int i = 0; i < num_devices; i++) {
+  device = devices[i];
-   struct dirent *dent;
-   while ((dent = readdir(sysdir))) {
-  char dev_path[128];
-  const char render_dev_prefix[] = "renderD";
-  size_t prefix_len = sizeof(render_dev_prefix) - 1;
-
-  if (strncmp(render_dev_prefix, dent->d_name, prefix_len) != 0)
+  if (!(device->available_nodes & (1 << DRM_NODE_RENDER)))
   continue;
-  snprintf(dev_path, sizeof(dev_path), "%s/%s", drm_dir_name, 
dent->d_name);
-  fd = loader_open_device(dev_path);
+  fd = loader_open_device(device->nodes[DRM_NODE_RENDER]);
    if (fd < 0) {
   _eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s",
   __func__, dev_path);
@@ -1341,7 +1336,7 @@ droid_open_device(_EGLDisplay *disp)
 }
  success:
-   closedir(sysdir);
+   drmFreeDevices(devices, num_devices);
 if (fallback_fd < 0 && fd < 0) {
    _eglLog(_EGL_WARNING, "Failed to open any DRM device");


___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/5] egl/android: use drmDevice instead of the manual /dev/dri iteration

2018-08-13 Thread Robert Foss

Hey Emil,

On 13/08/2018 16.44, Emil Velikov wrote:

From: Emil Velikov 

Replace the manual handling of /dev/dri in famour of the drmDevice API.
The latter provides a consistent way of enumerating the devices,
providing device details as needed.

Cc: Robert Foss 
Cc: Tomasz Figa 
Signed-off-by: Emil Velikov 
---
If using VGEM the following patch is needed [1]. It's been on the list
for ages - will double-check and commmit it to drm-misc.

[1] https://lists.freedesktop.org/archives/dri-devel/2018-March/170944.html
---
  src/egl/drivers/dri2/platform_android.c | 23 +--
  1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index cc16fd8118f..685851acfc2 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -1290,6 +1290,7 @@ static int
  droid_open_device(_EGLDisplay *disp)
  {
 const int MAX_DRM_DEVICES = 32;
+   drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };


The android-8.0.0_r35 AOSP checkout I'm running doesn't want to compile the 
above line.


external/mesa3d/src/egl/drivers/dri2/platform_android.c:1259:33: error: 
variable-sized object may not be initialized

   drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };
^~~
external/mesa3d/src/egl/drivers/dri2/platform_android.c:1282:28: error: use of 
undeclared identifier 'dev_path'

 __func__, dev_path);



 int prop_set, num_devices;
 int fd = -1, fallback_fd = -1;
  
@@ -1299,23 +1300,17 @@ droid_open_device(_EGLDisplay *disp)

 if (property_get("drm.gpu.vendor_name", vendor_buf, NULL) > 0)
vendor_name = vendor_buf;
  
-   const char *drm_dir_name = "/dev/dri";

-   DIR *sysdir = opendir(drm_dir_name);
+   num_devices = drmGetDevices2(0, devices, MAX_DRM_DEVICES);
+   if (num_devices < 0)
+  return num_devices;
  
-   if (!sysdir)

-   return -errno;
+   for (int i = 0; i < num_devices; i++) {
+  device = devices[i];
  
-   struct dirent *dent;

-   while ((dent = readdir(sysdir))) {
-  char dev_path[128];
-  const char render_dev_prefix[] = "renderD";
-  size_t prefix_len = sizeof(render_dev_prefix) - 1;
-
-  if (strncmp(render_dev_prefix, dent->d_name, prefix_len) != 0)
+  if (!(device->available_nodes & (1 << DRM_NODE_RENDER)))
   continue;
  
-  snprintf(dev_path, sizeof(dev_path), "%s/%s", drm_dir_name, dent->d_name);

-  fd = loader_open_device(dev_path);
+  fd = loader_open_device(device->nodes[DRM_NODE_RENDER]);
if (fd < 0) {
   _eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s",
   __func__, dev_path);
@@ -1341,7 +1336,7 @@ droid_open_device(_EGLDisplay *disp)
 }
  
  success:

-   closedir(sysdir);
+   drmFreeDevices(devices, num_devices);
  
 if (fallback_fd < 0 && fd < 0) {

_eglLog(_EGL_WARNING, "Failed to open any DRM device");


___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/5] egl/android: use drmDevice instead of the manual /dev/dri iteration

2018-08-13 Thread Robert Foss

Hey,

On 13/08/2018 16.44, Emil Velikov wrote:

From: Emil Velikov 

Replace the manual handling of /dev/dri in famour of the drmDevice API.
The latter provides a consistent way of enumerating the devices,
providing device details as needed.


Thanks for coding this up, it's neater and the way to go since vitio-gpu
support landed in libdrm.

Reviewed-by: Robert Foss 



Cc: Robert Foss 
Cc: Tomasz Figa 
Signed-off-by: Emil Velikov 
---
If using VGEM the following patch is needed [1]. It's been on the list
for ages - will double-check and commmit it to drm-misc.

[1] https://lists.freedesktop.org/archives/dri-devel/2018-March/170944.html
---
  src/egl/drivers/dri2/platform_android.c | 23 +--
  1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/src/egl/drivers/dri2/platform_android.c 
b/src/egl/drivers/dri2/platform_android.c
index cc16fd8118f..685851acfc2 100644
--- a/src/egl/drivers/dri2/platform_android.c
+++ b/src/egl/drivers/dri2/platform_android.c
@@ -1290,6 +1290,7 @@ static int
  droid_open_device(_EGLDisplay *disp)
  {
 const int MAX_DRM_DEVICES = 32;
+   drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };
 int prop_set, num_devices;
 int fd = -1, fallback_fd = -1;
  
@@ -1299,23 +1300,17 @@ droid_open_device(_EGLDisplay *disp)

 if (property_get("drm.gpu.vendor_name", vendor_buf, NULL) > 0)
vendor_name = vendor_buf;
  
-   const char *drm_dir_name = "/dev/dri";

-   DIR *sysdir = opendir(drm_dir_name);
+   num_devices = drmGetDevices2(0, devices, MAX_DRM_DEVICES);
+   if (num_devices < 0)
+  return num_devices;
  
-   if (!sysdir)

-   return -errno;
+   for (int i = 0; i < num_devices; i++) {
+  device = devices[i];
  
-   struct dirent *dent;

-   while ((dent = readdir(sysdir))) {
-  char dev_path[128];
-  const char render_dev_prefix[] = "renderD";
-  size_t prefix_len = sizeof(render_dev_prefix) - 1;
-
-  if (strncmp(render_dev_prefix, dent->d_name, prefix_len) != 0)
+  if (!(device->available_nodes & (1 << DRM_NODE_RENDER)))
   continue;
  
-  snprintf(dev_path, sizeof(dev_path), "%s/%s", drm_dir_name, dent->d_name);

-  fd = loader_open_device(dev_path);
+  fd = loader_open_device(device->nodes[DRM_NODE_RENDER]);
if (fd < 0) {
   _eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s",
   __func__, dev_path);
@@ -1341,7 +1336,7 @@ droid_open_device(_EGLDisplay *disp)
 }
  
  success:

-   closedir(sysdir);
+   drmFreeDevices(devices, num_devices);
  
 if (fallback_fd < 0 && fd < 0) {

_eglLog(_EGL_WARNING, "Failed to open any DRM device");


___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/5] egl/android: use drmDevice instead of the manual /dev/dri iteration

2018-08-13 Thread Emil Velikov
On 13 August 2018 at 16:37, Frank Binns  wrote:
> Hi Emil,
>
> Emil Velikov  writes:
>
>> From: Emil Velikov 
>>
>> Replace the manual handling of /dev/dri in famour of the drmDevice API.
>
> s/famour/favour/
>
>> The latter provides a consistent way of enumerating the devices,
>> providing device details as needed.
>>
>> Cc: Robert Foss 
>> Cc: Tomasz Figa 
>> Signed-off-by: Emil Velikov 
>> ---
>> If using VGEM the following patch is needed [1]. It's been on the list
>> for ages - will double-check and commmit it to drm-misc.
>>
>> [1] https://lists.freedesktop.org/archives/dri-devel/2018-March/170944.html
>> ---
>>  src/egl/drivers/dri2/platform_android.c | 23 +--
>>  1 file changed, 9 insertions(+), 14 deletions(-)
>>
>> diff --git a/src/egl/drivers/dri2/platform_android.c 
>> b/src/egl/drivers/dri2/platform_android.c
>> index cc16fd8118f..685851acfc2 100644
>> --- a/src/egl/drivers/dri2/platform_android.c
>> +++ b/src/egl/drivers/dri2/platform_android.c
>> @@ -1290,6 +1290,7 @@ static int
>>  droid_open_device(_EGLDisplay *disp)
>>  {
>> const int MAX_DRM_DEVICES = 32;
>> +   drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };
>> int prop_set, num_devices;
>> int fd = -1, fallback_fd = -1;
>>
>> @@ -1299,23 +1300,17 @@ droid_open_device(_EGLDisplay *disp)
>> if (property_get("drm.gpu.vendor_name", vendor_buf, NULL) > 0)
>>vendor_name = vendor_buf;
>>
>> -   const char *drm_dir_name = "/dev/dri";
>> -   DIR *sysdir = opendir(drm_dir_name);
>> +   num_devices = drmGetDevices2(0, devices, MAX_DRM_DEVICES);
>
> It would be more robust to use ARRAY_SIZE here instead of
> MAX_DRM_DEVICES.
>
Thanks Frank - fixed both locally.

-Emil
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 1/5] egl/android: use drmDevice instead of the manual /dev/dri iteration

2018-08-13 Thread Frank Binns
Hi Emil,

Emil Velikov  writes:

> From: Emil Velikov 
>
> Replace the manual handling of /dev/dri in famour of the drmDevice API.

s/famour/favour/

> The latter provides a consistent way of enumerating the devices,
> providing device details as needed.
>
> Cc: Robert Foss 
> Cc: Tomasz Figa 
> Signed-off-by: Emil Velikov 
> ---
> If using VGEM the following patch is needed [1]. It's been on the list
> for ages - will double-check and commmit it to drm-misc.
>
> [1] https://lists.freedesktop.org/archives/dri-devel/2018-March/170944.html
> ---
>  src/egl/drivers/dri2/platform_android.c | 23 +--
>  1 file changed, 9 insertions(+), 14 deletions(-)
>
> diff --git a/src/egl/drivers/dri2/platform_android.c 
> b/src/egl/drivers/dri2/platform_android.c
> index cc16fd8118f..685851acfc2 100644
> --- a/src/egl/drivers/dri2/platform_android.c
> +++ b/src/egl/drivers/dri2/platform_android.c
> @@ -1290,6 +1290,7 @@ static int
>  droid_open_device(_EGLDisplay *disp)
>  {
> const int MAX_DRM_DEVICES = 32;
> +   drmDevicePtr device, devices[MAX_DRM_DEVICES] = { NULL };
> int prop_set, num_devices;
> int fd = -1, fallback_fd = -1;
>  
> @@ -1299,23 +1300,17 @@ droid_open_device(_EGLDisplay *disp)
> if (property_get("drm.gpu.vendor_name", vendor_buf, NULL) > 0)
>vendor_name = vendor_buf;
>  
> -   const char *drm_dir_name = "/dev/dri";
> -   DIR *sysdir = opendir(drm_dir_name);
> +   num_devices = drmGetDevices2(0, devices, MAX_DRM_DEVICES);

It would be more robust to use ARRAY_SIZE here instead of
MAX_DRM_DEVICES.

Thanks
Frank

> +   if (num_devices < 0)
> +  return num_devices;
>  
> -   if (!sysdir)
> -   return -errno;
> +   for (int i = 0; i < num_devices; i++) {
> +  device = devices[i];
>  
> -   struct dirent *dent;
> -   while ((dent = readdir(sysdir))) {
> -  char dev_path[128];
> -  const char render_dev_prefix[] = "renderD";
> -  size_t prefix_len = sizeof(render_dev_prefix) - 1;
> -
> -  if (strncmp(render_dev_prefix, dent->d_name, prefix_len) != 0)
> +  if (!(device->available_nodes & (1 << DRM_NODE_RENDER)))
>   continue;
>  
> -  snprintf(dev_path, sizeof(dev_path), "%s/%s", drm_dir_name, 
> dent->d_name);
> -  fd = loader_open_device(dev_path);
> +  fd = loader_open_device(device->nodes[DRM_NODE_RENDER]);
>if (fd < 0) {
>   _eglLog(_EGL_WARNING, "%s() Failed to open DRM device %s",
>   __func__, dev_path);
> @@ -1341,7 +1336,7 @@ droid_open_device(_EGLDisplay *disp)
> }
>  
>  success:
> -   closedir(sysdir);
> +   drmFreeDevices(devices, num_devices);
>  
> if (fallback_fd < 0 && fd < 0) {
>_eglLog(_EGL_WARNING, "Failed to open any DRM device");

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev