XenevaOS
Loading...
Searching...
No Matches
Macros | Functions | Variables
audrv.c File Reference
#include <audrv.h>
#include <aucomponent.h>
#include <Cred/group.h>
#include <aubuiltin.h>
#include <Fs/Dev/devhw.h>
#include <Fs/Dev/devgpu.h>
#include <Sound/sndproxy.h>
#include <Net/netproxy.h>
#include <austatic.h>
#include <Ipc/auipc.h>
#include <Fs/srvfs.h>
#include <Hal/AA64/gic.h>
#include <Mm/pmmngr.h>
#include <Mm/vmmngr.h>
#include <string.h>
#include <pe.h>
#include <stdio.h>
#include <Mm/kmalloc.h>
#include <pcie.h>
#include <aucon.h>
#include <Drivers/uart.h>
#include <Fs/Dev/devfs.h>
#include <Sound/sound.h>
Include dependency graph for audrv.c:

Macros

#define AU_DRIVER_BASE_START   0xFFFFC00000A00000
 0xFFFFC00000400000 - 0xFFFFC00000A00000 – Kernel Boot Drivers 0xFFFFC00000A00000 - Kernel Runtime Drivers
 
#define AU_MAX_SUPPORTED_DEVICE   256
 
#define AU_DRV_MAX_FREE_REGIONS   64
 
#define AU_CALLER_DRIVER()   AuDriverOwnerOf((uint64_t)__builtin_return_address(0))
 

Functions

uint32_t AuRequestDriverId ()
 request an unique id for driver class
 
uint32_t AuRequestBootDriverId ()
 
void AuDecreaseDriverCount ()
 AuDecreaseDriverCount – decrease the number of device count.
 
void AuIncreaseDriverCount ()
 AuIncreaseDriverCount – increase the number of device count.
 
char * AuGetConfEntry (uint32_t vendor_id, uint32_t device_id, uint8_t *buffer, int entryoff)
 AuGetConfEntry – Get an entry offset in the file for required device.
 
AuDriver * AuCreateDriverInstance (char *drivername)
 AuCreateDriverInstance – creates a new driver slot.
 
AuDriver * AuCreateBootDriverInstance (char *drivername)
 AuCreateDriverInstance – creates a new driver slot.
 
AuDriver * AuGetDriverName (uint32_t vendor_id, uint32_t device_id, uint8_t *buffer, int entryoff)
 AuGetDriverName – Extract the driver path from its entry offset.
 
void AuBoardIterateModule (uint8_t *board, int moduleCount)
 AuBoardIterateModule – iterate all modules present in board config file.
 
void AuDriverLoad (char *filename, AuDriver *driver)
 AuDriverLoad – Manage and loads dll drivers.
 
bool AuIsPCIeInitialized ()
 
int FontManagerGetFontCount (uint8_t *buffer)
 FontManagerGetFontCount – returns number of font counts.
 
void AuDrvMngrInitialize (KERNEL_BOOT_INFO *info)
 AuDrvMngrInitialize – Initialize the driver manager.
 
AU_EXTERN AU_EXPORT void AuRegisterDevice (AuDevice *dev)
 AuRegisterDevice – register a new device to aurora system.
 
AU_EXTERN AU_EXPORT bool AuCheckDevice (uint16_t classC, uint16_t subclassC, uint8_t progIF)
 AuCheckDevice – checks an aurora device if it's already present.
 
void AuBootDriverLoad (void *driverBuffer, AuDriver *driver)
 AuBootDriverLoad – loads all boot drivers.
 
AU_EXTERN AU_EXPORT void AuBootDriverInitialise (KERNEL_BOOT_INFO *info)
 AuBootDriverInitialise – Initialise and load all boot time drivers.
 
uint64_t AuDrvMgrGetBaseAddress ()
 AuDrvMgrGetBaseAddress – returns the current driver load base address.
 
void AuDrvMgrSetBaseAddress (uint64_t base_address)
 AuDrvMgrSetBaseAddress – sets a new base address for driver to load it's highly risky because, if we set it to kernel stack location, kernel will crash.
 
AuDriver * AuDrvManagerCheckFault (uint64_t fault_addr)
 AuDrvManagerCheckFault – check if this driver contain the fault address, helpful for debugging.
 
void AuDrvCatchFault (AuDriver *drv, uint64_t fault_addr)
 AuDrvCatchFault – resolves original virtual address of the driver and relocate its symbol name.
 
void AuDrvUnloadAll ()
 AuDrvUnloadAll – call unload handler of all registered drivers.
 
AuDriver * AuDriverOwnerOf (uint64_t addr)
 AuDriverOwnerOf – the loaded driver whose image contains addr.
 
AuDriver * AuDriverFindByName (const char *name)
 
int AuDriverRef (AuDriver *drv)
 
void AuDriverUnref (AuDriver *drv)
 
