1 |
786 |
skrzyp |
#ifndef CYGONCE_PCI_H
|
2 |
|
|
#define CYGONCE_PCI_H
|
3 |
|
|
//=============================================================================
|
4 |
|
|
//
|
5 |
|
|
// pci.h
|
6 |
|
|
//
|
7 |
|
|
// PCI library
|
8 |
|
|
//
|
9 |
|
|
//=============================================================================
|
10 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
11 |
|
|
// -------------------------------------------
|
12 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
13 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
|
14 |
|
|
//
|
15 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
16 |
|
|
// the terms of the GNU General Public License as published by the Free
|
17 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
18 |
|
|
// version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
21 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License
|
26 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use
|
30 |
|
|
// macros or inline functions from this file, or you compile this file
|
31 |
|
|
// and link it with other works to produce a work based on this file,
|
32 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
33 |
|
|
// the GNU General Public License. However the source code for this file
|
34 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
35 |
|
|
// General Public License v2.
|
36 |
|
|
//
|
37 |
|
|
// This exception does not invalidate any other reasons why a work based
|
38 |
|
|
// on this file might be covered by the GNU General Public License.
|
39 |
|
|
// -------------------------------------------
|
40 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
41 |
|
|
//=============================================================================
|
42 |
|
|
//#####DESCRIPTIONBEGIN####
|
43 |
|
|
//
|
44 |
|
|
// Author(s): jskov, from design by nickg
|
45 |
|
|
// Contributors: jskov
|
46 |
|
|
// Date: 1999-08-09
|
47 |
|
|
// Purpose: PCI configuration access
|
48 |
|
|
// Usage:
|
49 |
|
|
// #include <cyg/io/pci.h>
|
50 |
|
|
// Description:
|
51 |
|
|
// This library provides a set of routines for accessing
|
52 |
|
|
// the PCI bus configuration space in a portable manner.
|
53 |
|
|
// This is provided by two APIs. The high level API (defined
|
54 |
|
|
// by this file) is used by device drivers, or other code, to
|
55 |
|
|
// access the PCI configuration space portably. The low level
|
56 |
|
|
// API (see pci_hw.h) is used by the PCI library itself
|
57 |
|
|
// to access the hardware in a platform-specific manner and
|
58 |
|
|
// may also be used by device drivers to access the PCI
|
59 |
|
|
// configuration space directly.
|
60 |
|
|
//
|
61 |
|
|
//####DESCRIPTIONEND####
|
62 |
|
|
//
|
63 |
|
|
//=============================================================================
|
64 |
|
|
|
65 |
|
|
#include <cyg/infra/cyg_type.h>
|
66 |
|
|
#include <cyg/io/pci_cfg.h>
|
67 |
|
|
#include <cyg/io/pci_hw.h>
|
68 |
|
|
|
69 |
|
|
//------------------------------------------------------------------
|
70 |
|
|
// Map a logical (CPU local) address to one used by a PCI master
|
71 |
|
|
// Normally, this is just the physical address of the object, but
|
72 |
|
|
// it may differ if the platform has different address maps from
|
73 |
|
|
// the CPU side vs. the PCI side
|
74 |
|
|
#ifndef CYGARC_PCI_DMA_ADDRESS
|
75 |
|
|
#define CYGARC_PCI_DMA_ADDRESS(_x_) CYGARC_PHYSICAL_ADDRESS(_x_)
|
76 |
|
|
#endif
|
77 |
|
|
|
78 |
|
|
//------------------------------------------------------------------
|
79 |
|
|
// The PCI memory space can span 64 bits, IO space only 32 bits
|
80 |
|
|
typedef CYG_WORD64 CYG_PCI_ADDRESS64;
|
81 |
|
|
typedef CYG_WORD32 CYG_PCI_ADDRESS32;
|
82 |
|
|
|
83 |
|
|
//------------------------------------------------------------------
|
84 |
|
|
// Macros for manufacturing and decomposing device ids
|
85 |
|
|
typedef CYG_WORD32 cyg_pci_device_id; // PCI device ID
|
86 |
|
|
|
87 |
|
|
#define CYG_PCI_DEV_MAKE_ID(__bus,__devfn) (((__bus)<<16)|((__devfn)<<8))
|
88 |
|
|
#define CYG_PCI_DEV_GET_BUS(__devid) ((__devid>>16)&0xFF)
|
89 |
|
|
#define CYG_PCI_DEV_GET_DEVFN(__devid) ((__devid>>8)&0xFF)
|
90 |
|
|
|
91 |
|
|
#define CYG_PCI_NULL_DEVID 0xffffffff
|
92 |
|
|
#define CYG_PCI_NULL_DEVFN 0xffff
|
93 |
|
|
|
94 |
|
|
//------------------------------------------------------------------
|
95 |
|
|
// PCI device data definitions and structures
|
96 |
|
|
|
97 |
|
|
typedef enum {
|
98 |
|
|
CYG_PCI_HEADER_NORMAL = 0,
|
99 |
|
|
CYG_PCI_HEADER_BRIDGE = 1,
|
100 |
|
|
CYG_PCI_HEADER_CARDBUS_BRIDGE = 2
|
101 |
|
|
} cyg_pci_header_type;
|
102 |
|
|
|
103 |
|
|
typedef struct // PCI device data
|
104 |
|
|
{
|
105 |
|
|
cyg_pci_device_id devid; // ID of this device
|
106 |
|
|
|
107 |
|
|
// The following fields are read out of the
|
108 |
|
|
// config space for this device.
|
109 |
|
|
|
110 |
|
|
cyg_uint16 vendor; // vendor ID
|
111 |
|
|
cyg_uint16 device; // device ID
|
112 |
|
|
cyg_uint16 command; // command register
|
113 |
|
|
cyg_uint16 status; // status register
|
114 |
|
|
cyg_uint32 class_rev; // class+revision
|
115 |
|
|
cyg_uint8 cache_line_size; // cache line size
|
116 |
|
|
cyg_uint8 latency_timer; // latency timer
|
117 |
|
|
cyg_pci_header_type header_type; // header type
|
118 |
|
|
cyg_uint8 bist; // Built-in Self-Test
|
119 |
|
|
cyg_uint32 base_address[6]; // Memory base address registers
|
120 |
|
|
|
121 |
|
|
// The following fields are used by the resource allocation
|
122 |
|
|
// routines to keep track of allocated resources.
|
123 |
|
|
cyg_uint32 num_bars;
|
124 |
|
|
|
125 |
|
|
cyg_uint32 base_size[6]; // Memory size for each base address
|
126 |
|
|
cyg_uint32 base_map[6]; // Physical address mapped
|
127 |
|
|
|
128 |
|
|
CYG_ADDRWORD hal_vector; // HAL interrupt vector used by
|
129 |
|
|
// device if int_line!=0
|
130 |
|
|
|
131 |
|
|
// One of the following unions will be filled in according to
|
132 |
|
|
// the value of the header_type field.
|
133 |
|
|
|
134 |
|
|
union
|
135 |
|
|
{
|
136 |
|
|
struct
|
137 |
|
|
{
|
138 |
|
|
cyg_uint32 cardbus_cis; // CardBus CIS Pointer
|
139 |
|
|
cyg_uint16 sub_vendor; // subsystem vendor id
|
140 |
|
|
cyg_uint16 sub_id; // subsystem id
|
141 |
|
|
cyg_uint32 rom_address; // ROM address register
|
142 |
|
|
cyg_uint8 cap_list; // capability list
|
143 |
|
|
cyg_uint8 reserved1[7];
|
144 |
|
|
cyg_uint8 int_line; // interrupt line
|
145 |
|
|
cyg_uint8 int_pin; // interrupt pin
|
146 |
|
|
cyg_uint8 min_gnt; // timeslice request
|
147 |
|
|
cyg_uint8 max_lat; // priority-level request
|
148 |
|
|
} normal;
|
149 |
|
|
struct
|
150 |
|
|
{
|
151 |
|
|
cyg_uint8 pri_bus; // primary bus number
|
152 |
|
|
cyg_uint8 sec_bus; // secondary bus number
|
153 |
|
|
cyg_uint8 sub_bus; // subordinate bus number
|
154 |
|
|
cyg_uint8 sec_latency_timer; // secondary bus latency
|
155 |
|
|
cyg_uint8 io_base;
|
156 |
|
|
cyg_uint8 io_limit;
|
157 |
|
|
cyg_uint16 sec_status; // secondary bus status
|
158 |
|
|
cyg_uint16 mem_base;
|
159 |
|
|
cyg_uint16 mem_limit;
|
160 |
|
|
cyg_uint16 prefetch_base;
|
161 |
|
|
cyg_uint16 prefetch_limit;
|
162 |
|
|
cyg_uint32 prefetch_base_upper32;
|
163 |
|
|
cyg_uint32 prefetch_limit_upper32;
|
164 |
|
|
cyg_uint16 io_base_upper16;
|
165 |
|
|
cyg_uint16 io_limit_upper16;
|
166 |
|
|
cyg_uint8 reserved1[4];
|
167 |
|
|
cyg_uint32 rom_address; // ROM address register
|
168 |
|
|
cyg_uint8 int_line; // interrupt line
|
169 |
|
|
cyg_uint8 int_pin; // interrupt pin
|
170 |
|
|
cyg_uint16 control; // bridge control
|
171 |
|
|
} bridge;
|
172 |
|
|
struct
|
173 |
|
|
{
|
174 |
|
|
// Not yet supported
|
175 |
|
|
} cardbus_bridge;
|
176 |
|
|
} header;
|
177 |
|
|
} cyg_pci_device;
|
178 |
|
|
|
179 |
|
|
//------------------------------------------------------------------------
|
180 |
|
|
// Init
|
181 |
|
|
externC void cyg_pci_init( void );
|
182 |
|
|
|
183 |
|
|
//------------------------------------------------------------------------
|
184 |
|
|
// Common device configuration access functions
|
185 |
|
|
|
186 |
|
|
// This function gets the PCI configuration information for the
|
187 |
|
|
// device indicated in devid. The common fields of the cyg_pci_device
|
188 |
|
|
// structure, and the appropriate fields of the relevant header union
|
189 |
|
|
// member are filled in from the device's configuration space. If the
|
190 |
|
|
// device has not been enabled, then this function will also fetch
|
191 |
|
|
// the size and type information from the base address registers and
|
192 |
|
|
// place it in the base_size[] array.
|
193 |
|
|
externC void cyg_pci_get_device_info ( cyg_pci_device_id devid,
|
194 |
|
|
cyg_pci_device *dev_info );
|
195 |
|
|
|
196 |
|
|
|
197 |
|
|
// This function sets the PCI configuration information for the
|
198 |
|
|
// device indicated in devid. Only the configuration space registers
|
199 |
|
|
// that are writable are actually written. Once all the fields have
|
200 |
|
|
// been written, the device info will be read back into *dev_info, so
|
201 |
|
|
// that it reflects the true state of the hardware.
|
202 |
|
|
externC void cyg_pci_set_device_info ( cyg_pci_device_id devid,
|
203 |
|
|
cyg_pci_device *dev_info );
|
204 |
|
|
|
205 |
|
|
//------------------------------------------------------------------------
|
206 |
|
|
// Device find functions
|
207 |
|
|
|
208 |
|
|
// Searches the PCI bus configuration space for a device with the
|
209 |
|
|
// given vendor and device ids. The search starts at the device
|
210 |
|
|
// pointed to by devid, or at the first slot if it contains
|
211 |
|
|
// CYG_PCI_NULL_DEVID. *devid will be updated with the ID of the next
|
212 |
|
|
// device found. Returns true if one is found and false if not.
|
213 |
|
|
externC cyg_bool cyg_pci_find_device( cyg_uint16 vendor, cyg_uint16 device,
|
214 |
|
|
cyg_pci_device_id *devid );
|
215 |
|
|
|
216 |
|
|
|
217 |
|
|
// Searches the PCI bus configuration space for a device with the
|
218 |
|
|
// given class code. The search starts at the device pointed to by
|
219 |
|
|
// devid, or at the first slot if it contains CYG_PCI_NULL_DEVID.
|
220 |
|
|
// *devid will be updated with the ID of the next device found.
|
221 |
|
|
// Returns true if one is found and false if not.
|
222 |
|
|
externC cyg_bool cyg_pci_find_class( cyg_uint32 dev_class,
|
223 |
|
|
cyg_pci_device_id *devid );
|
224 |
|
|
|
225 |
|
|
|
226 |
|
|
|
227 |
|
|
// Searches the PCI bus configuration space for a device whose properties
|
228 |
|
|
// match those required by the match_func, which the user supplies. The
|
229 |
|
|
// match_func's arguments are vendor, device, class exactly as they might
|
230 |
|
|
// be in the two APIs above. The additional parameter is for any state
|
231 |
|
|
// which a caller might wish available to its callback routine.
|
232 |
|
|
// The search starts at the device pointed to by
|
233 |
|
|
// devid, or at the first slot if it contains CYG_PCI_NULL_DEVID. *devid
|
234 |
|
|
// will be updated with the ID of the next device found. Returns true if
|
235 |
|
|
// one is found and false if not.
|
236 |
|
|
typedef cyg_bool (cyg_pci_match_func)( cyg_uint16,/* vendor */
|
237 |
|
|
cyg_uint16,/* device */
|
238 |
|
|
cyg_uint32,/* class */
|
239 |
|
|
void * /* arbitrary user data */ );
|
240 |
|
|
externC cyg_bool cyg_pci_find_matching( cyg_pci_match_func *matchp,
|
241 |
|
|
void * match_callback_data,
|
242 |
|
|
cyg_pci_device_id *devid );
|
243 |
|
|
|
244 |
|
|
|
245 |
|
|
// Searches the PCI configuration space for the next valid device
|
246 |
|
|
// after cur_devid. If cur_devid is given the value
|
247 |
|
|
// CYG_PCI_NULL_DEVID, then the search starts at the first slot. It
|
248 |
|
|
// is permitted for next_devid to point to the cur_devid. Returns
|
249 |
|
|
// true if another device is found and false if not.
|
250 |
|
|
externC cyg_bool cyg_pci_find_next( cyg_pci_device_id cur_devid,
|
251 |
|
|
cyg_pci_device_id *next_devid );
|
252 |
|
|
|
253 |
|
|
//------------------------------------------------------------------------
|
254 |
|
|
// Resource Allocation
|
255 |
|
|
// These routines allocate memory and IO space to PCI devices.
|
256 |
|
|
|
257 |
|
|
// Allocate memory and IO space to all base address registers using
|
258 |
|
|
// the current memory and IO base addresses in the library. If
|
259 |
|
|
// dev_info does not contain valid base_size[] entries, then the
|
260 |
|
|
// result is false.
|
261 |
|
|
externC cyg_bool cyg_pci_configure_device( cyg_pci_device *dev_info );
|
262 |
|
|
|
263 |
|
|
// Allocate memory and IO space for all devices found on the given
|
264 |
|
|
// bus and its subordinate busses. This routine recurses when a
|
265 |
|
|
// PCI-to-PCI bridge is encountered. The next_bus argument points
|
266 |
|
|
// to a variable holding the bus number of the next PCI bus to
|
267 |
|
|
// be allocated when a bridge is encountered. This routine returns
|
268 |
|
|
// true if successful, false if unsuccessful.
|
269 |
|
|
externC cyg_bool cyg_pci_configure_bus( cyg_uint8 bus,
|
270 |
|
|
cyg_uint8 *next_bus );
|
271 |
|
|
|
272 |
|
|
// These routines set the base addresses for memory and IO mappings
|
273 |
|
|
// to be used by the memory allocation routines. Normally these base
|
274 |
|
|
// addresses will be set to default values based on the platform,
|
275 |
|
|
// these routines allow those to be changed by application code if
|
276 |
|
|
// necessary.
|
277 |
|
|
externC void cyg_pci_set_memory_base( CYG_PCI_ADDRESS64 base );
|
278 |
|
|
externC void cyg_pci_set_io_base( CYG_PCI_ADDRESS32 base );
|
279 |
|
|
|
280 |
|
|
// These routines allocate memory or IO space to the base address
|
281 |
|
|
// register indicated by bar. The base address in *base will be
|
282 |
|
|
// correctly aligned and the address of the next free location will
|
283 |
|
|
// be written back into it if the allocation succeeds. If the base
|
284 |
|
|
// address register is of the wrong type for this allocation, or
|
285 |
|
|
// dev_info does not contain valid base_size[] entries, the result is
|
286 |
|
|
// false.
|
287 |
|
|
externC cyg_bool cyg_pci_allocate_memory( cyg_pci_device *dev_info,
|
288 |
|
|
cyg_uint32 bar,
|
289 |
|
|
CYG_PCI_ADDRESS64 *base );
|
290 |
|
|
externC cyg_bool cyg_pci_allocate_io( cyg_pci_device *dev_info,
|
291 |
|
|
cyg_uint32 bar,
|
292 |
|
|
CYG_PCI_ADDRESS32 *base );
|
293 |
|
|
|
294 |
|
|
// Translate the device's PCI interrupt (INTA#-INTD#) to the
|
295 |
|
|
// associated HAL vector. This may also depend on which slot the
|
296 |
|
|
// device occupies. If the device may generate interrupts, the
|
297 |
|
|
// translated vector number will be stored in vec and the result is
|
298 |
|
|
// true. Otherwise the result is false.
|
299 |
|
|
externC cyg_bool cyg_pci_translate_interrupt( cyg_pci_device *dev_info,
|
300 |
|
|
CYG_ADDRWORD *vec );
|
301 |
|
|
|
302 |
|
|
|
303 |
|
|
//----------------------------------------------------------------------
|
304 |
|
|
// Specific device configuration access functions
|
305 |
|
|
|
306 |
|
|
// Read functions
|
307 |
|
|
// These functions read registers of the appropriate size from the
|
308 |
|
|
// configuration space of the given device. They should mainly be
|
309 |
|
|
// used to access registers that are device specific. General PCI
|
310 |
|
|
// registers are best accessed through cyg_pci_get_device_info().
|
311 |
|
|
externC void cyg_pci_read_config_uint8( cyg_pci_device_id devid,
|
312 |
|
|
cyg_uint8 offset, cyg_uint8 *val);
|
313 |
|
|
externC void cyg_pci_read_config_uint16( cyg_pci_device_id devid,
|
314 |
|
|
cyg_uint8 offset, cyg_uint16 *val);
|
315 |
|
|
externC void cyg_pci_read_config_uint32( cyg_pci_device_id devid,
|
316 |
|
|
cyg_uint8 offset, cyg_uint32 *val);
|
317 |
|
|
|
318 |
|
|
// Write functions
|
319 |
|
|
// These functions write registers of the appropriate size to the
|
320 |
|
|
// configuration space of the given device. They should mainly be
|
321 |
|
|
// used to access registers that are device specific. General PCI
|
322 |
|
|
// registers are best accessed through
|
323 |
|
|
// cyg_pci_get_device_info(). Writing the general registers this way
|
324 |
|
|
// may render the contents of a cyg_pci_device structure invalid.
|
325 |
|
|
externC void cyg_pci_write_config_uint8( cyg_pci_device_id devid,
|
326 |
|
|
cyg_uint8 offset, cyg_uint8 val);
|
327 |
|
|
externC void cyg_pci_write_config_uint16( cyg_pci_device_id devid,
|
328 |
|
|
cyg_uint8 offset, cyg_uint16 val);
|
329 |
|
|
externC void cyg_pci_write_config_uint32( cyg_pci_device_id devid,
|
330 |
|
|
cyg_uint8 offset, cyg_uint32 val);
|
331 |
|
|
|
332 |
|
|
|
333 |
|
|
//----------------------------------------------------------------------
|
334 |
|
|
// Functions private to the PCI library. These should only be used by
|
335 |
|
|
// tests.
|
336 |
|
|
externC cyg_bool cyg_pci_allocate_memory_priv(cyg_pci_device *dev_info,
|
337 |
|
|
cyg_uint32 bar,
|
338 |
|
|
CYG_PCI_ADDRESS64 *base,
|
339 |
|
|
CYG_PCI_ADDRESS64 *assigned_addr);
|
340 |
|
|
externC cyg_bool cyg_pci_allocate_io_priv( cyg_pci_device *dev_info,
|
341 |
|
|
cyg_uint32 bar,
|
342 |
|
|
CYG_PCI_ADDRESS32 *base,
|
343 |
|
|
CYG_PCI_ADDRESS32 *assigned_addr);
|
344 |
|
|
|
345 |
|
|
|
346 |
|
|
//----------------------------------------------------------------------
|
347 |
|
|
// Bus probing limits.
|
348 |
|
|
// Note: these can be overridden by the platform
|
349 |
|
|
#ifndef CYG_PCI_MAX_BUS
|
350 |
|
|
#define CYG_PCI_MAX_BUS 8 // Eight is enough?
|
351 |
|
|
#endif
|
352 |
|
|
#ifndef CYG_PCI_MAX_DEV
|
353 |
|
|
#define CYG_PCI_MAX_DEV 32
|
354 |
|
|
#endif
|
355 |
|
|
#ifndef CYG_PCI_MIN_DEV
|
356 |
|
|
#define CYG_PCI_MIN_DEV 0
|
357 |
|
|
#endif
|
358 |
|
|
#ifndef CYG_PCI_MAX_FN
|
359 |
|
|
#define CYG_PCI_MAX_FN 8
|
360 |
|
|
#endif
|
361 |
|
|
#ifndef CYG_PCI_MAX_BAR
|
362 |
|
|
#define CYG_PCI_MAX_BAR 6
|
363 |
|
|
#endif
|
364 |
|
|
|
365 |
|
|
//-----------------------------------------------------------------------------
|
366 |
|
|
#endif // ifndef CYGONCE_PCI_H
|
367 |
|
|
// End of pci.h
|