]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.h
MdeModulePkg/UfsPassThruDxe: Refactor private data to use UfsHcInfo
[mirror_edk2.git] / MdeModulePkg / Bus / Ufs / UfsPassThruDxe / UfsPassThru.h
CommitLineData
0591696e
FT
1/** @file\r
2\r
90952ad7 3 Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>\r
9d510e61 4 SPDX-License-Identifier: BSD-2-Clause-Patent\r
0591696e
FT
5\r
6**/\r
7\r
8#ifndef _UFS_PASS_THRU_H_\r
9#define _UFS_PASS_THRU_H_\r
10\r
11#include <Uefi.h>\r
12\r
13#include <Protocol/ScsiPassThruExt.h>\r
32c9049d 14#include <Protocol/UfsDeviceConfig.h>\r
0591696e 15#include <Protocol/UfsHostController.h>\r
90952ad7 16#include <Protocol/UfsHostControllerPlatform.h>\r
0591696e
FT
17\r
18#include <Library/DebugLib.h>\r
19#include <Library/UefiDriverEntryPoint.h>\r
20#include <Library/BaseLib.h>\r
21#include <Library/UefiLib.h>\r
22#include <Library/BaseMemoryLib.h>\r
23#include <Library/MemoryAllocationLib.h>\r
24#include <Library/UefiBootServicesTableLib.h>\r
25#include <Library/DevicePathLib.h>\r
0591696e
FT
26#include <Library/TimerLib.h>\r
27\r
28#include "UfsPassThruHci.h"\r
29\r
30#define UFS_PASS_THRU_SIG SIGNATURE_32 ('U', 'F', 'S', 'P')\r
31\r
32//\r
d1102dba 33// Lun 0~7 is for 8 common luns.\r
0591696e
FT
34// Lun 8~11 is for those 4 well known luns (Refer to UFS 2.0 spec Table 10.58 for details):\r
35// Lun 8: REPORT LUNS\r
36// Lun 9: UFS DEVICE\r
37// Lun 10: BOOT\r
38// Lun 11: RPMB\r
39//\r
40#define UFS_MAX_LUNS 12\r
41#define UFS_WLUN_PREFIX 0xC1\r
42\r
43typedef struct {\r
44 UINT8 Lun[UFS_MAX_LUNS];\r
45 UINT16 BitMask:12; // Bit 0~7 is 1/1 mapping to common luns. Bit 8~11 is 1/1 mapping to well-known luns.\r
46 UINT16 Rsvd:4;\r
47} UFS_EXPOSED_LUNS;\r
48\r
0350b57c 49//\r
ed356b9e 50// Iterate through the double linked list. This is delete-safe.\r
0350b57c
HW
51// Do not touch NextEntry\r
52//\r
53#define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \\r
54 for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\\r
55 Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)\r
56\r
d1102dba 57typedef struct _UFS_PASS_THRU_PRIVATE_DATA {\r
0591696e
FT
58 UINT32 Signature;\r
59 EFI_HANDLE Handle;\r
60 EFI_EXT_SCSI_PASS_THRU_MODE ExtScsiPassThruMode;\r
61 EFI_EXT_SCSI_PASS_THRU_PROTOCOL ExtScsiPassThru;\r
32c9049d 62 EFI_UFS_DEVICE_CONFIG_PROTOCOL UfsDevConfig;\r
0591696e
FT
63 EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHostController;\r
64 UINTN UfsHcBase;\r
a71272ed 65 EDKII_UFS_HC_INFO UfsHcInfo;\r
0591696e
FT
66\r
67 UINT8 TaskTag;\r
68\r
69 VOID *UtpTrlBase;\r
70 UINT8 Nutrs;\r
71 VOID *TrlMapping;\r
72 VOID *UtpTmrlBase;\r
73 UINT8 Nutmrs;\r
74 VOID *TmrlMapping;\r
75\r
76 UFS_EXPOSED_LUNS Luns;\r
0350b57c
HW
77\r
78 //\r
79 // For Non-blocking operation.\r
80 //\r
81 EFI_EVENT TimerEvent;\r
82 LIST_ENTRY Queue;\r
0591696e
FT
83} UFS_PASS_THRU_PRIVATE_DATA;\r
84\r
0350b57c
HW
85#define UFS_PASS_THRU_TRANS_REQ_SIG SIGNATURE_32 ('U', 'F', 'S', 'T')\r
86\r
87typedef struct {\r
88 UINT32 Signature;\r
89 LIST_ENTRY TransferList;\r
90\r
91 UINT8 Slot;\r
92 UTP_TRD *Trd;\r
93 UINT32 CmdDescSize;\r
94 VOID *CmdDescHost;\r
95 VOID *CmdDescMapping;\r
a37e18f6
AM
96 VOID *AlignedDataBuf;\r
97 UINTN AlignedDataBufSize;\r
0350b57c
HW
98 VOID *DataBufMapping;\r
99\r
100 EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet;\r
101 UINT64 TimeoutRemain;\r
102 EFI_EVENT CallerEvent;\r
103} UFS_PASS_THRU_TRANS_REQ;\r
104\r
105#define UFS_PASS_THRU_TRANS_REQ_FROM_THIS(a) \\r
106 CR(a, UFS_PASS_THRU_TRANS_REQ, TransferList, UFS_PASS_THRU_TRANS_REQ_SIG)\r
107\r
0591696e 108#define UFS_TIMEOUT EFI_TIMER_PERIOD_SECONDS(3)\r
0350b57c 109#define UFS_HC_ASYNC_TIMER EFI_TIMER_PERIOD_MILLISECONDS(1)\r
0591696e
FT
110\r
111#define ROUNDUP8(x) (((x) % 8 == 0) ? (x) : ((x) / 8 + 1) * 8)\r
112\r
113#define IS_ALIGNED(addr, size) (((UINTN) (addr) & (size - 1)) == 0)\r
114\r
115#define UFS_PASS_THRU_PRIVATE_DATA_FROM_THIS(a) \\r
116 CR (a, \\r
117 UFS_PASS_THRU_PRIVATE_DATA, \\r
118 ExtScsiPassThru, \\r
119 UFS_PASS_THRU_SIG \\r
120 )\r
121\r
32c9049d
HW
122#define UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG(a) \\r
123 CR (a, \\r
124 UFS_PASS_THRU_PRIVATE_DATA, \\r
125 UfsDevConfig, \\r
126 UFS_PASS_THRU_SIG \\r
127 )\r
128\r
0591696e
FT
129typedef struct _UFS_DEVICE_MANAGEMENT_REQUEST_PACKET {\r
130 UINT64 Timeout;\r
95ad8f7f 131 VOID *DataBuffer;\r
0591696e
FT
132 UINT8 Opcode;\r
133 UINT8 DescId;\r
134 UINT8 Index;\r
135 UINT8 Selector;\r
95ad8f7f 136 UINT32 TransferLength;\r
0591696e 137 UINT8 DataDirection;\r
0591696e
FT
138} UFS_DEVICE_MANAGEMENT_REQUEST_PACKET;\r
139\r
140//\r
141// function prototype\r
142//\r
143/**\r
144 Tests to see if this driver supports a given controller. If a child device is provided,\r
145 it further tests to see if this driver supports creating a handle for the specified child device.\r
146\r
147 This function checks to see if the driver specified by This supports the device specified by\r
148 ControllerHandle. Drivers will typically use the device path attached to\r
149 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
150 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
151 may be called many times during platform initialization. In order to reduce boot times, the tests\r
152 performed by this function must be very small, and take as little time as possible to execute. This\r
153 function must not change the state of any hardware devices, and this function must be aware that the\r
154 device specified by ControllerHandle may already be managed by the same driver or a\r
155 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
156 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
157 Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
158 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
159 to guarantee the state of ControllerHandle is not modified by this function.\r
160\r
161 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
162 @param[in] ControllerHandle The handle of the controller to test. This handle\r
163 must support a protocol interface that supplies\r
164 an I/O abstraction to the driver.\r
165 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
166 parameter is ignored by device drivers, and is optional for bus\r
167 drivers. For bus drivers, if this parameter is not NULL, then\r
168 the bus driver must determine if the bus controller specified\r
169 by ControllerHandle and the child controller specified\r
170 by RemainingDevicePath are both supported by this\r
171 bus driver.\r
172\r
173 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
174 RemainingDevicePath is supported by the driver specified by This.\r
175 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
176 RemainingDevicePath is already being managed by the driver\r
177 specified by This.\r
178 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
179 RemainingDevicePath is already being managed by a different\r
180 driver or an application that requires exclusive access.\r
181 Currently not implemented.\r
182 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
183 RemainingDevicePath is not supported by the driver specified by This.\r
184**/\r
185EFI_STATUS\r
186EFIAPI\r
187UfsPassThruDriverBindingSupported (\r
188 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
189 IN EFI_HANDLE Controller,\r
190 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
191 );\r
192\r
193/**\r
194 Starts a device controller or a bus controller.\r
195\r
196 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
197 As a result, much of the error checking on the parameters to Start() has been moved into this\r
198 common boot service. It is legal to call Start() from other locations,\r
199 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
200 1. ControllerHandle must be a valid EFI_HANDLE.\r
201 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
202 EFI_DEVICE_PATH_PROTOCOL.\r
203 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
204 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
205\r
206 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
207 @param[in] ControllerHandle The handle of the controller to start. This handle\r
208 must support a protocol interface that supplies\r
209 an I/O abstraction to the driver.\r
210 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
211 parameter is ignored by device drivers, and is optional for bus\r
212 drivers. For a bus driver, if this parameter is NULL, then handles\r
213 for all the children of Controller are created by this driver.\r
214 If this parameter is not NULL and the first Device Path Node is\r
215 not the End of Device Path Node, then only the handle for the\r
216 child device specified by the first Device Path Node of\r
217 RemainingDevicePath is created by this driver.\r
218 If the first Device Path Node of RemainingDevicePath is\r
219 the End of Device Path Node, no child handle is created by this\r
220 driver.\r
221\r
222 @retval EFI_SUCCESS The device was started.\r
223 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
224 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
225 @retval Others The driver failded to start the device.\r
226\r
227**/\r
228EFI_STATUS\r
229EFIAPI\r
230UfsPassThruDriverBindingStart (\r
231 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
232 IN EFI_HANDLE Controller,\r
233 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
234 );\r
235\r
236/**\r
237 Stops a device controller or a bus controller.\r
238\r
239 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
240 As a result, much of the error checking on the parameters to Stop() has been moved\r
241 into this common boot service. It is legal to call Stop() from other locations,\r
242 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
243 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
244 same driver's Start() function.\r
245 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
246 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
247 Start() function, and the Start() function must have called OpenProtocol() on\r
248 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
249\r
250 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
251 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
252 support a bus specific I/O protocol for the driver\r
253 to use to stop the device.\r
254 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
255 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
256 if NumberOfChildren is 0.\r
257\r
258 @retval EFI_SUCCESS The device was stopped.\r
259 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
260\r
261**/\r
262EFI_STATUS\r
263EFIAPI\r
264UfsPassThruDriverBindingStop (\r
265 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
266 IN EFI_HANDLE Controller,\r
267 IN UINTN NumberOfChildren,\r
268 IN EFI_HANDLE *ChildHandleBuffer\r
269 );\r
270\r
271//\r
272// EFI Component Name Functions\r
273//\r
274/**\r
275 Retrieves a Unicode string that is the user readable name of the driver.\r
276\r
277 This function retrieves the user readable name of a driver in the form of a\r
278 Unicode string. If the driver specified by This has a user readable name in\r
279 the language specified by Language, then a pointer to the driver name is\r
280 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified\r
281 by This does not support the language specified by Language,\r
282 then EFI_UNSUPPORTED is returned.\r
283\r
284 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
285 EFI_COMPONENT_NAME_PROTOCOL instance.\r
286\r
287 @param Language[in] A pointer to a Null-terminated ASCII string\r
288 array indicating the language. This is the\r
289 language of the driver name that the caller is\r
290 requesting, and it must match one of the\r
291 languages specified in SupportedLanguages. The\r
292 number of languages supported by a driver is up\r
293 to the driver writer. Language is specified\r
294 in RFC 4646 or ISO 639-2 language code format.\r
295\r
296 @param DriverName[out] A pointer to the Unicode string to return.\r
297 This Unicode string is the name of the\r
298 driver specified by This in the language\r
299 specified by Language.\r
300\r
301 @retval EFI_SUCCESS The Unicode string for the Driver specified by\r
302 This and the language specified by Language was\r
303 returned in DriverName.\r
304\r
305 @retval EFI_INVALID_PARAMETER Language is NULL.\r
306\r
307 @retval EFI_INVALID_PARAMETER DriverName is NULL.\r
308\r
309 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
310 the language specified by Language.\r
311\r
312**/\r
313EFI_STATUS\r
314EFIAPI\r
315UfsPassThruComponentNameGetDriverName (\r
316 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
317 IN CHAR8 *Language,\r
318 OUT CHAR16 **DriverName\r
319 );\r
320\r
321\r
322/**\r
323 Retrieves a Unicode string that is the user readable name of the controller\r
324 that is being managed by a driver.\r
325\r
326 This function retrieves the user readable name of the controller specified by\r
327 ControllerHandle and ChildHandle in the form of a Unicode string. If the\r
328 driver specified by This has a user readable name in the language specified by\r
329 Language, then a pointer to the controller name is returned in ControllerName,\r
330 and EFI_SUCCESS is returned. If the driver specified by This is not currently\r
331 managing the controller specified by ControllerHandle and ChildHandle,\r
332 then EFI_UNSUPPORTED is returned. If the driver specified by This does not\r
333 support the language specified by Language, then EFI_UNSUPPORTED is returned.\r
334\r
335 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or\r
336 EFI_COMPONENT_NAME_PROTOCOL instance.\r
337\r
338 @param ControllerHandle[in] The handle of a controller that the driver\r
339 specified by This is managing. This handle\r
340 specifies the controller whose name is to be\r
341 returned.\r
342\r
343 @param ChildHandle[in] The handle of the child controller to retrieve\r
344 the name of. This is an optional parameter that\r
345 may be NULL. It will be NULL for device\r
346 drivers. It will also be NULL for a bus drivers\r
347 that wish to retrieve the name of the bus\r
348 controller. It will not be NULL for a bus\r
349 driver that wishes to retrieve the name of a\r
350 child controller.\r
351\r
352 @param Language[in] A pointer to a Null-terminated ASCII string\r
353 array indicating the language. This is the\r
354 language of the driver name that the caller is\r
355 requesting, and it must match one of the\r
356 languages specified in SupportedLanguages. The\r
357 number of languages supported by a driver is up\r
358 to the driver writer. Language is specified in\r
359 RFC 4646 or ISO 639-2 language code format.\r
360\r
361 @param ControllerName[out] A pointer to the Unicode string to return.\r
362 This Unicode string is the name of the\r
363 controller specified by ControllerHandle and\r
364 ChildHandle in the language specified by\r
365 Language from the point of view of the driver\r
366 specified by This.\r
367\r
368 @retval EFI_SUCCESS The Unicode string for the user readable name in\r
369 the language specified by Language for the\r
370 driver specified by This was returned in\r
371 DriverName.\r
372\r
373 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.\r
374\r
375 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
376 EFI_HANDLE.\r
377\r
378 @retval EFI_INVALID_PARAMETER Language is NULL.\r
379\r
380 @retval EFI_INVALID_PARAMETER ControllerName is NULL.\r
381\r
382 @retval EFI_UNSUPPORTED The driver specified by This is not currently\r
383 managing the controller specified by\r
384 ControllerHandle and ChildHandle.\r
385\r
386 @retval EFI_UNSUPPORTED The driver specified by This does not support\r
387 the language specified by Language.\r
388\r
389**/\r
390EFI_STATUS\r
391EFIAPI\r
392UfsPassThruComponentNameGetControllerName (\r
393 IN EFI_COMPONENT_NAME_PROTOCOL *This,\r
394 IN EFI_HANDLE ControllerHandle,\r
395 IN EFI_HANDLE ChildHandle OPTIONAL,\r
396 IN CHAR8 *Language,\r
397 OUT CHAR16 **ControllerName\r
398 );\r
399\r
400/**\r
401 Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function\r
402 supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the\r
403 nonblocking I/O functionality is optional.\r
404\r
405 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
406 @param Target The Target is an array of size TARGET_MAX_BYTES and it represents\r
407 the id of the SCSI device to send the SCSI Request Packet. Each\r
408 transport driver may choose to utilize a subset of this size to suit the needs\r
409 of transport target representation. For example, a Fibre Channel driver\r
410 may use only 8 bytes (WWN) to represent an FC target.\r
411 @param Lun The LUN of the SCSI device to send the SCSI Request Packet.\r
412 @param Packet A pointer to the SCSI Request Packet to send to the SCSI device\r
413 specified by Target and Lun.\r
414 @param Event If nonblocking I/O is not supported then Event is ignored, and blocking\r
415 I/O is performed. If Event is NULL, then blocking I/O is performed. If\r
416 Event is not NULL and non blocking I/O is supported, then\r
417 nonblocking I/O is performed, and Event will be signaled when the\r
418 SCSI Request Packet completes.\r
419\r
420 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional\r
421 commands, InTransferLength bytes were transferred from\r
422 InDataBuffer. For write and bi-directional commands,\r
423 OutTransferLength bytes were transferred by\r
424 OutDataBuffer.\r
425 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was not executed. The number of bytes that\r
426 could be transferred is returned in InTransferLength. For write\r
427 and bi-directional commands, OutTransferLength bytes were\r
428 transferred by OutDataBuffer.\r
429 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many\r
430 SCSI Request Packets already queued. The caller may retry again later.\r
431 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request\r
432 Packet.\r
433 @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid.\r
434 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported\r
435 by the host adapter. This includes the case of Bi-directional SCSI\r
436 commands not supported by the implementation. The SCSI Request\r
437 Packet was not sent, so no additional status information is available.\r
438 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.\r
439\r
440**/\r
441EFI_STATUS\r
442EFIAPI\r
443UfsPassThruPassThru (\r
444 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
445 IN UINT8 *Target,\r
446 IN UINT64 Lun,\r
447 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,\r
448 IN EFI_EVENT Event OPTIONAL\r
449 );\r
450\r
451/**\r
452 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These\r
453 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal\r
454 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the\r
455 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI\r
456 channel.\r
457\r
458 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
459 @param Target On input, a pointer to the Target ID (an array of size\r
460 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
461 On output, a pointer to the Target ID (an array of\r
462 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
463 channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
464 Target array retrieves the Target ID of the first SCSI device present on a\r
465 SCSI channel.\r
466 @param Lun On input, a pointer to the LUN of a SCSI device present on the SCSI\r
467 channel. On output, a pointer to the LUN of the next SCSI device present\r
468 on a SCSI channel.\r
469\r
470 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI\r
471 channel was returned in Target and Lun.\r
472 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were\r
473 not returned on a previous call to GetNextTargetLun().\r
474 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
475\r
476**/\r
477EFI_STATUS\r
478EFIAPI\r
479UfsPassThruGetNextTargetLun (\r
480 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
481 IN OUT UINT8 **Target,\r
482 IN OUT UINT64 *Lun\r
483 );\r
484\r
485/**\r
486 Used to allocate and build a device path node for a SCSI device on a SCSI channel.\r
487\r
488 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
489 @param Target The Target is an array of size TARGET_MAX_BYTES and it specifies the\r
490 Target ID of the SCSI device for which a device path node is to be\r
491 allocated and built. Transport drivers may chose to utilize a subset of\r
492 this size to suit the representation of targets. For example, a Fibre\r
493 Channel driver may use only 8 bytes (WWN) in the array to represent a\r
494 FC target.\r
495 @param Lun The LUN of the SCSI device for which a device path node is to be\r
496 allocated and built.\r
497 @param DevicePath A pointer to a single device path node that describes the SCSI device\r
498 specified by Target and Lun. This function is responsible for\r
499 allocating the buffer DevicePath with the boot service\r
500 AllocatePool(). It is the caller's responsibility to free\r
501 DevicePath when the caller is finished with DevicePath.\r
502\r
503 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by\r
504 Target and Lun was allocated and returned in\r
505 DevicePath.\r
506 @retval EFI_INVALID_PARAMETER DevicePath is NULL.\r
507 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist\r
508 on the SCSI channel.\r
509 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.\r
510\r
511**/\r
512EFI_STATUS\r
513EFIAPI\r
514UfsPassThruBuildDevicePath (\r
515 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
516 IN UINT8 *Target,\r
517 IN UINT64 Lun,\r
518 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath\r
519 );\r
520\r
521/**\r
522 Used to translate a device path node to a Target ID and LUN.\r
523\r
524 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
525 @param DevicePath A pointer to a single device path node that describes the SCSI device\r
526 on the SCSI channel.\r
527 @param Target A pointer to the Target Array which represents the ID of a SCSI device\r
528 on the SCSI channel.\r
529 @param Lun A pointer to the LUN of a SCSI device on the SCSI channel.\r
530\r
531 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and\r
532 LUN, and they were returned in Target and Lun.\r
533 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.\r
534 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN\r
535 does not exist.\r
536 @retval EFI_UNSUPPORTED This driver does not support the device path node type in\r
537 DevicePath.\r
538\r
539**/\r
540EFI_STATUS\r
541EFIAPI\r
542UfsPassThruGetTargetLun (\r
543 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
544 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
545 OUT UINT8 **Target,\r
546 OUT UINT64 *Lun\r
547 );\r
548\r
549/**\r
550 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.\r
551\r
552 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
553\r
554 @retval EFI_SUCCESS The SCSI channel was reset.\r
555 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.\r
556 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.\r
557 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.\r
558\r
559**/\r
560EFI_STATUS\r
561EFIAPI\r
562UfsPassThruResetChannel (\r
563 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This\r
564 );\r
565\r
566/**\r
567 Resets a SCSI logical unit that is connected to a SCSI channel.\r
568\r
569 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
570 @param Target The Target is an array of size TARGET_MAX_BYTE and it represents the\r
571 target port ID of the SCSI device containing the SCSI logical unit to\r
572 reset. Transport drivers may chose to utilize a subset of this array to suit\r
573 the representation of their targets.\r
574 @param Lun The LUN of the SCSI device to reset.\r
575\r
576 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.\r
577 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
578 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device\r
579 specified by Target and Lun.\r
580 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.\r
581 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device\r
582 specified by Target and Lun.\r
583\r
584**/\r
585EFI_STATUS\r
586EFIAPI\r
587UfsPassThruResetTargetLun (\r
588 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
589 IN UINT8 *Target,\r
590 IN UINT64 Lun\r
591 );\r
592\r
593/**\r
594 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either\r
595 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs\r
596 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to\r
597 see if a SCSI device is actually present at that location on the SCSI channel.\r
598\r
599 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
600 @param Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
601 On output, a pointer to the Target ID (an array of\r
602 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
603 channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
604 Target array retrieves the Target ID of the first SCSI device present on a\r
605 SCSI channel.\r
606\r
607 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI\r
608 channel was returned in Target.\r
609 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
610 @retval EFI_TIMEOUT Target array is not all 0xF, and Target was not\r
611 returned on a previous call to GetNextTarget().\r
612 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
613\r
614**/\r
615EFI_STATUS\r
616EFIAPI\r
617UfsPassThruGetNextTarget (\r
618 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
619 IN OUT UINT8 **Target\r
620 );\r
621\r
622/**\r
623 Sends a UFS-supported SCSI Request Packet to a UFS device that is attached to the UFS host controller.\r
624\r
625 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
626 @param[in] Lun The LUN of the UFS device to send the SCSI Request Packet.\r
627 @param[in, out] Packet A pointer to the SCSI Request Packet to send to a specified Lun of the\r
628 UFS device.\r
0350b57c
HW
629 @param[in] Event If nonblocking I/O is not supported then Event is ignored, and blocking\r
630 I/O is performed. If Event is NULL, then blocking I/O is performed. If\r
631 Event is not NULL and non blocking I/O is supported, then\r
632 nonblocking I/O is performed, and Event will be signaled when the\r
633 SCSI Request Packet completes.\r
0591696e
FT
634\r
635 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional\r
636 commands, InTransferLength bytes were transferred from\r
637 InDataBuffer. For write and bi-directional commands,\r
638 OutTransferLength bytes were transferred by\r
639 OutDataBuffer.\r
640 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request\r
641 Packet.\r
642 @retval EFI_OUT_OF_RESOURCES The resource for transfer is not available.\r
643 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.\r
644\r
645**/\r
646EFI_STATUS\r
647UfsExecScsiCmds (\r
648 IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
649 IN UINT8 Lun,\r
0350b57c
HW
650 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,\r
651 IN EFI_EVENT Event OPTIONAL\r
0591696e
FT
652 );\r
653\r
654/**\r
655 Initialize the UFS host controller.\r
656\r
657 @param[in] Private The pointer to the NVME_CONTROLLER_PRIVATE_DATA data structure.\r
658\r
659 @retval EFI_SUCCESS The NVM Express Controller is initialized successfully.\r
660 @retval Others A device error occurred while initializing the controller.\r
661\r
662**/\r
663EFI_STATUS\r
664UfsControllerInit (\r
665 IN UFS_PASS_THRU_PRIVATE_DATA *Private\r
666 );\r
667\r
668/**\r
669 Stop the UFS host controller.\r
670\r
671 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
672\r
673 @retval EFI_SUCCESS The Ufs Host Controller is stopped successfully.\r
674 @retval Others A device error occurred while stopping the controller.\r
675\r
676**/\r
677EFI_STATUS\r
678UfsControllerStop (\r
679 IN UFS_PASS_THRU_PRIVATE_DATA *Private\r
680 );\r
681\r
682/**\r
683 Allocate common buffer for host and UFS bus master access simultaneously.\r
684\r
685 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
686 @param[in] Size The length of buffer to be allocated.\r
687 @param[out] CmdDescHost A pointer to store the base system memory address of the allocated range.\r
688 @param[out] CmdDescPhyAddr The resulting map address for the UFS bus master to use to access the hosts CmdDescHost.\r
689 @param[out] CmdDescMapping A resulting value to pass to Unmap().\r
690\r
691 @retval EFI_SUCCESS The common buffer was allocated successfully.\r
692 @retval EFI_DEVICE_ERROR The allocation fails.\r
693 @retval EFI_OUT_OF_RESOURCES The memory resource is insufficient.\r
694\r
695**/\r
696EFI_STATUS\r
697UfsAllocateAlignCommonBuffer (\r
698 IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
699 IN UINTN Size,\r
700 OUT VOID **CmdDescHost,\r
701 OUT EFI_PHYSICAL_ADDRESS *CmdDescPhyAddr,\r
702 OUT VOID **CmdDescMapping\r
703 );\r
704\r
705/**\r
706 Set specified flag to 1 on a UFS device.\r
707\r
708 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
709 @param[in] FlagId The ID of flag to be set.\r
710\r
711 @retval EFI_SUCCESS The flag was set successfully.\r
712 @retval EFI_DEVICE_ERROR A device error occurred while attempting to set the flag.\r
713 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of setting the flag.\r
714\r
715**/\r
716EFI_STATUS\r
717UfsSetFlag (\r
718 IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
719 IN UINT8 FlagId\r
720 );\r
721\r
95ad8f7f
HW
722/**\r
723 Read specified flag from a UFS device.\r
724\r
725 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
726 @param[in] FlagId The ID of flag to be read.\r
727 @param[out] Value The flag's value.\r
728\r
729 @retval EFI_SUCCESS The flag was read successfully.\r
730 @retval EFI_DEVICE_ERROR A device error occurred while attempting to read the flag.\r
731 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of reading the flag.\r
732\r
733**/\r
734EFI_STATUS\r
735UfsReadFlag (\r
736 IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
737 IN UINT8 FlagId,\r
738 OUT UINT8 *Value\r
739 );\r
740\r
32c9049d
HW
741/**\r
742 Read or write specified flag of a UFS device.\r
743\r
744 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
745 @param[in] Read The boolean variable to show r/w direction.\r
746 @param[in] FlagId The ID of flag to be read or written.\r
747 @param[in, out] Value The value to set or clear flag.\r
748\r
749 @retval EFI_SUCCESS The flag was read/written successfully.\r
750 @retval EFI_DEVICE_ERROR A device error occurred while attempting to r/w the flag.\r
751 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of r/w the flag.\r
752\r
753**/\r
754EFI_STATUS\r
755UfsRwFlags (\r
756 IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
757 IN BOOLEAN Read,\r
758 IN UINT8 FlagId,\r
759 IN OUT UINT8 *Value\r
760 );\r
761\r
0591696e
FT
762/**\r
763 Read or write specified device descriptor of a UFS device.\r
764\r
765 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
766 @param[in] Read The boolean variable to show r/w direction.\r
767 @param[in] DescId The ID of device descriptor.\r
768 @param[in] Index The Index of device descriptor.\r
769 @param[in] Selector The Selector of device descriptor.\r
770 @param[in, out] Descriptor The buffer of device descriptor to be read or written.\r
32c9049d
HW
771 @param[in, out] DescSize The size of device descriptor buffer. On input, the size, in bytes,\r
772 of the data buffer specified by Descriptor. On output, the number\r
773 of bytes that were actually transferred.\r
0591696e
FT
774\r
775 @retval EFI_SUCCESS The device descriptor was read/written successfully.\r
776 @retval EFI_DEVICE_ERROR A device error occurred while attempting to r/w the device descriptor.\r
777 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of r/w the device descriptor.\r
778\r
779**/\r
780EFI_STATUS\r
781UfsRwDeviceDesc (\r
782 IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
783 IN BOOLEAN Read,\r
784 IN UINT8 DescId,\r
785 IN UINT8 Index,\r
786 IN UINT8 Selector,\r
787 IN OUT VOID *Descriptor,\r
32c9049d 788 IN OUT UINT32 *DescSize\r
0591696e
FT
789 );\r
790\r
95ad8f7f
HW
791/**\r
792 Read or write specified attribute of a UFS device.\r
793\r
794 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
795 @param[in] Read The boolean variable to show r/w direction.\r
796 @param[in] AttrId The ID of Attribute.\r
797 @param[in] Index The Index of Attribute.\r
798 @param[in] Selector The Selector of Attribute.\r
799 @param[in, out] Attributes The value of Attribute to be read or written.\r
800\r
801 @retval EFI_SUCCESS The Attribute was read/written successfully.\r
802 @retval EFI_DEVICE_ERROR A device error occurred while attempting to r/w the Attribute.\r
803 @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of r/w the Attribute.\r
804\r
805**/\r
806EFI_STATUS\r
807UfsRwAttributes (\r
808 IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
809 IN BOOLEAN Read,\r
810 IN UINT8 AttrId,\r
811 IN UINT8 Index,\r
812 IN UINT8 Selector,\r
813 IN OUT UINT32 *Attributes\r
814 );\r
815\r
0591696e
FT
816/**\r
817 Sends NOP IN cmd to a UFS device for initialization process request.\r
818 For more details, please refer to UFS 2.0 spec Figure 13.3.\r
819\r
820 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
821\r
822 @retval EFI_SUCCESS The NOP IN command was sent by the host. The NOP OUT response was\r
823 received successfully.\r
824 @retval EFI_DEVICE_ERROR A device error occurred while attempting to execute NOP IN command.\r
825 @retval EFI_OUT_OF_RESOURCES The resource for transfer is not available.\r
826 @retval EFI_TIMEOUT A timeout occurred while waiting for the NOP IN command to execute.\r
827\r
828**/\r
829EFI_STATUS\r
830UfsExecNopCmds (\r
831 IN UFS_PASS_THRU_PRIVATE_DATA *Private\r
832 );\r
833\r
0350b57c
HW
834/**\r
835 Call back function when the timer event is signaled.\r
836\r
837 @param[in] Event The Event this notify function registered to.\r
838 @param[in] Context Pointer to the context data registered to the Event.\r
839\r
840**/\r
841VOID\r
842EFIAPI\r
843ProcessAsyncTaskList (\r
844 IN EFI_EVENT Event,\r
845 IN VOID *Context\r
846 );\r
847\r
848/**\r
849 Internal helper function which will signal the caller event and clean up\r
850 resources.\r
851\r
852 @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data\r
853 structure.\r
854 @param[in] TransReq The pointer to the UFS_PASS_THRU_TRANS_REQ data\r
855 structure.\r
856\r
857**/\r
858VOID\r
859EFIAPI\r
860SignalCallerEvent (\r
861 IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
862 IN UFS_PASS_THRU_TRANS_REQ *TransReq\r
863 );\r
864\r
32c9049d
HW
865/**\r
866 Read or write specified device descriptor of a UFS device.\r
867\r
868 The function is used to read/write UFS device descriptors. The consumer of this API is\r
869 responsible for allocating the data buffer pointed by Descriptor.\r
870\r
871 @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.\r
872 @param[in] Read The boolean variable to show r/w direction.\r
873 @param[in] DescId The ID of device descriptor.\r
874 @param[in] Index The Index of device descriptor.\r
875 @param[in] Selector The Selector of device descriptor.\r
876 @param[in, out] Descriptor The buffer of device descriptor to be read or written.\r
877 @param[in, out] DescSize The size of device descriptor buffer. On input, the size, in bytes,\r
878 of the data buffer specified by Descriptor. On output, the number\r
879 of bytes that were actually transferred.\r
880\r
881 @retval EFI_SUCCESS The device descriptor is read/written successfully.\r
882 @retval EFI_INVALID_PARAMETER This is NULL or Descriptor is NULL or DescSize is NULL.\r
883 DescId, Index and Selector are invalid combination to point to a\r
884 type of UFS device descriptor.\r
885 @retval EFI_DEVICE_ERROR The device descriptor is not read/written successfully.\r
886\r
887**/\r
888EFI_STATUS\r
889EFIAPI\r
890UfsRwUfsDescriptor (\r
891 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,\r
892 IN BOOLEAN Read,\r
893 IN UINT8 DescId,\r
894 IN UINT8 Index,\r
895 IN UINT8 Selector,\r
896 IN OUT UINT8 *Descriptor,\r
897 IN OUT UINT32 *DescSize\r
898 );\r
899\r
900/**\r
901 Read or write specified flag of a UFS device.\r
902\r
903 The function is used to read/write UFS flag descriptors. The consumer of this API is responsible\r
904 for allocating the buffer pointed by Flag. The buffer size is 1 byte as UFS flag descriptor is\r
905 just a single Boolean value that represents a TRUE or FALSE, '0' or '1', ON or OFF type of value.\r
906\r
907 @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.\r
908 @param[in] Read The boolean variable to show r/w direction.\r
909 @param[in] FlagId The ID of flag to be read or written.\r
910 @param[in, out] Flag The buffer to set or clear flag.\r
911\r
912 @retval EFI_SUCCESS The flag descriptor is set/clear successfully.\r
913 @retval EFI_INVALID_PARAMETER This is NULL or Flag is NULL.\r
914 FlagId is an invalid UFS flag ID.\r
915 @retval EFI_DEVICE_ERROR The flag is not set/clear successfully.\r
916\r
917**/\r
918EFI_STATUS\r
919EFIAPI\r
920UfsRwUfsFlag (\r
921 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,\r
922 IN BOOLEAN Read,\r
923 IN UINT8 FlagId,\r
924 IN OUT UINT8 *Flag\r
925 );\r
926\r
927/**\r
928 Read or write specified attribute of a UFS device.\r
929\r
930 The function is used to read/write UFS attributes. The consumer of this API is responsible for\r
931 allocating the data buffer pointed by Attribute.\r
932\r
933 @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.\r
934 @param[in] Read The boolean variable to show r/w direction.\r
935 @param[in] AttrId The ID of Attribute.\r
936 @param[in] Index The Index of Attribute.\r
937 @param[in] Selector The Selector of Attribute.\r
938 @param[in, out] Attribute The buffer of Attribute to be read or written.\r
939 @param[in, out] AttrSize The size of Attribute buffer. On input, the size, in bytes, of the\r
940 data buffer specified by Attribute. On output, the number of bytes\r
941 that were actually transferred.\r
942\r
943 @retval EFI_SUCCESS The attribute is read/written successfully.\r
944 @retval EFI_INVALID_PARAMETER This is NULL or Attribute is NULL or AttrSize is NULL.\r
945 AttrId, Index and Selector are invalid combination to point to a\r
946 type of UFS attribute.\r
947 @retval EFI_DEVICE_ERROR The attribute is not read/written successfully.\r
948\r
949**/\r
950EFI_STATUS\r
951EFIAPI\r
952UfsRwUfsAttribute (\r
953 IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,\r
954 IN BOOLEAN Read,\r
955 IN UINT8 AttrId,\r
956 IN UINT8 Index,\r
957 IN UINT8 Selector,\r
958 IN OUT UINT8 *Attribute,\r
959 IN OUT UINT32 *AttrSize\r
960 );\r
961\r
a71272ed
AM
962/**\r
963 Initializes UfsHcInfo field in private data.\r
964\r
965 @param[in] Private Pointer to host controller private data.\r
966\r
967 @retval EFI_SUCCESS UfsHcInfo initialized successfully.\r
968 @retval Others Failed to initalize UfsHcInfo.\r
969**/\r
970EFI_STATUS\r
971GetUfsHcInfo (\r
972 IN UFS_PASS_THRU_PRIVATE_DATA *Private\r
973 );\r
974\r
5966dd8f
FT
975extern EFI_COMPONENT_NAME_PROTOCOL gUfsPassThruComponentName;\r
976extern EFI_COMPONENT_NAME2_PROTOCOL gUfsPassThruComponentName2;\r
977extern EFI_DRIVER_BINDING_PROTOCOL gUfsPassThruDriverBinding;\r
0591696e
FT
978\r
979#endif\r