RTEMS 6.1-rc2
Loading...
Searching...
No Matches
pci.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
13/*
14 * COPYRIGHT (c) 2009 Cobham Gaisler AB.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
29 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 * POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef __PCI_H__
39#define __PCI_H__
40
41#include <pci/pcireg.h>
42#include <pci/ids.h>
43
44#define PCI_INVALID_VENDORDEVICEID 0xffffffff
45
46#define PCID_CLASS(class, dev) ((class << 8) | dev)
47#define PCID_PCI2PCI_BRIDGE PCID_CLASS(PCIC_BRIDGE, PCIS_BRIDGE_PCI)
48
49#include <pci/access.h>
50
51#ifdef __cplusplus
52extern "C" {
53#endif
54
55/* The PCI Library have the following build time configuration options. It is
56 * up to the BSP header file (bsp.h) to set options properly.
57 *
58 * BSP_PCI_BIG_ENDIAN - Access inline routines will be for a big-endian PCI
59 * bus, if not defined the routines will assume that
60 * PCI is as the standard defines: little-endian.
61 *
62 * Note that drivers may be run-time configurable,
63 * meaning that they may adopt to either big-endian or
64 * little-endian PCI bus, the host driver or BSP may
65 * detect endianness during run-time.
66 */
67
68/* Error return values */
69enum {
70 PCISTS_ERR = -1, /* Undefined Error */
71 PCISTS_OK = 0,
72 PCISTS_EINVAL = 1, /* Bad input arguments */
73 PCISTS_MSTABRT = 2, /* CFG space access error (can be ignored) */
74};
75
76/* PCI System type can be used to determine system for drivers. Normally
77 * the system is Host, but the peripheral configuration library also supports
78 * being PCI peripheral not allowed to access configuration space.
79 *
80 * The active configuration Library set this variable.
81 */
82enum pci_system_type {
83 PCI_SYSTEM_NONE = 0,
84 PCI_SYSTEM_HOST = 1,
85 PCI_SYSTEM_PERIPHERAL = 2,
86};
87extern enum pci_system_type pci_system_type;
88
89/* PCI Bus Endianness. The PCI specification is little endian, however on some
90 * embedded systems (AT697-LEON2 for example) the PCI bus is defined as big
91 * endian (non-standard) in order to avoid byte-twisting.
92 */
93enum {
94 PCI_LITTLE_ENDIAN = 0,
95 PCI_BIG_ENDIAN = 1,
96};
97extern int pci_endian;
98
99/* Return the number of PCI busses in the system */
100extern int pci_bus_count(void);
101
102/* Scan the PCI bus and print the PCI device/functions/bridges and their
103 * current resources and size to the system console.
104 */
105extern void pci_print(void);
106
107/* Print current configuration of a single PCI device by reading PCI
108 * configuration space
109 */
110extern void pci_print_dev(pci_dev_t dev);
111extern void pci_print_device(int bus, int slot, int function);
112
113/*** PCI Configuration Space direct access routines ***/
114
115/* Function iterates over all PCI buses/devices/functions and calls
116 * func(PCIDEV,arg) for each present device. The iteration is stopped if
117 * func() returns non-zero result the same result is returned. As long
118 * as func() returns zero the function will keep on iterating, when all
119 * devices has been processed the function return zero.
120 *
121 * The function iterates over all devices/functions on all buses by accessing
122 * configuration space directly (PCI RAM data structures not used). This
123 * function is valid to call after PCI buses have been enumrated.
124 */
125extern int pci_for_each(int (*func)(pci_dev_t, void*), void *arg);
126
127/* Get PCI Configuration space BUS|SLOT|FUNC for a device matching PCI
128 * Vendor, Device and instance number 'index'.
129 *
130 * Return Values
131 * -1 pci_find_dev did not find a device matching the criterion.
132 * 0 device was found, *pdev was updated with the device's BUS|SLOT|FUNC
133 */
134extern int pci_find(uint16_t ven, uint16_t dev, int index, pci_dev_t *pdev);
135
136#ifdef __cplusplus
137}
138#endif
139
140#endif /* __PCI_H__ */
PCI Access Methods.