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

(-)programs/Xserver/hw/xfree86/int10/helper_exec.c.orig (-2 / +2 lines)
Lines 478-484 pciCfg1in(CARD16 addr, CARD32 *val) Link Here
478
	return 1;
478
	return 1;
479
    }
479
    }
480
    if (addr == 0xCFC) {
480
    if (addr == 0xCFC) {
481
	*val = pciReadLong(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr));
481
	*val = pciReadLong(Int10Current->Tag, OFFSET(PciCfg1Addr));
482
	return 1;
482
	return 1;
483
    }
483
    }
484
    return 0;
484
    return 0;
Lines 492-498 pciCfg1out(CARD16 addr, CARD32 val) Link Here
492
	return 1;
492
	return 1;
493
    }
493
    }
494
    if (addr == 0xCFC) {
494
    if (addr == 0xCFC) {
495
	pciWriteLong(TAG(PciCfg1Addr), OFFSET(PciCfg1Addr), val);
495
	pciWriteLong(Int10Current->Tag, OFFSET(PciCfg1Addr),val);
496
	return 1;
496
	return 1;
497
    }
497
    }
498
    return 0;
498
    return 0;
(-)programs/Xserver/hw/xfree86/os-support/bus/Pci.c.orig (+10 lines)
Lines 597-602 pciGetBaseSize(PCITAG tag, int index, Bo Link Here
597
  return bits;
597
  return bits;
598
}
598
}
599
599
600
void
601
pciInfoFromTag(PCITAG tag, int *domainnum, int *busnum,
602
               int *devnum, int *funcnum)
603
{
604
    *domainnum = PCI_DOM_FROM_TAG(tag);
605
    *busnum = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(tag));
606
    *devnum = PCI_DEV_FROM_TAG(tag);
607
    *funcnum = PCI_FUNC_FROM_TAG(tag);
