L4Re - L4 Runtime Environment
virtio.h
1 /*
2  * (c) 2013-2014 Alexander Warg <warg@os.inf.tu-dresden.de>
3  * Matthias Lange <matthias.lange@kernkonzept.com>
4  *
5  * This file is part of TUD:OS and distributed under the terms of the
6  * GNU General Public License 2.
7  * Please see the COPYING-GPL-2 file for details.
8  *
9  * As a special exception, you may use this file as part of a free software
10  * library without restriction. Specifically, if other files instantiate
11  * templates or use macros or inline functions from this file, or you compile
12  * this file and link it with other files to produce an executable, this
13  * file does not by itself cause the resulting executable to be covered by
14  * the GNU General Public License. This exception does not however
15  * invalidate any other reasons why the executable file might be covered by
16  * the GNU General Public License.
17  */
18 
19 #pragma once
20 
39 #include <l4/sys/utcb.h>
40 #include <l4/sys/ipc.h>
41 #include <l4/sys/types.h>
42 
45 {
46  L4VIRTIO_PROTOCOL = 0,
47 };
48 
49 enum L4virtio_magic
50 {
51  L4VIRTIO_MAGIC = 0x74726976
52 };
53 
56 {
61 };
62 
65 {
81  L4VIRTIO_ID_SOCK = 0x9999,
82 };
83 
86 {
92 };
93 
96 {
101 };
102 
108 {
111 };
112 
117 {
118  L4VIRTIO_CMD_NONE = 0x00000000,
119  L4VIRTIO_CMD_SET_STATUS = 0x01000000,
120  L4VIRTIO_CMD_CFG_QUEUE = 0x02000000,
121  L4VIRTIO_CMD_MASK = 0xff000000,
122 };
123 
127 typedef struct l4virtio_config_hdr_t
128 {
135  l4_uint32_t dev_features_sel;
136  l4_uint32_t _res1[2];
137 
138  l4_uint32_t driver_features;
139  l4_uint32_t driver_features_sel;
140 
141  /* some L4virtio specific members ... */
145  /* must start at 0x30 (per virtio-mmio layout) */
146  l4_uint32_t queue_sel;
147  l4_uint32_t queue_num_max;
148  l4_uint32_t queue_num;
149  l4_uint32_t _res3[2];
150  l4_uint32_t queue_ready;
151  l4_uint32_t _res4[2];
152 
153  l4_uint32_t queue_notify;
154  l4_uint32_t _res5[3];
155 
156  l4_uint32_t irq_status;
157  l4_uint32_t irq_ack;
158  l4_uint32_t _res6[2];
159 
167  l4_uint32_t _res7[3];
168 
169  l4_uint64_t queue_desc;
170  l4_uint32_t _res8[2];
171  l4_uint64_t queue_avail;
172  l4_uint32_t _res9[2];
173  l4_uint64_t queue_used;
174 
175  /* use the unused space here for device and driver feature bitmaps */
176  l4_uint32_t dev_features_map[8];
177  l4_uint32_t driver_features_map[8];
178 
179  l4_uint32_t _res10[2];
180 
185 
188  l4_uint32_t generation;
190 
209 {
214 
217 
220 
228 
230 
236 L4_INLINE l4virtio_config_queue_t *
238 {
239  return (l4virtio_config_queue_t *)(((l4_addr_t)cfg) + cfg->queues_offset);
240 }
241 
247 L4_INLINE void *
249 {
250  return (void *)(((l4_addr_t)cfg) + 0x100);
251 }
252 
256 L4_INLINE void
257 l4virtio_set_feature(l4_uint32_t *feature_map, unsigned feat)
258 {
259  unsigned idx = feat / 32;
260 
261  if (idx < 8)
262  feature_map[idx] |= 1UL << (feat % 32);
263 }
264 
268 L4_INLINE void
269 l4virtio_clear_feature(l4_uint32_t *feature_map, unsigned feat)
270 {
271  unsigned idx = feat / 32;
272 
273  if (idx < 8)
274  feature_map[idx] &= ~(1UL << (feat % 32));
275 }
276 
280 L4_INLINE unsigned
281 l4virtio_get_feature(l4_uint32_t *feature_map, unsigned feat)
282 {
283  unsigned idx = feat / 32;
284 
285  if (idx >= 8)
286  return 0;
287 
288  return feature_map[idx] & (1UL << (feat % 32));
289 }
290 
300 L4_CV int
302 
319 L4_CV int
320 l4virtio_config_queue(l4_cap_idx_t cap, unsigned queue) L4_NOTHROW;
321 
336 L4_CV int
338  l4_uint64_t base, l4_umword_t offset,
339  l4_umword_t size) L4_NOTHROW;
340 
355 L4_CV int
357  l4_cap_idx_t host_irq, l4_cap_idx_t config_ds) L4_NOTHROW;
359 
int l4virtio_register_iface(l4_cap_idx_t cap, l4_cap_idx_t guest_irq, l4_cap_idx_t host_irq, l4_cap_idx_t config_ds) L4_NOTHROW
Register client to the given L4-VIRTIO host.
Set the status register.
Definition: virtio.h:119
l4_uint32_t magic
magic value (must be &#39;virt&#39;).
Definition: virtio.h:129
Guest OS has found device.
Definition: virtio.h:87
l4_uint32_t status
Device status register (read-only).
Definition: virtio.h:166
Status and queue config are set via cmd field instead of via IPC.
Definition: virtio.h:100
L4virtio_device_status
Virtio device status bits.
Definition: virtio.h:85
VRING IRQ pending flag.
Definition: virtio.h:109
void l4virtio_set_feature(l4_uint32_t *feature_map, unsigned feat)
Set the given feature bit in a feature map.
Definition: virtio.h:257
l4_uint16_t device_notify_index
R: Event index to be used by the driver (driver to device)
Definition: virtio.h:226
General block device.
Definition: virtio.h:67
l4_uint32_t version
VIRTIO version.
Definition: virtio.h:130
l4_uint32_t cfg_driver_notify_index
W: Event index to be used for config notifications (device to driver)
Definition: virtio.h:182
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition: l4int.h:38
int l4virtio_config_queue(l4_cap_idx_t cap, unsigned queue) L4_NOTHROW
Trigger queue configuration of the given queue.
Fatal error in driver or device.
Definition: virtio.h:91
Common L4 ABI Data Types.
L4_virtio_cmd
Virtio commands for device configuration.
Definition: virtio.h:116
l4_uint32_t cmd
L4 specific command register polled by the driver iff supported.
Definition: virtio.h:187
#define EXTERN_C_END
End section with C types and functions.
Definition: compiler.h:187
CONFIG IRQ pending flag.
Definition: virtio.h:110
Driver has acknowledged feature set.
Definition: virtio.h:90
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:341
Device using 9P transport protocol.
Definition: virtio.h:73
Inofficial socket device.
Definition: virtio.h:81
l4_uint64_t used_addr
W: address of used ring.
Definition: virtio.h:223
Rproc serial device.
Definition: virtio.h:74
Virtual ethernet card.
Definition: virtio.h:66
l4virtio_config_queue_t * l4virtio_config_queues(l4virtio_config_hdr_t const *cfg)
Get the pointer to the first queue config.
Definition: virtio.h:237
Crypto.
Definition: virtio.h:79
L4virtio_feature_bits
L4virtio-specific feature bits.
Definition: virtio.h:95
L4_virtio_protocol
L4-VIRTIO protocol number.
Definition: virtio.h:44
l4_uint16_t num
RW: number of descriptors configured for this queue.
Definition: virtio.h:213
l4_uint32_t device
device ID
Definition: virtio.h:131
Device using CAIF network protocol.
Definition: virtio.h:75
int l4virtio_set_status(l4_cap_idx_t cap, unsigned status) L4_NOTHROW
Write the VIRTIO status register.
l4_uint32_t queues_offset
offset of virtqueue config array
Definition: virtio.h:143
Register a data space as transport memory.
Definition: virtio.h:60
void * l4virtio_device_config(l4virtio_config_hdr_t const *cfg)
Get the pointer to the device configuration.
Definition: virtio.h:248
l4_uint32_t cfg_device_notify_index
R: Event index to be used for config notifications (driver to device)
Definition: virtio.h:184
Register a transport driver to the device.
Definition: virtio.h:59
Configure a queue.
Definition: virtio.h:120
SCSI host device.
Definition: virtio.h:72
L4-VIRTIO config header, provided in shared data space.
Definition: virtio.h:127
unsigned l4virtio_get_feature(l4_uint32_t *feature_map, unsigned feat)
Check if the given bit in a feature map is set.
Definition: virtio.h:281
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
l4_uint16_t num_max
R: maximum number of descriptors supported by this queue.
Definition: virtio.h:211
#define EXTERN_C_BEGIN
Start section with C types and functions.
Definition: compiler.h:186
l4_uint32_t vendor
vendor ID
Definition: virtio.h:132
l4_uint32_t dev_features
device features windows selected by device_feature_sel
Definition: virtio.h:134
L4_virtio_opcodes
L4-VIRTIO opcodes.
Definition: virtio.h:55
#define L4_CV
Define calling convention.
Definition: linkage.h:44
Device using rpmsg protocol.
Definition: virtio.h:71
Set queue config in device config.
Definition: virtio.h:58
l4_uint16_t ready
RW: queue ready flag (read-write)
Definition: virtio.h:216
l4_uint16_t driver_notify_index
W: Event index to be used for device notifications (device to driver)
Definition: virtio.h:219
struct l4virtio_config_hdr_t l4virtio_config_hdr_t
L4-VIRTIO config header, provided in shared data space.
L4virtio_device_ids
Virtio device IDs as reported in the driver&#39;s config space.
Definition: virtio.h:64
Queue configuration entry.
Definition: virtio.h:208
Driver is set up.
Definition: virtio.h:89
l4_uint32_t num_queues
number of virtqueues
Definition: virtio.h:142
L4_virtio_irq_status
VIRTIO IRQ status codes (l4virtio_config_hdr_t::irq_status).
Definition: virtio.h:107
No command pending.
Definition: virtio.h:118
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition: l4int.h:42
Mask to get command bits.
Definition: virtio.h:121
Input.
Definition: virtio.h:77
int l4virtio_register_ds(l4_cap_idx_t cap, l4_cap_idx_t ds_cap, l4_uint64_t base, l4_umword_t offset, l4_umword_t size) L4_NOTHROW
Register a shared data space with VIRTIO host.
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
Set status register in device config.
Definition: virtio.h:57
Memory balooning device.
Definition: virtio.h:70
l4_uint64_t desc_addr
W: address of descriptor table.
Definition: virtio.h:221
void l4virtio_clear_feature(l4_uint32_t *feature_map, unsigned feat)
Clear the given feature bit in a feature map.
Definition: virtio.h:269
Simple device for data IO via ports.
Definition: virtio.h:68
Virtio protocol version 1 supported. Must be 1 for L4virtio.
Definition: virtio.h:98
Entropy source.
Definition: virtio.h:69
l4_uint64_t avail_addr
W: address of available ring.
Definition: virtio.h:222
struct l4virtio_config_queue_t l4virtio_config_queue_t
Queue configuration entry.
Guest OS knows how to drive device.
Definition: virtio.h:88
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition: l4int.h:40
Vsock transport.
Definition: virtio.h:78
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185