]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
Sync BaseTools Branch (version r2321) to EDKII main trunk.
[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
284ee2e8 4Copyright (c) 2006 - 2011, 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
36\r
9cb8724d 37#include <IndustryStandard/Scsi.h>\r
3a10d471 38\r
f3f2e05d 39#define SCSI_IO_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'i', 'o')\r
3a10d471 40\r
1ccdbf2a 41typedef union {\r
42 UINT32 Scsi;\r
43 UINT8 ExtScsi[4]; \r
44} SCSI_ID;\r
45\r
70c94b3b 46typedef struct _SCSI_TARGET_ID {\r
1ccdbf2a 47 SCSI_ID ScsiId;\r
70c94b3b 48 UINT8 ExtScsiId[12];\r
49}SCSI_TARGET_ID;\r
50\r
51\r
52typedef struct {\r
53 VOID *Data1;\r
54 VOID *Data2;\r
55} SCSI_EVENT_DATA;\r
56\r
57\r
3a10d471 58typedef struct {\r
70c94b3b 59 UINT32 Signature;\r
60 EFI_HANDLE Handle;\r
61 EFI_SCSI_IO_PROTOCOL ScsiIo;\r
62 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
63 BOOLEAN ExtScsiSupport; \r
64 EFI_SCSI_PASS_THRU_PROTOCOL *ScsiPassThru;\r
65 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiPassThru;\r
66 SCSI_TARGET_ID Pun;\r
67 UINT64 Lun;\r
68 UINT8 ScsiDeviceType;\r
69 UINT8 ScsiVersion;\r
70 BOOLEAN RemovableDevice;\r
3a10d471 71} SCSI_IO_DEV;\r
72\r
73#define SCSI_IO_DEV_FROM_THIS(a) CR (a, SCSI_IO_DEV, ScsiIo, SCSI_IO_DEV_SIGNATURE)\r
74\r
70c94b3b 75//\r
76// SCSI Bus Controller device strcuture\r
77//\r
78#define EFI_SCSI_BUS_PROTOCOL_GUID \\r
79 { \\r
84b5c78e 80 0x5261213D, 0x3A3D, 0x441E, {0xB3, 0xAF, 0x21, 0xD3, 0xF7, 0xA4, 0xCA, 0x17} \\r
70c94b3b 81 }\r
82\r
83typedef struct _EFI_SCSI_BUS_PROTOCOL {\r
84 UINT64 Reserved;\r
85} EFI_SCSI_BUS_PROTOCOL;\r
86\r
f3f2e05d 87#define SCSI_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('s', 'c', 's', 'i')\r
70c94b3b 88\r
89\r
90typedef struct _SCSI_BUS_DEVICE {\r
91 UINTN Signature;\r
92 EFI_SCSI_BUS_PROTOCOL BusIdentify;\r
93 BOOLEAN ExtScsiSupport; \r
94 EFI_SCSI_PASS_THRU_PROTOCOL *ScsiInterface;\r
95 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiInterface;\r
96 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
97} SCSI_BUS_DEVICE;\r
98\r
99#define SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS(a) CR (a, SCSI_BUS_DEVICE, BusIdentify, SCSI_BUS_DEVICE_SIGNATURE)\r
100\r
3a10d471 101//\r
102// Global Variables\r
103//\r
70da5bc2 104extern EFI_DRIVER_BINDING_PROTOCOL gScsiBusDriverBinding;\r
105extern EFI_COMPONENT_NAME_PROTOCOL gScsiBusComponentName;\r
106extern EFI_COMPONENT_NAME2_PROTOCOL gScsiBusComponentName2;\r
3a10d471 107\r
9beb888e 108/**\r
109 Test to see if this driver supports ControllerHandle.\r
110\r
111 This service is called by the EFI boot service ConnectController(). In order\r
112 to make drivers as small as possible, there are a few calling restrictions for\r
113 this service. ConnectController() must follow these calling restrictions. If\r
114 any other agent wishes to call Supported() it must also follow these calling\r
115 restrictions.\r
116\r
117 @param This Protocol instance pointer.\r
118 @param ControllerHandle Handle of device to test\r
119 @param RemainingDevicePath Optional parameter use to pick a specific child\r
120 device to start.\r
121\r
122 @retval EFI_SUCCESS This driver supports this device\r
123 @retval EFI_ALREADY_STARTED This driver is already running on this device\r
124 @retval other This driver does not support this device\r
125\r
126**/\r
3a10d471 127EFI_STATUS\r
128EFIAPI\r
129SCSIBusDriverBindingSupported (\r
130 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
131 IN EFI_HANDLE Controller,\r
132 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
133 );\r
134\r
9beb888e 135/**\r
136 Start this driver on ControllerHandle.\r
137\r
138 This service is called by the EFI boot service ConnectController(). In order\r
139 to make drivers as small as possible, there are a few calling restrictions for\r
140 this service. ConnectController() must follow these calling restrictions. If\r
141 any other agent wishes to call Start() it must also follow these calling\r
142 restrictions.\r
143\r
144 @param This Protocol instance pointer.\r
145 @param ControllerHandle Handle of device to bind driver to\r
146 @param RemainingDevicePath Optional parameter use to pick a specific child\r
147 device to start.\r
148\r
149 @retval EFI_SUCCESS This driver is added to ControllerHandle\r
150 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle\r
151 @retval other This driver does not support this device\r
152\r
153**/\r
3a10d471 154EFI_STATUS\r
155EFIAPI\r
156SCSIBusDriverBindingStart (\r
157 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
158 IN EFI_HANDLE Controller,\r
159 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
160 );\r
161\r
9beb888e 162/**\r
163 Stop this driver on ControllerHandle.\r
164\r
165 This service is called by the EFI boot service DisconnectController().\r
166 In order to make drivers as small as possible, there are a few calling\r
167 restrictions for this service. DisconnectController() must follow these\r
168 calling restrictions. If any other agent wishes to call Stop() it must also\r
169 follow these calling restrictions.\r
170 \r
171 @param This Protocol instance pointer.\r
172 @param ControllerHandle Handle of device to stop driver on\r
173 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
174 children is zero stop the entire bus driver.\r
175 @param ChildHandleBuffer List of Child Handles to Stop.\r
176\r
177 @retval EFI_SUCCESS This driver is removed ControllerHandle\r
178 @retval other This driver was not removed from this device\r
179\r
180**/\r
3a10d471 181EFI_STATUS\r
182EFIAPI\r
183SCSIBusDriverBindingStop (\r
184 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
185 IN EFI_HANDLE Controller,\r
186 IN UINTN NumberOfChildren,\r
187 IN EFI_HANDLE *ChildHandleBuffer\r
188 );\r
189\r
190//\r
191// EFI Component Name Functions\r
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
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 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
323 the SCSI Controller. \r
324\r
325 @retval EFI_SUCCESS Retrieves the device type information successfully.\r
326 @retval EFI_INVALID_PARAMETER The DeviceType is NULL.\r
327 \r
328**/\r
3a10d471 329EFI_STATUS\r
330EFIAPI\r
331ScsiGetDeviceType (\r
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
352 IN EFI_SCSI_IO_PROTOCOL *This,\r
353 IN OUT UINT8 **Target,\r
354 OUT UINT64 *Lun\r
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
366 @retval EFI_TIMEOUT A timeout occurred while attempting to reset \r
367 the SCSI bus.\r
368**/\r
3a10d471 369EFI_STATUS\r
370EFIAPI\r
9beb888e 371ScsiResetBus (\r
3a10d471 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
389 IN EFI_SCSI_IO_PROTOCOL *This\r
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
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
70c94b3b 399 does not support non-blocking I/O, then Event is \r
400 ignored, and blocking I/O is performed. \r
401 If Event is NULL, then blocking I/O is performed.\r
402 If Event is not NULL and non-blocking I/O is \r
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
9beb888e 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
411 SenseDataLength, and SenseData in that order\r
412 for additional status information.\r
413 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, \r
414 but the entire DataBuffer could not be transferred.\r
415 The actual number of bytes transferred is returned\r
416 in TransferLength. See HostAdapterStatus, \r
417 TargetStatus, SenseDataLength, and SenseData in \r
418 that order for additional status information.\r
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
421 queued.The caller may retry again later.\r
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
425 that order for additional status information.\r
426 @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid. \r
427 The SCSI Request Packet was not sent, so no \r
428 additional status information is available.\r
429 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet\r
430 is not supported by the SCSI initiator(i.e., SCSI \r
431 Host Controller). The SCSI Request Packet was not\r
432 sent, so no additional status information is \r
433 available.\r
434 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI \r
435 Request Packet to execute. See HostAdapterStatus,\r
436 TargetStatus, SenseDataLength, and SenseData in \r
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
452 @param TargetId Tartget to be scanned\r
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
458 @retval EFI_OUT_OF_RESOURCES Fail to discover the device.\r
3a10d471 459\r
9beb888e 460**/\r
461EFI_STATUS\r
462EFIAPI\r
463ScsiScanCreateDevice (\r
464 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
465 IN EFI_HANDLE Controller,\r
466 IN SCSI_TARGET_ID *TargetId,\r
467 IN UINT64 Lun,\r
468 IN OUT SCSI_BUS_DEVICE *ScsiBusDev\r
469 );\r
3a10d471 470\r
9beb888e 471/**\r
f36d6e66 472 Discovery SCSI Device\r
3a10d471 473\r
9beb888e 474 @param ScsiIoDevice The pointer of SCSI_IO_DEV\r
3a10d471 475\r
9beb888e 476 @retval TRUE Find SCSI Device and verify it.\r
477 @retval FALSE Unable to find SCSI Device.\r
3a10d471 478\r
9beb888e 479**/\r
480BOOLEAN\r
481DiscoverScsiDevice (\r
482 IN OUT SCSI_IO_DEV *ScsiIoDevice\r
483 );\r
3a10d471 484\r
3a10d471 485#endif\r