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/*
72* AuPCIEGetDevice -- gets a device address from its bus
73* dev and func
74* @param seg -- device segment
75* @param bus -- bus of the device
76* @param dev -- device number
77* @param func -- function number
78*/
79extern uint64_t AuPCIEGetDevice(uint16_t seg, int bus, int dev, int func);
80/*
81* AuPCIEAllocMSI -- Allocate MSI/MSI-X for interrupt
82* @todo -- MSIX not implemented yet
83* @param device -- PCIe device address
84* @param vector -- interrupt vector
85* @param bus -- PCIe device bus number
86* @param dev -- PCIe device dev number
87* @param func -- PCIe device function number
88*/
89AU_EXTERN AU_EXPORT bool AuPCIEAllocMSI(uint64_t device, size_t vector, int bus, int dev, int func);
90
91/*
92* AuPCIEScanClassIF -- scans and return pcie device with given class code and sub class code
93* @param classCode -- class code
94* @param subClassCode -- sub class code
95* @param bus -- address, where bus number will be stored
96* @param dev -- address, where device number will be stored
97* @param func -- address, where function number will be stored
98* @param progIf -- Programming interface
99*/
100AU_EXTERN AU_EXPORT uint64_t AuPCIEScanClassIF(uint8_t classCode, uint8_t subClassCode, uint8_t progIf, int *bus_, int *dev_, int *func_);
101
102/*
103* AuPCIEScanVendorDevice -- scans and return pcie device with given vendor id and device id
104* @param vendor -- vendor id
105* @param device -- device id
106* @param bus -- address, where bus number will be stored
107* @param dev -- address, where device number will be stored
108* @param func -- address, where function number will be stored
109*/
110AU_EXTERN AU_EXPORT uint64_t AuPCIEScanVendorDevice(uint16_t vendor, uint16_t device, int* bus_, int* dev_, int* func_);
111
112/*
113* AuPCIEScanClass -- scans and return pcie device with given class code and sub class code
114* @param classCode -- class code
115* @param subClassCode -- sub class code
116* @param bus -- address, where bus number will be stored
117* @param dev -- address, where device number will be stored
118* @param func -- address, where function number will be stored
119*/
120AU_EXTERN AU_EXPORT uint64_t AuPCIEScanClass(uint8_t classCode, uint8_t subClassCode, int *bus_, int *dev_, int *func_);
121
122/*
123* AuPCIEWrite -- writes to a register
124* @param device -- device address
125* @param reg -- register
126* @param size -- size to read
127* @param bus -- bus num
128* @param dev -- device number
129* @param func -- func number
130*/
131AU_EXTERN AU_EXPORT void AuPCIEWrite(uint64_t device, int reg, uint32_t val, int bus, int dev, int func);
132
133/*
134* AuPCIERead -- reads a register from pci express
135* @param device -- device address
136* @param reg -- register to read
137* @param bus -- bus number
138* @param dev -- device number
139* @param func -- function number
140*/
141AU_EXTERN AU_EXPORT uint32_t AuPCIERead(uint64_t device, int reg, int bus, int dev, int func);
142
143/*
144* AuPCIERead64 -- reads in 64
145* @param device -- device address
146* @param reg -- register
147* @param size -- size to read
148* @param bus -- bus num
149* @param dev -- device number
150* @param func -- func number
151*/
152AU_EXTERN AU_EXPORT uint64_t AuPCIERead64(uint64_t device, int reg, int size, int bus, int dev, int func);
153
154
155// {@private use|
156AU_EXTERN AU_EXPORT void AuPCIEWrite64(uint64_t device, int reg, int size, uint64_t val, int bus, int dev, int func);
157
158/*
159* AuPCIEReadBAR -- resolves a BAR index to its mapped base address (handling
160* 32-bit, 64-bit and I/O BARs), optionally probing its size
161* @param device -- device address
162* @param bus -- bus number
163* @param dev -- device number
164* @param func -- function number
165* @param BAR -- BAR index (0-5)
166* @param barsz -- if non-null, receives the BAR's size in bytes
167*/
168AU_EXTERN AU_EXPORT uint64_t AuPCIEReadBAR(uint64_t device, uint16_t bus, uint16_t dev, uint16_t func, size_t BAR, size_t* barsz);
169#endif
#define AU_EXTERN
Definition aurora.h:55
#define AU_EXPORT
Definition aurora.h:41
AuUSBDeviceStruc * device
Definition main.cpp:148
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
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:431
AU_EXTERN AU_EXPORT uint64_t AuPCIEReadBAR(uint64_t device, uint16_t bus, uint16_t dev, uint16_t func, size_t BAR, size_t *barsz)
Definition pcie.c:500
uint64_t AuPCIEGetDevice(uint16_t seg, int bus, int dev, int func)
AuPCIEGetDevice – gets a device address from its bus dev and func.
Definition pcie.cpp:44
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 AuPCIERead64(uint64_t device, int reg, int size, int bus, int dev, int func)
AuPCIERead64 – reads in 64.
Definition pcie.cpp:183
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
AU_EXTERN AU_EXPORT bool AuPCIEAllocMSI(uint64_t device, size_t vector, int bus, int dev, int func)
AuPCIEAllocMSI – Allocate MSI/MSI-X for interrupt.
Definition pcie.cpp:454
AU_EXTERN AU_EXPORT void AuPCIEWrite(uint64_t device, int reg, uint32_t val, int bus, int dev, int func)
AuPCIEWrite – writes to a register.
Definition pcie.cpp:226
AU_EXTERN AU_EXPORT uint64_t AuPCIEScanClass(uint8_t classCode, uint8_t subClassCode, int *bus_, int *dev_, int *func_)
AuPCIEScanClass – scans and return pcie device with given class code and sub class code.
Definition pcie.cpp:358
AU_EXTERN AU_EXPORT uint32_t AuPCIERead(uint64_t device, int reg, int bus, int dev, int func)
AuPCIERead – reads a register from pci express.
Definition pcie.cpp:72