View | Details | Raw Unified | Return to bug 197572
Collapse All | Expand All

(-)../xorg-server-1.1.99.3.orig/hw/xfree86/int10/helper_exec.c (-2 / +2 lines)
Lines 480-486 pciCfg1in(CARD16 addr, CARD32 *val) Link Here
480
	return 1;
480
	return 1;
481
    }
481
    }
482
    if (addr == 0xCFC) {
482
    if (addr == 0xCFC) {
483
	*val = pciReadLong(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr));
483
	*val = pciReadLong(Int10Current->Tag, OFFSET(PciCfg1Addr));
484
	return 1;
484
	return 1;
485
    }
485
    }
486
    return 0;
486
    return 0;
Lines 494-500 pciCfg1out(CARD16 addr, CARD32 val) Link Here
494
	return 1;
494
	return 1;
495
    }
495
    }
496
    if (addr == 0xCFC) {
496
    if (addr == 0xCFC) {
497
	pciWriteLong(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr), val);
497
	pciWriteLong(Int10Current->Tag, OFFSET(PciCfg1Addr),val);
498
	return 1;
498
	return 1;
499
    }
499
    }
500
    return 0;
500
    return 0;
(-)../xorg-server-1.1.99.3.orig/hw/xfree86/os-support/bus/Pci.c (+18 lines)
Lines 20-25 Link Here
20
 *	pciSetBitsByte()       - Write an 8 bit value against a mask
20
 *	pciSetBitsByte()       - Write an 8 bit value against a mask
21
 *	pciTag()               - Return tag for a given PCI bus, device, &
21
 *	pciTag()               - Return tag for a given PCI bus, device, &
22
 *                               function
22
 *                               function
23
 *	pciDomTag()            - Return tag for a given PCI domain, bus,
24
 *                               device & function
23
 *	pciBusAddrToHostAddr() - Convert a PCI address to a host address
25
 *	pciBusAddrToHostAddr() - Convert a PCI address to a host address
24
 *	pciHostAddrToBusAddr() - Convert a host address to a PCI address
26
 *	pciHostAddrToBusAddr() - Convert a host address to a PCI address
25
 *	pciGetBaseSize()       - Returns the number of bits in a PCI base
27
 *	pciGetBaseSize()       - Returns the number of bits in a PCI base
Lines 608-619 pciGetBaseSize(PCITAG tag, int index, Bo Link Here
608
  return bits;
610
  return bits;
609
}
611
}
610
612
613
_X_EXPORT void
614
pciInfoFromTag(PCITAG tag, int *domainnum, int *busnum,
615
               int *devnum, int *funcnum)
616
{
617
    *domainnum = PCI_DOM_FROM_TAG(tag);
618
    *busnum = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(tag));
619
    *devnum = PCI_DEV_FROM_TAG(tag);
620
    *funcnum = PCI_FUNC_FROM_TAG(tag);
621
}
622
611
_X_EXPORT PCITAG
623
_X_EXPORT PCITAG
612
pciTag(int busnum, int devnum, int funcnum)
624
pciTag(int busnum, int devnum, int funcnum)
613
{
625
{
614
	return(PCI_MAKE_TAG(busnum,devnum,funcnum));
626
	return(PCI_MAKE_TAG(busnum,devnum,funcnum));
615
}
627
}
616
628
629
_X_EXPORT PCITAG
630
pciDomTag(int domnum, int busnum, int devnum, int funcnum)
631
{
632
	return(PCI_MAKE_TAG(PCI_MAKE_BUS(domnum,busnum),devnum,funcnum));
633
}
634
617
#if defined(PCI_MFDEV_SUPPORT)
635
#if defined(PCI_MFDEV_SUPPORT)
618
636
619
Bool
637
Bool
(-)../xorg-server-1.1.99.3.orig/hw/xfree86/os-support/bus/Pci.h (-2 / +2 lines)
Lines 119-125 Link Here
119
				/* by xf86scanpci		     */
119
				/* by xf86scanpci		     */