608
}
609
600
PCITAG
610
PCITAG
601
pciTag(int busnum, int devnum, int funcnum)
611
pciTag(int busnum, int devnum, int funcnum)
602
{
612
{
(-)programs/Xserver/hw/xfree86/os-support/bus/Pci.h.orig (-2 / +2 lines)
Lines 120-126 Link Here
120
				/* by xf86scanpci		     */
120
				/* by xf86scanpci		     */
121
#if defined(sun) && defined(SVR4) && defined(sparc)
121
#if defined(sun) && defined(SVR4) && defined(sparc)
122
# define MAX_PCI_BUSES   4096	/* Max number of PCI buses           */
122
# define MAX_PCI_BUSES   4096	/* Max number of PCI buses           */
123
#elif defined(__alpha__) && defined (linux)
123
#elif (defined(__alpha__) || defined(__ia64__)) && defined (linux)
124
# define MAX_PCI_DOMAINS	512
124
# define MAX_PCI_DOMAINS	512
125
# define PCI_DOM_MASK	0x01fful
125
# define PCI_DOM_MASK	0x01fful
126
# define MAX_PCI_BUSES	(MAX_PCI_DOMAINS*256) /* 256 per domain      */
126
# define MAX_PCI_BUSES	(MAX_PCI_DOMAINS*256) /* 256 per domain      */
Lines 259-265 Link Here
259
# endif
259
# endif
260
#elif defined(__ia64__)
260
#elif defined(__ia64__)
261
# if defined(linux)
261
# if defined(linux)
262
#  define ARCH_PCI_INIT linuxPciInit
262
#  define ARCH_PCI_INIT ia64linuxPciInit
263
#  define INCLUDE_XF86_MAP_PCI_MEM
263
#  define INCLUDE_XF86_MAP_PCI_MEM
264
# elif defined(FreeBSD)
264
# elif defined(FreeBSD)
265
#  define ARCH_PCI_INIT freebsdPciInit
265
#  define ARCH_PCI_INIT freebsdPciInit
(-)programs/Xserver/hw/xfree86/os-support/bus/altixPCI.c.orig (-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
(-)programs/Xserver/hw/xfree86/os-support/bus/linuxPci.c.orig (-33 / +183 lines)
Lines 55-60 Link Here
55
#include "xf86Priv.h"
55
#include "xf86Priv.h"
56
#include "xf86_OSlib.h"
56
#include "xf86_OSlib.h"
57
#include "Pci.h"
57
#include "Pci.h"
58
#include <dirent.h>
58
59
59
/*
60
/*
60
 * linux platform specific PCI access functions -- using /proc/bus/pci
61
 * linux platform specific PCI access functions -- using /proc/bus/pci
Lines 73-78 static CARD8 linuxPciCfgReadByte(PCITAG Link Here
73
static void linuxPciCfgWriteByte(PCITAG tag, int off, CARD8 val);
74
static void linuxPciCfgWriteByte(PCITAG tag, int off, CARD8 val);
74
static CARD16 linuxPciCfgReadWord(PCITAG tag, int off);
75
static CARD16 linuxPciCfgReadWord(PCITAG tag, int off);
75
static void linuxPciCfgWriteWord(PCITAG tag, int off, CARD16 val);
76
static void linuxPciCfgWriteWord(PCITAG tag, int off, CARD16 val);
77
static Bool linuxDomainSupport(void);
76
78
77
static pciBusFuncs_t linuxFuncs0 = {
79
static pciBusFuncs_t linuxFuncs0 = {
78
/* pciReadLong      */	linuxPciCfgRead,
80
/* pciReadLong      */	linuxPciCfgRead,
Lines 111-116 static pciBusInfo_t linuxPci0 = { Link Here
111
/* bridge      */	NULL
113
/* bridge      */	NULL
112
};
114
};
113
115
116
static Bool	domain_support = FALSE;
117
114
void
118
void
115
linuxPciInit()
119
linuxPciInit()
116
{
120
{
Lines 121-163 linuxPciInit() Link Here
121
		   we'll need a fallback for 2.0 kernels here */
125
		   we'll need a fallback for 2.0 kernels here */
122
		return;
126
		return;
123
	}
127
	}
128
	
129
#ifndef INCLUDE_XF86_NO_DOMAIN
130
	domain_support = linuxDomainSupport();
131
#endif
124
	pciNumBuses    = 1;
132
	pciNumBuses    = 1;
125
	pciBusInfo[0]  = &linuxPci0;
133
	pciBusInfo[0]  = &linuxPci0;
126
	pciFindFirstFP = pciGenFindFirst;
134
	pciFindFirstFP = pciGenFindFirst;
127
	pciFindNextFP  = pciGenFindNext;
135
	pciFindNextFP  = pciGenFindNext;
136
137
	return;
128
}
138
}
129
139
130
static int
140
static int
131
linuxPciOpenFile(PCITAG tag, Bool write)
141
linuxPciOpenFile(PCITAG tag, Bool write)
132
{
142
{
133
	static int	lbus,ldev,lfunc,fd = -1,is_write = 0;
143
	static int	ldomain, lbus,ldev,lfunc,fd = -1,is_write = 0;
134
	int		bus, dev, func;
144
	int		domain, bus, dev, func;
135
	char		file[32];
145
	char		file[32];
136
	struct stat	ignored;
146
	struct stat	ignored;
137
147
138
	bus  = PCI_BUS_FROM_TAG(tag);
148
	domain = PCI_DOM_FROM_TAG(tag);
149
	bus  = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(tag));
139
	dev  = PCI_DEV_FROM_TAG(tag);
150
	dev  = PCI_DEV_FROM_TAG(tag);
140
	func = PCI_FUNC_FROM_TAG(tag);
151
	func = PCI_FUNC_FROM_TAG(tag);
141
	if (fd == -1 || (write && (!is_write))
152
142
	    || bus != lbus || dev != ldev || func != lfunc) {
153
	if (!domain_support && domain > 0)
143
		if (fd != -1)
154
	    return -1;
155
156
	if (fd == -1 || (write && (!is_write)) || bus != lbus
157
		|| dev != ldev || func != lfunc || domain != ldomain) {
158
159
		if (fd != -1) {
144
			close(fd);
160
			close(fd);
161
			fd = -1;
162
		}
145
		if (bus < 256) {
163
		if (bus < 256) {
146
		        sprintf(file,"/proc/bus/pci/%02x",bus);
164
		        sprintf(file, "/proc/bus/pci/%04x:%02x", domain, bus);
147
			if (stat(file, &ignored) < 0)
165
			if (stat(file, &ignored) < 0) {
148
				sprintf(file, "/proc/bus/pci/0000:%02x/%02x.%1x",
166
				if (domain == 0) 
149
					bus, dev, func);
167
					sprintf(file, "/proc/bus/pci/%02x/%02x.%1x",
150
			else
168
						bus, dev, func);
151
				sprintf(file, "/proc/bus/pci/%02x/%02x.%1x",
169
				else goto bail;
152
					bus, dev, func);
170
			} else
171
				sprintf(file, "/proc/bus/pci/%04x:%02x/%02x.%1x",
172
					domain, bus, dev, func);
153
		} else {
173
		} else {
154
		        sprintf(file,"/proc/bus/pci/%04x",bus);
174
		        sprintf(file, "/proc/bus/pci/%04x:%04x", domain, bus);
155
			if (stat(file, &ignored) < 0)
175
			if (stat(file, &ignored) < 0) {
156
				sprintf(file, "/proc/bus/pci/0000:%04x/%02x.%1x",
176
			    if (domain == 0)
157
					bus, dev, func);
177
					sprintf(file, "/proc/bus/pci/%04x/%02x.%1x",
158
			else
178
						bus, dev, func);
159
				sprintf(file, "/proc/bus/pci/%04x/%02x.%1x",
179
			    else goto bail;
160
					bus, dev, func);
180
			} else
181
				sprintf(file, "/proc/bus/pci/%04x:%04x/%02x.%1x",
182
					domain, bus, dev, func);
161
		}
183
		}
162
		if (write) {
184
		if (write) {
163
		    fd = open(file,O_RDWR);
185
		    fd = open(file,O_RDWR);
Lines 171-177 linuxPciOpenFile(PCITAG tag, Bool write) Link Here
171
			    fd = open(file,O_RDONLY);
193
			    fd = open(file,O_RDONLY);
172
			    is_write = FALSE;
194
			    is_write = FALSE;
173
		}
195
		}
174
		
196
	bail:
197
		ldomain = domain;
175
		lbus  = bus;
198
		lbus  = bus;
176
		ldev  = dev;
199
		ldev  = dev;
177
		lfunc = func;
200
		lfunc = func;
Lines 482-487 linuxGetSizes(PCITAG Tag, unsigned long Link Here
482
    }
505
    }
483
}
506
}
484
507
508
static Bool
509
linuxDomainSupport(void)
510
{
511
    DIR *dir;
512
    struct dirent *dirent;
513
    char *end;
514
515
    if (!(dir = opendir("/proc/bus/pci")))
516
	return FALSE;
517
    while (1) {
518
	if (!(dirent = readdir(dir)))
519
	    return FALSE;
520
	strtol(dirent->d_name,&end,16);
521
	/* entry of the form xx or xxxx : x=[0..f] no domain */
522
	if (*end == '\0')
523
	    return FALSE;
524
	else if (*end == ':') {
525
	    /* ':' found immediately after: verify for xxxx:xx or xxxx:xxxx */
526
	    strtol(end + 1,&end,16);
527
	    if (*end == '\0')
528
		return TRUE;
529
	}
530
    }
531
    return FALSE;
532
} 
533
	
