]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/DevicePathDxe/DevicePathFromText.c
Fix several bugs in the implementation of converting SAS/SASEX device path node from...
[mirror_edk2.git] / MdeModulePkg / Universal / DevicePathDxe / DevicePathFromText.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