120
#if defined(sun) && defined(SVR4) && defined(sparc)
120
#if defined(sun) && defined(SVR4) && defined(sparc)
121
# define MAX_PCI_BUSES   4096	/* Max number of PCI buses           */
121
# define MAX_PCI_BUSES   4096	/* Max number of PCI buses           */
122
#elif defined(__alpha__) && defined (linux)
122
#elif (defined(__alpha__) || defined(__ia64__)) && defined (linux)
123
# define MAX_PCI_DOMAINS	512
123
# define MAX_PCI_DOMAINS	512
124
# define PCI_DOM_MASK	0x01fful
124
# define PCI_DOM_MASK	0x01fful
125
# define MAX_PCI_BUSES	(MAX_PCI_DOMAINS*256) /* 256 per domain      */
125
# define MAX_PCI_BUSES	(MAX_PCI_DOMAINS*256) /* 256 per domain      */
Lines 258-264 Link Here
258
# endif
258
# endif
259
#elif defined(__ia64__)
259
#elif defined(__ia64__)
260
# if defined(linux)
260
# if defined(linux)
261
#  define ARCH_PCI_INIT linuxPciInit
261
#  define ARCH_PCI_INIT ia64linuxPciInit
262
#  define INCLUDE_XF86_MAP_PCI_MEM
262
#  define INCLUDE_XF86_MAP_PCI_MEM
263
# elif defined(FreeBSD)
263
# elif defined(FreeBSD)
264
#  define ARCH_PCI_INIT freebsdPciInit
264
#  define ARCH_PCI_INIT freebsdPciInit
(-)../xorg-server-1.1.99.3.orig/hw/xfree86/os-support/bus/altixPCI.c (-3 / +6 lines)
Lines 41-53 static pciDevice *get_dev_on_bus(unsigne Link Here
41
static void get_bridge_info(pciBusInfo_t *bus_info, pciDevice *pdev)
41
static void get_bridge_info(pciBusInfo_t *bus_info, pciDevice *pdev)
42
{
42
{
43
	unsigned int parent_segnum, segnum = PCI_DOM_FROM_TAG(pdev->tag);
43
	unsigned int parent_segnum, segnum = PCI_DOM_FROM_TAG(pdev->tag);
44
	unsigned int parent_busnum, busnum = pdev->busnum;
44
	unsigned int parent_busnum, parent_nodombus, busnum = pdev->busnum;
45
	unsigned int nodombus = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(pdev->tag));
45
	char bridge_path[] = "/sys/class/pci_bus/0000:00/bridge";
46
	char bridge_path[] = "/sys/class/pci_bus/0000:00/bridge";
46
	char bridge_target[] = "../../../devices/pci0000:00";
47
	char bridge_target[] = "../../../devices/pci0000:00";
47
48
48
	/* Path to this device's bridge */
49
	/* Path to this device's bridge */
49
	sprintf(bridge_path, "/sys/class/pci_bus/%04x:%02x/bridge", segnum,
50
	sprintf(bridge_path, "/sys/class/pci_bus/%04x:%02x/bridge", segnum,
50
		busnum);
51
		nodombus);
51
52
52
	if (readlink(bridge_path, bridge_target, strlen(bridge_target)) < 0) {
53
	if (readlink(bridge_path, bridge_target, strlen(bridge_target)) < 0) {
53
		perror("failed to dereference bridge link");
54
		perror("failed to dereference bridge link");
Lines 56-62 static void get_bridge_info(pciBusInfo_t Link Here
56
	}
57
	}
57
58
58
	sscanf(bridge_target, "../../../devices/pci%04x:%02x", &parent_segnum,
59
	sscanf(bridge_target, "../../../devices/pci%04x:%02x", &parent_segnum,
59
	       &parent_busnum);
60
	       &parent_nodombus);
61
62
	parent_busnum = PCI_MAKE_BUS(parent_segnum, parent_nodombus);
60
63
61
	/*
64
	/*
62
	 * If there's no bridge or the bridge points to the device, use
65
	 * If there's no bridge or the bridge points to the device, use
(-)../xorg-server-1.1.99.3.orig/hw/xfree86/os-support/bus/linuxPci.c (-36 / +184 lines)
Lines 54-59 Link Here
54
#include "xf86Priv.h"
54
#include "xf86Priv.h"
55
#include "xf86_OSlib.h"
55
#include "xf86_OSlib.h"
56
#include "Pci.h"
56
#include "Pci.h"
57
#include <dirent.h>
57
58
58
/*
59
/*
59
 * linux platform specific PCI access functions -- using /proc/bus/pci
60
 * linux platform specific PCI access functions -- using /proc/bus/pci
Lines 73-78 static void linuxPciCfgWriteByte(PCITAG Link Here
73
static CARD16 linuxPciCfgReadWord(PCITAG tag, int off);
74
static CARD16 linuxPciCfgReadWord(PCITAG tag, int off);
74
static void linuxPciCfgWriteWord(PCITAG tag, int off, CARD16 val);
75
static void linuxPciCfgWriteWord(PCITAG tag, int off, CARD16 val);
75
static int linuxPciHandleBIOS(PCITAG Tag, int basereg, unsigned char *buf, int len);
76
static int linuxPciHandleBIOS(PCITAG Tag, int basereg, unsigned char *buf, int len);
77
static Bool linuxDomainSupport(void);
76
78
77
static pciBusFuncs_t linuxFuncs0 = {
79
static pciBusFuncs_t linuxFuncs0 = {
78
/* pciReadLong      */	linuxPciCfgRead,
80
/* pciReadLong      */	linuxPciCfgRead,
Lines 110-115 static pciBusInfo_t linuxPci0 = { Link Here
110
/* from lnx_pci.c. */
112
/* from lnx_pci.c. */
111
extern int lnxPciInit(void);
113
extern int lnxPciInit(void);
112
114
115
static Bool	domain_support = FALSE;
116
113
void
117
void
114
linuxPciInit()
118
linuxPciInit()
115
{
119
{
Lines 120-125 linuxPciInit() Link Here
120
		   we'll need a fallback for 2.0 kernels here */
124
		   we'll need a fallback for 2.0 kernels here */
121
		return;
125
		return;
122
	}
126
	}
127
#ifndef INCLUDE_XF86_NO_DOMAIN
128
	domain_support = linuxDomainSupport();
129
#endif
123
	pciNumBuses    = 1;
130
	pciNumBuses    = 1;
124
	pciBusInfo[0]  = &linuxPci0;
131
	pciBusInfo[0]  = &linuxPci0;
125
	pciFindFirstFP = pciGenFindFirst;
132
	pciFindFirstFP = pciGenFindFirst;
Lines 131-143 linuxPciInit() Link Here
131
static int
138
static int
132
linuxPciOpenFile(PCITAG tag, Bool write)
139
linuxPciOpenFile(PCITAG tag, Bool write)
133
{
140
{
134
	static int	lbus,ldev,lfunc,fd = -1,is_write = 0;
141
	static int	ldomain, lbus,ldev,lfunc,fd = -1,is_write = 0;
135
	int		bus, dev, func;
142
	int		domain, bus, dev, func;
136
	char		file[64];
143
	char		file[64];
137
	struct stat	ignored;
144
	struct stat	ignored;
138
	static int is26 = -1;
145
	static int is26 = -1;
139
146
140
	bus  = PCI_BUS_FROM_TAG(tag);
147
	domain = PCI_DOM_FROM_TAG(tag);
148
	bus  = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(tag));
141
	dev  = PCI_DEV_FROM_TAG(tag);
149
	dev  = PCI_DEV_FROM_TAG(tag);
142
	func = PCI_FUNC_FROM_TAG(tag);
150
	func = PCI_FUNC_FROM_TAG(tag);
143
	if (is26 == -1) {
151
	if (is26 == -1) {
Lines 147-176 linuxPciOpenFile(PCITAG tag, Bool write) Link Here
147
			is26 = 1;
155
			is26 = 1;
148
	}
156
	}
149
	
157
	
150
	if (fd == -1 || (write && (!is_write))
158
	if (!domain_support && domain > 0)
159
	    return -1;
160
161
	if (fd == -1 || (write && (!is_write)) || domain != ldomain
151
	    || bus != lbus || dev != ldev || func != lfunc) {
162
	    || bus != lbus || dev != ldev || func != lfunc) {
152
		if (fd != -1)
163
		if (fd != -1) {
153
			close(fd);
164
			close(fd);
165
			fd = -1;
166
		}
154
		if (is26)
167
		if (is26)
155
			sprintf(file,"/sys/bus/pci/devices/0000:%02x:%02x.%01x/config",
168
			sprintf(file,"/sys/bus/pci/devices/%04x:%02x:%02x.%01x/config",
156
				bus, dev, func);
169
				domain, bus, dev, func);
157
		else {
170
		else {
158
			if (bus < 256) {
171
			if (bus < 256) {
159
				sprintf(file,"/proc/bus/pci/%02x",bus);
172
				sprintf(file, "/proc/bus/pci/%04x:%02x", domain, bus);
160
				if (stat(file, &ignored) < 0)
173
				if (stat(file, &ignored) < 0) {
161
					sprintf(file, "/proc/bus/pci/0000:%02x/%02x.%1x",
174
					if (domain == 0) 
162
						bus, dev, func);
175
						sprintf(file, "/proc/bus/pci/%02x/%02x.%1x",
163
				else
176
							bus, dev, func);
164
					sprintf(file, "/proc/bus/pci/%02x/%02x.%1x",
177
					else
165
						bus, dev, func);
178
						goto bail;
179
				} else
180
					sprintf(file, "/proc/bus/pci/%04x:%02x/%02x.%1x",
181
						domain, bus, dev, func);
166
			} else {
182
			} else {
167
				sprintf(file,"/proc/bus/pci/%04x",bus);
183
				sprintf(file, "/proc/bus/pci/%04x:%04x", domain, bus);
168
				if (stat(file, &ignored) < 0)
184
				if (stat(file, &ignored) < 0) {
169
					sprintf(file, "/proc/bus/pci/0000:%04x/%02x.%1x",
185
					if (domain == 0)
170
						bus, dev, func);
186
						sprintf(file, "/proc/bus/pci/%04x/%02x.%1x",
171
				else
187
							bus, dev, func);
172
					sprintf(file, "/proc/bus/pci/%04x/%02x.%1x",
188
					else
173
						bus, dev, func);
189
						goto bail;
190
				} else
191
					sprintf(file, "/proc/bus/pci/%04x:%04x/%02x.%1x",
192
						domain, bus, dev, func);
174
			}
193
			}
175
		}
194
		}
176
		if (write) {
195
		if (write) {
Lines 185-191 linuxPciOpenFile(PCITAG tag, Bool write) Link Here
185
			    fd = open(file,O_RDONLY);
204
			    fd = open(file,O_RDONLY);
186
			    is_write = FALSE;
205
			    is_write = FALSE;
187
		}
206
		}
188
		
207
	bail:
208
		ldomain = domain;
189
		lbus  = bus;
209
		lbus  = bus;
190
		ldev  = dev;
210
		ldev  = dev;
191
		lfunc = func;
211
		lfunc = func;
Lines 483-488 linuxGetSizes(PCITAG Tag, unsigned long Link Here
483
    *mem_size = sizes->mem_size;
503
    *mem_size = sizes->mem_size;
484
}
504
}
485
505
506
static Bool
507
linuxDomainSupport(void)
508
{
509
    DIR *dir;
510
    struct dirent *dirent;
511
    char *end;
512
513
    if (!(dir = opendir("/proc/bus/pci")))
514
       return FALSE;
515
    while (1) {
516
	if (!(dirent = readdir(dir)))
517
	    return FALSE;
518
	strtol(dirent->d_name,&end,16);
519
	/* entry of the form xx or xxxx : x=[0..f] no domain */
520
	if (*end == '\0')
521
	    return FALSE;
522
	else if (*end == ':') {
523
	    /* ':' found immediately after: verify for xxxx:xx or xxxx:xxxx */
524
	    strtol(end + 1,&end,16);
525
	    if (*end == '\0')
526
		return TRUE;
527
	}
528
    }
529
    return FALSE;
530
} 
531
486
_X_EXPORT int
532
_X_EXPORT int
487
xf86GetPciDomain(PCITAG Tag)
533
xf86GetPciDomain(PCITAG Tag)
488
{
534
{
Lines 495-509 xf86GetPciDomain(PCITAG Tag) Link Here
495
	return result;
541
	return result;
496
542
497
    if (!pPCI || pPCI->fakeDevice)
543
    if (!pPCI || pPCI->fakeDevice)
498
	return 1;		/* Domain 0 is reserved */
544
	return 0;
499
545
500
    if ((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0,FALSE)) < 0)
546
    if ((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0,FALSE)) < 0)
501
	return 0;
547
	return -1;
502
548
503
    if ((result = ioctl(fd, PCIIOC_CONTROLLER, 0)) < 0)
549
    if ((result = ioctl(fd, PCIIOC_CONTROLLER, 0)) < 0)
504
	return 0;
550
	return -1;
505
551
506
    return result + 1;		/* Domain 0 is reserved */
552
    return result;
507
}
553
}
508
554
509
static pointer
555
static pointer
Lines 575-581 linuxMapPci(int ScreenNum, int Flags, PC Link Here
575
    return NULL;
621
    return NULL;
576
}
622
}
577
623
578
#define MAX_DOMAINS 257
624
#define MAX_DOMAINS 256
579
static pointer DomainMmappedIO[MAX_DOMAINS];
625
static pointer DomainMmappedIO[MAX_DOMAINS];
580
static pointer DomainMmappedMem[MAX_DOMAINS];
626
static pointer DomainMmappedMem[MAX_DOMAINS];
581
627
Lines 597-607 linuxOpenLegacy(PCITAG Tag, char *name) Link Here
597
	domain = xf86GetPciDomain(Tag);
643
	domain = xf86GetPciDomain(Tag);
598
	bus = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
644
	bus = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
599
645
600
	/* Domain 0 is reserved -- see xf86GetPciDomain() */
646
	if ((domain < 0) || (domain >= MAX_DOMAINS))
601
	if ((domain <= 0) || (domain >= MAX_DOMAINS))
602
	    FatalError("linuxOpenLegacy():  domain out of range\n");
647
	    FatalError("linuxOpenLegacy():  domain out of range\n");
603
648
604
	sprintf(path, PREFIX, domain - 1, bus, name);
649
	sprintf(path, PREFIX, domain, bus, name);
605
	fd = open(path, O_RDWR);
650
	fd = open(path, O_RDWR);
606
	if (fd >= 0) {
651
	if (fd >= 0) {
607
	    xfree(path);
652
	    xfree(path);
Lines 686-692 xf86MapDomainIO(int ScreenNum, int Flags Link Here
686
    int domain = xf86GetPciDomain(Tag);
731
    int domain = xf86GetPciDomain(Tag);
687
    int fd;
732
    int fd;
688
733
689
    if ((domain <= 0) || (domain >= MAX_DOMAINS))
734
    if ((domain < 0) || (domain >= MAX_DOMAINS))
690
	FatalError("xf86MapDomainIO():  domain out of range\n");
735
	FatalError("xf86MapDomainIO():  domain out of range\n");
691
736
692
    if (DomainMmappedIO[domain])
737
    if (DomainMmappedIO[domain])
Lines 725-731 xf86ReadDomainMemory(PCITAG Tag, ADDRESS Link Here
725
    struct stat st;
770
    struct stat st;
726
771
727
    dom  = PCI_DOM_FROM_TAG(Tag);
772
    dom  = PCI_DOM_FROM_TAG(Tag);
728
    bus  = PCI_BUS_FROM_TAG(Tag);
773
    bus  = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
729
    dev  = PCI_DEV_FROM_TAG(Tag);
774
    dev  = PCI_DEV_FROM_TAG(Tag);
730
    func = PCI_FUNC_FROM_TAG(Tag);
775
    func = PCI_FUNC_FROM_TAG(Tag);
731
    sprintf(file, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/rom",
776
    sprintf(file, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/rom",
Lines 798-804 xf86BusAccWindowsFromOS(void) Link Here
798
		  RANGE_TYPE(ResExcIoBlock, domain));
843
		  RANGE_TYPE(ResExcIoBlock, domain));
799
	    pRes = xf86AddResToList(pRes, &range, -1);
844
	    pRes = xf86AddResToList(pRes, &range, -1);
800
845
801
	    if (domain <= 0)
846
	    if (domain < 0)
802
		break;
847
		break;
803
	}
848
	}
804
    }
849
    }
Lines 832-838 xf86PciBusAccWindowsFromOS(void) Link Here
832
		  RANGE_TYPE(ResExcIoBlock, domain));
877
		  RANGE_TYPE(ResExcIoBlock, domain));
833
	    pRes = xf86AddResToList(pRes, &range, -1);
878
	    pRes = xf86AddResToList(pRes, &range, -1);
834
879
835
	    if (domain <= 0)
880
	    if (domain < 0)
836
		break;
881
		break;
837
	}