485
int
534
int
486
xf86GetPciDomain(PCITAG Tag)
535
xf86GetPciDomain(PCITAG Tag)
487
{
536
{
Lines 494-508 xf86GetPciDomain(PCITAG Tag) Link Here
494
	return result;
543
	return result;
495
544
496
    if (!pPCI || pPCI->fakeDevice)
545
    if (!pPCI || pPCI->fakeDevice)
497
	return 1;		/* Domain 0 is reserved */
546
	return 0;
498
547
499
    if ((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0,FALSE)) < 0)
548
    if ((fd = linuxPciOpenFile(pPCI ? pPCI->tag : 0,FALSE)) < 0)
500
	return 0;
549
	return -1;
501
550
502
    if ((result = ioctl(fd, PCIIOC_CONTROLLER, 0)) < 0)
551
    if ((result = ioctl(fd, PCIIOC_CONTROLLER, 0)) < 0)
503
	return 0;
552
	return -1;
504
553
505
    return result + 1;		/* Domain 0 is reserved */
554
    return result;
506
}
555
}
507
556
508
static pointer
557
static pointer
Lines 574-580 linuxMapPci(int ScreenNum, int Flags, PC Link Here
574
    return NULL;
623
    return NULL;
575
}
624
}
576
625
577
#define MAX_DOMAINS 257
626
#define MAX_DOMAINS 256
578
static pointer DomainMmappedIO[MAX_DOMAINS];
627
static pointer DomainMmappedIO[MAX_DOMAINS];
579
static pointer DomainMmappedMem[MAX_DOMAINS];
628
static pointer DomainMmappedMem[MAX_DOMAINS];
580
629
Lines 596-606 linuxOpenLegacy(PCITAG Tag, char *name) Link Here
596
	domain = xf86GetPciDomain(Tag);
645
	domain = xf86GetPciDomain(Tag);
597
	bus = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
646
	bus = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
598
647
599
	/* Domain 0 is reserved -- see xf86GetPciDomain() */
648
	if ((domain < 0) || (domain >= MAX_DOMAINS))
600
	if ((domain <= 0) || (domain >= MAX_DOMAINS))
601
	    FatalError("linuxOpenLegacy():  domain out of range\n");
649
	    FatalError("linuxOpenLegacy():  domain out of range\n");
602
650
603
	sprintf(path, PREFIX, domain - 1, bus, name);
651
	sprintf(path, PREFIX, domain, bus, name);
604
	fd = open(path, O_RDWR);
652
	fd = open(path, O_RDWR);
605
	if (fd >= 0) {
653
	if (fd >= 0) {
606
	    xfree(path);
654
	    xfree(path);
Lines 685-691 xf86MapDomainIO(int ScreenNum, int Flags Link Here
685
    int domain = xf86GetPciDomain(Tag);
733
    int domain = xf86GetPciDomain(Tag);
686
    int fd;
734
    int fd;
687
735
688
    if ((domain <= 0) || (domain >= MAX_DOMAINS))
736
    if ((domain < 0) || (domain >= MAX_DOMAINS))
689
	FatalError("xf86MapDomainIO():  domain out of range\n");
737
	FatalError("xf86MapDomainIO():  domain out of range\n");
690
738
691
    if (DomainMmappedIO[domain])
739
    if (DomainMmappedIO[domain])
Lines 724-730 xf86ReadDomainMemory(PCITAG Tag, ADDRESS Link Here
724
    struct stat st;
772
    struct stat st;
725
773
726
    dom  = PCI_DOM_FROM_TAG(Tag);
774
    dom  = PCI_DOM_FROM_TAG(Tag);
727
    bus  = PCI_BUS_FROM_TAG(Tag);
775
    bus  = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
728
    dev  = PCI_DEV_FROM_TAG(Tag);
776
    dev  = PCI_DEV_FROM_TAG(Tag);
729
    func = PCI_FUNC_FROM_TAG(Tag);
777
    func = PCI_FUNC_FROM_TAG(Tag);
730
    sprintf(file, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/rom",
778
    sprintf(file, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/rom",
Lines 831-837 xf86PciBusAccWindowsFromOS(void) Link Here
831
		  RANGE_TYPE(ResExcIoBlock, domain));
879
		  RANGE_TYPE(ResExcIoBlock, domain));
832
	    pRes = xf86AddResToList(pRes, &range, -1);
880
	    pRes = xf86AddResToList(pRes, &range, -1);
833
881
834
	    if (domain <= 0)
882
	    if (domain < 0)
835
		break;
883
		break;
836
	}
884
	}
837
    }
885
    }