void AuDriverTrack (AuDriver *drv, uint8_t kind, uint64_t value, uint64_t extra, uint64_t extra2)
 
void AuDriverUntrack (AuDriver *drv, uint8_t kind, uint64_t value)
 
void AuDriverUntrackAny (uint8_t kind, uint64_t value)
 
 __attribute__ ((noinline))
 
void * AuDriverImportOverride (const char *name)
 AuGetProcAddress – get procedure address in a dll image.
 
int AuDriverUnload (AuDriver *drv)
 AuDriverUnload – unload a running driver.
 
int AuDriverUnloadByName (const char *name)
 
int AuDriverLoadByName (const char *name)
 AuDriverLoadByName – (re)load a driver that is not currently loaded, then run its AuDriverMain. Returns 0 on success.
 
bool AuDriverClaimsPci (int bus, int dev, int func)
 
void AuDriverCtlInitialize (void)
 

Variables

AuDriver * drivers [246]
 
AuDriver * bootDrivers [10]
 
AuDevice * au_devices [AU_MAX_SUPPORTED_DEVICE]
 
uint64_t * scratchBuffer
 

Detailed Description

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.

Macro Definition Documentation

◆ AU_CALLER_DRIVER

#define AU_CALLER_DRIVER ( )    AuDriverOwnerOf((uint64_t)__builtin_return_address(0))

◆ AU_DRIVER_BASE_START

#define AU_DRIVER_BASE_START   0xFFFFC00000A00000

0xFFFFC00000400000 - 0xFFFFC00000A00000 – Kernel Boot Drivers 0xFFFFC00000A00000 - Kernel Runtime Drivers

@TODO: Implement UEFI based pcie discovery mechanism and fix AuBootDriverLoad

◆ AU_DRV_MAX_FREE_REGIONS

#define AU_DRV_MAX_FREE_REGIONS   64

◆ AU_MAX_SUPPORTED_DEVICE

#define AU_MAX_SUPPORTED_DEVICE   256

Function Documentation

◆ __attribute__()

__attribute__ ( (noinline)  )

◆ AuBoardIterateModule()

void AuBoardIterateModule ( uint8_t *  board,
int  moduleCount 
)

AuBoardIterateModule – iterate all modules present in board config file.

Parameters
board– pointer to board config buffer
moduleCount– total number of module described

◆ AuBootDriverInitialise()

AU_EXTERN AU_EXPORT void AuBootDriverInitialise ( KERNEL_BOOT_INFO *  info)

AuBootDriverInitialise – Initialise and load all boot time drivers.

Parameters
info– Kernel boot information passed by XNLDR [TODO] : Everything is hard coded for now

◆ AuBootDriverLoad()

void AuBootDriverLoad ( void *  driverBuffer,
AuDriver *  driver 
)

AuBootDriverLoad – loads all boot drivers.

Parameters
driverBuffer- Pointer to driver location in memory
driver– Pointer to aurora driver structure

◆ AuCheckDevice()

AU_EXTERN AU_EXPORT bool AuCheckDevice ( uint16_t  classC,
uint16_t  subclassC,
uint8_t  progIF 
)

AuCheckDevice – checks an aurora device if it's already present.

Parameters
classC– class code of the device to check
subclassC– sub class code of the device to check
progIF– programming interface of the device

◆ AuCreateBootDriverInstance()

AuDriver * AuCreateBootDriverInstance ( char *  drivername)

AuCreateDriverInstance – creates a new driver slot.

Parameters
drivername– name of the driver

◆ AuCreateDriverInstance()

AuDriver * AuCreateDriverInstance ( char *  drivername)

AuCreateDriverInstance – creates a new driver slot.

Parameters
drivername– name of the driver

◆ AuDecreaseDriverCount()

void AuDecreaseDriverCount ( )

AuDecreaseDriverCount – decrease the number of device count.

◆ AuDriverClaimsPci()

bool AuDriverClaimsPci ( int  bus,
int  dev,
int  func 
)

◆ AuDriverCtlInitialize()

void AuDriverCtlInitialize ( void  )

◆ AuDriverFindByName()

AuDriver * AuDriverFindByName ( const char *  name)

◆ AuDriverImportOverride()

void * AuDriverImportOverride ( const char *  name)

AuGetProcAddress – get procedure address in a dll image.

Parameters
image– dll image
procname– procedure name
Returns
return the procedure address in memory

◆ AuDriverLoad()

void AuDriverLoad ( char *  filename,
AuDriver *  driver 
)

AuDriverLoad – Manage and loads dll drivers.

Parameters
filename– file path
driver– driver instance

◆ AuDriverLoadByName()

int AuDriverLoadByName ( const char *  name)

AuDriverLoadByName – (re)load a driver that is not currently loaded, then run its AuDriverMain. Returns 0 on success.

◆ AuDriverOwnerOf()

AuDriver * AuDriverOwnerOf ( uint64_t  addr)

