ata_hw.h

00001 /*
00002  * Copyright (c) 2009 Jiri Svoboda
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #ifndef __ATA_HW_H__
00036 #define __ATA_HW_H__
00037 
00038 #include <sys/types.h>
00039 
00040 enum {
00041         CTL_READ_START  = 0,
00042         CTL_WRITE_START = 1,
00043 };
00044 
00045 enum {
00046         STATUS_FAILURE = 0
00047 };
00048 
00049 enum {
00050         MAX_DISKS       = 2
00051 };
00052 
00054 typedef union {
00055         /* Read/Write */
00056         struct {
00057                 uint16_t data_port;
00058                 uint8_t sector_count;
00059                 uint8_t sector_number;
00060                 uint8_t cylinder_low;
00061                 uint8_t cylinder_high;
00062                 uint8_t drive_head;
00063                 uint8_t pad_rw0;
00064         };
00065 
00066         /* Read Only */
00067         struct {
00068                 uint8_t pad_ro0;
00069                 uint8_t error;
00070                 uint8_t pad_ro1[5];
00071                 uint8_t status;
00072         };
00073 
00074         /* Write Only */
00075         struct {
00076                 uint8_t pad_wo0;
00077                 uint8_t features;
00078                 uint8_t pad_wo1[5];
00079                 uint8_t command;
00080         };
00081 } ata_cmd_t;
00082 
00083 typedef union {
00084         /* Read */
00085         struct {
00086                 uint8_t pad0[6];
00087                 uint8_t alt_status;
00088                 uint8_t drive_address;
00089         };
00090 
00091         /* Write */
00092         struct {
00093                 uint8_t pad1[6];
00094                 uint8_t device_control;
00095                 uint8_t pad2;
00096         };
00097 } ata_ctl_t;
00098 
00099 enum devctl_bits {
00100         DCR_SRST        = 0x04, 
00101         DCR_nIEN        = 0x02  
00102 };
00103 
00104 enum status_bits {
00105         SR_BSY          = 0x80, 
00106         SR_DRDY         = 0x40, 
00107         SR_DWF          = 0x20, 
00108         SR_DSC          = 0x10, 
00109         SR_DRQ          = 0x08, 
00110         SR_CORR         = 0x04, 
00111         SR_IDX          = 0x02, 
00112         SR_ERR          = 0x01  
00113 };
00114 
00115 enum drive_head_bits {
00116         DHR_LBA         = 0x40, 
00117         DHR_DRV         = 0x10  
00118 };
00119 
00120 enum error_bits {
00121         ER_BBK          = 0x80, 
00122         ER_UNC          = 0x40, 
00123         ER_MC           = 0x20, 
00124         ER_IDNF         = 0x10, 
00125         ER_MCR          = 0x08, 
00126         ER_ABRT         = 0x04, 
00127         ER_TK0NF        = 0x02, 
00128         ER_AMNF         = 0x01  
00129 };
00130 
00131 enum ata_command {
00132         CMD_READ_SECTORS        = 0x20,
00133         CMD_READ_SECTORS_EXT    = 0x24,
00134         CMD_WRITE_SECTORS       = 0x30,
00135         CMD_WRITE_SECTORS_EXT   = 0x34,
00136         CMD_PACKET              = 0xA0,
00137         CMD_IDENTIFY_PKT_DEV    = 0xA1,
00138         CMD_IDENTIFY_DRIVE      = 0xEC
00139 };
00140 
00142 typedef struct {
00143         uint16_t gen_conf;
00144         uint16_t cylinders;
00145         uint16_t _res2;
00146         uint16_t heads;
00147         uint16_t _vs4;
00148         uint16_t _vs5;
00149         uint16_t sectors;
00150         uint16_t _vs7;
00151         uint16_t _vs8;
00152         uint16_t _vs9;
00153 
00154         uint16_t serial_number[10];
00155         uint16_t _vs20;
00156         uint16_t _vs21;
00157         uint16_t vs_bytes;
00158         uint16_t firmware_rev[4];
00159         uint16_t model_name[20];
00160 
00161         uint16_t max_rw_multiple;
00162         uint16_t _res48;
00163         uint16_t caps;          /* Different meaning for packet device */
00164         uint16_t _res50;
00165         uint16_t pio_timing;
00166         uint16_t dma_timing;
00167 
00168         uint16_t validity;
00169         uint16_t cur_cyl;
00170         uint16_t cur_heads;
00171         uint16_t cur_sectors;
00172         uint16_t cur_capacity0;
00173         uint16_t cur_capacity1;
00174         uint16_t mss;
00175         uint16_t total_lba28_0;
00176         uint16_t total_lba28_1;
00177         uint16_t sw_dma;
00178         uint16_t mw_dma;
00179         uint16_t pio_modes;
00180         uint16_t min_mw_dma_cycle;
00181         uint16_t rec_mw_dma_cycle;
00182         uint16_t min_raw_pio_cycle;
00183         uint16_t min_iordy_pio_cycle;
00184 
00185         uint16_t _res69;
00186         uint16_t _res70;
00187         uint16_t _res71;
00188         uint16_t _res72;
00189         uint16_t _res73;
00190         uint16_t _res74;
00191 
00192         uint16_t queue_depth;
00193         uint16_t _res76[1 + 79 - 76];
00194         uint16_t version_maj;
00195         uint16_t version_min;
00196         uint16_t cmd_set0;
00197         uint16_t cmd_set1;
00198         uint16_t csf_sup_ext;
00199         uint16_t csf_enabled0;
00200         uint16_t csf_enabled1;
00201         uint16_t csf_default;
00202         uint16_t udma;
00203 
00204         uint16_t _res89[1 + 99 - 89];
00205 
00206         /* Total number of blocks in LBA-48 addressing */
00207         uint16_t total_lba48_0;
00208         uint16_t total_lba48_1;
00209         uint16_t total_lba48_2;
00210         uint16_t total_lba48_3;
00211 
00212         /* Note: more fields are defined in ATA/ATAPI-7 */
00213         uint16_t _res104[1 + 127 - 104];
00214         uint16_t _vs128[1 + 159 - 128];
00215         uint16_t _res160[1 + 255 - 160];
00216 } identify_data_t;
00217 
00219 enum ata_regdev_caps {
00220         rd_cap_iordy            = 0x0800,
00221         rd_cap_iordy_cbd        = 0x0400,
00222         rd_cap_lba              = 0x0200,
00223         rd_cap_dma              = 0x0100
00224 };
00225 
00227 enum ata_pktdev_caps {
00228         pd_cap_ildma            = 0x8000,
00229         pd_cap_cmdqueue         = 0x4000,
00230         pd_cap_overlap          = 0x2000,
00231         pd_cap_need_softreset   = 0x1000,       /* Obsolete (ATAPI-6) */
00232         pd_cap_iordy            = 0x0800,
00233         pd_cap_iordy_dis        = 0x0400,
00234         pd_cap_lba              = 0x0200,       /* Must be on */
00235         pd_cap_dma              = 0x0100
00236 };
00237 
00239 enum ata_cs1 {
00240         cs1_addr48      = 0x0400        
00241 };
00242 
00244 enum ata_pkt_command {
00245         PCMD_INQUIRY            = 0x12,
00246         PCMD_READ_12            = 0xa8
00247 };
00248 
00250 typedef struct {
00251         uint8_t opcode;         
00252         uint8_t _res0;
00253         uint8_t _res1;
00254         uint8_t _res2;
00255         uint8_t alloc_len;      
00256         uint8_t _res3;
00257         uint8_t _res4;
00258         uint8_t _res5;
00259         uint32_t _res6;
00260 } __attribute__ ((packed)) ata_pcmd_inquiry_t;
00261 
00263 typedef struct {
00264         uint8_t opcode;         
00265         uint8_t _res0;
00266         uint32_t ba;            
00267         uint32_t nblocks;       
00268         uint8_t _res1;
00269         uint8_t _res2;
00270 } __attribute__ ((packed)) ata_pcmd_read_12_t;
00271 
00273 typedef struct {
00274         uint8_t pdev_type;      
00275         uint8_t rmb;            
00276         uint8_t std_version;    
00277         uint8_t atapi_ver_rdf;  
00278         uint8_t additional_len; 
00279         uint8_t _res0;
00280         uint8_t _res1;
00281         uint8_t _res2;
00282         uint8_t vendor_id[8];   
00283         uint8_t product_id[8];  
00284         uint8_t product_rev[4]; 
00285 } ata_inquiry_data_t;
00286 
00288 #define INQUIRY_PDEV_TYPE(val) ((val) & 0x1f)
00289 
00291 enum ata_pdev_type {
00292         PDEV_TYPE_CDROM         = 0x05
00293 };
00294 
00295 enum ata_pdev_signature {
00300         PDEV_SIGNATURE_BC       = 0xEB14
00301 };
00302 
00303 #endif
00304 

Generated on Thu Jun 2 07:45:49 2011 for HelenOS/USB by  doxygen 1.4.7