f57420c
From acf5a0100c98a040e5e07a79ecf4a83627da770e Mon Sep 17 00:00:00 2001
f57420c
From: Hans de Goede <hdegoede@redhat.com>
f57420c
Date: Thu, 23 Mar 2017 12:54:07 +0100
f57420c
Subject: [PATCH xserver] xf86: dri2: Use va_gl as vdpau_driver for Intel i965
f57420c
 GPUs
f57420c
f57420c
The modesetting driver (which now often is used with Intel GPUs),
f57420c
relies on dri2_probe_driver_name() to get the dri and vdpau driver
f57420c
names, before this commit it would always assign the same name to
f57420c
the 2 names. But the vdpau driver for i965 GPUs should be va_gl
f57420c
(i915 does not support vdpau at all).
f57420c
f57420c
This commit modifies the used lookup table and dri2_probe_driver_name()
f57420c
to set the vdpau_driver to va_gl for i965 GPUs, it leaves the 2
f57420c
names the same for all other GPUs.
f57420c
f57420c
Note this commit adds a FIXME comment for a memory leak in
f57420c
dri2_probe_driver_name(), that leak was already present and fixing
f57420c
it falls outside of the scope of this commit.
f57420c
f57420c
BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1413733
f57420c
Cc: kwizart@gmail.com
f57420c
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
f57420c
---
f57420c
 hw/xfree86/dri2/dri2.c                      | 31 +++++++++++++--------
f57420c
 hw/xfree86/dri2/pci_ids/pci_id_driver_map.h | 21 +++++++-------
f57420c
 2 files changed, 31 insertions(+), 21 deletions(-)
f57420c
f57420c
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
f57420c
index 6619e3aa7..1f8ad14bc 100644
f57420c
--- a/hw/xfree86/dri2/dri2.c
f57420c
+++ b/hw/xfree86/dri2/dri2.c
f57420c
@@ -1437,14 +1437,18 @@ get_prime_id(void)
f57420c
 
f57420c
 #include "pci_ids/pci_id_driver_map.h"
f57420c
 
f57420c
-static char *
f57420c
-dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info)
f57420c
+static void
f57420c
+dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info,
f57420c
+                       const char **dri_driver_ret,
f57420c
+                       const char **vdpau_driver_ret)
f57420c
 {
f57420c
 #ifdef WITH_LIBDRM
f57420c
     int i, j;
f57420c
-    char *driver = NULL;
f57420c
     drmDevicePtr dev;
f57420c
 
f57420c
+    *dri_driver_ret = NULL;
f57420c
+    *vdpau_driver_ret = NULL;
f57420c
+
f57420c
     /* For non-PCI devices and drmGetDevice fail, just assume that
f57420c
      * the 3D driver is named the same as the kernel driver. This is
f57420c
      * currently true for vc4 and msm (freedreno).
f57420c
@@ -1456,12 +1460,14 @@ dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info)
f57420c
             xf86DrvMsg(pScreen->myNum, X_ERROR,
f57420c
                        "[DRI2] Couldn't drmGetVersion() on non-PCI device, "
f57420c
                        "no driver name found.\n");
f57420c
-            return NULL;
f57420c
+            return;
f57420c
         }
f57420c
 
f57420c
-        driver = strndup(version->name, version->name_len);
f57420c
+        /* FIXME this gets leaked */
f57420c
+        *dri_driver_ret = strndup(version->name, version->name_len);
f57420c
+        *vdpau_driver_ret = *dri_driver_ret;
f57420c
         drmFreeVersion(version);
f57420c
-        return driver;
f57420c
+        return;
f57420c
     }
f57420c
 
f57420c
     for (i = 0; driver_map[i].driver; i++) {
f57420c
@@ -1469,13 +1475,15 @@ dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info)
f57420c
             continue;
f57420c
 
f57420c
         if (driver_map[i].num_chips_ids == -1) {
f57420c
-             driver = strdup(driver_map[i].driver);
f57420c
+             *dri_driver_ret = driver_map[i].driver;
f57420c
+             *vdpau_driver_ret = driver_map[i].vdpau_driver;
f57420c
              goto out;
f57420c
         }
f57420c
 
f57420c
         for (j = 0; j < driver_map[i].num_chips_ids; j++) {
f57420c
             if (driver_map[i].chip_ids[j] == dev->deviceinfo.pci->device_id) {
f57420c
-                driver = strdup(driver_map[i].driver);
f57420c
+                *dri_driver_ret = driver_map[i].driver;
f57420c
+                *vdpau_driver_ret = driver_map[i].vdpau_driver;
f57420c
                 goto out;
f57420c
             }
f57420c
         }
