XenevaOS
Loading...
Searching...
No Matches
Macros | Enumerations | Functions | Variables
pcie.c File Reference
#include <pcie.h>
#include <string.h>
#include <stdint.h>
#include <dtb.h>
#include <aucon.h>
#include <Hal/AA64/qemu.h>
#include <Hal/AA64/gic.h>
#include <Mm/vmmngr.h>
#include <kernelAA64.h>
#include <Hal/basicacpi.h>
#include <Hal/AA64/aa64lowlevel.h>
#include <Drivers/uart.h>
Include dependency graph for pcie.c:

Macros

#define PCI_MEM_BAR_TYPE(x)   ((x >>1) & 0x3)
 
#define PCI_IS_IO_BAR(x)   ((x & 1) != 0)
 
#define INTERNAL_PCI_REG_BAR0   0x4
 

Enumerations

enum  PCI_MEM_BAR_TYPES { MEMBAR32 , RESERVED , MEMBAR64 }
 

Functions

void AA64PCIeInitialize ()
 AA64PCIeInitialize – intialize pcie subsystem.
 
bool AuIsPCIeInitialized ()
 
uint64_t AuPCIEGetDevice (uint16_t seg, int bus, int dev, int func)
 AuPCIEGetDevice – gets a device address from its bus dev and func.
 
uint32_t AuPCIERead (uint64_t device, int reg, int bus, int dev, int func)
 AuPCIERead – reads a register from pci express.
 
uint64_t AuPCIERead64 (uint64_t device, int reg, int size, int bus, int dev, int func)
 AuPCIERead64 – reads in 64.
 
void AuPCIEWrite (uint64_t device, int reg, uint32_t val, int bus, int dev, int func)
 AuPCIEWrite – writes to a register.
 
void AuPCIEWrite64 (uint64_t device, int reg, int size, uint64_t val, int bus, int dev, int func)
 
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.
 
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.
 
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.
 
uint64_t AuPCIEReadBAR (uint64_t device, uint16_t bus, uint16_t dev, uint16_t func, size_t BAR, size_t *barsz)
 
bool AuPCIEAllocMSI (uint64_t device, size_t vector, int bus, int dev, int func)
 AuPCIEAllocMSI – Allocate MSI/MSI-X for interrupt.
 

Variables

uint64_t _ecamAddress
 
bool _pcieInitialized
 

Detailed Description

BSD 2-Clause License

Copyright (c) 2022-2025, 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.

Macro Definition Documentation

◆ INTERNAL_PCI_REG_BAR0

#define INTERNAL_PCI_REG_BAR0   0x4

◆ PCI_IS_IO_BAR

#define PCI_IS_IO_BAR (   x)    ((x & 1) != 0)

◆ PCI_MEM_BAR_TYPE

#define PCI_MEM_BAR_TYPE (   x)    ((x >>1) & 0x3)

Enumeration Type Documentation

◆ PCI_MEM_BAR_TYPES

Enumerator
MEMBAR32 
RESERVED 
MEMBAR64 

Function Documentation

◆ AA64PCIeInitialize()

void AA64PCIeInitialize ( )

AA64PCIeInitialize – intialize pcie subsystem.

AA64PCIeInitialize – intialize pcie controller.

◆ AuIsPCIeInitialized()

bool AuIsPCIeInitialized ( )

◆ AuPCIEAllocMSI()

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 
)

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

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

◆ AuPCIERead()

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()

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

◆ AuPCIEReadBAR()

uint64_t AuPCIEReadBAR ( uint64_t  device,
uint16_t  bus,
uint16_t  dev,
uint16_t  func,
size_t  BAR,
size_t barsz 
)

◆ AuPCIEScanClass()

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()

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()

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()

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()

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

Variable Documentation

◆ _ecamAddress

uint64_t _ecamAddress

◆ _pcieInitialized

bool _pcieInitialized