[openib-general] [PATCH] support domain names in /proc/bus/pci names

Tom Duffy tduffy at sun.com
Fri Jan 14 14:09:38 PST 2005


On Fri, 2005-01-14 at 16:41 +0200, Michael S. Tsirkin wrote:
> OK. I added an option for mmapping /proc/bus/pci

This patch adds support for pci domain names in the path
under /proc/bus/pci.

Singed-off-by: Tom Duffy <tduffy at sun.com>

Index: mtcr.h
===================================================================
--- mtcr.h	(revision 1534)
+++ mtcr.h	(working copy)
@@ -136,7 +136,8 @@
 
 /* Find the specific device by scanning /proc/bus/pci/devices */
 int mfind(const char* name, off_t* offset_p,
-		unsigned *bus_p, unsigned *dev_p, unsigned *func_p)
+		unsigned *bus_p, unsigned *dev_p, unsigned *func_p,
+		int *domain_p)
 {
   FILE* f;
 	unsigned     irq;
@@ -158,7 +159,7 @@
 
   unsigned long long offset;
 
-  unsigned my_domain = 0;
+  int my_domain = -1;
   unsigned my_bus;
   unsigned my_dev;
   unsigned my_func;
@@ -180,7 +181,7 @@
 
 name_parsed:
 
-  if (my_domain) {
+  if (my_domain > 0) {
     fprintf(stderr,"Device %s: domain number %#x detected.\n"
 		   "Only domain 0x0 supported for now, sorry.\n",
 		   name, my_domain);
@@ -266,6 +267,7 @@
   *bus_p=bus;
   *dev_p=dev;
   *func_p=func;
+  *domain_p=my_domain;
 
   fclose(f);
   return 0;
@@ -307,16 +309,22 @@
   {
 #if CONFIG_ENABLE_MMAP
     unsigned bus, dev, func;
-    if (mfind(name,&offset,&bus,&dev,&func)) goto find_failed;
+    int domain;
+    if (mfind(name,&offset,&bus,&dev,&func,&domain)) goto find_failed;
 
 #if CONFIG_USE_DEV_MEM
     mf->fd = open("/dev/mem", O_RDWR | O_SYNC);
     if (mf->fd<0) goto open_failed;
 #else
     {
-	    char file_name[]="/proc/bus/pci/00/00.0";
-	    sprintf(file_name,"/proc/bus/pci/%2.2x/%2.2x.%1.1x",
+	    char file_name[]="/proc/bus/pci/0000:00/00.0";
+	    if (domain >= 0) {
+	    	sprintf(file_name,"/proc/bus/pci/%4.4d:%2.2x/%2.2x.%1.1x",
+			    domain,bus,dev,func);
+	    } else {
+		sprintf(file_name,"/proc/bus/pci/%2.2x/%2.2x.%1.1x",
 			    bus,dev,func);
+	    }
 	    mf->fd = open(file_name, O_RDWR | O_SYNC);
 	    if (mf->fd<0) goto open_failed;
 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.openfabrics.org/pipermail/general/attachments/20050114/f4135375/attachment.sig>


More information about the general mailing list