2021-02-26 06:25:45 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-02-26 06:25:45 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/RefPtr.h>
|
|
|
|
#include <Kernel/Devices/Device.h>
|
|
|
|
#include <Kernel/IO.h>
|
|
|
|
#include <Kernel/Interrupts/IRQHandler.h>
|
2021-07-18 09:10:27 +02:00
|
|
|
#include <Kernel/Locking/Mutex.h>
|
2021-08-06 10:45:34 +02:00
|
|
|
#include <Kernel/Memory/PhysicalPage.h>
|
2021-02-26 06:25:45 +02:00
|
|
|
#include <Kernel/PhysicalAddress.h>
|
|
|
|
#include <Kernel/Random.h>
|
2021-06-22 17:40:16 +02:00
|
|
|
#include <Kernel/Sections.h>
|
2021-02-26 06:25:45 +02:00
|
|
|
#include <Kernel/Storage/AHCIController.h>
|
|
|
|
#include <Kernel/Storage/AHCIPort.h>
|
|
|
|
#include <Kernel/Storage/StorageDevice.h>
|
|
|
|
#include <Kernel/WaitQueue.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
class AsyncBlockDeviceRequest;
|
|
|
|
|
|
|
|
class AHCIController;
|
|
|
|
class AHCIPort;
|
|
|
|
class AHCIPortHandler final : public RefCounted<AHCIPortHandler>
|
|
|
|
, public IRQHandler {
|
|
|
|
friend class AHCIController;
|
|
|
|
friend class SATADiskDevice;
|
|
|
|
|
|
|
|
public:
|
|
|
|
UNMAP_AFTER_INIT static NonnullRefPtr<AHCIPortHandler> create(AHCIController&, u8 irq, AHCI::MaskedBitField taken_ports);
|
|
|
|
virtual ~AHCIPortHandler() override;
|
|
|
|
|
|
|
|
RefPtr<StorageDevice> device_at_port(size_t port_index) const;
|
2021-07-11 01:46:09 +02:00
|
|
|
virtual StringView purpose() const override { return "SATA Port Handler"; }
|
2021-02-26 06:25:45 +02:00
|
|
|
|
|
|
|
AHCI::HBADefinedCapabilities hba_capabilities() const;
|
|
|
|
NonnullRefPtr<AHCIController> hba_controller() const { return m_parent_controller; }
|
|
|
|
PhysicalAddress get_identify_metadata_physical_region(u32 port_index) const;
|
|
|
|
|
|
|
|
bool is_responsible_for_port_index(u32 port_index) const { return m_taken_ports.is_set_at(port_index); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
UNMAP_AFTER_INIT AHCIPortHandler(AHCIController&, u8 irq, AHCI::MaskedBitField taken_ports);
|
|
|
|
|
|
|
|
//^ IRQHandler
|
2021-06-05 09:00:18 +03:00
|
|
|
virtual bool handle_irq(const RegisterState&) override;
|
2021-02-26 06:25:45 +02:00
|
|
|
|
|
|
|
enum class Direction : u8 {
|
|
|
|
Read,
|
|
|
|
Write,
|
|
|
|
};
|
|
|
|
|
|
|
|
AHCI::MaskedBitField create_pending_ports_interrupts_bitfield() const;
|
|
|
|
|
|
|
|
void start_request(AsyncBlockDeviceRequest&, bool, bool, u16);
|
|
|
|
void complete_current_request(AsyncDeviceRequest::RequestResult);
|
|
|
|
|
|
|
|
void enumerate_ports(Function<void(const AHCIPort&)> callback) const;
|
|
|
|
RefPtr<AHCIPort> port_at_index(u32 port_index) const;
|
|
|
|
|
|
|
|
// Data members
|
|
|
|
HashMap<u32, NonnullRefPtr<AHCIPort>> m_handled_ports;
|
|
|
|
NonnullRefPtr<AHCIController> m_parent_controller;
|
2021-08-06 13:49:36 +02:00
|
|
|
NonnullRefPtrVector<Memory::PhysicalPage> m_identify_metadata_pages;
|
2021-02-26 06:25:45 +02:00
|
|
|
AHCI::MaskedBitField m_taken_ports;
|
|
|
|
AHCI::MaskedBitField m_pending_ports_interrupts;
|
|
|
|
};
|
|
|
|
}
|