882
	}
838
    }
883
    }
Lines 884-890 xf86AccResFromOS(resPtr pRes) Link Here
884
		  RANGE_TYPE(ResExcIoBlock, domain));
929
		  RANGE_TYPE(ResExcIoBlock, domain));
885
	    pRes = xf86AddResToList(pRes, &range, -1);
930
	    pRes = xf86AddResToList(pRes, &range, -1);
886
931
887
	    if (domain <= 0)
932
	    if (domain < 0)
888
		break;
933
		break;
889
	}
934
	}
890
    }
935
    }
Lines 904-910 int linuxPciHandleBIOS(PCITAG Tag, int b Link Here
904
  int sofar = 0;
949
  int sofar = 0;
905
950
906
  dom  = PCI_DOM_FROM_TAG(Tag);
951
  dom  = PCI_DOM_FROM_TAG(Tag);
907
  bus  = PCI_BUS_FROM_TAG(Tag);
952
  bus  = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
908
  dev  = PCI_DEV_FROM_TAG(Tag);
953
  dev  = PCI_DEV_FROM_TAG(Tag);
909
  func = PCI_FUNC_FROM_TAG(Tag);
954
  func = PCI_FUNC_FROM_TAG(Tag);
910
  sprintf(file, "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/rom",
955
  sprintf(file, "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/rom",
Lines 934-936 int linuxPciHandleBIOS(PCITAG Tag, int b Link Here
934
  }
979
  }
935
  return 0;
980
  return 0;
936
}
981
}
982
983
#ifdef __ia64__
984
static PCITAG ia64linuxPciFindFirst(void);
985
static PCITAG ia64linuxPciFindNext(void);
986
987
void   
988
ia64linuxPciInit()
989
{
990
    struct stat st;
991
992
    linuxPciInit();
993
	   
994
    if (!stat("/proc/sgi_sn/licenseID", &st) && pciNumBuses) {
995
       /* Be a little paranoid here and only use this code for Altix systems.
996
	* It is generic, so it should work on any system, but depends on
997
	* /proc/bus/pci entries for each domain/bus combination. Altix is
998
	* guaranteed a recent enough kernel to have them.
999
	*/
1000
       pciFindFirstFP = ia64linuxPciFindFirst;
1001
       pciFindNextFP  = ia64linuxPciFindNext;
1002
    }
1003
}
1004
1005
static DIR *busdomdir;
1006
static DIR *devdir;
1007
	       
