842f3b
From 27043630ebb54fd1915c5d1814ab62079ca3eca9 Mon Sep 17 00:00:00 2001
842f3b
From: Hans de Goede <hdegoede@redhat.com>
842f3b
Date: Thu, 23 Mar 2017 12:54:07 +0100
842f3b
Subject: [PATCH xserver] xf86: dri2: Use va_gl as vdpau_driver for Intel i965
842f3b
 GPUs
842f3b
842f3b
The modesetting driver (which now often is used with Intel GPUs),
842f3b
relies on dri2_probe_driver_name() to get the dri and vdpau driver
842f3b
names, before this commit it would always assign the same name to
842f3b
the 2 names. But the vdpau driver for i965 GPUs should be va_gl
842f3b
(i915 does not support vdpau at all).
842f3b
842f3b
This commit modifies the used lookup table and dri2_probe_driver_name()
842f3b
to set the vdpau_driver to va_gl for i965 GPUs, it leaves the 2
842f3b
names the same for all other GPUs.
842f3b
842f3b
Note this commit adds a FIXME comment for a memory leak in
842f3b
dri2_probe_driver_name(), that leak was already present and fixing
842f3b
it falls outside of the scope of this commit.
842f3b
842f3b
BugLink: https://bugzilla.redhat.com/show_bug.cgi?id=1413733
842f3b
Cc: kwizart@gmail.com
842f3b
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
842f3b
---
842f3b
 hw/xfree86/dri2/dri2.c                      | 36 +++++++++++++++++++----------
842f3b
 hw/xfree86/dri2/pci_ids/pci_id_driver_map.h | 21 +++++++++--------
842f3b
 2 files changed, 35 insertions(+), 22 deletions(-)
842f3b
842f3b
diff --git a/hw/xfree86/dri2/dri2.c b/hw/xfree86/dri2/dri2.c
842f3b
index 2165603..d0366746 100644
842f3b
--- a/hw/xfree86/dri2/dri2.c
842f3b
+++ b/hw/xfree86/dri2/dri2.c
842f3b
@@ -1437,14 +1437,19 @@ get_prime_id(void)
842f3b
 
842f3b
 #include "pci_ids/pci_id_driver_map.h"
842f3b
 
842f3b
-static char *
842f3b
-dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info)
842f3b
+static void
842f3b
+dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info,
842f3b
+                       const char **dri_driver_ret,
842f3b
+                       const char **vdpau_driver_ret)
842f3b
 {
842f3b
     ScrnInfoPtr pScrn = xf86ScreenToScrn(pScreen);
842f3b
     EntityInfoPtr pEnt = xf86GetEntityInfo(pScrn->entityList[0]);
842f3b
     struct pci_device *pdev = NULL;
842f3b
     int i, j;
842f3b
 
842f3b
+    *dri_driver_ret = NULL;
842f3b
+    *vdpau_driver_ret = NULL;
842f3b
+
842f3b
     if (pEnt)
842f3b
         pdev = xf86GetPciInfoForEntity(pEnt->index);
842f3b
 
842f3b
@@ -1454,30 +1459,37 @@ dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info)
842f3b
      */
842f3b
     if (!pdev) {
842f3b
         drmVersionPtr version = drmGetVersion(info->fd);
842f3b
-        char *kernel_driver;
842f3b
 
842f3b
         if (!version) {
842f3b
             xf86DrvMsg(pScreen->myNum, X_ERROR,
842f3b
                        "[DRI2] Couldn't drmGetVersion() on non-PCI device, "
842f3b
                        "no driver name found.\n");
842f3b
-            return NULL;
842f3b
+            return;
842f3b
         }
842f3b
 
842f3b
-        kernel_driver = strndup(version->name, version->name_len);
842f3b
+        /* FIXME this gets leaked */
842f3b
+        *dri_driver_ret = strndup(version->name, version->name_len);
842f3b
+        *vdpau_driver_ret = *dri_driver_ret;
842f3b
         drmFreeVersion(version);
842f3b
-        return kernel_driver;
842f3b
+        return;
842f3b
     }
842f3b
 
842f3b
     for (i = 0; driver_map[i].driver; i++) {
842f3b
         if (pdev->vendor_id != driver_map[i].vendor_id)
842f3b
             continue;
842f3b
 
842f3b
-        if (driver_map[i].num_chips_ids == -1)
842f3b
-            return strdup(driver_map[i].driver);
842f3b
+        if (driver_map[i].num_chips_ids == -1) {
842f3b
+             *dri_driver_ret = driver_map[i].driver;
842f3b
+             *vdpau_driver_ret = driver_map[i].vdpau_driver;
842f3b
+             return;
842f3b
+        }
842f3b
 
842f3b
         for (j = 0; j < driver_map[i].num_chips_ids; j++) {
842f3b
-            if (driver_map[i].chip_ids[j] == pdev->device_id)
842f3b
-                return strdup(driver_map[i].driver);
842f3b
+            if (driver_map[i].chip_ids[j] == pdev->device_id) {
842f3b
+                *dri_driver_ret = driver_map[i].driver;
842f3b
+                *vdpau_driver_ret = driver_map[i].vdpau_driver;
842f3b
+                return;
842f3b
+            }
842f3b
         }
842f3b
     }
