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

(-)Pci.c (+10 lines)
Lines 597-602 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
{
(-)Pci.h (-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
(-)altixPCI.c (-3 / +6 lines)
Lines 41-53 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 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
(-)linuxPci.c (-22 / +148 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 130-163 Link Here
130
static int
131
static int
131
linuxPciOpenFile(PCITAG tag, Bool write)
132
linuxPciOpenFile(PCITAG tag, Bool write)
132
{
133
{
133
	static int	lbus,ldev,lfunc,fd = -1,is_write = 0;
134
	static int	ldomain, lbus,ldev,lfunc,fd = -1,is_write = 0;
134
	int		bus, dev, func;
135
	static Bool	domain_support = TRUE;
136
	int		domain, bus, dev, func;
135
	char		file[32];
137
	char		file[32];
136
	struct stat	ignored;
138
	struct stat	ignored;
137
139
138
	bus  = PCI_BUS_FROM_TAG(tag);
140
	domain = PCI_DOM_FROM_TAG(tag);
141
	bus  = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(tag));
139
	dev  = PCI_DEV_FROM_TAG(tag);
142
	dev  = PCI_DEV_FROM_TAG(tag);
140
	func = PCI_FUNC_FROM_TAG(tag);
143
	func = PCI_FUNC_FROM_TAG(tag);
141
	if (fd == -1 || (write && (!is_write))
144
142
	    || bus != lbus || dev != ldev || func != lfunc) {
145
	if (!domain_support && domain > 0)
143
		if (fd != -1)
146
	    return -1;
147
148
	if (fd == -1 || (write && (!is_write)) || bus != lbus
149
		|| dev != ldev || func != lfunc || domain != ldomain) {
150
151
		if (fd != -1) {
144
			close(fd);
152
			close(fd);
153
			fd = -1;
154
		}
145
		if (bus < 256) {
155
		if (bus < 256) {
146
		        sprintf(file,"/proc/bus/pci/%02x",bus);
156
		        sprintf(file, "/proc/bus/pci/%04x:%02x", domain, bus);
147
			if (stat(file, &ignored) < 0)
157
			if (stat(file, &ignored) < 0) {
148
				sprintf(file, "/proc/bus/pci/0000:%02x/%02x.%1x",
158
				domain_support = FALSE;
149
					bus, dev, func);
159
				if (domain == 0) 
150
			else
160
					sprintf(file, "/proc/bus/pci/%02x/%02x.%1x",
151
				sprintf(file, "/proc/bus/pci/%02x/%02x.%1x",
161
						bus, dev, func);
152
					bus, dev, func);
162
				else goto bail;
163
			} else
164
				sprintf(file, "/proc/bus/pci/%04x:%02x/%02x.%1x",
165
					domain, bus, dev, func);
153
		} else {
166
		} else {
154
		        sprintf(file,"/proc/bus/pci/%04x",bus);
167
		        sprintf(file, "/proc/bus/pci/%04x:%02x", domain, bus);
155
			if (stat(file, &ignored) < 0)
168
			if (stat(file, &ignored) < 0) {
156
				sprintf(file, "/proc/bus/pci/0000:%04x/%02x.%1x",
169
			    domain_support = FALSE;
157
					bus, dev, func);
170
			    if (domain == 0)
158
			else
171
					sprintf(file, "/proc/bus/pci/%04x/%02x.%1x",
159
				sprintf(file, "/proc/bus/pci/%04x/%02x.%1x",
172
						bus, dev, func);
160
					bus, dev, func);
173
			    else goto bail;
174
			} else
175
				sprintf(file, "/proc/bus/pci/%04x:%02x/%02x.%1x",
176
					domain, bus, dev, func);
161
		}
177
		}
162
		if (write) {
178
		if (write) {
163
		    fd = open(file,O_RDWR);
179
		    fd = open(file,O_RDWR);
Lines 171-177 Link Here
171
			    fd = open(file,O_RDONLY);
187
			    fd = open(file,O_RDONLY);
172
			    is_write = FALSE;
188
			    is_write = FALSE;
173
		}
189
		}
174
		
190
	bail:
191
		ldomain = domain;
175
		lbus  = bus;
192
		lbus  = bus;
176
		ldev  = dev;
193
		ldev  = dev;
177
		lfunc = func;
194
		lfunc = func;
Lines 724-730 Link Here
724
    struct stat st;
741
    struct stat st;
725
742
726
    dom  = PCI_DOM_FROM_TAG(Tag);
743
    dom  = PCI_DOM_FROM_TAG(Tag);
727
    bus  = PCI_BUS_FROM_TAG(Tag);
744
    bus  = PCI_BUS_NO_DOMAIN(PCI_BUS_FROM_TAG(Tag));
728
    dev  = PCI_DEV_FROM_TAG(Tag);
745
    dev  = PCI_DEV_FROM_TAG(Tag);
729
    func = PCI_FUNC_FROM_TAG(Tag);
746
    func = PCI_FUNC_FROM_TAG(Tag);
730
    sprintf(file, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/rom",
747
    sprintf(file, "/sys/devices/pci%04x:%02x/%04x:%02x:%02x.%1x/rom",
Lines 892-894 Link Here
892
}
909
}
893
910
894
#endif /* !INCLUDE_XF86_NO_DOMAIN */
911
#endif /* !INCLUDE_XF86_NO_DOMAIN */
912
913
#ifdef __ia64__
914
static PCITAG ia64linuxPciFindFirst(void);
915
static PCITAG ia64linuxPciFindNext(void);
916
917
918
void
919
ia64linuxPciInit()
920
{
921
    struct stat st;
922
    /* Be a little paranoid here and only use this code for Altix systems.
923
     * It is generic, so it should work on any system, but depends on
924
     * /proc/bus/pci entries for each domain/bus combination. Altix is
925
     * guaranteed a recent enough kernel to have them.
926
     */
927
    if (stat("/proc/sgi_sn/licenseID", &st)) {
928
	return linuxPciInit();
929
    }
930
    if ((xf86Info.pciFlags == PCIForceNone) ||
931
        (-1 == stat("/proc/bus/pci", &st))) {
932
             /* when using this as default for all linux architectures,
933
		   we'll need a fallback for 2.0 kernels here */
934
            return;
935
    }
936
    pciNumBuses    = 1;
937
    pciBusInfo[0]  = &linuxPci0;
938
    pciFindFirstFP = ia64linuxPciFindFirst;
939
    pciFindNextFP  = ia64linuxPciFindNext;
940
}
941
942
static DIR *busdomdir;
943
static DIR *devdir;
944
945
static PCITAG
946
ia64linuxPciFindFirst(void)
947
{
948
	busdomdir = opendir("/proc/bus/pci");
949
	devdir = NULL;
950
951
	return ia64linuxPciFindNext();
952
}
953
954
static struct dirent *getnextbus(int *domain, int *bus)
955
{
956
    struct dirent *entry;
957
    int dombus;
958
959
    for (;;) {
960
        entry = readdir(busdomdir);
961
        if (entry == NULL) {
962
            *domain = 0;
963
            *bus = 0;
964
            closedir(busdomdir);
965
            return NULL;
966
        }
967
        if (sscanf(entry->d_name, "%04x:%02x", domain, bus) != 2)
968
            continue;
969
        dombus = PCI_MAKE_BUS(*domain, *bus);
970
971
        if (pciNumBuses <= dombus)
972
            pciNumBuses = dombus + 1;
973
        if (!pciBusInfo[dombus]) {
974
            pciBusInfo[dombus] = xnfalloc(sizeof(pciBusInfo_t));
975
            *pciBusInfo[dombus] = *pciBusInfo[0];
976
        }
977
978
        return entry;
979
    }
980
}
981
982
static PCITAG
983
ia64linuxPciFindNext(void)
984
{
985
    struct dirent *entry;
986
    char file[40];
987
    static int bus, dev, func, domain;
988
    PCITAG pciDeviceTag;
989
    CARD32 devid;
990
991
    for (;;) {
992
        if (devdir == NULL) {
993
            entry = getnextbus(&domain, &bus);
994
            if (!entry)
995
                return PCI_NOT_FOUND;
996
            snprintf(file, 40, "/proc/bus/pci/%s", entry->d_name);
997
            devdir = opendir(file);
998
            if (!devdir)
999
                return PCI_NOT_FOUND;
1000
1001
        }
1002
1003
        entry = readdir(devdir);
1004
1005
        if (entry == NULL) {
1006
            closedir(devdir);
1007
            devdir = NULL;
1008
            continue;
1009
        }
1010
1011
        if (sscanf(entry->d_name, "%02x . %01x", &dev, &func) == 2) {
1012
            pciDeviceTag = PCI_MAKE_TAG(PCI_MAKE_BUS(domain, bus), dev, func);
1013
            devid = pciReadLong(pciDeviceTag, PCI_ID_REG);
1014
            if ((devid & pciDevidMask) == pciDevid)
1015
                /* Yes - Return it.  Otherwise, next device */
1016
                return pciDeviceTag;
1017
        }
1018
    }
1019
}
1020
#endif
(-)xf86Pci.h (+2 lines)
Lines 768-773 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,

Return to bug 132308