1
/* $XFree86: xc/programs/Xserver/hw/xfree86/os-support/bus/Pci.h,v 1.21 2001/11/01 23:35:33 dawes Exp $ */
3
* Copyright 1998 by Concurrent Computer Corporation
5
* Permission to use, copy, modify, distribute, and sell this software
6
* and its documentation for any purpose is hereby granted without fee,
7
* provided that the above copyright notice appear in all copies and that
8
* both that copyright notice and this permission notice appear in
9
* supporting documentation, and that the name of Concurrent Computer
10
* Corporation not be used in advertising or publicity pertaining to
11
* distribution of the software without specific, written prior
12
* permission. Concurrent Computer Corporation makes no representations
13
* about the suitability of this software for any purpose. It is
14
* provided "as is" without express or implied warranty.
16
* CONCURRENT COMPUTER CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD
17
* TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18
* AND FITNESS, IN NO EVENT SHALL CONCURRENT COMPUTER CORPORATION BE
19
* LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
20
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
22
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
25
* Copyright 1998 by Metro Link Incorporated
27
* Permission to use, copy, modify, distribute, and sell this software
28
* and its documentation for any purpose is hereby granted without fee,
29
* provided that the above copyright notice appear in all copies and that
30
* both that copyright notice and this permission notice appear in
31
* supporting documentation, and that the name of Metro Link
32
* Incorporated not be used in advertising or publicity pertaining to
33
* distribution of the software without specific, written prior
34
* permission. Metro Link Incorporated makes no representations
35
* about the suitability of this software for any purpose. It is
36
* provided "as is" without express or implied warranty.
38
* METRO LINK INCORPORATED DISCLAIMS ALL WARRANTIES WITH REGARD
39
* TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
40
* AND FITNESS, IN NO EVENT SHALL METRO LINK INCORPORATED BE
41
* LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
42
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43
* WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44
* ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
47
* This file is derived in part from the original xf86_PCI.h that included
48
* following copyright message:
50
* Copyright 1995 by Robin Cutshaw <robin@XFree86.Org>
52
* Permission to use, copy, modify, distribute, and sell this software and its
53
* documentation for any purpose is hereby granted without fee, provided that
54
* the above copyright notice appear in all copies and that both that
55
* copyright notice and this permission notice appear in supporting
56
* documentation, and that the names of the above listed copyright holder(s)
57
* not be used in advertising or publicity pertaining to distribution of
58
* the software without specific, written prior permission. The above listed
59
* copyright holder(s) make(s) no representations about the suitability of this
60
* software for any purpose. It is provided "as is" without express or
63
* THE ABOVE LISTED COPYRIGHT HOLDER(S) DISCLAIM(S) ALL WARRANTIES WITH REGARD
64
* TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
65
* AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE
66
* LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
67
* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
68
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
69
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
74
* This file has the private Pci definitions. The public ones are imported
75
* from xf86Pci.h. Drivers should not use this file.
80
#include "Xfuncproto.h"
86
#define MAX_PCI_DEVICES 64 /* Max number of devices accomodated */
88
#if defined(i386) || defined(__i386__) || defined(__i386)
89
/* Q&D stopgap to deal with mainboards whose PCI space is smaller */
90
#define MAX_PCI_BUSES 128 /* Max number of PCI buses */
92
#define MAX_PCI_BUSES 256 /* Max number of PCI buses */
95
#define PCI_NOT_FOUND 0xffffffff
100
#define PCI_MAKE_TAG(b,d,f) ((((b) & 0xff) << 16) | \
101
(((d) & 0x1f) << 11) | \
104
#define PCI_BUS_FROM_TAG(tag) (((tag) & 0x00ff0000) >> 16)
105
#define PCI_DEV_FROM_TAG(tag) (((tag) & 0x0000f800) >> 11)
106
#define PCI_FUNC_FROM_TAG(tag) (((tag) & 0x00000700) >> 8)
108
#define PCI_DFN_FROM_TAG(tag) (((tag) & 0x0000ff00) >> 8)
111
* Debug Macros/Definitions
113
/* #define DEBUGPCI 2 */ /* Disable/enable trace in PCI code */
115
#if defined(DEBUGPCI)
117
# define PCITRACE(lvl,printfargs) \
118
if (lvl > xf86Verbose) { \
122
#else /* !defined(DEBUGPCI) */
124
# define PCITRACE(lvl,printfargs)
126
#endif /* !defined(DEBUGPCI) */
129
* PCI Config mechanism definitions
131
#define PCI_EN 0x80000000
133
#define PCI_CFGMECH1_ADDRESS_REG 0xCF8
134
#define PCI_CFGMECH1_DATA_REG 0xCFC
136
#define PCI_CFGMECH1_MAXDEV 32
138
#define PCI_CFGMECH1_TYPE1_CFGADDR(b,d,f,o) (PCI_EN | PCI_MAKE_TAG(b,d,f) | ((o) & 0xff) | 1)
139
#define PCI_CFGMECH1_TYPE0_CFGADDR(d,f,o) (PCI_EN | PCI_MAKE_TAG(0,d,f) | ((o) & 0xff))
142
* Select architecture specific PCI init function
144
#if (defined(__powerpc__) || defined(__mips__) || defined(__sh__) || defined(__mc68000__) || defined(__arm__) || defined(__s390__) || defined(__hppa__)) && defined(linux)
145
# define ARCH_PCI_INIT linuxPciInit
146
# define INCLUDE_XF86_MAP_PCI_MEM
147
#elif defined(__powerpc__) && defined(__OpenBSD__)
148
# define ARCH_PCI_INIT freebsdPciInit
149
# define INCLUDE_XF86_MAP_PCI_MEM
150
#elif defined(__powerpc__)
151
# define ARCH_PCI_INIT ppcPciInit
152
# if !defined(PowerMAX_OS)
153
# define INCLUDE_XF86_MAP_PCI_MEM
155
#elif defined(__sparc__) && (defined(linux) || defined(sun))
156
# define ARCH_PCI_INIT sparcPciInit
157
# define INCLUDE_XF86_MAP_PCI_MEM
158
#elif defined(__alpha__) && defined(linux)
159
# define ARCH_PCI_INIT axpPciInit
160
# define INCLUDE_XF86_MAP_PCI_MEM
161
#elif defined(__i386__) && defined(linux)
162
# define ARCH_PCI_INIT ix86PciInit
163
# define ARCH_PCI_OS_INIT linuxPciInit
164
# define INCLUDE_XF86_MAP_PCI_MEM
165
#elif defined(__ia64__) && defined(linux)
166
# define ARCH_PCI_INIT linuxPciInit
167
# define INCLUDE_XF86_MAP_PCI_MEM
168
#elif defined(__alpha__) && defined(__FreeBSD__)
169
# define ARCH_PCI_INIT freebsdPciInit
170
# define INCLUDE_XF86_MAP_PCI_MEM
172
# define ARCH_PCI_INIT ix86PciInit
173
# define INCLUDE_XF86_MAP_PCI_MEM
175
extern void ARCH_PCI_INIT(void);
176
#if defined(ARCH_PCI_OS_INIT)
177
extern void ARCH_PCI_OS_INIT(void);
181
* Table of functions used to access a specific PCI bus domain
182
* (e.g. a primary PCI bus and all of its secondaries)
184
typedef struct pci_bus_funcs {
185
CARD32 (*pciReadLong)(PCITAG, int);
186
void (*pciWriteLong)(PCITAG, int, CARD32);
187
void (*pciSetBitsLong)(PCITAG, int, CARD32, CARD32);
188
ADDRESS (*pciAddrHostToBus)(PCITAG, PciAddrType, ADDRESS);
189
ADDRESS (*pciAddrBusToHost)(PCITAG, PciAddrType, ADDRESS);
193
* pciBusInfo_t - One structure per defined PCI bus
195
typedef struct pci_bus_info {
196
unsigned char configMech; /* PCI config type to use */
197
unsigned char numDevices; /* Range of valid devnums */
198
unsigned char secondary; /* Boolean: bus is a secondary */
199
unsigned char primary_bus; /* Top level (primary) parent */
200
unsigned long ppc_io_base; /* PowerPC I/O spc membase */
201
unsigned long ppc_io_size; /* PowerPC I/O spc size */
202
pciBusFuncs_t funcs; /* PCI access functions */
203
void *pciBusPriv; /* Implementation private data */
206
/* configMech values */
207
#define PCI_CFG_MECH_UNKNOWN 0 /* Not yet known */
208
#define PCI_CFG_MECH_1 1 /* Most machines */
209
#define PCI_CFG_MECH_2 2 /* Older PC's */
210
#define PCI_CFG_MECH_OTHER 3 /* Something else */
212
/* Generic PCI service functions and helpers */
213
PCITAG pciGenFindFirst(void);
214
PCITAG pciGenFindNext(void);
215
CARD32 pciCfgMech1Read(PCITAG tag, int offset);
216
void pciCfgMech1Write(PCITAG tag, int offset, CARD32 val);
217
void pciCfgMech1SetBits(PCITAG tag, int offset, CARD32 mask,
219
CARD32 pciByteSwap(CARD32);
220
Bool pciMfDev(int, int);
221
CARD32 pciReadLongNULL(PCITAG tag, int offset);
222
void pciWriteLongNULL(PCITAG tag, int offset, CARD32 val);
223
void pciSetBitsLongNULL(PCITAG tag, int offset, CARD32 mask,
225
ADDRESS pciAddrNOOP(PCITAG tag, PciAddrType type, ADDRESS);
227
extern PCITAG (*pciFindFirstFP)(void);
228
extern PCITAG (*pciFindNextFP)(void);
230
extern CARD32 pciDevid;
231
extern CARD32 pciDevidMask;
233
extern int pciBusNum;
234
extern int pciDevNum;
235
extern int pciFuncNum;
236
extern PCITAG pciDeviceTag;
238
extern pciBusInfo_t *pciBusInfo[];
240
extern pciBusFuncs_t pciNOOPFuncs;