My Project
Loading...
Searching...
No Matches
ahci.h File Reference
#include <stdint.h>
#include <stdbool.h>
#include <stddef.h>
#include "../blk/block.h"
#include "../../mtstatus.h"

Go to the source code of this file.

Data Structures

struct  _HBA_MEM
 AHCI Register layout (Global HBA Registers) More...
struct  _HBA_PORT
 Per port registers at HBA_MEM + 0x100 + (port * 0x80) More...
struct  _FIS_REG_H2D
 Register - Host to Device FIS (FIS_TYPE_REG_H2D) More...
struct  _HBA_PRDT_ENTRY
 Physical Region Descriptor Table Entry. More...
struct  _HBA_CMD_TBL
 Command Table: one per slot. More...
struct  _HBA_CMD_HEADER
 HBA Command Header (defines an AHCI Command) More...

Macros

#define AHCI_MAX_PORTS   32
#define HBA_CMD_HDR_CFL_MASK   0x0000001Fu
#define HBA_CMD_HDR_A_BIT   (1u << 5)
#define HBA_CMD_HDR_W_BIT   (1u << 6)
#define HBA_CMD_HDR_P_BIT   (1u << 7)
#define HBA_CMD_HDR_PRDTL_MASK   0xFFFF0000u
#define ATA_DEV_BSY   0x80
#define ATA_DEV_DRQ   0x08
#define ATA_DEV_ERR   0x01
#define ATA_CMD_READ_DMA_EX   0x25
#define ATA_CMD_WRITE_DMA_EX   0x35
#define AHCI_DEV_NULL   0
#define AHCI_DEV_SATA   1
#define AHCI_DEV_SEMB   2
#define AHCI_DEV_PM   3
#define AHCI_DEV_SATAPI   4
#define HBA_PORT_IPM_ACTIVE   1
#define HBA_PORT_DET_PRESENT   3
#define HBA_PxCMD_ST   0x0001
#define HBA_PxCMD_FRE   0x0010
#define HBA_PxCMD_FR   0x4000
#define HBA_PxCMD_CR   0x8000
#define HBA_PxIS_TFES   (1 << 30) /* TFES - Task File Error Status */

Typedefs

typedef enum _FIS_TYPE FIS_TYPE
typedef volatile struct _HBA_MEM HBA_MEM
 AHCI Register layout (Global HBA Registers)
typedef volatile struct _HBA_PORT HBA_PORT
 Per port registers at HBA_MEM + 0x100 + (port * 0x80)
typedef struct _FIS_REG_H2D FIS_REG_H2D
 Register - Host to Device FIS (FIS_TYPE_REG_H2D)
typedef struct _HBA_PRDT_ENTRY HBA_PRDT_ENTRY
 Physical Region Descriptor Table Entry.
typedef struct _HBA_CMD_TBL HBA_CMD_TBL
 Command Table: one per slot.
typedef struct _HBA_CMD_HEADER HBA_CMD_HEADER
 HBA Command Header (defines an AHCI Command)

Enumerations

enum  _FIS_TYPE {
  FIS_TYPE_REG_H2D = 0x27 , FIS_TYPE_REG_D2H = 0x34 , FIS_TYPE_DMA_ACT = 0x39 , FIS_TYPE_DMA_SETUP = 0x41 ,
  FIS_TYPE_DATA = 0x46 , FIS_TYPE_BIST = 0x58 , FIS_TYPE_PIO_SETUP = 0x5F , FIS_TYPE_DEV_BITS = 0xA1
}

Functions

MTSTATUS ahci_init (void)
 #define AHCI_DEBUG_PRINT
MTSTATUS ahci_read_sector (BLOCK_DEVICE *dev, uint32_t lba, void *buf, size_t bytes)
 Read a single bytes-byte sector from the given LBA on a specific BLOCK_DEVICE.
MTSTATUS ahci_write_sector (BLOCK_DEVICE *dev, uint32_t lba, const void *buf, size_t bytes)
 Write a single bytes-byte sector to given LBA on a specific BLOCK_DEVICE.
BLOCK_DEVICEahci_get_block_device (int index)
 Retrieve a pointer to the AHCI driver's BLOCK_DEVICE instance.

Macro Definition Documentation

◆ AHCI_DEV_NULL

#define AHCI_DEV_NULL   0

Definition at line 158 of file ahci.h.

◆ AHCI_DEV_PM

#define AHCI_DEV_PM   3

Definition at line 161 of file ahci.h.

◆ AHCI_DEV_SATA

#define AHCI_DEV_SATA   1

Definition at line 159 of file ahci.h.

◆ AHCI_DEV_SATAPI

#define AHCI_DEV_SATAPI   4

Definition at line 162 of file ahci.h.

◆ AHCI_DEV_SEMB

#define AHCI_DEV_SEMB   2

Definition at line 160 of file ahci.h.

◆ AHCI_MAX_PORTS

#define AHCI_MAX_PORTS   32

Definition at line 17 of file ahci.h.

◆ ATA_CMD_READ_DMA_EX

#define ATA_CMD_READ_DMA_EX   0x25

Definition at line 155 of file ahci.h.

◆ ATA_CMD_WRITE_DMA_EX

#define ATA_CMD_WRITE_DMA_EX   0x35

Definition at line 156 of file ahci.h.

