mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 04:37:34 +00:00
Kernel/PCI: Don't hold spinlocks when doing fast device enumeration
Instead, hold the lock while we copy the contents to a stack-based Vector then iterate on it without any locking. Because we rely on heap allocations, we need to propagate errors back in case of OOM condition, therefore, both PCI::enumerate API function and PCI::Access::add_host_controller_and_enumerate_attached_devices use now a ErrorOr<void> return value to propagate errors. OOM Error can only occur when enumerating the m_device_identifiers vector under a spinlock and trying to expand the temporary Vector which will be used locklessly to actually iterate over the PCI::DeviceIdentifiers objects.
This commit is contained in:
parent
c0ed656c94
commit
3fb289e27d
14 changed files with 69 additions and 42 deletions
|
@ -7,6 +7,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Bitmap.h>
|
||||
#include <AK/Try.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <Kernel/Bus/PCI/Controller/HostController.h>
|
||||
#include <Kernel/Bus/PCI/Definitions.h>
|
||||
|
@ -21,7 +22,7 @@ public:
|
|||
static bool initialize_for_multiple_pci_domains(PhysicalAddress mcfg_table);
|
||||
static bool initialize_for_one_pci_domain();
|
||||
|
||||
void fast_enumerate(Function<void(DeviceIdentifier const&)>&) const;
|
||||
ErrorOr<void> fast_enumerate(Function<void(DeviceIdentifier const&)>&) const;
|
||||
void rescan_hardware();
|
||||
|
||||
static Access& the();
|
||||
|
@ -39,7 +40,7 @@ public:
|
|||
Spinlock const& scan_lock() const { return m_scan_lock; }
|
||||
RecursiveSpinlock const& access_lock() const { return m_access_lock; }
|
||||
|
||||
void add_host_controller_and_enumerate_attached_devices(NonnullOwnPtr<HostController>, Function<void(DeviceIdentifier const&)> callback);
|
||||
ErrorOr<void> add_host_controller_and_enumerate_attached_devices(NonnullOwnPtr<HostController>, Function<void(DeviceIdentifier const&)> callback);
|
||||
|
||||
private:
|
||||
u8 read8_field(Address address, RegisterOffset field);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue