]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Pci/UfsPciHcDxe/UfsPciHcDxe.c
MdeModulePkg: Add UFS (Universal Flash Storage) Stack
[mirror_edk2.git] / MdeModulePkg / Bus / Pci / UfsPciHcDxe / UfsPciHcDxe.c
1 /** @file
2 UfsHcDxe driver is used to provide platform-dependent info, mainly UFS host controller
3 MMIO base, to upper layer UFS drivers.
4
5 Copyright (c) 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php.
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #include "UfsPciHcDxe.h"
17
18 //
19 // NVM Express Driver Binding Protocol Instance
20 //
21 EFI_DRIVER_BINDING_PROTOCOL gUfsHcDriverBinding = {
22 UfsHcDriverBindingSupported,
23 UfsHcDriverBindingStart,
24 UfsHcDriverBindingStop,
25 0x10,
26 NULL,
27 NULL
28 };
29
30 //
31 // Template for Ufs host controller private data.
32 //
33 UFS_HOST_CONTROLLER_PRIVATE_DATA gUfsHcTemplate = {
34 UFS_HC_PRIVATE_DATA_SIGNATURE, // Signature
35 NULL, // Handle
36 { // UfsHcProtocol
37 UfsHcGetMmioBar,
38 UfsHcAllocateBuffer,
39 UfsHcFreeBuffer,
40 UfsHcMap,
41 UfsHcUnmap,
42 UfsHcFlush
43 },
44 NULL, // PciIo
45 0 // PciAttributes
46 };
47
48 /**
49 Get the MMIO base of the UFS host controller.
50
51 @param[in] This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
52 @param[out] MmioBar The MMIO base address of UFS host controller.
53
54 @retval EFI_SUCCESS The operation succeeds.
55 @retval others The operation fails.
56 **/
57 EFI_STATUS
58 EFIAPI
59 UfsHcGetMmioBar (
60 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
61 OUT UINTN *MmioBar
62 )
63 {
64 UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;
65 EFI_PCI_IO_PROTOCOL *PciIo;
66 EFI_STATUS Status;
67
68 if ((This == NULL) || (MmioBar == NULL)) {
69 return EFI_INVALID_PARAMETER;
70 }
71
72 Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);
73 PciIo = Private->PciIo;
74
75 Status = PciIo->Pci.Read (
76 PciIo,
77 EfiPciIoWidthUint8,
78 PCI_BASE_ADDRESSREG_OFFSET,
79 sizeof (UINT32),
80 MmioBar
81 );
82
83 if (!EFI_ERROR (Status)) {
84 *MmioBar &= (UINTN)~0xF;
85 }
86 return Status;
87 }
88
89 /**
90 Provides the UFS controller-specific addresses needed to access system memory.
91
92 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
93 @param Operation Indicates if the bus master is going to read or write to system memory.
94 @param HostAddress The system memory address to map to the UFS controller.
95 @param NumberOfBytes On input the number of bytes to map. On output the number of bytes
96 that were mapped.
97 @param DeviceAddress The resulting map address for the bus master UFS controller to use to
98 access the hosts HostAddress.
99 @param Mapping A resulting value to pass to Unmap().
100
101 @retval EFI_SUCCESS The range was mapped for the returned NumberOfBytes.
102 @retval EFI_UNSUPPORTED The HostAddress cannot be mapped as a common buffer.
103 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
104 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
105 @retval EFI_DEVICE_ERROR The system hardware could not map the requested address.
106
107 **/
108 EFI_STATUS
109 EFIAPI
110 UfsHcMap (
111 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
112 IN EDKII_UFS_HOST_CONTROLLER_OPERATION Operation,
113 IN VOID *HostAddress,
114 IN OUT UINTN *NumberOfBytes,
115 OUT EFI_PHYSICAL_ADDRESS *DeviceAddress,
116 OUT VOID **Mapping
117 )
118 {
119 UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;
120 EFI_PCI_IO_PROTOCOL *PciIo;
121 EFI_STATUS Status;
122
123 if ((This == NULL) || (HostAddress == NULL) || (NumberOfBytes == NULL) || (DeviceAddress == NULL) || (Mapping == NULL)) {
124 return EFI_INVALID_PARAMETER;
125 }
126
127 Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);
128 PciIo = Private->PciIo;
129
130 Status = PciIo->Map (PciIo, Operation, HostAddress, NumberOfBytes, DeviceAddress, Mapping);
131 return Status;
132 }
133
134 /**
135 Completes the Map() operation and releases any corresponding resources.
136
137 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
138 @param Mapping The mapping value returned from Map().
139
140 @retval EFI_SUCCESS The range was unmapped.
141 @retval EFI_DEVICE_ERROR The data was not committed to the target system memory.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 UfsHcUnmap (
147 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
148 IN VOID *Mapping
149 )
150 {
151 UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;
152 EFI_PCI_IO_PROTOCOL *PciIo;
153 EFI_STATUS Status;
154
155 if ((This == NULL) || (Mapping == NULL)) {
156 return EFI_INVALID_PARAMETER;
157 }
158
159 Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);
160 PciIo = Private->PciIo;
161
162 Status = PciIo->Unmap (PciIo, Mapping);
163 return Status;
164 }
165
166 /**
167 Allocates pages that are suitable for an EfiUfsHcOperationBusMasterCommonBuffer
168 mapping.
169
170 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
171 @param Type This parameter is not used and must be ignored.
172 @param MemoryType The type of memory to allocate, EfiBootServicesData or
173 EfiRuntimeServicesData.
174 @param Pages The number of pages to allocate.
175 @param HostAddress A pointer to store the base system memory address of the
176 allocated range.
177 @param Attributes The requested bit mask of attributes for the allocated range.
178
179 @retval EFI_SUCCESS The requested memory pages were allocated.
180 @retval EFI_UNSUPPORTED Attributes is unsupported. The only legal attribute bits are
181 MEMORY_WRITE_COMBINE and MEMORY_CACHED.
182 @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
183 @retval EFI_OUT_OF_RESOURCES The memory pages could not be allocated.
184
185 **/
186 EFI_STATUS
187 EFIAPI
188 UfsHcAllocateBuffer (
189 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
190 IN EFI_ALLOCATE_TYPE Type,
191 IN EFI_MEMORY_TYPE MemoryType,
192 IN UINTN Pages,
193 OUT VOID **HostAddress,
194 IN UINT64 Attributes
195 )
196 {
197 UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;
198 EFI_PCI_IO_PROTOCOL *PciIo;
199 EFI_STATUS Status;
200
201 if ((This == NULL) || (HostAddress == NULL)) {
202 return EFI_INVALID_PARAMETER;
203 }
204
205 Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);
206 PciIo = Private->PciIo;
207
208 Status = PciIo->AllocateBuffer (PciIo, Type, MemoryType, Pages, HostAddress, Attributes);
209 return Status;
210 }
211
212 /**
213 Frees memory that was allocated with AllocateBuffer().
214
215 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
216 @param Pages The number of pages to free.
217 @param HostAddress The base system memory address of the allocated range.
218
219 @retval EFI_SUCCESS The requested memory pages were freed.
220 @retval EFI_INVALID_PARAMETER The memory range specified by HostAddress and Pages
221 was not allocated with AllocateBuffer().
222
223 **/
224 EFI_STATUS
225 EFIAPI
226 UfsHcFreeBuffer (
227 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This,
228 IN UINTN Pages,
229 IN VOID *HostAddress
230 )
231 {
232 UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;
233 EFI_PCI_IO_PROTOCOL *PciIo;
234 EFI_STATUS Status;
235
236 if ((This == NULL) || (HostAddress == NULL)) {
237 return EFI_INVALID_PARAMETER;
238 }
239
240 Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);
241 PciIo = Private->PciIo;
242
243 Status = PciIo->FreeBuffer (PciIo, Pages, HostAddress);
244 return Status;
245 }
246
247 /**
248 Flushes all posted write transactions from the UFS bus to attached UFS device.
249
250 @param This A pointer to the EFI_UFS_HOST_CONTROLLER_PROTOCOL instance.
251
252 @retval EFI_SUCCESS The posted write transactions were flushed from the UFS bus
253 to attached UFS device.
254 @retval EFI_DEVICE_ERROR The posted write transactions were not flushed from the UFS
255 bus to attached UFS device due to a hardware error.
256
257 **/
258 EFI_STATUS
259 EFIAPI
260 UfsHcFlush (
261 IN EDKII_UFS_HOST_CONTROLLER_PROTOCOL *This
262 )
263 {
264 UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;
265 EFI_PCI_IO_PROTOCOL *PciIo;
266 EFI_STATUS Status;
267
268 Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (This);
269 PciIo = Private->PciIo;
270
271 Status = PciIo->Flush (PciIo);
272 return Status;
273 }
274
275 /**
276 Tests to see if this driver supports a given controller. If a child device is provided,
277 it further tests to see if this driver supports creating a handle for the specified child device.
278
279 This function checks to see if the driver specified by This supports the device specified by
280 ControllerHandle. Drivers will typically use the device path attached to
281 ControllerHandle and/or the services from the bus I/O abstraction attached to
282 ControllerHandle to determine if the driver supports ControllerHandle. This function
283 may be called many times during platform initialization. In order to reduce boot times, the tests
284 performed by this function must be very small, and take as little time as possible to execute. This
285 function must not change the state of any hardware devices, and this function must be aware that the
286 device specified by ControllerHandle may already be managed by the same driver or a
287 different driver. This function must match its calls to AllocatePages() with FreePages(),
288 AllocatePool() with FreePool(), and OpenProtocol() with CloseProtocol().
289 Since ControllerHandle may have been previously started by the same driver, if a protocol is
290 already in the opened state, then it must not be closed with CloseProtocol(). This is required
291 to guarantee the state of ControllerHandle is not modified by this function.
292
293 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
294 @param[in] ControllerHandle The handle of the controller to test. This handle
295 must support a protocol interface that supplies
296 an I/O abstraction to the driver.
297 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
298 parameter is ignored by device drivers, and is optional for bus
299 drivers. For bus drivers, if this parameter is not NULL, then
300 the bus driver must determine if the bus controller specified
301 by ControllerHandle and the child controller specified
302 by RemainingDevicePath are both supported by this
303 bus driver.
304
305 @retval EFI_SUCCESS The device specified by ControllerHandle and
306 RemainingDevicePath is supported by the driver specified by This.
307 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and
308 RemainingDevicePath is already being managed by the driver
309 specified by This.
310 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and
311 RemainingDevicePath is already being managed by a different
312 driver or an application that requires exclusive access.
313 Currently not implemented.
314 @retval EFI_UNSUPPORTED The device specified by ControllerHandle and
315 RemainingDevicePath is not supported by the driver specified by This.
316 **/
317 EFI_STATUS
318 EFIAPI
319 UfsHcDriverBindingSupported (
320 IN EFI_DRIVER_BINDING_PROTOCOL *This,
321 IN EFI_HANDLE Controller,
322 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
323 )
324 {
325 EFI_STATUS Status;
326 BOOLEAN UfsHcFound;
327 EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
328 EFI_PCI_IO_PROTOCOL *PciIo;
329 PCI_TYPE00 PciData;
330
331 PciIo = NULL;
332 ParentDevicePath = NULL;
333 UfsHcFound = FALSE;
334
335 //
336 // UfsHcDxe is a device driver, and should ingore the
337 // "RemainingDevicePath" according to EFI spec
338 //
339 Status = gBS->OpenProtocol (
340 Controller,
341 &gEfiDevicePathProtocolGuid,
342 (VOID *) &ParentDevicePath,
343 This->DriverBindingHandle,
344 Controller,
345 EFI_OPEN_PROTOCOL_BY_DRIVER
346 );
347 if (EFI_ERROR (Status)) {
348 //
349 // EFI_ALREADY_STARTED is also an error
350 //
351 return Status;
352 }
353 //
354 // Close the protocol because we don't use it here
355 //
356 gBS->CloseProtocol (
357 Controller,
358 &gEfiDevicePathProtocolGuid,
359 This->DriverBindingHandle,
360 Controller
361 );
362
363 //
364 // Now test the EfiPciIoProtocol
365 //
366 Status = gBS->OpenProtocol (
367 Controller,
368 &gEfiPciIoProtocolGuid,
369 (VOID **) &PciIo,
370 This->DriverBindingHandle,
371 Controller,
372 EFI_OPEN_PROTOCOL_BY_DRIVER
373 );
374 if (EFI_ERROR (Status)) {
375 return Status;
376 }
377 //
378 // Now further check the PCI header: Base class (offset 0x0B) and
379 // Sub Class (offset 0x0A). This controller should be an UFS controller
380 //
381 Status = PciIo->Pci.Read (
382 PciIo,
383 EfiPciIoWidthUint8,
384 0,
385 sizeof (PciData),
386 &PciData
387 );
388 if (EFI_ERROR (Status)) {
389 gBS->CloseProtocol (
390 Controller,
391 &gEfiPciIoProtocolGuid,
392 This->DriverBindingHandle,
393 Controller
394 );
395 return EFI_UNSUPPORTED;
396 }
397 //
398 // Since we already got the PciData, we can close protocol to avoid to carry it on for multiple exit points.
399 //
400 gBS->CloseProtocol (
401 Controller,
402 &gEfiPciIoProtocolGuid,
403 This->DriverBindingHandle,
404 Controller
405 );
406
407 //
408 // Examine UFS Host Controller PCI Configuration table fields
409 //
410 if (PciData.Hdr.ClassCode[2] == PCI_CLASS_MASS_STORAGE) {
411 if (PciData.Hdr.ClassCode[1] == 0x09 ) { //UFS Controller Subclass
412 UfsHcFound = TRUE;
413 }
414 }
415
416 if (!UfsHcFound) {
417 return EFI_UNSUPPORTED;
418 }
419
420 return Status;
421 }
422
423
424 /**
425 Starts a device controller or a bus controller.
426
427 The Start() function is designed to be invoked from the EFI boot service ConnectController().
428 As a result, much of the error checking on the parameters to Start() has been moved into this
429 common boot service. It is legal to call Start() from other locations,
430 but the following calling restrictions must be followed or the system behavior will not be deterministic.
431 1. ControllerHandle must be a valid EFI_HANDLE.
432 2. If RemainingDevicePath is not NULL, then it must be a pointer to a naturally aligned
433 EFI_DEVICE_PATH_PROTOCOL.
434 3. Prior to calling Start(), the Supported() function for the driver specified by This must
435 have been called with the same calling parameters, and Supported() must have returned EFI_SUCCESS.
436
437 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
438 @param[in] ControllerHandle The handle of the controller to start. This handle
439 must support a protocol interface that supplies
440 an I/O abstraction to the driver.
441 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
442 parameter is ignored by device drivers, and is optional for bus
443 drivers. For a bus driver, if this parameter is NULL, then handles
444 for all the children of Controller are created by this driver.
445 If this parameter is not NULL and the first Device Path Node is
446 not the End of Device Path Node, then only the handle for the
447 child device specified by the first Device Path Node of
448 RemainingDevicePath is created by this driver.
449 If the first Device Path Node of RemainingDevicePath is
450 the End of Device Path Node, no child handle is created by this
451 driver.
452
453 @retval EFI_SUCCESS The device was started.
454 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
455 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
456 @retval Others The driver failded to start the device.
457
458 **/
459 EFI_STATUS
460 EFIAPI
461 UfsHcDriverBindingStart (
462 IN EFI_DRIVER_BINDING_PROTOCOL *This,
463 IN EFI_HANDLE Controller,
464 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
465 )
466 {
467 EFI_STATUS Status;
468 EFI_PCI_IO_PROTOCOL *PciIo;
469 UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;
470 UINT64 Supports;
471
472 PciIo = NULL;
473 Private = NULL;
474 Supports = 0;
475
476 //
477 // Now test and open the EfiPciIoProtocol
478 //
479 Status = gBS->OpenProtocol (
480 Controller,
481 &gEfiPciIoProtocolGuid,
482 (VOID **) &PciIo,
483 This->DriverBindingHandle,
484 Controller,
485 EFI_OPEN_PROTOCOL_BY_DRIVER
486 );
487 //
488 // Status == 0 - A normal execution flow, SUCCESS and the program proceeds.
489 // Status == ALREADY_STARTED - A non-zero Status code returned. It indicates
490 // that the protocol has been opened and should be treated as a
491 // normal condition and the program proceeds. The Protocol will not
492 // opened 'again' by this call.
493 // Status != ALREADY_STARTED - Error status, terminate program execution
494 //
495 if (EFI_ERROR (Status)) {
496 //
497 // EFI_ALREADY_STARTED is also an error
498 //
499 return Status;
500 }
501
502 Private = AllocateCopyPool (sizeof (UFS_HOST_CONTROLLER_PRIVATE_DATA), &gUfsHcTemplate);
503 if (Private == NULL) {
504 Status = EFI_OUT_OF_RESOURCES;
505 goto Done;
506 }
507
508 Private->PciIo = PciIo;
509
510 Status = PciIo->Attributes (
511 PciIo,
512 EfiPciIoAttributeOperationGet,
513 0,
514 &Private->PciAttributes
515 );
516
517 if (EFI_ERROR (Status)) {
518 goto Done;
519 }
520
521 Status = PciIo->Attributes (
522 PciIo,
523 EfiPciIoAttributeOperationSupported,
524 0,
525 &Supports
526 );
527
528 if (!EFI_ERROR (Status)) {
529 Supports &= (UINT64)EFI_PCI_DEVICE_ENABLE;
530 Status = PciIo->Attributes (
531 PciIo,
532 EfiPciIoAttributeOperationEnable,
533 Supports,
534 NULL
535 );
536 } else {
537 goto Done;
538 }
539
540 ///
541 /// Install UFS_HOST_CONTROLLER protocol
542 ///
543 Status = gBS->InstallProtocolInterface (
544 &Controller,
545 &gEdkiiUfsHostControllerProtocolGuid,
546 EFI_NATIVE_INTERFACE,
547 (VOID*)&(Private->UfsHc)
548 );
549
550 Done:
551 if (EFI_ERROR (Status)) {
552 if ((Private != NULL) && (Private->PciAttributes != 0)) {
553 //
554 // Restore original PCI attributes
555 //
556 Status = PciIo->Attributes (
557 PciIo,
558 EfiPciIoAttributeOperationSet,
559 Private->PciAttributes,
560 NULL
561 );
562 ASSERT_EFI_ERROR (Status);
563 }
564 gBS->CloseProtocol (
565 Controller,
566 &gEfiPciIoProtocolGuid,
567 This->DriverBindingHandle,
568 Controller
569 );
570 if (Private != NULL) {
571 FreePool (Private);
572 }
573 }
574
575 return Status;
576 }
577
578
579 /**
580 Stops a device controller or a bus controller.
581
582 The Stop() function is designed to be invoked from the EFI boot service DisconnectController().
583 As a result, much of the error checking on the parameters to Stop() has been moved
584 into this common boot service. It is legal to call Stop() from other locations,
585 but the following calling restrictions must be followed or the system behavior will not be deterministic.
586 1. ControllerHandle must be a valid EFI_HANDLE that was used on a previous call to this
587 same driver's Start() function.
588 2. The first NumberOfChildren handles of ChildHandleBuffer must all be a valid
589 EFI_HANDLE. In addition, all of these handles must have been created in this driver's
590 Start() function, and the Start() function must have called OpenProtocol() on
591 ControllerHandle with an Attribute of EFI_OPEN_PROTOCOL_BY_CHILD_CONTROLLER.
592
593 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
594 @param[in] ControllerHandle A handle to the device being stopped. The handle must
595 support a bus specific I/O protocol for the driver
596 to use to stop the device.
597 @param[in] NumberOfChildren The number of child device handles in ChildHandleBuffer.
598 @param[in] ChildHandleBuffer An array of child handles to be freed. May be NULL
599 if NumberOfChildren is 0.
600
601 @retval EFI_SUCCESS The device was stopped.
602 @retval EFI_DEVICE_ERROR The device could not be stopped due to a device error.
603
604 **/
605 EFI_STATUS
606 EFIAPI
607 UfsHcDriverBindingStop (
608 IN EFI_DRIVER_BINDING_PROTOCOL *This,
609 IN EFI_HANDLE Controller,
610 IN UINTN NumberOfChildren,
611 IN EFI_HANDLE *ChildHandleBuffer
612 )
613 {
614 EFI_STATUS Status;
615 UFS_HOST_CONTROLLER_PRIVATE_DATA *Private;
616 EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHc;
617
618 ///
619 /// Get private data
620 ///
621 Status = gBS->OpenProtocol (
622 Controller,
623 &gEdkiiUfsHostControllerProtocolGuid,
624 (VOID **) &UfsHc,
625 This->DriverBindingHandle,
626 Controller,
627 EFI_OPEN_PROTOCOL_GET_PROTOCOL
628 );
629
630 if (EFI_ERROR (Status)) {
631 return EFI_DEVICE_ERROR;
632 }
633
634 Private = UFS_HOST_CONTROLLER_PRIVATE_DATA_FROM_UFSHC (UfsHc);
635
636 Status = gBS->UninstallProtocolInterface (
637 Controller,
638 &gEdkiiUfsHostControllerProtocolGuid,
639 &(Private->UfsHc)
640 );
641 if (!EFI_ERROR (Status)) {
642 //
643 // Restore original PCI attributes
644 //
645 Status = Private->PciIo->Attributes (
646 Private->PciIo,
647 EfiPciIoAttributeOperationSet,
648 Private->PciAttributes,
649 NULL
650 );
651 ASSERT_EFI_ERROR (Status);
652
653 //
654 // Close protocols opened by UFS host controller driver
655 //
656 gBS->CloseProtocol (
657 Controller,
658 &gEfiPciIoProtocolGuid,
659 This->DriverBindingHandle,
660 Controller
661 );
662
663 FreePool (Private);
664 }
665
666 return Status;
667 }
668
669 /**
670 The entry point for UFS host controller driver, used to install this driver on the ImageHandle.
671
672 @param[in] ImageHandle The firmware allocated handle for this driver image.
673 @param[in] SystemTable Pointer to the EFI system table.
674
675 @retval EFI_SUCCESS Driver loaded.
676 @retval other Driver not loaded.
677
678 **/
679 EFI_STATUS
680 EFIAPI
681 UfsHcDriverEntry (
682 IN EFI_HANDLE ImageHandle,
683 IN EFI_SYSTEM_TABLE *SystemTable
684 )
685 {
686 EFI_STATUS Status;
687
688 Status = EfiLibInstallDriverBindingComponentName2 (
689 ImageHandle,
690 SystemTable,
691 &gUfsHcDriverBinding,
692 ImageHandle,
693 &gUfsHcComponentName,
694 &gUfsHcComponentName2
695 );
696 ASSERT_EFI_ERROR (Status);
697
698 return Status;
699 }