]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/Ide.h
Code scrub for PCI Bus module and PciIncompatibleDeviceSupportLib module.
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / IdeBusDxe / Ide.h
CommitLineData
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
630d580d 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
35UINT8\r
36IDEReadPortB (\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
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
52VOID\r
53IDEReadPortWMultiple (\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
630d580d 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
67VOID\r
68IDEWritePortB (\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
630d580d 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
81VOID\r
82IDEWritePortW (\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
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
99VOID\r
100IDEWritePortWMultiple (\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
155 receive IDE IO port registers' base addresses\r
ead42efc 156\r
157**/\r
158EFI_STATUS\r
159GetIdeRegistersBaseAddr (\r
160 IN EFI_PCI_IO_PROTOCOL *PciIo,\r
161 OUT IDE_REGISTERS_BASE_ADDR *IdeRegsBaseAddr\r
ed66e1bc 162 );\r
ead42efc 163\r
164/**\r
630d580d 165 This function is used to requery IDE resources. The IDE controller will\r
166 probably switch between native and legacy modes during the EFI->CSM->OS\r
167 transfer. We do this everytime before an BlkIo operation to ensure its\r
168 succeess.\r
ead42efc 169\r
630d580d 170 @param IdeDev The BLK_IO private data which specifies the IDE device\r
ead42efc 171\r
172**/\r
173EFI_STATUS\r
174ReassignIdeResources (\r
175 IN IDE_BLK_IO_DEV *IdeDev\r
ed66e1bc 176 );\r
ead42efc 177\r
178/**\r
630d580d 179 Detect if there is disk attached to this port\r
ead42efc 180\r
630d580d 181 @param IdeDev The BLK_IO private data which specifies the IDE device.\r
ead42efc 182\r
183**/\r
184EFI_STATUS\r
185DiscoverIdeDevice (\r
186 IN IDE_BLK_IO_DEV *IdeDev\r
ed66e1bc 187 );\r
ead42efc 188\r
189/**\r
190 This interface is used to initialize all state data related to the\r
191 detection of one channel.\r
192\r
193 @retval EFI_SUCCESS Completed successfully.\r
194\r
195**/\r
196EFI_STATUS\r
197InitializeIDEChannelData (\r
198 VOID\r
ed66e1bc 199 );\r
ead42efc 200\r
201/**\r
630d580d 202 This function is used to poll for the DRQ bit clear in the Status\r
203 Register. DRQ is cleared when the device is finished transferring data.\r
204 So this function is called after data transfer is finished.\r
ead42efc 205\r
630d580d 206 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used \r
207 to record all the information of the IDE device.\r
208 @param TimeoutInMilliSeconds used to designate the timeout for the DRQ clear.\r
ead42efc 209\r
630d580d 210 @retval EFI_SUCCESS DRQ bit clear within the time out.\r
ead42efc 211\r
630d580d 212 @retval EFI_TIMEOUT DRQ bit not clear within the time out.\r
ead42efc 213\r
630d580d 214 @note\r
215 Read Status Register will clear interrupt status.\r
ead42efc 216\r
217**/\r
218EFI_STATUS\r
219DRQClear (\r
220 IN IDE_BLK_IO_DEV *IdeDev,\r
221 IN UINTN TimeoutInMilliSeconds\r
ed66e1bc 222 );\r
ead42efc 223\r
224/**\r
630d580d 225 This function is used to poll for the DRQ bit clear in the Alternate\r
226 Status Register. DRQ is cleared when the device is finished\r
227 transferring data. So this function is called after data transfer\r
228 is finished.\r
ead42efc 229\r
630d580d 230 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used \r
231 to record all the information of the IDE device.\r
ead42efc 232\r
630d580d 233 @param TimeoutInMilliSeconds used to designate the timeout for the DRQ clear.\r
234\r
235 @retval EFI_SUCCESS DRQ bit clear within the time out.\r
236\r
237 @retval EFI_TIMEOUT DRQ bit not clear within the time out.\r
238 @note\r
239 Read Alternate Status Register will not clear interrupt status.\r
ead42efc 240\r
241**/\r
242EFI_STATUS\r
243DRQClear2 (\r
244 IN IDE_BLK_IO_DEV *IdeDev,\r
245 IN UINTN TimeoutInMilliSeconds\r
ed66e1bc 246 );\r
ead42efc 247\r
248/**\r
630d580d 249 This function is used to poll for the DRQ bit set in the\r
250 Status Register.\r
251 DRQ is set when the device is ready to transfer data. So this function\r
252 is called after the command is sent to the device and before required\r
253 data is transferred.\r
254\r
255 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure,used to\r
256 record all the information of the IDE device.\r
257 @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r
ead42efc 258\r
630d580d 259 @retval EFI_SUCCESS DRQ bit set within the time out.\r
260 @retval EFI_TIMEOUT DRQ bit not set within the time out.\r
261 @retval EFI_ABORTED DRQ bit not set caused by the command abort.\r
ead42efc 262\r
630d580d 263 @note Read Status Register will clear interrupt status.\r
ead42efc 264\r
265**/\r
266EFI_STATUS\r
267DRQReady (\r
268 IN IDE_BLK_IO_DEV *IdeDev,\r
269 IN UINTN TimeoutInMilliSeconds\r
ed66e1bc 270 );\r
ead42efc 271\r
272/**\r
630d580d 273 This function is used to poll for the DRQ bit set in the Alternate Status Register.\r
274 DRQ is set when the device is ready to transfer data. So this function is called after \r
275 the command is sent to the device and before required data is transferred.\r
ead42efc 276\r
630d580d 277 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to \r
278 record all the information of the IDE device.\r
ead42efc 279\r
630d580d 280 @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r
281\r
282 @retval EFI_SUCCESS DRQ bit set within the time out.\r
283 @retval EFI_TIMEOUT DRQ bit not set within the time out.\r
284 @retval EFI_ABORTED DRQ bit not set caused by the command abort.\r
285 @note Read Alternate Status Register will not clear interrupt status.\r
ead42efc 286\r
287**/\r
288EFI_STATUS\r
289DRQReady2 (\r
290 IN IDE_BLK_IO_DEV *IdeDev,\r
291 IN UINTN TimeoutInMilliSeconds\r
ed66e1bc 292 );\r
ead42efc 293\r
294/**\r
630d580d 295 This function is used to poll for the BSY bit clear in the Status Register. BSY\r
296 is clear when the device is not busy. Every command must be sent after device is not busy.\r
ead42efc 297\r
630d580d 298 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used \r
299 to record all the information of the IDE device.\r
300 @param TimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r
ead42efc 301\r
630d580d 302 @retval EFI_SUCCESS BSY bit clear within the time out.\r
303 @retval EFI_TIMEOUT BSY bit not clear within the time out.\r
ead42efc 304\r
630d580d 305 @note Read Status Register will clear interrupt status.\r
ead42efc 306**/\r
307EFI_STATUS\r
308WaitForBSYClear (\r
309 IN IDE_BLK_IO_DEV *IdeDev,\r
310 IN UINTN TimeoutInMilliSeconds\r
ed66e1bc 311 );\r
ead42efc 312\r
313/**\r
630d580d 314 This function is used to poll for the BSY bit clear in the Alternate Status Register. \r
315 BSY is clear when the device is not busy. Every command must be sent after device is \r
316 not busy.\r
ead42efc 317\r
630d580d 318 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record \r
319 all the information of the IDE device.\r
320 @paramTimeoutInMilliSeconds used to designate the timeout for the DRQ ready.\r
ead42efc 321\r
630d580d 322 @retval EFI_SUCCESS BSY bit clear within the time out.\r
323 @retval EFI_TIMEOUT BSY bit not clear within the time out.\r
324 @note Read Alternate Status Register will not clear interrupt status.\r
ead42efc 325\r
326**/\r
327EFI_STATUS\r
328WaitForBSYClear2 (\r
329 IN IDE_BLK_IO_DEV *IdeDev,\r
330 IN UINTN TimeoutInMilliSeconds\r
ed66e1bc 331 );\r
ead42efc 332\r
333/**\r
630d580d 334 This function is used to poll for the DRDY bit set in the Status Register. DRDY\r
335 bit is set when the device is ready to accept command. Most ATA commands must be \r
336 sent after DRDY set except the ATAPI Packet Command.\r
ead42efc 337\r
630d580d 338 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r
339 to record all the information of the IDE device.\r
340 @param DelayInMilliSeconds used to designate the timeout for the DRQ ready.\r
ead42efc 341\r
630d580d 342 @retval EFI_SUCCESS DRDY bit set within the time out.\r
343 @retval EFI_TIMEOUT DRDY bit not set within the time out.\r
ead42efc 344\r
630d580d 345 @note Read Status Register will clear interrupt status.\r
ead42efc 346**/\r
347EFI_STATUS\r
348DRDYReady (\r
349 IN IDE_BLK_IO_DEV *IdeDev,\r
350 IN UINTN DelayInMilliSeconds\r
ed66e1bc 351 );\r
ead42efc 352\r
353/**\r
630d580d 354 This function is used to poll for the DRDY bit set in the Alternate Status Register. \r
355 DRDY bit is set when the device is ready to accept command. Most ATA commands must \r
356 be sent after DRDY set except the ATAPI Packet Command.\r
357\r
358 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r
359 to record all the information of the IDE device.\r
360 @param DelayInMilliSeconds used to designate the timeout for the DRQ ready.\r
ead42efc 361\r
630d580d 362 @retval EFI_SUCCESS DRDY bit set within the time out.\r
363 @retval EFI_TIMEOUT DRDY bit not set within the time out.\r
ead42efc 364\r
630d580d 365 @note Read Alternate Status Register will clear interrupt status.\r
ead42efc 366\r
367**/\r
368EFI_STATUS\r
369DRDYReady2 (\r
370 IN IDE_BLK_IO_DEV *IdeDev,\r
371 IN UINTN DelayInMilliSeconds\r
ed66e1bc 372 );\r
ead42efc 373\r
ead42efc 374//\r
375// ATA device functions' prototype\r
376//\r
377/**\r
630d580d 378 Sends out an ATA Identify Command to the specified device.\r
379\r
380 This function is called by DiscoverIdeDevice() during its device\r
381 identification. It sends out the ATA Identify Command to the\r
382 specified device. Only ATA device responses to this command. If\r
383 the command succeeds, it returns the Identify data structure which\r
384 contains information about the device. This function extracts the\r
385 information it needs to fill the IDE_BLK_IO_DEV data structure,\r
386 including device type, media block size, media capacity, and etc.\r
ead42efc 387\r
630d580d 388 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure,used to record \r
389 all the information of the IDE device.\r
ead42efc 390\r
630d580d 391 @retval EFI_SUCCESS Identify ATA device successfully.\r
392 @retval EFI_DEVICE_ERROR ATA Identify Device Command failed or device is not ATA device.\r
393 @note parameter IdeDev will be updated in this function.\r
ead42efc 394\r
395**/\r
396EFI_STATUS\r
397ATAIdentify (\r
398 IN IDE_BLK_IO_DEV *IdeDev\r
ed66e1bc 399 );\r
ead42efc 400\r
401/**\r
630d580d 402 This function is called by ATAIdentify() or ATAPIIdentify() to print device's module name.\r
ead42efc 403\r
630d580d 404 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record\r
405 all the information of the IDE device.\r
ead42efc 406**/\r
407VOID\r
408PrintAtaModuleName (\r
409 IN IDE_BLK_IO_DEV *IdeDev\r
ed66e1bc 410 );\r
ead42efc 411/**\r
630d580d 412 This function is used to send out ATA commands conforms to the PIO Data In Protocol.\r
ead42efc 413\r
630d580d 414 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record \r
415 all the information of the IDE device.\r
416 @param Buffer buffer contained data transferred from device to host.\r
417 @param ByteCount data size in byte unit of the buffer.\r
418 @param AtaCommand value of the Command Register\r
419 @param Head value of the Head/Device Register\r
420 @param SectorCount value of the Sector Count Register\r
421 @param SectorNumber value of the Sector Number Register\r
422 @param CylinderLsb value of the low byte of the Cylinder Register\r
423 @param CylinderMsb value of the high byte of the Cylinder Register\r
424 \r
425 @retval EFI_SUCCESS send out the ATA command and device send required data successfully.\r
426 @retval EFI_DEVICE_ERROR command sent failed.\r
ead42efc 427\r
428**/\r
429EFI_STATUS\r
430AtaPioDataIn (\r
431 IN IDE_BLK_IO_DEV *IdeDev,\r
432 IN VOID *Buffer,\r
433 IN UINT32 ByteCount,\r
434 IN UINT8 AtaCommand,\r
435 IN UINT8 Head,\r
436 IN UINT8 SectorCount,\r
437 IN UINT8 SectorNumber,\r
438 IN UINT8 CylinderLsb,\r
439 IN UINT8 CylinderMsb\r
ed66e1bc 440 );\r
ead42efc 441\r
442/**\r
630d580d 443 This function is used to send out ATA commands conforms to the\r
444 PIO Data Out Protocol.\r
ead42efc 445\r
630d580d 446 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r
447 to record all the information of the IDE device.\r
448 @param *Buffer buffer contained data transferred from host to device.\r
449 @param ByteCount data size in byte unit of the buffer.\r
450 @param AtaCommand value of the Command Register\r
451 @param Head value of the Head/Device Register\r
452 @param SectorCount value of the Sector Count Register\r
453 @param SectorNumber value of the Sector Number Register\r
454 @param CylinderLsb value of the low byte of the Cylinder Register\r
455 @param CylinderMsb value of the high byte of the Cylinder Register\r
ead42efc 456\r
630d580d 457 @retval EFI_SUCCESS send out the ATA command and device received required\r
458 data successfully.\r
459 @retval EFI_DEVICE_ERROR command sent failed.\r
ead42efc 460\r
461**/\r
462EFI_STATUS\r
463AtaPioDataOut (\r
464 IN IDE_BLK_IO_DEV *IdeDev,\r
465 IN VOID *Buffer,\r
466 IN UINT32 ByteCount,\r
467 IN UINT8 AtaCommand,\r
468 IN UINT8 Head,\r
469 IN UINT8 SectorCount,\r
470 IN UINT8 SectorNumber,\r
471 IN UINT8 CylinderLsb,\r
472 IN UINT8 CylinderMsb\r
ed66e1bc 473 );\r
ead42efc 474\r
475/**\r
630d580d 476 This function is used to analyze the Status Register and print out\r
477 some debug information and if there is ERR bit set in the Status\r
478 Register, the Error Register's value is also be parsed and print out.\r
ead42efc 479\r
630d580d 480 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to \r
481 record all the information of the IDE device.\r
ead42efc 482\r
630d580d 483 @retval EFI_SUCCESS No err information in the Status Register.\r
484 @retval EFI_DEVICE_ERROR Any err information in the Status Register.\r
ead42efc 485\r
486**/\r
487EFI_STATUS\r
488CheckErrorStatus (\r
489 IN IDE_BLK_IO_DEV *IdeDev\r
ed66e1bc 490 );\r
ead42efc 491\r
492/**\r
630d580d 493 This function is used to implement the Soft Reset on the specified device. But,\r
494 the ATA Soft Reset mechanism is so strong a reset method that it will force \r
495 resetting on both devices connected to the same cable.\r
ead42efc 496\r
630d580d 497 It is called by IdeBlkIoReset(), a interface function of Block\r
498 I/O protocol.\r
ead42efc 499\r
630d580d 500 This function can also be used by the ATAPI device to perform reset when\r
501 ATAPI Reset command is failed.\r
ead42efc 502\r
630d580d 503 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used to record\r
504 all the information of the IDE device.\r
505 @retval EFI_SUCCESS Soft reset completes successfully.\r
506 @retval EFI_DEVICE_ERROR Any step during the reset process is failed.\r
ead42efc 507\r
630d580d 508 @note The registers initial values after ATA soft reset are different\r
509 to the ATA device and ATAPI device.\r
ead42efc 510**/\r
511EFI_STATUS\r
512AtaSoftReset (\r
513 IN IDE_BLK_IO_DEV *IdeDev\r
ed66e1bc 514 );\r
ead42efc 515\r
516/**\r
630d580d 517 This function is the ATA implementation for ReadBlocks in the\r
518 Block I/O Protocol interface.\r
519\r
520 @param IdeBlkIoDevice Indicates the calling context.\r
521 @param MediaId The media id that the read request is for.\r
522 @param LBA The starting logical block address to read from on the device.\r
523 @param BufferSize The size of the Buffer in bytes. This must be a multiple\r
524 of the intrinsic block size of the device.\r
ead42efc 525\r
630d580d 526 @param Buffer A pointer to the destination buffer for the data. The caller\r
527 is responsible for either having implicit or explicit ownership\r
528 of the memory that data is read into.\r
ead42efc 529\r
630d580d 530 @retval EFI_SUCCESS Read Blocks successfully.\r
531 @retval EFI_DEVICE_ERROR Read Blocks failed.\r
532 @retval EFI_NO_MEDIA There is no media in the device.\r
533 @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.\r
534 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r
535 intrinsic block size of the device.\r
536 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
537 or the data buffer is not valid.\r
538\r
539 @note If Read Block error because of device error, this function will call\r
540 AtaSoftReset() function to reset device.\r
ead42efc 541\r
542**/\r
543EFI_STATUS\r
544AtaBlkIoReadBlocks (\r
545 IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r
546 IN UINT32 MediaId,\r
e72ca438 547 IN EFI_LBA Lba,\r
ead42efc 548 IN UINTN BufferSize,\r
549 OUT VOID *Buffer\r
ed66e1bc 550 );\r
ead42efc 551\r
552/**\r
630d580d 553 This function is the ATA implementation for WriteBlocks in the\r
554 Block I/O Protocol interface.\r
555\r
556 @param IdeBlkIoDevice Indicates the calling context.\r
557 @param MediaId The media id that the write request is for.\r
558 @param LBA The starting logical block address to write onto the device.\r
559 @param BufferSize The size of the Buffer in bytes. This must be a multiple\r
560 of the intrinsic block size of the device.\r
561 @param Buffer A pointer to the source buffer for the data.The caller\r
562 is responsible for either having implicit or explicit \r
563 ownership of the memory that data is written from.\r
ead42efc 564\r
630d580d 565 @retval EFI_SUCCESS Write Blocks successfully.\r
566 @retval EFI_DEVICE_ERROR Write Blocks failed.\r
567 @retval EFI_NO_MEDIA There is no media in the device.\r
568 @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.\r
ead42efc 569\r
630d580d 570 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r
571 intrinsic block size of the device.\r
572 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid,\r
573 or the data buffer is not valid.\r
ead42efc 574\r
630d580d 575 @note If Write Block error because of device error, this function will call\r
576 AtaSoftReset() function to reset device.\r
ead42efc 577**/\r
578EFI_STATUS\r
579AtaBlkIoWriteBlocks (\r
580 IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r
581 IN UINT32 MediaId,\r
e72ca438 582 IN EFI_LBA Lba,\r
ead42efc 583 IN UINTN BufferSize,\r
584 OUT VOID *Buffer\r
ed66e1bc 585 );\r
ead42efc 586\r
ead42efc 587/**\r
630d580d 588 This function is called by DiscoverIdeDevice() during its device\r
589 identification.\r
590 Its main purpose is to get enough information for the device media\r
591 to fill in the Media data structure of the Block I/O Protocol interface.\r
592\r
593 There are 5 steps to reach such objective:\r
594 1. Sends out the ATAPI Identify Command to the specified device. \r
595 Only ATAPI device responses to this command. If the command succeeds,\r
596 it returns the Identify data structure which filled with information \r
597 about the device. Since the ATAPI device contains removable media, \r
598 the only meaningful information is the device module name.\r
599 2. Sends out ATAPI Inquiry Packet Command to the specified device.\r
600 This command will return inquiry data of the device, which contains\r
601 the device type information.\r
602 3. Allocate sense data space for future use. We don't detect the media\r
603 presence here to improvement boot performance, especially when CD \r
604 media is present. The media detection will be performed just before\r
605 each BLK_IO read/write\r
606 \r
607 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r
608 to record all the information of the IDE device.\r
ead42efc 609\r
630d580d 610 @retval EFI_SUCCESS Identify ATAPI device successfully.\r
611 @retval EFI_DEVICE_ERROR ATAPI Identify Device Command failed or device type\r
612 is not supported by this IDE driver.\r
613 @retval EFI_OUT_OF_RESOURCES Allocate memory for sense data failed \r
ead42efc 614\r
630d580d 615 @note Parameter "IdeDev" will be updated in this function.\r
ead42efc 616**/\r
617EFI_STATUS\r
618ATAPIIdentify (\r
619 IN IDE_BLK_IO_DEV *IdeDev\r
ed66e1bc 620 );\r
ead42efc 621\r
622/**\r
630d580d 623 This function is used to implement the Soft Reset on the specified\r
624 ATAPI device. Different from the AtaSoftReset(), here reset is a ATA\r
625 Soft Reset Command special for ATAPI device, and it only take effects\r
626 on the specified ATAPI device, not on the whole IDE bus.\r
627 Since the ATAPI soft reset is needed when device is in exceptional\r
628 condition (such as BSY bit is always set ), I think the Soft Reset\r
629 command should be sent without waiting for the BSY clear and DRDY\r
630 set.\r
631 This function is called by IdeBlkIoReset(), \r
632 a interface function of Block I/O protocol.\r
ead42efc 633\r
630d580d 634 @param IdeDev pointer pointing to IDE_BLK_IO_DEV data structure, used\r
635 to record all the information of the IDE device.\r
ead42efc 636\r
630d580d 637 @retval EFI_SUCCESS Soft reset completes successfully.\r
638 @retval EFI_DEVICE_ERROR Any step during the reset process is failed.\r
ead42efc 639\r
640**/\r
641EFI_STATUS\r
642AtapiSoftReset (\r
643 IN IDE_BLK_IO_DEV *IdeDev\r
ed66e1bc 644 );\r
ead42efc 645\r
646/**\r
630d580d 647 This function is the ATAPI implementation for ReadBlocks in the\r
648 Block I/O Protocol interface.\r
ead42efc 649\r
630d580d 650 @param IdeBlkIoDevice Indicates the calling context.\r
651 @param MediaId The media id that the read request is for.\r
652 @param LBA The starting logical block address to read from on the device.\r
653 @param BufferSize The size of the Buffer in bytes. This must be a multiple\r
654 of the intrinsic block size of the device.\r
655 @param Buffer A pointer to the destination buffer for the data. The caller\r
656 is responsible for either having implicit or explicit \r
657 ownership of the memory that data is read into.\r
658 \r
659 @retval EFI_SUCCESS Read Blocks successfully.\r
660 @retval EFI_DEVICE_ERROR Read Blocks failed.\r
661 @retval EFI_NO_MEDIA There is no media in the device.\r
662 @retval EFI_MEDIA_CHANGED The MediaId is not for the current media.\r
663 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r
664 intrinsic block size of the device.\r
665 @retval EFI_INVALID_PARAMETER The read request contains LBAs that are not valid,\r
666 or the data buffer is not valid.\r
ead42efc 667**/\r
668EFI_STATUS\r
669AtapiBlkIoReadBlocks (\r
670 IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r
671 IN UINT32 MediaId,\r
e72ca438 672 IN EFI_LBA Lba,\r
ead42efc 673 IN UINTN BufferSize,\r
674 OUT VOID *Buffer\r
ed66e1bc 675 );\r
ead42efc 676\r
677/**\r
630d580d 678 This function is the ATAPI implementation for WriteBlocks in the\r
679 Block I/O Protocol interface.\r
ead42efc 680\r
630d580d 681 @param IdeBlkIoDevice Indicates the calling context.\r
682 @param MediaId The media id that the write request is for.\r
683 @param LBA The starting logical block address to write onto the device.\r
684 @param BufferSize The size of the Buffer in bytes. This must be a multiple\r
685 of the intrinsic block size of the device.\r
686 @param Buffer A pointer to the source buffer for the data. The caller\r
687 is responsible for either having implicit or explicit ownership\r
688 of the memory that data is written from.\r
ead42efc 689\r
630d580d 690 @retval EFI_SUCCESS Write Blocks successfully.\r
691 @retval EFI_DEVICE_ERROR Write Blocks failed.\r
692 @retval EFI_NO_MEDIA There is no media in the device.\r
693 @retval EFI_MEDIA_CHANGE The MediaId is not for the current media.\r
694 @retval EFI_BAD_BUFFER_SIZE The BufferSize parameter is not a multiple of the\r
695 intrinsic block size of the device. \r
696 @retval EFI_INVALID_PARAMETER The write request contains LBAs that are not valid, \r
697 or the data buffer is not valid.\r
ead42efc 698\r
630d580d 699 @retval EFI_WRITE_PROTECTED The write protected is enabled or the media does not support write\r
ead42efc 700**/\r
701EFI_STATUS\r
702AtapiBlkIoWriteBlocks (\r
703 IN IDE_BLK_IO_DEV *IdeBlkIoDevice,\r
704 IN UINT32 MediaId,\r
e72ca438 705 IN EFI_LBA Lba,\r
ead42efc 706 IN UINTN BufferSize,\r
707 OUT VOID *Buffer\r
ed66e1bc 708 );\r
ead42efc 709\r
710/**\r
630d580d 711 Release resources of an IDE device before stopping it.\r
ead42efc 712\r
630d580d 713 @param IdeBlkIoDevice Standard IDE device private data structure\r
ead42efc 714\r
715**/\r
716VOID\r
717ReleaseIdeResources (\r
718 IN IDE_BLK_IO_DEV *IdeBlkIoDevice\r
ed66e1bc 719 );\r
ead42efc 720\r
721/**\r
630d580d 722 Set the calculated Best transfer mode to a detected device\r
ead42efc 723\r
630d580d 724 @param IdeDev Standard IDE device private data structure\r
725 @param TransferMode The device transfer mode to be set\r
726 @return Set transfer mode Command execute status.\r
ead42efc 727**/\r
728EFI_STATUS\r
729SetDeviceTransferMode (\r
730 IN IDE_BLK_IO_DEV *IdeDev,\r
731 IN ATA_TRANSFER_MODE *TransferMode\r
ed66e1bc 732 );\r
ead42efc 733/**\r
630d580d 734 Send ATA command into device with NON_DATA protocol\r
ead42efc 735\r
630d580d 736 @param IdeDev Standard IDE device private data structure\r
737 @param AtaCommand The ATA command to be sent\r
738 @param Device The value in Device register\r
739 @param Feature The value in Feature register\r
740 @param SectorCount The value in SectorCount register\r
741 @param LbaLow The value in LBA_LOW register\r
742 @param LbaMiddle The value in LBA_MIDDLE register\r
743 @param LbaHigh The value in LBA_HIGH register\r
ead42efc 744\r
630d580d 745 @retval EFI_SUCCESS Reading succeed\r
746 @retval EFI_ABORTED Command failed\r
747 @retval EFI_DEVICE_ERROR Device status error.\r
ead42efc 748\r
749**/\r
750EFI_STATUS\r
751AtaNonDataCommandIn (\r
752 IN IDE_BLK_IO_DEV *IdeDev,\r
753 IN UINT8 AtaCommand,\r
754 IN UINT8 Device,\r
755 IN UINT8 Feature,\r
756 IN UINT8 SectorCount,\r
757 IN UINT8 LbaLow,\r
758 IN UINT8 LbaMiddle,\r
759 IN UINT8 LbaHigh\r
ed66e1bc 760 );\r
ead42efc 761\r
762/**\r
630d580d 763 Send ATA Ext command into device with NON_DATA protocol\r
ead42efc 764\r
630d580d 765 @param IdeDev Standard IDE device private data structure\r
766 @param AtaCommand The ATA command to be sent\r
767 @param Device The value in Device register\r
768 @param Feature The value in Feature register\r
769 @param SectorCount The value in SectorCount register\r
770 @param LbaAddress The LBA address in 48-bit mode\r
ead42efc 771\r
630d580d 772 @retval EFI_SUCCESS Reading succeed\r
773 @retval EFI_ABORTED Command failed\r
774 @retval EFI_DEVICE_ERROR Device status error.\r
ead42efc 775\r
776**/\r
777EFI_STATUS\r
778AtaNonDataCommandInExt (\r
779 IN IDE_BLK_IO_DEV *IdeDev,\r
780 IN UINT8 AtaCommand,\r
781 IN UINT8 Device,\r
782 IN UINT16 Feature,\r
783 IN UINT16 SectorCount,\r
784 IN EFI_LBA LbaAddress\r
ed66e1bc 785 );\r
75eccf9d 786/**\r
787 Enable Long Physical Sector Feature for ATA device.\r
788\r
789 @param IdeDev The IDE device data\r
790\r
791 @retval EFI_SUCCESS The ATA device supports Long Physical Sector feature\r
792 and corresponding fields in BlockIo structure is updated.\r
793 @retval EFI_UNSUPPORTED The device is not ATA device or Long Physical Sector\r
794 feature is not supported.\r
795**/\r
796EFI_STATUS\r
797AtaEnableLongPhysicalSector (\r
798 IN IDE_BLK_IO_DEV *IdeDev\r
799 );\r
800\r
ead42efc 801/**\r
630d580d 802 Set drive parameters for devices not support PACKETS command\r
ead42efc 803\r
630d580d 804 @param IdeDev Standard IDE device private data structure\r
805 @param DriveParameters The device parameters to be set into the disk\r
806 @return SetParameters Command execute status.\r
ead42efc 807\r
808**/\r
809EFI_STATUS\r
810SetDriveParameters (\r
811 IN IDE_BLK_IO_DEV *IdeDev,\r
812 IN ATA_DRIVE_PARMS *DriveParameters\r
ed66e1bc 813 );\r
ead42efc 814\r
815/**\r
630d580d 816 Enable Interrupt on IDE controller\r
ead42efc 817\r
630d580d 818 @param IdeDev Standard IDE device private data structure\r
ead42efc 819\r
630d580d 820 @retval EFI_SUCCESS Enable Interrupt successfully\r
ead42efc 821**/\r
822EFI_STATUS\r
823EnableInterrupt (\r
824 IN IDE_BLK_IO_DEV *IdeDev\r
ed66e1bc 825 );\r
ead42efc 826#endif\r