Kernel: Remove the weird StorageController base class

This wasn't really used for anything and broke nvme controller as it was
now doubly ref counted :P
This commit is contained in:
2026-07-02 15:02:02 +03:00
parent 8be90c49bc
commit d8f136a76f
10 changed files with 29 additions and 52 deletions

View File

@@ -4,7 +4,6 @@
#include <BAN/Vector.h>
#include <kernel/ACPI/AML/Node.h>
#include <kernel/Memory/Types.h>
#include <kernel/Storage/StorageController.h>
#include <sys/types.h>

View File

@@ -10,12 +10,14 @@
namespace Kernel
{
class AHCIController final : public StorageController, public Interruptable
class AHCIController final : public BAN::RefCounted<AHCIController>, public Interruptable
{
BAN_NON_COPYABLE(AHCIController);
BAN_NON_MOVABLE(AHCIController);
public:
static BAN::ErrorOr<BAN::RefPtr<AHCIController>> create(PCI::Device&);
~AHCIController();
virtual void handle_irq() override;
@@ -27,6 +29,7 @@ namespace Kernel
: m_pci_device(pci_device)
{ }
BAN::ErrorOr<void> initialize();
BAN::Optional<AHCIPortType> check_port_type(volatile HBAPortMemorySpace&);
private:

View File

@@ -56,8 +56,6 @@ namespace Kernel
// Non-owning pointers
BAN::Vector<ATADevice*> m_devices;
friend class ATAController;
};
}

View File

@@ -2,23 +2,22 @@
#include <BAN/UniqPtr.h>
#include <kernel/PCI.h>
#include <kernel/Storage/StorageController.h>
#include <kernel/Storage/ATA/ATABus.h>
#include <kernel/Storage/ATA/ATADevice.h>
namespace Kernel
{
class ATAController : public StorageController
class ATAController : public BAN::RefCounted<ATAController>
{
public:
static BAN::ErrorOr<BAN::RefPtr<StorageController>> create(PCI::Device&);
virtual BAN::ErrorOr<void> initialize() override;
static BAN::ErrorOr<BAN::RefPtr<ATAController>> create(PCI::Device&);
private:
ATAController(PCI::Device& pci_device)
: m_pci_device(pci_device)
{ }
BAN::ErrorOr<void> initialize();
private:
PCI::Device& m_pci_device;

View File

@@ -10,13 +10,13 @@
namespace Kernel
{
class NVMeController final : public StorageController, public CharacterDevice
class NVMeController final : public CharacterDevice
{
BAN_NON_COPYABLE(NVMeController);
BAN_NON_MOVABLE(NVMeController);
public:
static BAN::ErrorOr<BAN::RefPtr<StorageController>> create(PCI::Device&);
static BAN::ErrorOr<BAN::RefPtr<NVMeController>> create(PCI::Device&);
NVMeQueue& io_queue() { return *m_io_queue; }
@@ -30,7 +30,7 @@ namespace Kernel
private:
NVMeController(PCI::Device& pci_device);
virtual BAN::ErrorOr<void> initialize() override;
BAN::ErrorOr<void> initialize();
BAN::ErrorOr<void> identify_controller();
BAN::ErrorOr<void> identify_namespaces();

View File

@@ -1,15 +0,0 @@
#pragma once
#include <BAN/RefPtr.h>
namespace Kernel
{
class StorageController : public BAN::RefCounted<StorageController>
{
public:
virtual ~StorageController() {}
virtual BAN::ErrorOr<void> initialize() = 0;
};
}

View File

@@ -235,11 +235,13 @@ namespace Kernel::PCI
switch (pci_device.subclass())
{
case 0x01:
case 0x05:
case 0x06:
if (auto res = ATAController::create(pci_device); res.is_error())
dprintln("ATA: {}", res.error());
break;
case 0x06:
if (auto res = AHCIController::create(pci_device); res.is_error())
dprintln("AHCI: {}", res.error());
break;
case 0x08:
if (auto res = NVMeController::create(pci_device); res.is_error())
dprintln("NVMe: {}", res.error());

View File

@@ -7,6 +7,16 @@
namespace Kernel
{
BAN::ErrorOr<BAN::RefPtr<AHCIController>> AHCIController::create(PCI::Device& pci_device)
{
auto* controller_ptr = new AHCIController(pci_device);
if (controller_ptr == nullptr)
return BAN::Error::from_errno(ENOMEM);
auto controller = BAN::RefPtr<AHCIController>::adopt(controller_ptr);
TRY(controller->initialize());
return controller;
}
BAN::ErrorOr<void> AHCIController::initialize()
{
m_abar = TRY(m_pci_device.allocate_bar_region(5));

View File

@@ -9,29 +9,12 @@
namespace Kernel
{
BAN::ErrorOr<BAN::RefPtr<StorageController>> ATAController::create(PCI::Device& pci_device)
BAN::ErrorOr<BAN::RefPtr<ATAController>> ATAController::create(PCI::Device& pci_device)
{
StorageController* controller_ptr = nullptr;
switch (pci_device.subclass())
{
case 0x01:
controller_ptr = new ATAController(pci_device);
break;
case 0x05:
dwarnln("unsupported DMA ATA Controller");
return BAN::Error::from_errno(ENOTSUP);
case 0x06:
controller_ptr = new AHCIController(pci_device);
break;
default:
ASSERT_NOT_REACHED();
}
auto* controller_ptr = new ATAController(pci_device);
if (controller_ptr == nullptr)
return BAN::Error::from_errno(ENOMEM);
auto controller = BAN::RefPtr<StorageController>::adopt(controller_ptr);
auto controller = BAN::RefPtr<ATAController>::adopt(controller_ptr);
TRY(controller->initialize());
return controller;
}

View File

@@ -16,12 +16,12 @@ namespace Kernel
return minor++;
}
BAN::ErrorOr<BAN::RefPtr<StorageController>> NVMeController::create(PCI::Device& pci_device)
BAN::ErrorOr<BAN::RefPtr<NVMeController>> NVMeController::create(PCI::Device& pci_device)
{
auto* controller_ptr = new NVMeController(pci_device);
if (controller_ptr == nullptr)
return BAN::Error::from_errno(ENOMEM);
auto controller = BAN::RefPtr<StorageController>::adopt(controller_ptr);
auto controller = BAN::RefPtr<NVMeController>::adopt(controller_ptr);
TRY(controller->initialize());
return controller;
}
@@ -115,8 +115,6 @@ namespace Kernel
DevFileSystem::get().add_device(this);
StorageController::ref();
return {};
}