1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-28 21:05:09 +00:00
serenity/Kernel/Storage/ATA/GenericIDE/ISAController.cpp
Liav A 0810c1b972 Kernel/Storage: Introduce basic abstraction layer for ATA components
This abstraction layer is mainly for ATA ports (AHCI ports, IDE ports).
The goal is to create a convenient and flexible framework so it's
possible to expand to support other types of controller (e.g. Intel PIIX
and ICH IDE controllers) and to abstract operations that are possible on
each component.

Currently only the ATA IDE code is affected by this, making it much
cleaner and readable - the ATA bus mastering code is moved to the
ATAPort code so more implementations in the near future can take
advantage of such functionality easily.

In addition to that, the hierarchy of the ATA IDE code resembles more of
the SATA AHCI code now, which means the IDEChannel class is solely
responsible for getting interrupts, passing them for further processing
in the ATAPort code to take care of the rest of the handling logic.
2022-07-19 11:07:34 +01:00

59 lines
1.8 KiB
C++

/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/OwnPtr.h>
#include <AK/RefPtr.h>
#include <AK/Types.h>
#include <Kernel/Bus/PCI/API.h>
#include <Kernel/FileSystem/ProcFS.h>
#include <Kernel/Sections.h>
#include <Kernel/Storage/ATA/ATADiskDevice.h>
#include <Kernel/Storage/ATA/GenericIDE/Channel.h>
#include <Kernel/Storage/ATA/GenericIDE/ISAController.h>
namespace Kernel {
UNMAP_AFTER_INIT NonnullRefPtr<ISAIDEController> ISAIDEController::initialize()
{
return adopt_ref(*new ISAIDEController());
}
UNMAP_AFTER_INIT ISAIDEController::ISAIDEController()
{
initialize_channels();
}
UNMAP_AFTER_INIT void ISAIDEController::initialize_channels()
{
auto primary_base_io = IOAddress(0x1F0);
auto primary_control_io = IOAddress(0x3F6);
auto secondary_base_io = IOAddress(0x170);
auto secondary_control_io = IOAddress(0x376);
auto initialize_and_enumerate = [](IDEChannel& channel) -> void {
{
auto result = channel.allocate_resources_for_isa_ide_controller({});
// FIXME: Propagate errors properly
VERIFY(!result.is_error());
}
{
auto result = channel.detect_connected_devices();
// FIXME: Propagate errors properly
VERIFY(!result.is_error());
}
};
m_channels.append(IDEChannel::create(*this, { primary_base_io, primary_control_io }, IDEChannel::ChannelType::Primary));
initialize_and_enumerate(m_channels[0]);
m_channels[0].enable_irq();
m_channels.append(IDEChannel::create(*this, { secondary_base_io, secondary_control_io }, IDEChannel::ChannelType::Secondary));
initialize_and_enumerate(m_channels[1]);
m_channels[1].enable_irq();
dbgln("ISA IDE controller detected and initialized");
}
}