XenevaOS
Loading...
Searching...
No Matches
pcie.h
Go to the documentation of this file.
1
30#ifndef __PCIE_H__
31#define __PCIE_H__
32
33#include <stdint.h>
34#include <stddef.h>
35#include <Hal/basicacpi.h>
36#include <Hal/hal.h>
37#if defined(__GNUC__) || defined(__clang__)
38#ifndef __cplusplus
39#include <stdbool.h>
40#endif
41#endif
42
43
44#define PCI_VENDOR_ID 0x00
45#define PCI_DEVICE_ID 0x02
46#define PCI_COMMAND 0x04
47#define PCI_STATUS 0x06
48#define PCI_REVISION_ID 0x08
49#define PCI_PROG_IF 0x09
50#define PCI_SUBCLASS 0x0a
51#define PCI_CLASS 0x0b
52#define PCI_CACHE_LINE_SIZE 0x0c
53#define PCI_LATENCY_TIMER 0x0d
54#define PCI_HEADER_TYPE 0x0e
55#define PCI_BIST 0x0f
56#define PCI_BAR0 0x10
57#define PCI_BAR1 0x14
58#define PCI_BAR2 0x18
59#define PCI_BAR3 0x1C
60#define PCI_BAR4 0x20
61#define PCI_BAR5 0x24
62#define PCI_CAPABILITIES_PTR 0x34
63#define PCI_INTERRUPT_LINE 0x3C
64#define PCI_INTERRUPT_PIN 0x3D
65
66#define PCI_MAX_BUS 0x20
67#define PCI_DEVICE_PER_BUS 32
68#define PCI_FUNCTION_PER_DEVICE 8
69
70/*
71 * Whether an ECAM window was located and mapped. The DCL PCI fabric
72 * (DCL/pci_shim.c) asks before it scans: on a board where no discovery
73 * mechanism was found, AuPCIEGetDevice() would fall through to the
74 * ACPI-MCFG path with nothing behind it, and the fabric's job is to find
75 * no devices there, not to fault looking for them.
76 */
77bool AuIsPCIeInitialized(void);
78
79
80/*
81 * How many bus numbers the located ECAM window actually covers, in the
82 * 1 MiB stride ECAM uses per bus; 0 when the window is unknown. The DCL
83 * PCI fabric bounds its scan by this: past the window, the addresses
84 * AuPCIEGetDevice() composes are not configuration space, and on a QEMU
85 * virt machine a scan that runs off the end enumerates RAM contents as
86 * if they were devices.
87 */
88extern int AuPCIEBusCount(void);
89
90
91/*
92* AuPCIEGetDevice -- gets a device address from its bus
93* dev and func
94* @param seg -- device segment
95* @param bus -- bus of the device
96* @param dev -- device number
97* @param func -- function number
98*/
99extern uint64_t AuPCIEGetDevice(uint16_t seg, int bus, int dev, int func);
100/*
101* AuPCIEAllocMSI -- Allocate MSI/MSI-X for interrupt
102* @todo -- MSIX not implemented yet
103* @param device -- PCIe device address
104* @param vector -- interrupt vector
105* @param bus -- PCIe device bus number
106* @param dev -- PCIe device dev number
107* @param func -- PCIe device function number
108*/
109AU_EXTERN AU_EXPORT bool AuPCIEAllocMSI(uint64_t device, size_t vector, int bus, int dev, int func);
110
111/*
112* AuPCIEScanClassIF -- scans and return pcie device with given class code and sub class code
113* @param classCode -- class code
114* @param subClassCode -- sub class code
115* @param bus -- address, where bus number will be stored
116* @param dev -- address, where device number will be stored
117* @param func -- address, where function number will be stored
118* @param progIf -- Programming interface
119*/
120AU_EXTERN AU_EXPORT uint64_t AuPCIEScanClassIF(uint8_t classCode, uint8_t subClassCode, uint8_t progIf, int *bus_, int *dev_, int *func_);
121
122/*
123* AuPCIEScanVendorDevice -- scans and return pcie device with given vendor id and device id
124* @param vendor -- vendor id
125* @param device -- device id
126* @param bus -- address, where bus number will be stored
127* @param dev -- address, where device number will be stored
128* @param func -- address, where function number will be stored
129*/
131
132/*
133* AuPCIEScanClass -- scans and return pcie device with given class code and sub class code
134* @param classCode -- class code
135* @param subClassCode -- sub class code
136* @param bus -- address, where bus number will be stored
137* @param dev -- address, where device number will be stored
138* @param func -- address, where function number will be stored
139*/
140AU_EXTERN AU_EXPORT uint64_t AuPCIEScanClass(uint8_t classCode, uint8_t subClassCode, int *bus_, int *dev_, int *func_);
141
142/*
143* AuPCIEWrite -- writes to a register
144* @param device -- device address
145* @param reg -- register
146* @param size -- size to read
147* @param bus -- bus num
148* @param dev -- device number
149* @param func -- func number
150*/
151AU_EXTERN AU_EXPORT void AuPCIEWrite(uint64_t device, int reg, uint32_t val, int bus, int dev, int func);
152
153/*
154* AuPCIERead -- reads a register from pci express
155* @param device -- device address
156* @param reg -- register to read
157* @param bus -- bus number
158* @param dev -- device number
159* @param func -- function number
160*/
161AU_EXTERN AU_EXPORT uint32_t AuPCIERead(uint64_t device, int reg, int bus, int dev, int func);
162
163/*
164* AuPCIERead64 -- reads in 64
165* @param device -- device address
166* @param reg -- register
167* @param size -- size to read
168* @param bus -- bus num
169* @param dev -- device number
170* @param func -- func number
171*/
172AU_EXTERN AU_EXPORT uint64_t AuPCIERead64(uint64_t device, int reg, int size, int bus, int dev, int func);
173
174
175// {@private use|
176AU_EXTERN AU_EXPORT void AuPCIEWrite64(uint64_t device, int reg, int size, uint64_t val, int bus, int dev, int func);
177
178/*
179* AuPCIEReadBAR -- resolves a BAR index to its mapped base address (handling
180* 32-bit, 64-bit and I/O BARs), optionally probing its size
181* @param device -- device address
182* @param bus -- bus number
183* @param dev -- device number
184* @param func -- function number
185* @param BAR -- BAR index (0-5)
186* @param barsz -- if non-null, receives the BAR's size in bytes
187*/
188AU_EXTERN AU_EXPORT uint64_t AuPCIEReadBAR(uint64_t device, uint16_t bus, uint16_t dev, uint16_t func, size_t BAR, size_t* barsz);
189#endif
#define AU_EXTERN
Definition aurora.h:54
#define AU_EXPORT
Definition aurora.h:40
unsigned int uint32_t
Definition acefiex.h:163
unsigned char uint8_t
Definition acefiex.h:161
COMPILER_DEPENDENT_UINT64 uint64_t
Definition acefiex.h:165
unsigned short int uint16_t
Definition acefiex.h:162
uint16_t vendor
Definition devhw.c:88
size_t size
Definition drm_bridge.h:1299
const struct device * dev
Definition drm_print.h:519
void AuPCIERead64(void)
void AuPCIEWrite(void)
void AuPCIEAllocMSI(void)
void AuPCIEScanClass(void)
void AuPCIERead(void)
void AuPCIEReadBAR(void)
void AuPCIEGetDevice(void)
AU_EXTERN AU_EXPORT uint64_t AuPCIEScanVendorDevice(uint16_t vendor, uint16_t device, int *bus_, int *dev_, int *func_)
AuPCIEScanVendorDevice – scans and return pcie device with given vendor id and device id.
Definition pcie.c:452
AU_EXTERN AU_EXPORT void AuPCIEWrite64(uint64_t device, int reg, int size, uint64_t val, int bus, int dev, int func)
Definition pcie.cpp:326
AU_EXTERN AU_EXPORT uint64_t AuPCIEScanClassIF(uint8_t classCode, uint8_t subClassCode, uint8_t progIf, int *bus_, int *dev_, int *func_)
AuPCIEScanClassIF – scans and return pcie device with given class code and sub class code.
Definition pcie.cpp:405
int AuPCIEBusCount(void)
Definition pcie.c:150
bool AuIsPCIeInitialized(void)
Definition pcie.c:140
Definition fs.h:255