Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 178 lines (153 sloc) 6.265 kb
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
1 /* $NetBSD$ */
2
3 /*
4 * Copyright (c) 2010 Minoura Makoto.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 /*
29 * Part of the file derived from `Virtio PCI Card Specification v0.8.6 DRAFT'
30 * Appendix A.
31 */
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
32
33 /*
34 * An interface for efficient virtio implementation.
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
35 *
36 * This header is BSD licensed so anyone can use the definitions
37 * to implement compatible drivers/servers.
38 *
39 * Copyright 2007, 2009, IBM Corporation
40 * All rights reserved.
41 *
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
44 * are met:
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
50 * 3. Neither the name of IBM nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
53 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
54 * ``AS IS'' ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
55 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
57 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
58 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
59 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * SUCH DAMAGE.
64 */
65
66
67 #ifndef _DEV_PCI_VIRTIOREG_H_
68 #define _DEV_PCI_VIRTIOREG_H_
69
70 #include <sys/types.h>
71
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
72 #define PCI_VENDOR_QUMRANET 0x1af4
73 #define PCI_DEV_VIRTIO_MIN 0x1000
74 #define PCI_DEV_VIRTIO_MAX 0x103f
75 #define VIRTIO_PCI_ABI_VERSION 0
c623c4f @xl0 Add vendor/device ID definitions
xl0 authored
76
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
77 /* Virtio product id (subsystem) */
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
78 #define PCI_PRODUCT_VIRTIO_NETWORK 1
79 #define PCI_PRODUCT_VIRTIO_BLOCK 2
80 #define PCI_PRODUCT_VIRTIO_CONSOLE 3
81 #define PCI_PRODUCT_VIRTIO_ENTROPY 4
82 #define PCI_PRODUCT_VIRTIO_BALLOON 5
83 #define PCI_PRODUCT_VIRTIO_9P 9
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
84
85 /* Virtio header */
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
86 #define VIRTIO_CONFIG_DEVICE_FEATURES 0 /* 32bit */
87 #define VIRTIO_CONFIG_GUEST_FEATURES 4 /* 32bit */
6c226a7 @xl0 Implement legacy pci interrupt support
xl0 authored
88
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
89 #define VIRTIO_F_NOTIFY_ON_EMPTY (1<<24)
90 #define VIRTIO_F_RING_INDIRECT_DESC (1<<28)
91 #define VIRTIO_F_BAD_FEATURE (1<<30)
6c226a7 @xl0 Implement legacy pci interrupt support
xl0 authored
92
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
93 #define VIRTIO_CONFIG_QUEUE_ADDRESS 8 /* 32bit */
94 #define VIRTIO_CONFIG_QUEUE_SIZE 12 /* 16bit */
95 #define VIRTIO_CONFIG_QUEUE_SELECT 14 /* 16bit */
96 #define VIRTIO_CONFIG_QUEUE_NOTIFY 16 /* 16bit */
97 #define VIRTIO_CONFIG_DEVICE_STATUS 18 /* 8bit */
6c226a7 @xl0 Implement legacy pci interrupt support
xl0 authored
98
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
99 #define VIRTIO_CONFIG_DEVICE_STATUS_RESET 0
100 #define VIRTIO_CONFIG_DEVICE_STATUS_ACK 1
101 #define VIRTIO_CONFIG_DEVICE_STATUS_DRIVER 2
102 #define VIRTIO_CONFIG_DEVICE_STATUS_DRIVER_OK 4
103 #define VIRTIO_CONFIG_DEVICE_STATUS_FAILED 128
6c226a7 @xl0 Implement legacy pci interrupt support
xl0 authored
104
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
105 #define VIRTIO_CONFIG_ISR_STATUS 19 /* 8bit */
106 #define VIRTIO_CONFIG_ISR_CONFIG_CHANGE 2
6c226a7 @xl0 Implement legacy pci interrupt support
xl0 authored
107
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
108 #define VIRTIO_CONFIG_CONFIG_VECTOR 20 /* 16bit, optional */
109 #define VIRTIO_CONFIG_QUEUE_VECTOR 22
bd989f0 @xl0 Fix config offset updates
xl0 authored
110
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
111 #define VIRTIO_CONFIG_DEVICE_CONFIG_NOMSI 20
112 #define VIRTIO_CONFIG_DEVICE_CONFIG_MSI 24
24a335c @xl0 MSI update and stuff
xl0 authored
113
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
114 #define VIRTIO_MSI_NO_VECTOR 0xffff
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
115
116 /* Virtqueue */
117 /* This marks a buffer as continuing via the next field. */
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
118 #define VRING_DESC_F_NEXT 1
119 /*
120 * This marks a buffer as write-only, from the devices's perspective.
121 * (otherwise read-only).
122 */
123 #define VRING_DESC_F_WRITE 2
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
124 /* This means the buffer contains a list of buffer descriptors. */
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
125 #define VRING_DESC_F_INDIRECT 4
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
126
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
127 /*
128 * The Host uses this in used->flags to advise the Guest: don't kick me
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
129 * when you add a buffer. It's unreliable, so it's simply an
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
130 * optimization. Guest will still kick if it's out of buffers.
131 */
132 #define VRING_USED_F_NO_NOTIFY 1
133 /*
134 * The Guest uses this in avail->flags to advise the Host: don't
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
135 * interrupt me when you consume a buffer. It's unreliable, so it's
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
136 * simply an optimization.
137 */
138 #define VRING_AVAIL_F_NO_INTERRUPT 1
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
139
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
140 /*
141 * Virtio ring descriptors: 16 bytes.
142 * These can chain together via "next".
143 */
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
144 struct vring_desc {
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
145 /* Address (guest-physical). */
146 uint64_t addr;
147 /* Length. */
148 uint32_t len;
149 /* The flags as indicated above. */
150 uint16_t flags;
151 /* We chain unused descriptors via this, too */
152 uint16_t next;
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
153 } __packed;
154
155 struct vring_avail {
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
156 uint16_t flags;
157 uint16_t idx;
158 uint16_t ring[];
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
159 } __packed;
160
161 /* u32 is used here for ids for padding reasons. */
162 struct vring_used_elem {
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
163 /* Index of start of used descriptor chain. */
164 uint32_t id;
165 /* Total length of the descriptor chain which was written to. */
166 uint32_t len;
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
167 } __packed;
168
169 struct vring_used {
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
170 uint16_t flags;
171 uint16_t idx;
172 struct vring_used_elem ring[];
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
173 } __packed;
174
b64110f @xl0 I ♥♥♥ luuv ♥♥♥ cstyle
xl0 authored
175 #define VIRTIO_PAGE_SIZE (4096)
13b67be @xl0 Import virtioreg.h and virtiovar.h from the NetBSD driver
xl0 authored
176
177 #endif /* _DEV_PCI_VIRTIOREG_H_ */
Something went wrong with that request. Please try again.