mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 20:37:36 +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
52
Kernel/Bus/VirtIO/Transport/PCIe/Detect.cpp
Normal file
52
Kernel/Bus/VirtIO/Transport/PCIe/Detect.cpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* Copyright (c) 2021, the SerenityOS developers.
|
||||
* Copyright (c) 2023, Liav A. <liavalb@hotmail.co.il>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/Try.h>
|
||||
#include <Kernel/Boot/CommandLine.h>
|
||||
#include <Kernel/Bus/PCI/API.h>
|
||||
#include <Kernel/Bus/PCI/IDs.h>
|
||||
#include <Kernel/Bus/VirtIO/Console.h>
|
||||
#include <Kernel/Bus/VirtIO/Device.h>
|
||||
#include <Kernel/Bus/VirtIO/RNG.h>
|
||||
#include <Kernel/Bus/VirtIO/Transport/PCIe/Detect.h>
|
||||
#include <Kernel/Sections.h>
|
||||
|
||||
namespace Kernel::VirtIO {
|
||||
|
||||
UNMAP_AFTER_INIT void detect_pci_instances()
|
||||
{
|
||||
if (kernel_command_line().disable_virtio())
|
||||
return;
|
||||
MUST(PCI::enumerate([&](PCI::DeviceIdentifier const& device_identifier) {
|
||||
if (device_identifier.hardware_id().is_null())
|
||||
return;
|
||||
// TODO: We should also be checking that the device_id is in between 0x1000 - 0x107F inclusive
|
||||
if (device_identifier.hardware_id().vendor_id != PCI::VendorID::VirtIO)
|
||||
return;
|
||||
switch (device_identifier.hardware_id().device_id) {
|
||||
case PCI::DeviceID::VirtIOConsole: {
|
||||
auto& console = Console::must_create_for_pci_instance(device_identifier).leak_ref();
|
||||
MUST(console.initialize_virtio_resources());
|
||||
break;
|
||||
}
|
||||
case PCI::DeviceID::VirtIOEntropy: {
|
||||
auto& rng = RNG::must_create_for_pci_instance(device_identifier).leak_ref();
|
||||
MUST(rng.initialize_virtio_resources());
|
||||
break;
|
||||
}
|
||||
case PCI::DeviceID::VirtIOGPU: {
|
||||
// This should have been initialized by the graphics subsystem
|
||||
break;
|
||||
}
|
||||
default:
|
||||
dbgln_if(VIRTIO_DEBUG, "VirtIO: Unknown VirtIO device with ID: {}", device_identifier.hardware_id().device_id);
|
||||
break;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue