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