FrostWing
A lightweight raw-control operating system.
Loading...
Searching...
No Matches
ahci.h File Reference

Header definitions and structures for the AHCI Driver. More...

#include <basics.h>
#include <graphics.h>
Include dependency graph for ahci.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  ahci_port_mem_t
struct  ahci_port_t
 AHCI port registers and command header pointer. More...
struct  ahci_hba_mem_t
struct  ahci_disk_info_t
struct  block_device_info_t
struct  general_partition_t
struct  mount_entry

Macros

#define AHCI_PORT_DET_PRESENT   3
#define AHCI_PORT_IPM_ACTIVE   1
#define AHCI_PORT_CMD_ST   (1 << 0)
#define AHCI_PORT_CMD_FRE   (1 << 4)
#define AHCI_PORT_CMD_FR   (1 << 14)
#define AHCI_PORT_CMD_CR   (1 << 15)
#define READ_DMA_EXT   0x25
#define SECTOR_SIZE   512
#define ATA_CMD_WRITE_DMA_EXT   0x35
#define ATA_CMD_IDENTIFY   0xEC
#define MAX_PARTITIONS   128
#define MAX_BLOCK_DEVICES   64
#define AHCI_MAX_PRDT   16
#define PRDT_MAX_BYTES   (4 * 1024 * 1024)
#define sata_disk   0x00000101
 AHCI device signatures.
#define satapi_disk   0xEB140101
#define semb_disk   0xC33C0101
#define port_multiplier   0x96690101
#define AHCI_CMD_HDR_CFL_MASK   0x001F /* bits 0-4 */
#define AHCI_CMD_HDR_A_BIT   0x0020
#define AHCI_CMD_HDR_W_BIT   0x0040
#define AHCI_CMD_HDR_P_BIT   0x0080
#define AHCI_CMD_HDR_R_BIT   0x0100
#define AHCI_CMD_HDR_B_BIT   0x0200
#define AHCI_CMD_HDR_C_BIT   0x0400
#define AHCI_CMD_HDR_PMP_MASK   0xF000 /* bits 12-15 */

Typedefs

typedef struct mount_entry mount_entry_t

Enumerations

enum  block_device_type_t { BLOCK_DEVICE_AHCI = 0 , BLOCK_DEVICE_NVME }
enum  partition_fs_type_t {
  FS_UNKNOWN = 0 , FS_FAT12 , FS_FAT16 , FS_FAT32 ,
  FS_EXFAT , FS_EXT2 , FS_EXT3 , FS_EXT4 ,
  FS_XFS , FS_BTRFS , FS_NTFS , FS_ISO9660 ,
  FS_UDF , FS_PROC , FS_DEV
}
 GENERAL PARITION LAYOUT BEGIN. More...
enum  partition_table_type_t { PART_TABLE_MBR , PART_TABLE_GPT }

Functions

struct __attribute__ ((packed))
 AHCI command header structure.
void detect_ahci_devices (ahci_hba_mem_t *ahci_ctrl)
 Probes and detects all AHCI devices connected to the controller.
void handle_sata_disk (int portno)
void handle_satapi_disk (int portno)
void ahci_init_port (int portno)
int ahci_read_sector (int portno, uint64_t lba, void *buffer, uint32_t count)
int ahci_write_sector (int portno, uint64_t lba, void *buffer, uint32_t count)
int ahci_identify (int portno, void *buffer)
int block_register_device (block_device_type_t type, int backend_index, uint64_t total_sectors, uint32_t sector_size, const char *name)
block_device_info_tblock_get_device (int device_id)
const char * block_get_device_name (int device_id)
int block_read_sector (int device_id, uint64_t lba, void *buffer, uint32_t count)
int block_write_sector (int device_id, uint64_t lba, void *buffer, uint32_t count)
general_partition_tadd_general_partition (partition_table_type_t table_type, uint64 lba_start, uint64 lba_end, uint64 sector_count, uint64 ahci_port, bool bootable, partition_fs_type_t fs_type, cstring name, uint8_t mbr_type, const uint8_t *gpt_guid)
general_partition_tsearch_general_partition (cstring partition_name)
mount_entry_t * add_mount (const char *mount_point, const char *part_name, partition_fs_type_t type, void *fs_ptr)
mount_entry_t * find_mount_by_point (const char *mount_point)
int remove_mount (const char *mount_point)
void list_all_mounts (void)

Variables

 ahci_cmd_header_t
 prdt_entry_t
 ahci_cmd_table_t
ahci_port_mem_t port_mem [32]
ahci_disk_info_t ahci_disks [32]
general_partition_t ahci_partitions [128]
mount_entry_t mounted_partitions [128]
block_device_info_t block_devices [64]
int general_partition_count
int mounted_partition_count
int block_device_count
ahci_hba_mem_tglobal_ahci_ctrl
 Global AHCI controller pointer.

Detailed Description

Header definitions and structures for the AHCI Driver.

Author
Pradosh (prado.nosp@m.shga.nosp@m.me@gm.nosp@m.ail..nosp@m.com)
Version
0.1
Date
2023-12-16

Definition in file ahci.h.

