1 #ifndef _LINUX_VIRTIO_H
2 #define _LINUX_VIRTIO_H
3
4 #include "virtio_ring.h"
5
6 #define scatterlist VirtIOBufferDescriptor
7
8 struct VirtIOBufferDescriptor {
9 PHYSICAL_ADDRESS physAddr;
10 ULONG length;
11 };
12
13 typedef int (*proc_virtqueue_add_buf)(
14 struct virtqueue *vq,
15 struct scatterlist sg[],
16 unsigned int out_num,
17 unsigned int in_num,
18 void *opaque,
19 void *va_indirect,
20 ULONGLONG phys_indirect);
21
22 typedef bool(*proc_virtqueue_kick_prepare)(struct virtqueue *vq);
23
24 typedef void(*proc_virtqueue_kick_always)(struct virtqueue *vq);
25
26 typedef void * (*proc_virtqueue_get_buf)(struct virtqueue *vq, unsigned int *len);
27
28 typedef void(*proc_virtqueue_disable_cb)(struct virtqueue *vq);
29
30 typedef bool(*proc_virtqueue_enable_cb)(struct virtqueue *vq);
31
32 typedef bool(*proc_virtqueue_enable_cb_delayed)(struct virtqueue *vq);
33
34 typedef void * (*proc_virtqueue_detach_unused_buf)(struct virtqueue *vq);
35
36 typedef BOOLEAN(*proc_virtqueue_is_interrupt_enabled)(struct virtqueue *vq);
37
38 typedef BOOLEAN(*proc_virtqueue_has_buf)(struct virtqueue *vq);
39
40 typedef void(*proc_virtqueue_shutdown)(struct virtqueue *vq);
41
42 /* Represents one virtqueue; only data pointed to by the vring structure is exposed to the host */
43 struct virtqueue {
44 VirtIODevice *vdev;
45 unsigned int index;
46 void (*notification_cb)(struct virtqueue *vq);
47 void *notification_addr;
48 void *avail_va;
49 void *used_va;
50 proc_virtqueue_add_buf add_buf;
51 proc_virtqueue_kick_prepare kick_prepare;
52 proc_virtqueue_kick_always kick_always;
53 proc_virtqueue_get_buf get_buf;
54 proc_virtqueue_disable_cb disable_cb;
55 proc_virtqueue_enable_cb enable_cb;
56 proc_virtqueue_enable_cb_delayed enable_cb_delayed;
57 proc_virtqueue_detach_unused_buf detach_unused_buf;
58 proc_virtqueue_is_interrupt_enabled is_interrupt_enabled;
59 proc_virtqueue_has_buf has_buf;
60 proc_virtqueue_shutdown shutdown;
61 };
62
virtqueue_add_buf(struct virtqueue * vq,struct scatterlist sg[],unsigned int out_num,unsigned int in_num,void * opaque,void * va_indirect,ULONGLONG phys_indirect)63 static inline int virtqueue_add_buf(
64 struct virtqueue *vq,
65 struct scatterlist sg[],
66 unsigned int out_num,
67 unsigned int in_num,
68 void *opaque,
69 void *va_indirect,
70 ULONGLONG phys_indirect)
71 {
72 return vq->add_buf(vq, sg, out_num, in_num, opaque, va_indirect, phys_indirect);
73 }
74
virtqueue_kick_prepare(struct virtqueue * vq)75 static inline bool virtqueue_kick_prepare(struct virtqueue *vq)
76 {
77 return vq->kick_prepare(vq);
78 }
79
virtqueue_kick_always(struct virtqueue * vq)80 static inline void virtqueue_kick_always(struct virtqueue *vq)
81 {
82 vq->kick_always(vq);
83 }
84
virtqueue_get_buf(struct virtqueue * vq,unsigned int * len)85 static inline void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len)
86 {
87 return vq->get_buf(vq, len);
88 }
89
virtqueue_disable_cb(struct virtqueue * vq)90 static inline void virtqueue_disable_cb(struct virtqueue *vq)
91 {
92 vq->disable_cb(vq);
93 }
94
virtqueue_enable_cb(struct virtqueue * vq)95 static inline bool virtqueue_enable_cb(struct virtqueue *vq)
96 {
97 return vq->enable_cb(vq);
98 }
99
virtqueue_enable_cb_delayed(struct virtqueue * vq)100 static inline bool virtqueue_enable_cb_delayed(struct virtqueue *vq)
101 {
102 return vq->enable_cb_delayed(vq);
103 }
104
virtqueue_detach_unused_buf(struct virtqueue * vq)105 static inline void *virtqueue_detach_unused_buf(struct virtqueue *vq)
106 {
107 return vq->detach_unused_buf(vq);
108 }
109
virtqueue_is_interrupt_enabled(struct virtqueue * vq)110 static inline BOOLEAN virtqueue_is_interrupt_enabled(struct virtqueue *vq)
111 {
112 return vq->is_interrupt_enabled(vq);
113 }
114
virtqueue_has_buf(struct virtqueue * vq)115 static inline BOOLEAN virtqueue_has_buf(struct virtqueue *vq)
116 {
117 return vq->has_buf(vq);
118 }
119
virtqueue_shutdown(struct virtqueue * vq)120 static inline void virtqueue_shutdown(struct virtqueue *vq)
121 {
122 vq->shutdown(vq);
123 }
124
125 void virtqueue_notify(struct virtqueue *vq);
126 void virtqueue_kick(struct virtqueue *vq);
127
128 #endif /* _LINUX_VIRTIO_H */
129