1*2813126eSlogin #pragma once 2*2813126eSlogin 3*2813126eSlogin #include <common/glib.h> 4*2813126eSlogin 5*2813126eSlogin // ======== PIO端口定义 ======== 6*2813126eSlogin #define PORT_DISK0_DATA 0x1f0 // 数据 7*2813126eSlogin #define PORT_DISK0_ERR_STATUS 0x1f1 // 错误状态 8*2813126eSlogin #define PORT_DISK0_SECTOR_CNT 0x1f2 // 操作扇区数 9*2813126eSlogin #define PORT_DISK0_LBA_7_0 0x1f3 // 扇区号 / LBA[7:0] 10*2813126eSlogin #define PORT_DISK0_LBA_15_8 0x1f4 // 柱面号[7:0] / LBA[15:8] 11*2813126eSlogin #define PORT_DISK0_LBA_23_16 0x1f5 // 柱面号[15:8] / LBA[23:16] 12*2813126eSlogin #define PORT_DISK0_DEVICE_CONFIGURE_REG 0x1f6 // 设备配置寄存器 13*2813126eSlogin #define PORT_DISK0_CONTROLLER_STATUS_CMD 0x1f7 // 控制器状态端口 / 控制器命令端口 14*2813126eSlogin #define PORT_DISK0_STATUS_CTRL_REG 0x3f6 // 状态寄存器 / 控制寄存器 15*2813126eSlogin 16*2813126eSlogin #define PORT_DISK1_DATA 0x170 // 数据 17*2813126eSlogin #define PORT_DISK1_ERR_STATUS 0x171 // 错误状态 18*2813126eSlogin #define PORT_DISK1_SECTOR_CNT 0x172 // 操作扇区数 19*2813126eSlogin #define PORT_DISK1_LBA_7_0 0x173 // 扇区号 / LBA[7:0] 20*2813126eSlogin #define PORT_DISK1_LBA_15_8 0x174 // 柱面号[7:0] / LBA[15:8] 21*2813126eSlogin #define PORT_DISK1_LBA_23_16 0x175 // 柱面号[15:8] / LBA[23:16] 22*2813126eSlogin #define PORT_DISK1_DEVICE_CONFIGURE_REG 0x176 // 设备配置寄存器 23*2813126eSlogin #define PORT_DISK1_CONTROLLER_STATUS_CMD 0x177 // 控制器状态端口 / 控制器命令端口 24*2813126eSlogin #define PORT_DISK1_STATUS_CTRL_REG 0x376 // 状态寄存器 / 控制寄存器 25*2813126eSlogin 26*2813126eSlogin // ======= 状态寄存器的状态位 ========== 27*2813126eSlogin #define DISK_STATUS_BUSY (1 << 7) // 控制器忙 28*2813126eSlogin #define DISK_STATUS_READY (1 << 6) // 驱动器准备就绪 29*2813126eSlogin #define DISK_STATUS_SEEK (1 << 4) // 驱动器寻道 30*2813126eSlogin #define DISK_STATUS_DATA_REQ (1 << 3) // 数据请求 31*2813126eSlogin #define DISK_STATUS_DATA_ERROR (1 << 0) // 命令执行错误 32*2813126eSlogin 33*2813126eSlogin /** 34*2813126eSlogin * @brief 执行0xec指令返回的512bytes的硬件设备识别信息 35*2813126eSlogin * 位于ATA8-ACS中 Table-22 36*2813126eSlogin */ 37*2813126eSlogin struct ata_identify_device_data 38*2813126eSlogin { 39*2813126eSlogin // 0 General configuration bit-significant information 40*2813126eSlogin unsigned short General_Config; 41*2813126eSlogin 42*2813126eSlogin // 1 Obsolete 43*2813126eSlogin unsigned short Obsolete0; 44*2813126eSlogin 45*2813126eSlogin // 2 Specific configuration 46*2813126eSlogin unsigned short Specific_Coinfig; 47*2813126eSlogin 48*2813126eSlogin // 3 Obsolete 49*2813126eSlogin unsigned short Obsolete1; 50*2813126eSlogin 51*2813126eSlogin // 4-5 Retired 52*2813126eSlogin unsigned short Retired0[2]; 53*2813126eSlogin 54*2813126eSlogin // 6 Obsolete 55*2813126eSlogin unsigned short Obsolete2; 56*2813126eSlogin 57*2813126eSlogin // 7-8 Reserved for the CompactFlash Association 58*2813126eSlogin unsigned short CompactFlash[2]; 59*2813126eSlogin 60*2813126eSlogin // 9 Retired 61*2813126eSlogin unsigned short Retired1; 62*2813126eSlogin 63*2813126eSlogin // 10-19 Serial number (20 ASCII characters) 64*2813126eSlogin unsigned short Serial_Number[10]; 65*2813126eSlogin 66*2813126eSlogin // 20-21 Retired 67*2813126eSlogin unsigned short Retired2[2]; 68*2813126eSlogin 69*2813126eSlogin // 22 Obsolete 70*2813126eSlogin unsigned short Obsolete3; 71*2813126eSlogin 72*2813126eSlogin // 23-26 Firmware revision(8 ASCII characters) 73*2813126eSlogin unsigned short Firmware_Version[4]; 74*2813126eSlogin 75*2813126eSlogin // 27-46 Model number (40 ASCII characters) 76*2813126eSlogin unsigned short Model_Number[20]; 77*2813126eSlogin 78*2813126eSlogin // 47 15:8 80h 79*2813126eSlogin // 7:0 00h=Reserved 80*2813126eSlogin // 01h-FFh = Maximumnumber of logical sectors that shall be transferred per DRQ data block on READ/WRITE MULTIPLE commands 81*2813126eSlogin unsigned short Max_logical_transferred_per_DRQ; 82*2813126eSlogin 83*2813126eSlogin // 48 Trusted Computing feature set options 84*2813126eSlogin unsigned short Trusted_Computing_feature_set_options; 85*2813126eSlogin 86*2813126eSlogin // 49 Capabilities 87*2813126eSlogin unsigned short Capabilities0; 88*2813126eSlogin 89*2813126eSlogin // 50 Capabilities 90*2813126eSlogin unsigned short Capabilities1; 91*2813126eSlogin 92*2813126eSlogin // 51-52 Obsolete 93*2813126eSlogin unsigned short Obsolete4[2]; 94*2813126eSlogin 95*2813126eSlogin // 53 15:8 Free-fall Control Sensitivity 96*2813126eSlogin // 7:3 Reserved 97*2813126eSlogin // 2 the fields reported in word 88 are valid 98*2813126eSlogin // 1 the fields reported in words (70:64) are valid 99*2813126eSlogin unsigned short Report_88_70to64_valid; 100*2813126eSlogin 101*2813126eSlogin // 54-58 Obsolete 102*2813126eSlogin unsigned short Obsolete5[5]; 103*2813126eSlogin 104*2813126eSlogin // 59 15:9 Reserved 105*2813126eSlogin // 8 Multiple sector setting is valid 106*2813126eSlogin // 7:0 xxh current setting for number of logical sectors that shall be transferred per DRQ data block on READ/WRITE Multiple commands 107*2813126eSlogin unsigned short Mul_Sec_Setting_Valid; 108*2813126eSlogin 109*2813126eSlogin // 60-61 Total number of user addresssable logical sectors for 28bit CMD 110*2813126eSlogin unsigned short Addressable_Logical_Sectors_for_28[2]; 111*2813126eSlogin 112*2813126eSlogin // 62 Obsolete 113*2813126eSlogin unsigned short Obsolete6; 114*2813126eSlogin 115*2813126eSlogin // 63 15:11 Reserved 116*2813126eSlogin // 10:8=1 Multiword DMA mode 210 is selected 117*2813126eSlogin // 7:3 Reserved 118*2813126eSlogin // 2:0=1 Multiword DMA mode 210 and below are supported 119*2813126eSlogin unsigned short MultWord_DMA_Select; 120*2813126eSlogin 121*2813126eSlogin // 64 15:8 Reserved 122*2813126eSlogin // 7:0 PIO mdoes supported 123*2813126eSlogin unsigned short PIO_mode_supported; 124*2813126eSlogin 125*2813126eSlogin // 65 Minimum Multiword DMA transfer cycle time per word 126*2813126eSlogin unsigned short Min_MulWord_DMA_cycle_time_per_word; 127*2813126eSlogin 128*2813126eSlogin // 66 Manufacturer`s recommended Multiword DMA transfer cycle time 129*2813126eSlogin unsigned short Manufacture_Recommend_MulWord_DMA_cycle_time; 130*2813126eSlogin 131*2813126eSlogin // 67 Minimum PIO transfer cycle time without flow control 132*2813126eSlogin unsigned short Min_PIO_cycle_time_Flow_Control; 133*2813126eSlogin 134*2813126eSlogin // 68 Minimum PIO transfer cycle time with IORDY flow control 135*2813126eSlogin unsigned short Min_PIO_cycle_time_IOREDY_Flow_Control; 136*2813126eSlogin 137*2813126eSlogin // 69-70 Reserved 138*2813126eSlogin unsigned short Reserved1[2]; 139*2813126eSlogin 140*2813126eSlogin // 71-74 Reserved for the IDENTIFY PACKET DEVICE command 141*2813126eSlogin unsigned short Reserved2[4]; 142*2813126eSlogin 143*2813126eSlogin // 75 Queue depth 144*2813126eSlogin unsigned short Queue_depth; 145*2813126eSlogin 146*2813126eSlogin // 76 Serial ATA Capabilities 147*2813126eSlogin unsigned short SATA_Capabilities; 148*2813126eSlogin 149*2813126eSlogin // 77 Reserved for Serial ATA 150*2813126eSlogin unsigned short Reserved3; 151*2813126eSlogin 152*2813126eSlogin // 78 Serial ATA features Supported 153*2813126eSlogin unsigned short SATA_features_Supported; 154*2813126eSlogin 155*2813126eSlogin // 79 Serial ATA features enabled 156*2813126eSlogin unsigned short SATA_features_enabled; 157*2813126eSlogin 158*2813126eSlogin // 80 Major Version number 159*2813126eSlogin unsigned short Major_Version; 160*2813126eSlogin 161*2813126eSlogin // 81 Minor version number 162*2813126eSlogin unsigned short Minor_Version; 163*2813126eSlogin 164*2813126eSlogin // 82 Commands and feature sets supported 165*2813126eSlogin unsigned short Cmd_feature_sets_supported0; 166*2813126eSlogin 167*2813126eSlogin // 83 Commands and feature sets supported 168*2813126eSlogin unsigned short Cmd_feature_sets_supported1; 169*2813126eSlogin 170*2813126eSlogin // 84 Commands and feature sets supported 171*2813126eSlogin unsigned short Cmd_feature_sets_supported2; 172*2813126eSlogin 173*2813126eSlogin // 85 Commands and feature sets supported or enabled 174*2813126eSlogin unsigned short Cmd_feature_sets_supported3; 175*2813126eSlogin 176*2813126eSlogin // 86 Commands and feature sets supported or enabled 177*2813126eSlogin unsigned short Cmd_feature_sets_supported4; 178*2813126eSlogin 179*2813126eSlogin // 87 Commands and feature sets supported or enabled 180*2813126eSlogin unsigned short Cmd_feature_sets_supported5; 181*2813126eSlogin 182*2813126eSlogin // 88 15 Reserved 183*2813126eSlogin // 14:8=1 Ultra DMA mode 6543210 is selected 184*2813126eSlogin // 7 Reserved 185*2813126eSlogin // 6:0=1 Ultra DMA mode 6543210 and below are suported 186*2813126eSlogin unsigned short Ultra_DMA_modes; 187*2813126eSlogin 188*2813126eSlogin // 89 Time required for Normal Erase mode SECURITY ERASE UNIT command 189*2813126eSlogin unsigned short Time_required_Erase_CMD; 190*2813126eSlogin 191*2813126eSlogin // 90 Time required for an Enhanced Erase mode SECURITY ERASE UNIT command 192*2813126eSlogin unsigned short Time_required_Enhanced_CMD; 193*2813126eSlogin 194*2813126eSlogin // 91 Current APM level value 195*2813126eSlogin unsigned short Current_APM_level_Value; 196*2813126eSlogin 197*2813126eSlogin // 92 Master Password Identifier 198*2813126eSlogin unsigned short Master_Password_Identifier; 199*2813126eSlogin 200*2813126eSlogin // 93 Hardware resset result.The contents of bits (12:0) of this word shall change only during the execution of a hardware reset. 201*2813126eSlogin unsigned short HardWare_Reset_Result; 202*2813126eSlogin 203*2813126eSlogin // 94 Current AAM value 204*2813126eSlogin // 15:8 Vendor’s recommended AAM value 205*2813126eSlogin // 7:0 Current AAM value 206*2813126eSlogin unsigned short Current_AAM_value; 207*2813126eSlogin 208*2813126eSlogin // 95 Stream Minimum Request Size 209*2813126eSlogin unsigned short Stream_Min_Request_Size; 210*2813126eSlogin 211*2813126eSlogin // 96 Streaming Transger Time-DMA 212*2813126eSlogin unsigned short Streaming_Transger_time_DMA; 213*2813126eSlogin 214*2813126eSlogin // 97 Streaming Access Latency-DMA and PIO 215*2813126eSlogin unsigned short Streaming_Access_Latency_DMA_PIO; 216*2813126eSlogin 217*2813126eSlogin // 98-99 Streaming Performance Granularity (DWord) 218*2813126eSlogin unsigned short Streaming_Performance_Granularity[2]; 219*2813126eSlogin 220*2813126eSlogin // 100-103 Total Number of User Addressable Logical Sectors for 48-bit commands (QWord) 221*2813126eSlogin unsigned short Total_user_LBA_for_48_Address_Feature_set[4]; 222*2813126eSlogin 223*2813126eSlogin // 104 Streaming Transger Time-PIO 224*2813126eSlogin unsigned short Streaming_Transfer_Time_PIO; 225*2813126eSlogin 226*2813126eSlogin // 105 Reserved 227*2813126eSlogin unsigned short Reserved4; 228*2813126eSlogin 229*2813126eSlogin // 106 Physical Sector size/Logical Sector Size 230*2813126eSlogin unsigned short Physical_Logical_Sector_Size; 231*2813126eSlogin 232*2813126eSlogin // 107 Inter-seek delay for ISO-7779 acoustic testing in microseconds 233*2813126eSlogin unsigned short Inter_seek_delay; 234*2813126eSlogin 235*2813126eSlogin // 108-111 World wide name 236*2813126eSlogin unsigned short World_wide_name[4]; 237*2813126eSlogin 238*2813126eSlogin // 112-115 Reserved 239*2813126eSlogin unsigned short Reserved5[4]; 240*2813126eSlogin 241*2813126eSlogin // 116 Reserved for TLC 242*2813126eSlogin unsigned short Reserved6; 243*2813126eSlogin 244*2813126eSlogin // 117-118 Logical sector size (DWord) 245*2813126eSlogin unsigned short Words_per_Logical_Sector[2]; 246*2813126eSlogin 247*2813126eSlogin // 119 Commands and feature sets supported (Continued from words 84:82) 248*2813126eSlogin unsigned short CMD_feature_Supported; 249*2813126eSlogin 250*2813126eSlogin // 120 Commands and feature sets supported or enabled (Continued from words 87:85) 251*2813126eSlogin unsigned short CMD_feature_Supported_enabled; 252*2813126eSlogin 253*2813126eSlogin // 121-126 Reserved for expanded supported and enabled settings 254*2813126eSlogin unsigned short Reserved7[6]; 255*2813126eSlogin 256*2813126eSlogin // 127 Obsolete 257*2813126eSlogin unsigned short Obsolete7; 258*2813126eSlogin 259*2813126eSlogin // 128 Security status 260*2813126eSlogin unsigned short Security_Status; 261*2813126eSlogin 262*2813126eSlogin // 129-159 Vendor specific 263*2813126eSlogin unsigned short Vendor_Specific[31]; 264*2813126eSlogin 265*2813126eSlogin // 160 CFA power mode 266*2813126eSlogin unsigned short CFA_Power_mode; 267*2813126eSlogin 268*2813126eSlogin // 161-167 Reserved for the CompactFlash Association 269*2813126eSlogin unsigned short Reserved8[7]; 270*2813126eSlogin 271*2813126eSlogin // 168 Device Nominal Form Factor 272*2813126eSlogin unsigned short Dev_from_Factor; 273*2813126eSlogin 274*2813126eSlogin // 169-175 Reserved 275*2813126eSlogin unsigned short Reserved9[7]; 276*2813126eSlogin 277*2813126eSlogin // 176-205 Current media serial number (ATA string) 278*2813126eSlogin unsigned short Current_Media_Serial_Number[30]; 279*2813126eSlogin 280*2813126eSlogin // 206 SCT Command Transport 281*2813126eSlogin unsigned short SCT_Cmd_Transport; 282*2813126eSlogin 283*2813126eSlogin // 207-208 Reserved for CE-ATA 284*2813126eSlogin unsigned short Reserved10[2]; 285*2813126eSlogin 286*2813126eSlogin // 209 Alignment of logical blocks within a physical block 287*2813126eSlogin unsigned short Alignment_Logical_blocks_within_a_physical_block; 288*2813126eSlogin 289*2813126eSlogin // 210-211 Write-Read-Verify Sector Count Mode 3 (DWord) 290*2813126eSlogin unsigned short Write_Read_Verify_Sector_Count_Mode_3[2]; 291*2813126eSlogin 292*2813126eSlogin // 212-213 Write-Read-Verify Sector Count Mode 2 (DWord) 293*2813126eSlogin unsigned short Write_Read_Verify_Sector_Count_Mode_2[2]; 294*2813126eSlogin 295*2813126eSlogin // 214 NV Cache Capabilities 296*2813126eSlogin unsigned short NV_Cache_Capabilities; 297*2813126eSlogin 298*2813126eSlogin // 215-216 NV Cache Size in Logical Blocks (DWord) 299*2813126eSlogin unsigned short NV_Cache_Size[2]; 300*2813126eSlogin 301*2813126eSlogin // 217 Nominal media rotation rate 302*2813126eSlogin unsigned short Nominal_media_rotation_rate; 303*2813126eSlogin 304*2813126eSlogin // 218 Reserved 305*2813126eSlogin unsigned short Reserved11; 306*2813126eSlogin 307*2813126eSlogin // 219 NV Cache Options 308*2813126eSlogin unsigned short NV_Cache_Options; 309*2813126eSlogin 310*2813126eSlogin // 220 Write-Read-Verify feature set current mode 311*2813126eSlogin unsigned short Write_Read_Verify_feature_set_current_mode; 312*2813126eSlogin 313*2813126eSlogin // 221 Reserved 314*2813126eSlogin unsigned short Reserved12; 315*2813126eSlogin 316*2813126eSlogin // 222 Transport major version number. 317*2813126eSlogin // 0000h or ffffh = device does not report version 318*2813126eSlogin unsigned short Transport_Major_Version_Number; 319*2813126eSlogin 320*2813126eSlogin // 223 Transport Minor version number 321*2813126eSlogin unsigned short Transport_Minor_Version_Number; 322*2813126eSlogin 323*2813126eSlogin // 224-233 Reserved for CE-ATA 324*2813126eSlogin unsigned short Reserved13[10]; 325*2813126eSlogin 326*2813126eSlogin // 234 Minimum number of 512-byte data blocks per DOWNLOAD MICROCODE command for mode 03h 327*2813126eSlogin unsigned short Mini_blocks_per_CMD; 328*2813126eSlogin 329*2813126eSlogin // 235 Maximum number of 512-byte data blocks per DOWNLOAD MICROCODE command for mode 03h 330*2813126eSlogin unsigned short Max_blocks_per_CMD; 331*2813126eSlogin 332*2813126eSlogin // 236-254 Reserved 333*2813126eSlogin unsigned short Reserved14[19]; 334*2813126eSlogin 335*2813126eSlogin // 255 Integrity word 336*2813126eSlogin // 15:8 Checksum 337*2813126eSlogin // 7:0 Checksum Validity Indicator 338*2813126eSlogin unsigned short Integrity_word; 339*2813126eSlogin } __attribute__((packed)); 340*2813126eSlogin 341*2813126eSlogin /** 342*2813126eSlogin * @brief 初始化ATA磁盘驱动程序 343*2813126eSlogin * 344*2813126eSlogin */ 345*2813126eSlogin void ata_init();