summaryrefslogtreecommitdiff
path: root/Kernel
diff options
context:
space:
mode:
authorLiav A <liavalb@gmail.com>2021-03-27 06:22:55 +0300
committerAndreas Kling <kling@serenityos.org>2021-03-27 16:40:16 +0100
commitdfb6b296cf9ae8b5afa19cf2ea6813f0d774fcb1 (patch)
treee5d2aa91a74c932c46eb876857a1e06e72b1d5c2 /Kernel
parent531037db7ecff1b340cdfd3a8c8f8c689585e4af (diff)
downloadserenity-dfb6b296cf9ae8b5afa19cf2ea6813f0d774fcb1.zip
Kernel: Make IDEChannel Ref-counted
Technically not supported by the original ATA specification, IDE hot swapping is still in practice possible, so the only sane way to start support it is with ref-counting the IDEChannel object so if we remove a PATADiskDevice, it's not gone with it.
Diffstat (limited to 'Kernel')
-rw-r--r--Kernel/Storage/IDEChannel.cpp4
-rw-r--r--Kernel/Storage/IDEChannel.h8
-rw-r--r--Kernel/Storage/IDEController.h2
-rw-r--r--Kernel/Storage/PATADiskDevice.cpp4
-rw-r--r--Kernel/Storage/PATADiskDevice.h2
5 files changed, 11 insertions, 9 deletions
diff --git a/Kernel/Storage/IDEChannel.cpp b/Kernel/Storage/IDEChannel.cpp
index 86e2b04eb3..2fbc43f286 100644
--- a/Kernel/Storage/IDEChannel.cpp
+++ b/Kernel/Storage/IDEChannel.cpp
@@ -45,9 +45,9 @@ namespace Kernel {
#define PCI_Mass_Storage_Class 0x1
#define PCI_IDE_Controller_Subclass 0x1
-UNMAP_AFTER_INIT NonnullOwnPtr<IDEChannel> IDEChannel::create(const IDEController& controller, IOAddressGroup io_group, ChannelType type, bool force_pio)
+UNMAP_AFTER_INIT NonnullRefPtr<IDEChannel> IDEChannel::create(const IDEController& controller, IOAddressGroup io_group, ChannelType type, bool force_pio)
{
- return make<IDEChannel>(controller, io_group, type, force_pio);
+ return adopt(*new IDEChannel(controller, io_group, type, force_pio));
}
RefPtr<StorageDevice> IDEChannel::master_device() const
diff --git a/Kernel/Storage/IDEChannel.h b/Kernel/Storage/IDEChannel.h
index e48c7fd68c..095bc3808f 100644
--- a/Kernel/Storage/IDEChannel.h
+++ b/Kernel/Storage/IDEChannel.h
@@ -60,7 +60,8 @@ struct PhysicalRegionDescriptor {
};
class IDEController;
-class IDEChannel final : public IRQHandler {
+class IDEChannel final : public RefCounted<IDEChannel>
+ , public IRQHandler {
friend class IDEController;
friend class PATADiskDevice;
AK_MAKE_ETERNAL
@@ -104,8 +105,7 @@ public:
};
public:
- static NonnullOwnPtr<IDEChannel> create(const IDEController&, IOAddressGroup, ChannelType type, bool force_pio);
- IDEChannel(const IDEController&, IOAddressGroup, ChannelType type, bool force_pio);
+ static NonnullRefPtr<IDEChannel> create(const IDEController&, IOAddressGroup, ChannelType type, bool force_pio);
virtual ~IDEChannel() override;
RefPtr<StorageDevice> master_device() const;
@@ -114,6 +114,8 @@ public:
virtual const char* purpose() const override { return "PATA Channel"; }
private:
+ IDEChannel(const IDEController&, IOAddressGroup, ChannelType type, bool force_pio);
+
//^ IRQHandler
virtual void handle_irq(const RegisterState&) override;
diff --git a/Kernel/Storage/IDEController.h b/Kernel/Storage/IDEController.h
index 51518ffa21..aff37f1bd9 100644
--- a/Kernel/Storage/IDEController.h
+++ b/Kernel/Storage/IDEController.h
@@ -60,6 +60,6 @@ private:
void initialize(bool force_pio);
void detect_disks();
- NonnullOwnPtrVector<IDEChannel> m_channels;
+ NonnullRefPtrVector<IDEChannel> m_channels;
};
}
diff --git a/Kernel/Storage/PATADiskDevice.cpp b/Kernel/Storage/PATADiskDevice.cpp
index 4649b71581..1e6b6cba29 100644
--- a/Kernel/Storage/PATADiskDevice.cpp
+++ b/Kernel/Storage/PATADiskDevice.cpp
@@ -58,8 +58,8 @@ const char* PATADiskDevice::class_name() const
void PATADiskDevice::start_request(AsyncBlockDeviceRequest& request)
{
- bool use_dma = !m_channel.m_io_group.bus_master_base().is_null() && m_channel.m_dma_enabled.resource();
- m_channel.start_request(request, use_dma, is_slave(), m_capabilities);
+ bool use_dma = !m_channel->m_io_group.bus_master_base().is_null() && m_channel->m_dma_enabled.resource();
+ m_channel->start_request(request, use_dma, is_slave(), m_capabilities);
}
String PATADiskDevice::device_name() const
diff --git a/Kernel/Storage/PATADiskDevice.h b/Kernel/Storage/PATADiskDevice.h
index 55c394dd00..406242c584 100644
--- a/Kernel/Storage/PATADiskDevice.h
+++ b/Kernel/Storage/PATADiskDevice.h
@@ -77,7 +77,7 @@ private:
Lock m_lock { "IDEDiskDevice" };
u16 m_capabilities { 0 };
- IDEChannel& m_channel;
+ NonnullRefPtr<IDEChannel> m_channel;
DriveType m_drive_type { DriveType::Master };
InterfaceType m_interface_type { InterfaceType::ATA };
};