1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:47:44 +00:00

Kernel/Graphics: Introduce a new mechanism to initialize a PCI device

Instead of using a clunky switch-case paradigm, we now have all drivers
being declaring two methods for their adapter class - create and probe.
These methods are linked in each PCIGraphicsDriverInitializer structure,
in a new s_initializers static list of them.
Then, when we probe for a PCI device, we use each probe method and if
there's a match, then the corresponding create method is called.

As a result of this change, it's much more easy to add more drivers and
the initialization code is more readable.
This commit is contained in:
Liav A 2022-12-17 21:15:31 +02:00 committed by Andrew Kaster
parent 7625f7db73
commit 72b144e9e9
12 changed files with 85 additions and 71 deletions

View file

@ -20,16 +20,18 @@
namespace Kernel {
UNMAP_AFTER_INIT LockRefPtr<VMWareGraphicsAdapter> VMWareGraphicsAdapter::try_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
ErrorOr<bool> VMWareGraphicsAdapter::probe(PCI::DeviceIdentifier const& pci_device_identifier)
{
PCI::HardwareID id = pci_device_identifier.hardware_id();
VERIFY(id.vendor_id == PCI::VendorID::VMWare);
// Note: We only support VMWare SVGA II adapter
if (id.device_id != 0x0405)
return {};
auto registers_io_window = MUST(IOWindow::create_for_pci_device_bar(pci_device_identifier, PCI::HeaderType0BaseRegister::BAR0));
auto adapter = MUST(adopt_nonnull_lock_ref_or_enomem(new (nothrow) VMWareGraphicsAdapter(pci_device_identifier, move(registers_io_window))));
MUST(adapter->initialize_adapter());
return id.vendor_id == PCI::VendorID::VMWare && id.device_id == 0x0405;
}
ErrorOr<NonnullLockRefPtr<GenericGraphicsAdapter>> VMWareGraphicsAdapter::create(PCI::DeviceIdentifier const& pci_device_identifier)
{
auto registers_io_window = TRY(IOWindow::create_for_pci_device_bar(pci_device_identifier, PCI::HeaderType0BaseRegister::BAR0));
auto adapter = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) VMWareGraphicsAdapter(pci_device_identifier, move(registers_io_window))));
TRY(adapter->initialize_adapter());
return adapter;
}