Date   

[Patch 2/2 V4] BaseTools: Add unittest for Split tool

Bob Feng
 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3165

This patch is to add the unit test for Split python tool

Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
---
V3: Move test_split.py to tests/Sprit folder
V4: No change on V4
.../Source/Python/tests/Split/test_split.py | 111 ++++++++++++++++++
1 file changed, 111 insertions(+)
create mode 100644 BaseTools/Source/Python/tests/Split/test_split.py

diff --git a/BaseTools/Source/Python/tests/Split/test_split.py b/BaseTools/Source/Python/tests/Split/test_split.py
new file mode 100644
index 000000000000..82f71ecf5372
--- /dev/null
+++ b/BaseTools/Source/Python/tests/Split/test_split.py
@@ -0,0 +1,111 @@
+# @file
+# Split a file into two pieces at the request offset.
+#
+# Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+# Import Modules
+import unittest
+import tempfile
+import os
+import shutil
+import Split.Split as sp
+import struct as st
+
+
+class TestSplit(unittest.TestCase):
+ def setUp(self):
+ self.WORKSPACE = tempfile.mkdtemp()
+ self.binary_file = os.path.join(self.WORKSPACE, "Binary.bin")
+ self.create_inputfile()
+
+ def tearDown(self):
+ if os.path.exists(self.WORKSPACE):
+ shutil.rmtree(self.WORKSPACE)
+
+ def test_splitFile_position(self):
+ position = [-1, 0, 256, 512, 700, 1024, 2048]
+ result = [(0, 1024), (0, 1024), (256, 768),
+ (512, 512), (700, 324), (1024, 0), (1024, 0)]
+ for index, po in enumerate(position):
+ try:
+ sp.splitFile(self.binary_file, po)
+ except Exception as e:
+ self.assertTrue(False, msg="splitFile function error")
+
+ output1 = os.path.join(self.WORKSPACE, "Binary.bin1")
+ output2 = os.path.join(self.WORKSPACE, "Binary.bin2")
+ with open(output1, "rb") as f1:
+ size1 = len(f1.read())
+ with open(output2, "rb") as f2:
+ size2 = len(f2.read())
+
+ ex_result = result[index]
+ self.assertEqual(size1, ex_result[0])
+ self.assertEqual(size2, ex_result[1])
+
+ def create_inputfile(self):
+ with open(self.binary_file, "wb") as fout:
+ for i in range(512):
+ fout.write(st.pack("<H", i))
+
+ def test_splitFile_outputfile(self):
+ output = [None, "Binary.bin", "Binary1.bin", r"output/Binary1.bin",
+ os.path.join(self.WORKSPACE, r"output/Binary1.bin")]
+ for o in output:
+ try:
+ sp.splitFile(self.binary_file, 123, outputfile1=o)
+ except Exception as e:
+ self.assertTrue(False, msg="splitFile function error")
+ if o is None:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, "Binary.bin1")))
+ else:
+ if os.path.isabs(o):
+ self.assertTrue(os.path.exists(o))
+ else:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, o)))
+ self.create_inputfile()
+
+ try:
+ sp.splitFile(self.binary_file, 123, outputfile2=o)
+ except Exception as e:
+ self.assertTrue(False, msg="splitFile function error")
+ if o is None:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, "Binary.bin2")))
+ else:
+ if os.path.isabs(o):
+ self.assertTrue(os.path.exists(o))
+ else:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, o)))
+ self.create_inputfile()
+
+ def test_splitFile_outputfolder(self):
+ outputfolder = [None, "output", r"output1/output2",
+ os.path.join(self.WORKSPACE, "output")]
+ for o in outputfolder:
+ try:
+ sp.splitFile(self.binary_file, 123, outputdir=o)
+ except Exception as e:
+ self.assertTrue(False, msg="splitFile function error")
+
+ if o is None:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, "Binary.bin1")))
+ else:
+ if os.path.isabs(o):
+ self.assertTrue(os.path.exists(
+ os.path.join(o, "Binary.bin1")))
+ else:
+ self.assertTrue(os.path.exists(
+ os.path.join(self.WORKSPACE, o, "Binary.bin1")))
+
+
+if __name__ == '__main__':
+ unittest.main()
--
2.29.1.windows.1


[Patch 1/2 V4] BaseTools: Convert Split tool to python

Bob Feng
 

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3165

There are 2 reasons to convert Split tool from C to Python.
1. We are in the process of moving the Basetools Python code
to a separate repository. But there still are many C tools under
edk2/BaseTools. To make all Basetools be in the separate repo,
we can convert the C tools to Python tools.
2. The original Split tool is very slow. This python tool can reduce
90% time.

Signed-off-by: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Yuwei Chen <yuwei.chen@intel.com>
---
V3: No change for this patch.
V4: Update the version to 2.0
BaseTools/Source/C/Split/Split.c | 466 --------------------
BaseTools/BinWrappers/PosixLike/Split | 31 +-
BaseTools/BinWrappers/WindowsLike/Split.bat | 3 +
BaseTools/Source/C/GNUmakefile | 1 -
BaseTools/Source/C/Makefile | 1 -
BaseTools/Source/C/Split/GNUmakefile | 17 -
BaseTools/Source/C/Split/Makefile | 16 -
BaseTools/Source/Python/Split/Split.py | 202 +++++++++
BaseTools/Source/Python/Split/__init__.py | 10 +
9 files changed, 223 insertions(+), 524 deletions(-)
delete mode 100644 BaseTools/Source/C/Split/Split.c
create mode 100644 BaseTools/BinWrappers/WindowsLike/Split.bat
delete mode 100644 BaseTools/Source/C/Split/GNUmakefile
delete mode 100644 BaseTools/Source/C/Split/Makefile
create mode 100644 BaseTools/Source/Python/Split/Split.py
create mode 100644 BaseTools/Source/Python/Split/__init__.py

