Skip to content

Commit

Permalink
virtio: Inline vring_init() and vring_need_event() functions
Browse files Browse the repository at this point in the history
Both of these functions should be internal to virtqueue. They should have
had no usefulness outside of this file and so moving them should not
cause any API issue. This simplifies the virtio ring setup code for
later improvements

Signed-off-by: Andrew Davis <afd@ti.com>
  • Loading branch information
glneo committed Mar 15, 2024
1 parent 79b795e commit b66e8c5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 26 deletions.
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

0 comments on commit b66e8c5

Please sign in to comment.