1 /******************************************************************************
2 * Copyright (c) 2011 IBM Corporation
4 * This program and the accompanying materials
5 * are made available under the terms of the BSD License
6 * which accompanies this distribution, and is available at
7 * http://www.opensource.org/licenses/bsd-license.php
10 * IBM Corporation - initial implementation
11 *****************************************************************************/
18 /* Device status bits */
19 #define VIRTIO_STAT_ACKNOWLEDGE 1
20 #define VIRTIO_STAT_DRIVER 2
21 #define VIRTIO_STAT_DRIVER_OK 4
22 #define VIRTIO_STAT_FAILED 128
24 #define VIRTIO_TIMEOUT 5000 /* 5 sec timeout */
26 /* Definitions for vring_desc.flags */
27 #define VRING_DESC_F_NEXT 1 /* buffer continues via the next field */
28 #define VRING_DESC_F_WRITE 2 /* buffer is write-only (otherwise read-only) */
29 #define VRING_DESC_F_INDIRECT 4 /* buffer contains a list of buffer descriptors */
31 /* Descriptor table entry - see Virtio Spec chapter 2.3.2 */
33 uint64_t addr; /* Address (guest-physical) */
34 uint32_t len; /* Length */
35 uint16_t flags; /* The flags as indicated above */
36 uint16_t next; /* Next field if flags & NEXT */
39 /* Definitions for vring_avail.flags */
40 #define VRING_AVAIL_F_NO_INTERRUPT 1
42 /* Available ring - see Virtio Spec chapter 2.3.4 */
50 /* Definitions for vring_used.flags */
51 #define VRING_USED_F_NO_NOTIFY 1
53 struct vring_used_elem {
54 uint32_t id; /* Index of start of used descriptor chain */
55 uint32_t len; /* Total length of the descriptor chain which was used */
61 struct vring_used_elem ring[];
64 #define VIRTIO_TYPE_PCI 0 /* For virtio-pci interface */
65 struct virtio_device {
66 void *base; /* base address */
67 int type; /* VIRTIO_TYPE_PCI or VIRTIO_TYPE_VIO */
70 /* Parts of the virtqueue are aligned on a 4096 byte page boundary */
71 #define VQ_ALIGN(addr) (((addr) + 0xfff) & ~0xfff)
73 extern unsigned long virtio_vring_size(unsigned int qsize);
74 extern int virtio_get_qsize(struct virtio_device *dev, int queue);
75 extern struct vring_desc *virtio_get_vring_desc(struct virtio_device *dev, int queue);
76 extern struct vring_avail *virtio_get_vring_avail(struct virtio_device *dev, int queue);
77 extern struct vring_used *virtio_get_vring_used(struct virtio_device *dev, int queue);
79 extern void virtio_reset_device(struct virtio_device *dev);
80 extern void virtio_queue_notify(struct virtio_device *dev, int queue);
81 extern void virtio_set_status(struct virtio_device *dev, int status);
82 extern void virtio_set_qaddr(struct virtio_device *dev, int queue, unsigned int qaddr);
83 extern void virtio_set_guest_features(struct virtio_device *dev, int features);
84 extern void virtio_get_host_features(struct virtio_device *dev, int *features);
85 extern uint64_t virtio_get_config(struct virtio_device *dev, int offset, int size);
86 extern int __virtio_read_config(struct virtio_device *dev, void *dst,
90 #endif /* _LIBVIRTIO_H */