diff --git a/BaseTools/Source/C/Split/Split.c b/BaseTools/Source/C/Split/Split.c
deleted file mode 100644
index be0ee124bfe0..000000000000
--- a/BaseTools/Source/C/Split/Split.c
+++ /dev/null
@@ -1,466 +0,0 @@
-/** @file
-
- Split a file into two pieces at the request offset.
-
-Copyright (c) 1999 - 2017, Intel Corporation. All rights reserved.<BR>
-SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-// GC_TODO: fix comment to start with /*++
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#ifdef __GNUC__
-#include <unistd.h>
-#else
-#include <direct.h>
-#endif
-#include <ctype.h>
-#include "ParseInf.h"
-#include "CommonLib.h"
-#include "EfiUtilityMsgs.h"
-//
-// Utility Name
-//
-#define UTILITY_NAME "Split"
-
-//
-// Utility version information
-//
-#define UTILITY_MAJOR_VERSION 1
-#define UTILITY_MINOR_VERSION 0
-
-void
-Version (
- void
- )
-/*++
-
-Routine Description:
-
- Displays the standard utility information to SDTOUT
-
-Arguments:
-
- None
-
-Returns:
-
- None
-
---*/
-{
- printf ("%s Version %d.%d Build %s\n", UTILITY_NAME, UTILITY_MAJOR_VERSION, UTILITY_MINOR_VERSION, __BUILD_VERSION);
-}
-
-void
-Usage (
- void
- )
-/*++
-
-Routine Description:
-
- GC_TODO: Add function description
-
-Arguments:
-
-
-Returns:
-
- GC_TODO: add return values
-
---*/
-{
- Version();
- printf ("Copyright (c) 1999-2017 Intel Corporation. All rights reserved.\n");
- printf ("\n SplitFile creates two Binary files either in the same directory as the current working\n");
- printf (" directory or in the specified directory.\n");
- printf ("\nUsage: \n\
- Split\n\
- -f, --filename inputFile to split\n\
- -s, --split VALUE the number of bytes in the first file\n\
- [-p, --prefix OutputDir]\n\
- [-o, --firstfile Filename1]\n\
- [-t, --secondfile Filename2]\n\
- [-v, --verbose]\n\
- [--version]\n\
- [-q, --quiet disable all messages except fatal errors]\n\
- [-d, --debug[#]\n\
- [-h, --help]\n");
-}
-
-EFI_STATUS
-GetSplitValue (
- IN CONST CHAR8* SplitValueString,
- OUT UINT64 *ReturnValue
-)
-{
- UINT64 len = 0;
- UINT64 base = 1;
- UINT64 index = 0;
- UINT64 number = 0;
- CHAR8 lastCHAR = 0;
- EFI_STATUS Status = EFI_SUCCESS;
-
- if (SplitValueString != NULL){
- len = strlen(SplitValueString);
- }
-
- if (len == 0) {
- return EFI_ABORTED;
- }
-
- Status = AsciiStringToUint64 (SplitValueString, FALSE, ReturnValue);
- if (!EFI_ERROR (Status)) {
- return Status;
- }
-
- if (SplitValueString[0] == '0' && (SplitValueString[1] == 'x' || SplitValueString[1] == 'X')) {
- Status = AsciiStringToUint64 (SplitValueString, TRUE, ReturnValue);
- if (!EFI_ERROR (Status)) {
- return Status;
- }
- }
-
- lastCHAR = (CHAR8)toupper((int)SplitValueString[len - 1]);
-
- if (lastCHAR != 'K' && lastCHAR != 'M' && lastCHAR != 'G') {
- return STATUS_ERROR;
- }
-
- for (;index < len - 1; ++index) {
- if (!isdigit((int)SplitValueString[index])) {
- return EFI_ABORTED;
- }
- }
-
- number = atol (SplitValueString);
- if (lastCHAR == 'K')
- base = 1024;
- else if (lastCHAR == 'M')
- base = 1024*1024;
- else
- base = 1024*1024*1024;
-
- *ReturnValue = number*base;
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-CountVerboseLevel (
- IN CONST CHAR8* VerboseLevelString,
- IN CONST UINT64 Length,
- OUT UINT64 *ReturnValue
-)
-{
- UINT64 i = 0;
- for (;i < Length; ++i) {
- if (VerboseLevelString[i] != 'v' && VerboseLevelString[i] != 'V') {
- return EFI_ABORTED;
- }
- ++(*ReturnValue);
- }
-
- return EFI_SUCCESS;
-}
-
-EFI_STATUS
-CreateDir (
- IN OUT CHAR8** FullFileName
-)
-{
- CHAR8* temp = *FullFileName;
- CHAR8* start = temp;
- CHAR8 tempchar;
- UINT64 index = 0;
-
- for (;index < strlen(temp); ++index) {
- if (temp[index] == '\\' || temp[index] == '/') {
- if (temp[index + 1] != '\0') {
- tempchar = temp[index + 1];
- temp[index + 1] = 0;
- if (chdir(start)) {
- if (mkdir(start, S_IRWXU | S_IRWXG | S_IRWXO) != 0) {
- return EFI_ABORTED;
- }
- chdir(start);
- }
- start = temp + index + 1;
- temp[index] = '/';
- temp[index + 1] = tempchar;
- }
- }
- }
-
- return EFI_SUCCESS;
-}
-
-int
-main (
- int argc,
- char*argv[]
- )
-/*++
-
-Routine Description:
-
- GC_TODO: Add function description
-
-Arguments:
-
- argc - GC_TODO: add argument description
- ] - GC_TODO: add argument description
-
-Returns:
-
- GC_TODO: add return values
-
---*/
-{
- EFI_STATUS Status = EFI_SUCCESS;
- INTN ReturnStatus = STATUS_SUCCESS;
- FILE *In;
- CHAR8 *InputFileName = NULL;
- CHAR8 *OutputDir = NULL;
- CHAR8 *OutFileName1 = NULL;
- CHAR8 *OutFileName2 = NULL;
- UINT64 SplitValue = (UINT64) -1;
- FILE *Out1 = NULL;
- FILE *Out2 = NULL;
- CHAR8 *OutName1 = NULL;
- CHAR8 *OutName2 = NULL;
- CHAR8 *CurrentDir = NULL;
- UINT64 Index;
- CHAR8 CharC;
- UINT64 DebugLevel = 0;
- UINT64 VerboseLevel = 0;
-
- SetUtilityName(UTILITY_NAME);
- if (argc == 1) {
- Usage();
- return STATUS_ERROR;
- }
-
- argc --;
- argv ++;
-
- if ((stricmp (argv[0], "-h") == 0) || (stricmp (argv[0], "--help") == 0)) {
- Usage();
- return STATUS_SUCCESS;
- }
-
- if (stricmp (argv[0], "--version") == 0) {
- Version();
- return STATUS_SUCCESS;
- }
-
- while (argc > 0) {
- if ((stricmp (argv[0], "-p") == 0) || (stricmp (argv[0], "--prefix") == 0)) {
- OutputDir = argv[1];
- if (OutputDir == NULL) {
- Warning (NULL, 0, 0, "NO output directory specified.", NULL);
- return STATUS_ERROR;
- }
- argc -= 2;
- argv += 2;
- continue;
- }
-
- if ((stricmp (argv[0], "-f") == 0) || (stricmp (argv[0], "--filename") == 0)) {
- InputFileName = argv[1];
- if (InputFileName == NULL) {
- Error (NULL, 0, 0x1001, "NO Input file specified.", NULL);
- return STATUS_ERROR;
- }
- argc -= 2;
- argv += 2;
- continue;
- }
-
- if ((stricmp (argv[0], "-s") == 0) || (stricmp (argv[0], "--split") == 0)) {
- Status = GetSplitValue(argv[1], &SplitValue);
- if (EFI_ERROR (Status)) {
- Error (NULL, 0, 0x1003, "Input split value is not one valid integer.", NULL);
- return STATUS_ERROR;
- }
- argc -= 2;
- argv += 2;
- continue;
- }
-
- if ((stricmp (argv[0], "-o") == 0) || (stricmp (argv[0], "--firstfile") == 0)) {
- OutFileName1 = argv[1];
- if (OutFileName1 == NULL) {
- Warning (NULL, 0, 0, NULL, "No output file1 specified.");
- }
- argc -= 2;
- argv += 2;
- continue;
- }
-
- if ((stricmp (argv[0], "-t") == 0) || (stricmp (argv[0], "--secondfile") == 0)) {
- OutFileName2 = argv[1];
- if (OutFileName2 == NULL) {
- Warning (NULL, 0, 0, NULL, "No output file2 specified.");
- }
- argc -= 2;
- argv += 2;
- continue;
- }
-
- if ((stricmp (argv[0], "-q") == 0) || (stricmp (argv[0], "--quiet") == 0)) {
- argc --;
- argv ++;
- continue;
- }
-
- if ((strlen(argv[0]) >= 2 && argv[0][0] == '-' && (argv[0][1] == 'v' || argv[0][1] == 'V')) || (stricmp (argv[0], "--verbose") == 0)) {
- VerboseLevel = 1;
- if (strlen(argv[0]) > 2) {
- Status = CountVerboseLevel (&argv[0][2], strlen(argv[0]) - 2, &VerboseLevel);
- if (EFI_ERROR (Status)) {
- Error (NULL, 0, 0x1003, NULL, "%s is invalid parameter!", argv[0]);
- return STATUS_ERROR;
- }
- }
-
- argc --;
- argv ++;
- continue;
- }
-
- if ((stricmp (argv[0], "-d") == 0) || (stricmp (argv[0], "--debug") == 0)) {
- Status = AsciiStringToUint64 (argv[1], FALSE, &DebugLevel);
- if (EFI_ERROR (Status)) {
- Error (NULL, 0, 0x1003, "Input debug level is not one valid integrator.", NULL);
- return STATUS_ERROR;
- }
- argc -= 2;
- argv += 2;
- continue;
- }
- //
- // Don't recognize the parameter.
- //
- Error (NULL, 0, 0x1003, NULL, "%s is invalid parameter!", argv[0]);
- return STATUS_ERROR;
- }
-
- if (InputFileName == NULL) {
- Error (NULL, 0, 0x1001, "NO Input file specified.", NULL);
- return STATUS_ERROR;
- }
-
- In = fopen (LongFilePath (InputFileName), "rb");
- if (In == NULL) {
- // ("Unable to open file \"%s\"\n", InputFileName);
- Error (InputFileName, 0, 1, "File open failure", NULL);
- return STATUS_ERROR;
- }
-
- if (OutFileName1 == NULL) {
- OutName1 = (CHAR8*)malloc(strlen(InputFileName) + 16);
- if (OutName1 == NULL) {
- Warning (NULL, 0, 0, NULL, "Memory Allocation Fail.");
- ReturnStatus = STATUS_ERROR;
- goto Finish;
- }
- strcpy (OutName1, InputFileName);
- strcat (OutName1, "1");
- OutFileName1 = OutName1;
-
- }
- if (OutFileName2 == NULL) {
- OutName2 = (CHAR8*)malloc(strlen(InputFileName) + 16);
- if (OutName2 == NULL) {
- Warning (NULL, 0, 0, NULL, "Memory Allocation Fail.");
- ReturnStatus = STATUS_ERROR;
- goto Finish;
- }
- strcpy (OutName2, InputFileName);
- strcat (OutName2, "2");
- OutFileName2 = OutName2;
-
- }
-
- if (OutputDir != NULL) {
- //OutputDirSpecified = TRUE;
- if (chdir(OutputDir) != 0) {
- Warning (NULL, 0, 0, NULL, "Change dir to OutputDir Fail.");
- ReturnStatus = STATUS_ERROR;
- goto Finish;
- }
- }
-
- CurrentDir = (CHAR8*)getcwd((CHAR8*)0, 0);
- if (EFI_ERROR(CreateDir(&OutFileName1))) {
- Error (OutFileName1, 0, 5, "Create Dir for File1 Fail.", NULL);
- ReturnStatus = STATUS_ERROR;
- goto Finish;
- }
- chdir(CurrentDir);
-
- if (EFI_ERROR(CreateDir(&OutFileName2))) {
- Error (OutFileName2, 0, 5, "Create Dir for File2 Fail.", NULL);
- ReturnStatus = STATUS_ERROR;
- goto Finish;
- }
- chdir(CurrentDir);
- free(CurrentDir);
-
- Out1 = fopen (LongFilePath (OutFileName1), "wb");
- if (Out1 == NULL) {
- // ("Unable to open file \"%s\"\n", OutFileName1);
- Error (OutFileName1, 0, 1, "File open failure", NULL);
- ReturnStatus = STATUS_ERROR;
- goto Finish;
- }
-
- Out2 = fopen (LongFilePath (OutFileName2), "wb");
- if (Out2 == NULL) {
- // ("Unable to open file \"%s\"\n", OutFileName2);
- Error (OutFileName2, 0, 1, "File open failure", NULL);
- ReturnStatus = STATUS_ERROR;
- goto Finish;
- }
-
- for (Index = 0; Index < SplitValue; Index++) {
- CharC = (CHAR8) fgetc (In);
- if (feof (In)) {
- break;
- }
-
- fputc (CharC, Out1);
- }
-
- for (;;) {
- CharC = (CHAR8) fgetc (In);
- if (feof (In)) {
- break;
- }
-
- fputc (CharC, Out2);
- }
-
-Finish:
- if (OutName1 != NULL) {
- free(OutName1);
- }
- if (OutName2 != NULL) {
- free(OutName2);
- }
- if (In != NULL) {
- fclose (In);
- }
- if (Out1 != NULL) {
- fclose (Out1);
- }
- if (Out2 != NULL) {
- fclose (Out2);
- }
-
- return ReturnStatus;
-}
diff --git a/BaseTools/BinWrappers/PosixLike/Split b/BaseTools/BinWrappers/PosixLike/Split
index 0945d86d9209..f3770eed42b4 100755
--- a/BaseTools/BinWrappers/PosixLike/Split
+++ b/BaseTools/BinWrappers/PosixLike/Split
@@ -1,29 +1,14 @@
#!/usr/bin/env bash
+#python `dirname $0`/RunToolFromSource.py `basename $0` $*
+
+# If a ${PYTHON_COMMAND} command is available, use it in preference to python
+if command -v ${PYTHON_COMMAND} >/dev/null 2>&1; then
+ python_exe=${PYTHON_COMMAND}
+fi

full_cmd=${BASH_SOURCE:-$0} # see http://mywiki.wooledge.org/BashFAQ/028 for a discussion of why $0 is not a good choice here
dir=$(dirname "$full_cmd")
cmd=${full_cmd##*/}

-if [ -n "$WORKSPACE" ] && [ -e "$WORKSPACE/Conf/BaseToolsCBinaries" ]
-then
- exec "$WORKSPACE/Conf/BaseToolsCBinaries/$cmd"
-elif [ -n "$WORKSPACE" ] && [ -e "$EDK_TOOLS_PATH/Source/C" ]
-then
- if [ ! -e "$EDK_TOOLS_PATH/Source/C/bin/$cmd" ]
- then
- echo "BaseTools C Tool binary was not found ($cmd)"
- echo "You may need to run:"
- echo " make -C $EDK_TOOLS_PATH/Source/C"
- else
- exec "$EDK_TOOLS_PATH/Source/C/bin/$cmd" "$@"
- fi
-elif [ -e "$dir/../../Source/C/bin/$cmd" ]
-then
- exec "$dir/../../Source/C/bin/$cmd" "$@"
-else
- echo "Unable to find the real '$cmd' to run"
- echo "This message was printed by"
- echo " $0"
- exit 127
-fi
-
+export PYTHONPATH="$dir/../../Source/Python${PYTHONPATH:+:"$PYTHONPATH"}"
+exec "${python_exe:-python}" "$dir/../../Source/Python/$cmd/$cmd.py" "$@"
diff --git a/BaseTools/BinWrappers/WindowsLike/Split.bat b/BaseTools/BinWrappers/WindowsLike/Split.bat
new file mode 100644
index 000000000000..9616cd893bec
--- /dev/null
+++ b/BaseTools/BinWrappers/WindowsLike/Split.bat
@@ -0,0 +1,3 @@
+@setlocal
+@set ToolName=%~n0%
+@%PYTHON_COMMAND% %BASE_TOOLS_PATH%\Source\Python\%ToolName%\%ToolName%.py %*
diff --git a/BaseTools/Source/C/GNUmakefile b/BaseTools/Source/C/GNUmakefile
index 464f43277455..8c191e0c3817 100644
--- a/BaseTools/Source/C/GNUmakefile
+++ b/BaseTools/Source/C/GNUmakefile
@@ -55,11 +55,10 @@ APPLICATIONS = \
GenFv \
GenFw \
GenSec \
GenCrc32 \
LzmaCompress \
- Split \
TianoCompress \
VolInfo \
DevicePath

SUBDIRS := $(LIBRARIES) $(APPLICATIONS)
diff --git a/BaseTools/Source/C/Makefile b/BaseTools/Source/C/Makefile
index e8f8abe59a79..a376d32e220e 100644
--- a/BaseTools/Source/C/Makefile
+++ b/BaseTools/Source/C/Makefile
@@ -17,11 +17,10 @@ APPLICATIONS = \
GenFfs \
GenFv \
GenFw \
GenSec \
LzmaCompress \
- Split \
TianoCompress \
VolInfo \
DevicePath

all: libs apps install
diff --git a/BaseTools/Source/C/Split/GNUmakefile b/BaseTools/Source/C/Split/GNUmakefile
deleted file mode 100644
index b3d4dff51ac1..000000000000
--- a/BaseTools/Source/C/Split/GNUmakefile
+++ /dev/null
@@ -1,17 +0,0 @@
-## @file
-# GNU/Linux makefile for 'Split' module build.
-#
-# Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-MAKEROOT ?= ..
-
-APPNAME = Split
-
-OBJECTS = Split.o
-
-include $(MAKEROOT)/Makefiles/app.makefile
-
-LIBS = -lCommon
-
-
diff --git a/BaseTools/Source/C/Split/Makefile b/BaseTools/Source/C/Split/Makefile
deleted file mode 100644
index 19d3e31a7624..000000000000
--- a/BaseTools/Source/C/Split/Makefile
+++ /dev/null
@@ -1,16 +0,0 @@
-## @file
-# Windows makefile for 'Split' module build.
-#
-# Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-!INCLUDE ..\Makefiles\ms.common
-
-APPNAME = Split
-
-LIBS = $(LIB_PATH)\Common.lib
-
-OBJECTS = Split.obj
-
-!INCLUDE ..\Makefiles\ms.app
-
diff --git a/BaseTools/Source/Python/Split/Split.py b/BaseTools/Source/Python/Split/Split.py
new file mode 100644
index 000000000000..c39f8a7adc61
--- /dev/null
+++ b/BaseTools/Source/Python/Split/Split.py
@@ -0,0 +1,202 @@
+# @file
+# Split a file into two pieces at the request offset.
+#
+# Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+# Import Modules
+#
+import argparse
+import os
+import io
+import shutil
+import logging
+import sys
+import tempfile
+
+parser = argparse.ArgumentParser(description='''
+SplitFile creates two Binary files either in the same directory as the current working directory or in the specified directory.
+''')
+parser.add_argument("-f", "--filename", dest="inputfile",
+ required=True, help="The input file to split tool.")
+parser.add_argument("-s", "--split", dest="position",
+ required=True, help="The number of bytes in the first file. The valid format are HEX, Decimal and Decimal[KMG].")
+parser.add_argument("-p", "--prefix", dest="output",
+ help="The output folder.")
+parser.add_argument("-o", "--firstfile", help="The first file name")
+parser.add_argument("-t", "--secondfile", help="The second file name")
+parser.add_argument("--version", action="version", version='%(prog)s Version 2.0',
+ help="Print debug information.")
+
+group = parser.add_mutually_exclusive_group()
+group.add_argument("-v", "--verbose", action="store_true",
+ help="Print debug information.")
+group.add_argument("-q", "--quiet", action="store_true",
+ help="Disable all messages except fatal errors")
+
+SizeDict = {
+ "K": 1024,
+ "M": 1024*1024,
+ "G": 1024*1024*1024
+}
+
+
+def GetPositionValue(position):
+ '''
+ Parse the string of the argument position and return a decimal number.
+ The valid position formats are
+ 1. HEX
+ e.g. 0x1000 or 0X1000
+ 2. Decimal
+ e.g. 100
+ 3. Decimal[KMG]
+ e.g. 100K or 100M or 100G or 100k or 100m or 100g
+ '''
+ logger = logging.getLogger('Split')
+ PosVal = 0
+ header = position[:2].upper()
+ tailer = position[-1].upper()
+
+ try:
+ if tailer in SizeDict:
+ PosVal = int(position[:-1]) * SizeDict[tailer]
+ else:
+ if header == "0X":
+ PosVal = int(position, 16)
+ else:
+ PosVal = int(position)
+ except Exception as e:
+ logger.error(
+ "The parameter %s format is incorrect. The valid format is HEX, Decimal and Decimal[KMG]." % position)
+ raise(e)
+
+ return PosVal
+
+
+def getFileSize(filename):
+ '''
+ Read the input file and return the file size.
+ '''
+ logger = logging.getLogger('Split')
+ length = 0
+ try:
+ with open(filename, "rb") as fin:
+ fin.seek(0, io.SEEK_END)
+ length = fin.tell()
+ except Exception as e:
+ logger.error("Access file failed: %s", filename)
+ raise(e)
+
+ return length
+
+
+def splitFile(inputfile, position, outputdir=None, outputfile1=None, outputfile2=None):
+ '''
+ Split the inputfile into outputfile1 and outputfile2 from the position.
+ '''
+ logger = logging.getLogger('Split')
+
+ inputfile = os.path.abspath(inputfile)
+ workspace = os.path.dirname(inputfile)
+ if not os.path.exists(inputfile):
+ logger.error("File Not Found: %s" % inputfile)
+ raise(Exception)
+
+ if outputfile1 and outputfile2 and outputfile1 == outputfile2:
+ logger.error(
+ "The firstfile and the secondfile can't be the same: %s" % outputfile1)
+ raise(Exception)
+
+ if not outputdir:
+ outputdir = workspace
+ elif not os.path.isabs(outputdir):
+ outputdir = os.path.join(workspace, outputdir)
+
+ # Create dir for the output files
+ try:
+ if not outputfile1:
+ outputfile1 = os.path.abspath(os.path.join(
+ outputdir, "{}1".format(os.path.basename(inputfile))))
+ else:
+ outputfile1 = os.path.abspath(os.path.join(outputdir, outputfile1))
+ outputdir = os.path.dirname(outputfile1)
+ if not os.path.exists(outputdir):
+ os.makedirs(outputdir)
+
+ if not outputfile2:
+ outputfile2 = os.path.abspath(os.path.join(
+ outputdir, "{}2".format(os.path.basename(inputfile))))
+ else:
+ outputfile2 = os.path.abspath(os.path.join(outputdir, outputfile2))
+ outputdir = os.path.dirname(outputfile2)
+ if not os.path.exists(outputdir):
+ os.makedirs(outputdir)
+ except Exception as e:
+ logger.error("Can't make dir: %s" % outputdir)
+ raise(e)
+
+ if position <= 0:
+ if outputfile2 != inputfile:
+ shutil.copy2(inputfile, outputfile2)
+ with open(outputfile1, "wb") as fout:
+ fout.write(b'')
+ else:
+ inputfilesize = getFileSize(inputfile)
+ if position >= inputfilesize:
+ if outputfile1 != inputfile:
+ shutil.copy2(inputfile, outputfile1)
+ with open(outputfile2, "wb") as fout:
+ fout.write(b'')
+ else:
+ try:
+ tempdir = tempfile.mkdtemp()
+ tempfile1 = os.path.join(tempdir, "file1.bin")
+ tempfile2 = os.path.join(tempdir, "file2.bin")
+ with open(inputfile, "rb") as fin:
+ content1 = fin.read(position)
+ with open(tempfile1, "wb") as fout1:
+ fout1.write(content1)
+
+ content2 = fin.read(inputfilesize - position)
+ with open(tempfile2, "wb") as fout2:
+ fout2.write(content2)
+ shutil.copy2(tempfile1, outputfile1)
+ shutil.copy2(tempfile2, outputfile2)
+ except Exception as e:
+ logger.error("Split file failed")
+ raise(e)
+ finally:
+ if os.path.exists(tempdir):
+ shutil.rmtree(tempdir)
+
+
+def main():
+ args = parser.parse_args()
+ status = 0
+
+ logger = logging.getLogger('Split')
+ if args.quiet:
+ logger.setLevel(logging.CRITICAL)
+ if args.verbose:
+ logger.setLevel(logging.DEBUG)
+
+ lh = logging.StreamHandler(sys.stdout)
+ lf = logging.Formatter("%(levelname)-8s: %(message)s")
+ lh.setFormatter(lf)
+ logger.addHandler(lh)
+
+ try:
+ position = GetPositionValue(args.position)
+ splitFile(args.inputfile, position, args.output,
+ args.firstfile, args.secondfile)
+ except Exception as e:
+ status = 1
+
+ return status
+
+
+if __name__ == "__main__":
+ exit(main())
diff --git a/BaseTools/Source/Python/Split/__init__.py b/BaseTools/Source/Python/Split/__init__.py
new file mode 100644
index 000000000000..8f4daf86e84a
--- /dev/null
+++ b/BaseTools/Source/Python/Split/__init__.py
@@ -0,0 +1,10 @@
+# @file
+# Split a file into two pieces at the request offset.
+#
+# Copyright (c) 2021, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+# Import Modules
--
2.29.1.windows.1


[PATCH v6 08/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of GetRootBridges

Jiahui Cen
 

Extend parameter list of PciHostBridgeUtilityGetRootBridges() with
DmaAbove4G, NoExtendedConfigSpace to support for ArmVirtPkg.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 4 ---
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 24 ++++++++------
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 5 +++
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 34 +++++++++++---------
4 files changed, 39 insertions(+), 28 deletions(-)

diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
index fdae8cfe872e..83a734c1725e 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
@@ -39,9 +39,5 @@ [LibraryClasses]
DebugLib
DevicePathLib
MemoryAllocationLib
- PcdLib
PciLib
QemuFwCfgLib
-
-[Pcd]
- gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
index 2b7d5d3725c3..a0ea44d96a67 100644
--- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -102,23 +102,27 @@ PciHostBridgeUtilityUninitRootBridge (
/**
Utility function to return all the root bridge instances in an array.

- @param[out] Count The number of root bridge instances.
+ @param[out] Count The number of root bridge instances.

- @param[in] Attributes Initial attributes.
+ @param[in] Attributes Initial attributes.

- @param[in] AllocAttributes Allocation attributes.
+ @param[in] AllocAttributes Allocation attributes.

- @param[in] Io IO aperture.
+ @param[in] DmaAbove4G DMA above 4GB memory.

- @param[in] Mem MMIO aperture.
+ @param[in] NoExtendedConfigSpace No Extended Config Space.

- @param[in] MemAbove4G MMIO aperture above 4G.
+ @param[in] Io IO aperture.

- @param[in] PMem Prefetchable MMIO aperture.
+ @param[in] Mem MMIO aperture.

- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+ @param[in] MemAbove4G MMIO aperture above 4G.

- @return All the root bridge instances in an array.
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @return All the root bridge instances in an array.
**/
PCI_ROOT_BRIDGE *
EFIAPI
@@ -126,6 +130,8 @@ PciHostBridgeUtilityGetRootBridges (
OUT UINTN *Count,
IN UINT64 Attributes,
IN UINT64 AllocationAttributes,
+ IN BOOLEAN DmaAbove4G,
+ IN BOOLEAN NoExtendedConfigSpace,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
IN PCI_ROOT_BRIDGE_APERTURE *Mem,
IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 6ac41ff853a9..91b9e6baa1e8 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -9,6 +9,9 @@
**/
#include <PiDxe.h>

+#include <IndustryStandard/Pci.h>
+#include <IndustryStandard/Q35MchIch9.h>
+
#include <Protocol/PciHostBridgeResourceAllocation.h>
#include <Protocol/PciRootBridgeIo.h>

@@ -80,6 +83,8 @@ PciHostBridgeGetRootBridges (
Count,
Attributes,
AllocationAttributes,
+ FALSE,
+ PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
&Io,
&Mem,
&MemAbove4G,
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
index b1e74a469d50..1d78984b83ad 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -12,12 +12,10 @@

#include <IndustryStandard/Acpi10.h>
#include <IndustryStandard/Pci.h>
-#include <IndustryStandard/Q35MchIch9.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
-#include <Library/PcdLib.h>
#include <Library/PciHostBridgeUtilityLib.h>
#include <Library/PciLib.h>
#include <Library/QemuFwCfgLib.h>
@@ -192,23 +190,27 @@ PciHostBridgeUtilityUninitRootBridge (
/**
Utility function to return all the root bridge instances in an array.

- @param[out] Count The number of root bridge instances.
+ @param[out] Count The number of root bridge instances.

- @param[in] Attributes Initial attributes.
+ @param[in] Attributes Initial attributes.

- @param[in] AllocAttributes Allocation attributes.
+ @param[in] AllocAttributes Allocation attributes.

- @param[in] Io IO aperture.
+ @param[in] DmaAbove4G DMA above 4GB memory.

- @param[in] Mem MMIO aperture.
+ @param[in] NoExtendedConfigSpace No Extended Config Space.

- @param[in] MemAbove4G MMIO aperture above 4G.
+ @param[in] Io IO aperture.

- @param[in] PMem Prefetchable MMIO aperture.
+ @param[in] Mem MMIO aperture.

- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+ @param[in] MemAbove4G MMIO aperture above 4G.

- @return All the root bridge instances in an array.
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @return All the root bridge instances in an array.
**/
PCI_ROOT_BRIDGE *
EFIAPI
@@ -216,6 +218,8 @@ PciHostBridgeUtilityGetRootBridges (
OUT UINTN *Count,
IN UINT64 Attributes,
IN UINT64 AllocationAttributes,
+ IN BOOLEAN DmaAbove4G,
+ IN BOOLEAN NoExtendedConfigSpace,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
IN PCI_ROOT_BRIDGE_APERTURE *Mem,
IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
@@ -295,8 +299,8 @@ PciHostBridgeUtilityGetRootBridges (
Attributes,
Attributes,
AllocationAttributes,
- FALSE,
- PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
+ DmaAbove4G,
+ NoExtendedConfigSpace,
(UINT8) LastRootBridgeNumber,
(UINT8) (RootBridgeNumber - 1),
Io,
@@ -322,8 +326,8 @@ PciHostBridgeUtilityGetRootBridges (
Attributes,
Attributes,
AllocationAttributes,
- FALSE,
- PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
+ DmaAbove4G,
+ NoExtendedConfigSpace,
(UINT8) LastRootBridgeNumber,
PCI_MAX_BUS,
Io,
--
2.29.2


[PATCH v6 11/11] ArmVirtPkg/ArmVirtQemu: Add support for HotPlug

Jiahui Cen
 

It is necessary to add padding for hotplugable PCI Devices like
pcie-root-port.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
ArmVirtPkg/ArmVirtQemu.dsc | 1 +
ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 +
ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 1 +
3 files changed, 3 insertions(+)

diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index a11ffd9ba553..d77c226d80ee 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -488,6 +488,7 @@ [Components.common]
<LibraryClasses>
NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
}
+ OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
OvmfPkg/Virtio10Dxe/Virtio10.inf

diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index c27752b4d5e5..92f327eec4fb 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -424,6 +424,7 @@ [Components.common]
<LibraryClasses>
NULL|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
}
+ OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
OvmfPkg/Virtio10Dxe/Virtio10.inf

diff --git a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
index 1752fee12b79..5b1d10057545 100644
--- a/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
+++ b/ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc
@@ -162,6 +162,7 @@ [FV.FvMain]
INF ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf
INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf
INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
+ INF OvmfPkg/PciHotPlugInitDxe/PciHotPlugInit.inf
INF OvmfPkg/VirtioPciDeviceDxe/VirtioPciDeviceDxe.inf
INF OvmfPkg/Virtio10Dxe/Virtio10.inf

--
2.29.2


[PATCH v6 10/11] ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support

Jiahui Cen
 

In order to take advantages of extra pci root buses in ArmVirtPkg, it is
necessary to scan extra root buses when getting root briges. And now
PciHostBridgeUtilityLib already provides a set of utility functions that
support for extra pci root buses, like PciHostBridgeUtilityGetRootBridges()
/ PciHostBridgeUtilityFreeRootBridges(). So let's rebase
ArmVirtPkg/FdtPciHostBridgeLib to PciHostBridgeUtilityGetRootBridges() /
PciHostBridgeUtilityFreeRootBridges() to extend ArmVirtPkg with extra
pci root buses support.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 22 ++++----------------
1 file changed, 4 insertions(+), 18 deletions(-)

diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
index 3ec7992b6331..0099b8e3c391 100644
--- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
+++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
@@ -272,8 +272,6 @@ ProcessPciHost (
return Status;
}

-STATIC PCI_ROOT_BRIDGE mRootBridge;
-
/**
Return all the root bridge instances in an array.

@@ -361,8 +359,8 @@ PciHostBridgeGetRootBridges (
PMemAbove4G.Base = MAX_UINT64;
PMemAbove4G.Limit = 0;

- Status = PciHostBridgeUtilityInitRootBridge (
- Attributes,
+ return PciHostBridgeUtilityGetRootBridges (
+ Count,
Attributes,
AllocationAttributes,
TRUE,
@@ -373,19 +371,8 @@ PciHostBridgeGetRootBridges (
&Mem,
&MemAbove4G,
&PMem,
- &PMemAbove4G,
- &mRootBridge
+ &PMemAbove4G
);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "%a: failed to initialize PCI host bridge: %r\n",
- __FUNCTION__, Status));
- *Count = 0;
- return NULL;
- }
-
- *Count = 1;
-
- return &mRootBridge;
}

/**
@@ -402,8 +389,7 @@ PciHostBridgeFreeRootBridges (
UINTN Count
)
{
- ASSERT (Count == 1);
- PciHostBridgeUtilityUninitRootBridge (Bridges);
+ PciHostBridgeUtilityFreeRootBridges (Bridges, Count);
}

/**
--
2.29.2


[PATCH v6 09/11] OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with BusMin/BusMax

Jiahui Cen
 

Extend parameter list of PciHostBridgeUtilityGetRootBridges() with BusMin/
BusMax, so that the utility function could be compatible with ArmVirtPkg
who uses mutable bus range [BusMin, BusMax] insteand of [0, PCI_MAX_BUS].

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
---
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 6 ++++
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 2 ++
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 30 ++++++++++++++++----
3 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
index a0ea44d96a67..d2dc18a1afad 100644
--- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -112,6 +112,10 @@ PciHostBridgeUtilityUninitRootBridge (

@param[in] NoExtendedConfigSpace No Extended Config Space.

+ @param[in] BusMin Minimum Bus number, inclusive.
+
+ @param[in] BusMax Maximum Bus number, inclusive.
+
@param[in] Io IO aperture.

@param[in] Mem MMIO aperture.
@@ -132,6 +136,8 @@ PciHostBridgeUtilityGetRootBridges (
IN UINT64 AllocationAttributes,
IN BOOLEAN DmaAbove4G,
IN BOOLEAN NoExtendedConfigSpace,
+ IN UINTN BusMin,
+ IN UINTN BusMax,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
IN PCI_ROOT_BRIDGE_APERTURE *Mem,
IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 91b9e6baa1e8..7d9fb0fb293a 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -85,6 +85,8 @@ PciHostBridgeGetRootBridges (
AllocationAttributes,
FALSE,
PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
+ 0,
+ PCI_MAX_BUS,
&Io,
&Mem,
&MemAbove4G,
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
index 1d78984b83ad..69bed5c7843f 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -200,6 +200,10 @@ PciHostBridgeUtilityUninitRootBridge (

@param[in] NoExtendedConfigSpace No Extended Config Space.

+ @param[in] BusMin Minimum Bus number, inclusive.
+
+ @param[in] BusMax Maximum Bus number, inclusive.
+
@param[in] Io IO aperture.

@param[in] Mem MMIO aperture.
@@ -220,6 +224,8 @@ PciHostBridgeUtilityGetRootBridges (
IN UINT64 AllocationAttributes,
IN BOOLEAN DmaAbove4G,
IN BOOLEAN NoExtendedConfigSpace,
+ IN UINTN BusMin,
+ IN UINTN BusMax,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
IN PCI_ROOT_BRIDGE_APERTURE *Mem,
IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
@@ -236,6 +242,13 @@ PciHostBridgeUtilityGetRootBridges (
UINTN LastRootBridgeNumber;
UINTN RootBridgeNumber;

+ if (BusMin > BusMax || BusMax > PCI_MAX_BUS) {
+ DEBUG ((DEBUG_ERROR, "%a: invalid bus range with BusMin %d and BusMax %d\n",
+ __FUNCTION__, BusMin, BusMax));
+ *Count = 0;
+ return NULL;
+ }
+
//
// QEMU provides the number of extra root buses, shortening the exhaustive
// search below. If there is no hint, the feature is missing.
@@ -247,7 +260,14 @@ PciHostBridgeUtilityGetRootBridges (
QemuFwCfgSelectItem (FwCfgItem);
QemuFwCfgReadBytes (FwCfgSize, &ExtraRootBridges);

- if (ExtraRootBridges > PCI_MAX_BUS) {
+ //
+ // Validate the number of extra root bridges. As BusMax is inclusive, the
+ // max bus count is (BusMax - BusMin + 1). From that, the "main" root bus
+ // is always givin, so the max count for the "extra" root bridges is one
+ // less, i.e. (BusMax - BusMin). If QEME hint exceeds that, we have invalid
+ // behavior.
+ //
+ if (ExtraRootBridges > BusMax - BusMin) {
DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) "
"reported by QEMU\n", __FUNCTION__, ExtraRootBridges));
*Count = 0;
@@ -271,15 +291,15 @@ PciHostBridgeUtilityGetRootBridges (
//
// The "main" root bus is always there.
//
- LastRootBridgeNumber = 0;
+ LastRootBridgeNumber = BusMin;

//
// Scan all other root buses. If function 0 of any device on a bus returns a
// VendorId register value different from all-bits-one, then that bus is
// alive.
//
- for (RootBridgeNumber = 1;
- RootBridgeNumber <= PCI_MAX_BUS && Initialized < ExtraRootBridges;
+ for (RootBridgeNumber = BusMin + 1;
+ RootBridgeNumber <= BusMax && Initialized < ExtraRootBridges;
++RootBridgeNumber) {
UINTN Device;

@@ -329,7 +349,7 @@ PciHostBridgeUtilityGetRootBridges (
DmaAbove4G,
NoExtendedConfigSpace,
(UINT8) LastRootBridgeNumber,
- PCI_MAX_BUS,
+ (UINT8) BusMax,
Io,
Mem,
MemAbove4G,
--
2.29.2


[PATCH v6 07/11] OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges()

Jiahui Cen
 

Extract PciHostBridgeGetRootBridges() / PciHostBridgeFreeRootBridges() to
PciHostBridgeUtilityLib as common utility functions to share support for
scanning extra root bridges.

No change of functionality.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 -
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 6 +
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 50 +++++
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 138 +-------------
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 197 ++++++++++++++++++++
5 files changed, 257 insertions(+), 135 deletions(-)

diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
index 72458262cb42..4610a0c1490b 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
@@ -41,7 +41,6 @@ [LibraryClasses]
PcdLib
PciHostBridgeUtilityLib
PciLib
- QemuFwCfgLib

[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdPciIoBase
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
index 4d6764b702f4..fdae8cfe872e 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
@@ -39,3 +39,9 @@ [LibraryClasses]
DebugLib
DevicePathLib
MemoryAllocationLib
+ PcdLib
+ PciLib
+ QemuFwCfgLib
+
+[Pcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
index a44ad5034520..2b7d5d3725c3 100644
--- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -99,6 +99,56 @@ PciHostBridgeUtilityUninitRootBridge (
);


+/**
+ Utility function to return all the root bridge instances in an array.
+
+ @param[out] Count The number of root bridge instances.
+
+ @param[in] Attributes Initial attributes.
+
+ @param[in] AllocAttributes Allocation attributes.
+
+ @param[in] Io IO aperture.
+
+ @param[in] Mem MMIO aperture.
+
+ @param[in] MemAbove4G MMIO aperture above 4G.
+
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @return All the root bridge instances in an array.
+**/
+PCI_ROOT_BRIDGE *
+EFIAPI
+PciHostBridgeUtilityGetRootBridges (
+ OUT UINTN *Count,
+ IN UINT64 Attributes,
+ IN UINT64 AllocationAttributes,
+ IN PCI_ROOT_BRIDGE_APERTURE *Io,
+ IN PCI_ROOT_BRIDGE_APERTURE *Mem,
+ IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
+ IN PCI_ROOT_BRIDGE_APERTURE *PMem,
+ IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G
+ );
+
+
+/**
+ Utility function to free root bridge instances array from
+ PciHostBridgeUtilityGetRootBridges().
+
+ @param[in] Bridges The root bridge instances array.
+ @param[in] Count The count of the array.
+**/
+VOID
+EFIAPI
+PciHostBridgeUtilityFreeRootBridges (
+ IN PCI_ROOT_BRIDGE *Bridges,
+ IN UINTN Count
+ );
+
+
/**
Utility function to inform the platform that the resource conflict happens.

diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 8758d7c12bf0..6ac41ff853a9 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -9,9 +9,6 @@
**/
#include <PiDxe.h>

-#include <IndustryStandard/Pci.h>
-#include <IndustryStandard/Q35MchIch9.h>
-
#include <Protocol/PciHostBridgeResourceAllocation.h>
#include <Protocol/PciRootBridgeIo.h>

@@ -21,8 +18,6 @@
#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
#include <Library/PciHostBridgeUtilityLib.h>
-#include <Library/PciLib.h>
-#include <Library/QemuFwCfgLib.h>
#include "PciHostBridge.h"


@@ -44,14 +39,6 @@ PciHostBridgeGetRootBridges (
UINTN *Count
)
{
- EFI_STATUS Status;
- FIRMWARE_CONFIG_ITEM FwCfgItem;
- UINTN FwCfgSize;
- UINT64 ExtraRootBridges;
- PCI_ROOT_BRIDGE *Bridges;
- UINTN Initialized;
- UINTN LastRootBridgeNumber;
- UINTN RootBridgeNumber;
UINT64 Attributes;
UINT64 AllocationAttributes;
PCI_ROOT_BRIDGE_APERTURE Io;
@@ -89,123 +76,16 @@ PciHostBridgeGetRootBridges (
Mem.Base = PcdGet64 (PcdPciMmio32Base);
Mem.Limit = PcdGet64 (PcdPciMmio32Base) + (PcdGet64 (PcdPciMmio32Size) - 1);

- *Count = 0;
-
- //
- // QEMU provides the number of extra root buses, shortening the exhaustive
- // search below. If there is no hint, the feature is missing.
- //
- Status = QemuFwCfgFindFile ("etc/extra-pci-roots", &FwCfgItem, &FwCfgSize);
- if (EFI_ERROR (Status) || FwCfgSize != sizeof ExtraRootBridges) {
- ExtraRootBridges = 0;
- } else {
- QemuFwCfgSelectItem (FwCfgItem);
- QemuFwCfgReadBytes (FwCfgSize, &ExtraRootBridges);
-
- if (ExtraRootBridges > PCI_MAX_BUS) {
- DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) "
- "reported by QEMU\n", __FUNCTION__, ExtraRootBridges));
- return NULL;
- }
- DEBUG ((DEBUG_INFO, "%a: %Lu extra root buses reported by QEMU\n",
- __FUNCTION__, ExtraRootBridges));
- }
-
- //
- // Allocate the "main" root bridge, and any extra root bridges.
- //
- Bridges = AllocatePool ((1 + (UINTN)ExtraRootBridges) * sizeof *Bridges);
- if (Bridges == NULL) {
- DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
- return NULL;
- }
- Initialized = 0;
-
- //
- // The "main" root bus is always there.
- //
- LastRootBridgeNumber = 0;
-
- //
- // Scan all other root buses. If function 0 of any device on a bus returns a
- // VendorId register value different from all-bits-one, then that bus is
- // alive.
- //
- for (RootBridgeNumber = 1;
- RootBridgeNumber <= PCI_MAX_BUS && Initialized < ExtraRootBridges;
- ++RootBridgeNumber) {
- UINTN Device;
-
- for (Device = 0; Device <= PCI_MAX_DEVICE; ++Device) {
- if (PciRead16 (PCI_LIB_ADDRESS (RootBridgeNumber, Device, 0,
- PCI_VENDOR_ID_OFFSET)) != MAX_UINT16) {
- break;
- }
- }
- if (Device <= PCI_MAX_DEVICE) {
- //
- // Found the next root bus. We can now install the *previous* one,
- // because now we know how big a bus number range *that* one has, for any
- // subordinate buses that might exist behind PCI bridges hanging off it.
- //
- Status = PciHostBridgeUtilityInitRootBridge (
- Attributes,
- Attributes,
- AllocationAttributes,
- FALSE,
- PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
- (UINT8) LastRootBridgeNumber,
- (UINT8) (RootBridgeNumber - 1),
- &Io,
- &Mem,
- &MemAbove4G,
- &mNonExistAperture,
- &mNonExistAperture,
- &Bridges[Initialized]
- );
- if (EFI_ERROR (Status)) {
- goto FreeBridges;
- }
- ++Initialized;
- LastRootBridgeNumber = RootBridgeNumber;
- }
- }
-
- //
- // Install the last root bus (which might be the only, ie. main, root bus, if
- // we've found no extra root buses).
- //
- Status = PciHostBridgeUtilityInitRootBridge (
- Attributes,
+ return PciHostBridgeUtilityGetRootBridges (
+ Count,
Attributes,
AllocationAttributes,
- FALSE,
- PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
- (UINT8) LastRootBridgeNumber,
- PCI_MAX_BUS,
&Io,
&Mem,
&MemAbove4G,
&mNonExistAperture,
- &mNonExistAperture,
- &Bridges[Initialized]
+ &mNonExistAperture
);
- if (EFI_ERROR (Status)) {
- goto FreeBridges;
- }
- ++Initialized;
-
- *Count = Initialized;
- return Bridges;
-
-FreeBridges:
- while (Initialized > 0) {
- --Initialized;
- PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]);
- }
-
- FreePool (Bridges);
- return NULL;
}


@@ -223,17 +103,7 @@ PciHostBridgeFreeRootBridges (
UINTN Count
)
{
- if (Bridges == NULL && Count == 0) {
- return;
- }
- ASSERT (Bridges != NULL && Count > 0);
-
- do {
- --Count;
- PciHostBridgeUtilityUninitRootBridge (&Bridges[Count]);
- } while (Count > 0);
-
- FreePool (Bridges);
+ PciHostBridgeUtilityFreeRootBridges (Bridges, Count);
}


diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
index bed2d87ea89c..b1e74a469d50 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -11,11 +11,16 @@
**/

#include <IndustryStandard/Acpi10.h>
+#include <IndustryStandard/Pci.h>
+#include <IndustryStandard/Q35MchIch9.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include <Library/PciHostBridgeUtilityLib.h>
+#include <Library/PciLib.h>
+#include <Library/QemuFwCfgLib.h>


#pragma pack(1)
@@ -184,6 +189,198 @@ PciHostBridgeUtilityUninitRootBridge (
}


+/**
+ Utility function to return all the root bridge instances in an array.
+
+ @param[out] Count The number of root bridge instances.
+
+ @param[in] Attributes Initial attributes.
+
+ @param[in] AllocAttributes Allocation attributes.
+
+ @param[in] Io IO aperture.
+
+ @param[in] Mem MMIO aperture.
+
+ @param[in] MemAbove4G MMIO aperture above 4G.
+
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @return All the root bridge instances in an array.
+**/
+PCI_ROOT_BRIDGE *
+EFIAPI
+PciHostBridgeUtilityGetRootBridges (
+ OUT UINTN *Count,
+ IN UINT64 Attributes,
+ IN UINT64 AllocationAttributes,
+ IN PCI_ROOT_BRIDGE_APERTURE *Io,
+ IN PCI_ROOT_BRIDGE_APERTURE *Mem,
+ IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
+ IN PCI_ROOT_BRIDGE_APERTURE *PMem,
+ IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G
+ )
+{
+ EFI_STATUS Status;
+ FIRMWARE_CONFIG_ITEM FwCfgItem;
+ UINTN FwCfgSize;
+ UINT64 ExtraRootBridges;
+ PCI_ROOT_BRIDGE *Bridges;
+ UINTN Initialized;
+ UINTN LastRootBridgeNumber;
+ UINTN RootBridgeNumber;
+
+ //
+ // QEMU provides the number of extra root buses, shortening the exhaustive
+ // search below. If there is no hint, the feature is missing.
+ //
+ Status = QemuFwCfgFindFile ("etc/extra-pci-roots", &FwCfgItem, &FwCfgSize);
+ if (EFI_ERROR (Status) || FwCfgSize != sizeof ExtraRootBridges) {
+ ExtraRootBridges = 0;
+ } else {
+ QemuFwCfgSelectItem (FwCfgItem);
+ QemuFwCfgReadBytes (FwCfgSize, &ExtraRootBridges);
+
+ if (ExtraRootBridges > PCI_MAX_BUS) {
+ DEBUG ((DEBUG_ERROR, "%a: invalid count of extra root buses (%Lu) "
+ "reported by QEMU\n", __FUNCTION__, ExtraRootBridges));
+ *Count = 0;
+ return NULL;
+ }
+ DEBUG ((DEBUG_INFO, "%a: %Lu extra root buses reported by QEMU\n",
+ __FUNCTION__, ExtraRootBridges));
+ }
+
+ //
+ // Allocate the "main" root bridge, and any extra root bridges.
+ //
+ Bridges = AllocatePool ((1 + (UINTN)ExtraRootBridges) * sizeof *Bridges);
+ if (Bridges == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
+ *Count = 0;
+ return NULL;
+ }
+ Initialized = 0;
+
+ //
+ // The "main" root bus is always there.
+ //
+ LastRootBridgeNumber = 0;
+
+ //
+ // Scan all other root buses. If function 0 of any device on a bus returns a
+ // VendorId register value different from all-bits-one, then that bus is
+ // alive.
+ //
+ for (RootBridgeNumber = 1;
+ RootBridgeNumber <= PCI_MAX_BUS && Initialized < ExtraRootBridges;
+ ++RootBridgeNumber) {
+ UINTN Device;
+
+ for (Device = 0; Device <= PCI_MAX_DEVICE; ++Device) {
+ if (PciRead16 (PCI_LIB_ADDRESS (RootBridgeNumber, Device, 0,
+ PCI_VENDOR_ID_OFFSET)) != MAX_UINT16) {
+ break;
+ }
+ }
+ if (Device <= PCI_MAX_DEVICE) {
+ //
+ // Found the next root bus. We can now install the *previous* one,
+ // because now we know how big a bus number range *that* one has, for any
+ // subordinate buses that might exist behind PCI bridges hanging off it.
+ //
+ Status = PciHostBridgeUtilityInitRootBridge (
+ Attributes,
+ Attributes,
+ AllocationAttributes,
+ FALSE,
+ PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
+ (UINT8) LastRootBridgeNumber,
+ (UINT8) (RootBridgeNumber - 1),
+ Io,
+ Mem,
+ MemAbove4G,
+ PMem,
+ PMemAbove4G,
+ &Bridges[Initialized]
+ );
+ if (EFI_ERROR (Status)) {
+ goto FreeBridges;
+ }
+ ++Initialized;
+ LastRootBridgeNumber = RootBridgeNumber;
+ }
+ }
+
+ //
+ // Install the last root bus (which might be the only, ie. main, root bus, if
+ // we've found no extra root buses).
+ //
+ Status = PciHostBridgeUtilityInitRootBridge (
+ Attributes,
+ Attributes,
+ AllocationAttributes,
+ FALSE,
+ PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
+ (UINT8) LastRootBridgeNumber,
+ PCI_MAX_BUS,
+ Io,
+ Mem,
+ MemAbove4G,
+ PMem,
+ PMemAbove4G,
+ &Bridges[Initialized]
+ );
+ if (EFI_ERROR (Status)) {
+ goto FreeBridges;
+ }
+ ++Initialized;
+
+ *Count = Initialized;
+ return Bridges;
+
+FreeBridges:
+ while (Initialized > 0) {
+ --Initialized;
+ PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]);
+ }
+
+ FreePool (Bridges);
+ *Count = 0;
+ return NULL;
+}
+
+
+/**
+ Utility function to free root bridge instances array from
+ PciHostBridgeUtilityGetRootBridges().
+
+ @param[in] Bridges The root bridge instances array.
+ @param[in] Count The count of the array.
+**/
+VOID
+EFIAPI
+PciHostBridgeUtilityFreeRootBridges (
+ IN PCI_ROOT_BRIDGE *Bridges,
+ IN UINTN Count
+ )
+{
+ if (Bridges == NULL && Count == 0) {
+ return;
+ }
+ ASSERT (Bridges != NULL && Count > 0);
+
+ do {
+ --Count;
+ PciHostBridgeUtilityUninitRootBridge (&Bridges[Count]);
+ } while (Count > 0);
+
+ FreePool (Bridges);
+}
+
+
/**
Utility function to inform the platform that the resource conflict happens.

--
2.29.2


[PATCH v6 01/11] OvmfPkg: Introduce PciHostBridgeUtilityLib class

Jiahui Cen
 

Introduce a new PciHostBridgeUtilityLib class to share duplicate code
between OvmfPkg and ArmVirtPkg.

Extract function PciHostBridgeUtilityResourceConflict from
PciHostBridgeResourceConflict in OvmfPkg/PciHostBridgeLib.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Peter Grehan <grehan@freebsd.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien@xen.org>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
OvmfPkg/OvmfPkg.dec | 4 +
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/Bhyve/BhyveX64.dsc | 1 +
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/OvmfXen.dsc | 1 +
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 +
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 37 ++++++++++
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 38 ++++++++++
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 41 +---------
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 78 ++++++++++++++++++++
12 files changed, 166 insertions(+), 39 deletions(-)

diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec
index 54804962ec02..4348bb45c64a 100644
--- a/OvmfPkg/OvmfPkg.dec
+++ b/OvmfPkg/OvmfPkg.dec
@@ -49,6 +49,10 @@ [LibraryClasses]
# access.
PciCapPciSegmentLib|Include/Library/PciCapPciSegmentLib.h

+ ## @libraryclass Provide common utility functions to PciHostBridgeLib
+ # instances in ArmVirtPkg and OvmfPkg.
+ PciHostBridgeUtilityLib|Include/Library/PciHostBridgeUtilityLib.h
+
## @libraryclass Register a status code handler for printing the Boot
# Manager's LoadImage() and StartImage() preparations, and
# return codes, to the UEFI console.
diff --git a/OvmfPkg/AmdSev/AmdSevX64.dsc b/OvmfPkg/AmdSev/AmdSevX64.dsc
index dad8635c3388..62e97dbe320a 100644
--- a/OvmfPkg/AmdSev/AmdSevX64.dsc
+++ b/OvmfPkg/AmdSev/AmdSevX64.dsc
@@ -669,6 +669,7 @@ [Components]
MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {
<LibraryClasses>
PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf
}
MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {
diff --git a/OvmfPkg/Bhyve/BhyveX64.dsc b/OvmfPkg/Bhyve/BhyveX64.dsc
index 33edf3d2d6b5..9547523018e9 100644
--- a/OvmfPkg/Bhyve/BhyveX64.dsc
+++ b/OvmfPkg/Bhyve/BhyveX64.dsc
@@ -662,6 +662,7 @@ [Components]
MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {
<LibraryClasses>
PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf
}
MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {
diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc
index 75c5f46a7786..3555bd1691f2 100644
--- a/OvmfPkg/OvmfPkgIa32.dsc
+++ b/OvmfPkg/OvmfPkgIa32.dsc
@@ -747,6 +747,7 @@ [Components]
MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {
<LibraryClasses>
PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf
}
MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {
diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc
index 8693248b4ea0..d668c5c8eda8 100644
--- a/OvmfPkg/OvmfPkgIa32X64.dsc
+++ b/OvmfPkg/OvmfPkgIa32X64.dsc
@@ -761,6 +761,7 @@ [Components.X64]
MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {
<LibraryClasses>
PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf
}
MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index 70ff2bcf2342..ff32efb5ba8b 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -759,6 +759,7 @@ [Components]
MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {
<LibraryClasses>
PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf
}
MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {
diff --git a/OvmfPkg/OvmfXen.dsc b/OvmfPkg/OvmfXen.dsc
index 7d31e88907ca..ed34efe8ce47 100644
--- a/OvmfPkg/OvmfXen.dsc
+++ b/OvmfPkg/OvmfXen.dsc
@@ -552,6 +552,7 @@ [Components]
MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf {
<LibraryClasses>
PciHostBridgeLib|OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
NULL|OvmfPkg/Library/PlatformHasIoMmuLib/PlatformHasIoMmuLib.inf
}
MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf {
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
index 6ec9ec751478..4c56f3c90b3b 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
@@ -39,6 +39,7 @@ [LibraryClasses]
DebugLib
DevicePathLib
MemoryAllocationLib
+ PciHostBridgeUtilityLib
PciLib
QemuFwCfgLib

diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
new file mode 100644
index 000000000000..1ba8ec3e03c7
--- /dev/null
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
@@ -0,0 +1,37 @@
+## @file
+# Provide common utility functions to PciHostBridgeLib instances in
+# ArmVirtPkg and OvmfPkg.
+#
+# Copyright (C) 2016, Red Hat, Inc.
+# Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+#
+##
+
+[Defines]
+ INF_VERSION = 1.29
+ BASE_NAME = PciHostBridgeUtilityLib
+ FILE_GUID = e3aa5932-527a-42e7-86f5-81b144c7e5f1
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = PciHostBridgeUtilityLib
+
+#
+# The following information is for reference only and not required by the build
+# tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 AARCH64 ARM
+#
+
+[Sources]
+ PciHostBridgeUtilityLib.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec
+
+[LibraryClasses]
+ DebugLib
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
new file mode 100644
index 000000000000..5ea25ed2f4f4
--- /dev/null
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -0,0 +1,38 @@
+/** @file
+ Provide common utility functions to PciHostBridgeLib instances in
+ ArmVirtPkg and OvmfPkg.
+
+ Copyright (C) 2016, Red Hat, Inc.
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef __PCI_HOST_BRIDGE_UTILITY_LIB_H__
+#define __PCI_HOST_BRIDGE_UTILITY_LIB_H__
+
+
+/**
+ Utility function to inform the platform that the resource conflict happens.
+
+ @param[in] Configuration Pointer to PCI I/O and PCI memory resource
+ descriptors. The Configuration contains the
+ resources for all the root bridges. The resource
+ for each root bridge is terminated with END
+ descriptor and an additional END is appended
+ indicating the end of the entire resources. The
+ resource descriptor field values follow the
+ description in
+ EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
+ .SubmitResources().
+**/
+VOID
+EFIAPI
+PciHostBridgeUtilityResourceConflict (
+ IN VOID *Configuration
+ );
+
+
+#endif // __PCI_HOST_BRIDGE_UTILITY_LIB_H__
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index e850f7d183ee..4a176347fd49 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -20,6 +20,7 @@
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PciHostBridgeLib.h>
+#include <Library/PciHostBridgeUtilityLib.h>
#include <Library/PciLib.h>
#include <Library/QemuFwCfgLib.h>
#include "PciHostBridge.h"
@@ -33,12 +34,6 @@ typedef struct {
#pragma pack ()


-GLOBAL_REMOVE_IF_UNREFERENCED
-CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] = {
- L"Mem", L"I/O", L"Bus"
-};
-
-
STATIC
CONST
OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
@@ -407,37 +402,5 @@ PciHostBridgeResourceConflict (
VOID *Configuration
)
{
- EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;
- UINTN RootBridgeIndex;
- DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n"));
-
- RootBridgeIndex = 0;
- Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;
- while (Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {
- DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));
- for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {
- ASSERT (Descriptor->ResType <
- ARRAY_SIZE (mPciHostBridgeLibAcpiAddressSpaceTypeStr)
- );
- DEBUG ((DEBUG_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n",
- mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType],
- Descriptor->AddrLen, Descriptor->AddrRangeMax
- ));
- if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) {
- DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag = %ld / %02x%s\n",
- Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag,
- ((Descriptor->SpecificFlag &
- EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE
- ) != 0) ? L" (Prefetchable)" : L""
- ));
- }
- }
- //
- // Skip the END descriptor for root bridge
- //
- ASSERT (Descriptor->Desc == ACPI_END_TAG_DESCRIPTOR);
- Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)(
- (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1
- );
- }
+ PciHostBridgeUtilityResourceConflict (Configuration);
}
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
new file mode 100644
index 000000000000..ac94e62612be
--- /dev/null
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -0,0 +1,78 @@
+/** @file
+ Provide common utility functions to PciHostBridgeLib instances in
+ ArmVirtPkg and OvmfPkg.
+
+ Copyright (C) 2016, Red Hat, Inc.
+ Copyright (c) 2016, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2020, Huawei Corporation. All rights reserved.<BR>
+
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <IndustryStandard/Acpi10.h>
+#include <Library/DebugLib.h>
+#include <Library/PciHostBridgeUtilityLib.h>
+
+
+GLOBAL_REMOVE_IF_UNREFERENCED
+CHAR16 *mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[] = {
+ L"Mem", L"I/O", L"Bus"
+};
+
+
+/**
+ Utility function to inform the platform that the resource conflict happens.
+
+ @param[in] Configuration Pointer to PCI I/O and PCI memory resource
+ descriptors. The Configuration contains the
+ resources for all the root bridges. The resource
+ for each root bridge is terminated with END
+ descriptor and an additional END is appended
+ indicating the end of the entire resources. The
+ resource descriptor field values follow the
+ description in
+ EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL
+ .SubmitResources().
+**/
+VOID
+EFIAPI
+PciHostBridgeUtilityResourceConflict (
+ IN VOID *Configuration
+ )
+{
+ EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;
+ UINTN RootBridgeIndex;
+ DEBUG ((DEBUG_ERROR, "PciHostBridge: Resource conflict happens!\n"));
+
+ RootBridgeIndex = 0;
+ Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;
+ while (Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {
+ DEBUG ((DEBUG_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));
+ for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {
+ ASSERT (Descriptor->ResType <
+ ARRAY_SIZE (mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr)
+ );
+ DEBUG ((DEBUG_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n",
+ mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[Descriptor->ResType],
+ Descriptor->AddrLen, Descriptor->AddrRangeMax
+ ));
+ if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) {
+ DEBUG ((DEBUG_ERROR, " Granularity/SpecificFlag = %ld / %02x%s\n",
+ Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag,
+ ((Descriptor->SpecificFlag &
+ EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE
+ ) != 0) ? L" (Prefetchable)" : L""
+ ));
+ }
+ }
+ //
+ // Skip the END descriptor for root bridge
+ //
+ ASSERT (Descriptor->Desc == ACPI_END_TAG_DESCRIPTOR);
+ Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)(
+ (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1
+ );
+ }
+}
+
--
2.29.2


[PATCH v6 02/11] ArmVirtPkg: Refactor with PciHostBridgeUtilityLib

Jiahui Cen
 

Eliminate currently duplicated code in ArmVirtPkg with the common utility
class PciHostBridgeUtilityLib.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
ArmVirtPkg/ArmVirtKvmTool.dsc | 1 +
ArmVirtPkg/ArmVirtQemu.dsc | 1 +
ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 +
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf | 2 +
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 44 ++------------------
5 files changed, 8 insertions(+), 41 deletions(-)

diff --git a/ArmVirtPkg/ArmVirtKvmTool.dsc b/ArmVirtPkg/ArmVirtKvmTool.dsc
index bf008be50fcb..e027b17bec1b 100644
--- a/ArmVirtPkg/ArmVirtKvmTool.dsc
+++ b/ArmVirtPkg/ArmVirtKvmTool.dsc
@@ -58,6 +58,7 @@ [LibraryClasses.common]
PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf
PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf

TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc
index ef5d6dbeaddc..a11ffd9ba553 100644
--- a/ArmVirtPkg/ArmVirtQemu.dsc
+++ b/ArmVirtPkg/ArmVirtQemu.dsc
@@ -78,6 +78,7 @@ [LibraryClasses.common]
PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf
PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf

!if $(TPM2_ENABLE) == TRUE
Tpm2CommandLib|SecurityPkg/Library/Tpm2CommandLib/Tpm2CommandLib.inf
diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKernel.dsc
index f8f5f7f4b94b..c27752b4d5e5 100644
--- a/ArmVirtPkg/ArmVirtQemuKernel.dsc
+++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc
@@ -76,6 +76,7 @@ [LibraryClasses.common]
PciPcdProducerLib|ArmVirtPkg/Library/FdtPciPcdProducerLib/FdtPciPcdProducerLib.inf
PciSegmentLib|MdePkg/Library/BasePciSegmentLibPci/BasePciSegmentLibPci.inf
PciHostBridgeLib|ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
+ PciHostBridgeUtilityLib|OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf

