mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:27:35 +00:00
Kernel/VirtIO: Introduce the concept of transport options
The VirtIO specification defines many types of devices with different purposes, and it also defines 3 possible transport mediums where devices could be connected to the host machine. We only care about the PCIe transport, but this commit puts the actual foundations for supporting the lean MMIO transport too in the future. To ensure things are kept abstracted but still functional, the VirtIO transport code is responsible for what is deemed as related to an actual transport type - allocation of interrupt handlers and tinkering with low level transport-related registers, etc.
This commit is contained in:
parent
68c3f9aa5a
commit
d61c23569e
24 changed files with 732 additions and 429 deletions
|
@ -6,6 +6,7 @@
|
|||
*/
|
||||
|
||||
#include <Kernel/Bus/VirtIO/Console.h>
|
||||
#include <Kernel/Bus/VirtIO/Transport/PCIe/TransportLink.h>
|
||||
#include <Kernel/Devices/DeviceManagement.h>
|
||||
#include <Kernel/Sections.h>
|
||||
#include <Kernel/Tasks/WorkQueue.h>
|
||||
|
@ -14,15 +15,16 @@ namespace Kernel::VirtIO {
|
|||
|
||||
unsigned Console::next_device_id = 0;
|
||||
|
||||
UNMAP_AFTER_INIT NonnullLockRefPtr<Console> Console::must_create(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
UNMAP_AFTER_INIT NonnullLockRefPtr<Console> Console::must_create_for_pci_instance(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
return adopt_lock_ref_if_nonnull(new Console(pci_device_identifier)).release_nonnull();
|
||||
auto pci_transport_link = MUST(PCIeTransportLink::create(pci_device_identifier));
|
||||
return adopt_lock_ref_if_nonnull(new (nothrow) Console(move(pci_transport_link))).release_nonnull();
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT ErrorOr<void> Console::initialize_virtio_resources()
|
||||
{
|
||||
TRY(Device::initialize_virtio_resources());
|
||||
auto const* cfg = TRY(get_config(VirtIO::ConfigurationType::Device));
|
||||
auto const* cfg = TRY(transport_entity().get_config(VirtIO::ConfigurationType::Device));
|
||||
bool success = negotiate_features([&](u64 supported_features) {
|
||||
u64 negotiated = 0;
|
||||
if (is_feature_set(supported_features, VIRTIO_CONSOLE_F_SIZE))
|
||||
|
@ -35,13 +37,13 @@ UNMAP_AFTER_INIT ErrorOr<void> Console::initialize_virtio_resources()
|
|||
return Error::from_errno(EIO);
|
||||
u32 max_nr_ports = 0;
|
||||
u16 cols = 0, rows = 0;
|
||||
read_config_atomic([&]() {
|
||||
transport_entity().read_config_atomic([&]() {
|
||||
if (is_feature_accepted(VIRTIO_CONSOLE_F_SIZE)) {
|
||||
cols = config_read16(*cfg, 0x0);
|
||||
rows = config_read16(*cfg, 0x2);
|
||||
cols = transport_entity().config_read16(*cfg, 0x0);
|
||||
rows = transport_entity().config_read16(*cfg, 0x2);
|
||||
}
|
||||
if (is_feature_accepted(VIRTIO_CONSOLE_F_MULTIPORT)) {
|
||||
max_nr_ports = config_read32(*cfg, 0x4);
|
||||
max_nr_ports = transport_entity().config_read32(*cfg, 0x4);
|
||||
m_ports.resize(max_nr_ports);
|
||||
}
|
||||
});
|
||||
|
@ -62,8 +64,8 @@ UNMAP_AFTER_INIT ErrorOr<void> Console::initialize_virtio_resources()
|
|||
return {};
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT Console::Console(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
: VirtIO::Device(pci_device_identifier)
|
||||
UNMAP_AFTER_INIT Console::Console(NonnullOwnPtr<TransportEntity> transport_entity)
|
||||
: VirtIO::Device(move(transport_entity))
|
||||
, m_device_id(next_device_id++)
|
||||
{
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue