Subversion Repositories Kolibri OS

Rev

Rev 5270 | Rev 6102 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1964 serge 1
/*
2
 *	pci.h
3
 *
4
 *	PCI defines and function prototypes
5
 *	Copyright 1994, Drew Eckhardt
6
 *	Copyright 1997--1999 Martin Mares 
7
 *
8
 *	For more information, please consult the following manuals (look at
9
 *	http://www.pcisig.com/ for how to get them):
10
 *
11
 *	PCI BIOS Specification
12
 *	PCI Local Bus Specification
13
 *	PCI to PCI Bridge Specification
14
 *	PCI System Design Guide
15
 */
1970 serge 16
#ifndef LINUX_PCI_H
17
#define LINUX_PCI_H
18
 
3031 serge 19
#include 
5270 serge 20
#include 
21
#include 
22
#include 
23
#include 
24
 
2161 serge 25
#include 	/* The pci register defines */
5270 serge 26
#include 
1408 serge 27
 
6082 serge 28
#include 
1628 serge 29
 
6082 serge 30
#if 0
31
struct device
32
{
33
    struct device   *parent;
34
    void            *driver_data;
35
};
36
 
37
#endif
38
 
2161 serge 39
#define PCI_CFG_SPACE_SIZE      256
40
#define PCI_CFG_SPACE_EXP_SIZE  4096
1970 serge 41
 
2161 serge 42
 
1408 serge 43
#define PCI_ANY_ID (~0)
44
 
45
 
46
#define PCI_CLASS_NOT_DEFINED           0x0000
47
#define PCI_CLASS_NOT_DEFINED_VGA       0x0001
48
 
49
#define PCI_BASE_CLASS_STORAGE          0x01
50
#define PCI_CLASS_STORAGE_SCSI          0x0100
51
#define PCI_CLASS_STORAGE_IDE           0x0101
52
#define PCI_CLASS_STORAGE_FLOPPY        0x0102
53
#define PCI_CLASS_STORAGE_IPI           0x0103
54
#define PCI_CLASS_STORAGE_RAID          0x0104
55
#define PCI_CLASS_STORAGE_SATA          0x0106
56
#define PCI_CLASS_STORAGE_SATA_AHCI     0x010601
57
#define PCI_CLASS_STORAGE_SAS           0x0107
58
#define PCI_CLASS_STORAGE_OTHER         0x0180
59
 
60
#define PCI_BASE_CLASS_NETWORK          0x02
61
#define PCI_CLASS_NETWORK_ETHERNET      0x0200
62
#define PCI_CLASS_NETWORK_TOKEN_RING    0x0201
63
#define PCI_CLASS_NETWORK_FDDI          0x0202
64
#define PCI_CLASS_NETWORK_ATM           0x0203
65
#define PCI_CLASS_NETWORK_OTHER         0x0280
66
 
67
#define PCI_BASE_CLASS_DISPLAY          0x03
68
#define PCI_CLASS_DISPLAY_VGA           0x0300
69
#define PCI_CLASS_DISPLAY_XGA           0x0301
70
#define PCI_CLASS_DISPLAY_3D            0x0302
71
#define PCI_CLASS_DISPLAY_OTHER         0x0380
72
 
73
#define PCI_BASE_CLASS_MULTIMEDIA       0x04
74
#define PCI_CLASS_MULTIMEDIA_VIDEO      0x0400
75
#define PCI_CLASS_MULTIMEDIA_AUDIO      0x0401
76
#define PCI_CLASS_MULTIMEDIA_PHONE      0x0402
77
#define PCI_CLASS_MULTIMEDIA_OTHER      0x0480
78
 
79
#define PCI_BASE_CLASS_MEMORY           0x05
80
#define PCI_CLASS_MEMORY_RAM            0x0500
81
#define PCI_CLASS_MEMORY_FLASH          0x0501
82
#define PCI_CLASS_MEMORY_OTHER          0x0580
83
 
84
#define PCI_BASE_CLASS_BRIDGE           0x06
85
#define PCI_CLASS_BRIDGE_HOST           0x0600
86
#define PCI_CLASS_BRIDGE_ISA            0x0601
87
#define PCI_CLASS_BRIDGE_EISA           0x0602
88
#define PCI_CLASS_BRIDGE_MC             0x0603
89
#define PCI_CLASS_BRIDGE_PCI            0x0604
90
#define PCI_CLASS_BRIDGE_PCMCIA         0x0605
91
#define PCI_CLASS_BRIDGE_NUBUS          0x0606
92
#define PCI_CLASS_BRIDGE_CARDBUS        0x0607
93
#define PCI_CLASS_BRIDGE_RACEWAY        0x0608
94
#define PCI_CLASS_BRIDGE_OTHER          0x0680
95
 
