From patchwork Fri Aug 6 03:55:11 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Herrenschmidt X-Patchwork-Id: 117660 Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o763uZbw022549 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 6 Aug 2010 03:57:11 GMT Received: from localhost ([127.0.0.1] helo=sfs-ml-1.v29.ch3.sourceforge.com) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1OhE1m-0006nK-3H; Fri, 06 Aug 2010 03:55:26 +0000 Received: from sog-mx-1.v43.ch3.sourceforge.com ([172.29.43.191] helo=mx.sourceforge.net) by sfs-ml-1.v29.ch3.sourceforge.com with esmtp (Exim 4.69) (envelope-from ) id 1OhE1l-0006nC-52 for dri-devel@lists.sourceforge.net; Fri, 06 Aug 2010 03:55:25 +0000 X-ACL-Warn: Received: from gate.crashing.org ([63.228.1.57]) by sog-mx-1.v43.ch3.sourceforge.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.69) id 1OhE1j-00027N-Hl for dri-devel@lists.sourceforge.net; Fri, 06 Aug 2010 03:55:25 +0000 Received: from [IPv6:::1] (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.13.8) with ESMTP id o763tFXc009248; Thu, 5 Aug 2010 22:55:15 -0500 Subject: [PATCH] libdrm: Fix PCI domain domain support From: Benjamin Herrenschmidt To: Dave Airlie Date: Fri, 06 Aug 2010 13:55:11 +1000 Message-ID: <1281066911.2168.11.camel@pasglop> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 X-Spam-Score: 0.6 (/) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. -0.0 T_RP_MATCHES_RCVD Envelope sender domain matches handover relay domain 0.7 AWL AWL: From: address is in the auto white-list X-Headers-End: 1OhE1j-00027N-Hl Cc: dri-devel@lists.sourceforge.net X-BeenThere: dri-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.sourceforge.net X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 06 Aug 2010 03:57:11 +0000 (UTC) diff --git a/xf86drm.c b/xf86drm.c index 220aaa1..cb0c3a3 100644 --- a/xf86drm.c +++ b/xf86drm.c @@ -229,7 +229,7 @@ drmHashEntry *drmGetEntry(int fd) * PCI:b:d:f format and the newer pci:oooo:bb:dd.f format. In the format, o is * domain, b is bus, d is device, f is function. */ -static int drmMatchBusID(const char *id1, const char *id2) +static int drmMatchBusID(const char *id1, const char *id2, int pci_domain_ok) { /* First, check if the IDs are exactly the same */ if (strcasecmp(id1, id2) == 0) @@ -257,6 +257,13 @@ static int drmMatchBusID(const char *id1, const char *id2) return 0; } + /* If domains aren't properly supported by the kernel interface, + * just ignore them, which sucks less than picking a totally random + * card with "open by name" + */ + if (!pci_domain_ok) + o1 = o2 = 0; + if ((o1 != o2) || (b1 != b2) || (d1 != d2) || (f1 != f2)) return 0; else @@ -482,7 +489,7 @@ int drmAvailable(void) */ static int drmOpenByBusid(const char *busid) { - int i; + int i, pci_domain_ok = 1; int fd; const char *buf; drmSetVersion sv; @@ -492,14 +499,27 @@ static int drmOpenByBusid(const char *busid) fd = drmOpenMinor(i, 1, DRM_NODE_RENDER); drmMsg("drmOpenByBusid: drmOpenMinor returns %d\n", fd); if (fd >= 0) { + /* We need to try for 1.4 first for proper PCI domain support + * and if that fails, we know the kernel is busted + */ sv.drm_di_major = 1; - sv.drm_di_minor = 1; + sv.drm_di_minor = 4; sv.drm_dd_major = -1; /* Don't care */ sv.drm_dd_minor = -1; /* Don't care */ - drmSetInterfaceVersion(fd, &sv); + if (drmSetInterfaceVersion(fd, &sv)) { +#ifndef __alpha__ + pci_domain_ok = 0; +#endif + sv.drm_di_major = 1; + sv.drm_di_minor = 1; + sv.drm_dd_major = -1; /* Don't care */ + sv.drm_dd_minor = -1; /* Don't care */ + drmMsg("drmOpenByBusid: Interface 1.4 failed,trying 1.1\n", fd); + drmSetInterfaceVersion(fd, &sv); + } buf = drmGetBusid(fd); drmMsg("drmOpenByBusid: drmGetBusid reports %s\n", buf); - if (buf && drmMatchBusID(buf, busid)) { + if (buf && drmMatchBusID(buf, busid, pci_domain_ok)) { drmFreeBusid(buf); return fd; }