XenevaOS
Loading...
Searching...
No Matches
Macros | Functions
pcie.h File Reference
#include <stdint.h>
#include <Hal\basicacpi.h>
#include <Hal\hal.h>
Include dependency graph for pcie.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define PCI_VENDOR_ID   0x00
 
#define PCI_DEVICE_ID   0x02
 
#define PCI_COMMAND   0x04
 
#define PCI_STATUS   0x06
 
#define PCI_REVISION_ID   0x08
 
#define PCI_PROG_IF   0x09
 
#define PCI_SUBCLASS   0x0a
 
#define PCI_CLASS   0x0b
 
#define PCI_CACHE_LINE_SIZE   0x0c
 
#define PCI_LATENCY_TIMER   0x0d
 
#define PCI_HEADER_TYPE   0x0e
 
#define PCI_BIST   0x0f
 
#define PCI_BAR0   0x10
 
#define PCI_BAR1   0x14
 
#define PCI_BAR2   0x18
 
#define PCI_BAR3   0x1C
 
#define PCI_BAR4   0x20
 
#define PCI_BAR5   0x24
 
#define PCI_CAPABILITIES_PTR   0x34
 
#define PCI_INTERRUPT_LINE   0x3C
 
#define PCI_INTERRUPT_PIN   0x3D
 
#define PCI_MAX_BUS   0x20
 
#define PCI_DEVICE_PER_BUS   32
 
#define PCI_FUNCTION_PER_DEVICE   8
 

Functions

uint64_t AuPCIEGetDevice (uint16_t seg, int bus, int dev, int func)
 AuPCIEGetDevice – gets a device address from its bus dev and func.
 
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.
 
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.
 
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.
 
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.
 
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.
 
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.
 
AU_EXTERN AU_EXPORT uint64_t AuPCIERead64 (uint64_t device, int reg, int size, int bus, int dev, int func)
 AuPCIERead64 – reads in 64.
 
AU_EXTERN AU_EXPORT void AuPCIEWrite64 (uint64_t device, int reg, int size, uint64_t val, int bus, int dev, int func)
 

Macro Definition Documentation

◆ PCI_BAR0

#define PCI_BAR0   0x10

◆ PCI_BAR1

#define PCI_BAR1   0x14

◆ PCI_BAR2

#define PCI_BAR2   0x18

◆ PCI_BAR3

#define PCI_BAR3   0x1C

◆ PCI_BAR4

#define PCI_BAR4   0x20

◆ PCI_BAR5

#define PCI_BAR5   0x24

◆ PCI_BIST

#define PCI_BIST   0x0f

◆ PCI_CACHE_LINE_SIZE

#define PCI_CACHE_LINE_SIZE   0x0c

◆ PCI_CAPABILITIES_PTR

#define PCI_CAPABILITIES_PTR   0x34

◆ PCI_CLASS

#define PCI_CLASS   0x0b

◆ PCI_COMMAND

#define PCI_COMMAND   0x04

◆ PCI_DEVICE_ID

#define PCI_DEVICE_ID   0x02

◆ PCI_DEVICE_PER_BUS

#define PCI_DEVICE_PER_BUS   32

◆ PCI_FUNCTION_PER_DEVICE

#define PCI_FUNCTION_PER_DEVICE   8

◆ PCI_HEADER_TYPE

#define PCI_HEADER_TYPE   0x0e

◆ PCI_INTERRUPT_LINE

#define PCI_INTERRUPT_LINE   0x3C

◆ PCI_INTERRUPT_PIN

#define PCI_INTERRUPT_PIN   0x3D

◆ PCI_LATENCY_TIMER

#define PCI_LATENCY_TIMER   0x0d

◆ PCI_MAX_BUS

#define PCI_MAX_BUS   0x20

◆ PCI_PROG_IF

#define PCI_PROG_IF   0x09

◆ PCI_REVISION_ID

#define PCI_REVISION_ID   0x08

◆ PCI_STATUS

#define PCI_STATUS   0x06

◆ PCI_SUBCLASS

#define PCI_SUBCLASS   0x0a

◆ PCI_VENDOR_ID

#define PCI_VENDOR_ID   0x00

BSD 2-Clause License

Copyright (c) 2022-2023, Manas Kamal Choudhury All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

◆ AuPCIEAllocMSI()

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.

Todo:
– MSIX not implemented yet
Parameters
device– PCIe device address
vector– interrupt vector
bus– PCIe device bus number
dev– PCIe device dev number
func– PCIe device function number

◆ AuPCIEGetDevice()

uint64_t AuPCIEGetDevice ( uint16_t  seg,
int  bus,
int  dev,
int  func 
)
extern

AuPCIEGetDevice – gets a device address from its bus dev and func.

BSD 2-Clause License

Copyright (c) 2022-2023, Manas Kamal Choudhury All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Parameters
seg– device segment
bus– bus of the device
dev– device number
func– function number
Returns
return the composited device address

◆ AuPCIERead()

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.

Parameters
device– device address
reg– register to read
bus– bus number
dev– device number
func– function number
Returns
return the result in DWORD

◆ AuPCIERead64()

AU_EXTERN AU_EXPORT uint64_t AuPCIERead64 ( uint64_t  device,
int  reg,
int  size,
int  bus,
int  dev,
int  func 
)

AuPCIERead64 – reads in 64.

Parameters
device– device address
reg– register
size– size to read
bus– bus num
dev– device number
func– func number
Returns
return the read result in QWORD

◆ AuPCIEScanClass()

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.

Parameters
classCode– class code
subClassCode– sub class code
bus– address, where bus number will be stored
dev– address, where device number will be stored
func– address, where function number will be stored

◆ AuPCIEScanClassIF()

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.

Parameters
classCode– class code
subClassCode– sub class code
bus– address, where bus number will be stored
dev– address, where device number will be stored
func– address, where function number will be stored
progIf– Programming interface
Returns
pcie device address

◆ AuPCIEScanVendorDevice()

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.

Parameters
vendor– vendor id
device– device id
bus– address, where bus number will be stored
dev– address, where device number will be stored
func– address, where function number will be stored

◆ AuPCIEWrite()

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.

Parameters
device– device address
reg– register
size– size to read
bus– bus num
dev– device number
func– func number

◆ AuPCIEWrite64()

AU_EXTERN AU_EXPORT void AuPCIEWrite64 ( uint64_t  device,
int  reg,
int  size,
uint64_t  val,
int  bus,
int  dev,
int  func 
)