]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellDriver1CommandsLib/Devices.c
add comments to function declarations and definitions and updated to match coding...
[mirror_edk2.git] / ShellPkg / Library / UefiShellDriver1CommandsLib / Devices.c
index 485458f25c9b0f46899030c97c8361d85aa066c0..a6e27e93dac620566f063a1cfc13ffdac6f048a5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Main file for devices shell Driver1 function.\r
 \r
-  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
   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
 #include "UefiShellDriver1CommandsLib.h"\r
 \r
+/**\r
+  Get lots of info about a device from its handle.\r
+\r
+  @param[in] TheHandle      The device handle to get info on.\r
+  @param[in,out] Type       On successful return R, B, or D (root, bus, or \r
+                            device) will be placed in this buffer.\r
+  @param[in,out] Cfg        On successful return this buffer will be \r
+                            TRUE if the handle has configuration, FALSE\r
+                            otherwise.\r
+  @param[in,out] Diag       On successful return this buffer will be \r
+                            TRUE if the handle has disgnostics, FALSE\r
+                            otherwise.\r
+  @param[in,out] Parents    On successful return this buffer will be \r
+                            contain the number of parent handles.\r
+  @param[in,out] Devices    On successful return this buffer will be \r
+                            contain the number of devices controlled.\r
+  @param[in,out] Children   On successful return this buffer will be \r
+                            contain the number of child handles.\r
+  @param[out] Name          The pointer to a buffer that will be allocated\r
+                            and contain the string name of the handle.\r
+                            The caller must free this memory.\r
+  @param[in] Language       The language code as defined by the UEFI spec.\r
+\r
+  @retval EFI_SUCCESS           The info is there.\r
+  @retval EFI_INVALID_PARAMETER A parameter was invalid.\r
+**/\r
 EFI_STATUS\r
 EFIAPI\r
 GetDeviceHandleInfo (\r
   IN EFI_HANDLE   TheHandle,\r
-  IN CHAR16       *Type,\r
-  IN BOOLEAN      *Cfg,\r
-  IN BOOLEAN      *Diag,\r
-  IN UINT8        *Parents,\r
-  IN UINT8        *Devices,\r
-  IN UINT8        *Children,\r
+  IN OUT CHAR16   *Type,\r
+  IN OUT BOOLEAN  *Cfg,\r
+  IN OUT BOOLEAN  *Diag,\r
+  IN OUT UINTN    *Parents,\r
+  IN OUT UINTN    *Devices,\r
+  IN OUT UINTN    *Children,\r
   OUT CHAR16      **Name,\r
   IN CONST CHAR8  *Language\r
-  ){\r
-  *Name = NULL;\r
-\r
-  gEfiShellProtocol->GetDeviceName(TheHandle, EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, Name);\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
-\r
+  )\r
+{\r
+  EFI_STATUS    Status;\r
+  EFI_HANDLE    *HandleBuffer;\r
+  UINTN         Count;\r
+\r
+  if (TheHandle == NULL \r
+    || Type == NULL\r
+    || Cfg == NULL\r
+    || Diag == NULL\r
+    || Parents == NULL\r
+    || Devices == NULL\r
+    || Children == NULL\r
+    || Name == NULL ) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
+  *Cfg          = FALSE;\r
+  *Diag         = FALSE;\r
+  *Children     = 0;\r
+  *Parents      = 0;\r
+  *Devices      = 0;\r
+  *Type         = L' ';\r
+  *Name         = CHAR_NULL;\r
+  HandleBuffer  = NULL;\r
+  Status        = EFI_SUCCESS;\r
 \r
+  gEfiShellProtocol->GetDeviceName(TheHandle, EFI_DEVICE_NAME_USE_COMPONENT_NAME|EFI_DEVICE_NAME_USE_DEVICE_PATH, (CHAR8*)Language, Name);\r
 \r
+  Status = ParseHandleDatabaseForChildControllers(TheHandle, Children, NULL);\r
+//  if (!EFI_ERROR(Status)) {\r
+    Status = PARSE_HANDLE_DATABASE_PARENTS(TheHandle, Parents, NULL);\r
+    if (/*!EFI_ERROR(Status) && */Parents != NULL && Children != NULL) {\r
+      if (*Parents == 0) {\r
+        *Type = L'R';\r
+      } else if (*Children > 0) {\r
+        *Type = L'B';\r
+      } else {\r
+        *Type = L'D';\r
+      }\r
+    }\r
+//  }\r
+  Status = PARSE_HANDLE_DATABASE_UEFI_DRIVERS(TheHandle, Devices, &HandleBuffer);\r
+  if (!EFI_ERROR(Status) && Devices != NULL && HandleBuffer != NULL) {\r
+    for (Count = 0 ; Count < *Devices ; Count++) {\r
+      if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverConfigurationProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {\r
+        *Cfg = TRUE;\r
+      }\r
+      if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverDiagnosticsProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {\r
+        *Diag = TRUE;\r
+      }\r
+      if (!EFI_ERROR(gBS->OpenProtocol(HandleBuffer[Count], &gEfiDriverDiagnostics2ProtocolGuid, NULL, NULL, gImageHandle, EFI_OPEN_PROTOCOL_TEST_PROTOCOL))) {\r
+        *Diag = TRUE;\r
+      }\r
+    }\r
+    SHELL_FREE_NON_NULL(HandleBuffer);\r
+  }\r
 \r
-  return (EFI_SUCCESS);\r
+  return (Status);\r
 }\r
 \r
 STATIC CONST SHELL_PARAM_ITEM ParamList[] = {\r
@@ -51,11 +118,19 @@ STATIC CONST SHELL_PARAM_ITEM ParamList[] = {
   {NULL, TypeMax}\r
   };\r
 \r
+/**\r
+  Function for 'devices' command.\r
+\r
+  @param[in] ImageHandle  Handle to the Image (NULL if Internal).\r
+  @param[in] SystemTable  Pointer to the System Table (NULL if Internal).\r
+**/\r
 SHELL_STATUS\r
 EFIAPI\r
 ShellCommandRunDevices (\r
-  VOID                *RESERVED\r
-  ) {\r
+  IN EFI_HANDLE        ImageHandle,\r
+  IN EFI_SYSTEM_TABLE  *SystemTable\r
+  )\r
+{\r
   EFI_STATUS          Status;\r
   LIST_ENTRY          *Package;\r
   CHAR16              *ProblemParam;\r
@@ -66,10 +141,11 @@ ShellCommandRunDevices (
   CHAR16              Type;\r
   BOOLEAN             Cfg;\r
   BOOLEAN             Diag;\r
-  UINT8               Parents;\r
-  UINT8               Devices;\r
-  UINT8               Children;\r
+  UINTN               Parents;\r
+  UINTN               Devices;\r
+  UINTN               Children;\r
   CHAR16              *Name;\r
+  CONST CHAR16        *Lang;\r
 \r
   ShellStatus         = SHELL_SUCCESS;\r
   Language            = NULL;\r
@@ -87,7 +163,7 @@ ShellCommandRunDevices (
   // parse the command line\r
   //\r
   Status = ShellCommandLineParse (ParamList, &Package, &ProblemParam, TRUE);\r
-  if EFI_ERROR(Status) {\r
+  if (EFI_ERROR(Status)) {\r
     if (Status == EFI_VOLUME_CORRUPTED && ProblemParam != NULL) {\r
       ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_PROBLEM), gShellDriver1HiiHandle, ProblemParam);\r
       FreePool(ProblemParam);\r
@@ -109,11 +185,22 @@ ShellCommandRunDevices (
       //\r
       // get the language if necessary\r
       //\r
-      if (ShellCommandLineGetFlag(Package, L"-l") != FALSE) {\r
-        Language = AllocateZeroPool(StrSize(ShellCommandLineGetValue(Package, L"-l")));\r
-        AsciiSPrint(Language, StrSize(ShellCommandLineGetValue(Package, L"-l")), "%S", ShellCommandLineGetValue(Package, L"-l"));\r
+      Lang = ShellCommandLineGetValue(Package, L"-l");\r
+      if (Lang != NULL) {\r
+        Language = AllocateZeroPool(StrSize(Lang));\r
+        AsciiSPrint(Language, StrSize(Lang), "%S", Lang);\r
+      } else if (!ShellCommandLineGetFlag(Package, L"-l")){\r
+        ASSERT(Language == NULL);\r
+//        Language = AllocateZeroPool(10);\r
+//        AsciiSPrint(Language, 10, "en-us");\r
+      } else {\r
+        ASSERT(Language == NULL);\r
+        ShellPrintHiiEx(-1, -1, NULL, STRING_TOKEN (STR_GEN_NO_VALUE), gShellDriver1HiiHandle, L"-l");\r
+        ShellCommandLineFreeVarList (Package);\r
+        return (SHELL_INVALID_PARAMETER);\r
       }\r
 \r
+\r
       //\r
       // Print Header\r
       //\r
@@ -122,31 +209,33 @@ ShellCommandRunDevices (
       //\r
       // loop through each handle\r
       //\r
-      HandleList = GetHandleListByPotocol(NULL);\r
+      HandleList = GetHandleListByProtocol(NULL);\r
       ASSERT(HandleList != NULL);\r
       for (HandleListWalker = HandleList\r
-        ;  HandleListWalker != NULL && *HandleListWalker != NULL && !EFI_ERROR(Status)\r
+        ;  HandleListWalker != NULL && *HandleListWalker != NULL /*&& !EFI_ERROR(Status)*/\r
         ;  HandleListWalker++\r
-        ){\r
+       ){\r
+\r
         //\r
         // get all the info on each handle\r
         //\r
+        Name = NULL;\r
         Status = GetDeviceHandleInfo(*HandleListWalker, &Type, &Cfg, &Diag, &Parents, &Devices, &Children, &Name, Language);\r
-        if (Parents != 0 || Devices != 0 || Children != 0) {\r
+        if (Name != NULL && (Parents != 0 || Devices != 0 || Children != 0)) {\r
           ShellPrintHiiEx(\r
             -1,\r
             -1,\r
             Language,\r
             STRING_TOKEN (STR_DEVICES_ITEM_LINE),\r
             gShellDriver1HiiHandle,\r
-            *HandleListWalker,\r
+            ConvertHandleToHandleIndex(*HandleListWalker),\r
             Type,\r
-            Cfg!=FALSE?L'X':L'-',\r
-            Diag!=FALSE?L'X':L'-',\r
+            Cfg?L'X':L'-',\r
+            Diag?L'X':L'-',\r
             Parents,\r
             Devices,\r
             Children,\r
-            Name);\r
+            Name!=NULL?Name:L"<UNKNOWN>");\r
         }\r
         if (Name != NULL) {\r
           FreePool(Name);\r
@@ -156,7 +245,9 @@ ShellCommandRunDevices (
       if (HandleList != NULL) {\r
         FreePool(HandleList);\r
       }\r
\r
     }\r
+    SHELL_FREE_NON_NULL(Language);\r
     ShellCommandLineFreeVarList (Package);\r
   }\r
   return (ShellStatus);\r