mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:18:12 +00:00

This step would ideally not have been necessary (increases amount of refactoring and templates necessary, which in turn increases build times), but it gives us a couple of nice properties: - SpinlockProtected inside Singleton (a very common combination) can now obtain any lock rank just via the template parameter. It was not previously possible to do this with SingletonInstanceCreator magic. - SpinlockProtected's lock rank is now mandatory; this is the majority of cases and allows us to see where we're still missing proper ranks. - The type already informs us what lock rank a lock has, which aids code readability and (possibly, if gdb cooperates) lock mismatch debugging. - The rank of a lock can no longer be dynamic, which is not something we wanted in the first place (or made use of). Locks randomly changing their rank sounds like a disaster waiting to happen. - In some places, we might be able to statically check that locks are taken in the right order (with the right lock rank checking implementation) as rank information is fully statically known. This refactoring even more exposes the fact that Mutex has no lock rank capabilites, which is not fixed here.
66 lines
2.1 KiB
C++
66 lines
2.1 KiB
C++
/*
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <AK/Bitmap.h>
|
|
#include <AK/HashMap.h>
|
|
#include <AK/NonnullOwnPtr.h>
|
|
#include <AK/Try.h>
|
|
#include <AK/Vector.h>
|
|
#include <Kernel/Bus/PCI/Controller/HostController.h>
|
|
#include <Kernel/Bus/PCI/Definitions.h>
|
|
#include <Kernel/Locking/Spinlock.h>
|
|
|
|
namespace Kernel::PCI {
|
|
|
|
class Access {
|
|
public:
|
|
static bool initialize_for_multiple_pci_domains(PhysicalAddress mcfg_table);
|
|
|
|
#if ARCH(X86_64)
|
|
static bool initialize_for_one_pci_domain();
|
|
#endif
|
|
|
|
ErrorOr<void> fast_enumerate(Function<void(DeviceIdentifier const&)>&) const;
|
|
void rescan_hardware();
|
|
|
|
static Access& the();
|
|
static bool is_initialized();
|
|
static bool is_disabled();
|
|
static bool is_hardware_disabled();
|
|
|
|
void write8_field(Address address, u32 field, u8 value);
|
|
void write16_field(Address address, u32 field, u16 value);
|
|
void write32_field(Address address, u32 field, u32 value);
|
|
u8 read8_field(Address address, u32 field);
|
|
u16 read16_field(Address address, u32 field);
|
|
u32 read32_field(Address address, u32 field);
|
|
DeviceIdentifier get_device_identifier(Address address) const;
|
|
|
|
Spinlock<LockRank::None> const& scan_lock() const { return m_scan_lock; }
|
|
RecursiveSpinlock<LockRank::None> const& access_lock() const { return m_access_lock; }
|
|
|
|
ErrorOr<void> add_host_controller_and_enumerate_attached_devices(NonnullOwnPtr<HostController>, Function<void(DeviceIdentifier const&)> callback);
|
|
|
|
private:
|
|
u8 read8_field(Address address, RegisterOffset field);
|
|
u16 read16_field(Address address, RegisterOffset field);
|
|
|
|
void add_host_controller(NonnullOwnPtr<HostController>);
|
|
bool find_and_register_pci_host_bridges_from_acpi_mcfg_table(PhysicalAddress mcfg);
|
|
Access();
|
|
|
|
Vector<Capability> get_capabilities(Address);
|
|
Optional<u8> get_capabilities_pointer(Address address);
|
|
|
|
mutable RecursiveSpinlock<LockRank::None> m_access_lock {};
|
|
mutable Spinlock<LockRank::None> m_scan_lock {};
|
|
|
|
HashMap<u32, NonnullOwnPtr<PCI::HostController>> m_host_controllers;
|
|
Vector<DeviceIdentifier> m_device_identifiers;
|
|
};
|
|
}
|