RTEMS 6.1-rc1
pci_bus.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
9/*
10 * COPYRIGHT (c) 2008 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
35/* General part of drvmgr PCI Bus driver. The driver is typically
36 * initialized from the PCI host driver separating the host
37 * driver from the common parts in PCI drivers.
38 * The PCI library must be initialized before starting the
39 * PCI bus driver. The PCI library have set up BARs and
40 * assigned system IRQs for targets.
41 * This PCI bus driver rely on the PCI library (pci.c) for
42 * interrupt registeration (pci_interrupt_register) and PCI
43 * target set up.
44 */
45
46#ifndef __PCI_BUS_H__
47#define __PCI_BUS_H__
48
49#include <drvmgr/drvmgr.h>
50#include <pci.h>
51#include <pci/access.h>
52
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57/* PCI Driver ID generation (VENDOR: 16-bit, DEVICE: 16-bit) */
58#define DRIVER_PCI_ID(vendor, device) \
59 DRIVER_ID(DRVMGR_BUS_TYPE_PCI, \
60 ((((vendor) & 0xffff) << 16) | ((device) & 0xffff)))
61
62/* PCI Driver ID generation (CLASS: 24-bit) */
63#define DRIVER_PCI_CLASS(class) \
64 DRIVER_ID(DRVMGR_BUS_TYPE_PCI, ((1 << 32) | ((class) & 0xffffff)))
65
66/* PCI driver IDs (DRIVER_PCI_VENDOR_DEVICE or DRIVER_PCI_CLASS_NAME) */
67#define DRIVER_PCI_GAISLER_RASTAIO_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_IO)
68#define DRIVER_PCI_GAISLER_RASTATMTC_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_TMTC)
69#define DRIVER_PCI_GAISLER_GR701_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_701)
70#define DRIVER_PCI_GAISLER_RASTAADCDAC_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_ADCDAC)
71#define DRIVER_PCI_GAISLER_TMTC_1553_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_TMTC_1553)
72#define DRIVER_PCI_GAISLER_RASTA_SPW_ROUTER_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_SPW_RTR)
73#define DRIVER_PCI_GAISLER_LEON4_N2X_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_LEON4_N2X)
74#define DRIVER_PCI_GAISLER_CPCI_GR740_ID DRIVER_PCI_ID(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_CPCI_GR740)
75
76struct pci_dev_id {
77 uint16_t vendor;
78 uint16_t device;
79 uint16_t subvendor;
80 uint16_t subdevice;
81 uint32_t class; /* 24 lower bits */
82};
83
85 uint16_t vendor;
86 uint16_t device;
87 uint16_t subvendor;
88 uint16_t subdevice;
89 uint32_t class; /* 24 lower bits */
90 uint32_t class_mask; /* 24 lower bits */
91};
92#define PCIID_DEVVEND(vendor, device) \
93 {vendor, device, PCI_ID_ANY, PCI_ID_ANY, 0, 0}
94#define PCIID_END_TABLE {0, 0, 0, 0, 0, 0}
95
96enum {
97 /* A Device has up to 6 BARs and an optional ROM BAR */
98 PCIDEV_RES_BAR1 = 0,
99 PCIDEV_RES_BAR2 = 1,
100 PCIDEV_RES_BAR3 = 2,
101 PCIDEV_RES_BAR4 = 3,
102 PCIDEV_RES_BAR5 = 4,
103 PCIDEV_RES_BAR6 = 5,
104 PCIDEV_RES_ROM = 6,
105};
106/* Maximum Number of Resources of a device */
107#define PCIDEV_RES_CNT (PCIDEV_RES_ROM + 1)
108
109/* IO, MEMIO or MEM resource. Can be BAR, ROM or Bridge Window */
111 uint32_t address; /* Base Address, CPU accessible */
112 uint32_t size; /* 0=Unimplemented, 0!=Resource Size */
113 struct pci_res *res; /* PCI-layer resource */
114};
115
117 struct pci_dev_id id;
118 uint8_t rev;
119 uint8_t irq; /* 0 = NO IRQ */
120 pci_dev_t pcidev;
121 struct pcibus_res resources[PCIDEV_RES_CNT];
122 struct pci_dev *pci_device;
123};
124
126 struct drvmgr_drv general; /* General bus info */
127 /* PCI specific bus information */
128 struct pci_dev_id_match *ids; /* Supported hardware */
129};
130
131/* Access routines */
133 drvmgr_r8 r8;
134 drvmgr_r16 r16;
135 drvmgr_r32 r32;
136 drvmgr_r64 r64;
137 drvmgr_w8 w8;
138 drvmgr_w16 w16;
139 drvmgr_w32 w32;
140 drvmgr_w64 w64;
141};
142
143/* Let driver configure PCI bus driver */
145 struct drvmgr_map_entry *maps_up;
146 struct drvmgr_map_entry *maps_down;
147};
148
149/* PCI Configuration Space Access - Not implemented (use PCI Lib directly) */
150#define PCI_FUNC_CFG_R8 DRVMGR_RWFUNC(RW_SIZE_1|RW_READ|RW_CFG)
151#define PCI_FUNC_CFG_R16 DRVMGR_RWFUNC(RW_SIZE_2|RW_READ|RW_CFG)
152#define PCI_FUNC_CFG_R32 DRVMGR_RWFUNC(RW_SIZE_4|RW_READ|RW_CFG)
153#define PCI_FUNC_CFG_W8 DRVMGR_RWFUNC(RW_SIZE_1|RW_WRITE|RW_CFG)
154#define PCI_FUNC_CFG_W16 DRVMGR_RWFUNC(RW_SIZE_2|RW_WRITE|RW_CFG)
155#define PCI_FUNC_CFG_W32 DRVMGR_RWFUNC(RW_SIZE_4|RW_WRITE|RW_CFG)
156
157/* PCI I/O Register Access - Not implemented (use PCI Lib directly) */
158#define PCI_FUNC_IO_R8 DRVMGR_RWFUNC(RW_SIZE_1|RW_READ|RW_IO)
159#define PCI_FUNC_IO_R16 DRVMGR_RWFUNC(RW_SIZE_2|RW_READ|RW_IO)
160#define PCI_FUNC_IO_R32 DRVMGR_RWFUNC(RW_SIZE_4|RW_READ|RW_IO)
161#define PCI_FUNC_IO_W8 DRVMGR_RWFUNC(RW_SIZE_1|RW_WRITE|RW_IO)
162#define PCI_FUNC_IO_W16 DRVMGR_RWFUNC(RW_SIZE_2|RW_WRITE|RW_IO)
163#define PCI_FUNC_IO_W32 DRVMGR_RWFUNC(RW_SIZE_4|RW_WRITE|RW_IO)
164
165/* PCI Register Access over Memory Space (Little Endian) */
166#define PCI_FUNC_MREG_R8 DRVMGR_RWFUNC(RW_SIZE_1|RW_READ|RW_MEMREG)
167#define PCI_FUNC_MREG_R16 DRVMGR_RWFUNC(RW_SIZE_2|RW_READ|RW_MEMREG|RW_LITTLE)
168#define PCI_FUNC_MREG_R32 DRVMGR_RWFUNC(RW_SIZE_4|RW_READ|RW_MEMREG|RW_LITTLE)
169#define PCI_FUNC_MREG_W8 DRVMGR_RWFUNC(RW_SIZE_1|RW_WRITE|RW_MEMREG)
170#define PCI_FUNC_MREG_W16 DRVMGR_RWFUNC(RW_SIZE_2|RW_WRITE|RW_MEMREG|RW_LITTLE)
171#define PCI_FUNC_MREG_W32 DRVMGR_RWFUNC(RW_SIZE_4|RW_WRITE|RW_MEMREG|RW_LITTLE)
172
173/* Weak default PCI driver resources, override this from project configuration
174 * to set PCI Bus resources used to configure PCI device drivers.
175 */
176extern struct drvmgr_bus_res pcibus_drv_resources;
177
178/* Attach a PCI bus on top of a PCI Host device */
179extern int pcibus_register(struct drvmgr_dev *dev, struct pcibus_config *cfg);
180
181#ifdef __cplusplus
182}
183#endif
184
185#endif
Driver Manager Interface.
PCI Access Methods.
Definition: drvmgr.h:238
Definition: drvmgr.h:297
Definition: drvmgr.h:327
Definition: drvmgr.h:249
Definition: pci_bus.h:84
Definition: pci_bus.h:76
Definition: pci_bus.h:116
Definition: pci.h:41
Definition: pci_bus.h:125
Definition: cfg.h:168
Definition: pci_bus.h:144
Definition: pci_bus.h:132
Definition: pci_bus.h:110