mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05: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,19 +22,23 @@ namespace Kernel {
|
|||
#define DEVICE_EVENTS_CLEAR 0x4
|
||||
#define DEVICE_NUM_SCANOUTS 0x8
|
||||
|
||||
NonnullLockRefPtr<VirtIOGraphicsAdapter> VirtIOGraphicsAdapter::initialize(PCI::DeviceIdentifier const& device_identifier)
|
||||
ErrorOr<bool> VirtIOGraphicsAdapter::probe(PCI::DeviceIdentifier const& device_identifier)
|
||||
{
|
||||
return device_identifier.hardware_id().vendor_id == PCI::VendorID::VirtIO;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullLockRefPtr<GenericGraphicsAdapter>> VirtIOGraphicsAdapter::create(PCI::DeviceIdentifier const& device_identifier)
|
||||
{
|
||||
VERIFY(device_identifier.hardware_id().vendor_id == PCI::VendorID::VirtIO);
|
||||
// Setup memory transfer region
|
||||
auto scratch_space_region = MUST(MM.allocate_contiguous_kernel_region(
|
||||
auto scratch_space_region = TRY(MM.allocate_contiguous_kernel_region(
|
||||
32 * PAGE_SIZE,
|
||||
"VirtGPU Scratch Space"sv,
|
||||
Memory::Region::Access::ReadWrite));
|
||||
|
||||
auto active_context_ids = MUST(Bitmap::create(VREND_MAX_CTX, false));
|
||||
auto adapter = adopt_lock_ref(*new (nothrow) VirtIOGraphicsAdapter(device_identifier, move(active_context_ids), move(scratch_space_region)));
|
||||
auto active_context_ids = TRY(Bitmap::create(VREND_MAX_CTX, false));
|
||||
auto adapter = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) VirtIOGraphicsAdapter(device_identifier, move(active_context_ids), move(scratch_space_region))));
|
||||
adapter->initialize();
|
||||
MUST(adapter->initialize_adapter());
|
||||
TRY(adapter->initialize_adapter());
|
||||
return adapter;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue