The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
ata.h
Go to the documentation of this file.
1#pragma once
2
3#include "block_device.h"
4
5/**
6 * ATA channel selection.
7 * each channel has its own I/O base and control port.
8 */
9typedef enum
10{
11 ATA_CHANNEL_PRIMARY = 0, // primary channel: I/O base 0x1F0, control 0x3F6
12 ATA_CHANNEL_SECONDARY = 1, // secondary channel: I/O base 0x170, control 0x376
14
15/**
16 * ATA drive selection within a channel.
17 */
18typedef enum
19{
20 ATA_DRIVE_MASTER = 0, // drive select byte 0xE0 (LBA mode, master)
21 ATA_DRIVE_SLAVE = 1, // drive select byte 0xF0 (LBA mode, slave)
23
24/**
25 * ATA device structure.
26 * carries per-device I/O port state so multiple devices on different
27 * channels or drive positions can coexist without hardcoded port macros.
28 */
29typedef struct
30{
31 block_device_t block; // block device interface, must be first for safe casting.
32 uint16_t io_base; // I/O base port (0x1F0 primary, 0x170 secondary).
33 uint16_t control_base; // control/alt-status port (0x3F6 primary, 0x376 secondary).
34 uint8_t drive_select; // drive-select byte written to the drive/head register.
35 uint64_t sector_count; // total addressable sectors reported by IDENTIFY DEVICE.
37
38/**
39 * initialize an ATA device on the specified channel and drive position.
40 * issues IDENTIFY DEVICE to confirm the drive is present and is not ATAPI.
41 * populates all port fields and wires up the block device interface.
42 *
43 * @param device ATA device object to initialize.
44 * @param channel ATA_CHANNEL_PRIMARY or ATA_CHANNEL_SECONDARY.
45 * @param drive ATA_DRIVE_MASTER or ATA_DRIVE_SLAVE.
46 * @return true on success, false if no drive responds or device is ATAPI.
47 */
bool ata_initialize(ata_device_t *device, ata_channel_t channel, ata_drive_t drive)
initialize an ATA device on the specified channel and drive position.
Definition ata.c:402
ata_drive_t
ATA drive selection within a channel.
Definition ata.h:19
@ ATA_DRIVE_SLAVE
Definition ata.h:21
@ ATA_DRIVE_MASTER
Definition ata.h:20
ata_channel_t
ATA channel selection.
Definition ata.h:10
@ ATA_CHANNEL_SECONDARY
Definition ata.h:12
@ ATA_CHANNEL_PRIMARY
Definition ata.h:11
struct block_device block_device_t
Definition block_device.h:5
unsigned char uint8_t
Definition fb.h:18
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
unsigned short uint16_t
Definition stdint.h:13
ATA device structure.
Definition ata.h:30
uint16_t control_base
Definition ata.h:33
uint64_t sector_count
Definition ata.h:35
block_device_t block
Definition ata.h:31
uint8_t drive_select
Definition ata.h:34
uint16_t io_base
Definition ata.h:32
a registered device.
Definition device.h:114