1/* 2 * Copyright 2018, Data61 3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO) 4 * ABN 41 687 119 230. 5 * 6 * This software may be distributed and modified according to the terms of 7 * the BSD 2-Clause license. Note that NO WARRANTY is provided. 8 * See "LICENSE_BSD2.txt" for details. 9 * 10 * @TAG(DATA61_BSD) 11 */ 12 13#include <camkes/virtqueue.h> 14#include <camkes/virtqueue_template.h> 15 16camkes_virtqueue_channel_t camkes_virtqueue_channels[MAX_CAMKES_VIRTQUEUE_ID + 1]; 17int num_registered_virtqueue_channels = 0; 18 19int camkes_virtqueue_channel_register(int virtqueue_id, const char *interface_name, unsigned queue_len, size_t size, 20 volatile void *buf, void (*notify)(void), 21 seL4_CPtr recv_notification, seL4_Word recv_badge, virtqueue_role_t role) 22{ 23 /* Check that the virtqueue_id is in range */ 24 if (virtqueue_id > MAX_CAMKES_VIRTQUEUE_ID) { 25 return -1; 26 } 27 /* Check that the buffer and notify function are not NULL */ 28 if (buf == NULL || notify == NULL) { 29 return -1; 30 } 31 /* Initialise the contents of the virtqueue channel */ 32 camkes_virtqueue_channel_t *vq_channel = &camkes_virtqueue_channels[virtqueue_id]; 33 vq_channel->channel_buffer = buf; 34 vq_channel->channel_buffer_size = size; 35 vq_channel->queue_len = queue_len; 36 vq_channel->notify = notify; 37 vq_channel->recv_notification = recv_notification; 38 vq_channel->recv_badge = recv_badge; 39 vq_channel->role = role; 40 vq_channel->buffer_allocated = 0; 41 vq_channel->interface_name = interface_name; 42 num_registered_virtqueue_channels++; 43 return 0; 44} 45