96
#define PCI_BASE_CLASS_COMMUNICATION    0x07
97
#define PCI_CLASS_COMMUNICATION_SERIAL  0x0700
98
#define PCI_CLASS_COMMUNICATION_PARALLEL 0x0701
99
#define PCI_CLASS_COMMUNICATION_MULTISERIAL 0x0702
100
#define PCI_CLASS_COMMUNICATION_MODEM   0x0703
101
#define PCI_CLASS_COMMUNICATION_OTHER   0x0780
102
 
103
#define PCI_BASE_CLASS_SYSTEM           0x08
104
#define PCI_CLASS_SYSTEM_PIC            0x0800
105
#define PCI_CLASS_SYSTEM_PIC_IOAPIC     0x080010
106
#define PCI_CLASS_SYSTEM_PIC_IOXAPIC    0x080020
107
#define PCI_CLASS_SYSTEM_DMA            0x0801
108
#define PCI_CLASS_SYSTEM_TIMER          0x0802
109
#define PCI_CLASS_SYSTEM_RTC            0x0803
110
#define PCI_CLASS_SYSTEM_PCI_HOTPLUG    0x0804
111
#define PCI_CLASS_SYSTEM_SDHCI          0x0805
112
#define PCI_CLASS_SYSTEM_OTHER          0x0880
113
 
114
#define PCI_BASE_CLASS_INPUT            0x09
115
#define PCI_CLASS_INPUT_KEYBOARD        0x0900
116
#define PCI_CLASS_INPUT_PEN             0x0901
117
#define PCI_CLASS_INPUT_MOUSE           0x0902
118
#define PCI_CLASS_INPUT_SCANNER         0x0903
119
#define PCI_CLASS_INPUT_GAMEPORT        0x0904
120
#define PCI_CLASS_INPUT_OTHER           0x0980
121
 
122
#define PCI_BASE_CLASS_DOCKING          0x0a
123
#define PCI_CLASS_DOCKING_GENERIC       0x0a00
124
#define PCI_CLASS_DOCKING_OTHER         0x0a80
125
 
126
#define PCI_BASE_CLASS_PROCESSOR        0x0b
127
#define PCI_CLASS_PROCESSOR_386         0x0b00
128
#define PCI_CLASS_PROCESSOR_486         0x0b01
129
#define PCI_CLASS_PROCESSOR_PENTIUM     0x0b02
130
#define PCI_CLASS_PROCESSOR_ALPHA       0x0b10
131
#define PCI_CLASS_PROCESSOR_POWERPC     0x0b20
132
#define PCI_CLASS_PROCESSOR_MIPS        0x0b30
133
#define PCI_CLASS_PROCESSOR_CO          0x0b40
134
 
135
#define PCI_BASE_CLASS_SERIAL           0x0c
136
#define PCI_CLASS_SERIAL_FIREWIRE       0x0c00
137
#define PCI_CLASS_SERIAL_FIREWIRE_OHCI  0x0c0010
138
#define PCI_CLASS_SERIAL_ACCESS         0x0c01
139
#define PCI_CLASS_SERIAL_SSA            0x0c02
140
#define PCI_CLASS_SERIAL_USB            0x0c03
141
#define PCI_CLASS_SERIAL_USB_UHCI       0x0c0300
142
#define PCI_CLASS_SERIAL_USB_OHCI       0x0c0310
143
#define PCI_CLASS_SERIAL_USB_EHCI       0x0c0320
144
#define PCI_CLASS_SERIAL_FIBER          0x0c04
145
#define PCI_CLASS_SERIAL_SMBUS          0x0c05
146
 
147
#define PCI_BASE_CLASS_WIRELESS                 0x0d
148
#define PCI_CLASS_WIRELESS_RF_CONTROLLER        0x0d10
149
#define PCI_CLASS_WIRELESS_WHCI                 0x0d1010
150
 
151
#define PCI_BASE_CLASS_INTELLIGENT      0x0e
152
#define PCI_CLASS_INTELLIGENT_I2O       0x0e00
153
 
154
#define PCI_BASE_CLASS_SATELLITE        0x0f
155
#define PCI_CLASS_SATELLITE_TV          0x0f00
156
#define PCI_CLASS_SATELLITE_AUDIO       0x0f01
157
#define PCI_CLASS_SATELLITE_VOICE       0x0f03
158
#define PCI_CLASS_SATELLITE_DATA        0x0f04
159
 
160
#define PCI_BASE_CLASS_CRYPT            0x10
161
#define PCI_CLASS_CRYPT_NETWORK         0x1000
162
#define PCI_CLASS_CRYPT_ENTERTAINMENT   0x1001
163
#define PCI_CLASS_CRYPT_OTHER           0x1080
164
 
165
#define PCI_BASE_CLASS_SIGNAL_PROCESSING 0x11
166
#define PCI_CLASS_SP_DPIO               0x1100
167
#define PCI_CLASS_SP_OTHER              0x1180
168
 
