]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Ufs/UfsPassThruDxe/UfsPassThru.c
MdeModulePkg/UfsPassThruDxe: Check for RPMB W-LUN (SecurityLun)
[mirror_edk2.git] / MdeModulePkg / Bus / Ufs / UfsPassThruDxe / UfsPassThru.c
index 1518b251d88a903ded02bf4d7fad1cfb313b2c46..26c5a8b8555498d9fef8dab654e9058e45d41222 100644 (file)
@@ -1,6 +1,6 @@
 /** @file\r
 \r
-  Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2014 - 2019, Intel Corporation. All rights reserved.<BR>\r
   SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
@@ -35,7 +35,8 @@ UFS_PASS_THRU_PRIVATE_DATA gUfsPassThruTemplate = {
   },\r
   0,                              // UfsHostController\r
   0,                              // UfsHcBase\r
-  0,                              // Capabilities\r
+  {0, 0},                         // UfsHcInfo\r
+  {NULL, NULL},                   // UfsHcDriverInterface\r
   0,                              // TaskTag\r
   0,                              // UtpTrlBase\r
   0,                              // Nutrs\r
@@ -92,6 +93,8 @@ UFS_DEVICE_PATH    mUfsDevicePathTemplate = {
 \r
 UINT8 mUfsTargetId[TARGET_MAX_BYTES];\r
 \r
+GLOBAL_REMOVE_IF_UNREFERENCED EDKII_UFS_HC_PLATFORM_PROTOCOL  *mUfsHcPlatform;\r
+\r
 /**\r
   Sends a SCSI Request Packet to a SCSI device that is attached to the SCSI channel. This function\r
   supports both blocking I/O and nonblocking I/O. The blocking I/O functionality is required, and the\r
@@ -819,7 +822,9 @@ UfsPassThruDriverBindingStart (
   UINTN                                 UfsHcBase;\r
   UINT32                                Index;\r
   UFS_UNIT_DESC                         UnitDescriptor;\r
+  UFS_DEV_DESC                          DeviceDescriptor;\r
   UINT32                                UnitDescriptorSize;\r
+  UINT32                                DeviceDescriptorSize;\r
 \r
   Status    = EFI_SUCCESS;\r
   UfsHc     = NULL;\r
@@ -864,8 +869,27 @@ UfsPassThruDriverBindingStart (
   Private->ExtScsiPassThru.Mode = &Private->ExtScsiPassThruMode;\r
   Private->UfsHostController    = UfsHc;\r
   Private->UfsHcBase            = UfsHcBase;\r
+  Private->Handle               = Controller;\r
+  Private->UfsHcDriverInterface.UfsHcProtocol = UfsHc;\r
+  Private->UfsHcDriverInterface.UfsExecUicCommand = UfsHcDriverInterfaceExecUicCommand;\r
   InitializeListHead (&Private->Queue);\r
 \r
+  //\r
+  // This has to be done before initializing UfsHcInfo or calling the UfsControllerInit\r
+  //\r
+  if (mUfsHcPlatform == NULL) {\r
+    Status = gBS->LocateProtocol (&gEdkiiUfsHcPlatformProtocolGuid, NULL, (VOID**)&mUfsHcPlatform);\r
+    if (EFI_ERROR (Status)) {\r
+      DEBUG ((DEBUG_INFO, "No UfsHcPlatformProtocol present\n"));\r
+    }\r
+  }\r
+\r
+  Status = GetUfsHcInfo (Private);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "Failed to initialize UfsHcInfo\n"));\r
+    goto Error;\r
+  }\r
+\r
   //\r
   // Initialize UFS Host Controller H/W.\r
   //\r
@@ -894,7 +918,6 @@ UfsPassThruDriverBindingStart (
 \r
   //\r
   // Check if 8 common luns are active and set corresponding bit mask.\r
-  // TODO: Parse device descriptor to decide if exposing RPMB LUN to upper layer for authentication access.\r
   //\r
   UnitDescriptorSize = sizeof (UFS_UNIT_DESC);\r
   for (Index = 0; Index < 8; Index++) {\r
@@ -909,6 +932,20 @@ UfsPassThruDriverBindingStart (
     }\r
   }\r
 \r
+  //\r
+  // Check if RPMB WLUN is supported and set corresponding bit mask.\r
+  //\r
+  DeviceDescriptorSize = sizeof (UFS_DEV_DESC);\r
+  Status = UfsRwDeviceDesc (Private, TRUE, UfsDeviceDesc, 0, 0, &DeviceDescriptor, &DeviceDescriptorSize);\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_ERROR, "Failed to read device descriptor, status = %r\n", Status));\r
+  } else {\r
+    if (DeviceDescriptor.SecurityLun == 0x1) {\r
+      DEBUG ((DEBUG_INFO, "UFS WLUN RPMB is supported\n"));\r
+      Private->Luns.BitMask |= BIT11;\r
+    }\r
+  }\r
+\r
   //\r
   // Start the asynchronous interrupt monitor\r
   //\r