XenevaOS
Loading...
Searching...
No Matches
Classes | Macros
hwdev.h File Reference
#include <stdint.h>
Include dependency graph for hwdev.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  HwdevPciOpen
 
struct  HwdevCfg
 
struct  HwdevBar
 
struct  HwdevMap
 
struct  HwdevDma
 
struct  HwdevIrq
 
struct  HwdevIrqWait
 
struct  HwdevIrqAck
 

Macros

#define HWDEV_IOC_PCI_OPEN   0x4801 /* on /dev/hwdev; arg: HwdevPciOpen */
 
#define HWDEV_IOC_CFG_READ   0x4802 /* on a handle; arg: HwdevCfg */
 
#define HWDEV_IOC_CFG_WRITE   0x4803 /* on a handle; arg: HwdevCfg */
 
#define HWDEV_IOC_BAR_INFO   0x4804 /* on a handle; arg: HwdevBar */
 
#define HWDEV_IOC_MAP_BAR   0x4805 /* on a handle; arg: HwdevMap */
 
#define HWDEV_IOC_DMA_ALLOC   0x4806 /* on a handle; arg: HwdevDma */
 
#define HWDEV_IOC_IRQ_SETUP   0x4807 /* on a handle; arg: HwdevIrq */
 
#define HWDEV_IOC_IRQ_WAIT   0x4808 /* on a handle; arg: HwdevIrqWait */
 
#define HWDEV_IOC_IRQ_ACK   0x4809 /* on a handle; arg: HwdevIrqAck */
 
#define HWDEV_OK   0
 
#define HWDEV_E_PERM   -1 /* caller is not a driver process / lacks the right */
 
#define HWDEV_E_NODEV   -2 /* no such PCI function */
 
#define HWDEV_E_BUSY   -3 /* owned by an in-kernel driver or another process */
 
#define HWDEV_E_INVAL   -4 /* bad argument, out-of-range, or forbidden offset */
 
#define HWDEV_E_NOMEM   -5
 
#define HWDEV_BAR_MEM   0x1
 
#define HWDEV_BAR_IO   0x2
 
#define HWDEV_BAR_64BIT   0x4
 

Macro Definition Documentation

◆ HWDEV_BAR_64BIT

#define HWDEV_BAR_64BIT   0x4

◆ HWDEV_BAR_IO

#define HWDEV_BAR_IO   0x2

◆ HWDEV_BAR_MEM

#define HWDEV_BAR_MEM   0x1

◆ HWDEV_E_BUSY

#define HWDEV_E_BUSY   -3 /* owned by an in-kernel driver or another process */

◆ HWDEV_E_INVAL

#define HWDEV_E_INVAL   -4 /* bad argument, out-of-range, or forbidden offset */

◆ HWDEV_E_NODEV

#define HWDEV_E_NODEV   -2 /* no such PCI function */

◆ HWDEV_E_NOMEM

#define HWDEV_E_NOMEM   -5

◆ HWDEV_E_PERM

#define HWDEV_E_PERM   -1 /* caller is not a driver process / lacks the right */

◆ HWDEV_IOC_BAR_INFO

#define HWDEV_IOC_BAR_INFO   0x4804 /* on a handle; arg: HwdevBar */

◆ HWDEV_IOC_CFG_READ

#define HWDEV_IOC_CFG_READ   0x4802 /* on a handle; arg: HwdevCfg */

◆ HWDEV_IOC_CFG_WRITE

#define HWDEV_IOC_CFG_WRITE   0x4803 /* on a handle; arg: HwdevCfg */

◆ HWDEV_IOC_DMA_ALLOC

#define HWDEV_IOC_DMA_ALLOC   0x4806 /* on a handle; arg: HwdevDma */

◆ HWDEV_IOC_IRQ_ACK

#define HWDEV_IOC_IRQ_ACK   0x4809 /* on a handle; arg: HwdevIrqAck */

◆ HWDEV_IOC_IRQ_SETUP

#define HWDEV_IOC_IRQ_SETUP   0x4807 /* on a handle; arg: HwdevIrq */

◆ HWDEV_IOC_IRQ_WAIT

#define HWDEV_IOC_IRQ_WAIT   0x4808 /* on a handle; arg: HwdevIrqWait */

◆ HWDEV_IOC_MAP_BAR

#define HWDEV_IOC_MAP_BAR   0x4805 /* on a handle; arg: HwdevMap */

◆ HWDEV_IOC_PCI_OPEN

#define HWDEV_IOC_PCI_OPEN   0x4801 /* on /dev/hwdev; arg: HwdevPciOpen */

Shared kernel/user ABI for /dev/hwdev – hardware access for user-space drivers.

Model: a process in the MISC_DAEMONS group (or root) opens /dev/hwdev and asks for a PCI function with HWDEV_IOC_PCI_OPEN. On success it gets back a NEW file descriptor, a capability for exactly that one device. Every further operation (config access, BAR mapping, DMA buffers) is an ioctl on that descriptor, and everything it grants is bounded by the device:

  • config writes are limited to the command register and capability space, never the BARs, so a driver cannot re-point a device at kernel memory;
  • BAR mappings must lie inside a BAR of that device;
  • only PCI functions on the kernel's allowlist can be opened at all (default deny), and one that an in-kernel driver still owns is refused with HWDEV_E_BUSY: unload that driver first (see /dev/drvctl).

Closing the descriptor, or exiting, unmaps and frees everything granted.

◆ HWDEV_OK

#define HWDEV_OK   0