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>
33class Virtio_rng :
public L4virtio::Svr::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,
86 : _q(q), _rnd(rnd), _rng(rng), _head() {}
90 auto r = _q->next_avail();
95 _head =
start(_rng->mem_info(), r, &_req);
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);
126 :
L4virtio::Svr::Device(&_dev_config),
130 _request_processor(&_q, rnd, this)
137 L4virtio::Svr::Dev_config::Features hf;
139 _dev_config.host_features(0) = hf.
raw;
141 _dev_config.reset_hdr();
155 _request_processor.handle_request();
180 _notify_guest_irq->trigger();
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,
199 L4::Ipc::Cap<L4Re::Dataspace> &config_ds,
202 return L4virtio::Svr::Device::op_device_config(r, config_ds, ds_offset);
220 L4virtio::Svr::Dev_config_t<L4virtio::Svr::No_custom_data>_dev_config;
C++ interface for capabilities.
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.
void add_irq_status(l4_uint32_t status)
Adds irq status bit.
bool setup_queue(Virtqueue *q, unsigned qn, unsigned num_max)
void init_mem_info(unsigned num)
void reset_queue_config(unsigned idx, unsigned num_max, bool inc_generation=false)
T * local(Ptr< T > p) const
Get the local address for driver address p.
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.
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.
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.
Cap< T > cap_cast(Cap< F > const &c) noexcept
static_cast for capabilities.
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.
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.
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.