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