]>
Commit | Line | Data |
---|---|---|
ead42efc | 1 | /** @file\r |
2 | Header file for IDE Bus Driver, containing the helper functions'\r | |
630d580d | 3 | prototype.\r |
ead42efc | 4 | \r |
5 | Copyright (c) 2006 - 2007 Intel Corporation. <BR>\r | |
6 | All rights reserved. This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | @par Revision Reference:\r | |
15 | 2002-6: Add Atapi6 enhancement, support >120GB hard disk, including\r | |
16 | Add - IDEBlkIoReadBlocksExt() func definition\r | |
17 | Add - IDEBlkIoWriteBlocksExt() func definition\r | |
18 | \r | |
19 | **/\r | |
20 | \r | |
eeefcb9d | 21 | #ifndef _IDE_H_\r |
22 | #define _IDE_H_\r | |
ead42efc | 23 | \r |
24 | //\r | |
25 | // Helper functions Prototype\r | |
26 | //\r | |
27 | /**\r | |
cd57e888 | 28 | read a one-byte data from a IDE port.\r |
ead42efc | 29 | \r |
630d580d | 30 | @param PciIo The PCI IO protocol instance\r |
31 | @param Port the IDE Port number \r | |
ead42efc | 32 | \r |
630d580d | 33 | return the one-byte data read from IDE port\r |
ead42efc | 34 | **/\r |
35 | UINT8\r | |
36 | IDEReadPortB (\r | |
37 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
38 | IN UINT16 Port\r | |
ed66e1bc | 39 | );\r |
ead42efc | 40 | \r |
41 | /**\r | |
630d580d | 42 | Reads multiple words of data from the IDE data port.\r |
43 | Call the IO abstraction once to do the complete read,\r | |
cd57e888 | 44 | not one word at a time.\r |
ead42efc | 45 | \r |
630d580d | 46 | @param PciIo Pointer to the EFI_PCI_IO instance\r |
47 | @param Port IO port to read\r | |
48 | @param Count No. of UINT16's to read\r | |
49 | @param Buffer Pointer to the data buffer for read\r | |
ead42efc | 50 | \r |
51 | **/\r | |
52 | VOID\r | |
53 | IDEReadPortWMultiple (\r | |
54 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
55 | IN UINT16 Port,\r | |
56 | IN UINTN Count,\r | |
57 | OUT VOID *Buffer\r | |
ed66e1bc | 58 | );\r |
ead42efc | 59 | \r |
60 | /**\r | |
cd57e888 | 61 | write a 1-byte data to a specific IDE port.\r |
ead42efc | 62 | \r |
630d580d | 63 | @param PciIo PCI IO protocol instance\r |
64 | @param Port The IDE port to be writen\r | |
65 | @param Data The data to write to the port\r | |
ead42efc | 66 | **/\r |
67 | VOID\r | |
68 | IDEWritePortB (\r | |
69 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
70 | IN UINT16 Port,\r | |
71 | IN UINT8 Data\r | |
ed66e1bc | 72 | );\r |
ead42efc | 73 | \r |
74 | /**\r | |
cd57e888 | 75 | write a 1-word data to a specific IDE port.\r |
ead42efc | 76 | \r |
630d580d | 77 | @param PciIo PCI IO protocol instance\r |
78 | @param Port The IDE port to be writen\r | |
79 | @param Data The data to write to the port\r | |
ead42efc | 80 | **/\r |
81 | VOID\r | |
82 | IDEWritePortW (\r | |
83 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
84 | IN UINT16 Port,\r | |
85 | IN UINT16 Data\r | |
ed66e1bc | 86 | );\r |
ead42efc | 87 | \r |
88 | /**\r | |
630d580d | 89 | Write multiple words of data to the IDE data port.\r |
90 | Call the IO abstraction once to do the complete read,\r | |
cd57e888 | 91 | not one word at a time.\r |
ead42efc | 92 | \r |
630d580d | 93 | @param PciIo Pointer to the EFI_PCI_IO instance\r |
94 | @param Port IO port to read\r | |
95 | @param Count No. of UINT16's to read\r | |
96 | @param Buffer Pointer to the data buffer for read\r | |
ead42efc | 97 | \r |
98 | **/\r | |
99 | VOID\r | |
100 | IDEWritePortWMultiple (\r | |
101 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
102 | IN UINT16 Port,\r | |
103 | IN UINTN Count,\r | |
104 | IN VOID *Buffer\r | |
ed66e1bc | 105 | );\r |
ead42efc | 106 | \r |
107 | /**\r | |
630d580d | 108 | Get IDE IO port registers' base addresses by mode. In 'Compatibility' mode,\r |
109 | use fixed addresses. In Native-PCI mode, get base addresses from BARs in\r | |
110 | the PCI IDE controller's Configuration Space.\r | |
ead42efc | 111 | \r |
630d580d | 112 | The steps to get IDE IO port registers' base addresses for each channel\r |
113 | as follows:\r | |
ead42efc | 114 | \r |
630d580d | 115 | 1. Examine the Programming Interface byte of the Class Code fields in PCI IDE\r |
116 | controller's Configuration Space to determine the operating mode.\r | |
117 | \r | |
118 | 2. a) In 'Compatibility' mode, use fixed addresses shown in the Table 1 below.\r | |
119 | <pre>\r | |
120 | ___________________________________________\r | |
121 | | | Command Block | Control Block |\r | |
122 | | Channel | Registers | Registers |\r | |
123 | |___________|_______________|_______________|\r | |
124 | | Primary | 1F0h - 1F7h | 3F6h - 3F7h |\r | |
125 | |___________|_______________|_______________|\r | |
126 | | Secondary | 170h - 177h | 376h - 377h |\r | |
127 | |___________|_______________|_______________|\r | |
128 | \r | |
129 | Table 1. Compatibility resource mappings\r | |
130 | </pre>\r | |
131 | \r | |
132 | b) In Native-PCI mode, IDE registers are mapped into IO space using the BARs\r | |
133 | in IDE controller's PCI Configuration Space, shown in the Table 2 below.\r | |
134 | <pre>\r | |
135 | ___________________________________________________\r | |
136 | | | Command Block | Control Block |\r | |
137 | | Channel | Registers | Registers |\r | |
138 | |___________|___________________|___________________|\r | |
139 | | Primary | BAR at offset 0x10| BAR at offset 0x14|\r | |
140 | |___________|___________________|___________________|\r | |
141 | | Secondary | BAR at offset 0x18| BAR at offset 0x1C|\r | |
142 | |___________|___________________|___________________|\r | |
143 | \r | |
144 | Table 2. BARs for Register Mapping\r | |
145 | </pre>\r | |
146 | @note Refer to Intel ICH4 datasheet, Control Block Offset: 03F4h for\r | |
147 | primary, 0374h for secondary. So 2 bytes extra offset should be\r | |
148 | added to the base addresses read from BARs.\r | |
149 | \r | |
150 | For more details, please refer to PCI IDE Controller Specification and Intel\r | |
151 | ICH4 Datasheet.\r | |
152 | \r | |
153 | @param PciIo Pointer to the EFI_PCI_IO_PROTOCOL instance\r | |
154 | @param IdeRegsBaseAddr Pointer to IDE_REGISTERS_BASE_ADDR to\r | |
cd57e888 | 155 | receive IDE IO port registers' base addresses\r |
156 | \r | |
157 | @retval EFI_UNSUPPORTED return this value when the BARs is not IO type\r | |
158 | @retval EFI_SUCCESS Get the Base address successfully\r | |
159 | @retval other read the pci configureation data error\r | |
ead42efc | 160 | \r |
161 | **/\r | |
162 | EFI_STATUS\r | |
163 | GetIdeRegistersBaseAddr (\r | |
164 | IN EFI_PCI_IO_PROTOCOL *PciIo,\r | |
165 | OUT IDE_REGISTERS_BASE_ADDR *IdeRegsBaseAddr\r | |
ed66e1bc | 166 | );\r |
ead42efc | 167 | \r |
168 | /**\r | |
630d580d | 169 | This function is used to requery IDE resources. The IDE controller will\r |
170 | probably switch between native and legacy modes during the EFI->CSM->OS\r | |
171 | transfer. We do this everytime before an BlkIo operation to ensure its\r | |
172 | succeess.\r | |
ead42efc | 173 | \r |
630d580d | 174 | @param IdeDev The BLK_IO private data which specifies the IDE device\r |
ead42efc | 175 | \r |
cd57e888 | 176 | @retval EFI_INVALID_PARAMETER return this value when the channel is invalid\r |
177 | @retval EFI_SUCCESS reassign the IDE IO resource successfully\r | |
178 | @retval other get the IDE current base address effor\r | |
179 | \r | |
ead42efc | 180 | **/\r |
181 | EFI_STATUS\r | |
182 | ReassignIdeResources (\r | |
183 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 184 | );\r |
ead42efc | 185 | \r |
186 | /**\r | |
cd57e888 | 187 | Detect if there is disk attached to this port.\r |
ead42efc | 188 | \r |
630d580d | 189 | @param IdeDev The BLK_IO private data which specifies the IDE device.\r |
cd57e888 | 190 | \r |
191 | @retval EFI_NOT_FOUND The device or channel is not found\r | |
192 | @retval EFI_SUCCESS The device is found\r | |
ead42efc | 193 | \r |
194 | **/\r | |
195 | EFI_STATUS\r | |
196 | DiscoverIdeDevice (\r | |
197 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 198 | );\r |
ead42efc | 199 | \r |
200 | /**\r | |
201 | This interface is used to initialize all state data related to the\r | |
202 | detection of one channel.\r | |
203 | \r | |
204 | @retval EFI_SUCCESS Completed successfully.\r | |
205 | \r | |
206 | **/\r | |
207 | EFI_STATUS\r | |
208 | InitializeIDEChannelData (\r | |
209 | VOID\r | |
ed66e1bc | 210 | );\r |
ead42efc | 211 | \r |
212 | /**\r | |
630d580d | 213 | This function is used to poll for the DRQ bit clear in the Status\r |
214 | Register. DRQ is cleared when the device is finished transferring data.\r | |
215 | So this function is called after data transfer is finished.\r | |
ead42efc | 216 | \r |
630d580d | 217 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used \r |
218 | to record all the information of the IDE device.\r | |
219 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ clear.\r | |
ead42efc | 220 | \r |
630d580d | 221 | @retval EFI_SUCCESS DRQ bit clear within the time out.\r |
ead42efc | 222 | \r |
630d580d | 223 | @retval EFI_TIMEOUT DRQ bit not clear within the time out.\r |
ead42efc | 224 | \r |
630d580d | 225 | @note\r |
226 | Read Status Register will clear interrupt status.\r | |
ead42efc | 227 | \r |
228 | **/\r | |
229 | EFI_STATUS\r | |
230 | DRQClear (\r | |
231 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
232 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 233 | );\r |
ead42efc | 234 | \r |
235 | /**\r | |
630d580d | 236 | This function is used to poll for the DRQ bit clear in the Alternate\r |
237 | Status Register. DRQ is cleared when the device is finished\r | |
238 | transferring data. So this function is called after data transfer\r | |
239 | is finished.\r | |
ead42efc | 240 | \r |
630d580d | 241 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used \r |
242 | to record all the information of the IDE device.\r | |
ead42efc | 243 | \r |
630d580d | 244 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ clear.\r |
245 | \r | |
246 | @retval EFI_SUCCESS DRQ bit clear within the time out.\r | |
247 | \r | |
248 | @retval EFI_TIMEOUT DRQ bit not clear within the time out.\r | |
249 | @note\r | |
250 | Read Alternate Status Register will not clear interrupt status.\r | |
ead42efc | 251 | \r |
252 | **/\r | |
253 | EFI_STATUS\r | |
254 | DRQClear2 (\r | |
255 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
256 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 257 | );\r |
ead42efc | 258 | \r |
259 | /**\r | |
630d580d | 260 | This function is used to poll for the DRQ bit set in the\r |
261 | Status Register.\r | |
262 | DRQ is set when the device is ready to transfer data. So this function\r | |
263 | is called after the command is sent to the device and before required\r | |
264 | data is transferred.\r | |
265 | \r | |
266 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure,used to\r | |
267 | record all the information of the IDE device.\r | |
268 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r | |
ead42efc | 269 | \r |
630d580d | 270 | @retval EFI_SUCCESS DRQ bit set within the time out.\r |
271 | @retval EFI_TIMEOUT DRQ bit not set within the time out.\r | |
272 | @retval EFI_ABORTED DRQ bit not set caused by the command abort.\r | |
ead42efc | 273 | \r |
630d580d | 274 | @note Read Status Register will clear interrupt status.\r |
ead42efc | 275 | \r |
276 | **/\r | |
277 | EFI_STATUS\r | |
278 | DRQReady (\r | |
279 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
280 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 281 | );\r |
ead42efc | 282 | \r |
283 | /**\r | |
630d580d | 284 | This function is used to poll for the DRQ bit set in the Alternate Status Register.\r |
285 | DRQ is set when the device is ready to transfer data. So this function is called after \r | |
286 | the command is sent to the device and before required data is transferred.\r | |
ead42efc | 287 | \r |
630d580d | 288 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to \r |
289 | record all the information of the IDE device.\r | |
ead42efc | 290 | \r |
630d580d | 291 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r |
292 | \r | |
293 | @retval EFI_SUCCESS DRQ bit set within the time out.\r | |
294 | @retval EFI_TIMEOUT DRQ bit not set within the time out.\r | |
295 | @retval EFI_ABORTED DRQ bit not set caused by the command abort.\r | |
296 | @note Read Alternate Status Register will not clear interrupt status.\r | |
ead42efc | 297 | \r |
298 | **/\r | |
299 | EFI_STATUS\r | |
300 | DRQReady2 (\r | |
301 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
302 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 303 | );\r |
ead42efc | 304 | \r |
305 | /**\r | |
630d580d | 306 | This function is used to poll for the BSY bit clear in the Status Register. BSY\r |
307 | is clear when the device is not busy. Every command must be sent after device is not busy.\r | |
ead42efc | 308 | \r |
630d580d | 309 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used \r |
310 | to record all the information of the IDE device.\r | |
311 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r | |
ead42efc | 312 | \r |
630d580d | 313 | @retval EFI_SUCCESS BSY bit clear within the time out.\r |
314 | @retval EFI_TIMEOUT BSY bit not clear within the time out.\r | |
ead42efc | 315 | \r |
630d580d | 316 | @note Read Status Register will clear interrupt status.\r |
ead42efc | 317 | **/\r |
318 | EFI_STATUS\r | |
319 | WaitForBSYClear (\r | |
320 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
321 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 322 | );\r |
ead42efc | 323 | \r |
324 | /**\r | |
630d580d | 325 | This function is used to poll for the BSY bit clear in the Alternate Status Register. \r |
326 | BSY is clear when the device is not busy. Every command must be sent after device is \r | |
327 | not busy.\r | |
ead42efc | 328 | \r |
630d580d | 329 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record \r |
330 | all the information of the IDE device.\r | |
cd57e888 | 331 | @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r |
ead42efc | 332 | \r |
630d580d | 333 | @retval EFI_SUCCESS BSY bit clear within the time out.\r |
334 | @retval EFI_TIMEOUT BSY bit not clear within the time out.\r | |
335 | @note Read Alternate Status Register will not clear interrupt status.\r | |
ead42efc | 336 | \r |
337 | **/\r | |
338 | EFI_STATUS\r | |
339 | WaitForBSYClear2 (\r | |
340 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
341 | IN UINTN TimeoutInMilliSeconds\r | |
ed66e1bc | 342 | );\r |
ead42efc | 343 | \r |
344 | /**\r | |
630d580d | 345 | This function is used to poll for the DRDY bit set in the Status Register. DRDY\r |
346 | bit is set when the device is ready to accept command. Most ATA commands must be \r | |
347 | sent after DRDY set except the ATAPI Packet Command.\r | |
ead42efc | 348 | \r |
630d580d | 349 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r |
350 | to record all the information of the IDE device.\r | |
351 | @param DelayInMilliSeconds used to designate the timeout for the DRQ ready.\r | |
ead42efc | 352 | \r |
630d580d | 353 | @retval EFI_SUCCESS DRDY bit set within the time out.\r |
354 | @retval EFI_TIMEOUT DRDY bit not set within the time out.\r | |
ead42efc | 355 | \r |
630d580d | 356 | @note Read Status Register will clear interrupt status.\r |
ead42efc | 357 | **/\r |
358 | EFI_STATUS\r | |
359 | DRDYReady (\r | |
360 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
361 | IN UINTN DelayInMilliSeconds\r | |
ed66e1bc | 362 | );\r |
ead42efc | 363 | \r |
364 | /**\r | |
630d580d | 365 | This function is used to poll for the DRDY bit set in the Alternate Status Register. \r |
366 | DRDY bit is set when the device is ready to accept command. Most ATA commands must \r | |
367 | be sent after DRDY set except the ATAPI Packet Command.\r | |
368 | \r | |
369 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r | |
370 | to record all the information of the IDE device.\r | |
371 | @param DelayInMilliSeconds used to designate the timeout for the DRQ ready.\r | |
ead42efc | 372 | \r |
630d580d | 373 | @retval EFI_SUCCESS DRDY bit set within the time out.\r |
374 | @retval EFI_TIMEOUT DRDY bit not set within the time out.\r | |
ead42efc | 375 | \r |
630d580d | 376 | @note Read Alternate Status Register will clear interrupt status.\r |
ead42efc | 377 | \r |
378 | **/\r | |
379 | EFI_STATUS\r | |
380 | DRDYReady2 (\r | |
381 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
382 | IN UINTN DelayInMilliSeconds\r | |
ed66e1bc | 383 | );\r |
ead42efc | 384 | \r |
ead42efc | 385 | //\r |
386 | // ATA device functions' prototype\r | |
387 | //\r | |
388 | /**\r | |
630d580d | 389 | Sends out an ATA Identify Command to the specified device.\r |
390 | \r | |
391 | This function is called by DiscoverIdeDevice() during its device\r | |
392 | identification. It sends out the ATA Identify Command to the\r | |
393 | specified device. Only ATA device responses to this command. If\r | |
394 | the command succeeds, it returns the Identify data structure which\r | |
395 | contains information about the device. This function extracts the\r | |
396 | information it needs to fill the IDE_BLK_IO_DEV data structure,\r | |
397 | including device type, media block size, media capacity, and etc.\r | |
ead42efc | 398 | \r |
630d580d | 399 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure,used to record \r |
400 | all the information of the IDE device.\r | |
ead42efc | 401 | \r |
630d580d | 402 | @retval EFI_SUCCESS Identify ATA device successfully.\r |
403 | @retval EFI_DEVICE_ERROR ATA Identify Device Command failed or device is not ATA device.\r | |
404 | @note parameter IdeDev will be updated in this function.\r | |
ead42efc | 405 | \r |
406 | **/\r | |
407 | EFI_STATUS\r | |
408 | ATAIdentify (\r | |
409 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 410 | );\r |
ead42efc | 411 | \r |
412 | /**\r | |
630d580d | 413 | This function is called by ATAIdentify() or ATAPIIdentify() to print device's module name.\r |
ead42efc | 414 | \r |
630d580d | 415 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record\r |
416 | all the information of the IDE device.\r | |
ead42efc | 417 | **/\r |
418 | VOID\r | |
419 | PrintAtaModuleName (\r | |
420 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 421 | );\r |
ead42efc | 422 | /**\r |
630d580d | 423 | This function is used to send out ATA commands conforms to the PIO Data In Protocol.\r |
ead42efc | 424 | \r |
630d580d | 425 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record \r |
426 | all the information of the IDE device.\r | |
427 | @param Buffer buffer contained data transferred from device to host.\r | |
428 | @param ByteCount data size in byte unit of the buffer.\r | |
429 | @param AtaCommand value of the Command Register\r | |
430 | @param Head value of the Head/Device Register\r | |
431 | @param SectorCount value of the Sector Count Register\r | |
432 | @param SectorNumber value of the Sector Number Register\r | |
433 | @param CylinderLsb value of the low byte of the Cylinder Register\r | |
434 | @param CylinderMsb value of the high byte of the Cylinder Register\r | |
435 | \r | |
436 | @retval EFI_SUCCESS send out the ATA command and device send required data successfully.\r | |
437 | @retval EFI_DEVICE_ERROR command sent failed.\r | |
ead42efc | 438 | \r |
439 | **/\r | |
440 | EFI_STATUS\r | |
441 | AtaPioDataIn (\r | |
442 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
443 | IN VOID *Buffer,\r | |
444 | IN UINT32 ByteCount,\r | |
445 | IN UINT8 AtaCommand,\r | |
446 | IN UINT8 Head,\r | |
447 | IN UINT8 SectorCount,\r | |
448 | IN UINT8 SectorNumber,\r | |
449 | IN UINT8 CylinderLsb,\r | |
450 | IN UINT8 CylinderMsb\r | |
ed66e1bc | 451 | );\r |
ead42efc | 452 | \r |
453 | /**\r | |
630d580d | 454 | This function is used to send out ATA commands conforms to the\r |
455 | PIO Data Out Protocol.\r | |
ead42efc | 456 | \r |
630d580d | 457 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r |
458 | to record all the information of the IDE device.\r | |
459 | @param *Buffer buffer contained data transferred from host to device.\r | |
460 | @param ByteCount data size in byte unit of the buffer.\r | |
461 | @param AtaCommand value of the Command Register\r | |
462 | @param Head value of the Head/Device Register\r | |
463 | @param SectorCount value of the Sector Count Register\r | |
464 | @param SectorNumber value of the Sector Number Register\r | |
465 | @param CylinderLsb value of the low byte of the Cylinder Register\r | |
466 | @param CylinderMsb value of the high byte of the Cylinder Register\r | |
ead42efc | 467 | \r |
630d580d | 468 | @retval EFI_SUCCESS send out the ATA command and device received required\r |
469 | data successfully.\r | |
470 | @retval EFI_DEVICE_ERROR command sent failed.\r | |
ead42efc | 471 | \r |
472 | **/\r | |
473 | EFI_STATUS\r | |
474 | AtaPioDataOut (\r | |
475 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
476 | IN VOID *Buffer,\r | |
477 | IN UINT32 ByteCount,\r | |
478 | IN UINT8 AtaCommand,\r | |
479 | IN UINT8 Head,\r | |
480 | IN UINT8 SectorCount,\r | |
481 | IN UINT8 SectorNumber,\r | |
482 | IN UINT8 CylinderLsb,\r | |
483 | IN UINT8 CylinderMsb\r | |
ed66e1bc | 484 | );\r |
ead42efc | 485 | \r |
486 | /**\r | |
630d580d | 487 | This function is used to analyze the Status Register and print out\r |
488 | some debug information and if there is ERR bit set in the Status\r | |
489 | Register, the Error Register's value is also be parsed and print out.\r | |
ead42efc | 490 | \r |
630d580d | 491 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to \r |
492 | record all the information of the IDE device.\r | |
ead42efc | 493 | \r |
630d580d | 494 | @retval EFI_SUCCESS No err information in the Status Register.\r |
495 | @retval EFI_DEVICE_ERROR Any err information in the Status Register.\r | |
ead42efc | 496 | \r |
497 | **/\r | |
498 | EFI_STATUS\r | |
499 | CheckErrorStatus (\r | |
500 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 501 | );\r |
ead42efc | 502 | \r |
503 | /**\r | |
630d580d | 504 | This function is used to implement the Soft Reset on the specified device. But,\r |
505 | the ATA Soft Reset mechanism is so strong a reset method that it will force \r | |
506 | resetting on both devices connected to the same cable.\r | |
ead42efc | 507 | \r |
630d580d | 508 | It is called by IdeBlkIoReset(), a interface function of Block\r |
509 | I/O protocol.\r | |
ead42efc | 510 | \r |
630d580d | 511 | This function can also be used by the ATAPI device to perform reset when\r |
512 | ATAPI Reset command is failed.\r | |
ead42efc | 513 | \r |
630d580d | 514 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record\r |
515 | all the information of the IDE device.\r | |
516 | @retval EFI_SUCCESS Soft reset completes successfully.\r | |
517 | @retval EFI_DEVICE_ERROR Any step during the reset process is failed.\r | |
ead42efc | 518 | \r |
630d580d | 519 | @note The registers initial values after ATA soft reset are different\r |
520 | to the ATA device and ATAPI device.\r | |
ead42efc | 521 | **/\r |
522 | EFI_STATUS\r | |
523 | AtaSoftReset (\r | |
524 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 525 | );\r |
ead42efc | 526 | \r |
527 | /**\r | |
630d580d | 528 | This function is the ATA implementation for ReadBlocks in the\r |
529 | Block I/O Protocol interface.\r | |
530 | \r | |
531 | @param IdeBlkIoDevice Indicates the calling context.\r | |
532 | @param MediaId The media id that the read request is for.\r | |
cd57e888 | 533 | @param Lba The starting logical block address to read from on the device.\r |
630d580d | 534 | @param BufferSize The size of the Buffer in bytes. This must be a multiple\r |
535 | of the intrinsic block size of the device.\r | |
ead42efc | 536 | \r |
630d580d | 537 | @param Buffer A pointer to the destination buffer for the data. The caller\r |
538 | is responsible for either having implicit or explicit ownership\r | |
539 | of the memory that data is read into.\r | |
ead42efc | 540 | \r |
630d580d | 541 | @retval EFI_SUCCESS Read Blocks successfully.\r |
542 | @retval EFI_DEVICE_ERROR Read Blocks failed.\r | |
543 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
544 | @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.\r | |
545 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r | |
546 | intrinsic block size of the device.\r | |
547 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r | |
548 | or the data buffer is not valid.\r | |
549 | \r | |
550 | @note If Read Block error because of device error, this function will call\r | |
551 | AtaSoftReset() function to reset device.\r | |
ead42efc | 552 | \r |
553 | **/\r | |
554 | EFI_STATUS\r | |
555 | AtaBlkIoReadBlocks (\r | |
556 | IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r | |
557 | IN UINT32 MediaId,\r | |
e72ca438 | 558 | IN EFI_LBA Lba,\r |
ead42efc | 559 | IN UINTN BufferSize,\r |
560 | OUT VOID *Buffer\r | |
ed66e1bc | 561 | );\r |
ead42efc | 562 | \r |
563 | /**\r | |
630d580d | 564 | This function is the ATA implementation for WriteBlocks in the\r |
565 | Block I/O Protocol interface.\r | |
566 | \r | |
567 | @param IdeBlkIoDevice Indicates the calling context.\r | |
568 | @param MediaId The media id that the write request is for.\r | |
cd57e888 | 569 | @param Lba The starting logical block address to write onto the device.\r |
630d580d | 570 | @param BufferSize The size of the Buffer in bytes. This must be a multiple\r |
571 | of the intrinsic block size of the device.\r | |
572 | @param Buffer A pointer to the source buffer for the data.The caller\r | |
573 | is responsible for either having implicit or explicit \r | |
574 | ownership of the memory that data is written from.\r | |
ead42efc | 575 | \r |
630d580d | 576 | @retval EFI_SUCCESS Write Blocks successfully.\r |
577 | @retval EFI_DEVICE_ERROR Write Blocks failed.\r | |
578 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
579 | @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.\r | |
ead42efc | 580 | \r |
630d580d | 581 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r |
582 | intrinsic block size of the device.\r | |
583 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r | |
584 | or the data buffer is not valid.\r | |
ead42efc | 585 | \r |
630d580d | 586 | @note If Write Block error because of device error, this function will call\r |
587 | AtaSoftReset() function to reset device.\r | |
ead42efc | 588 | **/\r |
589 | EFI_STATUS\r | |
590 | AtaBlkIoWriteBlocks (\r | |
591 | IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r | |
592 | IN UINT32 MediaId,\r | |
e72ca438 | 593 | IN EFI_LBA Lba,\r |
ead42efc | 594 | IN UINTN BufferSize,\r |
595 | OUT VOID *Buffer\r | |
ed66e1bc | 596 | );\r |
ead42efc | 597 | \r |
ead42efc | 598 | /**\r |
630d580d | 599 | This function is called by DiscoverIdeDevice() during its device\r |
600 | identification.\r | |
601 | Its main purpose is to get enough information for the device media\r | |
602 | to fill in the Media data structure of the Block I/O Protocol interface.\r | |
603 | \r | |
604 | There are 5 steps to reach such objective:\r | |
605 | 1. Sends out the ATAPI Identify Command to the specified device. \r | |
606 | Only ATAPI device responses to this command. If the command succeeds,\r | |
607 | it returns the Identify data structure which filled with information \r | |
608 | about the device. Since the ATAPI device contains removable media, \r | |
609 | the only meaningful information is the device module name.\r | |
610 | 2. Sends out ATAPI Inquiry Packet Command to the specified device.\r | |
611 | This command will return inquiry data of the device, which contains\r | |
612 | the device type information.\r | |
613 | 3. Allocate sense data space for future use. We don't detect the media\r | |
614 | presence here to improvement boot performance, especially when CD \r | |
615 | media is present. The media detection will be performed just before\r | |
616 | each BLK_IO read/write\r | |
617 | \r | |
618 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r | |
619 | to record all the information of the IDE device.\r | |
ead42efc | 620 | \r |
630d580d | 621 | @retval EFI_SUCCESS Identify ATAPI device successfully.\r |
622 | @retval EFI_DEVICE_ERROR ATAPI Identify Device Command failed or device type\r | |
623 | is not supported by this IDE driver.\r | |
624 | @retval EFI_OUT_OF_RESOURCES Allocate memory for sense data failed \r | |
ead42efc | 625 | \r |
630d580d | 626 | @note Parameter "IdeDev" will be updated in this function.\r |
ead42efc | 627 | **/\r |
628 | EFI_STATUS\r | |
629 | ATAPIIdentify (\r | |
630 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 631 | );\r |
ead42efc | 632 | \r |
633 | /**\r | |
630d580d | 634 | This function is used to implement the Soft Reset on the specified\r |
635 | ATAPI device. Different from the AtaSoftReset(), here reset is a ATA\r | |
636 | Soft Reset Command special for ATAPI device, and it only take effects\r | |
637 | on the specified ATAPI device, not on the whole IDE bus.\r | |
638 | Since the ATAPI soft reset is needed when device is in exceptional\r | |
639 | condition (such as BSY bit is always set ), I think the Soft Reset\r | |
640 | command should be sent without waiting for the BSY clear and DRDY\r | |
641 | set.\r | |
642 | This function is called by IdeBlkIoReset(), \r | |
643 | a interface function of Block I/O protocol.\r | |
ead42efc | 644 | \r |
630d580d | 645 | @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r |
646 | to record all the information of the IDE device.\r | |
ead42efc | 647 | \r |
630d580d | 648 | @retval EFI_SUCCESS Soft reset completes successfully.\r |
649 | @retval EFI_DEVICE_ERROR Any step during the reset process is failed.\r | |
ead42efc | 650 | \r |
651 | **/\r | |
652 | EFI_STATUS\r | |
653 | AtapiSoftReset (\r | |
654 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 655 | );\r |
ead42efc | 656 | \r |
657 | /**\r | |
630d580d | 658 | This function is the ATAPI implementation for ReadBlocks in the\r |
659 | Block I/O Protocol interface.\r | |
ead42efc | 660 | \r |
630d580d | 661 | @param IdeBlkIoDevice Indicates the calling context.\r |
662 | @param MediaId The media id that the read request is for.\r | |
cd57e888 | 663 | @param Lba The starting logical block address to read from on the device.\r |
630d580d | 664 | @param BufferSize The size of the Buffer in bytes. This must be a multiple\r |
665 | of the intrinsic block size of the device.\r | |
666 | @param Buffer A pointer to the destination buffer for the data. The caller\r | |
667 | is responsible for either having implicit or explicit \r | |
668 | ownership of the memory that data is read into.\r | |
669 | \r | |
670 | @retval EFI_SUCCESS Read Blocks successfully.\r | |
671 | @retval EFI_DEVICE_ERROR Read Blocks failed.\r | |
672 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
673 | @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r | |
674 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r | |
675 | intrinsic block size of the device.\r | |
676 | @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r | |
677 | or the data buffer is not valid.\r | |
ead42efc | 678 | **/\r |
679 | EFI_STATUS\r | |
680 | AtapiBlkIoReadBlocks (\r | |
681 | IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r | |
682 | IN UINT32 MediaId,\r | |
e72ca438 | 683 | IN EFI_LBA Lba,\r |
ead42efc | 684 | IN UINTN BufferSize,\r |
685 | OUT VOID *Buffer\r | |
ed66e1bc | 686 | );\r |
ead42efc | 687 | \r |
688 | /**\r | |
630d580d | 689 | This function is the ATAPI implementation for WriteBlocks in the\r |
690 | Block I/O Protocol interface.\r | |
ead42efc | 691 | \r |
630d580d | 692 | @param IdeBlkIoDevice Indicates the calling context.\r |
693 | @param MediaId The media id that the write request is for.\r | |
cd57e888 | 694 | @param Lba The starting logical block address to write onto the device.\r |
630d580d | 695 | @param BufferSize The size of the Buffer in bytes. This must be a multiple\r |
696 | of the intrinsic block size of the device.\r | |
697 | @param Buffer A pointer to the source buffer for the data. The caller\r | |
698 | is responsible for either having implicit or explicit ownership\r | |
699 | of the memory that data is written from.\r | |
ead42efc | 700 | \r |
630d580d | 701 | @retval EFI_SUCCESS Write Blocks successfully.\r |
702 | @retval EFI_DEVICE_ERROR Write Blocks failed.\r | |
703 | @retval EFI_NO_MEDIA There is no media in the device.\r | |
704 | @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.\r | |
705 | @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r | |
706 | intrinsic block size of the device. \r | |
707 | @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r | |
708 | or the data buffer is not valid.\r | |
ead42efc | 709 | \r |
630d580d | 710 | @retval EFI_WRITE_PROTECTED The write protected is enabled or the media does not support write\r |
ead42efc | 711 | **/\r |
712 | EFI_STATUS\r | |
713 | AtapiBlkIoWriteBlocks (\r | |
714 | IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r | |
715 | IN UINT32 MediaId,\r | |
e72ca438 | 716 | IN EFI_LBA Lba,\r |
ead42efc | 717 | IN UINTN BufferSize,\r |
718 | OUT VOID *Buffer\r | |
ed66e1bc | 719 | );\r |
ead42efc | 720 | \r |
721 | /**\r | |
630d580d | 722 | Release resources of an IDE device before stopping it.\r |
ead42efc | 723 | \r |
630d580d | 724 | @param IdeBlkIoDevice Standard IDE device private data structure\r |
ead42efc | 725 | \r |
726 | **/\r | |
727 | VOID\r | |
728 | ReleaseIdeResources (\r | |
729 | IN IDE_BLK_IO_DEV *IdeBlkIoDevice\r | |
ed66e1bc | 730 | );\r |
ead42efc | 731 | \r |
732 | /**\r | |
630d580d | 733 | Set the calculated Best transfer mode to a detected device\r |
ead42efc | 734 | \r |
630d580d | 735 | @param IdeDev Standard IDE device private data structure\r |
736 | @param TransferMode The device transfer mode to be set\r | |
737 | @return Set transfer mode Command execute status.\r | |
ead42efc | 738 | **/\r |
739 | EFI_STATUS\r | |
740 | SetDeviceTransferMode (\r | |
741 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
742 | IN ATA_TRANSFER_MODE *TransferMode\r | |
ed66e1bc | 743 | );\r |
ead42efc | 744 | /**\r |
cd57e888 | 745 | Send ATA command into device with NON_DATA protocol.\r |
ead42efc | 746 | \r |
630d580d | 747 | @param IdeDev Standard IDE device private data structure\r |
748 | @param AtaCommand The ATA command to be sent\r | |
749 | @param Device The value in Device register\r | |
750 | @param Feature The value in Feature register\r | |
751 | @param SectorCount The value in SectorCount register\r | |
752 | @param LbaLow The value in LBA_LOW register\r | |
753 | @param LbaMiddle The value in LBA_MIDDLE register\r | |
754 | @param LbaHigh The value in LBA_HIGH register\r | |
ead42efc | 755 | \r |
630d580d | 756 | @retval EFI_SUCCESS Reading succeed\r |
757 | @retval EFI_ABORTED Command failed\r | |
758 | @retval EFI_DEVICE_ERROR Device status error.\r | |
ead42efc | 759 | \r |
760 | **/\r | |
761 | EFI_STATUS\r | |
762 | AtaNonDataCommandIn (\r | |
763 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
764 | IN UINT8 AtaCommand,\r | |
765 | IN UINT8 Device,\r | |
766 | IN UINT8 Feature,\r | |
767 | IN UINT8 SectorCount,\r | |
768 | IN UINT8 LbaLow,\r | |
769 | IN UINT8 LbaMiddle,\r | |
770 | IN UINT8 LbaHigh\r | |
ed66e1bc | 771 | );\r |
ead42efc | 772 | \r |
773 | /**\r | |
cd57e888 | 774 | Send ATA Ext command into device with NON_DATA protocol.\r |
ead42efc | 775 | \r |
630d580d | 776 | @param IdeDev Standard IDE device private data structure\r |
777 | @param AtaCommand The ATA command to be sent\r | |
778 | @param Device The value in Device register\r | |
779 | @param Feature The value in Feature register\r | |
780 | @param SectorCount The value in SectorCount register\r | |
cd57e888 | 781 | @param LbaAddress The Lba address in 48-bit mode\r |
ead42efc | 782 | \r |
630d580d | 783 | @retval EFI_SUCCESS Reading succeed\r |
784 | @retval EFI_ABORTED Command failed\r | |
785 | @retval EFI_DEVICE_ERROR Device status error.\r | |
ead42efc | 786 | \r |
787 | **/\r | |
788 | EFI_STATUS\r | |
789 | AtaNonDataCommandInExt (\r | |
790 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
791 | IN UINT8 AtaCommand,\r | |
792 | IN UINT8 Device,\r | |
793 | IN UINT16 Feature,\r | |
794 | IN UINT16 SectorCount,\r | |
795 | IN EFI_LBA LbaAddress\r | |
ed66e1bc | 796 | );\r |
75eccf9d | 797 | /**\r |
798 | Enable Long Physical Sector Feature for ATA device.\r | |
799 | \r | |
800 | @param IdeDev The IDE device data\r | |
801 | \r | |
802 | @retval EFI_SUCCESS The ATA device supports Long Physical Sector feature\r | |
803 | and corresponding fields in BlockIo structure is updated.\r | |
804 | @retval EFI_UNSUPPORTED The device is not ATA device or Long Physical Sector\r | |
805 | feature is not supported.\r | |
806 | **/\r | |
807 | EFI_STATUS\r | |
808 | AtaEnableLongPhysicalSector (\r | |
809 | IN IDE_BLK_IO_DEV *IdeDev\r | |
810 | );\r | |
811 | \r | |
ead42efc | 812 | /**\r |
cd57e888 | 813 | Set drive parameters for devices not support PACKETS command.\r |
ead42efc | 814 | \r |
630d580d | 815 | @param IdeDev Standard IDE device private data structure\r |
816 | @param DriveParameters The device parameters to be set into the disk\r | |
817 | @return SetParameters Command execute status.\r | |
ead42efc | 818 | \r |
819 | **/\r | |
820 | EFI_STATUS\r | |
821 | SetDriveParameters (\r | |
822 | IN IDE_BLK_IO_DEV *IdeDev,\r | |
823 | IN ATA_DRIVE_PARMS *DriveParameters\r | |
ed66e1bc | 824 | );\r |
ead42efc | 825 | \r |
826 | /**\r | |
7dd94873 | 827 | Enable Interrupt on IDE controller.\r |
ead42efc | 828 | \r |
630d580d | 829 | @param IdeDev Standard IDE device private data structure\r |
ead42efc | 830 | \r |
630d580d | 831 | @retval EFI_SUCCESS Enable Interrupt successfully\r |
ead42efc | 832 | **/\r |
833 | EFI_STATUS\r | |
834 | EnableInterrupt (\r | |
835 | IN IDE_BLK_IO_DEV *IdeDev\r | |
ed66e1bc | 836 | );\r |
ead42efc | 837 | #endif\r |