L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
virtio.h
1/* SPDX-License-Identifier: MIT */
2/*
3 * Copyright (C) 2013-2022, 2024-2025 Kernkonzept GmbH.
4 * Author(s): Alexander Warg <alexander.warg@kernkonzept.com>
5 * Matthias Lange <matthias.lange@kernkonzept.com>
6 *
7 */
8#pragma once
9
13
27
28#include <l4/sys/compiler.h>
29#include <l4/sys/utcb.h>
30#include <l4/sys/ipc.h>
31#include <l4/sys/types.h>
32
35{
36 L4VIRTIO_PROTOCOL = 0,
37};
38
39enum L4virtio_magic
40{
41 L4VIRTIO_MAGIC = 0x74726976
42};
43
44enum L4virtio_vendor
45{
46 L4VIRTIO_VENDOR_KK = 0x44
47};
48
60
89
100
101enum
102{
103 L4VIRTIO_FEATURES_MAP_WORDS = 6
104};
105
114
124
137
142{
143 /* Virtio(0x00): device config */
148
149 /* Virtio(0x10): device features */
151 l4_uint32_t dev_features_sel;
152 l4_uint32_t _res1[2];
153
154 /* Virtio(0x20): driver features */
155 l4_uint32_t driver_features;
156 l4_uint32_t driver_features_sel;
157
158 /* L4Virtio(0x28): L4 queue */
161
162 /* Virtio(0x30): queue status */
163 l4_uint32_t queue_sel;
164 l4_uint32_t queue_num_max;
165 l4_uint32_t queue_num;
166 l4_uint32_t _res3[2];
167 l4_uint32_t queue_ready;
168 l4_uint32_t _res4[2];
169
170 /* Virtio(0x50): queue notify */
171 l4_uint32_t queue_notify;
172 l4_uint32_t _res5[3];
173
174 /* Virtio(0x60): interrupt handling */
175 l4_uint32_t irq_status;
176 l4_uint32_t irq_ack;
177 l4_uint32_t _res6[2];
178
179 /* Virtio(0x70): Device status register (read-only). The register must be
180 * written using l4virtio_set_status(). */
181 l4_uint32_t status;
182
183 /* L4Virtio(0x74): W: Event index to be used for config notifications (device to driver) */
184 l4_uint32_t cfg_driver_notify_index;
185 /* L4Virtio(0x78): R: Event index to be used for config notifications (driver to device) */
186 l4_uint32_t cfg_device_notify_index;
187
188 /* L4Virtio(0x7c) L4 specific command register polled by the driver iff supported */
189 l4_uint32_t cmd;
190
191 /* Virtio(0x80): queue descriptors */
192 l4_uint64_t queue_desc;
193 l4_uint32_t _res8[2];
194 l4_uint64_t queue_avail;
195 l4_uint32_t _res9[2];
196 l4_uint64_t queue_used;
197
198 l4_uint32_t _res10[1];
199
200 /* Virtio(0xac): shared memory region */
201 l4_uint32_t shm_sel;
202 l4_uint64_t shm_len;
203 l4_uint64_t shm_base;
204
205 /* L4Virtio(0xc0): use the unused space here for device and driver feature bitmaps */
206 l4_uint32_t dev_features_map[L4VIRTIO_FEATURES_MAP_WORDS];
207 l4_uint32_t _res11[2];
208 l4_uint32_t driver_features_map[L4VIRTIO_FEATURES_MAP_WORDS];
209 l4_uint32_t _res12[1];
210
211 /* Virtio(0xfc): config generation */
212 l4_uint32_t generation;
214
252
254
265
271L4_INLINE void *
273{
274 return (void *)(((l4_addr_t)cfg) + 0x100);
275}
276
280L4_INLINE void
281l4virtio_set_feature(l4_uint32_t *feature_map, unsigned feat)
282{
283 unsigned idx = feat / 32;
284
285 if (idx < L4VIRTIO_FEATURES_MAP_WORDS)
286 feature_map[idx] |= 1UL << (feat % 32);
287}
288
292L4_INLINE void
293l4virtio_clear_feature(l4_uint32_t *feature_map, unsigned feat)
294{
295 unsigned idx = feat / 32;
296
297 if (idx < L4VIRTIO_FEATURES_MAP_WORDS)
298 feature_map[idx] &= ~(1UL << (feat % 32));
299}
300
304L4_INLINE unsigned
305l4virtio_get_feature(l4_uint32_t *feature_map, unsigned feat)
306{
307 unsigned idx = feat / 32;
308
309 if (idx >= L4VIRTIO_FEATURES_MAP_WORDS)
310 return 0;
311
312 return feature_map[idx] & (1UL << (feat % 32));
313}
314
320L4_CV int
322
328L4_CV int
330
336L4_CV int
338 l4_uint64_t base, l4_umword_t offset,
340
346L4_CV int
348 l4_addr_t *ds_offset) L4_NOTHROW;
349
355L4_CV int
358
360
L4 compiler related defines.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:29
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:27
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition l4int.h:31
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:374
#define L4_CV
Define calling convention.
Definition linkage.h:33
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition compiler.h:167
#define L4_INLINE
L4 Inline function attribute.
Definition compiler.h:51
#define L4_BEGIN_DECLS
Start section with C types and functions.
Definition compiler.h:171
#define L4_END_DECLS
End section with C types and functions.
Definition compiler.h:172
L4virtio_feature_bits
L4virtio-specific feature bits.
Definition virtio.h:108
L4virtio_device_status
Virtio device status bits.
Definition virtio.h:92
int l4virtio_set_status(l4_cap_idx_t cap, unsigned status) L4_NOTHROW
int l4virtio_device_notification_irq(l4_cap_idx_t cap, unsigned index, l4_cap_idx_t irq) L4_NOTHROW
L4_virtio_opcodes
Opcodes to setup and configure a device.
Definition virtio.h:53
L4_virtio_cmd
Virtio commands for device configuration.
Definition virtio.h:129
L4_virtio_protocol
L4-VIRTIO protocol number.
Definition virtio.h:35
int l4virtio_config_queue(l4_cap_idx_t cap, unsigned queue) L4_NOTHROW
int l4virtio_device_config_ds(l4_cap_idx_t cap, l4_cap_idx_t config_ds, l4_addr_t *ds_offset) L4_NOTHROW
L4virtio_device_ids
Virtio device IDs as reported in the driver's config space.
Definition virtio.h:63
void * l4virtio_device_config(l4virtio_config_hdr_t const *cfg)
Get the pointer to the device configuration.
Definition virtio.h:272
L4_BEGIN_DECLS l4virtio_config_queue_t * l4virtio_config_queues(l4virtio_config_hdr_t const *cfg)
Get the pointer to the first queue config.
Definition virtio.h:261
void l4virtio_clear_feature(l4_uint32_t *feature_map, unsigned feat)
Clear the given feature bit in a feature map.
Definition virtio.h:293
void l4virtio_set_feature(l4_uint32_t *feature_map, unsigned feat)
Set the given feature bit in a feature map.
Definition virtio.h:281
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
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:305
L4_virtio_irq_status
VIRTIO IRQ status codes (l4virtio_config_hdr_t::irq_status).
Definition virtio.h:120
@ L4VIRTIO_FEATURE_CMD_CONFIG
Status and queue config are set via cmd field instead of via IPC.
Definition virtio.h:112
@ L4VIRTIO_FEATURE_VERSION_1
Virtio protocol version 1 supported. Must be 1 for L4virtio.
Definition virtio.h:110
@ L4VIRTIO_STATUS_DRIVER
Guest OS knows how to drive device.
Definition virtio.h:94
@ L4VIRTIO_STATUS_FAILED
Driver detected fatal error.
Definition virtio.h:98
@ L4VIRTIO_STATUS_ACKNOWLEDGE
Guest OS has found device.
Definition virtio.h:93
@ L4VIRTIO_STATUS_FEATURES_OK
Driver has acknowledged feature set.
Definition virtio.h:96
@ L4VIRTIO_STATUS_DRIVER_OK
Driver is set up.
Definition virtio.h:95
@ L4VIRTIO_STATUS_DEVICE_NEEDS_RESET
Device detected fatal error.
Definition virtio.h:97
@ L4VIRTIO_OP_SET_STATUS
Write device status register.
Definition virtio.h:54
@ L4VIRTIO_OP_GET_DEVICE_IRQ
Retrieve device notification IRQ.
Definition virtio.h:58
@ L4VIRTIO_OP_DEVICE_CONFIG
Get device config page.
Definition virtio.h:57
@ L4VIRTIO_OP_CONFIG_QUEUE
Configure queue.
Definition virtio.h:55
@ L4VIRTIO_OP_REGISTER_DS
Register shared memory with device.
Definition virtio.h:56
@ L4VIRTIO_CMD_NOTIFY_QUEUE
Configure a queue.
Definition virtio.h:134
@ L4VIRTIO_CMD_NONE
No command pending.
Definition virtio.h:130
@ L4VIRTIO_CMD_SET_STATUS
Set the status register.
Definition virtio.h:131
@ L4VIRTIO_CMD_CFG_QUEUE
Configure a queue.
Definition virtio.h:132
@ L4VIRTIO_CMD_MASK
Mask to get command bits.
Definition virtio.h:135
@ L4VIRTIO_CMD_CFG_CHANGED
Device config changed.
Definition virtio.h:133
@ L4VIRTIO_ID_SCSI
SCSI host device.
Definition virtio.h:70
@ L4VIRTIO_ID_BLOCK
General block device.
Definition virtio.h:65
@ L4VIRTIO_ID_BALLOON
Memory ballooning device.
Definition virtio.h:68
@ L4VIRTIO_ID_RPMSG
Device using rpmsg protocol.
Definition virtio.h:69
@ L4VIRTIO_ID_INPUT
Input.
Definition virtio.h:75
@ L4VIRTIO_ID_RPROC_SERIAL
Rproc serial device.
Definition virtio.h:72
@ L4VIRTIO_ID_CONSOLE
Simple device for data IO via ports.
Definition virtio.h:66
@ L4VIRTIO_ID_FS
FS.
Definition virtio.h:79
@ L4VIRTIO_ID_CAN
CAN device.
Definition virtio.h:83
@ L4VIRTIO_ID_RNG
Entropy source.
Definition virtio.h:67
@ L4VIRTIO_ID_NET
Virtual ethernet card.
Definition virtio.h:64
@ L4VIRTIO_ID_SOCK
Unofficial socket device.
Definition virtio.h:87
@ L4VIRTIO_ID_CRYPTO
Crypto.
Definition virtio.h:77
@ L4VIRTIO_ID_WATCHDOG
Watchdog device.
Definition virtio.h:82
@ L4VIRTIO_ID_GPIO
Gpio device.
Definition virtio.h:84
@ L4VIRTIO_ID_VSOCK
Vsock transport.
Definition virtio.h:76
@ L4VIRTIO_ID_GPU
GPU.
Definition virtio.h:74
@ L4VIRTIO_ID_I2C
I2C device.
Definition virtio.h:81
@ L4VIRTIO_ID_SOUND
Sound device.
Definition virtio.h:78
@ L4VIRTIO_ID_9P
Device using 9P transport protocol.
Definition virtio.h:71
@ L4VIRTIO_ID_CAIF
Device using CAIF network protocol.
Definition virtio.h:73
@ L4VIRTIO_ID_SPI
SPI device.
Definition virtio.h:85
@ L4VIRTIO_ID_SCMI
Scmi device.
Definition virtio.h:80
@ L4VIRTIO_IRQ_STATUS_VRING
VRING IRQ pending flag.
Definition virtio.h:121
@ L4VIRTIO_IRQ_STATUS_CONFIG
CONFIG IRQ pending flag.
Definition virtio.h:122
Common IPC interface.
Common L4 ABI Data Types.
UTCB definitions.
L4-VIRTIO config header, provided in shared data space.
Definition virtio.h:142
l4_uint32_t vendor
vendor ID
Definition virtio.h:147
l4_uint32_t magic
magic value (must be 'virt').
Definition virtio.h:144
l4_uint32_t dev_features
device features windows selected by device_feature_sel
Definition virtio.h:150
l4_uint32_t queues_offset
offset of virtqueue config array
Definition virtio.h:160
l4_uint32_t device
device ID
Definition virtio.h:146
l4_uint32_t num_queues
number of virtqueues
Definition virtio.h:159
l4_uint32_t version
VIRTIO version.
Definition virtio.h:145
Queue configuration entry.
Definition virtio.h:233
l4_uint16_t device_notify_index
R: Event index to be used by the driver (driver to device).
Definition virtio.h:250
l4_uint16_t driver_notify_index
W: Event index to be used for device notifications (device to driver).
Definition virtio.h:243
l4_uint64_t avail_addr
W: address of available ring.
Definition virtio.h:246
l4_uint64_t desc_addr
W: address of descriptor table.
Definition virtio.h:245
l4_uint64_t used_addr
W: address of used ring.
Definition virtio.h:247
l4_uint16_t ready
RW: queue ready flag (read-write).
Definition virtio.h:240
l4_uint16_t num_max
R: maximum number of descriptors supported by this queue.
Definition virtio.h:235
l4_uint16_t num
RW: number of descriptors configured for this queue.
Definition virtio.h:237