1 | /** |
---|
2 | * @file |
---|
3 | */ |
---|
4 | |
---|
5 | /* |
---|
6 | * COPYRIGHT (c) 1989-2012. |
---|
7 | * On-Line Applications Research Corporation (OAR). |
---|
8 | * |
---|
9 | * The license and distribution terms for this file may be |
---|
10 | * found in the file LICENSE in this distribution or at |
---|
11 | * http://www.rtems.com/license/LICENSE. |
---|
12 | */ |
---|
13 | |
---|
14 | /* |
---|
15 | * |
---|
16 | * PCI defines and function prototypes |
---|
17 | * Copyright 1994, Drew Eckhardt |
---|
18 | * Copyright 1997, 1998 Martin Mares <mj@atrey.karlin.mff.cuni.cz> |
---|
19 | * |
---|
20 | * For more information, please consult the following manuals (look at |
---|
21 | * http://www.pcisig.com/ for how to get them): |
---|
22 | * |
---|
23 | * PCI BIOS Specification |
---|
24 | * PCI Local Bus Specification |
---|
25 | * PCI to PCI Bridge Specification |
---|
26 | * PCI System Design Guide |
---|
27 | */ |
---|
28 | |
---|
29 | #ifndef BSP_PCI_H |
---|
30 | #define BSP_PCI_H |
---|
31 | |
---|
32 | #include <rtems/pci.h> |
---|
33 | #include <bsp.h> |
---|
34 | #include <stdio.h> |
---|
35 | |
---|
36 | struct _pin_routes |
---|
37 | { |
---|
38 | int pin, int_name[4]; |
---|
39 | }; |
---|
40 | struct _int_map |
---|
41 | { |
---|
42 | int bus, slot, opts; |
---|
43 | struct _pin_routes pin_route[5]; |
---|
44 | }; |
---|
45 | struct pcibridge |
---|
46 | { |
---|
47 | int bus; |
---|
48 | int slot; |
---|
49 | }; |
---|
50 | |
---|
51 | /* If there's a conflict between a name in the routing table and |
---|
52 | * what's already set on the device, reprogram the device setting |
---|
53 | * to reflect int_name[0] for the routing table entry |
---|
54 | */ |
---|
55 | #define PCI_FIXUP_OPT_OVERRIDE_NAME (1<<0) |
---|
56 | |
---|
57 | void FixupPCI( const struct _int_map *, int (*swizzler)(int,int) ); |
---|
58 | |
---|
59 | /* FIXME: This probably belongs into rtems/pci.h */ |
---|
60 | extern unsigned char pci_bus_count(); |
---|
61 | |
---|
62 | /* FIXME: This also is generic and could go into rtems/pci.h */ |
---|
63 | |
---|
64 | /* Scan pci config space and run a user callback on each |
---|
65 | * device present; the user callback may return 0 to |
---|
66 | * continue the scan or a value > 0 to abort the scan. |
---|
67 | * Return values < 0 are reserved and must not be used. |
---|
68 | * |
---|
69 | * RETURNS: a (opaque) handle pointing to the bus/slot/fn-triple |
---|
70 | * just after where the scan was aborted by a callback |
---|
71 | * returning 1 (see above) or NULL if all devices were |
---|
72 | * scanned. |
---|
73 | * The handle may be passed to this routine to resume the |
---|
74 | * scan continuing with the device after the one causing the |
---|
75 | * abort. |
---|
76 | * Pass a NULL 'handle' argument to start scanning from |
---|
77 | * the beginning (bus/slot/fn = 0/0/0). |
---|
78 | */ |
---|
79 | typedef void *BSP_PciScanHandle; |
---|
80 | typedef int (*BSP_PciScannerCb)(int bus, int slot, int fun, void *uarg); |
---|
81 | |
---|
82 | |
---|
83 | BSP_PciScanHandle |
---|
84 | BSP_pciScan(BSP_PciScanHandle handle, BSP_PciScannerCb cb, void *uarg); |
---|
85 | |
---|
86 | /* Dump basic config. space info to a file. The argument may |
---|
87 | * be NULL in which case 'stdout' is used. |
---|
88 | * NOTE: the C-library must be functional before you can use |
---|
89 | * this routine. |
---|
90 | */ |
---|
91 | void BSP_pciConfigDump(FILE *fp); |
---|
92 | |
---|
93 | int indirect_pci_read_config_byte( |
---|
94 | unsigned char bus, |
---|
95 | unsigned char slot, |
---|
96 | unsigned char function, |
---|
97 | unsigned char offset, |
---|
98 | uint8_t *val |
---|
99 | ); |
---|
100 | |
---|
101 | int indirect_pci_read_config_word( |
---|
102 | unsigned char bus, |
---|
103 | unsigned char slot, |
---|
104 | unsigned char function, |
---|
105 | unsigned char offset, |
---|
106 | uint16_t *val |
---|
107 | ); |
---|
108 | |
---|
109 | int indirect_pci_read_config_dword( |
---|
110 | unsigned char bus, |
---|
111 | unsigned char slot, |
---|
112 | unsigned char function, |
---|
113 | unsigned char offset, |
---|
114 | uint32_t *val |
---|
115 | ); |
---|
116 | |
---|
117 | int indirect_pci_write_config_byte( |
---|
118 | unsigned char bus, |
---|
119 | unsigned char slot, |
---|
120 | unsigned char function, |
---|
121 | unsigned char offset, |
---|
122 | uint8_t val |
---|
123 | ); |
---|
124 | |
---|
125 | int indirect_pci_write_config_word( |
---|
126 | unsigned char bus, |
---|
127 | unsigned char slot, |
---|
128 | unsigned char function, |
---|
129 | unsigned char offset, |
---|
130 | uint16_t val |
---|
131 | ); |
---|
132 | |
---|
133 | int indirect_pci_write_config_dword( |
---|
134 | unsigned char bus, |
---|
135 | unsigned char slot, |
---|
136 | unsigned char function, |
---|
137 | unsigned char offset, |
---|
138 | uint32_t val |
---|
139 | ); |
---|
140 | |
---|
141 | /* Can these be moved to the rtems pci.h? */ |
---|
142 | int FindPCIbridge( int mybus, struct pcibridge *pb ); |
---|
143 | void pci_list_devices( void ); |
---|
144 | |
---|
145 | const pci_config_access_functions pci_indirect_functions; |
---|
146 | |
---|
147 | void pci_out_le32( uint32_t base, uint32_t addr, uint32_t val); |
---|
148 | void pci_out_32( uint32_t base, uint32_t addr, uint32_t val); |
---|
149 | uint8_t pci_in_8 ( uint32_t base, uint32_t addr ); |
---|
150 | int16_t pci_in_le16 ( uint32_t base, uint32_t addr ); |
---|
151 | uint32_t pci_in_le32 ( uint32_t base, uint32_t addr ); |
---|
152 | int16_t pci_in_16 ( uint32_t base, uint32_t addr ); |
---|
153 | uint32_t pci_in_32 ( uint32_t base, uint32_t addr ); |
---|
154 | void pci_out_8 ( uint32_t base, uint32_t addr, uint8_t val ); |
---|
155 | void pci_out_le16( uint32_t base, uint32_t addr, uint16_t val ); |
---|
156 | void pci_out_16( uint32_t base, uint32_t addr, uint16_t val ); |
---|
157 | void pci_out_32 ( uint32_t base, uint32_t addr, uint32_t val); |
---|
158 | |
---|
159 | #define out_32(_addr, _val) pci_out_32(BSP_PCI_BASE_ADDRESS, _addr, _val) |
---|
160 | #define out_le32(_addr, _val) pci_out_le32(BSP_PCI_BASE_ADDRESS, _addr, _val) |
---|
161 | #define out_32(_addr, _val) pci_out_32(BSP_PCI_BASE_ADDRESS, _addr, _val) |
---|
162 | #define in_8(_addr) pci_in_8( BSP_PCI_BASE_ADDRESS, _addr ) |
---|
163 | #define in_le16(_addr) pci_in_le16( BSP_PCI_BASE_ADDRESS, _addr ) |
---|
164 | #define in_le32(_addr) pci_in_le32( BSP_PCI_BASE_ADDRESS, _addr ) |
---|
165 | #define in_16(_addr) pci_in_16( BSP_PCI_BASE_ADDRESS, _addr ) |
---|
166 | #define in_32(_addr) pci_in_32( BSP_PCI_BASE_ADDRESS, _addr ) |
---|
167 | #define out_8(_addr,_val) pci_out_8( BSP_PCI_BASE_ADDRESS, _addr, _val ) |
---|
168 | #define out_le16(_addr,_val) pci_out_le16( BSP_PCI_BASE_ADDRESS, _addr, _val ) |
---|
169 | #define out_16(_addr,_val) pci_out_16( BSP_PCI_BASE_ADDRESS, _addr, _val ) |
---|
170 | |
---|
171 | #endif /* BSP_PCI_H */ |
---|