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_GUEST_H
11#define VIRTIO_GUEST_H
12
13struct virtqueue;
14
15/**
16 * represents the channel backend to be used for this VirtIO guest library
17 */
18enum virtio_guest_channel
19{
20    VIRTIO_GUEST_CHAN_INVALID,  ///< the channel type is invalid
21    VIRTIO_GUEST_CHAN_FLOUNDER, ///< the flounder RPC backend should be used
22    VIRTIO_GUEST_CHAN_XEON_PHI, ///< the xeon phi messaging backend should be used
23};
24
25/**
26 * holds the function pointers to the respective channel backends
27 */
28struct virtio_guest_chan_fn
29{
30    errval_t (*open)(uint8_t backend, struct capref *ret_frame);
31    errval_t (*close)(void);
32    errval_t (*add)(struct virtqueue *vq);
33    errval_t (*ext)(uint16_t vq_id, struct capref vbuf);
34    errval_t (*req)(uint64_t size, struct capref *cap);
35};
36
37extern struct virtio_guest_chan_fn *vguest_chan_fn;
38
39/**
40 *
41 */
42errval_t virtio_guest_init(enum virtio_guest_channel backend,
43                           char *iface);
44
45/**
46 *
47 */
48static inline errval_t virtio_guest_open_device(uint8_t backend,
49                                                struct capref *ret_frame)
50{
51    return vguest_chan_fn->open(backend, ret_frame);
52}
53
54/**
55 *
56 */
57static inline errval_t virtio_guest_close_device(void)
58{
59    return vguest_chan_fn->close();
60}
61
62/**
63 *
64 */
65static inline errval_t virtio_guest_add_virtq(struct virtqueue *vq)
66{
67    return vguest_chan_fn->add(vq);
68}
69
70/**
71 *
72 */
73static inline errval_t virtio_guest_extend_vring(uint16_t vq_id,
74                                                 struct capref vbuf)
75{
76    return vguest_chan_fn->ext(vq_id, vbuf);
77}
78
79/**
80 *
81 */
82static inline errval_t virtio_guest_request_mem(uint64_t size,
83                                                struct capref *cap)
84{
85    return vguest_chan_fn->req(size, cap);
86}
87
88#endif // VIRTIO_GUEST_H
89