169
#define PCI_CLASS_OTHERS                0xff
170
 
171
 
172
 
1964 serge 173
 
174
 
1408 serge 175
#define PCI_MAP_IS_IO(b)  ((b) & PCI_MAP_IO)
176
#define PCI_MAP_IS_MEM(b)   (!PCI_MAP_IS_IO(b))
177
 
178
#define PCI_MAP_IS64BITMEM(b)   \
179
    (((b) & PCI_MAP_MEMORY_TYPE_MASK) == PCI_MAP_MEMORY_TYPE_64BIT)
180
 
181
#define PCIGETMEMORY(b)   ((b) & PCI_MAP_MEMORY_ADDRESS_MASK)
182
#define PCIGETMEMORY64HIGH(b)   (*((CARD32*)&b + 1))
183
#define PCIGETMEMORY64(b)   \
184
    (PCIGETMEMORY(b) | ((CARD64)PCIGETMEMORY64HIGH(b) << 32))
185
 
186
#define PCI_MAP_IO_ADDRESS_MASK       0xfffffffc
187
 
188
#define PCIGETIO(b)     ((b) & PCI_MAP_IO_ADDRESS_MASK)
189
 
190
#define PCI_MAP_ROM_DECODE_ENABLE     0x00000001
191
#define PCI_MAP_ROM_ADDRESS_MASK      0xfffff800
192
 
193
#define PCIGETROM(b)        ((b) & PCI_MAP_ROM_ADDRESS_MASK)
194
 
195
 
196
#ifndef PCI_DOM_MASK
197
# define PCI_DOM_MASK 0x0ffu
198
#endif
199
#define PCI_DOMBUS_MASK (((PCI_DOM_MASK) << 8) | 0x0ffu)
200
 
201
#define PCI_MAKE_TAG(b,d,f)  ((((b) & (PCI_DOMBUS_MASK)) << 16) | \
202
                  (((d) & 0x00001fu) << 11) | \
203
                  (((f) & 0x000007u) << 8))
204
 
205
#define PCI_BUS_FROM_TAG(tag)  (((tag) >> 16) & (PCI_DOMBUS_MASK))
206
#define PCI_DEV_FROM_TAG(tag)  (((tag) & 0x0000f800u) >> 11)
207
#define PCI_FUNC_FROM_TAG(tag) (((tag) & 0x00000700u) >> 8)
208
#define PCI_DFN_FROM_TAG(tag)  (((tag) & 0x0000ff00u) >> 8)
209
 
2161 serge 210
/*
211
 * The PCI interface treats multi-function devices as independent
212
 * devices.  The slot/function address of each device is encoded
213
 * in a single byte as follows:
214
 *
215
 *	7:3 = slot
216
 *	2:0 = function
6082 serge 217
 *
218
 * PCI_DEVFN(), PCI_SLOT(), and PCI_FUNC() are defined in uapi/linux/pci.h.
219
 * In the interest of not exposing interfaces to user-space unnecessarily,
220
 * the following kernel-only defines are being added here.
2161 serge 221
 */
1408 serge 222
#define PCI_DEVFN(slot, func)  ((((slot) & 0x1f) << 3) | ((func) & 0x07))
223
#define PCI_SLOT(devfn)        (((devfn) >> 3) & 0x1f)
224
#define PCI_FUNC(devfn)        ((devfn) & 0x07)
225
 
226
 
227
 
228
typedef unsigned int PCITAG;
229
 
230
extern inline PCITAG
231
pciTag(int busnum, int devnum, int funcnum)
232
{
233
    return(PCI_MAKE_TAG(busnum,devnum,funcnum));
234
}
235
 
2161 serge 236
/* pci_slot represents a physical slot */
237
struct pci_slot {
238
	struct pci_bus *bus;		/* The bus this slot is on */
239
	struct list_head list;		/* node in list of slots on this bus */
240
	struct hotplug_slot *hotplug;	/* Hotplug info (migrate over time) */
241
	unsigned char number;		/* PCI_SLOT(pci_dev->devfn) */
242
};
1627 serge 243
 
2161 serge 244
/* File state for mmap()s on /proc/bus/pci/X/Y */
245
enum pci_mmap_state {
246
	pci_mmap_io,
247
	pci_mmap_mem
1964 serge 248
};
249
 
2161 serge 250
/* This defines the direction arg to the DMA mapping routines. */
251
#define PCI_DMA_BIDIRECTIONAL	0
252
#define PCI_DMA_TODEVICE	1
253
#define PCI_DMA_FROMDEVICE	2
254
#define PCI_DMA_NONE		3
255
 
1408 serge 256
/*
2161 serge 257
 *  For PCI devices, the region numbers are assigned this way:
1627 serge 258
 */
