2018-10-16 15:17:43 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-03-16 15:18:22 +03:00
|
|
|
#include <Kernel/Lock.h>
|
2018-10-16 15:17:43 +03:00
|
|
|
#include <AK/RetainPtr.h>
|
2019-04-03 13:36:40 +03:00
|
|
|
#include <Kernel/Devices/DiskDevice.h>
|
2019-05-19 04:46:50 +03:00
|
|
|
#include <Kernel/IRQHandler.h>
|
|
|
|
#include <Kernel/PCI.h>
|
|
|
|
#include <Kernel/PhysicalAddress.h>
|
|
|
|
#include <Kernel/VM/PhysicalPage.h>
|
|
|
|
|
|
|
|
struct PhysicalRegionDescriptor {
|
|
|
|
PhysicalAddress offset;
|
|
|
|
word size { 0 };
|
|
|
|
word end_of_table { 0 };
|
|
|
|
};
|
2018-10-16 15:17:43 +03:00
|
|
|
|
2018-11-10 17:15:31 +03:00
|
|
|
class IDEDiskDevice final : public IRQHandler, public DiskDevice {
|
2019-05-19 04:46:50 +03:00
|
|
|
AK_MAKE_ETERNAL
|
2018-10-16 15:17:43 +03:00
|
|
|
public:
|
2019-02-25 14:43:52 +03:00
|
|
|
static Retained<IDEDiskDevice> create();
|
2018-11-10 17:15:31 +03:00
|
|
|
virtual ~IDEDiskDevice() override;
|
2018-10-16 15:17:43 +03:00
|
|
|
|
2018-11-10 17:15:31 +03:00
|
|
|
// ^DiskDevice
|
2018-12-03 03:38:22 +03:00
|
|
|
virtual unsigned block_size() const override;
|
|
|
|
virtual bool read_block(unsigned index, byte*) const override;
|
|
|
|
virtual bool write_block(unsigned index, const byte*) override;
|
2019-05-19 05:40:30 +03:00
|
|
|
virtual bool read_blocks(unsigned index, word count, byte*) override;
|
2019-05-24 05:17:15 +03:00
|
|
|
virtual bool write_blocks(unsigned index, word count, const byte*) override;
|
2018-10-16 15:17:43 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
IDEDiskDevice();
|
|
|
|
|
|
|
|
private:
|
2018-11-10 17:15:31 +03:00
|
|
|
// ^IRQHandler
|
2018-12-03 02:39:25 +03:00
|
|
|
virtual void handle_irq() override;
|
2018-11-10 17:15:31 +03:00
|
|
|
|
|
|
|
// ^DiskDevice
|
2018-11-15 17:36:35 +03:00
|
|
|
virtual const char* class_name() const override;
|
2018-11-10 17:15:31 +03:00
|
|
|
|
|
|
|
void initialize();
|
|
|
|
bool wait_for_irq();
|
2019-05-26 15:58:21 +03:00
|
|
|
bool read_sectors_with_dma(dword lba, word count, byte*);
|
|
|
|
bool write_sectors_with_dma(dword lba, word count, const byte*);
|
|
|
|
bool read_sectors(dword lba, word count, byte* buffer);
|
|
|
|
bool write_sectors(dword lba, word count, const byte* data);
|
2018-11-10 17:15:31 +03:00
|
|
|
|
2019-05-02 04:28:20 +03:00
|
|
|
Lock m_lock { "IDEDiskDevice" };
|
2018-11-10 17:15:31 +03:00
|
|
|
word m_cylinders { 0 };
|
|
|
|
word m_heads { 0 };
|
|
|
|
word m_sectors_per_track { 0 };
|
2019-05-24 05:17:15 +03:00
|
|
|
word m_io_base { 0 };
|
2019-02-11 13:38:14 +03:00
|
|
|
volatile bool m_interrupted { false };
|
|
|
|
volatile byte m_device_error { 0 };
|
2018-11-10 17:15:31 +03:00
|
|
|
|
2019-05-19 04:46:50 +03:00
|
|
|
PCI::Address m_pci_address;
|
|
|
|
PhysicalRegionDescriptor m_prdt;
|
2019-05-19 05:40:30 +03:00
|
|
|
RetainPtr<PhysicalPage> m_dma_buffer_page;
|
2019-05-19 04:46:50 +03:00
|
|
|
word m_bus_master_base { 0 };
|
2019-05-19 16:54:33 +03:00
|
|
|
Lockable<bool> m_dma_enabled;
|
2018-10-16 15:17:43 +03:00
|
|
|
};
|
|
|
|
|