Fix several bugs in the implementation of converting SAS/SASEX device path node from/to text.

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
This commit is contained in:
niruiyu 2013-04-11 01:39:39 +00:00
parent 3588bb3529
commit 562fce0bf7
2 changed files with 98 additions and 38 deletions

View File

@ -1,7 +1,7 @@
/** @file
DevicePathFromText protocol as defined in the UEFI 2.0 specification.
Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -1636,6 +1636,7 @@ DevPathFromTextSAS (
CHAR16 *DriveBayStr;
CHAR16 *ReservedStr;
UINT16 Info;
UINT16 Uint16;
SAS_DEVICE_PATH *Sas;
AddressStr = GetNextParamStr (&TextDeviceNode);
@ -1646,7 +1647,6 @@ DevPathFromTextSAS (
ConnectStr = GetNextParamStr (&TextDeviceNode);
DriveBayStr = GetNextParamStr (&TextDeviceNode);
ReservedStr = GetNextParamStr (&TextDeviceNode);
Info = 0x0000;
Sas = (SAS_DEVICE_PATH *) CreateDeviceNode (
MESSAGING_DEVICE_PATH,
MSG_VENDOR_DP,
@ -1657,25 +1657,51 @@ DevPathFromTextSAS (
Strtoi64 (AddressStr, &Sas->SasAddress);
Strtoi64 (LunStr, &Sas->Lun);
Sas->RelativeTargetPort = (UINT16) Strtoi (RTPStr);
if (StrCmp (SASSATAStr, L"NoTopology") != 0) {
if (StrCmp (DriveBayStr, L"0") == 0) {
Info |= 0x0001;
if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
Info = 0x0;
} else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {
Uint16 = (UINT16) Strtoi (DriveBayStr);
if (Uint16 == 0) {
Info = 0x1;
} else {
Info |= 0x0002;
Info = (UINT16) (Info | (Strtoi (DriveBayStr) << 8));
Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
}
if (StrCmp (SASSATAStr, L"SATA") == 0) {
Info |= 0x0010;
Info |= BIT4;
}
//
// Location is an integer between 0 and 1 or else
// the keyword Internal (0) or External (1).
//
if (StrCmp (LocationStr, L"External") == 0) {
Info |= 0x0020;
Uint16 = 1;
} else if (StrCmp (LocationStr, L"Internal") == 0) {
Uint16 = 0;
} else {
Uint16 = (Strtoi (LocationStr) & BIT0);
}
Info |= (Uint16 << 5);
//
// Connect is an integer between 0 and 3 or else
// the keyword Direct (0) or Expanded (1).
//
if (StrCmp (ConnectStr, L"Expanded") == 0) {
Info |= 0x0040;
Uint16 = 1;
} else if (StrCmp (ConnectStr, L"Direct") == 0) {
Uint16 = 0;
} else {
Uint16 = (Strtoi (ConnectStr) & (BIT0 | BIT1));
}
Info |= (Uint16 << 6);
} else {
Info = (UINT16) Strtoi (SASSATAStr);
}
Sas->DeviceTopology = Info;
@ -1705,6 +1731,9 @@ DevPathFromTextSasEx (
CHAR16 *ConnectStr;
CHAR16 *DriveBayStr;
UINT16 Info;
UINT16 Uint16;
UINT64 SasAddress;
UINT64 Lun;
SASEX_DEVICE_PATH *SasEx;
AddressStr = GetNextParamStr (&TextDeviceNode);
@ -1714,37 +1743,62 @@ DevPathFromTextSasEx (
LocationStr = GetNextParamStr (&TextDeviceNode);
ConnectStr = GetNextParamStr (&TextDeviceNode);
DriveBayStr = GetNextParamStr (&TextDeviceNode);
Info = 0x0000;
SasEx = (SASEX_DEVICE_PATH *) CreateDeviceNode (
MESSAGING_DEVICE_PATH,
MSG_SASEX_DP,
(UINT16) sizeof (SASEX_DEVICE_PATH)
);
Strtoi64 (AddressStr, (UINT64 *) &SasEx->SasAddress);
Strtoi64 (LunStr, (UINT64 *) &SasEx->Lun);
*(UINT64 *) &SasEx->SasAddress = SwapBytes64 (*(UINT64 *) &SasEx->SasAddress);
*(UINT64 *) &SasEx->Lun = SwapBytes64 (*(UINT64 *) &SasEx->Lun);
Strtoi64 (AddressStr, &SasAddress);
Strtoi64 (LunStr, &Lun);
WriteUnaligned64 ((UINT64 *) &SasEx->SasAddress, SwapBytes64 (SasAddress));
WriteUnaligned64 ((UINT64 *) &SasEx->Lun, SwapBytes64 (Lun));
SasEx->RelativeTargetPort = (UINT16) Strtoi (RTPStr);
if (StrCmp (SASSATAStr, L"NoTopology") != 0) {
if (StrCmp (DriveBayStr, L"0") == 0) {
Info |= 0x0001;
if (StrCmp (SASSATAStr, L"NoTopology") == 0) {
Info = 0x0;
} else if ((StrCmp (SASSATAStr, L"SATA") == 0) || (StrCmp (SASSATAStr, L"SAS") == 0)) {
Uint16 = (UINT16) Strtoi (DriveBayStr);
if (Uint16 == 0) {
Info = 0x1;
} else {
Info |= 0x0002;
Info = (UINT16) (Info | (Strtoi (DriveBayStr) << 8));
Info = (UINT16) (0x2 | ((Uint16 - 1) << 8));
}
if (StrCmp (SASSATAStr, L"SATA") == 0) {
Info |= 0x0010;
Info |= BIT4;
}
//
// Location is an integer between 0 and 1 or else
// the keyword Internal (0) or External (1).
//
if (StrCmp (LocationStr, L"External") == 0) {
Info |= 0x0020;
Uint16 = 1;
} else if (StrCmp (LocationStr, L"Internal") == 0) {
Uint16 = 0;
} else {
Uint16 = (Strtoi (LocationStr) & BIT0);
}
Info |= (Uint16 << 5);
//
// Connect is an integer between 0 and 3 or else
// the keyword Direct (0) or Expanded (1).
//
if (StrCmp (ConnectStr, L"Expanded") == 0) {
Info |= 0x0040;
Uint16 = 1;
} else if (StrCmp (ConnectStr, L"Direct") == 0) {
Uint16 = 0;
} else {
Uint16 = (Strtoi (ConnectStr) & (BIT0 | BIT1));
}
Info |= (Uint16 << 6);
} else {
Info = (UINT16) Strtoi (SASSATAStr);
}
SasEx->DeviceTopology = Info;

View File

@ -1,7 +1,7 @@
/** @file
DevicePathToText protocol as defined in the UEFI 2.0 specification.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -234,23 +234,26 @@ DevPathToTextVendor (
((SAS_DEVICE_PATH *) Vendor)->RelativeTargetPort
);
Info = (((SAS_DEVICE_PATH *) Vendor)->DeviceTopology);
if ((Info & 0x0f) == 0) {
if (((Info & 0x0f) == 0) && ((Info & BIT7) == 0)) {
CatPrint (Str, L"NoTopology,0,0,0,");
} else if (((Info & 0x0f) == 1) || ((Info & 0x0f) == 2)) {
} else if (((Info & 0x0f) <= 2) && ((Info & BIT7) == 0)) {
CatPrint (
Str,
L"%s,%s,%s,",
((Info & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",
((Info & (0x1 << 5)) != 0) ? L"External" : L"Internal",
((Info & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"
((Info & BIT4) != 0) ? L"SATA" : L"SAS",
((Info & BIT5) != 0) ? L"External" : L"Internal",
((Info & BIT6) != 0) ? L"Expanded" : L"Direct"
);
if ((Info & 0x0f) == 1) {
CatPrint (Str, L"0,");
} else {
CatPrint (Str, L"0x%x,", (Info >> 8) & 0xff);
//
// Value 0x0 thru 0xFF -> Drive 1 thru Drive 256
//
CatPrint (Str, L"0x%x,", ((Info >> 8) & 0xff) + 1);
}
} else {
CatPrint (Str, L"0,0,0,0,");
CatPrint (Str, L"0x%x,0,0,0,", Info);
}
CatPrint (Str, L"0x%x)", ((SAS_DEVICE_PATH *) Vendor)->Reserved);
@ -689,23 +692,26 @@ DevPathToTextSasEx (
}
CatPrint (Str, L",0x%x,", SasEx->RelativeTargetPort);
if ((SasEx->DeviceTopology & 0x0f) == 0) {
if (((SasEx->DeviceTopology & 0x0f) == 0) && ((SasEx->DeviceTopology & BIT7) == 0)) {
CatPrint (Str, L"NoTopology,0,0,0");
} else if (((SasEx->DeviceTopology & 0x0f) == 1) || ((SasEx->DeviceTopology & 0x0f) == 2)) {
} else if (((SasEx->DeviceTopology & 0x0f) <= 2) && ((SasEx->DeviceTopology & BIT7) == 0)) {
CatPrint (
Str,
L"%s,%s,%s,",
((SasEx->DeviceTopology & (0x1 << 4)) != 0) ? L"SATA" : L"SAS",
((SasEx->DeviceTopology & (0x1 << 5)) != 0) ? L"External" : L"Internal",
((SasEx->DeviceTopology & (0x1 << 6)) != 0) ? L"Expanded" : L"Direct"
((SasEx->DeviceTopology & BIT4) != 0) ? L"SATA" : L"SAS",
((SasEx->DeviceTopology & BIT5) != 0) ? L"External" : L"Internal",
((SasEx->DeviceTopology & BIT6) != 0) ? L"Expanded" : L"Direct"
);
if ((SasEx->DeviceTopology & 0x0f) == 1) {
CatPrint (Str, L"0");
} else {
CatPrint (Str, L"0x%x", (SasEx->DeviceTopology >> 8) & 0xff);
//
// Value 0x0 thru 0xFF -> Drive 1 thru Drive 256
//
CatPrint (Str, L"0x%x", ((SasEx->DeviceTopology >> 8) & 0xff) + 1);
}
} else {
CatPrint (Str, L"0,0,0,0");
CatPrint (Str, L"0x%x,0,0,0", SasEx->DeviceTopology);
}
CatPrint (Str, L")");