]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c
MdeModulePkg UfsPassThruDxe: Add Non-blocking I/O Support
[mirror_edk2.git] / MdeModulePkg / Bus / Ufs / UfsPassThruDxe / UfsPassThru.c
CommitLineData
0591696e
FT
1/** @file\r
2\r
0350b57c 3 Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
0591696e
FT
4 This program and the accompanying materials\r
5 are licensed and made available under the terms and conditions of the BSD License\r
6 which accompanies this distribution. The full text of the license may be found at\r
7 http://opensource.org/licenses/bsd-license.php\r
8\r
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12**/\r
13\r
14#include "UfsPassThru.h"\r
15\r
16//\r
17// Template for Ufs Pass Thru private data.\r
18//\r
19UFS_PASS_THRU_PRIVATE_DATA gUfsPassThruTemplate = {\r
20 UFS_PASS_THRU_SIG, // Signature\r
21 NULL, // Handle \r
22 { // ExtScsiPassThruMode\r
23 0xFFFFFFFF,\r
0350b57c 24 EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_PHYSICAL | EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_LOGICAL | EFI_EXT_SCSI_PASS_THRU_ATTRIBUTES_NONBLOCKIO,\r
0591696e
FT
25 sizeof (UINTN)\r
26 },\r
27 { // ExtScsiPassThru\r
28 NULL,\r
29 UfsPassThruPassThru,\r
30 UfsPassThruGetNextTargetLun,\r
31 UfsPassThruBuildDevicePath,\r
32 UfsPassThruGetTargetLun,\r
33 UfsPassThruResetChannel,\r
34 UfsPassThruResetTargetLun,\r
35 UfsPassThruGetNextTarget\r
36 },\r
37 0, // UfsHostController\r
38 0, // UfsHcBase\r
39 0, // Capabilities\r
40 0, // TaskTag\r
41 0, // UtpTrlBase\r
42 0, // Nutrs\r
43 0, // TrlMapping\r
44 0, // UtpTmrlBase\r
45 0, // Nutmrs\r
46 0, // TmrlMapping\r
47 { // Luns\r
48 {\r
49 UFS_LUN_0, // Ufs Common Lun 0\r
50 UFS_LUN_1, // Ufs Common Lun 1\r
51 UFS_LUN_2, // Ufs Common Lun 2\r
52 UFS_LUN_3, // Ufs Common Lun 3\r
53 UFS_LUN_4, // Ufs Common Lun 4\r
54 UFS_LUN_5, // Ufs Common Lun 5\r
55 UFS_LUN_6, // Ufs Common Lun 6\r
56 UFS_LUN_7, // Ufs Common Lun 7\r
57 UFS_WLUN_REPORT_LUNS, // Ufs Reports Luns Well Known Lun\r
58 UFS_WLUN_UFS_DEV, // Ufs Device Well Known Lun\r
59 UFS_WLUN_BOOT, // Ufs Boot Well Known Lun\r
60 UFS_WLUN_RPMB // RPMB Well Known Lun\r
61 },\r
62 0x0000, // By default don't expose any Luns.\r
63 0x0\r
0350b57c
HW
64 },\r
65 NULL, // TimerEvent\r
66 { // Queue\r
67 NULL,\r
68 NULL\r
0591696e
FT
69 }\r
70};\r
71\r
72EFI_DRIVER_BINDING_PROTOCOL gUfsPassThruDriverBinding = {\r
73 UfsPassThruDriverBindingSupported,\r
74 UfsPassThruDriverBindingStart,\r
75 UfsPassThruDriverBindingStop,\r
76 0x10,\r
77 NULL,\r
78 NULL\r
79};\r
80\r
81UFS_DEVICE_PATH mUfsDevicePathTemplate = {\r
82 {\r
83 MESSAGING_DEVICE_PATH,\r
84 MSG_UFS_DP,\r
85 {\r
86 (UINT8) (sizeof (UFS_DEVICE_PATH)),\r
87 (UINT8) ((sizeof (UFS_DEVICE_PATH)) >> 8)\r
88 }\r
89 },\r
90 0,\r
91 0\r
92};\r
93\r
94UINT8 mUfsTargetId[TARGET_MAX_BYTES];\r
95\r
96/**\r
97 Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function\r
98 supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the\r
99 nonblocking I/O functionality is optional.\r
100\r
101 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
102 @param Target The Target is an array of size TARGET_MAX_BYTES and it represents\r
103 the id of the SCSI device to send the SCSI Request Packet. Each\r
104 transport driver may choose to utilize a subset of this size to suit the needs\r
105 of transport target representation. For example, a Fibre Channel driver\r
106 may use only 8 bytes (WWN) to represent an FC target.\r
107 @param Lun The LUN of the SCSI device to send the SCSI Request Packet.\r
108 @param Packet A pointer to the SCSI Request Packet to send to the SCSI device\r
109 specified by Target and Lun.\r
110 @param Event If nonblocking I/O is not supported then Event is ignored, and blocking\r
111 I/O is performed. If Event is NULL, then blocking I/O is performed. If\r
112 Event is not NULL and non blocking I/O is supported, then\r
113 nonblocking I/O is performed, and Event will be signaled when the\r
114 SCSI Request Packet completes.\r
115\r
116 @retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional\r
117 commands, InTransferLength bytes were transferred from\r
118 InDataBuffer. For write and bi-directional commands,\r
119 OutTransferLength bytes were transferred by\r
120 OutDataBuffer.\r
121 @retval EFI_BAD_BUFFER_SIZE The SCSI Request Packet was not executed. The number of bytes that\r
122 could be transferred is returned in InTransferLength. For write\r
123 and bi-directional commands, OutTransferLength bytes were\r
124 transferred by OutDataBuffer.\r
125 @retval EFI_NOT_READY The SCSI Request Packet could not be sent because there are too many\r
126 SCSI Request Packets already queued. The caller may retry again later.\r
127 @retval EFI_DEVICE_ERROR A device error occurred while attempting to send the SCSI Request\r
128 Packet.\r
129 @retval EFI_INVALID_PARAMETER Target, Lun, or the contents of ScsiRequestPacket are invalid.\r
130 @retval EFI_UNSUPPORTED The command described by the SCSI Request Packet is not supported\r
131 by the host adapter. This includes the case of Bi-directional SCSI\r
132 commands not supported by the implementation. The SCSI Request\r
133 Packet was not sent, so no additional status information is available.\r
134 @retval EFI_TIMEOUT A timeout occurred while waiting for the SCSI Request Packet to execute.\r
135\r
136**/\r
137EFI_STATUS\r
138EFIAPI\r
139UfsPassThruPassThru (\r
140 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
141 IN UINT8 *Target,\r
142 IN UINT64 Lun,\r
143 IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,\r
144 IN EFI_EVENT Event OPTIONAL\r
145 )\r
146{\r
147 EFI_STATUS Status;\r
148 UFS_PASS_THRU_PRIVATE_DATA *Private;\r
149 UINT8 UfsLun;\r
150 UINT16 Index;\r
151\r
152 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);\r
153\r
154 if ((Packet == NULL) || (Packet->Cdb == NULL)) {\r
155 return EFI_INVALID_PARAMETER;\r
156 }\r
157\r
158 //\r
159 // Don't support variable length CDB\r
160 //\r
161 if ((Packet->CdbLength != 6) && (Packet->CdbLength != 10) &&\r
162 (Packet->CdbLength != 12) && (Packet->CdbLength != 16)) {\r
163 return EFI_INVALID_PARAMETER;\r
164 }\r
165\r
166 if ((Packet->SenseDataLength != 0) && (Packet->SenseData == NULL)) {\r
167 return EFI_INVALID_PARAMETER;\r
168 }\r
169\r
170 if ((This->Mode->IoAlign > 1) && !IS_ALIGNED(Packet->InDataBuffer, This->Mode->IoAlign)) {\r
171 return EFI_INVALID_PARAMETER;\r
172 }\r
173\r
174 if ((This->Mode->IoAlign > 1) && !IS_ALIGNED(Packet->OutDataBuffer, This->Mode->IoAlign)) {\r
175 return EFI_INVALID_PARAMETER;\r
176 }\r
177\r
178 if ((This->Mode->IoAlign > 1) && !IS_ALIGNED(Packet->SenseData, This->Mode->IoAlign)) {\r
179 return EFI_INVALID_PARAMETER;\r
180 }\r
181\r
182 //\r
183 // For UFS 2.0 compatible device, 0 is always used to represent the location of the UFS device.\r
184 //\r
185 SetMem (mUfsTargetId, TARGET_MAX_BYTES, 0x00);\r
186 if ((Target == NULL) || (CompareMem(Target, mUfsTargetId, TARGET_MAX_BYTES) != 0)) {\r
187 return EFI_INVALID_PARAMETER;\r
188 }\r
189\r
190 //\r
191 // UFS 2.0 spec Section 10.6.7 - Translation of 8-bit UFS LUN to 64-bit SCSI LUN Address\r
192 // 0xC1 in the first 8 bits of the 64-bit address indicates a well known LUN address in the SAM SCSI format.\r
193 // The second 8 bits of the 64-bit address saves the corresponding 8-bit UFS LUN.\r
194 //\r
195 if ((UINT8)Lun == UFS_WLUN_PREFIX) {\r
196 UfsLun = BIT7 | (((UINT8*)&Lun)[1] & 0xFF);\r
197 } else if ((UINT8)Lun == 0) {\r
198 UfsLun = ((UINT8*)&Lun)[1] & 0xFF;\r
199 } else {\r
200 return EFI_INVALID_PARAMETER;\r
201 }\r
202\r
203 for (Index = 0; Index < UFS_MAX_LUNS; Index++) {\r
204 if ((Private->Luns.BitMask & (BIT0 << Index)) == 0) {\r
205 continue;\r
206 }\r
207 \r
208 if (Private->Luns.Lun[Index] == UfsLun) {\r
209 break;\r
210 }\r
211 }\r
212\r
213 if (Index == UFS_MAX_LUNS) {\r
214 return EFI_INVALID_PARAMETER;\r
215 }\r
216\r
0350b57c 217 Status = UfsExecScsiCmds (Private, UfsLun, Packet, Event);\r
0591696e
FT
218\r
219 return Status;\r
220}\r
221\r
222/**\r
223 Used to retrieve the list of legal Target IDs and LUNs for SCSI devices on a SCSI channel. These\r
224 can either be the list SCSI devices that are actually present on the SCSI channel, or the list of legal\r
225 Target Ids and LUNs for the SCSI channel. Regardless, the caller of this function must probe the\r
226 Target ID and LUN returned to see if a SCSI device is actually present at that location on the SCSI\r
227 channel.\r
228\r
229 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
230 @param Target On input, a pointer to the Target ID (an array of size\r
231 TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
232 On output, a pointer to the Target ID (an array of\r
233 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
234 channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
235 Target array retrieves the Target ID of the first SCSI device present on a\r
236 SCSI channel.\r
237 @param Lun On input, a pointer to the LUN of a SCSI device present on the SCSI\r
238 channel. On output, a pointer to the LUN of the next SCSI device present\r
239 on a SCSI channel.\r
240\r
241 @retval EFI_SUCCESS The Target ID and LUN of the next SCSI device on the SCSI\r
242 channel was returned in Target and Lun.\r
243 @retval EFI_INVALID_PARAMETER Target array is not all 0xF, and Target and Lun were\r
244 not returned on a previous call to GetNextTargetLun().\r
245 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
246\r
247**/\r
248EFI_STATUS\r
249EFIAPI\r
250UfsPassThruGetNextTargetLun (\r
251 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
252 IN OUT UINT8 **Target,\r
253 IN OUT UINT64 *Lun\r
254 )\r
255{\r
256 UFS_PASS_THRU_PRIVATE_DATA *Private;\r
257 UINT8 UfsLun;\r
258 UINT16 Index;\r
259 UINT16 Next;\r
260\r
261 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);\r
262\r
263 if (Target == NULL || Lun == NULL) {\r
264 return EFI_INVALID_PARAMETER;\r
265 }\r
266\r
267 if (*Target == NULL) {\r
268 return EFI_INVALID_PARAMETER;\r
269 }\r
270\r
271 UfsLun = 0;\r
272 SetMem (mUfsTargetId, TARGET_MAX_BYTES, 0xFF);\r
273 if (CompareMem (*Target, mUfsTargetId, TARGET_MAX_BYTES) == 0) {\r
274 //\r
275 // If the array is all 0xFF's, return the first exposed Lun to caller.\r
276 //\r
277 SetMem (*Target, TARGET_MAX_BYTES, 0x00);\r
278 for (Index = 0; Index < UFS_MAX_LUNS; Index++) {\r
279 if ((Private->Luns.BitMask & (BIT0 << Index)) != 0) {\r
280 UfsLun = Private->Luns.Lun[Index];\r
281 break;\r
282 }\r
283 }\r
284 if (Index != UFS_MAX_LUNS) {\r
285 *Lun = 0;\r
286 if ((UfsLun & BIT7) == BIT7) {\r
287 ((UINT8*)Lun)[0] = UFS_WLUN_PREFIX;\r
288 ((UINT8*)Lun)[1] = UfsLun & ~BIT7;\r
289 } else {\r
290 ((UINT8*)Lun)[1] = UfsLun;\r
291 }\r
292 return EFI_SUCCESS;\r
293 } else {\r
294 return EFI_NOT_FOUND;\r
295 }\r
296 }\r
297\r
298 SetMem (mUfsTargetId, TARGET_MAX_BYTES, 0x00);\r
299 if (CompareMem (*Target, mUfsTargetId, TARGET_MAX_BYTES) == 0) {\r
300 if (((UINT8*)Lun)[0] == UFS_WLUN_PREFIX) {\r
301 UfsLun = BIT7 | (((UINT8*)Lun)[1] & 0xFF);\r
302 } else if (((UINT8*)Lun)[0] == 0) {\r
303 UfsLun = ((UINT8*)Lun)[1] & 0xFF;\r
304 } else {\r
305 return EFI_NOT_FOUND;\r
306 }\r
307\r
308 for (Index = 0; Index < UFS_MAX_LUNS; Index++) {\r
309 if ((Private->Luns.BitMask & (BIT0 << Index)) == 0) {\r
310 continue;\r
311 }\r
312\r
313 if (Private->Luns.Lun[Index] != UfsLun) {\r
314 continue;\r
315 }\r
316\r
317 for (Next = Index + 1; Next < UFS_MAX_LUNS; Next++) {\r
318 if ((Private->Luns.BitMask & (BIT0 << Next)) != 0) {\r
319 UfsLun = Private->Luns.Lun[Next];\r
320 break;\r
321 }\r
322 }\r
323\r
324 if (Next == UFS_MAX_LUNS) {\r
325 return EFI_NOT_FOUND;\r
326 } else {\r
327 break;\r
328 }\r
329 }\r
330\r
331 if (Index != UFS_MAX_LUNS) {\r
332 *Lun = 0;\r
333 if ((UfsLun & BIT7) == BIT7) {\r
334 ((UINT8*)Lun)[0] = UFS_WLUN_PREFIX;\r
335 ((UINT8*)Lun)[1] = UfsLun & ~BIT7;\r
336 } else {\r
337 ((UINT8*)Lun)[1] = UfsLun;\r
338 }\r
339 return EFI_SUCCESS;\r
340 } else {\r
341 return EFI_NOT_FOUND;\r
342 }\r
343 }\r
344\r
345 return EFI_NOT_FOUND;\r
346}\r
347\r
348/**\r
349 Used to allocate and build a device path node for a SCSI device on a SCSI channel.\r
350\r
351 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
352 @param Target The Target is an array of size TARGET_MAX_BYTES and it specifies the\r
353 Target ID of the SCSI device for which a device path node is to be\r
354 allocated and built. Transport drivers may chose to utilize a subset of\r
355 this size to suit the representation of targets. For example, a Fibre\r
356 Channel driver may use only 8 bytes (WWN) in the array to represent a\r
357 FC target.\r
358 @param Lun The LUN of the SCSI device for which a device path node is to be\r
359 allocated and built.\r
360 @param DevicePath A pointer to a single device path node that describes the SCSI device\r
361 specified by Target and Lun. This function is responsible for\r
362 allocating the buffer DevicePath with the boot service\r
363 AllocatePool(). It is the caller's responsibility to free\r
364 DevicePath when the caller is finished with DevicePath.\r
365\r
366 @retval EFI_SUCCESS The device path node that describes the SCSI device specified by\r
367 Target and Lun was allocated and returned in\r
368 DevicePath.\r
369 @retval EFI_INVALID_PARAMETER DevicePath is NULL.\r
370 @retval EFI_NOT_FOUND The SCSI devices specified by Target and Lun does not exist\r
371 on the SCSI channel.\r
372 @retval EFI_OUT_OF_RESOURCES There are not enough resources to allocate DevicePath.\r
373\r
374**/\r
375EFI_STATUS\r
376EFIAPI\r
377UfsPassThruBuildDevicePath (\r
378 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
379 IN UINT8 *Target,\r
380 IN UINT64 Lun,\r
381 IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath\r
382 )\r
383{\r
384 UFS_PASS_THRU_PRIVATE_DATA *Private;\r
385 EFI_DEV_PATH *DevicePathNode;\r
386 UINT8 UfsLun;\r
387 UINT16 Index;\r
388\r
389 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);\r
390\r
391 //\r
392 // Validate parameters passed in.\r
393 //\r
394 SetMem (mUfsTargetId, TARGET_MAX_BYTES, 0x00);\r
395 if (CompareMem (Target, mUfsTargetId, TARGET_MAX_BYTES) != 0) {\r
396 return EFI_INVALID_PARAMETER;\r
397 }\r
398\r
399 if ((UINT8)Lun == UFS_WLUN_PREFIX) {\r
400 UfsLun = BIT7 | (((UINT8*)&Lun)[1] & 0xFF);\r
401 } else if ((UINT8)Lun == 0) {\r
402 UfsLun = ((UINT8*)&Lun)[1] & 0xFF;\r
403 } else {\r
404 return EFI_NOT_FOUND;\r
405 }\r
406\r
407 for (Index = 0; Index < UFS_MAX_LUNS; Index++) {\r
408 if ((Private->Luns.BitMask & (BIT0 << Index)) == 0) {\r
409 continue;\r
410 }\r
411 \r
412 if (Private->Luns.Lun[Index] == UfsLun) {\r
413 break;\r
414 }\r
415 }\r
416\r
417 if (Index == UFS_MAX_LUNS) {\r
418 return EFI_NOT_FOUND;\r
419 }\r
420\r
421 DevicePathNode = AllocateCopyPool (sizeof (UFS_DEVICE_PATH), &mUfsDevicePathTemplate);\r
422 if (DevicePathNode == NULL) {\r
423 return EFI_OUT_OF_RESOURCES;\r
424 }\r
425\r
426 DevicePathNode->Ufs.Pun = 0;\r
427 DevicePathNode->Ufs.Lun = UfsLun;\r
428\r
429 *DevicePath = (EFI_DEVICE_PATH_PROTOCOL *) DevicePathNode;\r
430\r
431 return EFI_SUCCESS;\r
432}\r
433\r
434/**\r
435 Used to translate a device path node to a Target ID and LUN.\r
436\r
437 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
438 @param DevicePath A pointer to a single device path node that describes the SCSI device\r
439 on the SCSI channel.\r
440 @param Target A pointer to the Target Array which represents the ID of a SCSI device\r
441 on the SCSI channel.\r
442 @param Lun A pointer to the LUN of a SCSI device on the SCSI channel.\r
443\r
444 @retval EFI_SUCCESS DevicePath was successfully translated to a Target ID and\r
445 LUN, and they were returned in Target and Lun.\r
446 @retval EFI_INVALID_PARAMETER DevicePath or Target or Lun is NULL.\r
447 @retval EFI_NOT_FOUND A valid translation from DevicePath to a Target ID and LUN\r
448 does not exist.\r
449 @retval EFI_UNSUPPORTED This driver does not support the device path node type in\r
450 DevicePath.\r
451\r
452**/\r
453EFI_STATUS\r
454EFIAPI\r
455UfsPassThruGetTargetLun (\r
456 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
457 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
458 OUT UINT8 **Target,\r
459 OUT UINT64 *Lun\r
460 )\r
461{\r
462 UFS_PASS_THRU_PRIVATE_DATA *Private;\r
463 EFI_DEV_PATH *DevicePathNode;\r
464 UINT8 Pun;\r
465 UINT8 UfsLun;\r
466 UINT16 Index;\r
467\r
468 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);\r
469\r
470 //\r
471 // Validate parameters passed in.\r
472 //\r
473 if (DevicePath == NULL || Target == NULL || Lun == NULL) {\r
474 return EFI_INVALID_PARAMETER;\r
475 }\r
476\r
477 if (*Target == NULL) {\r
478 return EFI_INVALID_PARAMETER;\r
479 }\r
480\r
481 //\r
482 // Check whether the DevicePath belongs to SCSI_DEVICE_PATH\r
483 //\r
484 if ((DevicePath->Type != MESSAGING_DEVICE_PATH) || (DevicePath->SubType != MSG_UFS_DP) ||\r
485 (DevicePathNodeLength(DevicePath) != sizeof(SCSI_DEVICE_PATH))) {\r
486 return EFI_UNSUPPORTED;\r
487 }\r
488\r
489 DevicePathNode = (EFI_DEV_PATH *) DevicePath;\r
490\r
491 Pun = (UINT8) DevicePathNode->Ufs.Pun;\r
492 UfsLun = (UINT8) DevicePathNode->Ufs.Lun;\r
493\r
494 if (Pun != 0) {\r
495 return EFI_NOT_FOUND;\r
496 }\r
497\r
498 for (Index = 0; Index < UFS_MAX_LUNS; Index++) {\r
499 if ((Private->Luns.BitMask & (BIT0 << Index)) == 0) {\r
500 continue;\r
501 }\r
502 \r
503 if (Private->Luns.Lun[Index] == UfsLun) {\r
504 break;\r
505 }\r
506 }\r
507\r
508 if (Index == UFS_MAX_LUNS) {\r
509 return EFI_NOT_FOUND;\r
510 }\r
511\r
512 SetMem (*Target, TARGET_MAX_BYTES, 0x00);\r
513 *Lun = 0;\r
514 if ((UfsLun & BIT7) == BIT7) {\r
515 ((UINT8*)Lun)[0] = UFS_WLUN_PREFIX;\r
516 ((UINT8*)Lun)[1] = UfsLun & ~BIT7;\r
517 } else {\r
518 ((UINT8*)Lun)[1] = UfsLun;\r
519 }\r
520 return EFI_SUCCESS;\r
521}\r
522\r
523/**\r
524 Resets a SCSI channel. This operation resets all the SCSI devices connected to the SCSI channel.\r
525\r
526 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
527\r
528 @retval EFI_SUCCESS The SCSI channel was reset.\r
529 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI channel.\r
530 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI channel.\r
531 @retval EFI_UNSUPPORTED The SCSI channel does not support a channel reset operation.\r
532\r
533**/\r
534EFI_STATUS\r
535EFIAPI\r
536UfsPassThruResetChannel (\r
537 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This\r
538 )\r
539{\r
540 //\r
541 // Return success directly then upper layer driver could think reset channel operation is done.\r
542 //\r
543 return EFI_SUCCESS;\r
544}\r
545\r
546/**\r
547 Resets a SCSI logical unit that is connected to a SCSI channel.\r
548\r
549 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
550 @param Target The Target is an array of size TARGET_MAX_BYTE and it represents the\r
551 target port ID of the SCSI device containing the SCSI logical unit to\r
552 reset. Transport drivers may chose to utilize a subset of this array to suit\r
553 the representation of their targets.\r
554 @param Lun The LUN of the SCSI device to reset.\r
555\r
556 @retval EFI_SUCCESS The SCSI device specified by Target and Lun was reset.\r
557 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
558 @retval EFI_TIMEOUT A timeout occurred while attempting to reset the SCSI device\r
559 specified by Target and Lun.\r
560 @retval EFI_UNSUPPORTED The SCSI channel does not support a target reset operation.\r
561 @retval EFI_DEVICE_ERROR A device error occurred while attempting to reset the SCSI device\r
562 specified by Target and Lun.\r
563\r
564**/\r
565EFI_STATUS\r
566EFIAPI\r
567UfsPassThruResetTargetLun (\r
568 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
569 IN UINT8 *Target,\r
570 IN UINT64 Lun\r
571 )\r
572{\r
573 //\r
574 // Return success directly then upper layer driver could think reset target LUN operation is done.\r
575 //\r
576 return EFI_SUCCESS;\r
577}\r
578\r
579/**\r
580 Used to retrieve the list of legal Target IDs for SCSI devices on a SCSI channel. These can either\r
581 be the list SCSI devices that are actually present on the SCSI channel, or the list of legal Target IDs\r
582 for the SCSI channel. Regardless, the caller of this function must probe the Target ID returned to\r
583 see if a SCSI device is actually present at that location on the SCSI channel.\r
584\r
585 @param This A pointer to the EFI_EXT_SCSI_PASS_THRU_PROTOCOL instance.\r
586 @param Target (TARGET_MAX_BYTES) of a SCSI device present on the SCSI channel.\r
587 On output, a pointer to the Target ID (an array of\r
588 TARGET_MAX_BYTES) of the next SCSI device present on a SCSI\r
589 channel. An input value of 0xF(all bytes in the array are 0xF) in the\r
590 Target array retrieves the Target ID of the first SCSI device present on a\r
591 SCSI channel.\r
592\r
593 @retval EFI_SUCCESS The Target ID of the next SCSI device on the SCSI\r
594 channel was returned in Target.\r
595 @retval EFI_INVALID_PARAMETER Target or Lun is NULL.\r
596 @retval EFI_TIMEOUT Target array is not all 0xF, and Target was not\r
597 returned on a previous call to GetNextTarget().\r
598 @retval EFI_NOT_FOUND There are no more SCSI devices on this SCSI channel.\r
599\r
600**/\r
601EFI_STATUS\r
602EFIAPI\r
603UfsPassThruGetNextTarget (\r
604 IN EFI_EXT_SCSI_PASS_THRU_PROTOCOL *This,\r
605 IN OUT UINT8 **Target\r
606 )\r
607{\r
608 UFS_PASS_THRU_PRIVATE_DATA *Private;\r
609\r
610 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_THIS (This);\r
611\r
612 if (Target == NULL || *Target == NULL) {\r
613 return EFI_INVALID_PARAMETER;\r
614 }\r
615\r
616 SetMem (mUfsTargetId, TARGET_MAX_BYTES, 0xFF);\r
617 if (CompareMem(*Target, mUfsTargetId, TARGET_MAX_BYTES) == 0) {\r
618 SetMem (*Target, TARGET_MAX_BYTES, 0x00);\r
619 return EFI_SUCCESS;\r
620 }\r
621\r
622 return EFI_NOT_FOUND;\r
623}\r
624\r
625/**\r
626 Tests to see if this driver supports a given controller. If a child device is provided,\r
627 it further tests to see if this driver supports creating a handle for the specified child device.\r
628\r
629 This function checks to see if the driver specified by This supports the device specified by\r
630 ControllerHandle. Drivers will typically use the device path attached to\r
631 ControllerHandle and/or the services from the bus I/O abstraction attached to\r
632 ControllerHandle to determine if the driver supports ControllerHandle. This function\r
633 may be called many times during platform initialization. In order to reduce boot times, the tests\r
634 performed by this function must be very small, and take as little time as possible to execute. This\r
635 function must not change the state of any hardware devices, and this function must be aware that the\r
636 device specified by ControllerHandle may already be managed by the same driver or a\r
637 different driver. This function must match its calls to AllocatePages() with FreePages(),\r
638 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().\r
639 Since ControllerHandle may have been previously started by the same driver, if a protocol is\r
640 already in the opened state, then it must not be closed with CloseProtocol(). This is required\r
641 to guarantee the state of ControllerHandle is not modified by this function.\r
642\r
643 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
644 @param[in] ControllerHandle The handle of the controller to test. This handle\r
645 must support a protocol interface that supplies\r
646 an I/O abstraction to the driver.\r
647 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
648 parameter is ignored by device drivers, and is optional for bus\r
649 drivers. For bus drivers, if this parameter is not NULL, then\r
650 the bus driver must determine if the bus controller specified\r
651 by ControllerHandle and the child controller specified\r
652 by RemainingDevicePath are both supported by this\r
653 bus driver.\r
654\r
655 @retval EFI_SUCCESS The device specified by ControllerHandle and\r
656 RemainingDevicePath is supported by the driver specified by This.\r
657 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
658 RemainingDevicePath is already being managed by the driver\r
659 specified by This.\r
660 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
661 RemainingDevicePath is already being managed by a different\r
662 driver or an application that requires exclusive access.\r
663 Currently not implemented.\r
664 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and\r
665 RemainingDevicePath is not supported by the driver specified by This.\r
666**/\r
667EFI_STATUS\r
668EFIAPI\r
669UfsPassThruDriverBindingSupported (\r
670 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
671 IN EFI_HANDLE Controller,\r
672 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
673 )\r
674{\r
675 EFI_STATUS Status;\r
676 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;\r
677 EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHostController;\r
678\r
679 //\r
680 // Ufs Pass Thru driver is a device driver, and should ingore the\r
681 // "RemainingDevicePath" according to UEFI spec\r
682 //\r
683 Status = gBS->OpenProtocol (\r
684 Controller,\r
685 &gEfiDevicePathProtocolGuid,\r
686 (VOID *) &ParentDevicePath,\r
687 This->DriverBindingHandle,\r
688 Controller,\r
689 EFI_OPEN_PROTOCOL_BY_DRIVER\r
690 );\r
691 if (EFI_ERROR (Status)) {\r
692 //\r
693 // EFI_ALREADY_STARTED is also an error\r
694 //\r
695 return Status;\r
696 }\r
697 //\r
698 // Close the protocol because we don't use it here\r
699 //\r
700 gBS->CloseProtocol (\r
701 Controller,\r
702 &gEfiDevicePathProtocolGuid,\r
703 This->DriverBindingHandle,\r
704 Controller\r
705 );\r
706\r
707 Status = gBS->OpenProtocol (\r
708 Controller,\r
709 &gEdkiiUfsHostControllerProtocolGuid,\r
710 (VOID **) &UfsHostController,\r
711 This->DriverBindingHandle,\r
712 Controller,\r
713 EFI_OPEN_PROTOCOL_BY_DRIVER\r
714 );\r
715\r
716 if (EFI_ERROR (Status)) {\r
717 //\r
718 // EFI_ALREADY_STARTED is also an error\r
719 //\r
720 return Status;\r
721 }\r
722\r
723 //\r
724 // Close the I/O Abstraction(s) used to perform the supported test\r
725 //\r
726 gBS->CloseProtocol (\r
727 Controller,\r
728 &gEdkiiUfsHostControllerProtocolGuid,\r
729 This->DriverBindingHandle,\r
730 Controller\r
731 );\r
732 \r
733 return EFI_SUCCESS;\r
734}\r
735\r
736/**\r
737 Starts a device controller or a bus controller.\r
738\r
739 The Start() function is designed to be invoked from the EFI boot service ConnectController().\r
740 As a result, much of the error checking on the parameters to Start() has been moved into this\r
741 common boot service. It is legal to call Start() from other locations,\r
742 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
743 1. ControllerHandle must be a valid EFI_HANDLE.\r
744 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned\r
745 EFI_DEVICE_PATH_PROTOCOL.\r
746 3. Prior to calling Start(), the Supported() function for the driver specified by This must\r
747 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.\r
748\r
749 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
750 @param[in] ControllerHandle The handle of the controller to start. This handle\r
751 must support a protocol interface that supplies\r
752 an I/O abstraction to the driver.\r
753 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
754 parameter is ignored by device drivers, and is optional for bus\r
755 drivers. For a bus driver, if this parameter is NULL, then handles\r
756 for all the children of Controller are created by this driver.\r
757 If this parameter is not NULL and the first Device Path Node is\r
758 not the End of Device Path Node, then only the handle for the\r
759 child device specified by the first Device Path Node of\r
760 RemainingDevicePath is created by this driver.\r
761 If the first Device Path Node of RemainingDevicePath is\r
762 the End of Device Path Node, no child handle is created by this\r
763 driver.\r
764\r
765 @retval EFI_SUCCESS The device was started.\r
766 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
767 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
768 @retval Others The driver failded to start the device.\r
769\r
770**/\r
771EFI_STATUS\r
772EFIAPI\r
773UfsPassThruDriverBindingStart (\r
774 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
775 IN EFI_HANDLE Controller,\r
776 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath\r
777 )\r
778{\r
779 EFI_STATUS Status;\r
780 EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHc;\r
781 UFS_PASS_THRU_PRIVATE_DATA *Private;\r
782 UINTN UfsHcBase;\r
783 UINT32 Index;\r
784 UFS_CONFIG_DESC Config;\r
785\r
786 Status = EFI_SUCCESS;\r
787 UfsHc = NULL;\r
788 Private = NULL;\r
789 UfsHcBase = 0;\r
790\r
791 DEBUG ((EFI_D_INFO, "==UfsPassThru Start== Controller = %x\n", Controller));\r
792\r
793 Status = gBS->OpenProtocol (\r
794 Controller,\r
795 &gEdkiiUfsHostControllerProtocolGuid,\r
796 (VOID **) &UfsHc,\r
797 This->DriverBindingHandle,\r
798 Controller,\r
799 EFI_OPEN_PROTOCOL_BY_DRIVER\r
800 );\r
801\r
802 if (EFI_ERROR (Status)) {\r
803 DEBUG ((EFI_D_ERROR, "Open Ufs Host Controller Protocol Error, Status = %r\n", Status));\r
804 goto Error;\r
805 }\r
806\r
807 //\r
808 // Get the UFS Host Controller MMIO Bar Base Address.\r
809 //\r
810 Status = UfsHc->GetUfsHcMmioBar (UfsHc, &UfsHcBase);\r
811 if (EFI_ERROR (Status)) {\r
812 DEBUG ((EFI_D_ERROR, "Get Ufs Host Controller Mmio Bar Error, Status = %r\n", Status));\r
813 goto Error;\r
814 }\r
815\r
816 //\r
817 // Initialize Ufs Pass Thru private data for managed UFS Host Controller.\r
818 //\r
819 Private = AllocateCopyPool (sizeof (UFS_PASS_THRU_PRIVATE_DATA), &gUfsPassThruTemplate);\r
820 if (Private == NULL) {\r
0350b57c 821 DEBUG ((EFI_D_ERROR, "Unable to allocate Ufs Pass Thru private data\n"));\r
0591696e
FT
822 Status = EFI_OUT_OF_RESOURCES;\r
823 goto Error;\r
824 }\r
825\r
826 Private->ExtScsiPassThru.Mode = &Private->ExtScsiPassThruMode;\r
827 Private->UfsHostController = UfsHc;\r
828 Private->UfsHcBase = UfsHcBase;\r
0350b57c 829 InitializeListHead (&Private->Queue);\r
0591696e
FT
830\r
831 //\r
832 // Initialize UFS Host Controller H/W.\r
833 //\r
834 Status = UfsControllerInit (Private);\r
835 if (EFI_ERROR (Status)) {\r
836 DEBUG ((EFI_D_ERROR, "Ufs Host Controller Initialization Error, Status = %r\n", Status));\r
837 goto Error;\r
838 }\r
839\r
840 //\r
841 // UFS 2.0 spec Section 13.1.3.3:\r
842 // At the end of the UFS Interconnect Layer initialization on both host and device side, \r
843 // the host shall send a NOP OUT UPIU to verify that the device UTP Layer is ready. \r
844 //\r
845 Status = UfsExecNopCmds (Private);\r
846 if (EFI_ERROR (Status)) {\r
847 DEBUG ((EFI_D_ERROR, "Ufs Sending NOP IN command Error, Status = %r\n", Status));\r
848 goto Error;\r
849 }\r
850\r
851 //\r
852 // The host enables the device initialization completion by setting fDeviceInit flag.\r
853 //\r
854 Status = UfsSetFlag (Private, UfsFlagDevInit);\r
855 if (EFI_ERROR (Status)) {\r
856 DEBUG ((EFI_D_ERROR, "Ufs Set fDeviceInit Flag Error, Status = %r\n", Status));\r
857 goto Error;\r
858 }\r
859\r
860 //\r
861 // Get Ufs Device's Lun Info by reading Configuration Descriptor.\r
862 //\r
863 Status = UfsRwDeviceDesc (Private, TRUE, UfsConfigDesc, 0, 0, &Config, sizeof (UFS_CONFIG_DESC));\r
864 if (EFI_ERROR (Status)) {\r
865 DEBUG ((EFI_D_ERROR, "Ufs Get Configuration Descriptor Error, Status = %r\n", Status));\r
866 goto Error;\r
867 }\r
868\r
869 //\r
870 // Check if 8 common luns are active and set corresponding bit mask.\r
871 // TODO: Parse device descriptor to decide if exposing RPMB LUN to upper layer for authentication access.\r
872 //\r
873 for (Index = 0; Index < 8; Index++) {\r
874 if (Config.UnitDescConfParams[Index].LunEn != 0) {\r
875 Private->Luns.BitMask |= (BIT0 << Index);\r
876 DEBUG ((EFI_D_INFO, "Ufs Lun %d is enabled\n", Index));\r
877 }\r
878 }\r
879\r
0350b57c
HW
880 //\r
881 // Start the asynchronous interrupt monitor\r
882 //\r
883 Status = gBS->CreateEvent (\r
884 EVT_TIMER | EVT_NOTIFY_SIGNAL,\r
885 TPL_CALLBACK,\r
886 ProcessAsyncTaskList,\r
887 Private,\r
888 &Private->TimerEvent\r
889 );\r
890 if (EFI_ERROR (Status)) {\r
891 DEBUG ((EFI_D_ERROR, "Ufs Create Async Tasks Event Error, Status = %r\n", Status));\r
892 goto Error;\r
893 }\r
894\r
895 Status = gBS->SetTimer (\r
896 Private->TimerEvent,\r
897 TimerPeriodic,\r
898 UFS_HC_ASYNC_TIMER\r
899 );\r
900 if (EFI_ERROR (Status)) {\r
901 DEBUG ((EFI_D_ERROR, "Ufs Set Periodic Timer Error, Status = %r\n", Status));\r
902 goto Error;\r
903 }\r
904\r
0591696e
FT
905 Status = gBS->InstallProtocolInterface (\r
906 &Controller,\r
907 &gEfiExtScsiPassThruProtocolGuid,\r
908 EFI_NATIVE_INTERFACE,\r
909 &(Private->ExtScsiPassThru)\r
910 );\r
911 ASSERT_EFI_ERROR (Status);\r
912\r
913 return EFI_SUCCESS;\r
914\r
915Error:\r
916 if (Private != NULL) {\r
917 if (Private->TmrlMapping != NULL) {\r
918 UfsHc->Unmap (UfsHc, Private->TmrlMapping); \r
919 }\r
920 if (Private->UtpTmrlBase != NULL) {\r
921 UfsHc->FreeBuffer (UfsHc, EFI_SIZE_TO_PAGES (Private->Nutmrs * sizeof (UTP_TMRD)), Private->UtpTmrlBase);\r
922 }\r
923\r
924 if (Private->TrlMapping != NULL) {\r
925 UfsHc->Unmap (UfsHc, Private->TrlMapping);\r
926 }\r
927 if (Private->UtpTrlBase != NULL) {\r
928 UfsHc->FreeBuffer (UfsHc, EFI_SIZE_TO_PAGES (Private->Nutrs * sizeof (UTP_TMRD)), Private->UtpTrlBase);\r
929 }\r
930\r
0350b57c
HW
931 if (Private->TimerEvent != NULL) {\r
932 gBS->CloseEvent (Private->TimerEvent);\r
933 }\r
934\r
0591696e
FT
935 FreePool (Private);\r
936 }\r
937\r
938 if (UfsHc != NULL) {\r
939 gBS->CloseProtocol (\r
940 Controller,\r
941 &gEdkiiUfsHostControllerProtocolGuid,\r
942 This->DriverBindingHandle,\r
943 Controller\r
944 );\r
945 }\r
946\r
947 return Status;\r
948}\r
949\r
950/**\r
951 Stops a device controller or a bus controller.\r
952\r
953 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().\r
954 As a result, much of the error checking on the parameters to Stop() has been moved\r
955 into this common boot service. It is legal to call Stop() from other locations,\r
956 but the following calling restrictions must be followed or the system behavior will not be deterministic.\r
957 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this\r
958 same driver's Start() function.\r
959 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid\r
960 EFI_HANDLE. In addition, all of these handles must have been created in this driver's\r
961 Start() function, and the Start() function must have called OpenProtocol() on\r
962 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.\r
963\r
964 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
965 @param[in] ControllerHandle A handle to the device being stopped. The handle must\r
966 support a bus specific I/O protocol for the driver\r
967 to use to stop the device.\r
968 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.\r
969 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL\r
970 if NumberOfChildren is 0.\r
971\r
972 @retval EFI_SUCCESS The device was stopped.\r
973 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.\r
974\r
975**/\r
976EFI_STATUS\r
977EFIAPI\r
978UfsPassThruDriverBindingStop (\r
979 IN EFI_DRIVER_BINDING_PROTOCOL *This,\r
980 IN EFI_HANDLE Controller,\r
981 IN UINTN NumberOfChildren,\r
982 IN EFI_HANDLE *ChildHandleBuffer\r
983 )\r
984{\r
985 EFI_STATUS Status;\r
986 UFS_PASS_THRU_PRIVATE_DATA *Private;\r
987 EFI_EXT_SCSI_PASS_THRU_PROTOCOL *ExtScsiPassThru;\r
988 EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHc;\r
0350b57c
HW
989 UFS_PASS_THRU_TRANS_REQ *TransReq;\r
990 LIST_ENTRY *Entry;\r
991 LIST_ENTRY *NextEntry;\r
0591696e
FT
992\r
993 DEBUG ((EFI_D_INFO, "==UfsPassThru Stop== Controller Controller = %x\n", Controller));\r
994\r
995 Status = gBS->OpenProtocol (\r
996 Controller,\r
997 &gEfiExtScsiPassThruProtocolGuid,\r
998 (VOID **) &ExtScsiPassThru,\r
999 This->DriverBindingHandle,\r
1000 Controller,\r
1001 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
1002 );\r
1003\r
1004 if (EFI_ERROR (Status)) {\r
1005 return EFI_DEVICE_ERROR;\r
1006 }\r
1007\r
1008 Private = UFS_PASS_THRU_PRIVATE_DATA_FROM_THIS (ExtScsiPassThru);\r
1009 UfsHc = Private->UfsHostController;\r
1010\r
0350b57c
HW
1011 //\r
1012 // Cleanup the resources of I/O requests in the async I/O queue\r
1013 //\r
1014 if (!IsListEmpty(&Private->Queue)) {\r
1015 EFI_LIST_FOR_EACH_SAFE (Entry, NextEntry, &Private->Queue) {\r
1016 TransReq = UFS_PASS_THRU_TRANS_REQ_FROM_THIS (Entry);\r
1017\r
1018 //\r
1019 // TODO: Should find/add a proper host adapter return status for this\r
1020 // case.\r
1021 //\r
1022 TransReq->Packet->HostAdapterStatus =\r
1023 EFI_EXT_SCSI_STATUS_HOST_ADAPTER_PHASE_ERROR;\r
1024\r
1025 SignalCallerEvent (Private, TransReq);\r
1026 }\r
1027 }\r
1028\r
0591696e
FT
1029 Status = gBS->UninstallProtocolInterface (\r
1030 Controller,\r
1031 &gEfiExtScsiPassThruProtocolGuid,\r
1032 &(Private->ExtScsiPassThru)\r
1033 );\r
1034\r
1035 if (EFI_ERROR (Status)) {\r
1036 return EFI_DEVICE_ERROR;\r
1037 }\r
1038\r
1039 //\r
1040 // Stop Ufs Host Controller\r
1041 //\r
1042 Status = UfsControllerStop (Private);\r
1043 ASSERT_EFI_ERROR (Status);\r
1044\r
1045 if (Private->TmrlMapping != NULL) {\r
1046 UfsHc->Unmap (UfsHc, Private->TmrlMapping);\r
1047 }\r
1048 if (Private->UtpTmrlBase != NULL) {\r
1049 UfsHc->FreeBuffer (UfsHc, EFI_SIZE_TO_PAGES (Private->Nutmrs * sizeof (UTP_TMRD)), Private->UtpTmrlBase);\r
1050 }\r
1051\r
1052 if (Private->TrlMapping != NULL) {\r
1053 UfsHc->Unmap (UfsHc, Private->TrlMapping);\r
1054 }\r
1055 if (Private->UtpTrlBase != NULL) {\r
1056 UfsHc->FreeBuffer (UfsHc, EFI_SIZE_TO_PAGES (Private->Nutrs * sizeof (UTP_TMRD)), Private->UtpTrlBase);\r
1057 }\r
1058\r
0350b57c
HW
1059 if (Private->TimerEvent != NULL) {\r
1060 gBS->CloseEvent (Private->TimerEvent);\r
1061 }\r
1062\r
0591696e
FT
1063 FreePool (Private);\r
1064\r
1065 //\r
1066 // Close protocols opened by UfsPassThru controller driver\r
1067 //\r
1068 gBS->CloseProtocol (\r
1069 Controller,\r
1070 &gEdkiiUfsHostControllerProtocolGuid,\r
1071 This->DriverBindingHandle,\r
1072 Controller\r
1073 );\r
1074\r
1075 return Status;\r
1076}\r
1077\r
1078\r
1079/**\r
1080 The user Entry Point for module UfsPassThru. The user code starts with this function.\r
1081\r
1082 @param[in] ImageHandle The firmware allocated handle for the EFI image.\r
1083 @param[in] SystemTable A pointer to the EFI System Table.\r
1084\r
1085 @retval EFI_SUCCESS The entry point is executed successfully.\r
1086 @retval other Some error occurs when executing this entry point.\r
1087\r
1088**/\r
1089EFI_STATUS\r
1090EFIAPI\r
1091InitializeUfsPassThru (\r
1092 IN EFI_HANDLE ImageHandle,\r
1093 IN EFI_SYSTEM_TABLE *SystemTable\r
1094 )\r
1095{\r
1096 EFI_STATUS Status;\r
1097\r
1098 //\r
1099 // Install driver model protocol(s).\r
1100 //\r
1101 Status = EfiLibInstallDriverBindingComponentName2 (\r
1102 ImageHandle,\r
1103 SystemTable,\r
1104 &gUfsPassThruDriverBinding,\r
1105 ImageHandle,\r
1106 &gUfsPassThruComponentName,\r
1107 &gUfsPassThruComponentName2\r
1108 );\r
1109 ASSERT_EFI_ERROR (Status);\r
1110\r
1111 return Status;\r
1112}\r