mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:17:35 +00:00
Kernel: Protect PCI access with spinlock instead of mutex
This commit is contained in:
parent
200589ba27
commit
64254b5df8
2 changed files with 11 additions and 12 deletions
|
@ -110,7 +110,7 @@ UNMAP_AFTER_INIT bool Access::initialize_for_one_pci_domain()
|
||||||
|
|
||||||
void Access::add_host_controller_and_enumerate_attached_devices(NonnullOwnPtr<HostController> controller, Function<void(DeviceIdentifier const&)> callback)
|
void Access::add_host_controller_and_enumerate_attached_devices(NonnullOwnPtr<HostController> controller, Function<void(DeviceIdentifier const&)> callback)
|
||||||
{
|
{
|
||||||
MutexLocker locker(m_access_lock);
|
SpinlockLocker locker(m_access_lock);
|
||||||
SpinlockLocker scan_locker(m_scan_lock);
|
SpinlockLocker scan_locker(m_scan_lock);
|
||||||
auto domain_number = controller->domain_number();
|
auto domain_number = controller->domain_number();
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ UNMAP_AFTER_INIT Access::Access()
|
||||||
|
|
||||||
UNMAP_AFTER_INIT void Access::rescan_hardware()
|
UNMAP_AFTER_INIT void Access::rescan_hardware()
|
||||||
{
|
{
|
||||||
MutexLocker locker(m_access_lock);
|
SpinlockLocker locker(m_access_lock);
|
||||||
SpinlockLocker scan_locker(m_scan_lock);
|
SpinlockLocker scan_locker(m_scan_lock);
|
||||||
VERIFY(m_device_identifiers.is_empty());
|
VERIFY(m_device_identifiers.is_empty());
|
||||||
for (auto it = m_host_controllers.begin(); it != m_host_controllers.end(); ++it) {
|
for (auto it = m_host_controllers.begin(); it != m_host_controllers.end(); ++it) {
|
||||||
|
@ -149,7 +149,7 @@ UNMAP_AFTER_INIT void Access::rescan_hardware()
|
||||||
|
|
||||||
void Access::fast_enumerate(Function<void(DeviceIdentifier const&)>& callback) const
|
void Access::fast_enumerate(Function<void(DeviceIdentifier const&)>& callback) const
|
||||||
{
|
{
|
||||||
MutexLocker locker(m_access_lock);
|
SpinlockLocker locker(m_access_lock);
|
||||||
VERIFY(!m_device_identifiers.is_empty());
|
VERIFY(!m_device_identifiers.is_empty());
|
||||||
for (auto const& device_identifier : m_device_identifiers) {
|
for (auto const& device_identifier : m_device_identifiers) {
|
||||||
callback(device_identifier);
|
callback(device_identifier);
|
||||||
|
@ -171,21 +171,21 @@ DeviceIdentifier Access::get_device_identifier(Address address) const
|
||||||
|
|
||||||
void Access::write8_field(Address address, u32 field, u8 value)
|
void Access::write8_field(Address address, u32 field, u8 value)
|
||||||
{
|
{
|
||||||
MutexLocker lock(m_access_lock);
|
SpinlockLocker locker(m_access_lock);
|
||||||
VERIFY(m_host_controllers.contains(address.domain()));
|
VERIFY(m_host_controllers.contains(address.domain()));
|
||||||
auto& controller = *m_host_controllers.get(address.domain()).value();
|
auto& controller = *m_host_controllers.get(address.domain()).value();
|
||||||
controller.write8_field(address.bus(), address.device(), address.function(), field, value);
|
controller.write8_field(address.bus(), address.device(), address.function(), field, value);
|
||||||
}
|
}
|
||||||
void Access::write16_field(Address address, u32 field, u16 value)
|
void Access::write16_field(Address address, u32 field, u16 value)
|
||||||
{
|
{
|
||||||
MutexLocker lock(m_access_lock);
|
SpinlockLocker locker(m_access_lock);
|
||||||
VERIFY(m_host_controllers.contains(address.domain()));
|
VERIFY(m_host_controllers.contains(address.domain()));
|
||||||
auto& controller = *m_host_controllers.get(address.domain()).value();
|
auto& controller = *m_host_controllers.get(address.domain()).value();
|
||||||
controller.write16_field(address.bus(), address.device(), address.function(), field, value);
|
controller.write16_field(address.bus(), address.device(), address.function(), field, value);
|
||||||
}
|
}
|
||||||
void Access::write32_field(Address address, u32 field, u32 value)
|
void Access::write32_field(Address address, u32 field, u32 value)
|
||||||
{
|
{
|
||||||
MutexLocker lock(m_access_lock);
|
SpinlockLocker locker(m_access_lock);
|
||||||
VERIFY(m_host_controllers.contains(address.domain()));
|
VERIFY(m_host_controllers.contains(address.domain()));
|
||||||
auto& controller = *m_host_controllers.get(address.domain()).value();
|
auto& controller = *m_host_controllers.get(address.domain()).value();
|
||||||
controller.write32_field(address.bus(), address.device(), address.function(), field, value);
|
controller.write32_field(address.bus(), address.device(), address.function(), field, value);
|
||||||
|
@ -202,21 +202,21 @@ u16 Access::read16_field(Address address, RegisterOffset field)
|
||||||
|
|
||||||
u8 Access::read8_field(Address address, u32 field)
|
u8 Access::read8_field(Address address, u32 field)
|
||||||
{
|
{
|
||||||
MutexLocker lock(m_access_lock);
|
SpinlockLocker locker(m_access_lock);
|
||||||
VERIFY(m_host_controllers.contains(address.domain()));
|
VERIFY(m_host_controllers.contains(address.domain()));
|
||||||
auto& controller = *m_host_controllers.get(address.domain()).value();
|
auto& controller = *m_host_controllers.get(address.domain()).value();
|
||||||
return controller.read8_field(address.bus(), address.device(), address.function(), field);
|
return controller.read8_field(address.bus(), address.device(), address.function(), field);
|
||||||
}
|
}
|
||||||
u16 Access::read16_field(Address address, u32 field)
|
u16 Access::read16_field(Address address, u32 field)
|
||||||
{
|
{
|
||||||
MutexLocker lock(m_access_lock);
|
SpinlockLocker locker(m_access_lock);
|
||||||
VERIFY(m_host_controllers.contains(address.domain()));
|
VERIFY(m_host_controllers.contains(address.domain()));
|
||||||
auto& controller = *m_host_controllers.get(address.domain()).value();
|
auto& controller = *m_host_controllers.get(address.domain()).value();
|
||||||
return controller.read16_field(address.bus(), address.device(), address.function(), field);
|
return controller.read16_field(address.bus(), address.device(), address.function(), field);
|
||||||
}
|
}
|
||||||
u32 Access::read32_field(Address address, u32 field)
|
u32 Access::read32_field(Address address, u32 field)
|
||||||
{
|
{
|
||||||
MutexLocker lock(m_access_lock);
|
SpinlockLocker locker(m_access_lock);
|
||||||
VERIFY(m_host_controllers.contains(address.domain()));
|
VERIFY(m_host_controllers.contains(address.domain()));
|
||||||
auto& controller = *m_host_controllers.get(address.domain()).value();
|
auto& controller = *m_host_controllers.get(address.domain()).value();
|
||||||
return controller.read32_field(address.bus(), address.device(), address.function(), field);
|
return controller.read32_field(address.bus(), address.device(), address.function(), field);
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
DeviceIdentifier get_device_identifier(Address address) const;
|
DeviceIdentifier get_device_identifier(Address address) const;
|
||||||
|
|
||||||
Spinlock const& scan_lock() const { return m_scan_lock; }
|
Spinlock const& scan_lock() const { return m_scan_lock; }
|
||||||
Mutex const& access_lock() const { return m_access_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);
|
void add_host_controller_and_enumerate_attached_devices(NonnullOwnPtr<HostController>, Function<void(DeviceIdentifier const&)> callback);
|
||||||
|
|
||||||
|
@ -51,8 +51,7 @@ private:
|
||||||
Vector<Capability> get_capabilities(Address);
|
Vector<Capability> get_capabilities(Address);
|
||||||
Optional<u8> get_capabilities_pointer(Address address);
|
Optional<u8> get_capabilities_pointer(Address address);
|
||||||
|
|
||||||
// General Data-members
|
mutable RecursiveSpinlock m_access_lock;
|
||||||
mutable Mutex m_access_lock;
|
|
||||||
mutable Spinlock m_scan_lock;
|
mutable Spinlock m_scan_lock;
|
||||||
|
|
||||||
HashMap<u32, NonnullOwnPtr<HostController>> m_host_controllers;
|
HashMap<u32, NonnullOwnPtr<HostController>> m_host_controllers;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue