mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:47:34 +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:
parent
7625f7db73
commit
72b144e9e9
12 changed files with 85 additions and 71 deletions
|
@ -22,17 +22,25 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
UNMAP_AFTER_INIT NonnullLockRefPtr<BochsGraphicsAdapter> BochsGraphicsAdapter::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
UNMAP_AFTER_INIT ErrorOr<bool> BochsGraphicsAdapter::probe(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
PCI::HardwareID id = pci_device_identifier.hardware_id();
|
||||
VERIFY((id.vendor_id == PCI::VendorID::QEMUOld && id.device_id == 0x1111) || (id.vendor_id == PCI::VendorID::VirtualBox && id.device_id == 0xbeef));
|
||||
auto adapter = adopt_lock_ref(*new BochsGraphicsAdapter(pci_device_identifier));
|
||||
if (id.vendor_id == PCI::VendorID::QEMUOld && id.device_id == 0x1111)
|
||||
return true;
|
||||
if (id.vendor_id == PCI::VendorID::VirtualBox && id.device_id == 0xbeef)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<GenericGraphicsAdapter>> BochsGraphicsAdapter::create(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
auto adapter = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) BochsGraphicsAdapter(pci_device_identifier.address())));
|
||||
MUST(adapter->initialize_adapter(pci_device_identifier));
|
||||
return adapter;
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT BochsGraphicsAdapter::BochsGraphicsAdapter(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
: PCI::Device(pci_device_identifier.address())
|
||||
UNMAP_AFTER_INIT BochsGraphicsAdapter::BochsGraphicsAdapter(PCI::Address const& address)
|
||||
: PCI::Device(address)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue