-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kernel/PCI: Add a driver for the PCI VirtIO GPU device
- Loading branch information
1 parent
8419d79
commit b6433c5
Showing
4 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright (c) 2023, Liav A. <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include <Kernel/Bus/PCI/Access.h> | ||
#include <Kernel/Bus/PCI/Drivers/Driver.h> | ||
#include <Kernel/Bus/VirtIO/Transport/PCIe/TransportLink.h> | ||
#include <Kernel/Devices/GPU/VirtIO/GraphicsAdapter.h> | ||
|
||
namespace Kernel::PCI { | ||
|
||
class VirtIOGPUDriver final : public PCI::Driver { | ||
public: | ||
static void init(); | ||
|
||
VirtIOGPUDriver() | ||
: PCI::Driver("VirtIOGPUDriver"sv) | ||
{ | ||
} | ||
|
||
virtual ErrorOr<void> probe(PCI::Device&) override; | ||
virtual void detach(PCI::Device&) override; | ||
virtual ClassID class_id() const override { return PCI::ClassID::Display; } | ||
virtual Span<HardwareIDMatch const> matches() override; | ||
|
||
private: | ||
IntrusiveList<&VirtIOGraphicsAdapter::m_driver_list_node> m_devices; | ||
}; | ||
|
||
ErrorOr<void> VirtIOGPUDriver::probe(PCI::Device& pci_device) | ||
{ | ||
auto pci_transport_link = TRY(VirtIO::PCIeTransportLink::create(pci_device)); | ||
auto device = TRY(VirtIOGraphicsAdapter::create(move(pci_transport_link))); | ||
m_devices.append(*device); | ||
return {}; | ||
} | ||
|
||
void VirtIOGPUDriver::detach(PCI::Device&) | ||
{ | ||
TODO(); | ||
} | ||
|
||
const static HardwareIDMatch __matches[] = { | ||
{ | ||
.subclass_code = to_underlying(PCI::Display::SubclassID::VGA), | ||
.revision_id = Optional<RevisionID> {}, | ||
.hardware_id = { | ||
PCI::VendorID::VirtIO, | ||
0x1050, | ||
}, | ||
.subsystem_id_match = Optional<HardwareIDMatch::SubsystemIDMatch> {}, | ||
.programming_interface = Optional<ProgrammingInterface> {}, | ||
}, | ||
{ | ||
.subclass_code = to_underlying(PCI::Display::SubclassID::Other), | ||
.revision_id = Optional<RevisionID> {}, | ||
.hardware_id = { | ||
PCI::VendorID::VirtIO, | ||
0x1050, | ||
}, | ||
.subsystem_id_match = Optional<HardwareIDMatch::SubsystemIDMatch> {}, | ||
.programming_interface = Optional<ProgrammingInterface> {}, | ||
}, | ||
}; | ||
|
||
Span<HardwareIDMatch const> VirtIOGPUDriver::matches() | ||
{ | ||
return __matches; | ||
} | ||
|
||
void VirtIOGPUDriver::init() | ||
{ | ||
auto driver = MUST(adopt_nonnull_ref_or_enomem(new VirtIOGPUDriver())); | ||
PCI::Access::the().register_driver(driver); | ||
} | ||
|
||
PCI_DEVICE_DRIVER(VirtIOGPUDriver); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters