mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 08:47:44 +00:00
Kernel: Make self-contained locking smart pointers their own classes
Until now, our kernel has reimplemented a number of AK classes to provide automatic internal locking: - RefPtr - NonnullRefPtr - WeakPtr - Weakable This patch renames the Kernel classes so that they can coexist with the original AK classes: - RefPtr => LockRefPtr - NonnullRefPtr => NonnullLockRefPtr - WeakPtr => LockWeakPtr - Weakable => LockWeakable The goal here is to eventually get rid of the Lock* classes in favor of using external locking.
This commit is contained in:
parent
e475263113
commit
11eee67b85
360 changed files with 1703 additions and 1672 deletions
|
@ -7,19 +7,19 @@
|
|||
#include <AK/Atomic.h>
|
||||
#include <AK/BuiltinWrappers.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/Bus/PCI/API.h>
|
||||
#include <Kernel/CommandLine.h>
|
||||
#include <Kernel/Library/LockRefPtr.h>
|
||||
#include <Kernel/Memory/MemoryManager.h>
|
||||
#include <Kernel/Storage/ATA/AHCI/Controller.h>
|
||||
#include <Kernel/Storage/ATA/AHCI/InterruptHandler.h>
|
||||
|
||||
namespace Kernel {
|
||||
|
||||
UNMAP_AFTER_INIT NonnullRefPtr<AHCIController> AHCIController::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
UNMAP_AFTER_INIT NonnullLockRefPtr<AHCIController> AHCIController::initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
auto controller = adopt_ref_if_nonnull(new (nothrow) AHCIController(pci_device_identifier)).release_nonnull();
|
||||
auto controller = adopt_lock_ref_if_nonnull(new (nothrow) AHCIController(pci_device_identifier)).release_nonnull();
|
||||
controller->initialize_hba(pci_device_identifier);
|
||||
return controller;
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ void AHCIController::enable_global_interrupts() const
|
|||
hba().control_regs.ghc = hba().control_regs.ghc | (1 << 1);
|
||||
}
|
||||
|
||||
RefPtr<StorageDevice> AHCIController::device_by_port(u32 port_index) const
|
||||
LockRefPtr<StorageDevice> AHCIController::device_by_port(u32 port_index) const
|
||||
{
|
||||
SpinlockLocker locker(m_hba_control_lock);
|
||||
auto port = m_ports[port_index];
|
||||
|
@ -202,9 +202,9 @@ RefPtr<StorageDevice> AHCIController::device_by_port(u32 port_index) const
|
|||
return port->connected_device();
|
||||
}
|
||||
|
||||
RefPtr<StorageDevice> AHCIController::device(u32 index) const
|
||||
LockRefPtr<StorageDevice> AHCIController::device(u32 index) const
|
||||
{
|
||||
NonnullRefPtrVector<StorageDevice> connected_devices;
|
||||
NonnullLockRefPtrVector<StorageDevice> connected_devices;
|
||||
u32 pi = hba().control_regs.pi;
|
||||
u32 bit = bit_scan_forward(pi);
|
||||
while (bit) {
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/Types.h>
|
||||
#include <Kernel/Library/LockRefPtr.h>
|
||||
#include <Kernel/Sections.h>
|
||||
#include <Kernel/Storage/ATA/AHCI/Definitions.h>
|
||||
#include <Kernel/Storage/ATA/ATAController.h>
|
||||
|
@ -24,10 +24,10 @@ class AHCIController final : public ATAController
|
|||
friend class AHCIInterruptHandler;
|
||||
|
||||
public:
|
||||
static NonnullRefPtr<AHCIController> initialize(PCI::DeviceIdentifier const& pci_device_identifier);
|
||||
static NonnullLockRefPtr<AHCIController> initialize(PCI::DeviceIdentifier const& pci_device_identifier);
|
||||
virtual ~AHCIController() override;
|
||||
|
||||
virtual RefPtr<StorageDevice> device(u32 index) const override;
|
||||
virtual LockRefPtr<StorageDevice> device(u32 index) const override;
|
||||
virtual bool reset() override;
|
||||
virtual bool shutdown() override;
|
||||
virtual size_t devices_count() const override;
|
||||
|
@ -44,13 +44,13 @@ private:
|
|||
void initialize_hba(PCI::DeviceIdentifier const&);
|
||||
|
||||
AHCI::HBADefinedCapabilities capabilities() const;
|
||||
RefPtr<StorageDevice> device_by_port(u32 index) const;
|
||||
LockRefPtr<StorageDevice> device_by_port(u32 index) const;
|
||||
|
||||
volatile AHCI::PortRegisters& port(size_t port_number) const;
|
||||
NonnullOwnPtr<Memory::Region> default_hba_region() const;
|
||||
volatile AHCI::HBA& hba() const;
|
||||
|
||||
Array<RefPtr<AHCIPort>, 32> m_ports;
|
||||
Array<LockRefPtr<AHCIPort>, 32> m_ports;
|
||||
NonnullOwnPtr<Memory::Region> m_hba_region;
|
||||
AHCI::HBADefinedCapabilities m_hba_capabilities;
|
||||
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/RefPtr.h>
|
||||
#include <Kernel/Arch/x86/IO.h>
|
||||
#include <Kernel/Devices/Device.h>
|
||||
#include <Kernel/Interrupts/IRQHandler.h>
|
||||
#include <Kernel/Library/LockRefPtr.h>
|
||||
#include <Kernel/Locking/Mutex.h>
|
||||
#include <Kernel/Memory/PhysicalPage.h>
|
||||
#include <Kernel/PhysicalAddress.h>
|
||||
|
@ -53,7 +53,7 @@ private:
|
|||
AHCI::MaskedBitField create_pending_ports_interrupts_bitfield() const;
|
||||
|
||||
// Data members
|
||||
NonnullRefPtr<AHCIController> m_parent_controller;
|
||||
NonnullLockRefPtr<AHCIController> m_parent_controller;
|
||||
AHCI::MaskedBitField m_taken_ports;
|
||||
AHCI::MaskedBitField m_pending_ports_interrupts;
|
||||
};
|
||||
|
|
|
@ -20,10 +20,10 @@
|
|||
|
||||
namespace Kernel {
|
||||
|
||||
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<AHCIPort>> AHCIPort::create(AHCIController const& controller, AHCI::HBADefinedCapabilities hba_capabilities, volatile AHCI::PortRegisters& registers, u32 port_index)
|
||||
UNMAP_AFTER_INIT ErrorOr<NonnullLockRefPtr<AHCIPort>> AHCIPort::create(AHCIController const& controller, AHCI::HBADefinedCapabilities hba_capabilities, volatile AHCI::PortRegisters& registers, u32 port_index)
|
||||
{
|
||||
auto identify_buffer_page = MUST(MM.allocate_physical_page());
|
||||
auto port = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) AHCIPort(controller, move(identify_buffer_page), hba_capabilities, registers, port_index)));
|
||||
auto port = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) AHCIPort(controller, move(identify_buffer_page), hba_capabilities, registers, port_index)));
|
||||
TRY(port->allocate_resources_and_initialize_ports());
|
||||
return port;
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ ErrorOr<void> AHCIPort::allocate_resources_and_initialize_ports()
|
|||
return {};
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT AHCIPort::AHCIPort(AHCIController const& controller, NonnullRefPtr<Memory::PhysicalPage> identify_buffer_page, AHCI::HBADefinedCapabilities hba_capabilities, volatile AHCI::PortRegisters& registers, u32 port_index)
|
||||
UNMAP_AFTER_INIT AHCIPort::AHCIPort(AHCIController const& controller, NonnullLockRefPtr<Memory::PhysicalPage> identify_buffer_page, AHCI::HBADefinedCapabilities hba_capabilities, volatile AHCI::PortRegisters& registers, u32 port_index)
|
||||
: m_port_index(port_index)
|
||||
, m_hba_capabilities(hba_capabilities)
|
||||
, m_identify_buffer_page(move(identify_buffer_page))
|
||||
|
@ -180,7 +180,7 @@ void AHCIPort::recover_from_fatal_error()
|
|||
{
|
||||
MutexLocker locker(m_lock);
|
||||
SpinlockLocker lock(m_hard_lock);
|
||||
RefPtr<AHCIController> controller = m_parent_controller.strong_ref();
|
||||
LockRefPtr<AHCIController> controller = m_parent_controller.strong_ref();
|
||||
if (!controller) {
|
||||
dmesgln("AHCI Port {}: fatal error, controller not available", representative_port_index());
|
||||
return;
|
||||
|
@ -355,7 +355,7 @@ bool AHCIPort::initialize()
|
|||
|
||||
// FIXME: We don't support ATAPI devices yet, so for now we don't "create" them
|
||||
if (!is_atapi_attached()) {
|
||||
RefPtr<AHCIController> controller = m_parent_controller.strong_ref();
|
||||
LockRefPtr<AHCIController> controller = m_parent_controller.strong_ref();
|
||||
if (!controller) {
|
||||
dmesgln("AHCI Port {}: Device found, but parent controller is not available, abort.", representative_port_index());
|
||||
return false;
|
||||
|
@ -496,7 +496,7 @@ Optional<AsyncDeviceRequest::RequestResult> AHCIPort::prepare_and_set_scatter_li
|
|||
VERIFY(m_lock.is_locked());
|
||||
VERIFY(request.block_count() > 0);
|
||||
|
||||
NonnullRefPtrVector<Memory::PhysicalPage> allocated_dma_regions;
|
||||
NonnullLockRefPtrVector<Memory::PhysicalPage> allocated_dma_regions;
|
||||
for (size_t index = 0; index < calculate_descriptors_count(request.block_count()); index++) {
|
||||
allocated_dma_regions.append(m_dma_buffers.at(index));
|
||||
}
|
||||
|
@ -662,7 +662,7 @@ bool AHCIPort::identify_device()
|
|||
if (!spin_until_ready())
|
||||
return false;
|
||||
|
||||
RefPtr<AHCIController> controller = m_parent_controller.strong_ref();
|
||||
LockRefPtr<AHCIController> controller = m_parent_controller.strong_ref();
|
||||
if (!controller)
|
||||
return false;
|
||||
|
||||
|
|
|
@ -7,11 +7,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <AK/Weakable.h>
|
||||
#include <Kernel/Devices/Device.h>
|
||||
#include <Kernel/Interrupts/IRQHandler.h>
|
||||
#include <Kernel/Library/LockRefPtr.h>
|
||||
#include <Kernel/Library/LockWeakPtr.h>
|
||||
#include <Kernel/Library/LockWeakable.h>
|
||||
#include <Kernel/Locking/Mutex.h>
|
||||
#include <Kernel/Locking/Spinlock.h>
|
||||
#include <Kernel/Memory/AnonymousVMObject.h>
|
||||
|
@ -33,18 +33,18 @@ class AsyncBlockDeviceRequest;
|
|||
class AHCIInterruptHandler;
|
||||
class AHCIPort
|
||||
: public AtomicRefCounted<AHCIPort>
|
||||
, public Weakable<AHCIPort> {
|
||||
, public LockWeakable<AHCIPort> {
|
||||
friend class AHCIController;
|
||||
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<AHCIPort>> create(AHCIController const&, AHCI::HBADefinedCapabilities, volatile AHCI::PortRegisters&, u32 port_index);
|
||||
static ErrorOr<NonnullLockRefPtr<AHCIPort>> create(AHCIController const&, AHCI::HBADefinedCapabilities, volatile AHCI::PortRegisters&, u32 port_index);
|
||||
|
||||
u32 port_index() const { return m_port_index; }
|
||||
u32 representative_port_index() const { return port_index() + 1; }
|
||||
bool is_operable() const;
|
||||
bool is_atapi_attached() const { return m_port_registers.sig == (u32)ATA::DeviceSignature::ATAPI; };
|
||||
|
||||
RefPtr<StorageDevice> connected_device() const { return m_connected_device; }
|
||||
LockRefPtr<StorageDevice> connected_device() const { return m_connected_device; }
|
||||
|
||||
bool reset();
|
||||
bool initialize_without_reset();
|
||||
|
@ -56,7 +56,7 @@ private:
|
|||
bool is_phy_enabled() const { return (m_port_registers.ssts & 0xf) == 3; }
|
||||
bool initialize();
|
||||
|
||||
AHCIPort(AHCIController const&, NonnullRefPtr<Memory::PhysicalPage> identify_buffer_page, AHCI::HBADefinedCapabilities, volatile AHCI::PortRegisters&, u32 port_index);
|
||||
AHCIPort(AHCIController const&, NonnullLockRefPtr<Memory::PhysicalPage> identify_buffer_page, AHCI::HBADefinedCapabilities, volatile AHCI::PortRegisters&, u32 port_index);
|
||||
|
||||
ALWAYS_INLINE void clear_sata_error_register() const;
|
||||
|
||||
|
@ -105,18 +105,18 @@ private:
|
|||
// Data members
|
||||
|
||||
EntropySource m_entropy_source;
|
||||
RefPtr<AsyncBlockDeviceRequest> m_current_request;
|
||||
LockRefPtr<AsyncBlockDeviceRequest> m_current_request;
|
||||
Spinlock m_hard_lock { LockRank::None };
|
||||
Mutex m_lock { "AHCIPort"sv };
|
||||
|
||||
mutable bool m_wait_for_completion { false };
|
||||
|
||||
NonnullRefPtrVector<Memory::PhysicalPage> m_dma_buffers;
|
||||
NonnullRefPtrVector<Memory::PhysicalPage> m_command_table_pages;
|
||||
RefPtr<Memory::PhysicalPage> m_command_list_page;
|
||||
NonnullLockRefPtrVector<Memory::PhysicalPage> m_dma_buffers;
|
||||
NonnullLockRefPtrVector<Memory::PhysicalPage> m_command_table_pages;
|
||||
LockRefPtr<Memory::PhysicalPage> m_command_list_page;
|
||||
OwnPtr<Memory::Region> m_command_list_region;
|
||||
RefPtr<Memory::PhysicalPage> m_fis_receive_page;
|
||||
RefPtr<ATADevice> m_connected_device;
|
||||
LockRefPtr<Memory::PhysicalPage> m_fis_receive_page;
|
||||
LockRefPtr<ATADevice> m_connected_device;
|
||||
|
||||
u32 m_port_index;
|
||||
|
||||
|
@ -125,14 +125,14 @@ private:
|
|||
// it's probably better to just "cache" this here instead.
|
||||
AHCI::HBADefinedCapabilities const m_hba_capabilities;
|
||||
|
||||
NonnullRefPtr<Memory::PhysicalPage> m_identify_buffer_page;
|
||||
NonnullLockRefPtr<Memory::PhysicalPage> m_identify_buffer_page;
|
||||
|
||||
volatile AHCI::PortRegisters& m_port_registers;
|
||||
WeakPtr<AHCIController> m_parent_controller;
|
||||
LockWeakPtr<AHCIController> m_parent_controller;
|
||||
AHCI::PortInterruptStatusBitField m_interrupt_status;
|
||||
AHCI::PortInterruptEnableBitField m_interrupt_enable;
|
||||
|
||||
RefPtr<Memory::ScatterGatherList> m_current_scatter_list;
|
||||
LockRefPtr<Memory::ScatterGatherList> m_current_scatter_list;
|
||||
bool m_disabled_by_firmware { false };
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue