Changeset 331d024 in mainline for uspace/lib/virtio/virtio.c
- Timestamp:
- 2018-06-28T18:57:36Z (7 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1e472ee
- Parents:
- 96c30c8
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/virtio/virtio.c
r96c30c8 r331d024 57 57 return pio_read_le16(&d->next); 58 58 } 59 60 /** Create free descriptor list from the unused VIRTIO descriptors 61 * 62 * @param vdev[in] VIRTIO device for which the free list will be created. 63 * @param num[in] Index of the virtqueue for which the free list will be 64 * created. 65 * @param size[in] Number of descriptors on the free list. The free list will 66 * contain descriptors starting from 0 to \a size - 1. 67 * @param head[out] Variable that will hold the VIRTIO descriptor at the head 68 * of the free list. 69 */ 70 void virtio_create_desc_free_list(virtio_dev_t *vdev, uint16_t num, 71 uint16_t size, uint16_t *head) 72 { 73 for (unsigned i = 0; i < size; i++) { 74 virtio_virtq_desc_set(vdev, num, i, 0, 0, 75 VIRTQ_DESC_F_NEXT, (i + 1 == size) ? -1U : i + 1); 76 } 77 *head = 0; 78 } 79 80 /** Allocate a descriptor from the free list 81 * 82 * @param vdev[in] VIRTIO device with the free list. 83 * @param num[in] Index of the virtqueue with free list. 84 * @param head[in,out] Head of the free list. 85 * 86 * @return Allocated descriptor or 0xFFFF if the list is empty. 87 */ 88 uint16_t virtio_alloc_desc(virtio_dev_t *vdev, uint16_t num, uint16_t *head) 89 { 90 virtq_t *q = &vdev->queues[num]; 91 fibril_mutex_lock(&q->lock); 92 uint16_t descno = *head; 93 if (descno != (uint16_t) -1U) 94 *head = virtio_virtq_desc_get_next(vdev, num, descno); 95 fibril_mutex_unlock(&q->lock); 96 return descno; 97 } 98 99 /** Free a descriptor into the free list 100 * 101 * @param vdev[in] VIRTIO device with the free list. 102 * @param num[in] Index of the virtqueue with free list. 103 * @param head[in,out] Head of the free list. 104 * @param descno[in] The freed descriptor. 105 */ 106 void virtio_free_desc(virtio_dev_t *vdev, uint16_t num, uint16_t *head, 107 uint16_t descno) 108 { 109 virtq_t *q = &vdev->queues[num]; 110 fibril_mutex_lock(&q->lock); 111 virtio_virtq_desc_set(vdev, num, descno, 0, 0, VIRTQ_DESC_F_NEXT, 112 *head); 113 *head = descno; 114 fibril_mutex_unlock(&q->lock); 115 } 116 59 117 60 118 void virtio_virtq_produce_available(virtio_dev_t *vdev, uint16_t num,
Note:
See TracChangeset
for help on using the changeset viewer.