2 Header file for SCSI Bus Driver.
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
21 #include <Protocol/ScsiPassThru.h>
22 #include <Protocol/ScsiPassThruExt.h>
23 #include <Protocol/ScsiIo.h>
24 #include <Protocol/ComponentName.h>
25 #include <Protocol/DriverBinding.h>
26 #include <Protocol/DevicePath.h>
28 #include <Library/DebugLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/UefiScsiLib.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/DevicePathLib.h>
37 #include <IndustryStandard/Scsi.h>
39 #define SCSI_IO_DEV_SIGNATURE SIGNATURE_32 ('s', 'c', 'i', 'o')
46 typedef struct _SCSI_TARGET_ID
{
61 EFI_SCSI_IO_PROTOCOL ScsiIo
;
62 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
63 BOOLEAN ExtScsiSupport
;
64 EFI_SCSI_PASS_THRU_PROTOCOL
*ScsiPassThru
;
65 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExtScsiPassThru
;
70 BOOLEAN RemovableDevice
;
73 #define SCSI_IO_DEV_FROM_THIS(a) CR (a, SCSI_IO_DEV, ScsiIo, SCSI_IO_DEV_SIGNATURE)
76 // SCSI Bus Controller device strcuture
80 // The ScsiBusProtocol is just used to locate ScsiBusDev
81 // structure in the SCSIBusDriverBindingStop(). Then we can
82 // Close all opened protocols and release this structure.
83 // ScsiBusProtocol is the private protocol.
84 // gEfiCallerIdGuid will be used as its protocol guid.
86 typedef struct _EFI_SCSI_BUS_PROTOCOL
{
88 } EFI_SCSI_BUS_PROTOCOL
;
90 #define SCSI_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('s', 'c', 's', 'i')
93 typedef struct _SCSI_BUS_DEVICE
{
95 EFI_SCSI_BUS_PROTOCOL BusIdentify
;
96 BOOLEAN ExtScsiSupport
;
97 EFI_SCSI_PASS_THRU_PROTOCOL
*ScsiInterface
;
98 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExtScsiInterface
;
99 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
102 #define SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS(a) CR (a, SCSI_BUS_DEVICE, BusIdentify, SCSI_BUS_DEVICE_SIGNATURE)
107 extern EFI_DRIVER_BINDING_PROTOCOL gScsiBusDriverBinding
;
108 extern EFI_COMPONENT_NAME_PROTOCOL gScsiBusComponentName
;
109 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiBusComponentName2
;
112 Test to see if this driver supports ControllerHandle.
114 This service is called by the EFI boot service ConnectController(). In order
115 to make drivers as small as possible, there are a few calling restrictions for
116 this service. ConnectController() must follow these calling restrictions. If
117 any other agent wishes to call Supported() it must also follow these calling
120 @param This Protocol instance pointer.
121 @param ControllerHandle Handle of device to test
122 @param RemainingDevicePath Optional parameter use to pick a specific child
125 @retval EFI_SUCCESS This driver supports this device
126 @retval EFI_ALREADY_STARTED This driver is already running on this device
127 @retval other This driver does not support this device
132 SCSIBusDriverBindingSupported (
133 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
134 IN EFI_HANDLE Controller
,
135 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
139 Start this driver on ControllerHandle.
141 This service is called by the EFI boot service ConnectController(). In order
142 to make drivers as small as possible, there are a few calling restrictions for
143 this service. ConnectController() must follow these calling restrictions. If
144 any other agent wishes to call Start() it must also follow these calling
147 @param This Protocol instance pointer.
148 @param ControllerHandle Handle of device to bind driver to
149 @param RemainingDevicePath Optional parameter use to pick a specific child
152 @retval EFI_SUCCESS This driver is added to ControllerHandle
153 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
154 @retval other This driver does not support this device
159 SCSIBusDriverBindingStart (
160 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
161 IN EFI_HANDLE Controller
,
162 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
166 Stop this driver on ControllerHandle.
168 This service is called by the EFI boot service DisconnectController().
169 In order to make drivers as small as possible, there are a few calling
170 restrictions for this service. DisconnectController() must follow these
171 calling restrictions. If any other agent wishes to call Stop() it must also
172 follow these calling restrictions.
174 @param This Protocol instance pointer.
175 @param ControllerHandle Handle of device to stop driver on
176 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
177 children is zero stop the entire bus driver.
178 @param ChildHandleBuffer List of Child Handles to Stop.
180 @retval EFI_SUCCESS This driver is removed ControllerHandle
181 @retval other This driver was not removed from this device
186 SCSIBusDriverBindingStop (
187 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
188 IN EFI_HANDLE Controller
,
189 IN UINTN NumberOfChildren
,
190 IN EFI_HANDLE
*ChildHandleBuffer
194 // EFI Component Name Functions
197 Retrieves a Unicode string that is the user readable name of the driver.
199 This function retrieves the user readable name of a driver in the form of a
200 Unicode string. If the driver specified by This has a user readable name in
201 the language specified by Language, then a pointer to the driver name is
202 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
203 by This does not support the language specified by Language,
204 then EFI_UNSUPPORTED is returned.
206 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
207 EFI_COMPONENT_NAME_PROTOCOL instance.
209 @param Language A pointer to a Null-terminated ASCII string
210 array indicating the language. This is the
211 language of the driver name that the caller is
212 requesting, and it must match one of the
213 languages specified in SupportedLanguages. The
214 number of languages supported by a driver is up
215 to the driver writer. Language is specified
216 in RFC 4646 or ISO 639-2 language code format.
218 @param DriverName A pointer to the Unicode string to return.
219 This Unicode string is the name of the
220 driver specified by This in the language
221 specified by Language.
223 @retval EFI_SUCCESS The Unicode string for the Driver specified by
224 This and the language specified by Language was
225 returned in DriverName.
227 @retval EFI_INVALID_PARAMETER Language is NULL.
229 @retval EFI_INVALID_PARAMETER DriverName is NULL.
231 @retval EFI_UNSUPPORTED The driver specified by This does not support
232 the language specified by Language.
237 ScsiBusComponentNameGetDriverName (
238 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
240 OUT CHAR16
**DriverName
244 Retrieves a Unicode string that is the user readable name of the controller
245 that is being managed by a driver.
247 This function retrieves the user readable name of the controller specified by
248 ControllerHandle and ChildHandle in the form of a Unicode string. If the
249 driver specified by This has a user readable name in the language specified by
250 Language, then a pointer to the controller name is returned in ControllerName,
251 and EFI_SUCCESS is returned. If the driver specified by This is not currently
252 managing the controller specified by ControllerHandle and ChildHandle,
253 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
254 support the language specified by Language, then EFI_UNSUPPORTED is returned.
256 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
257 EFI_COMPONENT_NAME_PROTOCOL instance.
259 @param ControllerHandle The handle of a controller that the driver
260 specified by This is managing. This handle
261 specifies the controller whose name is to be
264 @param ChildHandle The handle of the child controller to retrieve
265 the name of. This is an optional parameter that
266 may be NULL. It will be NULL for device
267 drivers. It will also be NULL for a bus drivers
268 that wish to retrieve the name of the bus
269 controller. It will not be NULL for a bus
270 driver that wishes to retrieve the name of a
273 @param Language A pointer to a Null-terminated ASCII string
274 array indicating the language. This is the
275 language of the driver name that the caller is
276 requesting, and it must match one of the
277 languages specified in SupportedLanguages. The
278 number of languages supported by a driver is up
279 to the driver writer. Language is specified in
280 RFC 4646 or ISO 639-2 language code format.
282 @param ControllerName A pointer to the Unicode string to return.
283 This Unicode string is the name of the
284 controller specified by ControllerHandle and
285 ChildHandle in the language specified by
286 Language from the point of view of the driver
289 @retval EFI_SUCCESS The Unicode string for the user readable name in
290 the language specified by Language for the
291 driver specified by This was returned in
294 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
296 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
299 @retval EFI_INVALID_PARAMETER Language is NULL.
301 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
303 @retval EFI_UNSUPPORTED The driver specified by This is not currently
304 managing the controller specified by
305 ControllerHandle and ChildHandle.
307 @retval EFI_UNSUPPORTED The driver specified by This does not support
308 the language specified by Language.
313 ScsiBusComponentNameGetControllerName (
314 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
315 IN EFI_HANDLE ControllerHandle
,
316 IN EFI_HANDLE ChildHandle OPTIONAL
,
318 OUT CHAR16
**ControllerName
322 Retrieves the device type information of the SCSI Controller.
324 @param This Protocol instance pointer.
325 @param DeviceType A pointer to the device type information retrieved from
328 @retval EFI_SUCCESS Retrieves the device type information successfully.
329 @retval EFI_INVALID_PARAMETER The DeviceType is NULL.
335 IN EFI_SCSI_IO_PROTOCOL
*This
,
336 OUT UINT8
*DeviceType
340 Retrieves the device location in the SCSI channel.
342 @param This Protocol instance pointer.
343 @param Target A pointer to the Target ID of a SCSI device
345 @param Lun A pointer to the LUN of the SCSI device on
348 @retval EFI_SUCCESS Retrieves the device location successfully.
349 @retval EFI_INVALID_PARAMETER The Target or Lun is NULL.
354 ScsiGetDeviceLocation (
355 IN EFI_SCSI_IO_PROTOCOL
*This
,
356 IN OUT UINT8
**Target
,
361 Resets the SCSI Bus that the SCSI Controller is attached to.
363 @param This Protocol instance pointer.
365 @retval EFI_SUCCESS The SCSI bus is reset successfully.
366 @retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus.
367 @retval EFI_UNSUPPORTED The bus reset operation is not supported by the
368 SCSI Host Controller.
369 @retval EFI_TIMEOUT A timeout occurred while attempting to reset
375 IN EFI_SCSI_IO_PROTOCOL
*This
379 Resets the SCSI Controller that the device handle specifies.
381 @param This Protocol instance pointer.
383 @retval EFI_SUCCESS Reset the SCSI controller successfully.
384 @retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller.
385 @retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation.
386 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the
392 IN EFI_SCSI_IO_PROTOCOL
*This
396 Sends a SCSI Request Packet to the SCSI Controller for execution.
398 @param This Protocol instance pointer.
399 @param CommandPacket The SCSI request packet to send to the SCSI
400 Controller specified by the device handle.
401 @param Event If the SCSI bus where the SCSI device is attached
402 does not support non-blocking I/O, then Event is
403 ignored, and blocking I/O is performed.
404 If Event is NULL, then blocking I/O is performed.
405 If Event is not NULL and non-blocking I/O is
406 supported, then non-blocking I/O is performed,
407 and Event will be signaled when the SCSI Request
410 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host
411 successfully, and TransferLength bytes were
412 transferred to/from DataBuffer.See
413 HostAdapterStatus, TargetStatus,
414 SenseDataLength, and SenseData in that order
415 for additional status information.
416 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
417 but the entire DataBuffer could not be transferred.
418 The actual number of bytes transferred is returned
419 in TransferLength. See HostAdapterStatus,
420 TargetStatus, SenseDataLength, and SenseData in
421 that order for additional status information.
422 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
423 there are too many SCSI Command Packets already
424 queued.The caller may retry again later.
425 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
426 the SCSI Request Packet. See HostAdapterStatus,
427 TargetStatus, SenseDataLength, and SenseData in
428 that order for additional status information.
429 @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.
430 The SCSI Request Packet was not sent, so no
431 additional status information is available.
432 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
433 is not supported by the SCSI initiator(i.e., SCSI
434 Host Controller). The SCSI Request Packet was not
435 sent, so no additional status information is
437 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
438 Request Packet to execute. See HostAdapterStatus,
439 TargetStatus, SenseDataLength, and SenseData in
440 that order for additional status information.
444 ScsiExecuteSCSICommand (
445 IN EFI_SCSI_IO_PROTOCOL
*This
,
446 IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
,
447 IN EFI_EVENT Event OPTIONAL
451 Scan SCSI Bus to discover the device, and attach ScsiIoProtocol to it.
453 @param This Protocol instance pointer
454 @param Controller Controller handle
455 @param TargetId Tartget to be scanned
456 @param Lun The Lun of the SCSI device on the SCSI channel.
457 @param ScsiBusDev The pointer of SCSI_BUS_DEVICE
459 @retval EFI_SUCCESS Successfully to discover the device and attach
460 ScsiIoProtocol to it.
461 @retval EFI_OUT_OF_RESOURCES Fail to discover the device.
466 ScsiScanCreateDevice (
467 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
468 IN EFI_HANDLE Controller
,
469 IN SCSI_TARGET_ID
*TargetId
,
471 IN OUT SCSI_BUS_DEVICE
*ScsiBusDev
475 Discovery SCSI Device
477 @param ScsiIoDevice The pointer of SCSI_IO_DEV
479 @retval TRUE Find SCSI Device and verify it.
480 @retval FALSE Unable to find SCSI Device.
485 IN OUT SCSI_IO_DEV
*ScsiIoDevice