Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/virtio/virtqueue.c
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | struct virtqueue { | ||||
device_t vq_dev; | device_t vq_dev; | ||||
char vq_name[VIRTQUEUE_MAX_NAME_SZ]; | char vq_name[VIRTQUEUE_MAX_NAME_SZ]; | ||||
uint16_t vq_queue_index; | uint16_t vq_queue_index; | ||||
uint16_t vq_nentries; | uint16_t vq_nentries; | ||||
uint32_t vq_flags; | uint32_t vq_flags; | ||||
#define VIRTQUEUE_FLAG_INDIRECT 0x0001 | #define VIRTQUEUE_FLAG_INDIRECT 0x0001 | ||||
#define VIRTQUEUE_FLAG_EVENT_IDX 0x0002 | #define VIRTQUEUE_FLAG_EVENT_IDX 0x0002 | ||||
bus_size_t vq_notify_offset; | |||||
int vq_alignment; | int vq_alignment; | ||||
int vq_ring_size; | int vq_ring_size; | ||||
void *vq_ring_mem; | void *vq_ring_mem; | ||||
int vq_max_indirect_size; | int vq_max_indirect_size; | ||||
int vq_indirect_mem_size; | int vq_indirect_mem_size; | ||||
virtqueue_intr_t *vq_intrhand; | virtqueue_intr_t *vq_intrhand; | ||||
void *vq_intrhand_arg; | void *vq_intrhand_arg; | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | virtqueue_filter_features(uint64_t features) | ||||
mask = (1 << VIRTIO_TRANSPORT_F_START) - 1; | mask = (1 << VIRTIO_TRANSPORT_F_START) - 1; | ||||
mask |= VIRTIO_RING_F_INDIRECT_DESC; | mask |= VIRTIO_RING_F_INDIRECT_DESC; | ||||
mask |= VIRTIO_RING_F_EVENT_IDX; | mask |= VIRTIO_RING_F_EVENT_IDX; | ||||
return (features & mask); | return (features & mask); | ||||
} | } | ||||
int | int | ||||
virtqueue_alloc(device_t dev, uint16_t queue, uint16_t size, int align, | virtqueue_alloc(device_t dev, uint16_t queue, uint16_t size, | ||||
vm_paddr_t highaddr, struct vq_alloc_info *info, struct virtqueue **vqp) | bus_size_t notify_offset, int align, vm_paddr_t highaddr, | ||||
struct vq_alloc_info *info, struct virtqueue **vqp) | |||||
{ | { | ||||
struct virtqueue *vq; | struct virtqueue *vq; | ||||
int error; | int error; | ||||
*vqp = NULL; | *vqp = NULL; | ||||
error = 0; | error = 0; | ||||
if (size == 0) { | if (size == 0) { | ||||
Show All 19 Lines | virtqueue_alloc(device_t dev, uint16_t queue, uint16_t size, | ||||
if (vq == NULL) { | if (vq == NULL) { | ||||
device_printf(dev, "cannot allocate virtqueue\n"); | device_printf(dev, "cannot allocate virtqueue\n"); | ||||
return (ENOMEM); | return (ENOMEM); | ||||
} | } | ||||
vq->vq_dev = dev; | vq->vq_dev = dev; | ||||
strlcpy(vq->vq_name, info->vqai_name, sizeof(vq->vq_name)); | strlcpy(vq->vq_name, info->vqai_name, sizeof(vq->vq_name)); | ||||
vq->vq_queue_index = queue; | vq->vq_queue_index = queue; | ||||
vq->vq_notify_offset = notify_offset; | |||||
vq->vq_alignment = align; | vq->vq_alignment = align; | ||||
vq->vq_nentries = size; | vq->vq_nentries = size; | ||||
vq->vq_free_cnt = size; | vq->vq_free_cnt = size; | ||||
vq->vq_intrhand = info->vqai_intr; | vq->vq_intrhand = info->vqai_intr; | ||||
vq->vq_intrhand_arg = info->vqai_intr_arg; | vq->vq_intrhand_arg = info->vqai_intr_arg; | ||||
if (VIRTIO_BUS_WITH_FEATURE(dev, VIRTIO_RING_F_EVENT_IDX) != 0) | if (VIRTIO_BUS_WITH_FEATURE(dev, VIRTIO_RING_F_EVENT_IDX) != 0) | ||||
vq->vq_flags |= VIRTQUEUE_FLAG_EVENT_IDX; | vq->vq_flags |= VIRTQUEUE_FLAG_EVENT_IDX; | ||||
▲ Show 20 Lines • Show All 620 Lines • ▼ Show 20 Lines | vq_ring_must_notify_host(struct virtqueue *vq) | ||||
return ((vq->vq_ring.used->flags & VRING_USED_F_NO_NOTIFY) == 0); | return ((vq->vq_ring.used->flags & VRING_USED_F_NO_NOTIFY) == 0); | ||||
} | } | ||||
static void | static void | ||||
vq_ring_notify_host(struct virtqueue *vq) | vq_ring_notify_host(struct virtqueue *vq) | ||||
{ | { | ||||
VIRTIO_BUS_NOTIFY_VQ(vq->vq_dev, vq->vq_queue_index); | VIRTIO_BUS_NOTIFY_VQ(vq->vq_dev, vq->vq_queue_index, | ||||
vq->vq_notify_offset); | |||||
} | } | ||||
static void | static void | ||||
vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) | vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx) | ||||
{ | { | ||||
struct vring_desc *dp; | struct vring_desc *dp; | ||||
struct vq_desc_extra *dxp; | struct vq_desc_extra *dxp; | ||||
Show All 29 Lines |