]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Bus/Pci/IdeBusDxe/DriverDiagnostics.c
Update in IdeBus to solve the non-backward compatibility issue by the MdePkg updates...
[mirror_edk2.git] / IntelFrameworkModulePkg / Bus / Pci / IdeBusDxe / DriverDiagnostics.c
index 8aa6d057125f5d45b5e6827b45a124b8843f9761..5e1383c0c265b9cf4d09fd72ce3f6352ea570a8a 100644 (file)
@@ -1,5 +1,8 @@
 /** @file\r
-  Copyright (c) 2006, Intel Corporation                                                         \r
+  Implementation of UEFI driver Dialnostics protocol which to perform diagnostic on the IDE\r
+  Bus controller.\r
+  \r
+  Copyright (c) 2006 - 2008, Intel Corporation                                                         \r
   All rights reserved. This program and the accompanying materials                          \r
   are licensed and made available under the terms and conditions of the BSD License         \r
   which accompanies this distribution.  The full text of the license may be found at        \r
 **/\r
 \r
 \r
-#include "idebus.h"\r
+#include "IdeBus.h"\r
 \r
 #define IDE_BUS_DIAGNOSTIC_ERROR  L"PCI IDE/ATAPI Driver Diagnostics Failed"\r
 \r
 //\r
 // EFI Driver Diagnostics Protocol\r
 //\r
-EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics = {\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS_PROTOCOL gIDEBusDriverDiagnostics = {\r
   IDEBusDriverDiagnosticsRunDiagnostics,\r
   "eng"\r
 };\r
 \r
+//\r
+// EFI Driver Diagnostics 2 Protocol\r
+//\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_DRIVER_DIAGNOSTICS2_PROTOCOL gIDEBusDriverDiagnostics2 = {\r
+  (EFI_DRIVER_DIAGNOSTICS2_RUN_DIAGNOSTICS) IDEBusDriverDiagnosticsRunDiagnostics,\r
+  "en"\r
+};\r
+\r
 /**\r
   Runs diagnostics on a controller.\r
 \r
-  @param  This A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOL\r
-  instance.\r
+  @param  This             A pointer to the EFI_DRIVER_DIAGNOSTICS_PROTOCOLinstance.\r
   @param  ControllerHandle The handle of the controller to run diagnostics on.\r
-  @param  ChildHandle The handle of the child controller to run diagnostics on\r
-  This is an optional parameter that may be NULL.  It will\r
-  be NULL for device drivers.  It will also be NULL for a\r
-  bus drivers that wish to run diagnostics on the bus\r
-  controller.  It will not be NULL for a bus driver that\r
-  wishes to run diagnostics on one of its child\r
-  controllers.\r
-  @param  DiagnosticType Indicates type of diagnostics to perform on the\r
-  controller specified by ControllerHandle and ChildHandle.\r
-  See "Related Definitions" for the list of supported\r
-  types.\r
-  @param  Language A pointer to a three character ISO 639-2 language\r
-  identifier.  This is the language in which the optional\r
-  error message should be returned in Buffer, and it must\r
-  match one of the languages specified in\r
-  SupportedLanguages. The number of languages supported by\r
-  a driver is up to the driver writer.\r
-  @param  ErrorType A GUID that defines the format of the data returned in\r
-  Buffer.\r
-  @param  BufferSize The size, in bytes, of the data returned in Buffer.\r
-  @param  Buffer A buffer that contains a Null-terminated Unicode string\r
-  plus some additional data whose format is defined by\r
-  ErrorType.  Buffer is allocated by this function with\r
-  AllocatePool(), and it is the caller's responsibility\r
-  to free it with a call to FreePool().\r
-\r
-  @retval  EFI_SUCCESS The controller specified by ControllerHandle and\r
-  ChildHandle passed the diagnostic.\r
+  @param  ChildHandle      The handle of the child controller to run diagnostics on\r
+                           This is an optional parameter that may be NULL.  It will\r
+                           be NULL for device drivers.  It will also be NULL for a\r
+                           bus drivers that wish to run diagnostics on the bus controller. \r
+                           It will not be NULL for a bus driver that wishes to run \r
+                           diagnostics on one of its child controllers.\r
+  @param  DiagnosticType   Indicates type of diagnostics to perform on the controller\r
+                           specified by ControllerHandle and ChildHandle.\r
+  @param  Language         A pointer to a three character ISO 639-2 language identifier. \r
+                           This is the language in which the optional error message should \r
+                           be returned in Buffer, and it must match one of the languages \r
+                           specified in SupportedLanguages. The number of languages supported by\r
+                           a driver is up to the driver writer.\r
+  @param  ErrorType        A GUID that defines the format of the data returned in Buffer.\r
+  @param  BufferSize       The size, in bytes, of the data returned in Buffer.\r
+  @param  Buffer           A buffer that contains a Null-terminated Unicode string\r
+                           plus some additional data whose format is defined by ErrorType.  \r
+                           Buffer is allocated by this function with AllocatePool(), and \r
+                           it is the caller's responsibility to free it with a call to FreePool().\r
+\r
+  @retval  EFI_SUCCESS           The controller specified by ControllerHandle and ChildHandle passed \r
+                                 the diagnostic.\r
   @retval  EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.\r
-  @retval  EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid\r
-  EFI_HANDLE.\r
+  @retval  EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid EFI_HANDLE.\r
   @retval  EFI_INVALID_PARAMETER Language is NULL.\r
   @retval  EFI_INVALID_PARAMETER ErrorType is NULL.\r
   @retval  EFI_INVALID_PARAMETER BufferType is NULL.\r
   @retval  EFI_INVALID_PARAMETER Buffer is NULL.\r
-  @retval  EFI_UNSUPPORTED The driver specified by This does not support\r
-  running diagnostics for the controller specified\r
-  by ControllerHandle and ChildHandle.\r
-  @retval  EFI_UNSUPPORTED The driver specified by This does not support the\r
-  type of diagnostic specified by DiagnosticType.\r
-  @retval  EFI_UNSUPPORTED The driver specified by This does not support the\r
-  language specified by Language.\r
-  @retval  EFI_OUT_OF_RESOURCES There are not enough resources available to complete\r
-  the diagnostics.\r
-  @retval  EFI_OUT_OF_RESOURCES There are not enough resources available to return\r
-  the status information in ErrorType, BufferSize,\r
-  and Buffer.\r
-  @retval  EFI_DEVICE_ERROR The controller specified by ControllerHandle and\r
-  ChildHandle did not pass the diagnostic.\r
-\r
+  @retval  EFI_UNSUPPORTED       The driver specified by This does not support running \r
+                                 diagnostics for the controller specified by ControllerHandle \r
+                                 and ChildHandle.\r
+  @retval  EFI_UNSUPPORTED       The driver specified by This does not support the\r
+                                 type of diagnostic specified by DiagnosticType.\r
+  @retval  EFI_UNSUPPORTED       The driver specified by This does not support the language \r
+                                 specified by Language.\r
+  @retval  EFI_OUT_OF_RESOURCES  There are not enough resources available to complete the \r
+                                 diagnostics.\r
+  @retval  EFI_OUT_OF_RESOURCES  There are not enough resources available to return the \r
+                                 status information in ErrorType, BufferSize,and Buffer.\r
+  @retval  EFI_DEVICE_ERROR      The controller specified by ControllerHandle and ChildHandle \r
+                                 did not pass the diagnostic.\r
 **/\r
 EFI_STATUS\r