Lines 883-889 xf86AccResFromOS(resPtr pRes) Link Here
883
		  RANGE_TYPE(ResExcIoBlock, domain));
931
		  RANGE_TYPE(ResExcIoBlock, domain));
884
	    pRes = xf86AddResToList(pRes, &range, -1);
932
	    pRes = xf86AddResToList(pRes, &range, -1);
885
933
886
	    if (domain <= 0)
934
	    if (domain < 0)
887
		break;
935
		break;
888
	}
936
	}
889
    }
937
    }
Lines 892-894 xf86AccResFromOS(resPtr pRes) Link Here
892
}
940
}
893
941
894
#endif /* !INCLUDE_XF86_NO_DOMAIN */
942
#endif /* !INCLUDE_XF86_NO_DOMAIN */
943
944
#ifdef __ia64__
945
static PCITAG ia64linuxPciFindFirst(void);
946
static PCITAG ia64linuxPciFindNext(void);
947
948
void
949
ia64linuxPciInit()
950
{
951
    struct stat st;
952
953
    linuxPciInit();
954
955
    if (!stat("/proc/sgi_sn/licenseID", &st) && pciNumBuses) {
956
	/* Be a little paranoid here and only use this code for Altix systems.
957
	 * It is generic, so it should work on any system, but depends on
958
	 * /proc/bus/pci entries for each domain/bus combination. Altix is
959
	 * guaranteed a recent enough kernel to have them.
960
	 */
961
	pciFindFirstFP = ia64linuxPciFindFirst;
962
	pciFindNextFP  = ia64linuxPciFindNext;
963
    }
964
}
965
966
static DIR *busdomdir;
967
static DIR *devdir;
968
969
static PCITAG
970
ia64linuxPciFindFirst(void)
971
{
972
	busdomdir = opendir("/proc/bus/pci");
973
	devdir = NULL;
974
975
	return ia64linuxPciFindNext();
976
}
977
978
static struct dirent *getnextbus(int *domain, int *bus)
979
{
980
    struct dirent *entry;
981
    int dombus;
982
983
    for (;;) {
984
        entry = readdir(busdomdir);
985
        if (entry == NULL) {
986
            *domain = 0;
987
            *bus = 0;
988
            closedir(busdomdir);
989
            return NULL;
990
        }
991
        if (sscanf(entry->d_name, "%04x:%02x", domain, bus) != 2)
992
            continue;
993
        dombus = PCI_MAKE_BUS(*domain, *bus);
994
995
        if (pciNumBuses <= dombus)
996
            pciNumBuses = dombus + 1;
997
        if (!pciBusInfo[dombus]) {
998
            pciBusInfo[dombus] = xnfalloc(sizeof(pciBusInfo_t));
999
            *pciBusInfo[dombus] = *pciBusInfo[0];
1000
        }
1001
1002
        return entry;
1003
    }
1004
}
1005
1006
static PCITAG
1007
ia64linuxPciFindNext(void)
1008
{
1009
    struct dirent *entry;
1010
    char file[40];
1011
    static int bus, dev, func, domain;
1012
    PCITAG pciDeviceTag;
1013
    CARD32 devid;
1014
1015
    for (;;) {
1016
        if (devdir == NULL) {
1017
            entry = getnextbus(&domain, &bus);
1018
            if (!entry)
1019
                return PCI_NOT_FOUND;
1020
            snprintf(file, 40, "/proc/bus/pci/%s", entry->d_name);
1021
            devdir = opendir(file);
1022
            if (!devdir)
1023
                return PCI_NOT_FOUND;
1024
1025
        }
1026
1027
        entry = readdir(devdir);
1028
1029
        if (entry == NULL) {
1030
            closedir(devdir);
1031
            devdir = NULL;
1032
            continue;
1033
        }
1034
1035
        if (sscanf(entry->d_name, "%02x . %01x", &dev, &func) == 2) {
1036
            pciDeviceTag = PCI_MAKE_TAG(PCI_MAKE_BUS(domain, bus), dev, func);
1037
            devid = pciReadLong(pciDeviceTag, PCI_ID_REG);
1038
            if ((devid & pciDevidMask) == pciDevid)
1039
                /* Yes - Return it.  Otherwise, next device */
1040
                return pciDeviceTag;
1041
        }
1042
    }
1043
}
1044
#endif
(-)programs/Xserver/hw/xfree86/os-support/bus/xf86Pci.h.orig (+2 lines)
Lines 768-773 void pciSetBitsByte(PCITAG tag, in Link Here
768
ADDRESS	      pciBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr);
768
ADDRESS	      pciBusAddrToHostAddr(PCITAG tag, PciAddrType type, ADDRESS addr);
769
ADDRESS	      pciHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr);
769
ADDRESS	      pciHostAddrToBusAddr(PCITAG tag, PciAddrType type, ADDRESS addr);
770
PCITAG	      pciTag(int busnum, int devnum, int funcnum);
770
PCITAG	      pciTag(int busnum, int devnum, int funcnum);
771
void	      pciInfoFromTag(PCITAG tag, int *domainnum,
772
				int *busnum, int *devnum, int *funcnum);
