4 #include <linux/virtio_ring.h>
5 #include <linux/virtio_pci.h>
7 #include <linux/types.h>
12 #define VIRTIO_IRQ_LOW 0
13 #define VIRTIO_IRQ_HIGH 1
15 #define VIRTIO_PCI_O_CONFIG 0
16 #define VIRTIO_PCI_O_MSIX 1
17 #define VIRTIO_PCI_O_FEATURES 2
22 /* The last_avail_idx field is an index to ->ring of struct vring_avail.
23 It's where we assume the next request index is at. */
27 static inline u16
virt_queue__pop(struct virt_queue
*queue
)
29 return queue
->vring
.avail
->ring
[queue
->last_avail_idx
++ % queue
->vring
.num
];
32 static inline struct vring_desc
*virt_queue__get_desc(struct virt_queue
*queue
, u16 desc_ndx
)
34 return &queue
->vring
.desc
[desc_ndx
];
37 static inline bool virt_queue__available(struct virt_queue
*vq
)
41 return vq
->vring
.avail
->idx
!= vq
->last_avail_idx
;
45 * Warning: on 32-bit hosts, shifting pfn left may cause a truncation of pfn values
46 * higher than 4GB - thus, pointing to the wrong area in guest virtual memory space
47 * and breaking the virt queue which owns this pfn.
49 static inline void *guest_pfn_to_host(struct kvm
*kvm
, u32 pfn
)
51 return guest_flat_to_host(kvm
, (unsigned long)pfn
<< VIRTIO_PCI_QUEUE_ADDR_SHIFT
);
54 struct vring_used_elem
*virt_queue__set_used_elem(struct virt_queue
*queue
, u32 head
, u32 len
);
56 u16
virt_queue__get_iov(struct virt_queue
*queue
, struct iovec iov
[], u16
*out
, u16
*in
, struct kvm
*kvm
);
57 u16
virt_queue__get_inout_iov(struct kvm
*kvm
, struct virt_queue
*queue
,
58 struct iovec in_iov
[], struct iovec out_iov
[],
61 void virt_queue__trigger_irq(struct virt_queue
*vq
, int irq
, u8
*isr
, struct kvm
*kvm
);
63 int virtio__get_dev_specific_field(int offset
, bool msix
, bool features_hi
, u32
*config_off
);
65 #endif /* KVM__VIRTIO_H */