RTEMS 6.1-rc4
Loading...
Searching...
No Matches
cfg.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
9/*
10 * COPYRIGHT (c) 2010 Cobham Gaisler AB.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/* Four versions of the library exists:
35 * - auto configuration (default)
36 * - read configuration from PnP (inherit BIOS set up)
37 * - static configuration (user defined config)
38 * - peripheral configuration, no CFG space accesses are possible instead a
39 * device tree known at compile-time have been built in.
40 * all versions are defined through here.
41 */
42
43#ifndef __PCI_CFG_H__
44#define __PCI_CFG_H__
45
46#include <pci.h>
47
48/* PCI Configuration library */
49
50/* Return the number of PCI buses in system */
51extern int pci_bus_count(void);
52
53/* PCI Address assigned to BARs which failed to fit into the PCI Window or
54 * is disabled by any other cause.
55 */
56extern uint32_t pci_invalid_address;
57
58/* PCI Configuration Library of the system */
59enum {
60 PCI_CONFIG_LIB_NONE = 0,
61 PCI_CONFIG_LIB_AUTO = 1,
62 PCI_CONFIG_LIB_STATIC = 2,
63 PCI_CONFIG_LIB_READ = 3,
64 PCI_CONFIG_LIB_PERIPHERAL = 4,
65};
66extern const int pci_config_lib_type;
67
68/* Configuration library function pointers, these are set in <rtems/confdefs.h>
69 * by project configuration or by the BSP. The configuration will pull in the
70 * PCI Library needed and the PCI initialization functions will call these
71 * functions on initialization from the host driver.
72 */
73extern int (*pci_config_lib_init)(void);
74extern void (*pci_config_lib_register)(void *config);
75
76/* Configure PCI devices and bridges, and setup the RAM data structures
77 * describing the PCI devices currently present in the system.
78 *
79 * Returns 0 on success, -1 on failure.
80 */
81extern int pci_config_init(void);
82
83/* Register a config-library specific configuration used by the libarary in
84 * pci_config_init().
85 */
86extern void pci_config_register(void *config);
87
88/* Print current PCI configuration (C-code) to terminal, can be used in
89 * static and peripheral PCI configuration library. The configuration is
90 * taken from the current configuration library setup.
91 */
92extern void pci_cfg_print(void);
93
94struct pci_bus; /* Bridge Device and secondary bus information */
95struct pci_dev; /* Device/function */
96struct pci_res; /* Resource: BAR, ROM or Bridge Window */
97
98/* The Host Bridge and all subdevices (the PCI RAM data structure) */
99extern struct pci_bus pci_hb;
100
101/* Arguments for pci_for_each_child() search option */
102#define SEARCH_CHILDREN 0 /* direct children of bus only */
103#define SEARCH_DEPTH 1 /* all children of bus */
104
105/* Iterate over all PCI devices on a bus (see search options) and call func(),
106 * iteration is stopped if a non-zero value is returned by func().
107 *
108 * The function iterates over the PCI RAM data structure, it is not
109 * available until after all devices have been found and pci_hb is populated,
110 * typically after pci_config_init() is called.
111 *
112 * search options: 0 (no child buses), 1 (depth first, recursive)
113 *
114 * Return Values
115 * 0 All PCI devices were processed, func() returned 0 on every call
116 * X func() returned non-zero X value, the search was stopped
117 */
118extern int pci_for_each_child(
119 struct pci_bus *bus,
120 int (*func)(struct pci_dev *, void *arg),
121 void *arg,
122 int search);
123
124/* Depth first search of all PCI devices in PCI RAM data structure and call
125 * func(dev, arg), iteration is stopped if a non-zero value is returned by
126 * func().
127 *
128 * The function iterates over the PCI RAM data structure, it is not
129 * available until after all devices have been found and pci_hb is populated,
130 * typically after pci_config_init() is called.
131 *
132 * Return Values
133 * 0 All PCI devices were processed, func() returned 0 on every call
134 * X func() returned non-zero X value, the search was stopped
135 */
136extern int pci_for_each_dev(
137 int (*func)(struct pci_dev *, void *arg),
138 void *arg);
139
140/* Get PCI device from RAM device tree for a device matching PCI Vendor, Device
141 * and instance number 'index'.
142 *
143 * Return Values
144 * -1 pci_find_dev did not find a device matching the criterion.
145 * 0 device was found, *ppdev was updated with the PCI device address
146 */
147extern int pci_find_dev(uint16_t ven, uint16_t dev, int index,
148 struct pci_dev **ppdev);
149
150/* Get PCI device from RAM device tree by BUS|SLOT|FUNC.
151 *
152 * Return Values
153 * -1 pci_get_dev did not find a device matching the criterion
154 * 0 device was found, *ppdev was updated with the PCI device address
155 */
156extern int pci_get_dev(pci_dev_t pcidev, struct pci_dev **ppdev);
157
158/* Resource flags */
159#define PCI_RES_IO 1
160#define PCI_RES_MEMIO 2
161#define PCI_RES_MEM_PREFETCH 1
162#define PCI_RES_MEM (PCI_RES_MEMIO | PCI_RES_MEM_PREFETCH)
163#define PCI_RES_TYPE_MASK 0x3
164#define PCI_RES_IO32 0x08
165#define PCI_RES_FAIL 0x10 /* Alloc Failed */
166
167/* BAR Resouces entry */
168struct pci_res {
169 struct pci_res *next;
170 uint32_t size;
171 uint32_t boundary;
172 unsigned char flags; /* I/O, MEM or MEMIO */
173 unsigned char bar;
174
175 /* Assigned Resource (PCI address), zero if not assigned */
176 uint32_t start;
177 uint32_t end;
178};
179
180/* Get Device from resource pointer. bar is the index of the pci_dev.resources
181 * array and used to get the device base address of which the resource is
182 * associated with.
183 */
184#define RES2DEV(res) ((struct pci_dev *) \
185 ((uintptr_t)res - (uintptr_t)(res->bar * (sizeof(struct pci_res)))))
186
187/* Device flags */
188#define PCI_DEV_BRIDGE 0x01 /* Device is a Bridge (struct pci_bus) */
189#define PCI_DEV_RES_FAIL 0x02 /* Resource alloction for device BARs failed */
190
191/* Bus Flags */
192#define PCI_BUS_IO 0x01 /* 16-bit I/O address decoding */
193#define PCI_BUS_MEMIO 0x02 /* Bus support non-prefetchable mem (always) */
194#define PCI_BUS_MEM 0x04 /* Bus support prefetchable memory space */
195#define PCI_BUS_IO32 0x08 /* 32-bit I/O address decoding */
196
197#define BRIDGE_RES_COUNT 2 /* Number of BAR resources a bridge can have */
198#define BUS_RES_START BRIDGE_RES_COUNT
199
200/* Bus Resources Array */
201enum {
202 BUS_RES_IO = 0,
203 BUS_RES_MEMIO = 1,
204 BUS_RES_MEM = 2,
205};
206
207/* Device Resource array index meaning */
208enum {
209 /* A Device has up to 6 BARs and an optional ROM BAR */
210 DEV_RES_BAR1 = 0,
211 DEV_RES_BAR2 = 1,
212 DEV_RES_BAR3 = 2,
213 DEV_RES_BAR4 = 3,
214 DEV_RES_BAR5 = 4,
215 DEV_RES_BAR6 = 5,
216 DEV_RES_ROM = 6,
217
218 /* Bridges have 2 BARs (BAR1 and BAR2) and 3 Windows to secondary bus
219 * and an optional ROM BAR
220 */
221 BRIDGE_RES_BAR1 = 0,
222 BRIDGE_RES_BAR2 = 1,
223 BRIDGE_RES_IO = 2,
224 BRIDGE_RES_MEMIO = 3,
225 BRIDGE_RES_MEM = 4,
226 BRIDGE_RES_UNUSED1 = 5,
227 BRIDGE_RES_ROM = 6,
228};
229
230/* Maximum Number of Resources of a device */
231#define DEV_RES_CNT (DEV_RES_ROM + 1)
232
233/* PCI Device (Bus|Slot|Function) description */
234struct pci_dev {
235 struct pci_res resources[DEV_RES_CNT]; /* must be topmost field */
236 struct pci_dev *next;
237 struct pci_bus *bus;
238 pci_dev_t busdevfun;
239 uint8_t flags;
240 uint8_t sysirq;
241 uint16_t vendor;
242 uint16_t device;
243 uint16_t subvendor;
244 uint16_t subdevice;
245 uint32_t classrev;
246
247 /* static configuration settings */
248 uint16_t command;
249};
250
251/* PCI Bus description */
252struct pci_bus {
253 struct pci_dev dev; /* PCI Bridge */
254 struct pci_dev *devs; /* Devices on child (secondary) Bus */
255 unsigned int flags;
256
257 /* Bridge Information */
258 int num; /* Bus number (0=Root-PCI-bus) */
259 int pri; /* Primary Bus Number */
260 int sord; /* Subordinate Buses (Child bus count) */
261
262#if defined(PCI_CFG_AUTO_LIB)
263 /* Resources of devices on bus. USED INTERNALLY IN AUTO-CFG LIBRARY.
264 *
265 * BUS_RES_IO = 0: I/O resources
266 * BUS_RES_MEMIO = 1: Prefetchable memory resources
267 * BUS_RES_MEM = 2: Non-Prefetchable memory resources
268 */
269 struct pci_res *busres[3];
270#endif
271};
272
273#include <pci/cfg_auto.h>
274#include <pci/cfg_static.h>
275#include <pci/cfg_read.h>
276#include <pci/cfg_peripheral.h>
277
278#endif
PCI Auto Configuration Library.
PCI Read Configuration Library.
Static PCI Auto Configuration Library.
Definition: deflate.c:114
Definition: pci.h:75
Definition: pci.h:41
Definition: cfg.h:168