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