]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmbeddedPkg/Universal/MmcDxe/Diagnostics.c
MmcDxe: Perform diagnostics specifically on the requested controller
[mirror_edk2.git] / EmbeddedPkg / Universal / MmcDxe / Diagnostics.c
index 516c832bb58cae03baeb4537d3872cf30e6015b9..310b7cc820befbff0a214d5547172af4d13741ab 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Diagnostics Protocol implementation for the MMC DXE driver\r
 \r
-  Copyright (c) 2011, ARM Limited. All rights reserved.\r
+  Copyright (c) 2011-2014, ARM Limited. All rights reserved.\r
   \r
   This program and the accompanying materials                          \r
   are licensed and made available under the terms and conditions of the BSD License         \r
@@ -17,6 +17,7 @@
 #include <Library/DebugLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/MemoryAllocationLib.h>\r
+#include <Library/BaseLib.h>\r
 \r
 #include "Mmc.h"\r
 \r
@@ -31,7 +32,7 @@ DiagnosticInitLog (
   )\r
 {\r
   mLogRemainChar = MaxBufferChar;\r
-  mLogBuffer = AllocatePool ((UINTN)MaxBufferChar * sizeof(CHAR16));\r
+  mLogBuffer = AllocatePool ((UINTN)MaxBufferChar * sizeof (CHAR16));\r
   return mLogBuffer;\r
 }\r
 \r
@@ -79,8 +80,8 @@ CompareBuffer (
 \r
   for (i = 0; i < (BufferSize >> 3); i++) {\r
     if (*BufferA64 != *BufferB64) {\r
-      DEBUG((EFI_D_ERROR, "CompareBuffer: Error at %i", i));\r
-      DEBUG((EFI_D_ERROR, "(0x%lX) != (0x%lX)\n", *BufferA64, *BufferB64));\r
+      DEBUG ((EFI_D_ERROR, "CompareBuffer: Error at %i", i));\r
+      DEBUG ((EFI_D_ERROR, "(0x%lX) != (0x%lX)\n", *BufferA64, *BufferB64));\r
       return FALSE;\r
     }\r
     BufferA64++;\r
@@ -192,6 +193,11 @@ MmcDriverDiagnosticsRunDiagnostics (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
+  // Check Language is supported (i.e. is "en-*" - only English is supported)\r
+  if (AsciiStrnCmp (Language, "en", 2) != 0) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
+\r
   Status = EFI_SUCCESS;\r
   *ErrorType  = NULL;\r
   *BufferSize = DIAGNOSTIC_LOGBUFFER_MAXCHAR;\r
@@ -199,34 +205,43 @@ MmcDriverDiagnosticsRunDiagnostics (
 \r
   DiagnosticLog (L"MMC Driver Diagnostics\n");\r
 \r
-  // For each MMC instance\r
+  // Find the MMC Host instance on which we have been asked to run diagnostics\r
+  MmcHostInstance = NULL;\r
   CurrentLink = mMmcHostPool.ForwardLink;\r
   while (CurrentLink != NULL && CurrentLink != &mMmcHostPool && (Status == EFI_SUCCESS)) {\r
     MmcHostInstance = MMC_HOST_INSTANCE_FROM_LINK(CurrentLink);\r
     ASSERT(MmcHostInstance != NULL);\r
+    if (MmcHostInstance->MmcHandle == ControllerHandle) {\r
+      break;\r
+    }\r
+    CurrentLink = CurrentLink->ForwardLink;\r
+  }\r
 \r
-    // LBA=1 Size=BlockSize\r
-    DiagnosticLog (L"MMC Driver Diagnostics - Test: First Block\n");\r
-    Status = MmcReadWriteDataTest (MmcHostInstance, 1, MmcHostInstance->BlockIo.Media->BlockSize);\r
+  // If we didn't find the controller, return EFI_UNSUPPORTED\r
+  if ((MmcHostInstance == NULL)\r
+      || (MmcHostInstance->MmcHandle != ControllerHandle)) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
-    // LBA=2 Size=BlockSize\r
-    DiagnosticLog (L"MMC Driver Diagnostics - Test: Second Block\n");\r
-    Status = MmcReadWriteDataTest (MmcHostInstance, 2, MmcHostInstance->BlockIo.Media->BlockSize);\r
+  // LBA=1 Size=BlockSize\r
+  DiagnosticLog (L"MMC Driver Diagnostics - Test: First Block\n");\r
+  Status = MmcReadWriteDataTest (MmcHostInstance, 1, MmcHostInstance->BlockIo.Media->BlockSize);\r
 \r
-    // LBA=10 Size=BlockSize\r
-    DiagnosticLog (L"MMC Driver Diagnostics - Test: Any Block\n");\r
-    Status = MmcReadWriteDataTest (MmcHostInstance, MmcHostInstance->BlockIo.Media->LastBlock >> 1, MmcHostInstance->BlockIo.Media->BlockSize);\r
+  // LBA=2 Size=BlockSize\r
+  DiagnosticLog (L"MMC Driver Diagnostics - Test: Second Block\n");\r
+  Status = MmcReadWriteDataTest (MmcHostInstance, 2, MmcHostInstance->BlockIo.Media->BlockSize);\r
 \r
-    // LBA=LastBlock Size=BlockSize\r
-    DiagnosticLog (L"MMC Driver Diagnostics - Test: Last Block\n");\r
-    Status = MmcReadWriteDataTest (MmcHostInstance, MmcHostInstance->BlockIo.Media->LastBlock, MmcHostInstance->BlockIo.Media->BlockSize);\r
+  // LBA=10 Size=BlockSize\r
+  DiagnosticLog (L"MMC Driver Diagnostics - Test: Any Block\n");\r
+  Status = MmcReadWriteDataTest (MmcHostInstance, MmcHostInstance->BlockIo.Media->LastBlock >> 1, MmcHostInstance->BlockIo.Media->BlockSize);\r
 \r
-    // LBA=1 Size=2*BlockSize\r
-    DiagnosticLog (L"MMC Driver Diagnostics - Test: First Block / 2 BlockSSize\n");\r
-    Status = MmcReadWriteDataTest (MmcHostInstance, 1, 2*MmcHostInstance->BlockIo.Media->BlockSize);\r
+  // LBA=LastBlock Size=BlockSize\r
+  DiagnosticLog (L"MMC Driver Diagnostics - Test: Last Block\n");\r
+  Status = MmcReadWriteDataTest (MmcHostInstance, MmcHostInstance->BlockIo.Media->LastBlock, MmcHostInstance->BlockIo.Media->BlockSize);\r
 \r
-    CurrentLink = CurrentLink->ForwardLink;\r
-  }\r
+  // LBA=1 Size=2*BlockSize\r
+  DiagnosticLog (L"MMC Driver Diagnostics - Test: First Block / 2 BlockSSize\n");\r
+  Status = MmcReadWriteDataTest (MmcHostInstance, 1, 2 * MmcHostInstance->BlockIo.Media->BlockSize);\r
 \r
   return Status;\r
 }\r