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

virtio: Inline vring_init() and vring_need_event() functions #569

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
25 changes: 0 additions & 25 deletions lib/include/openamp/virtio_ring.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,31 +186,6 @@ static inline int vring_size(unsigned int num, unsigned long align)
return size;
}

static inline void
vring_init(struct vring *vr, unsigned int num, uint8_t *p, unsigned long align)
{
vr->num = num;
vr->desc = (struct vring_desc *)p;
vr->avail = (struct vring_avail *)(p + num * sizeof(struct vring_desc));
vr->used = (struct vring_used *)
(((unsigned long)&vr->avail->ring[num] + sizeof(uint16_t) +
align - 1) & ~(align - 1));
}

/*
* The following is used with VIRTIO_RING_F_EVENT_IDX.
*
* Assuming a given event_idx value from the other size, if we have
* just incremented index from old to new_idx, should we trigger an
* event?
*/
static inline int
vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
{
return (uint16_t)(new_idx - event_idx - 1) <
(uint16_t)(new_idx - old);
}

#if defined __cplusplus
}
#endif
Expand Down
20 changes: 19 additions & 1 deletion lib/virtio/virtqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,12 @@ static void vq_ring_init(struct virtqueue *vq, void *ring_mem, int alignment)
size = vq->vq_nentries;
vr = &vq->vq_ring;

vring_init(vr, size, ring_mem, alignment);
vr->num = size;
vr->desc = (struct vring_desc *)ring_mem;
vr->avail = (struct vring_avail *)(ring_mem + size * sizeof(struct vring_desc));
vr->used = (struct vring_used *)
(((unsigned long)&vr->avail->ring[size] + sizeof(uint16_t) +
alignment - 1) & ~(alignment - 1));

#ifndef VIRTIO_DEVICE_ONLY
if (vq->vq_dev->role == VIRTIO_DEV_DRIVER) {
Expand Down Expand Up @@ -627,6 +632,19 @@ void virtqueue_notification(struct virtqueue *vq)
vq->callback(vq);
}

/*
* The following is used with VIRTIO_RING_F_EVENT_IDX.
*
* Assuming a given event_idx value from the other size, if we have
* just incremented index from old to new_idx, should we trigger an
* event?
*/
static int vring_need_event(uint16_t event_idx, uint16_t new_idx, uint16_t old)
{
return (uint16_t)(new_idx - event_idx - 1) <
(uint16_t)(new_idx - old);
}

/*
*
* vq_ring_must_notify
Expand Down
Loading