|
iPXE
|
Virtual I/O device. More...
Go to the source code of this file.
Data Structures | |
| struct | virtio_pci_capability |
| A virtio PCI capability. More... | |
| struct | virtio_desc |
| A virtio buffer descriptor. More... | |
| struct | virtio_sqe |
| A virtio submission queue entry. More... | |
| struct | virtio_sq |
| A virtio submission ("available") queue. More... | |
| struct | virtio_cqe |
| A virtio completion queue entry. More... | |
| struct | virtio_cq |
| A virtio completion ("used") queue. More... | |
| struct | virtio_queue |
| A virtio queue. More... | |
| struct | virtio_features |
| A virtio feature set. More... | |
| struct | virtio_device |
| A virtio device. More... | |
| struct | virtio_operations |
| Virtio device operations. More... | |
Macros | |
| #define | VIRTIO_PAGE 4096 |
| Virtio page alignment. | |
| #define | VIRTIO_RESET_MAX_WAIT_MS 100 |
| Maximum time to wait for reset (in ms). | |
| #define | VIRTIO_LEG_FEAT 0x00 |
| Legacy device supported features register. | |
| #define | VIRTIO_LEG_USED 0x04 |
| Legacy negotiated in-use features register. | |
| #define | VIRTIO_LEG_BASE 0x08 |
| Legacy queue base address register. | |
| #define | VIRTIO_LEG_SIZE 0x0c |
| Legacy queue size register. | |
| #define | VIRTIO_LEG_SEL 0x0e |
| Legacy queue select register. | |
| #define | VIRTIO_LEG_DB 0x10 |
| Legacy queue doorbell notification register. | |
| #define | VIRTIO_LEG_STAT 0x12 |
| Legacy driver status register. | |
| #define | VIRTIO_STAT_ACKNOWLEDGE 0x0001 |
| Guest has found device. | |
| #define | VIRTIO_STAT_DRIVER 0x0002 |
| Guest driver exists. | |
| #define | VIRTIO_STAT_DRIVER_OK 0x0004 |
| Guest driver is ready. | |
| #define | VIRTIO_STAT_FEATURES_OK 0x0008 |
| Guest driver has set features. | |
| #define | VIRTIO_STAT_FAIL 0x0080 |
| Guest driver has failed. | |
| #define | VIRTIO_LEG_DEV 0x14 |
| Legacy device-specific registers. | |
| #define | VIRTIO_LEG_DEV_MSIX 0x18 |
| Legacy device-specific register (if MSI-X is enabled). | |
| #define | VIRTIO_PCI_CAP_TYPE 0x03 |
| Capability type. | |
| #define | VIRTIO_PCI_CAP_TYPE_COMMON 0x01 |
| Common registers. | |
| #define | VIRTIO_PCI_CAP_TYPE_NOTIFY 0x02 |
| Notification doorbells. | |
| #define | VIRTIO_PCI_CAP_TYPE_DEVICE 0x04 |
| Device-specific registers. | |
| #define | VIRTIO_PCI_CAP_BAR 0x04 |
| Capability BAR index. | |
| #define | VIRTIO_PCI_CAP_OFFSET 0x08 |
| Capability BAR offset. | |
| #define | VIRTIO_PCI_CAP_END 0x10 |
| Capability minimum length. | |
| #define | VIRTIO_PCI_CAP_NOTIFY_MULT 0x10 |
| Notification doorbell capability multiplier offset. | |
| #define | VIRTIO_PCI_CAP_NOTIFY_END 0x14 |
| Notification doorbell capability minimum length. | |
| #define | VIRTIO_PCI_FEAT_SEL 0x00 |
| PCI device supported features select register. | |
| #define | VIRTIO_PCI_FEAT 0x04 |
| PCI device supported features register. | |
| #define | VIRTIO_PCI_USED_SEL 0x08 |
| PCI negotiated in-use features select register. | |
| #define | VIRTIO_PCI_USED 0x0c |
| PCI negotiated in-use features register. | |
| #define | VIRTIO_PCI_STAT 0x14 |
| PCI device status register. | |
| #define | VIRTIO_PCI_GEN 0x15 |
| PCI configuration generation register. | |
| #define | VIRTIO_PCI_SEL 0x16 |
| PCI queue select register. | |
| #define | VIRTIO_PCI_SIZE 0x18 |
| PCI queue size register. | |
| #define | VIRTIO_PCI_ENABLE 0x1c |
| PCI queue enable register. | |
| #define | VIRTIO_PCI_DBOFF 0x1e |
| PCI queue doorbell notification offset register. | |
| #define | VIRTIO_PCI_DESC 0x20 |
| PCI queue descriptor array base address register. | |
| #define | VIRTIO_PCI_SQ 0x28 |
| PCI queue submission queue base address register. | |
| #define | VIRTIO_PCI_CQ 0x30 |
| PCI queue completion queue base address register. | |
| #define | VIRTIO_DESC_FL_NEXT 0x0001 |
| Next descriptor index is valid. | |
| #define | VIRTIO_DESC_FL_WRITE 0x0002 |
| Buffer is write-only. | |
| #define | VIRTIO_SQ_FL_NO_INTERRUPT 0x0001 |
| Do not generate interrupt. | |
| #define | VIRTIO_FEATURE_WORDS 2 |
| Number of 32-bit feature words. | |
| #define | VIRTIO_FEAT0_ANY_LAYOUT 0x08000000 |
| Arbitrary descriptor layouts may be used. | |
| #define | VIRTIO_FEAT1_MODERN 0x00000001 |
| Virtio version 1.0 or above. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| FILE_SECBOOT (PERMITTED) | |
| static void | virtio_queue_init (struct virtio_queue *queue, unsigned int index) |
| Initialise virtio queue. | |
| static size_t | virtio_align (size_t size) |
| Calculate aligned size. | |
| static size_t | virtio_desc_size (unsigned int count) |
| Calculate (unaligned) descriptor array size. | |
| static size_t | virtio_sq_size (unsigned int count) |
| Calculate (unaligned) submission queue size. | |
| static size_t | virtio_cq_size (unsigned int count) |
| Calculate (unaligned) completion queue size. | |
| static void | virtio_submit (struct virtio_queue *queue, unsigned int index) |
| Submit descriptor(s) to queue. | |
| static void | virtio_notify (struct virtio_queue *queue) |
| Notify queue. | |
| static unsigned int | virtio_completions (struct virtio_queue *queue) |
| Check for completed descriptors. | |
| static unsigned int | virtio_complete (struct virtio_queue *queue, size_t *len) |
| Complete descriptor(s). | |
| static int | virtio_is_legacy (struct virtio_device *virtio) |
| Check if device is using the legacy interface. | |
| int | virtio_pci_map (struct virtio_device *virtio, struct pci_device *pci) |
| Map PCI device. | |
| int | virtio_reset (struct virtio_device *virtio) |
| Reset device. | |
| unsigned int | virtio_status (struct virtio_device *virtio, unsigned int stat) |
| Report driver status. | |
| int | virtio_init (struct virtio_device *virtio, const struct virtio_features *driver) |
| Initialise device. | |
| int | virtio_enable (struct virtio_device *virtio, struct virtio_queue *queue, unsigned int count) |
| Enable queue. | |
| void | virtio_free (struct virtio_device *virtio, struct virtio_queue *queue) |
| Free queue. | |
| void | virtio_unmap (struct virtio_device *virtio) |
| Unmap device. | |
Virtual I/O device.
Definition in file virtio.h.
| #define VIRTIO_PAGE 4096 |
Virtio page alignment.
Definition at line 19 of file virtio.h.
Referenced by virtio_align(), virtio_enable(), virtio_legacy_enable(), and virtio_pci_map_cap().
| #define VIRTIO_RESET_MAX_WAIT_MS 100 |
Maximum time to wait for reset (in ms).
Definition at line 22 of file virtio.h.
Referenced by virtio_legacy_reset(), and virtio_pci_reset().
| #define VIRTIO_DESC_FL_NEXT 0x0001 |
Next descriptor index is valid.
Definition at line 164 of file virtio.h.
Referenced by virtio_net_enable().
| #define VIRTIO_DESC_FL_WRITE 0x0002 |
| #define VIRTIO_SQ_FL_NO_INTERRUPT 0x0001 |
| #define VIRTIO_FEATURE_WORDS 2 |
Number of 32-bit feature words.
Definition at line 296 of file virtio.h.
Referenced by virtio_legacy_negotiate(), virtio_legacy_supported(), virtio_negotiate(), virtio_pci_negotiate(), and virtio_pci_supported().
| #define VIRTIO_FEAT0_ANY_LAYOUT 0x08000000 |
| #define VIRTIO_FEAT1_MODERN 0x00000001 |
Virtio version 1.0 or above.
Definition at line 308 of file virtio.h.
Referenced by virtio_init(), and virtio_is_legacy().
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| FILE_SECBOOT | ( | PERMITTED | ) |
|
inlinestatic |
Calculate aligned size.
| size | Unaligned size |
| size | Aligned size |
Definition at line 251 of file virtio.h.
References size, and VIRTIO_PAGE.
Referenced by virtio_legacy_enable(), virtio_legacy_size(), virtio_pci_enable(), and virtio_pci_size().
|
inlinestatic |
Calculate (unaligned) descriptor array size.
Definition at line 263 of file virtio.h.
Referenced by virtio_enable(), virtio_legacy_enable(), virtio_legacy_size(), virtio_pci_enable(), and virtio_pci_size().
|
inlinestatic |
Calculate (unaligned) submission queue size.
Definition at line 276 of file virtio.h.
References count, and virtio_sq::sqe.
Referenced by virtio_enable(), virtio_legacy_enable(), virtio_legacy_size(), virtio_pci_enable(), and virtio_pci_size().
|
inlinestatic |
Calculate (unaligned) completion queue size.
Definition at line 289 of file virtio.h.
References count, and virtio_cq::cqe.
Referenced by virtio_enable(), virtio_legacy_enable(), virtio_legacy_size(), virtio_pci_enable(), and virtio_pci_size().
|
inlinestatic |
Submit descriptor(s) to queue.
Definition at line 388 of file virtio.h.
References cpu_to_le16, index, queue, and sqe.
Referenced by virtio_net_submit().
|
inlinestatic |
Notify queue.
| queue | Virtio queue |
Definition at line 404 of file virtio.h.
References cpu_to_le16, iowrite16, queue, and wmb.
Referenced by virtio_net_refill_rx(), and virtio_net_transmit().
|
inlinestatic |
Check for completed descriptors.
| queue | Virtio queue |
| completions | Number of pending completions |
Definition at line 422 of file virtio.h.
References le16_to_cpu, and queue.
Referenced by virtio_net_poll_rx(), and virtio_net_poll_tx().
|
inlinestatic |
Complete descriptor(s).
| index | Starting descriptor index |
Definition at line 438 of file virtio.h.
References virtio_cqe::index, le32_to_cpu, len, virtio_cqe::len, and queue.
Referenced by virtio_net_complete().
|
inlinestatic |
Check if device is using the legacy interface.
| virtio | Virtio device |
| is_legacy | Device is using the legacy interface |
Definition at line 457 of file virtio.h.
References virtio_device::features, VIRTIO_FEAT1_MODERN, and virtio_features::word.
Referenced by virtio_net_open().
|
extern |
Map PCI device.
| virtio | Virtio device |
| pci | PCI device |
| rc | Return status code |
Definition at line 479 of file virtio.c.
References adjust_pci_device(), virtio_pci_capability::bar, common, virtio_device::common, ctrl, DBGC, pci_device::dev, virtio_device::device, pci_device::dma, virtio_device::dma, dma_set_mask_64bit(), ENODEV, iounmap(), virtio_pci_capability::len, virtio_device::multiplier, device::name, virtio_device::name, virtio_device::notify, virtio_pci_capability::offset, virtio_device::op, PCI_CAP_ID_MSIX, pci_find_capability(), PCI_MSIX_CTRL_ENABLE, pci_read_config_dword(), pci_read_config_word(), virtio_pci_capability::pos, rc, VIRTIO_LEG_DB, VIRTIO_LEG_DEV, VIRTIO_LEG_DEV_MSIX, virtio_legacy_operations, virtio_pci_cap(), VIRTIO_PCI_CAP_NOTIFY_END, VIRTIO_PCI_CAP_NOTIFY_MULT, VIRTIO_PCI_CAP_TYPE_COMMON, VIRTIO_PCI_CAP_TYPE_DEVICE, VIRTIO_PCI_CAP_TYPE_NOTIFY, virtio_pci_map_cap(), and virtio_pci_operations.
Referenced by virtio_net_probe().
|
extern |
Reset device.
| virtio | Virtio device |
| rc | Return status code |
Definition at line 580 of file virtio.c.
References DBGC, virtio_device::name, virtio_device::op, rc, virtio_operations::reset, virtio_device::stat, and strerror().
Referenced by virtio_init(), virtio_net_close(), virtio_net_open(), virtio_net_probe(), and virtio_net_remove().
|
extern |
Report driver status.
| virtio | Virtio device |
| stat | Additional driver status bits |
| stat | Actual device status |
Definition at line 603 of file virtio.c.
References virtio_device::op, stat, virtio_device::stat, and virtio_operations::status.
Referenced by virtio_init(), and virtio_net_open().
|
extern |
Initialise device.
| virtio | Virtio device |
| driver | Driver supported features |
| rc | Return status code |
Definition at line 650 of file virtio.c.
References DBGC, ENOTSUP, virtio_device::features, virtio_device::name, rc, stat, VIRTIO_FEAT1_MODERN, virtio_negotiate(), virtio_reset(), VIRTIO_STAT_ACKNOWLEDGE, VIRTIO_STAT_DRIVER, VIRTIO_STAT_FAIL, VIRTIO_STAT_FEATURES_OK, virtio_status(), and virtio_features::word.
Referenced by virtio_net_open(), and virtio_net_probe().
|
extern |
Enable queue.
| rc | Return status code |
Definition at line 696 of file virtio.c.
References count, DBGC, virtio_device::dma, dma_alloc(), dma_free(), virtio_operations::enable, ENODEV, ENOMEM, memset(), virtio_device::multiplier, virtio_device::name, virtio_device::notify, NULL, offset, virtio_device::op, queue, rc, virtio_operations::size, virtio_cq_size(), virtio_desc_size(), VIRTIO_PAGE, and virtio_sq_size().
Referenced by virtio_net_enable().
|
extern |
Free queue.
| virtio | Virtio device |
| queue | Virtio queue |
Definition at line 764 of file virtio.c.
References DBGC, dma_free(), virtio_device::name, NULL, and queue.
Referenced by virtio_net_close(), and virtio_net_open().
|
extern |
Unmap device.
| virtio | Virtio device |
Definition at line 780 of file virtio.c.
References virtio_device::common, virtio_device::device, iounmap(), and virtio_device::notify.
Referenced by virtio_net_probe(), and virtio_net_remove().