summaryrefslogtreecommitdiff
path: root/Kernel/Storage/BMIDEChannel.h
blob: c72e0a3da5691a88bb9717cf156db767276409fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
 * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include <AK/OwnPtr.h>
#include <Kernel/Storage/IDEChannel.h>

namespace Kernel {

class AsyncBlockDeviceRequest;

struct [[gnu::packed]] PhysicalRegionDescriptor {
    u32 offset;
    u16 size { 0 };
    u16 end_of_table { 0 };
};

class IDEController;
class BMIDEChannel final : public IDEChannel {
    friend class IDEController;
    friend class PATADiskDevice;

public:
    static NonnullRefPtr<BMIDEChannel> create(const IDEController&, IDEChannel::IOAddressGroup, IDEChannel::ChannelType type);
    static NonnullRefPtr<BMIDEChannel> create(const IDEController&, u8 irq, IDEChannel::IOAddressGroup, IDEChannel::ChannelType type);
    virtual ~BMIDEChannel() override {};

    virtual bool is_dma_enabled() const override { return true; };

private:
    BMIDEChannel(const IDEController&, IDEChannel::IOAddressGroup, IDEChannel::ChannelType type);
    BMIDEChannel(const IDEController&, u8 irq, IDEChannel::IOAddressGroup, IDEChannel::ChannelType type);
    void initialize();

    void complete_current_request(AsyncDeviceRequest::RequestResult);

    //^ IRQHandler
    virtual bool handle_irq(const RegisterState&) override;

    //* IDEChannel
    virtual void send_ata_io_command(LBAMode lba_mode, Direction direction) const override;
    virtual void ata_read_sectors(bool, u16) override;
    virtual void ata_write_sectors(bool, u16) override;

    PhysicalRegionDescriptor& prdt() { return *reinterpret_cast<PhysicalRegionDescriptor*>(m_prdt_region->vaddr().as_ptr()); }
    OwnPtr<Memory::Region> m_prdt_region;
    OwnPtr<Memory::Region> m_dma_buffer_region;
    RefPtr<Memory::PhysicalPage> m_prdt_page;
    RefPtr<Memory::PhysicalPage> m_dma_buffer_page;
};
}