|
ginnOS
The reference: libc, the libraries and the kernel
|
virtio 1.0 devices on PCI (the "modern" interface). More...
#include "common/stdint.h"#include "kernel/memory/phys.h"#include "drivers/pci/pci.h"#include "kernel/sync/spinlock.h"Go to the source code of this file.
Data Structures | |
| struct | virtio_device_t |
| struct | virtq_t |
Macros | |
| #define | VIRTIO_VENDOR_ID 0x1AF4 |
| #define | VIRTIO_STATUS_ACKNOWLEDGE 1 |
| #define | VIRTIO_STATUS_DRIVER 2 |
| #define | VIRTIO_STATUS_DRIVER_OK 4 |
| #define | VIRTIO_STATUS_FEATURES_OK 8 |
| #define | VIRTIO_STATUS_FAILED 128 |
| #define | VIRTIO_F_VERSION_1 32 |
| #define | VIRTQ_SIZE 64 |
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_ready (virtio_device_t *dev) |
| tell the device the driver is 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. | |
| 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. | |
| 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. | |
| 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 devices on PCI (the "modern" interface).
the device's registers are in BARs that vendor capabilities point at: the common configuration, the notify area, the interrupt status and the device configuration. queues are split virtqueues in one page each.
a queue is used in one of two ways:
| #define VIRTIO_VENDOR_ID 0x1AF4 |
| #define VIRTIO_STATUS_ACKNOWLEDGE 1 |
| #define VIRTIO_STATUS_DRIVER 2 |
| #define VIRTIO_STATUS_DRIVER_OK 4 |
| #define VIRTIO_STATUS_FEATURES_OK 8 |
| #define VIRTIO_STATUS_FAILED 128 |
| #define VIRTIO_F_VERSION_1 32 |
| #define VIRTQ_SIZE 64 |
| 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_ready | ( | virtio_device_t * | dev | ) |
tell the device the driver is 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.
| 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. |
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. |
| 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). |