Skip to contentSkip to conversation

nv: improve KMS detection

PATCH In review Marcin Slusarz 3 participants 6 messages May 23, 2010 – Jun 2, 2010 4 messages not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nv: improve KMS detection

1) DRICreatePCIBusID belongs to xserver dri module, so when it's unavailable we can't format string for drmCheckModesettingSupported. (This situation happened to me with KMS enabled and dri module moved somewhere else by Gentoo's "eselect opengl set nvidia" switcher) Open code DRICreatePCIBusID to drop dri dependency.
2) Once we dropped dependency on dri module (which linked to libdrm), we have to link directly to libdrm.

---
 src/Makefile.am |    2 +-
 src/nv_driver.c |   11 +++--------
 2 files changed, 4 insertions(+), 9 deletions(-)
src/Makefile.am +1 -1
index 5d57010..8b23e21 100644
@@ -25,7 +25,7 @@
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 AM_CFLAGS = @XMODES_CFLAGS@ @XORG_CFLAGS@ $(LIBDRM_CFLAGS)
 nv_drv_la_LTLIBRARIES = nv_drv.la
-nv_drv_la_LDFLAGS = -module -avoid-version
+nv_drv_la_LDFLAGS = -module -avoid-version $(LIBDRM_LIBS)
 nv_drv_ladir = @moduledir@/drivers
 
 nv_drv_la_SOURCES = $(nv_sources) $(riva_sources) $(g80_sources)
src/nv_driver.c +3 -8
index e10ae0c..6651cd4 100644
@@ -836,18 +836,13 @@ NVIsSupported(CARD32 id)
 }
 
 #ifdef HAVE_KMS
-static Bool NVKernelModesettingEnabled(struct pci_device *device)
+static Bool NVKernelModesettingEnabled(struct pci_device *dev)
 {
-    char *busIdString;
+    char busIdString[20];
     int ret;
 
-    if (!xf86LoaderCheckSymbol("DRICreatePCIBusID"))
-        return FALSE;
-
-    busIdString = DRICreatePCIBusID(device);
-
+    snprintf(busIdString, 20, "pci:%04x:%02x:%02x.%d", dev->domain, dev->bus, dev->dev, dev->func);
     ret = drmCheckModesettingSupported(busIdString);
-    xfree(busIdString);
 
     return (ret == 0);
 }
Signature · 1 line
1.7.1
#2 lore raw
In reply to a message not in the archive
Quoted 7 lines · Marcin Slusarz

1) DRICreatePCIBusID belongs to xserver dri module, so when it's unavailable we can't format string for drmCheckModesettingSupported. (This situation happened to me with KMS enabled and dri module moved somewhere else by Gentoo's "eselect opengl set nvidia" switcher) Open code DRICreatePCIBusID to drop dri dependency.
2) Once we dropped dependency on dri module (which linked to libdrm), we have to link directly to libdrm.

An alternative, which we use in Fedora for nv/vesa is to use pci_device_has_kernel_driver() from libpciaccess.

Ben.

Quoted 46 lines
---
 src/Makefile.am |    2 +-
 src/nv_driver.c |   11 +++--------
 2 files changed, 4 insertions(+), 9 deletions(-)
src/Makefile.am +1 -1
index 5d57010..8b23e21 100644
@@ -25,7 +25,7 @@
 # TODO: -nostdlib/-Bstatic/-lgcc platform magic, not installing the .a, etc.
 AM_CFLAGS = @XMODES_CFLAGS@ @XORG_CFLAGS@ $(LIBDRM_CFLAGS)
 nv_drv_la_LTLIBRARIES = nv_drv.la
-nv_drv_la_LDFLAGS = -module -avoid-version
+nv_drv_la_LDFLAGS = -module -avoid-version $(LIBDRM_LIBS)
 nv_drv_ladir = @moduledir@/drivers
 
 nv_drv_la_SOURCES = $(nv_sources) $(riva_sources) $(g80_sources)
src/nv_driver.c +3 -8
index e10ae0c..6651cd4 100644
@@ -836,18 +836,13 @@ NVIsSupported(CARD32 id)
 }
 
 #ifdef HAVE_KMS
-static Bool NVKernelModesettingEnabled(struct pci_device *device)
+static Bool NVKernelModesettingEnabled(struct pci_device *dev)
 {
-    char *busIdString;
+    char busIdString[20];
     int ret;
 
-    if (!xf86LoaderCheckSymbol("DRICreatePCIBusID"))
-        return FALSE;
-
-    busIdString = DRICreatePCIBusID(device);
-
+    snprintf(busIdString, 20, "pci:%04x:%02x:%02x.%d", dev->domain, dev->bus, dev->dev, dev->func);
     ret = drmCheckModesettingSupported(busIdString);
-    xfree(busIdString);
 
     return (ret == 0);
 }
#3 lore raw
Quoted 10 lines · Ben Skeggs
Quoted 7 lines · Marcin Slusarz

1) DRICreatePCIBusID belongs to xserver dri module, so when it's unavailable we can't format string for drmCheckModesettingSupported. (This situation happened to me with KMS enabled and dri module moved somewhere else by Gentoo's "eselect opengl set nvidia" switcher) Open code DRICreatePCIBusID to drop dri dependency.
2) Once we dropped dependency on dri module (which linked to libdrm), we have to link directly to libdrm.

