1 /** @file
2 Private Include file for IdeBus PEIM.
3 
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution.  The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11 
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14 
15 **/
16 
17 #ifndef _RECOVERY_ATAPI_H_
18 #define _RECOVERY_ATAPI_H_
19 
20 #include <PiPei.h>
21 
22 #include <Ppi/BlockIo.h>
23 #include <Ppi/AtaController.h>
24 
25 #include <Library/DebugLib.h>
26 #include <Library/TimerLib.h>
27 #include <Library/PeimEntryPoint.h>
28 #include <Library/PeiServicesLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/IoLib.h>
31 #include <Library/PeiServicesTablePointerLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/PcdLib.h>
34 
35 
36 #include <IndustryStandard/Atapi.h>
37 
38 #define MAX_SENSE_KEY_COUNT 6
39 #define MAX_IDE_CHANNELS    4  // Ide and Sata Primary, Secondary Channel.
40 #define MAX_IDE_DEVICES     8  // Ide, Sata Primary, Secondary and Master, Slave device.
41 
42 typedef enum {
43   IdePrimary    = 0,
44   IdeSecondary  = 1,
45   IdeMaxChannel = 2
46 } EFI_IDE_CHANNEL;
47 
48 typedef enum {
49   IdeMaster     = 0,
50   IdeSlave      = 1,
51   IdeMaxDevice  = 2
52 } EFI_IDE_DEVICE;
53 
54 //
55 // IDE Registers
56 //
57 typedef union {
58   UINT16  Command;        /* when write */
59   UINT16  Status;         /* when read */
60 } IDE_CMD_OR_STATUS;
61 
62 typedef union {
63   UINT16  Error;          /* when read */
64   UINT16  Feature;        /* when write */
65 } IDE_ERROR_OR_FEATURE;
66 
67 typedef union {
68   UINT16  AltStatus;      /* when read */
69   UINT16  DeviceControl;  /* when write */
70 } IDE_ALTSTATUS_OR_DEVICECONTROL;
71 
72 //
73 // IDE registers set
74 //
75 typedef struct {
76   UINT16                          Data;
77   IDE_ERROR_OR_FEATURE            Reg1;
78   UINT16                          SectorCount;
79   UINT16                          SectorNumber;
80   UINT16                          CylinderLsb;
81   UINT16                          CylinderMsb;
82   UINT16                          Head;
83   IDE_CMD_OR_STATUS               Reg;
84 
85   IDE_ALTSTATUS_OR_DEVICECONTROL  Alt;
86   UINT16                          DriveAddress;
87 } IDE_BASE_REGISTERS;
88 
89 typedef struct {
90 
91   UINTN                   DevicePosition;
92   EFI_PEI_BLOCK_IO_MEDIA  MediaInfo;
93 
94 } PEI_ATAPI_DEVICE_INFO;
95 
96 #define ATAPI_BLK_IO_DEV_SIGNATURE  SIGNATURE_32 ('a', 'b', 'i', 'o')
97 typedef struct {
98   UINTN                           Signature;
99 
100   EFI_PEI_RECOVERY_BLOCK_IO_PPI   AtapiBlkIo;
101   EFI_PEI_PPI_DESCRIPTOR          PpiDescriptor;
102   PEI_ATA_CONTROLLER_PPI          *AtaControllerPpi;
103 
104   UINTN                           DeviceCount;
105   PEI_ATAPI_DEVICE_INFO           DeviceInfo[MAX_IDE_DEVICES];   //for max 8 device
106   IDE_BASE_REGISTERS              IdeIoPortReg[MAX_IDE_CHANNELS]; //for max 4 channel.
107 } ATAPI_BLK_IO_DEV;
108 
109 #define PEI_RECOVERY_ATAPI_FROM_BLKIO_THIS(a) CR (a, ATAPI_BLK_IO_DEV, AtapiBlkIo, ATAPI_BLK_IO_DEV_SIGNATURE)
110 
111 
112 #define STALL_1_MILLI_SECOND  1000  // stall 1 ms
113 #define STALL_1_SECONDS       1000 * STALL_1_MILLI_SECOND
114 
115 //
116 // Time Out Value For IDE Device Polling
117 //
118 // ATATIMEOUT is used for waiting time out for ATA device
119 //
120 #define ATATIMEOUT  1000  // 1 second
121 // ATAPITIMEOUT is used for waiting operation
122 // except read and write time out for ATAPI device
123 //
124 #define ATAPITIMEOUT  1000  // 1 second
125 // ATAPILONGTIMEOUT is used for waiting read and
126 // write operation timeout for ATAPI device
127 //
128 #define CDROMLONGTIMEOUT  2000  // 2 seconds
129 #define ATAPILONGTIMEOUT  5000  // 5 seconds
130 
131 //
132 // PEI Recovery Block I/O PPI
133 //
134 
135 /**
136   Gets the count of block I/O devices that one specific block driver detects.
137 
138   This function is used for getting the count of block I/O devices that one
139   specific block driver detects.  To the PEI ATAPI driver, it returns the number
140   of all the detected ATAPI devices it detects during the enumeration process.
141   To the PEI legacy floppy driver, it returns the number of all the legacy
142   devices it finds during its enumeration process. If no device is detected,
143   then the function will return zero.
144 
145   @param[in]  PeiServices          General-purpose services that are available
146                                    to every PEIM.
147   @param[in]  This                 Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI
148                                    instance.
149   @param[out] NumberBlockDevices   The number of block I/O devices discovered.
150 
151   @retval     EFI_SUCCESS          Operation performed successfully.
152 
153 **/
154 EFI_STATUS
155 EFIAPI
156 AtapiGetNumberOfBlockDevices (
157   IN   EFI_PEI_SERVICES                  **PeiServices,
158   IN   EFI_PEI_RECOVERY_BLOCK_IO_PPI     *This,
159   OUT  UINTN                             *NumberBlockDevices
160   );
161 
162 /**
163   Gets a block device's media information.
164 
165   This function will provide the caller with the specified block device's media
166   information. If the media changes, calling this function will update the media
167   information accordingly.
168 
169   @param[in]  PeiServices   General-purpose services that are available to every
170                             PEIM
171   @param[in]  This          Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
172   @param[in]  DeviceIndex   Specifies the block device to which the function wants
173                             to talk. Because the driver that implements Block I/O
174                             PPIs will manage multiple block devices, the PPIs that
175                             want to talk to a single device must specify the
176                             device index that was assigned during the enumeration
177                             process. This index is a number from one to
178                             NumberBlockDevices.
179   @param[out] MediaInfo     The media information of the specified block media.
180                             The caller is responsible for the ownership of this
181                             data structure.
182 
183   @retval EFI_SUCCESS           Media information about the specified block device
184                                 was obtained successfully.
185   @retval EFI_DEVICE_ERROR      Cannot get the media information due to a hardware
186                                 error.
187   @retval Others                Other failure occurs.
188 
189 **/
190 EFI_STATUS
191 EFIAPI
192 AtapiGetBlockDeviceMediaInfo (
193   IN   EFI_PEI_SERVICES                     **PeiServices,
194   IN   EFI_PEI_RECOVERY_BLOCK_IO_PPI        *This,
195   IN   UINTN                                DeviceIndex,
196   OUT  EFI_PEI_BLOCK_IO_MEDIA               *MediaInfo
197   );
198 
199 /**
200   Reads the requested number of blocks from the specified block device.
201 
202   The function reads the requested number of blocks from the device. All the
203   blocks are read, or an error is returned. If there is no media in the device,
204   the function returns EFI_NO_MEDIA.
205 
206   @param[in]  PeiServices   General-purpose services that are available to
207                             every PEIM.
208   @param[in]  This          Indicates the EFI_PEI_RECOVERY_BLOCK_IO_PPI instance.
209   @param[in]  DeviceIndex   Specifies the block device to which the function wants
210                             to talk. Because the driver that implements Block I/O
211                             PPIs will manage multiple block devices, the PPIs that
212                             want to talk to a single device must specify the device
213                             index that was assigned during the enumeration process.
214                             This index is a number from one to NumberBlockDevices.
215   @param[in]  StartLBA      The starting logical block address (LBA) to read from
216                             on the device
217   @param[in]  BufferSize    The size of the Buffer in bytes. This number must be
218                             a multiple of the intrinsic block size of the device.
219   @param[out] Buffer        A pointer to the destination buffer for the data.
220                             The caller is responsible for the ownership of the
221                             buffer.
222 
223   @retval EFI_SUCCESS             The data was read correctly from the device.
224   @retval EFI_DEVICE_ERROR        The device reported an error while attempting
225                                   to perform the read operation.
226   @retval EFI_INVALID_PARAMETER   The read request contains LBAs that are not
227                                   valid, or the buffer is not properly aligned.
228   @retval EFI_NO_MEDIA            There is no media in the device.
229   @retval EFI_BAD_BUFFER_SIZE     The BufferSize parameter is not a multiple of
230                                   the intrinsic block size of the device.
231 
232 **/
233 EFI_STATUS
234 EFIAPI
235 AtapiReadBlocks (
236   IN   EFI_PEI_SERVICES                  **PeiServices,
237   IN   EFI_PEI_RECOVERY_BLOCK_IO_PPI     *This,
238   IN   UINTN                             DeviceIndex,
239   IN   EFI_PEI_LBA                       StartLBA,
240   IN   UINTN                             BufferSize,
241   OUT  VOID                              *Buffer
242   );
243 
244 //
245 // Internal functions
246 //
247 
248 /**
249   Enumerate Atapi devices.
250 
251   This function is used to enumerate Atatpi device in Ide channel.
252 
253   @param[in]  AtapiBlkIoDev  A pointer to atapi block IO device
254 
255 **/
256 VOID
257 AtapiEnumerateDevices (
258   IN  ATAPI_BLK_IO_DEV  *AtapiBlkIoDev
259   );
260 
261 /**
262   Detect Atapi devices.
263 
264   @param[in]  AtapiBlkIoDev   A pointer to atapi block IO device.
265   @param[in]  DevicePosition  An integer to signify device position.
266   @param[out] MediaInfo       The media information of the specified block media.
267 
268   @retval TRUE                Atapi device exists in specified position.
269   @retval FALSE               Atapi device does not exist in specified position.
270 
271 **/
272 BOOLEAN
273 DiscoverAtapiDevice (
274   IN  ATAPI_BLK_IO_DEV              *AtapiBlkIoDev,
275   IN  UINTN                         DevicePosition,
276   OUT EFI_PEI_BLOCK_IO_MEDIA        *MediaInfo
277   );
278 
279 /**
280   Detect if an IDE controller exists in specified position.
281 
282   @param[in]  AtapiBlkIoDev   A pointer to atapi block IO device.
283   @param[in]  DevicePosition  An integer to signify device position.
284 
285   @retval TRUE         The Atapi device exists.
286   @retval FALSE        The Atapi device does not present.
287 
288 **/
289 BOOLEAN
290 DetectIDEController (
291   IN  ATAPI_BLK_IO_DEV   *AtapiBlkIoDev,
292   IN  UINTN              DevicePosition
293   );
294 
295 /**
296   Wait specified time interval to poll for BSY bit clear in the Status Register.
297 
298   @param[in]  AtapiBlkIoDev          A pointer to atapi block IO device.
299   @param[in]  IdeIoRegisters         A pointer to IDE IO registers.
300   @param[in]  TimeoutInMilliSeconds  Time specified in milliseconds.
301 
302   @retval EFI_SUCCESS        BSY bit is cleared in the specified time interval.
303   @retval EFI_TIMEOUT        BSY bit is not cleared in the specified time interval.
304 
305 **/
306 EFI_STATUS
307 WaitForBSYClear (
308   IN  ATAPI_BLK_IO_DEV    *AtapiBlkIoDev,
309   IN  IDE_BASE_REGISTERS  *IdeIoRegisters,
310   IN  UINTN               TimeoutInMilliSeconds
311   );
312 
313 /**
314   Wait specified time interval to poll for DRDY bit set in the Status register.
315 
316   @param[in]  AtapiBlkIoDev          A pointer to atapi block IO device.
317   @param[in]  IdeIoRegisters         A pointer to IDE IO registers.
318   @param[in]  TimeoutInMilliSeconds  Time specified in milliseconds.
319 
320   @retval EFI_SUCCESS        DRDY bit is set in the specified time interval.
321   @retval EFI_TIMEOUT        DRDY bit is not set in the specified time interval.
322 
323 **/
324 EFI_STATUS
325 DRDYReady (
326   IN  ATAPI_BLK_IO_DEV    *AtapiBlkIoDev,
327   IN  IDE_BASE_REGISTERS  *IdeIoRegisters,
328   IN  UINTN               TimeoutInMilliSeconds
329   );
330 
331 /**
332   Wait specified time interval to poll for DRQ bit clear in the Status Register.
333 
334   @param[in]  AtapiBlkIoDev          A pointer to atapi block IO device.
335   @param[in]  IdeIoRegisters         A pointer to IDE IO registers.
336   @param[in]  TimeoutInMilliSeconds  Time specified in milliseconds.
337 
338   @retval EFI_SUCCESS        DRQ bit is cleared in the specified time interval.
339   @retval EFI_TIMEOUT        DRQ bit is not cleared in the specified time interval.
340 
341 **/
342 EFI_STATUS
343 DRQClear (
344   IN  ATAPI_BLK_IO_DEV    *AtapiBlkIoDev,
345   IN  IDE_BASE_REGISTERS  *IdeIoRegisters,
346   IN  UINTN               TimeoutInMilliSeconds
347   );
348 
349 /**
350   Wait specified time interval to poll for DRQ bit clear in the Alternate Status Register.
351 
352   @param[in]  AtapiBlkIoDev          A pointer to atapi block IO device.
353   @param[in]  IdeIoRegisters         A pointer to IDE IO registers.
354   @param[in]  TimeoutInMilliSeconds  Time specified in milliseconds.
355 
356   @retval EFI_SUCCESS        DRQ bit is cleared in the specified time interval.
357   @retval EFI_TIMEOUT        DRQ bit is not cleared in the specified time interval.
358 
359 **/
360 EFI_STATUS
361 DRQClear2 (
362   IN  ATAPI_BLK_IO_DEV    *AtapiBlkIoDev,
363   IN  IDE_BASE_REGISTERS  *IdeIoRegisters,
364   IN  UINTN               TimeoutInMilliSeconds
365   );
366 
367 /**
368   Wait specified time interval to poll for DRQ bit set in the Status Register.
369 
370   @param[in]  AtapiBlkIoDev          A pointer to atapi block IO device.
371   @param[in]  IdeIoRegisters         A pointer to IDE IO registers.
372   @param[in]  TimeoutInMilliSeconds  Time specified in milliseconds.
373 
374   @retval EFI_SUCCESS        DRQ bit is set in the specified time interval.
375   @retval EFI_TIMEOUT        DRQ bit is not set in the specified time interval.
376   @retval EFI_ABORTED        Operation Aborted.
377 
378 **/
379 EFI_STATUS
380 DRQReady (
381   IN  ATAPI_BLK_IO_DEV    *AtapiBlkIoDev,
382   IN  IDE_BASE_REGISTERS  *IdeIoRegisters,
383   IN  UINTN               TimeoutInMilliSeconds
384   );
385 
386 /**
387   Wait specified time interval to poll for DRQ bit set in the Alternate Status Register.
388 
389   @param[in]  AtapiBlkIoDev          A pointer to atapi block IO device.
390   @param[in]  IdeIoRegisters         A pointer to IDE IO registers.
391   @param[in]  TimeoutInMilliSeconds  Time specified in milliseconds.
392 
393   @retval EFI_SUCCESS        DRQ bit is set in the specified time interval.
394   @retval EFI_TIMEOUT        DRQ bit is not set in the specified time interval.
395   @retval EFI_ABORTED        Operation Aborted.
396 
397 **/
398 EFI_STATUS
399 DRQReady2 (
400   IN  ATAPI_BLK_IO_DEV    *AtapiBlkIoDev,
401   IN  IDE_BASE_REGISTERS  *IdeIoRegisters,
402   IN  UINTN               TimeoutInMilliSeconds
403   );
404 
405 /**
406   Check if there is an error in Status Register.
407 
408   @param[in]  AtapiBlkIoDev     A pointer to atapi block IO device.
409   @param[in]  StatusReg         The address to IDE IO registers.
410 
411   @retval EFI_SUCCESS        Operation success.
412   @retval EFI_DEVICE_ERROR   Device error.
413 
414 **/
415 EFI_STATUS
416 CheckErrorStatus (
417   IN  ATAPI_BLK_IO_DEV    *AtapiBlkIoDev,
418   IN  UINT16              StatusReg
419   );
420 
421 /**
422   Idendify Atapi devices.
423 
424   @param[in]  AtapiBlkIoDev     A pointer to atapi block IO device.
425   @param[in]  DevicePosition    An integer to signify device position.
426 
427   @retval EFI_SUCCESS        Identify successfully.
428   @retval EFI_DEVICE_ERROR   Device cannot be identified successfully.
429 
430 **/
431 EFI_STATUS
432 ATAPIIdentify (
433   IN  ATAPI_BLK_IO_DEV        *AtapiBlkIoDev,
434   IN  UINTN                   DevicePosition
435   );
436 
437 /**
438   Sends out ATAPI Test Unit Ready Packet Command to the specified device
439   to find out whether device is accessible.
440 
441   @param[in]  AtapiBlkIoDev     A pointer to atapi block IO device.
442   @param[in]  DevicePosition    An integer to signify device position.
443 
444   @retval EFI_SUCCESS        TestUnit command executed successfully.
445   @retval EFI_DEVICE_ERROR   Device cannot be executed TestUnit command successfully.
446 
447 **/
448 EFI_STATUS
449 TestUnitReady (
450   IN  ATAPI_BLK_IO_DEV    *AtapiBlkIoDev,
451   IN  UINTN               DevicePosition
452   ) ;
453 
454 /**
455   Send out ATAPI commands conforms to the Packet Command with PIO Data In Protocol.
456 
457   @param[in]  AtapiBlkIoDev         A pointer to atapi block IO device.
458   @param[in]  DevicePosition        An integer to signify device position.
459   @param[in]  Packet                A pointer to ATAPI command packet.
460   @param[in]  Buffer                Buffer to contain requested transfer data from device.
461   @param[in]  ByteCount             Requested transfer data length.
462   @param[in]  TimeoutInMilliSeconds Time out value, in unit of milliseconds.
463 
464   @retval EFI_SUCCESS        Command executed successfully.
465   @retval EFI_DEVICE_ERROR   Device cannot be executed command successfully.
466 
467 **/
468 EFI_STATUS
469 AtapiPacketCommandIn (
470   IN  ATAPI_BLK_IO_DEV      *AtapiBlkIoDev,
471   IN  UINTN                 DevicePosition,
472   IN  ATAPI_PACKET_COMMAND  *Packet,
473   IN  UINT16                *Buffer,
474   IN  UINT32                ByteCount,
475   IN  UINTN                 TimeoutInMilliSeconds
476   );
477 
478 /**
479   Sends out ATAPI Inquiry Packet Command to the specified device.
480   This command will return INQUIRY data of the device.
481 
482   @param[in]  AtapiBlkIoDev   A pointer to atapi block IO device.
483   @param[in]  DevicePosition  An integer to signify device position.
484   @param[out] MediaInfo       The media information of the specified block media.
485 
486   @retval EFI_SUCCESS        Command executed successfully.
487   @retval EFI_DEVICE_ERROR   Device cannot be executed command successfully.
488   @retval EFI_UNSUPPORTED    Unsupported device type.
489 
490 **/
491 EFI_STATUS
492 Inquiry (
493   IN  ATAPI_BLK_IO_DEV              *AtapiBlkIoDev,
494   IN  UINTN                         DevicePosition,
495   OUT EFI_PEI_BLOCK_IO_MEDIA        *MediaInfo
496   );
497 
498 /**
499   Used before read/write blocks from/to ATAPI device media.
500   Since ATAPI device media is removable, it is necessary to detect
501   whether media is present and get current present media's information.
502 
503   @param[in]  AtapiBlkIoDev     A pointer to atapi block IO device.
504   @param[in]  DevicePosition    An integer to signify device position.
505   @param[in, out] MediaInfo         The media information of the specified block media.
506 
507   @retval EFI_SUCCESS           Command executed successfully.
508   @retval EFI_DEVICE_ERROR      Some device errors happen.
509   @retval EFI_OUT_OF_RESOURCES  Can not allocate required resources.
510 
511 **/
512 EFI_STATUS
513 DetectMedia (
514   IN  ATAPI_BLK_IO_DEV              *AtapiBlkIoDev,
515   IN  UINTN                         DevicePosition,
516   IN OUT EFI_PEI_BLOCK_IO_MEDIA     *MediaInfo
517   );
518 
519 /**
520   Reset specified Atapi device.
521 
522   @param[in]  AtapiBlkIoDev     A pointer to atapi block IO device.
523   @param[in]  DevicePosition    An integer to signify device position.
524   @param[in]  Extensive         If TRUE, use ATA soft reset, otherwise use Atapi soft reset.
525 
526   @retval EFI_SUCCESS           Command executed successfully.
527   @retval EFI_DEVICE_ERROR      Some device errors happen.
528 
529 **/
530 EFI_STATUS
531 ResetDevice (
532   IN  ATAPI_BLK_IO_DEV  *AtapiBlkIoDev,
533   IN  UINTN             DevicePosition,
534   IN  BOOLEAN           Extensive
535   );
536 
537 /**
538   Sends out ATAPI Request Sense Packet Command to the specified device.
539 
540   @param[in]      AtapiBlkIoDev   A pointer to atapi block IO device.
541   @param[in]      DevicePosition  An integer to signify device position.
542   @param[in]      SenseBuffers    Pointer to sense buffer.
543   @param[in, out] SenseCounts     Length of sense buffer.
544 
545   @retval EFI_SUCCESS           Command executed successfully.
546   @retval EFI_DEVICE_ERROR      Some device errors happen.
547 
548 **/
549 EFI_STATUS
550 RequestSense (
551   IN  ATAPI_BLK_IO_DEV    *AtapiBlkIoDev,
552   IN  UINTN               DevicePosition,
553   IN  ATAPI_REQUEST_SENSE_DATA  *SenseBuffers,
554   IN OUT  UINT8           *SenseCounts
555   );
556 
557 /**
558   Sends out ATAPI Read Capacity Packet Command to the specified device.
559   This command will return the information regarding the capacity of the
560   media in the device.
561 
562   @param[in]  AtapiBlkIoDev   A pointer to atapi block IO device.
563   @param[in]  DevicePosition  An integer to signify device position.
564   @param[in, out] MediaInfo       The media information of the specified block media.
565 
566   @retval EFI_SUCCESS           Command executed successfully.
567   @retval EFI_DEVICE_ERROR      Some device errors happen.
568 
569 **/
570 EFI_STATUS
571 ReadCapacity (
572   IN  ATAPI_BLK_IO_DEV              *AtapiBlkIoDev,
573   IN  UINTN                         DevicePosition,
574   IN OUT EFI_PEI_BLOCK_IO_MEDIA     *MediaInfo
575   );
576 
577 /**
578   Perform read from disk in block unit.
579 
580   @param[in]  AtapiBlkIoDev   A pointer to atapi block IO device.
581   @param[in]  DevicePosition  An integer to signify device position.
582   @param[in]  Buffer          Buffer to contain read data.
583   @param[in]  StartLba        Starting LBA address.
584   @param[in]  NumberOfBlocks  Number of blocks to read.
585   @param[in]  BlockSize       Size of each block.
586 
587   @retval EFI_SUCCESS           Command executed successfully.
588   @retval EFI_DEVICE_ERROR      Some device errors happen.
589 
590 **/
591 EFI_STATUS
592 ReadSectors (
593   IN  ATAPI_BLK_IO_DEV    *AtapiBlkIoDev,
594   IN  UINTN               DevicePosition,
595   IN  VOID                *Buffer,
596   IN  EFI_PEI_LBA         StartLba,
597   IN  UINTN               NumberOfBlocks,
598   IN  UINTN               BlockSize
599   );
600 
601 /**
602   Check if there is media according to sense data.
603 
604   @param[in]  SenseData   Pointer to sense data.
605   @param[in]  SenseCounts Count of sense data.
606 
607   @retval TRUE    No media
608   @retval FALSE   Media exists
609 
610 **/
611 BOOLEAN
612 IsNoMedia (
613   IN  ATAPI_REQUEST_SENSE_DATA    *SenseData,
614   IN  UINTN                 SenseCounts
615   );
616 
617 /**
618   Check if device state is unclear according to sense data.
619 
620   @param[in]  SenseData   Pointer to sense data.
621   @param[in]  SenseCounts Count of sense data.
622 
623   @retval TRUE    Device state is unclear
624   @retval FALSE   Device state is clear
625 
626 **/
627 BOOLEAN
628 IsDeviceStateUnclear (
629   IN  ATAPI_REQUEST_SENSE_DATA    *SenseData,
630   IN  UINTN                 SenseCounts
631   );
632 
633 /**
634   Check if there is media error according to sense data.
635 
636   @param[in]  SenseData   Pointer to sense data.
637   @param[in]  SenseCounts Count of sense data.
638 
639   @retval TRUE    Media error
640   @retval FALSE   No media error
641 
642 **/
643 BOOLEAN
644 IsMediaError (
645   IN  ATAPI_REQUEST_SENSE_DATA    *SenseData,
646   IN  UINTN                 SenseCounts
647   );
648 
649 /**
650   Check if drive is ready according to sense data.
651 
652   @param[in]  SenseData   Pointer to sense data.
653   @param[in]  SenseCounts Count of sense data.
654   @param[out] NeedRetry   Indicate if retry is needed.
655 
656   @retval TRUE    Drive ready
657   @retval FALSE   Drive not ready
658 
659 **/
660 BOOLEAN
661 IsDriveReady (
662   IN  ATAPI_REQUEST_SENSE_DATA    *SenseData,
663   IN  UINTN                 SenseCounts,
664   OUT BOOLEAN               *NeedRetry
665   );
666 
667 #endif
668