1/* 2 * Copyright (c) 2014 ETH Zurich. 3 * All rights reserved. 4 * 5 * This file is distributed under the terms in the attached LICENSE file. 6 * If you do not find this file, copies can be found by writing to: 7 * ETH Zurich D-INFK, Universitaetsstrasse 6, CH-8092 Zurich. Attn: Systems Group. 8 */ 9 10#ifndef VIRTIO_HOST_H 11#define VIRTIO_HOST_H 12 13 14struct virtqueue_host; 15struct virtio_device; 16struct virtio_device_setup; 17struct virtqueue_setup; 18 19struct virtio_host_cb 20{ 21 errval_t (*open)(struct virtio_device *vdev, uint8_t backend, struct capref *ret_frame); 22 errval_t (*close)(void); 23 errval_t (*add)(struct virtio_device *vdev, struct capref ring, 24 uint16_t ndesc, uint8_t has_buffers, uint16_t vq_id); 25 errval_t (*ext)(struct virtio_device *vdev); 26 errval_t (*req)(struct virtio_device *vdev, struct capref *cap); 27 errval_t (*notify)(struct virtio_device *vq, uint16_t index); 28}; 29 30/** 31 * stores the information about the buffer received from the guest 32 */ 33struct virtio_host_buf 34{ 35 lvaddr_t vaddr; 36 size_t size; 37 uint16_t flags; 38 struct virtio_host_buf *next; 39 40}; 41 42/// workhandler for the virtqueue (host side) 43typedef void (*virtq_work_handler_t)(struct virtqueue_host *, 44 void *, 45 struct virtio_host_buf *, 46 uint16_t idx); 47 48 49 50/** 51 * \brief initializes the VirtIO device and the host side services 52 * 53 * \param host where the host structure pointer will be stored 54 * \param setup information needed to configure the host 55 */ 56errval_t virtio_host_init(struct virtio_device **host, 57 struct virtio_device_setup *setup); 58 59/** 60 * \brief polls the device to see if the driver has written something to the 61 * registers 62 * 63 * \param host the virtio host device 64 * 65 * \returns SYS_ERR_OK if there was an event on the device 66 * VIRTIO_ERR_DEVICE_IDLE if there was nothing new 67 * VIRTIO_ERR_* on failure 68 */ 69errval_t virtio_host_poll_device(struct virtio_device *host); 70 71/** 72 * 73 */ 74errval_t virtio_host_get_device_cap(struct virtio_device *host, 75 struct capref *ret_cap); 76 77 78lpaddr_t virtio_host_translate_host_addr(lpaddr_t host_phys); 79 80lpaddr_t virtio_host_translate_guest_addr(lpaddr_t guest_phys); 81 82#endif // VIRTIO_GUEST_H 83