19#define VIRTIO_PAGE 4096
22#define VIRTIO_RESET_MAX_WAIT_MS 100
30#define VIRTIO_LEG_FEAT 0x00
33#define VIRTIO_LEG_USED 0x04
36#define VIRTIO_LEG_BASE 0x08
39#define VIRTIO_LEG_SIZE 0x0c
42#define VIRTIO_LEG_SEL 0x0e
45#define VIRTIO_LEG_DB 0x10
48#define VIRTIO_LEG_STAT 0x12
49#define VIRTIO_STAT_ACKNOWLEDGE 0x0001
50#define VIRTIO_STAT_DRIVER 0x0002
51#define VIRTIO_STAT_DRIVER_OK 0x0004
52#define VIRTIO_STAT_FEATURES_OK 0x0008
53#define VIRTIO_STAT_FAIL 0x0080
56#define VIRTIO_LEG_DEV 0x14
59#define VIRTIO_LEG_DEV_MSIX 0x18
69#define VIRTIO_PCI_CAP_TYPE 0x03
70#define VIRTIO_PCI_CAP_TYPE_COMMON 0x01
71#define VIRTIO_PCI_CAP_TYPE_NOTIFY 0x02
72#define VIRTIO_PCI_CAP_TYPE_DEVICE 0x04
75#define VIRTIO_PCI_CAP_BAR 0x04
78#define VIRTIO_PCI_CAP_OFFSET 0x08
81#define VIRTIO_PCI_CAP_END 0x10
84#define VIRTIO_PCI_CAP_NOTIFY_MULT 0x10
87#define VIRTIO_PCI_CAP_NOTIFY_END 0x14
111#define VIRTIO_PCI_FEAT_SEL 0x00
114#define VIRTIO_PCI_FEAT 0x04
117#define VIRTIO_PCI_USED_SEL 0x08
120#define VIRTIO_PCI_USED 0x0c
123#define VIRTIO_PCI_STAT 0x14
126#define VIRTIO_PCI_GEN 0x15
129#define VIRTIO_PCI_SEL 0x16
132#define VIRTIO_PCI_SIZE 0x18
135#define VIRTIO_PCI_ENABLE 0x1c
138#define VIRTIO_PCI_DBOFF 0x1e
141#define VIRTIO_PCI_DESC 0x20
144#define VIRTIO_PCI_SQ 0x28
147#define VIRTIO_PCI_CQ 0x30
164#define VIRTIO_DESC_FL_NEXT 0x0001
167#define VIRTIO_DESC_FL_WRITE 0x0002
186#define VIRTIO_SQ_FL_NO_INTERRUPT 0x0001
279 return (
sizeof ( *sq ) + (
count *
sizeof ( sq->
sqe[0] ) ) );
292 return (
sizeof ( *cq ) + (
count *
sizeof ( cq->
cqe[0] ) ) );
296#define VIRTIO_FEATURE_WORDS 2
305#define VIRTIO_FEAT0_ANY_LAYOUT 0x08000000
308#define VIRTIO_FEAT1_MODERN 0x00000001
unsigned long long uint64_t
uint32_t stat
Completion status.
struct ena_tx_sqe sqe
Transmit descriptor.
struct ena_llq_option desc
Descriptor counts.
uint16_t size
Buffer size.
static unsigned int count
Number of entries.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
#define le16_to_cpu(value)
#define le32_to_cpu(value)
#define cpu_to_le16(value)
#define iowrite16(data, io_addr)
A virtio completion ("used") queue.
struct virtio_cqe cqe[]
Queue entries.
uint16_t prod
Producer index.
A virtio completion queue entry.
uint32_t index
Starting descriptor index.
uint32_t len
Length written.
A virtio buffer descriptor.
uint16_t next
Next descriptor index.
uint32_t len
Buffer length.
uint64_t addr
Buffer address.
struct virtio_features features
Negotiated features.
const char * name
Device name.
unsigned int multiplier
Notification doorbell multiplier.
void * notify
Doorbell notification registers.
void * common
Common registers.
void * device
Device-specific registers.
struct virtio_operations * op
Device operations.
struct dma_device * dma
DMA device.
unsigned int stat
Driver status.
struct virtio_features supported
Device supported features.
uint32_t word[VIRTIO_FEATURE_WORDS]
Feature words.
Virtio device operations.
void(* negotiate)(struct virtio_device *virtio)
Set negotiated features.
void(* enable)(struct virtio_device *virtio, struct virtio_queue *queue)
Enable queue.
void(* supported)(struct virtio_device *virtio)
Get supported features.
int(* reset)(struct virtio_device *virtio)
Reset device.
unsigned int(* status)(struct virtio_device *virtio)
Report driver status.
void(* size)(struct virtio_device *virtio, struct virtio_queue *queue, unsigned int count)
Set queue size.
uint32_t offset
Offset within BAR.
uint8_t type
Capability type.
uint8_t len
Capability length.
uint8_t pos
Capability offset.
unsigned int mask
Queue mask.
struct virtio_sq * sq
Submission queue.
struct virtio_cq * cq
Completion queue.
unsigned int cons
Completion queue consumer index.
struct dma_mapping map
DMA mapping.
unsigned int prod
Submission queue producer index.
struct virtio_desc * desc
Descriptor array (and start of DMA allocation).
size_t len
Total length of queue.
unsigned int index
Queue index.
unsigned int count
Queue size (must be a power of two).
void * db
Notification doorbell.
A virtio submission ("available") queue.
uint16_t prod
Producer index.
struct virtio_sqe sqe[]
Queue entries.
A virtio submission queue entry.
uint16_t index
Starting descriptor index.
static void virtio_notify(struct virtio_queue *queue)
Notify queue.
static void virtio_queue_init(struct virtio_queue *queue, unsigned int index)
Initialise virtio queue.
#define VIRTIO_FEATURE_WORDS
Number of 32-bit feature words.
int virtio_init(struct virtio_device *virtio, const struct virtio_features *driver)
Initialise device.
#define VIRTIO_FEAT1_MODERN
Virtio version 1.0 or above.
unsigned int virtio_status(struct virtio_device *virtio, unsigned int stat)
Report driver status.
int virtio_enable(struct virtio_device *virtio, struct virtio_queue *queue, unsigned int count)
Enable queue.
static unsigned int virtio_completions(struct virtio_queue *queue)
Check for completed descriptors.
int virtio_reset(struct virtio_device *virtio)
Reset device.
static int virtio_is_legacy(struct virtio_device *virtio)
Check if device is using the legacy interface.
static void virtio_submit(struct virtio_queue *queue, unsigned int index)
Submit descriptor(s) to queue.
static unsigned int virtio_complete(struct virtio_queue *queue, size_t *len)
Complete descriptor(s).
static size_t virtio_align(size_t size)
Calculate aligned size.
void virtio_free(struct virtio_device *virtio, struct virtio_queue *queue)
Free queue.
static size_t virtio_cq_size(unsigned int count)
Calculate (unaligned) completion queue size.
void virtio_unmap(struct virtio_device *virtio)
Unmap device.
static size_t virtio_sq_size(unsigned int count)
Calculate (unaligned) submission queue size.
static size_t virtio_desc_size(unsigned int count)
Calculate (unaligned) descriptor array size.
#define VIRTIO_PAGE
Virtio page alignment.
int virtio_pci_map(struct virtio_device *virtio, struct pci_device *pci)
Map PCI device.