L4Re - L4 Runtime Environment
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  */
19 #pragma once
39 #include <l4/sys/utcb.h>
40 #include <l4/sys/ipc.h>
41 #include <l4/sys/types.h>
45 {
47 };
49 enum L4virtio_magic
50 {
51  L4VIRTIO_MAGIC = 0x74726976
52 };
56 {
61 };
65 {
81  L4VIRTIO_ID_SOCK = 0x9999,
82 };
86 {
92 };
96 {
101 };
108 {
111 };
117 {
118  L4VIRTIO_CMD_NONE = 0x00000000,
119  L4VIRTIO_CMD_SET_STATUS = 0x01000000,
120  L4VIRTIO_CMD_CFG_QUEUE = 0x02000000,
121  L4VIRTIO_CMD_MASK = 0xff000000,
122 };
127 typedef struct l4virtio_config_hdr_t
128 {
135  l4_uint32_t dev_features_sel;
136  l4_uint32_t _res1[2];
138  l4_uint32_t driver_features;
139  l4_uint32_t driver_features_sel;
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];
153  l4_uint32_t queue_notify;
154  l4_uint32_t _res5[3];
156  l4_uint32_t irq_status;
157  l4_uint32_t irq_ack;
158  l4_uint32_t _res6[2];
167  l4_uint32_t _res7[3];
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;
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];
179  l4_uint32_t _res10[2];
188  l4_uint32_t generation;
209 {
236 L4_INLINE l4virtio_config_queue_t *
238 {
239  return (l4virtio_config_queue_t *)(((l4_addr_t)cfg) + cfg->queues_offset);
240 }
247 L4_INLINE void *
249 {
250  return (void *)(((l4_addr_t)cfg) + 0x100);
251 }
256 L4_INLINE void
257 l4virtio_set_feature(l4_uint32_t *feature_map, unsigned feat)
258 {
259  unsigned idx = feat / 32;
261  if (idx < 8)
262  feature_map[idx] |= 1UL << (feat % 32);
263 }
268 L4_INLINE void
269 l4virtio_clear_feature(l4_uint32_t *feature_map, unsigned feat)
270 {
271  unsigned idx = feat / 32;
273  if (idx < 8)
274  feature_map[idx] &= ~(1UL << (feat % 32));
275 }
280 L4_INLINE unsigned
281 l4virtio_get_feature(l4_uint32_t *feature_map, unsigned feat)
282 {
283  unsigned idx = feat / 32;
285  if (idx >= 8)
286  return 0;
288  return feature_map[idx] & (1UL << (feat % 32));
289 }
296 L4_CV int
304 L4_CV int
305 l4virtio_config_queue(l4_cap_idx_t cap, unsigned queue) L4_NOTHROW;
312 L4_CV int
314  l4_uint64_t base, l4_umword_t offset,
315  l4_umword_t size) L4_NOTHROW;
322 L4_CV int
324  l4_cap_idx_t host_irq, l4_cap_idx_t config_ds) L4_NOTHROW;
331 L4_CV int
333  l4_addr_t *ds_offset) L4_NOTHROW;
340 L4_CV int
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 L4-VIRTIO device.
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
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.
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:342
int l4virtio_device_notification_irq(l4_cap_idx_t cap, unsigned index, l4_cap_idx_t irq) L4_NOTHROW
Get the notification interrupt corresponding to the given index.
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
Definition: virtio.h:79
L4virtio-specific feature bits.
Definition: virtio.h:95
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
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.
Definition: virtio.h:55
#define L4_CV
Define calling convention.
Definition: linkage.h:44
int l4virtio_device_config_ds(l4_cap_idx_t cap, l4_cap_idx_t config_ds, l4_addr_t *ds_offset) L4_NOTHROW
Get the dataspace with the L4virtio configuration page.
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.
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
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
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