2 Header file for SCSI Bus Driver.
4 Copyright (c) 2006 - 2008, Intel Corporation. <BR>
5 All rights reserved. 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')
41 typedef struct _SCSI_TARGET_ID
{
59 EFI_SCSI_IO_PROTOCOL ScsiIo
;
60 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
61 BOOLEAN ExtScsiSupport
;
62 EFI_SCSI_PASS_THRU_PROTOCOL
*ScsiPassThru
;
63 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExtScsiPassThru
;
68 BOOLEAN RemovableDevice
;
71 #define SCSI_IO_DEV_FROM_THIS(a) CR (a, SCSI_IO_DEV, ScsiIo, SCSI_IO_DEV_SIGNATURE)
74 // SCSI Bus Controller device strcuture
76 #define EFI_SCSI_BUS_PROTOCOL_GUID \
78 0x5261213D, 0x3A3D, 0x441E, {0xB3, 0xAF, 0x21, 0xD3, 0xF7, 0xA4, 0xCA, 0x17} \
81 typedef struct _EFI_SCSI_BUS_PROTOCOL
{
83 } EFI_SCSI_BUS_PROTOCOL
;
85 #define SCSI_BUS_DEVICE_SIGNATURE SIGNATURE_32 ('s', 'c', 's', 'i')
88 typedef struct _SCSI_BUS_DEVICE
{
90 EFI_SCSI_BUS_PROTOCOL BusIdentify
;
91 BOOLEAN ExtScsiSupport
;
92 EFI_SCSI_PASS_THRU_PROTOCOL
*ScsiInterface
;
93 EFI_EXT_SCSI_PASS_THRU_PROTOCOL
*ExtScsiInterface
;
94 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
97 #define SCSI_BUS_CONTROLLER_DEVICE_FROM_THIS(a) CR (a, SCSI_BUS_DEVICE, BusIdentify, SCSI_BUS_DEVICE_SIGNATURE)
102 extern EFI_DRIVER_BINDING_PROTOCOL gScsiBusDriverBinding
;
103 extern EFI_COMPONENT_NAME_PROTOCOL gScsiBusComponentName
;
104 extern EFI_COMPONENT_NAME2_PROTOCOL gScsiBusComponentName2
;
107 Test to see if this driver supports ControllerHandle.
109 This service is called by the EFI boot service ConnectController(). In order
110 to make drivers as small as possible, there are a few calling restrictions for
111 this service. ConnectController() must follow these calling restrictions. If
112 any other agent wishes to call Supported() it must also follow these calling
115 @param This Protocol instance pointer.
116 @param ControllerHandle Handle of device to test
117 @param RemainingDevicePath Optional parameter use to pick a specific child
120 @retval EFI_SUCCESS This driver supports this device
121 @retval EFI_ALREADY_STARTED This driver is already running on this device
122 @retval other This driver does not support this device
127 SCSIBusDriverBindingSupported (
128 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
129 IN EFI_HANDLE Controller
,
130 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
134 Start this driver on ControllerHandle.
136 This service is called by the EFI boot service ConnectController(). In order
137 to make drivers as small as possible, there are a few calling restrictions for
138 this service. ConnectController() must follow these calling restrictions. If
139 any other agent wishes to call Start() it must also follow these calling
142 @param This Protocol instance pointer.
143 @param ControllerHandle Handle of device to bind driver to
144 @param RemainingDevicePath Optional parameter use to pick a specific child
147 @retval EFI_SUCCESS This driver is added to ControllerHandle
148 @retval EFI_ALREADY_STARTED This driver is already running on ControllerHandle
149 @retval other This driver does not support this device
154 SCSIBusDriverBindingStart (
155 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
156 IN EFI_HANDLE Controller
,
157 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
161 Stop this driver on ControllerHandle.
163 This service is called by the EFI boot service DisconnectController().
164 In order to make drivers as small as possible, there are a few calling
165 restrictions for this service. DisconnectController() must follow these
166 calling restrictions. If any other agent wishes to call Stop() it must also
167 follow these calling restrictions.
169 @param This Protocol instance pointer.
170 @param ControllerHandle Handle of device to stop driver on
171 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
172 children is zero stop the entire bus driver.
173 @param ChildHandleBuffer List of Child Handles to Stop.
175 @retval EFI_SUCCESS This driver is removed ControllerHandle
176 @retval other This driver was not removed from this device
181 SCSIBusDriverBindingStop (
182 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
183 IN EFI_HANDLE Controller
,
184 IN UINTN NumberOfChildren
,
185 IN EFI_HANDLE
*ChildHandleBuffer
189 // EFI Component Name Functions
192 Retrieves a Unicode string that is the user readable name of the driver.
194 This function retrieves the user readable name of a driver in the form of a
195 Unicode string. If the driver specified by This has a user readable name in
196 the language specified by Language, then a pointer to the driver name is
197 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
198 by This does not support the language specified by Language,
199 then EFI_UNSUPPORTED is returned.
201 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
202 EFI_COMPONENT_NAME_PROTOCOL instance.
204 @param Language A pointer to a Null-terminated ASCII string
205 array indicating the language. This is the
206 language of the driver name that the caller is
207 requesting, and it must match one of the
208 languages specified in SupportedLanguages. The
209 number of languages supported by a driver is up
210 to the driver writer. Language is specified
211 in RFC 3066 or ISO 639-2 language code format.
213 @param DriverName A pointer to the Unicode string to return.
214 This Unicode string is the name of the
215 driver specified by This in the language
216 specified by Language.
218 @retval EFI_SUCCESS The Unicode string for the Driver specified by
219 This and the language specified by Language was
220 returned in DriverName.
222 @retval EFI_INVALID_PARAMETER Language is NULL.
224 @retval EFI_INVALID_PARAMETER DriverName is NULL.
226 @retval EFI_UNSUPPORTED The driver specified by This does not support
227 the language specified by Language.
232 ScsiBusComponentNameGetDriverName (
233 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
235 OUT CHAR16
**DriverName
239 Retrieves a Unicode string that is the user readable name of the controller
240 that is being managed by a driver.
242 This function retrieves the user readable name of the controller specified by
243 ControllerHandle and ChildHandle in the form of a Unicode string. If the
244 driver specified by This has a user readable name in the language specified by
245 Language, then a pointer to the controller name is returned in ControllerName,
246 and EFI_SUCCESS is returned. If the driver specified by This is not currently
247 managing the controller specified by ControllerHandle and ChildHandle,
248 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
249 support the language specified by Language, then EFI_UNSUPPORTED is returned.
251 @param This A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
252 EFI_COMPONENT_NAME_PROTOCOL instance.
254 @param ControllerHandle The handle of a controller that the driver
255 specified by This is managing. This handle
256 specifies the controller whose name is to be
259 @param ChildHandle The handle of the child controller to retrieve
260 the name of. This is an optional parameter that
261 may be NULL. It will be NULL for device
262 drivers. It will also be NULL for a bus drivers
263 that wish to retrieve the name of the bus
264 controller. It will not be NULL for a bus
265 driver that wishes to retrieve the name of a
268 @param Language A pointer to a Null-terminated ASCII string
269 array indicating the language. This is the
270 language of the driver name that the caller is
271 requesting, and it must match one of the
272 languages specified in SupportedLanguages. The
273 number of languages supported by a driver is up
274 to the driver writer. Language is specified in
275 RFC 3066 or ISO 639-2 language code format.
277 @param ControllerName A pointer to the Unicode string to return.
278 This Unicode string is the name of the
279 controller specified by ControllerHandle and
280 ChildHandle in the language specified by
281 Language from the point of view of the driver
284 @retval EFI_SUCCESS The Unicode string for the user readable name in
285 the language specified by Language for the
286 driver specified by This was returned in
289 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
291 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
294 @retval EFI_INVALID_PARAMETER Language is NULL.
296 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
298 @retval EFI_UNSUPPORTED The driver specified by This is not currently
299 managing the controller specified by
300 ControllerHandle and ChildHandle.
302 @retval EFI_UNSUPPORTED The driver specified by This does not support
303 the language specified by Language.
308 ScsiBusComponentNameGetControllerName (
309 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
310 IN EFI_HANDLE ControllerHandle
,
311 IN EFI_HANDLE ChildHandle OPTIONAL
,
313 OUT CHAR16
**ControllerName
317 Retrieves the device type information of the SCSI Controller.
319 @param This Protocol instance pointer.
320 @param DeviceType A pointer to the device type information retrieved from
323 @retval EFI_SUCCESS Retrieves the device type information successfully.
324 @retval EFI_INVALID_PARAMETER The DeviceType is NULL.
330 IN EFI_SCSI_IO_PROTOCOL
*This
,
331 OUT UINT8
*DeviceType
335 Retrieves the device location in the SCSI channel.
337 @param This Protocol instance pointer.
338 @param Target A pointer to the Target ID of a SCSI device
340 @param Lun A pointer to the LUN of the SCSI device on
343 @retval EFI_SUCCESS Retrieves the device location successfully.
344 @retval EFI_INVALID_PARAMETER The Target or Lun is NULL.
349 ScsiGetDeviceLocation (
350 IN EFI_SCSI_IO_PROTOCOL
*This
,
351 IN OUT UINT8
**Target
,
356 Resets the SCSI Bus that the SCSI Controller is attached to.
358 @param This Protocol instance pointer.
360 @retval EFI_SUCCESS The SCSI bus is reset successfully.
361 @retval EFI_DEVICE_ERROR Errors encountered when resetting the SCSI bus.
362 @retval EFI_UNSUPPORTED The bus reset operation is not supported by the
363 SCSI Host Controller.
364 @retval EFI_TIMEOUT A timeout occurred while attempting to reset
370 IN EFI_SCSI_IO_PROTOCOL
*This
374 Resets the SCSI Controller that the device handle specifies.
376 @param This Protocol instance pointer.
378 @retval EFI_SUCCESS Reset the SCSI controller successfully.
379 @retval EFI_DEVICE_ERROR Errors are encountered when resetting the SCSI Controller.
380 @retval EFI_UNSUPPORTED The SCSI bus does not support a device reset operation.
381 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the
387 IN EFI_SCSI_IO_PROTOCOL
*This
391 Sends a SCSI Request Packet to the SCSI Controller for execution.
393 @param This Protocol instance pointer.
394 @param CommandPacket The SCSI request packet to send to the SCSI
395 Controller specified by the device handle.
396 @param Event If the SCSI bus where the SCSI device is attached
397 does not support non-blocking I/O, then Event is
398 ignored, and blocking I/O is performed.
399 If Event is NULL, then blocking I/O is performed.
400 If Event is not NULL and non-blocking I/O is
401 supported, then non-blocking I/O is performed,
402 and Event will be signaled when the SCSI Request
405 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host
406 successfully, and TransferLength bytes were
407 transferred to/from DataBuffer.See
408 HostAdapterStatus, TargetStatus,
409 SenseDataLength, and SenseData in that order
410 for additional status information.
411 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was executed,
412 but the entire DataBuffer could not be transferred.
413 The actual number of bytes transferred is returned
414 in TransferLength. See HostAdapterStatus,
415 TargetStatus, SenseDataLength, and SenseData in
416 that order for additional status information.
417 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because
418 there are too many SCSI Command Packets already
419 queued.The caller may retry again later.
420 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send
421 the SCSI Request Packet. See HostAdapterStatus,
422 TargetStatus, SenseDataLength, and SenseData in
423 that order for additional status information.
424 @retval EFI_INVALID_PARAMETER The contents of CommandPacket are invalid.
425 The SCSI Request Packet was not sent, so no
426 additional status information is available.
427 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet
428 is not supported by the SCSI initiator(i.e., SCSI
429 Host Controller). The SCSI Request Packet was not
430 sent, so no additional status information is
432 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI
433 Request Packet to execute. See HostAdapterStatus,
434 TargetStatus, SenseDataLength, and SenseData in
435 that order for additional status information.
439 ScsiExecuteSCSICommand (
440 IN EFI_SCSI_IO_PROTOCOL
*This
,
441 IN OUT EFI_SCSI_IO_SCSI_REQUEST_PACKET
*CommandPacket
,
442 IN EFI_EVENT Event OPTIONAL
446 Scan SCSI Bus to discover the device, and attach ScsiIoProtocol to it.
448 @param This Protocol instance pointer
449 @param Controller Controller handle
450 @param TargetId Tartget to be scanned
451 @param Lun The Lun of the SCSI device on the SCSI channel.
452 @param ScsiBusDev The pointer of SCSI_BUS_DEVICE
454 @retval EFI_SUCCESS Successfully to discover the device and attach
455 ScsiIoProtocol to it.
456 @retval EFI_OUT_OF_RESOURCES Fail to discover the device.
461 ScsiScanCreateDevice (
462 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
463 IN EFI_HANDLE Controller
,
464 IN SCSI_TARGET_ID
*TargetId
,
466 IN OUT SCSI_BUS_DEVICE
*ScsiBusDev
470 Discovery SCSI Device
472 @param ScsiIoDevice The pointer of SCSI_IO_DEV
474 @retval TRUE Find SCSI Device and verify it.
475 @retval FALSE Unable to find SCSI Device.
480 IN OUT SCSI_IO_DEV
*ScsiIoDevice