]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
UefiCpuPkg: Move AsmRelocateApLoopStart from Mpfuncs.nasm to AmdSev.nasm
[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
9d510e61 5SPDX-License-Identifier: BSD-2-Clause-Patent\r
3a10d471 6\r
3b2dbece 7**/\r
3a10d471 8\r
9beb888e 9#ifndef _SCSI_BUS_H_\r
10#define _SCSI_BUS_H_\r
3a10d471 11\r
9beb888e 12#include <Uefi.h>\r
13\r
14#include <Protocol/ScsiPassThru.h>\r
15#include <Protocol/ScsiPassThruExt.h>\r
16#include <Protocol/ScsiIo.h>\r
17#include <Protocol/ComponentName.h>\r
18#include <Protocol/DriverBinding.h>\r
19#include <Protocol/DevicePath.h>\r
20\r
21#include <Library/DebugLib.h>\r
22#include <Library/UefiDriverEntryPoint.h>\r
23#include <Library/UefiLib.h>\r
24#include <Library/BaseMemoryLib.h>\r
25#include <Library/MemoryAllocationLib.h>\r
ae50ee26 26#include <Library/UefiScsiLib.h>\r
9beb888e 27#include <Library/UefiBootServicesTableLib.h>\r
28#include <Library/DevicePathLib.h>\r
37623a5c 29#include <Library/ReportStatusCodeLib.h>\r
9beb888e 30\r
9cb8724d 31#include <IndustryStandard/Scsi.h>\r
3a10d471 32\r
1436aea4 33#define SCSI_IO_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'i', 'o')\r
3a10d471 34\r
1ccdbf2a 35typedef union {\r
1436aea4
MK
36 UINT32 Scsi;\r
37 UINT8 ExtScsi[4];\r
1ccdbf2a 38} SCSI_ID;\r
39\r
70c94b3b 40typedef struct _SCSI_TARGET_ID {\r
1436aea4
MK
41 SCSI_ID ScsiId;\r
42 UINT8 ExtScsiId[12];\r
43} SCSI_TARGET_ID;\r
70c94b3b 44\r
45typedef struct {\r
1436aea4
MK
46 VOID *Data1;\r
47 VOID *Data2;\r
70c94b3b 48} SCSI_EVENT_DATA;\r
49\r
70c94b3b 50//\r
cc530cd1 51// SCSI Bus Controller device structure\r
70c94b3b 52//\r
37623a5c 53#define SCSI_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('s', 'c', 's', 'i')\r
70c94b3b 54\r
3cc033c5
FT
55//\r
56// SCSI Bus Timeout Experience Value\r
57//\r
1436aea4 58#define SCSI_BUS_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)\r
3cc033c5 59\r
c8ad2d7a
LG
60//\r
61// The ScsiBusProtocol is just used to locate ScsiBusDev\r
62// structure in the SCSIBusDriverBindingStop(). Then we can\r
63// Close all opened protocols and release this structure.\r
64// ScsiBusProtocol is the private protocol.\r
65// gEfiCallerIdGuid will be used as its protocol guid.\r
66//\r
70c94b3b 67typedef struct _EFI_SCSI_BUS_PROTOCOL {\r
1436aea4 68 UINT64 Reserved;\r
70c94b3b 69} EFI_SCSI_BUS_PROTOCOL;\r
70\r
70c94b3b 71typedef struct _SCSI_BUS_DEVICE {\r
1436aea4
MK
72 UINTN Signature;\r
73 EFI_SCSI_BUS_PROTOCOL BusIdentify;\r
74 BOOLEAN ExtScsiSupport;\r
75 EFI_SCSI_PASS_THRU_PROTOCOL *ScsiInterface;\r
76 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiInterface;\r
77 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
70c94b3b 78} SCSI_BUS_DEVICE;\r
79\r
80#define SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS(a) CR (a, SCSI_BUS_DEVICE, BusIdentify, SCSI_BUS_DEVICE_SIGNATURE)\r
81\r
37623a5c 82typedef struct {\r
83 UINT32 Signature;\r
84 EFI_HANDLE Handle;\r
85 EFI_SCSI_IO_PROTOCOL ScsiIo;\r
86 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
d1102dba 87 BOOLEAN ExtScsiSupport;\r
37623a5c 88 EFI_SCSI_PASS_THRU_PROTOCOL *ScsiPassThru;\r
89 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiPassThru;\r
90 SCSI_BUS_DEVICE *ScsiBusDeviceData;\r
91 SCSI_TARGET_ID Pun;\r
92 UINT64 Lun;\r
93 UINT8 ScsiDeviceType;\r
94 UINT8 ScsiVersion;\r
95 BOOLEAN RemovableDevice;\r
96} SCSI_IO_DEV;\r
97\r
98#define SCSI_IO_DEV_FROM_THIS(a) CR (a, SCSI_IO_DEV, ScsiIo, SCSI_IO_DEV_SIGNATURE)\r
99\r
3a10d471 100//\r
101// Global Variables\r
102//\r
70da5bc2 103extern EFI_DRIVER_BINDING_PROTOCOL gScsiBusDriverBinding;\r
104extern EFI_COMPONENT_NAME_PROTOCOL gScsiBusComponentName;\r
105extern EFI_COMPONENT_NAME2_PROTOCOL gScsiBusComponentName2;\r
3a10d471 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. If\r
113 any other agent wishes to call Supported() it must also follow these calling\r
114 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
3a10d471 126EFI_STATUS\r
127EFIAPI\r
128SCSIBusDriverBindingSupported (\r
129 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
130 IN EFI_HANDLE Controller,\r
131 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
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
3a10d471 153EFI_STATUS\r
154EFIAPI\r
155SCSIBusDriverBindingStart (\r
156 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
157 IN EFI_HANDLE Controller,\r
158 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
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 also\r
168 follow these calling restrictions.\r
d1102dba 169\r
9beb888e 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
3a10d471 180EFI_STATUS\r
181EFIAPI\r
182SCSIBusDriverBindingStop (\r
1436aea4
MK
183 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
184 IN EFI_HANDLE Controller,\r
185 IN UINTN NumberOfChildren,\r
186 IN EFI_HANDLE *ChildHandleBuffer\r
3a10d471 187 );\r
188\r
189//\r
190// EFI Component Name Functions\r
191//\r
1436aea4 192\r
70da5bc2 193/**\r
194 Retrieves a Unicode string that is the user readable name of the driver.\r
195\r
196 This function retrieves the user readable name of a driver in the form of a\r
197 Unicode string. If the driver specified by This has a user readable name in\r
198 the language specified by Language, then a pointer to the driver name is\r
199 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
200 by This does not support the language specified by Language,\r
201 then EFI_UNSUPPORTED is returned.\r
202\r
9beb888e 203 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
70da5bc2 204 EFI_COMPONENT_NAME_PROTOCOL instance.\r
205\r
9beb888e 206 @param Language A pointer to a Null-terminated ASCII string\r
70da5bc2 207 array indicating the language. This is the\r
208 language of the driver name that the caller is\r
209 requesting, and it must match one of the\r
210 languages specified in SupportedLanguages. The\r
211 number of languages supported by a driver is up\r
212 to the driver writer. Language is specified\r
0254efc0 213 in RFC 4646 or ISO 639-2 language code format.\r
70da5bc2 214\r
9beb888e 215 @param DriverName A pointer to the Unicode string to return.\r
70da5bc2 216 This Unicode string is the name of the\r
217 driver specified by This in the language\r
218 specified by Language.\r
219\r
220 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
221 This and the language specified by Language was\r
222 returned in DriverName.\r
223\r
224 @retval EFI_INVALID_PARAMETER Language is NULL.\r
225\r
226 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
227\r
228 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
229 the language specified by Language.\r
230\r
231**/\r
3a10d471 232EFI_STATUS\r
233EFIAPI\r
234ScsiBusComponentNameGetDriverName (\r
235 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
236 IN CHAR8 *Language,\r
237 OUT CHAR16 **DriverName\r
238 );\r
239\r
70da5bc2 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
3a10d471 308EFI_STATUS\r
309EFIAPI\r
310ScsiBusComponentNameGetControllerName (\r
1436aea4
MK
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
3a10d471 316 );\r
317\r
9beb888e 318/**\r
319 Retrieves the device type information of the SCSI Controller.\r
70da5bc2 320\r
9beb888e 321 @param This Protocol instance pointer.\r
322 @param DeviceType A pointer to the device type information retrieved from\r
d1102dba 323 the SCSI Controller.\r
9beb888e 324\r
325 @retval EFI_SUCCESS Retrieves the device type information successfully.\r
326 @retval EFI_INVALID_PARAMETER The DeviceType is NULL.\r
d1102dba 327\r
9beb888e 328**/\r
3a10d471 329EFI_STATUS\r
330EFIAPI\r
331ScsiGetDeviceType (\r
1436aea4
MK
332 IN EFI_SCSI_IO_PROTOCOL *This,\r
333 OUT UINT8 *DeviceType\r
9beb888e 334 );\r
3a10d471 335\r
9beb888e 336/**\r
337 Retrieves the device location in the SCSI channel.\r
3a10d471 338\r
9beb888e 339 @param This Protocol instance pointer.\r
340 @param Target A pointer to the Target ID of a SCSI device\r
341 on the SCSI channel.\r
342 @param Lun A pointer to the LUN of the SCSI device on\r
343 the SCSI channel.\r
3a10d471 344\r
9beb888e 345 @retval EFI_SUCCESS Retrieves the device location successfully.\r
346 @retval EFI_INVALID_PARAMETER The Target or Lun is NULL.\r
3a10d471 347\r
9beb888e 348**/\r
3a10d471 349EFI_STATUS\r
350EFIAPI\r
9beb888e 351ScsiGetDeviceLocation (\r
1436aea4
MK
352 IN EFI_SCSI_IO_PROTOCOL *This,\r
353 IN OUT UINT8 **Target,\r
354 OUT UINT64 *Lun\r
9beb888e 355 );\r
3a10d471 356\r
9beb888e 357/**\r
70c94b3b 358 Resets the SCSI Bus that the SCSI Controller is attached to.\r
3a10d471 359\r
9beb888e 360 @param This Protocol instance pointer.\r
3a10d471 361\r
9beb888e 362 @retval EFI_SUCCESS The SCSI bus is reset successfully.\r
363 @retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus.\r
364 @retval EFI_UNSUPPORTED The bus reset operation is not supported by the\r
365 SCSI Host Controller.\r
d1102dba 366 @retval EFI_TIMEOUT A timeout occurred while attempting to reset\r
9beb888e 367 the SCSI bus.\r
368**/\r
3a10d471 369EFI_STATUS\r
370EFIAPI\r
9beb888e 371ScsiResetBus (\r
1436aea4 372 IN EFI_SCSI_IO_PROTOCOL *This\r
9beb888e 373 );\r
3a10d471 374\r
9beb888e 375/**\r
70c94b3b 376 Resets the SCSI Controller that the device handle specifies.\r
3a10d471 377\r
9beb888e 378 @param This Protocol instance pointer.\r
3a10d471 379\r
9beb888e 380 @retval EFI_SUCCESS Reset the SCSI controller successfully.\r
381 @retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller.\r
382 @retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation.\r
383 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the\r
384 SCSI Controller.\r
385**/\r
3a10d471 386EFI_STATUS\r
387EFIAPI\r
9beb888e 388ScsiResetDevice (\r
1436aea4 389 IN EFI_SCSI_IO_PROTOCOL *This\r
9beb888e 390 );\r
3a10d471 391\r
9beb888e 392/**\r
70c94b3b 393 Sends a SCSI Request Packet to the SCSI Controller for execution.\r
3a10d471 394\r
9beb888e 395 @param This Protocol instance pointer.\r
d1102dba 396 @param CommandPacket The SCSI request packet to send to the SCSI\r
70c94b3b 397 Controller specified by the device handle.\r
9beb888e 398 @param Event If the SCSI bus where the SCSI device is attached\r
d1102dba
LG
399 does not support non-blocking I/O, then Event is\r
400 ignored, and blocking I/O is performed.\r
70c94b3b 401 If Event is NULL, then blocking I/O is performed.\r
d1102dba 402 If Event is not NULL and non-blocking I/O is\r
70c94b3b 403 supported, then non-blocking I/O is performed,\r
404 and Event will be signaled when the SCSI Request\r
405 Packet completes.\r
3a10d471 406\r
d1102dba
LG
407 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host\r
408 successfully, and TransferLength bytes were\r
409 transferred to/from DataBuffer.See\r
410 HostAdapterStatus, TargetStatus,\r
9beb888e 411 SenseDataLength, and SenseData in that order\r
412 for additional status information.\r
d1102dba 413 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,\r
9beb888e 414 but the entire DataBuffer could not be transferred.\r
415 The actual number of bytes transferred is returned\r
d1102dba
LG
416 in TransferLength. See HostAdapterStatus,\r
417 TargetStatus, SenseDataLength, and SenseData in\r
9beb888e 418 that order for additional status information.\r
d1102dba
LG
419 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because\r
420 there are too many SCSI Command Packets already\r
9beb888e 421 queued.The caller may retry again later.\r
d1102dba
LG
422 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send\r
423 the SCSI Request Packet. See HostAdapterStatus,\r
424 TargetStatus, SenseDataLength, and SenseData in\r
9beb888e 425 that order for additional status information.\r
d1102dba
LG
426 @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.\r
427 The SCSI Request Packet was not sent, so no\r
9beb888e 428 additional status information is available.\r
429 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet\r
d1102dba 430 is not supported by the SCSI initiator(i.e., SCSI\r
9beb888e 431 Host Controller). The SCSI Request Packet was not\r
d1102dba 432 sent, so no additional status information is\r
9beb888e 433 available.\r
d1102dba 434 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI\r
9beb888e 435 Request Packet to execute. See HostAdapterStatus,\r
d1102dba 436 TargetStatus, SenseDataLength, and SenseData in\r
9beb888e 437 that order for additional status information.\r
438**/\r
3a10d471 439EFI_STATUS\r
9beb888e 440EFIAPI\r
441ScsiExecuteSCSICommand (\r
442 IN EFI_SCSI_IO_PROTOCOL *This,\r
443 IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET *CommandPacket,\r
444 IN EFI_EVENT Event OPTIONAL\r
445 );\r
3a10d471 446\r
9beb888e 447/**\r
70c94b3b 448 Scan SCSI Bus to discover the device, and attach ScsiIoProtocol to it.\r
3a10d471 449\r
9beb888e 450 @param This Protocol instance pointer\r
451 @param Controller Controller handle\r
cc530cd1 452 @param TargetId Target to be scanned\r
9beb888e 453 @param Lun The Lun of the SCSI device on the SCSI channel.\r
454 @param ScsiBusDev The pointer of SCSI_BUS_DEVICE\r
3a10d471 455\r
9beb888e 456 @retval EFI_SUCCESS Successfully to discover the device and attach\r
457 ScsiIoProtocol to it.\r
d375273c
YY
458 @retval EFI_NOT_FOUND Fail to discover the device.\r
459 @retval EFI_OUT_OF_RESOURCES Fail to allocate memory resources.\r
3a10d471 460\r
9beb888e 461**/\r
462EFI_STATUS\r
463EFIAPI\r
464ScsiScanCreateDevice (\r
1436aea4
MK
465 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
466 IN EFI_HANDLE Controller,\r
467 IN SCSI_TARGET_ID *TargetId,\r
468 IN UINT64 Lun,\r
469 IN OUT SCSI_BUS_DEVICE *ScsiBusDev\r
9beb888e 470 );\r
3a10d471 471\r
9beb888e 472/**\r
f36d6e66 473 Discovery SCSI Device\r
3a10d471 474\r
9beb888e 475 @param ScsiIoDevice The pointer of SCSI_IO_DEV\r
3a10d471 476\r
d375273c
YY
477 @retval EFI_SUCCESS Find SCSI Device and verify it.\r
478 @retval EFI_NOT_FOUND Unable to find SCSI Device.\r
479 @retval EFI_OUT_OF_RESOURCES Fail to allocate memory resources.\r
3a10d471 480\r
9beb888e 481**/\r
d375273c 482EFI_STATUS\r
9beb888e 483DiscoverScsiDevice (\r
1436aea4 484 IN OUT SCSI_IO_DEV *ScsiIoDevice\r
9beb888e 485 );\r
3a10d471 486\r
3a10d471 487#endif\r