loader: replace int/1/0 with bool/true/false
[mesa.git] / src / loader / loader.c
index d8d71c3020053d74d20f8ae6789f4a894872aeb7..873f55c8a9cb8540252d2bf3ec1e1b59a80bfd6d 100644 (file)
@@ -36,6 +36,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <stdlib.h>
+#include <limits.h>
 #include <sys/param.h>
 #ifdef MAJOR_IN_MKDEV
 #include <sys/mkdev.h>
@@ -184,7 +185,7 @@ static char *loader_get_dri_config_driver(int fd)
 
    driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
    driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0,
-                       "loader", kernel_driver);
+                       "loader", kernel_driver, NULL, 0);
    if (driCheckOption(&userInitOptions, "dri_driver", DRI_STRING)) {
       char *opt = driQueryOptionstr(&userInitOptions, "dri_driver");
       /* not an empty string */
@@ -205,7 +206,8 @@ static char *loader_get_dri_config_device_id(void)
    char *prime = NULL;
 
    driParseOptionInfo(&defaultInitOptions, __driConfigOptionsLoader);
-   driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0, "loader", NULL);
+   driParseConfigFiles(&userInitOptions, &defaultInitOptions, 0,
+                       "loader", NULL, NULL, 0);
    if (driCheckOption(&userInitOptions, "device_id", DRI_STRING))
       prime = strdup(driQueryOptionstr(&userInitOptions, "device_id"));
    driDestroyOptionCache(&userInitOptions);
@@ -384,27 +386,27 @@ int loader_get_user_preferred_fd(int default_fd, bool *different_device)
 
 #if defined(HAVE_LIBDRM)
 
-static int
+static bool
 drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
 {
    drmDevicePtr device;
-   int ret;
+   bool ret;
 
    if (drmGetDevice2(fd, 0, &device) == 0) {
       if (device->bustype == DRM_BUS_PCI) {
          *vendor_id = device->deviceinfo.pci->vendor_id;
          *chip_id = device->deviceinfo.pci->device_id;
-         ret = 1;
+         ret = true;
       }
       else {
          log_(_LOADER_DEBUG, "MESA-LOADER: device is not located on the PCI bus\n");
-         ret = 0;
+         ret = false;
       }
       drmFreeDevice(&device);
    }
    else {
       log_(_LOADER_WARNING, "MESA-LOADER: failed to retrieve device information\n");
-      ret = 0;
+      ret = false;
    }
 
    return ret;
@@ -412,14 +414,13 @@ drm_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
 #endif
 
 
-int
+bool
 loader_get_pci_id_for_fd(int fd, int *vendor_id, int *chip_id)
 {
 #if HAVE_LIBDRM
-   if (drm_get_pci_id_for_fd(fd, vendor_id, chip_id))
-      return 1;
+   return drm_get_pci_id_for_fd(fd, vendor_id, chip_id);
 #endif
-   return 0;
+   return false;
 }
 
 char *
@@ -483,6 +484,15 @@ loader_get_driver_for_fd(int fd)
          }
    }
 
+   driver = loader_get_kernel_driver_name(fd);
+   bool is_amdgpu = driver && strcmp(driver, "amdgpu") == 0;
+   free(driver);
+
+   if (is_amdgpu)
+      driver = strdup("radeonsi");
+   else
+      driver = NULL;
+
 out:
    log_(driver ? _LOADER_DEBUG : _LOADER_WARNING,
          "pci id for fd %d: %04x:%04x, driver %s\n",