73 lines
1.5 KiB
C
73 lines
1.5 KiB
C
|
#pragma once
|
||
|
#include "arch/PCI.h"
|
||
|
#include "fs/devices/DeviceRegistry.h"
|
||
|
#include <luna/Atomic.h>
|
||
|
#include <luna/SharedPtr.h>
|
||
|
|
||
|
namespace ATA
|
||
|
{
|
||
|
class Controller;
|
||
|
class Channel
|
||
|
{
|
||
|
public:
|
||
|
Channel(Controller* controller, u8 channel_index, Badge<Controller>);
|
||
|
|
||
|
bool initialize();
|
||
|
|
||
|
private:
|
||
|
Controller* m_controller;
|
||
|
u8 m_channel_index;
|
||
|
bool m_is_pci_native_mode;
|
||
|
|
||
|
u32 m_base_address;
|
||
|
u32 m_control_port_base_address;
|
||
|
};
|
||
|
|
||
|
class Controller
|
||
|
{
|
||
|
public:
|
||
|
static Result<void> scan();
|
||
|
|
||
|
const PCI::Device& device() const
|
||
|
{
|
||
|
return m_device;
|
||
|
}
|
||
|
|
||
|
bool initialize();
|
||
|
|
||
|
private:
|
||
|
Controller(const PCI::Device& device);
|
||
|
PCI::Device m_device;
|
||
|
Channel m_primary_channel;
|
||
|
Channel m_secondary_channel;
|
||
|
|
||
|
Atomic<int> m_hwlock = 0;
|
||
|
};
|
||
|
|
||
|
}
|
||
|
|
||
|
class ATADevice : public Device
|
||
|
{
|
||
|
public:
|
||
|
// Initializer for DeviceRegistry.
|
||
|
static Result<void> create(SharedPtr<ATA::Controller> controller, int channel, int drive);
|
||
|
|
||
|
Result<usize> read(u8*, usize, usize) const override;
|
||
|
|
||
|
Result<usize> write(const u8*, usize, usize) override;
|
||
|
|
||
|
bool blocking() const override;
|
||
|
|
||
|
Result<u64> ioctl(int request, void* arg) override;
|
||
|
|
||
|
usize size() const override;
|
||
|
|
||
|
virtual ~ATADevice() = default;
|
||
|
|
||
|
private:
|
||
|
ATADevice(SharedPtr<ATA::Controller> controller);
|
||
|
SharedPtr<ATA::Controller> m_controller;
|
||
|
int m_channel;
|
||
|
int m_drive;
|
||
|
};
|