]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h
ce8066f71e84867bb77e96e6a038043b18ef30fb
[mirror_edk2.git] / MdeModulePkg / Bus / Ufs / UfsPassThruDxe / UfsPassThru.h
1 /** @file
2
3 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>
4 This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
8
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11
12 **/
13
14 #ifndef _UFS_PASS_THRU_H_
15 #define _UFS_PASS_THRU_H_
16
17 #include <Uefi.h>
18
19 #include <Protocol/ScsiPassThruExt.h>
20 #include <Protocol/UfsHostController.h>
21
22 #include <Library/DebugLib.h>
23 #include <Library/UefiDriverEntryPoint.h>
24 #include <Library/BaseLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/BaseMemoryLib.h>
27 #include <Library/MemoryAllocationLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/DevicePathLib.h>
30 #include <Library/TimerLib.h>
31
32 #include "UfsPassThruHci.h"
33
34 #define UFS_PASS_THRU_SIG SIGNATURE_32 ('U', 'F', 'S', 'P')
35
36 //
37 // Lun 0~7 is for 8 common luns.
38 // Lun 8~11 is for those 4 well known luns (Refer to UFS 2.0 spec Table 10.58 for details):
39 // Lun 8: REPORT LUNS
40 // Lun 9: UFS DEVICE
41 // Lun 10: BOOT
42 // Lun 11: RPMB
43 //
44 #define UFS_MAX_LUNS 12
45 #define UFS_WLUN_PREFIX 0xC1
46
47 typedef struct {
48 UINT8 Lun[UFS_MAX_LUNS];
49 UINT16 BitMask:12; // Bit 0~7 is 1/1 mapping to common luns. Bit 8~11 is 1/1 mapping to well-known luns.
50 UINT16 Rsvd:4;
51 } UFS_EXPOSED_LUNS;
52
53 typedef struct _UFS_PASS_THRU_PRIVATE_DATA {
54 UINT32 Signature;
55 EFI_HANDLE Handle;
56 EFI_EXT_SCSI_PASS_THRU_MODE ExtScsiPassThruMode;
57 EFI_EXT_SCSI_PASS_THRU_PROTOCOL ExtScsiPassThru;
58 EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHostController;
59 UINTN UfsHcBase;
60 UINT32 Capabilities;
61
62 UINT8 TaskTag;
63
64 VOID *UtpTrlBase;
65 UINT8 Nutrs;
66 VOID *TrlMapping;
67 VOID *UtpTmrlBase;
68 UINT8 Nutmrs;
69 VOID *TmrlMapping;
70
71 UFS_EXPOSED_LUNS Luns;
72 } UFS_PASS_THRU_PRIVATE_DATA;
73
74 #define UFS_TIMEOUT EFI_TIMER_PERIOD_SECONDS(3)
75
76 #define ROUNDUP8(x) (((x) % 8 == 0) ? (x) : ((x) / 8 + 1) * 8)
77
78 #define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) == 0)
79
80 #define UFS_PASS_THRU_PRIVATE_DATA_FROM_THIS(a) \
81 CR (a, \
82 UFS_PASS_THRU_PRIVATE_DATA, \
83 ExtScsiPassThru, \
84 UFS_PASS_THRU_SIG \
85 )
86
87 typedef struct _UFS_DEVICE_MANAGEMENT_REQUEST_PACKET {
88 UINT64 Timeout;
89 VOID *InDataBuffer;
90 VOID *OutDataBuffer;
91 UINT8 Opcode;
92 UINT8 DescId;
93 UINT8 Index;
94 UINT8 Selector;
95 UINT32 InTransferLength;
96 UINT32 OutTransferLength;
97 UINT8 DataDirection;
98 UINT8 Ocs;
99 } UFS_DEVICE_MANAGEMENT_REQUEST_PACKET;
100
101 //
102 // function prototype
103 //
104 /**
105 Tests to see if this driver supports a given controller. If a child device is provided,
106 it further tests to see if this driver supports creating a handle for the specified child device.
107
108 This function checks to see if the driver specified by This supports the device specified by
109 ControllerHandle. Drivers will typically use the device path attached to
110 ControllerHandle and/or the services from the bus I/O abstraction attached to
111 ControllerHandle to determine if the driver supports ControllerHandle. This function
112 may be called many times during platform initialization. In order to reduce boot times, the tests
113 performed by this function must be very small, and take as little time as possible to execute. This
114 function must not change the state of any hardware devices, and this function must be aware that the
115 device specified by ControllerHandle may already be managed by the same driver or a
116 different driver. This function must match its calls to AllocatePages() with FreePages(),
117 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
118 Since ControllerHandle may have been previously started by the same driver, if a protocol is
119 already in the opened state, then it must not be closed with CloseProtocol(). This is required
120 to guarantee the state of ControllerHandle is not modified by this function.
121
122 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
123 @param[in] ControllerHandle The handle of the controller to test. This handle
124 must support a protocol interface that supplies
125 an I/O abstraction to the driver.
126 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
127 parameter is ignored by device drivers, and is optional for bus
128 drivers. For bus drivers, if this parameter is not NULL, then
129 the bus driver must determine if the bus controller specified
130 by ControllerHandle and the child controller specified
131 by RemainingDevicePath are both supported by this
132 bus driver.
133
134 @retval EFI_SUCCESS The device specified by ControllerHandle and
135 RemainingDevicePath is supported by the driver specified by This.
136 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
137 RemainingDevicePath is already being managed by the driver
138 specified by This.
139 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
140 RemainingDevicePath is already being managed by a different
141 driver or an application that requires exclusive access.
142 Currently not implemented.
143 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
144 RemainingDevicePath is not supported by the driver specified by This.
145 **/
146 EFI_STATUS
147 EFIAPI
148 UfsPassThruDriverBindingSupported (
149 IN EFI_DRIVER_BINDING_PROTOCOL *This,
150 IN EFI_HANDLE Controller,
151 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
152 );
153
154 /**
155 Starts a device controller or a bus controller.
156
157 The Start() function is designed to be invoked from the EFI boot service ConnectController().
158 As a result, much of the error checking on the parameters to Start() has been moved into this
159 common boot service. It is legal to call Start() from other locations,
160 but the following calling restrictions must be followed or the system behavior will not be deterministic.
161 1. ControllerHandle must be a valid EFI_HANDLE.
162 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
163 EFI_DEVICE_PATH_PROTOCOL.
164 3. Prior to calling Start(), the Supported() function for the driver specified by This must
165 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
166
167 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
168 @param[in] ControllerHandle The handle of the controller to start. This handle
169 must support a protocol interface that supplies
170 an I/O abstraction to the driver.
171 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
172 parameter is ignored by device drivers, and is optional for bus
173 drivers. For a bus driver, if this parameter is NULL, then handles
174 for all the children of Controller are created by this driver.
175 If this parameter is not NULL and the first Device Path Node is
176 not the End of Device Path Node, then only the handle for the
177 child device specified by the first Device Path Node of
178 RemainingDevicePath is created by this driver.
179 If the first Device Path Node of RemainingDevicePath is
180 the End of Device Path Node, no child handle is created by this
181 driver.
182
183 @retval EFI_SUCCESS The device was started.
184 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
185 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
186 @retval Others The driver failded to start the device.
187
188 **/
189 EFI_STATUS
190 EFIAPI
191 UfsPassThruDriverBindingStart (
192 IN EFI_DRIVER_BINDING_PROTOCOL *This,
193 IN EFI_HANDLE Controller,
194 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
195 );
196
197 /**
198 Stops a device controller or a bus controller.
199
200 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
201 As a result, much of the error checking on the parameters to Stop() has been moved
202 into this common boot service. It is legal to call Stop() from other locations,
203 but the following calling restrictions must be followed or the system behavior will not be deterministic.
204 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
205 same driver's Start() function.
206 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
207 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
208 Start() function, and the Start() function must have called OpenProtocol() on
209 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
210
211 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
212 @param[in] ControllerHandle A handle to the device being stopped. The handle must
213 support a bus specific I/O protocol for the driver
214 to use to stop the device.
215 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
216 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
217 if NumberOfChildren is 0.
218
219 @retval EFI_SUCCESS The device was stopped.
220 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
221
222 **/
223 EFI_STATUS
224 EFIAPI
225 UfsPassThruDriverBindingStop (
226 IN EFI_DRIVER_BINDING_PROTOCOL *This,
227 IN EFI_HANDLE Controller,
228 IN UINTN NumberOfChildren,
229 IN EFI_HANDLE *ChildHandleBuffer
230 );
231
232 //
233 // EFI Component Name Functions
234 //
235 /**
236 Retrieves a Unicode string that is the user readable name of the driver.
237
238 This function retrieves the user readable name of a driver in the form of a
239 Unicode string. If the driver specified by This has a user readable name in
240 the language specified by Language, then a pointer to the driver name is
241 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
242 by This does not support the language specified by Language,
243 then EFI_UNSUPPORTED is returned.
244
245 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
246 EFI_COMPONENT_NAME_PROTOCOL instance.
247
248 @param Language[in] A pointer to a Null-terminated ASCII string
249 array indicating the language. This is the
250 language of the driver name that the caller is
251 requesting, and it must match one of the
252 languages specified in SupportedLanguages. The
253 number of languages supported by a driver is up
254 to the driver writer. Language is specified
255 in RFC 4646 or ISO 639-2 language code format.
256
257 @param DriverName[out] A pointer to the Unicode string to return.
258 This Unicode string is the name of the
259 driver specified by This in the language
260 specified by Language.
261
262 @retval EFI_SUCCESS The Unicode string for the Driver specified by
263 This and the language specified by Language was
264 returned in DriverName.
265
266 @retval EFI_INVALID_PARAMETER Language is NULL.
267
268 @retval EFI_INVALID_PARAMETER DriverName is NULL.
269
270 @retval EFI_UNSUPPORTED The driver specified by This does not support
271 the language specified by Language.
272
273 **/
274 EFI_STATUS
275 EFIAPI
276 UfsPassThruComponentNameGetDriverName (
277 IN EFI_COMPONENT_NAME_PROTOCOL *This,
278 IN CHAR8 *Language,
279 OUT CHAR16 **DriverName
280 );
281
282
283 /**
284 Retrieves a Unicode string that is the user readable name of the controller
285 that is being managed by a driver.
286
287 This function retrieves the user readable name of the controller specified by
288 ControllerHandle and ChildHandle in the form of a Unicode string. If the
289 driver specified by This has a user readable name in the language specified by
290 Language, then a pointer to the controller name is returned in ControllerName,
291 and EFI_SUCCESS is returned. If the driver specified by This is not currently
292 managing the controller specified by ControllerHandle and ChildHandle,
293 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
294 support the language specified by Language, then EFI_UNSUPPORTED is returned.
295
296 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
297 EFI_COMPONENT_NAME_PROTOCOL instance.
298
299 @param ControllerHandle[in] The handle of a controller that the driver
300 specified by This is managing. This handle
301 specifies the controller whose name is to be
302 returned.
303
304 @param ChildHandle[in] The handle of the child controller to retrieve
305 the name of. This is an optional parameter that
306 may be NULL. It will be NULL for device
307 drivers. It will also be NULL for a bus drivers
308 that wish to retrieve the name of the bus
309 controller. It will not be NULL for a bus
310 driver that wishes to retrieve the name of a
311 child controller.
312
313 @param Language[in] A pointer to a Null-terminated ASCII string
314 array indicating the language. This is the
315 language of the driver name that the caller is
316 requesting, and it must match one of the
317 languages specified in SupportedLanguages. The
318 number of languages supported by a driver is up
319 to the driver writer. Language is specified in
320 RFC 4646 or ISO 639-2 language code format.
321
322 @param ControllerName[out] A pointer to the Unicode string to return.
323 This Unicode string is the name of the
324 controller specified by ControllerHandle and
325 ChildHandle in the language specified by
326 Language from the point of view of the driver
327 specified by This.
328
329 @retval EFI_SUCCESS The Unicode string for the user readable name in
330 the language specified by Language for the
331 driver specified by This was returned in
332 DriverName.
333
334 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
335
336 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
337 EFI_HANDLE.
338
339 @retval EFI_INVALID_PARAMETER Language is NULL.
340
341 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
342
343 @retval EFI_UNSUPPORTED The driver specified by This is not currently
344 managing the controller specified by
345 ControllerHandle and ChildHandle.
346
347 @retval EFI_UNSUPPORTED The driver specified by This does not support
348 the language specified by Language.
349
350 **/
351 EFI_STATUS
352 EFIAPI
353 UfsPassThruComponentNameGetControllerName (
354 IN EFI_COMPONENT_NAME_PROTOCOL *This,
355 IN EFI_HANDLE ControllerHandle,
356 IN EFI_HANDLE ChildHandle OPTIONAL,
357 IN CHAR8 *Language,
358 OUT CHAR16 **ControllerName
359 );
360
361 /**
362 Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function
363 supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the
364 nonblocking I/O functionality is optional.
365
366 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
367 @param Target The Target is an array of size TARGET_MAX_BYTES and it represents
368 the id of the SCSI device to send the SCSI Request Packet. Each
369 transport driver may choose to utilize a subset of this size to suit the needs
370 of transport target representation. For example, a Fibre Channel driver
371 may use only 8 bytes (WWN) to represent an FC target.
372 @param Lun The LUN of the SCSI device to send the SCSI Request Packet.
373 @param Packet A pointer to the SCSI Request Packet to send to the SCSI device
374 specified by Target and Lun.
375 @param Event If nonblocking I/O is not supported then Event is ignored, and blocking
376 I/O is performed. If Event is NULL, then blocking I/O is performed. If
377 Event is not NULL and non blocking I/O is supported, then
378 nonblocking I/O is performed, and Event will be signaled when the
379 SCSI Request Packet completes.
380
381 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional
382 commands, InTransferLength bytes were transferred from
383 InDataBuffer. For write and bi-directional commands,
384 OutTransferLength bytes were transferred by
385 OutDataBuffer.
386 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was not executed. The number of bytes that
387 could be transferred is returned in InTransferLength. For write
388 and bi-directional commands, OutTransferLength bytes were
389 transferred by OutDataBuffer.
390 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many
391 SCSI Request Packets already queued. The caller may retry again later.
392 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request
393 Packet.
394 @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid.
395 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported
396 by the host adapter. This includes the case of Bi-directional SCSI
397 commands not supported by the implementation. The SCSI Request
398 Packet was not sent, so no additional status information is available.
399 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
400
401 **/
402 EFI_STATUS
403 EFIAPI
404 UfsPassThruPassThru (
405 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
406 IN UINT8 *Target,
407 IN UINT64 Lun,
408 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,
409 IN EFI_EVENT Event OPTIONAL
410 );
411
412 /**
413 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These
414 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal
415 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the
416 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI
417 channel.
418
419 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
420 @param Target On input, a pointer to the Target ID (an array of size
421 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
422 On output, a pointer to the Target ID (an array of
423 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
424 channel. An input value of 0xF(all bytes in the array are 0xF) in the
425 Target array retrieves the Target ID of the first SCSI device present on a
426 SCSI channel.
427 @param Lun On input, a pointer to the LUN of a SCSI device present on the SCSI
428 channel. On output, a pointer to the LUN of the next SCSI device present
429 on a SCSI channel.
430
431 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI
432 channel was returned in Target and Lun.
433 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were
434 not returned on a previous call to GetNextTargetLun().
435 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
436
437 **/
438 EFI_STATUS
439 EFIAPI
440 UfsPassThruGetNextTargetLun (
441 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
442 IN OUT UINT8 **Target,
443 IN OUT UINT64 *Lun
444 );
445
446 /**
447 Used to allocate and build a device path node for a SCSI device on a SCSI channel.
448
449 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
450 @param Target The Target is an array of size TARGET_MAX_BYTES and it specifies the
451 Target ID of the SCSI device for which a device path node is to be
452 allocated and built. Transport drivers may chose to utilize a subset of
453 this size to suit the representation of targets. For example, a Fibre
454 Channel driver may use only 8 bytes (WWN) in the array to represent a
455 FC target.
456 @param Lun The LUN of the SCSI device for which a device path node is to be
457 allocated and built.
458 @param DevicePath A pointer to a single device path node that describes the SCSI device
459 specified by Target and Lun. This function is responsible for
460 allocating the buffer DevicePath with the boot service
461 AllocatePool(). It is the caller's responsibility to free
462 DevicePath when the caller is finished with DevicePath.
463
464 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by
465 Target and Lun was allocated and returned in
466 DevicePath.
467 @retval EFI_INVALID_PARAMETER DevicePath is NULL.
468 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist
469 on the SCSI channel.
470 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.
471
472 **/
473 EFI_STATUS
474 EFIAPI
475 UfsPassThruBuildDevicePath (
476 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
477 IN UINT8 *Target,
478 IN UINT64 Lun,
479 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath
480 );
481
482 /**
483 Used to translate a device path node to a Target ID and LUN.
484
485 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
486 @param DevicePath A pointer to a single device path node that describes the SCSI device
487 on the SCSI channel.
488 @param Target A pointer to the Target Array which represents the ID of a SCSI device
489 on the SCSI channel.
490 @param Lun A pointer to the LUN of a SCSI device on the SCSI channel.
491
492 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and
493 LUN, and they were returned in Target and Lun.
494 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.
495 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN
496 does not exist.
497 @retval EFI_UNSUPPORTED This driver does not support the device path node type in
498 DevicePath.
499
500 **/
501 EFI_STATUS
502 EFIAPI
503 UfsPassThruGetTargetLun (
504 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
505 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,
506 OUT UINT8 **Target,
507 OUT UINT64 *Lun
508 );
509
510 /**
511 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.
512
513 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
514
515 @retval EFI_SUCCESS The SCSI channel was reset.
516 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.
517 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.
518 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.
519
520 **/
521 EFI_STATUS
522 EFIAPI
523 UfsPassThruResetChannel (
524 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This
525 );
526
527 /**
528 Resets a SCSI logical unit that is connected to a SCSI channel.
529
530 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
531 @param Target The Target is an array of size TARGET_MAX_BYTE and it represents the
532 target port ID of the SCSI device containing the SCSI logical unit to
533 reset. Transport drivers may chose to utilize a subset of this array to suit
534 the representation of their targets.
535 @param Lun The LUN of the SCSI device to reset.
536
537 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.
538 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
539 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device
540 specified by Target and Lun.
541 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.
542 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device
543 specified by Target and Lun.
544
545 **/
546 EFI_STATUS
547 EFIAPI
548 UfsPassThruResetTargetLun (
549 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
550 IN UINT8 *Target,
551 IN UINT64 Lun
552 );
553
554 /**
555 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either
556 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs
557 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to
558 see if a SCSI device is actually present at that location on the SCSI channel.
559
560 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.
561 @param Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.
562 On output, a pointer to the Target ID (an array of
563 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI
564 channel. An input value of 0xF(all bytes in the array are 0xF) in the
565 Target array retrieves the Target ID of the first SCSI device present on a
566 SCSI channel.
567
568 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI
569 channel was returned in Target.
570 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.
571 @retval EFI_TIMEOUT Target array is not all 0xF, and Target was not
572 returned on a previous call to GetNextTarget().
573 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.
574
575 **/
576 EFI_STATUS
577 EFIAPI
578 UfsPassThruGetNextTarget (
579 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,
580 IN OUT UINT8 **Target
581 );
582
583 /**
584 Sends a UFS-supported SCSI Request Packet to a UFS device that is attached to the UFS host controller.
585
586 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.
587 @param[in] Lun The LUN of the UFS device to send the SCSI Request Packet.
588 @param[in, out] Packet A pointer to the SCSI Request Packet to send to a specified Lun of the
589 UFS device.
590
591 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional
592 commands, InTransferLength bytes were transferred from
593 InDataBuffer. For write and bi-directional commands,
594 OutTransferLength bytes were transferred by
595 OutDataBuffer.
596 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request
597 Packet.
598 @retval EFI_OUT_OF_RESOURCES The resource for transfer is not available.
599 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.
600
601 **/
602 EFI_STATUS
603 UfsExecScsiCmds (
604 IN UFS_PASS_THRU_PRIVATE_DATA *Private,
605 IN UINT8 Lun,
606 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet
607 );
608
609 /**
610 Initialize the UFS host controller.
611
612 @param[in] Private The pointer to the NVME_CONTROLLER_PRIVATE_DATA data structure.
613
614 @retval EFI_SUCCESS The NVM Express Controller is initialized successfully.
615 @retval Others A device error occurred while initializing the controller.
616
617 **/
618 EFI_STATUS
619 UfsControllerInit (
620 IN UFS_PASS_THRU_PRIVATE_DATA *Private
621 );
622
623 /**
624 Stop the UFS host controller.
625
626 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.
627
628 @retval EFI_SUCCESS The Ufs Host Controller is stopped successfully.
629 @retval Others A device error occurred while stopping the controller.
630
631 **/
632 EFI_STATUS
633 UfsControllerStop (
634 IN UFS_PASS_THRU_PRIVATE_DATA *Private
635 );
636
637 /**
638 Allocate common buffer for host and UFS bus master access simultaneously.
639
640 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.
641 @param[in] Size The length of buffer to be allocated.
642 @param[out] CmdDescHost A pointer to store the base system memory address of the allocated range.
643 @param[out] CmdDescPhyAddr The resulting map address for the UFS bus master to use to access the hosts CmdDescHost.
644 @param[out] CmdDescMapping A resulting value to pass to Unmap().
645
646 @retval EFI_SUCCESS The common buffer was allocated successfully.
647 @retval EFI_DEVICE_ERROR The allocation fails.
648 @retval EFI_OUT_OF_RESOURCES The memory resource is insufficient.
649
650 **/
651 EFI_STATUS
652 UfsAllocateAlignCommonBuffer (
653 IN UFS_PASS_THRU_PRIVATE_DATA *Private,
654 IN UINTN Size,
655 OUT VOID **CmdDescHost,
656 OUT EFI_PHYSICAL_ADDRESS *CmdDescPhyAddr,
657 OUT VOID **CmdDescMapping
658 );
659
660 /**
661 Set specified flag to 1 on a UFS device.
662
663 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.
664 @param[in] FlagId The ID of flag to be set.
665
666 @retval EFI_SUCCESS The flag was set successfully.
667 @retval EFI_DEVICE_ERROR A device error occurred while attempting to set the flag.
668 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of setting the flag.
669
670 **/
671 EFI_STATUS
672 UfsSetFlag (
673 IN UFS_PASS_THRU_PRIVATE_DATA *Private,
674 IN UINT8 FlagId
675 );
676
677 /**
678 Read or write specified device descriptor of a UFS device.
679
680 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.
681 @param[in] Read The boolean variable to show r/w direction.
682 @param[in] DescId The ID of device descriptor.
683 @param[in] Index The Index of device descriptor.
684 @param[in] Selector The Selector of device descriptor.
685 @param[in, out] Descriptor The buffer of device descriptor to be read or written.
686 @param[in] DescSize The size of device descriptor buffer.
687
688 @retval EFI_SUCCESS The device descriptor was read/written successfully.
689 @retval EFI_DEVICE_ERROR A device error occurred while attempting to r/w the device descriptor.
690 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of r/w the device descriptor.
691
692 **/
693 EFI_STATUS
694 UfsRwDeviceDesc (
695 IN UFS_PASS_THRU_PRIVATE_DATA *Private,
696 IN BOOLEAN Read,
697 IN UINT8 DescId,
698 IN UINT8 Index,
699 IN UINT8 Selector,
700 IN OUT VOID *Descriptor,
701 IN UINT32 DescSize
702 );
703
704 /**
705 Sends NOP IN cmd to a UFS device for initialization process request.
706 For more details, please refer to UFS 2.0 spec Figure 13.3.
707
708 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.
709
710 @retval EFI_SUCCESS The NOP IN command was sent by the host. The NOP OUT response was
711 received successfully.
712 @retval EFI_DEVICE_ERROR A device error occurred while attempting to execute NOP IN command.
713 @retval EFI_OUT_OF_RESOURCES The resource for transfer is not available.
714 @retval EFI_TIMEOUT A timeout occurred while waiting for the NOP IN command to execute.
715
716 **/
717 EFI_STATUS
718 UfsExecNopCmds (
719 IN UFS_PASS_THRU_PRIVATE_DATA *Private
720 );
721
722 extern EFI_COMPONENT_NAME_PROTOCOL gUfsPassThruComponentName;
723 extern EFI_COMPONENT_NAME2_PROTOCOL gUfsPassThruComponentName2;
724 extern EFI_DRIVER_BINDING_PROTOCOL gUfsPassThruDriverBinding;
725
726 #endif