Skip to content
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
4 changes: 2 additions & 2 deletions libsel4camkes/include/camkes/virtqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void *camkes_virtqueue_driver_offset_to_buffer(virtqueue_driver_t *virtqueue, ui
* @param size the size of the buffer
* @return 0 on success, -1 on fail
*/
int camkes_virtqueue_driver_send_buffer(virtqueue_driver_t *vq, void *buffer, size_t size);
int camkes_virtqueue_driver_send_buffer(virtqueue_driver_t *vq, const void *buffer, size_t size);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function is also used for enqueuing buffers in the virtqueue to receive data on?

In this case send means that the buffer is being sent to the other end of the queue (the device side). If the queue is used for transmitting data then the data in the buffer would be read by the other end, but if the queue is being used for receiving data then the other side would modify the contents before sending it back.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. Would it make sense to separate the APIs then for the different use cases to support proper semantics?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the semantics are just enqueuing into available hands a mutable reference over, and receiving from the other queue takes it back. Whether the buffers are written to by the other side is a higher level concern depending on the protocol using the buffers.


/* Scatter and send one buffer (add to the available ring). Performs the pointer to offset conversion.
* Doesn't notify the other side. Scatters the buffer into chunks of BLOCK_SIZE, so the buffer can have
Expand All @@ -157,7 +157,7 @@ int camkes_virtqueue_driver_send_buffer(virtqueue_driver_t *vq, void *buffer, si
* @param size the size of the buffer
* @return 0 on success, -1 on fail
*/
int camkes_virtqueue_driver_scatter_send_buffer(virtqueue_driver_t *vq, void *buffer, size_t size);
int camkes_virtqueue_driver_scatter_send_buffer(virtqueue_driver_t *vq, void const *buffer, size_t size);

/* Takes a handle (obtained from a get_used_buffer invocation), iterates through all the buffers in
* the scatterlist and copies them into the buffer given as parameter. Once each buffer has been copied,
Expand Down
4 changes: 2 additions & 2 deletions libsel4camkes/src/virtqueue.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void *camkes_virtqueue_driver_offset_to_buffer(virtqueue_driver_t *virtqueue, ui
return allocator->buffer + offset;
}

int camkes_virtqueue_driver_send_buffer(virtqueue_driver_t *vq, void *buffer, size_t size)
int camkes_virtqueue_driver_send_buffer(virtqueue_driver_t *vq, void const *buffer, size_t size)
{
uintptr_t base_offset = (uintptr_t)(((struct vq_buf_alloc *)vq->cookie)->buffer);
uintptr_t buf_offset = (uintptr_t)buffer - base_offset;
Expand All @@ -178,7 +178,7 @@ static int chain_vq_buf(virtqueue_driver_t *vq, virtqueue_ring_object_t *handle,
return 0;
}

int camkes_virtqueue_driver_scatter_send_buffer(virtqueue_driver_t *vq, void *buffer, size_t size)
int camkes_virtqueue_driver_scatter_send_buffer(virtqueue_driver_t *vq, void const *buffer, size_t size)
{
size_t sent = 0;
virtqueue_ring_object_t handle;
Expand Down