2161 serge 259
enum {
260
    /* #0-5: standard PCI resources */
261
    PCI_STD_RESOURCES,
262
    PCI_STD_RESOURCE_END = 5,
1627 serge 263
 
2161 serge 264
    /* #6: expansion ROM resource */
265
    PCI_ROM_RESOURCE,
1627 serge 266
 
2161 serge 267
    /* device specific resources */
268
#ifdef CONFIG_PCI_IOV
269
    PCI_IOV_RESOURCES,
270
    PCI_IOV_RESOURCE_END = PCI_IOV_RESOURCES + PCI_SRIOV_NUM_BARS - 1,
271
#endif
1627 serge 272
 
2161 serge 273
    /* resources assigned to buses behind the bridge */
274
#define PCI_BRIDGE_RESOURCE_NUM 4
1627 serge 275
 
2161 serge 276
    PCI_BRIDGE_RESOURCES,
277
    PCI_BRIDGE_RESOURCE_END = PCI_BRIDGE_RESOURCES +
278
                  PCI_BRIDGE_RESOURCE_NUM - 1,
1627 serge 279
 
2161 serge 280
    /* total resources associated with a PCI device */
281
    PCI_NUM_RESOURCES,
1627 serge 282
 
2161 serge 283
    /* preserve this for compatibility */
3747 Serge 284
	DEVICE_COUNT_RESOURCE = PCI_NUM_RESOURCES,
2161 serge 285
};
1627 serge 286
 
2161 serge 287
typedef int __bitwise pci_power_t;
1627 serge 288
 
2161 serge 289
#define PCI_D0		((pci_power_t __force) 0)
290
#define PCI_D1		((pci_power_t __force) 1)
291
#define PCI_D2		((pci_power_t __force) 2)
292
#define PCI_D3hot	((pci_power_t __force) 3)
293
#define PCI_D3cold	((pci_power_t __force) 4)
294
#define PCI_UNKNOWN	((pci_power_t __force) 5)
295
#define PCI_POWER_ERROR	((pci_power_t __force) -1)
3031 serge 296
 
297
/* Remember to update this when the list above changes! */
298
extern const char *pci_power_names[];
299
 
300
static inline const char *pci_power_name(pci_power_t state)
301
{
302
	return pci_power_names[1 + (int) state];
303
}
304
 
305
#define PCI_PM_D2_DELAY		200
306
#define PCI_PM_D3_WAIT		10
307
#define PCI_PM_D3COLD_WAIT	100
308
#define PCI_PM_BUS_WAIT		50
309
 
2161 serge 310
/** The pci_channel state describes connectivity between the CPU and
311
 *  the pci device.  If some PCI bus between here and the pci device
312
 *  has crashed or locked up, this info is reflected here.
313
 */
314
typedef unsigned int __bitwise pci_channel_state_t;
1964 serge 315
 
2161 serge 316
enum pci_channel_state {
317
	/* I/O channel is in normal state */
318
	pci_channel_io_normal = (__force pci_channel_state_t) 1,
1964 serge 319
 
2161 serge 320
	/* I/O to channel is blocked */
321
	pci_channel_io_frozen = (__force pci_channel_state_t) 2,
1964 serge 322
 
2161 serge 323
	/* PCI card is dead */
324
	pci_channel_io_perm_failure = (__force pci_channel_state_t) 3,
325
};
326
typedef unsigned short __bitwise pci_bus_flags_t;
327
enum pci_bus_flags {
328
    PCI_BUS_FLAGS_NO_MSI   = (__force pci_bus_flags_t) 1,
329
    PCI_BUS_FLAGS_NO_MMRBC = (__force pci_bus_flags_t) 2,
330
};
1964 serge 331
 
5270 serge 332
/* These values come from the PCI Express Spec */
333
enum pcie_link_width {
334
	PCIE_LNK_WIDTH_RESRV	= 0x00,
335
	PCIE_LNK_X1		= 0x01,
336
	PCIE_LNK_X2		= 0x02,
337
	PCIE_LNK_X4		= 0x04,
338
	PCIE_LNK_X8		= 0x08,
339
	PCIE_LNK_X12		= 0x0C,
340
	PCIE_LNK_X16		= 0x10,
341
	PCIE_LNK_X32		= 0x20,
342
	PCIE_LNK_WIDTH_UNKNOWN  = 0xFF,
343
};
344
 
2161 serge 345
/* Based on the PCI Hotplug Spec, but some values are made up by us */
346
enum pci_bus_speed {
347
	PCI_SPEED_33MHz			= 0x00,
348
	PCI_SPEED_66MHz			= 0x01,
349
	PCI_SPEED_66MHz_PCIX		= 0x02,
350
	PCI_SPEED_100MHz_PCIX		= 0x03,
351
	PCI_SPEED_133MHz_PCIX		= 0x04,
352
	PCI_SPEED_66MHz_PCIX_ECC	= 0x05,
353
	PCI_SPEED_100MHz_PCIX_ECC	= 0x06,
354
	PCI_SPEED_133MHz_PCIX_ECC	= 0x07,
355
	PCI_SPEED_66MHz_PCIX_266	= 0x09,
356
	PCI_SPEED_100MHz_PCIX_266	= 0x0a,
357
	PCI_SPEED_133MHz_PCIX_266	= 0x0b,
358
	AGP_UNKNOWN			= 0x0c,
359
	AGP_1X				= 0x0d,
360
	AGP_2X				= 0x0e,
361
	AGP_4X				= 0x0f,
362
	AGP_8X				= 0x10,
363
	PCI_SPEED_66MHz_PCIX_533	= 0x11,
364
	PCI_SPEED_100MHz_PCIX_533	= 0x12,
365
	PCI_SPEED_133MHz_PCIX_533	= 0x13,
366
	PCIE_SPEED_2_5GT		= 0x14,
367
	PCIE_SPEED_5_0GT		= 0x15,
368
	PCIE_SPEED_8_0GT		= 0x16,
369
	PCI_SPEED_UNKNOWN		= 0xff,
370
};
1408 serge 371
 
5270 serge 372
struct pci_cap_saved_data {
373
	u16 cap_nr;
374
	bool cap_extended;
375
	unsigned int size;
376
	u32 data[0];
377
};
378
 
379
struct pci_cap_saved_state {
380
	struct hlist_node next;
381
	struct pci_cap_saved_data cap;
382
};
383
 
384
struct pcie_link_state;
385
struct pci_vpd;
386
struct pci_sriov;
387
struct pci_ats;
388
 
1408 serge 389
/*
390
 * The pci_dev structure is used to describe PCI devices.
391
 */
392
struct pci_dev {
2161 serge 393
    struct list_head bus_list;  /* node in per-bus list */
394
    struct pci_bus  *bus;       /* bus this device is on */
395
    struct pci_bus  *subordinate;   /* bus this device bridges to */
1408 serge 396
 
2161 serge 397
	void		*sysdata;	/* hook for sys-specific extension */
1408 serge 398
//    struct proc_dir_entry *procent; /* device entry in /proc/bus/pci */
2161 serge 399
	struct pci_slot	*slot;		/* Physical slot this device is in */
5270 serge 400
	u32           busnr;
2161 serge 401
	unsigned int	devfn;		/* encoded device & function index */
402
	unsigned short	vendor;
403
	unsigned short	device;
404
	unsigned short	subsystem_vendor;
405
	unsigned short	subsystem_device;
406
	unsigned int	class;		/* 3 bytes: (base,sub,prog-if) */
407
	u8		revision;	/* PCI revision, low byte of class word */
408
	u8		hdr_type;	/* PCI header type (`multi' flag masked out) */
409
	u8		pcie_cap;	/* PCI-E capability offset */
3031 serge 410
	u8		pcie_mpss:3;	/* PCI-E Max Payload Size Supported */
2161 serge 411
	u8		rom_base_reg;	/* which config register controls the ROM */
412
	u8		pin;  		/* which interrupt pin this device uses */
3031 serge 413
	u16		pcie_flags_reg;	/* cached PCI-E Capabilities Register */
1408 serge 414
 
415
 //   struct pci_driver *driver;  /* which driver has allocated this device */
5270 serge 416
    u64     dma_mask;   /* Mask of the bits of bus address this
1408 serge 417
                       device implements.  Normally this is
418
                       0xffffffff.  You only need to change
419
                       this if your device has broken DMA
420
                       or supports 64-bit transfers.  */
421
 
422
 //   struct device_dma_parameters dma_parms;
423
 
2161 serge 424
	pci_power_t     current_state;  /* Current operating state. In ACPI-speak,
425
					   this is D0-D3, D0 being fully functional,
426
					   and D3 being off. */
3747 Serge 427
	u8		pm_cap;		/* PM capability offset */
1408 serge 428
    unsigned int    pme_support:5;  /* Bitmask of states from which PME#
429
                       can be generated */
2161 serge 430
	unsigned int	pme_interrupt:1;
3031 serge 431
	unsigned int	pme_poll:1;	/* Poll device's PME status bit */
1408 serge 432
    unsigned int    d1_support:1;   /* Low power state D1 is supported */
433
    unsigned int    d2_support:1;   /* Low power state D2 is supported */
3031 serge 434
	unsigned int	no_d1d2:1;	/* D1 and D2 are forbidden */
435
	unsigned int	no_d3cold:1;	/* D3cold is forbidden */
436
	unsigned int	d3cold_allowed:1;	/* D3cold is allowed by user */
2161 serge 437
	unsigned int	mmio_always_on:1;	/* disallow turning off io/mem
438
						   decoding during bar sizing */
439
	unsigned int	wakeup_prepared:1;
3031 serge 440
	unsigned int	runtime_d3cold:1;	/* whether go through runtime
441
						   D3cold, not set for devices
442
						   powered on/off by the
443
						   corresponding bridge */
6082 serge 444
	unsigned int	ignore_hotplug:1;	/* Ignore hotplug events */
2161 serge 445
	unsigned int	d3_delay;	/* D3->D0 transition time in ms */
3031 serge 446
	unsigned int	d3cold_delay;	/* D3cold->D0 transition time in ms */
1408 serge 447
 
3031 serge 448
#ifdef CONFIG_PCIEASPM
6082 serge 449
	struct pcie_link_state	*link_state;	/* ASPM link state */
3031 serge 450
#endif
2161 serge 451
 
452
	pci_channel_state_t error_state;	/* current connectivity state */
1430 serge 453
    struct  device  dev;        /* Generic device interface */
3747 Serge 454
 
2161 serge 455
    int     cfg_size;   /* Size of configuration space */
1408 serge 456
 
457
    /*
458
     * Instead of touching interrupt line and base address registers
459
     * directly, use the values stored here. They might be different!
460
     */
461
    unsigned int    irq;
462
    struct resource resource[DEVICE_COUNT_RESOURCE]; /* I/O and memory regions + expansion ROMs */
463
 
6082 serge 464
	bool match_driver;		/* Skip attaching driver */
1408 serge 465
    /* These fields are used by common fixups */
6082 serge 466
	unsigned int	transparent:1;	/* Subtractive decode PCI bridge */
1408 serge 467
    unsigned int    multifunction:1;/* Part of multi-function device */
468
    /* keep track of device state */
469
    unsigned int    is_added:1;
470
    unsigned int    is_busmaster:1; /* device is busmaster */
471
    unsigned int    no_msi:1;   /* device may not use msi */
6082 serge 472
	unsigned int	no_64bit_msi:1; /* device may only use 32-bit MSIs */
3031 serge 473
	unsigned int	block_cfg_access:1;	/* config space access is blocked */
1408 serge 474
    unsigned int    broken_parity_status:1; /* Device generates false positive parity */
475
    unsigned int    irq_reroute_variant:2;  /* device needs IRQ rerouting variant */
476
    unsigned int    msi_enabled:1;
477
    unsigned int    msix_enabled:1;
2161 serge 478
	unsigned int	ari_enabled:1;	/* ARI forwarding */
1408 serge 479
    unsigned int    is_managed:1;
2161 serge 480
	unsigned int    needs_freset:1; /* Dev requires fundamental reset */
1408 serge 481
    unsigned int    state_saved:1;
482
    unsigned int    is_physfn:1;
483
    unsigned int    is_virtfn:1;
2161 serge 484
	unsigned int	reset_fn:1;
485
	unsigned int    is_hotplug_bridge:1;
3031 serge 486
	unsigned int    __aer_firmware_first_valid:1;
487
	unsigned int	__aer_firmware_first:1;
488
	unsigned int	broken_intx_masking:1;
489
	unsigned int	io_window_1k:1;	/* Intel P2P bridge 1K I/O windows */
490
//	pci_dev_flags_t dev_flags;
491
	atomic_t	enable_cnt;	/* pci_enable_device has been called */
1408 serge 492
 
3031 serge 493
 
494
 
1408 serge 495
};
496
 
