1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:47:35 +00:00

Kernel: Change the indexing of storage devices in IDEController class

Previously, the indexing scheme was that 0 is Primary-Master, 1 is
Primary-Slave, 2 is Secondary-Master, 3 is Secondary-Slave.

Instead of merely matching between numbers to the channel & position,
the IDEController code will try to find all available drives connected to
the two channels, then it will create a Vector with nonnull RefPtr to
them. Then we take use the given index with this Vector.
This commit is contained in:
Liav A 2020-12-19 15:19:01 +02:00 committed by Andreas Kling
parent 6a691306b5
commit 78ae4b0530
2 changed files with 17 additions and 2 deletions

View file

@ -95,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));
}
RefPtr<StorageDevice> IDEController::device(u32 index) const
RefPtr<StorageDevice> IDEController::device_by_channel_and_position(u32 index) const
{
switch (index) {
case 0:
@ -107,7 +107,21 @@ RefPtr<StorageDevice> IDEController::device(u32 index) const
case 3:
return m_channels[1].slave_device();
}
return nullptr;
ASSERT_NOT_REACHED();
}
RefPtr<StorageDevice> IDEController::device(u32 index) const
{
NonnullRefPtrVector<StorageDevice> connected_devices;
for (size_t index = 0; index < 4; index++) {
auto checked_device = device_by_channel_and_position(index);
if (checked_device.is_null())
continue;
connected_devices.append(checked_device.release_nonnull());
}
if (index >= connected_devices.size())
return nullptr;
return connected_devices[index];
}
}