1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-03 00:52:12 +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

@ -26,13 +26,15 @@ static bool is_supported_model(u16 device_id)
return false;
}
LockRefPtr<IntelNativeGraphicsAdapter> IntelNativeGraphicsAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
ErrorOr<bool> IntelNativeGraphicsAdapter::probe(PCI::DeviceIdentifier const& pci_device_identifier)
{
VERIFY(pci_device_identifier.hardware_id().vendor_id == 0x8086);
if (!is_supported_model(pci_device_identifier.hardware_id().device_id))
return {};
auto adapter = adopt_lock_ref(*new IntelNativeGraphicsAdapter(pci_device_identifier.address()));
MUST(adapter->initialize_adapter());
return is_supported_model(pci_device_identifier.hardware_id().device_id);
}
ErrorOr<NonnullLockRefPtr<GenericGraphicsAdapter>> IntelNativeGraphicsAdapter::create(PCI::DeviceIdentifier const& pci_device_identifier)
{
auto adapter = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) IntelNativeGraphicsAdapter(pci_device_identifier.address())));
TRY(adapter->initialize_adapter());
return adapter;
}
@ -47,7 +49,7 @@ ErrorOr<void> IntelNativeGraphicsAdapter::initialize_adapter()
dmesgln_pci(*this, "framebuffer @ {}", PhysicalAddress(PCI::get_BAR2(address)));
PCI::enable_bus_mastering(address);
m_display_connector = IntelNativeDisplayConnector::must_create(PhysicalAddress(PCI::get_BAR2(address) & 0xfffffff0), bar2_space_size, PhysicalAddress(PCI::get_BAR0(address) & 0xfffffff0), bar0_space_size);
m_display_connector = TRY(IntelNativeDisplayConnector::try_create(PhysicalAddress(PCI::get_BAR2(address) & 0xfffffff0), bar2_space_size, PhysicalAddress(PCI::get_BAR0(address) & 0xfffffff0), bar0_space_size));
return {};
}