1008
static PCITAG
1009
ia64linuxPciFindFirst(void)
1010
{   
1011
       busdomdir = opendir("/proc/bus/pci");
1012
       devdir = NULL;
1013
1014
       return ia64linuxPciFindNext();
1015
}   
1016
1017
static struct dirent *getnextbus(int *domain, int *bus)
1018
{
1019
    struct dirent *entry;
1020
    int dombus;
1021
1022
    for (;;) {
1023
	entry = readdir(busdomdir);
1024
	if (entry == NULL) {
1025
	    *domain = 0;
1026
	    *bus = 0;
1027
	    closedir(busdomdir);
1028
	    return NULL;
1029
	}
1030
	if (sscanf(entry->d_name, "%04x:%02x", domain, bus) != 2)
1031
	    continue;
1032
	dombus = PCI_MAKE_BUS(*domain, *bus);
1033
1034
	if (pciNumBuses <= dombus)
1035
	    pciNumBuses = dombus + 1;
1036
	if (!pciBusInfo[dombus]) {
1037
	    pciBusInfo[dombus] = xnfalloc(sizeof(pciBusInfo_t));
1038
	    *pciBusInfo[dombus] = *pciBusInfo[0];
1039
	}
1040
1041
	return entry;
1042
    }
1043
}
1044
1045
static PCITAG
1046
ia64linuxPciFindNext(void)
1047
{
1048
    struct dirent *entry;
1049
    char file[40];
1050
    static int bus, dev, func, domain;
1051
    PCITAG pciDeviceTag;
1052
    CARD32 devid;
1053
1054
    for (;;) {
1055
	if (devdir == NULL) {
1056
	    entry = getnextbus(&domain, &bus);
1057
	    if (!entry)
1058
		return PCI_NOT_FOUND;
1059
	    snprintf(file, 40, "/proc/bus/pci/%s", entry->d_name);
1060
	    devdir = opendir(file);
1061
	    if (!devdir)
1062
		return PCI_NOT_FOUND;
1063
1064
	}
1065
1066
	entry = readdir(devdir);
1067
1068
	if (entry == NULL) {
1069
	    closedir(devdir);
1070
	    devdir = NULL;
1071
	    continue;
1072
	}
1073
1074
	if (sscanf(entry->d_name, "%02x . %01x", &dev, &func) == 2) {
1075
	    pciDeviceTag = PCI_MAKE_TAG(PCI_MAKE_BUS(domain, bus), dev, func);
1076
	    devid = pciReadLong(pciDeviceTag, PCI_ID_REG);
1077
	    if ((devid & pciDevidMask) == pciDevid)
1078
		/* Yes - Return it.  Otherwise, next device */
1079
		return pciDeviceTag;
1080
	}
1081
    }
1082
}
1083
#endif
1084
(-)../xorg-server-1.1.99.3.orig/hw/xfree86/os-support/bus/xf86Pci.h (+3 lines)
Lines 766-771 void pciSetBitsByte(PCITAG tag, in Link Here
766
ADDRESS	      pciBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr);
766
ADDRESS	      pciBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr);
767
ADDRESS	      pciHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr);
767
ADDRESS	      pciHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr);
768
PCITAG	      pciTag(int busnum, int devnum, int funcnum);
768
PCITAG	      pciTag(int busnum, int devnum, int funcnum);
769
PCITAG	      pciDomTag(int domnum, int busnum, int devnum, int funcnum);
770
void	      pciInfoFromTag(PCITAG tag, int *domainnum,
771
				int *busnum, int *devnum, int *funcnum);
769
int	      pciGetBaseSize(PCITAG tag, int indx, Bool destructive, Bool *min);
772
int	      pciGetBaseSize(PCITAG tag, int indx, Bool destructive, Bool *min);
770
CARD32	      pciCheckForBrokenBase(PCITAG tag,int basereg);
773
CARD32	      pciCheckForBrokenBase(PCITAG tag,int basereg);
771
pointer	      xf86MapPciMem(int ScreenNum, int Flags, PCITAG Tag,
774
pointer	      xf86MapPciMem(int ScreenNum, int Flags, PCITAG Tag,
(-)../xorg-server-1.1.99.3.orig/hw/xfree86/os-support/linux/lnx_pci.c (-18 / +62 lines)
Lines 3-9 Link Here
3
#include <xorg-config.h>
3
#include <xorg-config.h>
4
#endif
4
#endif
5
5
6
#include <sys/types.h>
6
#include <stdio.h>
7
#include <stdio.h>
8
#include <dirent.h>
7
#include <X11/X.h>
9
#include <X11/X.h>
8
#include "os.h"
10
#include "os.h"
9
#include "xf86.h"
11
#include "xf86.h"
Lines 25-32 Link Here
25
int lnxPciInit(void);
27
int lnxPciInit(void);
26
28
27
struct pci_dev {
29
struct pci_dev {
30
    unsigned int domain;
28
    unsigned int bus;
31
    unsigned int bus;
29
    unsigned int devfn;
32
    unsigned int dev;
33
    unsigned int fn;
30
    PCIADDR_TYPE offset[7];
34
    PCIADDR_TYPE offset[7];
31
    PCIADDR_TYPE size[7];
35
    PCIADDR_TYPE size[7];
32
    struct pci_dev *next;
36
    struct pci_dev *next;
Lines 38-47 int xf86OSLinuxNumPciDevs = 0; Link Here
38
static struct pci_dev *xf86OSLinuxGetPciDevs(void) {
42
static struct pci_dev *xf86OSLinuxGetPciDevs(void) {
39
    char c[0x200];
43
    char c[0x200];
40
    FILE *file = NULL;
44
    FILE *file = NULL;
45
    DIR  *dir;
46
    struct dirent *dirent;
41
    struct pci_dev *tmp, *ret = NULL;
47
    struct pci_dev *tmp, *ret = NULL;
42
    unsigned int num;
48
    unsigned int i, num, devfn;
49
    unsigned PCIADDR_TYPE begin, end;
43
    char *res;
50
    char *res;
44
    
51
    
52
    /* Try 2.6 devices first, with domain support */
53
    if ( (dir = opendir ("/sys/bus/pci/devices")) ) {
54
	xf86OSLinuxNumPciDevs = 0;
55
	while ( (dirent = readdir (dir)) ) {
56
	    unsigned int domain, bus, dev, fn;
57
	    if (sscanf (dirent->d_name, "%04x:%02x:%02x.%01x",
58
			&domain, &bus, &dev, &fn) == 4) {
59
		tmp = xcalloc (sizeof(struct pci_dev), 1);
60
		tmp->domain = domain;
61
		tmp->bus    = bus;
62
		tmp->dev    = dev;
63
		tmp->fn     = fn;
64
		sprintf (c, "/sys/bus/pci/devices/%12s/resource",
65
			 dirent->d_name);
66
		i = 0;
67
		if ( (file = fopen (c, "r")) ) {
68
		    while (i < 7 && fgets (c, 0x200, file)) {
69
			if (sscanf (c, PCIADDR_FMT " " PCIADDR_FMT " "
70
				    PCIADDR_IGNORE_FMT, &begin, &end) == 2) {
71
			    tmp->offset[i] = begin;
72
			    tmp->size[i]   = begin ? end-begin+1 : 0;
73
			    i++;
74
			}
75
		    }
76
		    fclose (file);
77
		}
78
		if (i > 0) {
79
		    tmp->next = ret;
80
		    ret       = tmp;
81
		    xf86OSLinuxNumPciDevs++;
82
		} else
83
		    xfree (tmp);
84
	    }
85
	}
86
	closedir (dir);
87
    }
88
89
    if (ret)
90
	return ret;
91
45
    file = fopen("/proc/bus/pci/devices", "r");
92
    file = fopen("/proc/bus/pci/devices", "r");
46
    if (!file) return NULL;
93
    if (!file) return NULL;
47
94
Lines 70-78 static struct pci_dev *xf86OSLinuxGetPci Link Here
70
                "\t" PCIADDR_FMT
117
                "\t" PCIADDR_FMT
71
                "\t" PCIADDR_FMT
118
                "\t" PCIADDR_FMT
72
                "\t" PCIADDR_FMT,
119
                "\t" PCIADDR_FMT,
73
                &tmp->bus,&tmp->devfn,&tmp->offset[0],&tmp->offset[1],&tmp->offset[2],&tmp->offset[3],
120
                &tmp->bus,&devfn,&tmp->offset[0],&tmp->offset[1],&tmp->offset[2],&tmp->offset[3],
74
                &tmp->offset[4],&tmp->offset[5],&tmp->offset[6], &tmp->size[0], &tmp->size[1], &tmp->size[2],
121
                &tmp->offset[4],&tmp->offset[5],&tmp->offset[6], &tmp->size[0], &tmp->size[1], &tmp->size[2],
75
                &tmp->size[3], &tmp->size[4], &tmp->size[5], &tmp->size[6]);
122
                &tmp->size[3], &tmp->size[4], &tmp->size[5], &tmp->size[6]);
123
            tmp->dev = devfn >> 3;
124
            tmp->fn  = devfn & 0x7;
76
            if (num != 16) {  /* apparantly not 2.3 style */
125
            if (num != 16) {  /* apparantly not 2.3 style */
77
                xfree(tmp);
126
                xfree(tmp);
78
                fclose(file);
127
                fclose(file);
Lines 100-110 int lnxPciInit(void) { Link Here
100
Bool
149
Bool
101
xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits)
150
xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits)
102
{
151
{
103
    unsigned int dev, fn;
104
    signed PCIADDR_TYPE Size;
152
    signed PCIADDR_TYPE Size;
105
    struct pci_dev *device;
153
    struct pci_dev *device;
106
154
107
    if (index > 7)
155
    if (index >= 7)
108
        return FALSE;
156
        return FALSE;
109
    
157
    
110
    if (!xf86OSLinuxPCIDevs) {
158
    if (!xf86OSLinuxPCIDevs) {
Lines 114-123 xf86GetPciSizeFromOS(PCITAG tag, int ind Link Here
114
        return FALSE;
162
        return FALSE;
115
    
163
    
116
    for (device = xf86OSLinuxPCIDevs; device; device = device->next) {
164
    for (device = xf86OSLinuxPCIDevs; device; device = device->next) {
117
        dev = device->devfn >> 3;
165
        if (tag == pciDomTag (device->domain, device->bus,
118
	fn = device->devfn & 0x7;
166
			      device->dev, device->fn)) {
119
        if (tag == pciTag(device->bus,dev,fn)) {
120
            *bits = 0;
121
            if (device->size[index] != 0) {
167
            if (device->size[index] != 0) {
122
                Size = device->size[index] - ((PCIADDR_TYPE) 1);
168
                Size = device->size[index] - ((PCIADDR_TYPE) 1);
123
                while (Size & ((PCIADDR_TYPE) 0x01)) {
169
                while (Size & ((PCIADDR_TYPE) 0x01)) {
Lines 134-147 xf86GetPciSizeFromOS(PCITAG tag, int ind Link Here
134
180
135
181
136
182
183
#if 0
137
/* Query the kvirt address (64bit) of a BAR range from TAG */
184
/* Query the kvirt address (64bit) of a BAR range from TAG */
138
Bool
185
Bool
139
xf86GetPciOffsetFromOS(PCITAG tag, int index, unsigned long* bases)
186
xf86GetPciOffsetFromOS(PCITAG tag, int index, unsigned long* bases)
140
{
187
{
141
    unsigned int dev, fn;
142
    struct pci_dev *device;
188
    struct pci_dev *device;
143
189
144
    if (index > 7)
190
    if (index >= 7)
145
        return FALSE;
191
        return FALSE;
146
192
147
    if (!xf86OSLinuxPCIDevs) {
193
    if (!xf86OSLinuxPCIDevs) {
Lines 151-159 xf86GetPciOffsetFromOS(PCITAG tag, int i Link Here
151
        return FALSE;
197
        return FALSE;
152
198
153
    for (device = xf86OSLinuxPCIDevs; device; device = device->next) {
199
    for (device = xf86OSLinuxPCIDevs; device; device = device->next) {
154
        dev = device->devfn >> 3;
200
        if (tag == pciDomTag (device->domain, device->bus,
155
        fn = device->devfn & 0x7;
201
			      device->dev, device->fn)) {
156
        if (tag == pciTag(device->bus,dev,fn)) {
157
            /* return the offset for the index requested */
202
            /* return the offset for the index requested */
158
            *bases = device->offset[index];
203
            *bases = device->offset[index];
159
            return TRUE;
204
            return TRUE;
Lines 162-173 xf86GetPciOffsetFromOS(PCITAG tag, int i Link Here
162
207
163
    return FALSE;
208
    return FALSE;
164
}
209
}
210
#endif
165
211
166
/* Query the kvirt address (64bit) of a BAR range from size for a given TAG */
212
/* Query the kvirt address (64bit) of a BAR range from size for a given TAG */
167
unsigned long
213
unsigned long
168
xf86GetOSOffsetFromPCI(PCITAG tag, int space, unsigned long base)
214
xf86GetOSOffsetFromPCI(PCITAG tag, int space, unsigned long base)
169
{
215
{
170
    unsigned int dev, fn;
171
    unsigned int ndx;
216
    unsigned int ndx;
172
    struct pci_dev *device;
217
    struct pci_dev *device;
173
218
Lines 179-187 xf86GetOSOffsetFromPCI(PCITAG tag, int s Link Here
179
    }
224
    }
180
225
181
    for (device = xf86OSLinuxPCIDevs; device; device = device->next) {
226
    for (device = xf86OSLinuxPCIDevs; device; device = device->next) {
182
        dev = device->devfn >> 3;
227
        if (tag == pciDomTag (device->domain, device->bus,
183
        fn = device->devfn & 0x7;
228
			      device->dev, device->fn)) {
184
        if (tag == pciTag(device->bus, dev, fn)) {
185
            /* ok now look through all the BAR values of this device */
229
            /* ok now look through all the BAR values of this device */
186
            pciConfigPtr pDev = xf86GetPciConfigFromTag(tag);
230
            pciConfigPtr pDev = xf86GetPciConfigFromTag(tag);
187
231

Return to bug 197572