f57420c
@@ -1487,9 +1495,9 @@ dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info)
f57420c
                dev->deviceinfo.pci->vendor_id, dev->deviceinfo.pci->device_id);
f57420c
 out:
f57420c
     drmFreeDevice(&dev;;
f57420c
-    return driver;
f57420c
 #else
f57420c
-    return NULL;
f57420c
+    *dri_driver_ret = NULL;
f57420c
+    *vdpau_driver_ret = NULL;
f57420c
 #endif
f57420c
 }
f57420c
 
f57420c
@@ -1610,7 +1618,8 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
f57420c
         if (info->driverName) {
f57420c
             ds->driverNames[0] = info->driverName;
f57420c
         } else {
f57420c
-            ds->driverNames[0] = ds->driverNames[1] = dri2_probe_driver_name(pScreen, info);
f57420c
+            dri2_probe_driver_name(pScreen, info,
f57420c
+                                   &ds->driverNames[0], &ds->driverNames[1]);
f57420c
             if (!ds->driverNames[0])
f57420c
                 return FALSE;
f57420c
         }
f57420c
diff --git a/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h b/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h
f57420c
index da7ea1c1e..7036d1003 100644
f57420c
--- a/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h
f57420c
+++ b/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h
f57420c
@@ -66,21 +66,22 @@ static const int vmwgfx_chip_ids[] = {
f57420c
 static const struct {
f57420c
    int vendor_id;
f57420c
    const char *driver;
f57420c
+   const char *vdpau_driver;
f57420c
    const int *chip_ids;
f57420c
    int num_chips_ids;
f57420c
 } driver_map[] = {
f57420c
-   { 0x8086, "i915", i915_chip_ids, ARRAY_SIZE(i915_chip_ids) },
f57420c
-   { 0x8086, "i965", i965_chip_ids, ARRAY_SIZE(i965_chip_ids) },
f57420c
+   { 0x8086, "i915", "i915", i915_chip_ids, ARRAY_SIZE(i915_chip_ids) },
f57420c
+   { 0x8086, "i965", "va_gl", i965_chip_ids, ARRAY_SIZE(i965_chip_ids) },
f57420c
 #ifndef DRIVER_MAP_GALLIUM_ONLY
f57420c
-   { 0x1002, "radeon", r100_chip_ids, ARRAY_SIZE(r100_chip_ids) },
f57420c
-   { 0x1002, "r200", r200_chip_ids, ARRAY_SIZE(r200_chip_ids) },
f57420c
+   { 0x1002, "radeon", "radeon", r100_chip_ids, ARRAY_SIZE(r100_chip_ids) },
f57420c
+   { 0x1002, "r200", "r200", r200_chip_ids, ARRAY_SIZE(r200_chip_ids) },
f57420c
 #endif
f57420c
-   { 0x1002, "r300", r300_chip_ids, ARRAY_SIZE(r300_chip_ids) },
f57420c
-   { 0x1002, "r600", r600_chip_ids, ARRAY_SIZE(r600_chip_ids) },
f57420c
-   { 0x1002, "radeonsi", radeonsi_chip_ids, ARRAY_SIZE(radeonsi_chip_ids) },
f57420c
-   { 0x10de, "nouveau", NULL, -1 },
f57420c
-   { 0x1af4, "virtio_gpu", virtio_gpu_chip_ids, ARRAY_SIZE(virtio_gpu_chip_ids) },
f57420c
-   { 0x15ad, "vmwgfx", vmwgfx_chip_ids, ARRAY_SIZE(vmwgfx_chip_ids) },
f57420c
+   { 0x1002, "r300", "r300", r300_chip_ids, ARRAY_SIZE(r300_chip_ids) },
f57420c
+   { 0x1002, "r600","r600",  r600_chip_ids, ARRAY_SIZE(r600_chip_ids) },
f57420c
+   { 0x1002, "radeonsi", "radeonsi", radeonsi_chip_ids, ARRAY_SIZE(radeonsi_chip_ids) },
f57420c
+   { 0x10de, "nouveau", "nouveau", NULL, -1 },
f57420c
+   { 0x1af4, "virtio_gpu", "virtio_gpu", virtio_gpu_chip_ids, ARRAY_SIZE(virtio_gpu_chip_ids) },
f57420c
+   { 0x15ad, "vmwgfx", "vmwgfx", vmwgfx_chip_ids, ARRAY_SIZE(vmwgfx_chip_ids) },
f57420c
    { 0x0000, NULL, NULL, 0 },
f57420c
 };
f57420c
 
f57420c
-- 
f57420c
2.19.0
f57420c