]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.c
ShellPkg/dh: Modify the dump of PciIo protocol
[mirror_edk2.git] / ShellPkg / Library / UefiHandleParsingLib / UefiHandleParsingLib.c
index 1c62415e8630f60d7756b9be0b5554b50e3366d5..e5b4bea8f69e83a9ee1f844eaa6dc7eddcb0d1f7 100644 (file)
@@ -16,6 +16,7 @@
 \r
 #include "UefiHandleParsingLib.h"\r
 #include "IndustryStandard/Acpi10.h"\r
+#include "IndustryStandard/Pci.h"\r
 #include <PiDxe.h>\r
 #include <Protocol/FirmwareVolume2.h>\r
 \r
@@ -1159,6 +1160,90 @@ DebugSupportProtocolDumpInformation (
   return RetVal;\r
 }\r
 \r
+/**\r
+  Function to dump information about PciIoProtocol.\r
+\r
+  This will allocate the return buffer from boot services pool.\r
+\r
+  @param[in] TheHandle      The handle that has PciRootBridgeIo installed.\r
+  @param[in] Verbose        TRUE for additional information, FALSE otherwise.\r
+\r
+  @retval A poitner to a string containing the information.\r
+**/\r
+CHAR16*\r
+EFIAPI\r
+PciIoProtocolDumpInformation (\r
+  IN CONST EFI_HANDLE TheHandle,\r
+  IN CONST BOOLEAN    Verbose\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_PCI_IO_PROTOCOL     *PciIo;\r
+  PCI_TYPE00              Pci;\r
+  UINTN                   Segment;\r
+  UINTN                   Bus;\r
+  UINTN                   Device;\r
+  UINTN                   Function;\r
+  UINTN                   Index;\r
+  CHAR16                  *GetString;\r
+  CHAR16                  *TempRetVal;\r
+  CHAR16                  *RetVal;\r
+\r
+  if (!Verbose) {\r
+    return (NULL);\r
+  }\r
+  RetVal = NULL;\r
+  GetString   = NULL;\r
+  TempRetVal  = NULL;\r
+  Status = gBS->OpenProtocol (\r
+                  TheHandle,\r
+                  &gEfiPciIoProtocolGuid,\r
+                  (VOID**)&PciIo,\r
+                  gImageHandle,\r
+                  NULL,\r
+                  EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
+                  );\r
+\r
+  if (EFI_ERROR(Status)) {\r
+    return NULL;\r
+  }\r
+  PciIo->Pci.Read (PciIo, EfiPciIoWidthUint8, 0, sizeof (Pci), &Pci);\r
+  PciIo->GetLocation (PciIo, &Segment, &Bus, &Device, &Function);\r
+  HandleParsingHiiInit ();\r
+  GetString = HiiGetString (mHandleParsingHiiHandle, STRING_TOKEN(STR_PCIIO_DUMP_MAIN), NULL);\r
+  if (GetString == NULL) {\r
+    return NULL;\r
+  }\r
+  RetVal = CatSPrint (\r
+            NULL,\r
+            GetString,\r
+            Segment,\r
+            Bus,\r
+            Device,\r
+            Function,\r
+            PciIo->RomSize,\r
+            PciIo->RomImage,\r
+            Pci.Hdr.VendorId,\r
+            Pci.Hdr.DeviceId,\r
+            Pci.Hdr.ClassCode[0],\r
+            Pci.Hdr.ClassCode[1],\r
+            Pci.Hdr.ClassCode[2]\r
+            );\r
+  for (Index = 0; Index < sizeof (Pci); Index ++) {\r
+    if ((Index % 0x10) == 0) {\r
+      TempRetVal = CatSPrint (RetVal, L"\r\n       %02x", *((UINT8 *) (&Pci) + Index));\r
+    } else {\r
+      TempRetVal = CatSPrint (RetVal, L"%02x", *((UINT8 *) (&Pci) + Index));\r
+    }\r
+    FreePool (RetVal);\r
+    RetVal = TempRetVal;\r
+    TempRetVal = NULL;\r
+  }\r
+\r
+  FreePool(GetString);\r
+  return RetVal;\r
+}\r
+\r
 /**\r
   Function to dump information about EfiAdapterInformation Protocol.\r
 \r
@@ -1874,7 +1959,7 @@ STATIC CONST GUID_INFO_BLOCK mGuidStringList[] = {
   {STRING_TOKEN(STR_UC),                    &gEfiUnicodeCollationProtocolGuid,                NULL},\r
   {STRING_TOKEN(STR_UC2),                   &gEfiUnicodeCollation2ProtocolGuid,               NULL},\r
   {STRING_TOKEN(STR_PCIRB_IO),              &gEfiPciRootBridgeIoProtocolGuid,                 PciRootBridgeIoDumpInformation},\r
-  {STRING_TOKEN(STR_PCI_IO),                &gEfiPciIoProtocolGuid,                           NULL},\r
+  {STRING_TOKEN(STR_PCI_IO),                &gEfiPciIoProtocolGuid,                           PciIoProtocolDumpInformation},\r
   {STRING_TOKEN(STR_SCSI_PT),               &gEfiScsiPassThruProtocolGuid,                    NULL},\r
   {STRING_TOKEN(STR_SCSI_IO),               &gEfiScsiIoProtocolGuid,                          NULL},\r
   {STRING_TOKEN(STR_SCSI_PT_EXT),           &gEfiExtScsiPassThruProtocolGuid,                 NULL},\r