497
#define pci_resource_start(dev, bar)    ((dev)->resource[(bar)].start)
498
#define pci_resource_end(dev, bar)      ((dev)->resource[(bar)].end)
499
#define pci_resource_flags(dev, bar)    ((dev)->resource[(bar)].flags)
500
#define pci_resource_len(dev,bar) \
501
        ((pci_resource_start((dev), (bar)) == 0 &&      \
502
          pci_resource_end((dev), (bar)) ==             \
503
          pci_resource_start((dev), (bar))) ? 0 :       \
504
                                                        \
505
         (pci_resource_end((dev), (bar)) -              \
506
          pci_resource_start((dev), (bar)) + 1))
507
 
5056 serge 508
#define PCI_REGION_FLAG_MASK	0x0fU	/* These bits of resource flags tell us the PCI region flags */
1408 serge 509
 
2161 serge 510
struct pci_bus {
511
    struct list_head node;      /* node in list of buses */
512
    struct pci_bus  *parent;    /* parent bus this bridge is on */
513
    struct list_head children;  /* list of child buses */
514
    struct list_head devices;   /* list of devices on this bus */
515
    struct pci_dev  *self;      /* bridge device as seen by parent */
516
    struct list_head slots;     /* list of slots on this bus */
517
    struct resource *resource[PCI_BRIDGE_RESOURCE_NUM];
518
    struct list_head resources; /* address space routed to this bus */
3031 serge 519
	struct resource busn_res;	/* bus numbers routed to this bus */
1964 serge 520
 
2161 serge 521
    struct pci_ops  *ops;       /* configuration access functions */
522
    void        *sysdata;   /* hook for sys-specific extension */
523
    struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
1964 serge 524
 
2161 serge 525
    unsigned char   number;     /* bus number */
526
    unsigned char   primary;    /* number of primary bridge */
527
    unsigned char   max_bus_speed;  /* enum pci_bus_speed */
528
    unsigned char   cur_bus_speed;  /* enum pci_bus_speed */
529
 
530
    char        name[48];
531
 
532
    unsigned short  bridge_ctl; /* manage NO_ISA/FBB/et al behaviors */
5056 serge 533
	pci_bus_flags_t bus_flags;	/* inherited by child buses */
2161 serge 534
    struct device       *bridge;
535
    struct device       dev;
536
    struct bin_attribute    *legacy_io; /* legacy I/O for this bus */
537
    struct bin_attribute    *legacy_mem; /* legacy mem */
538
    unsigned int        is_added:1;
539
};
540
 
541
 
542
#define pci_bus_b(n)    list_entry(n, struct pci_bus, node)
543
#define to_pci_bus(n)   container_of(n, struct pci_bus, dev)
544
#define pci_dev_b(n)    list_entry(n, struct pci_dev, bus_list)
545
#define to_pci_dev(n) container_of(n, struct pci_dev, dev)
546
#define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)
547
 
548
 
549
/* Low-level architecture-dependent routines */
550
 
551
struct pci_sysdata {
552
        int             domain;         /* PCI domain */
553
        int             node;           /* NUMA node */
554
};
555
 
556
 
557
#define pci_bus_b(n)    list_entry(n, struct pci_bus, node)
558
#define to_pci_bus(n)   container_of(n, struct pci_bus, dev)
559
 
560
/*
5056 serge 561
 * Returns true if the PCI bus is root (behind host-PCI bridge),
2161 serge 562
 * false otherwise
5056 serge 563
 *
564
 * Some code assumes that "bus->self == NULL" means that bus is a root bus.
565
 * This is incorrect because "virtual" buses added for SR-IOV (via
566
 * virtfn_add_bus()) have "bus->self == NULL" but are not root buses.
2161 serge 567
 */
568
static inline bool pci_is_root_bus(struct pci_bus *pbus)
569
{
570
    return !(pbus->parent);
571
}
572
 
573
struct pci_bus *
574
pci_find_next_bus(const struct pci_bus *from);
575
 
576
 
577
  /*
578
 * Error values that may be returned by PCI functions.
579
 */
580
#define PCIBIOS_SUCCESSFUL      0x00
581
#define PCIBIOS_FUNC_NOT_SUPPORTED  0x81
582
#define PCIBIOS_BAD_VENDOR_ID       0x83
583
#define PCIBIOS_DEVICE_NOT_FOUND    0x86
584
#define PCIBIOS_BAD_REGISTER_NUMBER 0x87
585
#define PCIBIOS_SET_FAILED      0x88
586
#define PCIBIOS_BUFFER_TOO_SMALL    0x89
587
 
5056 serge 588
/*
589
 * Translate above to generic errno for passing back through non-PCI code.
590
 */
591
static inline int pcibios_err_to_errno(int err)
592
{
593
	if (err <= PCIBIOS_SUCCESSFUL)
594
		return err; /* Assume already errno */
595
 
596
	switch (err) {
597
	case PCIBIOS_FUNC_NOT_SUPPORTED:
598
		return -ENOENT;
599
	case PCIBIOS_BAD_VENDOR_ID:
5270 serge 600
		return -ENOTTY;
5056 serge 601
	case PCIBIOS_DEVICE_NOT_FOUND:
602
		return -ENODEV;
603
	case PCIBIOS_BAD_REGISTER_NUMBER:
604
		return -EFAULT;
605
	case PCIBIOS_SET_FAILED:
606
		return -EIO;
607
	case PCIBIOS_BUFFER_TOO_SMALL:
608
		return -ENOSPC;
609
	}
610
 
5270 serge 611
	return -ERANGE;
5056 serge 612
}
613
 
2161 serge 614
/* Low-level architecture-dependent routines */
615
 
616
struct pci_ops {
617
    int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val);
618
    int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
619
};
620
 
5270 serge 621
/*
622
 * ACPI needs to be able to access PCI config space before we've done a
623
 * PCI bus scan and created pci_bus structures.
624
 */
625
int raw_pci_read(unsigned int domain, unsigned int bus, unsigned int devfn,
626
		 int reg, int len, u32 *val);
627
int raw_pci_write(unsigned int domain, unsigned int bus, unsigned int devfn,
628
		  int reg, int len, u32 val);
2161 serge 629
 
5270 serge 630
struct pci_bus_region {
631
	dma_addr_t start;
632
	dma_addr_t end;
633
};
634
 
2161 serge 635
enum pci_bar_type {
636
    pci_bar_unknown,    /* Standard PCI BAR probe */
637
    pci_bar_io,     /* An io port BAR */
638
    pci_bar_mem32,      /* A 32-bit memory BAR */
639
    pci_bar_mem64,      /* A 64-bit memory BAR */
640
};
641
 
642
/*
643
 * PCI domain support.  Sometimes called PCI segment (eg by ACPI),
644
 * a PCI domain is defined to be a set of PCI busses which share
645
 * configuration space.
646
 */
647
#ifdef CONFIG_PCI_DOMAINS
648
extern int pci_domains_supported;
649
#else
650
enum { pci_domains_supported = 0 };
651
static inline int pci_domain_nr(struct pci_bus *bus)
652
{
653
    return 0;
654
}
655
 
656
static inline int pci_proc_domain(struct pci_bus *bus)
657
{
658
    return 0;
659
}
660
#endif /* CONFIG_PCI_DOMAINS */
661
 
662
/**
663
 * pci_pcie_cap - get the saved PCIe capability offset
664
 * @dev: PCI device
665
 *
666
 * PCIe capability offset is calculated at PCI device initialization
667
 * time and saved in the data structure. This function returns saved
668
 * PCIe capability offset. Using this instead of pci_find_capability()
669
 * reduces unnecessary search in the PCI configuration space. If you
670
 * need to calculate PCIe capability offset from raw device for some
671
 * reasons, please use pci_find_capability() instead.
672
 */
673
static inline int pci_pcie_cap(struct pci_dev *dev)
674
{
675
    return dev->pcie_cap;
676
}
677
 
678
/**
679
 * pci_is_pcie - check if the PCI device is PCI Express capable
680
 * @dev: PCI device
681
 *
5056 serge 682
 * Returns: true if the PCI device is PCI Express capable, false otherwise.
2161 serge 683
 */
684
static inline bool pci_is_pcie(struct pci_dev *dev)
685
{
686
    return !!pci_pcie_cap(dev);
687
}
688
 
3031 serge 689
/**
690
 * pci_pcie_type - get the PCIe device/port type
691
 * @dev: PCI device
692
 */
693
static inline int pci_pcie_type(const struct pci_dev *dev)
694
{
695
	return (dev->pcie_flags_reg & PCI_EXP_FLAGS_TYPE) >> 4;
696
}
697
 
698
 
2161 serge 699
static inline int pci_iov_init(struct pci_dev *dev)
700
{
701
    return -ENODEV;
702
}
703
static inline void pci_iov_release(struct pci_dev *dev)
704
 
705
{}
706
 
707
static inline int pci_iov_resource_bar(struct pci_dev *dev, int resno,
708
                       enum pci_bar_type *type)
709
{
710
    return 0;
711
}
712
static inline void pci_restore_iov_state(struct pci_dev *dev)
713
{
714
}
715
static inline int pci_iov_bus_range(struct pci_bus *bus)
716
{
717
    return 0;
718
}
719
 
720
static inline int pci_enable_ats(struct pci_dev *dev, int ps)
721
{
722
    return -ENODEV;
723
}
724
static inline void pci_disable_ats(struct pci_dev *dev)
725
{
726
}
727
static inline int pci_ats_queue_depth(struct pci_dev *dev)
728
{
729
    return -ENODEV;
730
}
731
static inline int pci_ats_enabled(struct pci_dev *dev)
732
{
733
    return 0;
734
}
735
 
736
int pci_setup_device(struct pci_dev *dev);
737
int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
738
         struct resource *res, unsigned int reg);
739
int pci_resource_bar(struct pci_dev *dev, int resno,
740
         enum pci_bar_type *type);
741
int pci_bus_add_child(struct pci_bus *bus);
742
unsigned int pci_scan_child_bus(struct pci_bus *bus);
743
 
744
 
1408 serge 745
typedef struct
746
{
747
    struct list_head    link;
748
    struct pci_dev      pci_dev;
749
}pci_dev_t;
750
 
751
int enum_pci_devices(void);
752
 
2967 Serge 753
const struct pci_device_id*
754
find_pci_device(pci_dev_t* pdev, const struct pci_device_id *idlist);
1408 serge 755
 
756
#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
757
 
3391 Serge 758
#define pci_set_dma_mask(a, b)               0
759
#define pci_set_consistent_dma_mask(a, b)
1408 serge 760
 
2967 Serge 761
struct pci_dev *pci_get_bus_and_slot(unsigned int bus, unsigned int devfn);
762
struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from);
1408 serge 763
 
2967 Serge 764
void __iomem *pci_map_rom(struct pci_dev *pdev, size_t *size);
765
 
1964 serge 766
#define pci_name(x) "radeon"
1631 serge 767
 
5056 serge 768
static inline dma_addr_t pci_bus_address(struct pci_dev *pdev, int bar)
769
{
770
    return pdev->resource[bar].start;
771
}
772
 
1408 serge 773
#endif //__PCI__H__
774
 
775