◆ ATA_DEV_BSY

#define ATA_DEV_BSY   0x80

Definition at line 151 of file ahci.h.

◆ ATA_DEV_DRQ

#define ATA_DEV_DRQ   0x08

Definition at line 152 of file ahci.h.

◆ ATA_DEV_ERR

#define ATA_DEV_ERR   0x01

Definition at line 153 of file ahci.h.

◆ HBA_CMD_HDR_A_BIT

#define HBA_CMD_HDR_A_BIT   (1u << 5)

Definition at line 147 of file ahci.h.

◆ HBA_CMD_HDR_CFL_MASK

#define HBA_CMD_HDR_CFL_MASK   0x0000001Fu

Definition at line 146 of file ahci.h.

◆ HBA_CMD_HDR_P_BIT

#define HBA_CMD_HDR_P_BIT   (1u << 7)

Definition at line 149 of file ahci.h.

◆ HBA_CMD_HDR_PRDTL_MASK

#define HBA_CMD_HDR_PRDTL_MASK   0xFFFF0000u

Definition at line 150 of file ahci.h.

◆ HBA_CMD_HDR_W_BIT

#define HBA_CMD_HDR_W_BIT   (1u << 6)

Definition at line 148 of file ahci.h.

◆ HBA_PORT_DET_PRESENT

#define HBA_PORT_DET_PRESENT   3

Definition at line 165 of file ahci.h.

◆ HBA_PORT_IPM_ACTIVE

#define HBA_PORT_IPM_ACTIVE   1

Definition at line 164 of file ahci.h.

◆ HBA_PxCMD_CR

#define HBA_PxCMD_CR   0x8000

Definition at line 170 of file ahci.h.

◆ HBA_PxCMD_FR

#define HBA_PxCMD_FR   0x4000

Definition at line 169 of file ahci.h.

◆ HBA_PxCMD_FRE

#define HBA_PxCMD_FRE   0x0010

Definition at line 168 of file ahci.h.

◆ HBA_PxCMD_ST

#define HBA_PxCMD_ST   0x0001

Definition at line 167 of file ahci.h.

◆ HBA_PxIS_TFES

#define HBA_PxIS_TFES   (1 << 30) /* TFES - Task File Error Status */

Definition at line 171 of file ahci.h.

Typedef Documentation

◆ FIS_REG_H2D

typedef struct _FIS_REG_H2D FIS_REG_H2D

Register - Host to Device FIS (FIS_TYPE_REG_H2D)

◆ FIS_TYPE

typedef enum _FIS_TYPE FIS_TYPE

◆ HBA_CMD_HEADER

HBA Command Header (defines an AHCI Command)

◆ HBA_CMD_TBL

typedef struct _HBA_CMD_TBL HBA_CMD_TBL

Command Table: one per slot.

◆ HBA_MEM

typedef volatile struct _HBA_MEM HBA_MEM

AHCI Register layout (Global HBA Registers)

◆ HBA_PORT

typedef volatile struct _HBA_PORT HBA_PORT

Per port registers at HBA_MEM + 0x100 + (port * 0x80)

◆ HBA_PRDT_ENTRY

Physical Region Descriptor Table Entry.

Enumeration Type Documentation

◆ _FIS_TYPE

enum _FIS_TYPE
Enumerator
FIS_TYPE_REG_H2D 
FIS_TYPE_REG_D2H 
FIS_TYPE_DMA_ACT 
FIS_TYPE_DMA_SETUP 
FIS_TYPE_DATA 
FIS_TYPE_BIST 
FIS_TYPE_PIO_SETUP 
FIS_TYPE_DEV_BITS 

Definition at line 19 of file ahci.h.

Function Documentation

◆ ahci_get_block_device()

BLOCK_DEVICE * ahci_get_block_device ( int index)

Retrieve a pointer to the AHCI driver's BLOCK_DEVICE instance.

Parameters
indexIndex of the BLOCK_DEVICE registration.
Returns
A BLOCK_DEVICE struct pointer.

Definition at line 562 of file ahci.c.

◆ ahci_init()

MTSTATUS ahci_init ( void )

#define AHCI_DEBUG_PRINT

Initialize the AHCI Driver.

Returns
True or False based if it initialized correctly or not. (if failure = bugcheck)

Definition at line 292 of file ahci.c.

◆ ahci_read_sector()

MTSTATUS ahci_read_sector ( BLOCK_DEVICE * dev,
uint32_t lba,
void * buf,
size_t bytes )

Read a single bytes-byte sector from the given LBA on a specific BLOCK_DEVICE.

Parameters
devTakes the BLOCK_DEVICE device pointer (on register_block_device)
lbaLBA to read from.
bufReturn buffer to place the data read.
Returns
True or False based on succession | buf pointer changes.

Definition at line 330 of file ahci.c.

◆ ahci_write_sector()

MTSTATUS ahci_write_sector ( BLOCK_DEVICE * dev,
uint32_t lba,
const void * buf,
size_t bytes )

Write a single bytes-byte sector to given LBA on a specific BLOCK_DEVICE.

Parameters
devTakes the BLOCK_DEVICE device pointer (on register_block_device)
lbaLBA to read from.
bufThe buffer to write to the specified LBA.
Returns
True or False based on succession

Definition at line 450 of file ahci.c.