1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 13:48:12 +00:00
serenity/Kernel/Devices/IDEDiskDevice.h
Jesse ab90d2e251 Kernel: Extended IDE interface to allow slave device usage (#283)
The IDE Disk Controller driver has been extended to allow the secondary device on the channel to be initialised and used. A test as to whether this is working (for anyone interested) is to modify `init.cpp:87` to `auto dev_hd0 = IDEDiskDevice::create(IdeDiskDevice::DeviceType::SLAVE);`. The kernel will fail to boot, as there is no disk attached to CHANNEL 1's slave. This was born out of the fact that my FAT driver can't be tested as easily without creating a partition on `hda`.
2019-07-08 08:16:52 +02:00

75 lines
2.1 KiB
C++

#pragma once
#include <AK/RefPtr.h>
#include <Kernel/Devices/DiskDevice.h>
#include <Kernel/IRQHandler.h>
#include <Kernel/Lock.h>
#include <Kernel/PCI.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/VM/PhysicalPage.h>
struct PhysicalRegionDescriptor {
PhysicalAddress offset;
u16 size { 0 };
u16 end_of_table { 0 };
};
class IDEDiskDevice final : public IRQHandler
, public DiskDevice {
AK_MAKE_ETERNAL
public:
// Type of drive this IDEDiskDevice is on the ATA channel.
//
// Each PATA channel can contain only two devices, which (I think) are
// jumper selectable on the drive itself by shorting two pins.
enum class DriveType : u8 {
MASTER,
SLAVE
};
public:
static NonnullRefPtr<IDEDiskDevice> create(DriveType type);
virtual ~IDEDiskDevice() override;
// ^DiskDevice
virtual unsigned block_size() const override;
virtual bool read_block(unsigned index, u8*) const override;
virtual bool write_block(unsigned index, const u8*) override;
virtual bool read_blocks(unsigned index, u16 count, u8*) override;
virtual bool write_blocks(unsigned index, u16 count, const u8*) override;
protected:
explicit IDEDiskDevice(DriveType);
private:
// ^IRQHandler
virtual void handle_irq() override;
// ^DiskDevice
virtual const char* class_name() const override;
void initialize();
bool wait_for_irq();
bool read_sectors_with_dma(u32 lba, u16 count, u8*);
bool write_sectors_with_dma(u32 lba, u16 count, const u8*);
bool read_sectors(u32 lba, u16 count, u8* buffer);
bool write_sectors(u32 lba, u16 count, const u8* data);
bool is_slave() const;
Lock m_lock { "IDEDiskDevice" };
u16 m_cylinders { 0 };
u16 m_heads { 0 };
u16 m_sectors_per_track { 0 };
u16 m_io_base { 0 };
volatile bool m_interrupted { false };
volatile u8 m_device_error { 0 };
DriveType m_drive_type { DriveType::MASTER };
PCI::Address m_pci_address;
PhysicalRegionDescriptor m_prdt;
RefPtr<PhysicalPage> m_dma_buffer_page;
u16 m_bus_master_base { 0 };
Lockable<bool> m_dma_enabled;
};