771
int	      pciGetBaseSize(PCITAG tag, int indx, Bool destructive, Bool *min);
773
int	      pciGetBaseSize(PCITAG tag, int indx, Bool destructive, Bool *min);
772
CARD32	      pciCheckForBrokenBase(PCITAG tag,int basereg);
774
CARD32	      pciCheckForBrokenBase(PCITAG tag,int basereg);
773
pointer	      xf86MapPciMem(int ScreenNum, int Flags, PCITAG Tag,
775
pointer	      xf86MapPciMem(int ScreenNum, int Flags, PCITAG Tag,
(-)programs/Xserver/hw/xfree86/os-support/linux/lnx_pci.c.orig (-4 / +77 lines)
Lines 28-43 FILE *xf86OSLinuxPCIFile = NULL; Link Here
28
Bool
28
Bool
29
xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits)
29
xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits)
30
{
30
{
31
    FILE *file;
31
    char c[0x200];
32
    char c[0x200];
32
    char *res;
33
    char *res;
33
    unsigned int bus, devfn, dev, fn;
34
    unsigned int domain, bus, devfn, dev, fn;
34
    unsigned PCIADDR_TYPE size[7];
35
    unsigned PCIADDR_TYPE size[7];
35
    unsigned int num;
36
    unsigned int num;
36
    signed PCIADDR_TYPE Size;
37
    signed PCIADDR_TYPE Size;
38
    int resource;
39
    unsigned PCIADDR_TYPE begin, end;
37
40
38
    if (index > 7)
41
    if (index > 7)
39
	return FALSE;
42
	return FALSE;
40
    
43
44
    pciInfoFromTag(tag, &domain, &bus, &dev, &fn);
45
46
    sprintf(c, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/resource",
47
	    domain, bus, domain, bus, dev, fn);
48
    if (file = fopen(c, "r")) {
49
        for (resource=0; resource != index; resource++)
50
            fgets(c, 0x1ff, file);
51
        res = fgets(c, 0x1ff, file);
52
        num = sscanf(res, PCIADDR_FMT " " PCIADDR_FMT " " PCIADDR_IGNORE_FMT,
53
                     &begin, &end);
54
        if (num == 2) {
55
            Size = end - begin;
56
		    while (Size & ((PCIADDR_TYPE) 0x01)) {
57
                Size = Size >> ((PCIADDR_TYPE) 1);
58
                (*bits)++;
59
            }
60
            fclose(file);
61
            return TRUE;
62
        }
63
        fclose(file);
64
    }
65
41
    if (!xf86OSLinuxPCIFile && \
66
    if (!xf86OSLinuxPCIFile && \
42
        !(xf86OSLinuxPCIFile = fopen("/proc/bus/pci/devices","r")))
67
        !(xf86OSLinuxPCIFile = fopen("/proc/bus/pci/devices","r")))
43
	return FALSE;
68
	return FALSE;
Lines 99-111 xf86GetPciOffsetFromOS(PCITAG tag, int i Link Here
99
    FILE *file;
124
    FILE *file;
100
    char c[0x200];
125
    char c[0x200];
101
    char *res;
126
    char *res;
102
    unsigned int bus, devfn, dev, fn;
127
    unsigned int domain, bus, devfn, dev, fn;
103
    unsigned PCIADDR_TYPE offset[7];
128
    unsigned PCIADDR_TYPE offset[7];
104
    unsigned int num;
129
    unsigned int num;
130
    int resource;
105
131
106
    if (index > 7)
132
    if (index > 7)
107
        return FALSE;
133
        return FALSE;
108
134
135
    pciInfoFromTag(tag, &domain, &bus, &dev, &fn);
136
137
    sprintf(c, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/resource",
138
	    domain, bus, domain, bus, dev, fn);
139
    if (file = fopen(c, "r")) {
140
        for (resource=0; resource != index; resource++)
141
            fgets(c, 0x1ff, file);
142
        res = fgets(c, 0x1ff, file);
143
        num = sscanf(res, PCIADDR_FMT " " PCIADDR_IGNORE_FMT " " PCIADDR_IGNORE_FMT,
144
                     &offset[0]);
145
        if (num == 1) {
146
            *bases = offset[0];
147
            fclose(file);
148
            return TRUE;
149
        }
150
        fclose(file);
151
    }
152
109
    if (!(file = fopen("/proc/bus/pci/devices","r")))
153
    if (!(file = fopen("/proc/bus/pci/devices","r")))
110
        return FALSE;
154
        return FALSE;
111
    do {
155
    do {
Lines 159-169 xf86GetOSOffsetFromPCI(PCITAG tag, int s Link Here
159
    FILE *file;
203
    FILE *file;
160
    char c[0x200];
204
    char c[0x200];
161
    char *res;
205
    char *res;
162
    unsigned int bus, devfn, dev, fn;
206
    unsigned int domain, bus, devfn, dev, fn;
163
    unsigned PCIADDR_TYPE offset[7];
207
    unsigned PCIADDR_TYPE offset[7];
164
    unsigned PCIADDR_TYPE size[7];
208
    unsigned PCIADDR_TYPE size[7];
165
    unsigned int num;
209
    unsigned int num;
166
    unsigned int ndx;
210
    unsigned int ndx;
211
    unsigned PCIADDR_TYPE begin,end;
212
213
    pciInfoFromTag(tag, &domain, &bus, &dev, &fn);
214
215
    sprintf(c, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/resource",
216
	    domain, bus, domain, bus, dev, fn);
217
    if (file = fopen(c, "r")) {
218
        unsigned long savePtr;
219
        for (ndx=0; ndx < 7; ndx++) {
220
            res = fgets(c, 0x1ff, file);
221
            if (!res)
222
                break;
223
            num = sscanf(res, PCIADDR_FMT " " PCIADDR_FMT " " PCIADDR_IGNORE_FMT,
224
                         &begin, &end);
225
            if (num == 2) {
226
                if (ndx == 6)
227
                    savePtr = (0xFFFFFFF0) &
228
                        pciReadLong(tag, PCI_CMD_BIOS_REG);
229
                else /* this the ROM bar */
230
                    savePtr = (0xFFFFFFF0) &
231
                        pciReadLong(tag, PCI_CMD_BASE_REG + (0x4 * ndx));
232
                if (base >= savePtr && base <= (savePtr + (end - begin))) {
233
                    fclose(file);
234
                    return ( ~(0xFUL) & (begin + (base - savePtr)));
235
                }
236
            }
237
        }
238
        fclose(file);
239
    }
167
240
168
    if (!(file = fopen("/proc/bus/pci/devices","r")))
241
    if (!(file = fopen("/proc/bus/pci/devices","r")))
169
        return 0;
242
        return 0;

Return to bug 197572