[LibraryClasses.common.DXE_DRIVER]
diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
index 277ccfd24546..01d39626d14c 100644
--- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
+++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
@@ -31,12 +31,14 @@ [Packages]
ArmVirtPkg/ArmVirtPkg.dec
MdeModulePkg/MdeModulePkg.dec
MdePkg/MdePkg.dec
+ OvmfPkg/OvmfPkg.dec

[LibraryClasses]
DebugLib
DevicePathLib
DxeServicesTableLib
MemoryAllocationLib
+ PciHostBridgeUtilityLib
PciPcdProducerLib

[FixedPcd]
diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
index 496b192d2291..d554479bf0de 100644
--- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
+++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
@@ -7,12 +7,13 @@

**/
#include <PiDxe.h>
-#include <Library/PciHostBridgeLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/DxeServicesTableLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
+#include <Library/PciHostBridgeLib.h>
+#include <Library/PciHostBridgeUtilityLib.h>
#include <Library/UefiBootServicesTableLib.h>

#include <Protocol/FdtClient.h>
@@ -50,11 +51,6 @@ STATIC EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath = {
}
};

-GLOBAL_REMOVE_IF_UNREFERENCED
-CHAR16 *mPciHostBridgeLibAcpiAddressSpaceTypeStr[] = {
- L"Mem", L"I/O", L"Bus"
-};
-
//
// We expect the "ranges" property of "pci-host-ecam-generic" to consist of
// records like this.
@@ -435,39 +431,5 @@ PciHostBridgeResourceConflict (
VOID *Configuration
)
{
- EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Descriptor;
- UINTN RootBridgeIndex;
- DEBUG ((EFI_D_ERROR, "PciHostBridge: Resource conflict happens!\n"));
-
- RootBridgeIndex = 0;
- Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *) Configuration;
- while (Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR) {
- DEBUG ((EFI_D_ERROR, "RootBridge[%d]:\n", RootBridgeIndex++));
- for (; Descriptor->Desc == ACPI_ADDRESS_SPACE_DESCRIPTOR; Descriptor++) {
- ASSERT (Descriptor->ResType <
- (sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr) /
- sizeof (mPciHostBridgeLibAcpiAddressSpaceTypeStr[0])
- )
- );
- DEBUG ((EFI_D_ERROR, " %s: Length/Alignment = 0x%lx / 0x%lx\n",
- mPciHostBridgeLibAcpiAddressSpaceTypeStr[Descriptor->ResType],
- Descriptor->AddrLen, Descriptor->AddrRangeMax
- ));
- if (Descriptor->ResType == ACPI_ADDRESS_SPACE_TYPE_MEM) {
- DEBUG ((EFI_D_ERROR, " Granularity/SpecificFlag = %ld / %02x%s\n",
- Descriptor->AddrSpaceGranularity, Descriptor->SpecificFlag,
- ((Descriptor->SpecificFlag &
- EFI_ACPI_MEMORY_RESOURCE_SPECIFIC_FLAG_CACHEABLE_PREFETCHABLE
- ) != 0) ? L" (Prefetchable)" : L""
- ));
- }
- }
- //
- // Skip the END descriptor for root bridge
- //
- ASSERT (Descriptor->Desc == ACPI_END_TAG_DESCRIPTOR);
- Descriptor = (EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *)(
- (EFI_ACPI_END_TAG_DESCRIPTOR *)Descriptor + 1
- );
- }
+ PciHostBridgeUtilityResourceConflict (Configuration);
}
--
2.29.2


[PATCH v6 06/11] ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge

Jiahui Cen
 

Rebase ArmVirtPkg/FdtPciHostBridgeLib to the new
PciHostBridgeUtilityInitRootBridge()/PciHostBridgeUtilityUninitRootBridge()
utility functions.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf | 1 +
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 124 ++++++++++----------
2 files changed, 61 insertions(+), 64 deletions(-)

diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
index 01d39626d14c..b813a0851d2a 100644
--- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
+++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf
@@ -34,6 +34,7 @@ [Packages]
OvmfPkg/OvmfPkg.dec

[LibraryClasses]
+ BaseMemoryLib
DebugLib
DevicePathLib
DxeServicesTableLib
diff --git a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
index d554479bf0de..3ec7992b6331 100644
--- a/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
+++ b/ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c
@@ -7,6 +7,7 @@

**/
#include <PiDxe.h>
+#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/DxeServicesTableLib.h>
@@ -20,37 +21,6 @@
#include <Protocol/PciRootBridgeIo.h>
#include <Protocol/PciHostBridgeResourceAllocation.h>

-#pragma pack(1)
-typedef struct {
- ACPI_HID_DEVICE_PATH AcpiDevicePath;
- EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
-} EFI_PCI_ROOT_BRIDGE_DEVICE_PATH;
-#pragma pack ()
-
-STATIC EFI_PCI_ROOT_BRIDGE_DEVICE_PATH mEfiPciRootBridgeDevicePath = {
- {
- {
- ACPI_DEVICE_PATH,
- ACPI_DP,
- {
- (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),
- (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)
- }
- },
- EISA_PNP_ID(0x0A03),
- 0
- },
-
- {
- END_DEVICE_PATH_TYPE,
- END_ENTIRE_DEVICE_PATH_SUBTYPE,
- {
- END_DEVICE_PATH_LENGTH,
- 0
- }
- }
-};
-
//
// We expect the "ranges" property of "pci-host-ecam-generic" to consist of
// records like this.
@@ -319,11 +289,18 @@ PciHostBridgeGetRootBridges (
UINTN *Count
)
{
- UINT64 IoBase, IoSize;
- UINT64 Mmio32Base, Mmio32Size;
- UINT64 Mmio64Base, Mmio64Size;
- UINT32 BusMin, BusMax;
- EFI_STATUS Status;
+ UINT64 IoBase, IoSize;
+ UINT64 Mmio32Base, Mmio32Size;
+ UINT64 Mmio64Base, Mmio64Size;
+ UINT32 BusMin, BusMax;
+ EFI_STATUS Status;
+ UINT64 Attributes;
+ UINT64 AllocationAttributes;
+ PCI_ROOT_BRIDGE_APERTURE Io;
+ PCI_ROOT_BRIDGE_APERTURE Mem;
+ PCI_ROOT_BRIDGE_APERTURE MemAbove4G;
+ PCI_ROOT_BRIDGE_APERTURE PMem;
+ PCI_ROOT_BRIDGE_APERTURE PMemAbove4G;

if (PcdGet64 (PcdPciExpressBaseAddress) == 0) {
DEBUG ((EFI_D_INFO, "%a: PCI host bridge not present\n", __FUNCTION__));
@@ -341,33 +318,29 @@ PciHostBridgeGetRootBridges (
return NULL;
}

- *Count = 1;
+ ZeroMem (&Io, sizeof (Io));
+ ZeroMem (&Mem, sizeof (Mem));
+ ZeroMem (&MemAbove4G, sizeof (MemAbove4G));
+ ZeroMem (&PMem, sizeof (PMem));
+ ZeroMem (&PMemAbove4G, sizeof (PMemAbove4G));

- mRootBridge.Segment = 0;
- mRootBridge.Supports = EFI_PCI_ATTRIBUTE_ISA_IO_16 |
- EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO |
- EFI_PCI_ATTRIBUTE_VGA_IO_16 |
- EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16;
- mRootBridge.Attributes = mRootBridge.Supports;
+ Attributes = EFI_PCI_ATTRIBUTE_ISA_IO_16 |
+ EFI_PCI_ATTRIBUTE_ISA_MOTHERBOARD_IO |
+ EFI_PCI_ATTRIBUTE_VGA_IO_16 |
+ EFI_PCI_ATTRIBUTE_VGA_PALETTE_IO_16;

- mRootBridge.DmaAbove4G = TRUE;
- mRootBridge.NoExtendedConfigSpace = FALSE;
- mRootBridge.ResourceAssigned = FALSE;
+ AllocationAttributes = EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM;

- mRootBridge.AllocationAttributes = EFI_PCI_HOST_BRIDGE_COMBINE_MEM_PMEM;
-
- mRootBridge.Bus.Base = BusMin;
- mRootBridge.Bus.Limit = BusMax;
- mRootBridge.Io.Base = IoBase;
- mRootBridge.Io.Limit = IoBase + IoSize - 1;
- mRootBridge.Mem.Base = Mmio32Base;
- mRootBridge.Mem.Limit = Mmio32Base + Mmio32Size - 1;
+ Io.Base = IoBase;
+ Io.Limit = IoBase + IoSize - 1;
+ Mem.Base = Mmio32Base;
+ Mem.Limit = Mmio32Base + Mmio32Size - 1;

if (sizeof (UINTN) == sizeof (UINT64)) {
- mRootBridge.MemAbove4G.Base = Mmio64Base;
- mRootBridge.MemAbove4G.Limit = Mmio64Base + Mmio64Size - 1;
+ MemAbove4G.Base = Mmio64Base;
+ MemAbove4G.Limit = Mmio64Base + Mmio64Size - 1;
if (Mmio64Size > 0) {
- mRootBridge.AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE;
+ AllocationAttributes |= EFI_PCI_HOST_BRIDGE_MEM64_DECODE;
}
} else {
//
@@ -376,19 +349,41 @@ PciHostBridgeGetRootBridges (
// BARs unless they are allocated below 4 GB. So ignore the range above
// 4 GB in this case.
//
- mRootBridge.MemAbove4G.Base = MAX_UINT64;
- mRootBridge.MemAbove4G.Limit = 0;
+ MemAbove4G.Base = MAX_UINT64;
+ MemAbove4G.Limit = 0;
}

//
// No separate ranges for prefetchable and non-prefetchable BARs
//
- mRootBridge.PMem.Base = MAX_UINT64;
- mRootBridge.PMem.Limit = 0;
- mRootBridge.PMemAbove4G.Base = MAX_UINT64;
- mRootBridge.PMemAbove4G.Limit = 0;
+ PMem.Base = MAX_UINT64;
+ PMem.Limit = 0;
+ PMemAbove4G.Base = MAX_UINT64;
+ PMemAbove4G.Limit = 0;

- mRootBridge.DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)&mEfiPciRootBridgeDevicePath;
+ Status = PciHostBridgeUtilityInitRootBridge (
+ Attributes,
+ Attributes,
+ AllocationAttributes,
+ TRUE,
+ FALSE,
+ BusMin,
+ BusMax,
+ &Io,
+ &Mem,
+ &MemAbove4G,
+ &PMem,
+ &PMemAbove4G,
+ &mRootBridge
+ );
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: failed to initialize PCI host bridge: %r\n",
+ __FUNCTION__, Status));
+ *Count = 0;
+ return NULL;
+ }
+
+ *Count = 1;

return &mRootBridge;
}
@@ -408,6 +403,7 @@ PciHostBridgeFreeRootBridges (
)
{
ASSERT (Count == 1);
+ PciHostBridgeUtilityUninitRootBridge (Bridges);
}

