mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:37:36 +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
|
@ -62,10 +62,10 @@ static constexpr u16 UHCI_PORTSC_NON_WRITE_CLEAR_BIT_MASK = 0x1FF5; // This is u
|
|||
static constexpr u8 UHCI_NUMBER_OF_ISOCHRONOUS_TDS = 128;
|
||||
static constexpr u16 UHCI_NUMBER_OF_FRAMES = 1024;
|
||||
|
||||
ErrorOr<NonnullRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
ErrorOr<NonnullLockRefPtr<UHCIController>> UHCIController::try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier)
|
||||
{
|
||||
// NOTE: This assumes that address is pointing to a valid UHCI controller.
|
||||
auto controller = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) UHCIController(pci_device_identifier)));
|
||||
auto controller = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) UHCIController(pci_device_identifier)));
|
||||
TRY(controller->initialize());
|
||||
return controller;
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ size_t UHCIController::poll_transfer_queue(QueueHead& transfer_queue)
|
|||
|
||||
ErrorOr<void> UHCIController::spawn_port_process()
|
||||
{
|
||||
RefPtr<Thread> usb_hotplug_thread;
|
||||
LockRefPtr<Thread> usb_hotplug_thread;
|
||||
(void)Process::create_kernel_process(usb_hotplug_thread, TRY(KString::try_create("UHCI Hot Plug Task"sv)), [&] {
|
||||
for (;;) {
|
||||
if (m_root_hub)
|
||||
|
|
|
@ -33,7 +33,7 @@ class UHCIController final
|
|||
|
||||
public:
|
||||
static constexpr u8 NUMBER_OF_ROOT_PORTS = 2;
|
||||
static ErrorOr<NonnullRefPtr<UHCIController>> try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier);
|
||||
static ErrorOr<NonnullLockRefPtr<UHCIController>> try_to_initialize(PCI::DeviceIdentifier const& pci_device_identifier);
|
||||
virtual ~UHCIController() override;
|
||||
|
||||
virtual StringView purpose() const override { return "UHCI"sv; }
|
||||
|
|
|
@ -83,12 +83,12 @@ static USBHubDescriptor uhci_root_hub_hub_descriptor = {
|
|||
0x0, // Self-powered
|
||||
};
|
||||
|
||||
ErrorOr<NonnullOwnPtr<UHCIRootHub>> UHCIRootHub::try_create(NonnullRefPtr<UHCIController> uhci_controller)
|
||||
ErrorOr<NonnullOwnPtr<UHCIRootHub>> UHCIRootHub::try_create(NonnullLockRefPtr<UHCIController> uhci_controller)
|
||||
{
|
||||
return adopt_nonnull_own_or_enomem(new (nothrow) UHCIRootHub(move(uhci_controller)));
|
||||
}
|
||||
|
||||
UHCIRootHub::UHCIRootHub(NonnullRefPtr<UHCIController> uhci_controller)
|
||||
UHCIRootHub::UHCIRootHub(NonnullLockRefPtr<UHCIController> uhci_controller)
|
||||
: m_uhci_controller(move(uhci_controller))
|
||||
{
|
||||
}
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
#include <AK/Error.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <Kernel/Bus/USB/USBHub.h>
|
||||
#include <Kernel/Bus/USB/USBTransfer.h>
|
||||
#include <Kernel/Library/NonnullLockRefPtr.h>
|
||||
|
||||
namespace Kernel::USB {
|
||||
|
||||
|
@ -18,9 +18,9 @@ class UHCIController;
|
|||
|
||||
class UHCIRootHub {
|
||||
public:
|
||||
static ErrorOr<NonnullOwnPtr<UHCIRootHub>> try_create(NonnullRefPtr<UHCIController>);
|
||||
static ErrorOr<NonnullOwnPtr<UHCIRootHub>> try_create(NonnullLockRefPtr<UHCIController>);
|
||||
|
||||
UHCIRootHub(NonnullRefPtr<UHCIController>);
|
||||
UHCIRootHub(NonnullLockRefPtr<UHCIController>);
|
||||
~UHCIRootHub() = default;
|
||||
|
||||
ErrorOr<void> setup(Badge<UHCIController>);
|
||||
|
@ -32,8 +32,8 @@ public:
|
|||
void check_for_port_updates() { m_hub->check_for_port_updates(); }
|
||||
|
||||
private:
|
||||
NonnullRefPtr<UHCIController> m_uhci_controller;
|
||||
RefPtr<Hub> m_hub;
|
||||
NonnullLockRefPtr<UHCIController> m_uhci_controller;
|
||||
LockRefPtr<Hub> m_hub;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ public:
|
|||
private:
|
||||
u8 m_next_device_index { 1 };
|
||||
|
||||
IntrusiveListNode<USBController, NonnullRefPtr<USBController>> m_controller_list_node;
|
||||
IntrusiveListNode<USBController, NonnullLockRefPtr<USBController>> m_controller_list_node;
|
||||
|
||||
public:
|
||||
using List = IntrusiveList<&USBController::m_controller_list_node>;
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
|
||||
namespace Kernel::USB {
|
||||
|
||||
ErrorOr<NonnullRefPtr<Device>> Device::try_create(USBController const& controller, u8 port, DeviceSpeed speed)
|
||||
ErrorOr<NonnullLockRefPtr<Device>> Device::try_create(USBController const& controller, u8 port, DeviceSpeed speed)
|
||||
{
|
||||
auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0));
|
||||
auto device = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Device(controller, port, speed, move(pipe))));
|
||||
auto device = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) Device(controller, port, speed, move(pipe))));
|
||||
auto sysfs_node = TRY(SysFSUSBDeviceInformation::create(*device));
|
||||
device->m_sysfs_device_info_node = move(sysfs_node);
|
||||
TRY(device->enumerate_device());
|
||||
|
@ -35,7 +35,7 @@ Device::Device(USBController const& controller, u8 port, DeviceSpeed speed, Nonn
|
|||
{
|
||||
}
|
||||
|
||||
Device::Device(NonnullRefPtr<USBController> controller, u8 address, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe)
|
||||
Device::Device(NonnullLockRefPtr<USBController> controller, u8 address, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe)
|
||||
: m_device_port(port)
|
||||
, m_device_speed(speed)
|
||||
, m_address(address)
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
LowSpeed
|
||||
};
|
||||
|
||||
static ErrorOr<NonnullRefPtr<Device>> try_create(USBController const&, u8, DeviceSpeed);
|
||||
static ErrorOr<NonnullLockRefPtr<Device>> try_create(USBController const&, u8, DeviceSpeed);
|
||||
|
||||
Device(USBController const&, u8, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe);
|
||||
Device(Device const& device, NonnullOwnPtr<Pipe> default_pipe);
|
||||
|
@ -59,7 +59,7 @@ public:
|
|||
SysFSUSBDeviceInformation& sysfs_device_info_node(Badge<USB::Hub>) { return *m_sysfs_device_info_node; }
|
||||
|
||||
protected:
|
||||
Device(NonnullRefPtr<USBController> controller, u8 address, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe);
|
||||
Device(NonnullLockRefPtr<USBController> controller, u8 address, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe);
|
||||
|
||||
u8 m_device_port { 0 }; // What port is this device attached to. NOTE: This is 1-based.
|
||||
DeviceSpeed m_device_speed; // What speed is this device running at
|
||||
|
@ -71,14 +71,14 @@ protected:
|
|||
USBDeviceDescriptor m_device_descriptor {}; // Device Descriptor obtained from USB Device
|
||||
Vector<USBConfiguration> m_configurations; // Configurations for this device
|
||||
|
||||
NonnullRefPtr<USBController> m_controller;
|
||||
NonnullLockRefPtr<USBController> m_controller;
|
||||
NonnullOwnPtr<Pipe> m_default_pipe; // Default communication pipe (endpoint0) used during enumeration
|
||||
|
||||
private:
|
||||
IntrusiveListNode<Device, NonnullRefPtr<Device>> m_hub_child_node;
|
||||
IntrusiveListNode<Device, NonnullLockRefPtr<Device>> m_hub_child_node;
|
||||
|
||||
protected:
|
||||
RefPtr<SysFSUSBDeviceInformation> m_sysfs_device_info_node;
|
||||
LockRefPtr<SysFSUSBDeviceInformation> m_sysfs_device_info_node;
|
||||
|
||||
public:
|
||||
using List = IntrusiveList<&Device::m_hub_child_node>;
|
||||
|
|
|
@ -14,23 +14,23 @@
|
|||
|
||||
namespace Kernel::USB {
|
||||
|
||||
ErrorOr<NonnullRefPtr<Hub>> Hub::try_create_root_hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed)
|
||||
ErrorOr<NonnullLockRefPtr<Hub>> Hub::try_create_root_hub(NonnullLockRefPtr<USBController> controller, DeviceSpeed device_speed)
|
||||
{
|
||||
// NOTE: Enumeration does not happen here, as the controller must know what the device address is at all times during enumeration to intercept requests.
|
||||
auto pipe = TRY(Pipe::try_create_pipe(controller, Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, 8, 0));
|
||||
auto hub = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Hub(controller, device_speed, move(pipe))));
|
||||
auto hub = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) Hub(controller, device_speed, move(pipe))));
|
||||
return hub;
|
||||
}
|
||||
|
||||
ErrorOr<NonnullRefPtr<Hub>> Hub::try_create_from_device(Device const& device)
|
||||
ErrorOr<NonnullLockRefPtr<Hub>> Hub::try_create_from_device(Device const& device)
|
||||
{
|
||||
auto pipe = TRY(Pipe::try_create_pipe(device.controller(), Pipe::Type::Control, Pipe::Direction::Bidirectional, 0, device.device_descriptor().max_packet_size, device.address()));
|
||||
auto hub = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Hub(device, move(pipe))));
|
||||
auto hub = TRY(adopt_nonnull_lock_ref_or_enomem(new (nothrow) Hub(device, move(pipe))));
|
||||
TRY(hub->enumerate_and_power_on_hub());
|
||||
return hub;
|
||||
}
|
||||
|
||||
Hub::Hub(NonnullRefPtr<USBController> controller, DeviceSpeed device_speed, NonnullOwnPtr<Pipe> default_pipe)
|
||||
Hub::Hub(NonnullLockRefPtr<USBController> controller, DeviceSpeed device_speed, NonnullOwnPtr<Pipe> default_pipe)
|
||||
: Device(move(controller), 1 /* Port 1 */, device_speed, move(default_pipe))
|
||||
{
|
||||
}
|
||||
|
@ -266,7 +266,7 @@ void Hub::check_for_port_updates()
|
|||
} else {
|
||||
dbgln("USB Hub: Device detached on port {}!", port_number);
|
||||
|
||||
RefPtr<Device> device_to_remove = nullptr;
|
||||
LockRefPtr<Device> device_to_remove = nullptr;
|
||||
for (auto& child : m_children) {
|
||||
if (port_number == child.port()) {
|
||||
device_to_remove = &child;
|
||||
|
|
|
@ -79,8 +79,8 @@ static constexpr u16 PORT_STATUS_RESET_CHANGED = (1 << 4);
|
|||
|
||||
class Hub : public Device {
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<Hub>> try_create_root_hub(NonnullRefPtr<USBController>, DeviceSpeed);
|
||||
static ErrorOr<NonnullRefPtr<Hub>> try_create_from_device(Device const&);
|
||||
static ErrorOr<NonnullLockRefPtr<Hub>> try_create_root_hub(NonnullLockRefPtr<USBController>, DeviceSpeed);
|
||||
static ErrorOr<NonnullLockRefPtr<Hub>> try_create_from_device(Device const&);
|
||||
|
||||
virtual ~Hub() override = default;
|
||||
|
||||
|
@ -96,7 +96,7 @@ public:
|
|||
|
||||
private:
|
||||
// Root Hub constructor
|
||||
Hub(NonnullRefPtr<USBController>, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe);
|
||||
Hub(NonnullLockRefPtr<USBController>, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe);
|
||||
|
||||
Hub(Device const&, NonnullOwnPtr<Pipe> default_pipe);
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <AK/NonnullRefPtrVector.h>
|
||||
#include <Kernel/Bus/USB/USBController.h>
|
||||
#include <Kernel/Library/NonnullLockRefPtr.h>
|
||||
#include <Kernel/Library/NonnullLockRefPtrVector.h>
|
||||
|
||||
namespace Kernel::USB {
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public:
|
|||
private:
|
||||
friend class Device;
|
||||
|
||||
NonnullRefPtr<USBController> m_controller;
|
||||
NonnullLockRefPtr<USBController> m_controller;
|
||||
|
||||
Type m_type;
|
||||
Direction m_direction;
|
||||
|
|
|
@ -9,9 +9,9 @@
|
|||
|
||||
namespace Kernel::USB {
|
||||
|
||||
ErrorOr<NonnullRefPtr<Transfer>> Transfer::try_create(Pipe& pipe, u16 length, Memory::Region& dma_buffer)
|
||||
ErrorOr<NonnullLockRefPtr<Transfer>> Transfer::try_create(Pipe& pipe, u16 length, Memory::Region& dma_buffer)
|
||||
{
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) Transfer(pipe, length, dma_buffer));
|
||||
return adopt_nonnull_lock_ref_or_enomem(new (nothrow) Transfer(pipe, length, dma_buffer));
|
||||
}
|
||||
|
||||
Transfer::Transfer(Pipe& pipe, u16 len, Memory::Region& dma_buffer)
|
||||
|
|
|
@ -8,9 +8,9 @@
|
|||
|
||||
#include <AK/AtomicRefCounted.h>
|
||||
#include <AK/OwnPtr.h>
|
||||
#include <AK/RefPtr.h>
|
||||
#include <Kernel/Bus/USB/PacketTypes.h>
|
||||
#include <Kernel/Bus/USB/USBPipe.h>
|
||||
#include <Kernel/Library/LockRefPtr.h>
|
||||
#include <Kernel/Memory/AnonymousVMObject.h>
|
||||
#include <Kernel/Memory/PhysicalPage.h>
|
||||
#include <Kernel/Memory/Region.h>
|
||||
|
@ -20,7 +20,7 @@ namespace Kernel::USB {
|
|||
|
||||
class Transfer final : public AtomicRefCounted<Transfer> {
|
||||
public:
|
||||
static ErrorOr<NonnullRefPtr<Transfer>> try_create(Pipe&, u16 length, Memory::Region& dma_buffer);
|
||||
static ErrorOr<NonnullLockRefPtr<Transfer>> try_create(Pipe&, u16 length, Memory::Region& dma_buffer);
|
||||
|
||||
Transfer() = delete;
|
||||
~Transfer();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue