12#include <l4/sys/cxx/ipc_epiface>
14#include <l4/l4virtio/server/virtio>
15#include <l4/l4virtio/server/l4virtio>
16#include <l4/l4virtio/l4virtio>
32 template <
typename Rnd_state,
typename Epiface = L4virtio::Device>
39 Num_request_queues = 1,
44 using Random_state = Rnd_state;
73 Data_buffer() =
default;
75 Data_buffer(L4virtio::Svr::Driver_mem_region
const *r,
79 pos =
static_cast<char *
>(r->local(d.
addr));
86 : _q(q), _rnd(rnd), _rng(rng), _head() {}
100 void handle_request()
108 auto const pos =
reinterpret_cast<unsigned char *
>(_req.pos);
109 _rnd->get_random(_req.left, pos);
110 _q->
finish(_head, _rng, _req.left);
130 _request_processor(&_q, rnd, this)
139 _dev_config.host_features(0) = hf.
raw;
141 _dev_config.reset_hdr();
155 _request_processor.handle_request();
188 long op_set_status(L4virtio::Device::Rights r,
unsigned status)
190 return L4virtio::Svr::Device::op_set_status(r, status);
193 long op_config_queue(L4virtio::Device::Rights r,
unsigned queue)
195 return L4virtio::Svr::Device::op_config_queue(r, queue);
198 long op_device_config(L4virtio::Device::Rights r,
202 return L4virtio::Svr::Device::op_device_config(r, config_ds, ds_offset);
207 return L4::cap_cast<L4::Irq>(_host_irq.
obj_cap());
213 (server_iface()->
template rcv_cap<L4::Irq>(0));
220 L4virtio::Svr::Dev_config_t<L4virtio::Svr::No_custom_data>_dev_config;
C++ interface for capabilities.
Capability type for RPC interfaces (see L4::Cap<T>).
Interface for server-loop related functions.
Abstract interface for object registries.
virtual L4::Cap< L4::Irq > register_irq_obj(L4::Epiface *o)=0
Register o as server-side object for asynchronous IRQs.
Server-side L4-VIRTIO device stub.
bool setup_queue(Virtqueue *q, unsigned qn, unsigned num_max)
Enable/disable the specified queue.
void init_mem_info(unsigned num)
Initialize the memory region list to the given maximum.
Mem_list const * mem_info() const
Get the memory region list used for this device.
void reset_queue_config(unsigned idx, unsigned num_max, bool inc_generation=false)
Trigger reset for the configuration space for queue idx.
Encapsulate the state for processing a VIRTIO request.
void start(DESC_MAN *dm, Virtqueue *ring, Virtqueue::Head_desc const &request, ARGS... args)
Start processing a new request.
Handler for the host irq.
Handler for the Virtio requests.
A server implementation of the virtio-rng protocol.
void trigger_driver_config_irq() override
callback for triggering configuration change notification IRQ
void reset() override
reset callback, called for doing a device reset
L4::Cap< L4::Irq > device_notify_irq() const override
callback to gather the device notification IRQ (old-style)
int reconfig_queue(unsigned idx) override
callback for client queue-config request
bool check_queues() override
callback for checking if the queues at DRIVER_OK transition
void register_single_driver_irq() override
callback for registering a single guest IRQ for all queues (old-style)
VIRTIO request, essentially a descriptor from the available ring.
Virtqueue implementation for the device.
Request next_avail()
Get the next available descriptor from the available ring.
void finish(Head_desc &d, QUEUE_OBSERVER *o, l4_uint32_t len=0)
Add a descriptor to the used ring, and notify an observer.
Descriptor in the descriptor table.
l4_uint32_t len
Length of described buffer.
Ptr< void > addr
Address stored in descriptor.
bool no_notify_guest() const
Get the no IRQ flag of this queue.
unsigned long l4_addr_t
Address type.
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
@ L4VIRTIO_FEATURE_VERSION_1
Virtio protocol version 1 supported. Must be 1 for L4virtio.
@ L4VIRTIO_ID_RNG
Entropy source.
@ L4VIRTIO_IRQ_STATUS_VRING
VRING IRQ pending flag.
@ L4VIRTIO_IRQ_STATUS_CONFIG
CONFIG IRQ pending flag.
long chksys(long err, char const *extra="", long ret=0)
Generate C++ exception on error.
T chkcap(T &&cap, char const *extra="", long err=-L4_ENOMEM)
Check for valid capability or raise C++ exception.
l4_msgtag_t chkipc(l4_msgtag_t tag, char const *extra="", l4_utcb_t *utcb=l4_utcb())
Test a message tag for IPC errors.
L4-VIRTIO Transport C++ API.
Epiface implementation for Kobject-based interface implementations.
Server_iface * server_iface() const
Get pointer to server interface at which the object is currently registered.
Epiface implementation for interrupt handlers.
Cap< L4::Irq > obj_cap() const
Get the (typed) capability to this object.
l4_msgtag_t trigger(l4_utcb_t *utcb=l4_utcb()) noexcept
Trigger the object.
l4_uint32_t left
Bytes left in buffer.
char * pos
Current buffer position.
Type for device feature bitmap.
l4_uint32_t raw
The raw value of the features bitmap.
constexpr ring_indirect_desc_bfm_t::Val ring_indirect_desc() const
Get the ring_indirect_desc bits ( 28 to 28 ) of raw.