2 * Copyright 1998 by Concurrent Computer Corporation
4 * Permission to use, copy, modify, distribute, and sell this software
5 * and its documentation for any purpose is hereby granted without fee,
6 * provided that the above copyright notice appear in all copies and that
7 * both that copyright notice and this permission notice appear in
8 * supporting documentation, and that the name of Concurrent Computer
9 * Corporation not be used in advertising or publicity pertaining to
10 * distribution of the software without specific, written prior
11 * permission. Concurrent Computer Corporation makes no representations
12 * about the suitability of this software for any purpose. It is
13 * provided "as is" without express or implied warranty.
15 * CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
16 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
17 * AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
18 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
19 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
24 * Copyright 1998 by Metro Link Incorporated
26 * Permission to use, copy, modify, distribute, and sell this software
27 * and its documentation for any purpose is hereby granted without fee,
28 * provided that the above copyright notice appear in all copies and that
29 * both that copyright notice and this permission notice appear in
30 * supporting documentation, and that the name of Metro Link
31 * Incorporated not be used in advertising or publicity pertaining to
32 * distribution of the software without specific, written prior
33 * permission. Metro Link Incorporated makes no representations
34 * about the suitability of this software for any purpose. It is
35 * provided "as is" without express or implied warranty.
37 * METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
38 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
39 * AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
40 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
41 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
46 * This file is derived in part from the original xf86_PCI.h that included
47 * following copyright message:
49 * Copyright 1995 by Robin Cutshaw <robin@XFree86.Org>
51 * Permission to use, copy, modify, distribute, and sell this software and its
52 * documentation for any purpose is hereby granted without fee, provided that
53 * the above copyright notice appear in all copies and that both that
54 * copyright notice and this permission notice appear in supporting
55 * documentation, and that the names of the above listed copyright holder(s)
56 * not be used in advertising or publicity pertaining to distribution of
57 * the software without specific, written prior permission. The above listed
58 * copyright holder(s) make(s) no representations about the suitability of this
59 * software for any purpose. It is provided "as is" without express or
62 * THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD
63 * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
64 * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
65 * LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
66 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
67 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
68 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
72 * Copyright (c) 1999-2003 by The XFree86 Project, Inc.
74 * Permission is hereby granted, free of charge, to any person obtaining a
75 * copy of this software and associated documentation files (the "Software"),
76 * to deal in the Software without restriction, including without limitation
77 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
78 * and/or sell copies of the Software, and to permit persons to whom the
79 * Software is furnished to do so, subject to the following conditions:
81 * The above copyright notice and this permission notice shall be included in
82 * all copies or substantial portions of the Software.
84 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
85 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
86 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
87 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
88 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
89 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
90 * OTHER DEALINGS IN THE SOFTWARE.
92 * Except as contained in this notice, the name of the copyright holder(s)
93 * and author(s) shall not be used in advertising or otherwise to promote
94 * the sale, use or other dealings in this Software without prior written
95 * authorization from the copyright holder(s) and author(s).
100 * This file has the private Pci definitions. The public ones are imported
101 * from xf86Pci.h. Drivers should not use this file.
103 #ifdef HAVE_XORG_CONFIG_H
104 #include <xorg-config.h>
110 #include <X11/Xarch.h>
111 #include <X11/Xfuncproto.h>
113 #include "xf86PciInfo.h"
118 #define MAX_PCI_DEVICES 128 /* Max number of devices accomodated */
120 #if defined(sun) && defined(SVR4) && defined(sparc)
121 # define MAX_PCI_BUSES 4096 /* Max number of PCI buses */
122 #elif (defined(__alpha__) || defined(__ia64__)) && defined (linux)
123 # define MAX_PCI_DOMAINS 512
124 # define PCI_DOM_MASK 0x01fful
125 # define MAX_PCI_BUSES (MAX_PCI_DOMAINS*256) /* 256 per domain */
127 # define MAX_PCI_BUSES 256 /* Max number of PCI buses */
130 #define DEVID(vendor, device) \
131 ((CARD32)((PCI_##device << 16) | PCI_##vendor))
134 # define PCI_DOM_MASK 0x0ffu
136 #define PCI_DOMBUS_MASK (((PCI_DOM_MASK) << 8) | 0x0ffu)
139 * "b" contains an optional domain number.
141 #define PCI_MAKE_TAG(b,d,f) ((((b) & (PCI_DOMBUS_MASK)) << 16) | \
142 (((d) & 0x00001fu) << 11) | \
143 (((f) & 0x000007u) << 8))
145 #define PCI_MAKE_BUS(d,b) ((((d) & (PCI_DOM_MASK)) << 8) | ((b) & 0xffu))
147 #define PCI_DOM_FROM_TAG(tag) (((tag) >> 24) & (PCI_DOM_MASK))
148 #define PCI_BUS_FROM_TAG(tag) (((tag) >> 16) & (PCI_DOMBUS_MASK))
149 #define PCI_DEV_FROM_TAG(tag) (((tag) & 0x0000f800u) >> 11)
150 #define PCI_FUNC_FROM_TAG(tag) (((tag) & 0x00000700u) >> 8)
152 #define PCI_DFN_FROM_TAG(tag) (((tag) & 0x0000ff00u) >> 8)
153 #define PCI_BDEV_FROM_TAG(tag) ((tag) & 0x00fff800u)
155 #define PCI_DOM_FROM_BUS(bus) (((bus) >> 8) & (PCI_DOM_MASK))
156 #define PCI_BUS_NO_DOMAIN(bus) ((bus) & 0xffu)
157 #define PCI_TAG_NO_DOMAIN(tag) ((tag) & 0x00ffff00u)
160 * Macros for bus numbers found in P2P headers.
162 #define PCI_PRIMARY_BUS_EXTRACT(x, tag) \
163 ((((x) & PCI_PRIMARY_BUS_MASK ) >> 0) | (PCI_DOM_FROM_TAG(tag) << 8))
164 #define PCI_SECONDARY_BUS_EXTRACT(x, tag) \
165 ((((x) & PCI_SECONDARY_BUS_MASK ) >> 8) | (PCI_DOM_FROM_TAG(tag) << 8))
166 #define PCI_SUBORDINATE_BUS_EXTRACT(x, tag) \
167 ((((x) & PCI_SUBORDINATE_BUS_MASK) >> 16) | (PCI_DOM_FROM_TAG(tag) << 8))
169 #define PCI_PRIMARY_BUS_INSERT(x, y) \
170 (((x) & ~PCI_PRIMARY_BUS_MASK ) | (((y) & 0xffu) << 0))
171 #define PCI_SECONDARY_BUS_INSERT(x, y) \
172 (((x) & ~PCI_SECONDARY_BUS_MASK ) | (((y) & 0xffu) << 8))
173 #define PCI_SUBORDINATE_BUS_INSERT(x, y) \
174 (((x) & ~PCI_SUBORDINATE_BUS_MASK) | (((y) & 0xffu) << 16))
176 /* Ditto for CardBus bridges */
177 #define PCI_CB_PRIMARY_BUS_EXTRACT(x, tag) \
178 PCI_PRIMARY_BUS_EXTRACT(x, tag)
179 #define PCI_CB_CARDBUS_BUS_EXTRACT(x, tag) \
180 PCI_SECONDARY_BUS_EXTRACT(x, tag)
181 #define PCI_CB_SUBORDINATE_BUS_EXTRACT(x, tag) \
182 PCI_SUBORDINATE_BUS_EXTRACT(x, tag)
184 #define PCI_CB_PRIMARY_BUS_INSERT(x, tag) \
185 PCI_PRIMARY_BUS_INSERT(x, tag)
186 #define PCI_CB_CARDBUS_BUS_INSERT(x, tag) \
187 PCI_SECONDARY_BUS_INSERT(x, tag)
188 #define PCI_CB_SUBORDINATE_BUS_INSERT(x, tag) \
189 PCI_SUBORDINATE_BUS_INSERT(x, tag)
191 #if X_BYTE_ORDER == X_BIG_ENDIAN
192 #define PCI_CPU(val) (((val >> 24) & 0x000000ff) | \
193 ((val >> 8) & 0x0000ff00) | \
194 ((val << 8) & 0x00ff0000) | \
195 ((val << 24) & 0xff000000))
196 #define PCI_CPU16(val) (((val >> 8) & 0x000000ff) | \
197 ((val << 8) & 0x0000ff00))
199 #define PCI_CPU(val) (val)
200 #define PCI_CPU16(val) (val)
204 * Debug Macros/Definitions
206 /* #define DEBUGPCI 2 */ /* Disable/enable trace in PCI code */
208 #if defined(DEBUGPCI)
210 # define PCITRACE(lvl,printfargs) \
211 if (lvl > xf86Verbose) { \
215 #else /* !defined(DEBUGPCI) */
217 # define PCITRACE(lvl,printfargs)
219 #endif /* !defined(DEBUGPCI) */
222 * PCI Config mechanism definitions
224 #define PCI_EN 0x80000000
226 #define PCI_CFGMECH1_ADDRESS_REG 0xCF8
227 #define PCI_CFGMECH1_DATA_REG 0xCFC
229 #define PCI_CFGMECH1_MAXDEV 32
232 * Select architecture specific PCI init function
234 #if defined(__alpha__)
236 # define ARCH_PCI_INIT axpPciInit
237 # define INCLUDE_XF86_MAP_PCI_MEM
238 # elif defined(__FreeBSD__) || defined(__OpenBSD__)
239 # define ARCH_PCI_INIT freebsdPciInit
240 # define INCLUDE_XF86_MAP_PCI_MEM
241 # define INCLUDE_XF86_NO_DOMAIN
242 # elif defined(__NetBSD__)
243 # define ARCH_PCI_INIT netbsdPciInit
244 # define INCLUDE_XF86_MAP_PCI_MEM
245 # define INCLUDE_XF86_NO_DOMAIN
247 #elif defined(__arm__)
249 # define ARCH_PCI_INIT linuxPciInit
250 # define INCLUDE_XF86_MAP_PCI_MEM
251 # define INCLUDE_XF86_NO_DOMAIN
253 #elif defined(__hppa__)
255 # define ARCH_PCI_INIT linuxPciInit
256 # define INCLUDE_XF86_MAP_PCI_MEM
257 # define INCLUDE_XF86_NO_DOMAIN
259 #elif defined(__ia64__)
261 # define ARCH_PCI_INIT ia64linuxPciInit
262 # define INCLUDE_XF86_MAP_PCI_MEM
263 # elif defined(FreeBSD)
264 # define ARCH_PCI_INIT freebsdPciInit
265 # define INCLUDE_XF86_MAP_PCI_MEM
266 # define INCLUDE_XF86_NO_DOMAIN
268 # define XF86SCANPCI_WRAPPER ia64ScanPCIWrapper
269 #elif defined(__i386__) || defined(i386)
270 # define ARCH_PCI_INIT ix86PciInit
271 # define INCLUDE_XF86_MAP_PCI_MEM
272 # define INCLUDE_XF86_NO_DOMAIN
274 # define ARCH_PCI_OS_INIT linuxPciInit
276 #elif defined(__mc68000__)
278 # define ARCH_PCI_INIT linuxPciInit
279 # define INCLUDE_XF86_MAP_PCI_MEM
280 # define INCLUDE_XF86_NO_DOMAIN
282 #elif defined(__mips__)
284 # define ARCH_PCI_INIT linuxPciInit
285 # define INCLUDE_XF86_MAP_PCI_MEM
286 # define INCLUDE_XF86_NO_DOMAIN
288 #elif defined(__powerpc__) || defined(__powerpc64__)
290 # define ARCH_PCI_INIT linuxPciInit
291 # define INCLUDE_XF86_MAP_PCI_MEM
292 # define INCLUDE_XF86_NO_DOMAIN /* Needs kernel work to remove */
293 # elif defined(__FreeBSD__) || defined(__OpenBSD__)
294 # define ARCH_PCI_INIT freebsdPciInit
295 # define INCLUDE_XF86_MAP_PCI_MEM
296 # define INCLUDE_XF86_NO_DOMAIN
297 # elif defined(__NetBSD__)
298 # define ARCH_PCI_INIT netbsdPciInit
299 # define INCLUDE_XF86_MAP_PCI_MEM
300 # define INCLUDE_XF86_NO_DOMAIN
302 # define ARCH_PCI_INIT ppcPciInit
303 # define INCLUDE_XF86_MAP_PCI_MEM
304 # define INCLUDE_XF86_NO_DOMAIN
306 #elif defined(__s390__)
308 # define ARCH_PCI_INIT linuxPciInit
309 # define INCLUDE_XF86_MAP_PCI_MEM
310 # define INCLUDE_XF86_NO_DOMAIN
312 #elif defined(__sh__)
314 # define ARCH_PCI_INIT linuxPciInit
315 # define INCLUDE_XF86_MAP_PCI_MEM
316 # define INCLUDE_XF86_NO_DOMAIN
318 #elif defined(__sparc__) || defined(sparc)
320 # define ARCH_PCI_INIT linuxPciInit
321 # define INCLUDE_XF86_MAP_PCI_MEM
323 # define ARCH_PCI_INIT sparcPciInit
324 # define INCLUDE_XF86_MAP_PCI_MEM
325 # elif (defined(__OpenBSD__) || defined(__FreeBSD__)) && defined(__sparc64__)
326 # define ARCH_PCI_INIT freebsdPciInit
327 # define INCLUDE_XF86_MAP_PCI_MEM
328 # define INCLUDE_XF86_NO_DOMAIN
330 # if !defined(__FreeBSD__) && !defined(linux)
331 # define ARCH_PCI_PCI_BRIDGE sparcPciPciBridge
333 #elif defined(__amd64__) || defined(__amd64)
334 # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
335 # define ARCH_PCI_INIT freebsdPciInit
337 # define ARCH_PCI_INIT ix86PciInit
339 # define INCLUDE_XF86_MAP_PCI_MEM
340 # define INCLUDE_XF86_NO_DOMAIN
342 # define ARCH_PCI_OS_INIT linuxPciInit
346 #ifndef ARCH_PCI_INIT
347 #error No PCI support available for this architecture/OS combination
350 extern void ARCH_PCI_INIT(void);
351 #if defined(ARCH_PCI_OS_INIT)
352 extern void ARCH_PCI_OS_INIT(void);
355 #if defined(ARCH_PCI_PCI_BRIDGE)
356 extern void ARCH_PCI_PCI_BRIDGE(pciConfigPtr pPCI
);
359 #if defined(XF86SCANPCI_WRAPPER)
364 extern void XF86SCANPCI_WRAPPER(scanpciWrapperOpt flags
);
368 * Table of functions used to access a specific PCI bus domain
369 * (e.g. a primary PCI bus and all of its secondaries)
371 typedef struct pci_bus_funcs
{
372 CARD32 (*pciReadLong
)(PCITAG
, int);
373 void (*pciWriteLong
)(PCITAG
, int, CARD32
);
374 void (*pciSetBitsLong
)(PCITAG
, int, CARD32
, CARD32
);
375 ADDRESS (*pciAddrHostToBus
)(PCITAG
, PciAddrType
, ADDRESS
);
376 ADDRESS (*pciAddrBusToHost
)(PCITAG
, PciAddrType
, ADDRESS
);
378 * The next three are optional. If NULL, the corresponding function is
379 * to be performed generically.
381 CARD16 (*pciControlBridge
)(int, CARD16
, CARD16
);
382 void (*pciGetBridgeBuses
)(int, int *, int *, int *);
383 /* Use pointer's to avoid #include recursion */
384 void (*pciGetBridgeResources
)(int, pointer
*, pointer
*, pointer
*);
386 /* These are optional and will be implemented using read long
388 CARD8 (*pciReadByte
)(PCITAG
, int);
389 void (*pciWriteByte
)(PCITAG
, int, CARD8
);
390 CARD16 (*pciReadWord
)(PCITAG
, int);
391 void (*pciWriteWord
)(PCITAG
, int, CARD16
);
393 } pciBusFuncs_t
, *pciBusFuncs_p
;
396 * pciBusInfo_t - One structure per defined PCI bus
398 typedef struct pci_bus_info
{
399 unsigned char configMech
; /* PCI config type to use */
400 unsigned char numDevices
; /* Range of valid devnums */
401 unsigned char secondary
; /* Boolean: bus is a secondary */
402 int primary_bus
; /* Parent bus */
403 pciBusFuncs_p funcs
; /* PCI access functions */
404 void *pciBusPriv
; /* Implementation private data */
405 pciConfigPtr bridge
; /* bridge that opens this bus */
408 #define HOST_NO_BUS ((pciBusInfo_t *)(-1))
410 /* configMech values */
411 #define PCI_CFG_MECH_UNKNOWN 0 /* Not yet known */
412 #define PCI_CFG_MECH_1 1 /* Most machines */
413 #define PCI_CFG_MECH_2 2 /* Older PC's */
414 #define PCI_CFG_MECH_OTHER 3 /* Something else */
416 /* Generic PCI service functions and helpers */
417 PCITAG
pciGenFindFirst(void);
418 PCITAG
pciGenFindNext(void);
419 CARD32
pciCfgMech1Read(PCITAG tag
, int offset
);
420 void pciCfgMech1Write(PCITAG tag
, int offset
, CARD32 val
);
421 void pciCfgMech1SetBits(PCITAG tag
, int offset
, CARD32 mask
,
423 CARD32
pciByteSwap(CARD32
);
424 Bool
pciMfDev(int, int);
425 ADDRESS
pciAddrNOOP(PCITAG tag
, PciAddrType type
, ADDRESS
);
427 extern void pciSetOSBIOSPtr(int (*bios_fn
)(PCITAG Tag
, int basereg
, unsigned char * buf
, int len
));
428 extern PCITAG (*pciFindFirstFP
)(void);
429 extern PCITAG (*pciFindNextFP
)(void);
431 extern CARD32 pciDevid
;
432 extern CARD32 pciDevidMask
;
434 extern int pciMaxBusNum
;
436 extern int pciBusNum
;
437 extern int pciDevNum
;
438 extern int pciFuncNum
;
439 extern PCITAG pciDeviceTag
;
441 extern int xf86MaxPciDevs
;
443 extern pciBusInfo_t
*pciBusInfo
[];