842f3b
 
842f3b
@@ -1485,7 +1497,6 @@ dri2_probe_driver_name(ScreenPtr pScreen, DRI2InfoPtr info)
842f3b
                "[DRI2] No driver mapping found for PCI device "
842f3b
                "0x%04x / 0x%04x\n",
842f3b
                pdev->vendor_id, pdev->device_id);
842f3b
-    return NULL;
842f3b
 }
842f3b
 
842f3b
 Bool
842f3b
@@ -1606,7 +1617,8 @@ DRI2ScreenInit(ScreenPtr pScreen, DRI2InfoPtr info)
842f3b
         if (info->driverName) {
842f3b
             ds->driverNames[0] = info->driverName;
842f3b
         } else {
842f3b
-            ds->driverNames[0] = ds->driverNames[1] = dri2_probe_driver_name(pScreen, info);
842f3b
+            dri2_probe_driver_name(pScreen, info,
842f3b
+                                   &ds->driverNames[0], &ds->driverNames[1]);
842f3b
             if (!ds->driverNames[0])
842f3b
                 return FALSE;
842f3b
         }
842f3b
diff --git a/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h b/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h
842f3b
index da7ea1c..7036d10 100644
842f3b
--- a/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h
842f3b
+++ b/hw/xfree86/dri2/pci_ids/pci_id_driver_map.h
842f3b
@@ -66,21 +66,22 @@ static const int vmwgfx_chip_ids[] = {
842f3b
 static const struct {
842f3b
    int vendor_id;
842f3b
    const char *driver;
842f3b
+   const char *vdpau_driver;
842f3b
    const int *chip_ids;
842f3b
    int num_chips_ids;
842f3b
 } driver_map[] = {
842f3b
-   { 0x8086, "i915", i915_chip_ids, ARRAY_SIZE(i915_chip_ids) },
842f3b
-   { 0x8086, "i965", i965_chip_ids, ARRAY_SIZE(i965_chip_ids) },
842f3b
+   { 0x8086, "i915", "i915", i915_chip_ids, ARRAY_SIZE(i915_chip_ids) },
842f3b
+   { 0x8086, "i965", "va_gl", i965_chip_ids, ARRAY_SIZE(i965_chip_ids) },
842f3b
 #ifndef DRIVER_MAP_GALLIUM_ONLY
842f3b
-   { 0x1002, "radeon", r100_chip_ids, ARRAY_SIZE(r100_chip_ids) },
842f3b
-   { 0x1002, "r200", r200_chip_ids, ARRAY_SIZE(r200_chip_ids) },
842f3b
+   { 0x1002, "radeon", "radeon", r100_chip_ids, ARRAY_SIZE(r100_chip_ids) },
842f3b
+   { 0x1002, "r200", "r200", r200_chip_ids, ARRAY_SIZE(r200_chip_ids) },
842f3b
 #endif
842f3b
-   { 0x1002, "r300", r300_chip_ids, ARRAY_SIZE(r300_chip_ids) },
842f3b
-   { 0x1002, "r600", r600_chip_ids, ARRAY_SIZE(r600_chip_ids) },
842f3b
-   { 0x1002, "radeonsi", radeonsi_chip_ids, ARRAY_SIZE(radeonsi_chip_ids) },
842f3b
-   { 0x10de, "nouveau", NULL, -1 },
842f3b
-   { 0x1af4, "virtio_gpu", virtio_gpu_chip_ids, ARRAY_SIZE(virtio_gpu_chip_ids) },
842f3b
-   { 0x15ad, "vmwgfx", vmwgfx_chip_ids, ARRAY_SIZE(vmwgfx_chip_ids) },
842f3b
+   { 0x1002, "r300", "r300", r300_chip_ids, ARRAY_SIZE(r300_chip_ids) },
842f3b
+   { 0x1002, "r600","r600",  r600_chip_ids, ARRAY_SIZE(r600_chip_ids) },
842f3b
+   { 0x1002, "radeonsi", "radeonsi", radeonsi_chip_ids, ARRAY_SIZE(radeonsi_chip_ids) },
842f3b
+   { 0x10de, "nouveau", "nouveau", NULL, -1 },
842f3b
+   { 0x1af4, "virtio_gpu", "virtio_gpu", virtio_gpu_chip_ids, ARRAY_SIZE(virtio_gpu_chip_ids) },
842f3b
+   { 0x15ad, "vmwgfx", "vmwgfx", vmwgfx_chip_ids, ARRAY_SIZE(vmwgfx_chip_ids) },
842f3b
    { 0x0000, NULL, NULL, 0 },
842f3b
 };
842f3b
 
842f3b
-- 
842f3b
2.9.3
842f3b