]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Bus/Scsi/ScsiBusDxe/ScsiBus.h
MdeModulePkg ScsiBusDxe: Fix caller event may nerver be signaled
[mirror_edk2.git] / MdeModulePkg / Bus / Scsi / ScsiBusDxe / ScsiBus.h
... / ...
CommitLineData
1/** @file\r
2 Header file for SCSI Bus Driver.\r
3\r
4Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
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
9\r
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
12\r
13**/\r
14\r
15#ifndef _SCSI_BUS_H_\r
16#define _SCSI_BUS_H_\r
17\r
18\r
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
33#include <Library/UefiScsiLib.h>\r
34#include <Library/UefiBootServicesTableLib.h>\r
35#include <Library/DevicePathLib.h>\r
36#include <Library/ReportStatusCodeLib.h>\r
37\r
38#include <IndustryStandard/Scsi.h>\r
39\r
40#define SCSI_IO_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'i', 'o')\r
41\r
42typedef union {\r
43 UINT32 Scsi;\r
44 UINT8 ExtScsi[4]; \r
45} SCSI_ID;\r
46\r
47typedef struct _SCSI_TARGET_ID {\r
48 SCSI_ID ScsiId;\r
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
58//\r
59// SCSI Bus Controller device strcuture\r
60//\r
61#define SCSI_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('s', 'c', 's', 'i')\r
62\r
63//\r
64// SCSI Bus Timeout Experience Value\r
65//\r
66#define SCSI_BUS_TIMEOUT EFI_TIMER_PERIOD_SECONDS (3)\r
67\r
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
75typedef struct _EFI_SCSI_BUS_PROTOCOL {\r
76 UINT64 Reserved;\r
77} EFI_SCSI_BUS_PROTOCOL;\r
78\r
79typedef struct _SCSI_BUS_DEVICE {\r
80 UINTN Signature;\r
81 EFI_SCSI_BUS_PROTOCOL BusIdentify;\r
82 BOOLEAN ExtScsiSupport; \r
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
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
95 BOOLEAN ExtScsiSupport; \r
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
108//\r
109// Global Variables\r
110//\r
111extern EFI_DRIVER_BINDING_PROTOCOL gScsiBusDriverBinding;\r
112extern EFI_COMPONENT_NAME_PROTOCOL gScsiBusComponentName;\r
113extern EFI_COMPONENT_NAME2_PROTOCOL gScsiBusComponentName2;\r
114\r
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
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
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
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
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
177 \r
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
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
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
210 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
211 EFI_COMPONENT_NAME_PROTOCOL instance.\r
212\r
213 @param Language A pointer to a Null-terminated ASCII string\r
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
220 in RFC 4646 or ISO 639-2 language code format.\r
221\r
222 @param DriverName A pointer to the Unicode string to return.\r
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
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
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
260 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
261 EFI_COMPONENT_NAME_PROTOCOL instance.\r
262\r
263 @param ControllerHandle The handle of a controller that the driver\r
264 specified by This is managing. This handle\r
265 specifies the controller whose name is to be\r
266 returned.\r
267\r
268 @param ChildHandle The handle of the child controller to retrieve\r
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
277 @param Language A pointer to a Null-terminated ASCII string\r
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
284 RFC 4646 or ISO 639-2 language code format.\r
285\r
286 @param ControllerName A pointer to the Unicode string to return.\r
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
298 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
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
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
325/**\r
326 Retrieves the device type information of the SCSI Controller.\r
327\r
328 @param This Protocol instance pointer.\r
329 @param DeviceType A pointer to the device type information retrieved from\r
330 the SCSI Controller. \r
331\r
332 @retval EFI_SUCCESS Retrieves the device type information successfully.\r
333 @retval EFI_INVALID_PARAMETER The DeviceType is NULL.\r
334 \r
335**/\r
336EFI_STATUS\r
337EFIAPI\r
338ScsiGetDeviceType (\r
339 IN EFI_SCSI_IO_PROTOCOL *This,\r
340 OUT UINT8 *DeviceType\r
341 );\r
342\r
343/**\r
344 Retrieves the device location in the SCSI channel.\r
345\r
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
351\r
352 @retval EFI_SUCCESS Retrieves the device location successfully.\r
353 @retval EFI_INVALID_PARAMETER The Target or Lun is NULL.\r
354\r
355**/\r
356EFI_STATUS\r
357EFIAPI\r
358ScsiGetDeviceLocation (\r
359 IN EFI_SCSI_IO_PROTOCOL *This,\r
360 IN OUT UINT8 **Target,\r
361 OUT UINT64 *Lun\r
362 );\r
363\r
364/**\r
365 Resets the SCSI Bus that the SCSI Controller is attached to.\r
366\r
367 @param This Protocol instance pointer.\r
368\r
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
373 @retval EFI_TIMEOUT A timeout occurred while attempting to reset \r
374 the SCSI bus.\r
375**/\r
376EFI_STATUS\r
377EFIAPI\r
378ScsiResetBus (\r
379 IN EFI_SCSI_IO_PROTOCOL *This\r
380 );\r
381\r
382/**\r
383 Resets the SCSI Controller that the device handle specifies.\r
384\r
385 @param This Protocol instance pointer.\r
386\r
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
393EFI_STATUS\r
394EFIAPI\r
395ScsiResetDevice (\r
396 IN EFI_SCSI_IO_PROTOCOL *This\r
397 );\r
398\r
399/**\r
400 Sends a SCSI Request Packet to the SCSI Controller for execution.\r
401\r
402 @param This Protocol instance pointer.\r
403 @param CommandPacket The SCSI request packet to send to the SCSI \r
404 Controller specified by the device handle.\r
405 @param Event If the SCSI bus where the SCSI device is attached\r
406 does not support non-blocking I/O, then Event is \r
407 ignored, and blocking I/O is performed. \r
408 If Event is NULL, then blocking I/O is performed.\r
409 If Event is not NULL and non-blocking I/O is \r
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
413\r
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
418 SenseDataLength, and SenseData in that order\r
419 for additional status information.\r
420 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed, \r
421 but the entire DataBuffer could not be transferred.\r
422 The actual number of bytes transferred is returned\r
423 in TransferLength. See HostAdapterStatus, \r
424 TargetStatus, SenseDataLength, and SenseData in \r
425 that order for additional status information.\r
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
428 queued.The caller may retry again later.\r
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
432 that order for additional status information.\r
433 @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid. \r
434 The SCSI Request Packet was not sent, so no \r
435 additional status information is available.\r
436 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet\r
437 is not supported by the SCSI initiator(i.e., SCSI \r
438 Host Controller). The SCSI Request Packet was not\r
439 sent, so no additional status information is \r
440 available.\r
441 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI \r
442 Request Packet to execute. See HostAdapterStatus,\r
443 TargetStatus, SenseDataLength, and SenseData in \r
444 that order for additional status information.\r
445**/\r
446EFI_STATUS\r
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
453\r
454/**\r
455 Scan SCSI Bus to discover the device, and attach ScsiIoProtocol to it.\r
456\r
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
462\r
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
466\r
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
477\r
478/**\r
479 Discovery SCSI Device\r
480\r
481 @param ScsiIoDevice The pointer of SCSI_IO_DEV\r
482\r
483 @retval TRUE Find SCSI Device and verify it.\r
484 @retval FALSE Unable to find SCSI Device.\r
485\r
486**/\r
487BOOLEAN\r
488DiscoverScsiDevice (\r
489 IN OUT SCSI_IO_DEV *ScsiIoDevice\r
490 );\r
491\r
492#endif\r