Macro Definition Documentation

◆ AHCI_CMD_HDR_A_BIT

#define AHCI_CMD_HDR_A_BIT   0x0020

Definition at line 60 of file ahci.h.

◆ AHCI_CMD_HDR_B_BIT

#define AHCI_CMD_HDR_B_BIT   0x0200

Definition at line 64 of file ahci.h.

◆ AHCI_CMD_HDR_C_BIT

#define AHCI_CMD_HDR_C_BIT   0x0400

Definition at line 65 of file ahci.h.

◆ AHCI_CMD_HDR_CFL_MASK

#define AHCI_CMD_HDR_CFL_MASK   0x001F /* bits 0-4 */

Definition at line 59 of file ahci.h.

◆ AHCI_CMD_HDR_P_BIT

#define AHCI_CMD_HDR_P_BIT   0x0080

Definition at line 62 of file ahci.h.

◆ AHCI_CMD_HDR_PMP_MASK

#define AHCI_CMD_HDR_PMP_MASK   0xF000 /* bits 12-15 */

Definition at line 66 of file ahci.h.

◆ AHCI_CMD_HDR_R_BIT

#define AHCI_CMD_HDR_R_BIT   0x0100

Definition at line 63 of file ahci.h.

◆ AHCI_CMD_HDR_W_BIT

#define AHCI_CMD_HDR_W_BIT   0x0040

Definition at line 61 of file ahci.h.

◆ AHCI_MAX_PRDT

#define AHCI_MAX_PRDT   16

Definition at line 32 of file ahci.h.

◆ AHCI_PORT_CMD_CR

#define AHCI_PORT_CMD_CR   (1 << 15)

Definition at line 22 of file ahci.h.

◆ AHCI_PORT_CMD_FR

#define AHCI_PORT_CMD_FR   (1 << 14)

Definition at line 21 of file ahci.h.

◆ AHCI_PORT_CMD_FRE

#define AHCI_PORT_CMD_FRE   (1 << 4)

Definition at line 20 of file ahci.h.

◆ AHCI_PORT_CMD_ST

#define AHCI_PORT_CMD_ST   (1 << 0)

Definition at line 19 of file ahci.h.

◆ AHCI_PORT_DET_PRESENT

#define AHCI_PORT_DET_PRESENT   3

Definition at line 17 of file ahci.h.

◆ AHCI_PORT_IPM_ACTIVE

#define AHCI_PORT_IPM_ACTIVE   1

Definition at line 18 of file ahci.h.

◆ ATA_CMD_IDENTIFY

#define ATA_CMD_IDENTIFY   0xEC

Definition at line 27 of file ahci.h.

◆ ATA_CMD_WRITE_DMA_EXT

#define ATA_CMD_WRITE_DMA_EXT   0x35

Definition at line 26 of file ahci.h.

◆ MAX_BLOCK_DEVICES

#define MAX_BLOCK_DEVICES   64

Definition at line 30 of file ahci.h.

◆ MAX_PARTITIONS

#define MAX_PARTITIONS   128

Definition at line 29 of file ahci.h.

◆ port_multiplier

#define port_multiplier   0x96690101

Definition at line 42 of file ahci.h.

◆ PRDT_MAX_BYTES

#define PRDT_MAX_BYTES   (4 * 1024 * 1024)

Definition at line 33 of file ahci.h.

◆ READ_DMA_EXT

#define READ_DMA_EXT   0x25

Definition at line 23 of file ahci.h.

◆ sata_disk

#define sata_disk   0x00000101

AHCI device signatures.

Definition at line 39 of file ahci.h.

◆ satapi_disk

#define satapi_disk   0xEB140101

Definition at line 40 of file ahci.h.

◆ SECTOR_SIZE

#define SECTOR_SIZE   512

Definition at line 24 of file ahci.h.

◆ semb_disk

#define semb_disk   0xC33C0101

Definition at line 41 of file ahci.h.

Enumeration Type Documentation

◆ block_device_type_t

enum block_device_type_t

Definition at line 147 of file ahci.h.

◆ partition_fs_type_t

GENERAL PARITION LAYOUT BEGIN.

Definition at line 163 of file ahci.h.

◆ partition_table_type_t

enum partition_table_type_t

Definition at line 190 of file ahci.h.

Function Documentation

◆ __attribute__()

struct __attribute__ ( (packed) )

AHCI command header structure.

AHCI command table structure.

Physical Region Descriptor Table (PRDT) entry.

Represents the command header for a single AHCI port.

Definition at line 1 of file ahci.h.

◆ detect_ahci_devices()

void detect_ahci_devices ( ahci_hba_mem_t * ahci_ctrl)

Probes and detects all AHCI devices connected to the controller.

Parameters
ahci_ctrlPointer to the AHCI controller structure.

Variable Documentation

◆ ahci_cmd_header_t

ahci_cmd_header_t

Definition at line 57 of file ahci.h.

◆ ahci_cmd_table_t

ahci_cmd_table_t

Definition at line 87 of file ahci.h.

◆ prdt_entry_t

prdt_entry_t

Definition at line 76 of file ahci.h.