NeKernel dev
Loading...
Searching...
No Matches
AHCI+Generic.cc File Reference

AHCI Generic driver. More...

Namespaces

namespace  Kernel
 UPS inline definitions.
namespace  Kernel::Detail
 Implementation details namespace.

Macros

#define kSATAErrTaskFile   (1 << 30)
#define kSATAPxCmdST   (0x0001)
#define kSATAPxCmdFre   (0x0010)
#define kSATAPxCmdFR   (0x4000)
#define kSATAPxCmdCR   (0x8000)
#define kSATALBAMode   (1 << 6)
#define kSATASRBsy   (0x80)
#define kSATASRDrq   (0x08)
#define kSATABohcBiosOwned   (1 << 0)
#define kSATABohcOSOwned   (1 << 1)
#define kSATAPortCnt   (0x20)
#define kSATASig   (0x00000101)
#define kSATAPISig   (0xEB140101)
#define kSATAProgIfAHCI   (0x01)
#define kSATASubClass   (0x06)
#define kSATABar5   (0x24)

Functions

STATIC ALIGN (kib_cast(4)) UInt8 kIdentifyData[kAHCISectorSize]
template<BOOL Write, BOOL CommandOrCTRL, BOOL Identify>
STATIC Void drv_std_input_output_ahci (UInt64 lba, UInt8 *buffer, SizeT sector_sz, SizeT size_buffer)
 Send an AHCI command, according to the template parameters.
STATIC Int32 drv_find_cmd_slot_ahci (HbaPort *port)
 Finds a command slot for a HBA port.
STATIC Void drv_compute_disk_ahci ()
 Identify device and read LBA info, Disk OEM vendor.
STATIC SizeT drv_get_size_ahci ()
STATIC SizeT drv_get_sector_count_ahci ()
STATIC ATTRIBUTE (unused) SizeT drv_get_size_ahci()
 Get the drive size.
STATIC BOOL ahci_enable_and_probe ()
 Enable Host and probe using the IDENTIFY command.
STATIC Bool drv_init_command_structures_ahci ()
STATIC Bool drv_std_init_ahci (UInt16 &pi, BOOL &atapi)
 Initializes an AHCI disk.
Bool drv_std_detected_ahci ()
 Checks if an AHCI device is detected.
UInt16 Kernel::sk_init_ahci_device (BOOL atapi)
 Initialize an AHCI device (StorageKit).
STATIC Void Kernel::Detail::sk_io_read_ahci (DeviceInterface< IMountpoint * > *self, IMountpoint *mnt)
 Read AHCI device.
STATIC Void Kernel::Detail::sk_io_write_ahci (DeviceInterface< IMountpoint * > *self, IMountpoint *mnt)
 Write AHCI device.
ErrorOr< AHCIDeviceInterface > Kernel::sk_acquire_ahci_device (UInt32 drv_index)
 Acquires a new AHCI device with drv_index in mind.

Variables

STATIC PCI::Device kSATADev
STATIC HbaMemRef kSATAHba
STATIC Lba kSATASectorCount = 0UL
STATIC UInt16 kSATAIndex = 0U
STATIC Char kCurrentDiskModel [50] = {"GENERIC SATA"}
STATIC UInt16 kSATAPortsImplemented = 0U

Detailed Description

AHCI Generic driver.

Author
Amlal El Mahrouss (amlal.nosp@m.@nek.nosp@m.ernel.nosp@m..org)
Version
0.1
Date
2024-02-02

Macro Definition Documentation

◆ kSATABar5

#define kSATABar5   (0x24)

◆ kSATABohcBiosOwned

#define kSATABohcBiosOwned   (1 << 0)

◆ kSATABohcOSOwned

#define kSATABohcOSOwned   (1 << 1)

◆ kSATAErrTaskFile

#define kSATAErrTaskFile   (1 << 30)

◆ kSATALBAMode

#define kSATALBAMode   (1 << 6)

◆ kSATAPISig

#define kSATAPISig   (0xEB140101)

◆ kSATAPortCnt

#define kSATAPortCnt   (0x20)

◆ kSATAProgIfAHCI

#define kSATAProgIfAHCI   (0x01)

◆ kSATAPxCmdCR

#define kSATAPxCmdCR   (0x8000)

◆ kSATAPxCmdFR

#define kSATAPxCmdFR   (0x4000)

◆ kSATAPxCmdFre

#define kSATAPxCmdFre   (0x0010)

◆ kSATAPxCmdST

#define kSATAPxCmdST   (0x0001)

◆ kSATASig

#define kSATASig   (0x00000101)

◆ kSATASRBsy

#define kSATASRBsy   (0x80)

◆ kSATASRDrq

#define kSATASRDrq   (0x08)

◆ kSATASubClass

#define kSATASubClass   (0x06)

Function Documentation

◆ ahci_enable_and_probe()

STATIC BOOL ahci_enable_and_probe ( )

Enable Host and probe using the IDENTIFY command.

◆ ALIGN()

STATIC ALIGN ( kib_cast(4) )

◆ ATTRIBUTE()

STATIC ATTRIBUTE ( unused )

Get the drive size.

!

Returns
Disk size in bytes.

◆ drv_compute_disk_ahci()

STATIC Void drv_compute_disk_ahci ( )

Identify device and read LBA info, Disk OEM vendor.

Extract 48-bit LBA.

◆ drv_find_cmd_slot_ahci()

STATIC Int32 drv_find_cmd_slot_ahci ( HbaPort * port)

Finds a command slot for a HBA port.

Parameters
portThe port to search on.
Returns
The slot, or -1.

◆ drv_get_sector_count_ahci()

STATIC SizeT drv_get_sector_count_ahci ( )

◆ drv_get_size_ahci()

STATIC SizeT drv_get_size_ahci ( )

◆ drv_init_command_structures_ahci()

STATIC Bool drv_init_command_structures_ahci ( )

◆ drv_std_detected_ahci()

Bool drv_std_detected_ahci ( )

Checks if an AHCI device is detected.

Returns
Either if detected, or not found.

◆ drv_std_init_ahci()

STATIC Bool drv_std_init_ahci ( UInt16 & pi,
BOOL & atapi )

Initializes an AHCI disk.

Parameters
pithe amount of ports that have been detected.
atapireference value, tells whether we should detect ATAPI instead of SATA.
Returns
if the disk was successfully initialized or not.

AMLALE: TODO: Iterator is good enough, but we need to expand it.

◆ drv_std_input_output_ahci()

template<BOOL Write, BOOL CommandOrCTRL, BOOL Identify>
STATIC Void drv_std_input_output_ahci ( UInt64 lba,
UInt8 * buffer,
SizeT sector_sz,
SizeT size_buffer )

Send an AHCI command, according to the template parameters.

Parameters
lbaLogical Block Address to look for.
bufferThe data buffer to transfer.
sector_szThe disk's sector size (unused)
size_bufferThe size of the buffer parameter.

Variable Documentation

◆ kCurrentDiskModel

STATIC Char kCurrentDiskModel[50] = {"GENERIC SATA"}

◆ kSATADev

STATIC PCI::Device kSATADev

◆ kSATAHba

STATIC HbaMemRef kSATAHba

◆ kSATAIndex

STATIC UInt16 kSATAIndex = 0U

◆ kSATAPortsImplemented

STATIC UInt16 kSATAPortsImplemented = 0U

◆ kSATASectorCount

STATIC Lba kSATASectorCount = 0UL