AuDriverOwnerOf – the loaded driver whose image contains addr.

◆ AuDriverRef()

int AuDriverRef ( AuDriver *  drv)

◆ AuDriverTrack()

void AuDriverTrack ( AuDriver *  drv,
uint8_t  kind,
uint64_t  value,
uint64_t  extra,
uint64_t  extra2 
)

◆ AuDriverUnload()

int AuDriverUnload ( AuDriver *  drv)

AuDriverUnload – unload a running driver.

Order matters: ask the driver first (it may veto), then cut every kernel -> driver path BEFORE the image is unmapped: IRQ handlers are cleared and the driver's MMIO mappings removed. Physical pages the driver still owns are only REPORTED, never force-freed: the kernel may have taken them over without telling the ledger, and a leak is safe where a double free is not. Returns an AU_UNLOAD_* code.

◆ AuDriverUnloadByName()

int AuDriverUnloadByName ( const char *  name)

◆ AuDriverUnref()

void AuDriverUnref ( AuDriver *  drv)

◆ AuDriverUntrack()

void AuDriverUntrack ( AuDriver *  drv,
uint8_t  kind,
uint64_t  value 
)

◆ AuDriverUntrackAny()

void AuDriverUntrackAny ( uint8_t  kind,
uint64_t  value 
)

◆ AuDrvCatchFault()

void AuDrvCatchFault ( AuDriver *  drv,
uint64_t  fault_addr 
)

AuDrvCatchFault – resolves original virtual address of the driver and relocate its symbol name.

Parameters
drv– Pointer to driver
fault_addr– istruction pointer address

◆ AuDrvManagerCheckFault()

AuDriver * AuDrvManagerCheckFault ( uint64_t  fault_addr)

AuDrvManagerCheckFault – check if this driver contain the fault address, helpful for debugging.

Parameters
fault_addr– address of fault

◆ AuDrvMgrGetBaseAddress()

uint64_t AuDrvMgrGetBaseAddress ( )

AuDrvMgrGetBaseAddress – returns the current driver load base address.

◆ AuDrvMgrSetBaseAddress()

void AuDrvMgrSetBaseAddress ( uint64_t  base_address)

AuDrvMgrSetBaseAddress – sets a new base address for driver to load it's highly risky because, if we set it to kernel stack location, kernel will crash.

◆ AuDrvMngrInitialize()

void AuDrvMngrInitialize ( KERNEL_BOOT_INFO *  info)

AuDrvMngrInitialize – Initialize the driver manager.

Parameters
info– kernel boot info

now initialize board specific driver list

using font manager's function because both board config data and font manager config data shares same style

◆ AuDrvUnloadAll()

void AuDrvUnloadAll ( )

AuDrvUnloadAll – call unload handler of all registered drivers.

◆ AuGetConfEntry()

char * AuGetConfEntry ( uint32_t  vendor_id,
uint32_t  device_id,
uint8_t *  buffer,
int  entryoff 
)

AuGetConfEntry – Get an entry offset in the file for required device.

Parameters
vendor_id– vendor id of the product
device_id– device id of the product
buffer– configuration file buffer
entryoff– entry offset from where search begins

◆ AuGetDriverName()

AuDriver * AuGetDriverName ( uint32_t  vendor_id,
uint32_t  device_id,
uint8_t *  buffer,
int  entryoff 
)

AuGetDriverName – Extract the driver path from its entry offset.

Parameters
vendor_id– vendor id of the product
device_id– device id of the product
buffer– configuration file buffer
entryoff– entry offset from where search begins

◆ AuIncreaseDriverCount()

void AuIncreaseDriverCount ( )

AuIncreaseDriverCount – increase the number of device count.

◆ AuIsPCIeInitialized()

bool AuIsPCIeInitialized ( )
extern

◆ AuRegisterDevice()

AU_EXTERN AU_EXPORT void AuRegisterDevice ( AuDevice *  dev)

AuRegisterDevice – register a new device to aurora system.

Parameters
dev– Pointer to device to add

◆ AuRequestBootDriverId()

uint32_t AuRequestBootDriverId ( )

◆ AuRequestDriverId()

uint32_t AuRequestDriverId ( )

request an unique id for driver class

◆ FontManagerGetFontCount()

int FontManagerGetFontCount ( uint8_t *  fontlst)
extern

FontManagerGetFontCount – returns number of font counts.

we're using FontManagerGetFontCount because both board config descriptor file and font config file share same writing style

Parameters
fontlst– font list buffer
Returns
the number of total font available in the system

Variable Documentation

◆ au_devices

◆ base

uint64_t base

◆ bootDrivers

AuDriver* bootDrivers[10]

◆ drivers

AuDriver* drivers[246]

◆ fn

void* fn

◆ name

const char* name

◆ pages

size_t pages

◆ scratchBuffer

uint64_t* scratchBuffer