2021-10-03 23:19:00 +02:00
|
|
|
#pragma once
|
|
|
|
#include "stdarg.h"
|
|
|
|
|
2021-10-05 21:59:36 +02:00
|
|
|
#define ATA_PIO_DATA 0
|
|
|
|
#define ATA_PIO_ERR 1
|
|
|
|
#define ATA_PIO_FEAT 1
|
2021-10-03 23:19:00 +02:00
|
|
|
#define ATA_PIO_SEC_COUNT 2
|
|
|
|
#define ATA_PIO_LBALO 3
|
|
|
|
#define ATA_PIO_LBAMID 4
|
|
|
|
#define ATA_PIO_CYL_LOW 4
|
|
|
|
#define ATA_PIO_LBAHI 5
|
|
|
|
#define ATA_PIO_CYL_HI 5
|
|
|
|
#define ATA_PIO_DRIVE 6
|
|
|
|
#define ATA_PIO_STATUS 7
|
|
|
|
#define ATA_PIO_CMD 7
|
|
|
|
|
2021-10-05 21:59:36 +02:00
|
|
|
// cmd details
|
|
|
|
// https://people.freebsd.org/~imp/asiabsdcon2015/works/d2161r5-ATAATAPI_Command_Set_-_3.pdf
|
2021-10-03 23:19:00 +02:00
|
|
|
#define ATA_PIO_CMD_IDENTIFY 0xEC
|
|
|
|
|
|
|
|
#define ATA_PIO_ERROR_ADDR_MARK_NOT_FOUND 0
|
|
|
|
#define ATA_PIO_ERROR_TRACK_ZERO_NOT_FOUND 1
|
|
|
|
#define ATA_PIO_ERROR_ABORTED 2
|
|
|
|
#define ATA_PIO_ERROR_MEDIA_CHANGE_REQUEST 3
|
|
|
|
#define ATA_PIO_ERROR_ID_NOT_FOUND 4
|
|
|
|
#define ATA_PIO_ERROR_MEDIA_CHANGED 5
|
|
|
|
#define ATA_PIO_ERROR_UNCORRECTABLE_DATA 6
|
|
|
|
#define ATA_PIO_ERROR_BAD_BLOCK 7
|
|
|
|
|
2021-10-05 21:59:36 +02:00
|
|
|
#define ATA_PIO_STATUS_REG_ERR (1 << 0)
|
|
|
|
#define ATA_PIO_STATUS_IDX (1 << 1)
|
|
|
|
#define ATA_PIO_STATUS_CORP (1 << 2)
|
|
|
|
#define ATA_PIO_STATUS_DRQ (1 << 3)
|
|
|
|
#define ATA_PIO_STATUS_SRV (1 << 4)
|
|
|
|
#define ATA_PIO_STATUS_DRIVE_FAULT (1 << 5)
|
|
|
|
#define ATA_PIO_STATUS_DRIVE_RDY (1 << 6)
|
|
|
|
#define ATA_PIO_STATUS_DRIVE_BUSY (1 << 7)
|
|
|
|
|
|
|
|
#define MAX_ATA_CONTROLLER 2
|
|
|
|
#define MAX_ATA_DEVICES 2
|
|
|
|
|
|
|
|
#define DISK_SECTOR_SIZE 512
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
ATA_DEV_UNKNOWN,
|
|
|
|
ATA_DEV_PATA,
|
|
|
|
ATA_DEV_SATA,
|
|
|
|
ATA_DEV_PATAPI,
|
|
|
|
ATA_DEV_SATAPI
|
|
|
|
} ata_type;
|
|
|
|
|
|
|
|
struct ata_device {
|
|
|
|
int id;
|
|
|
|
ata_type type;
|
2021-10-03 23:19:00 +02:00
|
|
|
int isSlave;
|
2021-10-05 21:59:36 +02:00
|
|
|
struct ata_controller *ctl;
|
|
|
|
int heads;
|
|
|
|
int cyls;
|
|
|
|
int sectors;
|
2021-10-03 23:19:00 +02:00
|
|
|
};
|
|
|
|
|
2021-10-05 21:59:36 +02:00
|
|
|
struct ata_controller {
|
|
|
|
int id;
|
|
|
|
int16_t base;
|
|
|
|
int16_t dev_ctl;
|
|
|
|
int present;
|
|
|
|
struct ata_device devices[MAX_ATA_DEVICES];
|
|
|
|
};
|
2021-10-03 23:19:00 +02:00
|
|
|
|
|
|
|
int ATAInit();
|