Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

virtqueue cleanup #52

Merged
merged 5 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 1 addition & 12 deletions lib/include/openamp/virtqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,22 +64,13 @@ typedef enum {
} vq_postpone_t;

struct virtqueue {
//TODO: Need to define proper structure for
// virtio device with RPmsg and paravirtualization.

struct virtio_device *vq_dev;
char vq_name[VIRTQUEUE_MAX_NAME_SZ];
uint16_t vq_queue_index;
uint16_t vq_nentries;
uint32_t vq_flags;
int vq_alignment;
int vq_ring_size;
boolean vq_inuse;
void *vq_ring_mem;
void (*callback) (struct virtqueue * vq);
void (*notify) (struct virtqueue * vq);
int vq_max_indirect_size;
int vq_indirect_mem_size;
struct vring vq_ring;
uint16_t vq_free_cnt;
uint16_t vq_queued_cnt;
Expand All @@ -105,7 +96,7 @@ struct virtqueue {
*/
uint16_t vq_available_idx;

uint8_t padd;
boolean vq_inuse;

/*
* Used by the host side during callback. Cookie
Expand All @@ -115,8 +106,6 @@ struct virtqueue {

struct vq_desc_extra {
void *cookie;
struct vring_desc *indirect;
uint32_t indirect_paddr;
uint16_t ndescs;
} vq_descx[0];
};
Expand Down
30 changes: 4 additions & 26 deletions lib/virtio/virtqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <metal/alloc.h>

/* Prototype for internal functions. */
static void vq_ring_init(struct virtqueue *);
static void vq_ring_init(struct virtqueue *, void *, int);
static void vq_ring_update_avail(struct virtqueue *, uint16_t);
static uint16_t vq_ring_add_buffer(struct virtqueue *, struct vring_desc *,
uint16_t, struct metal_sg *, int, int);
Expand Down Expand Up @@ -57,8 +57,6 @@ int virtqueue_create(struct virtio_device *virt_dev, unsigned short id,
VQ_PARAM_CHK(ring->num_descs & (ring->num_descs - 1), status,
ERROR_VRING_ALIGN);

//TODO : Error check for indirect buffer addition

if (status == VQUEUE_SUCCESS) {

vq_size = sizeof(struct virtqueue)
Expand All @@ -74,29 +72,21 @@ int virtqueue_create(struct virtio_device *virt_dev, unsigned short id,
vq->vq_dev = virt_dev;
strncpy(vq->vq_name, name, VIRTQUEUE_MAX_NAME_SZ);
vq->vq_queue_index = id;
vq->vq_alignment = ring->align;
vq->vq_nentries = ring->num_descs;
vq->vq_free_cnt = vq->vq_nentries;
vq->callback = callback;
vq->notify = notify;
vq->shm_io = shm_io;

//TODO : Whether we want to support indirect addition or not.
vq->vq_ring_size = vring_size(ring->num_descs, ring->align);
vq->vq_ring_mem = (void *)ring->vaddr;

/* Initialize vring control block in virtqueue. */
vq_ring_init(vq);
vq_ring_init(vq, (void *)ring->vaddr, ring->align);

/* Disable callbacks - will be enabled by the application
* once initialization is completed.
*/
virtqueue_disable_cb(vq);

*v_queue = vq;

//TODO : Need to add cleanup in case of error used with the indirect buffer addition
//TODO: do we need to save the new queue in db based on its id
}

return (status);
Expand Down Expand Up @@ -131,14 +121,10 @@ int virtqueue_add_buffer(struct virtqueue *vq, struct metal_sg *sg,
VQ_PARAM_CHK(needed < 1, status, ERROR_VQUEUE_INVLD_PARAM);
VQ_PARAM_CHK(vq->vq_free_cnt == 0, status, ERROR_VRING_FULL);

//TODO: Add parameters validation for indirect buffer addition

VQUEUE_BUSY(vq);

if (status == VQUEUE_SUCCESS) {

//TODO : Indirect buffer addition support

VQASSERT(vq, cookie != NULL, "enqueuing with no cookie");

head_idx = vq->vq_desc_head_idx;
Expand Down Expand Up @@ -305,12 +291,6 @@ void virtqueue_free(struct virtqueue *vq)
"%s: freeing non-empty virtqueue\r\n",
vq->vq_name);
}
//TODO : Need to free indirect buffers here

if (vq->vq_ring_mem != NULL) {
vq->vq_ring_size = 0;
vq->vq_ring_mem = NULL;
}

metal_free_memory(vq);
}
Expand Down Expand Up @@ -582,17 +562,15 @@ static void vq_ring_free_chain(struct virtqueue *vq, uint16_t desc_idx)
* vq_ring_init
*
*/
static void vq_ring_init(struct virtqueue *vq)
static void vq_ring_init(struct virtqueue *vq, void *ring_mem, int alignment)
{
struct vring *vr;
unsigned char *ring_mem;
int i, size;

ring_mem = vq->vq_ring_mem;
size = vq->vq_nentries;
vr = &vq->vq_ring;

vring_init(vr, size, ring_mem, vq->vq_alignment);
vring_init(vr, size, (unsigned char *)ring_mem, alignment);

for (i = 0; i < size - 1; i++)
vr->desc[i].next = i + 1;
Expand Down