L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
l4virtio
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/* SPDX-License-Identifier: MIT */
3/*
4 * Copyright (C) 2013-2022 Kernkonzept GmbH.
5 * Author(s): Alexander Warg <alexander.warg@kernkonzept.com>
6 * Matthias Lange <matthias.lange@kernkonzept.com>
7 *
8 */
9#pragma once
10
11#include "virtio.h"
12#include <l4/sys/capability>
13#include <l4/sys/cxx/ipc_client>
14#include <l4/re/dataspace>
15#include <l4/sys/irq>
16#include <l4/cxx/utils>
17
18namespace L4virtio {
39class Device :
40 public L4::Kobject_t<Device, L4::Icu, L4VIRTIO_PROTOCOL,
41 L4::Type_info::Demand_t<1> >
42{
43public:
45 struct Config_hdr : l4virtio_config_hdr_t
46 {
47 Config_queue *queues() const
48 { return l4virtio_config_queues(this); }
49
50 template <typename T>
51 T *device_config() const
52 {
53 return static_cast<T*>(l4virtio_device_config(this));
54 }
55
56 int config_queue(unsigned num, L4::Cap<L4::Triggerable> out_notify,
59 {
60 return send_cmd(L4VIRTIO_CMD_CFG_QUEUE | num,
61 out_notify, in_notify, to);
62 }
63
64 int notify_queue(unsigned num, L4::Cap<L4::Triggerable> out_notify,
67 {
68 return send_cmd(L4VIRTIO_CMD_NOTIFY_QUEUE | num,
69 out_notify, in_notify, to);
70 }
71
80 bool fail_state() const
81 {
82 auto cfg_status = cxx::access_once(&status);
83 return cfg_status
85 }
86
87 int set_status(unsigned new_status, L4::Cap<L4::Triggerable> out_notify,
90 {
91 return send_cmd(L4VIRTIO_CMD_SET_STATUS | new_status,
92 out_notify, in_notify, to);
93 }
94
95 int cfg_changed(unsigned reg, L4::Cap<L4::Triggerable> out_notify,
98 {
99 return send_cmd(L4VIRTIO_CMD_CFG_CHANGED | reg,
100 out_notify, in_notify, to);
101 }
102
103 int send_cmd(unsigned command, L4::Cap<L4::Triggerable> out_notify,
104 L4::Cap<L4::Triggerable> in_notify,
106 {
107 cxx::write_now(&cmd, command);
108
109 if (out_notify)
110 out_notify->trigger();
111
112 auto utcb = l4_utcb();
113 auto ipc_to = l4_timeout(L4_IPC_TIMEOUT_0, to);
114
115 do
116 {
117 if (in_notify)
118 if (l4_ipc_error(l4_ipc_receive(in_notify.cap(), utcb, ipc_to),
119 utcb) == L4_IPC_RETIMEOUT)
120 break;
121 }
122 while (cxx::access_once(&cmd));
123
124 return cxx::access_once(&cmd) ? -L4_EBUSY : L4_EOK;
125 }
126 };
127
138 set_status, (unsigned status));
139
156 config_queue, (unsigned queue));
157
183 l4_uint64_t base, l4_umword_t offset,
185
196 l4_addr_t *ds_offset));
197
217 (unsigned index, L4::Ipc::Out<L4::Cap<L4::Triggerable> > irq));
218
219
220 typedef L4::Typeid::Rpcs<set_status_t, config_queue_t, register_ds_t,
221 device_config_t, device_notification_irq_t>
222 Rpcs;
223};
224
225}
L4::Cap related definitions.
l4_cap_idx_t cap() const noexcept
Return capability selector.
Definition capability.h:49
C++ interface for capabilities.
Definition capability.h:219
Capability type for RPC interfaces (see L4::Cap<T>).
Definition ipc_types:563
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:761
IPC interface for virtio over L4 IPC.
Definition l4virtio:42
long register_ds(L4::Ipc::Cap< L4Re::Dataspace > ds_cap, l4_uint64_t base, l4_umword_t offset, l4_umword_t size)
Register a shared data space with VIRTIO host.
long device_notification_irq(unsigned index, L4::Ipc::Out< L4::Cap< L4::Triggerable > > irq)
Get the notification interrupt corresponding to the given index.
long config_queue(unsigned queue)
Trigger queue configuration of the given queue.
long device_config(L4::Ipc::Out< L4::Cap< L4Re::Dataspace > > config_ds, l4_addr_t *ds_offset)
Get the dataspace with the L4virtio configuration page.
long set_status(unsigned status)
Write the VIRTIO status register.
Dataspace interface.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
unsigned long l4_addr_t
Address type.
Definition l4int.h:45
unsigned long long l4_uint64_t
Unsigned 64bit value.
Definition l4int.h:42
@ L4_EBUSY
Object currently busy, try later.
Definition err.h:53
@ L4_EOK
Ok.
Definition err.h:43
l4_msgtag_t l4_ipc_receive(l4_cap_idx_t object, l4_utcb_t *utcb, l4_timeout_t timeout) L4_NOTHROW
Wait for a message from a specific source.
Definition ipc.h:613
l4_umword_t l4_ipc_error(l4_msgtag_t tag, l4_utcb_t *utcb) L4_NOTHROW
Get the IPC error code for an IPC operation.
Definition ipc.h:640
@ L4_IPC_RETIMEOUT
Timeout during receive operation.
Definition ipc.h:100
#define L4_IPC_TIMEOUT_NEVER
never timeout
Definition __timeout.h:82
#define L4_IPC_TIMEOUT_0
Timeout constants.
Definition __timeout.h:81
L4_CONSTEXPR l4_timeout_t l4_timeout(l4_timeout_s snd, l4_timeout_s rcv) L4_NOTHROW
Combine send and receive timeout in a timeout.
Definition __timeout.h:221
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:340
l4virtio_config_queue_t * l4virtio_config_queues(l4virtio_config_hdr_t const *cfg)
Get the pointer to the first queue config.
Definition virtio.h:249
void * l4virtio_device_config(l4virtio_config_hdr_t const *cfg)
Get the pointer to the device configuration.
Definition virtio.h:260
@ L4VIRTIO_STATUS_FAILED
Driver detected fatal error.
Definition virtio.h:91
@ L4VIRTIO_STATUS_DEVICE_NEEDS_RESET
Device detected fatal error.
Definition virtio.h:90
@ L4VIRTIO_OP_SET_STATUS
Write device status register.
Definition virtio.h:53
@ L4VIRTIO_OP_GET_DEVICE_IRQ
Retrieve device notification IRQ.
Definition virtio.h:57
@ L4VIRTIO_OP_DEVICE_CONFIG
Get device config page.
Definition virtio.h:56
@ L4VIRTIO_OP_CONFIG_QUEUE
Configure queue.
Definition virtio.h:54
@ L4VIRTIO_OP_REGISTER_DS
Register shared memory with device.
Definition virtio.h:55
@ L4VIRTIO_CMD_NOTIFY_QUEUE
Configure a queue.
Definition virtio.h:122
@ L4VIRTIO_CMD_SET_STATUS
Set the status register.
Definition virtio.h:119
@ L4VIRTIO_CMD_CFG_QUEUE
Configure a queue.
Definition virtio.h:120
@ L4VIRTIO_CMD_CFG_CHANGED
Device config changed.
Definition virtio.h:121
#define L4_INLINE_RPC_OP(op, res, name, args, attr...)
Define an inline RPC call with specific opcode (type and callable).
Definition ipc_iface:484
C++ Irq interface.
L4-VIRTIO Transport C++ API.
Definition l4virtio:26
void write_now(T *a, VAL &&val)
Write a value at an address exactly once.
Definition utils:70
T access_once(T const *a)
Read the value at an address at most once.
Definition utils:39
Mark an argument as a output value in an RPC signature.
Definition ipc_types:42
Standard list of RPCs of an interface.
Definition __typeinfo.h:439
Basic timeout specification.
Definition __timeout.h:48
L4-VIRTIO config header, provided in shared data space.
Definition virtio.h:130
Queue configuration entry.
Definition virtio.h:221