12#include <l4/cxx/bitmap>
13#include <l4/cxx/static_vector>
14#include <l4/l4virtio/server/l4virtio>
15#include <l4/l4virtio/server/virtio-console>
18namespace L4virtio {
namespace Svr {
namespace Console {
31 Buffer(Driver_mem_region
const *r,
35 pos =
static_cast<char *
>(r->local(d.
addr));
44 bool poll_in_req =
true;
45 bool poll_out_req =
true;
124 Irq_object(
Device *parent) : _parent(parent) {}
126 void handle_irq() { _parent->kick(); }
134 {
return &_irq_handler; }
150 _ports[0].vq_max = vq_max;
151 reset_queue_configs();
163 explicit Device(
unsigned vq_max,
unsigned ports)
168 for (
unsigned i = 0; i < ports; ++i)
169 _ports[i].vq_max = vq_max;
170 reset_queue_configs();
163 explicit Device(
unsigned vq_max,
unsigned ports) {
…}
187 for (
unsigned i = 0; i < vq_max_nums.size(); ++i)
188 _ports[i].vq_max = vq_max_nums[i];
189 reset_queue_configs();
200 {
return _irq_handler.obj_cap(); }
208 _kick_driver_irq->trigger();
230 _kick_driver_irq->trigger();
241 for (
unsigned i = 0; i < max_ports(); ++i)
244 if (p.poll_in_req && p.tx_ready() && p.tx.desc_avail())
246 p.poll_in_req =
false;
250 if (p.poll_out_req && p.rx_ready() && p.rx.desc_avail())
252 p.poll_out_req =
false;
290 : Virtqueue::Request();
297 total += p.
src.copy_to(&dst);
307 p.
request = Virtqueue::Request();
314 p.
request = Virtqueue::Request();
321 p.poll_in_req =
true;
348 src.
pos =
const_cast<char*
>(buf);
361 Device_port::Buffer dst;
378 q->
finish(r,
this, chunk);
383 p.poll_out_req =
true;
404 for (
unsigned i = 0; i < max_ports(); ++i)
445 static_cast<void>(id);
446 static_cast<void>(value);
455 Port const *
port(
unsigned idx)
const override
461 Irq_object _irq_handler;
462 cxx::unique_ptr<Device_port[]> _ports;
C++ interface for capabilities.
Base class implementing a virtio console device with L4Re-based notification handling.
void notify_queue(Virtqueue *queue) override
Notify queue of available data.
void trigger_driver_config_irq() override
callback for triggering configuration change notification IRQ
Device(unsigned vq_max, unsigned ports)
Create a new console device.
virtual void tx_space_available(unsigned port)=0
Callback to notify that data can be written to port.
Port * port(unsigned idx) override
Return the specified port.
unsigned port_write(char const *buf, unsigned len, unsigned port=0)
Write data to port.
L4::Cap< L4::Irq > device_notify_irq() const override
callback to gather the device notification IRQ (old-style)
void process_device_ready(l4_uint16_t value) override
Callback called on DEVICE_READY event.
void process_port_ready(l4_uint32_t id, l4_uint16_t value) override
Callback called on PORT_READY event.
virtual bool queues_stopped()
Return true, if the queues should not be processed further.
Device(unsigned vq_max)
Create a new console device.
virtual void process_port_open(l4_uint32_t id, l4_uint16_t value)
Callback called on PORT_OPEN event.
virtual void rx_data_available(unsigned port)=0
Callback to notify that new data is available to be read from port.
Device(cxx::static_vector< unsigned > const &vq_max_nums)
Create a new console Device.
unsigned port_read(char *buf, unsigned len, unsigned port=0)
Read data from port.
void register_single_driver_irq() override
callback for registering a single guest IRQ for all queues (old-style)
Base class implementing a virtio console functionality.
int port_open(unsigned idx, bool open)
Send a PORT_OPEN message and update the internal state.
virtual void process_port_ready(l4_uint32_t id, l4_uint16_t value)
Callback called on PORT_READY event.
int port_remove(unsigned idx)
Send a DEVICE_REMOVE message and update the internal state.
int port_add(unsigned idx)
Send a DEVICE_ADD message and update the internal state.
int handle_control_message()
Handle control message received from the driver.
void device_error()
Transition device into DEVICE_NEEDS_RESET state.
Mem_list const * mem_info() const
Get the memory region list used for this device.
Encapsulate the state for processing a VIRTIO request.
bool next(DESC_MAN *dm, ARGS... args)
Switch to the next descriptor in a descriptor chain.
void start(DESC_MAN *dm, Virtqueue *ring, Virtqueue::Head_desc const &request, ARGS... args)
Start processing a new request.
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.
Simple encapsulation for a dynamically allocated array.
unsigned int l4_uint32_t
Unsigned 32bit value.
unsigned short int l4_uint16_t
Unsigned 16bit value.
@ L4VIRTIO_IRQ_STATUS_VRING
VRING IRQ pending flag.
@ L4VIRTIO_IRQ_STATUS_CONFIG
CONFIG IRQ pending flag.
L4::Detail::Unique_cap_impl< T, Smart_cap_auto< L4_FP_ALL_SPACES > > Unique_cap
Unique capability that implements automatic free and unmap of the capability selector.
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-VIRTIO Transport C++ API.
Base class for interface implementations.
Epiface implementation for interrupt handlers.
Exception used by Queue to indicate descriptor errors.
A console port with associated read/write state.
void reset() override
Reset the port to the initial state and disable its virtqueues.
Request_processor rp
Request processor associated with current request.
Virtqueue::Request request
Current virtio tx queue request.
Buffer src
Source data block to process.
Representation of a Virtio console port.
Port_status status
State the port is in.
Virtqueue rx
Transmitq of the port.
virtual void reset()
Reset the port to the initial state and disable its virtqueues.
Virtqueue tx
Receiveq of the port.
bool rx_ready() const
Check that device implementation may write to receive queues.
bool tx_ready() const
Check that device implementation may read from transmit queues.
@ Port_ready
Port is ready but still closed.
@ Port_failed
Device failure, port unusable.
l4_uint32_t copy_to(Data_buffer *dst, l4_uint32_t max=UINT_MAX)
Copy contents from this buffer to the destination buffer.
l4_uint32_t left
Bytes left in buffer.
char * pos
Current buffer position.