|
ginnOS
The reference: libc, the libraries and the kernel
|
virtio 1.0 on PCI: registers, features, split virtqueues (see virtio.h). More...
#include "virtio.h"#include "common/memory.h"#include "kernel/memory/mmio.h"#include "kernel/memory/page.h"#include "kernel/memory/phys.h"#include "kernel/memory/pmm.h"Data Structures | |
| struct | __attribute__ |
| ELF32 file header. More... | |
Macros | |
| #define | CAP_VENDOR 0x09 |
| #define | CFG_COMMON 1 |
| #define | CFG_NOTIFY 2 |
| #define | CFG_ISR 3 |
| #define | CFG_DEVICE 4 |
| #define | DEVICE_FEATURE_SELECT 0 |
| #define | DEVICE_FEATURE 4 |
| #define | DRIVER_FEATURE_SELECT 8 |
| #define | DRIVER_FEATURE 12 |
| #define | MSIX_CONFIG 16 |
| #define | DEVICE_STATUS 20 |
| #define | QUEUE_SELECT 22 |
| #define | QUEUE_SIZE 24 |
| #define | QUEUE_MSIX_VECTOR 26 |
| #define | QUEUE_ENABLE 28 |
| #define | QUEUE_NOTIFY_OFF 30 |
| #define | QUEUE_DESC 32 |
| #define | QUEUE_DRIVER 40 |
| #define | QUEUE_DEVICE 48 |
| #define | NO_VECTOR 0xFFFF |
| #define | DESC_NEXT 1 |
| #define | DESC_WRITE 2 |
| #define | WAIT_LOOPS 50000000u |
| #define | SLOTS 16 |
| #define | SLOT_SIZE 128 |
| #define | RESPONSE_AT 96 |
| #define | AVAIL_OFFSET (VIRTQ_SIZE * sizeof(desc_t)) |
| #define | USED_OFFSET 2048 |
Functions | |
| bool | virtio_init (virtio_device_t *dev, pci_device_t *pci, uint64_t features) |
| find the registers, reset the device and agree on features. | |
| bool | virtio_queue_init (virtio_device_t *dev, virtq_t *q, uint16_t index) |
| set up a queue (before virtio_ready). | |
| void | virtio_use_config_vector (virtio_device_t *dev) |
| route configuration change interrupts to MSI-X vector 0 (when the device uses MSI-X) and no queue interrupts: queues are polled. | |
| void | virtio_ready (virtio_device_t *dev) |
| tell the device the driver is ready. | |
| bool | virtq_post (virtq_t *q, const void *request, uint32_t request_size) |
| send a request and do not wait: its response is not read. | |
| bool | virtq_call (virtq_t *q, const void *request, uint32_t request_size, void *response, uint32_t response_size) |
| send a request and wait for the response. | |
| void | virtio_queue_interrupt (virtq_t *q) |
| send the interrupts of a queue to MSI-X vector 0 (before virtio_ready). | |
| bool | virtq_give (virtq_t *q, uint16_t id, phys_addr_t phys, uint32_t length, bool device_writes) |
| give the device a buffer, in descriptor id (each id is one buffer). | |
| bool | virtq_take (virtq_t *q, uint16_t *id, uint32_t *length) |
| take back a buffer the device is done with. | |
virtio 1.0 on PCI: registers, features, split virtqueues (see virtio.h).
| #define CAP_VENDOR 0x09 |
| #define CFG_COMMON 1 |
| #define CFG_NOTIFY 2 |
| #define CFG_ISR 3 |
| #define CFG_DEVICE 4 |
| #define DEVICE_FEATURE_SELECT 0 |
| #define DEVICE_FEATURE 4 |
| #define DRIVER_FEATURE_SELECT 8 |
| #define DRIVER_FEATURE 12 |
| #define MSIX_CONFIG 16 |
| #define DEVICE_STATUS 20 |
| #define QUEUE_SELECT 22 |
| #define QUEUE_SIZE 24 |
| #define QUEUE_MSIX_VECTOR 26 |
| #define QUEUE_ENABLE 28 |
| #define QUEUE_NOTIFY_OFF 30 |
| #define QUEUE_DESC 32 |
| #define QUEUE_DRIVER 40 |
| #define QUEUE_DEVICE 48 |
| #define NO_VECTOR 0xFFFF |
| #define DESC_NEXT 1 |
| #define DESC_WRITE 2 |
| #define WAIT_LOOPS 50000000u |
| #define SLOTS 16 |
| #define SLOT_SIZE 128 |
| #define RESPONSE_AT 96 |
| #define AVAIL_OFFSET (VIRTQ_SIZE * sizeof(desc_t)) |
| #define USED_OFFSET 2048 |
| bool virtio_init | ( | virtio_device_t * | dev, |
| pci_device_t * | pci, | ||
| uint64_t | features ) |
find the registers, reset the device and agree on features.
the device stays in that state until virtio_ready, so the driver can set up its queues first.
| features | the bits the driver wants; VIRTIO_F_VERSION_1 is added. |
| bool virtio_queue_init | ( | virtio_device_t * | dev, |
| virtq_t * | q, | ||
| uint16_t | index ) |
set up a queue (before virtio_ready).
| void virtio_use_config_vector | ( | virtio_device_t * | dev | ) |
route configuration change interrupts to MSI-X vector 0 (when the device uses MSI-X) and no queue interrupts: queues are polled.
| void virtio_ready | ( | virtio_device_t * | dev | ) |
tell the device the driver is ready.
send a request and do not wait: its response is not read.
for a device that does its requests in order (virtio-gpu 2D). a virtq_call after it waits until it is done. with many on the way this waits for room.
| request | up to 96 bytes the device reads. |
| bool virtq_call | ( | virtq_t * | q, |
| const void * | request, | ||
| uint32_t | request_size, | ||
| void * | response, | ||
| uint32_t | response_size ) |
send a request and wait for the response.
| request | request_size bytes the device reads. |
| response | response_size bytes the device writes. |
| void virtio_queue_interrupt | ( | virtq_t * | q | ) |
send the interrupts of a queue to MSI-X vector 0 (before virtio_ready).
without MSI-X the device raises its one interrupt (INTx or MSI), and bit 0 of the ISR status says a queue has used buffers.
give the device a buffer, in descriptor id (each id is one buffer).
| id | 0 to q->size - 1; the buffer comes back from virtq_take with this id. |
| device_writes | true for a buffer the device fills (receive), false for one it reads (send). |