diff options
author | Liav A <liavalb@gmail.com> | 2021-11-19 11:52:07 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-07-19 11:07:34 +0100 |
commit | c001e3f567bb9ceae8b49476ee72a7e5a4b9f37a (patch) | |
tree | 08a30ce8838f76b65a209088cb5ecc3d385b5ab3 /Kernel/Storage/ATA/GenericIDE/Controller.cpp | |
parent | a70e1a0340e683f4e835a47dff843392e5028a4b (diff) | |
download | serenity-c001e3f567bb9ceae8b49476ee72a7e5a4b9f37a.zip |
Kernel/Storage: Move AHCI and IDE code into new subdirectories
We do that to increase clarity of the major and secondary components in
the subsystem. To ensure it's even more understandable, we rename the
files to better represent the class within them and to remove redundancy
in the name.
Also, some includes are removed from the general components of the ATA
components' classes.
Diffstat (limited to 'Kernel/Storage/ATA/GenericIDE/Controller.cpp')
-rw-r--r-- | Kernel/Storage/ATA/GenericIDE/Controller.cpp | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/Kernel/Storage/ATA/GenericIDE/Controller.cpp b/Kernel/Storage/ATA/GenericIDE/Controller.cpp new file mode 100644 index 0000000000..9ad7b9f66f --- /dev/null +++ b/Kernel/Storage/ATA/GenericIDE/Controller.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2020-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/BusMasterChannel.h> +#include <Kernel/Storage/ATA/GenericIDE/Controller.h> + +namespace Kernel { + +UNMAP_AFTER_INIT NonnullRefPtr<IDEController> IDEController::initialize() +{ + return adopt_ref(*new IDEController()); +} + +bool IDEController::reset() +{ + TODO(); +} + +bool IDEController::shutdown() +{ + 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(ATADevice const& device, AsyncBlockDeviceRequest& request) +{ + auto& address = device.ata_address(); + VERIFY(address.subport < 2); + switch (address.port) { + case 0: + m_channels[0].start_request(request, address.subport == 0 ? false : true, device.ata_capabilites()); + return; + case 1: + m_channels[1].start_request(request, address.subport == 0 ? false : true, device.ata_capabilites()); + return; + } + VERIFY_NOT_REACHED(); +} + +void IDEController::complete_current_request(AsyncDeviceRequest::RequestResult) +{ + VERIFY_NOT_REACHED(); +} + +UNMAP_AFTER_INIT IDEController::IDEController() +{ +} + +UNMAP_AFTER_INIT IDEController::~IDEController() = default; + +RefPtr<StorageDevice> IDEController::device_by_channel_and_position(u32 index) const +{ + switch (index) { + case 0: + return m_channels[0].master_device(); + case 1: + return m_channels[0].slave_device(); + case 2: + return m_channels[1].master_device(); + case 3: + return m_channels[1].slave_device(); + } + VERIFY_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]; +} +} |