Kernel: Add a method to gather the devices count of a Storage controller

Also, change device() method to be const.
This commit is contained in:
Liav A 2020-12-19 13:56:12 +02:00 committed by Andreas Kling
parent e3b3805abf
commit 6a691306b5
5 changed files with 19 additions and 7 deletions

View file

@ -114,11 +114,11 @@ NonnullOwnPtr<IDEChannel> IDEChannel::create(const IDEController& controller, IO
return make<IDEChannel>(controller, io_group, type, force_pio); return make<IDEChannel>(controller, io_group, type, force_pio);
} }
RefPtr<StorageDevice> IDEChannel::master_device() RefPtr<StorageDevice> IDEChannel::master_device() const
{ {
return m_master; return m_master;
} }
RefPtr<StorageDevice> IDEChannel::slave_device() RefPtr<StorageDevice> IDEChannel::slave_device() const
{ {
return m_slave; return m_slave;
} }

View file

@ -108,8 +108,8 @@ public:
IDEChannel(const IDEController&, IOAddressGroup, ChannelType type, bool force_pio); IDEChannel(const IDEController&, IOAddressGroup, ChannelType type, bool force_pio);
virtual ~IDEChannel() override; virtual ~IDEChannel() override;
RefPtr<StorageDevice> master_device(); RefPtr<StorageDevice> master_device() const;
RefPtr<StorageDevice> slave_device(); RefPtr<StorageDevice> slave_device() const;
virtual const char* purpose() const override { return "PATA Channel"; } virtual const char* purpose() const override { return "PATA Channel"; }

View file

@ -47,6 +47,16 @@ bool IDEController::shutdown()
TODO(); TODO();
} }
size_t IDEController::devices_count() const
{
size_t count = 0;
for (u32 index = 0; index < 4; index++) {
if (!device(index).is_null())
count++;
}
return count;
}
void IDEController::start_request(const StorageDevice&, AsyncBlockDeviceRequest&) void IDEController::start_request(const StorageDevice&, AsyncBlockDeviceRequest&)
{ {
ASSERT_NOT_REACHED(); ASSERT_NOT_REACHED();
@ -85,7 +95,7 @@ void IDEController::initialize(bool force_pio)
m_channels.append(IDEChannel::create(*this, { base_io, control_io, bus_master_base.offset(8) }, IDEChannel::ChannelType::Secondary, force_pio)); m_channels.append(IDEChannel::create(*this, { base_io, control_io, bus_master_base.offset(8) }, IDEChannel::ChannelType::Secondary, force_pio));
} }
RefPtr<StorageDevice> IDEController::device(u32 index) RefPtr<StorageDevice> IDEController::device(u32 index) const
{ {
switch (index) { switch (index) {
case 0: case 0:

View file

@ -45,9 +45,10 @@ public:
virtual ~IDEController() override; virtual ~IDEController() override;
virtual Type type() const override { return Type::IDE; } virtual Type type() const override { return Type::IDE; }
virtual RefPtr<StorageDevice> device(u32 index) override; virtual RefPtr<StorageDevice> device(u32 index) const override;
virtual bool reset() override; virtual bool reset() override;
virtual bool shutdown() override; virtual bool shutdown() override;
virtual size_t devices_count() const override;
virtual void start_request(const StorageDevice&, AsyncBlockDeviceRequest&) override; virtual void start_request(const StorageDevice&, AsyncBlockDeviceRequest&) override;
virtual void complete_current_request(AsyncDeviceRequest::RequestResult) override; virtual void complete_current_request(AsyncDeviceRequest::RequestResult) override;

View file

@ -51,7 +51,8 @@ public:
NVMe NVMe
}; };
virtual Type type() const = 0; virtual Type type() const = 0;
virtual RefPtr<StorageDevice> device(u32 index) = 0; virtual RefPtr<StorageDevice> device(u32 index) const = 0;
virtual size_t devices_count() const = 0;
protected: protected:
explicit StorageController(PCI::Address address) explicit StorageController(PCI::Address address)