On Wed, Jun 22, 2016 at 06:02:39PM +0200, Marcin Wojtas wrote:
From: Jan Dąbroś jsd@semihalf.com
Since PCD tables are byte arrays, it is impossible to provide big values (e.g. memory addresses) for multiple devices in simple PCD entry. In order to overcome this, strings may be used. ParsePcdLib allows parsing PCD string entry.
So, I don't think this is the correct thing to do long-term, where we instead should be implementing an emulated discovery mechanism for non-discoverable buses. But for now, and as part only of the Marvell subtree, it is an acceptable stop-gap solution.
Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jan Dabros jsd@semihalf.com Signed-off-by: Marcin Wojtas mw@semihalf.com
Reviewed-by: Leif Lindholm leif.lindholm@linaro.org
Platforms/Marvell/Include/Library/ParsePcdLib.h | 46 +++++ .../Marvell/Library/ParsePcdLib/ParsePcdLib.c | 228 +++++++++++++++++++++ .../Marvell/Library/ParsePcdLib/ParsePcdLib.inf | 50 +++++ 3 files changed, 324 insertions(+) create mode 100644 Platforms/Marvell/Include/Library/ParsePcdLib.h create mode 100644 Platforms/Marvell/Library/ParsePcdLib/ParsePcdLib.c create mode 100644 Platforms/Marvell/Library/ParsePcdLib/ParsePcdLib.inf
diff --git a/Platforms/Marvell/Include/Library/ParsePcdLib.h b/Platforms/Marvell/Include/Library/ParsePcdLib.h new file mode 100644 index 0000000..a255685 --- /dev/null +++ b/Platforms/Marvell/Include/Library/ParsePcdLib.h @@ -0,0 +1,46 @@ +/******************************************************************************** +Copyright (C) 2016 Marvell International Ltd.
+Marvell BSD License Option
+If you received this File from Marvell, you may opt to use, redistribute and/or +modify this File under the following licensing terms. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met:
+* Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
+* Neither the name of Marvell nor the names of its contributors may be
- used to endorse or promote products derived from this software without
- specific prior written permission.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/
+#ifndef __PARSEPCDLIB_H__ +#define __PARSEPCDLIB_H__
+EFI_STATUS +ParsePcdString (
- IN CHAR16 *PcdString,
- IN UINT8 Count,
- OUT UINTN *ValueTable,
- OUT CHAR16 **StrTable
- );
+#endif diff --git a/Platforms/Marvell/Library/ParsePcdLib/ParsePcdLib.c b/Platforms/Marvell/Library/ParsePcdLib/ParsePcdLib.c new file mode 100644 index 0000000..9a4be8e --- /dev/null +++ b/Platforms/Marvell/Library/ParsePcdLib/ParsePcdLib.c @@ -0,0 +1,228 @@ +/******************************************************************************** +Copyright (C) 2016 Marvell International Ltd.
+Marvell BSD License Option
+If you received this File from Marvell, you may opt to use, redistribute and/or +modify this File under the following licensing terms. +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met:
+* Redistributions of source code must Retain the above copyright notice,
- this list of conditions and the following disclaimer.
+* Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
+* Neither the name of Marvell nor the names of its contributors may be
- used to endorse or promote products derived from this software without
- specific prior written permission.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*******************************************************************************/ +#define CHAR_NULL 0x0000
+#include <Library/BaseLib.h> +#include <Uefi.h> +#include <Library/UefiLib.h> +#include <Library/DebugLib.h>
+STATIC +CHAR16 +CharToUpper (
- IN CHAR16 Char
- )
+{
- if (Char >= L'a' && Char <= L'z') {
- return (CHAR16) (Char - (L'a' - L'A'));
- }
- return Char;
+}
+STATIC +BOOLEAN +IsDecimalDigitChar (
- IN CHAR16 Char
- )
+{
- return (BOOLEAN) (Char >= L'0' && Char <= L'9');
+}
+STATIC +UINTN +HexCharToUintn (
- IN CHAR16 Char
- )
+{
- if (IsDecimalDigitChar (Char)) {
- return Char - L'0';
- }
- return (UINTN) (10 + CharToUpper (Char) - L'A');
+}
+STATIC +BOOLEAN +IsHexDigitCharacter (
- CHAR16 Char
- )
+{
- return (BOOLEAN) ((Char >= L'0' && Char <= L'9') || (Char >= L'A' &&
- Char <= L'F') || (Char >= L'a' && Char <= L'f'));
+}
+STATIC +UINTN +HexStrToUintn (
- CHAR16 *String
- )
+{
- UINTN Result = 0;
- if (String == NULL || StrSize(String) == 0) {
- return (UINTN)(-1);
- }
- // Ignore spaces and tabs
- while ((*String == L' ') || (*String == L'\t')) {
- String++;
- }
- // Ignore leading zeros after spaces
- while (*String == L'0') {
- String++;
- }
- if (CharToUpper (*String) != L'X') {
- return (UINTN)(-1);
- }
- // Skip 'x'
- String++;
- while (IsHexDigitCharacter (*String)) {
- Result <<= 4;
- Result += HexCharToUintn (*String);
- String++;
- }
- return (UINTN) Result;
+}
+STATIC +UINTN +DecimalStrToUintn (
- CHAR16 *String
- )
+{
- UINTN Result = 0;
- while (IsDecimalDigitChar (*String)) {
- Result = 10 * Result + (*String - L'0');
- String++;
- }
- return Result;
+}
+STATIC +UINTN +StrToUintn (
- CHAR16 *String
- )
+{
- CHAR16 *Walker;
- // Chop off leading spaces
- for (Walker = String; Walker != NULL && *Walker != CHAR_NULL && *Walker == L' '; Walker++);
- if (StrnCmp(Walker, L"0x", 2) == 0 || StrnCmp(Walker, L"0X", 2) == 0) {
- return HexStrToUintn (Walker);
- } else {
- return DecimalStrToUintn (Walker);
- }
+}
+EFI_STATUS +ParsePcdString (
- IN CHAR16 *PcdString,
- IN UINT8 Count,
- OUT UINTN *ValueTable,
- OUT CHAR16 **StrTable
- )
+{
- BOOLEAN ValueFlag = FALSE;
- CHAR16 *Walker;
- UINTN i, Tmp = 0;
- if (ValueTable != NULL) {
- ValueFlag = TRUE;
- }
- // Set pointer at the end of PCD string
- Walker = PcdString + StrLen (PcdString);
- for (i = 0; i < Count; i++) {
- while ((--Walker) >= PcdString) {
if (*Walker == L';') {
// Cut off parsed chunk from PCD string by replacing ';' with
// null-terminator
*Walker = '\0';
if (ValueFlag) {
Tmp = StrToUintn ((Walker + 1));
if ((UINTN)(-1) == Tmp) {
return EFI_INVALID_PARAMETER;
}
// Entry is parsed from the end to the beginning
// so fill table in the same manner
ValueTable[Count - (i + 1)] = Tmp;
} else {
StrTable[Count - (i + 1)] = Walker + 1;
}
Walker--;
break;
}
if (Walker == PcdString) {
if (ValueFlag) {
Tmp = StrToUintn ((Walker));
if (Tmp == (UINTN)(-1)) {
return EFI_INVALID_PARAMETER;
}
}
// Last device's entry should be added to the table here.
// If not, return error
if (i != (Count - 1)) {
DEBUG((DEBUG_ERROR, "ParsePcdLib: Please set PCD value for every "
"device\n"));
return EFI_INVALID_PARAMETER;
}
// We parse from the end to the beginning
// so fill table in the same manner
if (ValueFlag) {
ValueTable[Count - (i + 1)] = Tmp;
} else {
StrTable[Count - (i + 1)] = Walker;
}
// End both loops
return EFI_SUCCESS;
}
- }
- }
- return EFI_SUCCESS;
+} diff --git a/Platforms/Marvell/Library/ParsePcdLib/ParsePcdLib.inf b/Platforms/Marvell/Library/ParsePcdLib/ParsePcdLib.inf new file mode 100644 index 0000000..b4db621 --- /dev/null +++ b/Platforms/Marvell/Library/ParsePcdLib/ParsePcdLib.inf @@ -0,0 +1,50 @@ +# Copyright (C) 2016 Marvell International Ltd. +# +# Marvell BSD License Option +# +# If you received this File from Marvell, you may opt to use, redistribute and/or +# modify this File under the following licensing terms. +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# * Redistributions of source code must retain the above copyright notice, +# this list of conditions and the following disclaimer. +# +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# * Neither the name of Marvell nor the names of its contributors may be +# used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = ParsePcdLib
- FILE_GUID = 698d85a0-a952-453e-b8a4-1d6ea338a38e
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = ParsePcdLib
+[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
+[LibraryClasses]
- ArmLib
- DebugLib
+[Sources.common]
- ParsePcdLib.c
-- 1.8.3.1