Subversion Repositories Kolibri OS

Rev

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