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