1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-17 03:45:07 +00:00
serenity/Kernel/Bus/VirtIO/Transport/PCIe/Detect.cpp
Liav A d61c23569e 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.
2023-09-16 14:04:17 -06:00

52 lines
1.8 KiB
C++

/*
* 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;
}
}));
}
}