00001 #include "../drivers.h"
00002 #include "../libdriver/driver.h"
00003 #include "../libdriver/drvlib.h"
00004
00005 _PROTOTYPE(int main, (int argc, char *argv[]));
00006
00007 #define VERBOSE 0
00008 #define ENABLE_ATAPI 1
00009
00010 #define ATAPI_DEBUG 0
00011
00012
00013
00014
00015 #define REG_CMD_BASE0 0x1F0
00016 #define REG_CMD_BASE1 0x170
00017 #define REG_CTL_BASE0 0x3F6
00018 #define REG_CTL_BASE1 0x376
00019
00020 #define PCI_CTL_OFF 2
00021 #define PCI_DMA_2ND_OFF 8
00022
00023
00024
00025 #define REG_DATA 0
00026 #define REG_PRECOMP 1
00027 #define REG_COUNT 2
00028 #define REG_SECTOR 3
00029 #define REG_CYL_LO 4
00030 #define REG_CYL_HI 5
00031 #define REG_LDH 6
00032 #define LDH_DEFAULT 0xA0
00033 #define LDH_LBA 0x40
00034 #define LDH_DEV 0x10
00035 #define ldh_init(drive) (LDH_DEFAULT | ((drive) << 4))
00036
00037
00038 #define REG_STATUS 7
00039 #define STATUS_BSY 0x80
00040 #define STATUS_RDY 0x40
00041 #define STATUS_WF 0x20
00042 #define STATUS_SC 0x10
00043 #define STATUS_DRQ 0x08
00044 #define STATUS_CRD 0x04
00045 #define STATUS_IDX 0x02
00046 #define STATUS_ERR 0x01
00047 #define STATUS_ADMBSY 0x100
00048 #define REG_ERROR 1
00049 #define ERROR_BB 0x80
00050 #define ERROR_ECC 0x40
00051 #define ERROR_ID 0x10
00052 #define ERROR_AC 0x04
00053 #define ERROR_TK 0x02
00054 #define ERROR_DM 0x01
00055
00056
00057 #define REG_COMMAND 7
00058 #define CMD_IDLE 0x00
00059 #define CMD_RECALIBRATE 0x10
00060 #define CMD_READ 0x20
00061 #define CMD_READ_EXT 0x24
00062 #define CMD_READ_DMA_EXT 0x25
00063 #define CMD_WRITE 0x30
00064 #define CMD_WRITE_EXT 0x34
00065 #define CMD_WRITE_DMA_EXT 0x35
00066 #define CMD_READVERIFY 0x40
00067 #define CMD_FORMAT 0x50
00068 #define CMD_SEEK 0x70
00069 #define CMD_DIAG 0x90
00070 #define CMD_SPECIFY 0x91
00071 #define CMD_READ_DMA 0xC8
00072 #define CMD_WRITE_DMA 0xCA
00073 #define ATA_IDENTIFY 0xEC
00074
00075 #define REG_CTL 0
00076 #define CTL_NORETRY 0x80
00077 #define CTL_NOECC 0x40
00078 #define CTL_EIGHTHEADS 0x08
00079 #define CTL_RESET 0x04
00080 #define CTL_INTDISABLE 0x02
00081 #define REG_CTL_ALTSTAT 0
00082
00083
00084 #define ID_GENERAL 0x00
00085 #define ID_GEN_NOT_ATA 0x8000
00086 #define ID_CAPABILITIES 0x31
00087 #define ID_CAP_LBA 0x0200
00088 #define ID_CAP_DMA 0x0100
00089 #define ID_FIELD_VALIDITY 0x35
00090 #define ID_FV_88 0x04
00091 #define ID_MULTIWORD_DMA 0x3f
00092 #define ID_MWDMA_2_SEL 0x0400
00093 #define ID_MWDMA_1_SEL 0x0200
00094 #define ID_MWDMA_0_SEL 0x0100
00095 #define ID_MWDMA_2_SUP 0x0004
00096 #define ID_MWDMA_1_SUP 0x0002
00097 #define ID_MWDMA_0_SUP 0x0001
00098 #define ID_CSS 0x53
00099 #define ID_CSS_LBA48 0x0400
00100 #define ID_ULTRA_DMA 0x58
00101 #define ID_UDMA_5_SEL 0x2000
00102 #define ID_UDMA_4_SEL 0x1000
00103 #define ID_UDMA_3_SEL 0x0800
00104 #define ID_UDMA_2_SEL 0x0400
00105 #define ID_UDMA_1_SEL 0x0200
00106 #define ID_UDMA_0_SEL 0x0100
00107 #define ID_UDMA_5_SUP 0x0020
00108 #define ID_UDMA_4_SUP 0x0010
00109 #define ID_UDMA_3_SUP 0x0008
00110 #define ID_UDMA_2_SUP 0x0004
00111 #define ID_UDMA_1_SUP 0x0002
00112 #define ID_UDMA_0_SUP 0x0001
00113
00114
00115 #define DMA_COMMAND 0
00116 #define DMA_CMD_WRITE 0x08
00117 #define DMA_CMD_START 0x01
00118 #define DMA_STATUS 2
00119 #define DMA_ST_D1_DMACAP 0x40
00120 #define DMA_ST_D0_DMACAP 0x20
00121 #define DMA_ST_INT 0x04
00122 #define DMA_ST_ERROR 0x02
00123 #define DMA_ST_BM_ACTIVE 0x01
00124 #define DMA_PRDTP 4
00125
00126
00127 #define LBA48_CHECK_SIZE 0x0f000000
00128 #define LBA_MAX_SIZE 0x0fffffff
00129
00130
00131
00132 #if ENABLE_ATAPI
00133 #define ERROR_SENSE 0xF0
00134 #define SENSE_NONE 0x00
00135 #define SENSE_RECERR 0x10
00136 #define SENSE_NOTRDY 0x20
00137 #define SENSE_MEDERR 0x30
00138 #define SENSE_HRDERR 0x40
00139 #define SENSE_ILRQST 0x50
00140 #define SENSE_UATTN 0x60
00141 #define SENSE_DPROT 0x70
00142 #define SENSE_ABRT 0xb0
00143 #define SENSE_MISCOM 0xe0
00144 #define ERROR_MCR 0x08
00145 #define ERROR_ABRT 0x04
00146 #define ERROR_EOM 0x02
00147 #define ERROR_ILI 0x01
00148 #define REG_FEAT 1
00149 #define FEAT_OVERLAP 0x02
00150 #define FEAT_DMA 0x01
00151 #define REG_IRR 2
00152 #define IRR_REL 0x04
00153 #define IRR_IO 0x02
00154 #define IRR_COD 0x01
00155 #define REG_SAMTAG 3
00156 #define REG_CNT_LO 4
00157 #define REG_CNT_HI 5
00158 #define REG_DRIVE 6
00159 #endif
00160
00161 #define REG_STATUS 7
00162 #define STATUS_BSY 0x80
00163 #define STATUS_DRDY 0x40
00164 #define STATUS_DMADF 0x20
00165 #define STATUS_SRVCDSC 0x10
00166 #define STATUS_DRQ 0x08
00167 #define STATUS_CORR 0x04
00168 #define STATUS_CHECK 0x01
00169
00170 #if ENABLE_ATAPI
00171 #define ATAPI_PACKETCMD 0xA0
00172 #define ATAPI_IDENTIFY 0xA1
00173 #define SCSI_READ10 0x28
00174 #define SCSI_SENSE 0x03
00175
00176 #define CD_SECTOR_SIZE 2048
00177 #endif
00178
00179
00180 #define NO_IRQ 0
00181
00182 #define ATAPI_PACKETSIZE 12
00183 #define SENSE_PACKETSIZE 18
00184
00185
00186 #define ERR (-1)
00187 #define ERR_BAD_SECTOR (-2)
00188
00189
00190 #define WAKEUP_SECS 32
00191 #define WAKEUP_TICKS (WAKEUP_SECS*system_hz)
00192
00193
00194 #define MAX_DRIVES 8
00195 #define COMPAT_DRIVES 4
00196 #if _WORD_SIZE > 2
00197 #define MAX_SECS 256
00198 #else
00199 #define MAX_SECS 127
00200 #endif
00201 #define MAX_ERRORS 4
00202 #define NR_MINORS (MAX_DRIVES * DEV_PER_DRIVE)
00203 #define SUB_PER_DRIVE (NR_PARTITIONS * NR_PARTITIONS)
00204 #define NR_SUBDEVS (MAX_DRIVES * SUB_PER_DRIVE)
00205 #define DELAY_USECS 1000
00206 #define DELAY_TICKS 1
00207 #define DEF_TIMEOUT_TICKS 300
00208 #define RECOVERY_USECS 500000
00209 #define RECOVERY_TICKS 30
00210 #define INITIALIZED 0x01
00211 #define DEAF 0x02
00212 #define SMART 0x04
00213 #if ENABLE_ATAPI
00214 #define ATAPI 0x08
00215 #else
00216 #define ATAPI 0
00217 #endif
00218 #define IDENTIFIED 0x10
00219 #define IGNORING 0x20
00220
00221 #define NO_DMA_VAR "ata_no_dma"
00222