]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Scsi/ScsiDiskDxe/ScsiDisk.h
Fix the comments to follow UEFI Spec regarding how to check an EFI_HANDLE is valid...
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiDiskDxe / ScsiDisk.h
1 /** @file
2 Header file for SCSI Disk Driver.
3
4 Copyright (c) 2004 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15 #ifndef _SCSI_DISK_H_
16 #define _SCSI_DISK_H_
17
18
19 #include <Uefi.h>
20
21
22 #include <Protocol/ScsiIo.h>
23 #include <Protocol/ComponentName.h>
24 #include <Protocol/BlockIo.h>
25 #include <Protocol/DriverBinding.h>
26 #include <Protocol/ScsiPassThruExt.h>
27 #include <Protocol/ScsiPassThru.h>
28 #include <Protocol/DiskInfo.h>
29
30
31 #include <Library/DebugLib.h>
32 #include <Library/UefiDriverEntryPoint.h>
33 #include <Library/UefiLib.h>
34 #include <Library/BaseMemoryLib.h>
35 #include <Library/MemoryAllocationLib.h>
36 #include <Library/UefiScsiLib.h>
37 #include <Library/UefiBootServicesTableLib.h>
38 #include <Library/DevicePathLib.h>
39
40 #include <IndustryStandard/Scsi.h>
41 #include <IndustryStandard/Atapi.h>
42
43 #define IS_DEVICE_FIXED(a) (a)->FixedDevice ? 1 : 0
44
45 #define SCSI_DISK_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'd', 'k')
46
47 typedef struct {
48 UINT32 Signature;
49
50 EFI_HANDLE Handle;
51
52 EFI_BLOCK_IO_PROTOCOL BlkIo;
53 EFI_BLOCK_IO_MEDIA BlkIoMedia;
54 EFI_SCSI_IO_PROTOCOL *ScsiIo;
55 UINT8 DeviceType;
56 BOOLEAN FixedDevice;
57 UINT16 Reserved;
58
59 EFI_SCSI_SENSE_DATA *SenseData;
60 UINTN SenseDataNumber;
61 EFI_SCSI_INQUIRY_DATA InquiryData;
62
63 EFI_UNICODE_STRING_TABLE *ControllerNameTable;
64
65 EFI_DISK_INFO_PROTOCOL DiskInfo;
66
67 //
68 // The following fields are only valid for ATAPI/SATA device
69 //
70 UINT32 Channel;
71 UINT32 Device;
72 ATAPI_IDENTIFY_DATA IdentifyData;
73
74 //
75 // The flag indicates if 16-byte command can be used
76 //
77 BOOLEAN Cdb16Byte;
78 } SCSI_DISK_DEV;
79
80 #define SCSI_DISK_DEV_FROM_THIS(a) CR (a, SCSI_DISK_DEV, BlkIo, SCSI_DISK_DEV_SIGNATURE)
81
82 #define SCSI_DISK_DEV_FROM_DISKINFO(a) CR (a, SCSI_DISK_DEV, DiskInfo, SCSI_DISK_DEV_SIGNATURE)
83
84 //
85 // Global Variables
86 //
87 extern EFI_DRIVER_BINDING_PROTOCOL gScsiDiskDriverBinding;
88 extern EFI_COMPONENT_NAME_PROTOCOL gScsiDiskComponentName;
89 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiDiskComponentName2;
90 //
91 // action code used in detect media process
92 //
93 #define ACTION_NO_ACTION 0x00
94 #define ACTION_READ_CAPACITY 0x01
95 #define ACTION_RETRY_COMMAND_LATER 0x02
96
97 #define SCSI_COMMAND_VERSION_1 0x01
98 #define SCSI_COMMAND_VERSION_2 0x02
99 #define SCSI_COMMAND_VERSION_3 0x03
100
101
102 /**
103 Test to see if this driver supports ControllerHandle.
104
105 This service is called by the EFI boot service ConnectController(). In order
106 to make drivers as small as possible, there are a few calling restrictions for
107 this service. ConnectController() must follow these calling restrictions.
108 If any other agent wishes to call Supported() it must also follow these
109 calling restrictions.
110
111 @param This Protocol instance pointer.
112 @param ControllerHandle Handle of device to test
113 @param RemainingDevicePath Optional parameter use to pick a specific child
114 device to start.
115
116 @retval EFI_SUCCESS This driver supports this device
117 @retval EFI_ALREADY_STARTED This driver is already running on this device
118 @retval other This driver does not support this device
119
120 **/
121 EFI_STATUS
122 EFIAPI
123 ScsiDiskDriverBindingSupported (
124 IN EFI_DRIVER_BINDING_PROTOCOL *This,
125 IN EFI_HANDLE Controller,
126 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
127 );
128
129 /**
130 Start this driver on ControllerHandle.
131
132 This service is called by the EFI boot service ConnectController(). In order
133 to make drivers as small as possible, there are a few calling restrictions for
134 this service. ConnectController() must follow these calling restrictions. If
135 any other agent wishes to call Start() it must also follow these calling
136 restrictions.
137
138 @param This Protocol instance pointer.
139 @param ControllerHandle Handle of device to bind driver to
140 @param RemainingDevicePath Optional parameter use to pick a specific child
141 device to start.
142
143 @retval EFI_SUCCESS This driver is added to ControllerHandle
144 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
145 @retval other This driver does not support this device
146
147 **/
148 EFI_STATUS
149 EFIAPI
150 ScsiDiskDriverBindingStart (
151 IN EFI_DRIVER_BINDING_PROTOCOL *This,
152 IN EFI_HANDLE Controller,
153 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL
154 );
155
156 /**
157 Stop this driver on ControllerHandle.
158
159 This service is called by the EFI boot service DisconnectController().
160 In order to make drivers as small as possible, there are a few calling
161 restrictions for this service. DisconnectController() must follow these
162 calling restrictions. If any other agent wishes to call Stop() it must
163 also follow these calling restrictions.
164
165 @param This Protocol instance pointer.
166 @param ControllerHandle Handle of device to stop driver on
167 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
168 children is zero stop the entire bus driver.
169 @param ChildHandleBuffer List of Child Handles to Stop.
170
171 @retval EFI_SUCCESS This driver is removed ControllerHandle
172 @retval other This driver was not removed from this device
173
174 **/
175 EFI_STATUS
176 EFIAPI
177 ScsiDiskDriverBindingStop (
178 IN EFI_DRIVER_BINDING_PROTOCOL *This,
179 IN EFI_HANDLE Controller,
180 IN UINTN NumberOfChildren,
181 IN EFI_HANDLE *ChildHandleBuffer OPTIONAL
182 );
183
184 //
185 // EFI Component Name Functions
186 //
187 /**
188 Retrieves a Unicode string that is the user readable name of the driver.
189
190 This function retrieves the user readable name of a driver in the form of a
191 Unicode string. If the driver specified by This has a user readable name in
192 the language specified by Language, then a pointer to the driver name is
193 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
194 by This does not support the language specified by Language,
195 then EFI_UNSUPPORTED is returned.
196
197 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
198 EFI_COMPONENT_NAME_PROTOCOL instance.
199
200 @param Language A pointer to a Null-terminated ASCII string
201 array indicating the language. This is the
202 language of the driver name that the caller is
203 requesting, and it must match one of the
204 languages specified in SupportedLanguages. The
205 number of languages supported by a driver is up
206 to the driver writer. Language is specified
207 in RFC 4646 or ISO 639-2 language code format.
208
209 @param DriverName A pointer to the Unicode string to return.
210 This Unicode string is the name of the
211 driver specified by This in the language
212 specified by Language.
213
214 @retval EFI_SUCCESS The Unicode string for the Driver specified by
215 This and the language specified by Language was
216 returned in DriverName.
217
218 @retval EFI_INVALID_PARAMETER Language is NULL.
219
220 @retval EFI_INVALID_PARAMETER DriverName is NULL.
221
222 @retval EFI_UNSUPPORTED The driver specified by This does not support
223 the language specified by Language.
224
225 **/
226 EFI_STATUS
227 EFIAPI
228 ScsiDiskComponentNameGetDriverName (
229 IN EFI_COMPONENT_NAME_PROTOCOL *This,
230 IN CHAR8 *Language,
231 OUT CHAR16 **DriverName
232 );
233
234
235 /**
236 Retrieves a Unicode string that is the user readable name of the controller
237 that is being managed by a driver.
238
239 This function retrieves the user readable name of the controller specified by
240 ControllerHandle and ChildHandle in the form of a Unicode string. If the
241 driver specified by This has a user readable name in the language specified by
242 Language, then a pointer to the controller name is returned in ControllerName,
243 and EFI_SUCCESS is returned. If the driver specified by This is not currently
244 managing the controller specified by ControllerHandle and ChildHandle,
245 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
246 support the language specified by Language, then EFI_UNSUPPORTED is returned.
247
248 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
249 EFI_COMPONENT_NAME_PROTOCOL instance.
250
251 @param ControllerHandle The handle of a controller that the driver
252 specified by This is managing. This handle
253 specifies the controller whose name is to be
254 returned.
255
256 @param ChildHandle The handle of the child controller to retrieve
257 the name of. This is an optional parameter that
258 may be NULL. It will be NULL for device
259 drivers. It will also be NULL for a bus drivers
260 that wish to retrieve the name of the bus
261 controller. It will not be NULL for a bus
262 driver that wishes to retrieve the name of a
263 child controller.
264
265 @param Language A pointer to a Null-terminated ASCII string
266 array indicating the language. This is the
267 language of the driver name that the caller is
268 requesting, and it must match one of the
269 languages specified in SupportedLanguages. The
270 number of languages supported by a driver is up
271 to the driver writer. Language is specified in
272 RFC 4646 or ISO 639-2 language code format.
273
274 @param ControllerName A pointer to the Unicode string to return.
275 This Unicode string is the name of the
276 controller specified by ControllerHandle and
277 ChildHandle in the language specified by
278 Language from the point of view of the driver
279 specified by This.
280
281 @retval EFI_SUCCESS The Unicode string for the user readable name in
282 the language specified by Language for the
283 driver specified by This was returned in
284 DriverName.
285
286 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
287
288 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
289 EFI_HANDLE.
290
291 @retval EFI_INVALID_PARAMETER Language is NULL.
292
293 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
294
295 @retval EFI_UNSUPPORTED The driver specified by This is not currently
296 managing the controller specified by
297 ControllerHandle and ChildHandle.
298
299 @retval EFI_UNSUPPORTED The driver specified by This does not support
300 the language specified by Language.
301
302 **/
303 EFI_STATUS
304 EFIAPI
305 ScsiDiskComponentNameGetControllerName (
306 IN EFI_COMPONENT_NAME_PROTOCOL *This,
307 IN EFI_HANDLE ControllerHandle,
308 IN EFI_HANDLE ChildHandle OPTIONAL,
309 IN CHAR8 *Language,
310 OUT CHAR16 **ControllerName
311 );
312
313 /**
314 Reset SCSI Disk.
315
316
317 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
318 @param ExtendedVerification The flag about if extend verificate
319
320 @retval EFI_SUCCESS The device was reset.
321 @retval EFI_DEVICE_ERROR The device is not functioning properly and could
322 not be reset.
323 @return EFI_STATUS is retured from EFI_SCSI_IO_PROTOCOL.ResetDevice().
324
325 **/
326 EFI_STATUS
327 EFIAPI
328 ScsiDiskReset (
329 IN EFI_BLOCK_IO_PROTOCOL *This,
330 IN BOOLEAN ExtendedVerification
331 );
332
333
334 /**
335 The function is to Read Block from SCSI Disk.
336
337 @param This The pointer of EFI_BLOCK_IO_PROTOCOL.
338 @param MediaId The Id of Media detected
339 @param Lba The logic block address
340 @param BufferSize The size of Buffer
341 @param Buffer The buffer to fill the read out data
342
343 @retval EFI_SUCCESS Successfully to read out block.
344 @retval EFI_DEVICE_ERROR Fail to detect media.
345 @retval EFI_NO_MEDIA Media is not present.
346 @retval EFI_MEDIA_CHANGED Media has changed.
347 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
348 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
349
350 **/
351 EFI_STATUS
352 EFIAPI
353 ScsiDiskReadBlocks (
354 IN EFI_BLOCK_IO_PROTOCOL *This,
355 IN UINT32 MediaId,
356 IN EFI_LBA Lba,
357 IN UINTN BufferSize,
358 OUT VOID *Buffer
359 );
360
361
362 /**
363 The function is to Write Block to SCSI Disk.
364
365 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
366 @param MediaId The Id of Media detected
367 @param Lba The logic block address
368 @param BufferSize The size of Buffer
369 @param Buffer The buffer to fill the read out data
370
371 @retval EFI_SUCCESS Successfully to read out block.
372 @retval EFI_WRITE_PROTECTED The device can not be written to.
373 @retval EFI_DEVICE_ERROR Fail to detect media.
374 @retval EFI_NO_MEDIA Media is not present.
375 @retval EFI_MEDIA_CHNAGED Media has changed.
376 @retval EFI_BAD_BUFFER_SIZE The Buffer was not a multiple of the block size of the device.
377 @retval EFI_INVALID_PARAMETER Invalid parameter passed in.
378
379 **/
380 EFI_STATUS
381 EFIAPI
382 ScsiDiskWriteBlocks (
383 IN EFI_BLOCK_IO_PROTOCOL *This,
384 IN UINT32 MediaId,
385 IN EFI_LBA Lba,
386 IN UINTN BufferSize,
387 IN VOID *Buffer
388 );
389
390
391 /**
392 Flush Block to Disk.
393
394 EFI_SUCCESS is returned directly.
395
396 @param This The pointer of EFI_BLOCK_IO_PROTOCOL
397
398 @retval EFI_SUCCESS All outstanding data was written to the device
399
400 **/
401 EFI_STATUS
402 EFIAPI
403 ScsiDiskFlushBlocks (
404 IN EFI_BLOCK_IO_PROTOCOL *This
405 );
406
407
408 /**
409 Provides inquiry information for the controller type.
410
411 This function is used by the IDE bus driver to get inquiry data. Data format
412 of Identify data is defined by the Interface GUID.
413
414 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
415 @param[in, out] InquiryData Pointer to a buffer for the inquiry data.
416 @param[in, out] InquiryDataSize Pointer to the value for the inquiry data size.
417
418 @retval EFI_SUCCESS The command was accepted without any errors.
419 @retval EFI_NOT_FOUND Device does not support this data class
420 @retval EFI_DEVICE_ERROR Error reading InquiryData from device
421 @retval EFI_BUFFER_TOO_SMALL InquiryDataSize not big enough
422
423 **/
424 EFI_STATUS
425 EFIAPI
426 ScsiDiskInfoInquiry (
427 IN EFI_DISK_INFO_PROTOCOL *This,
428 IN OUT VOID *InquiryData,
429 IN OUT UINT32 *InquiryDataSize
430 );
431
432
433 /**
434 Provides identify information for the controller type.
435
436 This function is used by the IDE bus driver to get identify data. Data format
437 of Identify data is defined by the Interface GUID.
438
439 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL
440 instance.
441 @param[in, out] IdentifyData Pointer to a buffer for the identify data.
442 @param[in, out] IdentifyDataSize Pointer to the value for the identify data
443 size.
444
445 @retval EFI_SUCCESS The command was accepted without any errors.
446 @retval EFI_NOT_FOUND Device does not support this data class
447 @retval EFI_DEVICE_ERROR Error reading IdentifyData from device
448 @retval EFI_BUFFER_TOO_SMALL IdentifyDataSize not big enough
449
450 **/
451 EFI_STATUS
452 EFIAPI
453 ScsiDiskInfoIdentify (
454 IN EFI_DISK_INFO_PROTOCOL *This,
455 IN OUT VOID *IdentifyData,
456 IN OUT UINT32 *IdentifyDataSize
457 );
458
459
460 /**
461 Provides sense data information for the controller type.
462
463 This function is used by the IDE bus driver to get sense data.
464 Data format of Sense data is defined by the Interface GUID.
465
466 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
467 @param[in, out] SenseData Pointer to the SenseData.
468 @param[in, out] SenseDataSize Size of SenseData in bytes.
469 @param[out] SenseDataNumber Pointer to the value for the sense data size.
470
471 @retval EFI_SUCCESS The command was accepted without any errors.
472 @retval EFI_NOT_FOUND Device does not support this data class.
473 @retval EFI_DEVICE_ERROR Error reading SenseData from device.
474 @retval EFI_BUFFER_TOO_SMALL SenseDataSize not big enough.
475
476 **/
477 EFI_STATUS
478 EFIAPI
479 ScsiDiskInfoSenseData (
480 IN EFI_DISK_INFO_PROTOCOL *This,
481 IN OUT VOID *SenseData,
482 IN OUT UINT32 *SenseDataSize,
483 OUT UINT8 *SenseDataNumber
484 );
485
486 /**
487 This function is used by the IDE bus driver to get controller information.
488
489 @param[in] This Pointer to the EFI_DISK_INFO_PROTOCOL instance.
490 @param[out] IdeChannel Pointer to the Ide Channel number. Primary or secondary.
491 @param[out] IdeDevice Pointer to the Ide Device number. Master or slave.
492
493 @retval EFI_SUCCESS IdeChannel and IdeDevice are valid.
494 @retval EFI_UNSUPPORTED This is not an IDE device.
495
496 **/
497 EFI_STATUS
498 EFIAPI
499 ScsiDiskInfoWhichIde (
500 IN EFI_DISK_INFO_PROTOCOL *This,
501 OUT UINT32 *IdeChannel,
502 OUT UINT32 *IdeDevice
503 );
504
505
506 /**
507 Detect Device and read out capacity ,if error occurs, parse the sense key.
508
509 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
510 @param MustReadCapacity The flag about reading device capacity
511 @param MediaChange The pointer of flag indicates if media has changed
512
513 @retval EFI_DEVICE_ERROR Indicates that error occurs
514 @retval EFI_SUCCESS Successfully to detect media
515
516 **/
517 EFI_STATUS
518 ScsiDiskDetectMedia (
519 IN SCSI_DISK_DEV *ScsiDiskDevice,
520 IN BOOLEAN MustReadCapacity,
521 OUT BOOLEAN *MediaChange
522 );
523
524 /**
525 To test device.
526
527 When Test Unit Ready command succeeds, retrieve Sense Keys via Request Sense;
528 When Test Unit Ready command encounters any error caused by host adapter or
529 target, return error without retrieving Sense Keys.
530
531 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
532 @param NeedRetry The pointer of flag indicates try again
533 @param SenseDataArray The pointer of an array of sense data
534 @param NumberOfSenseKeys The pointer of the number of sense data array
535
536 @retval EFI_DEVICE_ERROR Indicates that error occurs
537 @retval EFI_SUCCESS Successfully to test unit
538
539 **/
540 EFI_STATUS
541 ScsiDiskTestUnitReady (
542 IN SCSI_DISK_DEV *ScsiDiskDevice,
543 OUT BOOLEAN *NeedRetry,
544 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
545 OUT UINTN *NumberOfSenseKeys
546 );
547
548
549 /**
550 Parsing Sense Keys which got from request sense command.
551
552 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
553 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
554 @param NumberOfSenseKeys The number of sense key
555 @param Action The pointer of action which indicates what is need to do next
556
557 @retval EFI_DEVICE_ERROR Indicates that error occurs
558 @retval EFI_SUCCESS Successfully to complete the parsing
559
560 **/
561 EFI_STATUS
562 DetectMediaParsingSenseKeys (
563 OUT SCSI_DISK_DEV *ScsiDiskDevice,
564 IN EFI_SCSI_SENSE_DATA *SenseData,
565 IN UINTN NumberOfSenseKeys,
566 OUT UINTN *Action
567 );
568
569
570 /**
571 Send read capacity command to device and get the device parameter.
572
573 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
574 @param NeedRetry The pointer of flag indicates if need a retry
575 @param SenseDataArray The pointer of an array of sense data
576 @param NumberOfSenseKeys The number of sense key
577
578 @retval EFI_DEVICE_ERROR Indicates that error occurs
579 @retval EFI_SUCCESS Successfully to read capacity
580
581 **/
582 EFI_STATUS
583 ScsiDiskReadCapacity (
584 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
585 OUT BOOLEAN *NeedRetry,
586 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
587 OUT UINTN *NumberOfSenseKeys
588 );
589
590 /**
591 Check the HostAdapter status and re-interpret it in EFI_STATUS.
592
593 @param HostAdapterStatus Host Adapter status
594
595 @retval EFI_SUCCESS Host adapter is OK.
596 @retval EFI_TIMEOUT Timeout.
597 @retval EFI_NOT_READY Adapter NOT ready.
598 @retval EFI_DEVICE_ERROR Adapter device error.
599
600 **/
601 EFI_STATUS
602 CheckHostAdapterStatus (
603 IN UINT8 HostAdapterStatus
604 );
605
606
607 /**
608 Check the target status and re-interpret it in EFI_STATUS.
609
610 @param TargetStatus Target status
611
612 @retval EFI_NOT_READY Device is NOT ready.
613 @retval EFI_DEVICE_ERROR
614 @retval EFI_SUCCESS
615
616 **/
617 EFI_STATUS
618 CheckTargetStatus (
619 IN UINT8 TargetStatus
620 );
621
622 /**
623 Retrieve all sense keys from the device.
624
625 When encountering error during the process, if retrieve sense keys before
626 error encountered, it returns the sense keys with return status set to EFI_SUCCESS,
627 and NeedRetry set to FALSE; otherwize, return the proper return status.
628
629 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
630 @param NeedRetry The pointer of flag indicates if need a retry
631 @param SenseDataArray The pointer of an array of sense data
632 @param NumberOfSenseKeys The number of sense key
633 @param AskResetIfError The flag indicates if need reset when error occurs
634
635 @retval EFI_DEVICE_ERROR Indicates that error occurs
636 @retval EFI_SUCCESS Successfully to request sense key
637
638 **/
639 EFI_STATUS
640 ScsiDiskRequestSenseKeys (
641 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
642 OUT BOOLEAN *NeedRetry,
643 OUT EFI_SCSI_SENSE_DATA **SenseDataArray,
644 OUT UINTN *NumberOfSenseKeys,
645 IN BOOLEAN AskResetIfError
646 );
647
648 /**
649 Send out Inquiry command to Device.
650
651 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
652 @param NeedRetry Indicates if needs try again when error happens
653
654 @retval EFI_DEVICE_ERROR Indicates that error occurs
655 @retval EFI_SUCCESS Successfully to detect media
656
657 **/
658 EFI_STATUS
659 ScsiDiskInquiryDevice (
660 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
661 OUT BOOLEAN *NeedRetry
662 );
663
664 /**
665 Parse Inquiry data.
666
667 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
668
669 **/
670 VOID
671 ParseInquiryData (
672 IN OUT SCSI_DISK_DEV *ScsiDiskDevice
673 );
674
675 /**
676 Read sector from SCSI Disk.
677
678 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
679 @param Buffer The buffer to fill in the read out data
680 @param Lba Logic block address
681 @param NumberOfBlocks The number of blocks to read
682
683 @retval EFI_DEVICE_ERROR Indicates a device error.
684 @retval EFI_SUCCESS Operation is successful.
685
686 **/
687 EFI_STATUS
688 ScsiDiskReadSectors (
689 IN SCSI_DISK_DEV *ScsiDiskDevice,
690 OUT VOID *Buffer,
691 IN EFI_LBA Lba,
692 IN UINTN NumberOfBlocks
693 );
694
695 /**
696 Write sector to SCSI Disk.
697
698 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
699 @param Buffer The buffer of data to be written into SCSI Disk
700 @param Lba Logic block address
701 @param NumberOfBlocks The number of blocks to read
702
703 @retval EFI_DEVICE_ERROR Indicates a device error.
704 @retval EFI_SUCCESS Operation is successful.
705
706 **/
707 EFI_STATUS
708 ScsiDiskWriteSectors (
709 IN SCSI_DISK_DEV *ScsiDiskDevice,
710 IN VOID *Buffer,
711 IN EFI_LBA Lba,
712 IN UINTN NumberOfBlocks
713 );
714
715 /**
716 Submit Read command.
717
718 @param ScsiDiskDevice The pointer of ScsiDiskDevice
719 @param NeedRetry The pointer of flag indicates if needs retry if error happens
720 @param SenseDataArray NOT used yet in this function
721 @param NumberOfSenseKeys The number of sense key
722 @param Timeout The time to complete the command
723 @param DataBuffer The buffer to fill with the read out data
724 @param DataLength The length of buffer
725 @param StartLba The start logic block address
726 @param SectorSize The size of sector
727
728 @return EFI_STATUS is returned by calling ScsiRead10Command().
729 **/
730 EFI_STATUS
731 ScsiDiskRead10 (
732 IN SCSI_DISK_DEV *ScsiDiskDevice,
733 OUT BOOLEAN *NeedRetry,
734 OUT EFI_SCSI_SENSE_DATA **SenseDataArray, OPTIONAL
735 OUT UINTN *NumberOfSenseKeys,
736 IN UINT64 Timeout,
737 OUT UINT8 *DataBuffer,
738 IN OUT UINT32 *DataLength,
739 IN UINT32 StartLba,
740 IN UINT32 SectorSize
741 );
742
743 /**
744 Submit Write Command.
745
746 @param ScsiDiskDevice The pointer of ScsiDiskDevice
747 @param NeedRetry The pointer of flag indicates if needs retry if error happens
748 @param SenseDataArray NOT used yet in this function
749 @param NumberOfSenseKeys The number of sense key
750 @param Timeout The time to complete the command
751 @param DataBuffer The buffer to fill with the read out data
752 @param DataLength The length of buffer
753 @param StartLba The start logic block address
754 @param SectorSize The size of sector
755
756 @return EFI_STATUS is returned by calling ScsiWrite10Command().
757
758 **/
759 EFI_STATUS
760 ScsiDiskWrite10 (
761 IN SCSI_DISK_DEV *ScsiDiskDevice,
762 OUT BOOLEAN *NeedRetry,
763 OUT EFI_SCSI_SENSE_DATA **SenseDataArray, OPTIONAL
764 OUT UINTN *NumberOfSenseKeys,
765 IN UINT64 Timeout,
766 IN UINT8 *DataBuffer,
767 IN OUT UINT32 *DataLength,
768 IN UINT32 StartLba,
769 IN UINT32 SectorSize
770 );
771
772 /**
773 Submit Read(16) command.
774
775 @param ScsiDiskDevice The pointer of ScsiDiskDevice
776 @param NeedRetry The pointer of flag indicates if needs retry if error happens
777 @param SenseDataArray NOT used yet in this function
778 @param NumberOfSenseKeys The number of sense key
779 @param Timeout The time to complete the command
780 @param DataBuffer The buffer to fill with the read out data
781 @param DataLength The length of buffer
782 @param StartLba The start logic block address
783 @param SectorSize The size of sector
784
785 @return EFI_STATUS is returned by calling ScsiRead10Command().
786 **/
787 EFI_STATUS
788 ScsiDiskRead16 (
789 IN SCSI_DISK_DEV *ScsiDiskDevice,
790 OUT BOOLEAN *NeedRetry,
791 OUT EFI_SCSI_SENSE_DATA **SenseDataArray, OPTIONAL
792 OUT UINTN *NumberOfSenseKeys,
793 IN UINT64 Timeout,
794 OUT UINT8 *DataBuffer,
795 IN OUT UINT32 *DataLength,
796 IN UINT64 StartLba,
797 IN UINT32 SectorSize
798 );
799
800 /**
801 Submit Write(16) Command.
802
803 @param ScsiDiskDevice The pointer of ScsiDiskDevice
804 @param NeedRetry The pointer of flag indicates if needs retry if error happens
805 @param SenseDataArray NOT used yet in this function
806 @param NumberOfSenseKeys The number of sense key
807 @param Timeout The time to complete the command
808 @param DataBuffer The buffer to fill with the read out data
809 @param DataLength The length of buffer
810 @param StartLba The start logic block address
811 @param SectorSize The size of sector
812
813 @return EFI_STATUS is returned by calling ScsiWrite10Command().
814
815 **/
816 EFI_STATUS
817 ScsiDiskWrite16 (
818 IN SCSI_DISK_DEV *ScsiDiskDevice,
819 OUT BOOLEAN *NeedRetry,
820 OUT EFI_SCSI_SENSE_DATA **SenseDataArray, OPTIONAL
821 OUT UINTN *NumberOfSenseKeys,
822 IN UINT64 Timeout,
823 IN UINT8 *DataBuffer,
824 IN OUT UINT32 *DataLength,
825 IN UINT64 StartLba,
826 IN UINT32 SectorSize
827 );
828
829 /**
830 Get information from media read capacity command.
831
832 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
833 @param Capacity10 The pointer of EFI_SCSI_DISK_CAPACITY_DATA
834 @param Capacity16 The pointer of EFI_SCSI_DISK_CAPACITY_DATA16
835 **/
836 VOID
837 GetMediaInfo (
838 IN OUT SCSI_DISK_DEV *ScsiDiskDevice,
839 IN EFI_SCSI_DISK_CAPACITY_DATA *Capacity10,
840 IN EFI_SCSI_DISK_CAPACITY_DATA16 *Capacity16
841 );
842
843 /**
844 Check sense key to find if media presents.
845
846 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
847 @param SenseCounts The number of sense key
848
849 @retval TRUE NOT any media
850 @retval FALSE Media presents
851 **/
852 BOOLEAN
853 ScsiDiskIsNoMedia (
854 IN EFI_SCSI_SENSE_DATA *SenseData,
855 IN UINTN SenseCounts
856 );
857
858 /**
859 Parse sense key.
860
861 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
862 @param SenseCounts The number of sense key
863
864 @retval TRUE Error
865 @retval FALSE NOT error
866
867 **/
868 BOOLEAN
869 ScsiDiskIsMediaError (
870 IN EFI_SCSI_SENSE_DATA *SenseData,
871 IN UINTN SenseCounts
872 );
873
874 /**
875 Check sense key to find if hardware error happens.
876
877 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
878 @param SenseCounts The number of sense key
879
880 @retval TRUE Hardware error exits.
881 @retval FALSE NO error.
882
883 **/
884 BOOLEAN
885 ScsiDiskIsHardwareError (
886 IN EFI_SCSI_SENSE_DATA *SenseData,
887 IN UINTN SenseCounts
888 );
889
890 /**
891 Check sense key to find if media has changed.
892
893 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
894 @param SenseCounts The number of sense key
895
896 @retval TRUE Media is changed.
897 @retval FALSE Medit is NOT changed.
898 **/
899 BOOLEAN
900 ScsiDiskIsMediaChange (
901 IN EFI_SCSI_SENSE_DATA *SenseData,
902 IN UINTN SenseCounts
903 );
904
905 /**
906 Check sense key to find if reset happens.
907
908 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
909 @param SenseCounts The number of sense key
910
911 @retval TRUE It is reset before.
912 @retval FALSE It is NOT reset before.
913
914 **/
915 BOOLEAN
916 ScsiDiskIsResetBefore (
917 IN EFI_SCSI_SENSE_DATA *SenseData,
918 IN UINTN SenseCounts
919 );
920
921 /**
922 Check sense key to find if the drive is ready.
923
924 @param SenseData The pointer of EFI_SCSI_SENSE_DATA
925 @param SenseCounts The number of sense key
926 @param RetryLater The flag means if need a retry
927
928 @retval TRUE Drive is ready.
929 @retval FALSE Drive is NOT ready.
930
931 **/
932 BOOLEAN
933 ScsiDiskIsDriveReady (
934 IN EFI_SCSI_SENSE_DATA *SenseData,
935 IN UINTN SenseCounts,
936 OUT BOOLEAN *RetryLater
937 );
938
939 /**
940 Check sense key to find if it has sense key.
941
942 @param SenseData - The pointer of EFI_SCSI_SENSE_DATA
943 @param SenseCounts - The number of sense key
944
945 @retval TRUE It has sense key.
946 @retval FALSE It has NOT any sense key.
947
948 **/
949 BOOLEAN
950 ScsiDiskHaveSenseKey (
951 IN EFI_SCSI_SENSE_DATA *SenseData,
952 IN UINTN SenseCounts
953 );
954
955 /**
956 Release resource about disk device.
957
958 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV
959
960 **/
961 VOID
962 ReleaseScsiDiskDeviceResources (
963 IN SCSI_DISK_DEV *ScsiDiskDevice
964 );
965
966 /**
967 Determine if Block Io should be produced.
968
969
970 @param ChildHandle Child Handle to retrieve Parent information.
971
972 @retval TRUE Should produce Block Io.
973 @retval FALSE Should not produce Block Io.
974
975 **/
976 BOOLEAN
977 DetermineInstallBlockIo (
978 IN EFI_HANDLE ChildHandle
979 );
980
981 /**
982 Initialize the installation of DiskInfo protocol.
983
984 This function prepares for the installation of DiskInfo protocol on the child handle.
985 By default, it installs DiskInfo protocol with SCSI interface GUID. If it further
986 detects that the physical device is an ATAPI/AHCI device, it then updates interface GUID
987 to be IDE/AHCI interface GUID.
988
989 @param ScsiDiskDevice The pointer of SCSI_DISK_DEV.
990 @param ChildHandle Child handle to install DiskInfo protocol.
991
992 **/
993 VOID
994 InitializeInstallDiskInfo (
995 IN SCSI_DISK_DEV *ScsiDiskDevice,
996 IN EFI_HANDLE ChildHandle
997 );
998
999 /**
1000 Search protocol database and check to see if the protocol
1001 specified by ProtocolGuid is present on a ControllerHandle and opened by
1002 ChildHandle with an attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
1003 If the ControllerHandle is found, then the protocol specified by ProtocolGuid
1004 will be opened on it.
1005
1006
1007 @param ProtocolGuid ProtocolGuid pointer.
1008 @param ChildHandle Child Handle to retrieve Parent information.
1009
1010 **/
1011 VOID *
1012 EFIAPI
1013 GetParentProtocol (
1014 IN EFI_GUID *ProtocolGuid,
1015 IN EFI_HANDLE ChildHandle
1016 );
1017
1018 #endif