/* $Id: atalib.h 74 2015-12-21 00:40:51Z bird $ */ /** @file * Does a little write test. */ /* * Copyright (c) 2015 knut st. osmundsen * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with This program. If not, see * */ #ifndef ___atalib_h___ #define ___atalib_h___ #include /* The necessary I/O ports, indexed by "bus". */ #define ATA_PORT_SHIFT (g_cPortShift) /* For XT-CF trick */ #define ATA_REG_DATA(a_uBasePort) (a_uBasePort) #define ATA_REG_FEATURES(a_uBasePort) ((a_uBasePort) + (1 << ATA_PORT_SHIFT)) #define ATA_REG_SECTOR_COUNT(a_uBasePort) ((a_uBasePort) + (2 << ATA_PORT_SHIFT)) #define ATA_REG_SECTOR_NUMBER(a_uBasePort) ((a_uBasePort) + (3 << ATA_PORT_SHIFT)) #define ATA_REG_CYLINDER_LOW(a_uBasePort) ((a_uBasePort) + (4 << ATA_PORT_SHIFT)) #define ATA_REG_CYLINDER_HIGH(a_uBasePort) ((a_uBasePort) + (5 << ATA_PORT_SHIFT)) #define ATA_REG_HEAD(a_uBasePort) ((a_uBasePort) + (6 << ATA_PORT_SHIFT)) #define ATA_REG_LBA_0_7(a_uBasePort) ((a_uBasePort) + (3 << ATA_PORT_SHIFT)) #define ATA_REG_LBA_8_15(a_uBasePort) ((a_uBasePort) + (4 << ATA_PORT_SHIFT)) #define ATA_REG_LBA_16_23(a_uBasePort) ((a_uBasePort) + (5 << ATA_PORT_SHIFT)) #define ATA_REG_LBA_24_27_MODE(a_uBasePort) ((a_uBasePort) + (6 << ATA_PORT_SHIFT)) #define ATA_LBA_MODE UINT8_C(0x40) /**< Selects LBA mode in ATA_REG_LBA_24_27_MODE. */ #define ATA_REG_DEVICE_SELECT(a_uBasePort) ((a_uBasePort) + (6 << ATA_PORT_SHIFT)) #define ATA_REG_COMMAND(a_uBasePort) ((a_uBasePort) + (7 << ATA_PORT_SHIFT)) #define ATA_REG_STATUS(a_uBasePort) ATA_REG_COMMAND(a_uBasePort) #define ATA_REG_ALT_STATUS(a_uCtrlPort) ATA_REG_CONTROL(a_uCtrlPort) #define ATA_STS_BUSY UINT8_C(0x80) #define ATA_STS_DRDY UINT8_C(0x40) #define ATA_STS_DF UINT8_C(0x20) #define ATA_STS_DSC UINT8_C(0x10) #define ATA_STS_DRQ UINT8_C(0x08) #define ATA_STS_CORR UINT8_C(0x04) #define ATA_STS_IDX UINT8_C(0x02) #define ATA_STS_ERR UINT8_C(0x01) #define ATA_REG_ERROR(a_uBasePort) ATA_REG_FEATURES(a_uBasePort) #define ATA_ERR_RSVR UINT8_C(0x80) #define ATA_ERR_UNC UINT8_C(0x40) #define ATA_ERR_MC UINT8_C(0x20) #define ATA_ERR_IDNF UINT8_C(0x10) #define ATA_ERR_MCR UINT8_C(0x08) #define ATA_ERR_ABRT UINT8_C(0x04) #define ATA_ERR_TKNONF UINT8_C(0x02) #define ATA_ERR_AMNF UINT8_C(0x01) #define ATA_REG_CONTROL(a_uCtrlPort) ((a_uCtrlPort) + (6 << ATA_PORT_SHIFT)) #define ATA_CTL_IEN UINT8_C(0x02) /**< Interrupt enable. */ #define ATA_CTL_SRST UINT8_C(0x04) /**< software reset */ #define ATA_CMD_NOP UINT8_C(0x00) #define ATA_CMD_READ_SECTORS UINT8_C(0x20) #define ATA_CMD_READ_SECTORS_NR UINT8_C(0x21) #define ATA_CMD_READ_LONG UINT8_C(0x22) #define ATA_CMD_READ_LONG_NR UINT8_C(0x23) #define ATA_CMD_READ_BUFFER UINT8_C(0xe4) #define ATA_CMD_WRITE_SECTORS UINT8_C(0x30) #define ATA_CMD_WRITE_SECTORS_NR UINT8_C(0x31) #define ATA_CMD_WRITE_LONG UINT8_C(0x32) #define ATA_CMD_WRITE_LONG_NR UINT8_C(0x33) #define ATA_CMD_WRITE_BUFFER UINT8_C(0xe8) #define ATA_CMD_INIT_DEVICE_PARAMS UINT8_C(0x91) #define ATA_CMD_SET_FEATURES UINT8_C(0xef) #define ATA_CMD_IDENTIFY_DEVICE UINT8_C(0xec) #define ATA_DEV_MASTER UINT8_C(0x00) /**< Master device selection bit value. */ #define ATA_DEV_SLAVE UINT8_C(0x10) /**< Slave device selection bit value. */ #define ATA_FEATURE_EN_8BIT_DATA UINT8_C(0x01) #define ATA_FEATURE_DI_8BIT_DATA UINT8_C(0x81) #define ATA_FEATURE_EN_WRITE_CACHE UINT8_C(0x02) #define ATA_FEATURE_DI_WRITE_CACHE UINT8_C(0x82) #define ATA_FEATURE_SET_XFERMODE UINT8_C(0x03) #define ATA_FV_XFERMODE_PIO_MODE_DEFAULT UINT8_C(0x00) #define ATA_FV_XFERMODE_PIO_MODE_DEFAULT_NO_IORDY UINT8_C(0x01) #define ATA_FV_XFERMODE_PIO_MODE_XXX_FLAG UINT8_C(0x08) #define ATA_FV_XFERMODE_SWDMA_MODE_XXX_FLAG UINT8_C(0x10) #define ATA_FV_XFERMODE_MWDMA_MODE_XXX_FLAG UINT8_C(0x20) /** Delay a bit by reading PIC mask. Should take 4-5 bus cycles, * and thus be more than the required 400ns delay on old computers. */ #define ATA_DELAY_400NS() do { inp(0x21); } while (0) extern uint16_t g_cHeads; extern uint8_t g_cSectorsPerTrack; extern uint16_t g_cCylinders; extern uint16_t g_cSectorsPerCylinder; extern uint16_t g_awIdentify[256]; int AtaInit(uint16_t uBasePort, uint16_t uCtrlPort, uint8_t uPortShift, uint8_t bDevice, uint8_t f8BitData); int AtaInitFromArgv(int iArg, int cArgs, char **papszArgs); int AtaReInit(void); int AtaReset(void); int AtaIdentifyDevice(uint8_t bDevice, void *pvBuf); int AtaInitDeviceParams(uint8_t bDevice, uint8_t cSectorsPerTrack, uint8_t cHeads); int AtaSetFeature(uint8_t bDevice, uint8_t bFeature, uint8_t bValue); int AtaWriteSector(uint32_t iSector, void const *pvBuf); int AtaReadSector(uint32_t iSector, void *pvBuf); int AtaWriteBuffer(void const *pvBuf, uint8_t fExtraChecks); int AtaReadBuffer(void *pvBuf, uint8_t fExtraChecks); void AtaWriteData(void const *pvBuf, size_t cb, uint8_t f8BitData); void AtaReadData(void *pvBuf, size_t cb, uint8_t f8BitData); #endif