2018-10-16 14:17:43 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2018-11-10 15:15:31 +01:00
|
|
|
#include <AK/Lock.h>
|
2018-10-16 14:17:43 +02:00
|
|
|
#include <AK/RetainPtr.h>
|
2019-01-23 05:13:17 +01:00
|
|
|
#include <Kernel/DiskDevice.h>
|
2018-11-10 15:15:31 +01:00
|
|
|
#include "IRQHandler.h"
|
2018-10-16 14:17:43 +02:00
|
|
|
|
2018-11-10 15:15:31 +01:00
|
|
|
class IDEDiskDevice final : public IRQHandler, public DiskDevice {
|
2018-10-16 14:17:43 +02:00
|
|
|
public:
|
2019-02-25 12:43:52 +01:00
|
|
|
static Retained<IDEDiskDevice> create();
|
2018-11-10 15:15:31 +01:00
|
|
|
virtual ~IDEDiskDevice() override;
|
2018-10-16 14:17:43 +02:00
|
|
|
|
2018-11-10 15:15:31 +01:00
|
|
|
// ^DiskDevice
|
2018-12-03 01:38:22 +01: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;
|
2018-10-16 14:17:43 +02:00
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
IDEDiskDevice();
|
|
|
|
|
|
|
|
|
|
private:
|
2018-11-10 15:15:31 +01:00
|
|
|
// ^IRQHandler
|
2018-12-03 00:39:25 +01:00
|
|
|
virtual void handle_irq() override;
|
2018-11-10 15:15:31 +01:00
|
|
|
|
|
|
|
|
// ^DiskDevice
|
2018-11-15 15:36:35 +01:00
|
|
|
virtual const char* class_name() const override;
|
2018-11-10 15:15:31 +01:00
|
|
|
|
|
|
|
|
struct CHS {
|
|
|
|
|
dword cylinder;
|
|
|
|
|
word head;
|
|
|
|
|
word sector;
|
|
|
|
|
};
|
|
|
|
|
CHS lba_to_chs(dword) const;
|
|
|
|
|
|
|
|
|
|
void initialize();
|
|
|
|
|
bool wait_for_irq();
|
2018-11-18 14:57:41 +01:00
|
|
|
bool read_sectors(dword start_sector, word count, byte* buffer);
|
|
|
|
|
bool write_sectors(dword start_sector, word count, const byte* data);
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2019-01-17 16:25:02 +01:00
|
|
|
Lock m_lock;
|
2018-11-10 15:15:31 +01:00
|
|
|
word m_cylinders { 0 };
|
|
|
|
|
word m_heads { 0 };
|
|
|
|
|
word m_sectors_per_track { 0 };
|
2019-02-11 11:38:14 +01:00
|
|
|
volatile bool m_interrupted { false };
|
|
|
|
|
volatile byte m_device_error { 0 };
|
2018-11-10 15:15:31 +01:00
|
|
|
|
2018-10-16 14:17:43 +02:00
|
|
|
};
|
|
|
|
|
|