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
78 #define EFI_SCSI_BUS_PROTOCOL_GUID \
80 0x5261213D, 0x3A3D, 0x441E, {0xB3, 0xAF, 0x21, 0xD3, 0xF7, 0xA4, 0xCA, 0x17} \
83 typedef struct _EFI_SCSI_BUS_PROTOCOL
{
85 } EFI_SCSI_BUS_PROTOCOL
;
87 #define SCSI_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('s', 'c', 's', 'i')
90 typedef struct _SCSI_BUS_DEVICE
{
92 EFI_SCSI_BUS_PROTOCOL BusIdentify
;
93 BOOLEAN ExtScsiSupport
;
94 EFI_SCSI_PASS_THRU_PROTOCOL
*ScsiInterface
;
95 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExtScsiInterface
;
96 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
99 #define SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS(a) CR (a, SCSI_BUS_DEVICE, BusIdentify, SCSI_BUS_DEVICE_SIGNATURE)
104 extern EFI_DRIVER_BINDING_PROTOCOL gScsiBusDriverBinding
;
105 extern EFI_COMPONENT_NAME_PROTOCOL gScsiBusComponentName
;
106 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiBusComponentName2
;
109 Test to see if this driver supports ControllerHandle.
111 This service is called by the EFI boot service ConnectController(). In order
112 to make drivers as small as possible, there are a few calling restrictions for
113 this service. ConnectController() must follow these calling restrictions. If
114 any other agent wishes to call Supported() it must also follow these calling
117 @param This Protocol instance pointer.
118 @param ControllerHandle Handle of device to test
119 @param RemainingDevicePath Optional parameter use to pick a specific child
122 @retval EFI_SUCCESS This driver supports this device
123 @retval EFI_ALREADY_STARTED This driver is already running on this device
124 @retval other This driver does not support this device
129 SCSIBusDriverBindingSupported (
130 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
131 IN EFI_HANDLE Controller
,
132 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
136 Start this driver on ControllerHandle.
138 This service is called by the EFI boot service ConnectController(). In order
139 to make drivers as small as possible, there are a few calling restrictions for
140 this service. ConnectController() must follow these calling restrictions. If
141 any other agent wishes to call Start() it must also follow these calling
144 @param This Protocol instance pointer.
145 @param ControllerHandle Handle of device to bind driver to
146 @param RemainingDevicePath Optional parameter use to pick a specific child
149 @retval EFI_SUCCESS This driver is added to ControllerHandle
150 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
151 @retval other This driver does not support this device
156 SCSIBusDriverBindingStart (
157 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
158 IN EFI_HANDLE Controller
,
159 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
163 Stop this driver on ControllerHandle.
165 This service is called by the EFI boot service DisconnectController().
166 In order to make drivers as small as possible, there are a few calling
167 restrictions for this service. DisconnectController() must follow these
168 calling restrictions. If any other agent wishes to call Stop() it must also
169 follow these calling restrictions.
171 @param This Protocol instance pointer.
172 @param ControllerHandle Handle of device to stop driver on
173 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
174 children is zero stop the entire bus driver.
175 @param ChildHandleBuffer List of Child Handles to Stop.
177 @retval EFI_SUCCESS This driver is removed ControllerHandle
178 @retval other This driver was not removed from this device
183 SCSIBusDriverBindingStop (
184 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
185 IN EFI_HANDLE Controller
,
186 IN UINTN NumberOfChildren
,
187 IN EFI_HANDLE
*ChildHandleBuffer
191 // EFI Component Name Functions
194 Retrieves a Unicode string that is the user readable name of the driver.
196 This function retrieves the user readable name of a driver in the form of a
197 Unicode string. If the driver specified by This has a user readable name in
198 the language specified by Language, then a pointer to the driver name is
199 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
200 by This does not support the language specified by Language,
201 then EFI_UNSUPPORTED is returned.
203 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
204 EFI_COMPONENT_NAME_PROTOCOL instance.
206 @param Language A pointer to a Null-terminated ASCII string
207 array indicating the language. This is the
208 language of the driver name that the caller is
209 requesting, and it must match one of the
210 languages specified in SupportedLanguages. The
211 number of languages supported by a driver is up
212 to the driver writer. Language is specified
213 in RFC 4646 or ISO 639-2 language code format.
215 @param DriverName A pointer to the Unicode string to return.
216 This Unicode string is the name of the
217 driver specified by This in the language
218 specified by Language.
220 @retval EFI_SUCCESS The Unicode string for the Driver specified by
221 This and the language specified by Language was
222 returned in DriverName.
224 @retval EFI_INVALID_PARAMETER Language is NULL.
226 @retval EFI_INVALID_PARAMETER DriverName is NULL.
228 @retval EFI_UNSUPPORTED The driver specified by This does not support
229 the language specified by Language.
234 ScsiBusComponentNameGetDriverName (
235 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
237 OUT CHAR16
**DriverName
241 Retrieves a Unicode string that is the user readable name of the controller
242 that is being managed by a driver.
244 This function retrieves the user readable name of the controller specified by
245 ControllerHandle and ChildHandle in the form of a Unicode string. If the
246 driver specified by This has a user readable name in the language specified by
247 Language, then a pointer to the controller name is returned in ControllerName,
248 and EFI_SUCCESS is returned. If the driver specified by This is not currently
249 managing the controller specified by ControllerHandle and ChildHandle,
250 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
251 support the language specified by Language, then EFI_UNSUPPORTED is returned.
253 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
254 EFI_COMPONENT_NAME_PROTOCOL instance.
256 @param ControllerHandle The handle of a controller that the driver
257 specified by This is managing. This handle
258 specifies the controller whose name is to be
261 @param ChildHandle The handle of the child controller to retrieve
262 the name of. This is an optional parameter that
263 may be NULL. It will be NULL for device
264 drivers. It will also be NULL for a bus drivers
265 that wish to retrieve the name of the bus
266 controller. It will not be NULL for a bus
267 driver that wishes to retrieve the name of a
270 @param Language A pointer to a Null-terminated ASCII string
271 array indicating the language. This is the
272 language of the driver name that the caller is
273 requesting, and it must match one of the
274 languages specified in SupportedLanguages. The
275 number of languages supported by a driver is up
276 to the driver writer. Language is specified in
277 RFC 4646 or ISO 639-2 language code format.
279 @param ControllerName A pointer to the Unicode string to return.
280 This Unicode string is the name of the
281 controller specified by ControllerHandle and
282 ChildHandle in the language specified by
283 Language from the point of view of the driver
286 @retval EFI_SUCCESS The Unicode string for the user readable name in
287 the language specified by Language for the
288 driver specified by This was returned in
291 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
293 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
296 @retval EFI_INVALID_PARAMETER Language is NULL.
298 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
300 @retval EFI_UNSUPPORTED The driver specified by This is not currently
301 managing the controller specified by
302 ControllerHandle and ChildHandle.
304 @retval EFI_UNSUPPORTED The driver specified by This does not support
305 the language specified by Language.
310 ScsiBusComponentNameGetControllerName (
311 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
312 IN EFI_HANDLE ControllerHandle
,
313 IN EFI_HANDLE ChildHandle OPTIONAL
,
315 OUT CHAR16
**ControllerName
319 Retrieves the device type information of the SCSI Controller.
321 @param This Protocol instance pointer.
322 @param DeviceType A pointer to the device type information retrieved from
325 @retval EFI_SUCCESS Retrieves the device type information successfully.
326 @retval EFI_INVALID_PARAMETER The DeviceType is NULL.
332 IN EFI_SCSI_IO_PROTOCOL
*This
,
333 OUT UINT8
*DeviceType
337 Retrieves the device location in the SCSI channel.
339 @param This Protocol instance pointer.
340 @param Target A pointer to the Target ID of a SCSI device
342 @param Lun A pointer to the LUN of the SCSI device on
345 @retval EFI_SUCCESS Retrieves the device location successfully.
346 @retval EFI_INVALID_PARAMETER The Target or Lun is NULL.
351 ScsiGetDeviceLocation (
352 IN EFI_SCSI_IO_PROTOCOL
*This
,
353 IN OUT UINT8
**Target
,
358 Resets the SCSI Bus that the SCSI Controller is attached to.
360 @param This Protocol instance pointer.
362 @retval EFI_SUCCESS The SCSI bus is reset successfully.
363 @retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus.
364 @retval EFI_UNSUPPORTED The bus reset operation is not supported by the
365 SCSI Host Controller.
366 @retval EFI_TIMEOUT A timeout occurred while attempting to reset
372 IN EFI_SCSI_IO_PROTOCOL
*This
376 Resets the SCSI Controller that the device handle specifies.
378 @param This Protocol instance pointer.
380 @retval EFI_SUCCESS Reset the SCSI controller successfully.
381 @retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller.
382 @retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation.
383 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the
389 IN EFI_SCSI_IO_PROTOCOL
*This
393 Sends a SCSI Request Packet to the SCSI Controller for execution.
395 @param This Protocol instance pointer.
396 @param CommandPacket The SCSI request packet to send to the SCSI
397 Controller specified by the device handle.
398 @param Event If the SCSI bus where the SCSI device is attached
399 does not support non-blocking I/O, then Event is
400 ignored, and blocking I/O is performed.
401 If Event is NULL, then blocking I/O is performed.
402 If Event is not NULL and non-blocking I/O is
403 supported, then non-blocking I/O is performed,
404 and Event will be signaled when the SCSI Request
407 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host
408 successfully, and TransferLength bytes were
409 transferred to/from DataBuffer.See
410 HostAdapterStatus, TargetStatus,
411 SenseDataLength, and SenseData in that order
412 for additional status information.
413 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
414 but the entire DataBuffer could not be transferred.
415 The actual number of bytes transferred is returned
416 in TransferLength. See HostAdapterStatus,
417 TargetStatus, SenseDataLength, and SenseData in
418 that order for additional status information.
419 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
420 there are too many SCSI Command Packets already
421 queued.The caller may retry again later.
422 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
423 the SCSI Request Packet. See HostAdapterStatus,
424 TargetStatus, SenseDataLength, and SenseData in
425 that order for additional status information.
426 @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.
427 The SCSI Request Packet was not sent, so no
428 additional status information is available.
429 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
430 is not supported by the SCSI initiator(i.e., SCSI
431 Host Controller). The SCSI Request Packet was not
432 sent, so no additional status information is
434 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
435 Request Packet to execute. See HostAdapterStatus,
436 TargetStatus, SenseDataLength, and SenseData in
437 that order for additional status information.
441 ScsiExecuteSCSICommand (
442 IN EFI_SCSI_IO_PROTOCOL
*This
,
443 IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
,
444 IN EFI_EVENT Event OPTIONAL
448 Scan SCSI Bus to discover the device, and attach ScsiIoProtocol to it.
450 @param This Protocol instance pointer
451 @param Controller Controller handle
452 @param TargetId Tartget to be scanned
453 @param Lun The Lun of the SCSI device on the SCSI channel.
454 @param ScsiBusDev The pointer of SCSI_BUS_DEVICE
456 @retval EFI_SUCCESS Successfully to discover the device and attach
457 ScsiIoProtocol to it.
458 @retval EFI_OUT_OF_RESOURCES Fail to discover the device.
463 ScsiScanCreateDevice (
464 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
465 IN EFI_HANDLE Controller
,
466 IN SCSI_TARGET_ID
*TargetId
,
468 IN OUT SCSI_BUS_DEVICE
*ScsiBusDev
472 Discovery SCSI Device
474 @param ScsiIoDevice The pointer of SCSI_IO_DEV
476 @retval TRUE Find SCSI Device and verify it.
477 @retval FALSE Unable to find SCSI Device.
482 IN OUT SCSI_IO_DEV
*ScsiIoDevice