An alternative, which we use in Fedora for nv/vesa is to use pci_device_has_kernel_driver() from libpciaccess.

That seems better than open-coding it, and avoids a dependency on libdrm which is nice.

#5 lore raw
In reply to a message not in the archive
Quoted 9 lines · Aaron Plattner
Quoted 8 lines · Ben Skeggs
Quoted 7 lines · Marcin Slusarz

1) DRICreatePCIBusID belongs to xserver dri module, so when it's unavailable we can't format string for drmCheckModesettingSupported. (This situation happened to me with KMS enabled and dri module moved somewhere else by Gentoo's "eselect opengl set nvidia" switcher) Open code DRICreatePCIBusID to drop dri dependency.
2) Once we dropped dependency on dri module (which linked to libdrm), we have to link directly to libdrm.

Quoted 5 lines
Quoted 2 lines

An alternative, which we use in Fedora for nv/vesa is to use pci_device_has_kernel_driver() from libpciaccess.

That seems better than open-coding it, and avoids a dependency on libdrm which is nice.

Well, you are trading one dependency for other. It doesn't really matter... Ben, are you going to send your patch to Aaron?

Marcin

#7 lore raw
In reply to a message not in the archive
Quoted 10 lines · Marcin Slusarz
Quoted 9 lines · Aaron Plattner
Quoted 8 lines · Ben Skeggs
Quoted 7 lines · Marcin Slusarz

1) DRICreatePCIBusID belongs to xserver dri module, so when it's unavailable we can't format string for drmCheckModesettingSupported. (This situation happened to me with KMS enabled and dri module moved somewhere else by Gentoo's "eselect opengl set nvidia" switcher) Open code DRICreatePCIBusID to drop dri dependency.
2) Once we dropped dependency on dri module (which linked to libdrm), we have to link directly to libdrm.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

An alternative, which we use in Fedora for nv/vesa is to use pci_device_has_kernel_driver() from libpciaccess.

That seems better than open-coding it, and avoids a dependency on libdrm which is nice.

Well, you are trading one dependency for other. It doesn't really matter... Ben, are you going to send your patch to Aaron?

Yeah, but the server already has a dependency on libpciaccess, while the libdrm dependency is just for a module, and I think might be optional (I haven't kept up with the dri2 patches on the list).

-- Aaron

#9 lore raw
In reply to a message not in the archive
Quoted 17 lines · Aaron Plattner
Quoted 16 lines · Marcin Slusarz
Quoted 14 lines · Aaron Plattner
Quoted 10 lines · Ben Skeggs
Quoted 7 lines · Marcin Slusarz

1) DRICreatePCIBusID belongs to xserver dri module, so when it's unavailable we can't format string for drmCheckModesettingSupported. (This situation happened to me with KMS enabled and dri module moved somewhere else by Gentoo's "eselect opengl set nvidia" switcher) Open code DRICreatePCIBusID to drop dri dependency.
2) Once we dropped dependency on dri module (which linked to libdrm), we have to link directly to libdrm.

An alternative, which we use in Fedora for nv/vesa is to use pci_device_has_kernel_driver() from libpciaccess.

That seems better than open-coding it, and avoids a dependency on libdrm which is nice.

Quoted 6 lines
Quoted 2 lines

Well, you are trading one dependency for other. It doesn't really matter... Ben, are you going to send your patch to Aaron?

Yeah, but the server already has a dependency on libpciaccess, while the libdrm dependency is just for a module, and I think might be optional (I haven't kept up with the dri2 patches on the list).

Exactly. Patch is attached, but it was readily available in Fedora CVS anyway.

Ben.

Quoted 2 lines

-- Aaron

From ee544c2b11ab327abab6e205425e6eafe961de2e Mon Sep 17 00:00:00 2001
From: Ben Skeggs <[email protected]>
Date: Fri, 28 Aug 2009 09:43:16 +1000
Subject: [PATCH] nv: refuse to load if there's a kernel driver bound to the device already

---
 src/nv_driver.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
src/nv_driver.c +6 -0
index a7cf2dc..6f7fc0e 100644
@@ -780,6 +780,12 @@ NVPciProbe(DriverPtr drv, int entity, struct pci_device *dev, intptr_t data)
                       NVGetPCIXpressChip(dev) : dev->vendor_id << 16 | dev->device_id;
     const char *name = xf86TokenToString(NVKnownChipsets, id);
 
+    if (pci_device_has_kernel_driver(dev)) {
+	ErrorF("The PCI device has a kernel module claiming it.\n");
+	ErrorF("This driver cannot operate until it has been unloaded\n");
+	return FALSE;
+    }
+
     if(dev->vendor_id == PCI_VENDOR_NVIDIA && !name &&
        !NVIsSupported(id) && !NVIsG80(id)) {
         /* See if pci.ids knows what the heck this thing is */
Signature · 1 line
1.6.4

_______________________________________________
Nouveau mailing list [email protected]
http://lists.freedesktop.org/mailman/listinfo/nouveau