Skip to contentSkip to conversation

ati: Support loading the amdgpu driver from the ati wrapper

PATCH In review Michel Dänzer 2 participants 2 messages Jan 18, 2017 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ati: Support loading the amdgpu driver from the ati wrapper

From: Michel Dänzer <[email protected]>

If .../share/X11/xorg.conf.d/10-amdgpu.conf doesn't exist, but the ati wrapper is loaded, it will otherwise try to use the radeon driver even for GPUs driven by the amdgpu kernel driver. This can only fail, potentially in bad ways.

---
 src/ati.c | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)
src/ati.c +36 -4
index 227665e73..d5294df09 100644
@@ -58,6 +58,7 @@
 #endif
 
 #include <pciaccess.h>
+#include <xf86drm.h>
 #include "atipcirename.h"
 
 #include "ati.h"
@@ -68,6 +69,7 @@
 #define MACH64_DRIVER_NAME  "mach64"
 #define R128_DRIVER_NAME    "r128"
 #define RADEON_DRIVER_NAME  "radeon"
+#define AMDGPU_DRIVER_NAME  "amdgpu"
 
 enum
 {
@@ -140,9 +142,9 @@ ati_device_get_indexed(int index)
 void
 ati_gdev_subdriver(pointer options)
 {
-    int      nATIGDev, nMach64GDev, nR128GDev, nRadeonGDev;
+    int      nATIGDev, nMach64GDev, nR128GDev, nRadeonGDev, nAmdgpuGDev;
     GDevPtr *ATIGDevs;
-    Bool     load_mach64 = FALSE, load_r128 = FALSE, load_radeon = FALSE;
+    Bool     load_mach64 = FALSE, load_r128 = FALSE, load_radeon = FALSE, load_amdgpu = FALSE;
     int      i;
 
     /* let the subdrivers configure for themselves */
@@ -154,6 +156,7 @@ ati_gdev_subdriver(pointer options)
     nMach64GDev = xf86MatchDevice(MACH64_DRIVER_NAME, NULL);
     nR128GDev = xf86MatchDevice(R128_DRIVER_NAME, NULL);
     nRadeonGDev = xf86MatchDevice(RADEON_DRIVER_NAME, NULL);
+    nAmdgpuGDev = xf86MatchDevice(AMDGPU_DRIVER_NAME, NULL);
 
     for (i = 0; i < nATIGDev; i++) {
         GDevPtr     ati_gdev = ATIGDevs[i];
@@ -200,8 +203,34 @@ ati_gdev_subdriver(pointer options)
         }
 
         if (chip_family == ATI_CHIP_FAMILY_Radeon) {
-            ati_gdev->driver = RADEON_DRIVER_NAME;
-            load_radeon = TRUE;
+	    char *busid;
+
+	    XNFasprintf(&busid, "pci:%04x:%02x:%02x.%d",
+			device->domain, device->bus, device->dev,
+			device->func);
+
+	    if (busid) {
+		int fd = drmOpen(NULL, busid);
+
+		if (fd >= 0) {
+		    drmVersionPtr version = drmGetVersion(fd);
+
+		    if (version->version_major == 3) {
+			ati_gdev->driver = AMDGPU_DRIVER_NAME;
+			load_amdgpu = TRUE;
+		    }
+
+		    free(version);
+		    drmClose(fd);
+		}
+
+		free(busid);
+	    }
+
+	    if (strcmp(ati_gdev->driver, AMDGPU_DRIVER_NAME) != 0) {
+		ati_gdev->driver = RADEON_DRIVER_NAME;
+		load_radeon = TRUE;
+	    }
         }
     }
 
@@ -219,6 +248,9 @@ ati_gdev_subdriver(pointer options)
 
     if (load_radeon && (nRadeonGDev == 0))
          xf86LoadOneModule(RADEON_DRIVER_NAME, options);
+
+    if (load_amdgpu && (nAmdgpuGDev == 0))
+         xf86LoadOneModule(AMDGPU_DRIVER_NAME, options);
 }
 
 /*
Signature · 6 lines
2.11.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20170118100801.28182-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org

Reviewed-by
#2 lore raw
Quoted 8 lines · Michel Dänzer

From: Michel Dänzer <[email protected]>

If .../share/X11/xorg.conf.d/10-amdgpu.conf doesn't exist, but the ati wrapper is loaded, it will otherwise try to use the radeon driver even for GPUs driven by the amdgpu kernel driver. This can only fail, potentially in bad ways.

Quoted 94 lines
---
 src/ati.c | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)
src/ati.c +36 -5
index 227665e73..d5294df09 100644
@@ -58,6 +58,7 @@
 #endif
 
 #include <pciaccess.h>
+#include <xf86drm.h>
 #include "atipcirename.h"
 
 #include "ati.h"
@@ -68,6 +69,7 @@
 #define MACH64_DRIVER_NAME  "mach64"
 #define R128_DRIVER_NAME    "r128"
 #define RADEON_DRIVER_NAME  "radeon"
+#define AMDGPU_DRIVER_NAME  "amdgpu"
 
 enum
 {
@@ -140,9 +142,9 @@ ati_device_get_indexed(int index)
 void
 ati_gdev_subdriver(pointer options)
 {
-    int      nATIGDev, nMach64GDev, nR128GDev, nRadeonGDev;
+    int      nATIGDev, nMach64GDev, nR128GDev, nRadeonGDev, nAmdgpuGDev;
     GDevPtr *ATIGDevs;
-    Bool     load_mach64 = FALSE, load_r128 = FALSE, load_radeon = FALSE;
+    Bool     load_mach64 = FALSE, load_r128 = FALSE, load_radeon = FALSE, load_amdgpu = FALSE;
     int      i;
 
     /* let the subdrivers configure for themselves */
