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