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 <Hal/basicacpi.h>
35#include <Hal/hal.h>
36#if defined(__GNUC__) || defined(__clang__)
37#ifndef __cplusplus
38#include <stdbool.h>
39#endif
40#endif
41
42
43#define PCI_VENDOR_ID 0x00
44#define PCI_DEVICE_ID 0x02
45#define PCI_COMMAND 0x04
46#define PCI_STATUS 0x06
47#define PCI_REVISION_ID 0x08
48#define PCI_PROG_IF 0x09
49#define PCI_SUBCLASS 0x0a
50#define PCI_CLASS 0x0b
51#define PCI_CACHE_LINE_SIZE 0x0c
52#define PCI_LATENCY_TIMER 0x0d
53#define PCI_HEADER_TYPE 0x0e
54#define PCI_BIST 0x0f
55#define PCI_BAR0 0x10
56#define PCI_BAR1 0x14
57#define PCI_BAR2 0x18
58#define PCI_BAR3 0x1C
59#define PCI_BAR4 0x20
60#define PCI_BAR5 0x24
61#define PCI_CAPABILITIES_PTR 0x34
62#define PCI_INTERRUPT_LINE 0x3C
63#define PCI_INTERRUPT_PIN 0x3D
64
65#define PCI_MAX_BUS 0x20
66#define PCI_DEVICE_PER_BUS 32
67#define PCI_FUNCTION_PER_DEVICE 8
68
69
70/*
71* AuPCIEGetDevice -- gets a device address from its bus
72* dev and func
73* @param seg -- device segment
74* @param bus -- bus of the device
75* @param dev -- device number
76* @param func -- function number
77*/
78extern uint64_t AuPCIEGetDevice(uint16_t seg, int bus, int dev, int func);
79/*
80* AuPCIEAllocMSI -- Allocate MSI/MSI-X for interrupt
81* @todo -- MSIX not implemented yet
82* @param device -- PCIe device address
83* @param vector -- interrupt vector
84* @param bus -- PCIe device bus number
85* @param dev -- PCIe device dev number
86* @param func -- PCIe device function number
87*/
88AU_EXTERN AU_EXPORT bool AuPCIEAllocMSI(uint64_t device, size_t vector, int bus, int dev, int func);
89
90/*
91* AuPCIEScanClassIF -- scans and return pcie device with given class code and sub class code
92* @param classCode -- class code
93* @param subClassCode -- sub class code
94* @param bus -- address, where bus number will be stored
95* @param dev -- address, where device number will be stored
96* @param func -- address, where function number will be stored
97* @param progIf -- Programming interface
98*/
99AU_EXTERN AU_EXPORT uint64_t AuPCIEScanClassIF(uint8_t classCode, uint8_t subClassCode, uint8_t progIf, int *bus_, int *dev_, int *func_);
100
101/*
102* AuPCIEScanVendorDevice -- scans and return pcie device with given vendor id and device id
103* @param vendor -- vendor id
104* @param device -- device id
105* @param bus -- address, where bus number will be stored
106* @param dev -- address, where device number will be stored
107* @param func -- address, where function number will be stored
108*/
109AU_EXTERN AU_EXPORT uint64_t AuPCIEScanVendorDevice(uint16_t vendor, uint16_t device, int* bus_, int* dev_, int* func_);
110
111/*
112* AuPCIEScanClass -- 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*/
119AU_EXTERN AU_EXPORT uint64_t AuPCIEScanClass(uint8_t classCode, uint8_t subClassCode, int *bus_, int *dev_, int *func_);
120
121/*
122* AuPCIEWrite -- writes to a register
123* @param device -- device address
124* @param reg -- register
125* @param size -- size to read
126* @param bus -- bus num
127* @param dev -- device number
128* @param func -- func number
129*/
130AU_EXTERN AU_EXPORT void AuPCIEWrite(uint64_t device, int reg, uint32_t val, int bus, int dev, int func);
131
132/*
133* AuPCIERead -- reads a register from pci express
134* @param device -- device address
135* @param reg -- register to read
136* @param bus -- bus number
137* @param dev -- device number
138* @param func -- function number
139*/
140AU_EXTERN AU_EXPORT uint32_t AuPCIERead(uint64_t device, int reg, int bus, int dev, int func);
141
142/*
143* AuPCIERead64 -- reads in 64
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 uint64_t AuPCIERead64(uint64_t device, int reg, int size, int bus, int dev, int func);
152
153
154// {@private use|
155AU_EXTERN AU_EXPORT void AuPCIEWrite64(uint64_t device, int reg, int size, uint64_t val, int bus, int dev, int func);
156#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:456
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