]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkModulePkg/Library/GenericBdsLib/DevicePath.c
Minor code enhancement.
[mirror_edk2.git] / IntelFrameworkModulePkg / Library / GenericBdsLib / DevicePath.c
index 135fa63d1a018995d57a80f652243aad6115ded7..855b73b5025fa9a8357af9c326658be3bb7abaef 100644 (file)
@@ -2,7 +2,7 @@
   BDS internal function define the default device path string, it can be\r
   replaced by platform device path.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation. <BR>\r
+Copyright (c) 2004 - 2009, Intel Corporation. <BR>\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
@@ -20,7 +20,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
   The caller must free the resulting buffer.\r
 \r
   @param  Str      Tracks the allocated pool, size in use, and amount of pool allocated.\r
-  @param  fmt      The format string\r
+  @param  Fmt      The format string\r
   @param  ...      The data will be printed.\r
 \r
   @return Allocated buffer with the formatted string printed in it.\r
@@ -32,7 +32,7 @@ CHAR16 *
 EFIAPI\r
 CatPrint (\r
   IN OUT POOL_PRINT   *Str,\r
-  IN CHAR16           *fmt,\r
+  IN CHAR16           *Fmt,\r
   ...\r
   )\r
 {\r
@@ -42,36 +42,36 @@ CatPrint (
 \r
   AppendStr = AllocateZeroPool (0x1000);\r
   if (AppendStr == NULL) {\r
-    return Str->str;\r
+    return Str->Str;\r
   }\r
 \r
-  VA_START (Args, fmt);\r
-  UnicodeVSPrint (AppendStr, 0x1000, fmt, Args);\r
+  VA_START (Args, Fmt);\r
+  UnicodeVSPrint (AppendStr, 0x1000, Fmt, Args);\r
   VA_END (Args);\r
-  if (NULL == Str->str) {\r
+  if (NULL == Str->Str) {\r
     StringSize   = StrSize (AppendStr);\r
-    Str->str  = AllocateZeroPool (StringSize);\r
-    ASSERT (Str->str != NULL);\r
+    Str->Str  = AllocateZeroPool (StringSize);\r
+    ASSERT (Str->Str != NULL);\r
   } else {\r
     StringSize = StrSize (AppendStr);\r
-    StringSize += (StrSize (Str->str) - sizeof (UINT16));\r
+    StringSize += (StrSize (Str->Str) - sizeof (UINT16));\r
 \r
-    Str->str = ReallocatePool (\r
-                StrSize (Str->str),\r
+    Str->Str = ReallocatePool (\r
+                StrSize (Str->Str),\r
                 StringSize,\r
-                Str->str\r
+                Str->Str\r
                 );\r
-    ASSERT (Str->str != NULL);\r
+    ASSERT (Str->Str != NULL);\r
   }\r
 \r
-  Str->maxlen = MAX_CHAR * sizeof (UINT16);\r
-  if (StringSize < Str->maxlen) {\r
-    StrCat (Str->str, AppendStr);\r
-    Str->len = StringSize - sizeof (UINT16);\r
+  Str->Maxlen = MAX_CHAR * sizeof (UINT16);\r
+  if (StringSize < Str->Maxlen) {\r
+    StrCat (Str->Str, AppendStr);\r
+    Str->Len = StringSize - sizeof (UINT16);\r
   }\r
 \r
   FreePool (AppendStr);\r
-  return Str->str;\r
+  return Str->Str;\r
 }\r
 \r
 /**\r
@@ -140,7 +140,7 @@ DevPathMemMap (
   CatPrint (\r
     Str,\r
     L"MemMap(%d:%lx-%lx)",\r
-    MemMap->MemoryType,\r
+    (UINTN) MemMap->MemoryType,\r
     MemMap->StartingAddress,\r
     MemMap->EndingAddress\r
     );\r
@@ -177,7 +177,6 @@ DevPathController (
 \r
 **/\r
 VOID\r
-EFIAPI\r
 DevPathVendor (\r
   IN OUT POOL_PRINT       *Str,\r
   IN VOID                 *DevPath\r
@@ -239,7 +238,7 @@ DevPathVendor (
         L"SAS(%lx,%lx,%x,",\r
         ((SAS_DEVICE_PATH *) Vendor)->SasAddress,\r
         ((SAS_DEVICE_PATH *) Vendor)->Lun,\r
-        ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort\r
+        (UINTN) ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort\r
         );\r
       Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);\r
       if ((Info & 0x0f) == 0) {\r
@@ -345,16 +344,12 @@ DevPathExtendedAcpi (
   UINT16                          Anchor;\r
   CHAR8                           *AsChar8Array;\r
 \r
-  ASSERT (Str != NULL);\r
-  ASSERT (DevPath != NULL);\r
-\r
   HIDSTRIdx    = 0;\r
   UIDSTRIdx    = 0;\r
   CIDSTRIdx    = 0;\r
   ExtendedAcpi = DevPath;\r
   Length       = (UINT16) DevicePathNodeLength ((EFI_DEVICE_PATH_PROTOCOL *) ExtendedAcpi);\r
 \r
-  ASSERT (Length >= 19);\r
   AsChar8Array = (CHAR8 *) ExtendedAcpi;\r
 \r
   //\r
@@ -492,8 +487,8 @@ DevPathAtapi (
   CatPrint (\r
     Str,\r
     L"Ata(%s,%s)",\r
-    Atapi->PrimarySecondary ? L"Secondary" : L"Primary",\r
-    Atapi->SlaveMaster ? L"Slave" : L"Master"\r
+    (Atapi->PrimarySecondary != 0)? L"Secondary" : L"Primary",\r
+    (Atapi->SlaveMaster != 0)? L"Slave" : L"Master"\r
     );\r
 }\r
 \r
@@ -560,7 +555,7 @@ DevPath1394 (
   F1394_DEVICE_PATH *F1394Path;\r
 \r
   F1394Path = DevPath;\r
-  CatPrint (Str, L"1394(%g)", &F1394Path->Guid);\r
+  CatPrint (Str, L"1394(%lx)", &F1394Path->Guid);\r
 }\r
 \r
 /**\r
@@ -684,13 +679,22 @@ DevPathSata (
   SATA_DEVICE_PATH *Sata;\r
 \r
   Sata = DevPath;\r
-  CatPrint (\r
-    Str,\r
-    L"Sata(%x,%x,%x)",\r
-    (UINTN) Sata->HBAPortNumber,\r
-    (UINTN) Sata->PortMultiplierPortNumber,\r
-    (UINTN) Sata->Lun\r
-    );\r
+  if ((Sata->PortMultiplierPortNumber & SATA_HBA_DIRECT_CONNECT_FLAG) != 0) {\r
+    CatPrint (\r
+      Str,\r
+      L"Sata(%x,%x)",\r
+      (UINTN) Sata->HBAPortNumber,\r
+      (UINTN) Sata->Lun\r
+      );\r
+  } else {\r
+    CatPrint (\r
+      Str,\r
+      L"Sata(%x,%x,%x)",\r
+      (UINTN) Sata->HBAPortNumber,\r
+      (UINTN) Sata->PortMultiplierPortNumber,\r
+      (UINTN) Sata->Lun\r
+      );\r
+  }\r
 }\r
 \r
 /**\r
@@ -905,7 +909,7 @@ DevPathUart (
   if (Uart->BaudRate == 0) {\r
     CatPrint (Str, L"Uart(DEFAULT,%c,", Parity);\r
   } else {\r
-    CatPrint (Str, L"Uart(%d,%c,", Uart->BaudRate, Parity);\r
+    CatPrint (Str, L"Uart(%ld,%c,", Uart->BaudRate, Parity);\r
   }\r
 \r
   if (Uart->DataBits == 0) {\r
@@ -956,15 +960,12 @@ DevPathiSCSI (
   ISCSI_DEVICE_PATH_WITH_NAME *IScsi;\r
   UINT16                      Options;\r
 \r
-  ASSERT (Str != NULL);\r
-  ASSERT (DevPath != NULL);\r
-\r
   IScsi = DevPath;\r
   CatPrint (\r
     Str,\r
-    L"iSCSI(%s,%x,%lx,",\r
-    IScsi->iSCSITargetName,\r
-    IScsi->TargetPortalGroupTag,\r
+    L"iSCSI(%a,%x,%lx,",\r
+    IScsi->TargetName,\r
+    (UINTN) IScsi->TargetPortalGroupTag,\r
     IScsi->Lun\r
     );\r
 \r
@@ -983,6 +984,28 @@ DevPathiSCSI (
   CatPrint (Str, L"%s)", (IScsi->NetworkProtocol == 0) ? L"TCP" : L"reserved");\r
 }\r
 \r
+/**\r
+  Convert Device Path to a Unicode string for printing.\r
+\r
+  @param Str             The buffer holding the output string.\r
+                         This buffer contains the length of the\r
+                         string and the maixmum length reserved\r
+                         for the string buffer.\r
+  @param DevPath         The device path.\r
+\r
+**/\r
+VOID\r
+DevPathVlan (\r
+  IN OUT POOL_PRINT       *Str,\r
+  IN VOID                 *DevPath\r
+  )\r
+{\r
+  VLAN_DEVICE_PATH  *Vlan;\r
+\r
+  Vlan = DevPath;\r
+  CatPrint (Str, L"Vlan(%d)", (UINTN) Vlan->VlanId);\r
+}\r
+\r
 /**\r
   Convert Device Path to a Unicode string for printing.\r
 \r
@@ -1121,6 +1144,33 @@ DevPathFvFilePath (
   CatPrint (Str, L"%g", &FvFilePath->FvFileName);\r
 }\r
 \r
+/**\r
+  Convert Device Path to a Unicode string for printing.\r
+\r
+  @param Str             The buffer holding the output string.\r
+                         This buffer contains the length of the\r
+                         string and the maixmum length reserved\r
+                         for the string buffer.\r
+  @param DevPath         The device path.\r
+\r
+**/\r
+VOID\r
+DevPathRelativeOffsetRange (\r
+  IN OUT POOL_PRINT       *Str,\r
+  IN VOID                 *DevPath\r
+  )\r
+{\r
+  MEDIA_RELATIVE_OFFSET_RANGE_DEVICE_PATH *Offset;\r
+\r
+  Offset = DevPath;\r
+  CatPrint (\r
+    Str,\r
+    L"Offset(%lx,%lx)",\r
+    Offset->StartingOffset,\r
+    Offset->EndingOffset\r
+    );\r
+}\r
+\r
 /**\r
   Convert Device Path to a Unicode string for printing.\r
 \r
@@ -1214,6 +1264,27 @@ DevPathNodeUnknown (
 {\r
   CatPrint (Str, L"?");\r
 }\r
+/**\r
+  Convert Device Path to a Unicode string for printing.\r
+\r
+  @param Str             The buffer holding the output string.\r
+                         This buffer contains the length of the\r
+                         string and the maximum length reserved\r
+                         for the string buffer.\r
+  @param DevPath         The device path.\r
+\r
+**/\r
+VOID\r
+DevPathFvPath (\r
+  IN OUT POOL_PRINT       *Str,\r
+  IN VOID                 *DevPath\r
+  )\r
+{\r
+  MEDIA_FW_VOL_DEVICE_PATH *FvPath;\r
+\r
+  FvPath = DevPath;\r
+  CatPrint (Str, L"Fv(%g)", &FvPath->FvName);\r
+}\r
 \r
 DEVICE_PATH_STRING_TABLE  DevPathTable[] = {\r
   {\r
@@ -1341,6 +1412,11 @@ DEVICE_PATH_STRING_TABLE  DevPathTable[] = {
     MSG_ISCSI_DP,\r
     DevPathiSCSI\r
   },\r
+  {\r
+    MESSAGING_DEVICE_PATH,\r
+    MSG_VLAN_DP,\r
+    DevPathVlan\r
+  },\r
   {\r
     MEDIA_DEVICE_PATH,\r
     MEDIA_HARDDRIVE_DP,\r
@@ -1366,11 +1442,21 @@ DEVICE_PATH_STRING_TABLE  DevPathTable[] = {
     MEDIA_PROTOCOL_DP,\r
     DevPathMediaProtocol\r
   },\r
+  {\r
+    MEDIA_DEVICE_PATH,\r
+    MEDIA_PIWG_FW_VOL_DP,\r
+    DevPathFvPath,\r
+  },\r
   {\r
     MEDIA_DEVICE_PATH,\r
     MEDIA_PIWG_FW_FILE_DP,\r
     DevPathFvFilePath\r
   },\r
+  {\r
+    MEDIA_DEVICE_PATH,\r
+    MEDIA_RELATIVE_OFFSET_RANGE_DP,\r
+    DevPathRelativeOffsetRange,\r
+  },\r
   {\r
     BBS_DEVICE_PATH,\r
     BBS_BBS_DP,\r
@@ -1444,7 +1530,7 @@ DevicePathToStr (
     // Find the handler to dump this device path node\r
     //\r
     DumpNode = NULL;\r
-    for (Index = 0; DevPathTable[Index].Function; Index += 1) {\r
+    for (Index = 0; DevPathTable[Index].Function != NULL; Index += 1) {\r
 \r
       if (DevicePathType (DevPathNode) == DevPathTable[Index].Type &&\r
           DevicePathSubType (DevPathNode) == DevPathTable[Index].SubType\r
@@ -1462,7 +1548,7 @@ DevicePathToStr (
     //\r
     //  Put a path seperator in if needed\r
     //\r
-    if (Str.len && DumpNode != DevPathEndInstance) {\r
+    if ((Str.Len != 0) && (DumpNode != DevPathEndInstance)) {\r
       CatPrint (&Str, L"/");\r
     }\r
     //\r
@@ -1477,9 +1563,9 @@ DevicePathToStr (
   }\r
 \r
 Done:\r
-  NewSize = (Str.len + 1) * sizeof (CHAR16);\r
-  Str.str = ReallocatePool (NewSize, NewSize, Str.str);\r
-  ASSERT (Str.str != NULL);\r
-  Str.str[Str.len] = 0;\r
-  return Str.str;\r
+  NewSize = (Str.Len + 1) * sizeof (CHAR16);\r
+  Str.Str = ReallocatePool (NewSize, NewSize, Str.Str);\r
+  ASSERT (Str.Str != NULL);\r
+  Str.Str[Str.Len] = 0;\r
+  return Str.Str;\r
 }\r