+EFIAPI\r
 IDEBusDriverDiagnosticsRunDiagnostics (\r
   IN  EFI_DRIVER_DIAGNOSTICS_PROTOCOL               *This,\r
   IN  EFI_HANDLE                                    ControllerHandle,\r
@@ -98,6 +100,49 @@ IDEBusDriverDiagnosticsRunDiagnostics (
   IDE_BLK_IO_DEV        *IdeBlkIoDevice;\r
   UINT32                VendorDeviceId;\r
   VOID                  *BlockBuffer;\r
+  CHAR8                 *SupportedLanguages;\r
+  BOOLEAN               Iso639Language;\r
+  BOOLEAN               Found;\r
+  UINTN                 Index;\r
+\r
+  if (Language         == NULL ||\r
+      ErrorType        == NULL ||\r
+      Buffer           == NULL ||\r
+      ControllerHandle == NULL ||\r
+      BufferSize       == NULL) {\r
+\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  SupportedLanguages = This->SupportedLanguages;\r
+  Iso639Language = (BOOLEAN)(This == &gIDEBusDriverDiagnostics);\r
+  //\r
+  // Make sure Language is in the set of Supported Languages\r
+  //\r
+  Found = FALSE;\r
+  while (*SupportedLanguages != 0) {\r
+    if (Iso639Language) {\r
+      if (CompareMem (Language, SupportedLanguages, 3) == 0) {\r
+        Found = TRUE;\r
+        break;\r
+      }\r
+      SupportedLanguages += 3;\r
+    } else {\r
+      for (Index = 0; SupportedLanguages[Index] != 0 && SupportedLanguages[Index] != ';'; Index++);\r
+      if ((AsciiStrnCmp(SupportedLanguages, Language, Index) == 0) && (Language[Index] == 0)) {\r
+        Found = TRUE;\r
+        break;\r
+      }\r
+      SupportedLanguages += Index;\r
+      for (; *SupportedLanguages != 0 && *SupportedLanguages == ';'; SupportedLanguages++);\r
+    }\r
+  }\r
+  //\r
+  // If Language is not a member of SupportedLanguages, then return EFI_UNSUPPORTED\r
+  //\r
+  if (!Found) {\r
+    return EFI_UNSUPPORTED;\r
+  }\r
 \r
   *ErrorType  = NULL;\r
   *BufferSize = 0;\r
@@ -112,7 +157,7 @@ IDEBusDriverDiagnosticsRunDiagnostics (
                     EFI_OPEN_PROTOCOL_TEST_PROTOCOL\r
                     );\r
     if (EFI_ERROR (Status)) {\r
-      return EFI_UNSUPPORTED;\r
+      return Status;\r
     }\r
 \r
     Status = gBS->OpenProtocol (\r
@@ -151,7 +196,7 @@ IDEBusDriverDiagnosticsRunDiagnostics (
                   EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
                   );\r
   if (EFI_ERROR (Status)) {\r
-    return EFI_UNSUPPORTED;\r
+    return Status;\r
   }\r
 \r
   IdeBlkIoDevice = IDE_BLOCK_IO_DEV_FROM_THIS (BlkIo);\r