XenevaOS
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
devhw.c File Reference
#include <Fs/Dev/devhw.h>
#include <Fs/Dev/devfs.h>
#include <Fs/vfs.h>
#include <Cap/capability.h>
#include <Cred/group.h>
#include <Hal/AA64/sched.h>
#include <Hal/AA64/gic.h>
#include <Serv/sysserv.h>
#include <Mm/kmalloc.h>
#include <Mm/pmmngr.h>
#include <Mm/vmmngr.h>
#include <Drivers/uart.h>
#include <Drivers/virtio.h>
#include <Hal/AA64/aa64lowlevel.h>
#include <aucomponent.h>
#include <Sound/sndproxy.h>
#include <Net/netproxy.h>
#include <Fs/Dev/devgpu.h>
#include <hwdev.h>
#include <pcie.h>
#include <string.h>
#include <_null.h>
Include dependency graph for devhw.c:

Classes

struct  _hw_map_
 
struct  _hw_dma_
 
struct  _hw_bar_
 
struct  _hw_pci_
 

Macros

#define HW_MAX_CLAIMS   32
 
#define HW_MAX_MAPS   16
 
#define HW_MAX_DMA_PAGES   256 /* 1 MiB per buffer */
 
#define HW_MAX_DMAS   16
 
#define PCI_CMD_MEM   (1u << 1)
 
#define PCI_CMD_MASTER   (1u << 2)
 
#define PCI_CMD_INTXOFF   (1u << 10)
 
#define PCI_CMD_IO   (1u << 0)
 
#define HW_MAX_SPI   1024
 

Typedefs

typedef struct _hw_map_ HwMap
 
typedef struct _hw_dma_ HwDma
 
typedef struct _hw_bar_ HwBar
 
typedef struct _hw_pci_ HwPci
 

Functions

bool AuHwdevClaimsPci (int bus, int dev, int func)
 True when a live user-space hwdev capability owns this PCI function.
 
AuProcess * AuHwdevCurrentProcess (void)
 AuHwdevCurrentProcess – the process running the current thread.
 
bool AuHwdevCallerAllowed (AuProcess *proc)
 AuHwdevCallerAllowed – true when proc is in the MISC_DAEMONS group. Checked on every privileged operation: a write-mode open skips the VFS permission check, so node permissions alone are not enough.
 
bool AuHwdevOwnsDma (AuProcess *proc, uint64_t phys, uint64_t len)
 AuHwdevOwnsDma – true when [phys, phys+len) lies inside a DMA buffer that proc allocated through one of its own hw handles. Lets other kernel code accept a user-supplied physical address without trusting it.
 
bool AuHwdevHandleIsDevice (AuProcess *proc, int fd, uint16_t vendor, uint16_t device)
 Validate that fd is the caller's PCI function with the requested ID.
 
void * AuHwdevHandleObject (AuProcess *proc, int fd)
 Return the opaque kernel object for one exact caller handle.
 
bool AuHwdevHandleOwnsDma (AuProcess *proc, int fd, uint64_t phys, uint64_t len)
 Validate a DMA range against one exact hwdev capability.
 
void AuHwdevCapReleased (void *procptr, AuCapability *cap)
 
void AuHwdevInitialize (void)
 AuHwdevInitialize – register /dev/hwdev (hardware access for user-space drivers, see BaseHdr/hwdev.h)
 

Macro Definition Documentation

◆ HW_MAX_CLAIMS

#define HW_MAX_CLAIMS   32

devhw.c – /dev/hwdev: capability-gated hardware access for user-space drivers

See BaseHdr/hwdev.h for the contract. Summary: PCI_OPEN on the controller node returns a new fd that is a CAP_OBJ_PCIDEV capability for one PCI function; config access, BAR mapping and DMA buffers are ioctls on that fd, each bounded by the device. The capability table releases everything when the fd is closed or the process exits (AuHwdevCapReleased).

◆ HW_MAX_DMA_PAGES

#define HW_MAX_DMA_PAGES   256 /* 1 MiB per buffer */

◆ HW_MAX_DMAS

#define HW_MAX_DMAS   16

◆ HW_MAX_MAPS

#define HW_MAX_MAPS   16

◆ HW_MAX_SPI

#define HW_MAX_SPI   1024

◆ PCI_CMD_INTXOFF

#define PCI_CMD_INTXOFF   (1u << 10)

◆ PCI_CMD_IO

#define PCI_CMD_IO   (1u << 0)

◆ PCI_CMD_MASTER

#define PCI_CMD_MASTER   (1u << 2)

◆ PCI_CMD_MEM

#define PCI_CMD_MEM   (1u << 1)

Typedef Documentation

◆ HwBar

typedef struct _hw_bar_ HwBar

◆ HwDma

typedef struct _hw_dma_ HwDma

◆ HwMap

typedef struct _hw_map_ HwMap

◆ HwPci

typedef struct _hw_pci_ HwPci

Function Documentation

◆ AuHwdevCallerAllowed()

bool AuHwdevCallerAllowed ( AuProcess *  proc)

AuHwdevCallerAllowed – true when proc is in the MISC_DAEMONS group. Checked on every privileged operation: a write-mode open skips the VFS permission check, so node permissions alone are not enough.

◆ AuHwdevCapReleased()

void AuHwdevCapReleased ( void *  procptr,
AuCapability *  cap 
)

◆ AuHwdevClaimsPci()

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

True when a live user-space hwdev capability owns this PCI function.

◆ AuHwdevCurrentProcess()

AuProcess * AuHwdevCurrentProcess ( void  )

AuHwdevCurrentProcess – the process running the current thread.

◆ AuHwdevHandleIsDevice()

bool AuHwdevHandleIsDevice ( AuProcess *  proc,
int  fd,
uint16_t  vendor,
uint16_t  device 
)

Validate that fd is the caller's PCI function with the requested ID.

◆ AuHwdevHandleObject()

void * AuHwdevHandleObject ( AuProcess *  proc,
int  fd 
)

Return the opaque kernel object for one exact caller handle.

◆ AuHwdevHandleOwnsDma()

bool AuHwdevHandleOwnsDma ( AuProcess *  proc,
int  fd,
uint64_t  phys,
uint64_t  len 
)

Validate a DMA range against one exact hwdev capability.

◆ AuHwdevInitialize()

void AuHwdevInitialize ( void  )

AuHwdevInitialize – register /dev/hwdev (hardware access for user-space drivers, see BaseHdr/hwdev.h)

◆ AuHwdevOwnsDma()

bool AuHwdevOwnsDma ( AuProcess *  proc,
uint64_t  phys,
uint64_t  len 
)

AuHwdevOwnsDma – true when [phys, phys+len) lies inside a DMA buffer that proc allocated through one of its own hw handles. Lets other kernel code accept a user-supplied physical address without trusting it.

Variable Documentation

◆ device

◆ vendor

uint16_t vendor