1 | /* |
---|
2 | * PCI library. Defines in this file was taken from FreeBSD and auto-generated |
---|
3 | * pci_ids.h reused from RTEMS. |
---|
4 | * |
---|
5 | * COPYRIGHT (c) 2009 Cobham Gaisler AB. |
---|
6 | * |
---|
7 | * The license and distribution terms for this file may be |
---|
8 | * found in the file LICENSE in this distribution or at |
---|
9 | * http://www.rtems.org/license/LICENSE. |
---|
10 | */ |
---|
11 | |
---|
12 | #ifndef __PCI_H__ |
---|
13 | #define __PCI_H__ |
---|
14 | |
---|
15 | #include <pci/pcireg.h> |
---|
16 | #include <pci/ids.h> |
---|
17 | |
---|
18 | #define PCI_INVALID_VENDORDEVICEID 0xffffffff |
---|
19 | |
---|
20 | #define PCID_CLASS(class, dev) ((class << 8) | dev) |
---|
21 | #define PCID_PCI2PCI_BRIDGE PCID_CLASS(PCIC_BRIDGE, PCIS_BRIDGE_PCI) |
---|
22 | |
---|
23 | #include <pci/access.h> |
---|
24 | |
---|
25 | #ifdef __cplusplus |
---|
26 | extern "C" { |
---|
27 | #endif |
---|
28 | |
---|
29 | /* The PCI Library have the following build time configuration options. It is |
---|
30 | * up to the BSP header file (bsp.h) to set options properly. |
---|
31 | * |
---|
32 | * BSP_PCI_BIG_ENDIAN - Access inline routines will be for a big-endian PCI |
---|
33 | * bus, if not defined the routines will assume that |
---|
34 | * PCI is as the standard defines: little-endian. |
---|
35 | * |
---|
36 | * Note that drivers may be run-time configurable, |
---|
37 | * meaning that they may adopt to either big-endian or |
---|
38 | * little-endian PCI bus, the host driver or BSP may |
---|
39 | * detect endianness during run-time. |
---|
40 | */ |
---|
41 | |
---|
42 | /* Error return values */ |
---|
43 | enum { |
---|
44 | PCISTS_ERR = -1, /* Undefined Error */ |
---|
45 | PCISTS_OK = 0, |
---|
46 | PCISTS_EINVAL = 1, /* Bad input arguments */ |
---|
47 | PCISTS_MSTABRT = 2, /* CFG space access error (can be ignored) */ |
---|
48 | }; |
---|
49 | |
---|
50 | /* PCI System type can be used to determine system for drivers. Normally |
---|
51 | * the system is Host, but the peripheral configuration library also supports |
---|
52 | * being PCI peripheral not allowed to access configuration space. |
---|
53 | * |
---|
54 | * The active configuration Library set this variable. |
---|
55 | */ |
---|
56 | enum pci_system_type { |
---|
57 | PCI_SYSTEM_NONE = 0, |
---|
58 | PCI_SYSTEM_HOST = 1, |
---|
59 | PCI_SYSTEM_PERIPHERAL = 2, |
---|
60 | }; |
---|
61 | extern enum pci_system_type pci_system_type; |
---|
62 | |
---|
63 | /* PCI Bus Endianness. The PCI specification is little endian, however on some |
---|
64 | * embedded systems (AT697-LEON2 for example) the PCI bus is defined as big |
---|
65 | * endian (non-standard) in order to avoid byte-twisting. |
---|
66 | */ |
---|
67 | enum { |
---|
68 | PCI_LITTLE_ENDIAN = 0, |
---|
69 | PCI_BIG_ENDIAN = 1, |
---|
70 | }; |
---|
71 | extern int pci_endian; |
---|
72 | |
---|
73 | /* Return the number of PCI busses in the system */ |
---|
74 | extern int pci_bus_count(void); |
---|
75 | |
---|
76 | /* Scan the PCI bus and print the PCI device/functions/bridges and their |
---|
77 | * current resources and size to the system console. |
---|
78 | */ |
---|
79 | extern void pci_print(void); |
---|
80 | |
---|
81 | /* Print current configuration of a single PCI device by reading PCI |
---|
82 | * configuration space |
---|
83 | */ |
---|
84 | extern void pci_print_dev(pci_dev_t dev); |
---|
85 | extern void pci_print_device(int bus, int slot, int function); |
---|
86 | |
---|
87 | /*** PCI Configuration Space direct access routines ***/ |
---|
88 | |
---|
89 | /* Function iterates over all PCI buses/devices/functions and calls |
---|
90 | * func(PCIDEV,arg) for each present device. The iteration is stopped if |
---|
91 | * func() returns non-zero result the same result is returned. As long |
---|
92 | * as func() returns zero the function will keep on iterating, when all |
---|
93 | * devices has been processed the function return zero. |
---|
94 | * |
---|
95 | * The function iterates over all devices/functions on all buses by accessing |
---|
96 | * configuration space directly (PCI RAM data structures not used). This |
---|
97 | * function is valid to call after PCI buses have been enumrated. |
---|
98 | */ |
---|
99 | extern int pci_for_each(int (*func)(pci_dev_t, void*), void *arg); |
---|
100 | |
---|
101 | /* Get PCI Configuration space BUS|SLOT|FUNC for a device matching PCI |
---|
102 | * Vendor, Device and instance number 'index'. |
---|
103 | * |
---|
104 | * Return Values |
---|
105 | * -1 pci_find_dev did not find a device matching the criterion. |
---|
106 | * 0 device was found, *pdev was updated with the device's BUS|SLOT|FUNC |
---|
107 | */ |
---|
108 | extern int pci_find(uint16_t ven, uint16_t dev, int index, pci_dev_t *pdev); |
---|
109 | |
---|
110 | #ifdef __cplusplus |
---|
111 | } |
---|
112 | #endif |
---|
113 | |
---|
114 | #endif /* __PCI_H__ */ |
---|