Skip to content

AHCI

include/drivers/ahci.h View source View on GitHub
struct ahci_fis_reg_h2d (19 fields) source
NOTE

offsets and sizes in kernel/drivers/ahci/layout.c

§ uint8_t fis_type

0x27

§ uint8_t pmport : 4
§ uint8_t reserved1 : 3
§ uint8_t c : 1
§ uint8_t command
§ uint8_t featurel
§ uint8_t lba0
§ uint8_t lba1
§ uint8_t lba2
§ uint8_t device
§ uint8_t lba3
§ uint8_t lba4
§ uint8_t lba5
§ uint8_t featureh
§ uint8_t countl
§ uint8_t counth
§ uint8_t icc
§ uint8_t control
§ uint8_t reserved2[4]
struct ahci_fis_reg_d2h (19 fields) source
§ uint8_t fis_type

FIS_TYPE_REG_D2H

§ uint8_t pmport : 4

Port multiplier

§ uint8_t rsv0 : 2

Reserved

§ uint8_t i : 1

Interrupt bit

§ uint8_t rsv1 : 1

Reserved

§ uint8_t status

Status register

§ uint8_t error

Error register

§ uint8_t lba0

LBA low register, 7:0

§ uint8_t lba1

LBA mid register, 15:8

§ uint8_t lba2

LBA high register, 23:16

§ uint8_t device

Device register

§ uint8_t lba3

LBA register, 31:24

§ uint8_t lba4

LBA register, 39:32

§ uint8_t lba5

LBA register, 47:40

§ uint8_t rsv2

Reserved

§ uint8_t countl

Count register, 7:0

§ uint8_t counth

Count register, 15:8

§ uint8_t rsv3[2]

Reserved

§ uint8_t rsv4[4]

Reserved

struct ahci_prdt_entry (6 fields) source
§ uint32_t dba

Data base address

§ uint32_t dbau

Upper 32-bits of DBA

§ uint32_t reserved
§ uint32_t dbc : 22

Byte count (0-based)

§ uint32_t reserved2 : 9
§ uint32_t i : 1

Interrupt on completion

struct ahci_cmd_table (4 fields) source
§ uint8_t cfis[AHCI_CMD_TABLE_FIS_SIZE]

Command FIS (host to device)

ATAPI command

§ uint8_t reserved[48]
§ struct ahci_prdt_entry prdt_entry[]

up to 65535

struct ahci_full_port (6 fields) source
§ struct ahci_port cc_mem_io *port
§ void *cmd_list_base
§ void *fis
§ struct ahci_cmd_table **cmd_tables
§ struct ahci_cmd_header **cmd_hdrs
§ volatile atomic_uint32_t slot_bitmap
struct ahci_port (19 fields) source
§ uint32_t clb

Command List Base (lower 32 bits)

§ uint32_t clbu

Command List Base (upper 32 bits)

§ uint32_t fb

FIS Base (lower 32 bits)

§ uint32_t fbu

FIS Base (upper 32 bits)

§ uint32_t is

Interrupt Status

§ uint32_t ie

Interrupt Enable

§ uint32_t cmd

Command and Status

§ uint32_t rsv0

Reserved

§ uint32_t tfd

Task File Data

§ uint32_t sig

Signature

§ uint32_t ssts

SATA Status

§ uint32_t sctl

SATA Control

§ uint32_t serr

SATA Error

§ uint32_t sact

SATA Active

§ uint32_t ci

Command Issue

§ uint32_t sntf

SATA Notification

§ uint32_t fbs

FIS-based Switching

§ uint32_t rsv1[11]

Reserved

§ uint32_t vendor[4]

vendor specific

struct ahci_device (11 fields) source

one controller

§ uint8_t type

Device type

§ uint32_t signature

Device signature

§ uint32_t sectors

Total sectors (for disks)

§ uint16_t sector_size

Sector size in bytes

§ uint64_t port_count
§ uint16_t io_statuses[AHCI_MAX_PORTS][32]
§ struct ahci_request *io_requests[AHCI_MAX_PORTS][32]
§ irq_t irq_num
§ struct spinlock lock
§ struct ahci_full_port regs[32]

Pointer to port registers

struct ahci_disk (3 fields) source

one disk

§ struct ahci_device *device
§ uint32_t port
§ uint16_t sector_size

Sector size in bytes

struct ahci_controller (13 fields) source
§ uint32_t cap

Host Capabilities

§ uint32_t ghc

Global Host Control

§ uint32_t is

Interrupt Status

§ uint32_t pi

Ports Implemented

§ uint32_t vs

Version

§ uint32_t ccc_ctl

Command Completion Coalescing Control

§ uint32_t ccc_ports

CCC Ports

§ uint32_t em_loc

Enclosure Management Location

§ uint32_t em_ctl

