mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 13:27:34 +00:00
Kernel: Support multiport for VirtIOConsole
This involves refactoring VirtIOConsole into VirtIOConsole and VirtIOConsolePort. VirtIOConsole is the VirtIODevice, it owns multiple VirtIOConsolePorts as well as two control queues. Each VirtIOConsolePort is a CharacterDevice.
This commit is contained in:
parent
1492bb2fd6
commit
1fe08759e3
6 changed files with 419 additions and 126 deletions
63
Kernel/VirtIO/VirtIOConsolePort.h
Normal file
63
Kernel/VirtIO/VirtIOConsolePort.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021, Kyle Pereira <hey@xylepereira.me>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <Kernel/Devices/CharacterDevice.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/VM/RingBuffer.h>
|
||||
#include <Kernel/VirtIO/VirtIO.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
class VirtIOConsole;
|
||||
|
||||
#define VIRTIO_CONSOLE_F_SIZE (1 << 0)
|
||||
#define VIRTIO_CONSOLE_F_MULTIPORT (1 << 1)
|
||||
#define VIRTIO_CONSOLE_F_EMERG_WRITE (1 << 2)
|
||||
|
||||
class VirtIOConsolePort
|
||||
: public CharacterDevice {
|
||||
public:
|
||||
explicit VirtIOConsolePort(unsigned port, VirtIOConsole&);
|
||||
void handle_queue_update(Badge<VirtIOConsole>, u16 queue_index);
|
||||
|
||||
void set_open(Badge<VirtIOConsole>, bool state) { m_open = state; }
|
||||
bool is_open() const { return m_open; }
|
||||
|
||||
private:
|
||||
constexpr static size_t RINGBUFFER_SIZE = 2 * PAGE_SIZE;
|
||||
|
||||
virtual const char* class_name() const override { return "VirtIOConsolePort"; }
|
||||
|
||||
virtual bool can_read(const FileDescription&, size_t) const override;
|
||||
virtual KResultOr<size_t> read(FileDescription&, u64, UserOrKernelBuffer&, size_t) override;
|
||||
virtual bool can_write(const FileDescription&, size_t) const override;
|
||||
virtual KResultOr<size_t> write(FileDescription&, u64, const UserOrKernelBuffer&, size_t) override;
|
||||
virtual KResultOr<NonnullRefPtr<FileDescription>> open(int options) override;
|
||||
|
||||
mode_t required_mode() const override { return 0666; }
|
||||
|
||||
String device_name() const override;
|
||||
|
||||
void init_receive_buffer();
|
||||
|
||||
static unsigned next_device_id;
|
||||
u16 m_receive_queue {};
|
||||
u16 m_transmit_queue {};
|
||||
|
||||
OwnPtr<RingBuffer> m_receive_buffer;
|
||||
OwnPtr<RingBuffer> m_transmit_buffer;
|
||||
|
||||
VirtIOConsole& m_console;
|
||||
unsigned m_port;
|
||||
|
||||
bool m_open { false };
|
||||
Atomic<bool> m_receive_buffer_exhausted;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue