]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
IntelSiliconPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiBusDxe / ScsiBus.h
CommitLineData
3b2dbece 1/** @file\r
2 Header file for SCSI Bus Driver.\r
3a10d471 3\r
d1102dba 4Copyright (c) 2006 - 2018, 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
3a10d471 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
3a10d471 12\r
3b2dbece 13**/\r
3a10d471 14\r
9beb888e 15#ifndef _SCSI_BUS_H_\r
16#define _SCSI_BUS_H_\r
3a10d471 17\r
18\r
9beb888e 19#include <Uefi.h>\r
20\r
21#include <Protocol/ScsiPassThru.h>\r
22#include <Protocol/ScsiPassThruExt.h>\r
23#include <Protocol/ScsiIo.h>\r
24#include <Protocol/ComponentName.h>\r
25#include <Protocol/DriverBinding.h>\r
26#include <Protocol/DevicePath.h>\r
27\r
28#include <Library/DebugLib.h>\r
29#include <Library/UefiDriverEntryPoint.h>\r
30#include <Library/UefiLib.h>\r
31#include <Library/BaseMemoryLib.h>\r
32#include <Library/MemoryAllocationLib.h>\r
ae50ee26 33#include <Library/UefiScsiLib.h>\r
9beb888e 34#include <Library/UefiBootServicesTableLib.h>\r
35#include <Library/DevicePathLib.h>\r
37623a5c 36#include <Library/ReportStatusCodeLib.h>\r
9beb888e 37\r
9cb8724d 38#include <IndustryStandard/Scsi.h>\r
3a10d471 39\r
f3f2e05d 40#define SCSI_IO_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'i', 'o')\r
3a10d471 41\r
1ccdbf2a 42typedef union {\r
43 UINT32 Scsi;\r
d1102dba 44 UINT8 ExtScsi[4];\r
1ccdbf2a 45} SCSI_ID;\r
46\r
70c94b3b 47typedef struct _SCSI_TARGET_ID {\r
1ccdbf2a 48 SCSI_ID ScsiId;\r
70c94b3b 49 UINT8 ExtScsiId[12];\r
50}SCSI_TARGET_ID;\r
51\r
52\r
53typedef struct {\r
54 VOID *Data1;\r
55 VOID *Data2;\r
56} SCSI_EVENT_DATA;\r
57\r
70c94b3b 58//\r
59// SCSI Bus Controller device strcuture\r
60//\r
37623a5c 61#define SCSI_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('s', 'c', 's', 'i')\r
70c94b3b 62\r
3cc033c5
FT
63//\r
64// SCSI Bus Timeout Experience Value\r
65//\r
66#define SCSI_BUS_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)\r
67\r
c8ad2d7a
LG
68//\r
69// The ScsiBusProtocol is just used to locate ScsiBusDev\r
70// structure in the SCSIBusDriverBindingStop(). Then we can\r
71// Close all opened protocols and release this structure.\r
72// ScsiBusProtocol is the private protocol.\r
73// gEfiCallerIdGuid will be used as its protocol guid.\r
74//\r
70c94b3b 75typedef struct _EFI_SCSI_BUS_PROTOCOL {\r
76 UINT64 Reserved;\r
77} EFI_SCSI_BUS_PROTOCOL;\r
78\r
70c94b3b 79typedef struct _SCSI_BUS_DEVICE {\r
80 UINTN Signature;\r
81 EFI_SCSI_BUS_PROTOCOL BusIdentify;\r
d1102dba 82 BOOLEAN ExtScsiSupport;\r
70c94b3b 83 EFI_SCSI_PASS_THRU_PROTOCOL *ScsiInterface;\r
84 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiInterface;\r
85 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
86} SCSI_BUS_DEVICE;\r
87\r
88#define SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS(a) CR (a, SCSI_BUS_DEVICE, BusIdentify, SCSI_BUS_DEVICE_SIGNATURE)\r
89\r
37623a5c 90typedef struct {\r
91 UINT32 Signature;\r
92 EFI_HANDLE Handle;\r
93 EFI_SCSI_IO_PROTOCOL ScsiIo;\r
94 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
d1102dba 95 BOOLEAN ExtScsiSupport;\r
37623a5c 96 EFI_SCSI_PASS_THRU_PROTOCOL *ScsiPassThru;\r
97 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiPassThru;\r
98 SCSI_BUS_DEVICE *ScsiBusDeviceData;\r
99 SCSI_TARGET_ID Pun;\r
100 UINT64 Lun;\r
101 UINT8 ScsiDeviceType;\r
102 UINT8 ScsiVersion;\r
103 BOOLEAN RemovableDevice;\r
104} SCSI_IO_DEV;\r
105\r
106#define SCSI_IO_DEV_FROM_THIS(a) CR (a, SCSI_IO_DEV, ScsiIo, SCSI_IO_DEV_SIGNATURE)\r
107\r
3a10d471 108//\r
109// Global Variables\r
110//\r
70da5bc2 111extern EFI_DRIVER_BINDING_PROTOCOL gScsiBusDriverBinding;\r
112extern EFI_COMPONENT_NAME_PROTOCOL gScsiBusComponentName;\r
113extern EFI_COMPONENT_NAME2_PROTOCOL gScsiBusComponentName2;\r
3a10d471 114\r
9beb888e 115/**\r
116 Test to see if this driver supports ControllerHandle.\r
117\r
118 This service is called by the EFI boot service ConnectController(). In order\r
119 to make drivers as small as possible, there are a few calling restrictions for\r
120 this service. ConnectController() must follow these calling restrictions. If\r
121 any other agent wishes to call Supported() it must also follow these calling\r
122 restrictions.\r
123\r
124 @param This Protocol instance pointer.\r
125 @param ControllerHandle Handle of device to test\r
126 @param RemainingDevicePath Optional parameter use to pick a specific child\r
127 device to start.\r
128\r
129 @retval EFI_SUCCESS This driver supports this device\r
130 @retval EFI_ALREADY_STARTED This driver is already running on this device\r
131 @retval other This driver does not support this device\r
132\r
133**/\r
3a10d471 134EFI_STATUS\r
135EFIAPI\r
136SCSIBusDriverBindingSupported (\r
137 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
138 IN EFI_HANDLE Controller,\r
139 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
140 );\r
141\r
9beb888e 142/**\r
143 Start this driver on ControllerHandle.\r
144\r
145 This service is called by the EFI boot service ConnectController(). In order\r
146 to make drivers as small as possible, there are a few calling restrictions for\r
147 this service. ConnectController() must follow these calling restrictions. If\r
148 any other agent wishes to call Start() it must also follow these calling\r
149 restrictions.\r
150\r
151 @param This Protocol instance pointer.\r
152 @param ControllerHandle Handle of device to bind driver to\r
153 @param RemainingDevicePath Optional parameter use to pick a specific child\r
154 device to start.\r
155\r
156 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
157 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
158 @retval other This driver does not support this device\r
159\r
160**/\r
3a10d471 161EFI_STATUS\r
162EFIAPI\r
163SCSIBusDriverBindingStart (\r
164 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
165 IN EFI_HANDLE Controller,\r
166 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
167 );\r
168\r
9beb888e 169/**\r
170 Stop this driver on ControllerHandle.\r
171\r
172 This service is called by the EFI boot service DisconnectController().\r
173 In order to make drivers as small as possible, there are a few calling\r
174 restrictions for this service. DisconnectController() must follow these\r
175 calling restrictions. If any other agent wishes to call Stop() it must also\r
176 follow these calling restrictions.\r
d1102dba 177\r
9beb888e 178 @param This Protocol instance pointer.\r
179 @param ControllerHandle Handle of device to stop driver on\r
180 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
181 children is zero stop the entire bus driver.\r
182 @param ChildHandleBuffer List of Child Handles to Stop.\r
183\r
184 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
185 @retval other This driver was not removed from this device\r
186\r
187**/\r
3a10d471 188EFI_STATUS\r
189EFIAPI\r
190SCSIBusDriverBindingStop (\r
191 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
192 IN EFI_HANDLE Controller,\r
193 IN UINTN NumberOfChildren,\r
194 IN EFI_HANDLE *ChildHandleBuffer\r
195 );\r
196\r
197//\r
198// EFI Component Name Functions\r
199//\r
70da5bc2 200/**\r
201 Retrieves a Unicode string that is the user readable name of the driver.\r
202\r
203 This function retrieves the user readable name of a driver in the form of a\r
204 Unicode string. If the driver specified by This has a user readable name in\r
205 the language specified by Language, then a pointer to the driver name is\r
206 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
207 by This does not support the language specified by Language,\r
208 then EFI_UNSUPPORTED is returned.\r
209\r
9beb888e 210 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
70da5bc2 211 EFI_COMPONENT_NAME_PROTOCOL instance.\r
212\r
9beb888e 213 @param Language A pointer to a Null-terminated ASCII string\r
70da5bc2 214 array indicating the language. This is the\r
215 language of the driver name that the caller is\r
216 requesting, and it must match one of the\r
217 languages specified in SupportedLanguages. The\r
218 number of languages supported by a driver is up\r
219 to the driver writer. Language is specified\r
0254efc0 220 in RFC 4646 or ISO 639-2 language code format.\r
70da5bc2 221\r
9beb888e 222 @param DriverName A pointer to the Unicode string to return.\r
70da5bc2 223 This Unicode string is the name of the\r
224 driver specified by This in the language\r
225 specified by Language.\r
226\r
227 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
228 This and the language specified by Language was\r
229 returned in DriverName.\r
230\r
231 @retval EFI_INVALID_PARAMETER Language is NULL.\r
232\r
233 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
234\r
235 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
236 the language specified by Language.\r
237\r
238**/\r
3a10d471 239EFI_STATUS\r
240EFIAPI\r
241ScsiBusComponentNameGetDriverName (\r
242 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
243 IN CHAR8 *Language,\r
244 OUT CHAR16 **DriverName\r
245 );\r
246\r
70da5bc2 247/**\r
248 Retrieves a Unicode string that is the user readable name of the controller\r
249 that is being managed by a driver.\r
250\r
251 This function retrieves the user readable name of the controller specified by\r
252 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
253 driver specified by This has a user readable name in the language specified by\r
254 Language, then a pointer to the controller name is returned in ControllerName,\r
255 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
256 managing the controller specified by ControllerHandle and ChildHandle,\r
257 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
258 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
259\r
9beb888e 260 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
70da5bc2 261 EFI_COMPONENT_NAME_PROTOCOL instance.\r
262\r
9beb888e 263 @param ControllerHandle The handle of a controller that the driver\r
70da5bc2 264 specified by This is managing. This handle\r
265 specifies the controller whose name is to be\r
266 returned.\r
267\r
9beb888e 268 @param ChildHandle The handle of the child controller to retrieve\r
70da5bc2 269 the name of. This is an optional parameter that\r
270 may be NULL. It will be NULL for device\r
271 drivers. It will also be NULL for a bus drivers\r
272 that wish to retrieve the name of the bus\r
273 controller. It will not be NULL for a bus\r
274 driver that wishes to retrieve the name of a\r
275 child controller.\r
276\r
9beb888e 277 @param Language A pointer to a Null-terminated ASCII string\r
70da5bc2 278 array indicating the language. This is the\r
279 language of the driver name that the caller is\r
280 requesting, and it must match one of the\r
281 languages specified in SupportedLanguages. The\r
282 number of languages supported by a driver is up\r
283 to the driver writer. Language is specified in\r
0254efc0 284 RFC 4646 or ISO 639-2 language code format.\r
70da5bc2 285\r
9beb888e 286 @param ControllerName A pointer to the Unicode string to return.\r
70da5bc2 287 This Unicode string is the name of the\r
288 controller specified by ControllerHandle and\r
289 ChildHandle in the language specified by\r
290 Language from the point of view of the driver\r
291 specified by This.\r
292\r
293 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
294 the language specified by Language for the\r
295 driver specified by This was returned in\r
296 DriverName.\r
297\r
284ee2e8 298 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
70da5bc2 299\r
300 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
301 EFI_HANDLE.\r
302\r
303 @retval EFI_INVALID_PARAMETER Language is NULL.\r
304\r
305 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
306\r
307 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
308 managing the controller specified by\r
309 ControllerHandle and ChildHandle.\r
310\r
311 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
312 the language specified by Language.\r
313\r
314**/\r
3a10d471 315EFI_STATUS\r
316EFIAPI\r
317ScsiBusComponentNameGetControllerName (\r
318 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
319 IN EFI_HANDLE ControllerHandle,\r
320 IN EFI_HANDLE ChildHandle OPTIONAL,\r
321 IN CHAR8 *Language,\r
322 OUT CHAR16 **ControllerName\r
323 );\r
324\r
9beb888e 325/**\r
326 Retrieves the device type information of the SCSI Controller.\r
70da5bc2 327\r
9beb888e 328 @param This Protocol instance pointer.\r
329 @param DeviceType A pointer to the device type information retrieved from\r
d1102dba 330 the SCSI Controller.\r
9beb888e 331\r
332 @retval EFI_SUCCESS Retrieves the device type information successfully.\r
333 @retval EFI_INVALID_PARAMETER The DeviceType is NULL.\r
d1102dba 334\r
9beb888e 335**/\r
3a10d471 336EFI_STATUS\r
337EFIAPI\r
338ScsiGetDeviceType (\r
339 IN EFI_SCSI_IO_PROTOCOL *This,\r
340 OUT UINT8 *DeviceType\r
9beb888e 341 );\r
3a10d471 342\r
9beb888e 343/**\r
344 Retrieves the device location in the SCSI channel.\r
3a10d471 345\r
9beb888e 346 @param This Protocol instance pointer.\r
347 @param Target A pointer to the Target ID of a SCSI device\r
348 on the SCSI channel.\r
349 @param Lun A pointer to the LUN of the SCSI device on\r
350 the SCSI channel.\r
3a10d471 351\r
9beb888e 352 @retval EFI_SUCCESS Retrieves the device location successfully.\r
353 @retval EFI_INVALID_PARAMETER The Target or Lun is NULL.\r
3a10d471 354\r
9beb888e 355**/\r
3a10d471 356EFI_STATUS\r
357EFIAPI\r
9beb888e 358ScsiGetDeviceLocation (\r
359 IN EFI_SCSI_IO_PROTOCOL *This,\r
360 IN OUT UINT8 **Target,\r
361 OUT UINT64 *Lun\r
362 );\r
3a10d471 363\r
9beb888e 364/**\r
70c94b3b 365 Resets the SCSI Bus that the SCSI Controller is attached to.\r
3a10d471 366\r
9beb888e 367 @param This Protocol instance pointer.\r
3a10d471 368\r
9beb888e 369 @retval EFI_SUCCESS The SCSI bus is reset successfully.\r
370 @retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus.\r
371 @retval EFI_UNSUPPORTED The bus reset operation is not supported by the\r
372 SCSI Host Controller.\r
d1102dba 373 @retval EFI_TIMEOUT A timeout occurred while attempting to reset\r
9beb888e 374 the SCSI bus.\r
375**/\r
3a10d471 376EFI_STATUS\r
377EFIAPI\r
9beb888e 378ScsiResetBus (\r
3a10d471 379 IN EFI_SCSI_IO_PROTOCOL *This\r
9beb888e 380 );\r
3a10d471 381\r
9beb888e 382/**\r
70c94b3b 383 Resets the SCSI Controller that the device handle specifies.\r
3a10d471 384\r
9beb888e 385 @param This Protocol instance pointer.\r
3a10d471 386\r
9beb888e 387 @retval EFI_SUCCESS Reset the SCSI controller successfully.\r
388 @retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller.\r
389 @retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation.\r
390 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the\r
391 SCSI Controller.\r
392**/\r
3a10d471 393EFI_STATUS\r
394EFIAPI\r
9beb888e 395ScsiResetDevice (\r
396 IN EFI_SCSI_IO_PROTOCOL *This\r
397 );\r
3a10d471 398\r
9beb888e 399/**\r
70c94b3b 400 Sends a SCSI Request Packet to the SCSI Controller for execution.\r
3a10d471 401\r
9beb888e 402 @param This Protocol instance pointer.\r
d1102dba 403 @param CommandPacket The SCSI request packet to send to the SCSI\r
70c94b3b 404 Controller specified by the device handle.\r
9beb888e 405 @param Event If the SCSI bus where the SCSI device is attached\r
d1102dba
LG
406 does not support non-blocking I/O, then Event is\r
407 ignored, and blocking I/O is performed.\r
70c94b3b 408 If Event is NULL, then blocking I/O is performed.\r
d1102dba 409 If Event is not NULL and non-blocking I/O is\r
70c94b3b 410 supported, then non-blocking I/O is performed,\r
411 and Event will be signaled when the SCSI Request\r
412 Packet completes.\r
3a10d471 413\r
d1102dba
LG
414 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host\r
415 successfully, and TransferLength bytes were\r
416 transferred to/from DataBuffer.See\r
417 HostAdapterStatus, TargetStatus,\r
9beb888e 418 SenseDataLength, and SenseData in that order\r
419 for additional status information.\r
d1102dba 420 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,\r
9beb888e 421 but the entire DataBuffer could not be transferred.\r
422 The actual number of bytes transferred is returned\r
d1102dba
LG
423 in TransferLength. See HostAdapterStatus,\r
424 TargetStatus, SenseDataLength, and SenseData in\r
9beb888e 425 that order for additional status information.\r
d1102dba
LG
426 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because\r
427 there are too many SCSI Command Packets already\r
9beb888e 428 queued.The caller may retry again later.\r
d1102dba
LG
429 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send\r
430 the SCSI Request Packet. See HostAdapterStatus,\r
431 TargetStatus, SenseDataLength, and SenseData in\r
9beb888e 432 that order for additional status information.\r
d1102dba
LG
433 @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.\r
434 The SCSI Request Packet was not sent, so no\r
9beb888e 435 additional status information is available.\r
436 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet\r
d1102dba 437 is not supported by the SCSI initiator(i.e., SCSI\r
9beb888e 438 Host Controller). The SCSI Request Packet was not\r
d1102dba 439 sent, so no additional status information is\r
9beb888e 440 available.\r
d1102dba 441 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI\r
9beb888e 442 Request Packet to execute. See HostAdapterStatus,\r
d1102dba 443 TargetStatus, SenseDataLength, and SenseData in\r
9beb888e 444 that order for additional status information.\r
445**/\r
3a10d471 446EFI_STATUS\r
9beb888e 447EFIAPI\r
448ScsiExecuteSCSICommand (\r
449 IN EFI_SCSI_IO_PROTOCOL *This,\r
450 IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET *CommandPacket,\r
451 IN EFI_EVENT Event OPTIONAL\r
452 );\r
3a10d471 453\r
9beb888e 454/**\r
70c94b3b 455 Scan SCSI Bus to discover the device, and attach ScsiIoProtocol to it.\r
3a10d471 456\r
9beb888e 457 @param This Protocol instance pointer\r
458 @param Controller Controller handle\r
459 @param TargetId Tartget to be scanned\r
460 @param Lun The Lun of the SCSI device on the SCSI channel.\r
461 @param ScsiBusDev The pointer of SCSI_BUS_DEVICE\r
3a10d471 462\r
9beb888e 463 @retval EFI_SUCCESS Successfully to discover the device and attach\r
464 ScsiIoProtocol to it.\r
465 @retval EFI_OUT_OF_RESOURCES Fail to discover the device.\r
3a10d471 466\r
9beb888e 467**/\r
468EFI_STATUS\r
469EFIAPI\r
470ScsiScanCreateDevice (\r
471 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
472 IN EFI_HANDLE Controller,\r
473 IN SCSI_TARGET_ID *TargetId,\r
474 IN UINT64 Lun,\r
475 IN OUT SCSI_BUS_DEVICE *ScsiBusDev\r
476 );\r
3a10d471 477\r
9beb888e 478/**\r
f36d6e66 479 Discovery SCSI Device\r
3a10d471 480\r
9beb888e 481 @param ScsiIoDevice The pointer of SCSI_IO_DEV\r
3a10d471 482\r
9beb888e 483 @retval TRUE Find SCSI Device and verify it.\r
484 @retval FALSE Unable to find SCSI Device.\r
3a10d471 485\r
9beb888e 486**/\r
487BOOLEAN\r
488DiscoverScsiDevice (\r
489 IN OUT SCSI_IO_DEV *ScsiIoDevice\r
490 );\r
3a10d471 491\r
3a10d471 492#endif\r