Enclosure Management Control

§ uint32_t cap2

Extended Host Capabilities

§ uint32_t bohc

BIOS/OS Handoff Control

§ uint8_t rsv[0xA0 - 0x2C]
§ uint8_t vendor[0x100 - 0xA0]
struct ahci_cmd_header (14 fields) source
§ uint8_t cfl : 5

Command FIS length in DWORDS, 2 ~ 16

§ uint8_t a : 1

ATAPI

§ uint8_t w : 1

Write, 1: H2D, 0: D2H

§ uint8_t p : 1

Prefetchable

§ uint8_t r : 1

Reset

§ uint8_t b : 1

BIST

§ uint8_t c : 1

Clear busy upon R_OK

§ uint8_t rsv0 : 1

Reserved

§ uint8_t pmp : 4

Port multiplier port

§ uint16_t prdtl

Physical region descriptor table length in entries

§ uint32_t prdbc

Physical region descriptor byte count transferred

§ uint32_t ctba

Command table descriptor base address

§ uint32_t ctbau

Command table descriptor base address upper 32 bits

§ uint32_t rsv1[4]

Reserved

struct ahci_request (14 fields) source
§ struct event evt
§ bool has_waiter
§ uint32_t port
§ uint32_t slot
§ uint64_t lba
§ void *buffer
§ uint64_t size
§ uint64_t sector_count
§ bool write
§ bool trigger_completion
§ volatile bool done
§ int status
§ void (*on_complete)(struct ahci_request *)
§ void *user_data
void ahci_discover(struct ahci_controller cc_mem_io *ctrl)
source
uint32_t ahci_find_slot(struct ahci_full_port *port)
source
struct ahci_disk * ahci_setup_controller(
    struct ahci_controller cc_mem_io *ctrl,
    uint32_t *d_cnt
)
source
void ahci_identify(struct ahci_disk *disk)
source
void ahci_prepare_command(
    struct ahci_full_port *port,
    uint32_t slot,
    bool write,
    uint8_t *buf,
    uint64_t size
)
source
void ahci_setup_fis(
    struct ahci_cmd_table *cmd_tbl,
    uint8_t command,
    bool is_atapi
)
source
void ahci_send_command(
    struct ahci_disk *disk,
    struct ahci_full_port *port,
    struct ahci_request *req
)
source
struct ahci_disk * ahci_discover_device(
    uint8_t bus,
    uint8_t device,
    uint8_t function,
    uint32_t *out_disk_count
)
source
bool ahci_write_sector(
    struct block_device *disk,
    uint64_t lba,
    const uint8_t *in_buf,
    uint16_t cnt
)
source
bool ahci_write_sector_async(
    struct block_device *disk,
    uint64_t lba,
    uint8_t *in_buf,
    uint16_t count,
    struct ahci_request *req
)
source
bool ahci_read_sector(
    struct block_device *disk,
    uint64_t lba,
    uint8_t *out_buf,
    uint16_t cnt
)
source
bool ahci_read_sector_async(
    struct block_device *disk,
    uint64_t lba,
    uint8_t *buf,
    uint16_t count,
    struct ahci_request *req
)
source
bool ahci_read_sector_wrapper(
    struct block_device *disk,
    uint64_t lba,
    uint8_t *buf,
    uint64_t cnt
)
source
bool ahci_read_sector_async_wrapper(
    struct block_device *disk,
    uint64_t lba,
    uint8_t *buf,
    uint64_t cnt,
    struct ahci_request *req
)
source
bool ahci_write_sector_wrapper(
    struct block_device *disk,
    uint64_t lba,
    const uint8_t *buf,
    uint64_t cnt
)
source
bool ahci_write_sector_async_wrapper(
    struct block_device *disk,
    uint64_t lba,
    const uint8_t *buf,
    uint64_t cnt,
    struct ahci_request *req
)
source
bool ahci_submit_bio_request(
    struct block_device *disk,
    struct bio_request *bio
)
source
void ahci_do_coalesce(
    struct block_device *disk,
    struct bio_request *into,
    struct bio_request *from
)
source
bool ahci_should_coalesce(
    struct block_device *disk,
    const struct bio_request *a,
    const struct bio_request *b
)
source
void ahci_reorder(struct block_device *disk)
source
struct block_device * ahci_create_generic(struct ahci_disk *disk)
source
enum irq_result ahci_isr_handler(struct irq_context *ictx, void *ctx)
source
struct ahci_port cc_mem_io * ahci_get_port(
    struct ahci_device *dev,
    int n
)
source
void ahci_print_wrapper(struct block_device *d)
source
#define AHCI_CMD_TIMEOUT_MS 5000
source

Data commands (read/write)

#define AHCI_IDENT_TIMEOUT_MS 10000
source

Identify, flush cache, etc.

#define AHCI_RESET_TIMEOUT_MS 30000
source

Full controller reset or COMRESET

#define AHCI_CAP 0x00
source

Host Capabilities

#define AHCI_GHC 0x04
source

Global Host Control

#define AHCI_IS 0x08
source

Interrupt Status

#define AHCI_PI 0x0C
source

Ports Implemented

#define AHCI_VS 0x10
source

AHCI Version

#define AHCI_CCC_CTL 0x14
source

Command Completion Coalescing Control

#define AHCI_CCC_PORTS 0x18
source

CCC Ports

#define AHCI_EM_LOC 0x1C
source

Enclosure Management Location

#define AHCI_EM_CTL 0x20
source

Enclosure Management Control

#define AHCI_CAP2 0x24
source

Host Capabilities Extended

#define AHCI_BOHC 0x28
source

BIOS/OS Handoff Control and Status

#define AHCI_PORT_BASE 0x100
source

Base offset for port registers

#define AHCI_PORT_SIZE 0x80
source

Size of each port register set

#define AHCI_MAX_PORTS 32
source
#define AHCI_MAX_SLOTS 32
source
#define AHCI_PORT_CLB 0x00
source

Command List Base Address

#define AHCI_PORT_CLBU 0x04
source

Command List Base Address Upper

#define AHCI_PORT_FB 0x08
source

FIS Base Address

#define AHCI_PORT_FBU 0x0C
source

FIS Base Address Upper

#define AHCI_PORT_IS 0x10
source

Interrupt Status

#define AHCI_PORT_IE 0x14
source

Interrupt Enable

#define AHCI_PORT_CMD 0x18
source

Command and Status

#define AHCI_PORT_TFD 0x20
source

Task File Data

#define AHCI_PORT_SIG 0x24
source

Signature

#define AHCI_PORT_SSTS 0x28
source

SATA Status

#define AHCI_PORT_SCTL 0x2C
source

SATA Control

#define AHCI_PORT_SERR 0x30
source

SATA Error

#define AHCI_PORT_SACT 0x34
source

SATA Active

#define AHCI_PORT_CI 0x38
source

Command Issue

#define AHCI_PORT_SNTF 0x3C
source

SATA Notification

#define AHCI_DEV_NULL 0
source
#define AHCI_DEV_SATA 1
source
#define AHCI_DEV_BUSY BIT(30)
source
#define AHCI_DEV_DRDY 0x40
source
#define AHCI_DEV_SATAPI 2
source
#define AHCI_DEV_SEMB 3
source
#define AHCI_DEV_PM 4
source
#define AHCI_CMD_TABLE_FIS_SIZE 64
source
#define AHCI_CMD_TABLE_ATAPI_SIZE 16
source
#define AHCI_MAX_PRDT_ENTRIES 65535
source
#define AHCI_GHC_HR BIT(0)
source
#define AHCI_GHC_AE BIT(31)
source
#define AHCI_DET_NO_DEVICE 0x0
source
#define AHCI_DET_PRESENT 0x3
source
#define AHCI_IPM_NO_INTERFACE 0x0
source
#define AHCI_IPM_ACTIVE 0x1
source
#define AHCI_CMD_READ_DMA_EXT 0x25
source
#define AHCI_CMD_WRITE_DMA_EXT 0x35
source
#define AHCI_CMD_IDENTIFY 0xEC
source
#define AHCI_CMD_ST BIT(0)
source

Start

#define AHCI_CMD_SUD BIT(1)
source

Spin-Up Device

#define AHCI_CMD_FRE BIT(4)
source

FIS Receive Enable

#define AHCI_CMD_FR BIT(14)
source

FIS Receive Running

#define AHCI_CMD_CR BIT(15)
source

Command List Running

#define AHCI_CMD_CLO BIT(3)
source

Command List Override

#define AHCI_PORT_IPM_ACTIVE 1
source
#define AHCI_PORT_DET_PRESENT 3
source
#define AHCI_CMD_FLAGS_WRITE BIT(6)
source
#define AHCI_CMD_FLAGS_PRDTL 1
source
#define FIS_TYPE_REG_H2D 0x27
source
#define FIS_REG_CMD 0x80
source
#define LBA_MODE 0x40
source
#define CONTROL_BIT 0x80
source
#define AHCI_CMD_FLAGS_CFL_MASK 0x1F
source
#define AHCI_CMD_FLAGS_W_BIT 0x40
source
#define ahci_log(log_level, fmt, ...)
source
Expansion
#define ahci_log(log_level, fmt, ...) \
    log(LOG_SITE(ahci), LOG_HANDLE(ahci), log_level, fmt, ##__VA_ARGS__)
#define AHCI_PORT_OFFSET(n)
source
Expansion
#define AHCI_PORT_OFFSET(n) (0x100 + (n) * 0x80)