The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
ahci.h
Go to the documentation of this file.
1#pragma once
2
3/**
4 * @file ahci.h
5 * @brief SATA disks through an AHCI controller (PCI class 01:06:01).
6 *
7 * ahci_init finds the controller, maps its registers (BAR 5) and sets up
8 * each port that has a SATA disk. each disk is a block_device_t of 512-byte
9 * sectors. the transfers use DMA with 48-bit LBA commands. a process that
10 * waits for a command sleeps until the port interrupts; during boot, or
11 * without an interrupt, the driver polls the port.
12 */
13
14#include "block_device.h"
15#include "common/stdint.h"
16#include "kernel/memory/phys.h"
18#include "kernel/sync/mutex.h"
19
20#define AHCI_MAX_DISKS 4
21
22typedef struct
23{
24 block_device_t block; // the block device interface (context points here)
25 volatile uint32_t *port; // this port's registers
27 uint8_t *dma_page; // command list, FIS area, command table, bounce buffer
28 phys_addr_t dma_phys; // the physical address of dma_page
29 uint64_t sectors; // from IDENTIFY DEVICE
30 mutex_t lock; // one command at a time
31 completion_t done; // the port interrupt
32 volatile uint32_t irq_status; // the port status the interrupt handler cleared
34
35/**
36 * find the AHCI controller (the first one) and its disks. call after
37 * pci_init and mmio_init.
38 * @return the number of disks found.
39 */
41
42/**
43 * a disk by index (0 to the number ahci_init returned).
44 * @return the disk, or NULL.
45 */
ahci_disk_t * ahci_disk(uint32_t index)
a disk by index (0 to the number ahci_init returned).
Definition ahci.c:485
uint32_t ahci_init(void)
find the AHCI controller (the first one) and its disks.
Definition ahci.c:444
struct block_device block_device_t
Definition block_device.h:5
wait for a device: sleep until its interrupt, or poll.
unsigned int uint32_t
Definition fb.h:17
unsigned char uint8_t
Definition fb.h:18
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
uintptr_t phys_addr_t
physical addresses and the conversion between physical and virtual.
Definition phys.h:18
Definition ahci.h:23
uint8_t port_number
Definition ahci.h:26
volatile uint32_t * port
Definition ahci.h:25
uint8_t * dma_page
Definition ahci.h:27
mutex_t lock
Definition ahci.h:30
uint64_t sectors
Definition ahci.h:29
phys_addr_t dma_phys
Definition ahci.h:28
completion_t done
Definition ahci.h:31
volatile uint32_t irq_status
Definition ahci.h:32
block_device_t block
Definition ahci.h:24
Definition completion.h:25
sleeping mutex for long critical sections in process context (filesystem and disk I/O).
Definition mutex.h:20