]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Fix several bugs in the implementation of converting SAS/SASEX device path node from...
authorniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 11 Apr 2013 01:39:39 +0000 (01:39 +0000)
committerniruiyu <niruiyu@6f19259b-4bc3-4df7-8a09-765794883524>
Thu, 11 Apr 2013 01:39:39 +0000 (01:39 +0000)
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14256 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/DevicePathDxe/DevicePathFromText.c
MdeModulePkg/Universal/DevicePathDxe/DevicePathToText.c

index d94e149e588cec0d78058538d2c238e13628120b..c06188828003779dbf273c101518116a208885a6 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   DevicePathFromText protocol as defined in the UEFI 2.0 specification.\r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -1636,6 +1636,7 @@ DevPathFromTextSAS (
   CHAR16          *DriveBayStr;\r
   CHAR16          *ReservedStr;\r
   UINT16          Info;\r
+  UINT16          Uint16;\r
   SAS_DEVICE_PATH *Sas;\r
 \r
   AddressStr  = GetNextParamStr (&TextDeviceNode);\r
@@ -1646,7 +1647,6 @@ DevPathFromTextSAS (
   ConnectStr  = GetNextParamStr (&TextDeviceNode);\r
   DriveBayStr = GetNextParamStr (&TextDeviceNode);\r
   ReservedStr = GetNextParamStr (&TextDeviceNode);\r
-  Info        = 0x0000;\r
   Sas         = (SAS_DEVICE_PATH *) CreateDeviceNode (\r
                                        MESSAGING_DEVICE_PATH,\r
                                        MSG_VENDOR_DP,\r
@@ -1657,25 +1657,51 @@ DevPathFromTextSAS (
   Strtoi64 (AddressStr, &Sas->SasAddress);\r
   Strtoi64 (LunStr, &Sas->Lun);\r
   Sas->RelativeTargetPort = (UINT16) Strtoi (RTPStr);\r
-  if (StrCmp (SASSATAStr, L"NoTopology") != 0) {\r
-    if (StrCmp (DriveBayStr, L"0") == 0) {\r
-      Info |= 0x0001;\r
+\r
+  if (StrCmp (SASSATAStr, L"NoTopology") == 0) {\r
+    Info = 0x0;\r
+\r
+  } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {\r
+\r
+    Uint16 = (UINT16) Strtoi (DriveBayStr);\r
+    if (Uint16 == 0) {\r
+      Info = 0x1;\r
     } else {\r
-      Info |= 0x0002;\r
-      Info = (UINT16) (Info | (Strtoi (DriveBayStr) << 8));\r
+      Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));\r
     }\r
 \r
     if (StrCmp (SASSATAStr, L"SATA") == 0) {\r
-      Info |= 0x0010;\r
+      Info |= BIT4;\r
     }\r
 \r
+    //\r
+    // Location is an integer between 0 and 1 or else\r
+    // the keyword Internal (0) or External (1).\r
+    //\r
     if (StrCmp (LocationStr, L"External") == 0) {\r
-      Info |= 0x0020;\r
+      Uint16 = 1;\r
+    } else if (StrCmp (LocationStr, L"Internal") == 0) {\r
+      Uint16 = 0;\r
+    } else {\r
+      Uint16 = (Strtoi (LocationStr) & BIT0);\r
     }\r
+    Info |= (Uint16 << 5);\r
 \r
+    //\r
+    // Connect is an integer between 0 and 3 or else\r
+    // the keyword Direct (0) or Expanded (1).\r
+    //\r
     if (StrCmp (ConnectStr, L"Expanded") == 0) {\r
-      Info |= 0x0040;\r
+      Uint16 = 1;\r
+    } else if (StrCmp (ConnectStr, L"Direct") == 0) {\r
+      Uint16 = 0;\r
+    } else {\r
+      Uint16 = (Strtoi (ConnectStr) & (BIT0 | BIT1));\r
     }\r
+    Info |= (Uint16 << 6);\r
+\r
+  } else {\r
+    Info = (UINT16) Strtoi (SASSATAStr);\r
   }\r
 \r
   Sas->DeviceTopology = Info;\r
@@ -1705,6 +1731,9 @@ DevPathFromTextSasEx (
   CHAR16            *ConnectStr;\r
   CHAR16            *DriveBayStr;\r
   UINT16            Info;\r
+  UINT16            Uint16;\r
+  UINT64            SasAddress;\r
+  UINT64            Lun;\r
   SASEX_DEVICE_PATH *SasEx;\r
 \r
   AddressStr  = GetNextParamStr (&TextDeviceNode);\r
@@ -1714,37 +1743,62 @@ DevPathFromTextSasEx (
   LocationStr = GetNextParamStr (&TextDeviceNode);\r
   ConnectStr  = GetNextParamStr (&TextDeviceNode);\r
   DriveBayStr = GetNextParamStr (&TextDeviceNode);\r
-  Info        = 0x0000;\r
   SasEx       = (SASEX_DEVICE_PATH *) CreateDeviceNode (\r
                                         MESSAGING_DEVICE_PATH,\r
                                         MSG_SASEX_DP,\r
                                         (UINT16) sizeof (SASEX_DEVICE_PATH)\r
                                         );\r
 \r
-  Strtoi64 (AddressStr, (UINT64 *) &SasEx->SasAddress);\r
-  Strtoi64 (LunStr,     (UINT64 *) &SasEx->Lun);\r
-  *(UINT64 *) &SasEx->SasAddress = SwapBytes64 (*(UINT64 *) &SasEx->SasAddress);\r
-  *(UINT64 *) &SasEx->Lun        = SwapBytes64 (*(UINT64 *) &SasEx->Lun);\r
+  Strtoi64 (AddressStr, &SasAddress);\r
+  Strtoi64 (LunStr,     &Lun);\r
+  WriteUnaligned64 ((UINT64 *) &SasEx->SasAddress, SwapBytes64 (SasAddress));\r
+  WriteUnaligned64 ((UINT64 *) &SasEx->Lun,        SwapBytes64 (Lun));\r
   SasEx->RelativeTargetPort      = (UINT16) Strtoi (RTPStr);\r
-  if (StrCmp (SASSATAStr, L"NoTopology") != 0) {\r
-    if (StrCmp (DriveBayStr, L"0") == 0) {\r
-      Info |= 0x0001;\r
+\r
+  if (StrCmp (SASSATAStr, L"NoTopology") == 0) {\r
+    Info = 0x0;\r
+\r
+  } else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {\r
+\r
+    Uint16 = (UINT16) Strtoi (DriveBayStr);\r
+    if (Uint16 == 0) {\r
+      Info = 0x1;\r
     } else {\r
-      Info |= 0x0002;\r
-      Info = (UINT16) (Info | (Strtoi (DriveBayStr) << 8));\r
+      Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));\r
     }\r
 \r
     if (StrCmp (SASSATAStr, L"SATA") == 0) {\r
-      Info |= 0x0010;\r
+      Info |= BIT4;\r
     }\r
 \r
+    //\r
+    // Location is an integer between 0 and 1 or else\r
+    // the keyword Internal (0) or External (1).\r
+    //\r
     if (StrCmp (LocationStr, L"External") == 0) {\r
-      Info |= 0x0020;\r
+      Uint16 = 1;\r
+    } else if (StrCmp (LocationStr, L"Internal") == 0) {\r
+      Uint16 = 0;\r
+    } else {\r
+      Uint16 = (Strtoi (LocationStr) & BIT0);\r
     }\r
+    Info |= (Uint16 << 5);\r
 \r
+    //\r
+    // Connect is an integer between 0 and 3 or else\r
+    // the keyword Direct (0) or Expanded (1).\r
+    //\r
     if (StrCmp (ConnectStr, L"Expanded") == 0) {\r
-      Info |= 0x0040;\r
+      Uint16 = 1;\r
+    } else if (StrCmp (ConnectStr, L"Direct") == 0) {\r
+      Uint16 = 0;\r
+    } else {\r
+      Uint16 = (Strtoi (ConnectStr) & (BIT0 | BIT1));\r
     }\r
+    Info |= (Uint16 << 6);\r
+\r
+  } else {\r
+    Info = (UINT16) Strtoi (SASSATAStr);\r
   }\r
 \r
   SasEx->DeviceTopology = Info;\r
index 1f90f64204a79b370aad39734307686a1934a93b..3d9d7c7a7ecb3945e5bd038fd42dc13b6abf22a4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   DevicePathToText protocol as defined in the UEFI 2.0 specification.\r
 \r
-Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2013, 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
@@ -234,23 +234,26 @@ DevPathToTextVendor (
           ((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort\r
           );\r
         Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);\r
-        if ((Info & 0x0f) == 0) {\r
+        if (((Info & 0x0f) == 0) && ((Info & BIT7) == 0)) {\r
           CatPrint (Str, L"NoTopology,0,0,0,");\r
-        } else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {\r
+        } else if (((Info & 0x0f) <= 2) && ((Info & BIT7) == 0)) {\r
           CatPrint (\r
             Str,\r
             L"%s,%s,%s,",\r
-            ((Info & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",\r
-            ((Info & (0x1 << 5)) != 0) ? L"External" : L"Internal",\r
-            ((Info & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"\r
+            ((Info & BIT4) != 0) ? L"SATA" : L"SAS",\r
+            ((Info & BIT5) != 0) ? L"External" : L"Internal",\r
+            ((Info & BIT6) != 0) ? L"Expanded" : L"Direct"\r
             );\r
           if ((Info & 0x0f) == 1) {\r
             CatPrint (Str, L"0,");\r
           } else {\r
-            CatPrint (Str, L"0x%x,", (Info >> 8) & 0xff);\r
+            //\r
+            // Value 0x0 thru 0xFF -> Drive 1 thru Drive 256\r
+            //\r
+            CatPrint (Str, L"0x%x,", ((Info >> 8) & 0xff) + 1);\r
           }\r
         } else {\r
-          CatPrint (Str, L"0,0,0,0,");\r
+          CatPrint (Str, L"0x%x,0,0,0,", Info);\r
         }\r
 \r
         CatPrint (Str, L"0x%x)", ((SAS_DEVICE_PATH *) Vendor)->Reserved);\r
@@ -689,23 +692,26 @@ DevPathToTextSasEx (
   }\r
   CatPrint (Str, L",0x%x,", SasEx->RelativeTargetPort);\r
 \r
-  if ((SasEx->DeviceTopology & 0x0f) == 0) {\r
+  if (((SasEx->DeviceTopology & 0x0f) == 0) && ((SasEx->DeviceTopology & BIT7) == 0)) {\r
     CatPrint (Str, L"NoTopology,0,0,0");\r
-  } else if (((SasEx->DeviceTopology & 0x0f) == 1) || ((SasEx->DeviceTopology & 0x0f) == 2)) {\r
+  } else if (((SasEx->DeviceTopology & 0x0f) <= 2) && ((SasEx->DeviceTopology & BIT7) == 0)) {\r
     CatPrint (\r
       Str,\r
       L"%s,%s,%s,",\r
-      ((SasEx->DeviceTopology & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",\r
-      ((SasEx->DeviceTopology & (0x1 << 5)) != 0) ? L"External" : L"Internal",\r
-      ((SasEx->DeviceTopology & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"\r
+      ((SasEx->DeviceTopology & BIT4) != 0) ? L"SATA" : L"SAS",\r
+      ((SasEx->DeviceTopology & BIT5) != 0) ? L"External" : L"Internal",\r
+      ((SasEx->DeviceTopology & BIT6) != 0) ? L"Expanded" : L"Direct"\r
       );\r
     if ((SasEx->DeviceTopology & 0x0f) == 1) {\r
       CatPrint (Str, L"0");\r
     } else {\r
-      CatPrint (Str, L"0x%x", (SasEx->DeviceTopology >> 8) & 0xff);\r
+      //\r
+      // Value 0x0 thru 0xFF -> Drive 1 thru Drive 256\r
+      //\r
+      CatPrint (Str, L"0x%x", ((SasEx->DeviceTopology >> 8) & 0xff) + 1);\r
     }\r
   } else {\r
-    CatPrint (Str, L"0,0,0,0");\r
+    CatPrint (Str, L"0x%x,0,0,0", SasEx->DeviceTopology);\r
   }\r
 \r
   CatPrint (Str, L")");\r