@@ -154,6 +156,7 @@ ati_gdev_subdriver(pointer options)
     nMach64GDev = xf86MatchDevice(MACH64_DRIVER_NAME, NULL);
     nR128GDev = xf86MatchDevice(R128_DRIVER_NAME, NULL);
     nRadeonGDev = xf86MatchDevice(RADEON_DRIVER_NAME, NULL);
+    nAmdgpuGDev = xf86MatchDevice(AMDGPU_DRIVER_NAME, NULL);
 
     for (i = 0; i < nATIGDev; i++) {
         GDevPtr     ati_gdev = ATIGDevs[i];
@@ -200,8 +203,34 @@ ati_gdev_subdriver(pointer options)
         }
 
         if (chip_family == ATI_CHIP_FAMILY_Radeon) {
-            ati_gdev->driver = RADEON_DRIVER_NAME;
-            load_radeon = TRUE;
+           char *busid;
+
+           XNFasprintf(&busid, "pci:%04x:%02x:%02x.%d",
+                       device->domain, device->bus, device->dev,
+                       device->func);
+
+           if (busid) {
+               int fd = drmOpen(NULL, busid);
+
+               if (fd >= 0) {
+                   drmVersionPtr version = drmGetVersion(fd);
+
+                   if (version->version_major == 3) {
+                       ati_gdev->driver = AMDGPU_DRIVER_NAME;
+                       load_amdgpu = TRUE;
+                   }
+
+                   free(version);
+                   drmClose(fd);
+               }
+
+               free(busid);
+           }
+
+           if (strcmp(ati_gdev->driver, AMDGPU_DRIVER_NAME) != 0) {
+               ati_gdev->driver = RADEON_DRIVER_NAME;
+               load_radeon = TRUE;
+           }
         }
     }
 
@@ -219,6 +248,9 @@ ati_gdev_subdriver(pointer options)
 
     if (load_radeon && (nRadeonGDev == 0))
          xf86LoadOneModule(RADEON_DRIVER_NAME, options);
+
+    if (load_amdgpu && (nAmdgpuGDev == 0))
+         xf86LoadOneModule(AMDGPU_DRIVER_NAME, options);
 }
 
 /*
--

2.11.0

Quoted 4 lines

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx