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