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 (-25 / +174 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 492-498 xf86GetPciDomain(PCITAG Tag) Link Here
492
    pPCI = xf86GetPciHostConfigFromTag(Tag);
538
    pPCI = xf86GetPciHostConfigFromTag(Tag);
493
539
494
    if (pPCI && (result = PCI_DOM_FROM_BUS(pPCI->busnum)))
540
    if (pPCI && (result = PCI_DOM_FROM_BUS(pPCI->busnum)))
495
	return result;
541
	return result + 1;
496
542
497
    if (!pPCI || pPCI->fakeDevice)
543
    if (!pPCI || pPCI->fakeDevice)
498
	return 1;		/* Domain 0 is reserved */
544
	return 1;		/* Domain 0 is reserved */
Lines 725-731 xf86ReadDomainMemory(PCITAG Tag, ADDRESS Link Here
725
    struct stat st;
771
    struct stat st;
726
772
727
    dom  = PCI_DOM_FROM_TAG(Tag);
773
    dom  = PCI_DOM_FROM_TAG(Tag);
728
    bus  = PCI_BUS_FROM_TAG(Tag);
774
    bus  = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
729
    dev  = PCI_DEV_FROM_TAG(Tag);
775
    dev  = PCI_DEV_FROM_TAG(Tag);
730
    func = PCI_FUNC_FROM_TAG(Tag);
776
    func = PCI_FUNC_FROM_TAG(Tag);
731
    sprintf(file, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/rom",
777
    sprintf(file, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/rom",
Lines 906-912 int linuxPciHandleBIOS(PCITAG Tag, int b Link Here
906
  int sofar = 0;
952
  int sofar = 0;
907
953
908
  dom  = PCI_DOM_FROM_TAG(Tag);
954
  dom  = PCI_DOM_FROM_TAG(Tag);
909
  bus  = PCI_BUS_FROM_TAG(Tag);
955
  bus  = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
910
  dev  = PCI_DEV_FROM_TAG(Tag);
956
  dev  = PCI_DEV_FROM_TAG(Tag);
911
  func = PCI_FUNC_FROM_TAG(Tag);
957
  func = PCI_FUNC_FROM_TAG(Tag);
912
  sprintf(file, "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/rom",
958
  sprintf(file, "/sys/bus/pci/devices/%04x:%02x:%02x.%1x/rom",
Lines 936-938 int linuxPciHandleBIOS(PCITAG Tag, int b Link Here
936
  }
982
  }
937
  return 0;
983
  return 0;
938
}
984
}
985
986
#ifdef __ia64__
987
static PCITAG ia64linuxPciFindFirst(void);
988
static PCITAG ia64linuxPciFindNext(void);
989
990
void   
991
ia64linuxPciInit()
992
{
993
    struct stat st;
994
995
    linuxPciInit();
996
	   
997
    if (!stat("/proc/sgi_sn/licenseID", &st) && pciNumBuses) {
998
       /* Be a little paranoid here and only use this code for Altix systems.
999
	* It is generic, so it should work on any system, but depends on
1000
	* /proc/bus/pci entries for each domain/bus combination. Altix is
1001
	* guaranteed a recent enough kernel to have them.
1002
	*/
1003
       pciFindFirstFP = ia64linuxPciFindFirst;
1004
       pciFindNextFP  = ia64linuxPciFindNext;
1005
    }
1006
}
1007
1008
static DIR *busdomdir;
1009
static DIR *devdir;
1010
	       
1011
static PCITAG
1012
ia64linuxPciFindFirst(void)
1013
{   
1014
       busdomdir = opendir("/proc/bus/pci");
1015
       devdir = NULL;
1016
1017
       return ia64linuxPciFindNext();
1018
}   
1019
1020
static struct dirent *getnextbus(int *domain, int *bus)
1021
{
1022
    struct dirent *entry;
1023
    int dombus;
1024
1025
    for (;;) {
1026
	entry = readdir(busdomdir);
1027
	if (entry == NULL) {
1028
	    *domain = 0;
1029
	    *bus = 0;
1030
	    closedir(busdomdir);
1031
	    return NULL;
1032
	}
1033
	if (sscanf(entry->d_name, "%04x:%02x", domain, bus) != 2)
1034
	    continue;
1035
	dombus = PCI_MAKE_BUS(*domain, *bus);
1036
1037
	if (pciNumBuses <= dombus)
1038
	    pciNumBuses = dombus + 1;
1039
	if (!pciBusInfo[dombus]) {
1040
	    pciBusInfo[dombus] = xnfalloc(sizeof(pciBusInfo_t));
1041
	    *pciBusInfo[dombus] = *pciBusInfo[0];
1042
	}
1043
1044
	return entry;
1045
    }
1046
}
1047
1048
static PCITAG
1049
ia64linuxPciFindNext(void)
1050
{
1051
    struct dirent *entry;
1052
    char file[40];
1053
    static int bus, dev, func, domain;
1054
    PCITAG pciDeviceTag;
1055
    CARD32 devid;
1056
1057
    for (;;) {
1058
	if (devdir == NULL) {
1059
	    entry = getnextbus(&domain, &bus);
1060
	    if (!entry)
1061
		return PCI_NOT_FOUND;
1062
	    snprintf(file, 40, "/proc/bus/pci/%s", entry->d_name);
1063
	    devdir = opendir(file);
1064
	    if (!devdir)
1065
		return PCI_NOT_FOUND;
1066
1067
	}
1068
1069
	entry = readdir(devdir);
1070
1071
	if (entry == NULL) {
1072
	    closedir(devdir);
1073
	    devdir = NULL;
1074
	    continue;
1075
	}
1076
1077
	if (sscanf(entry->d_name, "%02x . %01x", &dev, &func) == 2) {
1078
	    pciDeviceTag = PCI_MAKE_TAG(PCI_MAKE_BUS(domain, bus), dev, func);
1079
	    devid = pciReadLong(pciDeviceTag, PCI_ID_REG);
1080
	    if ((devid & pciDevidMask) == pciDevid)
1081
		/* Yes - Return it.  Otherwise, next device */
1082
		return pciDeviceTag;
1083
	}
1084
    }
1085
}
1086
#endif
1087
(-)../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