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