/**
--
2.29.2


[PATCH v6 05/11] OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge()

Jiahui Cen
 

Extend parameter list of PciHostBridgeUtilityInitRootBridge() with
DmaAbove4G and NoExtendedConfigSpace to prepare for sharing with
ArmVirtPkg.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien@xen.org>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 +
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 4 --
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 56 +++++++++--------
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 5 ++
OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 1 +
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 63 +++++++++++---------
6 files changed, 73 insertions(+), 57 deletions(-)

diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
index 7944f94b7743..72458262cb42 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
@@ -50,4 +50,5 @@ [Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Size
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
index e3d0a3740952..4d6764b702f4 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
@@ -39,7 +39,3 @@ [LibraryClasses]
DebugLib
DevicePathLib
MemoryAllocationLib
- PcdLib
-
-[Pcd]
- gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
index 8a1ddc2f5e02..a44ad5034520 100644
--- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -20,43 +20,49 @@
/**
Utility function to initialize a PCI_ROOT_BRIDGE structure.

- @param[in] Supports Supported attributes.
+ @param[in] Supports Supported attributes.

- @param[in] Attributes Initial attributes.
+ @param[in] Attributes Initial attributes.

- @param[in] AllocAttributes Allocation attributes.
+ @param[in] AllocAttributes Allocation attributes.

- @param[in] RootBusNumber The bus number to store in RootBus.
+ @param[in] DmaAbove4G DMA above 4GB memory.

- @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
- assigned to any subordinate bus found behind any
- PCI bridge hanging off this root bus.
+ @param[in] NoExtendedConfigSpace No Extended Config Space.

- The caller is repsonsible for ensuring that
- RootBusNumber <= MaxSubBusNumber. If
- RootBusNumber equals MaxSubBusNumber, then the
- root bus has no room for subordinate buses.
+ @param[in] RootBusNumber The bus number to store in RootBus.

- @param[in] Io IO aperture.
+ @param[in] MaxSubBusNumber The inclusive maximum bus number that can
+ be assigned to any subordinate bus found
+ behind any PCI bridge hanging off this
+ root bus.

- @param[in] Mem MMIO aperture.
+ The caller is repsonsible for ensuring
+ that RootBusNumber <= MaxSubBusNumber. If
+ RootBusNumber equals MaxSubBusNumber, then
+ the root bus has no room for subordinate
+ buses.

- @param[in] MemAbove4G MMIO aperture above 4G.
+ @param[in] Io IO aperture.

- @param[in] PMem Prefetchable MMIO aperture.
+ @param[in] Mem MMIO aperture.

- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+ @param[in] MemAbove4G MMIO aperture above 4G.

- @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
- caller) that should be filled in by this
- function.
+ @param[in] PMem Prefetchable MMIO aperture.

- @retval EFI_SUCCESS Initialization successful. A device path
- consisting of an ACPI device path node, with
- UID = RootBusNumber, has been allocated and
- linked into RootBus.
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.

- @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+ @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated
+ by the caller) that should be filled in by
+ this function.
+
+ @retval EFI_SUCCESS Initialization successful. A device path
+ consisting of an ACPI device path node,
+ with UID = RootBusNumber, has been
+ allocated and linked into RootBus.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
**/
EFI_STATUS
EFIAPI
@@ -64,6 +70,8 @@ PciHostBridgeUtilityInitRootBridge (
IN UINT64 Supports,
IN UINT64 Attributes,
IN UINT64 AllocAttributes,
+ IN BOOLEAN DmaAbove4G,
+ IN BOOLEAN NoExtendedConfigSpace,
IN UINT8 RootBusNumber,
IN UINT8 MaxSubBusNumber,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 07fa98110e98..8758d7c12bf0 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -10,6 +10,7 @@
#include <PiDxe.h>

#include <IndustryStandard/Pci.h>
+#include <IndustryStandard/Q35MchIch9.h>

#include <Protocol/PciHostBridgeResourceAllocation.h>
#include <Protocol/PciRootBridgeIo.h>
@@ -151,6 +152,8 @@ PciHostBridgeGetRootBridges (
Attributes,
Attributes,
AllocationAttributes,
+ FALSE,
+ PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
(UINT8) LastRootBridgeNumber,
(UINT8) (RootBridgeNumber - 1),
&Io,
@@ -176,6 +179,8 @@ PciHostBridgeGetRootBridges (
Attributes,
Attributes,
AllocationAttributes,
+ FALSE,
+ PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
(UINT8) LastRootBridgeNumber,
PCI_MAX_BUS,
&Io,
diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
index 5dfeba0e6e23..9ef39f01821b 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
@@ -456,6 +456,7 @@ ScanForRootBridges (
ASSERT (RootBridges != NULL);
PciHostBridgeUtilityInitRootBridge (
Attributes, Attributes, 0,
+ FALSE, PcdGet16 (PcdOvmfHostBridgePciDevId) != INTEL_Q35_MCH_DEVICE_ID,
(UINT8) PrimaryBus, (UINT8) SubBus,
&Io, &Mem, &MemAbove4G, &mNonExistAperture, &mNonExistAperture,
&RootBridges[*NumberOfRootBridges]
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
index 92b42566e5f8..bed2d87ea89c 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -11,12 +11,10 @@
**/

#include <IndustryStandard/Acpi10.h>
-#include <IndustryStandard/Q35MchIch9.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
-#include <Library/PcdLib.h>
#include <Library/PciHostBridgeUtilityLib.h>


@@ -64,43 +62,49 @@ OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
/**
Utility function to initialize a PCI_ROOT_BRIDGE structure.

- @param[in] Supports Supported attributes.
+ @param[in] Supports Supported attributes.

- @param[in] Attributes Initial attributes.
+ @param[in] Attributes Initial attributes.

- @param[in] AllocAttributes Allocation attributes.
+ @param[in] AllocAttributes Allocation attributes.

- @param[in] RootBusNumber The bus number to store in RootBus.
+ @param[in] DmaAbove4G DMA above 4GB memory.

- @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
- assigned to any subordinate bus found behind any
- PCI bridge hanging off this root bus.
+ @param[in] NoExtendedConfigSpace No Extended Config Space.

- The caller is repsonsible for ensuring that
- RootBusNumber <= MaxSubBusNumber. If
- RootBusNumber equals MaxSubBusNumber, then the
- root bus has no room for subordinate buses.
+ @param[in] RootBusNumber The bus number to store in RootBus.

- @param[in] Io IO aperture.
+ @param[in] MaxSubBusNumber The inclusive maximum bus number that can
+ be assigned to any subordinate bus found
+ behind any PCI bridge hanging off this
+ root bus.

- @param[in] Mem MMIO aperture.
+ The caller is repsonsible for ensuring
+ that RootBusNumber <= MaxSubBusNumber. If
+ RootBusNumber equals MaxSubBusNumber, then
+ the root bus has no room for subordinate
+ buses.

- @param[in] MemAbove4G MMIO aperture above 4G.
+ @param[in] Io IO aperture.

- @param[in] PMem Prefetchable MMIO aperture.
+ @param[in] Mem MMIO aperture.

- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+ @param[in] MemAbove4G MMIO aperture above 4G.

- @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
- caller) that should be filled in by this
- function.
+ @param[in] PMem Prefetchable MMIO aperture.

- @retval EFI_SUCCESS Initialization successful. A device path
- consisting of an ACPI device path node, with
- UID = RootBusNumber, has been allocated and
- linked into RootBus.
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.

- @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+ @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated
+ by the caller) that should be filled in by
+ this function.
+
+ @retval EFI_SUCCESS Initialization successful. A device path
+ consisting of an ACPI device path node,
+ with UID = RootBusNumber, has been
+ allocated and linked into RootBus.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
**/
EFI_STATUS
EFIAPI
@@ -108,6 +112,8 @@ PciHostBridgeUtilityInitRootBridge (
IN UINT64 Supports,
IN UINT64 Attributes,
IN UINT64 AllocAttributes,
+ IN BOOLEAN DmaAbove4G,
+ IN BOOLEAN NoExtendedConfigSpace,
IN UINT8 RootBusNumber,
IN UINT8 MaxSubBusNumber,
IN PCI_ROOT_BRIDGE_APERTURE *Io,
@@ -130,7 +136,7 @@ PciHostBridgeUtilityInitRootBridge (
RootBus->Supports = Supports;
RootBus->Attributes = Attributes;

- RootBus->DmaAbove4G = FALSE;
+ RootBus->DmaAbove4G = DmaAbove4G;

RootBus->AllocationAttributes = AllocAttributes;
RootBus->Bus.Base = RootBusNumber;
@@ -141,8 +147,7 @@ PciHostBridgeUtilityInitRootBridge (
CopyMem (&RootBus->PMem, PMem, sizeof (*PMem));
CopyMem (&RootBus->PMemAbove4G, PMemAbove4G, sizeof (*PMemAbove4G));

- RootBus->NoExtendedConfigSpace = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=
- INTEL_Q35_MCH_DEVICE_ID);
+ RootBus->NoExtendedConfigSpace = NoExtendedConfigSpace;

DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,
&mRootBridgeDevicePathTemplate);
--
2.29.2


[PATCH v6 03/11] OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency

Jiahui Cen
 

OvmfPkg/PciHostBridgeLib instance fails to list its PcdLib dependency,
both between the #include directives, and in the INF file. So let's list
the dependency.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien@xen.org>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
---
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 1 +
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 1 +
OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 1 +
3 files changed, 3 insertions(+)

diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
index 4c56f3c90b3b..cec3f1631a72 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
@@ -39,6 +39,7 @@ [LibraryClasses]
DebugLib
DevicePathLib
MemoryAllocationLib
+ PcdLib
PciHostBridgeUtilityLib
PciLib
QemuFwCfgLib
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index 4a176347fd49..bf32455b9f0d 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -19,6 +19,7 @@
#include <Library/DebugLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
#include <Library/PciHostBridgeUtilityLib.h>
#include <Library/PciLib.h>
diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
index e161f14375ca..95ed0a280b9b 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
@@ -17,6 +17,7 @@
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
#include <Library/PciLib.h>
#include "PciHostBridge.h"
--
2.29.2


[PATCH v6 00/11] Add extra pci roots support for Arm

Jiahui Cen
 

v5->v6:
* Annotate library functions with EFIAPI, IN/OUT, @param[in]/[out].
* Split BusMin/BusMax addtion in PciHostBridgeUtilityGetRootBridges() into
a separate patch [09/11].
* Add more detailed commit message for patch [10/11].

v4->v5:
* Revert some risky renames.
* Explicitly list PcdLib dependency.
* Fix issues reported by PatchCheck.py.

v3->v4:
* Refactor InitRootBridges/UninitRootBridges/GetRootBridges/FreeRootBridges.
* Fix library dependencies.

v2->v3:
* Rename utility functions under the PciHostBridgeUtilityLib namespace.
* Remove some unused Library dependencies.
* Sort the Include headers.

v1->v2:
* Separated into four patches.
* Factor the same logic parts into a new library.

v4: https://edk2.groups.io/g/devel/message/70147
BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059
QEMU: https://lore.kernel.org/qemu-devel/20201119014841.7298-1-cenjiahui@huawei.com/

This patch series adds support for extra pci roots for ARM.

In order to avoid duplicated codes, we introduce a new library
PciHostBridgeUtilityLib which extracts common interfaces from
OvmfPkg/PciHostBridgeLib. It provides conflicts informing and extra pci
roots scanning. Using the utility lib, the uefi could scan for extra
root buses and recognize multiple roots for ARM.

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Rebecca Cran <rebecca@bsdio.com>
Cc: Peter Grehan <grehan@freebsd.org>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien@xen.org>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>

Jiahui Cen (11):
OvmfPkg: Introduce PciHostBridgeUtilityLib class
ArmVirtPkg: Refactor with PciHostBridgeUtilityLib
OvmfPkg/PciHostBridgeLib: List missing PcdLib dependency
OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() /
UninitRootBridge()
OvmfPkg/PciHostBridgeUtilityLib: Extend parameters of InitRootBridge()
ArmVirtPkg/FdtPciHostBridgeLib: Refactor init/uninit of root bridge
OvmfPkg/PciHostBridgeLib: Extract GetRootBridges() / FreeRootBridges()
OvmfPkg/PciHostBridgeUtilityLib: Extend parameter list of
GetRootBridges
OvmfPkg/PciHostBridgeUtilityLib: Extend GetRootBridges() with
BusMin/BusMax
ArmVirtPkg/FdtPciHostBridgeLib: Add extra pci root buses support
ArmVirtPkg/ArmVirtQemu: Add support for HotPlug

OvmfPkg/OvmfPkg.dec | 4 +
ArmVirtPkg/ArmVirtKvmTool.dsc | 1 +
ArmVirtPkg/ArmVirtQemu.dsc | 2 +
ArmVirtPkg/ArmVirtQemuKernel.dsc | 2 +
OvmfPkg/AmdSev/AmdSevX64.dsc | 1 +
OvmfPkg/Bhyve/BhyveX64.dsc | 1 +
OvmfPkg/OvmfPkgIa32.dsc | 1 +
OvmfPkg/OvmfPkgIa32X64.dsc | 1 +
OvmfPkg/OvmfPkgX64.dsc | 1 +
OvmfPkg/OvmfXen.dsc | 1 +
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.inf | 3 +
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 4 +-
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 43 +++
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 185 +++++++++++
OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h | 56 ----
ArmVirtPkg/Library/FdtPciHostBridgeLib/FdtPciHostBridgeLib.c | 164 ++++------
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 324 +-------------------
OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 5 +-
OvmfPkg/Library/{PciHostBridgeLib/PciHostBridgeLib.c => PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c} | 281 +++++++++--------
ArmVirtPkg/ArmVirtQemuFvMain.fdf.inc | 1 +
20 files changed, 467 insertions(+), 614 deletions(-)
create mode 100644 OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
create mode 100644 OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
copy OvmfPkg/Library/{PciHostBridgeLib/PciHostBridgeLib.c => PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c} (50%)

--
2.29.2


[PATCH v6 04/11] OvmfPkg/PciHostBridgeLib: Extract InitRootBridge() / UninitRootBridge()

Jiahui Cen
 

Extract InitRootBridge() / UninitRootBridge() to PciHostBridgeUtilityLib
as common utility functions. No change of functionality.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3059

Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Ard Biesheuvel <ard.biesheuvel@arm.com>
Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Julien Grall <julien@xen.org>
Signed-off-by: Jiahui Cen <cenjiahui@huawei.com>
Signed-off-by: Yubo Miao <miaoyubo@huawei.com>
---
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf | 2 -
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf | 8 +
OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h | 77 ++++++++++
OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h | 56 -------
OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c | 158 +-------------------
OvmfPkg/Library/PciHostBridgeLib/XenSupport.c | 3 +-
OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c | 158 ++++++++++++++++++++
7 files changed, 249 insertions(+), 213 deletions(-)

diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
index cec3f1631a72..7944f94b7743 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.inf
@@ -37,7 +37,6 @@ [Packages]
[LibraryClasses]
BaseMemoryLib
DebugLib
- DevicePathLib
MemoryAllocationLib
PcdLib
PciHostBridgeUtilityLib
@@ -51,5 +50,4 @@ [Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio32Size
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Base
gUefiOvmfPkgTokenSpaceGuid.PcdPciMmio64Size
- gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
gEfiMdeModulePkgTokenSpaceGuid.PcdPciDisableBusEnumeration
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
index 1ba8ec3e03c7..e3d0a3740952 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.inf
@@ -30,8 +30,16 @@ [Sources]
PciHostBridgeUtilityLib.c

[Packages]
+ MdeModulePkg/MdeModulePkg.dec
MdePkg/MdePkg.dec
OvmfPkg/OvmfPkg.dec

[LibraryClasses]
+ BaseMemoryLib
DebugLib
+ DevicePathLib
+ MemoryAllocationLib
+ PcdLib
+
+[Pcd]
+ gUefiOvmfPkgTokenSpaceGuid.PcdOvmfHostBridgePciDevId
diff --git a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
index 5ea25ed2f4f4..8a1ddc2f5e02 100644
--- a/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
+++ b/OvmfPkg/Include/Library/PciHostBridgeUtilityLib.h
@@ -14,6 +14,83 @@
#define __PCI_HOST_BRIDGE_UTILITY_LIB_H__


+#include <Library/PciHostBridgeLib.h>
+
+
+/**
+ Utility function to initialize a PCI_ROOT_BRIDGE structure.
+
+ @param[in] Supports Supported attributes.
+
+ @param[in] Attributes Initial attributes.
+
+ @param[in] AllocAttributes Allocation attributes.
+
+ @param[in] RootBusNumber The bus number to store in RootBus.
+
+ @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
+ assigned to any subordinate bus found behind any
+ PCI bridge hanging off this root bus.
+
+ The caller is repsonsible for ensuring that
+ RootBusNumber <= MaxSubBusNumber. If
+ RootBusNumber equals MaxSubBusNumber, then the
+ root bus has no room for subordinate buses.
+
+ @param[in] Io IO aperture.
+
+ @param[in] Mem MMIO aperture.
+
+ @param[in] MemAbove4G MMIO aperture above 4G.
+
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
+ caller) that should be filled in by this
+ function.
+
+ @retval EFI_SUCCESS Initialization successful. A device path
+ consisting of an ACPI device path node, with
+ UID = RootBusNumber, has been allocated and
+ linked into RootBus.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+**/
+EFI_STATUS
+EFIAPI
+PciHostBridgeUtilityInitRootBridge (
+ IN UINT64 Supports,
+ IN UINT64 Attributes,
+ IN UINT64 AllocAttributes,
+ IN UINT8 RootBusNumber,
+ IN UINT8 MaxSubBusNumber,
+ IN PCI_ROOT_BRIDGE_APERTURE *Io,
+ IN PCI_ROOT_BRIDGE_APERTURE *Mem,
+ IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
+ IN PCI_ROOT_BRIDGE_APERTURE *PMem,
+ IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G,
+ OUT PCI_ROOT_BRIDGE *RootBus
+ );
+
+
+/**
+ Utility function to uninitialize a PCI_ROOT_BRIDGE structure set up with
+ PciHostBridgeUtilityInitRootBridge().
+
+ @param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the caller and
+ initialized with PciHostBridgeUtilityInitRootBridge(),
+ that should be uninitialized. This function doesn't free
+ RootBus.
+**/
+VOID
+EFIAPI
+PciHostBridgeUtilityUninitRootBridge (
+ IN PCI_ROOT_BRIDGE *RootBus
+ );
+
+
/**
Utility function to inform the platform that the resource conflict happens.

diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h
index 134d7411214d..a2e4d8696281 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridge.h
@@ -11,59 +11,3 @@ PCI_ROOT_BRIDGE *
ScanForRootBridges (
UINTN *NumberOfRootBridges
);
-
-/**
- Initialize a PCI_ROOT_BRIDGE structure.
-
- @param[in] Supports Supported attributes.
-
- @param[in] Attributes Initial attributes.
-
- @param[in] AllocAttributes Allocation attributes.
-
- @param[in] RootBusNumber The bus number to store in RootBus.
-
- @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
- assigned to any subordinate bus found behind any
- PCI bridge hanging off this root bus.
-
- The caller is repsonsible for ensuring that
- RootBusNumber <= MaxSubBusNumber. If
- RootBusNumber equals MaxSubBusNumber, then the
- root bus has no room for subordinate buses.
-
- @param[in] Io IO aperture.
-
- @param[in] Mem MMIO aperture.
-
- @param[in] MemAbove4G MMIO aperture above 4G.
-
- @param[in] PMem Prefetchable MMIO aperture.
-
- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
-
- @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
- caller) that should be filled in by this
- function.
-
- @retval EFI_SUCCESS Initialization successful. A device path
- consisting of an ACPI device path node, with
- UID = RootBusNumber, has been allocated and
- linked into RootBus.
-
- @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
-**/
-EFI_STATUS
-InitRootBridge (
- IN UINT64 Supports,
- IN UINT64 Attributes,
- IN UINT64 AllocAttributes,
- IN UINT8 RootBusNumber,
- IN UINT8 MaxSubBusNumber,
- IN PCI_ROOT_BRIDGE_APERTURE *Io,
- IN PCI_ROOT_BRIDGE_APERTURE *Mem,
- IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
- IN PCI_ROOT_BRIDGE_APERTURE *PMem,
- IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G,
- OUT PCI_ROOT_BRIDGE *RootBus
- );
diff --git a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
index bf32455b9f0d..07fa98110e98 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/PciHostBridgeLib.c
@@ -10,14 +10,12 @@
#include <PiDxe.h>

#include <IndustryStandard/Pci.h>
-#include <IndustryStandard/Q35MchIch9.h>

#include <Protocol/PciHostBridgeResourceAllocation.h>
#include <Protocol/PciRootBridgeIo.h>

#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
-#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
@@ -27,156 +25,8 @@
#include "PciHostBridge.h"


-#pragma pack(1)
-typedef struct {
- ACPI_HID_DEVICE_PATH AcpiDevicePath;
- EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
-} OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH;
-#pragma pack ()
-
-
-STATIC
-CONST
-OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
- {
- {
- ACPI_DEVICE_PATH,
- ACPI_DP,
- {
- (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),
- (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)
- }
- },
- EISA_PNP_ID(0x0A03), // HID
- 0 // UID
- },
-
- {
- END_DEVICE_PATH_TYPE,
- END_ENTIRE_DEVICE_PATH_SUBTYPE,
- {
- END_DEVICE_PATH_LENGTH,
- 0
- }
- }
-};
-
STATIC PCI_ROOT_BRIDGE_APERTURE mNonExistAperture = { MAX_UINT64, 0 };

-/**
- Initialize a PCI_ROOT_BRIDGE structure.
-
- @param[in] Supports Supported attributes.
-
- @param[in] Attributes Initial attributes.
-
- @param[in] AllocAttributes Allocation attributes.
-
- @param[in] RootBusNumber The bus number to store in RootBus.
-
- @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
- assigned to any subordinate bus found behind any
- PCI bridge hanging off this root bus.
-
- The caller is repsonsible for ensuring that
- RootBusNumber <= MaxSubBusNumber. If
- RootBusNumber equals MaxSubBusNumber, then the
- root bus has no room for subordinate buses.
-
- @param[in] Io IO aperture.
-
- @param[in] Mem MMIO aperture.
-
- @param[in] MemAbove4G MMIO aperture above 4G.
-
- @param[in] PMem Prefetchable MMIO aperture.
-
- @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
-
- @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
- caller) that should be filled in by this
- function.
-
- @retval EFI_SUCCESS Initialization successful. A device path
- consisting of an ACPI device path node, with
- UID = RootBusNumber, has been allocated and
- linked into RootBus.
-
- @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
-**/
-EFI_STATUS
-InitRootBridge (
- IN UINT64 Supports,
- IN UINT64 Attributes,
- IN UINT64 AllocAttributes,
- IN UINT8 RootBusNumber,
- IN UINT8 MaxSubBusNumber,
- IN PCI_ROOT_BRIDGE_APERTURE *Io,
- IN PCI_ROOT_BRIDGE_APERTURE *Mem,
- IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
- IN PCI_ROOT_BRIDGE_APERTURE *PMem,
- IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G,
- OUT PCI_ROOT_BRIDGE *RootBus
- )
-{
- OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath;
-
- //
- // Be safe if other fields are added to PCI_ROOT_BRIDGE later.
- //
- ZeroMem (RootBus, sizeof *RootBus);
-
- RootBus->Segment = 0;
-
- RootBus->Supports = Supports;
- RootBus->Attributes = Attributes;
-
- RootBus->DmaAbove4G = FALSE;
-
- RootBus->AllocationAttributes = AllocAttributes;
- RootBus->Bus.Base = RootBusNumber;
- RootBus->Bus.Limit = MaxSubBusNumber;
- CopyMem (&RootBus->Io, Io, sizeof (*Io));
- CopyMem (&RootBus->Mem, Mem, sizeof (*Mem));
- CopyMem (&RootBus->MemAbove4G, MemAbove4G, sizeof (*MemAbove4G));
- CopyMem (&RootBus->PMem, PMem, sizeof (*PMem));
- CopyMem (&RootBus->PMemAbove4G, PMemAbove4G, sizeof (*PMemAbove4G));
-
- RootBus->NoExtendedConfigSpace = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=
- INTEL_Q35_MCH_DEVICE_ID);
-
- DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,
- &mRootBridgeDevicePathTemplate);
- if (DevicePath == NULL) {
- DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
- return EFI_OUT_OF_RESOURCES;
- }
- DevicePath->AcpiDevicePath.UID = RootBusNumber;
- RootBus->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;
-
- DEBUG ((DEBUG_INFO,
- "%a: populated root bus %d, with room for %d subordinate bus(es)\n",
- __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber));
- return EFI_SUCCESS;
-}
-
-
-/**
- Uninitialize a PCI_ROOT_BRIDGE structure set up with InitRootBridge().
-
- param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the caller and
- initialized with InitRootBridge(), that should be
- uninitialized. This function doesn't free RootBus.
-**/
-STATIC
-VOID
-UninitRootBridge (
- IN PCI_ROOT_BRIDGE *RootBus
- )
-{
- FreePool (RootBus->DevicePath);
-}
-

/**
Return all the root bridge instances in an array.
@@ -297,7 +147,7 @@ PciHostBridgeGetRootBridges (
// because now we know how big a bus number range *that* one has, for any
// subordinate buses that might exist behind PCI bridges hanging off it.
//
- Status = InitRootBridge (
+ Status = PciHostBridgeUtilityInitRootBridge (
Attributes,
Attributes,
AllocationAttributes,
@@ -322,7 +172,7 @@ PciHostBridgeGetRootBridges (
// Install the last root bus (which might be the only, ie. main, root bus, if
// we've found no extra root buses).
//
- Status = InitRootBridge (
+ Status = PciHostBridgeUtilityInitRootBridge (
Attributes,
Attributes,
AllocationAttributes,
@@ -346,7 +196,7 @@ PciHostBridgeGetRootBridges (
FreeBridges:
while (Initialized > 0) {
--Initialized;
- UninitRootBridge (&Bridges[Initialized]);
+ PciHostBridgeUtilityUninitRootBridge (&Bridges[Initialized]);
}

FreePool (Bridges);
@@ -375,7 +225,7 @@ PciHostBridgeFreeRootBridges (

do {
--Count;
- UninitRootBridge (&Bridges[Count]);
+ PciHostBridgeUtilityUninitRootBridge (&Bridges[Count]);
} while (Count > 0);

FreePool (Bridges);
diff --git a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
index 95ed0a280b9b..5dfeba0e6e23 100644
--- a/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
+++ b/OvmfPkg/Library/PciHostBridgeLib/XenSupport.c
@@ -19,6 +19,7 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/PciHostBridgeLib.h>
+#include <Library/PciHostBridgeUtilityLib.h>
#include <Library/PciLib.h>
#include "PciHostBridge.h"

@@ -453,7 +454,7 @@ ScanForRootBridges (
RootBridges
);
ASSERT (RootBridges != NULL);
- InitRootBridge (
+ PciHostBridgeUtilityInitRootBridge (
Attributes, Attributes, 0,
(UINT8) PrimaryBus, (UINT8) SubBus,
&Io, &Mem, &MemAbove4G, &mNonExistAperture, &mNonExistAperture,
diff --git a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
index ac94e62612be..92b42566e5f8 100644
--- a/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
+++ b/OvmfPkg/Library/PciHostBridgeUtilityLib/PciHostBridgeUtilityLib.c
@@ -11,16 +11,174 @@
**/

#include <IndustryStandard/Acpi10.h>
+#include <IndustryStandard/Q35MchIch9.h>
+#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
+#include <Library/DevicePathLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PcdLib.h>
#include <Library/PciHostBridgeUtilityLib.h>


+#pragma pack(1)
+typedef struct {
+ ACPI_HID_DEVICE_PATH AcpiDevicePath;
+ EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH;
+#pragma pack ()
+
+
GLOBAL_REMOVE_IF_UNREFERENCED
CHAR16 *mPciHostBridgeUtilityLibAcpiAddressSpaceTypeStr[] = {
L"Mem", L"I/O", L"Bus"
};


+STATIC
+CONST
+OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH mRootBridgeDevicePathTemplate = {
+ {
+ {
+ ACPI_DEVICE_PATH,
+ ACPI_DP,
+ {
+ (UINT8) (sizeof(ACPI_HID_DEVICE_PATH)),
+ (UINT8) ((sizeof(ACPI_HID_DEVICE_PATH)) >> 8)
+ }
+ },
+ EISA_PNP_ID(0x0A03), // HID
+ 0 // UID
+ },
+
+ {
+ END_DEVICE_PATH_TYPE,
+ END_ENTIRE_DEVICE_PATH_SUBTYPE,
+ {
+ END_DEVICE_PATH_LENGTH,
+ 0
+ }
+ }
+};
+
+
+/**
+ Utility function to initialize a PCI_ROOT_BRIDGE structure.
+
+ @param[in] Supports Supported attributes.
+
+ @param[in] Attributes Initial attributes.
+
+ @param[in] AllocAttributes Allocation attributes.
+
+ @param[in] RootBusNumber The bus number to store in RootBus.
+
+ @param[in] MaxSubBusNumber The inclusive maximum bus number that can be
+ assigned to any subordinate bus found behind any
+ PCI bridge hanging off this root bus.
+
+ The caller is repsonsible for ensuring that
+ RootBusNumber <= MaxSubBusNumber. If
+ RootBusNumber equals MaxSubBusNumber, then the
+ root bus has no room for subordinate buses.
+
+ @param[in] Io IO aperture.
+
+ @param[in] Mem MMIO aperture.
+
+ @param[in] MemAbove4G MMIO aperture above 4G.
+
+ @param[in] PMem Prefetchable MMIO aperture.
+
+ @param[in] PMemAbove4G Prefetchable MMIO aperture above 4G.
+
+ @param[out] RootBus The PCI_ROOT_BRIDGE structure (allocated by the
+ caller) that should be filled in by this
+ function.
+
+ @retval EFI_SUCCESS Initialization successful. A device path
+ consisting of an ACPI device path node, with
+ UID = RootBusNumber, has been allocated and
+ linked into RootBus.
+
+ @retval EFI_OUT_OF_RESOURCES Memory allocation failed.
+**/
+EFI_STATUS
+EFIAPI
+PciHostBridgeUtilityInitRootBridge (
+ IN UINT64 Supports,
+ IN UINT64 Attributes,
+ IN UINT64 AllocAttributes,
+ IN UINT8 RootBusNumber,
+ IN UINT8 MaxSubBusNumber,
+ IN PCI_ROOT_BRIDGE_APERTURE *Io,
+ IN PCI_ROOT_BRIDGE_APERTURE *Mem,
+ IN PCI_ROOT_BRIDGE_APERTURE *MemAbove4G,
+ IN PCI_ROOT_BRIDGE_APERTURE *PMem,
+ IN PCI_ROOT_BRIDGE_APERTURE *PMemAbove4G,
+ OUT PCI_ROOT_BRIDGE *RootBus
+ )
+{
+ OVMF_PCI_ROOT_BRIDGE_DEVICE_PATH *DevicePath;
+
+ //
+ // Be safe if other fields are added to PCI_ROOT_BRIDGE later.
+ //
+ ZeroMem (RootBus, sizeof *RootBus);
+
+ RootBus->Segment = 0;
+
+ RootBus->Supports = Supports;
+ RootBus->Attributes = Attributes;
+
+ RootBus->DmaAbove4G = FALSE;
+
+ RootBus->AllocationAttributes = AllocAttributes;
+ RootBus->Bus.Base = RootBusNumber;
+ RootBus->Bus.Limit = MaxSubBusNumber;
+ CopyMem (&RootBus->Io, Io, sizeof (*Io));
+ CopyMem (&RootBus->Mem, Mem, sizeof (*Mem));
+ CopyMem (&RootBus->MemAbove4G, MemAbove4G, sizeof (*MemAbove4G));
+ CopyMem (&RootBus->PMem, PMem, sizeof (*PMem));
+ CopyMem (&RootBus->PMemAbove4G, PMemAbove4G, sizeof (*PMemAbove4G));
+
+ RootBus->NoExtendedConfigSpace = (PcdGet16 (PcdOvmfHostBridgePciDevId) !=
+ INTEL_Q35_MCH_DEVICE_ID);
+
+ DevicePath = AllocateCopyPool (sizeof mRootBridgeDevicePathTemplate,
+ &mRootBridgeDevicePathTemplate);
+ if (DevicePath == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: %r\n", __FUNCTION__, EFI_OUT_OF_RESOURCES));
+ return EFI_OUT_OF_RESOURCES;
+ }
+ DevicePath->AcpiDevicePath.UID = RootBusNumber;
+ RootBus->DevicePath = (EFI_DEVICE_PATH_PROTOCOL *)DevicePath;
+
+ DEBUG ((DEBUG_INFO,
+ "%a: populated root bus %d, with room for %d subordinate bus(es)\n",
+ __FUNCTION__, RootBusNumber, MaxSubBusNumber - RootBusNumber));
+ return EFI_SUCCESS;
+}
+
+
+/**
+ Utility function to uninitialize a PCI_ROOT_BRIDGE structure set up with
+ PciHostBridgeUtilityInitRootBridge().
+
+ @param[in] RootBus The PCI_ROOT_BRIDGE structure, allocated by the caller and
+ initialized with PciHostBridgeUtilityInitRootBridge(),
+ that should be uninitialized. This function doesn't free
+ RootBus.
+**/
+VOID
+EFIAPI
+PciHostBridgeUtilityUninitRootBridge (
+ IN PCI_ROOT_BRIDGE *RootBus
+ )
+{
+ FreePool (RootBus->DevicePath);
+}
+
+
/**
Utility function to inform the platform that the resource conflict happens.

--
2.29.2


回复: [edk2-devel] Updated Event: TianoCore Bug Triage - APAC / NAMO #cal-invite

gaoliming
 

Hi, all

 The following issues will be reviewed in this week meeting.

 

3174

EDK2

Code

unassigned@...

UNCO

EDKII Platform level Redfish packet encode/decode library

Sun 22:49

abner.chang@...

3169

Tianocor

Code

unassigned@...

UNCO

Support Tcg2Smm under Standalone MM environment

Fri 13:20

kun.qin@...

3170

EDK2

Code

unassigned@...

UNCO

NetworkPkg/Library/DxeHttpIoLib: Http boot failure with no initializes timeout value.

Fri 01:08

gregx.yeh@...

3168

Tianocor

Code

unassigned@...

UNCO

Add non-MMRAM memory protection for Standalone MM environment

Thu 21:08

kun.qin@...

3166

EDK2

Code

unassigned@...

UNCO

CoreValidateHandle() is unsafe.

Wed 22:57

afish@...

2831

EDK2

Code

zhichao.gao@...

UNCO

UefiBootManagerLib is not specs compliant with regards to EFI_EVENT_GROUP_READY_TO_BOOT

Wed 12:37

pete@...

3164

EDK2

Code

unassigned@...

UNCO

IndustryStandard/SmBios.h has incorrectly capitalized filename

2021-01-12

leif@...

2557

Tianocor

Code

michael.d.kinney@...

UNCO

New SPI Serial bus resource descriptor

2021-01-11

john.garry@...

3157

EDK2

Code

unassigned@...

UNCO

Openssl allocatepool failed in PEI phase when Image buffer is large then 64K

2021-01-10

LarryLiu@...

3161

EDK2

Code

unassigned@...

UNCO

Build failed on os.makedirs() for .cache

2021-01-08

afish@...

3144

EDK2

Code

unassigned@...

UNCO

Initialize Real Non-volatile storage

2021-01-07

vu.dinh@...

3156

EDK2

Code

unassigned@...

UNCO

Core CI, Platform CI: issues with the "ubuntu-latest" VM image

2021-01-06

lersek@...

3135

EDK2

Code

unassigned@...

UNCO

Boot0000 would be first place after resetting BootOrder by efibootmgr

2021-01-05

walon.li@...

 

Thanks

Liming

 

发件人: bounce+27952+70511+4905953+8761045@groups.io <bounce+27952+70511+4905953+8761045@groups.io> 代表 devel@edk2.groups.io Calendar
发送时间: 2021119 8:54
收件人: devel@edk2.groups.io
主题: [edk2-devel] Updated Event: TianoCore Bug Triage - APAC / NAMO #cal-invite

 

TianoCore Bug Triage - APAC / NAMO

When:
Tuesday, 19 January 2021
6:30pm to 7:30pm
(UTC-08:00) America/Los Angeles
Repeats: Weekly on Tuesday

Where:
https://meetingsamer34.webex.com/meetingsamer34/j.php?MTID=mb96c5bd411bd010e1e6d43a6f6c65f45

Organizer: Liming Gao gaoliming@...

Description:

TianoCore Bug Triage - APAC / NAMO

Hosted by Liming Gao

 

https://meetingsamer34.webex.com/meetingsamer34/j.php?MTID=mb96c5bd411bd010e1e6d43a6f6c65f45

Wednesday, Jan 20, 2021 10:30 am | 50 minutes | (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi

Occurs every Wednesday effective 1/20/2021 from 10:30 AM to 11:20 AM, (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi

Meeting number: 126 867 1239

Password: ZhqYQunw246 (94797869 from video systems)

d8edc6c9604344b08f727b4bf054eaac_20210120T023000Z

 

Join by video system

Dial 1268671239@...

You can also dial 173.243.2.68 and enter your meeting number.

 

Join by phone

Use VoIP only


回复: [edk2-devel] 回复: [edk2-devel] [Patch 0/2] Convert Split tool to python

gaoliming
 

Bob:

 The code logic is fine. This is a big change. I suggest to update tool version from 1.0 to 2.0. With this change, Reviewed-by: Liming Gao <gaoliming@...>

 

Thanks

Liming

发件人: bounce+27952+70509+4905953+8761045@groups.io <bounce+27952+70509+4905953+8761045@groups.io> 代表 Bob Feng
发送时间: 2021119 7:57
收件人: devel@edk2.groups.io; gaoliming@...
主题: Re: [edk2-devel] 回复: [edk2-devel] [Patch 0/2] Convert Split tool to python

 

Liming,

 

I have sent the patch V3 that is to move the unit test to tests/Split folder.

 

Do you have any other concerns about this patch?

 

Thanks,

Bob

 

From: Feng, Bob C
Sent: Friday, January 15, 2021 9:50 AM
To: devel@edk2.groups.io; gaoliming@...
Cc: Feng, Bob C <bob.c.feng@...>
Subject: RE: [edk2-devel]
回复: [edk2-devel] [Patch 0/2] Convert Split tool to python

 

Hi Liming,

 

1. The test framework can be used for both incremental test and functionality test. We can do more discussion when I send out this framework for review.

2. Yes, I agree to add a sub folder under the test folder. I’ll update the patch.

 

Is there any other comments before I send the patch V2?

 

Thanks,

Bob

 

From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of gaoliming
Sent: Friday, January 15, 2021 9:13 AM
To: Feng, Bob C <bob.c.feng@...>; devel@edk2.groups.io
Subject:
回复: [edk2-devel] 回复: [edk2-devel] [Patch 0/2] Convert Split tool to python

 

Bob:

 Thanks for your planning sharing. For BaseTools test, I still have some questions.

 

1.      For test framework, is it the incremental test framework or the functionality test framework or both?

2.      For BaseTools\Source\Python\tests\test_split.py, it creates new directory tests for test case scripts, and use test_split.py for split tool. So, new tool test script will follow the same style. Besides, split tool is simple. It may not have its special test case. But, Fce/FMMT are too complex. They need the different bios images as their test cases. Then, where are those test cases placed into? I would prefer to place the test script and its test cases into the same directory. So, I would propose to create the subdirectory in tests for each tool test, such as Split for this case. Then, every tool can place its test script and test case into its own directory.

 

Thanks

Liming

发件人: tosubbounce+27952+0+0+0@groups.io <tosubbounce+27952+0+0+0@groups.io> 代表 Bob Feng
发送时间: 2021114 10:46
收件人: gaoliming <gaoliming@...>; devel@edk2.groups.io
主题: Re: [edk2-devel] 回复: [edk2-devel] [Patch 0/2] Convert Split tool to python

 

Good questions. I answer them inline.

Thanks,
Bob

On Thu, Jan 14, 2021 at 08:53 AM, gaoliming wrote:

Bob:
Have you plan to convert all C tools to Python tools? Or only some ones?

I am still investigating the feasibility of converting the C tools to Python tools. Some C tools are simple but some are complex. I hope all the C tools can be converted to Python tools so that all the tools can be moved to the BaseTools separate repo. I think we can file some BZs to track the progress of the C tools conversion. And I hope there could be more volunteers to be involved in this work.

Here are the discussions about the benefit and process of moving BaseTools out of the edk2 repo for reference.

Can you share your planning for the changes in BaseTools?

Except for this patch, my current work for Basetools are:
1. Re-write the FMMT/FCE with Python and propose to add these 2 tools to the edk2 BaseTools.
2. Prepare to publish the Basetools incremental build regression test cases and test framework.

And, I see you also add unittest for new split tool. Can you introduce the
unittest framework for python tool? If so, new added tool can follow the
same way to add unittest.

The unittest is the python build-in library for the unit test. https://docs.python.org/3/library/unittest.html 
I provide the unit test is to help you to review this patch. From the unit test case, it will be easy to
see if this tool's behavior is as expected. 

I think for the python code development, we can try our best to follow this document. https://edk2-docs.gitbook.io/edk-ii-python-development-process-specification/ 


Thanks
Liming

-----邮件原件-----
发件人: bounce+27952+70232+4905953+8761045@groups.io
<bounce+27952+70232+4905953+8761045@groups.io>
代表 Bob Feng
发送时间: 2021113 17:56
收件人: devel@edk2.groups.io
主题: [edk2-devel] [Patch 0/2] Convert Split tool to python

There are 2 reasons to convert Split tool from C to Python.

1. We are in the process of moving the Basetools Python code

to a separate repository. But there still are many C tools under

edk2/BaseTools. To make all Basetools be in the separate repo,

we can convert the C tools to Python tools.

2. The original Split tool is very slow. This python tool can reduce

90% time

Bob Feng (2):
BaseTools: Convert Split tool to python
BaseTools: Add unittest for Split tool

BaseTools/Source/C/Split/Split.c | 466 --------------------
BaseTools/BinWrappers/PosixLike/Split | 31 +-
BaseTools/BinWrappers/WindowsLike/Split.bat | 3 +
BaseTools/Source/C/GNUmakefile | 1 -
BaseTools/Source/C/Makefile | 1 -
BaseTools/Source/C/Split/GNUmakefile | 17 -
BaseTools/Source/C/Split/Makefile | 16 -
BaseTools/Source/Python/Split/Split.py | 203 +++++++++
BaseTools/Source/Python/Split/__init__.py | 10 +
BaseTools/Source/Python/tests/test_split.py | 101 +++++
10 files changed, 325 insertions(+), 524 deletions(-)
delete mode 100644 BaseTools/Source/C/Split/Split.c
create mode 100644 BaseTools/BinWrappers/WindowsLike/Split.bat
delete mode 100644 BaseTools/Source/C/Split/GNUmakefile
delete mode 100644 BaseTools/Source/C/Split/Makefile
create mode 100644 BaseTools/Source/Python/Split/Split.py
create mode 100644 BaseTools/Source/Python/Split/__init__.py
create mode 100644 BaseTools/Source/Python/tests/test_split.py

--
2.29.1.windows.1



-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70232): https://edk2.groups.io/g/devel/message/70232
Mute This Topic: https://groups.io/mt/79647273/4905953
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub
[gaoliming@...]
-=-=-=-=-=-=


Updated Event: TianoCore Bug Triage - APAC / NAMO #cal-invite

devel@edk2.groups.io Calendar <noreply@...>
 

TianoCore Bug Triage - APAC / NAMO

When:
Tuesday, 19 January 2021
6:30pm to 7:30pm
(UTC-08:00) America/Los Angeles
Repeats: Weekly on Tuesday

Where:
https://meetingsamer34.webex.com/meetingsamer34/j.php?MTID=mb96c5bd411bd010e1e6d43a6f6c65f45

Organizer: Liming Gao gaoliming@...

Description:

TianoCore Bug Triage - APAC / NAMO

Hosted by Liming Gao

 

https://meetingsamer34.webex.com/meetingsamer34/j.php?MTID=mb96c5bd411bd010e1e6d43a6f6c65f45

Wednesday, Jan 20, 2021 10:30 am | 50 minutes | (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi

Occurs every Wednesday effective 1/20/2021 from 10:30 AM to 11:20 AM, (UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi

Meeting number: 126 867 1239

Password: ZhqYQunw246 (94797869 from video systems)

d8edc6c9604344b08f727b4bf054eaac_20210120T023000Z

 

Join by video system

Dial 1268671239@...

You can also dial 173.243.2.68 and enter your meeting number.

 

Join by phone

Use VoIP only


回复: [edk2-devel] [edk2-platforms PATCH v2] Intel Platforms: add OrderedCollectionLib class resolution

gaoliming
 

Reviewed-by: Liming Gao <gaoliming@byosoft.com.cn>

-----邮件原件-----
发件人: bounce+27952+70497+4905953+8761045@groups.io
<bounce+27952+70497+4905953+8761045@groups.io> 代表 Laszlo Ersek
发送时间: 2021年1月18日 16:48
收件人: edk2-devel-groups-io <devel@edk2.groups.io>
抄送: Chasel Chiu <chasel.chiu@intel.com>; Eric Dong
<eric.dong@intel.com>; Kelly Steele <kelly.steele@intel.com>; Liming Gao
<gaoliming@byosoft.com.cn>; Michael D Kinney
<michael.d.kinney@intel.com>; Nate DeSimone
<nathaniel.l.desimone@intel.com>; Philippe Mathieu-Daudé
<philmd@redhat.com>; Yi Qian <yi.qian@intel.com>; Zailiang Sun
<zailiang.sun@intel.com>
主题: [edk2-devel] [edk2-platforms PATCH v2] Intel Platforms: add
OrderedCollectionLib class resolution

The edk2 patch

ShellPkg/ShellCommandLib: add ShellSortFileList

for BZ#3151 will make the

ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf

instance dependent on the OrderedCollectionLib class. Because the shell
binaries in the Intel platform DSCs consume the above UefiShellCommandLib
instance, resolve the OrderedCollectionLib class in them.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Kelly Steele <kelly.steele@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Cc: Yi Qian <yi.qian@intel.com>
Cc: Zailiang Sun <zailiang.sun@intel.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3151
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---

Notes:
v2:

- extract OpenBoardPkg update from CometlakeURvp, GalagoPro3,
KabylakeRvp3, BoardX58Ich10, UpXtreme, WhiskeylakeURvp to
"MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc" [Liming]

- do not pick up Phil's and Nate's R-b, due to the above change

Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc | 1 +
Platform/Intel/QuarkPlatformPkg/Quark.dsc | 1 +
Platform/Intel/QuarkPlatformPkg/QuarkMin.dsc | 1 +
Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc | 1 +
Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc | 1 +
5 files changed, 5 insertions(+)

diff --git a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc
b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc
index 5e3405d54785..cb40e111b5dd 100644
--- a/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc
+++ b/Platform/Intel/MinPlatformPkg/Include/Dsc/CoreCommonLib.dsc
@@ -96,6 +96,7 @@ [LibraryClasses.common]
ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
+
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLi
b/BaseOrderedCollectionRedBlackTreeLib.inf

#
# CPU
diff --git a/Platform/Intel/QuarkPlatformPkg/Quark.dsc
b/Platform/Intel/QuarkPlatformPkg/Quark.dsc
index 9f64dcb62724..e29c7465b1e4 100644
--- a/Platform/Intel/QuarkPlatformPkg/Quark.dsc
+++ b/Platform/Intel/QuarkPlatformPkg/Quark.dsc
@@ -912,6 +912,7 @@ [Components.IA32]

NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1Com
mandsLib.inf

NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1
CommandsLib.inf

HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingL
ib.inf
+
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLi
b/BaseOrderedCollectionRedBlackTreeLib.inf
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgC
ommandLib.inf

diff --git a/Platform/Intel/QuarkPlatformPkg/QuarkMin.dsc
b/Platform/Intel/QuarkPlatformPkg/QuarkMin.dsc
index db144aab75ae..6fdfba9a58dc 100644
--- a/Platform/Intel/QuarkPlatformPkg/QuarkMin.dsc
+++ b/Platform/Intel/QuarkPlatformPkg/QuarkMin.dsc
@@ -639,6 +639,7 @@ [Components.IA32]

NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1Com
mandsLib.inf

NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1
CommandsLib.inf

HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingL
ib.inf
+
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLi
b/BaseOrderedCollectionRedBlackTreeLib.inf
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgC
ommandLib.inf

diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc
b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc
index 4fa3e2013120..409f31c982d7 100644
--- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc
+++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgIA32.dsc
@@ -1152,6 +1152,7 @@ [Components.IA32]

NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1Com
mandsLib.inf

NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1
CommandsLib.inf

HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingL
ib.inf
+
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLi
b/BaseOrderedCollectionRedBlackTreeLib.inf
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgC
ommandLib.inf
<PcdsFixedAtBuild>
diff --git a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc
b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc
index 8adae2e24993..38bd825c8bdc 100644
--- a/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc
+++ b/Platform/Intel/Vlv2TbltDevicePkg/PlatformPkgX64.dsc
@@ -1167,6 +1167,7 @@ [Components.X64]

NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1Com
mandsLib.inf

NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1
CommandsLib.inf

HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingL
ib.inf
+
OrderedCollectionLib|MdePkg/Library/BaseOrderedCollectionRedBlackTreeLi
b/BaseOrderedCollectionRedBlackTreeLib.inf
PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf

BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgC
ommandLib.inf
<PcdsFixedAtBuild>

base-commit: d12d9c963ba3a02252afa9e113c4a3244192ca4a
--
2.19.1.3.g30247aa5d201





Re: 回复: [edk2-devel] [Patch 0/2] Convert Split tool to python

Bob Feng
 

Liming,

 

I have sent the patch V3 that is to move the unit test to tests/Split folder.

 

Do you have any other concerns about this patch?

 

Thanks,

Bob

 

From: Feng, Bob C
Sent: Friday, January 15, 2021 9:50 AM
To: devel@edk2.groups.io; gaoliming@...
Cc: Feng, Bob C <bob.c.feng@...>
Subject: RE: [edk2-devel]
回复: [edk2-devel] [Patch 0/2] Convert Split tool to python

 

Hi Liming,

 

1. The test framework can be used for both incremental test and functionality test. We can do more discussion when I send out this framework for review.

2. Yes, I agree to add a sub folder under the test folder. I’ll update the patch.

 

Is there any other comments before I send the patch V2?

 

Thanks,

Bob

 

From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of gaoliming
Sent: Friday, January 15, 2021 9:13 AM
To: Feng, Bob C <bob.c.feng@...>; devel@edk2.groups.io
Subject:
回复: [edk2-devel] 回复: [edk2-devel] [Patch 0/2] Convert Split tool to python

 

Bob:

 Thanks for your planning sharing. For BaseTools test, I still have some questions.

 

1.     For test framework, is it the incremental test framework or the functionality test framework or both?

2.     For BaseTools\Source\Python\tests\test_split.py, it creates new directory tests for test case scripts, and use test_split.py for split tool. So, new tool test script will follow the same style. Besides, split tool is simple. It may not have its special test case. But, Fce/FMMT are too complex. They need the different bios images as their test cases. Then, where are those test cases placed into? I would prefer to place the test script and its test cases into the same directory. So, I would propose to create the subdirectory in tests for each tool test, such as Split for this case. Then, every tool can place its test script and test case into its own directory.

 

Thanks

Liming

发件人: tosubbounce+27952+0+0+0@groups.io <tosubbounce+27952+0+0+0@groups.io> 代表 Bob Feng
发送时间: 2021114 10:46
收件人: gaoliming <gaoliming@...>; devel@edk2.groups.io
主题: Re: [edk2-devel] 回复: [edk2-devel] [Patch 0/2] Convert Split tool to python

 

Good questions. I answer them inline.

Thanks,
Bob

On Thu, Jan 14, 2021 at 08:53 AM, gaoliming wrote:

Bob:
Have you plan to convert all C tools to Python tools? Or only some ones?

I am still investigating the feasibility of converting the C tools to Python tools. Some C tools are simple but some are complex. I hope all the C tools can be converted to Python tools so that all the tools can be moved to the BaseTools separate repo. I think we can file some BZs to track the progress of the C tools conversion. And I hope there could be more volunteers to be involved in this work.

Here are the discussions about the benefit and process of moving BaseTools out of the edk2 repo for reference.

Can you share your planning for the changes in BaseTools?

Except for this patch, my current work for Basetools are:
1. Re-write the FMMT/FCE with Python and propose to add these 2 tools to the edk2 BaseTools.
2. Prepare to publish the Basetools incremental build regression test cases and test framework.

And, I see you also add unittest for new split tool. Can you introduce the
unittest framework for python tool? If so, new added tool can follow the
same way to add unittest.

The unittest is the python build-in library for the unit test. https://docs.python.org/3/library/unittest.html 
I provide the unit test is to help you to review this patch. From the unit test case, it will be easy to
see if this tool's behavior is as expected. 

I think for the python code development, we can try our best to follow this document. https://edk2-docs.gitbook.io/edk-ii-python-development-process-specification/ 


Thanks
Liming

-----邮件原件-----
发件人: bounce+27952+70232+4905953+8761045@groups.io
<bounce+27952+70232+4905953+8761045@groups.io> 代表 Bob Feng
发送时间: 2021113 17:56
收件人: devel@edk2.groups.io
主题: [edk2-devel] [Patch 0/2] Convert Split tool to python

There are 2 reasons to convert Split tool from C to Python.

1. We are in the process of moving the Basetools Python code

to a separate repository. But there still are many C tools under

edk2/BaseTools. To make all Basetools be in the separate repo,

we can convert the C tools to Python tools.

2. The original Split tool is very slow. This python tool can reduce

90% time

Bob Feng (2):
BaseTools: Convert Split tool to python
BaseTools: Add unittest for Split tool

BaseTools/Source/C/Split/Split.c | 466 --------------------
BaseTools/BinWrappers/PosixLike/Split | 31 +-
BaseTools/BinWrappers/WindowsLike/Split.bat | 3 +
BaseTools/Source/C/GNUmakefile | 1 -
BaseTools/Source/C/Makefile | 1 -
BaseTools/Source/C/Split/GNUmakefile | 17 -
BaseTools/Source/C/Split/Makefile | 16 -
BaseTools/Source/Python/Split/Split.py | 203 +++++++++
BaseTools/Source/Python/Split/__init__.py | 10 +
BaseTools/Source/Python/tests/test_split.py | 101 +++++
10 files changed, 325 insertions(+), 524 deletions(-)
delete mode 100644 BaseTools/Source/C/Split/Split.c
create mode 100644 BaseTools/BinWrappers/WindowsLike/Split.bat
delete mode 100644 BaseTools/Source/C/Split/GNUmakefile
delete mode 100644 BaseTools/Source/C/Split/Makefile
create mode 100644 BaseTools/Source/Python/Split/Split.py
create mode 100644 BaseTools/Source/Python/Split/__init__.py
create mode 100644 BaseTools/Source/Python/tests/test_split.py

--
2.29.1.windows.1



-=-=-=-=-=-=
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70232): https://edk2.groups.io/g/devel/message/70232
Mute This Topic: https://groups.io/mt/79647273/4905953
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub
[gaoliming@...]
-=-=-=-=-=-=


Re: [PATCH v4 0/9] support CPU hot-unplug

Ankur Arora
 

On 2021-01-18 9:09 a.m., Laszlo Ersek wrote:
On 01/18/21 07:34, Ankur Arora wrote:
Hi,

This series adds support for CPU hot-unplug with OVMF.

Please see this in conjunction with the QEMU secureboot hot-unplug v2
series posted here (now upstreamed):
https://lore.kernel.org/qemu-devel/20201207140739.3829993-1-imammedo@redhat.com/

Patches 1 and 3,
("OvmfPkg/CpuHotplugSmm: refactor hotplug logic")
("OvmfPkg/CpuHotplugSmm: add Qemu Cpu Status helper")
are either refactors or add support functions.

OvmfPkg/CpuHotplugSmm: introduce UnplugCpus()
OvmfPkg/CpuHotplugSmm: add CpuEject()
OvmfPkg/CpuHotplugSmm: add worker to do CPU ejection

Patch 2 and 9,
("OvmfPkg/CpuHotplugSmm: collect hot-unplug events")
("OvmfPkg/SmmControl2Dxe: negotiate CPU hot-unplug")
handle the QEMU protocol logic for collection of CPU hot-unplug events
or the protocol negotiation.

Patch 4,
("OvmfPkg/CpuHotplugSmm: introduce UnplugCpus()")
adds the MMI logic for CPU hot-unplug handling and informing
the PiSmmCpuDxeSmm of CPU removal.

Patches 5 and 6,
("OvmfPkg/CpuHotplugSmm: define CPU_HOT_EJECT_DATA")
("OvmfPkg/SmmCpuFeaturesLib: init CPU ejection state")
sets up state for doing the CPU ejection as part of hot-unplug.

Patches 7, and 8,
("OvmfPkg/CpuHotplugSmm: introduce UnplugCpus()")
("OvmfPkg/CpuHotplugSmm: add worker to do CPU ejection")
add the CPU ejection logic.

Testing (with QEMU 5.2.50):
- Stable with randomized CPU plug/unplug (guest maxcpus=1,8,128)
- Synthetic tests with simultaneous multi CPU hot-unplug
- Negotiation with/without CPU hotplug enabled

Also at:
github.com/terminus/edk2/ hot-unplug-v4

Changelog:
v4:
- Gets rid of unnecessary UefiCpuPkg changes

v3:
- Use a saner PCD based interface to share state between PiSmmCpuDxeSmm
and OvmfPkg/CpuHotplugSmm
- Cleaner split of the hot-unplug code
URL: https://patchew.org/EDK2/20210115074533.277448-1-ankur.a.arora@oracle.com/

v2:
- Do the ejection via SmmCpuFeaturesRendezvousExit()
URL: https://patchew.org/EDK2/20210107195515.106158-1-ankur.a.arora@oracle.com/

RFC:
URL: https://patchew.org/EDK2/20201208053432.2690694-1-ankur.a.arora@oracle.com/


Please review.
I've got this series in my review queue (confirming).
I'd like to finish review on the
<https://bugzilla.tianocore.org/show_bug.cgi?id=3059> series first,
since that's what I've got mostly in my mind at this point.
I hope to start reviewing the unplug series in a few days.
Sounds good. Thanks.

Ankur

Thanks
Laszlo


Thanks
Ankur

Ankur Arora (9):
OvmfPkg/CpuHotplugSmm: refactor hotplug logic
OvmfPkg/CpuHotplugSmm: collect hot-unplug events
OvmfPkg/CpuHotplugSmm: add Qemu Cpu Status helper
OvmfPkg/CpuHotplugSmm: introduce UnplugCpus()
OvmfPkg/CpuHotplugSmm: define CPU_HOT_EJECT_DATA
OvmfPkg/SmmCpuFeaturesLib: init CPU ejection state
OvmfPkg/CpuHotplugSmm: add CpuEject()
OvmfPkg/CpuHotplugSmm: add worker to do CPU ejection
OvmfPkg/SmmControl2Dxe: negotiate CPU hot-unplug

OvmfPkg/CpuHotplugSmm/CpuHotplug.c | 435 ++++++++++++++++-----
OvmfPkg/CpuHotplugSmm/CpuHotplugSmm.inf | 1 +
OvmfPkg/CpuHotplugSmm/QemuCpuhp.c | 58 ++-
OvmfPkg/CpuHotplugSmm/QemuCpuhp.h | 6 +
OvmfPkg/Include/IndustryStandard/QemuCpuHotplug.h | 2 +
OvmfPkg/Include/Library/CpuHotEjectData.h | 31 ++
.../Library/SmmCpuFeaturesLib/SmmCpuFeaturesLib.c | 62 +++
.../SmmCpuFeaturesLib/SmmCpuFeaturesLib.inf | 3 +
OvmfPkg/OvmfPkg.dec | 6 +
OvmfPkg/SmmControl2Dxe/SmiFeatures.c | 25 +-
10 files changed, 527 insertions(+), 102 deletions(-)
create mode 100644 OvmfPkg/Include/Library/CpuHotEjectData.h

15181 - 15200 of 85636