Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / SLOF / lib / libvirtio / virtio.h
1 /******************************************************************************
2  * Copyright (c) 2011 IBM Corporation
3  * All rights reserved.
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
8  *
9  * Contributors:
10  *     IBM Corporation - initial implementation
11  *****************************************************************************/
12
13 #ifndef _LIBVIRTIO_H
14 #define _LIBVIRTIO_H
15
16 #include <stdint.h>
17
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
23
24 #define VIRTIO_TIMEOUT                  5000 /* 5 sec timeout */
25
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 */
30
31 /* Descriptor table entry - see Virtio Spec chapter 2.3.2 */
32 struct vring_desc {
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 */
37 }; 
38
39 /* Definitions for vring_avail.flags */
40 #define VRING_AVAIL_F_NO_INTERRUPT      1
41
42 /* Available ring - see Virtio Spec chapter 2.3.4 */
43 struct vring_avail {
44         uint16_t flags;
45         uint16_t idx;
46         uint16_t ring[];
47 }; 
48
49
50 /* Definitions for vring_used.flags */
51 #define VRING_USED_F_NO_NOTIFY          1
52
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 */
56 };
57
58 struct vring_used {
59         uint16_t flags;
60         uint16_t idx;
61         struct vring_used_elem ring[];
62 };
63
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 */
68 };
69
70 /* Parts of the virtqueue are aligned on a 4096 byte page boundary */
71 #define VQ_ALIGN(addr)  (((addr) + 0xfff) & ~0xfff)
72
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);
78
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,
87                                 int offset, int len);
88
89
90 #endif /* _LIBVIRTIO_H */