The manual
ginnOS
The reference: libc, the libraries and the kernel
Toggle main menu visibility
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
"
17
#include "
kernel/sync/completion.h
"
18
#include "
kernel/sync/mutex.h
"
19
20
#define AHCI_MAX_DISKS 4
21
22
typedef
struct
23
{
24
block_device_t
block
;
// the block device interface (context points here)
25
volatile
uint32_t
*
port
;
// this port's registers
26
uint8_t
port_number
;
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
33
}
ahci_disk_t
;
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
*/
40
uint32_t
ahci_init
(
void
);
41
42
/**
43
* a disk by index (0 to the number ahci_init returned).
44
* @return the disk, or NULL.
45
*/
46
ahci_disk_t
*
ahci_disk
(
uint32_t
index);
ahci_disk
ahci_disk_t * ahci_disk(uint32_t index)
a disk by index (0 to the number ahci_init returned).
Definition
ahci.c:485
ahci_init
uint32_t ahci_init(void)
find the AHCI controller (the first one) and its disks.
Definition
ahci.c:444
block_device.h
block_device_t
struct block_device block_device_t
Definition
block_device.h:5
stdint.h
completion.h
wait for a device: sleep until its interrupt, or poll.
uint32_t
unsigned int uint32_t
Definition
fb.h:17
uint8_t
unsigned char uint8_t
Definition
fb.h:18
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
mutex.h
phys.h
phys_addr_t
uintptr_t phys_addr_t
physical addresses and the conversion between physical and virtual.
Definition
phys.h:18
ahci_disk_t
Definition
ahci.h:23
ahci_disk_t::port_number
uint8_t port_number
Definition
ahci.h:26
ahci_disk_t::port
volatile uint32_t * port
Definition
ahci.h:25
ahci_disk_t::dma_page
uint8_t * dma_page
Definition
ahci.h:27
ahci_disk_t::lock
mutex_t lock
Definition
ahci.h:30
ahci_disk_t::sectors
uint64_t sectors
Definition
ahci.h:29
ahci_disk_t::dma_phys
phys_addr_t dma_phys
Definition
ahci.h:28
ahci_disk_t::done
completion_t done
Definition
ahci.h:31
ahci_disk_t::irq_status
volatile uint32_t irq_status
Definition
ahci.h:32
ahci_disk_t::block
block_device_t block
Definition
ahci.h:24
completion_t
Definition
completion.h:25
mutex_t
sleeping mutex for long critical sections in process context (filesystem and disk I/O).
Definition
mutex.h:20
src
drivers
disk
ahci.h
Generated by
1.18.0